11 |
|
import java.util.concurrent.RecursiveAction; |
12 |
|
import java.util.concurrent.TimeUnit; |
13 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
14 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
15 |
|
import java.util.HashSet; |
16 |
|
import junit.framework.*; |
17 |
|
|
25 |
|
return new TestSuite(ForkJoinTaskTest.class); |
26 |
|
} |
27 |
|
|
28 |
+ |
// Runs with "mainPool" use > 1 thread. singletonPool tests use 1 |
29 |
+ |
static final int mainPoolSize = |
30 |
+ |
Math.max(2, Runtime.getRuntime().availableProcessors()); |
31 |
+ |
|
32 |
|
private static ForkJoinPool mainPool() { |
33 |
< |
return new ForkJoinPool(); |
33 |
> |
return new ForkJoinPool(mainPoolSize); |
34 |
|
} |
35 |
|
|
36 |
|
private static ForkJoinPool singletonPool() { |
45 |
|
|
46 |
|
private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { |
47 |
|
try { |
48 |
< |
assertTrue(pool.invoke(a) == null); |
48 |
> |
assertFalse(a.isDone()); |
49 |
> |
assertFalse(a.isCompletedNormally()); |
50 |
> |
assertFalse(a.isCompletedAbnormally()); |
51 |
> |
assertFalse(a.isCancelled()); |
52 |
> |
assertNull(a.getException()); |
53 |
> |
|
54 |
> |
assertNull(pool.invoke(a)); |
55 |
> |
|
56 |
> |
assertTrue(a.isDone()); |
57 |
> |
assertTrue(a.isCompletedNormally()); |
58 |
> |
assertFalse(a.isCompletedAbnormally()); |
59 |
> |
assertFalse(a.isCancelled()); |
60 |
> |
assertNull(a.getException()); |
61 |
|
} finally { |
62 |
|
joinPool(pool); |
63 |
|
} |
75 |
|
FJException() { super(); } |
76 |
|
} |
77 |
|
|
78 |
< |
static abstract class BinaryAsyncAction extends ForkJoinTask<Void> { |
78 |
> |
abstract static class BinaryAsyncAction extends ForkJoinTask<Void> { |
79 |
|
private volatile int controlState; |
80 |
|
|
81 |
|
static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater = |
250 |
|
* completed tasks. getRawResult of a RecursiveAction returns null; |
251 |
|
*/ |
252 |
|
public void testInvoke() { |
253 |
< |
RecursiveAction a = new RecursiveAction() { |
254 |
< |
public void compute() { |
253 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
254 |
> |
public void realCompute() { |
255 |
|
AsyncFib f = new AsyncFib(8); |
256 |
< |
threadAssertNull(f.invoke()); |
257 |
< |
threadAssertTrue(f.number == 21); |
258 |
< |
threadAssertTrue(f.isDone()); |
259 |
< |
threadAssertFalse(f.isCancelled()); |
260 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
261 |
< |
threadAssertTrue(f.getRawResult() == null); |
256 |
> |
assertNull(f.invoke()); |
257 |
> |
assertEquals(21, f.number); |
258 |
> |
assertTrue(f.isDone()); |
259 |
> |
assertFalse(f.isCancelled()); |
260 |
> |
assertFalse(f.isCompletedAbnormally()); |
261 |
> |
assertNull(f.getRawResult()); |
262 |
|
}}; |
263 |
|
testInvokeOnPool(mainPool(), a); |
264 |
|
} |
269 |
|
* completed tasks |
270 |
|
*/ |
271 |
|
public void testQuietlyInvoke() { |
272 |
< |
RecursiveAction a = new RecursiveAction() { |
273 |
< |
public void compute() { |
272 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
273 |
> |
public void realCompute() { |
274 |
|
AsyncFib f = new AsyncFib(8); |
275 |
|
f.quietlyInvoke(); |
276 |
< |
threadAssertTrue(f.number == 21); |
277 |
< |
threadAssertTrue(f.isDone()); |
278 |
< |
threadAssertFalse(f.isCancelled()); |
279 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
280 |
< |
threadAssertTrue(f.getRawResult() == null); |
276 |
> |
assertEquals(21, f.number); |
277 |
> |
assertTrue(f.isDone()); |
278 |
> |
assertFalse(f.isCancelled()); |
279 |
> |
assertFalse(f.isCompletedAbnormally()); |
280 |
> |
assertNull(f.getRawResult()); |
281 |
|
}}; |
282 |
|
testInvokeOnPool(mainPool(), a); |
283 |
|
} |
286 |
|
* join of a forked task returns when task completes |
287 |
|
*/ |
288 |
|
public void testForkJoin() { |
289 |
< |
RecursiveAction a = new RecursiveAction() { |
290 |
< |
public void compute() { |
289 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
290 |
> |
public void realCompute() { |
291 |
|
AsyncFib f = new AsyncFib(8); |
292 |
< |
threadAssertSame(f, f.fork()); |
293 |
< |
threadAssertNull(f.join()); |
294 |
< |
threadAssertTrue(f.number == 21); |
295 |
< |
threadAssertTrue(f.isDone()); |
296 |
< |
threadAssertTrue(f.getRawResult() == null); |
292 |
> |
assertSame(f, f.fork()); |
293 |
> |
assertNull(f.join()); |
294 |
> |
assertEquals(21, f.number); |
295 |
> |
assertTrue(f.isDone()); |
296 |
> |
assertNull(f.getRawResult()); |
297 |
|
}}; |
298 |
|
testInvokeOnPool(mainPool(), a); |
299 |
|
} |
302 |
|
* get of a forked task returns when task completes |
303 |
|
*/ |
304 |
|
public void testForkGet() { |
305 |
< |
RecursiveAction a = new RecursiveAction() { |
306 |
< |
public void compute() { |
307 |
< |
try { |
308 |
< |
AsyncFib f = new AsyncFib(8); |
309 |
< |
threadAssertSame(f, f.fork()); |
310 |
< |
threadAssertNull(f.get()); |
311 |
< |
threadAssertTrue(f.number == 21); |
295 |
< |
threadAssertTrue(f.isDone()); |
296 |
< |
} catch (Exception ex) { |
297 |
< |
unexpectedException(ex); |
298 |
< |
} |
305 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
306 |
> |
public void realCompute() throws Exception { |
307 |
> |
AsyncFib f = new AsyncFib(8); |
308 |
> |
assertSame(f, f.fork()); |
309 |
> |
assertNull(f.get()); |
310 |
> |
assertEquals(21, f.number); |
311 |
> |
assertTrue(f.isDone()); |
312 |
|
}}; |
313 |
|
testInvokeOnPool(mainPool(), a); |
314 |
|
} |
317 |
|
* timed get of a forked task returns when task completes |
318 |
|
*/ |
319 |
|
public void testForkTimedGet() { |
320 |
< |
RecursiveAction a = new RecursiveAction() { |
321 |
< |
public void compute() { |
322 |
< |
try { |
323 |
< |
AsyncFib f = new AsyncFib(8); |
324 |
< |
threadAssertSame(f, f.fork()); |
325 |
< |
threadAssertNull(f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
326 |
< |
threadAssertTrue(f.number == 21); |
314 |
< |
threadAssertTrue(f.isDone()); |
315 |
< |
} catch (Exception ex) { |
316 |
< |
unexpectedException(ex); |
317 |
< |
} |
320 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
321 |
> |
public void realCompute() throws Exception { |
322 |
> |
AsyncFib f = new AsyncFib(8); |
323 |
> |
assertSame(f, f.fork()); |
324 |
> |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
325 |
> |
assertEquals(21, f.number); |
326 |
> |
assertTrue(f.isDone()); |
327 |
|
}}; |
328 |
|
testInvokeOnPool(mainPool(), a); |
329 |
|
} |
332 |
|
* timed get with null time unit throws NPE |
333 |
|
*/ |
334 |
|
public void testForkTimedGetNPE() { |
335 |
< |
RecursiveAction a = new RecursiveAction() { |
336 |
< |
public void compute() { |
335 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
336 |
> |
public void realCompute() throws Exception { |
337 |
> |
AsyncFib f = new AsyncFib(8); |
338 |
> |
assertSame(f, f.fork()); |
339 |
|
try { |
329 |
– |
AsyncFib f = new AsyncFib(8); |
330 |
– |
threadAssertSame(f, f.fork()); |
340 |
|
f.get(5L, null); |
341 |
|
shouldThrow(); |
342 |
< |
} catch (NullPointerException success) { |
334 |
< |
} catch (Exception ex) { |
335 |
< |
unexpectedException(ex); |
336 |
< |
} |
342 |
> |
} catch (NullPointerException success) {} |
343 |
|
}}; |
344 |
|
testInvokeOnPool(mainPool(), a); |
345 |
|
} |
348 |
|
* quietlyJoin of a forked task returns when task completes |
349 |
|
*/ |
350 |
|
public void testForkQuietlyJoin() { |
351 |
< |
RecursiveAction a = new RecursiveAction() { |
352 |
< |
public void compute() { |
351 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
352 |
> |
public void realCompute() { |
353 |
|
AsyncFib f = new AsyncFib(8); |
354 |
< |
threadAssertSame(f, f.fork()); |
354 |
> |
assertSame(f, f.fork()); |
355 |
|
f.quietlyJoin(); |
356 |
< |
threadAssertTrue(f.number == 21); |
357 |
< |
threadAssertTrue(f.isDone()); |
356 |
> |
assertEquals(21, f.number); |
357 |
> |
assertTrue(f.isDone()); |
358 |
|
}}; |
359 |
|
testInvokeOnPool(mainPool(), a); |
360 |
|
} |
365 |
|
* getQueuedTaskCount returns 0 when quiescent |
366 |
|
*/ |
367 |
|
public void testForkHelpQuiesce() { |
368 |
< |
RecursiveAction a = new RecursiveAction() { |
369 |
< |
public void compute() { |
368 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
369 |
> |
public void realCompute() { |
370 |
|
AsyncFib f = new AsyncFib(8); |
371 |
< |
threadAssertSame(f, f.fork()); |
371 |
> |
assertSame(f, f.fork()); |
372 |
|
f.helpQuiesce(); |
373 |
< |
threadAssertTrue(f.number == 21); |
374 |
< |
threadAssertTrue(f.isDone()); |
375 |
< |
threadAssertTrue(getQueuedTaskCount() == 0); |
373 |
> |
assertEquals(21, f.number); |
374 |
> |
assertTrue(f.isDone()); |
375 |
> |
assertEquals(0, getQueuedTaskCount()); |
376 |
|
}}; |
377 |
|
testInvokeOnPool(mainPool(), a); |
378 |
|
} |
382 |
|
* invoke task throws exception when task completes abnormally |
383 |
|
*/ |
384 |
|
public void testAbnormalInvoke() { |
385 |
< |
RecursiveAction a = new RecursiveAction() { |
386 |
< |
public void compute() { |
385 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
386 |
> |
public void realCompute() { |
387 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
388 |
|
try { |
382 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
389 |
|
f.invoke(); |
390 |
|
shouldThrow(); |
391 |
< |
} catch (FJException success) { |
386 |
< |
} |
391 |
> |
} catch (FJException success) {} |
392 |
|
}}; |
393 |
|
testInvokeOnPool(mainPool(), a); |
394 |
|
} |
397 |
|
* quietlyInvoke task returns when task completes abnormally |
398 |
|
*/ |
399 |
|
public void testAbnormalQuietlyInvoke() { |
400 |
< |
RecursiveAction a = new RecursiveAction() { |
401 |
< |
public void compute() { |
400 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
401 |
> |
public void realCompute() { |
402 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
403 |
|
f.quietlyInvoke(); |
404 |
< |
threadAssertTrue(f.isDone()); |
404 |
> |
assertTrue(f.isDone()); |
405 |
|
}}; |
406 |
|
testInvokeOnPool(mainPool(), a); |
407 |
|
} |
410 |
|
* join of a forked task throws exception when task completes abnormally |
411 |
|
*/ |
412 |
|
public void testAbnormalForkJoin() { |
413 |
< |
RecursiveAction a = new RecursiveAction() { |
414 |
< |
public void compute() { |
413 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
414 |
> |
public void realCompute() { |
415 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
416 |
> |
assertSame(f, f.fork()); |
417 |
|
try { |
411 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
412 |
– |
threadAssertSame(f, f.fork()); |
418 |
|
f.join(); |
419 |
|
shouldThrow(); |
420 |
< |
} catch (FJException success) { |
416 |
< |
} |
420 |
> |
} catch (FJException success) {} |
421 |
|
}}; |
422 |
|
testInvokeOnPool(mainPool(), a); |
423 |
|
} |
426 |
|
* get of a forked task throws exception when task completes abnormally |
427 |
|
*/ |
428 |
|
public void testAbnormalForkGet() { |
429 |
< |
RecursiveAction a = new RecursiveAction() { |
430 |
< |
public void compute() { |
429 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
430 |
> |
public void realCompute() throws Exception { |
431 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
432 |
> |
assertSame(f, f.fork()); |
433 |
|
try { |
428 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
429 |
– |
threadAssertSame(f, f.fork()); |
434 |
|
f.get(); |
435 |
|
shouldThrow(); |
436 |
|
} catch (ExecutionException success) { |
437 |
< |
} catch (Exception ex) { |
438 |
< |
unexpectedException(ex); |
437 |
> |
Throwable cause = success.getCause(); |
438 |
> |
assertTrue(cause instanceof FJException); |
439 |
> |
assertTrue(f.isDone()); |
440 |
> |
assertTrue(f.isCompletedAbnormally()); |
441 |
> |
assertSame(cause.getClass(), f.getException().getClass()); |
442 |
|
} |
443 |
|
}}; |
444 |
|
testInvokeOnPool(mainPool(), a); |
448 |
|
* timed get of a forked task throws exception when task completes abnormally |
449 |
|
*/ |
450 |
|
public void testAbnormalForkTimedGet() { |
451 |
< |
RecursiveAction a = new RecursiveAction() { |
452 |
< |
public void compute() { |
451 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
452 |
> |
public void realCompute() throws Exception { |
453 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
454 |
> |
assertSame(f, f.fork()); |
455 |
|
try { |
456 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
448 |
< |
threadAssertSame(f, f.fork()); |
449 |
< |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
456 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
457 |
|
shouldThrow(); |
458 |
|
} catch (ExecutionException success) { |
459 |
< |
} catch (Exception ex) { |
460 |
< |
unexpectedException(ex); |
459 |
> |
Throwable cause = success.getCause(); |
460 |
> |
assertTrue(cause instanceof FJException); |
461 |
> |
assertTrue(f.isDone()); |
462 |
> |
assertTrue(f.isCompletedAbnormally()); |
463 |
> |
assertSame(cause.getClass(), f.getException().getClass()); |
464 |
|
} |
465 |
|
}}; |
466 |
|
testInvokeOnPool(mainPool(), a); |
470 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
471 |
|
*/ |
472 |
|
public void testAbnormalForkQuietlyJoin() { |
473 |
< |
RecursiveAction a = new RecursiveAction() { |
474 |
< |
public void compute() { |
473 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
474 |
> |
public void realCompute() { |
475 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
476 |
< |
threadAssertSame(f, f.fork()); |
476 |
> |
assertSame(f, f.fork()); |
477 |
|
f.quietlyJoin(); |
478 |
< |
threadAssertTrue(f.isDone()); |
479 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
480 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
478 |
> |
assertTrue(f.isDone()); |
479 |
> |
assertTrue(f.isCompletedAbnormally()); |
480 |
> |
assertTrue(f.getException() instanceof FJException); |
481 |
|
}}; |
482 |
|
testInvokeOnPool(mainPool(), a); |
483 |
|
} |
486 |
|
* invoke task throws exception when task cancelled |
487 |
|
*/ |
488 |
|
public void testCancelledInvoke() { |
489 |
< |
RecursiveAction a = new RecursiveAction() { |
490 |
< |
public void compute() { |
489 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
490 |
> |
public void realCompute() { |
491 |
> |
AsyncFib f = new AsyncFib(8); |
492 |
> |
assertTrue(f.cancel(true)); |
493 |
|
try { |
482 |
– |
AsyncFib f = new AsyncFib(8); |
483 |
– |
threadAssertTrue(f.cancel(true)); |
494 |
|
f.invoke(); |
495 |
|
shouldThrow(); |
496 |
|
} catch (CancellationException success) { |
497 |
+ |
assertTrue(f.isDone()); |
498 |
+ |
assertTrue(f.isCancelled()); |
499 |
+ |
assertTrue(f.isCompletedAbnormally()); |
500 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
501 |
|
} |
502 |
|
}}; |
503 |
|
testInvokeOnPool(mainPool(), a); |
507 |
|
* join of a forked task throws exception when task cancelled |
508 |
|
*/ |
509 |
|
public void testCancelledForkJoin() { |
510 |
< |
RecursiveAction a = new RecursiveAction() { |
511 |
< |
public void compute() { |
510 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
511 |
> |
public void realCompute() { |
512 |
> |
AsyncFib f = new AsyncFib(8); |
513 |
> |
assertTrue(f.cancel(true)); |
514 |
> |
assertSame(f, f.fork()); |
515 |
|
try { |
499 |
– |
AsyncFib f = new AsyncFib(8); |
500 |
– |
threadAssertTrue(f.cancel(true)); |
501 |
– |
threadAssertSame(f, f.fork()); |
516 |
|
f.join(); |
517 |
|
shouldThrow(); |
518 |
|
} catch (CancellationException success) { |
519 |
+ |
assertTrue(f.isDone()); |
520 |
+ |
assertTrue(f.isCancelled()); |
521 |
+ |
assertTrue(f.isCompletedAbnormally()); |
522 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
523 |
|
} |
524 |
|
}}; |
525 |
|
testInvokeOnPool(mainPool(), a); |
529 |
|
* get of a forked task throws exception when task cancelled |
530 |
|
*/ |
531 |
|
public void testCancelledForkGet() { |
532 |
< |
RecursiveAction a = new RecursiveAction() { |
533 |
< |
public void compute() { |
532 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
533 |
> |
public void realCompute() throws Exception { |
534 |
> |
AsyncFib f = new AsyncFib(8); |
535 |
> |
assertTrue(f.cancel(true)); |
536 |
> |
assertSame(f, f.fork()); |
537 |
|
try { |
517 |
– |
AsyncFib f = new AsyncFib(8); |
518 |
– |
threadAssertTrue(f.cancel(true)); |
519 |
– |
threadAssertSame(f, f.fork()); |
538 |
|
f.get(); |
539 |
|
shouldThrow(); |
540 |
|
} catch (CancellationException success) { |
541 |
< |
} catch (Exception ex) { |
542 |
< |
unexpectedException(ex); |
541 |
> |
assertTrue(f.isDone()); |
542 |
> |
assertTrue(f.isCancelled()); |
543 |
> |
assertTrue(f.isCompletedAbnormally()); |
544 |
> |
assertTrue(f.getException() instanceof CancellationException); |
545 |
|
} |
546 |
|
}}; |
547 |
|
testInvokeOnPool(mainPool(), a); |
550 |
|
/** |
551 |
|
* timed get of a forked task throws exception when task cancelled |
552 |
|
*/ |
553 |
< |
public void testCancelledForkTimedGet() { |
554 |
< |
RecursiveAction a = new RecursiveAction() { |
555 |
< |
public void compute() { |
556 |
< |
try { |
557 |
< |
AsyncFib f = new AsyncFib(8); |
558 |
< |
threadAssertTrue(f.cancel(true)); |
559 |
< |
threadAssertSame(f, f.fork()); |
560 |
< |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
553 |
> |
public void testCancelledForkTimedGet() throws Exception { |
554 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
555 |
> |
public void realCompute() throws Exception { |
556 |
> |
AsyncFib f = new AsyncFib(8); |
557 |
> |
assertTrue(f.cancel(true)); |
558 |
> |
assertSame(f, f.fork()); |
559 |
> |
try { |
560 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
561 |
|
shouldThrow(); |
562 |
|
} catch (CancellationException success) { |
563 |
< |
} catch (Exception ex) { |
564 |
< |
unexpectedException(ex); |
563 |
> |
assertTrue(f.isDone()); |
564 |
> |
assertTrue(f.isCancelled()); |
565 |
> |
assertTrue(f.isCompletedAbnormally()); |
566 |
> |
assertTrue(f.getException() instanceof CancellationException); |
567 |
|
} |
568 |
|
}}; |
569 |
|
testInvokeOnPool(mainPool(), a); |
573 |
|
* quietlyJoin of a forked task returns when task cancelled |
574 |
|
*/ |
575 |
|
public void testCancelledForkQuietlyJoin() { |
576 |
< |
RecursiveAction a = new RecursiveAction() { |
577 |
< |
public void compute() { |
576 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
577 |
> |
public void realCompute() { |
578 |
|
AsyncFib f = new AsyncFib(8); |
579 |
< |
threadAssertTrue(f.cancel(true)); |
580 |
< |
threadAssertSame(f, f.fork()); |
579 |
> |
assertTrue(f.cancel(true)); |
580 |
> |
assertSame(f, f.fork()); |
581 |
|
f.quietlyJoin(); |
582 |
< |
threadAssertTrue(f.isDone()); |
583 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
584 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
582 |
> |
assertTrue(f.isDone()); |
583 |
> |
assertTrue(f.isCompletedAbnormally()); |
584 |
> |
assertTrue(f.isCancelled()); |
585 |
> |
assertTrue(f.getException() instanceof CancellationException); |
586 |
|
}}; |
587 |
|
testInvokeOnPool(mainPool(), a); |
588 |
|
} |
592 |
|
*/ |
593 |
|
public void testGetPool() { |
594 |
|
final ForkJoinPool mainPool = mainPool(); |
595 |
< |
RecursiveAction a = new RecursiveAction() { |
596 |
< |
public void compute() { |
597 |
< |
threadAssertTrue(getPool() == mainPool); |
595 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
596 |
> |
public void realCompute() { |
597 |
> |
assertSame(mainPool, getPool()); |
598 |
|
}}; |
599 |
|
testInvokeOnPool(mainPool, a); |
600 |
|
} |
603 |
|
* getPool of non-FJ task returns null |
604 |
|
*/ |
605 |
|
public void testGetPool2() { |
606 |
< |
RecursiveAction a = new RecursiveAction() { |
607 |
< |
public void compute() { |
608 |
< |
threadAssertTrue(getPool() == null); |
606 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
607 |
> |
public void realCompute() { |
608 |
> |
assertNull(getPool()); |
609 |
|
}}; |
610 |
|
assertNull(a.invoke()); |
611 |
|
} |
614 |
|
* inForkJoinPool of executing task returns true |
615 |
|
*/ |
616 |
|
public void testInForkJoinPool() { |
617 |
< |
RecursiveAction a = new RecursiveAction() { |
618 |
< |
public void compute() { |
619 |
< |
threadAssertTrue(inForkJoinPool()); |
617 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
618 |
> |
public void realCompute() { |
619 |
> |
assertTrue(inForkJoinPool()); |
620 |
|
}}; |
621 |
|
testInvokeOnPool(mainPool(), a); |
622 |
|
} |
625 |
|
* inForkJoinPool of non-FJ task returns false |
626 |
|
*/ |
627 |
|
public void testInForkJoinPool2() { |
628 |
< |
RecursiveAction a = new RecursiveAction() { |
629 |
< |
public void compute() { |
630 |
< |
threadAssertTrue(!inForkJoinPool()); |
628 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
629 |
> |
public void realCompute() { |
630 |
> |
assertTrue(!inForkJoinPool()); |
631 |
|
}}; |
632 |
|
assertNull(a.invoke()); |
633 |
|
} |
636 |
|
* setRawResult(null) succeeds |
637 |
|
*/ |
638 |
|
public void testSetRawResult() { |
639 |
< |
RecursiveAction a = new RecursiveAction() { |
640 |
< |
public void compute() { |
639 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
640 |
> |
public void realCompute() { |
641 |
|
setRawResult(null); |
642 |
|
}}; |
643 |
|
assertNull(a.invoke()); |
647 |
|
* invoke task throws exception after invoking completeExceptionally |
648 |
|
*/ |
649 |
|
public void testCompleteExceptionally() { |
650 |
< |
RecursiveAction a = new RecursiveAction() { |
651 |
< |
public void compute() { |
650 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
651 |
> |
public void realCompute() { |
652 |
> |
AsyncFib f = new AsyncFib(8); |
653 |
> |
f.completeExceptionally(new FJException()); |
654 |
|
try { |
630 |
– |
AsyncFib f = new AsyncFib(8); |
631 |
– |
f.completeExceptionally(new FJException()); |
655 |
|
f.invoke(); |
656 |
|
shouldThrow(); |
657 |
< |
} catch (FJException success) { |
635 |
< |
} |
657 |
> |
} catch (FJException success) {} |
658 |
|
}}; |
659 |
|
testInvokeOnPool(mainPool(), a); |
660 |
|
} |
663 |
|
* invokeAll(t1, t2) invokes all task arguments |
664 |
|
*/ |
665 |
|
public void testInvokeAll2() { |
666 |
< |
RecursiveAction a = new RecursiveAction() { |
667 |
< |
public void compute() { |
666 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
667 |
> |
public void realCompute() { |
668 |
|
AsyncFib f = new AsyncFib(8); |
669 |
|
AsyncFib g = new AsyncFib(9); |
670 |
|
invokeAll(f, g); |
671 |
< |
threadAssertTrue(f.isDone()); |
672 |
< |
threadAssertTrue(f.number == 21); |
673 |
< |
threadAssertTrue(g.isDone()); |
674 |
< |
threadAssertTrue(g.number == 34); |
671 |
> |
assertTrue(f.isDone()); |
672 |
> |
assertEquals(21, f.number); |
673 |
> |
assertTrue(g.isDone()); |
674 |
> |
assertEquals(34, g.number); |
675 |
|
}}; |
676 |
|
testInvokeOnPool(mainPool(), a); |
677 |
|
} |
680 |
|
* invokeAll(tasks) with 1 argument invokes task |
681 |
|
*/ |
682 |
|
public void testInvokeAll1() { |
683 |
< |
RecursiveAction a = new RecursiveAction() { |
684 |
< |
public void compute() { |
683 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
684 |
> |
public void realCompute() { |
685 |
|
AsyncFib f = new AsyncFib(8); |
686 |
|
invokeAll(f); |
687 |
< |
threadAssertTrue(f.isDone()); |
688 |
< |
threadAssertTrue(f.number == 21); |
687 |
> |
assertTrue(f.isDone()); |
688 |
> |
assertEquals(21, f.number); |
689 |
|
}}; |
690 |
|
testInvokeOnPool(mainPool(), a); |
691 |
|
} |
694 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
695 |
|
*/ |
696 |
|
public void testInvokeAll3() { |
697 |
< |
RecursiveAction a = new RecursiveAction() { |
698 |
< |
public void compute() { |
697 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
698 |
> |
public void realCompute() { |
699 |
|
AsyncFib f = new AsyncFib(8); |
700 |
|
AsyncFib g = new AsyncFib(9); |
701 |
|
AsyncFib h = new AsyncFib(7); |
702 |
|
invokeAll(f, g, h); |
703 |
< |
threadAssertTrue(f.isDone()); |
704 |
< |
threadAssertTrue(f.number == 21); |
705 |
< |
threadAssertTrue(g.isDone()); |
706 |
< |
threadAssertTrue(g.number == 34); |
707 |
< |
threadAssertTrue(h.isDone()); |
708 |
< |
threadAssertTrue(h.number == 13); |
703 |
> |
assertTrue(f.isDone()); |
704 |
> |
assertEquals(21, f.number); |
705 |
> |
assertTrue(g.isDone()); |
706 |
> |
assertEquals(34, g.number); |
707 |
> |
assertTrue(h.isDone()); |
708 |
> |
assertEquals(13, h.number); |
709 |
|
}}; |
710 |
|
testInvokeOnPool(mainPool(), a); |
711 |
|
} |
714 |
|
* invokeAll(collection) invokes all tasks in the collection |
715 |
|
*/ |
716 |
|
public void testInvokeAllCollection() { |
717 |
< |
RecursiveAction a = new RecursiveAction() { |
718 |
< |
public void compute() { |
717 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
718 |
> |
public void realCompute() { |
719 |
|
AsyncFib f = new AsyncFib(8); |
720 |
|
AsyncFib g = new AsyncFib(9); |
721 |
|
AsyncFib h = new AsyncFib(7); |
724 |
|
set.add(g); |
725 |
|
set.add(h); |
726 |
|
invokeAll(set); |
727 |
< |
threadAssertTrue(f.isDone()); |
728 |
< |
threadAssertTrue(f.number == 21); |
729 |
< |
threadAssertTrue(g.isDone()); |
730 |
< |
threadAssertTrue(g.number == 34); |
731 |
< |
threadAssertTrue(h.isDone()); |
732 |
< |
threadAssertTrue(h.number == 13); |
727 |
> |
assertTrue(f.isDone()); |
728 |
> |
assertEquals(21, f.number); |
729 |
> |
assertTrue(g.isDone()); |
730 |
> |
assertEquals(34, g.number); |
731 |
> |
assertTrue(h.isDone()); |
732 |
> |
assertEquals(13, h.number); |
733 |
|
}}; |
734 |
|
testInvokeOnPool(mainPool(), a); |
735 |
|
} |
739 |
|
* invokeAll(tasks) with any null task throws NPE |
740 |
|
*/ |
741 |
|
public void testInvokeAllNPE() { |
742 |
< |
RecursiveAction a = new RecursiveAction() { |
743 |
< |
public void compute() { |
742 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
743 |
> |
public void realCompute() { |
744 |
> |
AsyncFib f = new AsyncFib(8); |
745 |
> |
AsyncFib g = new AsyncFib(9); |
746 |
> |
AsyncFib h = null; |
747 |
|
try { |
723 |
– |
AsyncFib f = new AsyncFib(8); |
724 |
– |
AsyncFib g = new AsyncFib(9); |
725 |
– |
AsyncFib h = null; |
748 |
|
invokeAll(f, g, h); |
749 |
|
shouldThrow(); |
750 |
< |
} catch (NullPointerException success) { |
729 |
< |
} |
750 |
> |
} catch (NullPointerException success) {} |
751 |
|
}}; |
752 |
|
testInvokeOnPool(mainPool(), a); |
753 |
|
} |
756 |
|
* invokeAll(t1, t2) throw exception if any task does |
757 |
|
*/ |
758 |
|
public void testAbnormalInvokeAll2() { |
759 |
< |
RecursiveAction a = new RecursiveAction() { |
760 |
< |
public void compute() { |
759 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
760 |
> |
public void realCompute() { |
761 |
> |
AsyncFib f = new AsyncFib(8); |
762 |
> |
FailingAsyncFib g = new FailingAsyncFib(9); |
763 |
|
try { |
741 |
– |
AsyncFib f = new AsyncFib(8); |
742 |
– |
FailingAsyncFib g = new FailingAsyncFib(9); |
764 |
|
invokeAll(f, g); |
765 |
|
shouldThrow(); |
766 |
< |
} catch (FJException success) { |
746 |
< |
} |
766 |
> |
} catch (FJException success) {} |
767 |
|
}}; |
768 |
|
testInvokeOnPool(mainPool(), a); |
769 |
|
} |
772 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
773 |
|
*/ |
774 |
|
public void testAbnormalInvokeAll1() { |
775 |
< |
RecursiveAction a = new RecursiveAction() { |
776 |
< |
public void compute() { |
775 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
776 |
> |
public void realCompute() { |
777 |
> |
FailingAsyncFib g = new FailingAsyncFib(9); |
778 |
|
try { |
758 |
– |
FailingAsyncFib g = new FailingAsyncFib(9); |
779 |
|
invokeAll(g); |
780 |
|
shouldThrow(); |
781 |
< |
} catch (FJException success) { |
762 |
< |
} |
781 |
> |
} catch (FJException success) {} |
782 |
|
}}; |
783 |
|
testInvokeOnPool(mainPool(), a); |
784 |
|
} |
787 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
788 |
|
*/ |
789 |
|
public void testAbnormalInvokeAll3() { |
790 |
< |
RecursiveAction a = new RecursiveAction() { |
791 |
< |
public void compute() { |
790 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
791 |
> |
public void realCompute() { |
792 |
> |
AsyncFib f = new AsyncFib(8); |
793 |
> |
FailingAsyncFib g = new FailingAsyncFib(9); |
794 |
> |
AsyncFib h = new AsyncFib(7); |
795 |
|
try { |
774 |
– |
AsyncFib f = new AsyncFib(8); |
775 |
– |
FailingAsyncFib g = new FailingAsyncFib(9); |
776 |
– |
AsyncFib h = new AsyncFib(7); |
796 |
|
invokeAll(f, g, h); |
797 |
|
shouldThrow(); |
798 |
< |
} catch (FJException success) { |
780 |
< |
} |
798 |
> |
} catch (FJException success) {} |
799 |
|
}}; |
800 |
|
testInvokeOnPool(mainPool(), a); |
801 |
|
} |
804 |
|
* invokeAll(collection) throws exception if any task does |
805 |
|
*/ |
806 |
|
public void testAbnormalInvokeAllCollection() { |
807 |
< |
RecursiveAction a = new RecursiveAction() { |
808 |
< |
public void compute() { |
807 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
808 |
> |
public void realCompute() { |
809 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
810 |
> |
AsyncFib g = new AsyncFib(9); |
811 |
> |
AsyncFib h = new AsyncFib(7); |
812 |
> |
HashSet set = new HashSet(); |
813 |
> |
set.add(f); |
814 |
> |
set.add(g); |
815 |
> |
set.add(h); |
816 |
|
try { |
792 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
793 |
– |
AsyncFib g = new AsyncFib(9); |
794 |
– |
AsyncFib h = new AsyncFib(7); |
795 |
– |
HashSet set = new HashSet(); |
796 |
– |
set.add(f); |
797 |
– |
set.add(g); |
798 |
– |
set.add(h); |
817 |
|
invokeAll(set); |
818 |
|
shouldThrow(); |
819 |
< |
} catch (FJException success) { |
802 |
< |
} |
819 |
> |
} catch (FJException success) {} |
820 |
|
}}; |
821 |
|
testInvokeOnPool(mainPool(), a); |
822 |
|
} |
826 |
|
* and suppresses execution |
827 |
|
*/ |
828 |
|
public void testTryUnfork() { |
829 |
< |
RecursiveAction a = new RecursiveAction() { |
830 |
< |
public void compute() { |
829 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
830 |
> |
public void realCompute() { |
831 |
|
AsyncFib g = new AsyncFib(9); |
832 |
< |
threadAssertSame(g, g.fork()); |
832 |
> |
assertSame(g, g.fork()); |
833 |
|
AsyncFib f = new AsyncFib(8); |
834 |
< |
threadAssertSame(f, f.fork()); |
835 |
< |
threadAssertTrue(f.tryUnfork()); |
834 |
> |
assertSame(f, f.fork()); |
835 |
> |
assertTrue(f.tryUnfork()); |
836 |
|
helpQuiesce(); |
837 |
< |
threadAssertFalse(f.isDone()); |
838 |
< |
threadAssertTrue(g.isDone()); |
837 |
> |
assertFalse(f.isDone()); |
838 |
> |
assertTrue(g.isDone()); |
839 |
|
}}; |
840 |
|
testInvokeOnPool(singletonPool(), a); |
841 |
|
} |
845 |
|
* there are more tasks than threads |
846 |
|
*/ |
847 |
|
public void testGetSurplusQueuedTaskCount() { |
848 |
< |
RecursiveAction a = new RecursiveAction() { |
849 |
< |
public void compute() { |
848 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
849 |
> |
public void realCompute() { |
850 |
|
AsyncFib h = new AsyncFib(7); |
851 |
< |
threadAssertSame(h, h.fork()); |
851 |
> |
assertSame(h, h.fork()); |
852 |
|
AsyncFib g = new AsyncFib(9); |
853 |
< |
threadAssertSame(g, g.fork()); |
853 |
> |
assertSame(g, g.fork()); |
854 |
|
AsyncFib f = new AsyncFib(8); |
855 |
< |
threadAssertSame(f, f.fork()); |
856 |
< |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
855 |
> |
assertSame(f, f.fork()); |
856 |
> |
assertTrue(getSurplusQueuedTaskCount() > 0); |
857 |
|
helpQuiesce(); |
858 |
|
}}; |
859 |
|
testInvokeOnPool(singletonPool(), a); |
863 |
|
* peekNextLocalTask returns most recent unexecuted task. |
864 |
|
*/ |
865 |
|
public void testPeekNextLocalTask() { |
866 |
< |
RecursiveAction a = new RecursiveAction() { |
867 |
< |
public void compute() { |
866 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
867 |
> |
public void realCompute() { |
868 |
|
AsyncFib g = new AsyncFib(9); |
869 |
< |
threadAssertSame(g, g.fork()); |
869 |
> |
assertSame(g, g.fork()); |
870 |
|
AsyncFib f = new AsyncFib(8); |
871 |
< |
threadAssertSame(f, f.fork()); |
872 |
< |
threadAssertTrue(peekNextLocalTask() == f); |
873 |
< |
threadAssertNull(f.join()); |
874 |
< |
threadAssertTrue(f.isDone()); |
871 |
> |
assertSame(f, f.fork()); |
872 |
> |
assertSame(f, peekNextLocalTask()); |
873 |
> |
assertNull(f.join()); |
874 |
> |
assertTrue(f.isDone()); |
875 |
|
helpQuiesce(); |
876 |
|
}}; |
877 |
|
testInvokeOnPool(singletonPool(), a); |
882 |
|
* without executing it |
883 |
|
*/ |
884 |
|
public void testPollNextLocalTask() { |
885 |
< |
RecursiveAction a = new RecursiveAction() { |
886 |
< |
public void compute() { |
885 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
886 |
> |
public void realCompute() { |
887 |
|
AsyncFib g = new AsyncFib(9); |
888 |
< |
threadAssertSame(g, g.fork()); |
888 |
> |
assertSame(g, g.fork()); |
889 |
|
AsyncFib f = new AsyncFib(8); |
890 |
< |
threadAssertSame(f, f.fork()); |
891 |
< |
threadAssertTrue(pollNextLocalTask() == f); |
890 |
> |
assertSame(f, f.fork()); |
891 |
> |
assertSame(f, pollNextLocalTask()); |
892 |
|
helpQuiesce(); |
893 |
< |
threadAssertFalse(f.isDone()); |
893 |
> |
assertFalse(f.isDone()); |
894 |
|
}}; |
895 |
|
testInvokeOnPool(singletonPool(), a); |
896 |
|
} |
900 |
|
* without executing it |
901 |
|
*/ |
902 |
|
public void testPollTask() { |
903 |
< |
RecursiveAction a = new RecursiveAction() { |
904 |
< |
public void compute() { |
903 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
904 |
> |
public void realCompute() { |
905 |
|
AsyncFib g = new AsyncFib(9); |
906 |
< |
threadAssertSame(g, g.fork()); |
906 |
> |
assertSame(g, g.fork()); |
907 |
|
AsyncFib f = new AsyncFib(8); |
908 |
< |
threadAssertSame(f, f.fork()); |
909 |
< |
threadAssertTrue(pollTask() == f); |
908 |
> |
assertSame(f, f.fork()); |
909 |
> |
assertSame(f, pollTask()); |
910 |
|
helpQuiesce(); |
911 |
< |
threadAssertFalse(f.isDone()); |
912 |
< |
threadAssertTrue(g.isDone()); |
911 |
> |
assertFalse(f.isDone()); |
912 |
> |
assertTrue(g.isDone()); |
913 |
|
}}; |
914 |
|
testInvokeOnPool(singletonPool(), a); |
915 |
|
} |
918 |
|
* peekNextLocalTask returns least recent unexecuted task in async mode |
919 |
|
*/ |
920 |
|
public void testPeekNextLocalTaskAsync() { |
921 |
< |
RecursiveAction a = new RecursiveAction() { |
922 |
< |
public void compute() { |
921 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
922 |
> |
public void realCompute() { |
923 |
|
AsyncFib g = new AsyncFib(9); |
924 |
< |
threadAssertSame(g, g.fork()); |
924 |
> |
assertSame(g, g.fork()); |
925 |
|
AsyncFib f = new AsyncFib(8); |
926 |
< |
threadAssertSame(f, f.fork()); |
927 |
< |
threadAssertTrue(peekNextLocalTask() == g); |
928 |
< |
threadAssertNull(f.join()); |
926 |
> |
assertSame(f, f.fork()); |
927 |
> |
assertSame(g, peekNextLocalTask()); |
928 |
> |
assertNull(f.join()); |
929 |
|
helpQuiesce(); |
930 |
< |
threadAssertTrue(f.isDone()); |
930 |
> |
assertTrue(f.isDone()); |
931 |
|
}}; |
932 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
933 |
|
} |
937 |
|
* without executing it, in async mode |
938 |
|
*/ |
939 |
|
public void testPollNextLocalTaskAsync() { |
940 |
< |
RecursiveAction a = new RecursiveAction() { |
941 |
< |
public void compute() { |
940 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
941 |
> |
public void realCompute() { |
942 |
|
AsyncFib g = new AsyncFib(9); |
943 |
< |
threadAssertSame(g, g.fork()); |
943 |
> |
assertSame(g, g.fork()); |
944 |
|
AsyncFib f = new AsyncFib(8); |
945 |
< |
threadAssertSame(f, f.fork()); |
946 |
< |
threadAssertTrue(pollNextLocalTask() == g); |
945 |
> |
assertSame(f, f.fork()); |
946 |
> |
assertSame(g, pollNextLocalTask()); |
947 |
|
helpQuiesce(); |
948 |
< |
threadAssertTrue(f.isDone()); |
949 |
< |
threadAssertFalse(g.isDone()); |
948 |
> |
assertTrue(f.isDone()); |
949 |
> |
assertFalse(g.isDone()); |
950 |
|
}}; |
951 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
952 |
|
} |
956 |
|
* without executing it, in async mode |
957 |
|
*/ |
958 |
|
public void testPollTaskAsync() { |
959 |
< |
RecursiveAction a = new RecursiveAction() { |
960 |
< |
public void compute() { |
959 |
> |
RecursiveAction a = new CheckedRecursiveAction() { |
960 |
> |
public void realCompute() { |
961 |
|
AsyncFib g = new AsyncFib(9); |
962 |
< |
threadAssertSame(g, g.fork()); |
962 |
> |
assertSame(g, g.fork()); |
963 |
|
AsyncFib f = new AsyncFib(8); |
964 |
< |
threadAssertSame(f, f.fork()); |
965 |
< |
threadAssertTrue(pollTask() == g); |
964 |
> |
assertSame(f, f.fork()); |
965 |
> |
assertSame(g, pollTask()); |
966 |
|
helpQuiesce(); |
967 |
< |
threadAssertTrue(f.isDone()); |
968 |
< |
threadAssertFalse(g.isDone()); |
967 |
> |
assertTrue(f.isDone()); |
968 |
> |
assertFalse(g.isDone()); |
969 |
|
}}; |
970 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
971 |
|
} |
972 |
+ |
|
973 |
+ |
// versions for singleton pools |
974 |
+ |
|
975 |
+ |
/** |
976 |
+ |
* invoke returns when task completes normally. |
977 |
+ |
* isCompletedAbnormally and isCancelled return false for normally |
978 |
+ |
* completed tasks. getRawResult of a RecursiveAction returns null; |
979 |
+ |
*/ |
980 |
+ |
public void testInvokeSingleton() { |
981 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
982 |
+ |
public void realCompute() { |
983 |
+ |
AsyncFib f = new AsyncFib(8); |
984 |
+ |
assertNull(f.invoke()); |
985 |
+ |
assertEquals(21, f.number); |
986 |
+ |
assertTrue(f.isDone()); |
987 |
+ |
assertFalse(f.isCancelled()); |
988 |
+ |
assertFalse(f.isCompletedAbnormally()); |
989 |
+ |
assertNull(f.getRawResult()); |
990 |
+ |
}}; |
991 |
+ |
testInvokeOnPool(singletonPool(), a); |
992 |
+ |
} |
993 |
+ |
|
994 |
+ |
/** |
995 |
+ |
* quietlyInvoke task returns when task completes normally. |
996 |
+ |
* isCompletedAbnormally and isCancelled return false for normally |
997 |
+ |
* completed tasks |
998 |
+ |
*/ |
999 |
+ |
public void testQuietlyInvokeSingleton() { |
1000 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1001 |
+ |
public void realCompute() { |
1002 |
+ |
AsyncFib f = new AsyncFib(8); |
1003 |
+ |
f.quietlyInvoke(); |
1004 |
+ |
assertEquals(21, f.number); |
1005 |
+ |
assertTrue(f.isDone()); |
1006 |
+ |
assertFalse(f.isCancelled()); |
1007 |
+ |
assertFalse(f.isCompletedAbnormally()); |
1008 |
+ |
assertNull(f.getRawResult()); |
1009 |
+ |
}}; |
1010 |
+ |
testInvokeOnPool(singletonPool(), a); |
1011 |
+ |
} |
1012 |
+ |
|
1013 |
+ |
/** |
1014 |
+ |
* join of a forked task returns when task completes |
1015 |
+ |
*/ |
1016 |
+ |
public void testForkJoinSingleton() { |
1017 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1018 |
+ |
public void realCompute() { |
1019 |
+ |
AsyncFib f = new AsyncFib(8); |
1020 |
+ |
assertSame(f, f.fork()); |
1021 |
+ |
assertNull(f.join()); |
1022 |
+ |
assertEquals(21, f.number); |
1023 |
+ |
assertTrue(f.isDone()); |
1024 |
+ |
assertNull(f.getRawResult()); |
1025 |
+ |
}}; |
1026 |
+ |
testInvokeOnPool(singletonPool(), a); |
1027 |
+ |
} |
1028 |
+ |
|
1029 |
+ |
/** |
1030 |
+ |
* get of a forked task returns when task completes |
1031 |
+ |
*/ |
1032 |
+ |
public void testForkGetSingleton() { |
1033 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1034 |
+ |
public void realCompute() throws Exception { |
1035 |
+ |
AsyncFib f = new AsyncFib(8); |
1036 |
+ |
assertSame(f, f.fork()); |
1037 |
+ |
assertNull(f.get()); |
1038 |
+ |
assertEquals(21, f.number); |
1039 |
+ |
assertTrue(f.isDone()); |
1040 |
+ |
}}; |
1041 |
+ |
testInvokeOnPool(singletonPool(), a); |
1042 |
+ |
} |
1043 |
+ |
|
1044 |
+ |
/** |
1045 |
+ |
* timed get of a forked task returns when task completes |
1046 |
+ |
*/ |
1047 |
+ |
public void testForkTimedGetSingleton() { |
1048 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1049 |
+ |
public void realCompute() throws Exception { |
1050 |
+ |
AsyncFib f = new AsyncFib(8); |
1051 |
+ |
assertSame(f, f.fork()); |
1052 |
+ |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1053 |
+ |
assertEquals(21, f.number); |
1054 |
+ |
assertTrue(f.isDone()); |
1055 |
+ |
}}; |
1056 |
+ |
testInvokeOnPool(singletonPool(), a); |
1057 |
+ |
} |
1058 |
+ |
|
1059 |
+ |
/** |
1060 |
+ |
* timed get with null time unit throws NPE |
1061 |
+ |
*/ |
1062 |
+ |
public void testForkTimedGetNPESingleton() { |
1063 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1064 |
+ |
public void realCompute() throws Exception { |
1065 |
+ |
AsyncFib f = new AsyncFib(8); |
1066 |
+ |
assertSame(f, f.fork()); |
1067 |
+ |
try { |
1068 |
+ |
f.get(5L, null); |
1069 |
+ |
shouldThrow(); |
1070 |
+ |
} catch (NullPointerException success) {} |
1071 |
+ |
}}; |
1072 |
+ |
testInvokeOnPool(singletonPool(), a); |
1073 |
+ |
} |
1074 |
+ |
|
1075 |
+ |
/** |
1076 |
+ |
* quietlyJoin of a forked task returns when task completes |
1077 |
+ |
*/ |
1078 |
+ |
public void testForkQuietlyJoinSingleton() { |
1079 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1080 |
+ |
public void realCompute() { |
1081 |
+ |
AsyncFib f = new AsyncFib(8); |
1082 |
+ |
assertSame(f, f.fork()); |
1083 |
+ |
f.quietlyJoin(); |
1084 |
+ |
assertEquals(21, f.number); |
1085 |
+ |
assertTrue(f.isDone()); |
1086 |
+ |
}}; |
1087 |
+ |
testInvokeOnPool(singletonPool(), a); |
1088 |
+ |
} |
1089 |
+ |
|
1090 |
+ |
|
1091 |
+ |
/** |
1092 |
+ |
* helpQuiesce returns when tasks are complete. |
1093 |
+ |
* getQueuedTaskCount returns 0 when quiescent |
1094 |
+ |
*/ |
1095 |
+ |
public void testForkHelpQuiesceSingleton() { |
1096 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1097 |
+ |
public void realCompute() { |
1098 |
+ |
AsyncFib f = new AsyncFib(8); |
1099 |
+ |
assertSame(f, f.fork()); |
1100 |
+ |
f.helpQuiesce(); |
1101 |
+ |
assertEquals(21, f.number); |
1102 |
+ |
assertTrue(f.isDone()); |
1103 |
+ |
assertEquals(0, getQueuedTaskCount()); |
1104 |
+ |
}}; |
1105 |
+ |
testInvokeOnPool(singletonPool(), a); |
1106 |
+ |
} |
1107 |
+ |
|
1108 |
+ |
|
1109 |
+ |
/** |
1110 |
+ |
* invoke task throws exception when task completes abnormally |
1111 |
+ |
*/ |
1112 |
+ |
public void testAbnormalInvokeSingleton() { |
1113 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1114 |
+ |
public void realCompute() { |
1115 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1116 |
+ |
try { |
1117 |
+ |
f.invoke(); |
1118 |
+ |
shouldThrow(); |
1119 |
+ |
} catch (FJException success) {} |
1120 |
+ |
}}; |
1121 |
+ |
testInvokeOnPool(singletonPool(), a); |
1122 |
+ |
} |
1123 |
+ |
|
1124 |
+ |
/** |
1125 |
+ |
* quietlyInvoke task returns when task completes abnormally |
1126 |
+ |
*/ |
1127 |
+ |
public void testAbnormalQuietlyInvokeSingleton() { |
1128 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1129 |
+ |
public void realCompute() { |
1130 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1131 |
+ |
f.quietlyInvoke(); |
1132 |
+ |
assertTrue(f.isDone()); |
1133 |
+ |
}}; |
1134 |
+ |
testInvokeOnPool(singletonPool(), a); |
1135 |
+ |
} |
1136 |
+ |
|
1137 |
+ |
/** |
1138 |
+ |
* join of a forked task throws exception when task completes abnormally |
1139 |
+ |
*/ |
1140 |
+ |
public void testAbnormalForkJoinSingleton() { |
1141 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1142 |
+ |
public void realCompute() { |
1143 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1144 |
+ |
assertSame(f, f.fork()); |
1145 |
+ |
try { |
1146 |
+ |
f.join(); |
1147 |
+ |
shouldThrow(); |
1148 |
+ |
} catch (FJException success) {} |
1149 |
+ |
}}; |
1150 |
+ |
testInvokeOnPool(singletonPool(), a); |
1151 |
+ |
} |
1152 |
+ |
|
1153 |
+ |
/** |
1154 |
+ |
* get of a forked task throws exception when task completes abnormally |
1155 |
+ |
*/ |
1156 |
+ |
public void testAbnormalForkGetSingleton() { |
1157 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1158 |
+ |
public void realCompute() throws Exception { |
1159 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1160 |
+ |
assertSame(f, f.fork()); |
1161 |
+ |
try { |
1162 |
+ |
f.get(); |
1163 |
+ |
shouldThrow(); |
1164 |
+ |
} catch (ExecutionException success) { |
1165 |
+ |
Throwable cause = success.getCause(); |
1166 |
+ |
assertTrue(cause instanceof FJException); |
1167 |
+ |
assertTrue(f.isDone()); |
1168 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1169 |
+ |
assertSame(cause.getClass(), f.getException().getClass()); |
1170 |
+ |
} |
1171 |
+ |
}}; |
1172 |
+ |
testInvokeOnPool(singletonPool(), a); |
1173 |
+ |
} |
1174 |
+ |
|
1175 |
+ |
/** |
1176 |
+ |
* timed get of a forked task throws exception when task completes abnormally |
1177 |
+ |
*/ |
1178 |
+ |
public void testAbnormalForkTimedGetSingleton() { |
1179 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1180 |
+ |
public void realCompute() throws Exception { |
1181 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1182 |
+ |
assertSame(f, f.fork()); |
1183 |
+ |
try { |
1184 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
1185 |
+ |
shouldThrow(); |
1186 |
+ |
} catch (ExecutionException success) { |
1187 |
+ |
Throwable cause = success.getCause(); |
1188 |
+ |
assertTrue(cause instanceof FJException); |
1189 |
+ |
assertTrue(f.isDone()); |
1190 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1191 |
+ |
assertSame(cause.getClass(), f.getException().getClass()); |
1192 |
+ |
} |
1193 |
+ |
}}; |
1194 |
+ |
testInvokeOnPool(singletonPool(), a); |
1195 |
+ |
} |
1196 |
+ |
|
1197 |
+ |
/** |
1198 |
+ |
* quietlyJoin of a forked task returns when task completes abnormally |
1199 |
+ |
*/ |
1200 |
+ |
public void testAbnormalForkQuietlyJoinSingleton() { |
1201 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1202 |
+ |
public void realCompute() { |
1203 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1204 |
+ |
assertSame(f, f.fork()); |
1205 |
+ |
f.quietlyJoin(); |
1206 |
+ |
assertTrue(f.isDone()); |
1207 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1208 |
+ |
assertTrue(f.getException() instanceof FJException); |
1209 |
+ |
}}; |
1210 |
+ |
testInvokeOnPool(singletonPool(), a); |
1211 |
+ |
} |
1212 |
+ |
|
1213 |
+ |
/** |
1214 |
+ |
* invoke task throws exception when task cancelled |
1215 |
+ |
*/ |
1216 |
+ |
public void testCancelledInvokeSingleton() { |
1217 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1218 |
+ |
public void realCompute() { |
1219 |
+ |
AsyncFib f = new AsyncFib(8); |
1220 |
+ |
assertTrue(f.cancel(true)); |
1221 |
+ |
try { |
1222 |
+ |
f.invoke(); |
1223 |
+ |
shouldThrow(); |
1224 |
+ |
} catch (CancellationException success) { |
1225 |
+ |
assertTrue(f.isDone()); |
1226 |
+ |
assertTrue(f.isCancelled()); |
1227 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1228 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
1229 |
+ |
} |
1230 |
+ |
}}; |
1231 |
+ |
testInvokeOnPool(singletonPool(), a); |
1232 |
+ |
} |
1233 |
+ |
|
1234 |
+ |
/** |
1235 |
+ |
* join of a forked task throws exception when task cancelled |
1236 |
+ |
*/ |
1237 |
+ |
public void testCancelledForkJoinSingleton() { |
1238 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1239 |
+ |
public void realCompute() { |
1240 |
+ |
AsyncFib f = new AsyncFib(8); |
1241 |
+ |
assertTrue(f.cancel(true)); |
1242 |
+ |
assertSame(f, f.fork()); |
1243 |
+ |
try { |
1244 |
+ |
f.join(); |
1245 |
+ |
shouldThrow(); |
1246 |
+ |
} catch (CancellationException success) { |
1247 |
+ |
assertTrue(f.isDone()); |
1248 |
+ |
assertTrue(f.isCancelled()); |
1249 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1250 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
1251 |
+ |
} |
1252 |
+ |
}}; |
1253 |
+ |
testInvokeOnPool(singletonPool(), a); |
1254 |
+ |
} |
1255 |
+ |
|
1256 |
+ |
/** |
1257 |
+ |
* get of a forked task throws exception when task cancelled |
1258 |
+ |
*/ |
1259 |
+ |
public void testCancelledForkGetSingleton() { |
1260 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1261 |
+ |
public void realCompute() throws Exception { |
1262 |
+ |
AsyncFib f = new AsyncFib(8); |
1263 |
+ |
assertTrue(f.cancel(true)); |
1264 |
+ |
assertSame(f, f.fork()); |
1265 |
+ |
try { |
1266 |
+ |
f.get(); |
1267 |
+ |
shouldThrow(); |
1268 |
+ |
} catch (CancellationException success) { |
1269 |
+ |
assertTrue(f.isDone()); |
1270 |
+ |
assertTrue(f.isCancelled()); |
1271 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1272 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
1273 |
+ |
} |
1274 |
+ |
}}; |
1275 |
+ |
testInvokeOnPool(singletonPool(), a); |
1276 |
+ |
} |
1277 |
+ |
|
1278 |
+ |
/** |
1279 |
+ |
* timed get of a forked task throws exception when task cancelled |
1280 |
+ |
*/ |
1281 |
+ |
public void testCancelledForkTimedGetSingleton() throws Exception { |
1282 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1283 |
+ |
public void realCompute() throws Exception { |
1284 |
+ |
AsyncFib f = new AsyncFib(8); |
1285 |
+ |
assertTrue(f.cancel(true)); |
1286 |
+ |
assertSame(f, f.fork()); |
1287 |
+ |
try { |
1288 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
1289 |
+ |
shouldThrow(); |
1290 |
+ |
} catch (CancellationException success) { |
1291 |
+ |
assertTrue(f.isDone()); |
1292 |
+ |
assertTrue(f.isCancelled()); |
1293 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1294 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
1295 |
+ |
} |
1296 |
+ |
}}; |
1297 |
+ |
testInvokeOnPool(singletonPool(), a); |
1298 |
+ |
} |
1299 |
+ |
|
1300 |
+ |
/** |
1301 |
+ |
* quietlyJoin of a forked task returns when task cancelled |
1302 |
+ |
*/ |
1303 |
+ |
public void testCancelledForkQuietlyJoinSingleton() { |
1304 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1305 |
+ |
public void realCompute() { |
1306 |
+ |
AsyncFib f = new AsyncFib(8); |
1307 |
+ |
assertTrue(f.cancel(true)); |
1308 |
+ |
assertSame(f, f.fork()); |
1309 |
+ |
f.quietlyJoin(); |
1310 |
+ |
assertTrue(f.isDone()); |
1311 |
+ |
assertTrue(f.isCompletedAbnormally()); |
1312 |
+ |
assertTrue(f.isCancelled()); |
1313 |
+ |
assertTrue(f.getException() instanceof CancellationException); |
1314 |
+ |
}}; |
1315 |
+ |
testInvokeOnPool(singletonPool(), a); |
1316 |
+ |
} |
1317 |
+ |
|
1318 |
+ |
/** |
1319 |
+ |
* invoke task throws exception after invoking completeExceptionally |
1320 |
+ |
*/ |
1321 |
+ |
public void testCompleteExceptionallySingleton() { |
1322 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1323 |
+ |
public void realCompute() { |
1324 |
+ |
AsyncFib f = new AsyncFib(8); |
1325 |
+ |
f.completeExceptionally(new FJException()); |
1326 |
+ |
try { |
1327 |
+ |
f.invoke(); |
1328 |
+ |
shouldThrow(); |
1329 |
+ |
} catch (FJException success) {} |
1330 |
+ |
}}; |
1331 |
+ |
testInvokeOnPool(singletonPool(), a); |
1332 |
+ |
} |
1333 |
+ |
|
1334 |
+ |
/** |
1335 |
+ |
* invokeAll(t1, t2) invokes all task arguments |
1336 |
+ |
*/ |
1337 |
+ |
public void testInvokeAll2Singleton() { |
1338 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1339 |
+ |
public void realCompute() { |
1340 |
+ |
AsyncFib f = new AsyncFib(8); |
1341 |
+ |
AsyncFib g = new AsyncFib(9); |
1342 |
+ |
invokeAll(f, g); |
1343 |
+ |
assertTrue(f.isDone()); |
1344 |
+ |
assertEquals(21, f.number); |
1345 |
+ |
assertTrue(g.isDone()); |
1346 |
+ |
assertEquals(34, g.number); |
1347 |
+ |
}}; |
1348 |
+ |
testInvokeOnPool(singletonPool(), a); |
1349 |
+ |
} |
1350 |
+ |
|
1351 |
+ |
/** |
1352 |
+ |
* invokeAll(tasks) with 1 argument invokes task |
1353 |
+ |
*/ |
1354 |
+ |
public void testInvokeAll1Singleton() { |
1355 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1356 |
+ |
public void realCompute() { |
1357 |
+ |
AsyncFib f = new AsyncFib(8); |
1358 |
+ |
invokeAll(f); |
1359 |
+ |
assertTrue(f.isDone()); |
1360 |
+ |
assertEquals(21, f.number); |
1361 |
+ |
}}; |
1362 |
+ |
testInvokeOnPool(singletonPool(), a); |
1363 |
+ |
} |
1364 |
+ |
|
1365 |
+ |
/** |
1366 |
+ |
* invokeAll(tasks) with > 2 argument invokes tasks |
1367 |
+ |
*/ |
1368 |
+ |
public void testInvokeAll3Singleton() { |
1369 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1370 |
+ |
public void realCompute() { |
1371 |
+ |
AsyncFib f = new AsyncFib(8); |
1372 |
+ |
AsyncFib g = new AsyncFib(9); |
1373 |
+ |
AsyncFib h = new AsyncFib(7); |
1374 |
+ |
invokeAll(f, g, h); |
1375 |
+ |
assertTrue(f.isDone()); |
1376 |
+ |
assertEquals(21, f.number); |
1377 |
+ |
assertTrue(g.isDone()); |
1378 |
+ |
assertEquals(34, g.number); |
1379 |
+ |
assertTrue(h.isDone()); |
1380 |
+ |
assertEquals(13, h.number); |
1381 |
+ |
}}; |
1382 |
+ |
testInvokeOnPool(singletonPool(), a); |
1383 |
+ |
} |
1384 |
+ |
|
1385 |
+ |
/** |
1386 |
+ |
* invokeAll(collection) invokes all tasks in the collection |
1387 |
+ |
*/ |
1388 |
+ |
public void testInvokeAllCollectionSingleton() { |
1389 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1390 |
+ |
public void realCompute() { |
1391 |
+ |
AsyncFib f = new AsyncFib(8); |
1392 |
+ |
AsyncFib g = new AsyncFib(9); |
1393 |
+ |
AsyncFib h = new AsyncFib(7); |
1394 |
+ |
HashSet set = new HashSet(); |
1395 |
+ |
set.add(f); |
1396 |
+ |
set.add(g); |
1397 |
+ |
set.add(h); |
1398 |
+ |
invokeAll(set); |
1399 |
+ |
assertTrue(f.isDone()); |
1400 |
+ |
assertEquals(21, f.number); |
1401 |
+ |
assertTrue(g.isDone()); |
1402 |
+ |
assertEquals(34, g.number); |
1403 |
+ |
assertTrue(h.isDone()); |
1404 |
+ |
assertEquals(13, h.number); |
1405 |
+ |
}}; |
1406 |
+ |
testInvokeOnPool(singletonPool(), a); |
1407 |
+ |
} |
1408 |
+ |
|
1409 |
+ |
|
1410 |
+ |
/** |
1411 |
+ |
* invokeAll(tasks) with any null task throws NPE |
1412 |
+ |
*/ |
1413 |
+ |
public void testInvokeAllNPESingleton() { |
1414 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1415 |
+ |
public void realCompute() { |
1416 |
+ |
AsyncFib f = new AsyncFib(8); |
1417 |
+ |
AsyncFib g = new AsyncFib(9); |
1418 |
+ |
AsyncFib h = null; |
1419 |
+ |
try { |
1420 |
+ |
invokeAll(f, g, h); |
1421 |
+ |
shouldThrow(); |
1422 |
+ |
} catch (NullPointerException success) {} |
1423 |
+ |
}}; |
1424 |
+ |
testInvokeOnPool(singletonPool(), a); |
1425 |
+ |
} |
1426 |
+ |
|
1427 |
+ |
/** |
1428 |
+ |
* invokeAll(t1, t2) throw exception if any task does |
1429 |
+ |
*/ |
1430 |
+ |
public void testAbnormalInvokeAll2Singleton() { |
1431 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1432 |
+ |
public void realCompute() { |
1433 |
+ |
AsyncFib f = new AsyncFib(8); |
1434 |
+ |
FailingAsyncFib g = new FailingAsyncFib(9); |
1435 |
+ |
try { |
1436 |
+ |
invokeAll(f, g); |
1437 |
+ |
shouldThrow(); |
1438 |
+ |
} catch (FJException success) {} |
1439 |
+ |
}}; |
1440 |
+ |
testInvokeOnPool(singletonPool(), a); |
1441 |
+ |
} |
1442 |
+ |
|
1443 |
+ |
/** |
1444 |
+ |
* invokeAll(tasks) with 1 argument throws exception if task does |
1445 |
+ |
*/ |
1446 |
+ |
public void testAbnormalInvokeAll1Singleton() { |
1447 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1448 |
+ |
public void realCompute() { |
1449 |
+ |
FailingAsyncFib g = new FailingAsyncFib(9); |
1450 |
+ |
try { |
1451 |
+ |
invokeAll(g); |
1452 |
+ |
shouldThrow(); |
1453 |
+ |
} catch (FJException success) {} |
1454 |
+ |
}}; |
1455 |
+ |
testInvokeOnPool(singletonPool(), a); |
1456 |
+ |
} |
1457 |
+ |
|
1458 |
+ |
/** |
1459 |
+ |
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1460 |
+ |
*/ |
1461 |
+ |
public void testAbnormalInvokeAll3Singleton() { |
1462 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1463 |
+ |
public void realCompute() { |
1464 |
+ |
AsyncFib f = new AsyncFib(8); |
1465 |
+ |
FailingAsyncFib g = new FailingAsyncFib(9); |
1466 |
+ |
AsyncFib h = new AsyncFib(7); |
1467 |
+ |
try { |
1468 |
+ |
invokeAll(f, g, h); |
1469 |
+ |
shouldThrow(); |
1470 |
+ |
} catch (FJException success) {} |
1471 |
+ |
}}; |
1472 |
+ |
testInvokeOnPool(singletonPool(), a); |
1473 |
+ |
} |
1474 |
+ |
|
1475 |
+ |
/** |
1476 |
+ |
* invokeAll(collection) throws exception if any task does |
1477 |
+ |
*/ |
1478 |
+ |
public void testAbnormalInvokeAllCollectionSingleton() { |
1479 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1480 |
+ |
public void realCompute() { |
1481 |
+ |
FailingAsyncFib f = new FailingAsyncFib(8); |
1482 |
+ |
AsyncFib g = new AsyncFib(9); |
1483 |
+ |
AsyncFib h = new AsyncFib(7); |
1484 |
+ |
HashSet set = new HashSet(); |
1485 |
+ |
set.add(f); |
1486 |
+ |
set.add(g); |
1487 |
+ |
set.add(h); |
1488 |
+ |
try { |
1489 |
+ |
invokeAll(set); |
1490 |
+ |
shouldThrow(); |
1491 |
+ |
} catch (FJException success) {} |
1492 |
+ |
}}; |
1493 |
+ |
testInvokeOnPool(singletonPool(), a); |
1494 |
+ |
} |
1495 |
+ |
|
1496 |
|
} |