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.2 by jsr166, Fri Jul 31 23:37:31 2009 UTC vs.
Revision 1.18 by dl, Mon Feb 22 11:25:16 2010 UTC

# Line 8 | Line 8
8   import junit.framework.*;
9   import java.util.*;
10   import java.util.concurrent.*;
11 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
12   import java.util.concurrent.locks.*;
13   import java.security.*;
14  
15 < public class ForkJoinPoolTest extends JSR166TestCase{
15 > public class ForkJoinPoolTest extends JSR166TestCase {
16      public static void main(String[] args) {
17          junit.textui.TestRunner.run (suite());
18      }
# Line 50 | Line 51 | public class ForkJoinPoolTest extends JS
51          protected void onStart() { throw new Error(); }
52      }
53  
54 <    static class FailingThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory {
54 >    static class FailingThreadFactory
55 >            implements ForkJoinPool.ForkJoinWorkerThreadFactory {
56          int calls = 0;
57          public ForkJoinWorkerThread newThread(ForkJoinPool p) {
58              if (++calls > 1) return null;
# Line 135 | Line 137 | public class ForkJoinPoolTest extends JS
137      }
138  
139      /**
140 <     * Succesfully constructed pool reports default factory,
140 >     * Successfully constructed pool reports default factory,
141       * parallelism and async mode policies, no active threads or
142       * tasks, and quiescent running state.
143       */
# Line 143 | Line 145 | public class ForkJoinPoolTest extends JS
145          ForkJoinPool p = null;
146          try {
147              p = new ForkJoinPool(1);
148 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
148 >            assertTrue(p.getFactory() ==
149 >                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
150              assertTrue(p.isQuiescent());
151              assertTrue(p.getMaintainsParallelism());
152              assertFalse(p.getAsyncMode());
# Line 167 | Line 170 | public class ForkJoinPoolTest extends JS
170          try {
171              new ForkJoinPool(-1);
172              shouldThrow();
173 <        }
171 <        catch (IllegalArgumentException success) {}
173 >        } catch (IllegalArgumentException success) {}
174      }
175  
176      /**
# Line 178 | Line 180 | public class ForkJoinPoolTest extends JS
180          try {
181              new ForkJoinPool(1, null);
182              shouldThrow();
183 <        }
182 <        catch (NullPointerException success) {}
183 >        } catch (NullPointerException success) {}
184      }
185  
186  
# Line 234 | Line 235 | public class ForkJoinPoolTest extends JS
235          ForkJoinPool p = null;
236          try {
237              p = new ForkJoinPool(1);
238 <            assertTrue(p.getPoolSize() == 0);
238 >            assertTrue(p.getActiveThreadCount() == 0);
239              Future<String> future = p.submit(new StringTask());
240              assertTrue(p.getPoolSize() == 1);
241  
# Line 308 | Line 309 | public class ForkJoinPoolTest extends JS
309       * Additionally tests: Overriding ForkJoinWorkerThread.onStart
310       * performs its defined action
311       */
312 <    public void testSetUncaughtExceptionHandler() {
312 >    public void testSetUncaughtExceptionHandler() throws InterruptedException {
313          ForkJoinPool p = null;
314          try {
315              p = new ForkJoinPool(1, new FailingThreadFactory());
# Line 318 | Line 319 | public class ForkJoinPoolTest extends JS
319              p.execute(new FailingTask());
320              Thread.sleep(MEDIUM_DELAY_MS);
321              assertTrue(eh.catches > 0);
321        } catch (InterruptedException e) {
322            unexpectedException();
322          } finally {
323              joinPool(p);
324          }
# Line 345 | Line 344 | public class ForkJoinPoolTest extends JS
344       * queues are empty, threads are not active, and
345       * construction parameters continue to hold
346       */
347 <    public void testisQuiescent() {
347 >    public void testisQuiescent() throws InterruptedException {
348          ForkJoinPool p = null;
349          try {
350              p = new ForkJoinPool(2);
351              p.invoke(new FibTask(20));
352 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
352 >            assertTrue(p.getFactory() ==
353 >                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
354              Thread.sleep(MEDIUM_DELAY_MS);
355              assertTrue(p.isQuiescent());
356              assertTrue(p.getMaintainsParallelism());
# Line 362 | Line 362 | public class ForkJoinPoolTest extends JS
362              assertFalse(p.isShutdown());
363              assertFalse(p.isTerminating());
364              assertFalse(p.isTerminated());
365        } catch (InterruptedException e) {
366            unexpectedException();
365          } finally {
366              joinPool(p);
367          }
# Line 372 | Line 370 | public class ForkJoinPoolTest extends JS
370      /**
371       * Completed submit(ForkJoinTask) returns result
372       */
373 <    public void testSubmitForkJoinTask() {
373 >    public void testSubmitForkJoinTask() throws Throwable {
374          ForkJoinPool p = null;
375          try {
376              p = new ForkJoinPool(1);
377              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
378              int r = f.get();
379              assertTrue(r == 21);
382        } catch (ExecutionException ex) {
383            unexpectedException();
384        } catch (InterruptedException ex) {
385            unexpectedException();
380          } finally {
381              joinPool(p);
382          }
# Line 408 | Line 402 | public class ForkJoinPoolTest extends JS
402      /**
403       * Pool maintains parallelism when using ManagedBlocker
404       */
405 <    public void testBlockingForkJoinTask() {
405 >    public void testBlockingForkJoinTask() throws Throwable {
406          ForkJoinPool p = null;
407          try {
408              p = new ForkJoinPool(4);
# Line 418 | Line 412 | public class ForkJoinPoolTest extends JS
412              p.execute(f);
413              assertTrue(p.getPoolSize() >= 4);
414              int r = f.get();
415 <            assertTrue(r ==  832040);
422 <        } catch (ExecutionException ex) {
423 <            unexpectedException();
424 <        } catch (InterruptedException ex) {
425 <            unexpectedException();
415 >            assertTrue(r == 832040);
416          } finally {
417 <            joinPool(p);
417 >            p.shutdownNow(); // don't wait out shutdown
418          }
419      }
420  
# Line 474 | Line 464 | public class ForkJoinPoolTest extends JS
464      /**
465       * execute(runnable) runs it to completion
466       */
467 <    public void testExecuteRunnable() {
468 <        try {
469 <            ExecutorService e = new ForkJoinPool(1);
470 <            TrackedShortRunnable task = new TrackedShortRunnable();
471 <            assertFalse(task.done);
472 <            Future<?> future = e.submit(task);
473 <            future.get();
484 <            assertTrue(task.done);
485 <        }
486 <        catch (ExecutionException ex) {
487 <            unexpectedException();
488 <        }
489 <        catch (InterruptedException ex) {
490 <            unexpectedException();
491 <        }
467 >    public void testExecuteRunnable() throws Throwable {
468 >        ExecutorService e = new ForkJoinPool(1);
469 >        TrackedShortRunnable task = new TrackedShortRunnable();
470 >        assertFalse(task.done);
471 >        Future<?> future = e.submit(task);
472 >        future.get();
473 >        assertTrue(task.done);
474      }
475  
476  
477      /**
478       * Completed submit(callable) returns result
479       */
480 <    public void testSubmitCallable() {
481 <        try {
482 <            ExecutorService e = new ForkJoinPool(1);
483 <            Future<String> future = e.submit(new StringTask());
484 <            String result = future.get();
503 <            assertSame(TEST_STRING, result);
504 <        }
505 <        catch (ExecutionException ex) {
506 <            unexpectedException();
507 <        }
508 <        catch (InterruptedException ex) {
509 <            unexpectedException();
510 <        }
480 >    public void testSubmitCallable() throws Throwable {
481 >        ExecutorService e = new ForkJoinPool(1);
482 >        Future<String> future = e.submit(new StringTask());
483 >        String result = future.get();
484 >        assertSame(TEST_STRING, result);
485      }
486  
487      /**
488       * Completed submit(runnable) returns successfully
489       */
490 <    public void testSubmitRunnable() {
491 <        try {
492 <            ExecutorService e = new ForkJoinPool(1);
493 <            Future<?> future = e.submit(new NoOpRunnable());
494 <            future.get();
521 <            assertTrue(future.isDone());
522 <        }
523 <        catch (ExecutionException ex) {
524 <            unexpectedException();
525 <        }
526 <        catch (InterruptedException ex) {
527 <            unexpectedException();
528 <        }
490 >    public void testSubmitRunnable() throws Throwable {
491 >        ExecutorService e = new ForkJoinPool(1);
492 >        Future<?> future = e.submit(new NoOpRunnable());
493 >        future.get();
494 >        assertTrue(future.isDone());
495      }
496  
497      /**
498       * Completed submit(runnable, result) returns result
499       */
500 <    public void testSubmitRunnable2() {
501 <        try {
502 <            ExecutorService e = new ForkJoinPool(1);
503 <            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
504 <            String result = future.get();
539 <            assertSame(TEST_STRING, result);
540 <        }
541 <        catch (ExecutionException ex) {
542 <            unexpectedException();
543 <        }
544 <        catch (InterruptedException ex) {
545 <            unexpectedException();
546 <        }
500 >    public void testSubmitRunnable2() throws Throwable {
501 >        ExecutorService e = new ForkJoinPool(1);
502 >        Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
503 >        String result = future.get();
504 >        assertSame(TEST_STRING, result);
505      }
506  
549
507      /**
508 <     * A submitted privileged action to completion
508 >     * A submitted privileged action runs to completion
509       */
510 <    public void testSubmitPrivilegedAction() {
511 <        Policy savedPolicy = null;
512 <        try {
513 <            savedPolicy = Policy.getPolicy();
514 <            AdjustablePolicy policy = new AdjustablePolicy();
558 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
559 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
560 <            Policy.setPolicy(policy);
561 <        } catch (AccessControlException ok) {
562 <            return;
563 <        }
564 <        try {
565 <            ExecutorService e = new ForkJoinPool(1);
566 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
510 >    public void testSubmitPrivilegedAction() throws Throwable {
511 >        Runnable r = new CheckedRunnable() {
512 >            public void realRun() throws Exception {
513 >                ExecutorService e = new ForkJoinPool(1);
514 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
515                      public Object run() {
516                          return TEST_STRING;
517                      }}));
518  
519 <            Object result = future.get();
520 <            assertSame(TEST_STRING, result);
521 <        }
522 <        catch (ExecutionException ex) {
523 <            unexpectedException();
576 <        }
577 <        catch (InterruptedException ex) {
578 <            unexpectedException();
579 <        }
580 <        finally {
581 <            try {
582 <                Policy.setPolicy(savedPolicy);
583 <            } catch (AccessControlException ok) {
584 <                return;
585 <            }
586 <        }
519 >                Object result = future.get();
520 >                assertSame(TEST_STRING, result);
521 >            }};
522 >
523 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
524      }
525  
526      /**
527 <     * A submitted a privileged exception action runs to completion
527 >     * A submitted privileged exception action runs to completion
528       */
529 <    public void testSubmitPrivilegedExceptionAction() {
530 <        Policy savedPolicy = null;
531 <        try {
532 <            savedPolicy = Policy.getPolicy();
533 <            AdjustablePolicy policy = new AdjustablePolicy();
597 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
598 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
599 <            Policy.setPolicy(policy);
600 <        } catch (AccessControlException ok) {
601 <            return;
602 <        }
603 <
604 <        try {
605 <            ExecutorService e = new ForkJoinPool(1);
606 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
529 >    public void testSubmitPrivilegedExceptionAction() throws Throwable {
530 >        Runnable r = new CheckedRunnable() {
531 >            public void realRun() throws Exception {
532 >                ExecutorService e = new ForkJoinPool(1);
533 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
534                      public Object run() {
535                          return TEST_STRING;
536                      }}));
537  
538 <            Object result = future.get();
539 <            assertSame(TEST_STRING, result);
540 <        }
541 <        catch (ExecutionException ex) {
542 <            unexpectedException();
616 <        }
617 <        catch (InterruptedException ex) {
618 <            unexpectedException();
619 <        }
620 <        finally {
621 <            Policy.setPolicy(savedPolicy);
622 <        }
538 >                Object result = future.get();
539 >                assertSame(TEST_STRING, result);
540 >            }};
541 >
542 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
543      }
544  
545      /**
546       * A submitted failed privileged exception action reports exception
547       */
548 <    public void testSubmitFailedPrivilegedExceptionAction() {
549 <        Policy savedPolicy = null;
550 <        try {
551 <            savedPolicy = Policy.getPolicy();
552 <            AdjustablePolicy policy = new AdjustablePolicy();
633 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
634 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
635 <            Policy.setPolicy(policy);
636 <        } catch (AccessControlException ok) {
637 <            return;
638 <        }
639 <
640 <
641 <        try {
642 <            ExecutorService e = new ForkJoinPool(1);
643 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
548 >    public void testSubmitFailedPrivilegedExceptionAction() throws Throwable {
549 >        Runnable r = new CheckedRunnable() {
550 >            public void realRun() throws Exception {
551 >                ExecutorService e = new ForkJoinPool(1);
552 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
553                      public Object run() throws Exception {
554                          throw new IndexOutOfBoundsException();
555                      }}));
556  
557 <            Object result = future.get();
558 <            shouldThrow();
559 <        }
560 <        catch (ExecutionException success) {
561 <        } catch (CancellationException success) {
562 <        } catch (InterruptedException ex) {
563 <            unexpectedException();
564 <        }
656 <        finally {
657 <            Policy.setPolicy(savedPolicy);
658 <        }
557 >                try {
558 >                    Object result = future.get();
559 >                    shouldThrow();
560 >                } catch (ExecutionException success) {
561 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
562 >                }}};
563 >
564 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
565      }
566  
567      /**
568 <     * execute(null runnable) throws NPE
568 >     * execute(null runnable) throws NullPointerException
569       */
570      public void testExecuteNullRunnable() {
571          try {
# Line 667 | Line 573 | public class ForkJoinPoolTest extends JS
573              TrackedShortRunnable task = null;
574              Future<?> future = e.submit(task);
575              shouldThrow();
576 <        }
671 <        catch (NullPointerException success) {
672 <        }
673 <        catch (Exception ex) {
674 <            unexpectedException();
675 <        }
576 >        } catch (NullPointerException success) {}
577      }
578  
579  
580      /**
581 <     * submit(null callable) throws NPE
581 >     * submit(null callable) throws NullPointerException
582       */
583      public void testSubmitNullCallable() {
584          try {
# Line 685 | Line 586 | public class ForkJoinPoolTest extends JS
586              StringTask t = null;
587              Future<String> future = e.submit(t);
588              shouldThrow();
589 <        }
689 <        catch (NullPointerException success) {
690 <        }
691 <        catch (Exception ex) {
692 <            unexpectedException();
693 <        }
589 >        } catch (NullPointerException success) {}
590      }
591  
592  
593      /**
594 <     *  Blocking on submit(callable) throws InterruptedException if
595 <     *  caller interrupted.
594 >     * Blocking on submit(callable) throws InterruptedException if
595 >     * caller interrupted.
596       */
597 <    public void testInterruptedSubmit() {
597 >    public void testInterruptedSubmit() throws InterruptedException {
598          final ForkJoinPool p = new ForkJoinPool(1);
599 <        Thread t = new Thread(new Runnable() {
600 <                public void run() {
601 <                    try {
602 <                        p.submit(new Callable<Object>() {
603 <                                public Object call() {
604 <                                    try {
605 <                                        Thread.sleep(MEDIUM_DELAY_MS);
606 <                                        shouldThrow();
607 <                                    } catch (InterruptedException e) {
608 <                                    }
609 <                                    return null;
610 <                                }
611 <                            }).get();
612 <                    } catch (InterruptedException success) {
613 <                    } catch (Exception e) {
614 <                        unexpectedException();
615 <                    }
616 <
721 <                }
722 <            });
723 <        try {
724 <            t.start();
725 <            Thread.sleep(SHORT_DELAY_MS);
726 <            t.interrupt();
727 <        } catch (Exception e) {
728 <            unexpectedException();
729 <        }
599 >
600 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
601 >            public void realRun() throws Throwable {
602 >                p.submit(new CheckedCallable<Object>() {
603 >                    public Object realCall() throws Throwable {
604 >                        try {
605 >                            Thread.sleep(MEDIUM_DELAY_MS);
606 >                        } catch (InterruptedException ok) {
607 >                        }
608 >                        return null;
609 >                    }}).get();
610 >            }});
611 >
612 >        t.start();
613 >        Thread.sleep(SHORT_DELAY_MS);
614 >        t.interrupt();
615 >        t.join();
616 >        p.shutdownNow();
617          joinPool(p);
618      }
619  
620      /**
621 <     *  get of submit(callable) throws ExecutionException if callable
622 <     *  throws exception
621 >     * get of submit(callable) throws ExecutionException if callable
622 >     * throws exception
623       */
624 <    public void testSubmitEE() {
624 >    public void testSubmitEE() throws Throwable {
625          ForkJoinPool p = new ForkJoinPool(1);
739
626          try {
627 <            Callable c = new Callable() {
628 <                    public Object call() {
629 <                        int i = 5/0;
630 <                        return Boolean.TRUE;
631 <                    }
746 <                };
747 <
748 <            for (int i = 0; i < 5; i++) {
749 <                p.submit(c).get();
750 <            }
751 <
627 >            p.submit(new Callable() {
628 >                public Object call() {
629 >                    int i = 5/0;
630 >                    return Boolean.TRUE;
631 >                }}).get();
632              shouldThrow();
633          } catch (ExecutionException success) {
634 <        } catch (CancellationException success) {
755 <        } catch (Exception e) {
756 <            unexpectedException();
634 >            assertTrue(success.getCause() instanceof ArithmeticException);
635          }
636 +
637          joinPool(p);
638      }
639  
640      /**
641 <     * invokeAny(null) throws NPE
641 >     * invokeAny(null) throws NullPointerException
642       */
643 <    public void testInvokeAny1() {
643 >    public void testInvokeAny1() throws Throwable {
644          ExecutorService e = new ForkJoinPool(1);
645          try {
646              e.invokeAny(null);
647 +            shouldThrow();
648          } catch (NullPointerException success) {
769        } catch (Exception ex) {
770            unexpectedException();
649          } finally {
650              joinPool(e);
651          }
652      }
653  
654      /**
655 <     * invokeAny(empty collection) throws IAE
655 >     * invokeAny(empty collection) throws IllegalArgumentException
656       */
657 <    public void testInvokeAny2() {
657 >    public void testInvokeAny2() throws Throwable {
658          ExecutorService e = new ForkJoinPool(1);
659          try {
660              e.invokeAny(new ArrayList<Callable<String>>());
661 +            shouldThrow();
662          } catch (IllegalArgumentException success) {
784        } catch (Exception ex) {
785            unexpectedException();
663          } finally {
664              joinPool(e);
665          }
666      }
667  
668      /**
669 <     * invokeAny(c) throws NPE if c has null elements
669 >     * invokeAny(c) throws NullPointerException if c has a single null element
670       */
671 <    public void testInvokeAny3() {
671 >    public void testInvokeAny3() throws Throwable {
672          ExecutorService e = new ForkJoinPool(1);
673 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
674 +        l.add(null);
675 +        try {
676 +            e.invokeAny(l);
677 +            shouldThrow();
678 +        } catch (NullPointerException success) {
679 +        } finally {
680 +            joinPool(e);
681 +        }
682 +    }
683 +
684 +    /**
685 +     * invokeAny(c) throws NullPointerException if c has null elements
686 +     */
687 +    public void testInvokeAny4() throws Throwable {
688 +        CountDownLatch latch = new CountDownLatch(1);
689 +        ExecutorService e = new ForkJoinPool(1);
690 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
691 +        l.add(latchAwaitingStringTask(latch));
692 +        l.add(null);
693          try {
797            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
798            l.add(new StringTask());
799            l.add(null);
694              e.invokeAny(l);
695 +            shouldThrow();
696          } catch (NullPointerException success) {
802        } catch (Exception ex) {
803            ex.printStackTrace();
804            unexpectedException();
697          } finally {
698 +            latch.countDown();
699              joinPool(e);
700          }
701      }
# Line 810 | Line 703 | public class ForkJoinPoolTest extends JS
703      /**
704       * invokeAny(c) throws ExecutionException if no task in c completes
705       */
706 <    public void testInvokeAny4() {
706 >    public void testInvokeAny5() throws Throwable {
707          ExecutorService e = new ForkJoinPool(1);
708 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
709 +        l.add(new NPETask());
710          try {
816            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
817            l.add(new NPETask());
711              e.invokeAny(l);
712 +            shouldThrow();
713          } catch (ExecutionException success) {
714 <        } catch (CancellationException success) {
821 <        } catch (Exception ex) {
822 <            unexpectedException();
714 >            assertTrue(success.getCause() instanceof NullPointerException);
715          } finally {
716              joinPool(e);
717          }
# Line 828 | Line 720 | public class ForkJoinPoolTest extends JS
720      /**
721       * invokeAny(c) returns result of some task in c if at least one completes
722       */
723 <    public void testInvokeAny5() {
723 >    public void testInvokeAny6() throws Throwable {
724          ExecutorService e = new ForkJoinPool(1);
725          try {
726 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
726 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
727              l.add(new StringTask());
728              l.add(new StringTask());
729              String result = e.invokeAny(l);
730              assertSame(TEST_STRING, result);
839        } catch (ExecutionException success) {
840        } catch (CancellationException success) {
841        } catch (Exception ex) {
842            unexpectedException();
731          } finally {
732              joinPool(e);
733          }
734      }
735  
736      /**
737 <     * invokeAll(null) throws NPE
737 >     * invokeAll(null) throws NullPointerException
738       */
739 <    public void testInvokeAll1() {
739 >    public void testInvokeAll1() throws Throwable {
740          ExecutorService e = new ForkJoinPool(1);
741          try {
742              e.invokeAll(null);
743 +            shouldThrow();
744          } catch (NullPointerException success) {
856        } catch (Exception ex) {
857            unexpectedException();
745          } finally {
746              joinPool(e);
747          }
# Line 863 | Line 750 | public class ForkJoinPoolTest extends JS
750      /**
751       * invokeAll(empty collection) returns empty collection
752       */
753 <    public void testInvokeAll2() {
753 >    public void testInvokeAll2() throws InterruptedException {
754          ExecutorService e = new ForkJoinPool(1);
755          try {
756 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
756 >            List<Future<String>> r
757 >                = e.invokeAll(new ArrayList<Callable<String>>());
758              assertTrue(r.isEmpty());
871        } catch (Exception ex) {
872            unexpectedException();
759          } finally {
760              joinPool(e);
761          }
762      }
763  
764      /**
765 <     * invokeAll(c) throws NPE if c has null elements
765 >     * invokeAll(c) throws NullPointerException if c has null elements
766       */
767 <    public void testInvokeAll3() {
767 >    public void testInvokeAll3() throws InterruptedException {
768          ExecutorService e = new ForkJoinPool(1);
769 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
770 +        l.add(new StringTask());
771 +        l.add(null);
772          try {
884            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
885            l.add(new StringTask());
886            l.add(null);
773              e.invokeAll(l);
774 +            shouldThrow();
775          } catch (NullPointerException success) {
889        } catch (Exception ex) {
890            unexpectedException();
776          } finally {
777              joinPool(e);
778          }
779      }
780  
781      /**
782 <     * get of returned element of invokeAll(c) throws exception on failed task
782 >     * get of returned element of invokeAll(c) throws
783 >     * ExecutionException on failed task
784       */
785 <    public void testInvokeAll4() {
785 >    public void testInvokeAll4() throws Throwable {
786          ExecutorService e = new ForkJoinPool(1);
787 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
788 +        l.add(new NPETask());
789 +        List<Future<String>> futures = e.invokeAll(l);
790 +        assertEquals(1, futures.size());
791          try {
792 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
793 <            l.add(new NPETask());
904 <            List<Future<String>> result = e.invokeAll(l);
905 <            assertEquals(1, result.size());
906 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
907 <                it.next().get();
792 >            futures.get(0).get();
793 >            shouldThrow();
794          } catch (ExecutionException success) {
795 <        } catch (CancellationException success) {
910 <        } catch (Exception ex) {
911 <            ex.printStackTrace();
912 <            unexpectedException();
795 >            assertTrue(success.getCause() instanceof NullPointerException);
796          } finally {
797              joinPool(e);
798          }
# Line 918 | Line 801 | public class ForkJoinPoolTest extends JS
801      /**
802       * invokeAll(c) returns results of all completed tasks in c
803       */
804 <    public void testInvokeAll5() {
804 >    public void testInvokeAll5() throws Throwable {
805          ExecutorService e = new ForkJoinPool(1);
806          try {
807 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
807 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
808              l.add(new StringTask());
809              l.add(new StringTask());
810 <            List<Future<String>> result = e.invokeAll(l);
811 <            assertEquals(2, result.size());
812 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
813 <                assertSame(TEST_STRING, it.next().get());
931 <        } catch (ExecutionException success) {
932 <        } catch (CancellationException success) {
933 <        } catch (Exception ex) {
934 <            ex.printStackTrace();
935 <            unexpectedException();
810 >            List<Future<String>> futures = e.invokeAll(l);
811 >            assertEquals(2, futures.size());
812 >            for (Future<String> future : futures)
813 >                assertSame(TEST_STRING, future.get());
814          } finally {
815              joinPool(e);
816          }
# Line 940 | Line 818 | public class ForkJoinPoolTest extends JS
818  
819  
820      /**
821 <     * timed invokeAny(null) throws NPE
821 >     * timed invokeAny(null) throws NullPointerException
822       */
823 <    public void testTimedInvokeAny1() {
823 >    public void testTimedInvokeAny1() throws Throwable {
824          ExecutorService e = new ForkJoinPool(1);
825          try {
826 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
826 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
827 >            shouldThrow();
828          } catch (NullPointerException success) {
950        } catch (Exception ex) {
951            ex.printStackTrace();
952            unexpectedException();
829          } finally {
830              joinPool(e);
831          }
832      }
833  
834      /**
835 <     * timed invokeAny(null time unit) throws NPE
835 >     * timed invokeAny(null time unit) throws NullPointerException
836       */
837 <    public void testTimedInvokeAnyNullTimeUnit() {
837 >    public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
838          ExecutorService e = new ForkJoinPool(1);
839 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
840 +        l.add(new StringTask());
841          try {
964            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
965            l.add(new StringTask());
842              e.invokeAny(l, MEDIUM_DELAY_MS, null);
843 +            shouldThrow();
844          } catch (NullPointerException success) {
968        } catch (Exception ex) {
969            ex.printStackTrace();
970            unexpectedException();
845          } finally {
846              joinPool(e);
847          }
848      }
849  
850      /**
851 <     * timed invokeAny(empty collection) throws IAE
851 >     * timed invokeAny(empty collection) throws IllegalArgumentException
852       */
853 <    public void testTimedInvokeAny2() {
853 >    public void testTimedInvokeAny2() throws Throwable {
854          ExecutorService e = new ForkJoinPool(1);
855          try {
856 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
856 >            e.invokeAny(new ArrayList<Callable<String>>(),
857 >                        MEDIUM_DELAY_MS, MILLISECONDS);
858 >            shouldThrow();
859          } catch (IllegalArgumentException success) {
984        } catch (Exception ex) {
985            ex.printStackTrace();
986            unexpectedException();
860          } finally {
861              joinPool(e);
862          }
863      }
864  
865      /**
866 <     * timed invokeAny(c) throws NPE if c has null elements
866 >     * timed invokeAny(c) throws NullPointerException if c has null elements
867       */
868 <    public void testTimedInvokeAny3() {
868 >    public void testTimedInvokeAny3() throws Throwable {
869 >        CountDownLatch latch = new CountDownLatch(1);
870          ExecutorService e = new ForkJoinPool(1);
871 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
872 +        l.add(latchAwaitingStringTask(latch));
873 +        l.add(null);
874          try {
875 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
876 <            l.add(new StringTask());
1000 <            l.add(null);
1001 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
875 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
876 >            shouldThrow();
877          } catch (NullPointerException success) {
1003        } catch (Exception ex) {
1004            ex.printStackTrace();
1005            unexpectedException();
878          } finally {
879 +            latch.countDown();
880              joinPool(e);
881          }
882      }
# Line 1011 | Line 884 | public class ForkJoinPoolTest extends JS
884      /**
885       * timed invokeAny(c) throws ExecutionException if no task completes
886       */
887 <    public void testTimedInvokeAny4() {
887 >    public void testTimedInvokeAny4() throws Throwable {
888          ExecutorService e = new ForkJoinPool(1);
889 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
890 +        l.add(new NPETask());
891          try {
892 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
893 <            l.add(new NPETask());
1019 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
892 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
893 >            shouldThrow();
894          } catch (ExecutionException success) {
895 <        } catch (CancellationException success) {
1022 <        } catch (Exception ex) {
1023 <            ex.printStackTrace();
1024 <            unexpectedException();
895 >            assertTrue(success.getCause() instanceof NullPointerException);
896          } finally {
897              joinPool(e);
898          }
# Line 1030 | Line 901 | public class ForkJoinPoolTest extends JS
901      /**
902       * timed invokeAny(c) returns result of some task in c
903       */
904 <    public void testTimedInvokeAny5() {
904 >    public void testTimedInvokeAny5() throws Throwable {
905          ExecutorService e = new ForkJoinPool(1);
906          try {
907 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
907 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
908              l.add(new StringTask());
909              l.add(new StringTask());
910 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
910 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
911              assertSame(TEST_STRING, result);
1041        } catch (ExecutionException success) {
1042        } catch (CancellationException success) {
1043        } catch (Exception ex) {
1044            ex.printStackTrace();
1045            unexpectedException();
912          } finally {
913              joinPool(e);
914          }
915      }
916  
917      /**
918 <     * timed invokeAll(null) throws NPE
918 >     * timed invokeAll(null) throws NullPointerException
919       */
920 <    public void testTimedInvokeAll1() {
920 >    public void testTimedInvokeAll1() throws Throwable {
921          ExecutorService e = new ForkJoinPool(1);
922          try {
923 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
923 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
924 >            shouldThrow();
925          } catch (NullPointerException success) {
1059        } catch (Exception ex) {
1060            ex.printStackTrace();
1061            unexpectedException();
926          } finally {
927              joinPool(e);
928          }
929      }
930  
931      /**
932 <     * timed invokeAll(null time unit) throws NPE
932 >     * timed invokeAll(null time unit) throws NullPointerException
933       */
934 <    public void testTimedInvokeAllNullTimeUnit() {
934 >    public void testTimedInvokeAllNullTimeUnit() throws Throwable {
935          ExecutorService e = new ForkJoinPool(1);
936 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
937 +        l.add(new StringTask());
938          try {
1073            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1074            l.add(new StringTask());
939              e.invokeAll(l, MEDIUM_DELAY_MS, null);
940 +            shouldThrow();
941          } catch (NullPointerException success) {
1077        } catch (Exception ex) {
1078            ex.printStackTrace();
1079            unexpectedException();
942          } finally {
943              joinPool(e);
944          }
# Line 1085 | Line 947 | public class ForkJoinPoolTest extends JS
947      /**
948       * timed invokeAll(empty collection) returns empty collection
949       */
950 <    public void testTimedInvokeAll2() {
950 >    public void testTimedInvokeAll2() throws InterruptedException {
951          ExecutorService e = new ForkJoinPool(1);
952          try {
953 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
953 >            List<Future<String>> r
954 >                = e.invokeAll(new ArrayList<Callable<String>>(),
955 >                              MEDIUM_DELAY_MS, MILLISECONDS);
956              assertTrue(r.isEmpty());
1093        } catch (Exception ex) {
1094            ex.printStackTrace();
1095            unexpectedException();
957          } finally {
958              joinPool(e);
959          }
960      }
961  
962      /**
963 <     * timed invokeAll(c) throws NPE if c has null elements
963 >     * timed invokeAll(c) throws NullPointerException if c has null elements
964       */
965 <    public void testTimedInvokeAll3() {
965 >    public void testTimedInvokeAll3() throws InterruptedException {
966          ExecutorService e = new ForkJoinPool(1);
967 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
968 +        l.add(new StringTask());
969 +        l.add(null);
970          try {
971 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
972 <            l.add(new StringTask());
1109 <            l.add(null);
1110 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
971 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
972 >            shouldThrow();
973          } catch (NullPointerException success) {
1112        } catch (Exception ex) {
1113            ex.printStackTrace();
1114            unexpectedException();
974          } finally {
975              joinPool(e);
976          }
# Line 1120 | Line 979 | public class ForkJoinPoolTest extends JS
979      /**
980       * get of returned element of invokeAll(c) throws exception on failed task
981       */
982 <    public void testTimedInvokeAll4() {
982 >    public void testTimedInvokeAll4() throws Throwable {
983          ExecutorService e = new ForkJoinPool(1);
984 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
985 +        l.add(new NPETask());
986 +        List<Future<String>> futures
987 +            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
988 +        assertEquals(1, futures.size());
989          try {
990 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
991 <            l.add(new NPETask());
1128 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1129 <            assertEquals(1, result.size());
1130 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1131 <                it.next().get();
990 >            futures.get(0).get();
991 >            shouldThrow();
992          } catch (ExecutionException success) {
993 <        } catch (CancellationException success) {
1134 <        } catch (Exception ex) {
1135 <            ex.printStackTrace();
1136 <            unexpectedException();
993 >            assertTrue(success.getCause() instanceof NullPointerException);
994          } finally {
995              joinPool(e);
996          }
# Line 1142 | Line 999 | public class ForkJoinPoolTest extends JS
999      /**
1000       * timed invokeAll(c) returns results of all completed tasks in c
1001       */
1002 <    public void testTimedInvokeAll5() {
1002 >    public void testTimedInvokeAll5() throws Throwable {
1003          ExecutorService e = new ForkJoinPool(1);
1004          try {
1005 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1005 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1006              l.add(new StringTask());
1007              l.add(new StringTask());
1008 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1009 <            assertEquals(2, result.size());
1010 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1011 <                assertSame(TEST_STRING, it.next().get());
1012 <        } catch (ExecutionException success) {
1156 <        } catch (CancellationException success) {
1157 <        } catch (Exception ex) {
1158 <            ex.printStackTrace();
1159 <            unexpectedException();
1008 >            List<Future<String>> futures
1009 >                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1010 >            assertEquals(2, futures.size());
1011 >            for (Future<String> future : futures)
1012 >                assertSame(TEST_STRING, future.get());
1013          } finally {
1014              joinPool(e);
1015          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines