ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinPoolTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.57 by jsr166, Sat Oct 3 16:57:25 2015 UTC vs.
Revision 1.69 by jsr166, Tue Oct 13 21:14:39 2015 UTC

# Line 64 | Line 64 | public class ForkJoinPoolTest extends JS
64          }
65      }
66  
67 +    static class MyError extends Error {}
68 +
69      // to test handlers
70      static class FailingFJWSubclass extends ForkJoinWorkerThread {
71          public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
72 <        protected void onStart() { super.onStart(); throw new Error(); }
72 >        protected void onStart() { super.onStart(); throw new MyError(); }
73      }
74  
75      static class FailingThreadFactory
# Line 162 | Line 164 | public class ForkJoinPoolTest extends JS
164       */
165      public void testDefaultInitialState() {
166          ForkJoinPool p = new ForkJoinPool(1);
167 <        try {
167 >        try (PoolCleaner cleaner = cleaner(p)) {
168              assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
169                         p.getFactory());
170              assertFalse(p.getAsyncMode());
# Line 174 | Line 176 | public class ForkJoinPoolTest extends JS
176              assertFalse(p.isShutdown());
177              assertFalse(p.isTerminating());
178              assertFalse(p.isTerminated());
177        } finally {
178            joinPool(p);
179          }
180      }
181  
# Line 204 | Line 204 | public class ForkJoinPoolTest extends JS
204       */
205      public void testGetParallelism() {
206          ForkJoinPool p = new ForkJoinPool(1);
207 <        try {
207 >        try (PoolCleaner cleaner = cleaner(p)) {
208              assertEquals(1, p.getParallelism());
209        } finally {
210            joinPool(p);
209          }
210      }
211  
# Line 215 | Line 213 | public class ForkJoinPoolTest extends JS
213       * getPoolSize returns number of started workers.
214       */
215      public void testGetPoolSize() {
216 <        ForkJoinPool p = new ForkJoinPool(1);
217 <        try {
216 >        final CountDownLatch taskStarted = new CountDownLatch(1);
217 >        final CountDownLatch done = new CountDownLatch(1);
218 >        final ForkJoinPool p = new ForkJoinPool(1);
219 >        try (PoolCleaner cleaner = cleaner(p)) {
220              assertEquals(0, p.getActiveThreadCount());
221 <            Future<String> future = p.submit(new StringTask());
221 >            final Runnable task = new CheckedRunnable() {
222 >                public void realRun() throws InterruptedException {
223 >                    taskStarted.countDown();
224 >                    assertEquals(1, p.getPoolSize());
225 >                    assertEquals(1, p.getActiveThreadCount());
226 >                    done.await();
227 >                }};
228 >            Future<?> future = p.submit(task);
229 >            await(taskStarted);
230              assertEquals(1, p.getPoolSize());
231 <        } finally {
232 <            joinPool(p);
231 >            assertEquals(1, p.getActiveThreadCount());
232 >            done.countDown();
233          }
234 +        assertEquals(0, p.getPoolSize());
235 +        assertEquals(0, p.getActiveThreadCount());
236      }
237  
238      /**
# Line 230 | Line 240 | public class ForkJoinPoolTest extends JS
240       */
241      public void testAwaitTermination_timesOut() throws InterruptedException {
242          ForkJoinPool p = new ForkJoinPool(1);
243 <        assertFalse(p.isTerminated());
244 <        assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
245 <        assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
246 <        assertFalse(p.awaitTermination(-1L, NANOSECONDS));
247 <        assertFalse(p.awaitTermination(-1L, MILLISECONDS));
248 <        assertFalse(p.awaitTermination(0L, NANOSECONDS));
249 <        assertFalse(p.awaitTermination(0L, MILLISECONDS));
250 <        long timeoutNanos = 999999L;
251 <        long startTime = System.nanoTime();
252 <        assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
253 <        assertTrue(System.nanoTime() - startTime >= timeoutNanos);
254 <        assertFalse(p.isTerminated());
255 <        startTime = System.nanoTime();
256 <        long timeoutMillis = timeoutMillis();
257 <        assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
258 <        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
259 <        assertFalse(p.isTerminated());
260 <        p.shutdown();
261 <        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
262 <        assertTrue(p.isTerminated());
243 >        try (PoolCleaner cleaner = cleaner(p)) {
244 >            assertFalse(p.isTerminated());
245 >            assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
246 >            assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
247 >            assertFalse(p.awaitTermination(-1L, NANOSECONDS));
248 >            assertFalse(p.awaitTermination(-1L, MILLISECONDS));
249 >            assertFalse(p.awaitTermination(0L, NANOSECONDS));
250 >            assertFalse(p.awaitTermination(0L, MILLISECONDS));
251 >            long timeoutNanos = 999999L;
252 >            long startTime = System.nanoTime();
253 >            assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
254 >            assertTrue(System.nanoTime() - startTime >= timeoutNanos);
255 >            assertFalse(p.isTerminated());
256 >            startTime = System.nanoTime();
257 >            long timeoutMillis = timeoutMillis();
258 >            assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
259 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
260 >            assertFalse(p.isTerminated());
261 >            p.shutdown();
262 >            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
263 >            assertTrue(p.isTerminated());
264 >        }
265      }
266  
267      /**
# Line 260 | Line 272 | public class ForkJoinPoolTest extends JS
272       */
273      public void testSetUncaughtExceptionHandler() throws InterruptedException {
274          final CountDownLatch uehInvoked = new CountDownLatch(1);
275 <        final Thread.UncaughtExceptionHandler eh =
275 >        final Thread.UncaughtExceptionHandler ueh =
276              new Thread.UncaughtExceptionHandler() {
277                  public void uncaughtException(Thread t, Throwable e) {
278 +                    threadAssertTrue(e instanceof MyError);
279 +                    threadAssertTrue(t instanceof FailingFJWSubclass);
280                      uehInvoked.countDown();
281                  }};
282          ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(),
283 <                                          eh, false);
284 <        try {
285 <            assertSame(eh, p.getUncaughtExceptionHandler());
283 >                                          ueh, false);
284 >        try (PoolCleaner cleaner = cleaner(p)) {
285 >            assertSame(ueh, p.getUncaughtExceptionHandler());
286              try {
287                  p.execute(new FibTask(8));
288 <                assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS));
289 <            } catch (RejectedExecutionException ok) {
288 >                await(uehInvoked);
289 >            } finally {
290 >                p.shutdownNow(); // failure might have prevented processing task
291              }
277        } finally {
278            p.shutdownNow(); // failure might have prevented processing task
279            joinPool(p);
292          }
293      }
294  
# Line 288 | Line 300 | public class ForkJoinPoolTest extends JS
300       */
301      public void testIsQuiescent() throws Exception {
302          ForkJoinPool p = new ForkJoinPool(2);
303 <        try {
303 >        try (PoolCleaner cleaner = cleaner(p)) {
304              assertTrue(p.isQuiescent());
305              long startTime = System.nanoTime();
306              FibTask f = new FibTask(20);
# Line 316 | Line 328 | public class ForkJoinPoolTest extends JS
328              assertFalse(p.isTerminated());
329              assertTrue(f.isDone());
330              assertEquals(6765, (int) f.get());
319        } finally {
320            joinPool(p);
331          }
332      }
333  
# Line 326 | Line 336 | public class ForkJoinPoolTest extends JS
336       */
337      public void testSubmitForkJoinTask() throws Throwable {
338          ForkJoinPool p = new ForkJoinPool(1);
339 <        try {
339 >        try (PoolCleaner cleaner = cleaner(p)) {
340              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
341              assertEquals(21, (int) f.get());
332        } finally {
333            joinPool(p);
342          }
343      }
344  
# Line 339 | Line 347 | public class ForkJoinPoolTest extends JS
347       */
348      public void testSubmitAfterShutdown() {
349          ForkJoinPool p = new ForkJoinPool(1);
350 <        try {
350 >        try (PoolCleaner cleaner = cleaner(p)) {
351              p.shutdown();
352              assertTrue(p.isShutdown());
353              try {
354                  ForkJoinTask<Integer> f = p.submit(new FibTask(8));
355                  shouldThrow();
356              } catch (RejectedExecutionException success) {}
349        } finally {
350            joinPool(p);
357          }
358      }
359  
# Line 373 | Line 379 | public class ForkJoinPoolTest extends JS
379      public void testPollSubmission() {
380          final CountDownLatch done = new CountDownLatch(1);
381          SubFJP p = new SubFJP();
382 <        try {
382 >        try (PoolCleaner cleaner = cleaner(p)) {
383              ForkJoinTask a = p.submit(awaiter(done));
384              ForkJoinTask b = p.submit(awaiter(done));
385              ForkJoinTask c = p.submit(awaiter(done));
386              ForkJoinTask r = p.pollSubmission();
387              assertTrue(r == a || r == b || r == c);
388              assertFalse(r.isDone());
383        } finally {
389              done.countDown();
385            joinPool(p);
390          }
391      }
392  
# Line 392 | Line 396 | public class ForkJoinPoolTest extends JS
396      public void testDrainTasksTo() {
397          final CountDownLatch done = new CountDownLatch(1);
398          SubFJP p = new SubFJP();
399 <        try {
399 >        try (PoolCleaner cleaner = cleaner(p)) {
400              ForkJoinTask a = p.submit(awaiter(done));
401              ForkJoinTask b = p.submit(awaiter(done));
402              ForkJoinTask c = p.submit(awaiter(done));
# Line 403 | Line 407 | public class ForkJoinPoolTest extends JS
407                  assertTrue(r == a || r == b || r == c);
408                  assertFalse(r.isDone());
409              }
406        } finally {
410              done.countDown();
408            joinPool(p);
411          }
412      }
413  
# Line 416 | Line 418 | public class ForkJoinPoolTest extends JS
418       */
419      public void testExecuteRunnable() throws Throwable {
420          ExecutorService e = new ForkJoinPool(1);
421 <        try {
421 >        try (PoolCleaner cleaner = cleaner(e)) {
422              final AtomicBoolean done = new AtomicBoolean(false);
423              Future<?> future = e.submit(new CheckedRunnable() {
424                  public void realRun() {
# Line 427 | Line 429 | public class ForkJoinPoolTest extends JS
429              assertTrue(done.get());
430              assertTrue(future.isDone());
431              assertFalse(future.isCancelled());
430        } finally {
431            joinPool(e);
432          }
433      }
434  
# Line 437 | Line 437 | public class ForkJoinPoolTest extends JS
437       */
438      public void testSubmitCallable() throws Throwable {
439          ExecutorService e = new ForkJoinPool(1);
440 <        try {
440 >        try (PoolCleaner cleaner = cleaner(e)) {
441              Future<String> future = e.submit(new StringTask());
442              assertSame(TEST_STRING, future.get());
443              assertTrue(future.isDone());
444              assertFalse(future.isCancelled());
445        } finally {
446            joinPool(e);
445          }
446      }
447  
# Line 452 | Line 450 | public class ForkJoinPoolTest extends JS
450       */
451      public void testSubmitRunnable() throws Throwable {
452          ExecutorService e = new ForkJoinPool(1);
453 <        try {
453 >        try (PoolCleaner cleaner = cleaner(e)) {
454              Future<?> future = e.submit(new NoOpRunnable());
455              assertNull(future.get());
456              assertTrue(future.isDone());
457              assertFalse(future.isCancelled());
460        } finally {
461            joinPool(e);
458          }
459      }
460  
# Line 467 | Line 463 | public class ForkJoinPoolTest extends JS
463       */
464      public void testSubmitRunnable2() throws Throwable {
465          ExecutorService e = new ForkJoinPool(1);
466 <        try {
466 >        try (PoolCleaner cleaner = cleaner(e)) {
467              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
468              assertSame(TEST_STRING, future.get());
469              assertTrue(future.isDone());
470              assertFalse(future.isCancelled());
475        } finally {
476            joinPool(e);
471          }
472      }
473  
# Line 486 | Line 480 | public class ForkJoinPoolTest extends JS
480          Runnable r = new CheckedRunnable() {
481          public void realRun() throws Exception {
482              ExecutorService e = new ForkJoinPool(1);
483 <            try {
483 >            try (PoolCleaner cleaner = cleaner(e)) {
484                  Future future = e.submit(callable);
485                  assertSame(TEST_STRING, future.get());
492            } finally {
493                joinPool(e);
486              }
487          }};
488  
# Line 507 | Line 499 | public class ForkJoinPoolTest extends JS
499          Runnable r = new CheckedRunnable() {
500          public void realRun() throws Exception {
501              ExecutorService e = new ForkJoinPool(1);
502 <            try {
502 >            try (PoolCleaner cleaner = cleaner(e)) {
503                  Future future = e.submit(callable);
504                  assertSame(TEST_STRING, future.get());
513            } finally {
514                joinPool(e);
505              }
506          }};
507  
# Line 528 | Line 518 | public class ForkJoinPoolTest extends JS
518          Runnable r = new CheckedRunnable() {
519          public void realRun() throws Exception {
520              ExecutorService e = new ForkJoinPool(1);
521 <            try {
521 >            try (PoolCleaner cleaner = cleaner(e)) {
522                  Future future = e.submit(callable);
523                  try {
524                      future.get();
# Line 536 | Line 526 | public class ForkJoinPoolTest extends JS
526                  } catch (ExecutionException success) {
527                      assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
528                  }
539            } finally {
540                joinPool(e);
529              }
530          }};
531  
# Line 549 | Line 537 | public class ForkJoinPoolTest extends JS
537       */
538      public void testExecuteNullRunnable() {
539          ExecutorService e = new ForkJoinPool(1);
540 <        try {
541 <            Future<?> future = e.submit((Runnable) null);
542 <            shouldThrow();
543 <        } catch (NullPointerException success) {
544 <        } finally {
557 <            joinPool(e);
540 >        try (PoolCleaner cleaner = cleaner(e)) {
541 >            try {
542 >                Future<?> future = e.submit((Runnable) null);
543 >                shouldThrow();
544 >            } catch (NullPointerException success) {}
545          }
546      }
547  
# Line 563 | Line 550 | public class ForkJoinPoolTest extends JS
550       */
551      public void testSubmitNullCallable() {
552          ExecutorService e = new ForkJoinPool(1);
553 <        try {
554 <            Future<String> future = e.submit((Callable) null);
555 <            shouldThrow();
556 <        } catch (NullPointerException success) {
557 <        } finally {
571 <            joinPool(e);
553 >        try (PoolCleaner cleaner = cleaner(e)) {
554 >            try {
555 >                Future<String> future = e.submit((Callable) null);
556 >                shouldThrow();
557 >            } catch (NullPointerException success) {}
558          }
559      }
560  
# Line 578 | Line 564 | public class ForkJoinPoolTest extends JS
564      public void testInterruptedSubmit() throws InterruptedException {
565          final CountDownLatch submitted    = new CountDownLatch(1);
566          final CountDownLatch quittingTime = new CountDownLatch(1);
581        final ExecutorService p = new ForkJoinPool(1);
567          final Callable<Void> awaiter = new CheckedCallable<Void>() {
568              public Void realCall() throws InterruptedException {
569 <                assertTrue(quittingTime.await(MEDIUM_DELAY_MS, MILLISECONDS));
569 >                assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
570                  return null;
571              }};
572 <        try {
572 >        final ExecutorService p = new ForkJoinPool(1);
573 >        try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
574              Thread t = new Thread(new CheckedInterruptedRunnable() {
575                  public void realRun() throws Exception {
576                      Future<Void> future = p.submit(awaiter);
# Line 592 | Line 578 | public class ForkJoinPoolTest extends JS
578                      future.get();
579                  }});
580              t.start();
581 <            assertTrue(submitted.await(MEDIUM_DELAY_MS, MILLISECONDS));
581 >            await(submitted);
582              t.interrupt();
583 <            t.join();
598 <        } finally {
599 <            quittingTime.countDown();
600 <            joinPool(p);
583 >            awaitTermination(t);
584          }
585      }
586  
# Line 607 | Line 590 | public class ForkJoinPoolTest extends JS
590       */
591      public void testSubmitEE() throws Throwable {
592          ForkJoinPool p = new ForkJoinPool(1);
593 <        try {
594 <            p.submit(new Callable() {
595 <                public Object call() { throw new ArithmeticException(); }})
596 <                .get();
597 <            shouldThrow();
598 <        } catch (ExecutionException success) {
599 <            assertTrue(success.getCause() instanceof ArithmeticException);
600 <        } finally {
601 <            joinPool(p);
593 >        try (PoolCleaner cleaner = cleaner(p)) {
594 >            try {
595 >                p.submit(new Callable() {
596 >                        public Object call() { throw new ArithmeticException(); }})
597 >                    .get();
598 >                shouldThrow();
599 >            } catch (ExecutionException success) {
600 >                assertTrue(success.getCause() instanceof ArithmeticException);
601 >            }
602          }
603      }
604  
# Line 624 | Line 607 | public class ForkJoinPoolTest extends JS
607       */
608      public void testInvokeAny1() throws Throwable {
609          ExecutorService e = new ForkJoinPool(1);
610 <        try {
611 <            e.invokeAny(null);
612 <            shouldThrow();
613 <        } catch (NullPointerException success) {
614 <        } finally {
632 <            joinPool(e);
610 >        try (PoolCleaner cleaner = cleaner(e)) {
611 >            try {
612 >                e.invokeAny(null);
613 >                shouldThrow();
614 >            } catch (NullPointerException success) {}
615          }
616      }
617  
# Line 638 | Line 620 | public class ForkJoinPoolTest extends JS
620       */
621      public void testInvokeAny2() throws Throwable {
622          ExecutorService e = new ForkJoinPool(1);
623 <        try {
624 <            e.invokeAny(new ArrayList<Callable<String>>());
625 <            shouldThrow();
626 <        } catch (IllegalArgumentException success) {
627 <        } finally {
646 <            joinPool(e);
623 >        try (PoolCleaner cleaner = cleaner(e)) {
624 >            try {
625 >                e.invokeAny(new ArrayList<Callable<String>>());
626 >                shouldThrow();
627 >            } catch (IllegalArgumentException success) {}
628          }
629      }
630  
# Line 652 | Line 633 | public class ForkJoinPoolTest extends JS
633       */
634      public void testInvokeAny3() throws Throwable {
635          ExecutorService e = new ForkJoinPool(1);
636 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
637 <        l.add(null);
638 <        try {
639 <            e.invokeAny(l);
640 <            shouldThrow();
641 <        } catch (NullPointerException success) {
642 <        } finally {
662 <            joinPool(e);
636 >        try (PoolCleaner cleaner = cleaner(e)) {
637 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
638 >            l.add(null);
639 >            try {
640 >                e.invokeAny(l);
641 >                shouldThrow();
642 >            } catch (NullPointerException success) {}
643          }
644      }
645  
# Line 669 | Line 649 | public class ForkJoinPoolTest extends JS
649      public void testInvokeAny4() throws Throwable {
650          CountDownLatch latch = new CountDownLatch(1);
651          ExecutorService e = new ForkJoinPool(1);
652 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
653 <        l.add(latchAwaitingStringTask(latch));
654 <        l.add(null);
655 <        try {
656 <            e.invokeAny(l);
657 <            shouldThrow();
658 <        } catch (NullPointerException success) {
659 <        } finally {
652 >        try (PoolCleaner cleaner = cleaner(e)) {
653 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
654 >            l.add(latchAwaitingStringTask(latch));
655 >            l.add(null);
656 >            try {
657 >                e.invokeAny(l);
658 >                shouldThrow();
659 >            } catch (NullPointerException success) {}
660              latch.countDown();
681            joinPool(e);
661          }
662      }
663  
# Line 687 | Line 666 | public class ForkJoinPoolTest extends JS
666       */
667      public void testInvokeAny5() throws Throwable {
668          ExecutorService e = new ForkJoinPool(1);
669 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
670 <        l.add(new NPETask());
671 <        try {
672 <            e.invokeAny(l);
673 <            shouldThrow();
674 <        } catch (ExecutionException success) {
675 <            assertTrue(success.getCause() instanceof NullPointerException);
676 <        } finally {
677 <            joinPool(e);
669 >        try (PoolCleaner cleaner = cleaner(e)) {
670 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
671 >            l.add(new NPETask());
672 >            try {
673 >                e.invokeAny(l);
674 >                shouldThrow();
675 >            } catch (ExecutionException success) {
676 >                assertTrue(success.getCause() instanceof NullPointerException);
677 >            }
678          }
679      }
680  
# Line 704 | Line 683 | public class ForkJoinPoolTest extends JS
683       */
684      public void testInvokeAny6() throws Throwable {
685          ExecutorService e = new ForkJoinPool(1);
686 <        try {
686 >        try (PoolCleaner cleaner = cleaner(e)) {
687              List<Callable<String>> l = new ArrayList<Callable<String>>();
688              l.add(new StringTask());
689              l.add(new StringTask());
690              String result = e.invokeAny(l);
691              assertSame(TEST_STRING, result);
713        } finally {
714            joinPool(e);
692          }
693      }
694  
# Line 720 | Line 697 | public class ForkJoinPoolTest extends JS
697       */
698      public void testInvokeAll1() throws Throwable {
699          ExecutorService e = new ForkJoinPool(1);
700 <        try {
701 <            e.invokeAll(null);
702 <            shouldThrow();
703 <        } catch (NullPointerException success) {
704 <        } finally {
728 <            joinPool(e);
700 >        try (PoolCleaner cleaner = cleaner(e)) {
701 >            try {
702 >                e.invokeAll(null);
703 >                shouldThrow();
704 >            } catch (NullPointerException success) {}
705          }
706      }
707  
# Line 734 | Line 710 | public class ForkJoinPoolTest extends JS
710       */
711      public void testInvokeAll2() throws InterruptedException {
712          ExecutorService e = new ForkJoinPool(1);
713 <        try {
713 >        try (PoolCleaner cleaner = cleaner(e)) {
714              List<Future<String>> r
715                  = e.invokeAll(new ArrayList<Callable<String>>());
716              assertTrue(r.isEmpty());
741        } finally {
742            joinPool(e);
717          }
718      }
719  
# Line 748 | Line 722 | public class ForkJoinPoolTest extends JS
722       */
723      public void testInvokeAll3() throws InterruptedException {
724          ExecutorService e = new ForkJoinPool(1);
725 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
726 <        l.add(new StringTask());
727 <        l.add(null);
728 <        try {
729 <            e.invokeAll(l);
730 <            shouldThrow();
731 <        } catch (NullPointerException success) {
732 <        } finally {
759 <            joinPool(e);
725 >        try (PoolCleaner cleaner = cleaner(e)) {
726 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
727 >            l.add(new StringTask());
728 >            l.add(null);
729 >            try {
730 >                e.invokeAll(l);
731 >                shouldThrow();
732 >            } catch (NullPointerException success) {}
733          }
734      }
735  
# Line 766 | Line 739 | public class ForkJoinPoolTest extends JS
739       */
740      public void testInvokeAll4() throws Throwable {
741          ExecutorService e = new ForkJoinPool(1);
742 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
743 <        l.add(new NPETask());
744 <        List<Future<String>> futures = e.invokeAll(l);
745 <        assertEquals(1, futures.size());
746 <        try {
747 <            futures.get(0).get();
748 <            shouldThrow();
749 <        } catch (ExecutionException success) {
750 <            assertTrue(success.getCause() instanceof NullPointerException);
751 <        } finally {
752 <            joinPool(e);
742 >        try (PoolCleaner cleaner = cleaner(e)) {
743 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
744 >            l.add(new NPETask());
745 >            List<Future<String>> futures = e.invokeAll(l);
746 >            assertEquals(1, futures.size());
747 >            try {
748 >                futures.get(0).get();
749 >                shouldThrow();
750 >            } catch (ExecutionException success) {
751 >                assertTrue(success.getCause() instanceof NullPointerException);
752 >            }
753          }
754      }
755  
# Line 785 | Line 758 | public class ForkJoinPoolTest extends JS
758       */
759      public void testInvokeAll5() throws Throwable {
760          ExecutorService e = new ForkJoinPool(1);
761 <        try {
761 >        try (PoolCleaner cleaner = cleaner(e)) {
762              List<Callable<String>> l = new ArrayList<Callable<String>>();
763              l.add(new StringTask());
764              l.add(new StringTask());
# Line 793 | Line 766 | public class ForkJoinPoolTest extends JS
766              assertEquals(2, futures.size());
767              for (Future<String> future : futures)
768                  assertSame(TEST_STRING, future.get());
796        } finally {
797            joinPool(e);
769          }
770      }
771  
# Line 803 | Line 774 | public class ForkJoinPoolTest extends JS
774       */
775      public void testTimedInvokeAny1() throws Throwable {
776          ExecutorService e = new ForkJoinPool(1);
777 <        try {
778 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
779 <            shouldThrow();
780 <        } catch (NullPointerException success) {
781 <        } finally {
811 <            joinPool(e);
777 >        try (PoolCleaner cleaner = cleaner(e)) {
778 >            try {
779 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
780 >                shouldThrow();
781 >            } catch (NullPointerException success) {}
782          }
783      }
784  
# Line 817 | Line 787 | public class ForkJoinPoolTest extends JS
787       */
788      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
789          ExecutorService e = new ForkJoinPool(1);
790 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
791 <        l.add(new StringTask());
792 <        try {
793 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
794 <            shouldThrow();
795 <        } catch (NullPointerException success) {
796 <        } finally {
827 <            joinPool(e);
790 >        try (PoolCleaner cleaner = cleaner(e)) {
791 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
792 >            l.add(new StringTask());
793 >            try {
794 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
795 >                shouldThrow();
796 >            } catch (NullPointerException success) {}
797          }
798      }
799  
# Line 833 | Line 802 | public class ForkJoinPoolTest extends JS
802       */
803      public void testTimedInvokeAny2() throws Throwable {
804          ExecutorService e = new ForkJoinPool(1);
805 <        try {
806 <            e.invokeAny(new ArrayList<Callable<String>>(),
807 <                        MEDIUM_DELAY_MS, MILLISECONDS);
808 <            shouldThrow();
809 <        } catch (IllegalArgumentException success) {
810 <        } finally {
842 <            joinPool(e);
805 >        try (PoolCleaner cleaner = cleaner(e)) {
806 >            try {
807 >                e.invokeAny(new ArrayList<Callable<String>>(),
808 >                            MEDIUM_DELAY_MS, MILLISECONDS);
809 >                shouldThrow();
810 >            } catch (IllegalArgumentException success) {}
811          }
812      }
813  
# Line 849 | Line 817 | public class ForkJoinPoolTest extends JS
817      public void testTimedInvokeAny3() throws Throwable {
818          CountDownLatch latch = new CountDownLatch(1);
819          ExecutorService e = new ForkJoinPool(1);
820 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
821 <        l.add(latchAwaitingStringTask(latch));
822 <        l.add(null);
823 <        try {
824 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
825 <            shouldThrow();
826 <        } catch (NullPointerException success) {
827 <        } finally {
820 >        try (PoolCleaner cleaner = cleaner(e)) {
821 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
822 >            l.add(latchAwaitingStringTask(latch));
823 >            l.add(null);
824 >            try {
825 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
826 >                shouldThrow();
827 >            } catch (NullPointerException success) {}
828              latch.countDown();
861            joinPool(e);
829          }
830      }
831  
# Line 867 | Line 834 | public class ForkJoinPoolTest extends JS
834       */
835      public void testTimedInvokeAny4() throws Throwable {
836          ExecutorService e = new ForkJoinPool(1);
837 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
838 <        l.add(new NPETask());
839 <        try {
840 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
841 <            shouldThrow();
842 <        } catch (ExecutionException success) {
843 <            assertTrue(success.getCause() instanceof NullPointerException);
844 <        } finally {
845 <            joinPool(e);
837 >        try (PoolCleaner cleaner = cleaner(e)) {
838 >            long startTime = System.nanoTime();
839 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
840 >            l.add(new NPETask());
841 >            try {
842 >                e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
843 >                shouldThrow();
844 >            } catch (ExecutionException success) {
845 >                assertTrue(success.getCause() instanceof NullPointerException);
846 >            }
847 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
848          }
849      }
850  
# Line 884 | Line 853 | public class ForkJoinPoolTest extends JS
853       */
854      public void testTimedInvokeAny5() throws Throwable {
855          ExecutorService e = new ForkJoinPool(1);
856 <        try {
856 >        try (PoolCleaner cleaner = cleaner(e)) {
857 >            long startTime = System.nanoTime();
858              List<Callable<String>> l = new ArrayList<Callable<String>>();
859              l.add(new StringTask());
860              l.add(new StringTask());
861 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
861 >            String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
862              assertSame(TEST_STRING, result);
863 <        } finally {
894 <            joinPool(e);
863 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
864          }
865      }
866  
# Line 900 | Line 869 | public class ForkJoinPoolTest extends JS
869       */
870      public void testTimedInvokeAll1() throws Throwable {
871          ExecutorService e = new ForkJoinPool(1);
872 <        try {
873 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
874 <            shouldThrow();
875 <        } catch (NullPointerException success) {
876 <        } finally {
908 <            joinPool(e);
872 >        try (PoolCleaner cleaner = cleaner(e)) {
873 >            try {
874 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
875 >                shouldThrow();
876 >            } catch (NullPointerException success) {}
877          }
878      }
879  
# Line 914 | Line 882 | public class ForkJoinPoolTest extends JS
882       */
883      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
884          ExecutorService e = new ForkJoinPool(1);
885 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
886 <        l.add(new StringTask());
887 <        try {
888 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
889 <            shouldThrow();
890 <        } catch (NullPointerException success) {
891 <        } finally {
924 <            joinPool(e);
885 >        try (PoolCleaner cleaner = cleaner(e)) {
886 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
887 >            l.add(new StringTask());
888 >            try {
889 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
890 >                shouldThrow();
891 >            } catch (NullPointerException success) {}
892          }
893      }
894  
# Line 930 | Line 897 | public class ForkJoinPoolTest extends JS
897       */
898      public void testTimedInvokeAll2() throws InterruptedException {
899          ExecutorService e = new ForkJoinPool(1);
900 <        try {
900 >        try (PoolCleaner cleaner = cleaner(e)) {
901              List<Future<String>> r
902                  = e.invokeAll(new ArrayList<Callable<String>>(),
903                                MEDIUM_DELAY_MS, MILLISECONDS);
904              assertTrue(r.isEmpty());
938        } finally {
939            joinPool(e);
905          }
906      }
907  
# Line 945 | Line 910 | public class ForkJoinPoolTest extends JS
910       */
911      public void testTimedInvokeAll3() throws InterruptedException {
912          ExecutorService e = new ForkJoinPool(1);
913 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
914 <        l.add(new StringTask());
915 <        l.add(null);
916 <        try {
917 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
918 <            shouldThrow();
919 <        } catch (NullPointerException success) {
920 <        } finally {
956 <            joinPool(e);
913 >        try (PoolCleaner cleaner = cleaner(e)) {
914 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
915 >            l.add(new StringTask());
916 >            l.add(null);
917 >            try {
918 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
919 >                shouldThrow();
920 >            } catch (NullPointerException success) {}
921          }
922      }
923  
# Line 962 | Line 926 | public class ForkJoinPoolTest extends JS
926       */
927      public void testTimedInvokeAll4() throws Throwable {
928          ExecutorService e = new ForkJoinPool(1);
929 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
930 <        l.add(new NPETask());
931 <        List<Future<String>> futures
932 <            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
933 <        assertEquals(1, futures.size());
934 <        try {
935 <            futures.get(0).get();
936 <            shouldThrow();
937 <        } catch (ExecutionException success) {
938 <            assertTrue(success.getCause() instanceof NullPointerException);
939 <        } finally {
940 <            joinPool(e);
929 >        try (PoolCleaner cleaner = cleaner(e)) {
930 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
931 >            l.add(new NPETask());
932 >            List<Future<String>> futures
933 >                = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
934 >            assertEquals(1, futures.size());
935 >            try {
936 >                futures.get(0).get();
937 >                shouldThrow();
938 >            } catch (ExecutionException success) {
939 >                assertTrue(success.getCause() instanceof NullPointerException);
940 >            }
941          }
942      }
943  
# Line 981 | Line 945 | public class ForkJoinPoolTest extends JS
945       * timed invokeAll(c) returns results of all completed tasks in c
946       */
947      public void testTimedInvokeAll5() throws Throwable {
948 <        try (PoolCloser<ForkJoinPool> poolCloser
949 <             = new PoolCloser(new ForkJoinPool(1))) {
986 <            ForkJoinPool e = poolCloser.pool;
948 >        ForkJoinPool e = new ForkJoinPool(1);
949 >        try (PoolCleaner cleaner = cleaner(e)) {
950              List<Callable<String>> l = new ArrayList<Callable<String>>();
951              l.add(new StringTask());
952              l.add(new StringTask());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines