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

Comparing jsr166/src/test/tck/ForkJoinTask8Test.java (file contents):
Revision 1.9 by jsr166, Sat Feb 7 17:43:38 2015 UTC vs.
Revision 1.12 by jsr166, Sat Feb 7 22:32:48 2015 UTC

# Line 7 | Line 7
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8   import static java.util.concurrent.TimeUnit.SECONDS;
9  
10 < import java.util.HashSet;
10 > import java.util.Arrays;
11   import java.util.concurrent.ExecutionException;
12   import java.util.concurrent.ForkJoinPool;
13   import java.util.concurrent.ForkJoinTask;
# Line 59 | Line 59 | public class ForkJoinTask8Test extends J
59                                  null, true);
60      }
61  
62 +    // Compute fib naively and efficiently
63 +    final int[] fib;
64 +    {
65 +        int[] fib = new int[10];
66 +        fib[0] = 0;
67 +        fib[1] = 1;
68 +        for (int i = 2; i < fib.length; i++)
69 +            fib[i] = fib[i - 1] + fib[i - 2];
70 +        this.fib = fib;
71 +    }
72 +
73      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
74          try {
75              assertFalse(a.isDone());
# Line 279 | Line 290 | public class ForkJoinTask8Test extends J
290  
291      }
292  
293 <    static final class AsyncFib extends BinaryAsyncAction {
293 >    final class AsyncFib extends BinaryAsyncAction {
294          int number;
295 <        public AsyncFib(int n) {
296 <            this.number = n;
295 >        int expectedResult;
296 >        public AsyncFib(int number) {
297 >            this.number = number;
298 >            this.expectedResult = fib[number];
299          }
300  
301          public final boolean exec() {
# Line 311 | Line 324 | public class ForkJoinTask8Test extends J
324              number = ((AsyncFib)x).number + ((AsyncFib)y).number;
325              super.onComplete(x, y);
326          }
327 +
328 +        public void checkCompletedNormally() {
329 +            assertEquals(expectedResult, number);
330 +            ForkJoinTask8Test.this.checkCompletedNormally(this);
331 +        }
332      }
333  
334      static final class FailingAsyncFib extends BinaryAsyncAction {
# Line 347 | Line 365 | public class ForkJoinTask8Test extends J
365       * completed tasks; getRawResult returns null.
366       */
367      public void testInvoke() {
368 +        testInvoke(mainPool());
369 +    }
370 +    public void testInvoke_Singleton() {
371 +        testInvoke(singletonPool());
372 +    }
373 +    public void testInvoke(ForkJoinPool pool) {
374          RecursiveAction a = new CheckedRecursiveAction() {
375              protected void realCompute() {
376                  AsyncFib f = new AsyncFib(8);
377                  assertNull(f.invoke());
378 <                assertEquals(21, f.number);
355 <                checkCompletedNormally(f);
378 >                f.checkCompletedNormally();
379              }};
380 <        testInvokeOnPool(mainPool(), a);
380 >        testInvokeOnPool(pool, a);
381      }
382  
383      /**
# Line 363 | Line 386 | public class ForkJoinTask8Test extends J
386       * completed tasks
387       */
388      public void testQuietlyInvoke() {
389 +        testQuietlyInvoke(mainPool());
390 +    }
391 +    public void testQuietlyInvoke_Singleton() {
392 +        testQuietlyInvoke(singletonPool());
393 +    }
394 +    public void testQuietlyInvoke(ForkJoinPool pool) {
395          RecursiveAction a = new CheckedRecursiveAction() {
396              protected void realCompute() {
397                  AsyncFib f = new AsyncFib(8);
398                  f.quietlyInvoke();
399 <                assertEquals(21, f.number);
371 <                checkCompletedNormally(f);
399 >                f.checkCompletedNormally();
400              }};
401 <        testInvokeOnPool(mainPool(), a);
401 >        testInvokeOnPool(pool, a);
402      }
403  
404      /**
405       * join of a forked task returns when task completes
406       */
407      public void testForkJoin() {
408 +        testForkJoin(mainPool());
409 +    }
410 +    public void testForkJoin_Singleton() {
411 +        testForkJoin(singletonPool());
412 +    }
413 +    public void testForkJoin(ForkJoinPool pool) {
414          RecursiveAction a = new CheckedRecursiveAction() {
415              protected void realCompute() {
416                  AsyncFib f = new AsyncFib(8);
417                  assertSame(f, f.fork());
418                  assertNull(f.join());
419 <                assertEquals(21, f.number);
386 <                checkCompletedNormally(f);
419 >                f.checkCompletedNormally();
420              }};
421 <        testInvokeOnPool(mainPool(), a);
421 >        testInvokeOnPool(pool, a);
422      }
423  
424      /**
425       * get of a forked task returns when task completes
426       */
427      public void testForkGet() {
428 +        testForkGet(mainPool());
429 +    }
430 +    public void testForkGet_Singleton() {
431 +        testForkGet(singletonPool());
432 +    }
433 +    public void testForkGet(ForkJoinPool pool) {
434          RecursiveAction a = new CheckedRecursiveAction() {
435              protected void realCompute() throws Exception {
436                  AsyncFib f = new AsyncFib(8);
437                  assertSame(f, f.fork());
438                  assertNull(f.get());
439 <                assertEquals(21, f.number);
401 <                checkCompletedNormally(f);
439 >                f.checkCompletedNormally();
440              }};
441 <        testInvokeOnPool(mainPool(), a);
441 >        testInvokeOnPool(pool, a);
442      }
443  
444      /**
445       * timed get of a forked task returns when task completes
446       */
447      public void testForkTimedGet() {
448 +        testForkTimedGet(mainPool());
449 +    }
450 +    public void testForkTimedGet_Singleton() {
451 +        testForkTimedGet(singletonPool());
452 +    }
453 +    public void testForkTimedGet(ForkJoinPool pool) {
454          RecursiveAction a = new CheckedRecursiveAction() {
455              protected void realCompute() throws Exception {
456                  AsyncFib f = new AsyncFib(8);
457                  assertSame(f, f.fork());
458                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
459 <                assertEquals(21, f.number);
416 <                checkCompletedNormally(f);
459 >                f.checkCompletedNormally();
460              }};
461 <        testInvokeOnPool(mainPool(), a);
461 >        testInvokeOnPool(pool, a);
462      }
463  
464      /**
465 <     * timed get with null time unit throws NPE
465 >     * timed get with null time unit throws NullPointerException
466       */
467 <    public void testForkTimedGetNPE() {
467 >    public void testForkTimedGetNullTimeUnit() {
468 >        testForkTimedGetNullTimeUnit(mainPool());
469 >    }
470 >    public void testForkTimedGetNullTimeUnit_Singleton() {
471 >        testForkTimedGet(singletonPool());
472 >    }
473 >    public void testForkTimedGetNullTimeUnit(ForkJoinPool pool) {
474          RecursiveAction a = new CheckedRecursiveAction() {
475              protected void realCompute() throws Exception {
476                  AsyncFib f = new AsyncFib(8);
# Line 431 | Line 480 | public class ForkJoinTask8Test extends J
480                      shouldThrow();
481                  } catch (NullPointerException success) {}
482              }};
483 <        testInvokeOnPool(mainPool(), a);
483 >        testInvokeOnPool(pool, a);
484      }
485  
486      /**
487       * quietlyJoin of a forked task returns when task completes
488       */
489      public void testForkQuietlyJoin() {
490 +        testForkQuietlyJoin(mainPool());
491 +    }
492 +    public void testForkQuietlyJoin_Singleton() {
493 +        testForkQuietlyJoin(singletonPool());
494 +    }
495 +    public void testForkQuietlyJoin(ForkJoinPool pool) {
496          RecursiveAction a = new CheckedRecursiveAction() {
497              protected void realCompute() {
498                  AsyncFib f = new AsyncFib(8);
499                  assertSame(f, f.fork());
500                  f.quietlyJoin();
501 <                assertEquals(21, f.number);
447 <                checkCompletedNormally(f);
501 >                f.checkCompletedNormally();
502              }};
503 <        testInvokeOnPool(mainPool(), a);
503 >        testInvokeOnPool(pool, a);
504      }
505  
506      /**
# Line 454 | Line 508 | public class ForkJoinTask8Test extends J
508       * getQueuedTaskCount returns 0 when quiescent
509       */
510      public void testForkHelpQuiesce() {
511 +        testForkHelpQuiesce(mainPool());
512 +    }
513 +    public void testForkHelpQuiesce_Singleton() {
514 +        testForkHelpQuiesce(singletonPool());
515 +    }
516 +    public void testForkHelpQuiesce(ForkJoinPool pool) {
517          RecursiveAction a = new CheckedRecursiveAction() {
518              protected void realCompute() {
519                  AsyncFib f = new AsyncFib(8);
520                  assertSame(f, f.fork());
521                  helpQuiesce();
462                assertEquals(21, f.number);
522                  assertEquals(0, getQueuedTaskCount());
523 <                checkCompletedNormally(f);
523 >                f.checkCompletedNormally();
524              }};
525 <        testInvokeOnPool(mainPool(), a);
525 >        testInvokeOnPool(pool, a);
526      }
527  
528      /**
529       * invoke task throws exception when task completes abnormally
530       */
531      public void testAbnormalInvoke() {
532 +        testAbnormalInvoke(mainPool());
533 +    }
534 +    public void testAbnormalInvoke_Singleton() {
535 +        testAbnormalInvoke(singletonPool());
536 +    }
537 +    public void testAbnormalInvoke(ForkJoinPool pool) {
538          RecursiveAction a = new CheckedRecursiveAction() {
539              protected void realCompute() {
540                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 480 | Line 545 | public class ForkJoinTask8Test extends J
545                      checkCompletedAbnormally(f, success);
546                  }
547              }};
548 <        testInvokeOnPool(mainPool(), a);
548 >        testInvokeOnPool(pool, a);
549      }
550  
551      /**
552       * quietlyInvoke task returns when task completes abnormally
553       */
554      public void testAbnormalQuietlyInvoke() {
555 +        testAbnormalQuietlyInvoke(mainPool());
556 +    }
557 +    public void testAbnormalQuietlyInvoke_Singleton() {
558 +        testAbnormalQuietlyInvoke(singletonPool());
559 +    }
560 +    public void testAbnormalQuietlyInvoke(ForkJoinPool pool) {
561          RecursiveAction a = new CheckedRecursiveAction() {
562              protected void realCompute() {
563                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 494 | Line 565 | public class ForkJoinTask8Test extends J
565                  assertTrue(f.getException() instanceof FJException);
566                  checkCompletedAbnormally(f, f.getException());
567              }};
568 <        testInvokeOnPool(mainPool(), a);
568 >        testInvokeOnPool(pool, a);
569      }
570  
571      /**
572       * join of a forked task throws exception when task completes abnormally
573       */
574      public void testAbnormalForkJoin() {
575 +        testAbnormalForkJoin(mainPool());
576 +    }
577 +    public void testAbnormalForkJoin_Singleton() {
578 +        testAbnormalForkJoin(singletonPool());
579 +    }
580 +    public void testAbnormalForkJoin(ForkJoinPool pool) {
581          RecursiveAction a = new CheckedRecursiveAction() {
582              protected void realCompute() {
583                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 512 | Line 589 | public class ForkJoinTask8Test extends J
589                      checkCompletedAbnormally(f, success);
590                  }
591              }};
592 <        testInvokeOnPool(mainPool(), a);
592 >        testInvokeOnPool(pool, a);
593      }
594  
595      /**
596       * get of a forked task throws exception when task completes abnormally
597       */
598      public void testAbnormalForkGet() {
599 +        testAbnormalForkGet(mainPool());
600 +    }
601 +    public void testAbnormalForkGet_Singleton() {
602 +        testAbnormalForkJoin(singletonPool());
603 +    }
604 +    public void testAbnormalForkGet(ForkJoinPool pool) {
605          RecursiveAction a = new CheckedRecursiveAction() {
606              protected void realCompute() throws Exception {
607                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 532 | Line 615 | public class ForkJoinTask8Test extends J
615                      checkCompletedAbnormally(f, cause);
616                  }
617              }};
618 <        testInvokeOnPool(mainPool(), a);
618 >        testInvokeOnPool(pool, a);
619      }
620  
621      /**
622       * timed get of a forked task throws exception when task completes abnormally
623       */
624      public void testAbnormalForkTimedGet() {
625 +        testAbnormalForkTimedGet(mainPool());
626 +    }
627 +    public void testAbnormalForkTimedGet_Singleton() {
628 +        testAbnormalForkTimedGet(singletonPool());
629 +    }
630 +    public void testAbnormalForkTimedGet(ForkJoinPool pool) {
631          RecursiveAction a = new CheckedRecursiveAction() {
632              protected void realCompute() throws Exception {
633                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 552 | Line 641 | public class ForkJoinTask8Test extends J
641                      checkCompletedAbnormally(f, cause);
642                  }
643              }};
644 <        testInvokeOnPool(mainPool(), a);
644 >        testInvokeOnPool(pool, a);
645      }
646  
647      /**
648       * quietlyJoin of a forked task returns when task completes abnormally
649       */
650      public void testAbnormalForkQuietlyJoin() {
651 +        testAbnormalForkQuietlyJoin(mainPool());
652 +    }
653 +    public void testAbnormalForkQuietlyJoin_Singleton() {
654 +        testAbnormalForkQuietlyJoin(singletonPool());
655 +    }
656 +    public void testAbnormalForkQuietlyJoin(ForkJoinPool pool) {
657          RecursiveAction a = new CheckedRecursiveAction() {
658              protected void realCompute() {
659                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 567 | Line 662 | public class ForkJoinTask8Test extends J
662                  assertTrue(f.getException() instanceof FJException);
663                  checkCompletedAbnormally(f, f.getException());
664              }};
665 <        testInvokeOnPool(mainPool(), a);
665 >        testInvokeOnPool(pool, a);
666      }
667  
668      /**
669       * getPool of executing task returns its pool
670       */
671      public void testGetPool() {
672 <        final ForkJoinPool mainPool = mainPool();
672 >        testGetPool(mainPool());
673 >    }
674 >    public void testGetPool_Singleton() {
675 >        testGetPool(singletonPool());
676 >    }
677 >    public void testGetPool(ForkJoinPool pool) {
678          RecursiveAction a = new CheckedRecursiveAction() {
679              protected void realCompute() {
680 <                assertSame(mainPool, getPool());
680 >                assertSame(pool, getPool());
681              }};
682 <        testInvokeOnPool(mainPool, a);
682 >        testInvokeOnPool(pool, a);
683      }
684  
685      /**
# Line 597 | Line 697 | public class ForkJoinTask8Test extends J
697       * inForkJoinPool of executing task returns true
698       */
699      public void testInForkJoinPool() {
700 +        testInForkJoinPool(mainPool());
701 +    }
702 +    public void testInForkJoinPool_Singleton() {
703 +        testInForkJoinPool(singletonPool());
704 +    }
705 +    public void testInForkJoinPool(ForkJoinPool pool) {
706          RecursiveAction a = new CheckedRecursiveAction() {
707              protected void realCompute() {
708                  assertTrue(inForkJoinPool());
709              }};
710 <        testInvokeOnPool(mainPool(), a);
710 >        testInvokeOnPool(pool, a);
711      }
712  
713      /**
# Line 631 | Line 737 | public class ForkJoinTask8Test extends J
737       * invoke task throws exception after invoking completeExceptionally
738       */
739      public void testCompleteExceptionally() {
740 +        testCompleteExceptionally(mainPool());
741 +    }
742 +    public void testCompleteExceptionally_Singleton() {
743 +        testCompleteExceptionally(singletonPool());
744 +    }
745 +    public void testCompleteExceptionally(ForkJoinPool pool) {
746          RecursiveAction a = new CheckedRecursiveAction() {
747              protected void realCompute() {
748                  AsyncFib f = new AsyncFib(8);
# Line 642 | Line 754 | public class ForkJoinTask8Test extends J
754                      checkCompletedAbnormally(f, success);
755                  }
756              }};
757 <        testInvokeOnPool(mainPool(), a);
757 >        testInvokeOnPool(pool, a);
758      }
759  
760      /**
761 <     * invokeAll(t1, t2) invokes all task arguments
761 >     * invokeAll(tasks) with 1 argument invokes task
762       */
763 <    public void testInvokeAll2() {
763 >    public void testInvokeAll1() {
764 >        testInvokeAll1(mainPool());
765 >    }
766 >    public void testInvokeAll1_Singleton() {
767 >        testInvokeAll1(singletonPool());
768 >    }
769 >    public void testInvokeAll1(ForkJoinPool pool) {
770          RecursiveAction a = new CheckedRecursiveAction() {
771              protected void realCompute() {
772                  AsyncFib f = new AsyncFib(8);
773 <                AsyncFib g = new AsyncFib(9);
774 <                invokeAll(f, g);
657 <                assertEquals(21, f.number);
658 <                assertEquals(34, g.number);
659 <                checkCompletedNormally(f);
660 <                checkCompletedNormally(g);
773 >                invokeAll(f);
774 >                f.checkCompletedNormally();
775              }};
776 <        testInvokeOnPool(mainPool(), a);
776 >        testInvokeOnPool(pool, a);
777      }
778  
779      /**
780 <     * invokeAll(tasks) with 1 argument invokes task
780 >     * invokeAll(t1, t2) invokes all task arguments
781       */
782 <    public void testInvokeAll1() {
782 >    public void testInvokeAll2() {
783 >        testInvokeAll2(mainPool());
784 >    }
785 >    public void testInvokeAll2_Singleton() {
786 >        testInvokeAll2(singletonPool());
787 >    }
788 >    public void testInvokeAll2(ForkJoinPool pool) {
789          RecursiveAction a = new CheckedRecursiveAction() {
790              protected void realCompute() {
791 <                AsyncFib f = new AsyncFib(8);
792 <                invokeAll(f);
793 <                checkCompletedNormally(f);
794 <                assertEquals(21, f.number);
791 >                AsyncFib[] tasks = {
792 >                    new AsyncFib(8),
793 >                    new AsyncFib(9),
794 >                };
795 >                invokeAll(tasks[0], tasks[1]);
796 >                for (AsyncFib task : tasks) assertTrue(task.isDone());
797 >                for (AsyncFib task : tasks) task.checkCompletedNormally();
798              }};
799 <        testInvokeOnPool(mainPool(), a);
799 >        testInvokeOnPool(pool, a);
800      }
801  
802      /**
803       * invokeAll(tasks) with > 2 argument invokes tasks
804       */
805      public void testInvokeAll3() {
806 +        testInvokeAll3(mainPool());
807 +    }
808 +    public void testInvokeAll3_Singleton() {
809 +        testInvokeAll3(singletonPool());
810 +    }
811 +    public void testInvokeAll3(ForkJoinPool pool) {
812          RecursiveAction a = new CheckedRecursiveAction() {
813              protected void realCompute() {
814 <                AsyncFib f = new AsyncFib(8);
815 <                AsyncFib g = new AsyncFib(9);
816 <                AsyncFib h = new AsyncFib(7);
817 <                invokeAll(f, g, h);
818 <                assertEquals(21, f.number);
819 <                assertEquals(34, g.number);
820 <                assertEquals(13, h.number);
821 <                checkCompletedNormally(f);
693 <                checkCompletedNormally(g);
694 <                checkCompletedNormally(h);
814 >                AsyncFib[] tasks = {
815 >                    new AsyncFib(8),
816 >                    new AsyncFib(9),
817 >                    new AsyncFib(7),
818 >                };
819 >                invokeAll(tasks[0], tasks[1], tasks[2]);
820 >                for (AsyncFib task : tasks) assertTrue(task.isDone());
821 >                for (AsyncFib task : tasks) task.checkCompletedNormally();
822              }};
823 <        testInvokeOnPool(mainPool(), a);
823 >        testInvokeOnPool(pool, a);
824      }
825  
826      /**
827       * invokeAll(collection) invokes all tasks in the collection
828       */
829      public void testInvokeAllCollection() {
830 +        testInvokeAllCollection(mainPool());
831 +    }
832 +    public void testInvokeAllCollection_Singleton() {
833 +        testInvokeAllCollection(singletonPool());
834 +    }
835 +    public void testInvokeAllCollection(ForkJoinPool pool) {
836          RecursiveAction a = new CheckedRecursiveAction() {
837              protected void realCompute() {
838 <                AsyncFib f = new AsyncFib(8);
839 <                AsyncFib g = new AsyncFib(9);
840 <                AsyncFib h = new AsyncFib(7);
841 <                HashSet set = new HashSet();
842 <                set.add(f);
843 <                set.add(g);
844 <                set.add(h);
845 <                invokeAll(set);
713 <                assertEquals(21, f.number);
714 <                assertEquals(34, g.number);
715 <                assertEquals(13, h.number);
716 <                checkCompletedNormally(f);
717 <                checkCompletedNormally(g);
718 <                checkCompletedNormally(h);
838 >                AsyncFib[] tasks = {
839 >                    new AsyncFib(8),
840 >                    new AsyncFib(9),
841 >                    new AsyncFib(7),
842 >                };
843 >                invokeAll(Arrays.asList(tasks));
844 >                for (AsyncFib task : tasks) assertTrue(task.isDone());
845 >                for (AsyncFib task : tasks) task.checkCompletedNormally();
846              }};
847 <        testInvokeOnPool(mainPool(), a);
847 >        testInvokeOnPool(pool, a);
848      }
849  
850      /**
851 <     * invokeAll(tasks) with any null task throws NPE
851 >     * invokeAll(tasks) with any null task throws NullPointerException
852       */
853 <    public void testInvokeAllNPE() {
853 >    public void testInvokeAllNullTask() {
854 >        testInvokeAllNullTask(mainPool());
855 >    }
856 >    public void testInvokeAllNullTask_Singleton() {
857 >        testInvokeAllNullTask(singletonPool());
858 >    }
859 >    public void testInvokeAllNullTask(ForkJoinPool pool) {
860          RecursiveAction a = new CheckedRecursiveAction() {
861              protected void realCompute() {
862 <                AsyncFib f = new AsyncFib(8);
730 <                AsyncFib g = new AsyncFib(9);
731 <                AsyncFib h = null;
862 >                AsyncFib nul = null;
863                  Runnable[] throwingActions = {
864 <                    () -> invokeAll(h),
865 <                    () -> invokeAll(f, g, h),
866 <                    () -> invokeAll(f, h, g),
867 <                    () -> invokeAll(h, f, g),
864 >                    () -> invokeAll(nul),
865 >                    () -> invokeAll(nul, nul),
866 >                    () -> invokeAll(new AsyncFib(8), new AsyncFib(9), nul),
867 >                    () -> invokeAll(new AsyncFib(8), nul, new AsyncFib(9)),
868 >                    () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)),
869                  };
870                  assertThrows(NullPointerException.class, throwingActions);
871              }};
872 <        testInvokeOnPool(mainPool(), a);
872 >        testInvokeOnPool(pool, a);
873      }
874  
875      /**
876       * invokeAll(t1, t2) throw exception if any task does
877       */
878      public void testAbnormalInvokeAll2() {
879 +        testAbnormalInvokeAll2(mainPool());
880 +    }
881 +    public void testAbnormalInvokeAll2_Singleton() {
882 +        testAbnormalInvokeAll2(singletonPool());
883 +    }
884 +    public void testAbnormalInvokeAll2(ForkJoinPool pool) {
885          RecursiveAction a = new CheckedRecursiveAction() {
886              protected void realCompute() {
887                  AsyncFib f = new AsyncFib(8);
# Line 755 | Line 893 | public class ForkJoinTask8Test extends J
893                      checkCompletedAbnormally(g, success);
894                  }
895              }};
896 <        testInvokeOnPool(mainPool(), a);
896 >        testInvokeOnPool(pool, a);
897      }
898  
899      /**
900       * invokeAll(tasks) with 1 argument throws exception if task does
901       */
902      public void testAbnormalInvokeAll1() {
903 +        testAbnormalInvokeAll1(mainPool());
904 +    }
905 +    public void testAbnormalInvokeAll1_Singleton() {
906 +        testAbnormalInvokeAll1(singletonPool());
907 +    }
908 +    public void testAbnormalInvokeAll1(ForkJoinPool pool) {
909          RecursiveAction a = new CheckedRecursiveAction() {
910              protected void realCompute() {
911                  FailingAsyncFib g = new FailingAsyncFib(9);
# Line 772 | Line 916 | public class ForkJoinTask8Test extends J
916                      checkCompletedAbnormally(g, success);
917                  }
918              }};
919 <        testInvokeOnPool(mainPool(), a);
919 >        testInvokeOnPool(pool, a);
920      }
921  
922      /**
923       * invokeAll(tasks) with > 2 argument throws exception if any task does
924       */
925      public void testAbnormalInvokeAll3() {
926 +        testAbnormalInvokeAll3(mainPool());
927 +    }
928 +    public void testAbnormalInvokeAll3_Singleton() {
929 +        testAbnormalInvokeAll3(singletonPool());
930 +    }
931 +    public void testAbnormalInvokeAll3(ForkJoinPool pool) {
932          RecursiveAction a = new CheckedRecursiveAction() {
933              protected void realCompute() {
934                  AsyncFib f = new AsyncFib(8);
# Line 791 | Line 941 | public class ForkJoinTask8Test extends J
941                      checkCompletedAbnormally(g, success);
942                  }
943              }};
944 <        testInvokeOnPool(mainPool(), a);
944 >        testInvokeOnPool(pool, a);
945      }
946  
947      /**
948       * invokeAll(collection) throws exception if any task does
949       */
950      public void testAbnormalInvokeAllCollection() {
951 +        testAbnormalInvokeAllCollection(mainPool());
952 +    }
953 +    public void testAbnormalInvokeAllCollection_Singleton() {
954 +        testAbnormalInvokeAllCollection(singletonPool());
955 +    }
956 +    public void testAbnormalInvokeAllCollection(ForkJoinPool pool) {
957          RecursiveAction a = new CheckedRecursiveAction() {
958              protected void realCompute() {
959                  FailingAsyncFib f = new FailingAsyncFib(8);
960                  AsyncFib g = new AsyncFib(9);
961                  AsyncFib h = new AsyncFib(7);
962 <                HashSet set = new HashSet();
807 <                set.add(f);
808 <                set.add(g);
809 <                set.add(h);
962 >                ForkJoinTask[] tasks = { f, g, h };
963                  try {
964 <                    invokeAll(set);
964 >                    invokeAll(Arrays.asList(tasks));
965                      shouldThrow();
966                  } catch (FJException success) {
967                      checkCompletedAbnormally(f, success);
968                  }
969              }};
970 <        testInvokeOnPool(mainPool(), a);
970 >        testInvokeOnPool(pool, a);
971      }
972  
973      /**
# Line 831 | Line 984 | public class ForkJoinTask8Test extends J
984                  assertTrue(f.tryUnfork());
985                  helpQuiesce();
986                  checkNotDone(f);
987 <                checkCompletedNormally(g);
987 >                g.checkCompletedNormally();
988              }};
989          testInvokeOnPool(singletonPool(), a);
990      }
# Line 852 | Line 1005 | public class ForkJoinTask8Test extends J
1005                  assertTrue(getSurplusQueuedTaskCount() > 0);
1006                  helpQuiesce();
1007                  assertEquals(0, getSurplusQueuedTaskCount());
1008 <                checkCompletedNormally(f);
1009 <                checkCompletedNormally(g);
1010 <                checkCompletedNormally(h);
1008 >                f.checkCompletedNormally();
1009 >                g.checkCompletedNormally();
1010 >                h.checkCompletedNormally();
1011              }};
1012          testInvokeOnPool(singletonPool(), a);
1013      }
# Line 871 | Line 1024 | public class ForkJoinTask8Test extends J
1024                  assertSame(f, f.fork());
1025                  assertSame(f, peekNextLocalTask());
1026                  assertNull(f.join());
1027 <                checkCompletedNormally(f);
1027 >                f.checkCompletedNormally();
1028                  helpQuiesce();
1029 <                checkCompletedNormally(g);
1029 >                g.checkCompletedNormally();
1030              }};
1031          testInvokeOnPool(singletonPool(), a);
1032      }
# Line 892 | Line 1045 | public class ForkJoinTask8Test extends J
1045                  assertSame(f, pollNextLocalTask());
1046                  helpQuiesce();
1047                  checkNotDone(f);
1048 <                assertEquals(34, g.number);
896 <                checkCompletedNormally(g);
1048 >                g.checkCompletedNormally();
1049              }};
1050          testInvokeOnPool(singletonPool(), a);
1051      }
# Line 911 | Line 1063 | public class ForkJoinTask8Test extends J
1063                  assertSame(f, pollTask());
1064                  helpQuiesce();
1065                  checkNotDone(f);
1066 <                checkCompletedNormally(g);
1066 >                g.checkCompletedNormally();
1067              }};
1068          testInvokeOnPool(singletonPool(), a);
1069      }
# Line 929 | Line 1081 | public class ForkJoinTask8Test extends J
1081                  assertSame(g, peekNextLocalTask());
1082                  assertNull(f.join());
1083                  helpQuiesce();
1084 <                checkCompletedNormally(f);
1085 <                assertEquals(34, g.number);
934 <                checkCompletedNormally(g);
1084 >                f.checkCompletedNormally();
1085 >                g.checkCompletedNormally();
1086              }};
1087          testInvokeOnPool(asyncSingletonPool(), a);
1088      }
# Line 949 | Line 1100 | public class ForkJoinTask8Test extends J
1100                  assertSame(f, f.fork());
1101                  assertSame(g, pollNextLocalTask());
1102                  helpQuiesce();
1103 <                assertEquals(21, f.number);
953 <                checkCompletedNormally(f);
1103 >                f.checkCompletedNormally();
1104                  checkNotDone(g);
1105              }};
1106          testInvokeOnPool(asyncSingletonPool(), a);
# Line 969 | Line 1119 | public class ForkJoinTask8Test extends J
1119                  assertSame(f, f.fork());
1120                  assertSame(g, pollTask());
1121                  helpQuiesce();
1122 <                assertEquals(21, f.number);
973 <                checkCompletedNormally(f);
1122 >                f.checkCompletedNormally();
1123                  checkNotDone(g);
1124              }};
1125          testInvokeOnPool(asyncSingletonPool(), a);
1126      }
1127  
979    // versions for singleton pools
980
981    /**
982     * invoke returns when task completes normally.
983     * isCompletedAbnormally and isCancelled return false for normally
984     * completed tasks; getRawResult returns null.
985     */
986    public void testInvokeSingleton() {
987        RecursiveAction a = new CheckedRecursiveAction() {
988            protected void realCompute() {
989                AsyncFib f = new AsyncFib(8);
990                assertNull(f.invoke());
991                assertEquals(21, f.number);
992                checkCompletedNormally(f);
993            }};
994        testInvokeOnPool(singletonPool(), a);
995    }
996
997    /**
998     * quietlyInvoke task returns when task completes normally.
999     * isCompletedAbnormally and isCancelled return false for normally
1000     * completed tasks
1001     */
1002    public void testQuietlyInvokeSingleton() {
1003        RecursiveAction a = new CheckedRecursiveAction() {
1004            protected void realCompute() {
1005                AsyncFib f = new AsyncFib(8);
1006                f.quietlyInvoke();
1007                assertEquals(21, f.number);
1008                checkCompletedNormally(f);
1009            }};
1010        testInvokeOnPool(singletonPool(), a);
1011    }
1012
1013    /**
1014     * join of a forked task returns when task completes
1015     */
1016    public void testForkJoinSingleton() {
1017        RecursiveAction a = new CheckedRecursiveAction() {
1018            protected void realCompute() {
1019                AsyncFib f = new AsyncFib(8);
1020                assertSame(f, f.fork());
1021                assertNull(f.join());
1022                assertEquals(21, f.number);
1023                checkCompletedNormally(f);
1024            }};
1025        testInvokeOnPool(singletonPool(), a);
1026    }
1027
1028    /**
1029     * get of a forked task returns when task completes
1030     */
1031    public void testForkGetSingleton() {
1032        RecursiveAction a = new CheckedRecursiveAction() {
1033            protected void realCompute() throws Exception {
1034                AsyncFib f = new AsyncFib(8);
1035                assertSame(f, f.fork());
1036                assertNull(f.get());
1037                assertEquals(21, f.number);
1038                checkCompletedNormally(f);
1039            }};
1040        testInvokeOnPool(singletonPool(), a);
1041    }
1042
1043    /**
1044     * timed get of a forked task returns when task completes
1045     */
1046    public void testForkTimedGetSingleton() {
1047        RecursiveAction a = new CheckedRecursiveAction() {
1048            protected void realCompute() throws Exception {
1049                AsyncFib f = new AsyncFib(8);
1050                assertSame(f, f.fork());
1051                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1052                assertEquals(21, f.number);
1053                checkCompletedNormally(f);
1054            }};
1055        testInvokeOnPool(singletonPool(), a);
1056    }
1057
1058    /**
1059     * timed get with null time unit throws NPE
1060     */
1061    public void testForkTimedGetNPESingleton() {
1062        RecursiveAction a = new CheckedRecursiveAction() {
1063            protected void realCompute() throws Exception {
1064                AsyncFib f = new AsyncFib(8);
1065                assertSame(f, f.fork());
1066                try {
1067                    f.get(5L, null);
1068                    shouldThrow();
1069                } catch (NullPointerException success) {}
1070            }};
1071        testInvokeOnPool(singletonPool(), a);
1072    }
1073
1074    /**
1075     * quietlyJoin of a forked task returns when task completes
1076     */
1077    public void testForkQuietlyJoinSingleton() {
1078        RecursiveAction a = new CheckedRecursiveAction() {
1079            protected void realCompute() {
1080                AsyncFib f = new AsyncFib(8);
1081                assertSame(f, f.fork());
1082                f.quietlyJoin();
1083                assertEquals(21, f.number);
1084                checkCompletedNormally(f);
1085            }};
1086        testInvokeOnPool(singletonPool(), a);
1087    }
1088
1089    /**
1090     * helpQuiesce returns when tasks are complete.
1091     * getQueuedTaskCount returns 0 when quiescent
1092     */
1093    public void testForkHelpQuiesceSingleton() {
1094        RecursiveAction a = new CheckedRecursiveAction() {
1095            protected void realCompute() {
1096                AsyncFib f = new AsyncFib(8);
1097                assertSame(f, f.fork());
1098                helpQuiesce();
1099                assertEquals(0, getQueuedTaskCount());
1100                assertEquals(21, f.number);
1101                checkCompletedNormally(f);
1102            }};
1103        testInvokeOnPool(singletonPool(), a);
1104    }
1105
1106    /**
1107     * invoke task throws exception when task completes abnormally
1108     */
1109    public void testAbnormalInvokeSingleton() {
1110        RecursiveAction a = new CheckedRecursiveAction() {
1111            protected void realCompute() {
1112                FailingAsyncFib f = new FailingAsyncFib(8);
1113                try {
1114                    f.invoke();
1115                    shouldThrow();
1116                } catch (FJException success) {
1117                    checkCompletedAbnormally(f, success);
1118                }
1119            }};
1120        testInvokeOnPool(singletonPool(), a);
1121    }
1122
1123    /**
1124     * quietlyInvoke task returns when task completes abnormally
1125     */
1126    public void testAbnormalQuietlyInvokeSingleton() {
1127        RecursiveAction a = new CheckedRecursiveAction() {
1128            protected void realCompute() {
1129                FailingAsyncFib f = new FailingAsyncFib(8);
1130                f.quietlyInvoke();
1131                assertTrue(f.getException() instanceof FJException);
1132                checkCompletedAbnormally(f, f.getException());
1133            }};
1134        testInvokeOnPool(singletonPool(), a);
1135    }
1136
1137    /**
1138     * join of a forked task throws exception when task completes abnormally
1139     */
1140    public void testAbnormalForkJoinSingleton() {
1141        RecursiveAction a = new CheckedRecursiveAction() {
1142            protected void realCompute() {
1143                FailingAsyncFib f = new FailingAsyncFib(8);
1144                assertSame(f, f.fork());
1145                try {
1146                    f.join();
1147                    shouldThrow();
1148                } catch (FJException success) {
1149                    checkCompletedAbnormally(f, success);
1150                }
1151            }};
1152        testInvokeOnPool(singletonPool(), a);
1153    }
1154
1155    /**
1156     * get of a forked task throws exception when task completes abnormally
1157     */
1158    public void testAbnormalForkGetSingleton() {
1159        RecursiveAction a = new CheckedRecursiveAction() {
1160            protected void realCompute() throws Exception {
1161                FailingAsyncFib f = new FailingAsyncFib(8);
1162                assertSame(f, f.fork());
1163                try {
1164                    f.get();
1165                    shouldThrow();
1166                } catch (ExecutionException success) {
1167                    Throwable cause = success.getCause();
1168                    assertTrue(cause instanceof FJException);
1169                    checkCompletedAbnormally(f, cause);
1170                }
1171            }};
1172        testInvokeOnPool(singletonPool(), a);
1173    }
1174
1175    /**
1176     * timed get of a forked task throws exception when task completes abnormally
1177     */
1178    public void testAbnormalForkTimedGetSingleton() {
1179        RecursiveAction a = new CheckedRecursiveAction() {
1180            protected void realCompute() throws Exception {
1181                FailingAsyncFib f = new FailingAsyncFib(8);
1182                assertSame(f, f.fork());
1183                try {
1184                    f.get(LONG_DELAY_MS, MILLISECONDS);
1185                    shouldThrow();
1186                } catch (ExecutionException success) {
1187                    Throwable cause = success.getCause();
1188                    assertTrue(cause instanceof FJException);
1189                    checkCompletedAbnormally(f, cause);
1190                }
1191            }};
1192        testInvokeOnPool(singletonPool(), a);
1193    }
1194
1195    /**
1196     * quietlyJoin of a forked task returns when task completes abnormally
1197     */
1198    public void testAbnormalForkQuietlyJoinSingleton() {
1199        RecursiveAction a = new CheckedRecursiveAction() {
1200            protected void realCompute() {
1201                FailingAsyncFib f = new FailingAsyncFib(8);
1202                assertSame(f, f.fork());
1203                f.quietlyJoin();
1204                assertTrue(f.getException() instanceof FJException);
1205                checkCompletedAbnormally(f, f.getException());
1206            }};
1207        testInvokeOnPool(singletonPool(), a);
1208    }
1209
1210    /**
1211     * invoke task throws exception after invoking completeExceptionally
1212     */
1213    public void testCompleteExceptionallySingleton() {
1214        RecursiveAction a = new CheckedRecursiveAction() {
1215            protected void realCompute() {
1216                AsyncFib f = new AsyncFib(8);
1217                f.completeExceptionally(new FJException());
1218                try {
1219                    f.invoke();
1220                    shouldThrow();
1221                } catch (FJException success) {
1222                    checkCompletedAbnormally(f, success);
1223                }
1224            }};
1225        testInvokeOnPool(singletonPool(), a);
1226    }
1227
1228    /**
1229     * invokeAll(t1, t2) invokes all task arguments
1230     */
1231    public void testInvokeAll2Singleton() {
1232        RecursiveAction a = new CheckedRecursiveAction() {
1233            protected void realCompute() {
1234                AsyncFib f = new AsyncFib(8);
1235                AsyncFib g = new AsyncFib(9);
1236                invokeAll(f, g);
1237                assertEquals(21, f.number);
1238                assertEquals(34, g.number);
1239                checkCompletedNormally(f);
1240                checkCompletedNormally(g);
1241            }};
1242        testInvokeOnPool(singletonPool(), a);
1243    }
1244
1245    /**
1246     * invokeAll(tasks) with 1 argument invokes task
1247     */
1248    public void testInvokeAll1Singleton() {
1249        RecursiveAction a = new CheckedRecursiveAction() {
1250            protected void realCompute() {
1251                AsyncFib f = new AsyncFib(8);
1252                invokeAll(f);
1253                checkCompletedNormally(f);
1254                assertEquals(21, f.number);
1255            }};
1256        testInvokeOnPool(singletonPool(), a);
1257    }
1258
1259    /**
1260     * invokeAll(tasks) with > 2 argument invokes tasks
1261     */
1262    public void testInvokeAll3Singleton() {
1263        RecursiveAction a = new CheckedRecursiveAction() {
1264            protected void realCompute() {
1265                AsyncFib f = new AsyncFib(8);
1266                AsyncFib g = new AsyncFib(9);
1267                AsyncFib h = new AsyncFib(7);
1268                invokeAll(f, g, h);
1269                assertEquals(21, f.number);
1270                assertEquals(34, g.number);
1271                assertEquals(13, h.number);
1272                checkCompletedNormally(f);
1273                checkCompletedNormally(g);
1274                checkCompletedNormally(h);
1275            }};
1276        testInvokeOnPool(singletonPool(), a);
1277    }
1278
1279    /**
1280     * invokeAll(collection) invokes all tasks in the collection
1281     */
1282    public void testInvokeAllCollectionSingleton() {
1283        RecursiveAction a = new CheckedRecursiveAction() {
1284            protected void realCompute() {
1285                AsyncFib f = new AsyncFib(8);
1286                AsyncFib g = new AsyncFib(9);
1287                AsyncFib h = new AsyncFib(7);
1288                HashSet set = new HashSet();
1289                set.add(f);
1290                set.add(g);
1291                set.add(h);
1292                invokeAll(set);
1293                assertEquals(21, f.number);
1294                assertEquals(34, g.number);
1295                assertEquals(13, h.number);
1296                checkCompletedNormally(f);
1297                checkCompletedNormally(g);
1298                checkCompletedNormally(h);
1299            }};
1300        testInvokeOnPool(singletonPool(), a);
1301    }
1302
1303    /**
1304     * invokeAll(tasks) with any null task throws NPE
1305     */
1306    public void testInvokeAllNPESingleton() {
1307        RecursiveAction a = new CheckedRecursiveAction() {
1308            protected void realCompute() {
1309                AsyncFib f = new AsyncFib(8);
1310                AsyncFib g = new AsyncFib(9);
1311                AsyncFib h = null;
1312                try {
1313                    invokeAll(f, g, h);
1314                    shouldThrow();
1315                } catch (NullPointerException success) {}
1316            }};
1317        testInvokeOnPool(singletonPool(), a);
1318    }
1319
1320    /**
1321     * invokeAll(t1, t2) throw exception if any task does
1322     */
1323    public void testAbnormalInvokeAll2Singleton() {
1324        RecursiveAction a = new CheckedRecursiveAction() {
1325            protected void realCompute() {
1326                AsyncFib f = new AsyncFib(8);
1327                FailingAsyncFib g = new FailingAsyncFib(9);
1328                try {
1329                    invokeAll(f, g);
1330                    shouldThrow();
1331                } catch (FJException success) {
1332                    checkCompletedAbnormally(g, success);
1333                }
1334            }};
1335        testInvokeOnPool(singletonPool(), a);
1336    }
1337
1338    /**
1339     * invokeAll(tasks) with 1 argument throws exception if task does
1340     */
1341    public void testAbnormalInvokeAll1Singleton() {
1342        RecursiveAction a = new CheckedRecursiveAction() {
1343            protected void realCompute() {
1344                FailingAsyncFib g = new FailingAsyncFib(9);
1345                try {
1346                    invokeAll(g);
1347                    shouldThrow();
1348                } catch (FJException success) {
1349                    checkCompletedAbnormally(g, success);
1350                }
1351            }};
1352        testInvokeOnPool(singletonPool(), a);
1353    }
1354
1355    /**
1356     * invokeAll(tasks) with > 2 argument throws exception if any task does
1357     */
1358    public void testAbnormalInvokeAll3Singleton() {
1359        RecursiveAction a = new CheckedRecursiveAction() {
1360            protected void realCompute() {
1361                AsyncFib f = new AsyncFib(8);
1362                FailingAsyncFib g = new FailingAsyncFib(9);
1363                AsyncFib h = new AsyncFib(7);
1364                try {
1365                    invokeAll(f, g, h);
1366                    shouldThrow();
1367                } catch (FJException success) {
1368                    checkCompletedAbnormally(g, success);
1369                }
1370            }};
1371        testInvokeOnPool(singletonPool(), a);
1372    }
1373
1374    /**
1375     * invokeAll(collection) throws exception if any task does
1376     */
1377    public void testAbnormalInvokeAllCollectionSingleton() {
1378        RecursiveAction a = new CheckedRecursiveAction() {
1379            protected void realCompute() {
1380                FailingAsyncFib f = new FailingAsyncFib(8);
1381                AsyncFib g = new AsyncFib(9);
1382                AsyncFib h = new AsyncFib(7);
1383                HashSet set = new HashSet();
1384                set.add(f);
1385                set.add(g);
1386                set.add(h);
1387                try {
1388                    invokeAll(set);
1389                    shouldThrow();
1390                } catch (FJException success) {
1391                    checkCompletedAbnormally(f, success);
1392                }
1393            }};
1394        testInvokeOnPool(singletonPool(), a);
1395    }
1396
1128      /**
1129       * ForkJoinTask.quietlyComplete returns when task completes
1130       * normally without setting a value. The most recent value

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines