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.18 by jsr166, Fri Sep 17 00:55:19 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 >    private static ForkJoinPool mainPool() {
29 >        return new ForkJoinPool();
30 >    }
31 >
32 >    private static ForkJoinPool singletonPool() {
33 >        return new ForkJoinPool(1);
34 >    }
35 >
36 >    private static ForkJoinPool asyncSingletonPool() {
37 >        return new ForkJoinPool(1,
38 >                                ForkJoinPool.defaultForkJoinWorkerThreadFactory,
39 >                                null, true);
40 >    }
41 >
42 >    private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
43 >        try {
44 >            assertFalse(a.isDone());
45 >            assertFalse(a.isCompletedNormally());
46 >            assertFalse(a.isCompletedAbnormally());
47 >            assertFalse(a.isCancelled());
48 >            assertNull(a.getException());
49 >
50 >            assertNull(pool.invoke(a));
51 >
52 >            assertTrue(a.isDone());
53 >            assertTrue(a.isCompletedNormally());
54 >            assertFalse(a.isCompletedAbnormally());
55 >            assertFalse(a.isCancelled());
56 >            assertNull(a.getException());
57 >        } finally {
58 >            joinPool(pool);
59 >        }
60 >    }
61 >
62 >    /*
63       * Testing coverage notes:
64 <     *
64 >     *
65       * To test extension methods and overrides, most tests use
66       * BinaryAsyncAction extension class that processes joins
67       * differently than supplied Recursive forms.
68 <     */    
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 <    }
68 >     */
69  
70      static final class FJException extends RuntimeException {
71          FJException() { super(); }
# Line 40 | Line 75 | public class ForkJoinTaskTest extends JS
75          private volatile int controlState;
76  
77          static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
78 <            AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
78 >            AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
79                                                   "controlState");
80  
81          private BinaryAsyncAction parent;
# Line 92 | Line 127 | public class ForkJoinTaskTest extends JS
127                      break;
128                  try {
129                      p.onComplete(a, s);
130 <                } catch(Throwable rex) {
130 >                } catch (Throwable rex) {
131                      p.completeExceptionally(rex);
132                      return;
133                  }
# Line 129 | Line 164 | public class ForkJoinTaskTest extends JS
164              return controlState;
165          }
166  
167 <        protected final boolean compareAndSetControlState(int expect,
167 >        protected final boolean compareAndSetControlState(int expect,
168                                                            int update) {
169              return controlStateUpdater.compareAndSet(this, expect, update);
170          }
# Line 148 | Line 183 | public class ForkJoinTaskTest extends JS
183  
184      }
185  
186 <    static final class AsyncFib  extends BinaryAsyncAction {
186 >    static final class AsyncFib extends BinaryAsyncAction {
187          int number;
188 <        public AsyncFib(int n) {
188 >        public AsyncFib(int n) {
189              this.number = n;
190          }
191 <        
191 >
192          public final boolean exec() {
193              AsyncFib f = this;
194              int n = f.number;
# Line 177 | Line 212 | public class ForkJoinTaskTest extends JS
212      }
213  
214  
215 <    static final class FailingAsyncFib  extends BinaryAsyncAction {
215 >    static final class FailingAsyncFib extends BinaryAsyncAction {
216          int number;
217 <        public FailingAsyncFib(int n) {
217 >        public FailingAsyncFib(int n) {
218              this.number = n;
219          }
220 <        
220 >
221          public final boolean exec() {
222              FailingAsyncFib f = this;
223              int n = f.number;
# Line 205 | Line 240 | public class ForkJoinTaskTest extends JS
240          }
241      }
242  
243 <    /**
243 >    /**
244       * invoke returns when task completes normally.
245       * isCompletedAbnormally and isCancelled return false for normally
246       * completed tasks. getRawResult of a RecursiveAction returns null;
212     *
247       */
248      public void testInvoke() {
249 <        RecursiveAction a = new RecursiveAction() {
250 <                public void compute() {
251 <                    AsyncFib f = new AsyncFib(8);
252 <                    f.invoke();
253 <                    threadAssertTrue(f.number == 21);
254 <                    threadAssertTrue(f.isDone());
255 <                    threadAssertFalse(f.isCancelled());
256 <                    threadAssertFalse(f.isCompletedAbnormally());
257 <                    threadAssertTrue(f.getRawResult() == null);
258 <                }
259 <            };
226 <        mainPool.invoke(a);
249 >        RecursiveAction a = new CheckedRecursiveAction() {
250 >            public void realCompute() {
251 >                AsyncFib f = new AsyncFib(8);
252 >                assertNull(f.invoke());
253 >                assertEquals(21, f.number);
254 >                assertTrue(f.isDone());
255 >                assertFalse(f.isCancelled());
256 >                assertFalse(f.isCompletedAbnormally());
257 >                assertNull(f.getRawResult());
258 >            }};
259 >        testInvokeOnPool(mainPool(), a);
260      }
261  
262 <    /**
262 >    /**
263       * quietlyInvoke task returns when task completes normally.
264       * isCompletedAbnormally and isCancelled return false for normally
265       * completed tasks
266       */
267      public void testQuietlyInvoke() {
268 <        RecursiveAction a = new RecursiveAction() {
269 <                public void compute() {
270 <                    AsyncFib f = new AsyncFib(8);
271 <                    f.quietlyInvoke();
272 <                    threadAssertTrue(f.number == 21);
273 <                    threadAssertTrue(f.isDone());
274 <                    threadAssertFalse(f.isCancelled());
275 <                    threadAssertFalse(f.isCompletedAbnormally());
276 <                    threadAssertTrue(f.getRawResult() == null);
277 <                }
278 <            };
246 <        mainPool.invoke(a);
268 >        RecursiveAction a = new CheckedRecursiveAction() {
269 >            public void realCompute() {
270 >                AsyncFib f = new AsyncFib(8);
271 >                f.quietlyInvoke();
272 >                assertEquals(21, f.number);
273 >                assertTrue(f.isDone());
274 >                assertFalse(f.isCancelled());
275 >                assertFalse(f.isCompletedAbnormally());
276 >                assertNull(f.getRawResult());
277 >            }};
278 >        testInvokeOnPool(mainPool(), a);
279      }
280  
281 <    /**
281 >    /**
282       * join of a forked task returns when task completes
283       */
284      public void testForkJoin() {
285 <        RecursiveAction a = new RecursiveAction() {
286 <                public void compute() {
287 <                    AsyncFib f = new AsyncFib(8);
288 <                    f.fork();
289 <                    f.join();
290 <                    threadAssertTrue(f.number == 21);
291 <                    threadAssertTrue(f.isDone());
292 <                    threadAssertTrue(f.getRawResult() == null);
293 <                }
294 <            };
263 <        mainPool.invoke(a);
285 >        RecursiveAction a = new CheckedRecursiveAction() {
286 >            public void realCompute() {
287 >                AsyncFib f = new AsyncFib(8);
288 >                assertSame(f, f.fork());
289 >                assertNull(f.join());
290 >                assertEquals(21, f.number);
291 >                assertTrue(f.isDone());
292 >                assertNull(f.getRawResult());
293 >            }};
294 >        testInvokeOnPool(mainPool(), a);
295      }
296  
297 <    /**
297 >    /**
298       * get of a forked task returns when task completes
299       */
300      public void testForkGet() {
301 <        RecursiveAction a = new RecursiveAction() {
302 <                public void compute() {
303 <                    try {
304 <                        AsyncFib f = new AsyncFib(8);
305 <                        f.fork();
306 <                        f.get();
307 <                        threadAssertTrue(f.number == 21);
308 <                        threadAssertTrue(f.isDone());
309 <                    } catch(Exception ex) {
279 <                        unexpectedException();
280 <                    }
281 <                }
282 <            };
283 <        mainPool.invoke(a);
301 >        RecursiveAction a = new CheckedRecursiveAction() {
302 >            public void realCompute() throws Exception {
303 >                AsyncFib f = new AsyncFib(8);
304 >                assertSame(f, f.fork());
305 >                assertNull(f.get());
306 >                assertEquals(21, f.number);
307 >                assertTrue(f.isDone());
308 >            }};
309 >        testInvokeOnPool(mainPool(), a);
310      }
311  
312 <    /**
312 >    /**
313       * timed get of a forked task returns when task completes
314       */
315      public void testForkTimedGet() {
316 <        RecursiveAction a = new RecursiveAction() {
317 <                public void compute() {
318 <                    try {
319 <                        AsyncFib f = new AsyncFib(8);
320 <                        f.fork();
321 <                        f.get(5L, TimeUnit.SECONDS);
322 <                        threadAssertTrue(f.number == 21);
323 <                        threadAssertTrue(f.isDone());
324 <                    } catch(Exception ex) {
299 <                        unexpectedException();
300 <                    }
301 <                }
302 <            };
303 <        mainPool.invoke(a);
316 >        RecursiveAction a = new CheckedRecursiveAction() {
317 >            public void realCompute() throws Exception {
318 >                AsyncFib f = new AsyncFib(8);
319 >                assertSame(f, f.fork());
320 >                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
321 >                assertEquals(21, f.number);
322 >                assertTrue(f.isDone());
323 >            }};
324 >        testInvokeOnPool(mainPool(), a);
325      }
326  
327 <    /**
327 >    /**
328       * timed get with null time unit throws NPE
329       */
330      public void testForkTimedGetNPE() {
331 <        RecursiveAction a = new RecursiveAction() {
332 <                public void compute() {
333 <                    try {
334 <                        AsyncFib f = new AsyncFib(8);
335 <                        f.fork();
336 <                        f.get(5L, null);
337 <                    } catch(NullPointerException success) {
338 <                    } catch(Exception ex) {
339 <                        unexpectedException();
340 <                    }
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);
331 >        RecursiveAction a = new CheckedRecursiveAction() {
332 >            public void realCompute() throws Exception {
333 >                AsyncFib f = new AsyncFib(8);
334 >                assertSame(f, f.fork());
335 >                try {
336 >                    f.get(5L, null);
337 >                    shouldThrow();
338 >                } catch (NullPointerException success) {}
339 >            }};
340 >        testInvokeOnPool(mainPool(), a);
341      }
342  
343 <    /**
343 >    /**
344       * quietlyJoin of a forked task returns when task completes
345       */
346      public void testForkQuietlyJoin() {
347 <        RecursiveAction a = new RecursiveAction() {
348 <                public void compute() {
349 <                    AsyncFib f = new AsyncFib(8);
350 <                    f.fork();
351 <                    f.quietlyJoin();
352 <                    threadAssertTrue(f.number == 21);
353 <                    threadAssertTrue(f.isDone());
354 <                }
355 <            };
354 <        mainPool.invoke(a);
355 <    }
356 <
357 <
358 <    /**
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);
347 >        RecursiveAction a = new CheckedRecursiveAction() {
348 >            public void realCompute() {
349 >                AsyncFib f = new AsyncFib(8);
350 >                assertSame(f, f.fork());
351 >                f.quietlyJoin();
352 >                assertEquals(21, f.number);
353 >                assertTrue(f.isDone());
354 >            }};
355 >        testInvokeOnPool(mainPool(), a);
356      }
357  
358  
359 <    /**
359 >    /**
360       * helpQuiesce returns when tasks are complete.
361       * getQueuedTaskCount returns 0 when quiescent
362       */
363      public void testForkHelpQuiesce() {
364 <        RecursiveAction a = new RecursiveAction() {
365 <                public void compute() {
366 <                    AsyncFib f = new AsyncFib(8);
367 <                    f.fork();
368 <                    f.helpQuiesce();
369 <                    threadAssertTrue(f.number == 21);
370 <                    threadAssertTrue(f.isDone());
371 <                    threadAssertTrue(getQueuedTaskCount() == 0);
372 <                }
373 <            };
390 <        mainPool.invoke(a);
364 >        RecursiveAction a = new CheckedRecursiveAction() {
365 >            public void realCompute() {
366 >                AsyncFib f = new AsyncFib(8);
367 >                assertSame(f, f.fork());
368 >                f.helpQuiesce();
369 >                assertEquals(21, f.number);
370 >                assertTrue(f.isDone());
371 >                assertEquals(0, getQueuedTaskCount());
372 >            }};
373 >        testInvokeOnPool(mainPool(), a);
374      }
375  
376  
377 <    /**
377 >    /**
378       * invoke task throws exception when task completes abnormally
379       */
380      public void testAbnormalInvoke() {
381 <        RecursiveAction a = new RecursiveAction() {
382 <                public void compute() {
383 <                    try {
384 <                        FailingAsyncFib f = new FailingAsyncFib(8);
385 <                        f.invoke();
386 <                        shouldThrow();
387 <                    } catch(FJException success) {
388 <                    }
389 <                }
407 <            };
408 <        mainPool.invoke(a);
381 >        RecursiveAction a = new CheckedRecursiveAction() {
382 >            public void realCompute() {
383 >                FailingAsyncFib f = new FailingAsyncFib(8);
384 >                try {
385 >                    f.invoke();
386 >                    shouldThrow();
387 >                } catch (FJException success) {}
388 >            }};
389 >        testInvokeOnPool(mainPool(), a);
390      }
391  
392 <    /**
393 <     * quietelyInvoke task returns when task completes abnormally
392 >    /**
393 >     * quietlyInvoke task returns when task completes abnormally
394       */
395      public void testAbnormalQuietlyInvoke() {
396 <        RecursiveAction a = new RecursiveAction() {
397 <                public void compute() {
398 <                    FailingAsyncFib f = new FailingAsyncFib(8);
399 <                    f.quietlyInvoke();
400 <                    threadAssertTrue(f.isDone());
401 <                }
402 <            };
422 <        mainPool.invoke(a);
396 >        RecursiveAction a = new CheckedRecursiveAction() {
397 >            public void realCompute() {
398 >                FailingAsyncFib f = new FailingAsyncFib(8);
399 >                f.quietlyInvoke();
400 >                assertTrue(f.isDone());
401 >            }};
402 >        testInvokeOnPool(mainPool(), a);
403      }
404  
405 <    /**
405 >    /**
406       * join of a forked task throws exception when task completes abnormally
407       */
408      public void testAbnormalForkJoin() {
409 <        RecursiveAction a = new RecursiveAction() {
410 <                public void compute() {
411 <                    try {
412 <                        FailingAsyncFib f = new FailingAsyncFib(8);
413 <                        f.fork();
414 <                        f.join();
415 <                        shouldThrow();
416 <                    } catch(FJException success) {
417 <                    }
418 <                }
439 <            };
440 <        mainPool.invoke(a);
409 >        RecursiveAction a = new CheckedRecursiveAction() {
410 >            public void realCompute() {
411 >                FailingAsyncFib f = new FailingAsyncFib(8);
412 >                assertSame(f, f.fork());
413 >                try {
414 >                    f.join();
415 >                    shouldThrow();
416 >                } catch (FJException success) {}
417 >            }};
418 >        testInvokeOnPool(mainPool(), a);
419      }
420  
421 <    /**
421 >    /**
422       * get of a forked task throws exception when task completes abnormally
423       */
424      public void testAbnormalForkGet() {
425 <        RecursiveAction a = new RecursiveAction() {
426 <                public void compute() {
427 <                    try {
428 <                        FailingAsyncFib f = new FailingAsyncFib(8);
429 <                        f.fork();
430 <                        f.get();
431 <                        shouldThrow();
432 <                    } catch(Exception success) {
433 <                    }
425 >        RecursiveAction a = new CheckedRecursiveAction() {
426 >            public void realCompute() throws Exception {
427 >                FailingAsyncFib f = new FailingAsyncFib(8);
428 >                assertSame(f, f.fork());
429 >                try {
430 >                    f.get();
431 >                    shouldThrow();
432 >                } catch (ExecutionException success) {
433 >                    Throwable cause = success.getCause();
434 >                    assertTrue(cause instanceof FJException);
435 >                    assertTrue(f.isDone());
436 >                    assertTrue(f.isCompletedAbnormally());
437 >                    assertSame(cause, f.getException());
438                  }
439 <            };
440 <        mainPool.invoke(a);
439 >            }};
440 >        testInvokeOnPool(mainPool(), a);
441      }
442  
443 <    /**
443 >    /**
444       * timed get of a forked task throws exception when task completes abnormally
445       */
446      public void testAbnormalForkTimedGet() {
447 <        RecursiveAction a = new RecursiveAction() {
448 <                public void compute() {
449 <                    try {
450 <                        FailingAsyncFib f = new FailingAsyncFib(8);
451 <                        f.fork();
452 <                        f.get(5L, TimeUnit.SECONDS);
453 <                        shouldThrow();
454 <                    } catch(Exception success) {
455 <                    }
456 <                }
457 <            };
458 <        mainPool.invoke(a);
459 <    }
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);
447 >        RecursiveAction a = new CheckedRecursiveAction() {
448 >            public void realCompute() throws Exception {
449 >                FailingAsyncFib f = new FailingAsyncFib(8);
450 >                assertSame(f, f.fork());
451 >                try {
452 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
453 >                    shouldThrow();
454 >                } catch (ExecutionException success) {
455 >                    Throwable cause = success.getCause();
456 >                    assertTrue(cause instanceof FJException);
457 >                    assertTrue(f.isDone());
458 >                    assertTrue(f.isCompletedAbnormally());
459 >                    assertSame(cause, f.getException());
460                  }
461 <            };
462 <        mainPool.invoke(a);
461 >            }};
462 >        testInvokeOnPool(mainPool(), a);
463      }
464  
465 <    /**
465 >    /**
466       * quietlyJoin of a forked task returns when task completes abnormally
467       */
468      public void testAbnormalForkQuietlyJoin() {
469 <        RecursiveAction a = new RecursiveAction() {
470 <                public void compute() {
471 <                    FailingAsyncFib f = new FailingAsyncFib(8);
472 <                    f.fork();
473 <                    f.quietlyJoin();
474 <                    threadAssertTrue(f.isDone());
475 <                    threadAssertTrue(f.isCompletedAbnormally());
476 <                    threadAssertTrue(f.getException() instanceof FJException);
477 <                }
478 <            };
532 <        mainPool.invoke(a);
469 >        RecursiveAction a = new CheckedRecursiveAction() {
470 >            public void realCompute() {
471 >                FailingAsyncFib f = new FailingAsyncFib(8);
472 >                assertSame(f, f.fork());
473 >                f.quietlyJoin();
474 >                assertTrue(f.isDone());
475 >                assertTrue(f.isCompletedAbnormally());
476 >                assertTrue(f.getException() instanceof FJException);
477 >            }};
478 >        testInvokeOnPool(mainPool(), a);
479      }
480  
481 <    /**
481 >    /**
482       * invoke task throws exception when task cancelled
483       */
484      public void testCancelledInvoke() {
485 <        RecursiveAction a = new RecursiveAction() {
486 <                public void compute() {
487 <                    try {
488 <                        AsyncFib f = new AsyncFib(8);
489 <                        f.cancel(true);
490 <                        f.invoke();
491 <                        shouldThrow();
492 <                    } catch(CancellationException success) {
493 <                    }
485 >        RecursiveAction a = new CheckedRecursiveAction() {
486 >            public void realCompute() {
487 >                AsyncFib f = new AsyncFib(8);
488 >                assertTrue(f.cancel(true));
489 >                try {
490 >                    f.invoke();
491 >                    shouldThrow();
492 >                } catch (CancellationException success) {
493 >                    assertTrue(f.isDone());
494 >                    assertTrue(f.isCancelled());
495 >                    assertTrue(f.isCompletedAbnormally());
496 >                    assertTrue(f.getException() instanceof CancellationException);
497                  }
498 <            };
499 <        mainPool.invoke(a);
498 >            }};
499 >        testInvokeOnPool(mainPool(), a);
500      }
501  
502 <    /**
502 >    /**
503       * join of a forked task throws exception when task cancelled
504       */
505      public void testCancelledForkJoin() {
506 <        RecursiveAction a = new RecursiveAction() {
507 <                public void compute() {
508 <                    try {
509 <                        AsyncFib f = new AsyncFib(8);
510 <                        f.cancel(true);
511 <                        f.fork();
512 <                        f.join();
513 <                        shouldThrow();
514 <                    } catch(CancellationException success) {
515 <                    }
506 >        RecursiveAction a = new CheckedRecursiveAction() {
507 >            public void realCompute() {
508 >                AsyncFib f = new AsyncFib(8);
509 >                assertTrue(f.cancel(true));
510 >                assertSame(f, f.fork());
511 >                try {
512 >                    f.join();
513 >                    shouldThrow();
514 >                } catch (CancellationException success) {
515 >                    assertTrue(f.isDone());
516 >                    assertTrue(f.isCancelled());
517 >                    assertTrue(f.isCompletedAbnormally());
518 >                    assertTrue(f.getException() instanceof CancellationException);
519                  }
520 <            };
521 <        mainPool.invoke(a);
520 >            }};
521 >        testInvokeOnPool(mainPool(), a);
522      }
523  
524 <    /**
524 >    /**
525       * get of a forked task throws exception when task cancelled
526       */
527      public void testCancelledForkGet() {
528 <        RecursiveAction a = new RecursiveAction() {
529 <                public void compute() {
530 <                    try {
531 <                        AsyncFib f = new AsyncFib(8);
532 <                        f.cancel(true);
533 <                        f.fork();
534 <                        f.get();
535 <                        shouldThrow();
536 <                    } catch(Exception success) {
537 <                    }
528 >        RecursiveAction a = new CheckedRecursiveAction() {
529 >            public void realCompute() throws Exception {
530 >                AsyncFib f = new AsyncFib(8);
531 >                assertTrue(f.cancel(true));
532 >                assertSame(f, f.fork());
533 >                try {
534 >                    f.get();
535 >                    shouldThrow();
536 >                } catch (CancellationException success) {
537 >                    assertTrue(f.isDone());
538 >                    assertTrue(f.isCancelled());
539 >                    assertTrue(f.isCompletedAbnormally());
540 >                    assertTrue(f.getException() instanceof CancellationException);
541                  }
542 <            };
543 <        mainPool.invoke(a);
542 >            }};
543 >        testInvokeOnPool(mainPool(), a);
544      }
545  
546 <    /**
546 >    /**
547       * timed get of a forked task throws exception when task cancelled
548       */
549 <    public void testCancelledForkTimedGet() {
550 <        RecursiveAction a = new RecursiveAction() {
551 <                public void compute() {
552 <                    try {
553 <                        AsyncFib f = new AsyncFib(8);
554 <                        f.cancel(true);
555 <                        f.fork();
556 <                        f.get(5L, TimeUnit.SECONDS);
557 <                        shouldThrow();
558 <                    } catch(Exception success) {
559 <                    }
560 <                }
561 <            };
562 <        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);
549 >    public void testCancelledForkTimedGet() throws Exception {
550 >        RecursiveAction a = new CheckedRecursiveAction() {
551 >            public void realCompute() throws Exception {
552 >                AsyncFib f = new AsyncFib(8);
553 >                assertTrue(f.cancel(true));
554 >                assertSame(f, f.fork());
555 >                try {
556 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
557 >                    shouldThrow();
558 >                } catch (CancellationException success) {
559 >                    assertTrue(f.isDone());
560 >                    assertTrue(f.isCancelled());
561 >                    assertTrue(f.isCompletedAbnormally());
562 >                    assertTrue(f.getException() instanceof CancellationException);
563                  }
564 <            };
565 <        mainPool.invoke(a);
564 >            }};
565 >        testInvokeOnPool(mainPool(), a);
566      }
567  
568 <    /**
568 >    /**
569       * quietlyJoin of a forked task returns when task cancelled
570       */
571      public void testCancelledForkQuietlyJoin() {
572 <        RecursiveAction a = new RecursiveAction() {
573 <                public void compute() {
574 <                    AsyncFib f = new AsyncFib(8);
575 <                    f.cancel(true);
576 <                    f.fork();
577 <                    f.quietlyJoin();
578 <                    threadAssertTrue(f.isDone());
579 <                    threadAssertTrue(f.isCompletedAbnormally());
580 <                    threadAssertTrue(f.getException() instanceof CancellationException);
581 <                }
582 <            };
583 <        mainPool.invoke(a);
572 >        RecursiveAction a = new CheckedRecursiveAction() {
573 >            public void realCompute() {
574 >                AsyncFib f = new AsyncFib(8);
575 >                assertTrue(f.cancel(true));
576 >                assertSame(f, f.fork());
577 >                f.quietlyJoin();
578 >                assertTrue(f.isDone());
579 >                assertTrue(f.isCompletedAbnormally());
580 >                assertTrue(f.isCancelled());
581 >                assertTrue(f.getException() instanceof CancellationException);
582 >            }};
583 >        testInvokeOnPool(mainPool(), a);
584      }
585  
586      /**
587       * getPool of executing task returns its pool
588       */
589      public void testGetPool() {
590 <        RecursiveAction a = new RecursiveAction() {
591 <                public void compute() {
592 <                    threadAssertTrue(getPool() == mainPool);
593 <                }
594 <            };
595 <        mainPool.invoke(a);
590 >        final ForkJoinPool mainPool = mainPool();
591 >        RecursiveAction a = new CheckedRecursiveAction() {
592 >            public void realCompute() {
593 >                assertSame(mainPool, getPool());
594 >            }};
595 >        testInvokeOnPool(mainPool, a);
596      }
597  
598      /**
599       * getPool of non-FJ task returns null
600       */
601      public void testGetPool2() {
602 <        RecursiveAction a = new RecursiveAction() {
603 <                public void compute() {
604 <                    threadAssertTrue(getPool() == null);
605 <                }
606 <            };
690 <        a.invoke();
602 >        RecursiveAction a = new CheckedRecursiveAction() {
603 >            public void realCompute() {
604 >                assertNull(getPool());
605 >            }};
606 >        assertNull(a.invoke());
607      }
608  
609      /**
610       * inForkJoinPool of executing task returns true
611       */
612      public void testInForkJoinPool() {
613 <        RecursiveAction a = new RecursiveAction() {
614 <                public void compute() {
615 <                    threadAssertTrue(inForkJoinPool());
616 <                }
617 <            };
702 <        mainPool.invoke(a);
613 >        RecursiveAction a = new CheckedRecursiveAction() {
614 >            public void realCompute() {
615 >                assertTrue(inForkJoinPool());
616 >            }};
617 >        testInvokeOnPool(mainPool(), a);
618      }
619  
620      /**
621       * inForkJoinPool of non-FJ task returns false
622       */
623      public void testInForkJoinPool2() {
624 <        RecursiveAction a = new RecursiveAction() {
625 <                public void compute() {
626 <                    threadAssertTrue(!inForkJoinPool());
627 <                }
628 <            };
714 <        a.invoke();
624 >        RecursiveAction a = new CheckedRecursiveAction() {
625 >            public void realCompute() {
626 >                assertTrue(!inForkJoinPool());
627 >            }};
628 >        assertNull(a.invoke());
629      }
630  
631      /**
632       * setRawResult(null) succeeds
633       */
634      public void testSetRawResult() {
635 <        RecursiveAction a = new RecursiveAction() {
636 <                public void compute() {
637 <                    setRawResult(null);
638 <                }
639 <            };
726 <        a.invoke();
635 >        RecursiveAction a = new CheckedRecursiveAction() {
636 >            public void realCompute() {
637 >                setRawResult(null);
638 >            }};
639 >        assertNull(a.invoke());
640      }
641  
642 <    /**
642 >    /**
643       * invoke task throws exception after invoking completeExceptionally
644       */
645      public void testCompleteExceptionally() {
646 <        RecursiveAction a = new RecursiveAction() {
647 <                public void compute() {
648 <                    try {
649 <                        AsyncFib f = new AsyncFib(8);
650 <                        f.completeExceptionally(new FJException());
651 <                        f.invoke();
652 <                        shouldThrow();
653 <                    } catch(FJException success) {
654 <                    }
655 <                }
743 <            };
744 <        mainPool.invoke(a);
646 >        RecursiveAction a = new CheckedRecursiveAction() {
647 >            public void realCompute() {
648 >                AsyncFib f = new AsyncFib(8);
649 >                f.completeExceptionally(new FJException());
650 >                try {
651 >                    f.invoke();
652 >                    shouldThrow();
653 >                } catch (FJException success) {}
654 >            }};
655 >        testInvokeOnPool(mainPool(), a);
656      }
657  
658 <    /**
658 >    /**
659       * invokeAll(t1, t2) invokes all task arguments
660       */
661      public void testInvokeAll2() {
662 <        RecursiveAction a = new RecursiveAction() {
663 <                public void compute() {
664 <                    AsyncFib f = new AsyncFib(8);
665 <                    AsyncFib g = new AsyncFib(9);
666 <                    invokeAll(f, g);
667 <                    threadAssertTrue(f.isDone());
668 <                    threadAssertTrue(f.number == 21);
669 <                    threadAssertTrue(g.isDone());
670 <                    threadAssertTrue(g.number == 34);
671 <                }
672 <            };
762 <        mainPool.invoke(a);
662 >        RecursiveAction a = new CheckedRecursiveAction() {
663 >            public void realCompute() {
664 >                AsyncFib f = new AsyncFib(8);
665 >                AsyncFib g = new AsyncFib(9);
666 >                invokeAll(f, g);
667 >                assertTrue(f.isDone());
668 >                assertEquals(21, f.number);
669 >                assertTrue(g.isDone());
670 >                assertEquals(34, g.number);
671 >            }};
672 >        testInvokeOnPool(mainPool(), a);
673      }
674  
675 <    /**
675 >    /**
676       * invokeAll(tasks) with 1 argument invokes task
677       */
678      public void testInvokeAll1() {
679 <        RecursiveAction a = new RecursiveAction() {
680 <                public void compute() {
681 <                    AsyncFib f = new AsyncFib(8);
682 <                    invokeAll(f);
683 <                    threadAssertTrue(f.isDone());
684 <                    threadAssertTrue(f.number == 21);
685 <                }
686 <            };
777 <        mainPool.invoke(a);
679 >        RecursiveAction a = new CheckedRecursiveAction() {
680 >            public void realCompute() {
681 >                AsyncFib f = new AsyncFib(8);
682 >                invokeAll(f);
683 >                assertTrue(f.isDone());
684 >                assertEquals(21, f.number);
685 >            }};
686 >        testInvokeOnPool(mainPool(), a);
687      }
688  
689 <    /**
689 >    /**
690       * invokeAll(tasks) with > 2 argument invokes tasks
691       */
692      public void testInvokeAll3() {
693 <        RecursiveAction a = new RecursiveAction() {
694 <                public void compute() {
695 <                    AsyncFib f = new AsyncFib(8);
696 <                    AsyncFib g = new AsyncFib(9);
697 <                    AsyncFib h = new AsyncFib(7);
698 <                    invokeAll(f, g, h);
699 <                    threadAssertTrue(f.isDone());
700 <                    threadAssertTrue(f.number == 21);
701 <                    threadAssertTrue(g.isDone());
702 <                    threadAssertTrue(g.number == 34);
703 <                    threadAssertTrue(h.isDone());
704 <                    threadAssertTrue(h.number == 13);
705 <                }
706 <            };
798 <        mainPool.invoke(a);
693 >        RecursiveAction a = new CheckedRecursiveAction() {
694 >            public void realCompute() {
695 >                AsyncFib f = new AsyncFib(8);
696 >                AsyncFib g = new AsyncFib(9);
697 >                AsyncFib h = new AsyncFib(7);
698 >                invokeAll(f, g, h);
699 >                assertTrue(f.isDone());
700 >                assertEquals(21, f.number);
701 >                assertTrue(g.isDone());
702 >                assertEquals(34, g.number);
703 >                assertTrue(h.isDone());
704 >                assertEquals(13, h.number);
705 >            }};
706 >        testInvokeOnPool(mainPool(), a);
707      }
708  
709 <    /**
709 >    /**
710       * invokeAll(collection) invokes all tasks in the collection
711       */
712      public void testInvokeAllCollection() {
713 <        RecursiveAction a = new RecursiveAction() {
714 <                public void compute() {
715 <                    AsyncFib f = new AsyncFib(8);
716 <                    AsyncFib g = new AsyncFib(9);
717 <                    AsyncFib h = new AsyncFib(7);
718 <                    HashSet set = new HashSet();
719 <                    set.add(f);
720 <                    set.add(g);
721 <                    set.add(h);
722 <                    invokeAll(set);
723 <                    threadAssertTrue(f.isDone());
724 <                    threadAssertTrue(f.number == 21);
725 <                    threadAssertTrue(g.isDone());
726 <                    threadAssertTrue(g.number == 34);
727 <                    threadAssertTrue(h.isDone());
728 <                    threadAssertTrue(h.number == 13);
729 <                }
730 <            };
823 <        mainPool.invoke(a);
713 >        RecursiveAction a = new CheckedRecursiveAction() {
714 >            public void realCompute() {
715 >                AsyncFib f = new AsyncFib(8);
716 >                AsyncFib g = new AsyncFib(9);
717 >                AsyncFib h = new AsyncFib(7);
718 >                HashSet set = new HashSet();
719 >                set.add(f);
720 >                set.add(g);
721 >                set.add(h);
722 >                invokeAll(set);
723 >                assertTrue(f.isDone());
724 >                assertEquals(21, f.number);
725 >                assertTrue(g.isDone());
726 >                assertEquals(34, g.number);
727 >                assertTrue(h.isDone());
728 >                assertEquals(13, h.number);
729 >            }};
730 >        testInvokeOnPool(mainPool(), a);
731      }
732  
733  
734 <    /**
734 >    /**
735       * invokeAll(tasks) with any null task throws NPE
736       */
737      public void testInvokeAllNPE() {
738 <        RecursiveAction a = new RecursiveAction() {
739 <                public void compute() {
740 <                    try {
741 <                        AsyncFib f = new AsyncFib(8);
742 <                        AsyncFib g = new AsyncFib(9);
743 <                        AsyncFib h = null;
744 <                        invokeAll(f, g, h);
745 <                        shouldThrow();
746 <                    } catch (NullPointerException success) {
747 <                    }
748 <                }
842 <            };
843 <        mainPool.invoke(a);
738 >        RecursiveAction a = new CheckedRecursiveAction() {
739 >            public void realCompute() {
740 >                AsyncFib f = new AsyncFib(8);
741 >                AsyncFib g = new AsyncFib(9);
742 >                AsyncFib h = null;
743 >                try {
744 >                    invokeAll(f, g, h);
745 >                    shouldThrow();
746 >                } catch (NullPointerException success) {}
747 >            }};
748 >        testInvokeOnPool(mainPool(), a);
749      }
750  
751 <    /**
751 >    /**
752       * invokeAll(t1, t2) throw exception if any task does
753       */
754      public void testAbnormalInvokeAll2() {
755 <        RecursiveAction a = new RecursiveAction() {
756 <                public void compute() {
757 <                    try {
758 <                        AsyncFib f = new AsyncFib(8);
759 <                        FailingAsyncFib g = new FailingAsyncFib(9);
760 <                        invokeAll(f, g);
761 <                        shouldThrow();
762 <                    } catch(FJException success) {
763 <                    }
764 <                }
860 <            };
861 <        mainPool.invoke(a);
755 >        RecursiveAction a = new CheckedRecursiveAction() {
756 >            public void realCompute() {
757 >                AsyncFib f = new AsyncFib(8);
758 >                FailingAsyncFib g = new FailingAsyncFib(9);
759 >                try {
760 >                    invokeAll(f, g);
761 >                    shouldThrow();
762 >                } catch (FJException success) {}
763 >            }};
764 >        testInvokeOnPool(mainPool(), a);
765      }
766  
767 <    /**
767 >    /**
768       * invokeAll(tasks) with 1 argument throws exception if task does
769       */
770      public void testAbnormalInvokeAll1() {
771 <        RecursiveAction a = new RecursiveAction() {
772 <                public void compute() {
773 <                    try {
774 <                        FailingAsyncFib g = new FailingAsyncFib(9);
775 <                        invokeAll(g);
776 <                        shouldThrow();
777 <                    } catch(FJException success) {
778 <                    }
779 <                }
877 <            };
878 <        mainPool.invoke(a);
771 >        RecursiveAction a = new CheckedRecursiveAction() {
772 >            public void realCompute() {
773 >                FailingAsyncFib g = new FailingAsyncFib(9);
774 >                try {
775 >                    invokeAll(g);
776 >                    shouldThrow();
777 >                } catch (FJException success) {}
778 >            }};
779 >        testInvokeOnPool(mainPool(), a);
780      }
781  
782 <    /**
782 >    /**
783       * invokeAll(tasks) with > 2 argument throws exception if any task does
784       */
785      public void testAbnormalInvokeAll3() {
786 <        RecursiveAction a = new RecursiveAction() {
787 <                public void compute() {
788 <                    try {
789 <                        AsyncFib f = new AsyncFib(8);
790 <                        FailingAsyncFib g = new FailingAsyncFib(9);
791 <                        AsyncFib h = new AsyncFib(7);
792 <                        invokeAll(f, g, h);
793 <                        shouldThrow();
794 <                    } catch(FJException success) {
795 <                    }
796 <                }
896 <            };
897 <        mainPool.invoke(a);
786 >        RecursiveAction a = new CheckedRecursiveAction() {
787 >            public void realCompute() {
788 >                AsyncFib f = new AsyncFib(8);
789 >                FailingAsyncFib g = new FailingAsyncFib(9);
790 >                AsyncFib h = new AsyncFib(7);
791 >                try {
792 >                    invokeAll(f, g, h);
793 >                    shouldThrow();
794 >                } catch (FJException success) {}
795 >            }};
796 >        testInvokeOnPool(mainPool(), a);
797      }
798  
799 <    /**
799 >    /**
800       * invokeAll(collection)  throws exception if any task does
801       */
802      public void testAbnormalInvokeAllCollection() {
803 <        RecursiveAction a = new RecursiveAction() {
804 <                public void compute() {
805 <                    try {
806 <                        FailingAsyncFib f = new FailingAsyncFib(8);
807 <                        AsyncFib g = new AsyncFib(9);
808 <                        AsyncFib h = new AsyncFib(7);
809 <                        HashSet set = new HashSet();
810 <                        set.add(f);
811 <                        set.add(g);
812 <                        set.add(h);
813 <                        invokeAll(set);
814 <                        shouldThrow();
815 <                    } catch(FJException success) {
816 <                    }
817 <                }
919 <            };
920 <        mainPool.invoke(a);
803 >        RecursiveAction a = new CheckedRecursiveAction() {
804 >            public void realCompute() {
805 >                FailingAsyncFib f = new FailingAsyncFib(8);
806 >                AsyncFib g = new AsyncFib(9);
807 >                AsyncFib h = new AsyncFib(7);
808 >                HashSet set = new HashSet();
809 >                set.add(f);
810 >                set.add(g);
811 >                set.add(h);
812 >                try {
813 >                    invokeAll(set);
814 >                    shouldThrow();
815 >                } catch (FJException success) {}
816 >            }};
817 >        testInvokeOnPool(mainPool(), a);
818      }
819  
820 <    /**
820 >    /**
821       * tryUnfork returns true for most recent unexecuted task,
822       * and suppresses execution
823       */
824      public void testTryUnfork() {
825 <        RecursiveAction a = new RecursiveAction() {
826 <                public void compute() {
827 <                    AsyncFib g = new AsyncFib(9);
828 <                    g.fork();
829 <                    AsyncFib f = new AsyncFib(8);
830 <                    f.fork();
831 <                    threadAssertTrue(f.tryUnfork());
832 <                    helpQuiesce();
833 <                    threadAssertFalse(f.isDone());
834 <                    threadAssertTrue(g.isDone());
835 <                }
836 <            };
940 <        singletonPool.invoke(a);
825 >        RecursiveAction a = new CheckedRecursiveAction() {
826 >            public void realCompute() {
827 >                AsyncFib g = new AsyncFib(9);
828 >                assertSame(g, g.fork());
829 >                AsyncFib f = new AsyncFib(8);
830 >                assertSame(f, f.fork());
831 >                assertTrue(f.tryUnfork());
832 >                helpQuiesce();
833 >                assertFalse(f.isDone());
834 >                assertTrue(g.isDone());
835 >            }};
836 >        testInvokeOnPool(singletonPool(), a);
837      }
838  
839 <    /**
839 >    /**
840       * getSurplusQueuedTaskCount returns > 0 when
841       * there are more tasks than threads
842       */
843      public void testGetSurplusQueuedTaskCount() {
844 <        RecursiveAction a = new RecursiveAction() {
845 <                public void compute() {
846 <                    AsyncFib h = new AsyncFib(7);
847 <                    h.fork();
848 <                    AsyncFib g = new AsyncFib(9);
849 <                    g.fork();
850 <                    AsyncFib f = new AsyncFib(8);
851 <                    f.fork();
852 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
853 <                    helpQuiesce();
854 <                }
855 <            };
960 <        singletonPool.invoke(a);
844 >        RecursiveAction a = new CheckedRecursiveAction() {
845 >            public void realCompute() {
846 >                AsyncFib h = new AsyncFib(7);
847 >                assertSame(h, h.fork());
848 >                AsyncFib g = new AsyncFib(9);
849 >                assertSame(g, g.fork());
850 >                AsyncFib f = new AsyncFib(8);
851 >                assertSame(f, f.fork());
852 >                assertTrue(getSurplusQueuedTaskCount() > 0);
853 >                helpQuiesce();
854 >            }};
855 >        testInvokeOnPool(singletonPool(), a);
856      }
857  
858 <    /**
858 >    /**
859       * peekNextLocalTask returns most recent unexecuted task.
860       */
861      public void testPeekNextLocalTask() {
862 <        RecursiveAction a = new RecursiveAction() {
863 <                public void compute() {
864 <                    AsyncFib g = new AsyncFib(9);
865 <                    g.fork();
866 <                    AsyncFib f = new AsyncFib(8);
867 <                    f.fork();
868 <                    threadAssertTrue(peekNextLocalTask() == f);
869 <                    f.join();
870 <                    threadAssertTrue(f.isDone());
871 <                    helpQuiesce();
872 <                }
873 <            };
979 <        singletonPool.invoke(a);
862 >        RecursiveAction a = new CheckedRecursiveAction() {
863 >            public void realCompute() {
864 >                AsyncFib g = new AsyncFib(9);
865 >                assertSame(g, g.fork());
866 >                AsyncFib f = new AsyncFib(8);
867 >                assertSame(f, f.fork());
868 >                assertSame(f, peekNextLocalTask());
869 >                assertNull(f.join());
870 >                assertTrue(f.isDone());
871 >                helpQuiesce();
872 >            }};
873 >        testInvokeOnPool(singletonPool(), a);
874      }
875  
876 <    /**
876 >    /**
877       * pollNextLocalTask returns most recent unexecuted task
878       * without executing it
879       */
880      public void testPollNextLocalTask() {
881 <        RecursiveAction a = new RecursiveAction() {
882 <                public void compute() {
883 <                    AsyncFib g = new AsyncFib(9);
884 <                    g.fork();
885 <                    AsyncFib f = new AsyncFib(8);
886 <                    f.fork();
887 <                    threadAssertTrue(pollNextLocalTask() == f);
888 <                    helpQuiesce();
889 <                    threadAssertFalse(f.isDone());
890 <                }
891 <            };
998 <        singletonPool.invoke(a);
881 >        RecursiveAction a = new CheckedRecursiveAction() {
882 >            public void realCompute() {
883 >                AsyncFib g = new AsyncFib(9);
884 >                assertSame(g, g.fork());
885 >                AsyncFib f = new AsyncFib(8);
886 >                assertSame(f, f.fork());
887 >                assertSame(f, pollNextLocalTask());
888 >                helpQuiesce();
889 >                assertFalse(f.isDone());
890 >            }};
891 >        testInvokeOnPool(singletonPool(), a);
892      }
893  
894 <    /**
894 >    /**
895       * pollTask returns an unexecuted task
896       * without executing it
897       */
898      public void testPollTask() {
899 <        RecursiveAction a = new RecursiveAction() {
900 <                public void compute() {
901 <                    AsyncFib g = new AsyncFib(9);
902 <                    g.fork();
903 <                    AsyncFib f = new AsyncFib(8);
904 <                    f.fork();
905 <                    threadAssertTrue(pollTask() == f);
906 <                    helpQuiesce();
907 <                    threadAssertFalse(f.isDone());
908 <                    threadAssertTrue(g.isDone());
909 <                }
910 <            };
1018 <        singletonPool.invoke(a);
899 >        RecursiveAction a = new CheckedRecursiveAction() {
900 >            public void realCompute() {
901 >                AsyncFib g = new AsyncFib(9);
902 >                assertSame(g, g.fork());
903 >                AsyncFib f = new AsyncFib(8);
904 >                assertSame(f, f.fork());
905 >                assertSame(f, pollTask());
906 >                helpQuiesce();
907 >                assertFalse(f.isDone());
908 >                assertTrue(g.isDone());
909 >            }};
910 >        testInvokeOnPool(singletonPool(), a);
911      }
912  
913 <    /**
913 >    /**
914       * peekNextLocalTask returns least recent unexecuted task in async mode
915       */
916      public void testPeekNextLocalTaskAsync() {
917 <        RecursiveAction a = new RecursiveAction() {
918 <                public void compute() {
919 <                    AsyncFib g = new AsyncFib(9);
920 <                    g.fork();
921 <                    AsyncFib f = new AsyncFib(8);
922 <                    f.fork();
923 <                    threadAssertTrue(peekNextLocalTask() == g);
924 <                    f.join();
925 <                    helpQuiesce();
926 <                    threadAssertTrue(f.isDone());
927 <                }
928 <            };
1037 <        asyncSingletonPool.invoke(a);
917 >        RecursiveAction a = new CheckedRecursiveAction() {
918 >            public void realCompute() {
919 >                AsyncFib g = new AsyncFib(9);
920 >                assertSame(g, g.fork());
921 >                AsyncFib f = new AsyncFib(8);
922 >                assertSame(f, f.fork());
923 >                assertSame(g, peekNextLocalTask());
924 >                assertNull(f.join());
925 >                helpQuiesce();
926 >                assertTrue(f.isDone());
927 >            }};
928 >        testInvokeOnPool(asyncSingletonPool(), a);
929      }
930  
931 <    /**
931 >    /**
932       * pollNextLocalTask returns least recent unexecuted task
933       * without executing it, in async mode
934       */
935      public void testPollNextLocalTaskAsync() {
936 <        RecursiveAction a = new RecursiveAction() {
937 <                public void compute() {
938 <                    AsyncFib g = new AsyncFib(9);
939 <                    g.fork();
940 <                    AsyncFib f = new AsyncFib(8);
941 <                    f.fork();
942 <                    threadAssertTrue(pollNextLocalTask() == g);
943 <                    helpQuiesce();
944 <                    threadAssertTrue(f.isDone());
945 <                    threadAssertFalse(g.isDone());
946 <                }
947 <            };
1057 <        asyncSingletonPool.invoke(a);
936 >        RecursiveAction a = new CheckedRecursiveAction() {
937 >            public void realCompute() {
938 >                AsyncFib g = new AsyncFib(9);
939 >                assertSame(g, g.fork());
940 >                AsyncFib f = new AsyncFib(8);
941 >                assertSame(f, f.fork());
942 >                assertSame(g, pollNextLocalTask());
943 >                helpQuiesce();
944 >                assertTrue(f.isDone());
945 >                assertFalse(g.isDone());
946 >            }};
947 >        testInvokeOnPool(asyncSingletonPool(), a);
948      }
949  
950 <    /**
950 >    /**
951       * pollTask returns an unexecuted task
952       * without executing it, in async mode
953       */
954      public void testPollTaskAsync() {
955 <        RecursiveAction a = new RecursiveAction() {
956 <                public void compute() {
957 <                    AsyncFib g = new AsyncFib(9);
958 <                    g.fork();
959 <                    AsyncFib f = new AsyncFib(8);
960 <                    f.fork();
961 <                    threadAssertTrue(pollTask() == g);
962 <                    helpQuiesce();
963 <                    threadAssertTrue(f.isDone());
964 <                    threadAssertFalse(g.isDone());
965 <                }
966 <            };
1077 <        asyncSingletonPool.invoke(a);
955 >        RecursiveAction a = new CheckedRecursiveAction() {
956 >            public void realCompute() {
957 >                AsyncFib g = new AsyncFib(9);
958 >                assertSame(g, g.fork());
959 >                AsyncFib f = new AsyncFib(8);
960 >                assertSame(f, f.fork());
961 >                assertSame(g, pollTask());
962 >                helpQuiesce();
963 >                assertTrue(f.isDone());
964 >                assertFalse(g.isDone());
965 >            }};
966 >        testInvokeOnPool(asyncSingletonPool(), a);
967      }
968   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines