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.47 by jsr166, Sun Oct 11 15:34:07 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.Arrays;
11 > import java.util.Collections;
12 > import java.util.HashSet;
13 > import java.util.List;
14   import java.util.concurrent.CancellationException;
15 + import java.util.concurrent.ExecutionException;
16   import java.util.concurrent.ForkJoinPool;
17   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.ForkJoinWorkerThread;
18   import java.util.concurrent.RecursiveAction;
19 < import java.util.concurrent.TimeUnit;
19 > import java.util.concurrent.TimeoutException;
20   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
21 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
22 < import java.util.HashSet;
23 < import junit.framework.*;
21 >
22 > import junit.framework.Test;
23 > import junit.framework.TestSuite;
24  
25   public class ForkJoinTaskTest extends JSR166TestCase {
26  
27      public static void main(String[] args) {
28 <        junit.textui.TestRunner.run(suite());
28 >        main(suite(), args);
29      }
30  
31      public static Test suite() {
# Line 44 | Line 51 | public class ForkJoinTaskTest extends JS
51      }
52  
53      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
54 <        try {
54 >        try (PoolCleaner cleaner = cleaner(pool)) {
55              assertFalse(a.isDone());
56              assertFalse(a.isCompletedNormally());
57              assertFalse(a.isCompletedAbnormally());
58              assertFalse(a.isCancelled());
59              assertNull(a.getException());
60 +            assertNull(a.getRawResult());
61  
62              assertNull(pool.invoke(a));
63  
# Line 58 | Line 66 | public class ForkJoinTaskTest extends JS
66              assertFalse(a.isCompletedAbnormally());
67              assertFalse(a.isCancelled());
68              assertNull(a.getException());
69 <        } finally {
70 <            joinPool(pool);
69 >            assertNull(a.getRawResult());
70 >        }
71 >    }
72 >
73 >    void checkNotDone(ForkJoinTask a) {
74 >        assertFalse(a.isDone());
75 >        assertFalse(a.isCompletedNormally());
76 >        assertFalse(a.isCompletedAbnormally());
77 >        assertFalse(a.isCancelled());
78 >        assertNull(a.getException());
79 >        assertNull(a.getRawResult());
80 >
81 >        try {
82 >            a.get(0L, SECONDS);
83 >            shouldThrow();
84 >        } catch (TimeoutException success) {
85 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
86 >    }
87 >
88 >    <T> void checkCompletedNormally(ForkJoinTask<T> a) {
89 >        checkCompletedNormally(a, null);
90 >    }
91 >
92 >    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
93 >        assertTrue(a.isDone());
94 >        assertFalse(a.isCancelled());
95 >        assertTrue(a.isCompletedNormally());
96 >        assertFalse(a.isCompletedAbnormally());
97 >        assertNull(a.getException());
98 >        assertSame(expected, a.getRawResult());
99 >
100 >        {
101 >            Thread.currentThread().interrupt();
102 >            long startTime = System.nanoTime();
103 >            assertSame(expected, a.join());
104 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
105 >            Thread.interrupted();
106 >        }
107 >
108 >        {
109 >            Thread.currentThread().interrupt();
110 >            long startTime = System.nanoTime();
111 >            a.quietlyJoin();        // should be no-op
112 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
113 >            Thread.interrupted();
114          }
115 +
116 +        assertFalse(a.cancel(false));
117 +        assertFalse(a.cancel(true));
118 +        try {
119 +            assertSame(expected, a.get());
120 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
121 +        try {
122 +            assertSame(expected, a.get(5L, SECONDS));
123 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
124 +    }
125 +
126 +    void checkCancelled(ForkJoinTask a) {
127 +        assertTrue(a.isDone());
128 +        assertTrue(a.isCancelled());
129 +        assertFalse(a.isCompletedNormally());
130 +        assertTrue(a.isCompletedAbnormally());
131 +        assertTrue(a.getException() instanceof CancellationException);
132 +        assertNull(a.getRawResult());
133 +        assertTrue(a.cancel(false));
134 +        assertTrue(a.cancel(true));
135 +
136 +        try {
137 +            Thread.currentThread().interrupt();
138 +            a.join();
139 +            shouldThrow();
140 +        } catch (CancellationException success) {
141 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
142 +        Thread.interrupted();
143 +
144 +        {
145 +            long startTime = System.nanoTime();
146 +            a.quietlyJoin();        // should be no-op
147 +            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
148 +        }
149 +
150 +        try {
151 +            a.get();
152 +            shouldThrow();
153 +        } catch (CancellationException success) {
154 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
155 +
156 +        try {
157 +            a.get(5L, SECONDS);
158 +            shouldThrow();
159 +        } catch (CancellationException success) {
160 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
161 +    }
162 +
163 +    void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
164 +        assertTrue(a.isDone());
165 +        assertFalse(a.isCancelled());
166 +        assertFalse(a.isCompletedNormally());
167 +        assertTrue(a.isCompletedAbnormally());
168 +        assertSame(t.getClass(), a.getException().getClass());
169 +        assertNull(a.getRawResult());
170 +        assertFalse(a.cancel(false));
171 +        assertFalse(a.cancel(true));
172 +
173 +        try {
174 +            Thread.currentThread().interrupt();
175 +            a.join();
176 +            shouldThrow();
177 +        } catch (Throwable expected) {
178 +            assertSame(t.getClass(), expected.getClass());
179 +        }
180 +        Thread.interrupted();
181 +
182 +        {
183 +            long startTime = System.nanoTime();
184 +            a.quietlyJoin();        // should be no-op
185 +            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
186 +        }
187 +
188 +        try {
189 +            a.get();
190 +            shouldThrow();
191 +        } catch (ExecutionException success) {
192 +            assertSame(t.getClass(), success.getCause().getClass());
193 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
194 +
195 +        try {
196 +            a.get(5L, SECONDS);
197 +            shouldThrow();
198 +        } catch (ExecutionException success) {
199 +            assertSame(t.getClass(), success.getCause().getClass());
200 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
201      }
202  
203      /*
# Line 71 | Line 208 | public class ForkJoinTaskTest extends JS
208       * differently than supplied Recursive forms.
209       */
210  
211 <    static final class FJException extends RuntimeException {
211 >    public static final class FJException extends RuntimeException {
212          FJException() { super(); }
213      }
214  
# Line 82 | Line 219 | public class ForkJoinTaskTest extends JS
219              AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
220                                                   "controlState");
221  
222 <        private BinaryAsyncAction parent;
222 >        private volatile BinaryAsyncAction parent;
223  
224 <        private BinaryAsyncAction sibling;
224 >        private volatile BinaryAsyncAction sibling;
225  
226          protected BinaryAsyncAction() {
227          }
# Line 119 | Line 256 | public class ForkJoinTaskTest extends JS
256              super.completeExceptionally(ex);
257          }
258  
259 +        public boolean cancel(boolean mayInterruptIfRunning) {
260 +            if (super.cancel(mayInterruptIfRunning)) {
261 +                completeExceptionally(new FJException());
262 +                return true;
263 +            }
264 +            return false;
265 +        }
266 +
267          public final void complete() {
268              BinaryAsyncAction a = this;
269              for (;;) {
# Line 140 | Line 285 | public class ForkJoinTaskTest extends JS
285          }
286  
287          public final void completeExceptionally(Throwable ex) {
288 <            BinaryAsyncAction a = this;
144 <            while (!a.isCompletedAbnormally()) {
288 >            for (BinaryAsyncAction a = this;;) {
289                  a.completeThisExceptionally(ex);
290                  BinaryAsyncAction s = a.sibling;
291 <                if (s != null)
292 <                    s.cancel(false);
293 <                if (!a.onException() || (a = a.parent) == null)
291 >                if (s != null && !s.isDone())
292 >                    s.completeExceptionally(ex);
293 >                if ((a = a.parent) == null)
294                      break;
295              }
296          }
# Line 215 | Line 359 | public class ForkJoinTaskTest extends JS
359          }
360      }
361  
218
362      static final class FailingAsyncFib extends BinaryAsyncAction {
363          int number;
364          public FailingAsyncFib(int n) {
# Line 247 | Line 390 | public class ForkJoinTaskTest extends JS
390      /**
391       * invoke returns when task completes normally.
392       * isCompletedAbnormally and isCancelled return false for normally
393 <     * completed tasks. getRawResult of a RecursiveAction returns null;
393 >     * completed tasks; getRawResult returns null.
394       */
395      public void testInvoke() {
396          RecursiveAction a = new CheckedRecursiveAction() {
397 <            public void realCompute() {
397 >            protected void realCompute() {
398                  AsyncFib f = new AsyncFib(8);
399                  assertNull(f.invoke());
400                  assertEquals(21, f.number);
401 <                assertTrue(f.isDone());
259 <                assertFalse(f.isCancelled());
260 <                assertFalse(f.isCompletedAbnormally());
261 <                assertNull(f.getRawResult());
401 >                checkCompletedNormally(f);
402              }};
403          testInvokeOnPool(mainPool(), a);
404      }
# Line 270 | Line 410 | public class ForkJoinTaskTest extends JS
410       */
411      public void testQuietlyInvoke() {
412          RecursiveAction a = new CheckedRecursiveAction() {
413 <            public void realCompute() {
413 >            protected void realCompute() {
414                  AsyncFib f = new AsyncFib(8);
415                  f.quietlyInvoke();
416                  assertEquals(21, f.number);
417 <                assertTrue(f.isDone());
278 <                assertFalse(f.isCancelled());
279 <                assertFalse(f.isCompletedAbnormally());
280 <                assertNull(f.getRawResult());
417 >                checkCompletedNormally(f);
418              }};
419          testInvokeOnPool(mainPool(), a);
420      }
# Line 287 | Line 424 | public class ForkJoinTaskTest extends JS
424       */
425      public void testForkJoin() {
426          RecursiveAction a = new CheckedRecursiveAction() {
427 <            public void realCompute() {
427 >            protected void realCompute() {
428                  AsyncFib f = new AsyncFib(8);
429                  assertSame(f, f.fork());
430                  assertNull(f.join());
431                  assertEquals(21, f.number);
432 <                assertTrue(f.isDone());
296 <                assertNull(f.getRawResult());
432 >                checkCompletedNormally(f);
433              }};
434          testInvokeOnPool(mainPool(), a);
435      }
# Line 303 | Line 439 | public class ForkJoinTaskTest extends JS
439       */
440      public void testForkGet() {
441          RecursiveAction a = new CheckedRecursiveAction() {
442 <            public void realCompute() throws Exception {
442 >            protected void realCompute() throws Exception {
443                  AsyncFib f = new AsyncFib(8);
444                  assertSame(f, f.fork());
445                  assertNull(f.get());
446                  assertEquals(21, f.number);
447 <                assertTrue(f.isDone());
447 >                checkCompletedNormally(f);
448              }};
449          testInvokeOnPool(mainPool(), a);
450      }
# Line 318 | Line 454 | public class ForkJoinTaskTest extends JS
454       */
455      public void testForkTimedGet() {
456          RecursiveAction a = new CheckedRecursiveAction() {
457 <            public void realCompute() throws Exception {
457 >            protected void realCompute() throws Exception {
458                  AsyncFib f = new AsyncFib(8);
459                  assertSame(f, f.fork());
460                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
461                  assertEquals(21, f.number);
462 <                assertTrue(f.isDone());
462 >                checkCompletedNormally(f);
463              }};
464          testInvokeOnPool(mainPool(), a);
465      }
# Line 333 | Line 469 | public class ForkJoinTaskTest extends JS
469       */
470      public void testForkTimedGetNPE() {
471          RecursiveAction a = new CheckedRecursiveAction() {
472 <            public void realCompute() throws Exception {
472 >            protected void realCompute() throws Exception {
473                  AsyncFib f = new AsyncFib(8);
474                  assertSame(f, f.fork());
475                  try {
# Line 349 | Line 485 | public class ForkJoinTaskTest extends JS
485       */
486      public void testForkQuietlyJoin() {
487          RecursiveAction a = new CheckedRecursiveAction() {
488 <            public void realCompute() {
488 >            protected void realCompute() {
489                  AsyncFib f = new AsyncFib(8);
490                  assertSame(f, f.fork());
491                  f.quietlyJoin();
492                  assertEquals(21, f.number);
493 <                assertTrue(f.isDone());
493 >                checkCompletedNormally(f);
494              }};
495          testInvokeOnPool(mainPool(), a);
496      }
497  
362
498      /**
499       * helpQuiesce returns when tasks are complete.
500       * getQueuedTaskCount returns 0 when quiescent
501       */
502      public void testForkHelpQuiesce() {
503          RecursiveAction a = new CheckedRecursiveAction() {
504 <            public void realCompute() {
504 >            protected void realCompute() {
505                  AsyncFib f = new AsyncFib(8);
506                  assertSame(f, f.fork());
507 <                f.helpQuiesce();
507 >                helpQuiesce();
508                  assertEquals(21, f.number);
374                assertTrue(f.isDone());
509                  assertEquals(0, getQueuedTaskCount());
510 +                checkCompletedNormally(f);
511              }};
512          testInvokeOnPool(mainPool(), a);
513      }
514  
380
515      /**
516       * invoke task throws exception when task completes abnormally
517       */
518      public void testAbnormalInvoke() {
519          RecursiveAction a = new CheckedRecursiveAction() {
520 <            public void realCompute() {
520 >            protected void realCompute() {
521                  FailingAsyncFib f = new FailingAsyncFib(8);
522                  try {
523                      f.invoke();
524                      shouldThrow();
525 <                } catch (FJException success) {}
525 >                } catch (FJException success) {
526 >                    checkCompletedAbnormally(f, success);
527 >                }
528              }};
529          testInvokeOnPool(mainPool(), a);
530      }
# Line 398 | Line 534 | public class ForkJoinTaskTest extends JS
534       */
535      public void testAbnormalQuietlyInvoke() {
536          RecursiveAction a = new CheckedRecursiveAction() {
537 <            public void realCompute() {
537 >            protected void realCompute() {
538                  FailingAsyncFib f = new FailingAsyncFib(8);
539                  f.quietlyInvoke();
540 <                assertTrue(f.isDone());
540 >                assertTrue(f.getException() instanceof FJException);
541 >                checkCompletedAbnormally(f, f.getException());
542              }};
543          testInvokeOnPool(mainPool(), a);
544      }
# Line 411 | Line 548 | public class ForkJoinTaskTest extends JS
548       */
549      public void testAbnormalForkJoin() {
550          RecursiveAction a = new CheckedRecursiveAction() {
551 <            public void realCompute() {
551 >            protected void realCompute() {
552                  FailingAsyncFib f = new FailingAsyncFib(8);
553                  assertSame(f, f.fork());
554                  try {
555                      f.join();
556                      shouldThrow();
557 <                } catch (FJException success) {}
557 >                } catch (FJException success) {
558 >                    checkCompletedAbnormally(f, success);
559 >                }
560              }};
561          testInvokeOnPool(mainPool(), a);
562      }
# Line 427 | Line 566 | public class ForkJoinTaskTest extends JS
566       */
567      public void testAbnormalForkGet() {
568          RecursiveAction a = new CheckedRecursiveAction() {
569 <            public void realCompute() throws Exception {
569 >            protected void realCompute() throws Exception {
570                  FailingAsyncFib f = new FailingAsyncFib(8);
571                  assertSame(f, f.fork());
572                  try {
# Line 436 | Line 575 | public class ForkJoinTaskTest extends JS
575                  } catch (ExecutionException success) {
576                      Throwable cause = success.getCause();
577                      assertTrue(cause instanceof FJException);
578 <                    assertTrue(f.isDone());
440 <                    assertTrue(f.isCompletedAbnormally());
441 <                    assertSame(cause.getClass(), f.getException().getClass());
578 >                    checkCompletedAbnormally(f, cause);
579                  }
580              }};
581          testInvokeOnPool(mainPool(), a);
# Line 449 | Line 586 | public class ForkJoinTaskTest extends JS
586       */
587      public void testAbnormalForkTimedGet() {
588          RecursiveAction a = new CheckedRecursiveAction() {
589 <            public void realCompute() throws Exception {
589 >            protected void realCompute() throws Exception {
590                  FailingAsyncFib f = new FailingAsyncFib(8);
591                  assertSame(f, f.fork());
592                  try {
# Line 458 | Line 595 | public class ForkJoinTaskTest extends JS
595                  } catch (ExecutionException success) {
596                      Throwable cause = success.getCause();
597                      assertTrue(cause instanceof FJException);
598 <                    assertTrue(f.isDone());
462 <                    assertTrue(f.isCompletedAbnormally());
463 <                    assertSame(cause.getClass(), f.getException().getClass());
598 >                    checkCompletedAbnormally(f, cause);
599                  }
600              }};
601          testInvokeOnPool(mainPool(), a);
# Line 471 | Line 606 | public class ForkJoinTaskTest extends JS
606       */
607      public void testAbnormalForkQuietlyJoin() {
608          RecursiveAction a = new CheckedRecursiveAction() {
609 <            public void realCompute() {
609 >            protected void realCompute() {
610                  FailingAsyncFib f = new FailingAsyncFib(8);
611                  assertSame(f, f.fork());
612                  f.quietlyJoin();
478                assertTrue(f.isDone());
479                assertTrue(f.isCompletedAbnormally());
613                  assertTrue(f.getException() instanceof FJException);
614 +                checkCompletedAbnormally(f, f.getException());
615              }};
616          testInvokeOnPool(mainPool(), a);
617      }
# Line 487 | Line 621 | public class ForkJoinTaskTest extends JS
621       */
622      public void testCancelledInvoke() {
623          RecursiveAction a = new CheckedRecursiveAction() {
624 <            public void realCompute() {
624 >            protected void realCompute() {
625                  AsyncFib f = new AsyncFib(8);
626                  assertTrue(f.cancel(true));
627                  try {
628                      f.invoke();
629                      shouldThrow();
630                  } catch (CancellationException success) {
631 <                    assertTrue(f.isDone());
498 <                    assertTrue(f.isCancelled());
499 <                    assertTrue(f.isCompletedAbnormally());
500 <                    assertTrue(f.getException() instanceof CancellationException);
631 >                    checkCancelled(f);
632                  }
633              }};
634          testInvokeOnPool(mainPool(), a);
# Line 508 | Line 639 | public class ForkJoinTaskTest extends JS
639       */
640      public void testCancelledForkJoin() {
641          RecursiveAction a = new CheckedRecursiveAction() {
642 <            public void realCompute() {
642 >            protected void realCompute() {
643                  AsyncFib f = new AsyncFib(8);
644                  assertTrue(f.cancel(true));
645                  assertSame(f, f.fork());
# Line 516 | Line 647 | public class ForkJoinTaskTest extends JS
647                      f.join();
648                      shouldThrow();
649                  } catch (CancellationException success) {
650 <                    assertTrue(f.isDone());
520 <                    assertTrue(f.isCancelled());
521 <                    assertTrue(f.isCompletedAbnormally());
522 <                    assertTrue(f.getException() instanceof CancellationException);
650 >                    checkCancelled(f);
651                  }
652              }};
653          testInvokeOnPool(mainPool(), a);
# Line 530 | Line 658 | public class ForkJoinTaskTest extends JS
658       */
659      public void testCancelledForkGet() {
660          RecursiveAction a = new CheckedRecursiveAction() {
661 <            public void realCompute() throws Exception {
661 >            protected void realCompute() throws Exception {
662                  AsyncFib f = new AsyncFib(8);
663                  assertTrue(f.cancel(true));
664                  assertSame(f, f.fork());
# Line 538 | Line 666 | public class ForkJoinTaskTest extends JS
666                      f.get();
667                      shouldThrow();
668                  } catch (CancellationException success) {
669 <                    assertTrue(f.isDone());
542 <                    assertTrue(f.isCancelled());
543 <                    assertTrue(f.isCompletedAbnormally());
544 <                    assertTrue(f.getException() instanceof CancellationException);
669 >                    checkCancelled(f);
670                  }
671              }};
672          testInvokeOnPool(mainPool(), a);
# Line 552 | Line 677 | public class ForkJoinTaskTest extends JS
677       */
678      public void testCancelledForkTimedGet() throws Exception {
679          RecursiveAction a = new CheckedRecursiveAction() {
680 <            public void realCompute() throws Exception {
680 >            protected void realCompute() throws Exception {
681                  AsyncFib f = new AsyncFib(8);
682                  assertTrue(f.cancel(true));
683                  assertSame(f, f.fork());
# Line 560 | Line 685 | public class ForkJoinTaskTest extends JS
685                      f.get(LONG_DELAY_MS, MILLISECONDS);
686                      shouldThrow();
687                  } catch (CancellationException success) {
688 <                    assertTrue(f.isDone());
564 <                    assertTrue(f.isCancelled());
565 <                    assertTrue(f.isCompletedAbnormally());
566 <                    assertTrue(f.getException() instanceof CancellationException);
688 >                    checkCancelled(f);
689                  }
690              }};
691          testInvokeOnPool(mainPool(), a);
# Line 574 | Line 696 | public class ForkJoinTaskTest extends JS
696       */
697      public void testCancelledForkQuietlyJoin() {
698          RecursiveAction a = new CheckedRecursiveAction() {
699 <            public void realCompute() {
699 >            protected void realCompute() {
700                  AsyncFib f = new AsyncFib(8);
701                  assertTrue(f.cancel(true));
702                  assertSame(f, f.fork());
703                  f.quietlyJoin();
704 <                assertTrue(f.isDone());
583 <                assertTrue(f.isCompletedAbnormally());
584 <                assertTrue(f.isCancelled());
585 <                assertTrue(f.getException() instanceof CancellationException);
704 >                checkCancelled(f);
705              }};
706          testInvokeOnPool(mainPool(), a);
707      }
# Line 593 | Line 712 | public class ForkJoinTaskTest extends JS
712      public void testGetPool() {
713          final ForkJoinPool mainPool = mainPool();
714          RecursiveAction a = new CheckedRecursiveAction() {
715 <            public void realCompute() {
715 >            protected void realCompute() {
716                  assertSame(mainPool, getPool());
717              }};
718          testInvokeOnPool(mainPool, a);
# Line 604 | Line 723 | public class ForkJoinTaskTest extends JS
723       */
724      public void testGetPool2() {
725          RecursiveAction a = new CheckedRecursiveAction() {
726 <            public void realCompute() {
726 >            protected void realCompute() {
727                  assertNull(getPool());
728              }};
729          assertNull(a.invoke());
# Line 615 | Line 734 | public class ForkJoinTaskTest extends JS
734       */
735      public void testInForkJoinPool() {
736          RecursiveAction a = new CheckedRecursiveAction() {
737 <            public void realCompute() {
737 >            protected void realCompute() {
738                  assertTrue(inForkJoinPool());
739              }};
740          testInvokeOnPool(mainPool(), a);
# Line 626 | Line 745 | public class ForkJoinTaskTest extends JS
745       */
746      public void testInForkJoinPool2() {
747          RecursiveAction a = new CheckedRecursiveAction() {
748 <            public void realCompute() {
749 <                assertTrue(!inForkJoinPool());
748 >            protected void realCompute() {
749 >                assertFalse(inForkJoinPool());
750              }};
751          assertNull(a.invoke());
752      }
# Line 637 | Line 756 | public class ForkJoinTaskTest extends JS
756       */
757      public void testSetRawResult() {
758          RecursiveAction a = new CheckedRecursiveAction() {
759 <            public void realCompute() {
759 >            protected void realCompute() {
760                  setRawResult(null);
761 +                assertNull(getRawResult());
762              }};
763          assertNull(a.invoke());
764      }
# Line 648 | Line 768 | public class ForkJoinTaskTest extends JS
768       */
769      public void testCompleteExceptionally() {
770          RecursiveAction a = new CheckedRecursiveAction() {
771 <            public void realCompute() {
771 >            protected void realCompute() {
772                  AsyncFib f = new AsyncFib(8);
773                  f.completeExceptionally(new FJException());
774                  try {
775                      f.invoke();
776                      shouldThrow();
777 <                } catch (FJException success) {}
777 >                } catch (FJException success) {
778 >                    checkCompletedAbnormally(f, success);
779 >                }
780              }};
781          testInvokeOnPool(mainPool(), a);
782      }
# Line 664 | Line 786 | public class ForkJoinTaskTest extends JS
786       */
787      public void testInvokeAll2() {
788          RecursiveAction a = new CheckedRecursiveAction() {
789 <            public void realCompute() {
789 >            protected void realCompute() {
790                  AsyncFib f = new AsyncFib(8);
791                  AsyncFib g = new AsyncFib(9);
792                  invokeAll(f, g);
671                assertTrue(f.isDone());
793                  assertEquals(21, f.number);
673                assertTrue(g.isDone());
794                  assertEquals(34, g.number);
795 +                checkCompletedNormally(f);
796 +                checkCompletedNormally(g);
797              }};
798          testInvokeOnPool(mainPool(), a);
799      }
# Line 681 | Line 803 | public class ForkJoinTaskTest extends JS
803       */
804      public void testInvokeAll1() {
805          RecursiveAction a = new CheckedRecursiveAction() {
806 <            public void realCompute() {
806 >            protected void realCompute() {
807                  AsyncFib f = new AsyncFib(8);
808                  invokeAll(f);
809 <                assertTrue(f.isDone());
809 >                checkCompletedNormally(f);
810                  assertEquals(21, f.number);
811              }};
812          testInvokeOnPool(mainPool(), a);
# Line 695 | Line 817 | public class ForkJoinTaskTest extends JS
817       */
818      public void testInvokeAll3() {
819          RecursiveAction a = new CheckedRecursiveAction() {
820 <            public void realCompute() {
820 >            protected void realCompute() {
821                  AsyncFib f = new AsyncFib(8);
822                  AsyncFib g = new AsyncFib(9);
823                  AsyncFib h = new AsyncFib(7);
824                  invokeAll(f, g, h);
703                assertTrue(f.isDone());
825                  assertEquals(21, f.number);
705                assertTrue(g.isDone());
826                  assertEquals(34, g.number);
707                assertTrue(h.isDone());
827                  assertEquals(13, h.number);
828 +                checkCompletedNormally(f);
829 +                checkCompletedNormally(g);
830 +                checkCompletedNormally(h);
831              }};
832          testInvokeOnPool(mainPool(), a);
833      }
# Line 715 | Line 837 | public class ForkJoinTaskTest extends JS
837       */
838      public void testInvokeAllCollection() {
839          RecursiveAction a = new CheckedRecursiveAction() {
840 <            public void realCompute() {
840 >            protected void realCompute() {
841                  AsyncFib f = new AsyncFib(8);
842                  AsyncFib g = new AsyncFib(9);
843                  AsyncFib h = new AsyncFib(7);
# Line 724 | Line 846 | public class ForkJoinTaskTest extends JS
846                  set.add(g);
847                  set.add(h);
848                  invokeAll(set);
727                assertTrue(f.isDone());
849                  assertEquals(21, f.number);
729                assertTrue(g.isDone());
850                  assertEquals(34, g.number);
731                assertTrue(h.isDone());
851                  assertEquals(13, h.number);
852 +                checkCompletedNormally(f);
853 +                checkCompletedNormally(g);
854 +                checkCompletedNormally(h);
855              }};
856          testInvokeOnPool(mainPool(), a);
857      }
858  
737
859      /**
860       * invokeAll(tasks) with any null task throws NPE
861       */
862      public void testInvokeAllNPE() {
863          RecursiveAction a = new CheckedRecursiveAction() {
864 <            public void realCompute() {
864 >            protected void realCompute() {
865                  AsyncFib f = new AsyncFib(8);
866                  AsyncFib g = new AsyncFib(9);
867                  AsyncFib h = null;
# Line 757 | Line 878 | public class ForkJoinTaskTest extends JS
878       */
879      public void testAbnormalInvokeAll2() {
880          RecursiveAction a = new CheckedRecursiveAction() {
881 <            public void realCompute() {
881 >            protected void realCompute() {
882                  AsyncFib f = new AsyncFib(8);
883                  FailingAsyncFib g = new FailingAsyncFib(9);
884 +                ForkJoinTask[] tasks = { f, g };
885 +                Collections.shuffle(Arrays.asList(tasks));
886                  try {
887 <                    invokeAll(f, g);
887 >                    invokeAll(tasks);
888                      shouldThrow();
889 <                } catch (FJException success) {}
889 >                } catch (FJException success) {
890 >                    checkCompletedAbnormally(g, success);
891 >                }
892              }};
893          testInvokeOnPool(mainPool(), a);
894      }
# Line 773 | Line 898 | public class ForkJoinTaskTest extends JS
898       */
899      public void testAbnormalInvokeAll1() {
900          RecursiveAction a = new CheckedRecursiveAction() {
901 <            public void realCompute() {
901 >            protected void realCompute() {
902                  FailingAsyncFib g = new FailingAsyncFib(9);
903                  try {
904                      invokeAll(g);
905                      shouldThrow();
906 <                } catch (FJException success) {}
906 >                } catch (FJException success) {
907 >                    checkCompletedAbnormally(g, success);
908 >                }
909              }};
910          testInvokeOnPool(mainPool(), a);
911      }
# Line 788 | Line 915 | public class ForkJoinTaskTest extends JS
915       */
916      public void testAbnormalInvokeAll3() {
917          RecursiveAction a = new CheckedRecursiveAction() {
918 <            public void realCompute() {
918 >            protected void realCompute() {
919                  AsyncFib f = new AsyncFib(8);
920                  FailingAsyncFib g = new FailingAsyncFib(9);
921                  AsyncFib h = new AsyncFib(7);
922 +                ForkJoinTask[] tasks = { f, g, h };
923 +                Collections.shuffle(Arrays.asList(tasks));
924                  try {
925 <                    invokeAll(f, g, h);
925 >                    invokeAll(tasks);
926                      shouldThrow();
927 <                } catch (FJException success) {}
927 >                } catch (FJException success) {
928 >                    checkCompletedAbnormally(g, success);
929 >                }
930              }};
931          testInvokeOnPool(mainPool(), a);
932      }
933  
934      /**
935 <     * invokeAll(collection)  throws exception if any task does
935 >     * invokeAll(collection) throws exception if any task does
936       */
937      public void testAbnormalInvokeAllCollection() {
938          RecursiveAction a = new CheckedRecursiveAction() {
939 <            public void realCompute() {
939 >            protected void realCompute() {
940                  FailingAsyncFib f = new FailingAsyncFib(8);
941                  AsyncFib g = new AsyncFib(9);
942                  AsyncFib h = new AsyncFib(7);
943 <                HashSet set = new HashSet();
944 <                set.add(f);
945 <                set.add(g);
815 <                set.add(h);
943 >                ForkJoinTask[] tasks = { f, g, h };
944 >                List taskList = Arrays.asList(tasks);
945 >                Collections.shuffle(taskList);
946                  try {
947 <                    invokeAll(set);
947 >                    invokeAll(taskList);
948                      shouldThrow();
949 <                } catch (FJException success) {}
949 >                } catch (FJException success) {
950 >                    checkCompletedAbnormally(f, success);
951 >                }
952              }};
953          testInvokeOnPool(mainPool(), a);
954      }
# Line 827 | Line 959 | public class ForkJoinTaskTest extends JS
959       */
960      public void testTryUnfork() {
961          RecursiveAction a = new CheckedRecursiveAction() {
962 <            public void realCompute() {
962 >            protected void realCompute() {
963                  AsyncFib g = new AsyncFib(9);
964                  assertSame(g, g.fork());
965                  AsyncFib f = new AsyncFib(8);
966                  assertSame(f, f.fork());
967                  assertTrue(f.tryUnfork());
968                  helpQuiesce();
969 <                assertFalse(f.isDone());
970 <                assertTrue(g.isDone());
969 >                checkNotDone(f);
970 >                checkCompletedNormally(g);
971              }};
972          testInvokeOnPool(singletonPool(), a);
973      }
# Line 846 | Line 978 | public class ForkJoinTaskTest extends JS
978       */
979      public void testGetSurplusQueuedTaskCount() {
980          RecursiveAction a = new CheckedRecursiveAction() {
981 <            public void realCompute() {
981 >            protected void realCompute() {
982                  AsyncFib h = new AsyncFib(7);
983                  assertSame(h, h.fork());
984                  AsyncFib g = new AsyncFib(9);
# Line 855 | Line 987 | public class ForkJoinTaskTest extends JS
987                  assertSame(f, f.fork());
988                  assertTrue(getSurplusQueuedTaskCount() > 0);
989                  helpQuiesce();
990 +                assertEquals(0, getSurplusQueuedTaskCount());
991 +                checkCompletedNormally(f);
992 +                checkCompletedNormally(g);
993 +                checkCompletedNormally(h);
994              }};
995          testInvokeOnPool(singletonPool(), a);
996      }
# Line 864 | Line 1000 | public class ForkJoinTaskTest extends JS
1000       */
1001      public void testPeekNextLocalTask() {
1002          RecursiveAction a = new CheckedRecursiveAction() {
1003 <            public void realCompute() {
1003 >            protected void realCompute() {
1004                  AsyncFib g = new AsyncFib(9);
1005                  assertSame(g, g.fork());
1006                  AsyncFib f = new AsyncFib(8);
1007                  assertSame(f, f.fork());
1008                  assertSame(f, peekNextLocalTask());
1009                  assertNull(f.join());
1010 <                assertTrue(f.isDone());
1010 >                checkCompletedNormally(f);
1011                  helpQuiesce();
1012 +                checkCompletedNormally(g);
1013              }};
1014          testInvokeOnPool(singletonPool(), a);
1015      }
1016  
1017      /**
1018 <     * pollNextLocalTask returns most recent unexecuted task
1019 <     * without executing it
1018 >     * pollNextLocalTask returns most recent unexecuted task without
1019 >     * executing it
1020       */
1021      public void testPollNextLocalTask() {
1022          RecursiveAction a = new CheckedRecursiveAction() {
1023 <            public void realCompute() {
1023 >            protected void realCompute() {
1024                  AsyncFib g = new AsyncFib(9);
1025                  assertSame(g, g.fork());
1026                  AsyncFib f = new AsyncFib(8);
1027                  assertSame(f, f.fork());
1028                  assertSame(f, pollNextLocalTask());
1029                  helpQuiesce();
1030 <                assertFalse(f.isDone());
1030 >                checkNotDone(f);
1031 >                assertEquals(34, g.number);
1032 >                checkCompletedNormally(g);
1033              }};
1034          testInvokeOnPool(singletonPool(), a);
1035      }
1036  
1037      /**
1038 <     * pollTask returns an unexecuted task
900 <     * without executing it
1038 >     * pollTask returns an unexecuted task without executing it
1039       */
1040      public void testPollTask() {
1041          RecursiveAction a = new CheckedRecursiveAction() {
1042 <            public void realCompute() {
1042 >            protected void realCompute() {
1043                  AsyncFib g = new AsyncFib(9);
1044                  assertSame(g, g.fork());
1045                  AsyncFib f = new AsyncFib(8);
1046                  assertSame(f, f.fork());
1047                  assertSame(f, pollTask());
1048                  helpQuiesce();
1049 <                assertFalse(f.isDone());
1050 <                assertTrue(g.isDone());
1049 >                checkNotDone(f);
1050 >                checkCompletedNormally(g);
1051              }};
1052          testInvokeOnPool(singletonPool(), a);
1053      }
# Line 919 | Line 1057 | public class ForkJoinTaskTest extends JS
1057       */
1058      public void testPeekNextLocalTaskAsync() {
1059          RecursiveAction a = new CheckedRecursiveAction() {
1060 <            public void realCompute() {
1060 >            protected void realCompute() {
1061                  AsyncFib g = new AsyncFib(9);
1062                  assertSame(g, g.fork());
1063                  AsyncFib f = new AsyncFib(8);
# Line 927 | Line 1065 | public class ForkJoinTaskTest extends JS
1065                  assertSame(g, peekNextLocalTask());
1066                  assertNull(f.join());
1067                  helpQuiesce();
1068 <                assertTrue(f.isDone());
1068 >                checkCompletedNormally(f);
1069 >                assertEquals(34, g.number);
1070 >                checkCompletedNormally(g);
1071              }};
1072          testInvokeOnPool(asyncSingletonPool(), a);
1073      }
1074  
1075      /**
1076 <     * pollNextLocalTask returns least recent unexecuted task
1077 <     * without executing it, in async mode
1076 >     * pollNextLocalTask returns least recent unexecuted task without
1077 >     * executing it, in async mode
1078       */
1079      public void testPollNextLocalTaskAsync() {
1080          RecursiveAction a = new CheckedRecursiveAction() {
1081 <            public void realCompute() {
1081 >            protected void realCompute() {
1082                  AsyncFib g = new AsyncFib(9);
1083                  assertSame(g, g.fork());
1084                  AsyncFib f = new AsyncFib(8);
1085                  assertSame(f, f.fork());
1086                  assertSame(g, pollNextLocalTask());
1087                  helpQuiesce();
1088 <                assertTrue(f.isDone());
1089 <                assertFalse(g.isDone());
1088 >                assertEquals(21, f.number);
1089 >                checkCompletedNormally(f);
1090 >                checkNotDone(g);
1091              }};
1092          testInvokeOnPool(asyncSingletonPool(), a);
1093      }
1094  
1095      /**
1096 <     * pollTask returns an unexecuted task
1097 <     * without executing it, in async mode
1096 >     * pollTask returns an unexecuted task without executing it, in
1097 >     * async mode
1098       */
1099      public void testPollTaskAsync() {
1100          RecursiveAction a = new CheckedRecursiveAction() {
1101 <            public void realCompute() {
1101 >            protected void realCompute() {
1102                  AsyncFib g = new AsyncFib(9);
1103                  assertSame(g, g.fork());
1104                  AsyncFib f = new AsyncFib(8);
1105                  assertSame(f, f.fork());
1106                  assertSame(g, pollTask());
1107                  helpQuiesce();
1108 <                assertTrue(f.isDone());
1109 <                assertFalse(g.isDone());
1108 >                assertEquals(21, f.number);
1109 >                checkCompletedNormally(f);
1110 >                checkNotDone(g);
1111              }};
1112          testInvokeOnPool(asyncSingletonPool(), a);
1113      }
# Line 975 | Line 1117 | public class ForkJoinTaskTest extends JS
1117      /**
1118       * invoke returns when task completes normally.
1119       * isCompletedAbnormally and isCancelled return false for normally
1120 <     * completed tasks. getRawResult of a RecursiveAction returns null;
1120 >     * completed tasks; getRawResult returns null.
1121       */
1122      public void testInvokeSingleton() {
1123          RecursiveAction a = new CheckedRecursiveAction() {
1124 <            public void realCompute() {
1124 >            protected void realCompute() {
1125                  AsyncFib f = new AsyncFib(8);
1126                  assertNull(f.invoke());
1127                  assertEquals(21, f.number);
1128 <                assertTrue(f.isDone());
987 <                assertFalse(f.isCancelled());
988 <                assertFalse(f.isCompletedAbnormally());
989 <                assertNull(f.getRawResult());
1128 >                checkCompletedNormally(f);
1129              }};
1130          testInvokeOnPool(singletonPool(), a);
1131      }
# Line 998 | Line 1137 | public class ForkJoinTaskTest extends JS
1137       */
1138      public void testQuietlyInvokeSingleton() {
1139          RecursiveAction a = new CheckedRecursiveAction() {
1140 <            public void realCompute() {
1140 >            protected void realCompute() {
1141                  AsyncFib f = new AsyncFib(8);
1142                  f.quietlyInvoke();
1143                  assertEquals(21, f.number);
1144 <                assertTrue(f.isDone());
1006 <                assertFalse(f.isCancelled());
1007 <                assertFalse(f.isCompletedAbnormally());
1008 <                assertNull(f.getRawResult());
1144 >                checkCompletedNormally(f);
1145              }};
1146          testInvokeOnPool(singletonPool(), a);
1147      }
# Line 1015 | Line 1151 | public class ForkJoinTaskTest extends JS
1151       */
1152      public void testForkJoinSingleton() {
1153          RecursiveAction a = new CheckedRecursiveAction() {
1154 <            public void realCompute() {
1154 >            protected void realCompute() {
1155                  AsyncFib f = new AsyncFib(8);
1156                  assertSame(f, f.fork());
1157                  assertNull(f.join());
1158                  assertEquals(21, f.number);
1159 <                assertTrue(f.isDone());
1024 <                assertNull(f.getRawResult());
1159 >                checkCompletedNormally(f);
1160              }};
1161          testInvokeOnPool(singletonPool(), a);
1162      }
# Line 1031 | Line 1166 | public class ForkJoinTaskTest extends JS
1166       */
1167      public void testForkGetSingleton() {
1168          RecursiveAction a = new CheckedRecursiveAction() {
1169 <            public void realCompute() throws Exception {
1169 >            protected void realCompute() throws Exception {
1170                  AsyncFib f = new AsyncFib(8);
1171                  assertSame(f, f.fork());
1172                  assertNull(f.get());
1173                  assertEquals(21, f.number);
1174 <                assertTrue(f.isDone());
1174 >                checkCompletedNormally(f);
1175              }};
1176          testInvokeOnPool(singletonPool(), a);
1177      }
# Line 1046 | Line 1181 | public class ForkJoinTaskTest extends JS
1181       */
1182      public void testForkTimedGetSingleton() {
1183          RecursiveAction a = new CheckedRecursiveAction() {
1184 <            public void realCompute() throws Exception {
1184 >            protected void realCompute() throws Exception {
1185                  AsyncFib f = new AsyncFib(8);
1186                  assertSame(f, f.fork());
1187                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1188                  assertEquals(21, f.number);
1189 <                assertTrue(f.isDone());
1189 >                checkCompletedNormally(f);
1190              }};
1191          testInvokeOnPool(singletonPool(), a);
1192      }
# Line 1061 | Line 1196 | public class ForkJoinTaskTest extends JS
1196       */
1197      public void testForkTimedGetNPESingleton() {
1198          RecursiveAction a = new CheckedRecursiveAction() {
1199 <            public void realCompute() throws Exception {
1199 >            protected void realCompute() throws Exception {
1200                  AsyncFib f = new AsyncFib(8);
1201                  assertSame(f, f.fork());
1202                  try {
# Line 1077 | Line 1212 | public class ForkJoinTaskTest extends JS
1212       */
1213      public void testForkQuietlyJoinSingleton() {
1214          RecursiveAction a = new CheckedRecursiveAction() {
1215 <            public void realCompute() {
1215 >            protected void realCompute() {
1216                  AsyncFib f = new AsyncFib(8);
1217                  assertSame(f, f.fork());
1218                  f.quietlyJoin();
1219                  assertEquals(21, f.number);
1220 <                assertTrue(f.isDone());
1220 >                checkCompletedNormally(f);
1221              }};
1222          testInvokeOnPool(singletonPool(), a);
1223      }
1224  
1090
1225      /**
1226       * helpQuiesce returns when tasks are complete.
1227       * getQueuedTaskCount returns 0 when quiescent
1228       */
1229      public void testForkHelpQuiesceSingleton() {
1230          RecursiveAction a = new CheckedRecursiveAction() {
1231 <            public void realCompute() {
1231 >            protected void realCompute() {
1232                  AsyncFib f = new AsyncFib(8);
1233                  assertSame(f, f.fork());
1234 <                f.helpQuiesce();
1101 <                assertEquals(21, f.number);
1102 <                assertTrue(f.isDone());
1234 >                helpQuiesce();
1235                  assertEquals(0, getQueuedTaskCount());
1236 +                assertEquals(21, f.number);
1237 +                checkCompletedNormally(f);
1238              }};
1239          testInvokeOnPool(singletonPool(), a);
1240      }
1241  
1108
1242      /**
1243       * invoke task throws exception when task completes abnormally
1244       */
1245      public void testAbnormalInvokeSingleton() {
1246          RecursiveAction a = new CheckedRecursiveAction() {
1247 <            public void realCompute() {
1247 >            protected void realCompute() {
1248                  FailingAsyncFib f = new FailingAsyncFib(8);
1249                  try {
1250                      f.invoke();
1251                      shouldThrow();
1252 <                } catch (FJException success) {}
1252 >                } catch (FJException success) {
1253 >                    checkCompletedAbnormally(f, success);
1254 >                }
1255              }};
1256          testInvokeOnPool(singletonPool(), a);
1257      }
# Line 1126 | Line 1261 | public class ForkJoinTaskTest extends JS
1261       */
1262      public void testAbnormalQuietlyInvokeSingleton() {
1263          RecursiveAction a = new CheckedRecursiveAction() {
1264 <            public void realCompute() {
1264 >            protected void realCompute() {
1265                  FailingAsyncFib f = new FailingAsyncFib(8);
1266                  f.quietlyInvoke();
1267 <                assertTrue(f.isDone());
1267 >                assertTrue(f.getException() instanceof FJException);
1268 >                checkCompletedAbnormally(f, f.getException());
1269              }};
1270          testInvokeOnPool(singletonPool(), a);
1271      }
# Line 1139 | Line 1275 | public class ForkJoinTaskTest extends JS
1275       */
1276      public void testAbnormalForkJoinSingleton() {
1277          RecursiveAction a = new CheckedRecursiveAction() {
1278 <            public void realCompute() {
1278 >            protected void realCompute() {
1279                  FailingAsyncFib f = new FailingAsyncFib(8);
1280                  assertSame(f, f.fork());
1281                  try {
1282                      f.join();
1283                      shouldThrow();
1284 <                } catch (FJException success) {}
1284 >                } catch (FJException success) {
1285 >                    checkCompletedAbnormally(f, success);
1286 >                }
1287              }};
1288          testInvokeOnPool(singletonPool(), a);
1289      }
# Line 1155 | Line 1293 | public class ForkJoinTaskTest extends JS
1293       */
1294      public void testAbnormalForkGetSingleton() {
1295          RecursiveAction a = new CheckedRecursiveAction() {
1296 <            public void realCompute() throws Exception {
1296 >            protected void realCompute() throws Exception {
1297                  FailingAsyncFib f = new FailingAsyncFib(8);
1298                  assertSame(f, f.fork());
1299                  try {
# Line 1164 | Line 1302 | public class ForkJoinTaskTest extends JS
1302                  } catch (ExecutionException success) {
1303                      Throwable cause = success.getCause();
1304                      assertTrue(cause instanceof FJException);
1305 <                    assertTrue(f.isDone());
1168 <                    assertTrue(f.isCompletedAbnormally());
1169 <                    assertSame(cause.getClass(), f.getException().getClass());
1305 >                    checkCompletedAbnormally(f, cause);
1306                  }
1307              }};
1308          testInvokeOnPool(singletonPool(), a);
# Line 1177 | Line 1313 | public class ForkJoinTaskTest extends JS
1313       */
1314      public void testAbnormalForkTimedGetSingleton() {
1315          RecursiveAction a = new CheckedRecursiveAction() {
1316 <            public void realCompute() throws Exception {
1316 >            protected void realCompute() throws Exception {
1317                  FailingAsyncFib f = new FailingAsyncFib(8);
1318                  assertSame(f, f.fork());
1319                  try {
# Line 1186 | Line 1322 | public class ForkJoinTaskTest extends JS
1322                  } catch (ExecutionException success) {
1323                      Throwable cause = success.getCause();
1324                      assertTrue(cause instanceof FJException);
1325 <                    assertTrue(f.isDone());
1190 <                    assertTrue(f.isCompletedAbnormally());
1191 <                    assertSame(cause.getClass(), f.getException().getClass());
1325 >                    checkCompletedAbnormally(f, cause);
1326                  }
1327              }};
1328          testInvokeOnPool(singletonPool(), a);
# Line 1199 | Line 1333 | public class ForkJoinTaskTest extends JS
1333       */
1334      public void testAbnormalForkQuietlyJoinSingleton() {
1335          RecursiveAction a = new CheckedRecursiveAction() {
1336 <            public void realCompute() {
1336 >            protected void realCompute() {
1337                  FailingAsyncFib f = new FailingAsyncFib(8);
1338                  assertSame(f, f.fork());
1339                  f.quietlyJoin();
1206                assertTrue(f.isDone());
1207                assertTrue(f.isCompletedAbnormally());
1340                  assertTrue(f.getException() instanceof FJException);
1341 +                checkCompletedAbnormally(f, f.getException());
1342              }};
1343          testInvokeOnPool(singletonPool(), a);
1344      }
# Line 1215 | Line 1348 | public class ForkJoinTaskTest extends JS
1348       */
1349      public void testCancelledInvokeSingleton() {
1350          RecursiveAction a = new CheckedRecursiveAction() {
1351 <            public void realCompute() {
1351 >            protected void realCompute() {
1352                  AsyncFib f = new AsyncFib(8);
1353                  assertTrue(f.cancel(true));
1354                  try {
1355                      f.invoke();
1356                      shouldThrow();
1357                  } catch (CancellationException success) {
1358 <                    assertTrue(f.isDone());
1226 <                    assertTrue(f.isCancelled());
1227 <                    assertTrue(f.isCompletedAbnormally());
1228 <                    assertTrue(f.getException() instanceof CancellationException);
1358 >                    checkCancelled(f);
1359                  }
1360              }};
1361          testInvokeOnPool(singletonPool(), a);
# Line 1236 | Line 1366 | public class ForkJoinTaskTest extends JS
1366       */
1367      public void testCancelledForkJoinSingleton() {
1368          RecursiveAction a = new CheckedRecursiveAction() {
1369 <            public void realCompute() {
1369 >            protected void realCompute() {
1370                  AsyncFib f = new AsyncFib(8);
1371                  assertTrue(f.cancel(true));
1372                  assertSame(f, f.fork());
# Line 1244 | Line 1374 | public class ForkJoinTaskTest extends JS
1374                      f.join();
1375                      shouldThrow();
1376                  } catch (CancellationException success) {
1377 <                    assertTrue(f.isDone());
1248 <                    assertTrue(f.isCancelled());
1249 <                    assertTrue(f.isCompletedAbnormally());
1250 <                    assertTrue(f.getException() instanceof CancellationException);
1377 >                    checkCancelled(f);
1378                  }
1379              }};
1380          testInvokeOnPool(singletonPool(), a);
# Line 1258 | Line 1385 | public class ForkJoinTaskTest extends JS
1385       */
1386      public void testCancelledForkGetSingleton() {
1387          RecursiveAction a = new CheckedRecursiveAction() {
1388 <            public void realCompute() throws Exception {
1388 >            protected void realCompute() throws Exception {
1389                  AsyncFib f = new AsyncFib(8);
1390                  assertTrue(f.cancel(true));
1391                  assertSame(f, f.fork());
# Line 1266 | Line 1393 | public class ForkJoinTaskTest extends JS
1393                      f.get();
1394                      shouldThrow();
1395                  } catch (CancellationException success) {
1396 <                    assertTrue(f.isDone());
1270 <                    assertTrue(f.isCancelled());
1271 <                    assertTrue(f.isCompletedAbnormally());
1272 <                    assertTrue(f.getException() instanceof CancellationException);
1396 >                    checkCancelled(f);
1397                  }
1398              }};
1399          testInvokeOnPool(singletonPool(), a);
# Line 1280 | Line 1404 | public class ForkJoinTaskTest extends JS
1404       */
1405      public void testCancelledForkTimedGetSingleton() throws Exception {
1406          RecursiveAction a = new CheckedRecursiveAction() {
1407 <            public void realCompute() throws Exception {
1407 >            protected void realCompute() throws Exception {
1408                  AsyncFib f = new AsyncFib(8);
1409                  assertTrue(f.cancel(true));
1410                  assertSame(f, f.fork());
# Line 1288 | Line 1412 | public class ForkJoinTaskTest extends JS
1412                      f.get(LONG_DELAY_MS, MILLISECONDS);
1413                      shouldThrow();
1414                  } catch (CancellationException success) {
1415 <                    assertTrue(f.isDone());
1292 <                    assertTrue(f.isCancelled());
1293 <                    assertTrue(f.isCompletedAbnormally());
1294 <                    assertTrue(f.getException() instanceof CancellationException);
1415 >                    checkCancelled(f);
1416                  }
1417              }};
1418          testInvokeOnPool(singletonPool(), a);
# Line 1302 | Line 1423 | public class ForkJoinTaskTest extends JS
1423       */
1424      public void testCancelledForkQuietlyJoinSingleton() {
1425          RecursiveAction a = new CheckedRecursiveAction() {
1426 <            public void realCompute() {
1426 >            protected void realCompute() {
1427                  AsyncFib f = new AsyncFib(8);
1428                  assertTrue(f.cancel(true));
1429                  assertSame(f, f.fork());
1430                  f.quietlyJoin();
1431 <                assertTrue(f.isDone());
1311 <                assertTrue(f.isCompletedAbnormally());
1312 <                assertTrue(f.isCancelled());
1313 <                assertTrue(f.getException() instanceof CancellationException);
1431 >                checkCancelled(f);
1432              }};
1433          testInvokeOnPool(singletonPool(), a);
1434      }
# Line 1320 | Line 1438 | public class ForkJoinTaskTest extends JS
1438       */
1439      public void testCompleteExceptionallySingleton() {
1440          RecursiveAction a = new CheckedRecursiveAction() {
1441 <            public void realCompute() {
1441 >            protected void realCompute() {
1442                  AsyncFib f = new AsyncFib(8);
1443                  f.completeExceptionally(new FJException());
1444                  try {
1445                      f.invoke();
1446                      shouldThrow();
1447 <                } catch (FJException success) {}
1447 >                } catch (FJException success) {
1448 >                    checkCompletedAbnormally(f, success);
1449 >                }
1450              }};
1451          testInvokeOnPool(singletonPool(), a);
1452      }
# Line 1336 | Line 1456 | public class ForkJoinTaskTest extends JS
1456       */
1457      public void testInvokeAll2Singleton() {
1458          RecursiveAction a = new CheckedRecursiveAction() {
1459 <            public void realCompute() {
1459 >            protected void realCompute() {
1460                  AsyncFib f = new AsyncFib(8);
1461                  AsyncFib g = new AsyncFib(9);
1462                  invokeAll(f, g);
1343                assertTrue(f.isDone());
1463                  assertEquals(21, f.number);
1345                assertTrue(g.isDone());
1464                  assertEquals(34, g.number);
1465 +                checkCompletedNormally(f);
1466 +                checkCompletedNormally(g);
1467              }};
1468          testInvokeOnPool(singletonPool(), a);
1469      }
# Line 1353 | Line 1473 | public class ForkJoinTaskTest extends JS
1473       */
1474      public void testInvokeAll1Singleton() {
1475          RecursiveAction a = new CheckedRecursiveAction() {
1476 <            public void realCompute() {
1476 >            protected void realCompute() {
1477                  AsyncFib f = new AsyncFib(8);
1478                  invokeAll(f);
1479 <                assertTrue(f.isDone());
1479 >                checkCompletedNormally(f);
1480                  assertEquals(21, f.number);
1481              }};
1482          testInvokeOnPool(singletonPool(), a);
# Line 1367 | Line 1487 | public class ForkJoinTaskTest extends JS
1487       */
1488      public void testInvokeAll3Singleton() {
1489          RecursiveAction a = new CheckedRecursiveAction() {
1490 <            public void realCompute() {
1490 >            protected void realCompute() {
1491                  AsyncFib f = new AsyncFib(8);
1492                  AsyncFib g = new AsyncFib(9);
1493                  AsyncFib h = new AsyncFib(7);
1494                  invokeAll(f, g, h);
1375                assertTrue(f.isDone());
1495                  assertEquals(21, f.number);
1377                assertTrue(g.isDone());
1496                  assertEquals(34, g.number);
1379                assertTrue(h.isDone());
1497                  assertEquals(13, h.number);
1498 +                checkCompletedNormally(f);
1499 +                checkCompletedNormally(g);
1500 +                checkCompletedNormally(h);
1501              }};
1502          testInvokeOnPool(singletonPool(), a);
1503      }
# Line 1387 | Line 1507 | public class ForkJoinTaskTest extends JS
1507       */
1508      public void testInvokeAllCollectionSingleton() {
1509          RecursiveAction a = new CheckedRecursiveAction() {
1510 <            public void realCompute() {
1510 >            protected void realCompute() {
1511                  AsyncFib f = new AsyncFib(8);
1512                  AsyncFib g = new AsyncFib(9);
1513                  AsyncFib h = new AsyncFib(7);
# Line 1396 | Line 1516 | public class ForkJoinTaskTest extends JS
1516                  set.add(g);
1517                  set.add(h);
1518                  invokeAll(set);
1399                assertTrue(f.isDone());
1519                  assertEquals(21, f.number);
1401                assertTrue(g.isDone());
1520                  assertEquals(34, g.number);
1403                assertTrue(h.isDone());
1521                  assertEquals(13, h.number);
1522 +                checkCompletedNormally(f);
1523 +                checkCompletedNormally(g);
1524 +                checkCompletedNormally(h);
1525              }};
1526          testInvokeOnPool(singletonPool(), a);
1527      }
1528  
1409
1529      /**
1530       * invokeAll(tasks) with any null task throws NPE
1531       */
1532      public void testInvokeAllNPESingleton() {
1533          RecursiveAction a = new CheckedRecursiveAction() {
1534 <            public void realCompute() {
1534 >            protected void realCompute() {
1535                  AsyncFib f = new AsyncFib(8);
1536                  AsyncFib g = new AsyncFib(9);
1537                  AsyncFib h = null;
# Line 1429 | Line 1548 | public class ForkJoinTaskTest extends JS
1548       */
1549      public void testAbnormalInvokeAll2Singleton() {
1550          RecursiveAction a = new CheckedRecursiveAction() {
1551 <            public void realCompute() {
1551 >            protected void realCompute() {
1552                  AsyncFib f = new AsyncFib(8);
1553                  FailingAsyncFib g = new FailingAsyncFib(9);
1554 +                ForkJoinTask[] tasks = { f, g };
1555 +                Collections.shuffle(Arrays.asList(tasks));
1556                  try {
1557 <                    invokeAll(f, g);
1557 >                    invokeAll(tasks);
1558                      shouldThrow();
1559 <                } catch (FJException success) {}
1559 >                } catch (FJException success) {
1560 >                    checkCompletedAbnormally(g, success);
1561 >                }
1562              }};
1563          testInvokeOnPool(singletonPool(), a);
1564      }
# Line 1445 | Line 1568 | public class ForkJoinTaskTest extends JS
1568       */
1569      public void testAbnormalInvokeAll1Singleton() {
1570          RecursiveAction a = new CheckedRecursiveAction() {
1571 <            public void realCompute() {
1571 >            protected void realCompute() {
1572                  FailingAsyncFib g = new FailingAsyncFib(9);
1573                  try {
1574                      invokeAll(g);
1575                      shouldThrow();
1576 <                } catch (FJException success) {}
1576 >                } catch (FJException success) {
1577 >                    checkCompletedAbnormally(g, success);
1578 >                }
1579              }};
1580          testInvokeOnPool(singletonPool(), a);
1581      }
# Line 1460 | Line 1585 | public class ForkJoinTaskTest extends JS
1585       */
1586      public void testAbnormalInvokeAll3Singleton() {
1587          RecursiveAction a = new CheckedRecursiveAction() {
1588 <            public void realCompute() {
1588 >            protected void realCompute() {
1589                  AsyncFib f = new AsyncFib(8);
1590                  FailingAsyncFib g = new FailingAsyncFib(9);
1591                  AsyncFib h = new AsyncFib(7);
1592 +                ForkJoinTask[] tasks = { f, g, h };
1593 +                Collections.shuffle(Arrays.asList(tasks));
1594                  try {
1595 <                    invokeAll(f, g, h);
1595 >                    invokeAll(tasks);
1596                      shouldThrow();
1597 <                } catch (FJException success) {}
1597 >                } catch (FJException success) {
1598 >                    checkCompletedAbnormally(g, success);
1599 >                }
1600              }};
1601          testInvokeOnPool(singletonPool(), a);
1602      }
1603  
1604      /**
1605 <     * invokeAll(collection)  throws exception if any task does
1605 >     * invokeAll(collection) throws exception if any task does
1606       */
1607      public void testAbnormalInvokeAllCollectionSingleton() {
1608          RecursiveAction a = new CheckedRecursiveAction() {
1609 <            public void realCompute() {
1609 >            protected void realCompute() {
1610                  FailingAsyncFib f = new FailingAsyncFib(8);
1611                  AsyncFib g = new AsyncFib(9);
1612                  AsyncFib h = new AsyncFib(7);
1613 <                HashSet set = new HashSet();
1614 <                set.add(f);
1615 <                set.add(g);
1487 <                set.add(h);
1613 >                ForkJoinTask[] tasks = { f, g, h };
1614 >                List taskList = Arrays.asList(tasks);
1615 >                Collections.shuffle(taskList);
1616                  try {
1617 <                    invokeAll(set);
1617 >                    invokeAll(taskList);
1618                      shouldThrow();
1619 <                } catch (FJException success) {}
1619 >                } catch (FJException success) {
1620 >                    checkCompletedAbnormally(f, success);
1621 >                }
1622              }};
1623          testInvokeOnPool(singletonPool(), a);
1624      }
1625  
1626 +    /**
1627 +     * ForkJoinTask.quietlyComplete returns when task completes
1628 +     * normally without setting a value. The most recent value
1629 +     * established by setRawResult(V) (or null by default) is returned
1630 +     * from invoke.
1631 +     */
1632 +    public void testQuietlyComplete() {
1633 +        RecursiveAction a = new CheckedRecursiveAction() {
1634 +                protected void realCompute() {
1635 +                    AsyncFib f = new AsyncFib(8);
1636 +                    f.quietlyComplete();
1637 +                    assertEquals(8, f.number);
1638 +                    checkCompletedNormally(f);
1639 +                }};
1640 +        testInvokeOnPool(mainPool(), a);
1641 +    }
1642 +
1643   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines