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

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.18 by jsr166, Fri Sep 17 00:55:19 2010 UTC vs.
Revision 1.41 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 < import java.util.concurrent.ExecutionException;
6 >
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.ExecutionException;
13   import java.util.concurrent.ForkJoinPool;
14   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.ForkJoinWorkerThread;
15   import java.util.concurrent.RecursiveAction;
16 < import java.util.concurrent.TimeUnit;
16 > import java.util.concurrent.TimeoutException;
17   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
18 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
19 < import java.util.HashSet;
20 < import junit.framework.*;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class ForkJoinTaskTest extends JSR166TestCase {
23  
24      public static void main(String[] args) {
25 <        junit.textui.TestRunner.run(suite());
25 >        main(suite(), args);
26      }
27  
28      public static Test suite() {
29          return new TestSuite(ForkJoinTaskTest.class);
30      }
31  
32 +    // Runs with "mainPool" use > 1 thread. singletonPool tests use 1
33 +    static final int mainPoolSize =
34 +        Math.max(2, Runtime.getRuntime().availableProcessors());
35 +
36      private static ForkJoinPool mainPool() {
37 <        return new ForkJoinPool();
37 >        return new ForkJoinPool(mainPoolSize);
38      }
39  
40      private static ForkJoinPool singletonPool() {
# Line 46 | Line 54 | public class ForkJoinTaskTest extends JS
54              assertFalse(a.isCompletedAbnormally());
55              assertFalse(a.isCancelled());
56              assertNull(a.getException());
57 +            assertNull(a.getRawResult());
58  
59              assertNull(pool.invoke(a));
60  
# Line 54 | Line 63 | public class ForkJoinTaskTest extends JS
63              assertFalse(a.isCompletedAbnormally());
64              assertFalse(a.isCancelled());
65              assertNull(a.getException());
66 +            assertNull(a.getRawResult());
67          } finally {
68              joinPool(pool);
69          }
70      }
71  
72 +    void checkNotDone(ForkJoinTask a) {
73 +        assertFalse(a.isDone());
74 +        assertFalse(a.isCompletedNormally());
75 +        assertFalse(a.isCompletedAbnormally());
76 +        assertFalse(a.isCancelled());
77 +        assertNull(a.getException());
78 +        assertNull(a.getRawResult());
79 +
80 +        try {
81 +            a.get(0L, SECONDS);
82 +            shouldThrow();
83 +        } catch (TimeoutException success) {
84 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
85 +    }
86 +
87 +    <T> void checkCompletedNormally(ForkJoinTask<T> a) {
88 +        checkCompletedNormally(a, null);
89 +    }
90 +
91 +    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
92 +        assertTrue(a.isDone());
93 +        assertFalse(a.isCancelled());
94 +        assertTrue(a.isCompletedNormally());
95 +        assertFalse(a.isCompletedAbnormally());
96 +        assertNull(a.getException());
97 +        assertSame(expected, a.getRawResult());
98 +
99 +        {
100 +            Thread.currentThread().interrupt();
101 +            long t0 = System.nanoTime();
102 +            assertSame(expected, a.join());
103 +            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
104 +            Thread.interrupted();
105 +        }
106 +
107 +        {
108 +            Thread.currentThread().interrupt();
109 +            long t0 = System.nanoTime();
110 +            a.quietlyJoin();        // should be no-op
111 +            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
112 +            Thread.interrupted();
113 +        }
114 +
115 +        assertFalse(a.cancel(false));
116 +        assertFalse(a.cancel(true));
117 +        try {
118 +            assertSame(expected, a.get());
119 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
120 +        try {
121 +            assertSame(expected, a.get(5L, SECONDS));
122 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
123 +    }
124 +
125 +    void checkCancelled(ForkJoinTask a) {
126 +        assertTrue(a.isDone());
127 +        assertTrue(a.isCancelled());
128 +        assertFalse(a.isCompletedNormally());
129 +        assertTrue(a.isCompletedAbnormally());
130 +        assertTrue(a.getException() instanceof CancellationException);
131 +        assertNull(a.getRawResult());
132 +        assertTrue(a.cancel(false));
133 +        assertTrue(a.cancel(true));
134 +
135 +        try {
136 +            Thread.currentThread().interrupt();
137 +            a.join();
138 +            shouldThrow();
139 +        } catch (CancellationException success) {
140 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
141 +        Thread.interrupted();
142 +
143 +        {
144 +            long t0 = System.nanoTime();
145 +            a.quietlyJoin();        // should be no-op
146 +            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
147 +        }
148 +
149 +        try {
150 +            a.get();
151 +            shouldThrow();
152 +        } catch (CancellationException success) {
153 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
154 +
155 +        try {
156 +            a.get(5L, SECONDS);
157 +            shouldThrow();
158 +        } catch (CancellationException success) {
159 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
160 +    }
161 +
162 +    void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
163 +        assertTrue(a.isDone());
164 +        assertFalse(a.isCancelled());
165 +        assertFalse(a.isCompletedNormally());
166 +        assertTrue(a.isCompletedAbnormally());
167 +        assertSame(t.getClass(), a.getException().getClass());
168 +        assertNull(a.getRawResult());
169 +        assertFalse(a.cancel(false));
170 +        assertFalse(a.cancel(true));
171 +
172 +        try {
173 +            Thread.currentThread().interrupt();
174 +            a.join();
175 +            shouldThrow();
176 +        } catch (Throwable expected) {
177 +            assertSame(t.getClass(), expected.getClass());
178 +        }
179 +        Thread.interrupted();
180 +
181 +        {
182 +            long t0 = System.nanoTime();
183 +            a.quietlyJoin();        // should be no-op
184 +            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
185 +        }
186 +
187 +        try {
188 +            a.get();
189 +            shouldThrow();
190 +        } catch (ExecutionException success) {
191 +            assertSame(t.getClass(), success.getCause().getClass());
192 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
193 +
194 +        try {
195 +            a.get(5L, SECONDS);
196 +            shouldThrow();
197 +        } catch (ExecutionException success) {
198 +            assertSame(t.getClass(), success.getCause().getClass());
199 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
200 +    }
201 +
202      /*
203       * Testing coverage notes:
204       *
# Line 67 | Line 207 | public class ForkJoinTaskTest extends JS
207       * differently than supplied Recursive forms.
208       */
209  
210 <    static final class FJException extends RuntimeException {
210 >    public static final class FJException extends RuntimeException {
211          FJException() { super(); }
212      }
213  
214 <    static abstract class BinaryAsyncAction extends ForkJoinTask<Void> {
214 >    abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
215          private volatile int controlState;
216  
217          static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
# Line 211 | Line 351 | public class ForkJoinTaskTest extends JS
351          }
352      }
353  
214
354      static final class FailingAsyncFib extends BinaryAsyncAction {
355          int number;
356          public FailingAsyncFib(int n) {
# Line 243 | Line 382 | public class ForkJoinTaskTest extends JS
382      /**
383       * invoke returns when task completes normally.
384       * isCompletedAbnormally and isCancelled return false for normally
385 <     * completed tasks. getRawResult of a RecursiveAction returns null;
385 >     * completed tasks; getRawResult returns null.
386       */
387      public void testInvoke() {
388          RecursiveAction a = new CheckedRecursiveAction() {
389 <            public void realCompute() {
389 >            protected void realCompute() {
390                  AsyncFib f = new AsyncFib(8);
391                  assertNull(f.invoke());
392                  assertEquals(21, f.number);
393 <                assertTrue(f.isDone());
255 <                assertFalse(f.isCancelled());
256 <                assertFalse(f.isCompletedAbnormally());
257 <                assertNull(f.getRawResult());
393 >                checkCompletedNormally(f);
394              }};
395          testInvokeOnPool(mainPool(), a);
396      }
# Line 266 | Line 402 | public class ForkJoinTaskTest extends JS
402       */
403      public void testQuietlyInvoke() {
404          RecursiveAction a = new CheckedRecursiveAction() {
405 <            public void realCompute() {
405 >            protected void realCompute() {
406                  AsyncFib f = new AsyncFib(8);
407                  f.quietlyInvoke();
408                  assertEquals(21, f.number);
409 <                assertTrue(f.isDone());
274 <                assertFalse(f.isCancelled());
275 <                assertFalse(f.isCompletedAbnormally());
276 <                assertNull(f.getRawResult());
409 >                checkCompletedNormally(f);
410              }};
411          testInvokeOnPool(mainPool(), a);
412      }
# Line 283 | Line 416 | public class ForkJoinTaskTest extends JS
416       */
417      public void testForkJoin() {
418          RecursiveAction a = new CheckedRecursiveAction() {
419 <            public void realCompute() {
419 >            protected void realCompute() {
420                  AsyncFib f = new AsyncFib(8);
421                  assertSame(f, f.fork());
422                  assertNull(f.join());
423                  assertEquals(21, f.number);
424 <                assertTrue(f.isDone());
292 <                assertNull(f.getRawResult());
424 >                checkCompletedNormally(f);
425              }};
426          testInvokeOnPool(mainPool(), a);
427      }
# Line 299 | Line 431 | public class ForkJoinTaskTest extends JS
431       */
432      public void testForkGet() {
433          RecursiveAction a = new CheckedRecursiveAction() {
434 <            public void realCompute() throws Exception {
434 >            protected void realCompute() throws Exception {
435                  AsyncFib f = new AsyncFib(8);
436                  assertSame(f, f.fork());
437                  assertNull(f.get());
438                  assertEquals(21, f.number);
439 <                assertTrue(f.isDone());
439 >                checkCompletedNormally(f);
440              }};
441          testInvokeOnPool(mainPool(), a);
442      }
# Line 314 | Line 446 | public class ForkJoinTaskTest extends JS
446       */
447      public void testForkTimedGet() {
448          RecursiveAction a = new CheckedRecursiveAction() {
449 <            public void realCompute() throws Exception {
449 >            protected void realCompute() throws Exception {
450                  AsyncFib f = new AsyncFib(8);
451                  assertSame(f, f.fork());
452                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
453                  assertEquals(21, f.number);
454 <                assertTrue(f.isDone());
454 >                checkCompletedNormally(f);
455              }};
456          testInvokeOnPool(mainPool(), a);
457      }
# Line 329 | Line 461 | public class ForkJoinTaskTest extends JS
461       */
462      public void testForkTimedGetNPE() {
463          RecursiveAction a = new CheckedRecursiveAction() {
464 <            public void realCompute() throws Exception {
464 >            protected void realCompute() throws Exception {
465                  AsyncFib f = new AsyncFib(8);
466                  assertSame(f, f.fork());
467                  try {
# Line 345 | Line 477 | public class ForkJoinTaskTest extends JS
477       */
478      public void testForkQuietlyJoin() {
479          RecursiveAction a = new CheckedRecursiveAction() {
480 <            public void realCompute() {
480 >            protected void realCompute() {
481                  AsyncFib f = new AsyncFib(8);
482                  assertSame(f, f.fork());
483                  f.quietlyJoin();
484                  assertEquals(21, f.number);
485 <                assertTrue(f.isDone());
485 >                checkCompletedNormally(f);
486              }};
487          testInvokeOnPool(mainPool(), a);
488      }
489  
358
490      /**
491       * helpQuiesce returns when tasks are complete.
492       * getQueuedTaskCount returns 0 when quiescent
493       */
494      public void testForkHelpQuiesce() {
495          RecursiveAction a = new CheckedRecursiveAction() {
496 <            public void realCompute() {
496 >            protected void realCompute() {
497                  AsyncFib f = new AsyncFib(8);
498                  assertSame(f, f.fork());
499 <                f.helpQuiesce();
499 >                helpQuiesce();
500                  assertEquals(21, f.number);
370                assertTrue(f.isDone());
501                  assertEquals(0, getQueuedTaskCount());
502 +                checkCompletedNormally(f);
503              }};
504          testInvokeOnPool(mainPool(), a);
505      }
506  
376
507      /**
508       * invoke task throws exception when task completes abnormally
509       */
510      public void testAbnormalInvoke() {
511          RecursiveAction a = new CheckedRecursiveAction() {
512 <            public void realCompute() {
512 >            protected void realCompute() {
513                  FailingAsyncFib f = new FailingAsyncFib(8);
514                  try {
515                      f.invoke();
516                      shouldThrow();
517 <                } catch (FJException success) {}
517 >                } catch (FJException success) {
518 >                    checkCompletedAbnormally(f, success);
519 >                }
520              }};
521          testInvokeOnPool(mainPool(), a);
522      }
# Line 394 | Line 526 | public class ForkJoinTaskTest extends JS
526       */
527      public void testAbnormalQuietlyInvoke() {
528          RecursiveAction a = new CheckedRecursiveAction() {
529 <            public void realCompute() {
529 >            protected void realCompute() {
530                  FailingAsyncFib f = new FailingAsyncFib(8);
531                  f.quietlyInvoke();
532 <                assertTrue(f.isDone());
532 >                assertTrue(f.getException() instanceof FJException);
533 >                checkCompletedAbnormally(f, f.getException());
534              }};
535          testInvokeOnPool(mainPool(), a);
536      }
# Line 407 | Line 540 | public class ForkJoinTaskTest extends JS
540       */
541      public void testAbnormalForkJoin() {
542          RecursiveAction a = new CheckedRecursiveAction() {
543 <            public void realCompute() {
543 >            protected void realCompute() {
544                  FailingAsyncFib f = new FailingAsyncFib(8);
545                  assertSame(f, f.fork());
546                  try {
547                      f.join();
548                      shouldThrow();
549 <                } catch (FJException success) {}
549 >                } catch (FJException success) {
550 >                    checkCompletedAbnormally(f, success);
551 >                }
552              }};
553          testInvokeOnPool(mainPool(), a);
554      }
# Line 423 | Line 558 | public class ForkJoinTaskTest extends JS
558       */
559      public void testAbnormalForkGet() {
560          RecursiveAction a = new CheckedRecursiveAction() {
561 <            public void realCompute() throws Exception {
561 >            protected void realCompute() throws Exception {
562                  FailingAsyncFib f = new FailingAsyncFib(8);
563                  assertSame(f, f.fork());
564                  try {
# Line 432 | Line 567 | public class ForkJoinTaskTest extends JS
567                  } catch (ExecutionException success) {
568                      Throwable cause = success.getCause();
569                      assertTrue(cause instanceof FJException);
570 <                    assertTrue(f.isDone());
436 <                    assertTrue(f.isCompletedAbnormally());
437 <                    assertSame(cause, f.getException());
570 >                    checkCompletedAbnormally(f, cause);
571                  }
572              }};
573          testInvokeOnPool(mainPool(), a);
# Line 445 | Line 578 | public class ForkJoinTaskTest extends JS
578       */
579      public void testAbnormalForkTimedGet() {
580          RecursiveAction a = new CheckedRecursiveAction() {
581 <            public void realCompute() throws Exception {
581 >            protected void realCompute() throws Exception {
582                  FailingAsyncFib f = new FailingAsyncFib(8);
583                  assertSame(f, f.fork());
584                  try {
# Line 454 | Line 587 | public class ForkJoinTaskTest extends JS
587                  } catch (ExecutionException success) {
588                      Throwable cause = success.getCause();
589                      assertTrue(cause instanceof FJException);
590 <                    assertTrue(f.isDone());
458 <                    assertTrue(f.isCompletedAbnormally());
459 <                    assertSame(cause, f.getException());
590 >                    checkCompletedAbnormally(f, cause);
591                  }
592              }};
593          testInvokeOnPool(mainPool(), a);
# Line 467 | Line 598 | public class ForkJoinTaskTest extends JS
598       */
599      public void testAbnormalForkQuietlyJoin() {
600          RecursiveAction a = new CheckedRecursiveAction() {
601 <            public void realCompute() {
601 >            protected void realCompute() {
602                  FailingAsyncFib f = new FailingAsyncFib(8);
603                  assertSame(f, f.fork());
604                  f.quietlyJoin();
474                assertTrue(f.isDone());
475                assertTrue(f.isCompletedAbnormally());
605                  assertTrue(f.getException() instanceof FJException);
606 +                checkCompletedAbnormally(f, f.getException());
607              }};
608          testInvokeOnPool(mainPool(), a);
609      }
# Line 483 | Line 613 | public class ForkJoinTaskTest extends JS
613       */
614      public void testCancelledInvoke() {
615          RecursiveAction a = new CheckedRecursiveAction() {
616 <            public void realCompute() {
616 >            protected void realCompute() {
617                  AsyncFib f = new AsyncFib(8);
618                  assertTrue(f.cancel(true));
619                  try {
620                      f.invoke();
621                      shouldThrow();
622                  } catch (CancellationException success) {
623 <                    assertTrue(f.isDone());
494 <                    assertTrue(f.isCancelled());
495 <                    assertTrue(f.isCompletedAbnormally());
496 <                    assertTrue(f.getException() instanceof CancellationException);
623 >                    checkCancelled(f);
624                  }
625              }};
626          testInvokeOnPool(mainPool(), a);
# Line 504 | Line 631 | public class ForkJoinTaskTest extends JS
631       */
632      public void testCancelledForkJoin() {
633          RecursiveAction a = new CheckedRecursiveAction() {
634 <            public void realCompute() {
634 >            protected void realCompute() {
635                  AsyncFib f = new AsyncFib(8);
636                  assertTrue(f.cancel(true));
637                  assertSame(f, f.fork());
# Line 512 | Line 639 | public class ForkJoinTaskTest extends JS
639                      f.join();
640                      shouldThrow();
641                  } catch (CancellationException success) {
642 <                    assertTrue(f.isDone());
516 <                    assertTrue(f.isCancelled());
517 <                    assertTrue(f.isCompletedAbnormally());
518 <                    assertTrue(f.getException() instanceof CancellationException);
642 >                    checkCancelled(f);
643                  }
644              }};
645          testInvokeOnPool(mainPool(), a);
# Line 526 | Line 650 | public class ForkJoinTaskTest extends JS
650       */
651      public void testCancelledForkGet() {
652          RecursiveAction a = new CheckedRecursiveAction() {
653 <            public void realCompute() throws Exception {
653 >            protected void realCompute() throws Exception {
654                  AsyncFib f = new AsyncFib(8);
655                  assertTrue(f.cancel(true));
656                  assertSame(f, f.fork());
# Line 534 | Line 658 | public class ForkJoinTaskTest extends JS
658                      f.get();
659                      shouldThrow();
660                  } catch (CancellationException success) {
661 <                    assertTrue(f.isDone());
538 <                    assertTrue(f.isCancelled());
539 <                    assertTrue(f.isCompletedAbnormally());
540 <                    assertTrue(f.getException() instanceof CancellationException);
661 >                    checkCancelled(f);
662                  }
663              }};
664          testInvokeOnPool(mainPool(), a);
# Line 548 | Line 669 | public class ForkJoinTaskTest extends JS
669       */
670      public void testCancelledForkTimedGet() throws Exception {
671          RecursiveAction a = new CheckedRecursiveAction() {
672 <            public void realCompute() throws Exception {
672 >            protected void realCompute() throws Exception {
673                  AsyncFib f = new AsyncFib(8);
674                  assertTrue(f.cancel(true));
675                  assertSame(f, f.fork());
# Line 556 | Line 677 | public class ForkJoinTaskTest extends JS
677                      f.get(LONG_DELAY_MS, MILLISECONDS);
678                      shouldThrow();
679                  } catch (CancellationException success) {
680 <                    assertTrue(f.isDone());
560 <                    assertTrue(f.isCancelled());
561 <                    assertTrue(f.isCompletedAbnormally());
562 <                    assertTrue(f.getException() instanceof CancellationException);
680 >                    checkCancelled(f);
681                  }
682              }};
683          testInvokeOnPool(mainPool(), a);
# Line 570 | Line 688 | public class ForkJoinTaskTest extends JS
688       */
689      public void testCancelledForkQuietlyJoin() {
690          RecursiveAction a = new CheckedRecursiveAction() {
691 <            public void realCompute() {
691 >            protected void realCompute() {
692                  AsyncFib f = new AsyncFib(8);
693                  assertTrue(f.cancel(true));
694                  assertSame(f, f.fork());
695                  f.quietlyJoin();
696 <                assertTrue(f.isDone());
579 <                assertTrue(f.isCompletedAbnormally());
580 <                assertTrue(f.isCancelled());
581 <                assertTrue(f.getException() instanceof CancellationException);
696 >                checkCancelled(f);
697              }};
698          testInvokeOnPool(mainPool(), a);
699      }
# Line 589 | Line 704 | public class ForkJoinTaskTest extends JS
704      public void testGetPool() {
705          final ForkJoinPool mainPool = mainPool();
706          RecursiveAction a = new CheckedRecursiveAction() {
707 <            public void realCompute() {
707 >            protected void realCompute() {
708                  assertSame(mainPool, getPool());
709              }};
710          testInvokeOnPool(mainPool, a);
# Line 600 | Line 715 | public class ForkJoinTaskTest extends JS
715       */
716      public void testGetPool2() {
717          RecursiveAction a = new CheckedRecursiveAction() {
718 <            public void realCompute() {
718 >            protected void realCompute() {
719                  assertNull(getPool());
720              }};
721          assertNull(a.invoke());
# Line 611 | Line 726 | public class ForkJoinTaskTest extends JS
726       */
727      public void testInForkJoinPool() {
728          RecursiveAction a = new CheckedRecursiveAction() {
729 <            public void realCompute() {
729 >            protected void realCompute() {
730                  assertTrue(inForkJoinPool());
731              }};
732          testInvokeOnPool(mainPool(), a);
# Line 622 | Line 737 | public class ForkJoinTaskTest extends JS
737       */
738      public void testInForkJoinPool2() {
739          RecursiveAction a = new CheckedRecursiveAction() {
740 <            public void realCompute() {
741 <                assertTrue(!inForkJoinPool());
740 >            protected void realCompute() {
741 >                assertFalse(inForkJoinPool());
742              }};
743          assertNull(a.invoke());
744      }
# Line 633 | Line 748 | public class ForkJoinTaskTest extends JS
748       */
749      public void testSetRawResult() {
750          RecursiveAction a = new CheckedRecursiveAction() {
751 <            public void realCompute() {
751 >            protected void realCompute() {
752                  setRawResult(null);
753 +                assertNull(getRawResult());
754              }};
755          assertNull(a.invoke());
756      }
# Line 644 | Line 760 | public class ForkJoinTaskTest extends JS
760       */
761      public void testCompleteExceptionally() {
762          RecursiveAction a = new CheckedRecursiveAction() {
763 <            public void realCompute() {
763 >            protected void realCompute() {
764                  AsyncFib f = new AsyncFib(8);
765                  f.completeExceptionally(new FJException());
766                  try {
767                      f.invoke();
768                      shouldThrow();
769 <                } catch (FJException success) {}
769 >                } catch (FJException success) {
770 >                    checkCompletedAbnormally(f, success);
771 >                }
772              }};
773          testInvokeOnPool(mainPool(), a);
774      }
# Line 660 | Line 778 | public class ForkJoinTaskTest extends JS
778       */
779      public void testInvokeAll2() {
780          RecursiveAction a = new CheckedRecursiveAction() {
781 <            public void realCompute() {
781 >            protected void realCompute() {
782                  AsyncFib f = new AsyncFib(8);
783                  AsyncFib g = new AsyncFib(9);
784                  invokeAll(f, g);
667                assertTrue(f.isDone());
785                  assertEquals(21, f.number);
669                assertTrue(g.isDone());
786                  assertEquals(34, g.number);
787 +                checkCompletedNormally(f);
788 +                checkCompletedNormally(g);
789              }};
790          testInvokeOnPool(mainPool(), a);
791      }
# Line 677 | Line 795 | public class ForkJoinTaskTest extends JS
795       */
796      public void testInvokeAll1() {
797          RecursiveAction a = new CheckedRecursiveAction() {
798 <            public void realCompute() {
798 >            protected void realCompute() {
799                  AsyncFib f = new AsyncFib(8);
800                  invokeAll(f);
801 <                assertTrue(f.isDone());
801 >                checkCompletedNormally(f);
802                  assertEquals(21, f.number);
803              }};
804          testInvokeOnPool(mainPool(), a);
# Line 691 | Line 809 | public class ForkJoinTaskTest extends JS
809       */
810      public void testInvokeAll3() {
811          RecursiveAction a = new CheckedRecursiveAction() {
812 <            public void realCompute() {
812 >            protected void realCompute() {
813                  AsyncFib f = new AsyncFib(8);
814                  AsyncFib g = new AsyncFib(9);
815                  AsyncFib h = new AsyncFib(7);
816                  invokeAll(f, g, h);
699                assertTrue(f.isDone());
817                  assertEquals(21, f.number);
701                assertTrue(g.isDone());
818                  assertEquals(34, g.number);
703                assertTrue(h.isDone());
819                  assertEquals(13, h.number);
820 +                checkCompletedNormally(f);
821 +                checkCompletedNormally(g);
822 +                checkCompletedNormally(h);
823              }};
824          testInvokeOnPool(mainPool(), a);
825      }
# Line 711 | Line 829 | public class ForkJoinTaskTest extends JS
829       */
830      public void testInvokeAllCollection() {
831          RecursiveAction a = new CheckedRecursiveAction() {
832 <            public void realCompute() {
832 >            protected void realCompute() {
833                  AsyncFib f = new AsyncFib(8);
834                  AsyncFib g = new AsyncFib(9);
835                  AsyncFib h = new AsyncFib(7);
# Line 720 | Line 838 | public class ForkJoinTaskTest extends JS
838                  set.add(g);
839                  set.add(h);
840                  invokeAll(set);
723                assertTrue(f.isDone());
841                  assertEquals(21, f.number);
725                assertTrue(g.isDone());
842                  assertEquals(34, g.number);
727                assertTrue(h.isDone());
843                  assertEquals(13, h.number);
844 +                checkCompletedNormally(f);
845 +                checkCompletedNormally(g);
846 +                checkCompletedNormally(h);
847              }};
848          testInvokeOnPool(mainPool(), a);
849      }
850  
733
851      /**
852       * invokeAll(tasks) with any null task throws NPE
853       */
854      public void testInvokeAllNPE() {
855          RecursiveAction a = new CheckedRecursiveAction() {
856 <            public void realCompute() {
856 >            protected void realCompute() {
857                  AsyncFib f = new AsyncFib(8);
858                  AsyncFib g = new AsyncFib(9);
859                  AsyncFib h = null;
# Line 753 | Line 870 | public class ForkJoinTaskTest extends JS
870       */
871      public void testAbnormalInvokeAll2() {
872          RecursiveAction a = new CheckedRecursiveAction() {
873 <            public void realCompute() {
873 >            protected void realCompute() {
874                  AsyncFib f = new AsyncFib(8);
875                  FailingAsyncFib g = new FailingAsyncFib(9);
876                  try {
877                      invokeAll(f, g);
878                      shouldThrow();
879 <                } catch (FJException success) {}
879 >                } catch (FJException success) {
880 >                    checkCompletedAbnormally(g, success);
881 >                }
882              }};
883          testInvokeOnPool(mainPool(), a);
884      }
# Line 769 | Line 888 | public class ForkJoinTaskTest extends JS
888       */
889      public void testAbnormalInvokeAll1() {
890          RecursiveAction a = new CheckedRecursiveAction() {
891 <            public void realCompute() {
891 >            protected void realCompute() {
892                  FailingAsyncFib g = new FailingAsyncFib(9);
893                  try {
894                      invokeAll(g);
895                      shouldThrow();
896 <                } catch (FJException success) {}
896 >                } catch (FJException success) {
897 >                    checkCompletedAbnormally(g, success);
898 >                }
899              }};
900          testInvokeOnPool(mainPool(), a);
901      }
# Line 784 | Line 905 | public class ForkJoinTaskTest extends JS
905       */
906      public void testAbnormalInvokeAll3() {
907          RecursiveAction a = new CheckedRecursiveAction() {
908 <            public void realCompute() {
908 >            protected void realCompute() {
909                  AsyncFib f = new AsyncFib(8);
910                  FailingAsyncFib g = new FailingAsyncFib(9);
911                  AsyncFib h = new AsyncFib(7);
912                  try {
913                      invokeAll(f, g, h);
914                      shouldThrow();
915 <                } catch (FJException success) {}
915 >                } catch (FJException success) {
916 >                    checkCompletedAbnormally(g, success);
917 >                }
918              }};
919          testInvokeOnPool(mainPool(), a);
920      }
921  
922      /**
923 <     * invokeAll(collection)  throws exception if any task does
923 >     * invokeAll(collection) throws exception if any task does
924       */
925      public void testAbnormalInvokeAllCollection() {
926          RecursiveAction a = new CheckedRecursiveAction() {
927 <            public void realCompute() {
927 >            protected void realCompute() {
928                  FailingAsyncFib f = new FailingAsyncFib(8);
929                  AsyncFib g = new AsyncFib(9);
930                  AsyncFib h = new AsyncFib(7);
# Line 812 | Line 935 | public class ForkJoinTaskTest extends JS
935                  try {
936                      invokeAll(set);
937                      shouldThrow();
938 <                } catch (FJException success) {}
938 >                } catch (FJException success) {
939 >                    checkCompletedAbnormally(f, success);
940 >                }
941              }};
942          testInvokeOnPool(mainPool(), a);
943      }
# Line 823 | Line 948 | public class ForkJoinTaskTest extends JS
948       */
949      public void testTryUnfork() {
950          RecursiveAction a = new CheckedRecursiveAction() {
951 <            public void realCompute() {
951 >            protected void realCompute() {
952                  AsyncFib g = new AsyncFib(9);
953                  assertSame(g, g.fork());
954                  AsyncFib f = new AsyncFib(8);
955                  assertSame(f, f.fork());
956                  assertTrue(f.tryUnfork());
957                  helpQuiesce();
958 <                assertFalse(f.isDone());
959 <                assertTrue(g.isDone());
958 >                checkNotDone(f);
959 >                checkCompletedNormally(g);
960              }};
961          testInvokeOnPool(singletonPool(), a);
962      }
# Line 842 | Line 967 | public class ForkJoinTaskTest extends JS
967       */
968      public void testGetSurplusQueuedTaskCount() {
969          RecursiveAction a = new CheckedRecursiveAction() {
970 <            public void realCompute() {
970 >            protected void realCompute() {
971                  AsyncFib h = new AsyncFib(7);
972                  assertSame(h, h.fork());
973                  AsyncFib g = new AsyncFib(9);
# Line 851 | Line 976 | public class ForkJoinTaskTest extends JS
976                  assertSame(f, f.fork());
977                  assertTrue(getSurplusQueuedTaskCount() > 0);
978                  helpQuiesce();
979 +                assertEquals(0, getSurplusQueuedTaskCount());
980 +                checkCompletedNormally(f);
981 +                checkCompletedNormally(g);
982 +                checkCompletedNormally(h);
983              }};
984          testInvokeOnPool(singletonPool(), a);
985      }
# Line 860 | Line 989 | public class ForkJoinTaskTest extends JS
989       */
990      public void testPeekNextLocalTask() {
991          RecursiveAction a = new CheckedRecursiveAction() {
992 <            public void realCompute() {
992 >            protected void realCompute() {
993                  AsyncFib g = new AsyncFib(9);
994                  assertSame(g, g.fork());
995                  AsyncFib f = new AsyncFib(8);
996                  assertSame(f, f.fork());
997                  assertSame(f, peekNextLocalTask());
998                  assertNull(f.join());
999 <                assertTrue(f.isDone());
999 >                checkCompletedNormally(f);
1000                  helpQuiesce();
1001 +                checkCompletedNormally(g);
1002              }};
1003          testInvokeOnPool(singletonPool(), a);
1004      }
1005  
1006      /**
1007 <     * pollNextLocalTask returns most recent unexecuted task
1008 <     * without executing it
1007 >     * pollNextLocalTask returns most recent unexecuted task without
1008 >     * executing it
1009       */
1010      public void testPollNextLocalTask() {
1011          RecursiveAction a = new CheckedRecursiveAction() {
1012 <            public void realCompute() {
1012 >            protected void realCompute() {
1013                  AsyncFib g = new AsyncFib(9);
1014                  assertSame(g, g.fork());
1015                  AsyncFib f = new AsyncFib(8);
1016                  assertSame(f, f.fork());
1017                  assertSame(f, pollNextLocalTask());
1018                  helpQuiesce();
1019 <                assertFalse(f.isDone());
1019 >                checkNotDone(f);
1020 >                assertEquals(34, g.number);
1021 >                checkCompletedNormally(g);
1022              }};
1023          testInvokeOnPool(singletonPool(), a);
1024      }
1025  
1026      /**
1027 <     * pollTask returns an unexecuted task
896 <     * without executing it
1027 >     * pollTask returns an unexecuted task without executing it
1028       */
1029      public void testPollTask() {
1030          RecursiveAction a = new CheckedRecursiveAction() {
1031 <            public void realCompute() {
1031 >            protected void realCompute() {
1032                  AsyncFib g = new AsyncFib(9);
1033                  assertSame(g, g.fork());
1034                  AsyncFib f = new AsyncFib(8);
1035                  assertSame(f, f.fork());
1036                  assertSame(f, pollTask());
1037                  helpQuiesce();
1038 <                assertFalse(f.isDone());
1039 <                assertTrue(g.isDone());
1038 >                checkNotDone(f);
1039 >                checkCompletedNormally(g);
1040              }};
1041          testInvokeOnPool(singletonPool(), a);
1042      }
# Line 915 | Line 1046 | public class ForkJoinTaskTest extends JS
1046       */
1047      public void testPeekNextLocalTaskAsync() {
1048          RecursiveAction a = new CheckedRecursiveAction() {
1049 <            public void realCompute() {
1049 >            protected void realCompute() {
1050                  AsyncFib g = new AsyncFib(9);
1051                  assertSame(g, g.fork());
1052                  AsyncFib f = new AsyncFib(8);
# Line 923 | Line 1054 | public class ForkJoinTaskTest extends JS
1054                  assertSame(g, peekNextLocalTask());
1055                  assertNull(f.join());
1056                  helpQuiesce();
1057 <                assertTrue(f.isDone());
1057 >                checkCompletedNormally(f);
1058 >                assertEquals(34, g.number);
1059 >                checkCompletedNormally(g);
1060              }};
1061          testInvokeOnPool(asyncSingletonPool(), a);
1062      }
1063  
1064      /**
1065 <     * pollNextLocalTask returns least recent unexecuted task
1066 <     * without executing it, in async mode
1065 >     * pollNextLocalTask returns least recent unexecuted task without
1066 >     * executing it, in async mode
1067       */
1068      public void testPollNextLocalTaskAsync() {
1069          RecursiveAction a = new CheckedRecursiveAction() {
1070 <            public void realCompute() {
1070 >            protected void realCompute() {
1071                  AsyncFib g = new AsyncFib(9);
1072                  assertSame(g, g.fork());
1073                  AsyncFib f = new AsyncFib(8);
1074                  assertSame(f, f.fork());
1075                  assertSame(g, pollNextLocalTask());
1076                  helpQuiesce();
1077 <                assertTrue(f.isDone());
1078 <                assertFalse(g.isDone());
1077 >                assertEquals(21, f.number);
1078 >                checkCompletedNormally(f);
1079 >                checkNotDone(g);
1080              }};
1081          testInvokeOnPool(asyncSingletonPool(), a);
1082      }
1083  
1084      /**
1085 <     * pollTask returns an unexecuted task
1086 <     * without executing it, in async mode
1085 >     * pollTask returns an unexecuted task without executing it, in
1086 >     * async mode
1087       */
1088      public void testPollTaskAsync() {
1089          RecursiveAction a = new CheckedRecursiveAction() {
1090 <            public void realCompute() {
1090 >            protected void realCompute() {
1091                  AsyncFib g = new AsyncFib(9);
1092                  assertSame(g, g.fork());
1093                  AsyncFib f = new AsyncFib(8);
1094                  assertSame(f, f.fork());
1095                  assertSame(g, pollTask());
1096                  helpQuiesce();
1097 <                assertTrue(f.isDone());
1098 <                assertFalse(g.isDone());
1097 >                assertEquals(21, f.number);
1098 >                checkCompletedNormally(f);
1099 >                checkNotDone(g);
1100              }};
1101          testInvokeOnPool(asyncSingletonPool(), a);
1102      }
1103 +
1104 +    // versions for singleton pools
1105 +
1106 +    /**
1107 +     * invoke returns when task completes normally.
1108 +     * isCompletedAbnormally and isCancelled return false for normally
1109 +     * completed tasks; getRawResult returns null.
1110 +     */
1111 +    public void testInvokeSingleton() {
1112 +        RecursiveAction a = new CheckedRecursiveAction() {
1113 +            protected void realCompute() {
1114 +                AsyncFib f = new AsyncFib(8);
1115 +                assertNull(f.invoke());
1116 +                assertEquals(21, f.number);
1117 +                checkCompletedNormally(f);
1118 +            }};
1119 +        testInvokeOnPool(singletonPool(), a);
1120 +    }
1121 +
1122 +    /**
1123 +     * quietlyInvoke task returns when task completes normally.
1124 +     * isCompletedAbnormally and isCancelled return false for normally
1125 +     * completed tasks
1126 +     */
1127 +    public void testQuietlyInvokeSingleton() {
1128 +        RecursiveAction a = new CheckedRecursiveAction() {
1129 +            protected void realCompute() {
1130 +                AsyncFib f = new AsyncFib(8);
1131 +                f.quietlyInvoke();
1132 +                assertEquals(21, f.number);
1133 +                checkCompletedNormally(f);
1134 +            }};
1135 +        testInvokeOnPool(singletonPool(), a);
1136 +    }
1137 +
1138 +    /**
1139 +     * join of a forked task returns when task completes
1140 +     */
1141 +    public void testForkJoinSingleton() {
1142 +        RecursiveAction a = new CheckedRecursiveAction() {
1143 +            protected void realCompute() {
1144 +                AsyncFib f = new AsyncFib(8);
1145 +                assertSame(f, f.fork());
1146 +                assertNull(f.join());
1147 +                assertEquals(21, f.number);
1148 +                checkCompletedNormally(f);
1149 +            }};
1150 +        testInvokeOnPool(singletonPool(), a);
1151 +    }
1152 +
1153 +    /**
1154 +     * get of a forked task returns when task completes
1155 +     */
1156 +    public void testForkGetSingleton() {
1157 +        RecursiveAction a = new CheckedRecursiveAction() {
1158 +            protected void realCompute() throws Exception {
1159 +                AsyncFib f = new AsyncFib(8);
1160 +                assertSame(f, f.fork());
1161 +                assertNull(f.get());
1162 +                assertEquals(21, f.number);
1163 +                checkCompletedNormally(f);
1164 +            }};
1165 +        testInvokeOnPool(singletonPool(), a);
1166 +    }
1167 +
1168 +    /**
1169 +     * timed get of a forked task returns when task completes
1170 +     */
1171 +    public void testForkTimedGetSingleton() {
1172 +        RecursiveAction a = new CheckedRecursiveAction() {
1173 +            protected void realCompute() throws Exception {
1174 +                AsyncFib f = new AsyncFib(8);
1175 +                assertSame(f, f.fork());
1176 +                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1177 +                assertEquals(21, f.number);
1178 +                checkCompletedNormally(f);
1179 +            }};
1180 +        testInvokeOnPool(singletonPool(), a);
1181 +    }
1182 +
1183 +    /**
1184 +     * timed get with null time unit throws NPE
1185 +     */
1186 +    public void testForkTimedGetNPESingleton() {
1187 +        RecursiveAction a = new CheckedRecursiveAction() {
1188 +            protected void realCompute() throws Exception {
1189 +                AsyncFib f = new AsyncFib(8);
1190 +                assertSame(f, f.fork());
1191 +                try {
1192 +                    f.get(5L, null);
1193 +                    shouldThrow();
1194 +                } catch (NullPointerException success) {}
1195 +            }};
1196 +        testInvokeOnPool(singletonPool(), a);
1197 +    }
1198 +
1199 +    /**
1200 +     * quietlyJoin of a forked task returns when task completes
1201 +     */
1202 +    public void testForkQuietlyJoinSingleton() {
1203 +        RecursiveAction a = new CheckedRecursiveAction() {
1204 +            protected void realCompute() {
1205 +                AsyncFib f = new AsyncFib(8);
1206 +                assertSame(f, f.fork());
1207 +                f.quietlyJoin();
1208 +                assertEquals(21, f.number);
1209 +                checkCompletedNormally(f);
1210 +            }};
1211 +        testInvokeOnPool(singletonPool(), a);
1212 +    }
1213 +
1214 +    /**
1215 +     * helpQuiesce returns when tasks are complete.
1216 +     * getQueuedTaskCount returns 0 when quiescent
1217 +     */
1218 +    public void testForkHelpQuiesceSingleton() {
1219 +        RecursiveAction a = new CheckedRecursiveAction() {
1220 +            protected void realCompute() {
1221 +                AsyncFib f = new AsyncFib(8);
1222 +                assertSame(f, f.fork());
1223 +                helpQuiesce();
1224 +                assertEquals(0, getQueuedTaskCount());
1225 +                assertEquals(21, f.number);
1226 +                checkCompletedNormally(f);
1227 +            }};
1228 +        testInvokeOnPool(singletonPool(), a);
1229 +    }
1230 +
1231 +    /**
1232 +     * invoke task throws exception when task completes abnormally
1233 +     */
1234 +    public void testAbnormalInvokeSingleton() {
1235 +        RecursiveAction a = new CheckedRecursiveAction() {
1236 +            protected void realCompute() {
1237 +                FailingAsyncFib f = new FailingAsyncFib(8);
1238 +                try {
1239 +                    f.invoke();
1240 +                    shouldThrow();
1241 +                } catch (FJException success) {
1242 +                    checkCompletedAbnormally(f, success);
1243 +                }
1244 +            }};
1245 +        testInvokeOnPool(singletonPool(), a);
1246 +    }
1247 +
1248 +    /**
1249 +     * quietlyInvoke task returns when task completes abnormally
1250 +     */
1251 +    public void testAbnormalQuietlyInvokeSingleton() {
1252 +        RecursiveAction a = new CheckedRecursiveAction() {
1253 +            protected void realCompute() {
1254 +                FailingAsyncFib f = new FailingAsyncFib(8);
1255 +                f.quietlyInvoke();
1256 +                assertTrue(f.getException() instanceof FJException);
1257 +                checkCompletedAbnormally(f, f.getException());
1258 +            }};
1259 +        testInvokeOnPool(singletonPool(), a);
1260 +    }
1261 +
1262 +    /**
1263 +     * join of a forked task throws exception when task completes abnormally
1264 +     */
1265 +    public void testAbnormalForkJoinSingleton() {
1266 +        RecursiveAction a = new CheckedRecursiveAction() {
1267 +            protected void realCompute() {
1268 +                FailingAsyncFib f = new FailingAsyncFib(8);
1269 +                assertSame(f, f.fork());
1270 +                try {
1271 +                    f.join();
1272 +                    shouldThrow();
1273 +                } catch (FJException success) {
1274 +                    checkCompletedAbnormally(f, success);
1275 +                }
1276 +            }};
1277 +        testInvokeOnPool(singletonPool(), a);
1278 +    }
1279 +
1280 +    /**
1281 +     * get of a forked task throws exception when task completes abnormally
1282 +     */
1283 +    public void testAbnormalForkGetSingleton() {
1284 +        RecursiveAction a = new CheckedRecursiveAction() {
1285 +            protected void realCompute() throws Exception {
1286 +                FailingAsyncFib f = new FailingAsyncFib(8);
1287 +                assertSame(f, f.fork());
1288 +                try {
1289 +                    f.get();
1290 +                    shouldThrow();
1291 +                } catch (ExecutionException success) {
1292 +                    Throwable cause = success.getCause();
1293 +                    assertTrue(cause instanceof FJException);
1294 +                    checkCompletedAbnormally(f, cause);
1295 +                }
1296 +            }};
1297 +        testInvokeOnPool(singletonPool(), a);
1298 +    }
1299 +
1300 +    /**
1301 +     * timed get of a forked task throws exception when task completes abnormally
1302 +     */
1303 +    public void testAbnormalForkTimedGetSingleton() {
1304 +        RecursiveAction a = new CheckedRecursiveAction() {
1305 +            protected void realCompute() throws Exception {
1306 +                FailingAsyncFib f = new FailingAsyncFib(8);
1307 +                assertSame(f, f.fork());
1308 +                try {
1309 +                    f.get(LONG_DELAY_MS, MILLISECONDS);
1310 +                    shouldThrow();
1311 +                } catch (ExecutionException success) {
1312 +                    Throwable cause = success.getCause();
1313 +                    assertTrue(cause instanceof FJException);
1314 +                    checkCompletedAbnormally(f, cause);
1315 +                }
1316 +            }};
1317 +        testInvokeOnPool(singletonPool(), a);
1318 +    }
1319 +
1320 +    /**
1321 +     * quietlyJoin of a forked task returns when task completes abnormally
1322 +     */
1323 +    public void testAbnormalForkQuietlyJoinSingleton() {
1324 +        RecursiveAction a = new CheckedRecursiveAction() {
1325 +            protected void realCompute() {
1326 +                FailingAsyncFib f = new FailingAsyncFib(8);
1327 +                assertSame(f, f.fork());
1328 +                f.quietlyJoin();
1329 +                assertTrue(f.getException() instanceof FJException);
1330 +                checkCompletedAbnormally(f, f.getException());
1331 +            }};
1332 +        testInvokeOnPool(singletonPool(), a);
1333 +    }
1334 +
1335 +    /**
1336 +     * invoke task throws exception when task cancelled
1337 +     */
1338 +    public void testCancelledInvokeSingleton() {
1339 +        RecursiveAction a = new CheckedRecursiveAction() {
1340 +            protected void realCompute() {
1341 +                AsyncFib f = new AsyncFib(8);
1342 +                assertTrue(f.cancel(true));
1343 +                try {
1344 +                    f.invoke();
1345 +                    shouldThrow();
1346 +                } catch (CancellationException success) {
1347 +                    checkCancelled(f);
1348 +                }
1349 +            }};
1350 +        testInvokeOnPool(singletonPool(), a);
1351 +    }
1352 +
1353 +    /**
1354 +     * join of a forked task throws exception when task cancelled
1355 +     */
1356 +    public void testCancelledForkJoinSingleton() {
1357 +        RecursiveAction a = new CheckedRecursiveAction() {
1358 +            protected void realCompute() {
1359 +                AsyncFib f = new AsyncFib(8);
1360 +                assertTrue(f.cancel(true));
1361 +                assertSame(f, f.fork());
1362 +                try {
1363 +                    f.join();
1364 +                    shouldThrow();
1365 +                } catch (CancellationException success) {
1366 +                    checkCancelled(f);
1367 +                }
1368 +            }};
1369 +        testInvokeOnPool(singletonPool(), a);
1370 +    }
1371 +
1372 +    /**
1373 +     * get of a forked task throws exception when task cancelled
1374 +     */
1375 +    public void testCancelledForkGetSingleton() {
1376 +        RecursiveAction a = new CheckedRecursiveAction() {
1377 +            protected void realCompute() throws Exception {
1378 +                AsyncFib f = new AsyncFib(8);
1379 +                assertTrue(f.cancel(true));
1380 +                assertSame(f, f.fork());
1381 +                try {
1382 +                    f.get();
1383 +                    shouldThrow();
1384 +                } catch (CancellationException success) {
1385 +                    checkCancelled(f);
1386 +                }
1387 +            }};
1388 +        testInvokeOnPool(singletonPool(), a);
1389 +    }
1390 +
1391 +    /**
1392 +     * timed get of a forked task throws exception when task cancelled
1393 +     */
1394 +    public void testCancelledForkTimedGetSingleton() throws Exception {
1395 +        RecursiveAction a = new CheckedRecursiveAction() {
1396 +            protected void realCompute() throws Exception {
1397 +                AsyncFib f = new AsyncFib(8);
1398 +                assertTrue(f.cancel(true));
1399 +                assertSame(f, f.fork());
1400 +                try {
1401 +                    f.get(LONG_DELAY_MS, MILLISECONDS);
1402 +                    shouldThrow();
1403 +                } catch (CancellationException success) {
1404 +                    checkCancelled(f);
1405 +                }
1406 +            }};
1407 +        testInvokeOnPool(singletonPool(), a);
1408 +    }
1409 +
1410 +    /**
1411 +     * quietlyJoin of a forked task returns when task cancelled
1412 +     */
1413 +    public void testCancelledForkQuietlyJoinSingleton() {
1414 +        RecursiveAction a = new CheckedRecursiveAction() {
1415 +            protected void realCompute() {
1416 +                AsyncFib f = new AsyncFib(8);
1417 +                assertTrue(f.cancel(true));
1418 +                assertSame(f, f.fork());
1419 +                f.quietlyJoin();
1420 +                checkCancelled(f);
1421 +            }};
1422 +        testInvokeOnPool(singletonPool(), a);
1423 +    }
1424 +
1425 +    /**
1426 +     * invoke task throws exception after invoking completeExceptionally
1427 +     */
1428 +    public void testCompleteExceptionallySingleton() {
1429 +        RecursiveAction a = new CheckedRecursiveAction() {
1430 +            protected void realCompute() {
1431 +                AsyncFib f = new AsyncFib(8);
1432 +                f.completeExceptionally(new FJException());
1433 +                try {
1434 +                    f.invoke();
1435 +                    shouldThrow();
1436 +                } catch (FJException success) {
1437 +                    checkCompletedAbnormally(f, success);
1438 +                }
1439 +            }};
1440 +        testInvokeOnPool(singletonPool(), a);
1441 +    }
1442 +
1443 +    /**
1444 +     * invokeAll(t1, t2) invokes all task arguments
1445 +     */
1446 +    public void testInvokeAll2Singleton() {
1447 +        RecursiveAction a = new CheckedRecursiveAction() {
1448 +            protected void realCompute() {
1449 +                AsyncFib f = new AsyncFib(8);
1450 +                AsyncFib g = new AsyncFib(9);
1451 +                invokeAll(f, g);
1452 +                assertEquals(21, f.number);
1453 +                assertEquals(34, g.number);
1454 +                checkCompletedNormally(f);
1455 +                checkCompletedNormally(g);
1456 +            }};
1457 +        testInvokeOnPool(singletonPool(), a);
1458 +    }
1459 +
1460 +    /**
1461 +     * invokeAll(tasks) with 1 argument invokes task
1462 +     */
1463 +    public void testInvokeAll1Singleton() {
1464 +        RecursiveAction a = new CheckedRecursiveAction() {
1465 +            protected void realCompute() {
1466 +                AsyncFib f = new AsyncFib(8);
1467 +                invokeAll(f);
1468 +                checkCompletedNormally(f);
1469 +                assertEquals(21, f.number);
1470 +            }};
1471 +        testInvokeOnPool(singletonPool(), a);
1472 +    }
1473 +
1474 +    /**
1475 +     * invokeAll(tasks) with > 2 argument invokes tasks
1476 +     */
1477 +    public void testInvokeAll3Singleton() {
1478 +        RecursiveAction a = new CheckedRecursiveAction() {
1479 +            protected void realCompute() {
1480 +                AsyncFib f = new AsyncFib(8);
1481 +                AsyncFib g = new AsyncFib(9);
1482 +                AsyncFib h = new AsyncFib(7);
1483 +                invokeAll(f, g, h);
1484 +                assertEquals(21, f.number);
1485 +                assertEquals(34, g.number);
1486 +                assertEquals(13, h.number);
1487 +                checkCompletedNormally(f);
1488 +                checkCompletedNormally(g);
1489 +                checkCompletedNormally(h);
1490 +            }};
1491 +        testInvokeOnPool(singletonPool(), a);
1492 +    }
1493 +
1494 +    /**
1495 +     * invokeAll(collection) invokes all tasks in the collection
1496 +     */
1497 +    public void testInvokeAllCollectionSingleton() {
1498 +        RecursiveAction a = new CheckedRecursiveAction() {
1499 +            protected void realCompute() {
1500 +                AsyncFib f = new AsyncFib(8);
1501 +                AsyncFib g = new AsyncFib(9);
1502 +                AsyncFib h = new AsyncFib(7);
1503 +                HashSet set = new HashSet();
1504 +                set.add(f);
1505 +                set.add(g);
1506 +                set.add(h);
1507 +                invokeAll(set);
1508 +                assertEquals(21, f.number);
1509 +                assertEquals(34, g.number);
1510 +                assertEquals(13, h.number);
1511 +                checkCompletedNormally(f);
1512 +                checkCompletedNormally(g);
1513 +                checkCompletedNormally(h);
1514 +            }};
1515 +        testInvokeOnPool(singletonPool(), a);
1516 +    }
1517 +
1518 +    /**
1519 +     * invokeAll(tasks) with any null task throws NPE
1520 +     */
1521 +    public void testInvokeAllNPESingleton() {
1522 +        RecursiveAction a = new CheckedRecursiveAction() {
1523 +            protected void realCompute() {
1524 +                AsyncFib f = new AsyncFib(8);
1525 +                AsyncFib g = new AsyncFib(9);
1526 +                AsyncFib h = null;
1527 +                try {
1528 +                    invokeAll(f, g, h);
1529 +                    shouldThrow();
1530 +                } catch (NullPointerException success) {}
1531 +            }};
1532 +        testInvokeOnPool(singletonPool(), a);
1533 +    }
1534 +
1535 +    /**
1536 +     * invokeAll(t1, t2) throw exception if any task does
1537 +     */
1538 +    public void testAbnormalInvokeAll2Singleton() {
1539 +        RecursiveAction a = new CheckedRecursiveAction() {
1540 +            protected void realCompute() {
1541 +                AsyncFib f = new AsyncFib(8);
1542 +                FailingAsyncFib g = new FailingAsyncFib(9);
1543 +                try {
1544 +                    invokeAll(f, g);
1545 +                    shouldThrow();
1546 +                } catch (FJException success) {
1547 +                    checkCompletedAbnormally(g, success);
1548 +                }
1549 +            }};
1550 +        testInvokeOnPool(singletonPool(), a);
1551 +    }
1552 +
1553 +    /**
1554 +     * invokeAll(tasks) with 1 argument throws exception if task does
1555 +     */
1556 +    public void testAbnormalInvokeAll1Singleton() {
1557 +        RecursiveAction a = new CheckedRecursiveAction() {
1558 +            protected void realCompute() {
1559 +                FailingAsyncFib g = new FailingAsyncFib(9);
1560 +                try {
1561 +                    invokeAll(g);
1562 +                    shouldThrow();
1563 +                } catch (FJException success) {
1564 +                    checkCompletedAbnormally(g, success);
1565 +                }
1566 +            }};
1567 +        testInvokeOnPool(singletonPool(), a);
1568 +    }
1569 +
1570 +    /**
1571 +     * invokeAll(tasks) with > 2 argument throws exception if any task does
1572 +     */
1573 +    public void testAbnormalInvokeAll3Singleton() {
1574 +        RecursiveAction a = new CheckedRecursiveAction() {
1575 +            protected void realCompute() {
1576 +                AsyncFib f = new AsyncFib(8);
1577 +                FailingAsyncFib g = new FailingAsyncFib(9);
1578 +                AsyncFib h = new AsyncFib(7);
1579 +                try {
1580 +                    invokeAll(f, g, h);
1581 +                    shouldThrow();
1582 +                } catch (FJException success) {
1583 +                    checkCompletedAbnormally(g, success);
1584 +                }
1585 +            }};
1586 +        testInvokeOnPool(singletonPool(), a);
1587 +    }
1588 +
1589 +    /**
1590 +     * invokeAll(collection) throws exception if any task does
1591 +     */
1592 +    public void testAbnormalInvokeAllCollectionSingleton() {
1593 +        RecursiveAction a = new CheckedRecursiveAction() {
1594 +            protected void realCompute() {
1595 +                FailingAsyncFib f = new FailingAsyncFib(8);
1596 +                AsyncFib g = new AsyncFib(9);
1597 +                AsyncFib h = new AsyncFib(7);
1598 +                HashSet set = new HashSet();
1599 +                set.add(f);
1600 +                set.add(g);
1601 +                set.add(h);
1602 +                try {
1603 +                    invokeAll(set);
1604 +                    shouldThrow();
1605 +                } catch (FJException success) {
1606 +                    checkCompletedAbnormally(f, success);
1607 +                }
1608 +            }};
1609 +        testInvokeOnPool(singletonPool(), a);
1610 +    }
1611 +
1612 +    /**
1613 +     * ForkJoinTask.quietlyComplete returns when task completes
1614 +     * normally without setting a value. The most recent value
1615 +     * established by setRawResult(V) (or null by default) is returned
1616 +     * from invoke.
1617 +     */
1618 +    public void testQuietlyComplete() {
1619 +        RecursiveAction a = new CheckedRecursiveAction() {
1620 +                protected void realCompute() {
1621 +                    AsyncFib f = new AsyncFib(8);
1622 +                    f.quietlyComplete();
1623 +                    assertEquals(8, f.number);
1624 +                    checkCompletedNormally(f);
1625 +                }};
1626 +        testInvokeOnPool(mainPool(), a);
1627 +    }
1628 +
1629   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines