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.6 by jsr166, Tue Aug 4 10:13:48 2009 UTC vs.
Revision 1.22 by jsr166, Sun Nov 21 20:32:15 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() {
210 <                    FibAction f = new FibAction(8);
211 <                    f.invoke();
212 <                    threadAssertTrue(f.result == 21);
213 <                    threadAssertTrue(f.isDone());
214 <                    threadAssertFalse(f.isCancelled());
215 <                    threadAssertFalse(f.isCompletedAbnormally());
82 <                    threadAssertTrue(f.getRawResult() == null);
83 <                }
84 <            };
85 <        mainPool.invoke(a);
208 >        RecursiveAction a = new CheckedRecursiveAction() {
209 >            public void realCompute() {
210 >                FibAction f = new FibAction(8);
211 >                assertNull(f.invoke());
212 >                assertEquals(21, f.result);
213 >                checkCompletedNormally(f);
214 >            }};
215 >        testInvokeOnPool(mainPool(), a);
216      }
217  
218      /**
# Line 91 | Line 221 | public class RecursiveActionTest extends
221       * completed tasks
222       */
223      public void testQuietlyInvoke() {
224 <        RecursiveAction a = new RecursiveAction() {
225 <                public void compute() {
226 <                    FibAction f = new FibAction(8);
227 <                    f.quietlyInvoke();
228 <                    threadAssertTrue(f.result == 21);
229 <                    threadAssertTrue(f.isDone());
230 <                    threadAssertFalse(f.isCancelled());
231 <                    threadAssertFalse(f.isCompletedAbnormally());
102 <                    threadAssertTrue(f.getRawResult() == null);
103 <                }
104 <            };
105 <        mainPool.invoke(a);
224 >        RecursiveAction a = new CheckedRecursiveAction() {
225 >            public void realCompute() {
226 >                FibAction f = new FibAction(8);
227 >                f.quietlyInvoke();
228 >                assertEquals(21, f.result);
229 >                checkCompletedNormally(f);
230 >            }};
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() {
240 <                    FibAction f = new FibAction(8);
241 <                    f.fork();
242 <                    f.join();
243 <                    threadAssertTrue(f.result == 21);
244 <                    threadAssertTrue(f.isDone());
245 <                    threadAssertTrue(f.getRawResult() == null);
246 <                }
121 <            };
122 <        mainPool.invoke(a);
238 >        RecursiveAction a = new CheckedRecursiveAction() {
239 >            public void realCompute() {
240 >                FibAction f = new FibAction(8);
241 >                assertSame(f, f.fork());
242 >                assertNull(f.join());
243 >                assertEquals(21, f.result);
244 >                checkCompletedNormally(f);
245 >            }};
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);
260 <                        threadAssertTrue(f.isDone());
261 <                    } catch (Exception ex) {
138 <                        unexpectedException(ex);
139 <                    }
140 <                }
141 <            };
142 <        mainPool.invoke(a);
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 >        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);
275 <                        threadAssertTrue(f.isDone());
276 <                    } catch (Exception ex) {
158 <                        unexpectedException(ex);
159 <                    }
160 <                }
161 <            };
162 <        mainPool.invoke(a);
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 >        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() {
285 <                    try {
286 <                        FibAction f = new FibAction(8);
287 <                        f.fork();
288 <                        f.get(5L, null);
289 <                        shouldThrow();
290 <                    } catch (NullPointerException success) {
291 <                    } catch (Exception ex) {
292 <                        unexpectedException(ex);
179 <                    }
180 <                }
181 <            };
182 <        mainPool.invoke(a);
183 <    }
184 <
185 <    /**
186 <     * helpJoin of a forked task returns when task completes
187 <     */
188 <    public void testForkHelpJoin() {
189 <        RecursiveAction a = new RecursiveAction() {
190 <                public void compute() {
191 <                    FibAction f = new FibAction(8);
192 <                    f.fork();
193 <                    f.helpJoin();
194 <                    threadAssertTrue(f.result == 21);
195 <                    threadAssertTrue(f.isDone());
196 <                }
197 <            };
198 <        mainPool.invoke(a);
283 >        RecursiveAction a = new CheckedRecursiveAction() {
284 >            public void realCompute() throws Exception {
285 >                FibAction f = new FibAction(8);
286 >                assertSame(f, f.fork());
287 >                try {
288 >                    f.get(5L, null);
289 >                    shouldThrow();
290 >                } catch (NullPointerException success) {}
291 >            }};
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() {
301 <                    FibAction f = new FibAction(8);
302 <                    f.fork();
303 <                    f.quietlyJoin();
304 <                    threadAssertTrue(f.result == 21);
305 <                    threadAssertTrue(f.isDone());
306 <                }
307 <            };
214 <        mainPool.invoke(a);
215 <    }
216 <
217 <
218 <    /**
219 <     * quietlyHelpJoin of a forked task returns when task completes
220 <     */
221 <    public void testForkQuietlyHelpJoin() {
222 <        RecursiveAction a = new RecursiveAction() {
223 <                public void compute() {
224 <                    FibAction f = new FibAction(8);
225 <                    f.fork();
226 <                    f.quietlyHelpJoin();
227 <                    threadAssertTrue(f.result == 21);
228 <                    threadAssertTrue(f.isDone());
229 <                }
230 <            };
231 <        mainPool.invoke(a);
299 >        RecursiveAction a = new CheckedRecursiveAction() {
300 >            public void realCompute() {
301 >                FibAction f = new FibAction(8);
302 >                assertSame(f, f.fork());
303 >                f.quietlyJoin();
304 >                assertEquals(21, f.result);
305 >                checkCompletedNormally(f);
306 >            }};
307 >        testInvokeOnPool(mainPool(), a);
308      }
309  
310  
# Line 237 | 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() {
318 <                    FibAction f = new FibAction(8);
319 <                    f.fork();
320 <                    f.helpQuiesce();
321 <                    threadAssertTrue(f.result == 21);
322 <                    threadAssertTrue(f.isDone());
323 <                    threadAssertTrue(getQueuedTaskCount() == 0);
324 <                }
325 <            };
250 <        mainPool.invoke(a);
316 >        RecursiveAction a = new CheckedRecursiveAction() {
317 >            public void realCompute() {
318 >                FibAction f = new FibAction(8);
319 >                assertSame(f, f.fork());
320 >                f.helpQuiesce();
321 >                assertEquals(21, f.result);
322 >                assertEquals(0, getQueuedTaskCount());
323 >                checkCompletedNormally(f);
324 >            }};
325 >        testInvokeOnPool(mainPool(), a);
326      }
327  
328  
# Line 255 | 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() {
335 <                    try {
336 <                        FailingFibAction f = new FailingFibAction(8);
337 <                        f.invoke();
338 <                        shouldThrow();
339 <                    } catch (FJException success) {
340 <                    }
333 >        RecursiveAction a = new CheckedRecursiveAction() {
334 >            public void realCompute() {
335 >                FailingFibAction f = new FailingFibAction(8);
336 >                try {
337 >                    f.invoke();
338 >                    shouldThrow();
339 >                } catch (FJException success) {
340 >                    checkCompletedAbnormally(f, success);
341                  }
342 <            };
343 <        mainPool.invoke(a);
342 >            }};
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() {
352 <                    FailingFibAction f = new FailingFibAction(8);
353 <                    f.quietlyInvoke();
354 <                    threadAssertTrue(f.isDone());
355 <                }
356 <            };
357 <        mainPool.invoke(a);
350 >        RecursiveAction a = new CheckedRecursiveAction() {
351 >            public void realCompute() {
352 >                FailingFibAction f = new FailingFibAction(8);
353 >                f.quietlyInvoke();
354 >                assertTrue(f.getException() instanceof FJException);
355 >                checkCompletedAbnormally(f, f.getException());
356 >            }};
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() {
366 <                    try {
367 <                        FailingFibAction f = new FailingFibAction(8);
368 <                        f.fork();
369 <                        f.join();
370 <                        shouldThrow();
371 <                    } catch (FJException success) {
372 <                    }
364 >        RecursiveAction a = new CheckedRecursiveAction() {
365 >            public void realCompute() {
366 >                FailingFibAction f = new FailingFibAction(8);
367 >                assertSame(f, f.fork());
368 >                try {
369 >                    f.join();
370 >                    shouldThrow();
371 >                } catch (FJException success) {
372 >                    checkCompletedAbnormally(f, success);
373                  }
374 <            };
375 <        mainPool.invoke(a);
374 >            }};
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() {
384 <                    try {
385 <                        FailingFibAction f = new FailingFibAction(8);
386 <                        f.fork();
387 <                        f.get();
388 <                        shouldThrow();
389 <                    } catch (ExecutionException success) {
390 <                    } catch (Exception ex) {
391 <                        unexpectedException(ex);
392 <                    }
382 >        RecursiveAction a = new CheckedRecursiveAction() {
383 >            public void realCompute() throws Exception {
384 >                FailingFibAction f = new FailingFibAction(8);
385 >                assertSame(f, f.fork());
386 >                try {
387 >                    f.get();
388 >                    shouldThrow();
389 >                } catch (ExecutionException success) {
390 >                    Throwable cause = success.getCause();
391 >                    assertTrue(cause instanceof FJException);
392 >                    checkCompletedAbnormally(f, cause);
393                  }
394 <            };
395 <        mainPool.invoke(a);
394 >            }};
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() {
404 <                    try {
405 <                        FailingFibAction f = new FailingFibAction(8);
406 <                        f.fork();
407 <                        f.get(5L, TimeUnit.SECONDS);
408 <                        shouldThrow();
409 <                    } catch (ExecutionException success) {
410 <                    } catch (Exception ex) {
411 <                        unexpectedException(ex);
412 <                    }
338 <                }
339 <            };
340 <        mainPool.invoke(a);
341 <    }
342 <
343 <    /**
344 <     * join of a forked task throws exception when task completes abnormally
345 <     */
346 <    public void testAbnormalForkHelpJoin() {
347 <        RecursiveAction a = new RecursiveAction() {
348 <                public void compute() {
349 <                    try {
350 <                        FailingFibAction f = new FailingFibAction(8);
351 <                        f.fork();
352 <                        f.helpJoin();
353 <                        shouldThrow();
354 <                    } catch (FJException success) {
355 <                    }
356 <                }
357 <            };
358 <        mainPool.invoke(a);
359 <    }
360 <
361 <    /**
362 <     * quietlyHelpJoin of a forked task returns when task completes abnormally.
363 <     * getException of failed task returns its exception.
364 <     * isCompletedAbnormally of a failed task returns true.
365 <     * isCancelled of a failed uncancelled task returns false
366 <     */
367 <    public void testAbnormalForkQuietlyHelpJoin() {
368 <        RecursiveAction a = new RecursiveAction() {
369 <                public void compute() {
370 <                    FailingFibAction f = new FailingFibAction(8);
371 <                    f.fork();
372 <                    f.quietlyHelpJoin();
373 <                    threadAssertTrue(f.isDone());
374 <                    threadAssertTrue(f.isCompletedAbnormally());
375 <                    threadAssertFalse(f.isCancelled());
376 <                    threadAssertTrue(f.getException() instanceof FJException);
402 >        RecursiveAction a = new CheckedRecursiveAction() {
403 >            public void realCompute() throws Exception {
404 >                FailingFibAction f = new FailingFibAction(8);
405 >                assertSame(f, f.fork());
406 >                try {
407 >                    f.get(5L, TimeUnit.SECONDS);
408 >                    shouldThrow();
409 >                } catch (ExecutionException success) {
410 >                    Throwable cause = success.getCause();
411 >                    assertTrue(cause instanceof FJException);
412 >                    checkCompletedAbnormally(f, cause);
413                  }
414 <            };
415 <        mainPool.invoke(a);
414 >            }};
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() {
424 <                    FailingFibAction f = new FailingFibAction(8);
425 <                    f.fork();
426 <                    f.quietlyJoin();
427 <                    threadAssertTrue(f.isDone());
428 <                    threadAssertTrue(f.isCompletedAbnormally());
429 <                    threadAssertTrue(f.getException() instanceof FJException);
430 <                }
395 <            };
396 <        mainPool.invoke(a);
422 >        RecursiveAction a = new CheckedRecursiveAction() {
423 >            public void realCompute() {
424 >                FailingFibAction f = new FailingFibAction(8);
425 >                assertSame(f, f.fork());
426 >                f.quietlyJoin();
427 >                assertTrue(f.getException() instanceof FJException);
428 >                checkCompletedAbnormally(f, f.getException());
429 >            }};
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() {
439 <                    try {
440 <                        FibAction f = new FibAction(8);
441 <                        f.cancel(true);
442 <                        f.invoke();
443 <                        shouldThrow();
444 <                    } catch (CancellationException success) {
445 <                    }
437 >        RecursiveAction a = new CheckedRecursiveAction() {
438 >            public void realCompute() {
439 >                FibAction f = new FibAction(8);
440 >                assertTrue(f.cancel(true));
441 >                try {
442 >                    f.invoke();
443 >                    shouldThrow();
444 >                } catch (CancellationException success) {
445 >                    checkCancelled(f);
446                  }
447 <            };
448 <        mainPool.invoke(a);
447 >            }};
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() {
457 <                    try {
458 <                        FibAction f = new FibAction(8);
459 <                        f.cancel(true);
460 <                        f.fork();
461 <                        f.join();
462 <                        shouldThrow();
463 <                    } catch (CancellationException success) {
464 <                    }
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 {
461 >                    f.join();
462 >                    shouldThrow();
463 >                } catch (CancellationException success) {
464 >                    checkCancelled(f);
465                  }
466 <            };
467 <        mainPool.invoke(a);
466 >            }};
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() {
476 <                    try {
477 <                        FibAction f = new FibAction(8);
478 <                        f.cancel(true);
479 <                        f.fork();
480 <                        f.get();
481 <                        shouldThrow();
482 <                    } catch (CancellationException success) {
483 <                    } catch (Exception ex) {
450 <                        unexpectedException(ex);
451 <                    }
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 {
480 >                    f.get();
481 >                    shouldThrow();
482 >                } catch (CancellationException success) {
483 >                    checkCancelled(f);
484                  }
485 <            };
486 <        mainPool.invoke(a);
485 >            }};
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() {
495 <                    try {
496 <                        FibAction f = new FibAction(8);
497 <                        f.cancel(true);
498 <                        f.fork();
499 <                        f.get(5L, TimeUnit.SECONDS);
500 <                        shouldThrow();
501 <                    } catch (CancellationException success) {
502 <                    } catch (Exception ex) {
471 <                        unexpectedException(ex);
472 <                    }
473 <                }
474 <            };
475 <        mainPool.invoke(a);
476 <    }
477 <
478 <    /**
479 <     * join of a forked task throws exception when task cancelled
480 <     */
481 <    public void testCancelledForkHelpJoin() {
482 <        RecursiveAction a = new RecursiveAction() {
483 <                public void compute() {
484 <                    try {
485 <                        FibAction f = new FibAction(8);
486 <                        f.cancel(true);
487 <                        f.fork();
488 <                        f.helpJoin();
489 <                        shouldThrow();
490 <                    } catch (CancellationException success) {
491 <                    }
492 <                }
493 <            };
494 <        mainPool.invoke(a);
495 <    }
496 <
497 <    /**
498 <     * quietlyHelpJoin of a forked task returns when task cancelled.
499 <     * getException of cancelled task returns its exception.
500 <     * isCompletedAbnormally of a cancelled task returns true.
501 <     * isCancelled of a cancelled task returns true
502 <     */
503 <    public void testCancelledForkQuietlyHelpJoin() {
504 <        RecursiveAction a = new RecursiveAction() {
505 <                public void compute() {
506 <                    FibAction f = new FibAction(8);
507 <                    f.cancel(true);
508 <                    f.fork();
509 <                    f.quietlyHelpJoin();
510 <                    threadAssertTrue(f.isDone());
511 <                    threadAssertTrue(f.isCompletedAbnormally());
512 <                    threadAssertTrue(f.isCancelled());
513 <                    threadAssertTrue(f.getException() instanceof CancellationException);
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 >                    f.get(5L, SECONDS);
500 >                    shouldThrow();
501 >                } catch (CancellationException success) {
502 >                    checkCancelled(f);
503                  }
504 <            };
505 <        mainPool.invoke(a);
504 >            }};
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() {
514 <                    FibAction f = new FibAction(8);
515 <                    f.cancel(true);
516 <                    f.fork();
517 <                    f.quietlyJoin();
518 <                    threadAssertTrue(f.isDone());
519 <                    threadAssertTrue(f.isCompletedAbnormally());
520 <                    threadAssertTrue(f.getException() instanceof CancellationException);
532 <                }
533 <            };
534 <        mainPool.invoke(a);
512 >        RecursiveAction a = new CheckedRecursiveAction() {
513 >            public void realCompute() {
514 >                FibAction f = new FibAction(8);
515 >                assertTrue(f.cancel(true));
516 >                assertSame(f, f.fork());
517 >                f.quietlyJoin();
518 >                checkCancelled(f);
519 >            }};
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);
530 <                }
531 <            };
532 <        mainPool.invoke(a);
527 >        final ForkJoinPool mainPool = mainPool();
528 >        RecursiveAction a = new CheckedRecursiveAction() {
529 >            public void realCompute() {
530 >                assertSame(mainPool, getPool());
531 >            }};
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);
542 <                }
543 <            };
558 <        a.invoke();
539 >        RecursiveAction a = new CheckedRecursiveAction() {
540 >            public void realCompute() {
541 >                assertNull(getPool());
542 >            }};
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());
553 <                }
554 <            };
570 <        mainPool.invoke(a);
550 >        RecursiveAction a = new CheckedRecursiveAction() {
551 >            public void realCompute() {
552 >                assertTrue(inForkJoinPool());
553 >            }};
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());
564 <                }
565 <            };
582 <        a.invoke();
561 >        RecursiveAction a = new CheckedRecursiveAction() {
562 >            public void realCompute() {
563 >                assertFalse(inForkJoinPool());
564 >            }};
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() {
574 <                    ForkJoinWorkerThread w =
575 <                        (ForkJoinWorkerThread)(Thread.currentThread());
576 <                    threadAssertTrue(w.getPool() == mainPool);
577 <                }
578 <            };
579 <        mainPool.invoke(a);
572 >        final ForkJoinPool mainPool = mainPool();
573 >        RecursiveAction a = new CheckedRecursiveAction() {
574 >            public void realCompute() {
575 >                ForkJoinWorkerThread w =
576 >                    (ForkJoinWorkerThread) Thread.currentThread();
577 >                assertSame(mainPool, w.getPool());
578 >            }};
579 >        testInvokeOnPool(mainPool, a);
580      }
581  
582      /**
583       * getPoolIndex of current thread in pool returns 0 <= value < poolSize
601     *
584       */
585      public void testWorkerGetPoolIndex() {
586 <        RecursiveAction a = new RecursiveAction() {
587 <                public void compute() {
588 <                    ForkJoinWorkerThread w =
589 <                        (ForkJoinWorkerThread)(Thread.currentThread());
590 <                    int idx = w.getPoolIndex();
591 <                    threadAssertTrue(idx >= 0);
592 <                    threadAssertTrue(idx < mainPool.getPoolSize());
593 <                }
594 <            };
613 <        mainPool.invoke(a);
586 >        final ForkJoinPool mainPool = mainPool();
587 >        RecursiveAction a = new CheckedRecursiveAction() {
588 >            public void realCompute() {
589 >                ForkJoinWorkerThread w =
590 >                    (ForkJoinWorkerThread)(Thread.currentThread());
591 >                assertTrue(w.getPoolIndex() >= 0);
592 >                assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
593 >            }};
594 >        testInvokeOnPool(mainPool, a);
595      }
596  
597  
# Line 618 | Line 599 | public class RecursiveActionTest extends
599       * setRawResult(null) succeeds
600       */
601      public void testSetRawResult() {
602 <        RecursiveAction a = new RecursiveAction() {
603 <                public void compute() {
604 <                    setRawResult(null);
605 <                }
606 <            };
626 <        a.invoke();
602 >        RecursiveAction a = new CheckedRecursiveAction() {
603 >            public void realCompute() {
604 >                setRawResult(null);
605 >            }};
606 >        assertNull(a.invoke());
607      }
608  
609      /**
610       * A reinitialized task may be re-invoked
611       */
612      public void testReinitialize() {
613 <        RecursiveAction a = new RecursiveAction() {
614 <                public void compute() {
615 <                    FibAction f = new FibAction(8);
616 <                    f.invoke();
617 <                    threadAssertTrue(f.result == 21);
618 <                    threadAssertTrue(f.isDone());
619 <                    threadAssertFalse(f.isCancelled());
620 <                    threadAssertFalse(f.isCompletedAbnormally());
613 >        RecursiveAction a = new CheckedRecursiveAction() {
614 >            public void realCompute() {
615 >                FibAction f = new FibAction(8);
616 >                checkNotDone(f);
617 >
618 >                for (int i = 0; i < 3; i++) {
619 >                    assertNull(f.invoke());
620 >                    assertEquals(21, f.result);
621 >                    checkCompletedNormally(f);
622                      f.reinitialize();
623 <                    f.invoke();
643 <                    threadAssertTrue(f.result == 21);
623 >                    checkNotDone(f);
624                  }
625 <            };
626 <        mainPool.invoke(a);
625 >            }};
626 >        testInvokeOnPool(mainPool(), a);
627      }
628  
629      /**
630       * invoke task throws exception after invoking completeExceptionally
631       */
632      public void testCompleteExceptionally() {
633 <        RecursiveAction a = new RecursiveAction() {
634 <                public void compute() {
635 <                    try {
636 <                        FibAction f = new FibAction(8);
637 <                        f.completeExceptionally(new FJException());
638 <                        f.invoke();
639 <                        shouldThrow();
640 <                    } catch (FJException success) {
641 <                    }
633 >        RecursiveAction a = new CheckedRecursiveAction() {
634 >            public void realCompute() {
635 >                FibAction f = new FibAction(8);
636 >                f.completeExceptionally(new FJException());
637 >                try {
638 >                    f.invoke();
639 >                    shouldThrow();
640 >                } catch (FJException success) {
641 >                    checkCompletedAbnormally(f, success);
642                  }
643 <            };
644 <        mainPool.invoke(a);
643 >            }};
644 >        testInvokeOnPool(mainPool(), a);
645      }
646  
647      /**
648       * invoke task suppresses execution invoking complete
649       */
650      public void testComplete() {
651 <        RecursiveAction a = new RecursiveAction() {
652 <                public void compute() {
653 <                    FibAction f = new FibAction(8);
654 <                    f.complete(null);
655 <                    f.invoke();
656 <                    threadAssertTrue(f.isDone());
657 <                    threadAssertTrue(f.result == 0);
658 <                }
659 <            };
680 <        mainPool.invoke(a);
651 >        RecursiveAction a = new CheckedRecursiveAction() {
652 >            public void realCompute() {
653 >                FibAction f = new FibAction(8);
654 >                f.complete(null);
655 >                assertNull(f.invoke());
656 >                assertEquals(0, f.result);
657 >                checkCompletedNormally(f);
658 >            }};
659 >        testInvokeOnPool(mainPool(), a);
660      }
661  
662      /**
663       * invokeAll(t1, t2) invokes all task arguments
664       */
665      public void testInvokeAll2() {
666 <        RecursiveAction a = new RecursiveAction() {
667 <                public void compute() {
668 <                    FibAction f = new FibAction(8);
669 <                    FibAction g = new FibAction(9);
670 <                    invokeAll(f, g);
671 <                    threadAssertTrue(f.isDone());
672 <                    threadAssertTrue(f.result == 21);
673 <                    threadAssertTrue(g.isDone());
674 <                    threadAssertTrue(g.result == 34);
675 <                }
676 <            };
698 <        mainPool.invoke(a);
666 >        RecursiveAction a = new CheckedRecursiveAction() {
667 >            public void realCompute() {
668 >                FibAction f = new FibAction(8);
669 >                FibAction g = new FibAction(9);
670 >                invokeAll(f, g);
671 >                checkCompletedNormally(f);
672 >                assertEquals(21, f.result);
673 >                checkCompletedNormally(g);
674 >                assertEquals(34, g.result);
675 >            }};
676 >        testInvokeOnPool(mainPool(), a);
677      }
678  
679      /**
680       * invokeAll(tasks) with 1 argument invokes task
681       */
682      public void testInvokeAll1() {
683 <        RecursiveAction a = new RecursiveAction() {
684 <                public void compute() {
685 <                    FibAction f = new FibAction(8);
686 <                    invokeAll(f);
687 <                    threadAssertTrue(f.isDone());
688 <                    threadAssertTrue(f.result == 21);
689 <                }
690 <            };
713 <        mainPool.invoke(a);
683 >        RecursiveAction a = new CheckedRecursiveAction() {
684 >            public void realCompute() {
685 >                FibAction f = new FibAction(8);
686 >                invokeAll(f);
687 >                checkCompletedNormally(f);
688 >                assertEquals(21, f.result);
689 >            }};
690 >        testInvokeOnPool(mainPool(), a);
691      }
692  
693      /**
694       * invokeAll(tasks) with > 2 argument invokes tasks
695       */
696      public void testInvokeAll3() {
697 <        RecursiveAction a = new RecursiveAction() {
698 <                public void compute() {
699 <                    FibAction f = new FibAction(8);
700 <                    FibAction g = new FibAction(9);
701 <                    FibAction h = new FibAction(7);
702 <                    invokeAll(f, g, h);
703 <                    threadAssertTrue(f.isDone());
704 <                    threadAssertTrue(f.result == 21);
705 <                    threadAssertTrue(g.isDone());
706 <                    threadAssertTrue(g.result == 34);
707 <                    threadAssertTrue(h.isDone());
708 <                    threadAssertTrue(h.result == 13);
709 <                }
710 <            };
711 <        mainPool.invoke(a);
697 >        RecursiveAction a = new CheckedRecursiveAction() {
698 >            public void realCompute() {
699 >                FibAction f = new FibAction(8);
700 >                FibAction g = new FibAction(9);
701 >                FibAction h = new FibAction(7);
702 >                invokeAll(f, g, h);
703 >                assertTrue(f.isDone());
704 >                assertTrue(g.isDone());
705 >                assertTrue(h.isDone());
706 >                checkCompletedNormally(f);
707 >                assertEquals(21, f.result);
708 >                checkCompletedNormally(g);
709 >                assertEquals(34, g.result);
710 >                checkCompletedNormally(g);
711 >                assertEquals(13, h.result);
712 >            }};
713 >        testInvokeOnPool(mainPool(), a);
714      }
715  
716      /**
717       * invokeAll(collection) invokes all tasks in the collection
718       */
719      public void testInvokeAllCollection() {
720 <        RecursiveAction a = new RecursiveAction() {
721 <                public void compute() {
722 <                    FibAction f = new FibAction(8);
723 <                    FibAction g = new FibAction(9);
724 <                    FibAction h = new FibAction(7);
725 <                    HashSet set = new HashSet();
726 <                    set.add(f);
727 <                    set.add(g);
728 <                    set.add(h);
729 <                    invokeAll(set);
730 <                    threadAssertTrue(f.isDone());
731 <                    threadAssertTrue(f.result == 21);
732 <                    threadAssertTrue(g.isDone());
733 <                    threadAssertTrue(g.result == 34);
734 <                    threadAssertTrue(h.isDone());
735 <                    threadAssertTrue(h.result == 13);
736 <                }
737 <            };
738 <        mainPool.invoke(a);
720 >        RecursiveAction a = new CheckedRecursiveAction() {
721 >            public void realCompute() {
722 >                FibAction f = new FibAction(8);
723 >                FibAction g = new FibAction(9);
724 >                FibAction h = new FibAction(7);
725 >                HashSet set = new HashSet();
726 >                set.add(f);
727 >                set.add(g);
728 >                set.add(h);
729 >                invokeAll(set);
730 >                assertTrue(f.isDone());
731 >                assertTrue(g.isDone());
732 >                assertTrue(h.isDone());
733 >                checkCompletedNormally(f);
734 >                assertEquals(21, f.result);
735 >                checkCompletedNormally(g);
736 >                assertEquals(34, g.result);
737 >                checkCompletedNormally(g);
738 >                assertEquals(13, h.result);
739 >            }};
740 >        testInvokeOnPool(mainPool(), a);
741      }
742  
743  
# Line 764 | Line 745 | public class RecursiveActionTest extends
745       * invokeAll(tasks) with any null task throws NPE
746       */
747      public void testInvokeAllNPE() {
748 <        RecursiveAction a = new RecursiveAction() {
749 <                public void compute() {
750 <                    try {
751 <                        FibAction f = new FibAction(8);
752 <                        FibAction g = new FibAction(9);
753 <                        FibAction h = null;
754 <                        invokeAll(f, g, h);
755 <                        shouldThrow();
756 <                    } catch (NullPointerException success) {
757 <                    }
758 <                }
778 <            };
779 <        mainPool.invoke(a);
748 >        RecursiveAction a = new CheckedRecursiveAction() {
749 >            public void realCompute() {
750 >                FibAction f = new FibAction(8);
751 >                FibAction g = new FibAction(9);
752 >                FibAction h = null;
753 >                try {
754 >                    invokeAll(f, g, h);
755 >                    shouldThrow();
756 >                } catch (NullPointerException success) {}
757 >            }};
758 >        testInvokeOnPool(mainPool(), a);
759      }
760  
761      /**
762       * invokeAll(t1, t2) throw exception if any task does
763       */
764      public void testAbnormalInvokeAll2() {
765 <        RecursiveAction a = new RecursiveAction() {
766 <                public void compute() {
767 <                    try {
768 <                        FibAction f = new FibAction(8);
769 <                        FailingFibAction g = new FailingFibAction(9);
770 <                        invokeAll(f, g);
771 <                        shouldThrow();
772 <                    } catch (FJException success) {
773 <                    }
765 >        RecursiveAction a = new CheckedRecursiveAction() {
766 >            public void realCompute() {
767 >                FibAction f = new FibAction(8);
768 >                FailingFibAction g = new FailingFibAction(9);
769 >                try {
770 >                    invokeAll(f, g);
771 >                    shouldThrow();
772 >                } catch (FJException success) {
773 >                    checkCompletedAbnormally(g, success);
774                  }
775 <            };
776 <        mainPool.invoke(a);
775 >            }};
776 >        testInvokeOnPool(mainPool(), a);
777      }
778  
779      /**
780       * invokeAll(tasks) with 1 argument throws exception if task does
781       */
782      public void testAbnormalInvokeAll1() {
783 <        RecursiveAction a = new RecursiveAction() {
784 <                public void compute() {
785 <                    try {
786 <                        FailingFibAction g = new FailingFibAction(9);
787 <                        invokeAll(g);
788 <                        shouldThrow();
789 <                    } catch (FJException success) {
790 <                    }
783 >        RecursiveAction a = new CheckedRecursiveAction() {
784 >            public void realCompute() {
785 >                FailingFibAction g = new FailingFibAction(9);
786 >                try {
787 >                    invokeAll(g);
788 >                    shouldThrow();
789 >                } catch (FJException success) {
790 >                    checkCompletedAbnormally(g, success);
791                  }
792 <            };
793 <        mainPool.invoke(a);
792 >            }};
793 >        testInvokeOnPool(mainPool(), a);
794      }
795  
796      /**
797       * invokeAll(tasks) with > 2 argument throws exception if any task does
798       */
799      public void testAbnormalInvokeAll3() {
800 <        RecursiveAction a = new RecursiveAction() {
801 <                public void compute() {
802 <                    try {
803 <                        FibAction f = new FibAction(8);
804 <                        FailingFibAction g = new FailingFibAction(9);
805 <                        FibAction h = new FibAction(7);
806 <                        invokeAll(f, g, h);
807 <                        shouldThrow();
808 <                    } catch (FJException success) {
809 <                    }
800 >        RecursiveAction a = new CheckedRecursiveAction() {
801 >            public void realCompute() {
802 >                FibAction f = new FibAction(8);
803 >                FailingFibAction g = new FailingFibAction(9);
804 >                FibAction h = new FibAction(7);
805 >                try {
806 >                    invokeAll(f, g, h);
807 >                    shouldThrow();
808 >                } catch (FJException success) {
809 >                    checkCompletedAbnormally(g, success);
810                  }
811 <            };
812 <        mainPool.invoke(a);
811 >            }};
812 >        testInvokeOnPool(mainPool(), a);
813      }
814  
815      /**
816       * invokeAll(collection) throws exception if any task does
817       */
818      public void testAbnormalInvokeAllCollection() {
819 <        RecursiveAction a = new RecursiveAction() {
820 <                public void compute() {
821 <                    try {
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 <                        invokeAll(set);
830 <                        shouldThrow();
831 <                    } catch (FJException success) {
832 <                    }
819 >        RecursiveAction a = new CheckedRecursiveAction() {
820 >            public void realCompute() {
821 >                FailingFibAction f = new FailingFibAction(8);
822 >                FibAction g = new FibAction(9);
823 >                FibAction h = new FibAction(7);
824 >                HashSet set = new HashSet();
825 >                set.add(f);
826 >                set.add(g);
827 >                set.add(h);
828 >                try {
829 >                    invokeAll(set);
830 >                    shouldThrow();
831 >                } catch (FJException success) {
832 >                    checkCompletedAbnormally(f, success);
833                  }
834 <            };
835 <        mainPool.invoke(a);
834 >            }};
835 >        testInvokeOnPool(mainPool(), a);
836      }
837  
838      /**
# Line 861 | Line 840 | public class RecursiveActionTest extends
840       * and suppresses execution
841       */
842      public void testTryUnfork() {
843 <        RecursiveAction a = new RecursiveAction() {
844 <                public void compute() {
845 <                    FibAction g = new FibAction(9);
846 <                    g.fork();
847 <                    FibAction f = new FibAction(8);
848 <                    f.fork();
849 <                    threadAssertTrue(f.tryUnfork());
850 <                    helpQuiesce();
851 <                    threadAssertFalse(f.isDone());
852 <                    threadAssertTrue(g.isDone());
853 <                }
854 <            };
876 <        singletonPool.invoke(a);
843 >        RecursiveAction a = new CheckedRecursiveAction() {
844 >            public void realCompute() {
845 >                FibAction g = new FibAction(9);
846 >                assertSame(g, g.fork());
847 >                FibAction f = new FibAction(8);
848 >                assertSame(f, f.fork());
849 >                assertTrue(f.tryUnfork());
850 >                helpQuiesce();
851 >                checkNotDone(f);
852 >                checkCompletedNormally(g);
853 >            }};
854 >        testInvokeOnPool(singletonPool(), a);
855      }
856  
857      /**
# Line 881 | Line 859 | public class RecursiveActionTest extends
859       * there are more tasks than threads
860       */
861      public void testGetSurplusQueuedTaskCount() {
862 <        RecursiveAction a = new RecursiveAction() {
863 <                public void compute() {
864 <                    FibAction h = new FibAction(7);
865 <                    h.fork();
866 <                    FibAction g = new FibAction(9);
867 <                    g.fork();
868 <                    FibAction f = new FibAction(8);
869 <                    f.fork();
870 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
871 <                    helpQuiesce();
872 <                }
873 <            };
874 <        singletonPool.invoke(a);
862 >        RecursiveAction a = new CheckedRecursiveAction() {
863 >            public void realCompute() {
864 >                FibAction h = new FibAction(7);
865 >                assertSame(h, h.fork());
866 >                FibAction g = new FibAction(9);
867 >                assertSame(g, g.fork());
868 >                FibAction f = new FibAction(8);
869 >                assertSame(f, f.fork());
870 >                assertTrue(getSurplusQueuedTaskCount() > 0);
871 >                helpQuiesce();
872 >                assertEquals(0, getSurplusQueuedTaskCount());
873 >                checkCompletedNormally(f);
874 >                checkCompletedNormally(g);
875 >                checkCompletedNormally(h);
876 >            }};
877 >        testInvokeOnPool(singletonPool(), a);
878      }
879  
880      /**
881       * peekNextLocalTask returns most recent unexecuted task.
882       */
883      public void testPeekNextLocalTask() {
884 <        RecursiveAction a = new RecursiveAction() {
885 <                public void compute() {
886 <                    FibAction g = new FibAction(9);
887 <                    g.fork();
888 <                    FibAction f = new FibAction(8);
889 <                    f.fork();
890 <                    threadAssertTrue(peekNextLocalTask() == f);
891 <                    f.join();
892 <                    threadAssertTrue(f.isDone());
893 <                    helpQuiesce();
894 <                }
895 <            };
896 <        singletonPool.invoke(a);
884 >        RecursiveAction a = new CheckedRecursiveAction() {
885 >            public void realCompute() {
886 >                FibAction g = new FibAction(9);
887 >                assertSame(g, g.fork());
888 >                FibAction f = new FibAction(8);
889 >                assertSame(f, f.fork());
890 >                assertSame(f, peekNextLocalTask());
891 >                assertNull(f.join());
892 >                checkCompletedNormally(f);
893 >                helpQuiesce();
894 >                checkCompletedNormally(f);
895 >                checkCompletedNormally(g);
896 >            }};
897 >        testInvokeOnPool(singletonPool(), a);
898      }
899  
900      /**
# Line 920 | Line 902 | public class RecursiveActionTest extends
902       * without executing it
903       */
904      public void testPollNextLocalTask() {
905 <        RecursiveAction a = new RecursiveAction() {
906 <                public void compute() {
907 <                    FibAction g = new FibAction(9);
908 <                    g.fork();
909 <                    FibAction f = new FibAction(8);
910 <                    f.fork();
911 <                    threadAssertTrue(pollNextLocalTask() == f);
912 <                    helpQuiesce();
913 <                    threadAssertFalse(f.isDone());
914 <                }
915 <            };
916 <        singletonPool.invoke(a);
905 >        RecursiveAction a = new CheckedRecursiveAction() {
906 >            public void realCompute() {
907 >                FibAction g = new FibAction(9);
908 >                assertSame(g, g.fork());
909 >                FibAction f = new FibAction(8);
910 >                assertSame(f, f.fork());
911 >                assertSame(f, pollNextLocalTask());
912 >                helpQuiesce();
913 >                checkNotDone(f);
914 >                checkCompletedNormally(g);
915 >            }};
916 >        testInvokeOnPool(singletonPool(), a);
917      }
918  
919      /**
920 <     * pollTask returns an unexecuted task
939 <     * without executing it
920 >     * pollTask returns an unexecuted task without executing it
921       */
922      public void testPollTask() {
923 <        RecursiveAction a = new RecursiveAction() {
924 <                public void compute() {
925 <                    FibAction g = new FibAction(9);
926 <                    g.fork();
927 <                    FibAction f = new FibAction(8);
928 <                    f.fork();
929 <                    threadAssertTrue(pollTask() == f);
930 <                    helpQuiesce();
931 <                    threadAssertFalse(f.isDone());
932 <                    threadAssertTrue(g.isDone());
933 <                }
934 <            };
954 <        singletonPool.invoke(a);
923 >        RecursiveAction a = new CheckedRecursiveAction() {
924 >            public void realCompute() {
925 >                FibAction g = new FibAction(9);
926 >                assertSame(g, g.fork());
927 >                FibAction f = new FibAction(8);
928 >                assertSame(f, f.fork());
929 >                assertSame(f, pollTask());
930 >                helpQuiesce();
931 >                checkNotDone(f);
932 >                checkCompletedNormally(g);
933 >            }};
934 >        testInvokeOnPool(singletonPool(), a);
935      }
936  
937      /**
938       * peekNextLocalTask returns least recent unexecuted task in async mode
939       */
940      public void testPeekNextLocalTaskAsync() {
941 <        RecursiveAction a = new RecursiveAction() {
942 <                public void compute() {
943 <                    FibAction g = new FibAction(9);
944 <                    g.fork();
945 <                    FibAction f = new FibAction(8);
946 <                    f.fork();
947 <                    threadAssertTrue(peekNextLocalTask() == g);
948 <                    f.join();
949 <                    helpQuiesce();
950 <                    threadAssertTrue(f.isDone());
951 <                }
952 <            };
953 <        asyncSingletonPool.invoke(a);
941 >        RecursiveAction a = new CheckedRecursiveAction() {
942 >            public void realCompute() {
943 >                FibAction g = new FibAction(9);
944 >                assertSame(g, g.fork());
945 >                FibAction f = new FibAction(8);
946 >                assertSame(f, f.fork());
947 >                assertSame(g, peekNextLocalTask());
948 >                assertNull(f.join());
949 >                helpQuiesce();
950 >                checkCompletedNormally(f);
951 >                checkCompletedNormally(g);
952 >            }};
953 >        testInvokeOnPool(asyncSingletonPool(), a);
954      }
955  
956      /**
957 <     * pollNextLocalTask returns least recent unexecuted task
958 <     * without executing it, in async mode
957 >     * pollNextLocalTask returns least recent unexecuted task without
958 >     * executing it, in async mode
959       */
960      public void testPollNextLocalTaskAsync() {
961 <        RecursiveAction a = new RecursiveAction() {
962 <                public void compute() {
963 <                    FibAction g = new FibAction(9);
964 <                    g.fork();
965 <                    FibAction f = new FibAction(8);
966 <                    f.fork();
967 <                    threadAssertTrue(pollNextLocalTask() == g);
968 <                    helpQuiesce();
969 <                    threadAssertTrue(f.isDone());
970 <                    threadAssertFalse(g.isDone());
971 <                }
972 <            };
993 <        asyncSingletonPool.invoke(a);
961 >        RecursiveAction a = new CheckedRecursiveAction() {
962 >            public void realCompute() {
963 >                FibAction g = new FibAction(9);
964 >                assertSame(g, g.fork());
965 >                FibAction f = new FibAction(8);
966 >                assertSame(f, f.fork());
967 >                assertSame(g, pollNextLocalTask());
968 >                helpQuiesce();
969 >                checkCompletedNormally(f);
970 >                checkNotDone(g);
971 >            }};
972 >        testInvokeOnPool(asyncSingletonPool(), a);
973      }
974  
975      /**
976 <     * pollTask returns an unexecuted task
977 <     * without executing it, in async mode
976 >     * pollTask returns an unexecuted task without executing it, in
977 >     * async mode
978       */
979      public void testPollTaskAsync() {
980 <        RecursiveAction a = new RecursiveAction() {
981 <                public void compute() {
982 <                    FibAction g = new FibAction(9);
983 <                    g.fork();
984 <                    FibAction f = new FibAction(8);
985 <                    f.fork();
986 <                    threadAssertTrue(pollTask() == g);
987 <                    helpQuiesce();
988 <                    threadAssertTrue(f.isDone());
989 <                    threadAssertFalse(g.isDone());
990 <                }
991 <            };
1013 <        asyncSingletonPool.invoke(a);
980 >        RecursiveAction a = new CheckedRecursiveAction() {
981 >            public void realCompute() {
982 >                FibAction g = new FibAction(9);
983 >                assertSame(g, g.fork());
984 >                FibAction f = new FibAction(8);
985 >                assertSame(f, f.fork());
986 >                assertSame(g, pollTask());
987 >                helpQuiesce();
988 >                checkCompletedNormally(f);
989 >                checkNotDone(g);
990 >            }};
991 >        testInvokeOnPool(asyncSingletonPool(), a);
992      }
993  
994   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines