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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines