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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines