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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines