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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines