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.22 by dl, Thu Nov 18 11:44:29 2010 UTC vs.
Revision 1.40 by jsr166, Wed Dec 31 19:05:42 2014 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  
# Line 50 | 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 58 | 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 71 | 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  
# Line 215 | Line 351 | public class ForkJoinTaskTest extends JS
351          }
352      }
353  
218
354      static final class FailingAsyncFib extends BinaryAsyncAction {
355          int number;
356          public FailingAsyncFib(int n) {
# Line 247 | 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());
259 <                assertFalse(f.isCancelled());
260 <                assertFalse(f.isCompletedAbnormally());
261 <                assertNull(f.getRawResult());
393 >                checkCompletedNormally(f);
394              }};
395          testInvokeOnPool(mainPool(), a);
396      }
# Line 270 | 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());
278 <                assertFalse(f.isCancelled());
279 <                assertFalse(f.isCompletedAbnormally());
280 <                assertNull(f.getRawResult());
409 >                checkCompletedNormally(f);
410              }};
411          testInvokeOnPool(mainPool(), a);
412      }
# Line 287 | 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());
296 <                assertNull(f.getRawResult());
424 >                checkCompletedNormally(f);
425              }};
426          testInvokeOnPool(mainPool(), a);
427      }
# Line 303 | 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 318 | 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 333 | 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 349 | 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  
362
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);
374                assertTrue(f.isDone());
501                  assertEquals(0, getQueuedTaskCount());
502 +                checkCompletedNormally(f);
503              }};
504          testInvokeOnPool(mainPool(), a);
505      }
506  
380
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 398 | 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 411 | 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 427 | 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 436 | 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());
440 <                    assertTrue(f.isCompletedAbnormally());
441 <                    assertSame(cause.getClass(), f.getException().getClass());
570 >                    checkCompletedAbnormally(f, cause);
571                  }
572              }};
573          testInvokeOnPool(mainPool(), a);
# Line 449 | 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 458 | 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());
462 <                    assertTrue(f.isCompletedAbnormally());
463 <                    assertSame(cause.getClass(), f.getException().getClass());
590 >                    checkCompletedAbnormally(f, cause);
591                  }
592              }};
593          testInvokeOnPool(mainPool(), a);
# Line 471 | 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();
478                assertTrue(f.isDone());
479                assertTrue(f.isCompletedAbnormally());
605                  assertTrue(f.getException() instanceof FJException);
606 +                checkCompletedAbnormally(f, f.getException());
607              }};
608          testInvokeOnPool(mainPool(), a);
609      }
# Line 487 | 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());
498 <                    assertTrue(f.isCancelled());
499 <                    assertTrue(f.isCompletedAbnormally());
500 <                    assertTrue(f.getException() instanceof CancellationException);
623 >                    checkCancelled(f);
624                  }
625              }};
626          testInvokeOnPool(mainPool(), a);
# Line 508 | 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 516 | Line 639 | public class ForkJoinTaskTest extends JS
639                      f.join();
640                      shouldThrow();
641                  } catch (CancellationException success) {
642 <                    assertTrue(f.isDone());
520 <                    assertTrue(f.isCancelled());
521 <                    assertTrue(f.isCompletedAbnormally());
522 <                    assertTrue(f.getException() instanceof CancellationException);
642 >                    checkCancelled(f);
643                  }
644              }};
645          testInvokeOnPool(mainPool(), a);
# Line 530 | 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 538 | Line 658 | public class ForkJoinTaskTest extends JS
658                      f.get();
659                      shouldThrow();
660                  } catch (CancellationException success) {
661 <                    assertTrue(f.isDone());
542 <                    assertTrue(f.isCancelled());
543 <                    assertTrue(f.isCompletedAbnormally());
544 <                    assertTrue(f.getException() instanceof CancellationException);
661 >                    checkCancelled(f);
662                  }
663              }};
664          testInvokeOnPool(mainPool(), a);
# Line 552 | 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 560 | Line 677 | public class ForkJoinTaskTest extends JS
677                      f.get(LONG_DELAY_MS, MILLISECONDS);
678                      shouldThrow();
679                  } catch (CancellationException success) {
680 <                    assertTrue(f.isDone());
564 <                    assertTrue(f.isCancelled());
565 <                    assertTrue(f.isCompletedAbnormally());
566 <                    assertTrue(f.getException() instanceof CancellationException);
680 >                    checkCancelled(f);
681                  }
682              }};
683          testInvokeOnPool(mainPool(), a);
# Line 574 | 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());
583 <                assertTrue(f.isCompletedAbnormally());
584 <                assertTrue(f.isCancelled());
585 <                assertTrue(f.getException() instanceof CancellationException);
696 >                checkCancelled(f);
697              }};
698          testInvokeOnPool(mainPool(), a);
699      }
# Line 593 | 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 604 | 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 615 | 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 626 | 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 637 | 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 648 | 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 664 | 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);
671                assertTrue(f.isDone());
785                  assertEquals(21, f.number);
673                assertTrue(g.isDone());
786                  assertEquals(34, g.number);
787 +                checkCompletedNormally(f);
788 +                checkCompletedNormally(g);
789              }};
790          testInvokeOnPool(mainPool(), a);
791      }
# Line 681 | 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 695 | 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);
703                assertTrue(f.isDone());
817                  assertEquals(21, f.number);
705                assertTrue(g.isDone());
818                  assertEquals(34, g.number);
707                assertTrue(h.isDone());
819                  assertEquals(13, h.number);
820 +                checkCompletedNormally(f);
821 +                checkCompletedNormally(g);
822 +                checkCompletedNormally(h);
823              }};
824          testInvokeOnPool(mainPool(), a);
825      }
# Line 715 | 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 724 | Line 838 | public class ForkJoinTaskTest extends JS
838                  set.add(g);
839                  set.add(h);
840                  invokeAll(set);
727                assertTrue(f.isDone());
841                  assertEquals(21, f.number);
729                assertTrue(g.isDone());
842                  assertEquals(34, g.number);
731                assertTrue(h.isDone());
843                  assertEquals(13, h.number);
844 +                checkCompletedNormally(f);
845 +                checkCompletedNormally(g);
846 +                checkCompletedNormally(h);
847              }};
848          testInvokeOnPool(mainPool(), a);
849      }
850  
737
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 757 | 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 773 | 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 788 | 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 816 | 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 827 | 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 846 | 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 855 | 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 864 | 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
900 <     * 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 919 | 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 927 | 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      }
# Line 975 | Line 1106 | public class ForkJoinTaskTest extends JS
1106      /**
1107       * invoke returns when task completes normally.
1108       * isCompletedAbnormally and isCancelled return false for normally
1109 <     * completed tasks. getRawResult of a RecursiveAction returns null;
1109 >     * completed tasks; getRawResult returns null.
1110       */
1111      public void testInvokeSingleton() {
1112          RecursiveAction a = new CheckedRecursiveAction() {
1113 <            public void realCompute() {
1113 >            protected void realCompute() {
1114                  AsyncFib f = new AsyncFib(8);
1115                  assertNull(f.invoke());
1116                  assertEquals(21, f.number);
1117 <                assertTrue(f.isDone());
987 <                assertFalse(f.isCancelled());
988 <                assertFalse(f.isCompletedAbnormally());
989 <                assertNull(f.getRawResult());
1117 >                checkCompletedNormally(f);
1118              }};
1119          testInvokeOnPool(singletonPool(), a);
1120      }
# Line 998 | Line 1126 | public class ForkJoinTaskTest extends JS
1126       */
1127      public void testQuietlyInvokeSingleton() {
1128          RecursiveAction a = new CheckedRecursiveAction() {
1129 <            public void realCompute() {
1129 >            protected void realCompute() {
1130                  AsyncFib f = new AsyncFib(8);
1131                  f.quietlyInvoke();
1132                  assertEquals(21, f.number);
1133 <                assertTrue(f.isDone());
1006 <                assertFalse(f.isCancelled());
1007 <                assertFalse(f.isCompletedAbnormally());
1008 <                assertNull(f.getRawResult());
1133 >                checkCompletedNormally(f);
1134              }};
1135          testInvokeOnPool(singletonPool(), a);
1136      }
# Line 1015 | Line 1140 | public class ForkJoinTaskTest extends JS
1140       */
1141      public void testForkJoinSingleton() {
1142          RecursiveAction a = new CheckedRecursiveAction() {
1143 <            public void realCompute() {
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 <                assertTrue(f.isDone());
1024 <                assertNull(f.getRawResult());
1148 >                checkCompletedNormally(f);
1149              }};
1150          testInvokeOnPool(singletonPool(), a);
1151      }
# Line 1031 | Line 1155 | public class ForkJoinTaskTest extends JS
1155       */
1156      public void testForkGetSingleton() {
1157          RecursiveAction a = new CheckedRecursiveAction() {
1158 <            public void realCompute() throws Exception {
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 <                assertTrue(f.isDone());
1163 >                checkCompletedNormally(f);
1164              }};
1165          testInvokeOnPool(singletonPool(), a);
1166      }
# Line 1046 | Line 1170 | public class ForkJoinTaskTest extends JS
1170       */
1171      public void testForkTimedGetSingleton() {
1172          RecursiveAction a = new CheckedRecursiveAction() {
1173 <            public void realCompute() throws Exception {
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 <                assertTrue(f.isDone());
1178 >                checkCompletedNormally(f);
1179              }};
1180          testInvokeOnPool(singletonPool(), a);
1181      }
# Line 1061 | Line 1185 | public class ForkJoinTaskTest extends JS
1185       */
1186      public void testForkTimedGetNPESingleton() {
1187          RecursiveAction a = new CheckedRecursiveAction() {
1188 <            public void realCompute() throws Exception {
1188 >            protected void realCompute() throws Exception {
1189                  AsyncFib f = new AsyncFib(8);
1190                  assertSame(f, f.fork());
1191                  try {
# Line 1077 | Line 1201 | public class ForkJoinTaskTest extends JS
1201       */
1202      public void testForkQuietlyJoinSingleton() {
1203          RecursiveAction a = new CheckedRecursiveAction() {
1204 <            public void realCompute() {
1204 >            protected void realCompute() {
1205                  AsyncFib f = new AsyncFib(8);
1206                  assertSame(f, f.fork());
1207                  f.quietlyJoin();
1208                  assertEquals(21, f.number);
1209 <                assertTrue(f.isDone());
1209 >                checkCompletedNormally(f);
1210              }};
1211          testInvokeOnPool(singletonPool(), a);
1212      }
1213  
1090
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 <            public void realCompute() {
1220 >            protected void realCompute() {
1221                  AsyncFib f = new AsyncFib(8);
1222                  assertSame(f, f.fork());
1223 <                f.helpQuiesce();
1101 <                assertEquals(21, f.number);
1102 <                assertTrue(f.isDone());
1223 >                helpQuiesce();
1224                  assertEquals(0, getQueuedTaskCount());
1225 +                assertEquals(21, f.number);
1226 +                checkCompletedNormally(f);
1227              }};
1228          testInvokeOnPool(singletonPool(), a);
1229      }
1230  
1108
1231      /**
1232       * invoke task throws exception when task completes abnormally
1233       */
1234      public void testAbnormalInvokeSingleton() {
1235          RecursiveAction a = new CheckedRecursiveAction() {
1236 <            public void realCompute() {
1236 >            protected void realCompute() {
1237                  FailingAsyncFib f = new FailingAsyncFib(8);
1238                  try {
1239                      f.invoke();
1240                      shouldThrow();
1241 <                } catch (FJException success) {}
1241 >                } catch (FJException success) {
1242 >                    checkCompletedAbnormally(f, success);
1243 >                }
1244              }};
1245          testInvokeOnPool(singletonPool(), a);
1246      }
# Line 1126 | Line 1250 | public class ForkJoinTaskTest extends JS
1250       */
1251      public void testAbnormalQuietlyInvokeSingleton() {
1252          RecursiveAction a = new CheckedRecursiveAction() {
1253 <            public void realCompute() {
1253 >            protected void realCompute() {
1254                  FailingAsyncFib f = new FailingAsyncFib(8);
1255                  f.quietlyInvoke();
1256 <                assertTrue(f.isDone());
1256 >                assertTrue(f.getException() instanceof FJException);
1257 >                checkCompletedAbnormally(f, f.getException());
1258              }};
1259          testInvokeOnPool(singletonPool(), a);
1260      }
# Line 1139 | Line 1264 | public class ForkJoinTaskTest extends JS
1264       */
1265      public void testAbnormalForkJoinSingleton() {
1266          RecursiveAction a = new CheckedRecursiveAction() {
1267 <            public void realCompute() {
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) {}
1273 >                } catch (FJException success) {
1274 >                    checkCompletedAbnormally(f, success);
1275 >                }
1276              }};
1277          testInvokeOnPool(singletonPool(), a);
1278      }
# Line 1155 | Line 1282 | public class ForkJoinTaskTest extends JS
1282       */
1283      public void testAbnormalForkGetSingleton() {
1284          RecursiveAction a = new CheckedRecursiveAction() {
1285 <            public void realCompute() throws Exception {
1285 >            protected void realCompute() throws Exception {
1286                  FailingAsyncFib f = new FailingAsyncFib(8);
1287                  assertSame(f, f.fork());
1288                  try {
# Line 1164 | Line 1291 | public class ForkJoinTaskTest extends JS
1291                  } catch (ExecutionException success) {
1292                      Throwable cause = success.getCause();
1293                      assertTrue(cause instanceof FJException);
1294 <                    assertTrue(f.isDone());
1168 <                    assertTrue(f.isCompletedAbnormally());
1169 <                    assertSame(cause.getClass(), f.getException().getClass());
1294 >                    checkCompletedAbnormally(f, cause);
1295                  }
1296              }};
1297          testInvokeOnPool(singletonPool(), a);
# Line 1177 | Line 1302 | public class ForkJoinTaskTest extends JS
1302       */
1303      public void testAbnormalForkTimedGetSingleton() {
1304          RecursiveAction a = new CheckedRecursiveAction() {
1305 <            public void realCompute() throws Exception {
1305 >            protected void realCompute() throws Exception {
1306                  FailingAsyncFib f = new FailingAsyncFib(8);
1307                  assertSame(f, f.fork());
1308                  try {
# Line 1186 | Line 1311 | public class ForkJoinTaskTest extends JS
1311                  } catch (ExecutionException success) {
1312                      Throwable cause = success.getCause();
1313                      assertTrue(cause instanceof FJException);
1314 <                    assertTrue(f.isDone());
1190 <                    assertTrue(f.isCompletedAbnormally());
1191 <                    assertSame(cause.getClass(), f.getException().getClass());
1314 >                    checkCompletedAbnormally(f, cause);
1315                  }
1316              }};
1317          testInvokeOnPool(singletonPool(), a);
# Line 1199 | Line 1322 | public class ForkJoinTaskTest extends JS
1322       */
1323      public void testAbnormalForkQuietlyJoinSingleton() {
1324          RecursiveAction a = new CheckedRecursiveAction() {
1325 <            public void realCompute() {
1325 >            protected void realCompute() {
1326                  FailingAsyncFib f = new FailingAsyncFib(8);
1327                  assertSame(f, f.fork());
1328                  f.quietlyJoin();
1206                assertTrue(f.isDone());
1207                assertTrue(f.isCompletedAbnormally());
1329                  assertTrue(f.getException() instanceof FJException);
1330 +                checkCompletedAbnormally(f, f.getException());
1331              }};
1332          testInvokeOnPool(singletonPool(), a);
1333      }
# Line 1215 | Line 1337 | public class ForkJoinTaskTest extends JS
1337       */
1338      public void testCancelledInvokeSingleton() {
1339          RecursiveAction a = new CheckedRecursiveAction() {
1340 <            public void realCompute() {
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 <                    assertTrue(f.isDone());
1226 <                    assertTrue(f.isCancelled());
1227 <                    assertTrue(f.isCompletedAbnormally());
1228 <                    assertTrue(f.getException() instanceof CancellationException);
1347 >                    checkCancelled(f);
1348                  }
1349              }};
1350          testInvokeOnPool(singletonPool(), a);
# Line 1236 | Line 1355 | public class ForkJoinTaskTest extends JS
1355       */
1356      public void testCancelledForkJoinSingleton() {
1357          RecursiveAction a = new CheckedRecursiveAction() {
1358 <            public void realCompute() {
1358 >            protected void realCompute() {
1359                  AsyncFib f = new AsyncFib(8);
1360                  assertTrue(f.cancel(true));
1361                  assertSame(f, f.fork());
# Line 1244 | Line 1363 | public class ForkJoinTaskTest extends JS
1363                      f.join();
1364                      shouldThrow();
1365                  } catch (CancellationException success) {
1366 <                    assertTrue(f.isDone());
1248 <                    assertTrue(f.isCancelled());
1249 <                    assertTrue(f.isCompletedAbnormally());
1250 <                    assertTrue(f.getException() instanceof CancellationException);
1366 >                    checkCancelled(f);
1367                  }
1368              }};
1369          testInvokeOnPool(singletonPool(), a);
# Line 1258 | Line 1374 | public class ForkJoinTaskTest extends JS
1374       */
1375      public void testCancelledForkGetSingleton() {
1376          RecursiveAction a = new CheckedRecursiveAction() {
1377 <            public void realCompute() throws Exception {
1377 >            protected void realCompute() throws Exception {
1378                  AsyncFib f = new AsyncFib(8);
1379                  assertTrue(f.cancel(true));
1380                  assertSame(f, f.fork());
# Line 1266 | Line 1382 | public class ForkJoinTaskTest extends JS
1382                      f.get();
1383                      shouldThrow();
1384                  } catch (CancellationException success) {
1385 <                    assertTrue(f.isDone());
1270 <                    assertTrue(f.isCancelled());
1271 <                    assertTrue(f.isCompletedAbnormally());
1272 <                    assertTrue(f.getException() instanceof CancellationException);
1385 >                    checkCancelled(f);
1386                  }
1387              }};
1388          testInvokeOnPool(singletonPool(), a);
# Line 1280 | Line 1393 | public class ForkJoinTaskTest extends JS
1393       */
1394      public void testCancelledForkTimedGetSingleton() throws Exception {
1395          RecursiveAction a = new CheckedRecursiveAction() {
1396 <            public void realCompute() throws Exception {
1396 >            protected void realCompute() throws Exception {
1397                  AsyncFib f = new AsyncFib(8);
1398                  assertTrue(f.cancel(true));
1399                  assertSame(f, f.fork());
# Line 1288 | Line 1401 | public class ForkJoinTaskTest extends JS
1401                      f.get(LONG_DELAY_MS, MILLISECONDS);
1402                      shouldThrow();
1403                  } catch (CancellationException success) {
1404 <                    assertTrue(f.isDone());
1292 <                    assertTrue(f.isCancelled());
1293 <                    assertTrue(f.isCompletedAbnormally());
1294 <                    assertTrue(f.getException() instanceof CancellationException);
1404 >                    checkCancelled(f);
1405                  }
1406              }};
1407          testInvokeOnPool(singletonPool(), a);
# Line 1302 | Line 1412 | public class ForkJoinTaskTest extends JS
1412       */
1413      public void testCancelledForkQuietlyJoinSingleton() {
1414          RecursiveAction a = new CheckedRecursiveAction() {
1415 <            public void realCompute() {
1415 >            protected void realCompute() {
1416                  AsyncFib f = new AsyncFib(8);
1417                  assertTrue(f.cancel(true));
1418                  assertSame(f, f.fork());
1419                  f.quietlyJoin();
1420 <                assertTrue(f.isDone());
1311 <                assertTrue(f.isCompletedAbnormally());
1312 <                assertTrue(f.isCancelled());
1313 <                assertTrue(f.getException() instanceof CancellationException);
1420 >                checkCancelled(f);
1421              }};
1422          testInvokeOnPool(singletonPool(), a);
1423      }
# Line 1320 | Line 1427 | public class ForkJoinTaskTest extends JS
1427       */
1428      public void testCompleteExceptionallySingleton() {
1429          RecursiveAction a = new CheckedRecursiveAction() {
1430 <            public void realCompute() {
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) {}
1436 >                } catch (FJException success) {
1437 >                    checkCompletedAbnormally(f, success);
1438 >                }
1439              }};
1440          testInvokeOnPool(singletonPool(), a);
1441      }
# Line 1336 | Line 1445 | public class ForkJoinTaskTest extends JS
1445       */
1446      public void testInvokeAll2Singleton() {
1447          RecursiveAction a = new CheckedRecursiveAction() {
1448 <            public void realCompute() {
1448 >            protected void realCompute() {
1449                  AsyncFib f = new AsyncFib(8);
1450                  AsyncFib g = new AsyncFib(9);
1451                  invokeAll(f, g);
1343                assertTrue(f.isDone());
1452                  assertEquals(21, f.number);
1345                assertTrue(g.isDone());
1453                  assertEquals(34, g.number);
1454 +                checkCompletedNormally(f);
1455 +                checkCompletedNormally(g);
1456              }};
1457          testInvokeOnPool(singletonPool(), a);
1458      }
# Line 1353 | Line 1462 | public class ForkJoinTaskTest extends JS
1462       */
1463      public void testInvokeAll1Singleton() {
1464          RecursiveAction a = new CheckedRecursiveAction() {
1465 <            public void realCompute() {
1465 >            protected void realCompute() {
1466                  AsyncFib f = new AsyncFib(8);
1467                  invokeAll(f);
1468 <                assertTrue(f.isDone());
1468 >                checkCompletedNormally(f);
1469                  assertEquals(21, f.number);
1470              }};
1471          testInvokeOnPool(singletonPool(), a);
# Line 1367 | Line 1476 | public class ForkJoinTaskTest extends JS
1476       */
1477      public void testInvokeAll3Singleton() {
1478          RecursiveAction a = new CheckedRecursiveAction() {
1479 <            public void realCompute() {
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);
1375                assertTrue(f.isDone());
1484                  assertEquals(21, f.number);
1377                assertTrue(g.isDone());
1485                  assertEquals(34, g.number);
1379                assertTrue(h.isDone());
1486                  assertEquals(13, h.number);
1487 +                checkCompletedNormally(f);
1488 +                checkCompletedNormally(g);
1489 +                checkCompletedNormally(h);
1490              }};
1491          testInvokeOnPool(singletonPool(), a);
1492      }
# Line 1387 | Line 1496 | public class ForkJoinTaskTest extends JS
1496       */
1497      public void testInvokeAllCollectionSingleton() {
1498          RecursiveAction a = new CheckedRecursiveAction() {
1499 <            public void realCompute() {
1499 >            protected void realCompute() {
1500                  AsyncFib f = new AsyncFib(8);
1501                  AsyncFib g = new AsyncFib(9);
1502                  AsyncFib h = new AsyncFib(7);
# Line 1396 | Line 1505 | public class ForkJoinTaskTest extends JS
1505                  set.add(g);
1506                  set.add(h);
1507                  invokeAll(set);
1399                assertTrue(f.isDone());
1508                  assertEquals(21, f.number);
1401                assertTrue(g.isDone());
1509                  assertEquals(34, g.number);
1403                assertTrue(h.isDone());
1510                  assertEquals(13, h.number);
1511 +                checkCompletedNormally(f);
1512 +                checkCompletedNormally(g);
1513 +                checkCompletedNormally(h);
1514              }};
1515          testInvokeOnPool(singletonPool(), a);
1516      }
1517  
1409
1518      /**
1519       * invokeAll(tasks) with any null task throws NPE
1520       */
1521      public void testInvokeAllNPESingleton() {
1522          RecursiveAction a = new CheckedRecursiveAction() {
1523 <            public void realCompute() {
1523 >            protected void realCompute() {
1524                  AsyncFib f = new AsyncFib(8);
1525                  AsyncFib g = new AsyncFib(9);
1526                  AsyncFib h = null;
# Line 1429 | Line 1537 | public class ForkJoinTaskTest extends JS
1537       */
1538      public void testAbnormalInvokeAll2Singleton() {
1539          RecursiveAction a = new CheckedRecursiveAction() {
1540 <            public void realCompute() {
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) {}
1546 >                } catch (FJException success) {
1547 >                    checkCompletedAbnormally(g, success);
1548 >                }
1549              }};
1550          testInvokeOnPool(singletonPool(), a);
1551      }
# Line 1445 | Line 1555 | public class ForkJoinTaskTest extends JS
1555       */
1556      public void testAbnormalInvokeAll1Singleton() {
1557          RecursiveAction a = new CheckedRecursiveAction() {
1558 <            public void realCompute() {
1558 >            protected void realCompute() {
1559                  FailingAsyncFib g = new FailingAsyncFib(9);
1560                  try {
1561                      invokeAll(g);
1562                      shouldThrow();
1563 <                } catch (FJException success) {}
1563 >                } catch (FJException success) {
1564 >                    checkCompletedAbnormally(g, success);
1565 >                }
1566              }};
1567          testInvokeOnPool(singletonPool(), a);
1568      }
# Line 1460 | Line 1572 | public class ForkJoinTaskTest extends JS
1572       */
1573      public void testAbnormalInvokeAll3Singleton() {
1574          RecursiveAction a = new CheckedRecursiveAction() {
1575 <            public void realCompute() {
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) {}
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
1590 >     * invokeAll(collection) throws exception if any task does
1591       */
1592      public void testAbnormalInvokeAllCollectionSingleton() {
1593          RecursiveAction a = new CheckedRecursiveAction() {
1594 <            public void realCompute() {
1594 >            protected void realCompute() {
1595                  FailingAsyncFib f = new FailingAsyncFib(8);
1596                  AsyncFib g = new AsyncFib(9);
1597                  AsyncFib h = new AsyncFib(7);
# Line 1488 | Line 1602 | public class ForkJoinTaskTest extends JS
1602                  try {
1603                      invokeAll(set);
1604                      shouldThrow();
1605 <                } catch (FJException success) {}
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