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.61 by jsr166, Sun Oct 4 00:59:08 2015 UTC vs.
Revision 1.62 by jsr166, Sun Oct 4 07:42:07 2015 UTC

# Line 162 | Line 162 | public class ForkJoinPoolTest extends JS
162       */
163      public void testDefaultInitialState() {
164          ForkJoinPool p = new ForkJoinPool(1);
165 <        try {
165 >        try (PoolCleaner cleaner = cleaner(p)) {
166              assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
167                         p.getFactory());
168              assertFalse(p.getAsyncMode());
# Line 174 | Line 174 | public class ForkJoinPoolTest extends JS
174              assertFalse(p.isShutdown());
175              assertFalse(p.isTerminating());
176              assertFalse(p.isTerminated());
177        } finally {
178            joinPool(p);
177          }
178      }
179  
# Line 204 | Line 202 | public class ForkJoinPoolTest extends JS
202       */
203      public void testGetParallelism() {
204          ForkJoinPool p = new ForkJoinPool(1);
205 <        try {
205 >        try (PoolCleaner cleaner = cleaner(p)) {
206              assertEquals(1, p.getParallelism());
209        } finally {
210            joinPool(p);
207          }
208      }
209  
# Line 216 | Line 212 | public class ForkJoinPoolTest extends JS
212       */
213      public void testGetPoolSize() {
214          ForkJoinPool p = new ForkJoinPool(1);
215 <        try {
215 >        try (PoolCleaner cleaner = cleaner(p)) {
216              assertEquals(0, p.getActiveThreadCount());
217              Future<String> future = p.submit(new StringTask());
218              assertEquals(1, p.getPoolSize());
223        } finally {
224            joinPool(p);
219          }
220      }
221  
# Line 230 | Line 224 | public class ForkJoinPoolTest extends JS
224       */
225      public void testAwaitTermination_timesOut() throws InterruptedException {
226          ForkJoinPool p = new ForkJoinPool(1);
227 <        assertFalse(p.isTerminated());
228 <        assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
229 <        assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
230 <        assertFalse(p.awaitTermination(-1L, NANOSECONDS));
231 <        assertFalse(p.awaitTermination(-1L, MILLISECONDS));
232 <        assertFalse(p.awaitTermination(0L, NANOSECONDS));
233 <        assertFalse(p.awaitTermination(0L, MILLISECONDS));
234 <        long timeoutNanos = 999999L;
235 <        long startTime = System.nanoTime();
236 <        assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
237 <        assertTrue(System.nanoTime() - startTime >= timeoutNanos);
238 <        assertFalse(p.isTerminated());
239 <        startTime = System.nanoTime();
240 <        long timeoutMillis = timeoutMillis();
241 <        assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
242 <        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
243 <        assertFalse(p.isTerminated());
244 <        p.shutdown();
245 <        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
246 <        assertTrue(p.isTerminated());
227 >        try (PoolCleaner cleaner = cleaner(p)) {
228 >            assertFalse(p.isTerminated());
229 >            assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
230 >            assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
231 >            assertFalse(p.awaitTermination(-1L, NANOSECONDS));
232 >            assertFalse(p.awaitTermination(-1L, MILLISECONDS));
233 >            assertFalse(p.awaitTermination(0L, NANOSECONDS));
234 >            assertFalse(p.awaitTermination(0L, MILLISECONDS));
235 >            long timeoutNanos = 999999L;
236 >            long startTime = System.nanoTime();
237 >            assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
238 >            assertTrue(System.nanoTime() - startTime >= timeoutNanos);
239 >            assertFalse(p.isTerminated());
240 >            startTime = System.nanoTime();
241 >            long timeoutMillis = timeoutMillis();
242 >            assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
243 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
244 >            assertFalse(p.isTerminated());
245 >            p.shutdown();
246 >            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
247 >            assertTrue(p.isTerminated());
248 >        }
249      }
250  
251      /**
# Line 288 | Line 284 | public class ForkJoinPoolTest extends JS
284       */
285      public void testIsQuiescent() throws Exception {
286          ForkJoinPool p = new ForkJoinPool(2);
287 <        try {
287 >        try (PoolCleaner cleaner = cleaner(p)) {
288              assertTrue(p.isQuiescent());
289              long startTime = System.nanoTime();
290              FibTask f = new FibTask(20);
# Line 316 | Line 312 | public class ForkJoinPoolTest extends JS
312              assertFalse(p.isTerminated());
313              assertTrue(f.isDone());
314              assertEquals(6765, (int) f.get());
319        } finally {
320            joinPool(p);
315          }
316      }
317  
# Line 326 | Line 320 | public class ForkJoinPoolTest extends JS
320       */
321      public void testSubmitForkJoinTask() throws Throwable {
322          ForkJoinPool p = new ForkJoinPool(1);
323 <        try {
323 >        try (PoolCleaner cleaner = cleaner(p)) {
324              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
325              assertEquals(21, (int) f.get());
332        } finally {
333            joinPool(p);
326          }
327      }
328  
# Line 339 | Line 331 | public class ForkJoinPoolTest extends JS
331       */
332      public void testSubmitAfterShutdown() {
333          ForkJoinPool p = new ForkJoinPool(1);
334 <        try {
334 >        try (PoolCleaner cleaner = cleaner(p)) {
335              p.shutdown();
336              assertTrue(p.isShutdown());
337              try {
338                  ForkJoinTask<Integer> f = p.submit(new FibTask(8));
339                  shouldThrow();
340              } catch (RejectedExecutionException success) {}
349        } finally {
350            joinPool(p);
341          }
342      }
343  
# Line 373 | Line 363 | public class ForkJoinPoolTest extends JS
363      public void testPollSubmission() {
364          final CountDownLatch done = new CountDownLatch(1);
365          SubFJP p = new SubFJP();
366 <        try {
366 >        try (PoolCleaner cleaner = cleaner(p)) {
367              ForkJoinTask a = p.submit(awaiter(done));
368              ForkJoinTask b = p.submit(awaiter(done));
369              ForkJoinTask c = p.submit(awaiter(done));
370              ForkJoinTask r = p.pollSubmission();
371              assertTrue(r == a || r == b || r == c);
372              assertFalse(r.isDone());
383        } finally {
373              done.countDown();
385            joinPool(p);
374          }
375      }
376  
# Line 392 | Line 380 | public class ForkJoinPoolTest extends JS
380      public void testDrainTasksTo() {
381          final CountDownLatch done = new CountDownLatch(1);
382          SubFJP p = new SubFJP();
383 <        try {
383 >        try (PoolCleaner cleaner = cleaner(p)) {
384              ForkJoinTask a = p.submit(awaiter(done));
385              ForkJoinTask b = p.submit(awaiter(done));
386              ForkJoinTask c = p.submit(awaiter(done));
# Line 403 | Line 391 | public class ForkJoinPoolTest extends JS
391                  assertTrue(r == a || r == b || r == c);
392                  assertFalse(r.isDone());
393              }
406        } finally {
394              done.countDown();
408            joinPool(p);
395          }
396      }
397  
# Line 416 | Line 402 | public class ForkJoinPoolTest extends JS
402       */
403      public void testExecuteRunnable() throws Throwable {
404          ExecutorService e = new ForkJoinPool(1);
405 <        try {
405 >        try (PoolCleaner cleaner = cleaner(e)) {
406              final AtomicBoolean done = new AtomicBoolean(false);
407              Future<?> future = e.submit(new CheckedRunnable() {
408                  public void realRun() {
# Line 427 | Line 413 | public class ForkJoinPoolTest extends JS
413              assertTrue(done.get());
414              assertTrue(future.isDone());
415              assertFalse(future.isCancelled());
430        } finally {
431            joinPool(e);
416          }
417      }
418  
# Line 437 | Line 421 | public class ForkJoinPoolTest extends JS
421       */
422      public void testSubmitCallable() throws Throwable {
423          ExecutorService e = new ForkJoinPool(1);
424 <        try {
424 >        try (PoolCleaner cleaner = cleaner(e)) {
425              Future<String> future = e.submit(new StringTask());
426              assertSame(TEST_STRING, future.get());
427              assertTrue(future.isDone());
428              assertFalse(future.isCancelled());
445        } finally {
446            joinPool(e);
429          }
430      }
431  
# Line 452 | Line 434 | public class ForkJoinPoolTest extends JS
434       */
435      public void testSubmitRunnable() throws Throwable {
436          ExecutorService e = new ForkJoinPool(1);
437 <        try {
437 >        try (PoolCleaner cleaner = cleaner(e)) {
438              Future<?> future = e.submit(new NoOpRunnable());
439              assertNull(future.get());
440              assertTrue(future.isDone());
441              assertFalse(future.isCancelled());
460        } finally {
461            joinPool(e);
442          }
443      }
444  
# Line 467 | Line 447 | public class ForkJoinPoolTest extends JS
447       */
448      public void testSubmitRunnable2() throws Throwable {
449          ExecutorService e = new ForkJoinPool(1);
450 <        try {
450 >        try (PoolCleaner cleaner = cleaner(e)) {
451              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
452              assertSame(TEST_STRING, future.get());
453              assertTrue(future.isDone());
454              assertFalse(future.isCancelled());
475        } finally {
476            joinPool(e);
455          }
456      }
457  
# Line 486 | Line 464 | public class ForkJoinPoolTest extends JS
464          Runnable r = new CheckedRunnable() {
465          public void realRun() throws Exception {
466              ExecutorService e = new ForkJoinPool(1);
467 <            try {
467 >            try (PoolCleaner cleaner = cleaner(e)) {
468                  Future future = e.submit(callable);
469                  assertSame(TEST_STRING, future.get());
492            } finally {
493                joinPool(e);
470              }
471          }};
472  
# Line 507 | Line 483 | public class ForkJoinPoolTest extends JS
483          Runnable r = new CheckedRunnable() {
484          public void realRun() throws Exception {
485              ExecutorService e = new ForkJoinPool(1);
486 <            try {
486 >            try (PoolCleaner cleaner = cleaner(e)) {
487                  Future future = e.submit(callable);
488                  assertSame(TEST_STRING, future.get());
513            } finally {
514                joinPool(e);
489              }
490          }};
491  
# Line 528 | Line 502 | public class ForkJoinPoolTest extends JS
502          Runnable r = new CheckedRunnable() {
503          public void realRun() throws Exception {
504              ExecutorService e = new ForkJoinPool(1);
505 <            try {
505 >            try (PoolCleaner cleaner = cleaner(e)) {
506                  Future future = e.submit(callable);
507                  try {
508                      future.get();
# Line 536 | Line 510 | public class ForkJoinPoolTest extends JS
510                  } catch (ExecutionException success) {
511                      assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
512                  }
539            } finally {
540                joinPool(e);
513              }
514          }};
515  
# Line 549 | Line 521 | public class ForkJoinPoolTest extends JS
521       */
522      public void testExecuteNullRunnable() {
523          ExecutorService e = new ForkJoinPool(1);
524 <        try {
525 <            Future<?> future = e.submit((Runnable) null);
526 <            shouldThrow();
527 <        } catch (NullPointerException success) {
528 <        } finally {
557 <            joinPool(e);
524 >        try (PoolCleaner cleaner = cleaner(e)) {
525 >            try {
526 >                Future<?> future = e.submit((Runnable) null);
527 >                shouldThrow();
528 >            } catch (NullPointerException success) {}
529          }
530      }
531  
# Line 563 | Line 534 | public class ForkJoinPoolTest extends JS
534       */
535      public void testSubmitNullCallable() {
536          ExecutorService e = new ForkJoinPool(1);
537 <        try {
538 <            Future<String> future = e.submit((Callable) null);
539 <            shouldThrow();
540 <        } catch (NullPointerException success) {
541 <        } finally {
571 <            joinPool(e);
537 >        try (PoolCleaner cleaner = cleaner(e)) {
538 >            try {
539 >                Future<String> future = e.submit((Callable) null);
540 >                shouldThrow();
541 >            } catch (NullPointerException success) {}
542          }
543      }
544  
# Line 607 | Line 577 | public class ForkJoinPoolTest extends JS
577       */
578      public void testSubmitEE() throws Throwable {
579          ForkJoinPool p = new ForkJoinPool(1);
580 <        try {
581 <            p.submit(new Callable() {
582 <                public Object call() { throw new ArithmeticException(); }})
583 <                .get();
584 <            shouldThrow();
585 <        } catch (ExecutionException success) {
586 <            assertTrue(success.getCause() instanceof ArithmeticException);
587 <        } finally {
588 <            joinPool(p);
580 >        try (PoolCleaner cleaner = cleaner(p)) {
581 >            try {
582 >                p.submit(new Callable() {
583 >                        public Object call() { throw new ArithmeticException(); }})
584 >                    .get();
585 >                shouldThrow();
586 >            } catch (ExecutionException success) {
587 >                assertTrue(success.getCause() instanceof ArithmeticException);
588 >            }
589          }
590      }
591  
# Line 624 | Line 594 | public class ForkJoinPoolTest extends JS
594       */
595      public void testInvokeAny1() throws Throwable {
596          ExecutorService e = new ForkJoinPool(1);
597 <        try {
598 <            e.invokeAny(null);
599 <            shouldThrow();
600 <        } catch (NullPointerException success) {
601 <        } finally {
632 <            joinPool(e);
597 >        try (PoolCleaner cleaner = cleaner(e)) {
598 >            try {
599 >                e.invokeAny(null);
600 >                shouldThrow();
601 >            } catch (NullPointerException success) {}
602          }
603      }
604  
# Line 638 | Line 607 | public class ForkJoinPoolTest extends JS
607       */
608      public void testInvokeAny2() throws Throwable {
609          ExecutorService e = new ForkJoinPool(1);
610 <        try {
611 <            e.invokeAny(new ArrayList<Callable<String>>());
612 <            shouldThrow();
613 <        } catch (IllegalArgumentException success) {
614 <        } finally {
646 <            joinPool(e);
610 >        try (PoolCleaner cleaner = cleaner(e)) {
611 >            try {
612 >                e.invokeAny(new ArrayList<Callable<String>>());
613 >                shouldThrow();
614 >            } catch (IllegalArgumentException success) {}
615          }
616      }
617  
# Line 652 | Line 620 | public class ForkJoinPoolTest extends JS
620       */
621      public void testInvokeAny3() throws Throwable {
622          ExecutorService e = new ForkJoinPool(1);
623 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
624 <        l.add(null);
625 <        try {
626 <            e.invokeAny(l);
627 <            shouldThrow();
628 <        } catch (NullPointerException success) {
629 <        } finally {
662 <            joinPool(e);
623 >        try (PoolCleaner cleaner = cleaner(e)) {
624 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
625 >            l.add(null);
626 >            try {
627 >                e.invokeAny(l);
628 >                shouldThrow();
629 >            } catch (NullPointerException success) {}
630          }
631      }
632  
# Line 669 | Line 636 | public class ForkJoinPoolTest extends JS
636      public void testInvokeAny4() throws Throwable {
637          CountDownLatch latch = new CountDownLatch(1);
638          ExecutorService e = new ForkJoinPool(1);
639 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
640 <        l.add(latchAwaitingStringTask(latch));
641 <        l.add(null);
642 <        try {
643 <            e.invokeAny(l);
644 <            shouldThrow();
645 <        } catch (NullPointerException success) {
646 <        } finally {
639 >        try (PoolCleaner cleaner = cleaner(e)) {
640 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
641 >            l.add(latchAwaitingStringTask(latch));
642 >            l.add(null);
643 >            try {
644 >                e.invokeAny(l);
645 >                shouldThrow();
646 >            } catch (NullPointerException success) {}
647              latch.countDown();
681            joinPool(e);
648          }
649      }
650  
# Line 687 | Line 653 | public class ForkJoinPoolTest extends JS
653       */
654      public void testInvokeAny5() throws Throwable {
655          ExecutorService e = new ForkJoinPool(1);
656 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
657 <        l.add(new NPETask());
658 <        try {
659 <            e.invokeAny(l);
660 <            shouldThrow();
661 <        } catch (ExecutionException success) {
662 <            assertTrue(success.getCause() instanceof NullPointerException);
663 <        } finally {
664 <            joinPool(e);
656 >        try (PoolCleaner cleaner = cleaner(e)) {
657 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
658 >            l.add(new NPETask());
659 >            try {
660 >                e.invokeAny(l);
661 >                shouldThrow();
662 >            } catch (ExecutionException success) {
663 >                assertTrue(success.getCause() instanceof NullPointerException);
664 >            }
665          }
666      }
667  
# Line 704 | Line 670 | public class ForkJoinPoolTest extends JS
670       */
671      public void testInvokeAny6() throws Throwable {
672          ExecutorService e = new ForkJoinPool(1);
673 <        try {
673 >        try (PoolCleaner cleaner = cleaner(e)) {
674              List<Callable<String>> l = new ArrayList<Callable<String>>();
675              l.add(new StringTask());
676              l.add(new StringTask());
677              String result = e.invokeAny(l);
678              assertSame(TEST_STRING, result);
713        } finally {
714            joinPool(e);
679          }
680      }
681  
# Line 720 | Line 684 | public class ForkJoinPoolTest extends JS
684       */
685      public void testInvokeAll1() throws Throwable {
686          ExecutorService e = new ForkJoinPool(1);
687 <        try {
688 <            e.invokeAll(null);
689 <            shouldThrow();
690 <        } catch (NullPointerException success) {
691 <        } finally {
728 <            joinPool(e);
687 >        try (PoolCleaner cleaner = cleaner(e)) {
688 >            try {
689 >                e.invokeAll(null);
690 >                shouldThrow();
691 >            } catch (NullPointerException success) {}
692          }
693      }
694  
# Line 734 | Line 697 | public class ForkJoinPoolTest extends JS
697       */
698      public void testInvokeAll2() throws InterruptedException {
699          ExecutorService e = new ForkJoinPool(1);
700 <        try {
700 >        try (PoolCleaner cleaner = cleaner(e)) {
701              List<Future<String>> r
702                  = e.invokeAll(new ArrayList<Callable<String>>());
703              assertTrue(r.isEmpty());
741        } finally {
742            joinPool(e);
704          }
705      }
706  
# Line 748 | Line 709 | public class ForkJoinPoolTest extends JS
709       */
710      public void testInvokeAll3() throws InterruptedException {
711          ExecutorService e = new ForkJoinPool(1);
712 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
713 <        l.add(new StringTask());
714 <        l.add(null);
715 <        try {
716 <            e.invokeAll(l);
717 <            shouldThrow();
718 <        } catch (NullPointerException success) {
719 <        } finally {
759 <            joinPool(e);
712 >        try (PoolCleaner cleaner = cleaner(e)) {
713 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
714 >            l.add(new StringTask());
715 >            l.add(null);
716 >            try {
717 >                e.invokeAll(l);
718 >                shouldThrow();
719 >            } catch (NullPointerException success) {}
720          }
721      }
722  
# Line 766 | Line 726 | public class ForkJoinPoolTest extends JS
726       */
727      public void testInvokeAll4() throws Throwable {
728          ExecutorService e = new ForkJoinPool(1);
729 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
730 <        l.add(new NPETask());
731 <        List<Future<String>> futures = e.invokeAll(l);
732 <        assertEquals(1, futures.size());
733 <        try {
734 <            futures.get(0).get();
735 <            shouldThrow();
736 <        } catch (ExecutionException success) {
737 <            assertTrue(success.getCause() instanceof NullPointerException);
738 <        } finally {
739 <            joinPool(e);
729 >        try (PoolCleaner cleaner = cleaner(e)) {
730 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
731 >            l.add(new NPETask());
732 >            List<Future<String>> futures = e.invokeAll(l);
733 >            assertEquals(1, futures.size());
734 >            try {
735 >                futures.get(0).get();
736 >                shouldThrow();
737 >            } catch (ExecutionException success) {
738 >                assertTrue(success.getCause() instanceof NullPointerException);
739 >            }
740          }
741      }
742  
# Line 785 | Line 745 | public class ForkJoinPoolTest extends JS
745       */
746      public void testInvokeAll5() throws Throwable {
747          ExecutorService e = new ForkJoinPool(1);
748 <        try {
748 >        try (PoolCleaner cleaner = cleaner(e)) {
749              List<Callable<String>> l = new ArrayList<Callable<String>>();
750              l.add(new StringTask());
751              l.add(new StringTask());
# Line 793 | Line 753 | public class ForkJoinPoolTest extends JS
753              assertEquals(2, futures.size());
754              for (Future<String> future : futures)
755                  assertSame(TEST_STRING, future.get());
796        } finally {
797            joinPool(e);
756          }
757      }
758  
# Line 803 | Line 761 | public class ForkJoinPoolTest extends JS
761       */
762      public void testTimedInvokeAny1() throws Throwable {
763          ExecutorService e = new ForkJoinPool(1);
764 <        try {
765 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
766 <            shouldThrow();
767 <        } catch (NullPointerException success) {
768 <        } finally {
811 <            joinPool(e);
764 >        try (PoolCleaner cleaner = cleaner(e)) {
765 >            try {
766 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
767 >                shouldThrow();
768 >            } catch (NullPointerException success) {}
769          }
770      }
771  
# Line 817 | Line 774 | public class ForkJoinPoolTest extends JS
774       */
775      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
776          ExecutorService e = new ForkJoinPool(1);
777 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
778 <        l.add(new StringTask());
779 <        try {
780 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
781 <            shouldThrow();
782 <        } catch (NullPointerException success) {
783 <        } finally {
827 <            joinPool(e);
777 >        try (PoolCleaner cleaner = cleaner(e)) {
778 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
779 >            l.add(new StringTask());
780 >            try {
781 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
782 >                shouldThrow();
783 >            } catch (NullPointerException success) {}
784          }
785      }
786  
# Line 833 | Line 789 | public class ForkJoinPoolTest extends JS
789       */
790      public void testTimedInvokeAny2() throws Throwable {
791          ExecutorService e = new ForkJoinPool(1);
792 <        try {
793 <            e.invokeAny(new ArrayList<Callable<String>>(),
794 <                        MEDIUM_DELAY_MS, MILLISECONDS);
795 <            shouldThrow();
796 <        } catch (IllegalArgumentException success) {
797 <        } finally {
842 <            joinPool(e);
792 >        try (PoolCleaner cleaner = cleaner(e)) {
793 >            try {
794 >                e.invokeAny(new ArrayList<Callable<String>>(),
795 >                            MEDIUM_DELAY_MS, MILLISECONDS);
796 >                shouldThrow();
797 >            } catch (IllegalArgumentException success) {}
798          }
799      }
800  
# Line 849 | Line 804 | public class ForkJoinPoolTest extends JS
804      public void testTimedInvokeAny3() throws Throwable {
805          CountDownLatch latch = new CountDownLatch(1);
806          ExecutorService e = new ForkJoinPool(1);
807 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
808 <        l.add(latchAwaitingStringTask(latch));
809 <        l.add(null);
810 <        try {
811 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
812 <            shouldThrow();
813 <        } catch (NullPointerException success) {
814 <        } finally {
807 >        try (PoolCleaner cleaner = cleaner(e)) {
808 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
809 >            l.add(latchAwaitingStringTask(latch));
810 >            l.add(null);
811 >            try {
812 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
813 >                shouldThrow();
814 >            } catch (NullPointerException success) {}
815              latch.countDown();
861            joinPool(e);
816          }
817      }
818  
# Line 867 | Line 821 | public class ForkJoinPoolTest extends JS
821       */
822      public void testTimedInvokeAny4() throws Throwable {
823          ExecutorService e = new ForkJoinPool(1);
824 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
825 <        l.add(new NPETask());
826 <        try {
827 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
828 <            shouldThrow();
829 <        } catch (ExecutionException success) {
830 <            assertTrue(success.getCause() instanceof NullPointerException);
831 <        } finally {
832 <            joinPool(e);
824 >        try (PoolCleaner cleaner = cleaner(e)) {
825 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
826 >            l.add(new NPETask());
827 >            try {
828 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
829 >                shouldThrow();
830 >            } catch (ExecutionException success) {
831 >                assertTrue(success.getCause() instanceof NullPointerException);
832 >            }
833          }
834      }
835  
# Line 884 | Line 838 | public class ForkJoinPoolTest extends JS
838       */
839      public void testTimedInvokeAny5() throws Throwable {
840          ExecutorService e = new ForkJoinPool(1);
841 <        try {
841 >        try (PoolCleaner cleaner = cleaner(e)) {
842              List<Callable<String>> l = new ArrayList<Callable<String>>();
843              l.add(new StringTask());
844              l.add(new StringTask());
845              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
846              assertSame(TEST_STRING, result);
893        } finally {
894            joinPool(e);
847          }
848      }
849  
# Line 900 | Line 852 | public class ForkJoinPoolTest extends JS
852       */
853      public void testTimedInvokeAll1() throws Throwable {
854          ExecutorService e = new ForkJoinPool(1);
855 <        try {
856 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
857 <            shouldThrow();
858 <        } catch (NullPointerException success) {
859 <        } finally {
908 <            joinPool(e);
855 >        try (PoolCleaner cleaner = cleaner(e)) {
856 >            try {
857 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
858 >                shouldThrow();
859 >            } catch (NullPointerException success) {}
860          }
861      }
862  
# Line 914 | Line 865 | public class ForkJoinPoolTest extends JS
865       */
866      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
867          ExecutorService e = new ForkJoinPool(1);
868 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
869 <        l.add(new StringTask());
870 <        try {
871 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
872 <            shouldThrow();
873 <        } catch (NullPointerException success) {
874 <        } finally {
924 <            joinPool(e);
868 >        try (PoolCleaner cleaner = cleaner(e)) {
869 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
870 >            l.add(new StringTask());
871 >            try {
872 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
873 >                shouldThrow();
874 >            } catch (NullPointerException success) {}
875          }
876      }
877  
# Line 930 | Line 880 | public class ForkJoinPoolTest extends JS
880       */
881      public void testTimedInvokeAll2() throws InterruptedException {
882          ExecutorService e = new ForkJoinPool(1);
883 <        try {
883 >        try (PoolCleaner cleaner = cleaner(e)) {
884              List<Future<String>> r
885                  = e.invokeAll(new ArrayList<Callable<String>>(),
886                                MEDIUM_DELAY_MS, MILLISECONDS);
887              assertTrue(r.isEmpty());
938        } finally {
939            joinPool(e);
888          }
889      }
890  
# Line 945 | Line 893 | public class ForkJoinPoolTest extends JS
893       */
894      public void testTimedInvokeAll3() throws InterruptedException {
895          ExecutorService e = new ForkJoinPool(1);
896 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
897 <        l.add(new StringTask());
898 <        l.add(null);
899 <        try {
900 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
901 <            shouldThrow();
902 <        } catch (NullPointerException success) {
903 <        } finally {
956 <            joinPool(e);
896 >        try (PoolCleaner cleaner = cleaner(e)) {
897 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
898 >            l.add(new StringTask());
899 >            l.add(null);
900 >            try {
901 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
902 >                shouldThrow();
903 >            } catch (NullPointerException success) {}
904          }
905      }
906  
# Line 962 | Line 909 | public class ForkJoinPoolTest extends JS
909       */
910      public void testTimedInvokeAll4() throws Throwable {
911          ExecutorService e = new ForkJoinPool(1);
912 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
913 <        l.add(new NPETask());
914 <        List<Future<String>> futures
915 <            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
916 <        assertEquals(1, futures.size());
917 <        try {
918 <            futures.get(0).get();
919 <            shouldThrow();
920 <        } catch (ExecutionException success) {
921 <            assertTrue(success.getCause() instanceof NullPointerException);
922 <        } finally {
923 <            joinPool(e);
912 >        try (PoolCleaner cleaner = cleaner(e)) {
913 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
914 >            l.add(new NPETask());
915 >            List<Future<String>> futures
916 >                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
917 >            assertEquals(1, futures.size());
918 >            try {
919 >                futures.get(0).get();
920 >                shouldThrow();
921 >            } catch (ExecutionException success) {
922 >                assertTrue(success.getCause() instanceof NullPointerException);
923 >            }
924          }
925      }
926  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines