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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines