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.20 by dl, Sun Oct 24 13:41:17 2010 UTC vs.
Revision 1.52 by jsr166, Mon May 29 19:15:02 2017 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 >
9 > import java.util.Arrays;
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.ExecutionException;
13   import java.util.concurrent.ForkJoinPool;
14   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.ForkJoinWorkerThread;
15   import java.util.concurrent.RecursiveAction;
16 < import java.util.concurrent.TimeUnit;
16 > import java.util.concurrent.TimeoutException;
17   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
18 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
19 < import java.util.HashSet;
20 < import junit.framework.*;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class ForkJoinTaskTest extends JSR166TestCase {
23  
24      public static void main(String[] args) {
25 <        junit.textui.TestRunner.run(suite());
25 >        main(suite(), args);
26      }
27  
28      public static Test suite() {
# Line 26 | Line 30 | public class ForkJoinTaskTest extends JS
30      }
31  
32      // Runs with "mainPool" use > 1 thread. singletonPool tests use 1
33 <    static final int mainPoolSize =
33 >    static final int mainPoolSize =
34          Math.max(2, Runtime.getRuntime().availableProcessors());
35  
36      private static ForkJoinPool mainPool() {
# Line 44 | Line 48 | public class ForkJoinTaskTest extends JS
48      }
49  
50      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
51 <        try {
51 >        try (PoolCleaner cleaner = cleaner(pool)) {
52              assertFalse(a.isDone());
53              assertFalse(a.isCompletedNormally());
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 <        } finally {
67 <            joinPool(pool);
66 >            assertNull(a.getRawResult());
67 >        }
68 >    }
69 >
70 >    void checkNotDone(ForkJoinTask a) {
71 >        assertFalse(a.isDone());
72 >        assertFalse(a.isCompletedNormally());
73 >        assertFalse(a.isCompletedAbnormally());
74 >        assertFalse(a.isCancelled());
75 >        assertNull(a.getException());
76 >        assertNull(a.getRawResult());
77 >
78 >        try {
79 >            a.get(randomExpiredTimeout(), randomTimeUnit());
80 >            shouldThrow();
81 >        } catch (TimeoutException success) {
82 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
83 >    }
84 >
85 >    <T> void checkCompletedNormally(ForkJoinTask<T> a) {
86 >        checkCompletedNormally(a, null);
87 >    }
88 >
89 >    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
90 >        assertTrue(a.isDone());
91 >        assertFalse(a.isCancelled());
92 >        assertTrue(a.isCompletedNormally());
93 >        assertFalse(a.isCompletedAbnormally());
94 >        assertNull(a.getException());
95 >        assertSame(expected, a.getRawResult());
96 >
97 >        {
98 >            Thread.currentThread().interrupt();
99 >            long startTime = System.nanoTime();
100 >            assertSame(expected, a.join());
101 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
102 >            Thread.interrupted();
103 >        }
104 >
105 >        {
106 >            Thread.currentThread().interrupt();
107 >            long startTime = System.nanoTime();
108 >            a.quietlyJoin();        // should be no-op
109 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
110 >            Thread.interrupted();
111 >        }
112 >
113 >        assertFalse(a.cancel(false));
114 >        assertFalse(a.cancel(true));
115 >        try {
116 >            assertSame(expected, a.get());
117 >            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
118 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
119 >    }
120 >
121 >    void checkCancelled(ForkJoinTask a) {
122 >        assertTrue(a.isDone());
123 >        assertTrue(a.isCancelled());
124 >        assertFalse(a.isCompletedNormally());
125 >        assertTrue(a.isCompletedAbnormally());
126 >        assertTrue(a.getException() instanceof CancellationException);
127 >        assertNull(a.getRawResult());
128 >        assertTrue(a.cancel(false));
129 >        assertTrue(a.cancel(true));
130 >
131 >        try {
132 >            Thread.currentThread().interrupt();
133 >            a.join();
134 >            shouldThrow();
135 >        } catch (CancellationException success) {
136 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
137 >        Thread.interrupted();
138 >
139 >        {
140 >            long startTime = System.nanoTime();
141 >            a.quietlyJoin();        // should be no-op
142 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
143 >        }
144 >
145 >        try {
146 >            a.get();
147 >            shouldThrow();
148 >        } catch (CancellationException success) {
149 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
150 >
151 >        try {
152 >            a.get(randomTimeout(), randomTimeUnit());
153 >            shouldThrow();
154 >        } catch (CancellationException success) {
155 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
156 >    }
157 >
158 >    void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
159 >        assertTrue(a.isDone());
160 >        assertFalse(a.isCancelled());
161 >        assertFalse(a.isCompletedNormally());
162 >        assertTrue(a.isCompletedAbnormally());
163 >        assertSame(t.getClass(), a.getException().getClass());
164 >        assertNull(a.getRawResult());
165 >        assertFalse(a.cancel(false));
166 >        assertFalse(a.cancel(true));
167 >
168 >        try {
169 >            Thread.currentThread().interrupt();
170 >            a.join();
171 >            shouldThrow();
172 >        } catch (Throwable expected) {
173 >            assertSame(t.getClass(), expected.getClass());
174 >        }
175 >        Thread.interrupted();
176 >
177 >        {
178 >            long startTime = System.nanoTime();
179 >            a.quietlyJoin();        // should be no-op
180 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
181          }
182 +
183 +        try {
184 +            a.get();
185 +            shouldThrow();
186 +        } catch (ExecutionException success) {
187 +            assertSame(t.getClass(), success.getCause().getClass());
188 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
189 +
190 +        try {
191 +            a.get(randomTimeout(), randomTimeUnit());
192 +            shouldThrow();
193 +        } catch (ExecutionException success) {
194 +            assertSame(t.getClass(), success.getCause().getClass());
195 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
196      }
197  
198      /*
# Line 71 | Line 203 | public class ForkJoinTaskTest extends JS
203       * differently than supplied Recursive forms.
204       */
205  
206 <    static final class FJException extends RuntimeException {
206 >    public static final class FJException extends RuntimeException {
207          FJException() { super(); }
208      }
209  
# Line 82 | Line 214 | public class ForkJoinTaskTest extends JS
214              AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
215                                                   "controlState");
216  
217 <        private BinaryAsyncAction parent;
217 >        private volatile BinaryAsyncAction parent;
218  
219 <        private BinaryAsyncAction sibling;
219 >        private volatile BinaryAsyncAction sibling;
220  
221          protected BinaryAsyncAction() {
222          }
# Line 119 | Line 251 | public class ForkJoinTaskTest extends JS
251              super.completeExceptionally(ex);
252          }
253  
254 +        public boolean cancel(boolean mayInterruptIfRunning) {
255 +            if (super.cancel(mayInterruptIfRunning)) {
256 +                completeExceptionally(new FJException());
257 +                return true;
258 +            }
259 +            return false;
260 +        }
261 +
262          public final void complete() {
263              BinaryAsyncAction a = this;
264              for (;;) {
# Line 140 | Line 280 | public class ForkJoinTaskTest extends JS
280          }
281  
282          public final void completeExceptionally(Throwable ex) {
283 <            BinaryAsyncAction a = this;
144 <            while (!a.isCompletedAbnormally()) {
283 >            for (BinaryAsyncAction a = this;;) {
284                  a.completeThisExceptionally(ex);
285                  BinaryAsyncAction s = a.sibling;
286 <                if (s != null)
287 <                    s.cancel(false);
288 <                if (!a.onException() || (a = a.parent) == null)
286 >                if (s != null && !s.isDone())
287 >                    s.completeExceptionally(ex);
288 >                if ((a = a.parent) == null)
289                      break;
290              }
291          }
# Line 196 | Line 335 | public class ForkJoinTaskTest extends JS
335          public final boolean exec() {
336              AsyncFib f = this;
337              int n = f.number;
338 <            if (n > 1) {
339 <                while (n > 1) {
340 <                    AsyncFib p = f;
341 <                    AsyncFib r = new AsyncFib(n - 2);
342 <                    f = new AsyncFib(--n);
343 <                    p.linkSubtasks(r, f);
205 <                    r.fork();
206 <                }
207 <                f.number = n;
338 >            while (n > 1) {
339 >                AsyncFib p = f;
340 >                AsyncFib r = new AsyncFib(n - 2);
341 >                f = new AsyncFib(--n);
342 >                p.linkSubtasks(r, f);
343 >                r.fork();
344              }
345              f.complete();
346              return false;
# 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 225 | Line 360 | public class ForkJoinTaskTest extends JS
360          public final boolean exec() {
361              FailingAsyncFib f = this;
362              int n = f.number;
363 <            if (n > 1) {
364 <                while (n > 1) {
365 <                    FailingAsyncFib p = f;
366 <                    FailingAsyncFib r = new FailingAsyncFib(n - 2);
367 <                    f = new FailingAsyncFib(--n);
368 <                    p.linkSubtasks(r, f);
234 <                    r.fork();
235 <                }
236 <                f.number = n;
363 >            while (n > 1) {
364 >                FailingAsyncFib p = f;
365 >                FailingAsyncFib r = new FailingAsyncFib(n - 2);
366 >                f = new FailingAsyncFib(--n);
367 >                p.linkSubtasks(r, f);
368 >                r.fork();
369              }
370              f.complete();
371              return false;
# Line 247 | Line 379 | public class ForkJoinTaskTest extends JS
379      /**
380       * invoke returns when task completes normally.
381       * isCompletedAbnormally and isCancelled return false for normally
382 <     * completed tasks. getRawResult of a RecursiveAction returns null;
382 >     * completed tasks; getRawResult returns null.
383       */
384      public void testInvoke() {
385          RecursiveAction a = new CheckedRecursiveAction() {
386 <            public void realCompute() {
386 >            protected void realCompute() {
387                  AsyncFib f = new AsyncFib(8);
388                  assertNull(f.invoke());
389                  assertEquals(21, f.number);
390 <                assertTrue(f.isDone());
259 <                assertFalse(f.isCancelled());
260 <                assertFalse(f.isCompletedAbnormally());
261 <                assertNull(f.getRawResult());
390 >                checkCompletedNormally(f);
391              }};
392          testInvokeOnPool(mainPool(), a);
393      }
# Line 270 | Line 399 | public class ForkJoinTaskTest extends JS
399       */
400      public void testQuietlyInvoke() {
401          RecursiveAction a = new CheckedRecursiveAction() {
402 <            public void realCompute() {
402 >            protected void realCompute() {
403                  AsyncFib f = new AsyncFib(8);
404                  f.quietlyInvoke();
405                  assertEquals(21, f.number);
406 <                assertTrue(f.isDone());
278 <                assertFalse(f.isCancelled());
279 <                assertFalse(f.isCompletedAbnormally());
280 <                assertNull(f.getRawResult());
406 >                checkCompletedNormally(f);
407              }};
408          testInvokeOnPool(mainPool(), a);
409      }
# Line 287 | Line 413 | public class ForkJoinTaskTest extends JS
413       */
414      public void testForkJoin() {
415          RecursiveAction a = new CheckedRecursiveAction() {
416 <            public void realCompute() {
416 >            protected void realCompute() {
417                  AsyncFib f = new AsyncFib(8);
418                  assertSame(f, f.fork());
419                  assertNull(f.join());
420                  assertEquals(21, f.number);
421 <                assertTrue(f.isDone());
296 <                assertNull(f.getRawResult());
421 >                checkCompletedNormally(f);
422              }};
423          testInvokeOnPool(mainPool(), a);
424      }
# Line 303 | Line 428 | public class ForkJoinTaskTest extends JS
428       */
429      public void testForkGet() {
430          RecursiveAction a = new CheckedRecursiveAction() {
431 <            public void realCompute() throws Exception {
431 >            protected void realCompute() throws Exception {
432                  AsyncFib f = new AsyncFib(8);
433                  assertSame(f, f.fork());
434                  assertNull(f.get());
435                  assertEquals(21, f.number);
436 <                assertTrue(f.isDone());
436 >                checkCompletedNormally(f);
437              }};
438          testInvokeOnPool(mainPool(), a);
439      }
# Line 318 | Line 443 | public class ForkJoinTaskTest extends JS
443       */
444      public void testForkTimedGet() {
445          RecursiveAction a = new CheckedRecursiveAction() {
446 <            public void realCompute() throws Exception {
446 >            protected void realCompute() throws Exception {
447                  AsyncFib f = new AsyncFib(8);
448                  assertSame(f, f.fork());
449                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
450                  assertEquals(21, f.number);
451 <                assertTrue(f.isDone());
451 >                checkCompletedNormally(f);
452              }};
453          testInvokeOnPool(mainPool(), a);
454      }
# Line 333 | Line 458 | public class ForkJoinTaskTest extends JS
458       */
459      public void testForkTimedGetNPE() {
460          RecursiveAction a = new CheckedRecursiveAction() {
461 <            public void realCompute() throws Exception {
461 >            protected void realCompute() throws Exception {
462                  AsyncFib f = new AsyncFib(8);
463                  assertSame(f, f.fork());
464                  try {
465 <                    f.get(5L, null);
465 >                    f.get(randomTimeout(), null);
466                      shouldThrow();
467                  } catch (NullPointerException success) {}
468              }};
# Line 349 | Line 474 | public class ForkJoinTaskTest extends JS
474       */
475      public void testForkQuietlyJoin() {
476          RecursiveAction a = new CheckedRecursiveAction() {
477 <            public void realCompute() {
477 >            protected void realCompute() {
478                  AsyncFib f = new AsyncFib(8);
479                  assertSame(f, f.fork());
480                  f.quietlyJoin();
481                  assertEquals(21, f.number);
482 <                assertTrue(f.isDone());
482 >                checkCompletedNormally(f);
483              }};
484          testInvokeOnPool(mainPool(), a);
485      }
486  
362
487      /**
488       * helpQuiesce returns when tasks are complete.
489       * getQueuedTaskCount returns 0 when quiescent
490       */
491      public void testForkHelpQuiesce() {
492          RecursiveAction a = new CheckedRecursiveAction() {
493 <            public void realCompute() {
493 >            protected void realCompute() {
494                  AsyncFib f = new AsyncFib(8);
495                  assertSame(f, f.fork());
496 <                f.helpQuiesce();
496 >                helpQuiesce();
497                  assertEquals(21, f.number);
374                assertTrue(f.isDone());
498                  assertEquals(0, getQueuedTaskCount());
499 +                checkCompletedNormally(f);
500              }};
501          testInvokeOnPool(mainPool(), a);
502      }
503  
380
504      /**
505       * invoke task throws exception when task completes abnormally
506       */
507      public void testAbnormalInvoke() {
508          RecursiveAction a = new CheckedRecursiveAction() {
509 <            public void realCompute() {
509 >            protected void realCompute() {
510                  FailingAsyncFib f = new FailingAsyncFib(8);
511                  try {
512                      f.invoke();
513                      shouldThrow();
514 <                } catch (FJException success) {}
514 >                } catch (FJException success) {
515 >                    checkCompletedAbnormally(f, success);
516 >                }
517              }};
518          testInvokeOnPool(mainPool(), a);
519      }
# Line 398 | Line 523 | public class ForkJoinTaskTest extends JS
523       */
524      public void testAbnormalQuietlyInvoke() {
525          RecursiveAction a = new CheckedRecursiveAction() {
526 <            public void realCompute() {
526 >            protected void realCompute() {
527                  FailingAsyncFib f = new FailingAsyncFib(8);
528                  f.quietlyInvoke();
529 <                assertTrue(f.isDone());
529 >                assertTrue(f.getException() instanceof FJException);
530 >                checkCompletedAbnormally(f, f.getException());
531              }};
532          testInvokeOnPool(mainPool(), a);
533      }
# Line 411 | Line 537 | public class ForkJoinTaskTest extends JS
537       */
538      public void testAbnormalForkJoin() {
539          RecursiveAction a = new CheckedRecursiveAction() {
540 <            public void realCompute() {
540 >            protected void realCompute() {
541                  FailingAsyncFib f = new FailingAsyncFib(8);
542                  assertSame(f, f.fork());
543                  try {
544                      f.join();
545                      shouldThrow();
546 <                } catch (FJException success) {}
546 >                } catch (FJException success) {
547 >                    checkCompletedAbnormally(f, success);
548 >                }
549              }};
550          testInvokeOnPool(mainPool(), a);
551      }
# Line 427 | Line 555 | public class ForkJoinTaskTest extends JS
555       */
556      public void testAbnormalForkGet() {
557          RecursiveAction a = new CheckedRecursiveAction() {
558 <            public void realCompute() throws Exception {
558 >            protected void realCompute() throws Exception {
559                  FailingAsyncFib f = new FailingAsyncFib(8);
560                  assertSame(f, f.fork());
561                  try {
# Line 436 | Line 564 | public class ForkJoinTaskTest extends JS
564                  } catch (ExecutionException success) {
565                      Throwable cause = success.getCause();
566                      assertTrue(cause instanceof FJException);
567 <                    assertTrue(f.isDone());
440 <                    assertTrue(f.isCompletedAbnormally());
441 <                    assertSame(cause, f.getException());
567 >                    checkCompletedAbnormally(f, cause);
568                  }
569              }};
570          testInvokeOnPool(mainPool(), a);
# Line 449 | Line 575 | public class ForkJoinTaskTest extends JS
575       */
576      public void testAbnormalForkTimedGet() {
577          RecursiveAction a = new CheckedRecursiveAction() {
578 <            public void realCompute() throws Exception {
578 >            protected void realCompute() throws Exception {
579                  FailingAsyncFib f = new FailingAsyncFib(8);
580                  assertSame(f, f.fork());
581                  try {
# Line 458 | Line 584 | public class ForkJoinTaskTest extends JS
584                  } catch (ExecutionException success) {
585                      Throwable cause = success.getCause();
586                      assertTrue(cause instanceof FJException);
587 <                    assertTrue(f.isDone());
462 <                    assertTrue(f.isCompletedAbnormally());
463 <                    assertSame(cause, f.getException());
587 >                    checkCompletedAbnormally(f, cause);
588                  }
589              }};
590          testInvokeOnPool(mainPool(), a);
# Line 471 | Line 595 | public class ForkJoinTaskTest extends JS
595       */
596      public void testAbnormalForkQuietlyJoin() {
597          RecursiveAction a = new CheckedRecursiveAction() {
598 <            public void realCompute() {
598 >            protected void realCompute() {
599                  FailingAsyncFib f = new FailingAsyncFib(8);
600                  assertSame(f, f.fork());
601                  f.quietlyJoin();
478                assertTrue(f.isDone());
479                assertTrue(f.isCompletedAbnormally());
602                  assertTrue(f.getException() instanceof FJException);
603 +                checkCompletedAbnormally(f, f.getException());
604              }};
605          testInvokeOnPool(mainPool(), a);
606      }
# Line 487 | Line 610 | public class ForkJoinTaskTest extends JS
610       */
611      public void testCancelledInvoke() {
612          RecursiveAction a = new CheckedRecursiveAction() {
613 <            public void realCompute() {
613 >            protected void realCompute() {
614                  AsyncFib f = new AsyncFib(8);
615                  assertTrue(f.cancel(true));
616                  try {
617                      f.invoke();
618                      shouldThrow();
619                  } catch (CancellationException success) {
620 <                    assertTrue(f.isDone());
498 <                    assertTrue(f.isCancelled());
499 <                    assertTrue(f.isCompletedAbnormally());
500 <                    assertTrue(f.getException() instanceof CancellationException);
620 >                    checkCancelled(f);
621                  }
622              }};
623          testInvokeOnPool(mainPool(), a);
# Line 508 | Line 628 | public class ForkJoinTaskTest extends JS
628       */
629      public void testCancelledForkJoin() {
630          RecursiveAction a = new CheckedRecursiveAction() {
631 <            public void realCompute() {
631 >            protected void realCompute() {
632                  AsyncFib f = new AsyncFib(8);
633                  assertTrue(f.cancel(true));
634                  assertSame(f, f.fork());
# Line 516 | Line 636 | public class ForkJoinTaskTest extends JS
636                      f.join();
637                      shouldThrow();
638                  } catch (CancellationException success) {
639 <                    assertTrue(f.isDone());
520 <                    assertTrue(f.isCancelled());
521 <                    assertTrue(f.isCompletedAbnormally());
522 <                    assertTrue(f.getException() instanceof CancellationException);
639 >                    checkCancelled(f);
640                  }
641              }};
642          testInvokeOnPool(mainPool(), a);
# Line 530 | Line 647 | public class ForkJoinTaskTest extends JS
647       */
648      public void testCancelledForkGet() {
649          RecursiveAction a = new CheckedRecursiveAction() {
650 <            public void realCompute() throws Exception {
650 >            protected void realCompute() throws Exception {
651                  AsyncFib f = new AsyncFib(8);
652                  assertTrue(f.cancel(true));
653                  assertSame(f, f.fork());
# Line 538 | Line 655 | public class ForkJoinTaskTest extends JS
655                      f.get();
656                      shouldThrow();
657                  } catch (CancellationException success) {
658 <                    assertTrue(f.isDone());
542 <                    assertTrue(f.isCancelled());
543 <                    assertTrue(f.isCompletedAbnormally());
544 <                    assertTrue(f.getException() instanceof CancellationException);
658 >                    checkCancelled(f);
659                  }
660              }};
661          testInvokeOnPool(mainPool(), a);
# Line 552 | Line 666 | public class ForkJoinTaskTest extends JS
666       */
667      public void testCancelledForkTimedGet() throws Exception {
668          RecursiveAction a = new CheckedRecursiveAction() {
669 <            public void realCompute() throws Exception {
669 >            protected void realCompute() throws Exception {
670                  AsyncFib f = new AsyncFib(8);
671                  assertTrue(f.cancel(true));
672                  assertSame(f, f.fork());
# Line 560 | Line 674 | public class ForkJoinTaskTest extends JS
674                      f.get(LONG_DELAY_MS, MILLISECONDS);
675                      shouldThrow();
676                  } catch (CancellationException success) {
677 <                    assertTrue(f.isDone());
564 <                    assertTrue(f.isCancelled());
565 <                    assertTrue(f.isCompletedAbnormally());
566 <                    assertTrue(f.getException() instanceof CancellationException);
677 >                    checkCancelled(f);
678                  }
679              }};
680          testInvokeOnPool(mainPool(), a);
# Line 574 | Line 685 | public class ForkJoinTaskTest extends JS
685       */
686      public void testCancelledForkQuietlyJoin() {
687          RecursiveAction a = new CheckedRecursiveAction() {
688 <            public void realCompute() {
688 >            protected void realCompute() {
689                  AsyncFib f = new AsyncFib(8);
690                  assertTrue(f.cancel(true));
691                  assertSame(f, f.fork());
692                  f.quietlyJoin();
693 <                assertTrue(f.isDone());
583 <                assertTrue(f.isCompletedAbnormally());
584 <                assertTrue(f.isCancelled());
585 <                assertTrue(f.getException() instanceof CancellationException);
693 >                checkCancelled(f);
694              }};
695          testInvokeOnPool(mainPool(), a);
696      }
# Line 593 | Line 701 | public class ForkJoinTaskTest extends JS
701      public void testGetPool() {
702          final ForkJoinPool mainPool = mainPool();
703          RecursiveAction a = new CheckedRecursiveAction() {
704 <            public void realCompute() {
704 >            protected void realCompute() {
705                  assertSame(mainPool, getPool());
706              }};
707          testInvokeOnPool(mainPool, a);
# Line 604 | Line 712 | public class ForkJoinTaskTest extends JS
712       */
713      public void testGetPool2() {
714          RecursiveAction a = new CheckedRecursiveAction() {
715 <            public void realCompute() {
715 >            protected void realCompute() {
716                  assertNull(getPool());
717              }};
718          assertNull(a.invoke());
# Line 615 | Line 723 | public class ForkJoinTaskTest extends JS
723       */
724      public void testInForkJoinPool() {
725          RecursiveAction a = new CheckedRecursiveAction() {
726 <            public void realCompute() {
726 >            protected void realCompute() {
727                  assertTrue(inForkJoinPool());
728              }};
729          testInvokeOnPool(mainPool(), a);
# Line 626 | Line 734 | public class ForkJoinTaskTest extends JS
734       */
735      public void testInForkJoinPool2() {
736          RecursiveAction a = new CheckedRecursiveAction() {
737 <            public void realCompute() {
738 <                assertTrue(!inForkJoinPool());
737 >            protected void realCompute() {
738 >                assertFalse(inForkJoinPool());
739              }};
740          assertNull(a.invoke());
741      }
# Line 637 | Line 745 | public class ForkJoinTaskTest extends JS
745       */
746      public void testSetRawResult() {
747          RecursiveAction a = new CheckedRecursiveAction() {
748 <            public void realCompute() {
748 >            protected void realCompute() {
749                  setRawResult(null);
750 +                assertNull(getRawResult());
751              }};
752          assertNull(a.invoke());
753      }
# Line 648 | Line 757 | public class ForkJoinTaskTest extends JS
757       */
758      public void testCompleteExceptionally() {
759          RecursiveAction a = new CheckedRecursiveAction() {
760 <            public void realCompute() {
760 >            protected void realCompute() {
761                  AsyncFib f = new AsyncFib(8);
762                  f.completeExceptionally(new FJException());
763                  try {
764                      f.invoke();
765                      shouldThrow();
766 <                } catch (FJException success) {}
766 >                } catch (FJException success) {
767 >                    checkCompletedAbnormally(f, success);
768 >                }
769 >            }};
770 >        testInvokeOnPool(mainPool(), a);
771 >    }
772 >
773 >    /**
774 >     * completeExceptionally(null) surprisingly has the same effect as
775 >     * completeExceptionally(new RuntimeException())
776 >     */
777 >    public void testCompleteExceptionally_null() {
778 >        RecursiveAction a = new CheckedRecursiveAction() {
779 >            protected void realCompute() {
780 >                AsyncFib f = new AsyncFib(8);
781 >                f.completeExceptionally(null);
782 >                try {
783 >                    f.invoke();
784 >                    shouldThrow();
785 >                } catch (RuntimeException success) {
786 >                    assertSame(success.getClass(), RuntimeException.class);
787 >                    assertNull(success.getCause());
788 >                    checkCompletedAbnormally(f, success);
789 >                }
790              }};
791          testInvokeOnPool(mainPool(), a);
792      }
# Line 664 | Line 796 | public class ForkJoinTaskTest extends JS
796       */
797      public void testInvokeAll2() {
798          RecursiveAction a = new CheckedRecursiveAction() {
799 <            public void realCompute() {
799 >            protected void realCompute() {
800                  AsyncFib f = new AsyncFib(8);
801                  AsyncFib g = new AsyncFib(9);
802                  invokeAll(f, g);
671                assertTrue(f.isDone());
803                  assertEquals(21, f.number);
673                assertTrue(g.isDone());
804                  assertEquals(34, g.number);
805 +                checkCompletedNormally(f);
806 +                checkCompletedNormally(g);
807              }};
808          testInvokeOnPool(mainPool(), a);
809      }
# Line 681 | Line 813 | public class ForkJoinTaskTest extends JS
813       */
814      public void testInvokeAll1() {
815          RecursiveAction a = new CheckedRecursiveAction() {
816 <            public void realCompute() {
816 >            protected void realCompute() {
817                  AsyncFib f = new AsyncFib(8);
818                  invokeAll(f);
819 <                assertTrue(f.isDone());
819 >                checkCompletedNormally(f);
820                  assertEquals(21, f.number);
821              }};
822          testInvokeOnPool(mainPool(), a);
# Line 695 | Line 827 | public class ForkJoinTaskTest extends JS
827       */
828      public void testInvokeAll3() {
829          RecursiveAction a = new CheckedRecursiveAction() {
830 <            public void realCompute() {
830 >            protected void realCompute() {
831                  AsyncFib f = new AsyncFib(8);
832                  AsyncFib g = new AsyncFib(9);
833                  AsyncFib h = new AsyncFib(7);
834                  invokeAll(f, g, h);
703                assertTrue(f.isDone());
835                  assertEquals(21, f.number);
705                assertTrue(g.isDone());
836                  assertEquals(34, g.number);
707                assertTrue(h.isDone());
837                  assertEquals(13, h.number);
838 +                checkCompletedNormally(f);
839 +                checkCompletedNormally(g);
840 +                checkCompletedNormally(h);
841              }};
842          testInvokeOnPool(mainPool(), a);
843      }
# Line 715 | Line 847 | public class ForkJoinTaskTest extends JS
847       */
848      public void testInvokeAllCollection() {
849          RecursiveAction a = new CheckedRecursiveAction() {
850 <            public void realCompute() {
850 >            protected void realCompute() {
851                  AsyncFib f = new AsyncFib(8);
852                  AsyncFib g = new AsyncFib(9);
853                  AsyncFib h = new AsyncFib(7);
# Line 724 | Line 856 | public class ForkJoinTaskTest extends JS
856                  set.add(g);
857                  set.add(h);
858                  invokeAll(set);
727                assertTrue(f.isDone());
859                  assertEquals(21, f.number);
729                assertTrue(g.isDone());
860                  assertEquals(34, g.number);
731                assertTrue(h.isDone());
861                  assertEquals(13, h.number);
862 +                checkCompletedNormally(f);
863 +                checkCompletedNormally(g);
864 +                checkCompletedNormally(h);
865              }};
866          testInvokeOnPool(mainPool(), a);
867      }
868  
737
869      /**
870       * invokeAll(tasks) with any null task throws NPE
871       */
872      public void testInvokeAllNPE() {
873          RecursiveAction a = new CheckedRecursiveAction() {
874 <            public void realCompute() {
874 >            protected void realCompute() {
875                  AsyncFib f = new AsyncFib(8);
876                  AsyncFib g = new AsyncFib(9);
877                  AsyncFib h = null;
# Line 757 | Line 888 | public class ForkJoinTaskTest extends JS
888       */
889      public void testAbnormalInvokeAll2() {
890          RecursiveAction a = new CheckedRecursiveAction() {
891 <            public void realCompute() {
891 >            protected void realCompute() {
892                  AsyncFib f = new AsyncFib(8);
893                  FailingAsyncFib g = new FailingAsyncFib(9);
894 +                ForkJoinTask[] tasks = { f, g };
895 +                shuffle(tasks);
896                  try {
897 <                    invokeAll(f, g);
897 >                    invokeAll(tasks);
898                      shouldThrow();
899 <                } catch (FJException success) {}
899 >                } catch (FJException success) {
900 >                    checkCompletedAbnormally(g, success);
901 >                }
902              }};
903          testInvokeOnPool(mainPool(), a);
904      }
# Line 773 | Line 908 | public class ForkJoinTaskTest extends JS
908       */
909      public void testAbnormalInvokeAll1() {
910          RecursiveAction a = new CheckedRecursiveAction() {
911 <            public void realCompute() {
911 >            protected void realCompute() {
912                  FailingAsyncFib g = new FailingAsyncFib(9);
913                  try {
914                      invokeAll(g);
915                      shouldThrow();
916 <                } catch (FJException success) {}
916 >                } catch (FJException success) {
917 >                    checkCompletedAbnormally(g, success);
918 >                }
919              }};
920          testInvokeOnPool(mainPool(), a);
921      }
# Line 788 | Line 925 | public class ForkJoinTaskTest extends JS
925       */
926      public void testAbnormalInvokeAll3() {
927          RecursiveAction a = new CheckedRecursiveAction() {
928 <            public void realCompute() {
928 >            protected void realCompute() {
929                  AsyncFib f = new AsyncFib(8);
930                  FailingAsyncFib g = new FailingAsyncFib(9);
931                  AsyncFib h = new AsyncFib(7);
932 +                ForkJoinTask[] tasks = { f, g, h };
933 +                shuffle(tasks);
934                  try {
935 <                    invokeAll(f, g, h);
935 >                    invokeAll(tasks);
936                      shouldThrow();
937 <                } catch (FJException success) {}
937 >                } catch (FJException success) {
938 >                    checkCompletedAbnormally(g, success);
939 >                }
940              }};
941          testInvokeOnPool(mainPool(), a);
942      }
943  
944      /**
945 <     * invokeAll(collection)  throws exception if any task does
945 >     * invokeAll(collection) throws exception if any task does
946       */
947      public void testAbnormalInvokeAllCollection() {
948          RecursiveAction a = new CheckedRecursiveAction() {
949 <            public void realCompute() {
949 >            protected void realCompute() {
950                  FailingAsyncFib f = new FailingAsyncFib(8);
951                  AsyncFib g = new AsyncFib(9);
952                  AsyncFib h = new AsyncFib(7);
953 <                HashSet set = new HashSet();
954 <                set.add(f);
814 <                set.add(g);
815 <                set.add(h);
953 >                ForkJoinTask[] tasks = { f, g, h };
954 >                shuffle(tasks);
955                  try {
956 <                    invokeAll(set);
956 >                    invokeAll(Arrays.asList(tasks));
957                      shouldThrow();
958 <                } catch (FJException success) {}
958 >                } catch (FJException success) {
959 >                    checkCompletedAbnormally(f, success);
960 >                }
961              }};
962          testInvokeOnPool(mainPool(), a);
963      }
# Line 827 | Line 968 | public class ForkJoinTaskTest extends JS
968       */
969      public void testTryUnfork() {
970          RecursiveAction a = new CheckedRecursiveAction() {
971 <            public void realCompute() {
971 >            protected void realCompute() {
972                  AsyncFib g = new AsyncFib(9);
973                  assertSame(g, g.fork());
974                  AsyncFib f = new AsyncFib(8);
975                  assertSame(f, f.fork());
976                  assertTrue(f.tryUnfork());
977                  helpQuiesce();
978 <                assertFalse(f.isDone());
979 <                assertTrue(g.isDone());
978 >                checkNotDone(f);
979 >                checkCompletedNormally(g);
980              }};
981          testInvokeOnPool(singletonPool(), a);
982      }
# Line 846 | Line 987 | public class ForkJoinTaskTest extends JS
987       */
988      public void testGetSurplusQueuedTaskCount() {
989          RecursiveAction a = new CheckedRecursiveAction() {
990 <            public void realCompute() {
990 >            protected void realCompute() {
991                  AsyncFib h = new AsyncFib(7);
992                  assertSame(h, h.fork());
993                  AsyncFib g = new AsyncFib(9);
# Line 855 | Line 996 | public class ForkJoinTaskTest extends JS
996                  assertSame(f, f.fork());
997                  assertTrue(getSurplusQueuedTaskCount() > 0);
998                  helpQuiesce();
999 +                assertEquals(0, getSurplusQueuedTaskCount());
1000 +                checkCompletedNormally(f);
1001 +                checkCompletedNormally(g);
1002 +                checkCompletedNormally(h);
1003              }};
1004          testInvokeOnPool(singletonPool(), a);
1005      }
# Line 864 | Line 1009 | public class ForkJoinTaskTest extends JS
1009       */
1010      public void testPeekNextLocalTask() {
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, peekNextLocalTask());
1018                  assertNull(f.join());
1019 <                assertTrue(f.isDone());
1019 >                checkCompletedNormally(f);
1020                  helpQuiesce();
1021 +                checkCompletedNormally(g);
1022              }};
1023          testInvokeOnPool(singletonPool(), a);
1024      }
1025  
1026      /**
1027 <     * pollNextLocalTask returns most recent unexecuted task
1028 <     * without executing it
1027 >     * pollNextLocalTask returns most recent unexecuted task without
1028 >     * executing it
1029       */
1030      public void testPollNextLocalTask() {
1031          RecursiveAction a = new CheckedRecursiveAction() {
1032 <            public void realCompute() {
1032 >            protected void realCompute() {
1033                  AsyncFib g = new AsyncFib(9);
1034                  assertSame(g, g.fork());
1035                  AsyncFib f = new AsyncFib(8);
1036                  assertSame(f, f.fork());
1037                  assertSame(f, pollNextLocalTask());
1038                  helpQuiesce();
1039 <                assertFalse(f.isDone());
1039 >                checkNotDone(f);
1040 >                assertEquals(34, g.number);
1041 >                checkCompletedNormally(g);
1042              }};
1043          testInvokeOnPool(singletonPool(), a);
1044      }
1045  
1046      /**
1047 <     * pollTask returns an unexecuted task
900 <     * without executing it
1047 >     * pollTask returns an unexecuted task without executing it
1048       */
1049      public void testPollTask() {
1050          RecursiveAction a = new CheckedRecursiveAction() {
1051 <            public void realCompute() {
1051 >            protected void realCompute() {
1052                  AsyncFib g = new AsyncFib(9);
1053                  assertSame(g, g.fork());
1054                  AsyncFib f = new AsyncFib(8);
1055                  assertSame(f, f.fork());
1056                  assertSame(f, pollTask());
1057                  helpQuiesce();
1058 <                assertFalse(f.isDone());
1059 <                assertTrue(g.isDone());
1058 >                checkNotDone(f);
1059 >                checkCompletedNormally(g);
1060              }};
1061          testInvokeOnPool(singletonPool(), a);
1062      }
# Line 919 | Line 1066 | public class ForkJoinTaskTest extends JS
1066       */
1067      public void testPeekNextLocalTaskAsync() {
1068          RecursiveAction a = new CheckedRecursiveAction() {
1069 <            public void realCompute() {
1069 >            protected void realCompute() {
1070                  AsyncFib g = new AsyncFib(9);
1071                  assertSame(g, g.fork());
1072                  AsyncFib f = new AsyncFib(8);
# Line 927 | Line 1074 | public class ForkJoinTaskTest extends JS
1074                  assertSame(g, peekNextLocalTask());
1075                  assertNull(f.join());
1076                  helpQuiesce();
1077 <                assertTrue(f.isDone());
1077 >                checkCompletedNormally(f);
1078 >                assertEquals(34, g.number);
1079 >                checkCompletedNormally(g);
1080              }};
1081          testInvokeOnPool(asyncSingletonPool(), a);
1082      }
1083  
1084      /**
1085 <     * pollNextLocalTask returns least recent unexecuted task
1086 <     * without executing it, in async mode
1085 >     * pollNextLocalTask returns least recent unexecuted task without
1086 >     * executing it, in async mode
1087       */
1088      public void testPollNextLocalTaskAsync() {
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, pollNextLocalTask());
1096                  helpQuiesce();
1097 <                assertTrue(f.isDone());
1098 <                assertFalse(g.isDone());
1097 >                assertEquals(21, f.number);
1098 >                checkCompletedNormally(f);
1099 >                checkNotDone(g);
1100              }};
1101          testInvokeOnPool(asyncSingletonPool(), a);
1102      }
1103  
1104      /**
1105 <     * pollTask returns an unexecuted task
1106 <     * without executing it, in async mode
1105 >     * pollTask returns an unexecuted task without executing it, in
1106 >     * async mode
1107       */
1108      public void testPollTaskAsync() {
1109          RecursiveAction a = new CheckedRecursiveAction() {
1110 <            public void realCompute() {
1110 >            protected void realCompute() {
1111                  AsyncFib g = new AsyncFib(9);
1112                  assertSame(g, g.fork());
1113                  AsyncFib f = new AsyncFib(8);
1114                  assertSame(f, f.fork());
1115                  assertSame(g, pollTask());
1116                  helpQuiesce();
1117 <                assertTrue(f.isDone());
1118 <                assertFalse(g.isDone());
1117 >                assertEquals(21, f.number);
1118 >                checkCompletedNormally(f);
1119 >                checkNotDone(g);
1120              }};
1121          testInvokeOnPool(asyncSingletonPool(), a);
1122      }
# Line 975 | Line 1126 | public class ForkJoinTaskTest extends JS
1126      /**
1127       * invoke returns when task completes normally.
1128       * isCompletedAbnormally and isCancelled return false for normally
1129 <     * completed tasks. getRawResult of a RecursiveAction returns null;
1129 >     * completed tasks; getRawResult returns null.
1130       */
1131      public void testInvokeSingleton() {
1132          RecursiveAction a = new CheckedRecursiveAction() {
1133 <            public void realCompute() {
1133 >            protected void realCompute() {
1134                  AsyncFib f = new AsyncFib(8);
1135                  assertNull(f.invoke());
1136                  assertEquals(21, f.number);
1137 <                assertTrue(f.isDone());
987 <                assertFalse(f.isCancelled());
988 <                assertFalse(f.isCompletedAbnormally());
989 <                assertNull(f.getRawResult());
1137 >                checkCompletedNormally(f);
1138              }};
1139          testInvokeOnPool(singletonPool(), a);
1140      }
# Line 998 | Line 1146 | public class ForkJoinTaskTest extends JS
1146       */
1147      public void testQuietlyInvokeSingleton() {
1148          RecursiveAction a = new CheckedRecursiveAction() {
1149 <            public void realCompute() {
1149 >            protected void realCompute() {
1150                  AsyncFib f = new AsyncFib(8);
1151                  f.quietlyInvoke();
1152                  assertEquals(21, f.number);
1153 <                assertTrue(f.isDone());
1006 <                assertFalse(f.isCancelled());
1007 <                assertFalse(f.isCompletedAbnormally());
1008 <                assertNull(f.getRawResult());
1153 >                checkCompletedNormally(f);
1154              }};
1155          testInvokeOnPool(singletonPool(), a);
1156      }
# Line 1015 | Line 1160 | public class ForkJoinTaskTest extends JS
1160       */
1161      public void testForkJoinSingleton() {
1162          RecursiveAction a = new CheckedRecursiveAction() {
1163 <            public void realCompute() {
1163 >            protected void realCompute() {
1164                  AsyncFib f = new AsyncFib(8);
1165                  assertSame(f, f.fork());
1166                  assertNull(f.join());
1167                  assertEquals(21, f.number);
1168 <                assertTrue(f.isDone());
1024 <                assertNull(f.getRawResult());
1168 >                checkCompletedNormally(f);
1169              }};
1170          testInvokeOnPool(singletonPool(), a);
1171      }
# Line 1031 | Line 1175 | public class ForkJoinTaskTest extends JS
1175       */
1176      public void testForkGetSingleton() {
1177          RecursiveAction a = new CheckedRecursiveAction() {
1178 <            public void realCompute() throws Exception {
1178 >            protected void realCompute() throws Exception {
1179                  AsyncFib f = new AsyncFib(8);
1180                  assertSame(f, f.fork());
1181                  assertNull(f.get());
1182                  assertEquals(21, f.number);
1183 <                assertTrue(f.isDone());
1183 >                checkCompletedNormally(f);
1184              }};
1185          testInvokeOnPool(singletonPool(), a);
1186      }
# Line 1046 | Line 1190 | public class ForkJoinTaskTest extends JS
1190       */
1191      public void testForkTimedGetSingleton() {
1192          RecursiveAction a = new CheckedRecursiveAction() {
1193 <            public void realCompute() throws Exception {
1193 >            protected void realCompute() throws Exception {
1194                  AsyncFib f = new AsyncFib(8);
1195                  assertSame(f, f.fork());
1196                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1197                  assertEquals(21, f.number);
1198 <                assertTrue(f.isDone());
1198 >                checkCompletedNormally(f);
1199              }};
1200          testInvokeOnPool(singletonPool(), a);
1201      }
# Line 1061 | Line 1205 | public class ForkJoinTaskTest extends JS
1205       */
1206      public void testForkTimedGetNPESingleton() {
1207          RecursiveAction a = new CheckedRecursiveAction() {
1208 <            public void realCompute() throws Exception {
1208 >            protected void realCompute() throws Exception {
1209                  AsyncFib f = new AsyncFib(8);
1210                  assertSame(f, f.fork());
1211                  try {
1212 <                    f.get(5L, null);
1212 >                    f.get(randomTimeout(), null);
1213                      shouldThrow();
1214                  } catch (NullPointerException success) {}
1215              }};
# Line 1077 | Line 1221 | public class ForkJoinTaskTest extends JS
1221       */
1222      public void testForkQuietlyJoinSingleton() {
1223          RecursiveAction a = new CheckedRecursiveAction() {
1224 <            public void realCompute() {
1224 >            protected void realCompute() {
1225                  AsyncFib f = new AsyncFib(8);
1226                  assertSame(f, f.fork());
1227                  f.quietlyJoin();
1228                  assertEquals(21, f.number);
1229 <                assertTrue(f.isDone());
1229 >                checkCompletedNormally(f);
1230              }};
1231          testInvokeOnPool(singletonPool(), a);
1232      }
1233  
1090
1234      /**
1235       * helpQuiesce returns when tasks are complete.
1236       * getQueuedTaskCount returns 0 when quiescent
1237       */
1238      public void testForkHelpQuiesceSingleton() {
1239          RecursiveAction a = new CheckedRecursiveAction() {
1240 <            public void realCompute() {
1240 >            protected void realCompute() {
1241                  AsyncFib f = new AsyncFib(8);
1242                  assertSame(f, f.fork());
1243 <                f.helpQuiesce();
1101 <                assertEquals(21, f.number);
1102 <                assertTrue(f.isDone());
1243 >                helpQuiesce();
1244                  assertEquals(0, getQueuedTaskCount());
1245 +                assertEquals(21, f.number);
1246 +                checkCompletedNormally(f);
1247              }};
1248          testInvokeOnPool(singletonPool(), a);
1249      }
1250  
1108
1251      /**
1252       * invoke task throws exception when task completes abnormally
1253       */
1254      public void testAbnormalInvokeSingleton() {
1255          RecursiveAction a = new CheckedRecursiveAction() {
1256 <            public void realCompute() {
1256 >            protected void realCompute() {
1257                  FailingAsyncFib f = new FailingAsyncFib(8);
1258                  try {
1259                      f.invoke();
1260                      shouldThrow();
1261 <                } catch (FJException success) {}
1261 >                } catch (FJException success) {
1262 >                    checkCompletedAbnormally(f, success);
1263 >                }
1264              }};
1265          testInvokeOnPool(singletonPool(), a);
1266      }
# Line 1126 | Line 1270 | public class ForkJoinTaskTest extends JS
1270       */
1271      public void testAbnormalQuietlyInvokeSingleton() {
1272          RecursiveAction a = new CheckedRecursiveAction() {
1273 <            public void realCompute() {
1273 >            protected void realCompute() {
1274                  FailingAsyncFib f = new FailingAsyncFib(8);
1275                  f.quietlyInvoke();
1276 <                assertTrue(f.isDone());
1276 >                assertTrue(f.getException() instanceof FJException);
1277 >                checkCompletedAbnormally(f, f.getException());
1278              }};
1279          testInvokeOnPool(singletonPool(), a);
1280      }
# Line 1139 | Line 1284 | public class ForkJoinTaskTest extends JS
1284       */
1285      public void testAbnormalForkJoinSingleton() {
1286          RecursiveAction a = new CheckedRecursiveAction() {
1287 <            public void realCompute() {
1287 >            protected void realCompute() {
1288                  FailingAsyncFib f = new FailingAsyncFib(8);
1289                  assertSame(f, f.fork());
1290                  try {
1291                      f.join();
1292                      shouldThrow();
1293 <                } catch (FJException success) {}
1293 >                } catch (FJException success) {
1294 >                    checkCompletedAbnormally(f, success);
1295 >                }
1296              }};
1297          testInvokeOnPool(singletonPool(), a);
1298      }
# Line 1155 | Line 1302 | public class ForkJoinTaskTest extends JS
1302       */
1303      public void testAbnormalForkGetSingleton() {
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 1164 | 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());
1168 <                    assertTrue(f.isCompletedAbnormally());
1169 <                    assertSame(cause, f.getException());
1314 >                    checkCompletedAbnormally(f, cause);
1315                  }
1316              }};
1317          testInvokeOnPool(singletonPool(), a);
# Line 1177 | Line 1322 | public class ForkJoinTaskTest extends JS
1322       */
1323      public void testAbnormalForkTimedGetSingleton() {
1324          RecursiveAction a = new CheckedRecursiveAction() {
1325 <            public void realCompute() throws Exception {
1325 >            protected void realCompute() throws Exception {
1326                  FailingAsyncFib f = new FailingAsyncFib(8);
1327                  assertSame(f, f.fork());
1328                  try {
# Line 1186 | Line 1331 | public class ForkJoinTaskTest extends JS
1331                  } catch (ExecutionException success) {
1332                      Throwable cause = success.getCause();
1333                      assertTrue(cause instanceof FJException);
1334 <                    assertTrue(f.isDone());
1190 <                    assertTrue(f.isCompletedAbnormally());
1191 <                    assertSame(cause, f.getException());
1334 >                    checkCompletedAbnormally(f, cause);
1335                  }
1336              }};
1337          testInvokeOnPool(singletonPool(), a);
# Line 1199 | Line 1342 | public class ForkJoinTaskTest extends JS
1342       */
1343      public void testAbnormalForkQuietlyJoinSingleton() {
1344          RecursiveAction a = new CheckedRecursiveAction() {
1345 <            public void realCompute() {
1345 >            protected void realCompute() {
1346                  FailingAsyncFib f = new FailingAsyncFib(8);
1347                  assertSame(f, f.fork());
1348                  f.quietlyJoin();
1206                assertTrue(f.isDone());
1207                assertTrue(f.isCompletedAbnormally());
1349                  assertTrue(f.getException() instanceof FJException);
1350 +                checkCompletedAbnormally(f, f.getException());
1351              }};
1352          testInvokeOnPool(singletonPool(), a);
1353      }
# Line 1215 | Line 1357 | public class ForkJoinTaskTest extends JS
1357       */
1358      public void testCancelledInvokeSingleton() {
1359          RecursiveAction a = new CheckedRecursiveAction() {
1360 <            public void realCompute() {
1360 >            protected void realCompute() {
1361                  AsyncFib f = new AsyncFib(8);
1362                  assertTrue(f.cancel(true));
1363                  try {
1364                      f.invoke();
1365                      shouldThrow();
1366                  } catch (CancellationException success) {
1367 <                    assertTrue(f.isDone());
1226 <                    assertTrue(f.isCancelled());
1227 <                    assertTrue(f.isCompletedAbnormally());
1228 <                    assertTrue(f.getException() instanceof CancellationException);
1367 >                    checkCancelled(f);
1368                  }
1369              }};
1370          testInvokeOnPool(singletonPool(), a);
# Line 1236 | Line 1375 | public class ForkJoinTaskTest extends JS
1375       */
1376      public void testCancelledForkJoinSingleton() {
1377          RecursiveAction a = new CheckedRecursiveAction() {
1378 <            public void realCompute() {
1378 >            protected void realCompute() {
1379                  AsyncFib f = new AsyncFib(8);
1380                  assertTrue(f.cancel(true));
1381                  assertSame(f, f.fork());
# Line 1244 | Line 1383 | public class ForkJoinTaskTest extends JS
1383                      f.join();
1384                      shouldThrow();
1385                  } catch (CancellationException success) {
1386 <                    assertTrue(f.isDone());
1248 <                    assertTrue(f.isCancelled());
1249 <                    assertTrue(f.isCompletedAbnormally());
1250 <                    assertTrue(f.getException() instanceof CancellationException);
1386 >                    checkCancelled(f);
1387                  }
1388              }};
1389          testInvokeOnPool(singletonPool(), a);
# Line 1258 | Line 1394 | public class ForkJoinTaskTest extends JS
1394       */
1395      public void testCancelledForkGetSingleton() {
1396          RecursiveAction a = new CheckedRecursiveAction() {
1397 <            public void realCompute() throws Exception {
1397 >            protected void realCompute() throws Exception {
1398                  AsyncFib f = new AsyncFib(8);
1399                  assertTrue(f.cancel(true));
1400                  assertSame(f, f.fork());
# Line 1266 | Line 1402 | public class ForkJoinTaskTest extends JS
1402                      f.get();
1403                      shouldThrow();
1404                  } catch (CancellationException success) {
1405 <                    assertTrue(f.isDone());
1270 <                    assertTrue(f.isCancelled());
1271 <                    assertTrue(f.isCompletedAbnormally());
1272 <                    assertTrue(f.getException() instanceof CancellationException);
1405 >                    checkCancelled(f);
1406                  }
1407              }};
1408          testInvokeOnPool(singletonPool(), a);
# Line 1280 | Line 1413 | public class ForkJoinTaskTest extends JS
1413       */
1414      public void testCancelledForkTimedGetSingleton() throws Exception {
1415          RecursiveAction a = new CheckedRecursiveAction() {
1416 <            public void realCompute() throws Exception {
1416 >            protected void realCompute() throws Exception {
1417                  AsyncFib f = new AsyncFib(8);
1418                  assertTrue(f.cancel(true));
1419                  assertSame(f, f.fork());
# Line 1288 | Line 1421 | public class ForkJoinTaskTest extends JS
1421                      f.get(LONG_DELAY_MS, MILLISECONDS);
1422                      shouldThrow();
1423                  } catch (CancellationException success) {
1424 <                    assertTrue(f.isDone());
1292 <                    assertTrue(f.isCancelled());
1293 <                    assertTrue(f.isCompletedAbnormally());
1294 <                    assertTrue(f.getException() instanceof CancellationException);
1424 >                    checkCancelled(f);
1425                  }
1426              }};
1427          testInvokeOnPool(singletonPool(), a);
# Line 1302 | Line 1432 | public class ForkJoinTaskTest extends JS
1432       */
1433      public void testCancelledForkQuietlyJoinSingleton() {
1434          RecursiveAction a = new CheckedRecursiveAction() {
1435 <            public void realCompute() {
1435 >            protected void realCompute() {
1436                  AsyncFib f = new AsyncFib(8);
1437                  assertTrue(f.cancel(true));
1438                  assertSame(f, f.fork());
1439                  f.quietlyJoin();
1440 <                assertTrue(f.isDone());
1311 <                assertTrue(f.isCompletedAbnormally());
1312 <                assertTrue(f.isCancelled());
1313 <                assertTrue(f.getException() instanceof CancellationException);
1440 >                checkCancelled(f);
1441              }};
1442          testInvokeOnPool(singletonPool(), a);
1443      }
# Line 1320 | Line 1447 | public class ForkJoinTaskTest extends JS
1447       */
1448      public void testCompleteExceptionallySingleton() {
1449          RecursiveAction a = new CheckedRecursiveAction() {
1450 <            public void realCompute() {
1450 >            protected void realCompute() {
1451                  AsyncFib f = new AsyncFib(8);
1452                  f.completeExceptionally(new FJException());
1453                  try {
1454                      f.invoke();
1455                      shouldThrow();
1456 <                } catch (FJException success) {}
1456 >                } catch (FJException success) {
1457 >                    checkCompletedAbnormally(f, success);
1458 >                }
1459              }};
1460          testInvokeOnPool(singletonPool(), a);
1461      }
# Line 1336 | Line 1465 | public class ForkJoinTaskTest extends JS
1465       */
1466      public void testInvokeAll2Singleton() {
1467          RecursiveAction a = new CheckedRecursiveAction() {
1468 <            public void realCompute() {
1468 >            protected void realCompute() {
1469                  AsyncFib f = new AsyncFib(8);
1470                  AsyncFib g = new AsyncFib(9);
1471                  invokeAll(f, g);
1343                assertTrue(f.isDone());
1472                  assertEquals(21, f.number);
1345                assertTrue(g.isDone());
1473                  assertEquals(34, g.number);
1474 +                checkCompletedNormally(f);
1475 +                checkCompletedNormally(g);
1476              }};
1477          testInvokeOnPool(singletonPool(), a);
1478      }
# Line 1353 | Line 1482 | public class ForkJoinTaskTest extends JS
1482       */
1483      public void testInvokeAll1Singleton() {
1484          RecursiveAction a = new CheckedRecursiveAction() {
1485 <            public void realCompute() {
1485 >            protected void realCompute() {
1486                  AsyncFib f = new AsyncFib(8);
1487                  invokeAll(f);
1488 <                assertTrue(f.isDone());
1488 >                checkCompletedNormally(f);
1489                  assertEquals(21, f.number);
1490              }};
1491          testInvokeOnPool(singletonPool(), a);
# Line 1367 | Line 1496 | public class ForkJoinTaskTest extends JS
1496       */
1497      public void testInvokeAll3Singleton() {
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);
1503                  invokeAll(f, g, h);
1375                assertTrue(f.isDone());
1504                  assertEquals(21, f.number);
1377                assertTrue(g.isDone());
1505                  assertEquals(34, g.number);
1379                assertTrue(h.isDone());
1506                  assertEquals(13, h.number);
1507 +                checkCompletedNormally(f);
1508 +                checkCompletedNormally(g);
1509 +                checkCompletedNormally(h);
1510              }};
1511          testInvokeOnPool(singletonPool(), a);
1512      }
# Line 1387 | Line 1516 | public class ForkJoinTaskTest extends JS
1516       */
1517      public void testInvokeAllCollectionSingleton() {
1518          RecursiveAction a = new CheckedRecursiveAction() {
1519 <            public void realCompute() {
1519 >            protected void realCompute() {
1520                  AsyncFib f = new AsyncFib(8);
1521                  AsyncFib g = new AsyncFib(9);
1522                  AsyncFib h = new AsyncFib(7);
# Line 1396 | Line 1525 | public class ForkJoinTaskTest extends JS
1525                  set.add(g);
1526                  set.add(h);
1527                  invokeAll(set);
1399                assertTrue(f.isDone());
1528                  assertEquals(21, f.number);
1401                assertTrue(g.isDone());
1529                  assertEquals(34, g.number);
1403                assertTrue(h.isDone());
1530                  assertEquals(13, h.number);
1531 +                checkCompletedNormally(f);
1532 +                checkCompletedNormally(g);
1533 +                checkCompletedNormally(h);
1534              }};
1535          testInvokeOnPool(singletonPool(), a);
1536      }
1537  
1409
1538      /**
1539       * invokeAll(tasks) with any null task throws NPE
1540       */
1541      public void testInvokeAllNPESingleton() {
1542          RecursiveAction a = new CheckedRecursiveAction() {
1543 <            public void realCompute() {
1543 >            protected void realCompute() {
1544                  AsyncFib f = new AsyncFib(8);
1545                  AsyncFib g = new AsyncFib(9);
1546                  AsyncFib h = null;
# Line 1429 | Line 1557 | public class ForkJoinTaskTest extends JS
1557       */
1558      public void testAbnormalInvokeAll2Singleton() {
1559          RecursiveAction a = new CheckedRecursiveAction() {
1560 <            public void realCompute() {
1560 >            protected void realCompute() {
1561                  AsyncFib f = new AsyncFib(8);
1562                  FailingAsyncFib g = new FailingAsyncFib(9);
1563 +                ForkJoinTask[] tasks = { f, g };
1564 +                shuffle(tasks);
1565                  try {
1566 <                    invokeAll(f, g);
1566 >                    invokeAll(tasks);
1567                      shouldThrow();
1568 <                } catch (FJException success) {}
1568 >                } catch (FJException success) {
1569 >                    checkCompletedAbnormally(g, success);
1570 >                }
1571              }};
1572          testInvokeOnPool(singletonPool(), a);
1573      }
# Line 1445 | Line 1577 | public class ForkJoinTaskTest extends JS
1577       */
1578      public void testAbnormalInvokeAll1Singleton() {
1579          RecursiveAction a = new CheckedRecursiveAction() {
1580 <            public void realCompute() {
1580 >            protected void realCompute() {
1581                  FailingAsyncFib g = new FailingAsyncFib(9);
1582                  try {
1583                      invokeAll(g);
1584                      shouldThrow();
1585 <                } catch (FJException success) {}
1585 >                } catch (FJException success) {
1586 >                    checkCompletedAbnormally(g, success);
1587 >                }
1588              }};
1589          testInvokeOnPool(singletonPool(), a);
1590      }
# Line 1460 | Line 1594 | public class ForkJoinTaskTest extends JS
1594       */
1595      public void testAbnormalInvokeAll3Singleton() {
1596          RecursiveAction a = new CheckedRecursiveAction() {
1597 <            public void realCompute() {
1597 >            protected void realCompute() {
1598                  AsyncFib f = new AsyncFib(8);
1599                  FailingAsyncFib g = new FailingAsyncFib(9);
1600                  AsyncFib h = new AsyncFib(7);
1601 +                ForkJoinTask[] tasks = { f, g, h };
1602 +                shuffle(tasks);
1603                  try {
1604 <                    invokeAll(f, g, h);
1604 >                    invokeAll(tasks);
1605                      shouldThrow();
1606 <                } catch (FJException success) {}
1606 >                } catch (FJException success) {
1607 >                    checkCompletedAbnormally(g, success);
1608 >                }
1609              }};
1610          testInvokeOnPool(singletonPool(), a);
1611      }
1612  
1613      /**
1614 <     * invokeAll(collection)  throws exception if any task does
1614 >     * invokeAll(collection) throws exception if any task does
1615       */
1616      public void testAbnormalInvokeAllCollectionSingleton() {
1617          RecursiveAction a = new CheckedRecursiveAction() {
1618 <            public void realCompute() {
1618 >            protected void realCompute() {
1619                  FailingAsyncFib f = new FailingAsyncFib(8);
1620                  AsyncFib g = new AsyncFib(9);
1621                  AsyncFib h = new AsyncFib(7);
1622 <                HashSet set = new HashSet();
1623 <                set.add(f);
1486 <                set.add(g);
1487 <                set.add(h);
1622 >                ForkJoinTask[] tasks = { f, g, h };
1623 >                shuffle(tasks);
1624                  try {
1625 <                    invokeAll(set);
1625 >                    invokeAll(Arrays.asList(tasks));
1626                      shouldThrow();
1627 <                } catch (FJException success) {}
1627 >                } catch (FJException success) {
1628 >                    checkCompletedAbnormally(f, success);
1629 >                }
1630              }};
1631          testInvokeOnPool(singletonPool(), a);
1632      }
1633  
1634 +    /**
1635 +     * ForkJoinTask.quietlyComplete returns when task completes
1636 +     * normally without setting a value. The most recent value
1637 +     * established by setRawResult(V) (or null by default) is returned
1638 +     * from invoke.
1639 +     */
1640 +    public void testQuietlyComplete() {
1641 +        RecursiveAction a = new CheckedRecursiveAction() {
1642 +                protected void realCompute() {
1643 +                    AsyncFib f = new AsyncFib(8);
1644 +                    f.quietlyComplete();
1645 +                    assertEquals(8, f.number);
1646 +                    checkCompletedNormally(f);
1647 +                }};
1648 +        testInvokeOnPool(mainPool(), a);
1649 +    }
1650 +
1651   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines