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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines