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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines