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 |
|
static final ForkJoinPool mainPool = new ForkJoinPool(); |
22 |
|
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
23 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
24 |
< |
static { |
25 |
< |
asyncSingletonPool.setAsyncMode(true); |
25 |
< |
} |
23 |
> |
static final ForkJoinPool asyncSingletonPool = |
24 |
> |
new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
25 |
> |
null, true); |
26 |
|
|
27 |
|
static final class FJException extends RuntimeException { |
28 |
|
FJException() { super(); } |
68 |
|
* invoke returns when task completes normally. |
69 |
|
* isCompletedAbnormally and isCancelled return false for normally |
70 |
|
* completed tasks. getRawResult of a RecursiveAction returns null; |
71 |
– |
* |
71 |
|
*/ |
72 |
|
public void testInvoke() { |
73 |
|
RecursiveAction a = new RecursiveAction() { |
176 |
|
} |
177 |
|
|
178 |
|
/** |
180 |
– |
* helpJoin of a forked task returns when task completes |
181 |
– |
*/ |
182 |
– |
public void testForkHelpJoin() { |
183 |
– |
RecursiveAction a = new RecursiveAction() { |
184 |
– |
public void compute() { |
185 |
– |
FibAction f = new FibAction(8); |
186 |
– |
f.fork(); |
187 |
– |
f.helpJoin(); |
188 |
– |
threadAssertTrue(f.result == 21); |
189 |
– |
threadAssertTrue(f.isDone()); |
190 |
– |
}}; |
191 |
– |
mainPool.invoke(a); |
192 |
– |
} |
193 |
– |
|
194 |
– |
/** |
179 |
|
* quietlyJoin of a forked task returns when task completes |
180 |
|
*/ |
181 |
|
public void testForkQuietlyJoin() { |
192 |
|
|
193 |
|
|
194 |
|
/** |
211 |
– |
* quietlyHelpJoin of a forked task returns when task completes |
212 |
– |
*/ |
213 |
– |
public void testForkQuietlyHelpJoin() { |
214 |
– |
RecursiveAction a = new RecursiveAction() { |
215 |
– |
public void compute() { |
216 |
– |
FibAction f = new FibAction(8); |
217 |
– |
f.fork(); |
218 |
– |
f.quietlyHelpJoin(); |
219 |
– |
threadAssertTrue(f.result == 21); |
220 |
– |
threadAssertTrue(f.isDone()); |
221 |
– |
}}; |
222 |
– |
mainPool.invoke(a); |
223 |
– |
} |
224 |
– |
|
225 |
– |
|
226 |
– |
/** |
195 |
|
* helpQuiesce returns when tasks are complete. |
196 |
|
* getQueuedTaskCount returns 0 when quiescent |
197 |
|
*/ |
294 |
|
} |
295 |
|
|
296 |
|
/** |
329 |
– |
* join of a forked task throws exception when task completes abnormally |
330 |
– |
*/ |
331 |
– |
public void testAbnormalForkHelpJoin() { |
332 |
– |
RecursiveAction a = new RecursiveAction() { |
333 |
– |
public void compute() { |
334 |
– |
try { |
335 |
– |
FailingFibAction f = new FailingFibAction(8); |
336 |
– |
f.fork(); |
337 |
– |
f.helpJoin(); |
338 |
– |
shouldThrow(); |
339 |
– |
} catch (FJException success) { |
340 |
– |
} |
341 |
– |
}}; |
342 |
– |
mainPool.invoke(a); |
343 |
– |
} |
344 |
– |
|
345 |
– |
/** |
346 |
– |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
347 |
– |
* getException of failed task returns its exception. |
348 |
– |
* isCompletedAbnormally of a failed task returns true. |
349 |
– |
* isCancelled of a failed uncancelled task returns false |
350 |
– |
*/ |
351 |
– |
public void testAbnormalForkQuietlyHelpJoin() { |
352 |
– |
RecursiveAction a = new RecursiveAction() { |
353 |
– |
public void compute() { |
354 |
– |
FailingFibAction f = new FailingFibAction(8); |
355 |
– |
f.fork(); |
356 |
– |
f.quietlyHelpJoin(); |
357 |
– |
threadAssertTrue(f.isDone()); |
358 |
– |
threadAssertTrue(f.isCompletedAbnormally()); |
359 |
– |
threadAssertFalse(f.isCancelled()); |
360 |
– |
threadAssertTrue(f.getException() instanceof FJException); |
361 |
– |
}}; |
362 |
– |
mainPool.invoke(a); |
363 |
– |
} |
364 |
– |
|
365 |
– |
/** |
297 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
298 |
|
*/ |
299 |
|
public void testAbnormalForkQuietlyJoin() { |
385 |
|
} |
386 |
|
|
387 |
|
/** |
457 |
– |
* join of a forked task throws exception when task cancelled |
458 |
– |
*/ |
459 |
– |
public void testCancelledForkHelpJoin() { |
460 |
– |
RecursiveAction a = new RecursiveAction() { |
461 |
– |
public void compute() { |
462 |
– |
try { |
463 |
– |
FibAction f = new FibAction(8); |
464 |
– |
f.cancel(true); |
465 |
– |
f.fork(); |
466 |
– |
f.helpJoin(); |
467 |
– |
shouldThrow(); |
468 |
– |
} catch (CancellationException success) { |
469 |
– |
} |
470 |
– |
}}; |
471 |
– |
mainPool.invoke(a); |
472 |
– |
} |
473 |
– |
|
474 |
– |
/** |
475 |
– |
* quietlyHelpJoin of a forked task returns when task cancelled. |
476 |
– |
* getException of cancelled task returns its exception. |
477 |
– |
* isCompletedAbnormally of a cancelled task returns true. |
478 |
– |
* isCancelled of a cancelled task returns true |
479 |
– |
*/ |
480 |
– |
public void testCancelledForkQuietlyHelpJoin() { |
481 |
– |
RecursiveAction a = new RecursiveAction() { |
482 |
– |
public void compute() { |
483 |
– |
FibAction f = new FibAction(8); |
484 |
– |
f.cancel(true); |
485 |
– |
f.fork(); |
486 |
– |
f.quietlyHelpJoin(); |
487 |
– |
threadAssertTrue(f.isDone()); |
488 |
– |
threadAssertTrue(f.isCompletedAbnormally()); |
489 |
– |
threadAssertTrue(f.isCancelled()); |
490 |
– |
threadAssertTrue(f.getException() instanceof CancellationException); |
491 |
– |
}}; |
492 |
– |
mainPool.invoke(a); |
493 |
– |
} |
494 |
– |
|
495 |
– |
/** |
388 |
|
* quietlyJoin of a forked task returns when task cancelled |
389 |
|
*/ |
390 |
|
public void testCancelledForkQuietlyJoin() { |
460 |
|
|
461 |
|
/** |
462 |
|
* getPoolIndex of current thread in pool returns 0 <= value < poolSize |
571 |
– |
* |
463 |
|
*/ |
464 |
|
public void testWorkerGetPoolIndex() { |
465 |
|
RecursiveAction a = new RecursiveAction() { |