ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/RecursiveActionTest.java
(Generate patch)

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.8 by jsr166, Tue Nov 17 12:31:23 2009 UTC vs.
Revision 1.27 by jsr166, Tue Nov 23 08:48:23 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 junit.framework.*;
7 import java.util.concurrent.*;
8 import java.util.*;
6  
7 + import junit.framework.*;
8 + import java.util.concurrent.CancellationException;
9 + import java.util.concurrent.SynchronousQueue;
10 + import java.util.concurrent.ExecutionException;
11 + import java.util.concurrent.ForkJoinPool;
12 + import java.util.concurrent.ForkJoinTask;
13 + import java.util.concurrent.ForkJoinWorkerThread;
14 + import java.util.concurrent.RecursiveAction;
15 + import java.util.concurrent.TimeUnit;
16 + import java.util.concurrent.TimeoutException;
17 + import static java.util.concurrent.TimeUnit.SECONDS;
18 + import java.util.HashSet;
19  
20   public class RecursiveActionTest extends JSR166TestCase {
21  
22      public static void main(String[] args) {
23 <        junit.textui.TestRunner.run (suite());
23 >        junit.textui.TestRunner.run(suite());
24      }
25 +
26      public static Test suite() {
27 <        return new TestSuite(RecursiveActionTest.class);
27 >        return new TestSuite(RecursiveActionTest.class);
28 >    }
29 >
30 >    private static ForkJoinPool mainPool() {
31 >        return new ForkJoinPool();
32 >    }
33 >
34 >    private static ForkJoinPool singletonPool() {
35 >        return new ForkJoinPool(1);
36 >    }
37 >
38 >    private static ForkJoinPool asyncSingletonPool() {
39 >        return new ForkJoinPool(1,
40 >                                ForkJoinPool.defaultForkJoinWorkerThreadFactory,
41 >                                null, true);
42 >    }
43 >
44 >    private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
45 >        try {
46 >            checkNotDone(a);
47 >
48 >            assertNull(pool.invoke(a));
49 >
50 >            checkCompletedNormally(a);
51 >        } finally {
52 >            joinPool(pool);
53 >        }
54      }
55  
56 <    static final ForkJoinPool mainPool = new ForkJoinPool();
57 <    static final ForkJoinPool singletonPool = new ForkJoinPool(1);
58 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
59 <    static {
60 <        asyncSingletonPool.setAsyncMode(true);
56 >    void checkNotDone(RecursiveAction a) {
57 >        assertFalse(a.isDone());
58 >        assertFalse(a.isCompletedNormally());
59 >        assertFalse(a.isCompletedAbnormally());
60 >        assertFalse(a.isCancelled());
61 >        assertNull(a.getException());
62 >        assertNull(a.getRawResult());
63 >
64 >        if (! ForkJoinTask.inForkJoinPool()) {
65 >            Thread.currentThread().interrupt();
66 >            try {
67 >                a.get();
68 >                shouldThrow();
69 >            } catch (InterruptedException success) {
70 >            } catch (Throwable fail) { threadUnexpectedException(fail); }
71 >
72 >            Thread.currentThread().interrupt();
73 >            try {
74 >                a.get(5L, SECONDS);
75 >                shouldThrow();
76 >            } catch (InterruptedException success) {
77 >            } catch (Throwable fail) { threadUnexpectedException(fail); }
78 >        }
79 >
80 >        try {
81 >            a.get(0L, SECONDS);
82 >            shouldThrow();
83 >        } catch (TimeoutException success) {
84 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
85 >    }
86 >
87 >    void checkCompletedNormally(RecursiveAction a) {
88 >        assertTrue(a.isDone());
89 >        assertFalse(a.isCancelled());
90 >        assertTrue(a.isCompletedNormally());
91 >        assertFalse(a.isCompletedAbnormally());
92 >        assertNull(a.getException());
93 >        assertNull(a.getRawResult());
94 >        assertNull(a.join());
95 >        assertFalse(a.cancel(false));
96 >        assertFalse(a.cancel(true));
97 >        try {
98 >            assertNull(a.get());
99 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
100 >        try {
101 >            assertNull(a.get(5L, SECONDS));
102 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
103 >    }
104 >
105 >    void checkCancelled(RecursiveAction a) {
106 >        assertTrue(a.isDone());
107 >        assertTrue(a.isCancelled());
108 >        assertFalse(a.isCompletedNormally());
109 >        assertTrue(a.isCompletedAbnormally());
110 >        assertTrue(a.getException() instanceof CancellationException);
111 >        assertNull(a.getRawResult());
112 >
113 >        try {
114 >            a.join();
115 >            shouldThrow();
116 >        } catch (CancellationException success) {
117 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
118 >
119 >        try {
120 >            a.get();
121 >            shouldThrow();
122 >        } catch (CancellationException success) {
123 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
124 >
125 >        try {
126 >            a.get(5L, SECONDS);
127 >            shouldThrow();
128 >        } catch (CancellationException success) {
129 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
130 >    }
131 >
132 >    void checkCompletedAbnormally(RecursiveAction a, Throwable t) {
133 >        assertTrue(a.isDone());
134 >        assertFalse(a.isCancelled());
135 >        assertFalse(a.isCompletedNormally());
136 >        assertTrue(a.isCompletedAbnormally());
137 >        assertSame(t, a.getException());
138 >        assertNull(a.getRawResult());
139 >        assertFalse(a.cancel(false));
140 >        assertFalse(a.cancel(true));
141 >
142 >        try {
143 >            a.join();
144 >            shouldThrow();
145 >        } catch (Throwable expected) {
146 >            assertSame(t, expected);
147 >        }
148 >
149 >        try {
150 >            a.get();
151 >            shouldThrow();
152 >        } catch (ExecutionException success) {
153 >            assertSame(t, success.getCause());
154 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
155 >
156 >        try {
157 >            a.get(5L, SECONDS);
158 >            shouldThrow();
159 >        } catch (ExecutionException success) {
160 >            assertSame(t, success.getCause());
161 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
162      }
163  
164      static final class FJException extends RuntimeException {
# Line 29 | Line 166 | public class RecursiveActionTest extends
166      }
167  
168      // A simple recursive action for testing
169 <    static final class FibAction extends RecursiveAction {
169 >    final class FibAction extends CheckedRecursiveAction {
170          final int number;
171          int result;
172          FibAction(int n) { number = n; }
173 <        public void compute() {
173 >        public void realCompute() {
174              int n = number;
175              if (n <= 1)
176                  result = n;
# Line 68 | Line 205 | public class RecursiveActionTest extends
205       * invoke returns when task completes normally.
206       * isCompletedAbnormally and isCancelled return false for normally
207       * completed tasks. getRawResult of a RecursiveAction returns null;
71     *
208       */
209      public void testInvoke() {
210 <        RecursiveAction a = new RecursiveAction() {
211 <            public void compute() {
210 >        RecursiveAction a = new CheckedRecursiveAction() {
211 >            public void realCompute() {
212                  FibAction f = new FibAction(8);
213 <                f.invoke();
214 <                threadAssertTrue(f.result == 21);
215 <                threadAssertTrue(f.isDone());
80 <                threadAssertFalse(f.isCancelled());
81 <                threadAssertFalse(f.isCompletedAbnormally());
82 <                threadAssertTrue(f.getRawResult() == null);
213 >                assertNull(f.invoke());
214 >                assertEquals(21, f.result);
215 >                checkCompletedNormally(f);
216              }};
217 <        mainPool.invoke(a);
217 >        testInvokeOnPool(mainPool(), a);
218      }
219  
220      /**
# Line 90 | Line 223 | public class RecursiveActionTest extends
223       * completed tasks
224       */
225      public void testQuietlyInvoke() {
226 <        RecursiveAction a = new RecursiveAction() {
227 <            public void compute() {
226 >        RecursiveAction a = new CheckedRecursiveAction() {
227 >            public void realCompute() {
228                  FibAction f = new FibAction(8);
229                  f.quietlyInvoke();
230 <                threadAssertTrue(f.result == 21);
231 <                threadAssertTrue(f.isDone());
99 <                threadAssertFalse(f.isCancelled());
100 <                threadAssertFalse(f.isCompletedAbnormally());
101 <                threadAssertTrue(f.getRawResult() == null);
230 >                assertEquals(21, f.result);
231 >                checkCompletedNormally(f);
232              }};
233 <        mainPool.invoke(a);
233 >        testInvokeOnPool(mainPool(), a);
234      }
235  
236      /**
237       * join of a forked task returns when task completes
238       */
239      public void testForkJoin() {
240 <        RecursiveAction a = new RecursiveAction() {
241 <            public void compute() {
240 >        RecursiveAction a = new CheckedRecursiveAction() {
241 >            public void realCompute() {
242                  FibAction f = new FibAction(8);
243 <                f.fork();
244 <                f.join();
245 <                threadAssertTrue(f.result == 21);
246 <                threadAssertTrue(f.isDone());
117 <                threadAssertTrue(f.getRawResult() == null);
243 >                assertSame(f, f.fork());
244 >                assertNull(f.join());
245 >                assertEquals(21, f.result);
246 >                checkCompletedNormally(f);
247              }};
248 <        mainPool.invoke(a);
248 >        testInvokeOnPool(mainPool(), a);
249      }
250  
251      /**
252 <     * get of a forked task returns when task completes
252 >     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
253       */
254 <    public void testForkGet() {
255 <        RecursiveAction a = new RecursiveAction() {
256 <            public void compute() {
254 >    public void testJoinIgnoresInterrupts() {
255 >        RecursiveAction a = new CheckedRecursiveAction() {
256 >            public void realCompute() {
257 >                FibAction f = new FibAction(8);
258 >
259 >                // test join()
260 >                assertSame(f, f.fork());
261 >                Thread.currentThread().interrupt();
262 >                assertNull(f.join());
263 >                Thread.interrupted();
264 >                assertEquals(21, f.result);
265 >                checkCompletedNormally(f);
266 >
267 >                f.reinitialize();
268 >                f.cancel(true);
269 >                assertSame(f, f.fork());
270 >                Thread.currentThread().interrupt();
271                  try {
272 <                    FibAction f = new FibAction(8);
273 <                    f.fork();
274 <                    f.get();
275 <                    threadAssertTrue(f.result == 21);
276 <                    threadAssertTrue(f.isDone());
134 <                } catch (Exception ex) {
135 <                    unexpectedException(ex);
272 >                    f.join();
273 >                    shouldThrow();
274 >                } catch (CancellationException success) {
275 >                    Thread.interrupted();
276 >                    checkCancelled(f);
277                  }
137            }};
138        mainPool.invoke(a);
139    }
278  
279 <    /**
280 <     * timed get of a forked task returns when task completes
281 <     */
282 <    public void testForkTimedGet() {
145 <        RecursiveAction a = new RecursiveAction() {
146 <            public void compute() {
279 >                f.reinitialize();
280 >                f.completeExceptionally(new FJException());
281 >                assertSame(f, f.fork());
282 >                Thread.currentThread().interrupt();
283                  try {
284 <                    FibAction f = new FibAction(8);
285 <                    f.fork();
286 <                    f.get(5L, TimeUnit.SECONDS);
287 <                    threadAssertTrue(f.result == 21);
288 <                    threadAssertTrue(f.isDone());
153 <                } catch (Exception ex) {
154 <                    unexpectedException(ex);
284 >                    f.join();
285 >                    shouldThrow();
286 >                } catch (FJException success) {
287 >                    Thread.interrupted();
288 >                    checkCompletedAbnormally(f, success);
289                  }
290 +
291 +                // test quietlyJoin()
292 +                f.reinitialize();
293 +                assertSame(f, f.fork());
294 +                Thread.currentThread().interrupt();
295 +                f.quietlyJoin();
296 +                Thread.interrupted();
297 +                assertEquals(21, f.result);
298 +                checkCompletedNormally(f);
299 +
300 +                f.reinitialize();
301 +                f.cancel(true);
302 +                assertSame(f, f.fork());
303 +                Thread.currentThread().interrupt();
304 +                f.quietlyJoin();
305 +                Thread.interrupted();
306 +                checkCancelled(f);
307 +
308 +                f.reinitialize();
309 +                f.completeExceptionally(new FJException());
310 +                assertSame(f, f.fork());
311 +                Thread.currentThread().interrupt();
312 +                f.quietlyJoin();
313 +                Thread.interrupted();
314 +                checkCompletedAbnormally(f, f.getException());
315              }};
316 <        mainPool.invoke(a);
316 >        testInvokeOnPool(mainPool(), a);
317 >        a.reinitialize();
318 >        testInvokeOnPool(singletonPool(), a);
319      }
320  
321      /**
322 <     * timed get with null time unit throws NPE
322 >     * join/quietlyJoin of a forked task when not in ForkJoinPool
323 >     * succeeds in the presence of interrupts
324       */
325 <    public void testForkTimedGetNPE() {
326 <        RecursiveAction a = new RecursiveAction() {
327 <            public void compute() {
325 >    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
326 >        final SynchronousQueue<FibAction[]> sq =
327 >            new SynchronousQueue<FibAction[]>();
328 >        RecursiveAction a = new CheckedRecursiveAction() {
329 >            public void realCompute() throws InterruptedException {
330 >                FibAction[] fibActions = new FibAction[6];
331 >                for (int i = 0; i < fibActions.length; i++)
332 >                    fibActions[i] = new FibAction(8);
333 >
334 >                fibActions[1].cancel(false);
335 >                fibActions[2].completeExceptionally(new FJException());
336 >                fibActions[4].cancel(true);
337 >                fibActions[5].completeExceptionally(new FJException());
338 >
339 >                for (int i = 0; i < fibActions.length; i++)
340 >                    fibActions[i].fork();
341 >
342 >                sq.put(fibActions);
343 >
344 >                helpQuiesce();
345 >            }};
346 >
347 >        Runnable r = new CheckedRunnable() {
348 >            public void realRun() throws InterruptedException {
349 >                FibAction[] fibActions = sq.take();
350 >                FibAction f;
351 >
352 >                // test join() ------------
353 >
354 >                f = fibActions[0];
355 >                assertFalse(ForkJoinTask.inForkJoinPool());
356 >                Thread.currentThread().interrupt();
357 >                assertNull(f.join());
358 >                assertTrue(Thread.interrupted());
359 >                assertEquals(21, f.result);
360 >                checkCompletedNormally(f);
361 >
362 >                f = fibActions[1];
363 >                Thread.currentThread().interrupt();
364                  try {
365 <                    FibAction f = new FibAction(8);
366 <                    f.fork();
367 <                    f.get(5L, null);
365 >                    f.join();
366 >                    shouldThrow();
367 >                } catch (CancellationException success) {
368 >                    assertTrue(Thread.interrupted());
369 >                    checkCancelled(f);
370 >                }
371 >
372 >                f = fibActions[2];
373 >                Thread.currentThread().interrupt();
374 >                try {
375 >                    f.join();
376                      shouldThrow();
377 <                } catch (NullPointerException success) {
378 <                } catch (Exception ex) {
379 <                    unexpectedException(ex);
377 >                } catch (FJException success) {
378 >                    assertTrue(Thread.interrupted());
379 >                    checkCompletedAbnormally(f, success);
380                  }
381 +
382 +                // test quietlyJoin() ---------
383 +
384 +                f = fibActions[3];
385 +                Thread.currentThread().interrupt();
386 +                f.quietlyJoin();
387 +                assertTrue(Thread.interrupted());
388 +                assertEquals(21, f.result);
389 +                checkCompletedNormally(f);
390 +
391 +                f = fibActions[4];
392 +                Thread.currentThread().interrupt();
393 +                f.quietlyJoin();
394 +                assertTrue(Thread.interrupted());
395 +                checkCancelled(f);
396 +
397 +                f = fibActions[5];
398 +                Thread.currentThread().interrupt();
399 +                f.quietlyJoin();
400 +                assertTrue(Thread.interrupted());
401 +                assertTrue(f.getException() instanceof FJException);
402 +                checkCompletedAbnormally(f, f.getException());
403              }};
404 <        mainPool.invoke(a);
404 >
405 >        Thread t;
406 >
407 >        t = newStartedThread(r);
408 >        testInvokeOnPool(mainPool(), a);
409 >        awaitTermination(t, LONG_DELAY_MS);
410 >
411 >        a.reinitialize();
412 >        t = newStartedThread(r);
413 >        testInvokeOnPool(singletonPool(), a);
414 >        awaitTermination(t, LONG_DELAY_MS);
415      }
416  
417      /**
418 <     * helpJoin of a forked task returns when task completes
418 >     * get of a forked task returns when task completes
419       */
420 <    public void testForkHelpJoin() {
421 <        RecursiveAction a = new RecursiveAction() {
422 <            public void compute() {
420 >    public void testForkGet() {
421 >        RecursiveAction a = new CheckedRecursiveAction() {
422 >            public void realCompute() throws Exception {
423                  FibAction f = new FibAction(8);
424 <                f.fork();
425 <                f.helpJoin();
426 <                threadAssertTrue(f.result == 21);
427 <                threadAssertTrue(f.isDone());
424 >                assertSame(f, f.fork());
425 >                assertNull(f.get());
426 >                assertEquals(21, f.result);
427 >                checkCompletedNormally(f);
428              }};
429 <        mainPool.invoke(a);
429 >        testInvokeOnPool(mainPool(), a);
430      }
431  
432      /**
433 <     * quietlyJoin of a forked task returns when task completes
433 >     * timed get of a forked task returns when task completes
434       */
435 <    public void testForkQuietlyJoin() {
436 <        RecursiveAction a = new RecursiveAction() {
437 <            public void compute() {
435 >    public void testForkTimedGet() {
436 >        RecursiveAction a = new CheckedRecursiveAction() {
437 >            public void realCompute() throws Exception {
438                  FibAction f = new FibAction(8);
439 <                f.fork();
440 <                f.quietlyJoin();
441 <                threadAssertTrue(f.result == 21);
442 <                threadAssertTrue(f.isDone());
439 >                assertSame(f, f.fork());
440 >                assertNull(f.get(5L, SECONDS));
441 >                assertEquals(21, f.result);
442 >                checkCompletedNormally(f);
443              }};
444 <        mainPool.invoke(a);
444 >        testInvokeOnPool(mainPool(), a);
445      }
446  
447 +    /**
448 +     * timed get with null time unit throws NPE
449 +     */
450 +    public void testForkTimedGetNPE() {
451 +        RecursiveAction a = new CheckedRecursiveAction() {
452 +            public void realCompute() throws Exception {
453 +                FibAction f = new FibAction(8);
454 +                assertSame(f, f.fork());
455 +                try {
456 +                    f.get(5L, null);
457 +                    shouldThrow();
458 +                } catch (NullPointerException success) {}
459 +            }};
460 +        testInvokeOnPool(mainPool(), a);
461 +    }
462  
463      /**
464 <     * quietlyHelpJoin of a forked task returns when task completes
464 >     * quietlyJoin of a forked task returns when task completes
465       */
466 <    public void testForkQuietlyHelpJoin() {
467 <        RecursiveAction a = new RecursiveAction() {
468 <            public void compute() {
466 >    public void testForkQuietlyJoin() {
467 >        RecursiveAction a = new CheckedRecursiveAction() {
468 >            public void realCompute() {
469                  FibAction f = new FibAction(8);
470 <                f.fork();
471 <                f.quietlyHelpJoin();
472 <                threadAssertTrue(f.result == 21);
473 <                threadAssertTrue(f.isDone());
470 >                assertSame(f, f.fork());
471 >                f.quietlyJoin();
472 >                assertEquals(21, f.result);
473 >                checkCompletedNormally(f);
474              }};
475 <        mainPool.invoke(a);
475 >        testInvokeOnPool(mainPool(), a);
476      }
477  
478  
# Line 228 | Line 481 | public class RecursiveActionTest extends
481       * getQueuedTaskCount returns 0 when quiescent
482       */
483      public void testForkHelpQuiesce() {
484 <        RecursiveAction a = new RecursiveAction() {
485 <            public void compute() {
484 >        RecursiveAction a = new CheckedRecursiveAction() {
485 >            public void realCompute() {
486                  FibAction f = new FibAction(8);
487 <                f.fork();
487 >                assertSame(f, f.fork());
488                  f.helpQuiesce();
489 <                threadAssertTrue(f.result == 21);
490 <                threadAssertTrue(f.isDone());
491 <                threadAssertTrue(getQueuedTaskCount() == 0);
489 >                assertEquals(21, f.result);
490 >                assertEquals(0, getQueuedTaskCount());
491 >                checkCompletedNormally(f);
492              }};
493 <        mainPool.invoke(a);
493 >        testInvokeOnPool(mainPool(), a);
494      }
495  
496  
# Line 245 | Line 498 | public class RecursiveActionTest extends
498       * invoke task throws exception when task completes abnormally
499       */
500      public void testAbnormalInvoke() {
501 <        RecursiveAction a = new RecursiveAction() {
502 <            public void compute() {
501 >        RecursiveAction a = new CheckedRecursiveAction() {
502 >            public void realCompute() {
503 >                FailingFibAction f = new FailingFibAction(8);
504                  try {
251                    FailingFibAction f = new FailingFibAction(8);
505                      f.invoke();
506                      shouldThrow();
507                  } catch (FJException success) {
508 +                    checkCompletedAbnormally(f, success);
509                  }
510              }};
511 <        mainPool.invoke(a);
511 >        testInvokeOnPool(mainPool(), a);
512      }
513  
514      /**
515       * quietlyInvoke task returns when task completes abnormally
516       */
517      public void testAbnormalQuietlyInvoke() {
518 <        RecursiveAction a = new RecursiveAction() {
519 <            public void compute() {
518 >        RecursiveAction a = new CheckedRecursiveAction() {
519 >            public void realCompute() {
520                  FailingFibAction f = new FailingFibAction(8);
521                  f.quietlyInvoke();
522 <                threadAssertTrue(f.isDone());
522 >                assertTrue(f.getException() instanceof FJException);
523 >                checkCompletedAbnormally(f, f.getException());
524              }};
525 <        mainPool.invoke(a);
525 >        testInvokeOnPool(mainPool(), a);
526      }
527  
528      /**
529       * join of a forked task throws exception when task completes abnormally
530       */
531      public void testAbnormalForkJoin() {
532 <        RecursiveAction a = new RecursiveAction() {
533 <            public void compute() {
532 >        RecursiveAction a = new CheckedRecursiveAction() {
533 >            public void realCompute() {
534 >                FailingFibAction f = new FailingFibAction(8);
535 >                assertSame(f, f.fork());
536                  try {
280                    FailingFibAction f = new FailingFibAction(8);
281                    f.fork();
537                      f.join();
538                      shouldThrow();
539                  } catch (FJException success) {
540 +                    checkCompletedAbnormally(f, success);
541                  }
542              }};
543 <        mainPool.invoke(a);
543 >        testInvokeOnPool(mainPool(), a);
544      }
545  
546      /**
547       * get of a forked task throws exception when task completes abnormally
548       */
549      public void testAbnormalForkGet() {
550 <        RecursiveAction a = new RecursiveAction() {
551 <            public void compute() {
550 >        RecursiveAction a = new CheckedRecursiveAction() {
551 >            public void realCompute() throws Exception {
552 >                FailingFibAction f = new FailingFibAction(8);
553 >                assertSame(f, f.fork());
554                  try {
297                    FailingFibAction f = new FailingFibAction(8);
298                    f.fork();
555                      f.get();
556                      shouldThrow();
557                  } catch (ExecutionException success) {
558 <                } catch (Exception ex) {
559 <                    unexpectedException(ex);
558 >                    Throwable cause = success.getCause();
559 >                    assertTrue(cause instanceof FJException);
560 >                    checkCompletedAbnormally(f, cause);
561                  }
562              }};
563 <        mainPool.invoke(a);
563 >        testInvokeOnPool(mainPool(), a);
564      }
565  
566      /**
567       * timed get of a forked task throws exception when task completes abnormally
568       */
569      public void testAbnormalForkTimedGet() {
570 <        RecursiveAction a = new RecursiveAction() {
571 <            public void compute() {
570 >        RecursiveAction a = new CheckedRecursiveAction() {
571 >            public void realCompute() throws Exception {
572 >                FailingFibAction f = new FailingFibAction(8);
573 >                assertSame(f, f.fork());
574                  try {
316                    FailingFibAction f = new FailingFibAction(8);
317                    f.fork();
575                      f.get(5L, TimeUnit.SECONDS);
576                      shouldThrow();
577                  } catch (ExecutionException success) {
578 <                } catch (Exception ex) {
579 <                    unexpectedException(ex);
580 <                }
324 <            }};
325 <        mainPool.invoke(a);
326 <    }
327 <
328 <    /**
329 <     * join of a forked task throws exception when task completes abnormally
330 <     */
331 <    public void testAbnormalForkHelpJoin() {
332 <        RecursiveAction a = new RecursiveAction() {
333 <            public void compute() {
334 <                try {
335 <                    FailingFibAction f = new FailingFibAction(8);
336 <                    f.fork();
337 <                    f.helpJoin();
338 <                    shouldThrow();
339 <                } catch (FJException success) {
578 >                    Throwable cause = success.getCause();
579 >                    assertTrue(cause instanceof FJException);
580 >                    checkCompletedAbnormally(f, cause);
581                  }
582              }};
583 <        mainPool.invoke(a);
343 <    }
344 <
345 <    /**
346 <     * quietlyHelpJoin of a forked task returns when task completes abnormally.
347 <     * getException of failed task returns its exception.
348 <     * isCompletedAbnormally of a failed task returns true.
349 <     * isCancelled of a failed uncancelled task returns false
350 <     */
351 <    public void testAbnormalForkQuietlyHelpJoin() {
352 <        RecursiveAction a = new RecursiveAction() {
353 <            public void compute() {
354 <                FailingFibAction f = new FailingFibAction(8);
355 <                f.fork();
356 <                f.quietlyHelpJoin();
357 <                threadAssertTrue(f.isDone());
358 <                threadAssertTrue(f.isCompletedAbnormally());
359 <                threadAssertFalse(f.isCancelled());
360 <                threadAssertTrue(f.getException() instanceof FJException);
361 <            }};
362 <        mainPool.invoke(a);
583 >        testInvokeOnPool(mainPool(), a);
584      }
585  
586      /**
587       * quietlyJoin of a forked task returns when task completes abnormally
588       */
589      public void testAbnormalForkQuietlyJoin() {
590 <        RecursiveAction a = new RecursiveAction() {
591 <            public void compute() {
590 >        RecursiveAction a = new CheckedRecursiveAction() {
591 >            public void realCompute() {
592                  FailingFibAction f = new FailingFibAction(8);
593 <                f.fork();
593 >                assertSame(f, f.fork());
594                  f.quietlyJoin();
595 <                threadAssertTrue(f.isDone());
596 <                threadAssertTrue(f.isCompletedAbnormally());
376 <                threadAssertTrue(f.getException() instanceof FJException);
595 >                assertTrue(f.getException() instanceof FJException);
596 >                checkCompletedAbnormally(f, f.getException());
597              }};
598 <        mainPool.invoke(a);
598 >        testInvokeOnPool(mainPool(), a);
599      }
600  
601      /**
602       * invoke task throws exception when task cancelled
603       */
604      public void testCancelledInvoke() {
605 <        RecursiveAction a = new RecursiveAction() {
606 <            public void compute() {
605 >        RecursiveAction a = new CheckedRecursiveAction() {
606 >            public void realCompute() {
607 >                FibAction f = new FibAction(8);
608 >                assertTrue(f.cancel(true));
609                  try {
388                    FibAction f = new FibAction(8);
389                    f.cancel(true);
610                      f.invoke();
611                      shouldThrow();
612                  } catch (CancellationException success) {
613 +                    checkCancelled(f);
614                  }
615              }};
616 <        mainPool.invoke(a);
616 >        testInvokeOnPool(mainPool(), a);
617      }
618  
619      /**
620       * join of a forked task throws exception when task cancelled
621       */
622      public void testCancelledForkJoin() {
623 <        RecursiveAction a = new RecursiveAction() {
624 <            public void compute() {
623 >        RecursiveAction a = new CheckedRecursiveAction() {
624 >            public void realCompute() {
625 >                FibAction f = new FibAction(8);
626 >                assertTrue(f.cancel(true));
627 >                assertSame(f, f.fork());
628                  try {
405                    FibAction f = new FibAction(8);
406                    f.cancel(true);
407                    f.fork();
629                      f.join();
630                      shouldThrow();
631                  } catch (CancellationException success) {
632 +                    checkCancelled(f);
633                  }
634              }};
635 <        mainPool.invoke(a);
635 >        testInvokeOnPool(mainPool(), a);
636      }
637  
638      /**
639       * get of a forked task throws exception when task cancelled
640       */
641      public void testCancelledForkGet() {
642 <        RecursiveAction a = new RecursiveAction() {
643 <            public void compute() {
642 >        RecursiveAction a = new CheckedRecursiveAction() {
643 >            public void realCompute() throws Exception {
644 >                FibAction f = new FibAction(8);
645 >                assertTrue(f.cancel(true));
646 >                assertSame(f, f.fork());
647                  try {
423                    FibAction f = new FibAction(8);
424                    f.cancel(true);
425                    f.fork();
648                      f.get();
649                      shouldThrow();
650                  } catch (CancellationException success) {
651 <                } catch (Exception ex) {
430 <                    unexpectedException(ex);
651 >                    checkCancelled(f);
652                  }
653              }};
654 <        mainPool.invoke(a);
654 >        testInvokeOnPool(mainPool(), a);
655      }
656  
657      /**
658       * timed get of a forked task throws exception when task cancelled
659       */
660      public void testCancelledForkTimedGet() {
661 <        RecursiveAction a = new RecursiveAction() {
662 <            public void compute() {
661 >        RecursiveAction a = new CheckedRecursiveAction() {
662 >            public void realCompute() throws Exception {
663 >                FibAction f = new FibAction(8);
664 >                assertTrue(f.cancel(true));
665 >                assertSame(f, f.fork());
666                  try {
667 <                    FibAction f = new FibAction(8);
444 <                    f.cancel(true);
445 <                    f.fork();
446 <                    f.get(5L, TimeUnit.SECONDS);
447 <                    shouldThrow();
448 <                } catch (CancellationException success) {
449 <                } catch (Exception ex) {
450 <                    unexpectedException(ex);
451 <                }
452 <            }};
453 <        mainPool.invoke(a);
454 <    }
455 <
456 <    /**
457 <     * join of a forked task throws exception when task cancelled
458 <     */
459 <    public void testCancelledForkHelpJoin() {
460 <        RecursiveAction a = new RecursiveAction() {
461 <            public void compute() {
462 <                try {
463 <                    FibAction f = new FibAction(8);
464 <                    f.cancel(true);
465 <                    f.fork();
466 <                    f.helpJoin();
667 >                    f.get(5L, SECONDS);
668                      shouldThrow();
669                  } catch (CancellationException success) {
670 +                    checkCancelled(f);
671                  }
672              }};
673 <        mainPool.invoke(a);
472 <    }
473 <
474 <    /**
475 <     * quietlyHelpJoin of a forked task returns when task cancelled.
476 <     * getException of cancelled task returns its exception.
477 <     * isCompletedAbnormally of a cancelled task returns true.
478 <     * isCancelled of a cancelled task returns true
479 <     */
480 <    public void testCancelledForkQuietlyHelpJoin() {
481 <        RecursiveAction a = new RecursiveAction() {
482 <            public void compute() {
483 <                FibAction f = new FibAction(8);
484 <                f.cancel(true);
485 <                f.fork();
486 <                f.quietlyHelpJoin();
487 <                threadAssertTrue(f.isDone());
488 <                threadAssertTrue(f.isCompletedAbnormally());
489 <                threadAssertTrue(f.isCancelled());
490 <                threadAssertTrue(f.getException() instanceof CancellationException);
491 <            }};
492 <        mainPool.invoke(a);
673 >        testInvokeOnPool(mainPool(), a);
674      }
675  
676      /**
677       * quietlyJoin of a forked task returns when task cancelled
678       */
679      public void testCancelledForkQuietlyJoin() {
680 <        RecursiveAction a = new RecursiveAction() {
681 <            public void compute() {
680 >        RecursiveAction a = new CheckedRecursiveAction() {
681 >            public void realCompute() {
682                  FibAction f = new FibAction(8);
683 <                f.cancel(true);
684 <                f.fork();
683 >                assertTrue(f.cancel(true));
684 >                assertSame(f, f.fork());
685                  f.quietlyJoin();
686 <                threadAssertTrue(f.isDone());
506 <                threadAssertTrue(f.isCompletedAbnormally());
507 <                threadAssertTrue(f.getException() instanceof CancellationException);
686 >                checkCancelled(f);
687              }};
688 <        mainPool.invoke(a);
688 >        testInvokeOnPool(mainPool(), a);
689      }
690  
691      /**
692       * getPool of executing task returns its pool
693       */
694      public void testGetPool() {
695 <        RecursiveAction a = new RecursiveAction() {
696 <            public void compute() {
697 <                threadAssertTrue(getPool() == mainPool);
695 >        final ForkJoinPool mainPool = mainPool();
696 >        RecursiveAction a = new CheckedRecursiveAction() {
697 >            public void realCompute() {
698 >                assertSame(mainPool, getPool());
699              }};
700 <        mainPool.invoke(a);
700 >        testInvokeOnPool(mainPool, a);
701      }
702  
703      /**
704       * getPool of non-FJ task returns null
705       */
706      public void testGetPool2() {
707 <        RecursiveAction a = new RecursiveAction() {
708 <            public void compute() {
709 <                threadAssertTrue(getPool() == null);
707 >        RecursiveAction a = new CheckedRecursiveAction() {
708 >            public void realCompute() {
709 >                assertNull(getPool());
710              }};
711 <        a.invoke();
711 >        assertNull(a.invoke());
712      }
713  
714      /**
715       * inForkJoinPool of executing task returns true
716       */
717      public void testInForkJoinPool() {
718 <        RecursiveAction a = new RecursiveAction() {
719 <            public void compute() {
720 <                threadAssertTrue(inForkJoinPool());
718 >        RecursiveAction a = new CheckedRecursiveAction() {
719 >            public void realCompute() {
720 >                assertTrue(inForkJoinPool());
721              }};
722 <        mainPool.invoke(a);
722 >        testInvokeOnPool(mainPool(), a);
723      }
724  
725      /**
726       * inForkJoinPool of non-FJ task returns false
727       */
728      public void testInForkJoinPool2() {
729 <        RecursiveAction a = new RecursiveAction() {
730 <            public void compute() {
731 <                threadAssertTrue(!inForkJoinPool());
729 >        RecursiveAction a = new CheckedRecursiveAction() {
730 >            public void realCompute() {
731 >                assertFalse(inForkJoinPool());
732              }};
733 <        a.invoke();
733 >        assertNull(a.invoke());
734      }
735  
736      /**
737       * getPool of current thread in pool returns its pool
738       */
739      public void testWorkerGetPool() {
740 <        RecursiveAction a = new RecursiveAction() {
741 <            public void compute() {
740 >        final ForkJoinPool mainPool = mainPool();
741 >        RecursiveAction a = new CheckedRecursiveAction() {
742 >            public void realCompute() {
743                  ForkJoinWorkerThread w =
744 <                    (ForkJoinWorkerThread)(Thread.currentThread());
745 <                threadAssertTrue(w.getPool() == mainPool);
744 >                    (ForkJoinWorkerThread) Thread.currentThread();
745 >                assertSame(mainPool, w.getPool());
746              }};
747 <        mainPool.invoke(a);
747 >        testInvokeOnPool(mainPool, a);
748      }
749  
750      /**
751       * getPoolIndex of current thread in pool returns 0 <= value < poolSize
571     *
752       */
753      public void testWorkerGetPoolIndex() {
754 <        RecursiveAction a = new RecursiveAction() {
755 <            public void compute() {
754 >        final ForkJoinPool mainPool = mainPool();
755 >        RecursiveAction a = new CheckedRecursiveAction() {
756 >            public void realCompute() {
757                  ForkJoinWorkerThread w =
758                      (ForkJoinWorkerThread)(Thread.currentThread());
759 <                int idx = w.getPoolIndex();
760 <                threadAssertTrue(idx >= 0);
580 <                threadAssertTrue(idx < mainPool.getPoolSize());
759 >                assertTrue(w.getPoolIndex() >= 0);
760 >                assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
761              }};
762 <        mainPool.invoke(a);
762 >        testInvokeOnPool(mainPool, a);
763      }
764  
765  
# Line 587 | Line 767 | public class RecursiveActionTest extends
767       * setRawResult(null) succeeds
768       */
769      public void testSetRawResult() {
770 <        RecursiveAction a = new RecursiveAction() {
771 <            public void compute() {
770 >        RecursiveAction a = new CheckedRecursiveAction() {
771 >            public void realCompute() {
772                  setRawResult(null);
773 +                assertNull(getRawResult());
774              }};
775 <        a.invoke();
775 >        assertNull(a.invoke());
776      }
777  
778      /**
779       * A reinitialized task may be re-invoked
780       */
781      public void testReinitialize() {
782 <        RecursiveAction a = new RecursiveAction() {
783 <            public void compute() {
782 >        RecursiveAction a = new CheckedRecursiveAction() {
783 >            public void realCompute() {
784                  FibAction f = new FibAction(8);
785 <                f.invoke();
786 <                threadAssertTrue(f.result == 21);
787 <                threadAssertTrue(f.isDone());
788 <                threadAssertFalse(f.isCancelled());
789 <                threadAssertFalse(f.isCompletedAbnormally());
790 <                f.reinitialize();
791 <                f.invoke();
792 <                threadAssertTrue(f.result == 21);
785 >                checkNotDone(f);
786 >
787 >                for (int i = 0; i < 3; i++) {
788 >                    assertNull(f.invoke());
789 >                    assertEquals(21, f.result);
790 >                    checkCompletedNormally(f);
791 >                    f.reinitialize();
792 >                    checkNotDone(f);
793 >                }
794              }};
795 <        mainPool.invoke(a);
795 >        testInvokeOnPool(mainPool(), a);
796      }
797  
798      /**
799       * invoke task throws exception after invoking completeExceptionally
800       */
801      public void testCompleteExceptionally() {
802 <        RecursiveAction a = new RecursiveAction() {
803 <            public void compute() {
802 >        RecursiveAction a = new CheckedRecursiveAction() {
803 >            public void realCompute() {
804 >                FibAction f = new FibAction(8);
805 >                f.completeExceptionally(new FJException());
806                  try {
623                    FibAction f = new FibAction(8);
624                    f.completeExceptionally(new FJException());
807                      f.invoke();
808                      shouldThrow();
809                  } catch (FJException success) {
810 +                    checkCompletedAbnormally(f, success);
811                  }
812              }};
813 <        mainPool.invoke(a);
813 >        testInvokeOnPool(mainPool(), a);
814      }
815  
816      /**
817       * invoke task suppresses execution invoking complete
818       */
819      public void testComplete() {
820 <        RecursiveAction a = new RecursiveAction() {
821 <            public void compute() {
820 >        RecursiveAction a = new CheckedRecursiveAction() {
821 >            public void realCompute() {
822                  FibAction f = new FibAction(8);
823                  f.complete(null);
824 <                f.invoke();
825 <                threadAssertTrue(f.isDone());
826 <                threadAssertTrue(f.result == 0);
824 >                assertNull(f.invoke());
825 >                assertEquals(0, f.result);
826 >                checkCompletedNormally(f);
827              }};
828 <        mainPool.invoke(a);
828 >        testInvokeOnPool(mainPool(), a);
829      }
830  
831      /**
832       * invokeAll(t1, t2) invokes all task arguments
833       */
834      public void testInvokeAll2() {
835 <        RecursiveAction a = new RecursiveAction() {
836 <            public void compute() {
835 >        RecursiveAction a = new CheckedRecursiveAction() {
836 >            public void realCompute() {
837                  FibAction f = new FibAction(8);
838                  FibAction g = new FibAction(9);
839                  invokeAll(f, g);
840 <                threadAssertTrue(f.isDone());
841 <                threadAssertTrue(f.result == 21);
842 <                threadAssertTrue(g.isDone());
843 <                threadAssertTrue(g.result == 34);
840 >                checkCompletedNormally(f);
841 >                assertEquals(21, f.result);
842 >                checkCompletedNormally(g);
843 >                assertEquals(34, g.result);
844              }};
845 <        mainPool.invoke(a);
845 >        testInvokeOnPool(mainPool(), a);
846      }
847  
848      /**
849       * invokeAll(tasks) with 1 argument invokes task
850       */
851      public void testInvokeAll1() {
852 <        RecursiveAction a = new RecursiveAction() {
853 <            public void compute() {
852 >        RecursiveAction a = new CheckedRecursiveAction() {
853 >            public void realCompute() {
854                  FibAction f = new FibAction(8);
855                  invokeAll(f);
856 <                threadAssertTrue(f.isDone());
857 <                threadAssertTrue(f.result == 21);
856 >                checkCompletedNormally(f);
857 >                assertEquals(21, f.result);
858              }};
859 <        mainPool.invoke(a);
859 >        testInvokeOnPool(mainPool(), a);
860      }
861  
862      /**
863       * invokeAll(tasks) with > 2 argument invokes tasks
864       */
865      public void testInvokeAll3() {
866 <        RecursiveAction a = new RecursiveAction() {
867 <            public void compute() {
866 >        RecursiveAction a = new CheckedRecursiveAction() {
867 >            public void realCompute() {
868                  FibAction f = new FibAction(8);
869                  FibAction g = new FibAction(9);
870                  FibAction h = new FibAction(7);
871                  invokeAll(f, g, h);
872 <                threadAssertTrue(f.isDone());
873 <                threadAssertTrue(f.result == 21);
874 <                threadAssertTrue(g.isDone());
875 <                threadAssertTrue(g.result == 34);
876 <                threadAssertTrue(h.isDone());
877 <                threadAssertTrue(h.result == 13);
872 >                assertTrue(f.isDone());
873 >                assertTrue(g.isDone());
874 >                assertTrue(h.isDone());
875 >                checkCompletedNormally(f);
876 >                assertEquals(21, f.result);
877 >                checkCompletedNormally(g);
878 >                assertEquals(34, g.result);
879 >                checkCompletedNormally(g);
880 >                assertEquals(13, h.result);
881              }};
882 <        mainPool.invoke(a);
882 >        testInvokeOnPool(mainPool(), a);
883      }
884  
885      /**
886       * invokeAll(collection) invokes all tasks in the collection
887       */
888      public void testInvokeAllCollection() {
889 <        RecursiveAction a = new RecursiveAction() {
890 <            public void compute() {
889 >        RecursiveAction a = new CheckedRecursiveAction() {
890 >            public void realCompute() {
891                  FibAction f = new FibAction(8);
892                  FibAction g = new FibAction(9);
893                  FibAction h = new FibAction(7);
# Line 710 | Line 896 | public class RecursiveActionTest extends
896                  set.add(g);
897                  set.add(h);
898                  invokeAll(set);
899 <                threadAssertTrue(f.isDone());
900 <                threadAssertTrue(f.result == 21);
901 <                threadAssertTrue(g.isDone());
902 <                threadAssertTrue(g.result == 34);
903 <                threadAssertTrue(h.isDone());
904 <                threadAssertTrue(h.result == 13);
899 >                assertTrue(f.isDone());
900 >                assertTrue(g.isDone());
901 >                assertTrue(h.isDone());
902 >                checkCompletedNormally(f);
903 >                assertEquals(21, f.result);
904 >                checkCompletedNormally(g);
905 >                assertEquals(34, g.result);
906 >                checkCompletedNormally(g);
907 >                assertEquals(13, h.result);
908              }};
909 <        mainPool.invoke(a);
909 >        testInvokeOnPool(mainPool(), a);
910      }
911  
912  
# Line 725 | Line 914 | public class RecursiveActionTest extends
914       * invokeAll(tasks) with any null task throws NPE
915       */
916      public void testInvokeAllNPE() {
917 <        RecursiveAction a = new RecursiveAction() {
918 <            public void compute() {
917 >        RecursiveAction a = new CheckedRecursiveAction() {
918 >            public void realCompute() {
919 >                FibAction f = new FibAction(8);
920 >                FibAction g = new FibAction(9);
921 >                FibAction h = null;
922                  try {
731                    FibAction f = new FibAction(8);
732                    FibAction g = new FibAction(9);
733                    FibAction h = null;
923                      invokeAll(f, g, h);
924                      shouldThrow();
925 <                } catch (NullPointerException success) {
737 <                }
925 >                } catch (NullPointerException success) {}
926              }};
927 <        mainPool.invoke(a);
927 >        testInvokeOnPool(mainPool(), a);
928      }
929  
930      /**
931       * invokeAll(t1, t2) throw exception if any task does
932       */
933      public void testAbnormalInvokeAll2() {
934 <        RecursiveAction a = new RecursiveAction() {
935 <            public void compute() {
934 >        RecursiveAction a = new CheckedRecursiveAction() {
935 >            public void realCompute() {
936 >                FibAction f = new FibAction(8);
937 >                FailingFibAction g = new FailingFibAction(9);
938                  try {
749                    FibAction f = new FibAction(8);
750                    FailingFibAction g = new FailingFibAction(9);
939                      invokeAll(f, g);
940                      shouldThrow();
941                  } catch (FJException success) {
942 +                    checkCompletedAbnormally(g, success);
943                  }
944              }};
945 <        mainPool.invoke(a);
945 >        testInvokeOnPool(mainPool(), a);
946      }
947  
948      /**
949       * invokeAll(tasks) with 1 argument throws exception if task does
950       */
951      public void testAbnormalInvokeAll1() {
952 <        RecursiveAction a = new RecursiveAction() {
953 <            public void compute() {
952 >        RecursiveAction a = new CheckedRecursiveAction() {
953 >            public void realCompute() {
954 >                FailingFibAction g = new FailingFibAction(9);
955                  try {
766                    FailingFibAction g = new FailingFibAction(9);
956                      invokeAll(g);
957                      shouldThrow();
958                  } catch (FJException success) {
959 +                    checkCompletedAbnormally(g, success);
960                  }
961              }};
962 <        mainPool.invoke(a);
962 >        testInvokeOnPool(mainPool(), a);
963      }
964  
965      /**
966       * invokeAll(tasks) with > 2 argument throws exception if any task does
967       */
968      public void testAbnormalInvokeAll3() {
969 <        RecursiveAction a = new RecursiveAction() {
970 <            public void compute() {
969 >        RecursiveAction a = new CheckedRecursiveAction() {
970 >            public void realCompute() {
971 >                FibAction f = new FibAction(8);
972 >                FailingFibAction g = new FailingFibAction(9);
973 >                FibAction h = new FibAction(7);
974                  try {
782                    FibAction f = new FibAction(8);
783                    FailingFibAction g = new FailingFibAction(9);
784                    FibAction h = new FibAction(7);
975                      invokeAll(f, g, h);
976                      shouldThrow();
977                  } catch (FJException success) {
978 +                    checkCompletedAbnormally(g, success);
979                  }
980              }};
981 <        mainPool.invoke(a);
981 >        testInvokeOnPool(mainPool(), a);
982      }
983  
984      /**
985       * invokeAll(collection) throws exception if any task does
986       */
987      public void testAbnormalInvokeAllCollection() {
988 <        RecursiveAction a = new RecursiveAction() {
989 <            public void compute() {
988 >        RecursiveAction a = new CheckedRecursiveAction() {
989 >            public void realCompute() {
990 >                FailingFibAction f = new FailingFibAction(8);
991 >                FibAction g = new FibAction(9);
992 >                FibAction h = new FibAction(7);
993 >                HashSet set = new HashSet();
994 >                set.add(f);
995 >                set.add(g);
996 >                set.add(h);
997                  try {
800                    FailingFibAction f = new FailingFibAction(8);
801                    FibAction g = new FibAction(9);
802                    FibAction h = new FibAction(7);
803                    HashSet set = new HashSet();
804                    set.add(f);
805                    set.add(g);
806                    set.add(h);
998                      invokeAll(set);
999                      shouldThrow();
1000                  } catch (FJException success) {
1001 +                    checkCompletedAbnormally(f, success);
1002                  }
1003              }};
1004 <        mainPool.invoke(a);
1004 >        testInvokeOnPool(mainPool(), a);
1005      }
1006  
1007      /**
# Line 817 | Line 1009 | public class RecursiveActionTest extends
1009       * and suppresses execution
1010       */
1011      public void testTryUnfork() {
1012 <        RecursiveAction a = new RecursiveAction() {
1013 <            public void compute() {
1012 >        RecursiveAction a = new CheckedRecursiveAction() {
1013 >            public void realCompute() {
1014                  FibAction g = new FibAction(9);
1015 <                g.fork();
1015 >                assertSame(g, g.fork());
1016                  FibAction f = new FibAction(8);
1017 <                f.fork();
1018 <                threadAssertTrue(f.tryUnfork());
1017 >                assertSame(f, f.fork());
1018 >                assertTrue(f.tryUnfork());
1019                  helpQuiesce();
1020 <                threadAssertFalse(f.isDone());
1021 <                threadAssertTrue(g.isDone());
1020 >                checkNotDone(f);
1021 >                checkCompletedNormally(g);
1022              }};
1023 <        singletonPool.invoke(a);
1023 >        testInvokeOnPool(singletonPool(), a);
1024      }
1025  
1026      /**
# Line 836 | Line 1028 | public class RecursiveActionTest extends
1028       * there are more tasks than threads
1029       */
1030      public void testGetSurplusQueuedTaskCount() {
1031 <        RecursiveAction a = new RecursiveAction() {
1032 <            public void compute() {
1031 >        RecursiveAction a = new CheckedRecursiveAction() {
1032 >            public void realCompute() {
1033                  FibAction h = new FibAction(7);
1034 <                h.fork();
1034 >                assertSame(h, h.fork());
1035                  FibAction g = new FibAction(9);
1036 <                g.fork();
1036 >                assertSame(g, g.fork());
1037                  FibAction f = new FibAction(8);
1038 <                f.fork();
1039 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
1038 >                assertSame(f, f.fork());
1039 >                assertTrue(getSurplusQueuedTaskCount() > 0);
1040                  helpQuiesce();
1041 +                assertEquals(0, getSurplusQueuedTaskCount());
1042 +                checkCompletedNormally(f);
1043 +                checkCompletedNormally(g);
1044 +                checkCompletedNormally(h);
1045              }};
1046 <        singletonPool.invoke(a);
1046 >        testInvokeOnPool(singletonPool(), a);
1047      }
1048  
1049      /**
1050       * peekNextLocalTask returns most recent unexecuted task.
1051       */
1052      public void testPeekNextLocalTask() {
1053 <        RecursiveAction a = new RecursiveAction() {
1054 <            public void compute() {
1053 >        RecursiveAction a = new CheckedRecursiveAction() {
1054 >            public void realCompute() {
1055                  FibAction g = new FibAction(9);
1056 <                g.fork();
1056 >                assertSame(g, g.fork());
1057                  FibAction f = new FibAction(8);
1058 <                f.fork();
1059 <                threadAssertTrue(peekNextLocalTask() == f);
1060 <                f.join();
1061 <                threadAssertTrue(f.isDone());
1058 >                assertSame(f, f.fork());
1059 >                assertSame(f, peekNextLocalTask());
1060 >                assertNull(f.join());
1061 >                checkCompletedNormally(f);
1062                  helpQuiesce();
1063 +                checkCompletedNormally(f);
1064 +                checkCompletedNormally(g);
1065              }};
1066 <        singletonPool.invoke(a);
1066 >        testInvokeOnPool(singletonPool(), a);
1067      }
1068  
1069      /**
# Line 873 | Line 1071 | public class RecursiveActionTest extends
1071       * without executing it
1072       */
1073      public void testPollNextLocalTask() {
1074 <        RecursiveAction a = new RecursiveAction() {
1075 <            public void compute() {
1074 >        RecursiveAction a = new CheckedRecursiveAction() {
1075 >            public void realCompute() {
1076                  FibAction g = new FibAction(9);
1077 <                g.fork();
1077 >                assertSame(g, g.fork());
1078                  FibAction f = new FibAction(8);
1079 <                f.fork();
1080 <                threadAssertTrue(pollNextLocalTask() == f);
1079 >                assertSame(f, f.fork());
1080 >                assertSame(f, pollNextLocalTask());
1081                  helpQuiesce();
1082 <                threadAssertFalse(f.isDone());
1082 >                checkNotDone(f);
1083 >                checkCompletedNormally(g);
1084              }};
1085 <        singletonPool.invoke(a);
1085 >        testInvokeOnPool(singletonPool(), a);
1086      }
1087  
1088      /**
1089 <     * pollTask returns an unexecuted task
891 <     * without executing it
1089 >     * pollTask returns an unexecuted task without executing it
1090       */
1091      public void testPollTask() {
1092 <        RecursiveAction a = new RecursiveAction() {
1093 <            public void compute() {
1092 >        RecursiveAction a = new CheckedRecursiveAction() {
1093 >            public void realCompute() {
1094                  FibAction g = new FibAction(9);
1095 <                g.fork();
1095 >                assertSame(g, g.fork());
1096                  FibAction f = new FibAction(8);
1097 <                f.fork();
1098 <                threadAssertTrue(pollTask() == f);
1097 >                assertSame(f, f.fork());
1098 >                assertSame(f, pollTask());
1099                  helpQuiesce();
1100 <                threadAssertFalse(f.isDone());
1101 <                threadAssertTrue(g.isDone());
1100 >                checkNotDone(f);
1101 >                checkCompletedNormally(g);
1102              }};
1103 <        singletonPool.invoke(a);
1103 >        testInvokeOnPool(singletonPool(), a);
1104      }
1105  
1106      /**
1107       * peekNextLocalTask returns least recent unexecuted task in async mode
1108       */
1109      public void testPeekNextLocalTaskAsync() {
1110 <        RecursiveAction a = new RecursiveAction() {
1111 <            public void compute() {
1110 >        RecursiveAction a = new CheckedRecursiveAction() {
1111 >            public void realCompute() {
1112                  FibAction g = new FibAction(9);
1113 <                g.fork();
1113 >                assertSame(g, g.fork());
1114                  FibAction f = new FibAction(8);
1115 <                f.fork();
1116 <                threadAssertTrue(peekNextLocalTask() == g);
1117 <                f.join();
1115 >                assertSame(f, f.fork());
1116 >                assertSame(g, peekNextLocalTask());
1117 >                assertNull(f.join());
1118                  helpQuiesce();
1119 <                threadAssertTrue(f.isDone());
1119 >                checkCompletedNormally(f);
1120 >                checkCompletedNormally(g);
1121              }};
1122 <        asyncSingletonPool.invoke(a);
1122 >        testInvokeOnPool(asyncSingletonPool(), a);
1123      }
1124  
1125      /**
1126 <     * pollNextLocalTask returns least recent unexecuted task
1127 <     * without executing it, in async mode
1126 >     * pollNextLocalTask returns least recent unexecuted task without
1127 >     * executing it, in async mode
1128       */
1129      public void testPollNextLocalTaskAsync() {
1130 <        RecursiveAction a = new RecursiveAction() {
1131 <            public void compute() {
1130 >        RecursiveAction a = new CheckedRecursiveAction() {
1131 >            public void realCompute() {
1132                  FibAction g = new FibAction(9);
1133 <                g.fork();
1133 >                assertSame(g, g.fork());
1134                  FibAction f = new FibAction(8);
1135 <                f.fork();
1136 <                threadAssertTrue(pollNextLocalTask() == g);
1135 >                assertSame(f, f.fork());
1136 >                assertSame(g, pollNextLocalTask());
1137                  helpQuiesce();
1138 <                threadAssertTrue(f.isDone());
1139 <                threadAssertFalse(g.isDone());
1138 >                checkCompletedNormally(f);
1139 >                checkNotDone(g);
1140              }};
1141 <        asyncSingletonPool.invoke(a);
1141 >        testInvokeOnPool(asyncSingletonPool(), a);
1142      }
1143  
1144      /**
1145 <     * pollTask returns an unexecuted task
1146 <     * without executing it, in async mode
1145 >     * pollTask returns an unexecuted task without executing it, in
1146 >     * async mode
1147       */
1148      public void testPollTaskAsync() {
1149 <        RecursiveAction a = new RecursiveAction() {
1150 <            public void compute() {
1149 >        RecursiveAction a = new CheckedRecursiveAction() {
1150 >            public void realCompute() {
1151                  FibAction g = new FibAction(9);
1152 <                g.fork();
1152 >                assertSame(g, g.fork());
1153                  FibAction f = new FibAction(8);
1154 <                f.fork();
1155 <                threadAssertTrue(pollTask() == g);
1154 >                assertSame(f, f.fork());
1155 >                assertSame(g, pollTask());
1156                  helpQuiesce();
1157 <                threadAssertTrue(f.isDone());
1158 <                threadAssertFalse(g.isDone());
1157 >                checkCompletedNormally(f);
1158 >                checkNotDone(g);
1159              }};
1160 <        asyncSingletonPool.invoke(a);
1160 >        testInvokeOnPool(asyncSingletonPool(), a);
1161      }
1162  
1163   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines