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.1 by dl, Fri Jul 31 23:02:49 2009 UTC vs.
Revision 1.24 by jsr166, Sun Nov 21 19:06:53 2010 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5   */
6 + import java.util.concurrent.ExecutionException;
7 + import java.util.concurrent.CancellationException;
8 + import java.util.concurrent.ForkJoinPool;
9 + import java.util.concurrent.ForkJoinTask;
10 + import java.util.concurrent.ForkJoinWorkerThread;
11 + import java.util.concurrent.RecursiveAction;
12 + import java.util.concurrent.TimeUnit;
13 + import java.util.concurrent.TimeoutException;
14 + import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
15 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
16 + import static java.util.concurrent.TimeUnit.SECONDS;
17 + import java.util.HashSet;
18   import junit.framework.*;
7 import java.util.concurrent.*;
8 import java.util.concurrent.atomic.*;
9 import java.util.*;
19  
20   public class ForkJoinTaskTest extends JSR166TestCase {
21  
22      public static void main(String[] args) {
23 <        junit.textui.TestRunner.run (suite());  
23 >        junit.textui.TestRunner.run(suite());
24      }
25 +
26      public static Test suite() {
27 <        return new TestSuite(ForkJoinTaskTest.class);
27 >        return new TestSuite(ForkJoinTaskTest.class);
28      }
29  
30 <    /**
30 >    // Runs with "mainPool" use > 1 thread. singletonPool tests use 1
31 >    static final int mainPoolSize =
32 >        Math.max(2, Runtime.getRuntime().availableProcessors());
33 >
34 >    private static ForkJoinPool mainPool() {
35 >        return new ForkJoinPool(mainPoolSize);
36 >    }
37 >
38 >    private static ForkJoinPool singletonPool() {
39 >        return new ForkJoinPool(1);
40 >    }
41 >
42 >    private static ForkJoinPool asyncSingletonPool() {
43 >        return new ForkJoinPool(1,
44 >                                ForkJoinPool.defaultForkJoinWorkerThreadFactory,
45 >                                null, true);
46 >    }
47 >
48 >    private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
49 >        try {
50 >            assertFalse(a.isDone());
51 >            assertFalse(a.isCompletedNormally());
52 >            assertFalse(a.isCompletedAbnormally());
53 >            assertFalse(a.isCancelled());
54 >            assertNull(a.getException());
55 >            assertNull(a.getRawResult());
56 >
57 >            assertNull(pool.invoke(a));
58 >
59 >            assertTrue(a.isDone());
60 >            assertTrue(a.isCompletedNormally());
61 >            assertFalse(a.isCompletedAbnormally());
62 >            assertFalse(a.isCancelled());
63 >            assertNull(a.getException());
64 >            assertNull(a.getRawResult());
65 >        } finally {
66 >            joinPool(pool);
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(0L, SECONDS);
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 >        assertSame(expected, a.join());
97 >        try {
98 >            assertSame(expected, a.get());
99 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
100 >        try {
101 >            assertSame(expected, a.get(5L, SECONDS));
102 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
103 >    }
104 >
105 >    void checkCancelled(ForkJoinTask a) {
106 >        assertTrue(a.isDone());
107 >        assertTrue(a.isCancelled());
108 >        assertFalse(a.isCompletedNormally());
109 >        assertTrue(a.isCompletedAbnormally());
110 >        assertTrue(a.getException() instanceof CancellationException);
111 >        assertNull(a.getRawResult());
112 >
113 >        try {
114 >            a.join();
115 >            shouldThrow();
116 >        } catch (CancellationException success) {
117 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
118 >
119 >        try {
120 >            a.get();
121 >            shouldThrow();
122 >        } catch (CancellationException success) {
123 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
124 >
125 >        try {
126 >            a.get(5L, SECONDS);
127 >            shouldThrow();
128 >        } catch (CancellationException success) {
129 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
130 >    }
131 >
132 >    void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
133 >        assertTrue(a.isDone());
134 >        assertFalse(a.isCancelled());
135 >        assertFalse(a.isCompletedNormally());
136 >        assertTrue(a.isCompletedAbnormally());
137 >        assertSame(t, a.getException());
138 >        assertNull(a.getRawResult());
139 >
140 >        try {
141 >            a.join();
142 >            shouldThrow();
143 >        } catch (Throwable expected) {
144 >            assertSame(t, expected);
145 >        }
146 >
147 >        try {
148 >            a.get();
149 >            shouldThrow();
150 >        } catch (ExecutionException success) {
151 >            assertSame(t, success.getCause());
152 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
153 >
154 >        try {
155 >            a.get(5L, SECONDS);
156 >            shouldThrow();
157 >        } catch (ExecutionException success) {
158 >            assertSame(t, success.getCause());
159 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
160 >    }
161 >
162 >    /*
163       * Testing coverage notes:
164 <     *
164 >     *
165       * To test extension methods and overrides, most tests use
166       * BinaryAsyncAction extension class that processes joins
167       * differently than supplied Recursive forms.
168 <     */    
27 <
28 <    static final ForkJoinPool mainPool = new ForkJoinPool();
29 <    static final ForkJoinPool singletonPool = new ForkJoinPool(1);
30 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
31 <    static {
32 <        asyncSingletonPool.setAsyncMode(true);
33 <    }
168 >     */
169  
170      static final class FJException extends RuntimeException {
171          FJException() { super(); }
172      }
173  
174 <    static abstract class BinaryAsyncAction extends ForkJoinTask<Void> {
174 >    abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
175          private volatile int controlState;
176  
177          static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
178 <            AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
178 >            AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
179                                                   "controlState");
180  
181          private BinaryAsyncAction parent;
# Line 92 | Line 227 | public class ForkJoinTaskTest extends JS
227                      break;
228                  try {
229                      p.onComplete(a, s);
230 <                } catch(Throwable rex) {
230 >                } catch (Throwable rex) {
231                      p.completeExceptionally(rex);
232                      return;
233                  }
# Line 129 | Line 264 | public class ForkJoinTaskTest extends JS
264              return controlState;
265          }
266  
267 <        protected final boolean compareAndSetControlState(int expect,
267 >        protected final boolean compareAndSetControlState(int expect,
268                                                            int update) {
269              return controlStateUpdater.compareAndSet(this, expect, update);
270          }
# Line 148 | Line 283 | public class ForkJoinTaskTest extends JS
283  
284      }
285  
286 <    static final class AsyncFib  extends BinaryAsyncAction {
286 >    static final class AsyncFib extends BinaryAsyncAction {
287          int number;
288 <        public AsyncFib(int n) {
288 >        public AsyncFib(int n) {
289              this.number = n;
290          }
291 <        
291 >
292          public final boolean exec() {
293              AsyncFib f = this;
294              int n = f.number;
# Line 177 | Line 312 | public class ForkJoinTaskTest extends JS
312      }
313  
314  
315 <    static final class FailingAsyncFib  extends BinaryAsyncAction {
315 >    static final class FailingAsyncFib extends BinaryAsyncAction {
316          int number;
317 <        public FailingAsyncFib(int n) {
317 >        public FailingAsyncFib(int n) {
318              this.number = n;
319          }
320 <        
320 >
321          public final boolean exec() {
322              FailingAsyncFib f = this;
323              int n = f.number;
# Line 205 | Line 340 | public class ForkJoinTaskTest extends JS
340          }
341      }
342  
343 <    /**
343 >    /**
344       * invoke returns when task completes normally.
345       * isCompletedAbnormally and isCancelled return false for normally
346       * completed tasks. getRawResult of a RecursiveAction returns null;
212     *
347       */
348      public void testInvoke() {
349 <        RecursiveAction a = new RecursiveAction() {
350 <                public void compute() {
351 <                    AsyncFib f = new AsyncFib(8);
352 <                    f.invoke();
353 <                    threadAssertTrue(f.number == 21);
354 <                    threadAssertTrue(f.isDone());
355 <                    threadAssertFalse(f.isCancelled());
356 <                    threadAssertFalse(f.isCompletedAbnormally());
223 <                    threadAssertTrue(f.getRawResult() == null);
224 <                }
225 <            };
226 <        mainPool.invoke(a);
349 >        RecursiveAction a = new CheckedRecursiveAction() {
350 >            public void realCompute() {
351 >                AsyncFib f = new AsyncFib(8);
352 >                assertNull(f.invoke());
353 >                assertEquals(21, f.number);
354 >                checkCompletedNormally(f);
355 >            }};
356 >        testInvokeOnPool(mainPool(), a);
357      }
358  
359 <    /**
359 >    /**
360       * quietlyInvoke task returns when task completes normally.
361       * isCompletedAbnormally and isCancelled return false for normally
362       * completed tasks
363       */
364      public void testQuietlyInvoke() {
365 <        RecursiveAction a = new RecursiveAction() {
366 <                public void compute() {
367 <                    AsyncFib f = new AsyncFib(8);
368 <                    f.quietlyInvoke();
369 <                    threadAssertTrue(f.number == 21);
370 <                    threadAssertTrue(f.isDone());
371 <                    threadAssertFalse(f.isCancelled());
372 <                    threadAssertFalse(f.isCompletedAbnormally());
243 <                    threadAssertTrue(f.getRawResult() == null);
244 <                }
245 <            };
246 <        mainPool.invoke(a);
365 >        RecursiveAction a = new CheckedRecursiveAction() {
366 >            public void realCompute() {
367 >                AsyncFib f = new AsyncFib(8);
368 >                f.quietlyInvoke();
369 >                assertEquals(21, f.number);
370 >                checkCompletedNormally(f);
371 >            }};
372 >        testInvokeOnPool(mainPool(), a);
373      }
374  
375 <    /**
375 >    /**
376       * join of a forked task returns when task completes
377       */
378      public void testForkJoin() {
379 <        RecursiveAction a = new RecursiveAction() {
380 <                public void compute() {
381 <                    AsyncFib f = new AsyncFib(8);
382 <                    f.fork();
383 <                    f.join();
384 <                    threadAssertTrue(f.number == 21);
385 <                    threadAssertTrue(f.isDone());
386 <                    threadAssertTrue(f.getRawResult() == null);
387 <                }
262 <            };
263 <        mainPool.invoke(a);
379 >        RecursiveAction a = new CheckedRecursiveAction() {
380 >            public void realCompute() {
381 >                AsyncFib f = new AsyncFib(8);
382 >                assertSame(f, f.fork());
383 >                assertNull(f.join());
384 >                assertEquals(21, f.number);
385 >                checkCompletedNormally(f);
386 >            }};
387 >        testInvokeOnPool(mainPool(), a);
388      }
389  
390 <    /**
390 >    /**
391       * get of a forked task returns when task completes
392       */
393      public void testForkGet() {
394 <        RecursiveAction a = new RecursiveAction() {
395 <                public void compute() {
396 <                    try {
397 <                        AsyncFib f = new AsyncFib(8);
398 <                        f.fork();
399 <                        f.get();
400 <                        threadAssertTrue(f.number == 21);
401 <                        threadAssertTrue(f.isDone());
402 <                    } catch(Exception ex) {
279 <                        unexpectedException();
280 <                    }
281 <                }
282 <            };
283 <        mainPool.invoke(a);
394 >        RecursiveAction a = new CheckedRecursiveAction() {
395 >            public void realCompute() throws Exception {
396 >                AsyncFib f = new AsyncFib(8);
397 >                assertSame(f, f.fork());
398 >                assertNull(f.get());
399 >                assertEquals(21, f.number);
400 >                checkCompletedNormally(f);
401 >            }};
402 >        testInvokeOnPool(mainPool(), a);
403      }
404  
405 <    /**
405 >    /**
406       * timed get of a forked task returns when task completes
407       */
408      public void testForkTimedGet() {
409 <        RecursiveAction a = new RecursiveAction() {
410 <                public void compute() {
411 <                    try {
412 <                        AsyncFib f = new AsyncFib(8);
413 <                        f.fork();
414 <                        f.get(5L, TimeUnit.SECONDS);
415 <                        threadAssertTrue(f.number == 21);
416 <                        threadAssertTrue(f.isDone());
417 <                    } catch(Exception ex) {
299 <                        unexpectedException();
300 <                    }
301 <                }
302 <            };
303 <        mainPool.invoke(a);
409 >        RecursiveAction a = new CheckedRecursiveAction() {
410 >            public void realCompute() throws Exception {
411 >                AsyncFib f = new AsyncFib(8);
412 >                assertSame(f, f.fork());
413 >                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
414 >                assertEquals(21, f.number);
415 >                checkCompletedNormally(f);
416 >            }};
417 >        testInvokeOnPool(mainPool(), a);
418      }
419  
420 <    /**
420 >    /**
421       * timed get with null time unit throws NPE
422       */
423      public void testForkTimedGetNPE() {
424 <        RecursiveAction a = new RecursiveAction() {
425 <                public void compute() {
426 <                    try {
427 <                        AsyncFib f = new AsyncFib(8);
428 <                        f.fork();
429 <                        f.get(5L, null);
430 <                    } catch(NullPointerException success) {
431 <                    } catch(Exception ex) {
432 <                        unexpectedException();
433 <                    }
320 <                }
321 <            };
322 <        mainPool.invoke(a);
323 <    }
324 <
325 <    /**
326 <     * helpJoin of a forked task returns when task completes
327 <     */
328 <    public void testForkHelpJoin() {
329 <        RecursiveAction a = new RecursiveAction() {
330 <                public void compute() {
331 <                    AsyncFib f = new AsyncFib(8);
332 <                    f.fork();
333 <                    f.helpJoin();
334 <                    threadAssertTrue(f.number == 21);
335 <                    threadAssertTrue(f.isDone());
336 <                }
337 <            };
338 <        mainPool.invoke(a);
424 >        RecursiveAction a = new CheckedRecursiveAction() {
425 >            public void realCompute() throws Exception {
426 >                AsyncFib f = new AsyncFib(8);
427 >                assertSame(f, f.fork());
428 >                try {
429 >                    f.get(5L, null);
430 >                    shouldThrow();
431 >                } catch (NullPointerException success) {}
432 >            }};
433 >        testInvokeOnPool(mainPool(), a);
434      }
435  
436 <    /**
436 >    /**
437       * quietlyJoin of a forked task returns when task completes
438       */
439      public void testForkQuietlyJoin() {
440 <        RecursiveAction a = new RecursiveAction() {
441 <                public void compute() {
442 <                    AsyncFib f = new AsyncFib(8);
443 <                    f.fork();
444 <                    f.quietlyJoin();
445 <                    threadAssertTrue(f.number == 21);
446 <                    threadAssertTrue(f.isDone());
447 <                }
448 <            };
354 <        mainPool.invoke(a);
440 >        RecursiveAction a = new CheckedRecursiveAction() {
441 >            public void realCompute() {
442 >                AsyncFib f = new AsyncFib(8);
443 >                assertSame(f, f.fork());
444 >                f.quietlyJoin();
445 >                assertEquals(21, f.number);
446 >                checkCompletedNormally(f);
447 >            }};
448 >        testInvokeOnPool(mainPool(), a);
449      }
450  
451  
452 <    /**
359 <     * quietlyHelpJoin of a forked task returns when task completes
360 <     */
361 <    public void testForkQuietlyHelpJoin() {
362 <        RecursiveAction a = new RecursiveAction() {
363 <                public void compute() {
364 <                    AsyncFib f = new AsyncFib(8);
365 <                    f.fork();
366 <                    f.quietlyHelpJoin();
367 <                    threadAssertTrue(f.number == 21);
368 <                    threadAssertTrue(f.isDone());
369 <                }
370 <            };
371 <        mainPool.invoke(a);
372 <    }
373 <
374 <
375 <    /**
452 >    /**
453       * helpQuiesce returns when tasks are complete.
454       * getQueuedTaskCount returns 0 when quiescent
455       */
456      public void testForkHelpQuiesce() {
457 <        RecursiveAction a = new RecursiveAction() {
458 <                public void compute() {
459 <                    AsyncFib f = new AsyncFib(8);
460 <                    f.fork();
461 <                    f.helpQuiesce();
462 <                    threadAssertTrue(f.number == 21);
463 <                    threadAssertTrue(f.isDone());
464 <                    threadAssertTrue(getQueuedTaskCount() == 0);
465 <                }
466 <            };
390 <        mainPool.invoke(a);
457 >        RecursiveAction a = new CheckedRecursiveAction() {
458 >            public void realCompute() {
459 >                AsyncFib f = new AsyncFib(8);
460 >                assertSame(f, f.fork());
461 >                f.helpQuiesce();
462 >                assertEquals(21, f.number);
463 >                assertEquals(0, getQueuedTaskCount());
464 >                checkCompletedNormally(f);
465 >            }};
466 >        testInvokeOnPool(mainPool(), a);
467      }
468  
469  
470 <    /**
470 >    /**
471       * invoke task throws exception when task completes abnormally
472       */
473      public void testAbnormalInvoke() {
474 <        RecursiveAction a = new RecursiveAction() {
475 <                public void compute() {
476 <                    try {
477 <                        FailingAsyncFib f = new FailingAsyncFib(8);
478 <                        f.invoke();
479 <                        shouldThrow();
480 <                    } catch(FJException success) {
481 <                    }
474 >        RecursiveAction a = new CheckedRecursiveAction() {
475 >            public void realCompute() {
476 >                FailingAsyncFib f = new FailingAsyncFib(8);
477 >                try {
478 >                    f.invoke();
479 >                    shouldThrow();
480 >                } catch (FJException success) {
481 >                    checkCompletedAbnormally(f, success);
482                  }
483 <            };
484 <        mainPool.invoke(a);
483 >            }};
484 >        testInvokeOnPool(mainPool(), a);
485      }
486  
487 <    /**
488 <     * quietelyInvoke task returns when task completes abnormally
487 >    /**
488 >     * quietlyInvoke task returns when task completes abnormally
489       */
490      public void testAbnormalQuietlyInvoke() {
491 <        RecursiveAction a = new RecursiveAction() {
492 <                public void compute() {
493 <                    FailingAsyncFib f = new FailingAsyncFib(8);
494 <                    f.quietlyInvoke();
495 <                    threadAssertTrue(f.isDone());
496 <                }
497 <            };
498 <        mainPool.invoke(a);
491 >        RecursiveAction a = new CheckedRecursiveAction() {
492 >            public void realCompute() {
493 >                FailingAsyncFib f = new FailingAsyncFib(8);
494 >                f.quietlyInvoke();
495 >                assertTrue(f.getException() instanceof FJException);
496 >                checkCompletedAbnormally(f, f.getException());
497 >            }};
498 >        testInvokeOnPool(mainPool(), a);
499      }
500  
501 <    /**
501 >    /**
502       * join of a forked task throws exception when task completes abnormally
503       */
504      public void testAbnormalForkJoin() {
505 <        RecursiveAction a = new RecursiveAction() {
506 <                public void compute() {
507 <                    try {
508 <                        FailingAsyncFib f = new FailingAsyncFib(8);
509 <                        f.fork();
510 <                        f.join();
511 <                        shouldThrow();
512 <                    } catch(FJException success) {
513 <                    }
505 >        RecursiveAction a = new CheckedRecursiveAction() {
506 >            public void realCompute() {
507 >                FailingAsyncFib f = new FailingAsyncFib(8);
508 >                assertSame(f, f.fork());
509 >                try {
510 >                    f.join();
511 >                    shouldThrow();
512 >                } catch (FJException success) {
513 >                    checkCompletedAbnormally(f, success);
514                  }
515 <            };
516 <        mainPool.invoke(a);
515 >            }};
516 >        testInvokeOnPool(mainPool(), a);
517      }
518  
519 <    /**
519 >    /**
520       * get of a forked task throws exception when task completes abnormally
521       */
522      public void testAbnormalForkGet() {
523 <        RecursiveAction a = new RecursiveAction() {
524 <                public void compute() {
525 <                    try {
526 <                        FailingAsyncFib f = new FailingAsyncFib(8);
527 <                        f.fork();
528 <                        f.get();
529 <                        shouldThrow();
530 <                    } catch(Exception success) {
531 <                    }
523 >        RecursiveAction a = new CheckedRecursiveAction() {
524 >            public void realCompute() throws Exception {
525 >                FailingAsyncFib f = new FailingAsyncFib(8);
526 >                assertSame(f, f.fork());
527 >                try {
528 >                    f.get();
529 >                    shouldThrow();
530 >                } catch (ExecutionException success) {
531 >                    Throwable cause = success.getCause();
532 >                    assertTrue(cause instanceof FJException);
533 >                    checkCompletedAbnormally(f, cause);
534                  }
535 <            };
536 <        mainPool.invoke(a);
535 >            }};
536 >        testInvokeOnPool(mainPool(), a);
537      }
538  
539 <    /**
539 >    /**
540       * timed get of a forked task throws exception when task completes abnormally
541       */
542      public void testAbnormalForkTimedGet() {
543 <        RecursiveAction a = new RecursiveAction() {
544 <                public void compute() {
545 <                    try {
546 <                        FailingAsyncFib f = new FailingAsyncFib(8);
547 <                        f.fork();
548 <                        f.get(5L, TimeUnit.SECONDS);
549 <                        shouldThrow();
550 <                    } catch(Exception success) {
551 <                    }
552 <                }
553 <            };
476 <        mainPool.invoke(a);
477 <    }
478 <
479 <    /**
480 <     * join of a forked task throws exception when task completes abnormally
481 <     */
482 <    public void testAbnormalForkHelpJoin() {
483 <        RecursiveAction a = new RecursiveAction() {
484 <                public void compute() {
485 <                    try {
486 <                        FailingAsyncFib f = new FailingAsyncFib(8);
487 <                        f.fork();
488 <                        f.helpJoin();
489 <                        shouldThrow();
490 <                    } catch(FJException success) {
491 <                    }
492 <                }
493 <            };
494 <        mainPool.invoke(a);
495 <    }
496 <
497 <    /**
498 <     * quietlyHelpJoin of a forked task returns when task completes abnormally.
499 <     * getException of failed task returns its exception.
500 <     * isCompletedAbnormally of a failed task returns true.
501 <     * isCancelled of a failed uncancelled task returns false
502 <     */
503 <    public void testAbnormalForkQuietlyHelpJoin() {
504 <        RecursiveAction a = new RecursiveAction() {
505 <                public void compute() {
506 <                    FailingAsyncFib f = new FailingAsyncFib(8);
507 <                    f.fork();
508 <                    f.quietlyHelpJoin();
509 <                    threadAssertTrue(f.isDone());
510 <                    threadAssertTrue(f.isCompletedAbnormally());
511 <                    threadAssertFalse(f.isCancelled());
512 <                    threadAssertTrue(f.getException() instanceof FJException);
543 >        RecursiveAction a = new CheckedRecursiveAction() {
544 >            public void realCompute() throws Exception {
545 >                FailingAsyncFib f = new FailingAsyncFib(8);
546 >                assertSame(f, f.fork());
547 >                try {
548 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
549 >                    shouldThrow();
550 >                } catch (ExecutionException success) {
551 >                    Throwable cause = success.getCause();
552 >                    assertTrue(cause instanceof FJException);
553 >                    checkCompletedAbnormally(f, cause);
554                  }
555 <            };
556 <        mainPool.invoke(a);
555 >            }};
556 >        testInvokeOnPool(mainPool(), a);
557      }
558  
559 <    /**
559 >    /**
560       * quietlyJoin of a forked task returns when task completes abnormally
561       */
562      public void testAbnormalForkQuietlyJoin() {
563 <        RecursiveAction a = new RecursiveAction() {
564 <                public void compute() {
565 <                    FailingAsyncFib f = new FailingAsyncFib(8);
566 <                    f.fork();
567 <                    f.quietlyJoin();
568 <                    threadAssertTrue(f.isDone());
569 <                    threadAssertTrue(f.isCompletedAbnormally());
570 <                    threadAssertTrue(f.getException() instanceof FJException);
571 <                }
531 <            };
532 <        mainPool.invoke(a);
563 >        RecursiveAction a = new CheckedRecursiveAction() {
564 >            public void realCompute() {
565 >                FailingAsyncFib f = new FailingAsyncFib(8);
566 >                assertSame(f, f.fork());
567 >                f.quietlyJoin();
568 >                assertTrue(f.getException() instanceof FJException);
569 >                checkCompletedAbnormally(f, f.getException());
570 >            }};
571 >        testInvokeOnPool(mainPool(), a);
572      }
573  
574 <    /**
574 >    /**
575       * invoke task throws exception when task cancelled
576       */
577      public void testCancelledInvoke() {
578 <        RecursiveAction a = new RecursiveAction() {
579 <                public void compute() {
580 <                    try {
581 <                        AsyncFib f = new AsyncFib(8);
582 <                        f.cancel(true);
583 <                        f.invoke();
584 <                        shouldThrow();
585 <                    } catch(CancellationException success) {
586 <                    }
578 >        RecursiveAction a = new CheckedRecursiveAction() {
579 >            public void realCompute() {
580 >                AsyncFib f = new AsyncFib(8);
581 >                assertTrue(f.cancel(true));
582 >                try {
583 >                    f.invoke();
584 >                    shouldThrow();
585 >                } catch (CancellationException success) {
586 >                    checkCancelled(f);
587                  }
588 <            };
589 <        mainPool.invoke(a);
588 >            }};
589 >        testInvokeOnPool(mainPool(), a);
590      }
591  
592 <    /**
592 >    /**
593       * join of a forked task throws exception when task cancelled
594       */
595      public void testCancelledForkJoin() {
596 <        RecursiveAction a = new RecursiveAction() {
597 <                public void compute() {
598 <                    try {
599 <                        AsyncFib f = new AsyncFib(8);
600 <                        f.cancel(true);
601 <                        f.fork();
602 <                        f.join();
603 <                        shouldThrow();
604 <                    } catch(CancellationException success) {
605 <                    }
596 >        RecursiveAction a = new CheckedRecursiveAction() {
597 >            public void realCompute() {
598 >                AsyncFib f = new AsyncFib(8);
599 >                assertTrue(f.cancel(true));
600 >                assertSame(f, f.fork());
601 >                try {
602 >                    f.join();
603 >                    shouldThrow();
604 >                } catch (CancellationException success) {
605 >                    checkCancelled(f);
606                  }
607 <            };
608 <        mainPool.invoke(a);
607 >            }};
608 >        testInvokeOnPool(mainPool(), a);
609      }
610  
611 <    /**
611 >    /**
612       * get of a forked task throws exception when task cancelled
613       */
614      public void testCancelledForkGet() {
615 <        RecursiveAction a = new RecursiveAction() {
616 <                public void compute() {
617 <                    try {
618 <                        AsyncFib f = new AsyncFib(8);
619 <                        f.cancel(true);
620 <                        f.fork();
621 <                        f.get();
622 <                        shouldThrow();
623 <                    } catch(Exception success) {
624 <                    }
615 >        RecursiveAction a = new CheckedRecursiveAction() {
616 >            public void realCompute() throws Exception {
617 >                AsyncFib f = new AsyncFib(8);
618 >                assertTrue(f.cancel(true));
619 >                assertSame(f, f.fork());
620 >                try {
621 >                    f.get();
622 >                    shouldThrow();
623 >                } catch (CancellationException success) {
624 >                    checkCancelled(f);
625                  }
626 <            };
627 <        mainPool.invoke(a);
626 >            }};
627 >        testInvokeOnPool(mainPool(), a);
628      }
629  
630 <    /**
630 >    /**
631       * timed get of a forked task throws exception when task cancelled
632       */
633 <    public void testCancelledForkTimedGet() {
634 <        RecursiveAction a = new RecursiveAction() {
635 <                public void compute() {
636 <                    try {
637 <                        AsyncFib f = new AsyncFib(8);
638 <                        f.cancel(true);
639 <                        f.fork();
640 <                        f.get(5L, TimeUnit.SECONDS);
641 <                        shouldThrow();
642 <                    } catch(Exception success) {
643 <                    }
605 <                }
606 <            };
607 <        mainPool.invoke(a);
608 <    }
609 <
610 <    /**
611 <     * join of a forked task throws exception when task cancelled
612 <     */
613 <    public void testCancelledForkHelpJoin() {
614 <        RecursiveAction a = new RecursiveAction() {
615 <                public void compute() {
616 <                    try {
617 <                        AsyncFib f = new AsyncFib(8);
618 <                        f.cancel(true);
619 <                        f.fork();
620 <                        f.helpJoin();
621 <                        shouldThrow();
622 <                    } catch(CancellationException success) {
623 <                    }
624 <                }
625 <            };
626 <        mainPool.invoke(a);
627 <    }
628 <
629 <    /**
630 <     * quietlyHelpJoin of a forked task returns when task cancelled.
631 <     * getException of cancelled task returns its exception.
632 <     * isCompletedAbnormally of a cancelled task returns true.
633 <     * isCancelled of a cancelled task returns true
634 <     */
635 <    public void testCancelledForkQuietlyHelpJoin() {
636 <        RecursiveAction a = new RecursiveAction() {
637 <                public void compute() {
638 <                    AsyncFib f = new AsyncFib(8);
639 <                    f.cancel(true);
640 <                    f.fork();
641 <                    f.quietlyHelpJoin();
642 <                    threadAssertTrue(f.isDone());
643 <                    threadAssertTrue(f.isCompletedAbnormally());
644 <                    threadAssertTrue(f.isCancelled());
645 <                    threadAssertTrue(f.getException() instanceof CancellationException);
633 >    public void testCancelledForkTimedGet() throws Exception {
634 >        RecursiveAction a = new CheckedRecursiveAction() {
635 >            public void realCompute() throws Exception {
636 >                AsyncFib f = new AsyncFib(8);
637 >                assertTrue(f.cancel(true));
638 >                assertSame(f, f.fork());
639 >                try {
640 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
641 >                    shouldThrow();
642 >                } catch (CancellationException success) {
643 >                    checkCancelled(f);
644                  }
645 <            };
646 <        mainPool.invoke(a);
645 >            }};
646 >        testInvokeOnPool(mainPool(), a);
647      }
648  
649 <    /**
649 >    /**
650       * quietlyJoin of a forked task returns when task cancelled
651       */
652      public void testCancelledForkQuietlyJoin() {
653 <        RecursiveAction a = new RecursiveAction() {
654 <                public void compute() {
655 <                    AsyncFib f = new AsyncFib(8);
656 <                    f.cancel(true);
657 <                    f.fork();
658 <                    f.quietlyJoin();
659 <                    threadAssertTrue(f.isDone());
660 <                    threadAssertTrue(f.isCompletedAbnormally());
661 <                    threadAssertTrue(f.getException() instanceof CancellationException);
664 <                }
665 <            };
666 <        mainPool.invoke(a);
653 >        RecursiveAction a = new CheckedRecursiveAction() {
654 >            public void realCompute() {
655 >                AsyncFib f = new AsyncFib(8);
656 >                assertTrue(f.cancel(true));
657 >                assertSame(f, f.fork());
658 >                f.quietlyJoin();
659 >                checkCancelled(f);
660 >            }};
661 >        testInvokeOnPool(mainPool(), a);
662      }
663  
664      /**
665       * getPool of executing task returns its pool
666       */
667      public void testGetPool() {
668 <        RecursiveAction a = new RecursiveAction() {
669 <                public void compute() {
670 <                    threadAssertTrue(getPool() == mainPool);
671 <                }
672 <            };
673 <        mainPool.invoke(a);
668 >        final ForkJoinPool mainPool = mainPool();
669 >        RecursiveAction a = new CheckedRecursiveAction() {
670 >            public void realCompute() {
671 >                assertSame(mainPool, getPool());
672 >            }};
673 >        testInvokeOnPool(mainPool, a);
674      }
675  
676      /**
677       * getPool of non-FJ task returns null
678       */
679      public void testGetPool2() {
680 <        RecursiveAction a = new RecursiveAction() {
681 <                public void compute() {
682 <                    threadAssertTrue(getPool() == null);
683 <                }
684 <            };
690 <        a.invoke();
680 >        RecursiveAction a = new CheckedRecursiveAction() {
681 >            public void realCompute() {
682 >                assertNull(getPool());
683 >            }};
684 >        assertNull(a.invoke());
685      }
686  
687      /**
688       * inForkJoinPool of executing task returns true
689       */
690      public void testInForkJoinPool() {
691 <        RecursiveAction a = new RecursiveAction() {
692 <                public void compute() {
693 <                    threadAssertTrue(inForkJoinPool());
694 <                }
695 <            };
702 <        mainPool.invoke(a);
691 >        RecursiveAction a = new CheckedRecursiveAction() {
692 >            public void realCompute() {
693 >                assertTrue(inForkJoinPool());
694 >            }};
695 >        testInvokeOnPool(mainPool(), a);
696      }
697  
698      /**
699       * inForkJoinPool of non-FJ task returns false
700       */
701      public void testInForkJoinPool2() {
702 <        RecursiveAction a = new RecursiveAction() {
703 <                public void compute() {
704 <                    threadAssertTrue(!inForkJoinPool());
705 <                }
706 <            };
714 <        a.invoke();
702 >        RecursiveAction a = new CheckedRecursiveAction() {
703 >            public void realCompute() {
704 >                assertFalse(inForkJoinPool());
705 >            }};
706 >        assertNull(a.invoke());
707      }
708  
709      /**
710       * setRawResult(null) succeeds
711       */
712      public void testSetRawResult() {
713 <        RecursiveAction a = new RecursiveAction() {
714 <                public void compute() {
715 <                    setRawResult(null);
716 <                }
717 <            };
726 <        a.invoke();
713 >        RecursiveAction a = new CheckedRecursiveAction() {
714 >            public void realCompute() {
715 >                setRawResult(null);
716 >            }};
717 >        assertNull(a.invoke());
718      }
719  
720 <    /**
720 >    /**
721       * invoke task throws exception after invoking completeExceptionally
722       */
723      public void testCompleteExceptionally() {
724 <        RecursiveAction a = new RecursiveAction() {
725 <                public void compute() {
726 <                    try {
727 <                        AsyncFib f = new AsyncFib(8);
728 <                        f.completeExceptionally(new FJException());
729 <                        f.invoke();
730 <                        shouldThrow();
731 <                    } catch(FJException success) {
732 <                    }
724 >        RecursiveAction a = new CheckedRecursiveAction() {
725 >            public void realCompute() {
726 >                AsyncFib f = new AsyncFib(8);
727 >                f.completeExceptionally(new FJException());
728 >                try {
729 >                    f.invoke();
730 >                    shouldThrow();
731 >                } catch (FJException success) {
732 >                    checkCompletedAbnormally(f, success);
733                  }
734 <            };
735 <        mainPool.invoke(a);
734 >            }};
735 >        testInvokeOnPool(mainPool(), a);
736      }
737  
738 <    /**
738 >    /**
739       * invokeAll(t1, t2) invokes all task arguments
740       */
741      public void testInvokeAll2() {
742 <        RecursiveAction a = new RecursiveAction() {
743 <                public void compute() {
744 <                    AsyncFib f = new AsyncFib(8);
745 <                    AsyncFib g = new AsyncFib(9);
746 <                    invokeAll(f, g);
747 <                    threadAssertTrue(f.isDone());
748 <                    threadAssertTrue(f.number == 21);
749 <                    threadAssertTrue(g.isDone());
750 <                    threadAssertTrue(g.number == 34);
751 <                }
752 <            };
762 <        mainPool.invoke(a);
742 >        RecursiveAction a = new CheckedRecursiveAction() {
743 >            public void realCompute() {
744 >                AsyncFib f = new AsyncFib(8);
745 >                AsyncFib g = new AsyncFib(9);
746 >                invokeAll(f, g);
747 >                assertEquals(21, f.number);
748 >                assertEquals(34, g.number);
749 >                checkCompletedNormally(f);
750 >                checkCompletedNormally(g);
751 >            }};
752 >        testInvokeOnPool(mainPool(), a);
753      }
754  
755 <    /**
755 >    /**
756       * invokeAll(tasks) with 1 argument invokes task
757       */
758      public void testInvokeAll1() {
759 <        RecursiveAction a = new RecursiveAction() {
760 <                public void compute() {
761 <                    AsyncFib f = new AsyncFib(8);
762 <                    invokeAll(f);
763 <                    threadAssertTrue(f.isDone());
764 <                    threadAssertTrue(f.number == 21);
765 <                }
766 <            };
777 <        mainPool.invoke(a);
759 >        RecursiveAction a = new CheckedRecursiveAction() {
760 >            public void realCompute() {
761 >                AsyncFib f = new AsyncFib(8);
762 >                invokeAll(f);
763 >                checkCompletedNormally(f);
764 >                assertEquals(21, f.number);
765 >            }};
766 >        testInvokeOnPool(mainPool(), a);
767      }
768  
769 <    /**
769 >    /**
770       * invokeAll(tasks) with > 2 argument invokes tasks
771       */
772      public void testInvokeAll3() {
773 <        RecursiveAction a = new RecursiveAction() {
774 <                public void compute() {
775 <                    AsyncFib f = new AsyncFib(8);
776 <                    AsyncFib g = new AsyncFib(9);
777 <                    AsyncFib h = new AsyncFib(7);
778 <                    invokeAll(f, g, h);
779 <                    threadAssertTrue(f.isDone());
780 <                    threadAssertTrue(f.number == 21);
781 <                    threadAssertTrue(g.isDone());
782 <                    threadAssertTrue(g.number == 34);
783 <                    threadAssertTrue(h.isDone());
784 <                    threadAssertTrue(h.number == 13);
785 <                }
786 <            };
798 <        mainPool.invoke(a);
773 >        RecursiveAction a = new CheckedRecursiveAction() {
774 >            public void realCompute() {
775 >                AsyncFib f = new AsyncFib(8);
776 >                AsyncFib g = new AsyncFib(9);
777 >                AsyncFib h = new AsyncFib(7);
778 >                invokeAll(f, g, h);
779 >                assertEquals(21, f.number);
780 >                assertEquals(34, g.number);
781 >                assertEquals(13, h.number);
782 >                checkCompletedNormally(f);
783 >                checkCompletedNormally(g);
784 >                checkCompletedNormally(h);
785 >            }};
786 >        testInvokeOnPool(mainPool(), a);
787      }
788  
789 <    /**
789 >    /**
790       * invokeAll(collection) invokes all tasks in the collection
791       */
792      public void testInvokeAllCollection() {
793 <        RecursiveAction a = new RecursiveAction() {
794 <                public void compute() {
795 <                    AsyncFib f = new AsyncFib(8);
796 <                    AsyncFib g = new AsyncFib(9);
797 <                    AsyncFib h = new AsyncFib(7);
798 <                    HashSet set = new HashSet();
799 <                    set.add(f);
800 <                    set.add(g);
801 <                    set.add(h);
802 <                    invokeAll(set);
803 <                    threadAssertTrue(f.isDone());
804 <                    threadAssertTrue(f.number == 21);
805 <                    threadAssertTrue(g.isDone());
806 <                    threadAssertTrue(g.number == 34);
807 <                    threadAssertTrue(h.isDone());
808 <                    threadAssertTrue(h.number == 13);
809 <                }
810 <            };
823 <        mainPool.invoke(a);
793 >        RecursiveAction a = new CheckedRecursiveAction() {
794 >            public void realCompute() {
795 >                AsyncFib f = new AsyncFib(8);
796 >                AsyncFib g = new AsyncFib(9);
797 >                AsyncFib h = new AsyncFib(7);
798 >                HashSet set = new HashSet();
799 >                set.add(f);
800 >                set.add(g);
801 >                set.add(h);
802 >                invokeAll(set);
803 >                assertEquals(21, f.number);
804 >                assertEquals(34, g.number);
805 >                assertEquals(13, h.number);
806 >                checkCompletedNormally(f);
807 >                checkCompletedNormally(g);
808 >                checkCompletedNormally(h);
809 >            }};
810 >        testInvokeOnPool(mainPool(), a);
811      }
812  
813  
814 <    /**
814 >    /**
815       * invokeAll(tasks) with any null task throws NPE
816       */
817      public void testInvokeAllNPE() {
818 <        RecursiveAction a = new RecursiveAction() {
819 <                public void compute() {
820 <                    try {
821 <                        AsyncFib f = new AsyncFib(8);
822 <                        AsyncFib g = new AsyncFib(9);
823 <                        AsyncFib h = null;
824 <                        invokeAll(f, g, h);
825 <                        shouldThrow();
826 <                    } catch (NullPointerException success) {
827 <                    }
828 <                }
842 <            };
843 <        mainPool.invoke(a);
818 >        RecursiveAction a = new CheckedRecursiveAction() {
819 >            public void realCompute() {
820 >                AsyncFib f = new AsyncFib(8);
821 >                AsyncFib g = new AsyncFib(9);
822 >                AsyncFib h = null;
823 >                try {
824 >                    invokeAll(f, g, h);
825 >                    shouldThrow();
826 >                } catch (NullPointerException success) {}
827 >            }};
828 >        testInvokeOnPool(mainPool(), a);
829      }
830  
831 <    /**
831 >    /**
832       * invokeAll(t1, t2) throw exception if any task does
833       */
834      public void testAbnormalInvokeAll2() {
835 <        RecursiveAction a = new RecursiveAction() {
836 <                public void compute() {
837 <                    try {
838 <                        AsyncFib f = new AsyncFib(8);
839 <                        FailingAsyncFib g = new FailingAsyncFib(9);
840 <                        invokeAll(f, g);
841 <                        shouldThrow();
842 <                    } catch(FJException success) {
843 <                    }
835 >        RecursiveAction a = new CheckedRecursiveAction() {
836 >            public void realCompute() {
837 >                AsyncFib f = new AsyncFib(8);
838 >                FailingAsyncFib g = new FailingAsyncFib(9);
839 >                try {
840 >                    invokeAll(f, g);
841 >                    shouldThrow();
842 >                } catch (FJException success) {
843 >                    checkCompletedAbnormally(g, success);
844                  }
845 <            };
846 <        mainPool.invoke(a);
845 >            }};
846 >        testInvokeOnPool(mainPool(), a);
847      }
848  
849 <    /**
849 >    /**
850       * invokeAll(tasks) with 1 argument throws exception if task does
851       */
852      public void testAbnormalInvokeAll1() {
853 <        RecursiveAction a = new RecursiveAction() {
854 <                public void compute() {
855 <                    try {
856 <                        FailingAsyncFib g = new FailingAsyncFib(9);
857 <                        invokeAll(g);
858 <                        shouldThrow();
859 <                    } catch(FJException success) {
860 <                    }
853 >        RecursiveAction a = new CheckedRecursiveAction() {
854 >            public void realCompute() {
855 >                FailingAsyncFib g = new FailingAsyncFib(9);
856 >                try {
857 >                    invokeAll(g);
858 >                    shouldThrow();
859 >                } catch (FJException success) {
860 >                    checkCompletedAbnormally(g, success);
861                  }
862 <            };
863 <        mainPool.invoke(a);
862 >            }};
863 >        testInvokeOnPool(mainPool(), a);
864      }
865  
866 <    /**
866 >    /**
867       * invokeAll(tasks) with > 2 argument throws exception if any task does
868       */
869      public void testAbnormalInvokeAll3() {
870 <        RecursiveAction a = new RecursiveAction() {
871 <                public void compute() {
872 <                    try {
873 <                        AsyncFib f = new AsyncFib(8);
874 <                        FailingAsyncFib g = new FailingAsyncFib(9);
875 <                        AsyncFib h = new AsyncFib(7);
876 <                        invokeAll(f, g, h);
877 <                        shouldThrow();
878 <                    } catch(FJException success) {
879 <                    }
870 >        RecursiveAction a = new CheckedRecursiveAction() {
871 >            public void realCompute() {
872 >                AsyncFib f = new AsyncFib(8);
873 >                FailingAsyncFib g = new FailingAsyncFib(9);
874 >                AsyncFib h = new AsyncFib(7);
875 >                try {
876 >                    invokeAll(f, g, h);
877 >                    shouldThrow();
878 >                } catch (FJException success) {
879 >                    checkCompletedAbnormally(g, success);
880                  }
881 <            };
882 <        mainPool.invoke(a);
881 >            }};
882 >        testInvokeOnPool(mainPool(), a);
883      }
884  
885 <    /**
885 >    /**
886       * invokeAll(collection)  throws exception if any task does
887       */
888      public void testAbnormalInvokeAllCollection() {
889 <        RecursiveAction a = new RecursiveAction() {
890 <                public void compute() {
891 <                    try {
892 <                        FailingAsyncFib f = new FailingAsyncFib(8);
893 <                        AsyncFib g = new AsyncFib(9);
894 <                        AsyncFib h = new AsyncFib(7);
895 <                        HashSet set = new HashSet();
896 <                        set.add(f);
897 <                        set.add(g);
898 <                        set.add(h);
899 <                        invokeAll(set);
900 <                        shouldThrow();
901 <                    } catch(FJException success) {
902 <                    }
889 >        RecursiveAction a = new CheckedRecursiveAction() {
890 >            public void realCompute() {
891 >                FailingAsyncFib f = new FailingAsyncFib(8);
892 >                AsyncFib g = new AsyncFib(9);
893 >                AsyncFib h = new AsyncFib(7);
894 >                HashSet set = new HashSet();
895 >                set.add(f);
896 >                set.add(g);
897 >                set.add(h);
898 >                try {
899 >                    invokeAll(set);
900 >                    shouldThrow();
901 >                } catch (FJException success) {
902 >                    checkCompletedAbnormally(f, success);
903                  }
904 <            };
905 <        mainPool.invoke(a);
904 >            }};
905 >        testInvokeOnPool(mainPool(), a);
906      }
907  
908 <    /**
908 >    /**
909       * tryUnfork returns true for most recent unexecuted task,
910       * and suppresses execution
911       */
912      public void testTryUnfork() {
913 <        RecursiveAction a = new RecursiveAction() {
914 <                public void compute() {
915 <                    AsyncFib g = new AsyncFib(9);
916 <                    g.fork();
917 <                    AsyncFib f = new AsyncFib(8);
918 <                    f.fork();
919 <                    threadAssertTrue(f.tryUnfork());
920 <                    helpQuiesce();
921 <                    threadAssertFalse(f.isDone());
922 <                    threadAssertTrue(g.isDone());
923 <                }
924 <            };
940 <        singletonPool.invoke(a);
913 >        RecursiveAction a = new CheckedRecursiveAction() {
914 >            public void realCompute() {
915 >                AsyncFib g = new AsyncFib(9);
916 >                assertSame(g, g.fork());
917 >                AsyncFib f = new AsyncFib(8);
918 >                assertSame(f, f.fork());
919 >                assertTrue(f.tryUnfork());
920 >                helpQuiesce();
921 >                checkNotDone(f);
922 >                checkCompletedNormally(g);
923 >            }};
924 >        testInvokeOnPool(singletonPool(), a);
925      }
926  
927 <    /**
927 >    /**
928       * getSurplusQueuedTaskCount returns > 0 when
929       * there are more tasks than threads
930       */
931      public void testGetSurplusQueuedTaskCount() {
932 <        RecursiveAction a = new RecursiveAction() {
933 <                public void compute() {
934 <                    AsyncFib h = new AsyncFib(7);
935 <                    h.fork();
936 <                    AsyncFib g = new AsyncFib(9);
937 <                    g.fork();
938 <                    AsyncFib f = new AsyncFib(8);
939 <                    f.fork();
940 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
941 <                    helpQuiesce();
942 <                }
943 <            };
944 <        singletonPool.invoke(a);
932 >        RecursiveAction a = new CheckedRecursiveAction() {
933 >            public void realCompute() {
934 >                AsyncFib h = new AsyncFib(7);
935 >                assertSame(h, h.fork());
936 >                AsyncFib g = new AsyncFib(9);
937 >                assertSame(g, g.fork());
938 >                AsyncFib f = new AsyncFib(8);
939 >                assertSame(f, f.fork());
940 >                assertTrue(getSurplusQueuedTaskCount() > 0);
941 >                helpQuiesce();
942 >                assertEquals(0, getSurplusQueuedTaskCount());
943 >                checkCompletedNormally(f);
944 >                checkCompletedNormally(g);
945 >                checkCompletedNormally(h);
946 >            }};
947 >        testInvokeOnPool(singletonPool(), a);
948      }
949  
950 <    /**
950 >    /**
951       * peekNextLocalTask returns most recent unexecuted task.
952       */
953      public void testPeekNextLocalTask() {
954 <        RecursiveAction a = new RecursiveAction() {
955 <                public void compute() {
956 <                    AsyncFib g = new AsyncFib(9);
957 <                    g.fork();
958 <                    AsyncFib f = new AsyncFib(8);
959 <                    f.fork();
960 <                    threadAssertTrue(peekNextLocalTask() == f);
961 <                    f.join();
962 <                    threadAssertTrue(f.isDone());
963 <                    helpQuiesce();
964 <                }
965 <            };
966 <        singletonPool.invoke(a);
954 >        RecursiveAction a = new CheckedRecursiveAction() {
955 >            public void realCompute() {
956 >                AsyncFib g = new AsyncFib(9);
957 >                assertSame(g, g.fork());
958 >                AsyncFib f = new AsyncFib(8);
959 >                assertSame(f, f.fork());
960 >                assertSame(f, peekNextLocalTask());
961 >                assertNull(f.join());
962 >                checkCompletedNormally(f);
963 >                helpQuiesce();
964 >                checkCompletedNormally(g);
965 >            }};
966 >        testInvokeOnPool(singletonPool(), a);
967      }
968  
969 <    /**
970 <     * pollNextLocalTask returns most recent unexecuted task
971 <     * without executing it
969 >    /**
970 >     * pollNextLocalTask returns most recent unexecuted task without
971 >     * executing it
972       */
973      public void testPollNextLocalTask() {
974 <        RecursiveAction a = new RecursiveAction() {
975 <                public void compute() {
976 <                    AsyncFib g = new AsyncFib(9);
977 <                    g.fork();
978 <                    AsyncFib f = new AsyncFib(8);
979 <                    f.fork();
980 <                    threadAssertTrue(pollNextLocalTask() == f);
981 <                    helpQuiesce();
982 <                    threadAssertFalse(f.isDone());
983 <                }
984 <            };
985 <        singletonPool.invoke(a);
986 <    }
987 <
988 <    /**
989 <     * pollTask returns an unexecuted task
990 <     * without executing it
974 >        RecursiveAction a = new CheckedRecursiveAction() {
975 >            public void realCompute() {
976 >                AsyncFib g = new AsyncFib(9);
977 >                assertSame(g, g.fork());
978 >                AsyncFib f = new AsyncFib(8);
979 >                assertSame(f, f.fork());
980 >                assertSame(f, pollNextLocalTask());
981 >                helpQuiesce();
982 >                checkNotDone(f);
983 >                assertEquals(34, g.number);
984 >                checkCompletedNormally(g);
985 >            }};
986 >        testInvokeOnPool(singletonPool(), a);
987 >    }
988 >
989 >    /**
990 >     * pollTask returns an unexecuted task without executing it
991       */
992      public void testPollTask() {
993 <        RecursiveAction a = new RecursiveAction() {
994 <                public void compute() {
995 <                    AsyncFib g = new AsyncFib(9);
996 <                    g.fork();
997 <                    AsyncFib f = new AsyncFib(8);
998 <                    f.fork();
999 <                    threadAssertTrue(pollTask() == f);
1000 <                    helpQuiesce();
1001 <                    threadAssertFalse(f.isDone());
1002 <                    threadAssertTrue(g.isDone());
1003 <                }
1004 <            };
1018 <        singletonPool.invoke(a);
993 >        RecursiveAction a = new CheckedRecursiveAction() {
994 >            public void realCompute() {
995 >                AsyncFib g = new AsyncFib(9);
996 >                assertSame(g, g.fork());
997 >                AsyncFib f = new AsyncFib(8);
998 >                assertSame(f, f.fork());
999 >                assertSame(f, pollTask());
1000 >                helpQuiesce();
1001 >                checkNotDone(f);
1002 >                checkCompletedNormally(g);
1003 >            }};
1004 >        testInvokeOnPool(singletonPool(), a);
1005      }
1006  
1007 <    /**
1007 >    /**
1008       * peekNextLocalTask returns least recent unexecuted task in async mode
1009       */
1010      public void testPeekNextLocalTaskAsync() {
1011 <        RecursiveAction a = new RecursiveAction() {
1012 <                public void compute() {
1013 <                    AsyncFib g = new AsyncFib(9);
1014 <                    g.fork();
1015 <                    AsyncFib f = new AsyncFib(8);
1016 <                    f.fork();
1017 <                    threadAssertTrue(peekNextLocalTask() == g);
1018 <                    f.join();
1019 <                    helpQuiesce();
1020 <                    threadAssertTrue(f.isDone());
1021 <                }
1022 <            };
1023 <        asyncSingletonPool.invoke(a);
1011 >        RecursiveAction a = new CheckedRecursiveAction() {
1012 >            public 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(g, peekNextLocalTask());
1018 >                assertNull(f.join());
1019 >                helpQuiesce();
1020 >                checkCompletedNormally(f);
1021 >                assertEquals(34, g.number);
1022 >                checkCompletedNormally(g);
1023 >            }};
1024 >        testInvokeOnPool(asyncSingletonPool(), a);
1025      }
1026  
1027 <    /**
1028 <     * pollNextLocalTask returns least recent unexecuted task
1029 <     * without executing it, in async mode
1027 >    /**
1028 >     * pollNextLocalTask returns least recent unexecuted task without
1029 >     * executing it, in async mode
1030       */
1031      public void testPollNextLocalTaskAsync() {
1032 <        RecursiveAction a = new RecursiveAction() {
1033 <                public void compute() {
1034 <                    AsyncFib g = new AsyncFib(9);
1035 <                    g.fork();
1036 <                    AsyncFib f = new AsyncFib(8);
1037 <                    f.fork();
1038 <                    threadAssertTrue(pollNextLocalTask() == g);
1039 <                    helpQuiesce();
1040 <                    threadAssertTrue(f.isDone());
1041 <                    threadAssertFalse(g.isDone());
1042 <                }
1043 <            };
1044 <        asyncSingletonPool.invoke(a);
1045 <    }
1046 <
1047 <    /**
1048 <     * pollTask returns an unexecuted task
1049 <     * without executing it, in async mode
1032 >        RecursiveAction a = new CheckedRecursiveAction() {
1033 >            public void realCompute() {
1034 >                AsyncFib g = new AsyncFib(9);
1035 >                assertSame(g, g.fork());
1036 >                AsyncFib f = new AsyncFib(8);
1037 >                assertSame(f, f.fork());
1038 >                assertSame(g, pollNextLocalTask());
1039 >                helpQuiesce();
1040 >                assertEquals(21, f.number);
1041 >                checkCompletedNormally(f);
1042 >                checkNotDone(g);
1043 >            }};
1044 >        testInvokeOnPool(asyncSingletonPool(), a);
1045 >    }
1046 >
1047 >    /**
1048 >     * pollTask returns an unexecuted task without executing it, in
1049 >     * async mode
1050       */
1051      public void testPollTaskAsync() {
1052 <        RecursiveAction a = new RecursiveAction() {
1053 <                public void compute() {
1054 <                    AsyncFib g = new AsyncFib(9);
1055 <                    g.fork();
1056 <                    AsyncFib f = new AsyncFib(8);
1057 <                    f.fork();
1058 <                    threadAssertTrue(pollTask() == g);
1059 <                    helpQuiesce();
1060 <                    threadAssertTrue(f.isDone());
1061 <                    threadAssertFalse(g.isDone());
1052 >        RecursiveAction a = new CheckedRecursiveAction() {
1053 >            public void realCompute() {
1054 >                AsyncFib g = new AsyncFib(9);
1055 >                assertSame(g, g.fork());
1056 >                AsyncFib f = new AsyncFib(8);
1057 >                assertSame(f, f.fork());
1058 >                assertSame(g, pollTask());
1059 >                helpQuiesce();
1060 >                assertEquals(21, f.number);
1061 >                checkCompletedNormally(f);
1062 >                checkNotDone(g);
1063 >            }};
1064 >        testInvokeOnPool(asyncSingletonPool(), a);
1065 >    }
1066 >
1067 >    // versions for singleton pools
1068 >
1069 >    /**
1070 >     * invoke returns when task completes normally.
1071 >     * isCompletedAbnormally and isCancelled return false for normally
1072 >     * completed tasks. getRawResult of a RecursiveAction returns null;
1073 >     */
1074 >    public void testInvokeSingleton() {
1075 >        RecursiveAction a = new CheckedRecursiveAction() {
1076 >            public void realCompute() {
1077 >                AsyncFib f = new AsyncFib(8);
1078 >                assertNull(f.invoke());
1079 >                assertEquals(21, f.number);
1080 >                checkCompletedNormally(f);
1081 >            }};
1082 >        testInvokeOnPool(singletonPool(), a);
1083 >    }
1084 >
1085 >    /**
1086 >     * quietlyInvoke task returns when task completes normally.
1087 >     * isCompletedAbnormally and isCancelled return false for normally
1088 >     * completed tasks
1089 >     */
1090 >    public void testQuietlyInvokeSingleton() {
1091 >        RecursiveAction a = new CheckedRecursiveAction() {
1092 >            public void realCompute() {
1093 >                AsyncFib f = new AsyncFib(8);
1094 >                f.quietlyInvoke();
1095 >                assertEquals(21, f.number);
1096 >                checkCompletedNormally(f);
1097 >            }};
1098 >        testInvokeOnPool(singletonPool(), a);
1099 >    }
1100 >
1101 >    /**
1102 >     * join of a forked task returns when task completes
1103 >     */
1104 >    public void testForkJoinSingleton() {
1105 >        RecursiveAction a = new CheckedRecursiveAction() {
1106 >            public void realCompute() {
1107 >                AsyncFib f = new AsyncFib(8);
1108 >                assertSame(f, f.fork());
1109 >                assertNull(f.join());
1110 >                assertEquals(21, f.number);
1111 >                checkCompletedNormally(f);
1112 >            }};
1113 >        testInvokeOnPool(singletonPool(), a);
1114 >    }
1115 >
1116 >    /**
1117 >     * get of a forked task returns when task completes
1118 >     */
1119 >    public void testForkGetSingleton() {
1120 >        RecursiveAction a = new CheckedRecursiveAction() {
1121 >            public void realCompute() throws Exception {
1122 >                AsyncFib f = new AsyncFib(8);
1123 >                assertSame(f, f.fork());
1124 >                assertNull(f.get());
1125 >                assertEquals(21, f.number);
1126 >                checkCompletedNormally(f);
1127 >            }};
1128 >        testInvokeOnPool(singletonPool(), a);
1129 >    }
1130 >
1131 >    /**
1132 >     * timed get of a forked task returns when task completes
1133 >     */
1134 >    public void testForkTimedGetSingleton() {
1135 >        RecursiveAction a = new CheckedRecursiveAction() {
1136 >            public void realCompute() throws Exception {
1137 >                AsyncFib f = new AsyncFib(8);
1138 >                assertSame(f, f.fork());
1139 >                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1140 >                assertEquals(21, f.number);
1141 >                checkCompletedNormally(f);
1142 >            }};
1143 >        testInvokeOnPool(singletonPool(), a);
1144 >    }
1145 >
1146 >    /**
1147 >     * timed get with null time unit throws NPE
1148 >     */
1149 >    public void testForkTimedGetNPESingleton() {
1150 >        RecursiveAction a = new CheckedRecursiveAction() {
1151 >            public void realCompute() throws Exception {
1152 >                AsyncFib f = new AsyncFib(8);
1153 >                assertSame(f, f.fork());
1154 >                try {
1155 >                    f.get(5L, null);
1156 >                    shouldThrow();
1157 >                } catch (NullPointerException success) {}
1158 >            }};
1159 >        testInvokeOnPool(singletonPool(), a);
1160 >    }
1161 >
1162 >    /**
1163 >     * quietlyJoin of a forked task returns when task completes
1164 >     */
1165 >    public void testForkQuietlyJoinSingleton() {
1166 >        RecursiveAction a = new CheckedRecursiveAction() {
1167 >            public void realCompute() {
1168 >                AsyncFib f = new AsyncFib(8);
1169 >                assertSame(f, f.fork());
1170 >                f.quietlyJoin();
1171 >                assertEquals(21, f.number);
1172 >                checkCompletedNormally(f);
1173 >            }};
1174 >        testInvokeOnPool(singletonPool(), a);
1175 >    }
1176 >
1177 >
1178 >    /**
1179 >     * helpQuiesce returns when tasks are complete.
1180 >     * getQueuedTaskCount returns 0 when quiescent
1181 >     */
1182 >    public void testForkHelpQuiesceSingleton() {
1183 >        RecursiveAction a = new CheckedRecursiveAction() {
1184 >            public void realCompute() {
1185 >                AsyncFib f = new AsyncFib(8);
1186 >                assertSame(f, f.fork());
1187 >                f.helpQuiesce();
1188 >                assertEquals(0, getQueuedTaskCount());
1189 >                assertEquals(21, f.number);
1190 >                checkCompletedNormally(f);
1191 >            }};
1192 >        testInvokeOnPool(singletonPool(), a);
1193 >    }
1194 >
1195 >
1196 >    /**
1197 >     * invoke task throws exception when task completes abnormally
1198 >     */
1199 >    public void testAbnormalInvokeSingleton() {
1200 >        RecursiveAction a = new CheckedRecursiveAction() {
1201 >            public void realCompute() {
1202 >                FailingAsyncFib f = new FailingAsyncFib(8);
1203 >                try {
1204 >                    f.invoke();
1205 >                    shouldThrow();
1206 >                } catch (FJException success) {
1207 >                    checkCompletedAbnormally(f, success);
1208 >                }
1209 >            }};
1210 >        testInvokeOnPool(singletonPool(), a);
1211 >    }
1212 >
1213 >    /**
1214 >     * quietlyInvoke task returns when task completes abnormally
1215 >     */
1216 >    public void testAbnormalQuietlyInvokeSingleton() {
1217 >        RecursiveAction a = new CheckedRecursiveAction() {
1218 >            public void realCompute() {
1219 >                FailingAsyncFib f = new FailingAsyncFib(8);
1220 >                f.quietlyInvoke();
1221 >                assertTrue(f.getException() instanceof FJException);
1222 >                checkCompletedAbnormally(f, f.getException());
1223 >            }};
1224 >        testInvokeOnPool(singletonPool(), a);
1225 >    }
1226 >
1227 >    /**
1228 >     * join of a forked task throws exception when task completes abnormally
1229 >     */
1230 >    public void testAbnormalForkJoinSingleton() {
1231 >        RecursiveAction a = new CheckedRecursiveAction() {
1232 >            public void realCompute() {
1233 >                FailingAsyncFib f = new FailingAsyncFib(8);
1234 >                assertSame(f, f.fork());
1235 >                try {
1236 >                    f.join();
1237 >                    shouldThrow();
1238 >                } catch (FJException success) {
1239 >                    checkCompletedAbnormally(f, success);
1240 >                }
1241 >            }};
1242 >        testInvokeOnPool(singletonPool(), a);
1243 >    }
1244 >
1245 >    /**
1246 >     * get of a forked task throws exception when task completes abnormally
1247 >     */
1248 >    public void testAbnormalForkGetSingleton() {
1249 >        RecursiveAction a = new CheckedRecursiveAction() {
1250 >            public void realCompute() throws Exception {
1251 >                FailingAsyncFib f = new FailingAsyncFib(8);
1252 >                assertSame(f, f.fork());
1253 >                try {
1254 >                    f.get();
1255 >                    shouldThrow();
1256 >                } catch (ExecutionException success) {
1257 >                    Throwable cause = success.getCause();
1258 >                    assertTrue(cause instanceof FJException);
1259 >                    checkCompletedAbnormally(f, cause);
1260 >                }
1261 >            }};
1262 >        testInvokeOnPool(singletonPool(), a);
1263 >    }
1264 >
1265 >    /**
1266 >     * timed get of a forked task throws exception when task completes abnormally
1267 >     */
1268 >    public void testAbnormalForkTimedGetSingleton() {
1269 >        RecursiveAction a = new CheckedRecursiveAction() {
1270 >            public void realCompute() throws Exception {
1271 >                FailingAsyncFib f = new FailingAsyncFib(8);
1272 >                assertSame(f, f.fork());
1273 >                try {
1274 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
1275 >                    shouldThrow();
1276 >                } catch (ExecutionException success) {
1277 >                    Throwable cause = success.getCause();
1278 >                    assertTrue(cause instanceof FJException);
1279 >                    checkCompletedAbnormally(f, cause);
1280 >                }
1281 >            }};
1282 >        testInvokeOnPool(singletonPool(), a);
1283 >    }
1284 >
1285 >    /**
1286 >     * quietlyJoin of a forked task returns when task completes abnormally
1287 >     */
1288 >    public void testAbnormalForkQuietlyJoinSingleton() {
1289 >        RecursiveAction a = new CheckedRecursiveAction() {
1290 >            public void realCompute() {
1291 >                FailingAsyncFib f = new FailingAsyncFib(8);
1292 >                assertSame(f, f.fork());
1293 >                f.quietlyJoin();
1294 >                assertTrue(f.getException() instanceof FJException);
1295 >                checkCompletedAbnormally(f, f.getException());
1296 >            }};
1297 >        testInvokeOnPool(singletonPool(), a);
1298 >    }
1299 >
1300 >    /**
1301 >     * invoke task throws exception when task cancelled
1302 >     */
1303 >    public void testCancelledInvokeSingleton() {
1304 >        RecursiveAction a = new CheckedRecursiveAction() {
1305 >            public void realCompute() {
1306 >                AsyncFib f = new AsyncFib(8);
1307 >                assertTrue(f.cancel(true));
1308 >                try {
1309 >                    f.invoke();
1310 >                    shouldThrow();
1311 >                } catch (CancellationException success) {
1312 >                    checkCancelled(f);
1313 >                }
1314 >            }};
1315 >        testInvokeOnPool(singletonPool(), a);
1316 >    }
1317 >
1318 >    /**
1319 >     * join of a forked task throws exception when task cancelled
1320 >     */
1321 >    public void testCancelledForkJoinSingleton() {
1322 >        RecursiveAction a = new CheckedRecursiveAction() {
1323 >            public void realCompute() {
1324 >                AsyncFib f = new AsyncFib(8);
1325 >                assertTrue(f.cancel(true));
1326 >                assertSame(f, f.fork());
1327 >                try {
1328 >                    f.join();
1329 >                    shouldThrow();
1330 >                } catch (CancellationException success) {
1331 >                    checkCancelled(f);
1332 >                }
1333 >            }};
1334 >        testInvokeOnPool(singletonPool(), a);
1335 >    }
1336 >
1337 >    /**
1338 >     * get of a forked task throws exception when task cancelled
1339 >     */
1340 >    public void testCancelledForkGetSingleton() {
1341 >        RecursiveAction a = new CheckedRecursiveAction() {
1342 >            public void realCompute() throws Exception {
1343 >                AsyncFib f = new AsyncFib(8);
1344 >                assertTrue(f.cancel(true));
1345 >                assertSame(f, f.fork());
1346 >                try {
1347 >                    f.get();
1348 >                    shouldThrow();
1349 >                } catch (CancellationException success) {
1350 >                    checkCancelled(f);
1351 >                }
1352 >            }};
1353 >        testInvokeOnPool(singletonPool(), a);
1354 >    }
1355 >
1356 >    /**
1357 >     * timed get of a forked task throws exception when task cancelled
1358 >     */
1359 >    public void testCancelledForkTimedGetSingleton() throws Exception {
1360 >        RecursiveAction a = new CheckedRecursiveAction() {
1361 >            public void realCompute() throws Exception {
1362 >                AsyncFib f = new AsyncFib(8);
1363 >                assertTrue(f.cancel(true));
1364 >                assertSame(f, f.fork());
1365 >                try {
1366 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
1367 >                    shouldThrow();
1368 >                } catch (CancellationException success) {
1369 >                    checkCancelled(f);
1370 >                }
1371 >            }};
1372 >        testInvokeOnPool(singletonPool(), a);
1373 >    }
1374 >
1375 >    /**
1376 >     * quietlyJoin of a forked task returns when task cancelled
1377 >     */
1378 >    public void testCancelledForkQuietlyJoinSingleton() {
1379 >        RecursiveAction a = new CheckedRecursiveAction() {
1380 >            public void realCompute() {
1381 >                AsyncFib f = new AsyncFib(8);
1382 >                assertTrue(f.cancel(true));
1383 >                assertSame(f, f.fork());
1384 >                f.quietlyJoin();
1385 >                checkCancelled(f);
1386 >            }};
1387 >        testInvokeOnPool(singletonPool(), a);
1388 >    }
1389 >
1390 >    /**
1391 >     * invoke task throws exception after invoking completeExceptionally
1392 >     */
1393 >    public void testCompleteExceptionallySingleton() {
1394 >        RecursiveAction a = new CheckedRecursiveAction() {
1395 >            public void realCompute() {
1396 >                AsyncFib f = new AsyncFib(8);
1397 >                f.completeExceptionally(new FJException());
1398 >                try {
1399 >                    f.invoke();
1400 >                    shouldThrow();
1401 >                } catch (FJException success) {
1402 >                    checkCompletedAbnormally(f, success);
1403 >                }
1404 >            }};
1405 >        testInvokeOnPool(singletonPool(), a);
1406 >    }
1407 >
1408 >    /**
1409 >     * invokeAll(t1, t2) invokes all task arguments
1410 >     */
1411 >    public void testInvokeAll2Singleton() {
1412 >        RecursiveAction a = new CheckedRecursiveAction() {
1413 >            public void realCompute() {
1414 >                AsyncFib f = new AsyncFib(8);
1415 >                AsyncFib g = new AsyncFib(9);
1416 >                invokeAll(f, g);
1417 >                assertEquals(21, f.number);
1418 >                assertEquals(34, g.number);
1419 >                checkCompletedNormally(f);
1420 >                checkCompletedNormally(g);
1421 >            }};
1422 >        testInvokeOnPool(singletonPool(), a);
1423 >    }
1424 >
1425 >    /**
1426 >     * invokeAll(tasks) with 1 argument invokes task
1427 >     */
1428 >    public void testInvokeAll1Singleton() {
1429 >        RecursiveAction a = new CheckedRecursiveAction() {
1430 >            public void realCompute() {
1431 >                AsyncFib f = new AsyncFib(8);
1432 >                invokeAll(f);
1433 >                checkCompletedNormally(f);
1434 >                assertEquals(21, f.number);
1435 >            }};
1436 >        testInvokeOnPool(singletonPool(), a);
1437 >    }
1438 >
1439 >    /**
1440 >     * invokeAll(tasks) with > 2 argument invokes tasks
1441 >     */
1442 >    public void testInvokeAll3Singleton() {
1443 >        RecursiveAction a = new CheckedRecursiveAction() {
1444 >            public void realCompute() {
1445 >                AsyncFib f = new AsyncFib(8);
1446 >                AsyncFib g = new AsyncFib(9);
1447 >                AsyncFib h = new AsyncFib(7);
1448 >                invokeAll(f, g, h);
1449 >                assertEquals(21, f.number);
1450 >                assertEquals(34, g.number);
1451 >                assertEquals(13, h.number);
1452 >                checkCompletedNormally(f);
1453 >                checkCompletedNormally(g);
1454 >                checkCompletedNormally(h);
1455 >            }};
1456 >        testInvokeOnPool(singletonPool(), a);
1457 >    }
1458 >
1459 >    /**
1460 >     * invokeAll(collection) invokes all tasks in the collection
1461 >     */
1462 >    public void testInvokeAllCollectionSingleton() {
1463 >        RecursiveAction a = new CheckedRecursiveAction() {
1464 >            public void realCompute() {
1465 >                AsyncFib f = new AsyncFib(8);
1466 >                AsyncFib g = new AsyncFib(9);
1467 >                AsyncFib h = new AsyncFib(7);
1468 >                HashSet set = new HashSet();
1469 >                set.add(f);
1470 >                set.add(g);
1471 >                set.add(h);
1472 >                invokeAll(set);
1473 >                assertEquals(21, f.number);
1474 >                assertEquals(34, g.number);
1475 >                assertEquals(13, h.number);
1476 >                checkCompletedNormally(f);
1477 >                checkCompletedNormally(g);
1478 >                checkCompletedNormally(h);
1479 >            }};
1480 >        testInvokeOnPool(singletonPool(), a);
1481 >    }
1482 >
1483 >
1484 >    /**
1485 >     * invokeAll(tasks) with any null task throws NPE
1486 >     */
1487 >    public void testInvokeAllNPESingleton() {
1488 >        RecursiveAction a = new CheckedRecursiveAction() {
1489 >            public void realCompute() {
1490 >                AsyncFib f = new AsyncFib(8);
1491 >                AsyncFib g = new AsyncFib(9);
1492 >                AsyncFib h = null;
1493 >                try {
1494 >                    invokeAll(f, g, h);
1495 >                    shouldThrow();
1496 >                } catch (NullPointerException success) {}
1497 >            }};
1498 >        testInvokeOnPool(singletonPool(), a);
1499 >    }
1500 >
1501 >    /**
1502 >     * invokeAll(t1, t2) throw exception if any task does
1503 >     */
1504 >    public void testAbnormalInvokeAll2Singleton() {
1505 >        RecursiveAction a = new CheckedRecursiveAction() {
1506 >            public void realCompute() {
1507 >                AsyncFib f = new AsyncFib(8);
1508 >                FailingAsyncFib g = new FailingAsyncFib(9);
1509 >                try {
1510 >                    invokeAll(f, g);
1511 >                    shouldThrow();
1512 >                } catch (FJException success) {
1513 >                    checkCompletedAbnormally(g, success);
1514                  }
1515 <            };
1516 <        asyncSingletonPool.invoke(a);
1515 >            }};
1516 >        testInvokeOnPool(singletonPool(), a);
1517      }
1518 +
1519 +    /**
1520 +     * invokeAll(tasks) with 1 argument throws exception if task does
1521 +     */
1522 +    public void testAbnormalInvokeAll1Singleton() {
1523 +        RecursiveAction a = new CheckedRecursiveAction() {
1524 +            public void realCompute() {
1525 +                FailingAsyncFib g = new FailingAsyncFib(9);
1526 +                try {
1527 +                    invokeAll(g);
1528 +                    shouldThrow();
1529 +                } catch (FJException success) {
1530 +                    checkCompletedAbnormally(g, success);
1531 +                }
1532 +            }};
1533 +        testInvokeOnPool(singletonPool(), a);
1534 +    }
1535 +
1536 +    /**
1537 +     * invokeAll(tasks) with > 2 argument throws exception if any task does
1538 +     */
1539 +    public void testAbnormalInvokeAll3Singleton() {
1540 +        RecursiveAction a = new CheckedRecursiveAction() {
1541 +            public void realCompute() {
1542 +                AsyncFib f = new AsyncFib(8);
1543 +                FailingAsyncFib g = new FailingAsyncFib(9);
1544 +                AsyncFib h = new AsyncFib(7);
1545 +                try {
1546 +                    invokeAll(f, g, h);
1547 +                    shouldThrow();
1548 +                } catch (FJException success) {
1549 +                    checkCompletedAbnormally(g, success);
1550 +                }
1551 +            }};
1552 +        testInvokeOnPool(singletonPool(), a);
1553 +    }
1554 +
1555 +    /**
1556 +     * invokeAll(collection)  throws exception if any task does
1557 +     */
1558 +    public void testAbnormalInvokeAllCollectionSingleton() {
1559 +        RecursiveAction a = new CheckedRecursiveAction() {
1560 +            public void realCompute() {
1561 +                FailingAsyncFib f = new FailingAsyncFib(8);
1562 +                AsyncFib g = new AsyncFib(9);
1563 +                AsyncFib h = new AsyncFib(7);
1564 +                HashSet set = new HashSet();
1565 +                set.add(f);
1566 +                set.add(g);
1567 +                set.add(h);
1568 +                try {
1569 +                    invokeAll(set);
1570 +                    shouldThrow();
1571 +                } catch (FJException success) {
1572 +                    checkCompletedAbnormally(f, success);
1573 +                }
1574 +            }};
1575 +        testInvokeOnPool(singletonPool(), a);
1576 +    }
1577 +
1578   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines