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.2 by jsr166, Fri Jul 31 23:37:31 2009 UTC vs.
Revision 1.25 by jsr166, Tue Nov 23 06:33:26 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 >    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 <    static final ForkJoinPool mainPool = new ForkJoinPool();
55 <    static final ForkJoinPool singletonPool = new ForkJoinPool(1);
56 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
57 <    static {
58 <        asyncSingletonPool.setAsyncMode(true);
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();
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 >     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
251 >     */
252 >    public void testJoinIgnoresInterrupts() {
253 >        RecursiveAction a = new CheckedRecursiveAction() {
254 >            public void realCompute() {
255 >                FibAction f = new FibAction(8);
256 >
257 >                // test join()
258 >                assertSame(f, f.fork());
259 >                Thread.currentThread().interrupt();
260 >                assertNull(f.join());
261 >                Thread.interrupted();
262 >                assertEquals(21, f.result);
263 >                checkCompletedNormally(f);
264 >
265 >                f.reinitialize();
266 >                f.cancel(true);
267 >                assertSame(f, f.fork());
268 >                Thread.currentThread().interrupt();
269 >                try {
270                      f.join();
271 <                    threadAssertTrue(f.result == 21);
272 <                    threadAssertTrue(f.isDone());
273 <                    threadAssertTrue(f.getRawResult() == null);
271 >                    shouldThrow();
272 >                } catch (CancellationException success) {
273 >                    Thread.interrupted();
274 >                    checkCancelled(f);
275                  }
276 <            };
277 <        mainPool.invoke(a);
276 >
277 >                f.reinitialize();
278 >                f.completeExceptionally(new FJException());
279 >                assertSame(f, f.fork());
280 >                Thread.currentThread().interrupt();
281 >                try {
282 >                    f.join();
283 >                    shouldThrow();
284 >                } catch (FJException success) {
285 >                    Thread.interrupted();
286 >                    checkCompletedAbnormally(f, success);
287 >                }
288 >
289 >                // test quietlyJoin()
290 >                f.reinitialize();
291 >                assertSame(f, f.fork());
292 >                Thread.currentThread().interrupt();
293 >                f.quietlyJoin();
294 >                Thread.interrupted();
295 >                assertEquals(21, f.result);
296 >                checkCompletedNormally(f);
297 >
298 >                f.reinitialize();
299 >                f.cancel(true);
300 >                assertSame(f, f.fork());
301 >                Thread.currentThread().interrupt();
302 >                f.quietlyJoin();
303 >                Thread.interrupted();
304 >                checkCancelled(f);
305 >
306 >                f.reinitialize();
307 >                f.completeExceptionally(new FJException());
308 >                assertSame(f, f.fork());
309 >                Thread.currentThread().interrupt();
310 >                f.quietlyJoin();
311 >                Thread.interrupted();
312 >                checkCompletedAbnormally(f, f.getException());
313 >            }};
314 >        testInvokeOnPool(mainPool(), a);
315 >        a.reinitialize();
316 >        testInvokeOnPool(singletonPool(), a);
317      }
318  
319      /**
320       * get of a forked task returns when task completes
321       */
322      public void testForkGet() {
323 <        RecursiveAction a = new RecursiveAction() {
324 <                public void compute() {
325 <                    try {
326 <                        FibAction f = new FibAction(8);
327 <                        f.fork();
328 <                        f.get();
329 <                        threadAssertTrue(f.result == 21);
330 <                        threadAssertTrue(f.isDone());
331 <                    } catch (Exception ex) {
138 <                        unexpectedException();
139 <                    }
140 <                }
141 <            };
142 <        mainPool.invoke(a);
323 >        RecursiveAction a = new CheckedRecursiveAction() {
324 >            public void realCompute() throws Exception {
325 >                FibAction f = new FibAction(8);
326 >                assertSame(f, f.fork());
327 >                assertNull(f.get());
328 >                assertEquals(21, f.result);
329 >                checkCompletedNormally(f);
330 >            }};
331 >        testInvokeOnPool(mainPool(), a);
332      }
333  
334      /**
335       * timed get of a forked task returns when task completes
336       */
337      public void testForkTimedGet() {
338 <        RecursiveAction a = new RecursiveAction() {
339 <                public void compute() {
340 <                    try {
341 <                        FibAction f = new FibAction(8);
342 <                        f.fork();
343 <                        f.get(5L, TimeUnit.SECONDS);
344 <                        threadAssertTrue(f.result == 21);
345 <                        threadAssertTrue(f.isDone());
346 <                    } catch (Exception ex) {
158 <                        unexpectedException();
159 <                    }
160 <                }
161 <            };
162 <        mainPool.invoke(a);
338 >        RecursiveAction a = new CheckedRecursiveAction() {
339 >            public void realCompute() throws Exception {
340 >                FibAction f = new FibAction(8);
341 >                assertSame(f, f.fork());
342 >                assertNull(f.get(5L, SECONDS));
343 >                assertEquals(21, f.result);
344 >                checkCompletedNormally(f);
345 >            }};
346 >        testInvokeOnPool(mainPool(), a);
347      }
348  
349      /**
350       * timed get with null time unit throws NPE
351       */
352      public void testForkTimedGetNPE() {
353 <        RecursiveAction a = new RecursiveAction() {
354 <                public void compute() {
355 <                    try {
356 <                        FibAction f = new FibAction(8);
357 <                        f.fork();
358 <                        f.get(5L, null);
359 <                    } catch (NullPointerException success) {
360 <                    } catch (Exception ex) {
361 <                        unexpectedException();
362 <                    }
179 <                }
180 <            };
181 <        mainPool.invoke(a);
182 <    }
183 <
184 <    /**
185 <     * helpJoin of a forked task returns when task completes
186 <     */
187 <    public void testForkHelpJoin() {
188 <        RecursiveAction a = new RecursiveAction() {
189 <                public void compute() {
190 <                    FibAction f = new FibAction(8);
191 <                    f.fork();
192 <                    f.helpJoin();
193 <                    threadAssertTrue(f.result == 21);
194 <                    threadAssertTrue(f.isDone());
195 <                }
196 <            };
197 <        mainPool.invoke(a);
353 >        RecursiveAction a = new CheckedRecursiveAction() {
354 >            public void realCompute() throws Exception {
355 >                FibAction f = new FibAction(8);
356 >                assertSame(f, f.fork());
357 >                try {
358 >                    f.get(5L, null);
359 >                    shouldThrow();
360 >                } catch (NullPointerException success) {}
361 >            }};
362 >        testInvokeOnPool(mainPool(), a);
363      }
364  
365      /**
366       * quietlyJoin of a forked task returns when task completes
367       */
368      public void testForkQuietlyJoin() {
369 <        RecursiveAction a = new RecursiveAction() {
370 <                public void compute() {
371 <                    FibAction f = new FibAction(8);
372 <                    f.fork();
373 <                    f.quietlyJoin();
374 <                    threadAssertTrue(f.result == 21);
375 <                    threadAssertTrue(f.isDone());
376 <                }
377 <            };
213 <        mainPool.invoke(a);
214 <    }
215 <
216 <
217 <    /**
218 <     * quietlyHelpJoin of a forked task returns when task completes
219 <     */
220 <    public void testForkQuietlyHelpJoin() {
221 <        RecursiveAction a = new RecursiveAction() {
222 <                public void compute() {
223 <                    FibAction f = new FibAction(8);
224 <                    f.fork();
225 <                    f.quietlyHelpJoin();
226 <                    threadAssertTrue(f.result == 21);
227 <                    threadAssertTrue(f.isDone());
228 <                }
229 <            };
230 <        mainPool.invoke(a);
369 >        RecursiveAction a = new CheckedRecursiveAction() {
370 >            public void realCompute() {
371 >                FibAction f = new FibAction(8);
372 >                assertSame(f, f.fork());
373 >                f.quietlyJoin();
374 >                assertEquals(21, f.result);
375 >                checkCompletedNormally(f);
376 >            }};
377 >        testInvokeOnPool(mainPool(), a);
378      }
379  
380  
# Line 236 | Line 383 | public class RecursiveActionTest extends
383       * getQueuedTaskCount returns 0 when quiescent
384       */
385      public void testForkHelpQuiesce() {
386 <        RecursiveAction a = new RecursiveAction() {
387 <                public void compute() {
388 <                    FibAction f = new FibAction(8);
389 <                    f.fork();
390 <                    f.helpQuiesce();
391 <                    threadAssertTrue(f.result == 21);
392 <                    threadAssertTrue(f.isDone());
393 <                    threadAssertTrue(getQueuedTaskCount() == 0);
394 <                }
395 <            };
249 <        mainPool.invoke(a);
386 >        RecursiveAction a = new CheckedRecursiveAction() {
387 >            public void realCompute() {
388 >                FibAction f = new FibAction(8);
389 >                assertSame(f, f.fork());
390 >                f.helpQuiesce();
391 >                assertEquals(21, f.result);
392 >                assertEquals(0, getQueuedTaskCount());
393 >                checkCompletedNormally(f);
394 >            }};
395 >        testInvokeOnPool(mainPool(), a);
396      }
397  
398  
# Line 254 | Line 400 | public class RecursiveActionTest extends
400       * invoke task throws exception when task completes abnormally
401       */
402      public void testAbnormalInvoke() {
403 <        RecursiveAction a = new RecursiveAction() {
404 <                public void compute() {
405 <                    try {
406 <                        FailingFibAction f = new FailingFibAction(8);
407 <                        f.invoke();
408 <                        shouldThrow();
409 <                    } catch (FJException success) {
410 <                    }
403 >        RecursiveAction a = new CheckedRecursiveAction() {
404 >            public void realCompute() {
405 >                FailingFibAction f = new FailingFibAction(8);
406 >                try {
407 >                    f.invoke();
408 >                    shouldThrow();
409 >                } catch (FJException success) {
410 >                    checkCompletedAbnormally(f, success);
411                  }
412 <            };
413 <        mainPool.invoke(a);
412 >            }};
413 >        testInvokeOnPool(mainPool(), a);
414      }
415  
416      /**
417 <     * quietelyInvoke task returns when task completes abnormally
417 >     * quietlyInvoke task returns when task completes abnormally
418       */
419      public void testAbnormalQuietlyInvoke() {
420 <        RecursiveAction a = new RecursiveAction() {
421 <                public void compute() {
422 <                    FailingFibAction f = new FailingFibAction(8);
423 <                    f.quietlyInvoke();
424 <                    threadAssertTrue(f.isDone());
425 <                }
426 <            };
427 <        mainPool.invoke(a);
420 >        RecursiveAction a = new CheckedRecursiveAction() {
421 >            public void realCompute() {
422 >                FailingFibAction f = new FailingFibAction(8);
423 >                f.quietlyInvoke();
424 >                assertTrue(f.getException() instanceof FJException);
425 >                checkCompletedAbnormally(f, f.getException());
426 >            }};
427 >        testInvokeOnPool(mainPool(), a);
428      }
429  
430      /**
431       * join of a forked task throws exception when task completes abnormally
432       */
433      public void testAbnormalForkJoin() {
434 <        RecursiveAction a = new RecursiveAction() {
435 <                public void compute() {
436 <                    try {
437 <                        FailingFibAction f = new FailingFibAction(8);
438 <                        f.fork();
439 <                        f.join();
440 <                        shouldThrow();
441 <                    } catch (FJException success) {
442 <                    }
434 >        RecursiveAction a = new CheckedRecursiveAction() {
435 >            public void realCompute() {
436 >                FailingFibAction f = new FailingFibAction(8);
437 >                assertSame(f, f.fork());
438 >                try {
439 >                    f.join();
440 >                    shouldThrow();
441 >                } catch (FJException success) {
442 >                    checkCompletedAbnormally(f, success);
443                  }
444 <            };
445 <        mainPool.invoke(a);
444 >            }};
445 >        testInvokeOnPool(mainPool(), a);
446      }
447  
448      /**
449       * get of a forked task throws exception when task completes abnormally
450       */
451      public void testAbnormalForkGet() {
452 <        RecursiveAction a = new RecursiveAction() {
453 <                public void compute() {
454 <                    try {
455 <                        FailingFibAction f = new FailingFibAction(8);
456 <                        f.fork();
457 <                        f.get();
458 <                        shouldThrow();
459 <                    } catch (Exception success) {
460 <                    }
452 >        RecursiveAction a = new CheckedRecursiveAction() {
453 >            public void realCompute() throws Exception {
454 >                FailingFibAction f = new FailingFibAction(8);
455 >                assertSame(f, f.fork());
456 >                try {
457 >                    f.get();
458 >                    shouldThrow();
459 >                } catch (ExecutionException success) {
460 >                    Throwable cause = success.getCause();
461 >                    assertTrue(cause instanceof FJException);
462 >                    checkCompletedAbnormally(f, cause);
463                  }
464 <            };
465 <        mainPool.invoke(a);
464 >            }};
465 >        testInvokeOnPool(mainPool(), a);
466      }
467  
468      /**
469       * timed get of a forked task throws exception when task completes abnormally
470       */
471      public void testAbnormalForkTimedGet() {
472 <        RecursiveAction a = new RecursiveAction() {
473 <                public void compute() {
474 <                    try {
475 <                        FailingFibAction f = new FailingFibAction(8);
476 <                        f.fork();
477 <                        f.get(5L, TimeUnit.SECONDS);
478 <                        shouldThrow();
479 <                    } catch (Exception success) {
480 <                    }
472 >        RecursiveAction a = new CheckedRecursiveAction() {
473 >            public void realCompute() throws Exception {
474 >                FailingFibAction f = new FailingFibAction(8);
475 >                assertSame(f, f.fork());
476 >                try {
477 >                    f.get(5L, TimeUnit.SECONDS);
478 >                    shouldThrow();
479 >                } catch (ExecutionException success) {
480 >                    Throwable cause = success.getCause();
481 >                    assertTrue(cause instanceof FJException);
482 >                    checkCompletedAbnormally(f, cause);
483                  }
484 <            };
485 <        mainPool.invoke(a);
336 <    }
337 <
338 <    /**
339 <     * join of a forked task throws exception when task completes abnormally
340 <     */
341 <    public void testAbnormalForkHelpJoin() {
342 <        RecursiveAction a = new RecursiveAction() {
343 <                public void compute() {
344 <                    try {
345 <                        FailingFibAction f = new FailingFibAction(8);
346 <                        f.fork();
347 <                        f.helpJoin();
348 <                        shouldThrow();
349 <                    } catch (FJException success) {
350 <                    }
351 <                }
352 <            };
353 <        mainPool.invoke(a);
354 <    }
355 <
356 <    /**
357 <     * quietlyHelpJoin of a forked task returns when task completes abnormally.
358 <     * getException of failed task returns its exception.
359 <     * isCompletedAbnormally of a failed task returns true.
360 <     * isCancelled of a failed uncancelled task returns false
361 <     */
362 <    public void testAbnormalForkQuietlyHelpJoin() {
363 <        RecursiveAction a = new RecursiveAction() {
364 <                public void compute() {
365 <                    FailingFibAction f = new FailingFibAction(8);
366 <                    f.fork();
367 <                    f.quietlyHelpJoin();
368 <                    threadAssertTrue(f.isDone());
369 <                    threadAssertTrue(f.isCompletedAbnormally());
370 <                    threadAssertFalse(f.isCancelled());
371 <                    threadAssertTrue(f.getException() instanceof FJException);
372 <                }
373 <            };
374 <        mainPool.invoke(a);
484 >            }};
485 >        testInvokeOnPool(mainPool(), a);
486      }
487  
488      /**
489       * quietlyJoin of a forked task returns when task completes abnormally
490       */
491      public void testAbnormalForkQuietlyJoin() {
492 <        RecursiveAction a = new RecursiveAction() {
493 <                public void compute() {
494 <                    FailingFibAction f = new FailingFibAction(8);
495 <                    f.fork();
496 <                    f.quietlyJoin();
497 <                    threadAssertTrue(f.isDone());
498 <                    threadAssertTrue(f.isCompletedAbnormally());
499 <                    threadAssertTrue(f.getException() instanceof FJException);
500 <                }
390 <            };
391 <        mainPool.invoke(a);
492 >        RecursiveAction a = new CheckedRecursiveAction() {
493 >            public void realCompute() {
494 >                FailingFibAction f = new FailingFibAction(8);
495 >                assertSame(f, f.fork());
496 >                f.quietlyJoin();
497 >                assertTrue(f.getException() instanceof FJException);
498 >                checkCompletedAbnormally(f, f.getException());
499 >            }};
500 >        testInvokeOnPool(mainPool(), a);
501      }
502  
503      /**
504       * invoke task throws exception when task cancelled
505       */
506      public void testCancelledInvoke() {
507 <        RecursiveAction a = new RecursiveAction() {
508 <                public void compute() {
509 <                    try {
510 <                        FibAction f = new FibAction(8);
511 <                        f.cancel(true);
512 <                        f.invoke();
513 <                        shouldThrow();
514 <                    } catch (CancellationException success) {
515 <                    }
507 >        RecursiveAction a = new CheckedRecursiveAction() {
508 >            public void realCompute() {
509 >                FibAction f = new FibAction(8);
510 >                assertTrue(f.cancel(true));
511 >                try {
512 >                    f.invoke();
513 >                    shouldThrow();
514 >                } catch (CancellationException success) {
515 >                    checkCancelled(f);
516                  }
517 <            };
518 <        mainPool.invoke(a);
517 >            }};
518 >        testInvokeOnPool(mainPool(), a);
519      }
520  
521      /**
522       * join of a forked task throws exception when task cancelled
523       */
524      public void testCancelledForkJoin() {
525 <        RecursiveAction a = new RecursiveAction() {
526 <                public void compute() {
527 <                    try {
528 <                        FibAction f = new FibAction(8);
529 <                        f.cancel(true);
530 <                        f.fork();
531 <                        f.join();
532 <                        shouldThrow();
533 <                    } catch (CancellationException success) {
534 <                    }
525 >        RecursiveAction a = new CheckedRecursiveAction() {
526 >            public void realCompute() {
527 >                FibAction f = new FibAction(8);
528 >                assertTrue(f.cancel(true));
529 >                assertSame(f, f.fork());
530 >                try {
531 >                    f.join();
532 >                    shouldThrow();
533 >                } catch (CancellationException success) {
534 >                    checkCancelled(f);
535                  }
536 <            };
537 <        mainPool.invoke(a);
536 >            }};
537 >        testInvokeOnPool(mainPool(), a);
538      }
539  
540      /**
541       * get of a forked task throws exception when task cancelled
542       */
543      public void testCancelledForkGet() {
544 <        RecursiveAction a = new RecursiveAction() {
545 <                public void compute() {
546 <                    try {
547 <                        FibAction f = new FibAction(8);
548 <                        f.cancel(true);
549 <                        f.fork();
550 <                        f.get();
551 <                        shouldThrow();
552 <                    } catch (Exception success) {
553 <                    }
544 >        RecursiveAction a = new CheckedRecursiveAction() {
545 >            public void realCompute() throws Exception {
546 >                FibAction f = new FibAction(8);
547 >                assertTrue(f.cancel(true));
548 >                assertSame(f, f.fork());
549 >                try {
550 >                    f.get();
551 >                    shouldThrow();
552 >                } catch (CancellationException success) {
553 >                    checkCancelled(f);
554                  }
555 <            };
556 <        mainPool.invoke(a);
555 >            }};
556 >        testInvokeOnPool(mainPool(), a);
557      }
558  
559      /**
560       * timed get of a forked task throws exception when task cancelled
561       */
562      public void testCancelledForkTimedGet() {
563 <        RecursiveAction a = new RecursiveAction() {
564 <                public void compute() {
565 <                    try {
566 <                        FibAction f = new FibAction(8);
567 <                        f.cancel(true);
568 <                        f.fork();
569 <                        f.get(5L, TimeUnit.SECONDS);
570 <                        shouldThrow();
571 <                    } catch (Exception success) {
572 <                    }
563 >        RecursiveAction a = new CheckedRecursiveAction() {
564 >            public void realCompute() throws Exception {
565 >                FibAction f = new FibAction(8);
566 >                assertTrue(f.cancel(true));
567 >                assertSame(f, f.fork());
568 >                try {
569 >                    f.get(5L, SECONDS);
570 >                    shouldThrow();
571 >                } catch (CancellationException success) {
572 >                    checkCancelled(f);
573                  }
574 <            };
575 <        mainPool.invoke(a);
467 <    }
468 <
469 <    /**
470 <     * join of a forked task throws exception when task cancelled
471 <     */
472 <    public void testCancelledForkHelpJoin() {
473 <        RecursiveAction a = new RecursiveAction() {
474 <                public void compute() {
475 <                    try {
476 <                        FibAction f = new FibAction(8);
477 <                        f.cancel(true);
478 <                        f.fork();
479 <                        f.helpJoin();
480 <                        shouldThrow();
481 <                    } catch (CancellationException success) {
482 <                    }
483 <                }
484 <            };
485 <        mainPool.invoke(a);
486 <    }
487 <
488 <    /**
489 <     * quietlyHelpJoin of a forked task returns when task cancelled.
490 <     * getException of cancelled task returns its exception.
491 <     * isCompletedAbnormally of a cancelled task returns true.
492 <     * isCancelled of a cancelled task returns true
493 <     */
494 <    public void testCancelledForkQuietlyHelpJoin() {
495 <        RecursiveAction a = new RecursiveAction() {
496 <                public void compute() {
497 <                    FibAction f = new FibAction(8);
498 <                    f.cancel(true);
499 <                    f.fork();
500 <                    f.quietlyHelpJoin();
501 <                    threadAssertTrue(f.isDone());
502 <                    threadAssertTrue(f.isCompletedAbnormally());
503 <                    threadAssertTrue(f.isCancelled());
504 <                    threadAssertTrue(f.getException() instanceof CancellationException);
505 <                }
506 <            };
507 <        mainPool.invoke(a);
574 >            }};
575 >        testInvokeOnPool(mainPool(), a);
576      }
577  
578      /**
579       * quietlyJoin of a forked task returns when task cancelled
580       */
581      public void testCancelledForkQuietlyJoin() {
582 <        RecursiveAction a = new RecursiveAction() {
583 <                public void compute() {
584 <                    FibAction f = new FibAction(8);
585 <                    f.cancel(true);
586 <                    f.fork();
587 <                    f.quietlyJoin();
588 <                    threadAssertTrue(f.isDone());
589 <                    threadAssertTrue(f.isCompletedAbnormally());
590 <                    threadAssertTrue(f.getException() instanceof CancellationException);
523 <                }
524 <            };
525 <        mainPool.invoke(a);
582 >        RecursiveAction a = new CheckedRecursiveAction() {
583 >            public void realCompute() {
584 >                FibAction f = new FibAction(8);
585 >                assertTrue(f.cancel(true));
586 >                assertSame(f, f.fork());
587 >                f.quietlyJoin();
588 >                checkCancelled(f);
589 >            }};
590 >        testInvokeOnPool(mainPool(), a);
591      }
592  
593      /**
594       * getPool of executing task returns its pool
595       */
596      public void testGetPool() {
597 <        RecursiveAction a = new RecursiveAction() {
598 <                public void compute() {
599 <                    threadAssertTrue(getPool() == mainPool);
600 <                }
601 <            };
602 <        mainPool.invoke(a);
597 >        final ForkJoinPool mainPool = mainPool();
598 >        RecursiveAction a = new CheckedRecursiveAction() {
599 >            public void realCompute() {
600 >                assertSame(mainPool, getPool());
601 >            }};
602 >        testInvokeOnPool(mainPool, a);
603      }
604  
605      /**
606       * getPool of non-FJ task returns null
607       */
608      public void testGetPool2() {
609 <        RecursiveAction a = new RecursiveAction() {
610 <                public void compute() {
611 <                    threadAssertTrue(getPool() == null);
612 <                }
613 <            };
549 <        a.invoke();
609 >        RecursiveAction a = new CheckedRecursiveAction() {
610 >            public void realCompute() {
611 >                assertNull(getPool());
612 >            }};
613 >        assertNull(a.invoke());
614      }
615  
616      /**
617       * inForkJoinPool of executing task returns true
618       */
619      public void testInForkJoinPool() {
620 <        RecursiveAction a = new RecursiveAction() {
621 <                public void compute() {
622 <                    threadAssertTrue(inForkJoinPool());
623 <                }
624 <            };
561 <        mainPool.invoke(a);
620 >        RecursiveAction a = new CheckedRecursiveAction() {
621 >            public void realCompute() {
622 >                assertTrue(inForkJoinPool());
623 >            }};
624 >        testInvokeOnPool(mainPool(), a);
625      }
626  
627      /**
628       * inForkJoinPool of non-FJ task returns false
629       */
630      public void testInForkJoinPool2() {
631 <        RecursiveAction a = new RecursiveAction() {
632 <                public void compute() {
633 <                    threadAssertTrue(!inForkJoinPool());
634 <                }
635 <            };
573 <        a.invoke();
631 >        RecursiveAction a = new CheckedRecursiveAction() {
632 >            public void realCompute() {
633 >                assertFalse(inForkJoinPool());
634 >            }};
635 >        assertNull(a.invoke());
636      }
637  
638      /**
639       * getPool of current thread in pool returns its pool
640       */
641      public void testWorkerGetPool() {
642 <        RecursiveAction a = new RecursiveAction() {
643 <                public void compute() {
644 <                    ForkJoinWorkerThread w =
645 <                        (ForkJoinWorkerThread)(Thread.currentThread());
646 <                    threadAssertTrue(w.getPool() == mainPool);
647 <                }
648 <            };
649 <        mainPool.invoke(a);
642 >        final ForkJoinPool mainPool = mainPool();
643 >        RecursiveAction a = new CheckedRecursiveAction() {
644 >            public void realCompute() {
645 >                ForkJoinWorkerThread w =
646 >                    (ForkJoinWorkerThread) Thread.currentThread();
647 >                assertSame(mainPool, w.getPool());
648 >            }};
649 >        testInvokeOnPool(mainPool, a);
650      }
651  
652      /**
653       * getPoolIndex of current thread in pool returns 0 <= value < poolSize
592     *
654       */
655      public void testWorkerGetPoolIndex() {
656 <        RecursiveAction a = new RecursiveAction() {
657 <                public void compute() {
658 <                    ForkJoinWorkerThread w =
659 <                        (ForkJoinWorkerThread)(Thread.currentThread());
660 <                    int idx = w.getPoolIndex();
661 <                    threadAssertTrue(idx >= 0);
662 <                    threadAssertTrue(idx < mainPool.getPoolSize());
663 <                }
664 <            };
604 <        mainPool.invoke(a);
656 >        final ForkJoinPool mainPool = mainPool();
657 >        RecursiveAction a = new CheckedRecursiveAction() {
658 >            public void realCompute() {
659 >                ForkJoinWorkerThread w =
660 >                    (ForkJoinWorkerThread)(Thread.currentThread());
661 >                assertTrue(w.getPoolIndex() >= 0);
662 >                assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
663 >            }};
664 >        testInvokeOnPool(mainPool, a);
665      }
666  
667  
# Line 609 | Line 669 | public class RecursiveActionTest extends
669       * setRawResult(null) succeeds
670       */
671      public void testSetRawResult() {
672 <        RecursiveAction a = new RecursiveAction() {
673 <                public void compute() {
674 <                    setRawResult(null);
675 <                }
676 <            };
677 <        a.invoke();
672 >        RecursiveAction a = new CheckedRecursiveAction() {
673 >            public void realCompute() {
674 >                setRawResult(null);
675 >                assertNull(getRawResult());
676 >            }};
677 >        assertNull(a.invoke());
678      }
679  
680      /**
681       * A reinitialized task may be re-invoked
682       */
683      public void testReinitialize() {
684 <        RecursiveAction a = new RecursiveAction() {
685 <                public void compute() {
686 <                    FibAction f = new FibAction(8);
687 <                    f.invoke();
688 <                    threadAssertTrue(f.result == 21);
689 <                    threadAssertTrue(f.isDone());
690 <                    threadAssertFalse(f.isCancelled());
691 <                    threadAssertFalse(f.isCompletedAbnormally());
684 >        RecursiveAction a = new CheckedRecursiveAction() {
685 >            public void realCompute() {
686 >                FibAction f = new FibAction(8);
687 >                checkNotDone(f);
688 >
689 >                for (int i = 0; i < 3; i++) {
690 >                    assertNull(f.invoke());
691 >                    assertEquals(21, f.result);
692 >                    checkCompletedNormally(f);
693                      f.reinitialize();
694 <                    f.invoke();
634 <                    threadAssertTrue(f.result == 21);
694 >                    checkNotDone(f);
695                  }
696 <            };
697 <        mainPool.invoke(a);
696 >            }};
697 >        testInvokeOnPool(mainPool(), a);
698      }
699  
700      /**
701       * invoke task throws exception after invoking completeExceptionally
702       */
703      public void testCompleteExceptionally() {
704 <        RecursiveAction a = new RecursiveAction() {
705 <                public void compute() {
706 <                    try {
707 <                        FibAction f = new FibAction(8);
708 <                        f.completeExceptionally(new FJException());
709 <                        f.invoke();
710 <                        shouldThrow();
711 <                    } catch (FJException success) {
712 <                    }
704 >        RecursiveAction a = new CheckedRecursiveAction() {
705 >            public void realCompute() {
706 >                FibAction f = new FibAction(8);
707 >                f.completeExceptionally(new FJException());
708 >                try {
709 >                    f.invoke();
710 >                    shouldThrow();
711 >                } catch (FJException success) {
712 >                    checkCompletedAbnormally(f, success);
713                  }
714 <            };
715 <        mainPool.invoke(a);
714 >            }};
715 >        testInvokeOnPool(mainPool(), a);
716      }
717  
718      /**
719       * invoke task suppresses execution invoking complete
720       */
721      public void testComplete() {
722 <        RecursiveAction a = new RecursiveAction() {
723 <                public void compute() {
724 <                    FibAction f = new FibAction(8);
725 <                    f.complete(null);
726 <                    f.invoke();
727 <                    threadAssertTrue(f.isDone());
728 <                    threadAssertTrue(f.result == 0);
729 <                }
730 <            };
671 <        mainPool.invoke(a);
722 >        RecursiveAction a = new CheckedRecursiveAction() {
723 >            public void realCompute() {
724 >                FibAction f = new FibAction(8);
725 >                f.complete(null);
726 >                assertNull(f.invoke());
727 >                assertEquals(0, f.result);
728 >                checkCompletedNormally(f);
729 >            }};
730 >        testInvokeOnPool(mainPool(), a);
731      }
732  
733      /**
734       * invokeAll(t1, t2) invokes all task arguments
735       */
736      public void testInvokeAll2() {
737 <        RecursiveAction a = new RecursiveAction() {
738 <                public void compute() {
739 <                    FibAction f = new FibAction(8);
740 <                    FibAction g = new FibAction(9);
741 <                    invokeAll(f, g);
742 <                    threadAssertTrue(f.isDone());
743 <                    threadAssertTrue(f.result == 21);
744 <                    threadAssertTrue(g.isDone());
745 <                    threadAssertTrue(g.result == 34);
746 <                }
747 <            };
689 <        mainPool.invoke(a);
737 >        RecursiveAction a = new CheckedRecursiveAction() {
738 >            public void realCompute() {
739 >                FibAction f = new FibAction(8);
740 >                FibAction g = new FibAction(9);
741 >                invokeAll(f, g);
742 >                checkCompletedNormally(f);
743 >                assertEquals(21, f.result);
744 >                checkCompletedNormally(g);
745 >                assertEquals(34, g.result);
746 >            }};
747 >        testInvokeOnPool(mainPool(), a);
748      }
749  
750      /**
751       * invokeAll(tasks) with 1 argument invokes task
752       */
753      public void testInvokeAll1() {
754 <        RecursiveAction a = new RecursiveAction() {
755 <                public void compute() {
756 <                    FibAction f = new FibAction(8);
757 <                    invokeAll(f);
758 <                    threadAssertTrue(f.isDone());
759 <                    threadAssertTrue(f.result == 21);
760 <                }
761 <            };
704 <        mainPool.invoke(a);
754 >        RecursiveAction a = new CheckedRecursiveAction() {
755 >            public void realCompute() {
756 >                FibAction f = new FibAction(8);
757 >                invokeAll(f);
758 >                checkCompletedNormally(f);
759 >                assertEquals(21, f.result);
760 >            }};
761 >        testInvokeOnPool(mainPool(), a);
762      }
763  
764      /**
765       * invokeAll(tasks) with > 2 argument invokes tasks
766       */
767      public void testInvokeAll3() {
768 <        RecursiveAction a = new RecursiveAction() {
769 <                public void compute() {
770 <                    FibAction f = new FibAction(8);
771 <                    FibAction g = new FibAction(9);
772 <                    FibAction h = new FibAction(7);
773 <                    invokeAll(f, g, h);
774 <                    threadAssertTrue(f.isDone());
775 <                    threadAssertTrue(f.result == 21);
776 <                    threadAssertTrue(g.isDone());
777 <                    threadAssertTrue(g.result == 34);
778 <                    threadAssertTrue(h.isDone());
779 <                    threadAssertTrue(h.result == 13);
780 <                }
781 <            };
782 <        mainPool.invoke(a);
768 >        RecursiveAction a = new CheckedRecursiveAction() {
769 >            public void realCompute() {
770 >                FibAction f = new FibAction(8);
771 >                FibAction g = new FibAction(9);
772 >                FibAction h = new FibAction(7);
773 >                invokeAll(f, g, h);
774 >                assertTrue(f.isDone());
775 >                assertTrue(g.isDone());
776 >                assertTrue(h.isDone());
777 >                checkCompletedNormally(f);
778 >                assertEquals(21, f.result);
779 >                checkCompletedNormally(g);
780 >                assertEquals(34, g.result);
781 >                checkCompletedNormally(g);
782 >                assertEquals(13, h.result);
783 >            }};
784 >        testInvokeOnPool(mainPool(), a);
785      }
786  
787      /**
788       * invokeAll(collection) invokes all tasks in the collection
789       */
790      public void testInvokeAllCollection() {
791 <        RecursiveAction a = new RecursiveAction() {
792 <                public void compute() {
793 <                    FibAction f = new FibAction(8);
794 <                    FibAction g = new FibAction(9);
795 <                    FibAction h = new FibAction(7);
796 <                    HashSet set = new HashSet();
797 <                    set.add(f);
798 <                    set.add(g);
799 <                    set.add(h);
800 <                    invokeAll(set);
801 <                    threadAssertTrue(f.isDone());
802 <                    threadAssertTrue(f.result == 21);
803 <                    threadAssertTrue(g.isDone());
804 <                    threadAssertTrue(g.result == 34);
805 <                    threadAssertTrue(h.isDone());
806 <                    threadAssertTrue(h.result == 13);
807 <                }
808 <            };
809 <        mainPool.invoke(a);
791 >        RecursiveAction a = new CheckedRecursiveAction() {
792 >            public void realCompute() {
793 >                FibAction f = new FibAction(8);
794 >                FibAction g = new FibAction(9);
795 >                FibAction h = new FibAction(7);
796 >                HashSet set = new HashSet();
797 >                set.add(f);
798 >                set.add(g);
799 >                set.add(h);
800 >                invokeAll(set);
801 >                assertTrue(f.isDone());
802 >                assertTrue(g.isDone());
803 >                assertTrue(h.isDone());
804 >                checkCompletedNormally(f);
805 >                assertEquals(21, f.result);
806 >                checkCompletedNormally(g);
807 >                assertEquals(34, g.result);
808 >                checkCompletedNormally(g);
809 >                assertEquals(13, h.result);
810 >            }};
811 >        testInvokeOnPool(mainPool(), a);
812      }
813  
814  
# Line 755 | Line 816 | public class RecursiveActionTest extends
816       * invokeAll(tasks) with any null task throws NPE
817       */
818      public void testInvokeAllNPE() {
819 <        RecursiveAction a = new RecursiveAction() {
820 <                public void compute() {
821 <                    try {
822 <                        FibAction f = new FibAction(8);
823 <                        FibAction g = new FibAction(9);
824 <                        FibAction h = null;
825 <                        invokeAll(f, g, h);
826 <                        shouldThrow();
827 <                    } catch (NullPointerException success) {
828 <                    }
829 <                }
769 <            };
770 <        mainPool.invoke(a);
819 >        RecursiveAction a = new CheckedRecursiveAction() {
820 >            public void realCompute() {
821 >                FibAction f = new FibAction(8);
822 >                FibAction g = new FibAction(9);
823 >                FibAction h = null;
824 >                try {
825 >                    invokeAll(f, g, h);
826 >                    shouldThrow();
827 >                } catch (NullPointerException success) {}
828 >            }};
829 >        testInvokeOnPool(mainPool(), a);
830      }
831  
832      /**
833       * invokeAll(t1, t2) throw exception if any task does
834       */
835      public void testAbnormalInvokeAll2() {
836 <        RecursiveAction a = new RecursiveAction() {
837 <                public void compute() {
838 <                    try {
839 <                        FibAction f = new FibAction(8);
840 <                        FailingFibAction g = new FailingFibAction(9);
841 <                        invokeAll(f, g);
842 <                        shouldThrow();
843 <                    } catch (FJException success) {
844 <                    }
836 >        RecursiveAction a = new CheckedRecursiveAction() {
837 >            public void realCompute() {
838 >                FibAction f = new FibAction(8);
839 >                FailingFibAction g = new FailingFibAction(9);
840 >                try {
841 >                    invokeAll(f, g);
842 >                    shouldThrow();
843 >                } catch (FJException success) {
844 >                    checkCompletedAbnormally(g, success);
845                  }
846 <            };
847 <        mainPool.invoke(a);
846 >            }};
847 >        testInvokeOnPool(mainPool(), a);
848      }
849  
850      /**
851       * invokeAll(tasks) with 1 argument throws exception if task does
852       */
853      public void testAbnormalInvokeAll1() {
854 <        RecursiveAction a = new RecursiveAction() {
855 <                public void compute() {
856 <                    try {
857 <                        FailingFibAction g = new FailingFibAction(9);
858 <                        invokeAll(g);
859 <                        shouldThrow();
860 <                    } catch (FJException success) {
861 <                    }
854 >        RecursiveAction a = new CheckedRecursiveAction() {
855 >            public void realCompute() {
856 >                FailingFibAction g = new FailingFibAction(9);
857 >                try {
858 >                    invokeAll(g);
859 >                    shouldThrow();
860 >                } catch (FJException success) {
861 >                    checkCompletedAbnormally(g, success);
862                  }
863 <            };
864 <        mainPool.invoke(a);
863 >            }};
864 >        testInvokeOnPool(mainPool(), a);
865      }
866  
867      /**
868       * invokeAll(tasks) with > 2 argument throws exception if any task does
869       */
870      public void testAbnormalInvokeAll3() {
871 <        RecursiveAction a = new RecursiveAction() {
872 <                public void compute() {
873 <                    try {
874 <                        FibAction f = new FibAction(8);
875 <                        FailingFibAction g = new FailingFibAction(9);
876 <                        FibAction h = new FibAction(7);
877 <                        invokeAll(f, g, h);
878 <                        shouldThrow();
879 <                    } catch (FJException success) {
880 <                    }
871 >        RecursiveAction a = new CheckedRecursiveAction() {
872 >            public void realCompute() {
873 >                FibAction f = new FibAction(8);
874 >                FailingFibAction g = new FailingFibAction(9);
875 >                FibAction h = new FibAction(7);
876 >                try {
877 >                    invokeAll(f, g, h);
878 >                    shouldThrow();
879 >                } catch (FJException success) {
880 >                    checkCompletedAbnormally(g, success);
881                  }
882 <            };
883 <        mainPool.invoke(a);
882 >            }};
883 >        testInvokeOnPool(mainPool(), a);
884      }
885  
886      /**
887 <     * invokeAll(collection)  throws exception if any task does
887 >     * invokeAll(collection) throws exception if any task does
888       */
889      public void testAbnormalInvokeAllCollection() {
890 <        RecursiveAction a = new RecursiveAction() {
891 <                public void compute() {
892 <                    try {
893 <                        FailingFibAction f = new FailingFibAction(8);
894 <                        FibAction g = new FibAction(9);
895 <                        FibAction h = new FibAction(7);
896 <                        HashSet set = new HashSet();
897 <                        set.add(f);
898 <                        set.add(g);
899 <                        set.add(h);
900 <                        invokeAll(set);
901 <                        shouldThrow();
902 <                    } catch (FJException success) {
903 <                    }
890 >        RecursiveAction a = new CheckedRecursiveAction() {
891 >            public void realCompute() {
892 >                FailingFibAction f = new FailingFibAction(8);
893 >                FibAction g = new FibAction(9);
894 >                FibAction h = new FibAction(7);
895 >                HashSet set = new HashSet();
896 >                set.add(f);
897 >                set.add(g);
898 >                set.add(h);
899 >                try {
900 >                    invokeAll(set);
901 >                    shouldThrow();
902 >                } catch (FJException success) {
903 >                    checkCompletedAbnormally(f, success);
904                  }
905 <            };
906 <        mainPool.invoke(a);
905 >            }};
906 >        testInvokeOnPool(mainPool(), a);
907      }
908  
909      /**
# Line 852 | Line 911 | public class RecursiveActionTest extends
911       * and suppresses execution
912       */
913      public void testTryUnfork() {
914 <        RecursiveAction a = new RecursiveAction() {
915 <                public void compute() {
916 <                    FibAction g = new FibAction(9);
917 <                    g.fork();
918 <                    FibAction f = new FibAction(8);
919 <                    f.fork();
920 <                    threadAssertTrue(f.tryUnfork());
921 <                    helpQuiesce();
922 <                    threadAssertFalse(f.isDone());
923 <                    threadAssertTrue(g.isDone());
924 <                }
925 <            };
867 <        singletonPool.invoke(a);
914 >        RecursiveAction a = new CheckedRecursiveAction() {
915 >            public void realCompute() {
916 >                FibAction g = new FibAction(9);
917 >                assertSame(g, g.fork());
918 >                FibAction f = new FibAction(8);
919 >                assertSame(f, f.fork());
920 >                assertTrue(f.tryUnfork());
921 >                helpQuiesce();
922 >                checkNotDone(f);
923 >                checkCompletedNormally(g);
924 >            }};
925 >        testInvokeOnPool(singletonPool(), a);
926      }
927  
928      /**
# Line 872 | Line 930 | public class RecursiveActionTest extends
930       * there are more tasks than threads
931       */
932      public void testGetSurplusQueuedTaskCount() {
933 <        RecursiveAction a = new RecursiveAction() {
934 <                public void compute() {
935 <                    FibAction h = new FibAction(7);
936 <                    h.fork();
937 <                    FibAction g = new FibAction(9);
938 <                    g.fork();
939 <                    FibAction f = new FibAction(8);
940 <                    f.fork();
941 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
942 <                    helpQuiesce();
943 <                }
944 <            };
945 <        singletonPool.invoke(a);
933 >        RecursiveAction a = new CheckedRecursiveAction() {
934 >            public void realCompute() {
935 >                FibAction h = new FibAction(7);
936 >                assertSame(h, h.fork());
937 >                FibAction g = new FibAction(9);
938 >                assertSame(g, g.fork());
939 >                FibAction f = new FibAction(8);
940 >                assertSame(f, f.fork());
941 >                assertTrue(getSurplusQueuedTaskCount() > 0);
942 >                helpQuiesce();
943 >                assertEquals(0, getSurplusQueuedTaskCount());
944 >                checkCompletedNormally(f);
945 >                checkCompletedNormally(g);
946 >                checkCompletedNormally(h);
947 >            }};
948 >        testInvokeOnPool(singletonPool(), a);
949      }
950  
951      /**
952       * peekNextLocalTask returns most recent unexecuted task.
953       */
954      public void testPeekNextLocalTask() {
955 <        RecursiveAction a = new RecursiveAction() {
956 <                public void compute() {
957 <                    FibAction g = new FibAction(9);
958 <                    g.fork();
959 <                    FibAction f = new FibAction(8);
960 <                    f.fork();
961 <                    threadAssertTrue(peekNextLocalTask() == f);
962 <                    f.join();
963 <                    threadAssertTrue(f.isDone());
964 <                    helpQuiesce();
965 <                }
966 <            };
967 <        singletonPool.invoke(a);
955 >        RecursiveAction a = new CheckedRecursiveAction() {
956 >            public void realCompute() {
957 >                FibAction g = new FibAction(9);
958 >                assertSame(g, g.fork());
959 >                FibAction f = new FibAction(8);
960 >                assertSame(f, f.fork());
961 >                assertSame(f, peekNextLocalTask());
962 >                assertNull(f.join());
963 >                checkCompletedNormally(f);
964 >                helpQuiesce();
965 >                checkCompletedNormally(f);
966 >                checkCompletedNormally(g);
967 >            }};
968 >        testInvokeOnPool(singletonPool(), a);
969      }
970  
971      /**
# Line 911 | Line 973 | public class RecursiveActionTest extends
973       * without executing it
974       */
975      public void testPollNextLocalTask() {
976 <        RecursiveAction a = new RecursiveAction() {
977 <                public void compute() {
978 <                    FibAction g = new FibAction(9);
979 <                    g.fork();
980 <                    FibAction f = new FibAction(8);
981 <                    f.fork();
982 <                    threadAssertTrue(pollNextLocalTask() == f);
983 <                    helpQuiesce();
984 <                    threadAssertFalse(f.isDone());
985 <                }
986 <            };
987 <        singletonPool.invoke(a);
976 >        RecursiveAction a = new CheckedRecursiveAction() {
977 >            public void realCompute() {
978 >                FibAction g = new FibAction(9);
979 >                assertSame(g, g.fork());
980 >                FibAction f = new FibAction(8);
981 >                assertSame(f, f.fork());
982 >                assertSame(f, pollNextLocalTask());
983 >                helpQuiesce();
984 >                checkNotDone(f);
985 >                checkCompletedNormally(g);
986 >            }};
987 >        testInvokeOnPool(singletonPool(), a);
988      }
989  
990      /**
991 <     * pollTask returns an unexecuted task
930 <     * without executing it
991 >     * pollTask returns an unexecuted task without executing it
992       */
993      public void testPollTask() {
994 <        RecursiveAction a = new RecursiveAction() {
995 <                public void compute() {
996 <                    FibAction g = new FibAction(9);
997 <                    g.fork();
998 <                    FibAction f = new FibAction(8);
999 <                    f.fork();
1000 <                    threadAssertTrue(pollTask() == f);
1001 <                    helpQuiesce();
1002 <                    threadAssertFalse(f.isDone());
1003 <                    threadAssertTrue(g.isDone());
1004 <                }
1005 <            };
945 <        singletonPool.invoke(a);
994 >        RecursiveAction a = new CheckedRecursiveAction() {
995 >            public void realCompute() {
996 >                FibAction g = new FibAction(9);
997 >                assertSame(g, g.fork());
998 >                FibAction f = new FibAction(8);
999 >                assertSame(f, f.fork());
1000 >                assertSame(f, pollTask());
1001 >                helpQuiesce();
1002 >                checkNotDone(f);
1003 >                checkCompletedNormally(g);
1004 >            }};
1005 >        testInvokeOnPool(singletonPool(), a);
1006      }
1007  
1008      /**
1009       * peekNextLocalTask returns least recent unexecuted task in async mode
1010       */
1011      public void testPeekNextLocalTaskAsync() {
1012 <        RecursiveAction a = new RecursiveAction() {
1013 <                public void compute() {
1014 <                    FibAction g = new FibAction(9);
1015 <                    g.fork();
1016 <                    FibAction f = new FibAction(8);
1017 <                    f.fork();
1018 <                    threadAssertTrue(peekNextLocalTask() == g);
1019 <                    f.join();
1020 <                    helpQuiesce();
1021 <                    threadAssertTrue(f.isDone());
1022 <                }
1023 <            };
1024 <        asyncSingletonPool.invoke(a);
1012 >        RecursiveAction a = new CheckedRecursiveAction() {
1013 >            public void realCompute() {
1014 >                FibAction g = new FibAction(9);
1015 >                assertSame(g, g.fork());
1016 >                FibAction f = new FibAction(8);
1017 >                assertSame(f, f.fork());
1018 >                assertSame(g, peekNextLocalTask());
1019 >                assertNull(f.join());
1020 >                helpQuiesce();
1021 >                checkCompletedNormally(f);
1022 >                checkCompletedNormally(g);
1023 >            }};
1024 >        testInvokeOnPool(asyncSingletonPool(), a);
1025      }
1026  
1027      /**
1028 <     * pollNextLocalTask returns least recent unexecuted task
1029 <     * without executing it, in async mode
1028 >     * pollNextLocalTask returns least recent unexecuted task without
1029 >     * executing it, in async mode
1030       */
1031      public void testPollNextLocalTaskAsync() {
1032 <        RecursiveAction a = new RecursiveAction() {
1033 <                public void compute() {
1034 <                    FibAction g = new FibAction(9);
1035 <                    g.fork();
1036 <                    FibAction f = new FibAction(8);
1037 <                    f.fork();
1038 <                    threadAssertTrue(pollNextLocalTask() == g);
1039 <                    helpQuiesce();
1040 <                    threadAssertTrue(f.isDone());
1041 <                    threadAssertFalse(g.isDone());
1042 <                }
1043 <            };
984 <        asyncSingletonPool.invoke(a);
1032 >        RecursiveAction a = new CheckedRecursiveAction() {
1033 >            public void realCompute() {
1034 >                FibAction g = new FibAction(9);
1035 >                assertSame(g, g.fork());
1036 >                FibAction f = new FibAction(8);
1037 >                assertSame(f, f.fork());
1038 >                assertSame(g, pollNextLocalTask());
1039 >                helpQuiesce();
1040 >                checkCompletedNormally(f);
1041 >                checkNotDone(g);
1042 >            }};
1043 >        testInvokeOnPool(asyncSingletonPool(), a);
1044      }
1045  
1046      /**
1047 <     * pollTask returns an unexecuted task
1048 <     * without executing it, in async mode
1047 >     * pollTask returns an unexecuted task without executing it, in
1048 >     * async mode
1049       */
1050      public void testPollTaskAsync() {
1051 <        RecursiveAction a = new RecursiveAction() {
1052 <                public void compute() {
1053 <                    FibAction g = new FibAction(9);
1054 <                    g.fork();
1055 <                    FibAction f = new FibAction(8);
1056 <                    f.fork();
1057 <                    threadAssertTrue(pollTask() == g);
1058 <                    helpQuiesce();
1059 <                    threadAssertTrue(f.isDone());
1060 <                    threadAssertFalse(g.isDone());
1061 <                }
1062 <            };
1004 <        asyncSingletonPool.invoke(a);
1051 >        RecursiveAction a = new CheckedRecursiveAction() {
1052 >            public void realCompute() {
1053 >                FibAction g = new FibAction(9);
1054 >                assertSame(g, g.fork());
1055 >                FibAction f = new FibAction(8);
1056 >                assertSame(f, f.fork());
1057 >                assertSame(g, pollTask());
1058 >                helpQuiesce();
1059 >                checkCompletedNormally(f);
1060 >                checkNotDone(g);
1061 >            }};
1062 >        testInvokeOnPool(asyncSingletonPool(), a);
1063      }
1064  
1065   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines