7 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
9 |
|
|
10 |
< |
import java.util.HashSet; |
10 |
> |
import java.util.Arrays; |
11 |
|
import java.util.concurrent.ExecutionException; |
12 |
|
import java.util.concurrent.ForkJoinPool; |
13 |
|
import java.util.concurrent.ForkJoinTask; |
59 |
|
null, true); |
60 |
|
} |
61 |
|
|
62 |
+ |
// Compute fib naively and efficiently |
63 |
+ |
final int[] fib; |
64 |
+ |
{ |
65 |
+ |
int[] fib = new int[10]; |
66 |
+ |
fib[0] = 0; |
67 |
+ |
fib[1] = 1; |
68 |
+ |
for (int i = 2; i < fib.length; i++) |
69 |
+ |
fib[i] = fib[i - 1] + fib[i - 2]; |
70 |
+ |
this.fib = fib; |
71 |
+ |
} |
72 |
+ |
|
73 |
|
private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { |
74 |
|
try { |
75 |
|
assertFalse(a.isDone()); |
290 |
|
|
291 |
|
} |
292 |
|
|
293 |
< |
static final class AsyncFib extends BinaryAsyncAction { |
293 |
> |
final class AsyncFib extends BinaryAsyncAction { |
294 |
|
int number; |
295 |
< |
public AsyncFib(int n) { |
296 |
< |
this.number = n; |
295 |
> |
int expectedResult; |
296 |
> |
public AsyncFib(int number) { |
297 |
> |
this.number = number; |
298 |
> |
this.expectedResult = fib[number]; |
299 |
|
} |
300 |
|
|
301 |
|
public final boolean exec() { |
324 |
|
number = ((AsyncFib)x).number + ((AsyncFib)y).number; |
325 |
|
super.onComplete(x, y); |
326 |
|
} |
327 |
+ |
|
328 |
+ |
public void checkCompletedNormally() { |
329 |
+ |
assertEquals(expectedResult, number); |
330 |
+ |
ForkJoinTask8Test.this.checkCompletedNormally(this); |
331 |
+ |
} |
332 |
|
} |
333 |
|
|
334 |
|
static final class FailingAsyncFib extends BinaryAsyncAction { |
365 |
|
* completed tasks; getRawResult returns null. |
366 |
|
*/ |
367 |
|
public void testInvoke() { |
368 |
+ |
testInvoke(mainPool()); |
369 |
+ |
} |
370 |
+ |
public void testInvoke_Singleton() { |
371 |
+ |
testInvoke(singletonPool()); |
372 |
+ |
} |
373 |
+ |
public void testInvoke(ForkJoinPool pool) { |
374 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
375 |
|
protected void realCompute() { |
376 |
|
AsyncFib f = new AsyncFib(8); |
377 |
|
assertNull(f.invoke()); |
378 |
< |
assertEquals(21, f.number); |
355 |
< |
checkCompletedNormally(f); |
378 |
> |
f.checkCompletedNormally(); |
379 |
|
}}; |
380 |
< |
testInvokeOnPool(mainPool(), a); |
380 |
> |
testInvokeOnPool(pool, a); |
381 |
|
} |
382 |
|
|
383 |
|
/** |
386 |
|
* completed tasks |
387 |
|
*/ |
388 |
|
public void testQuietlyInvoke() { |
389 |
+ |
testQuietlyInvoke(mainPool()); |
390 |
+ |
} |
391 |
+ |
public void testQuietlyInvoke_Singleton() { |
392 |
+ |
testQuietlyInvoke(singletonPool()); |
393 |
+ |
} |
394 |
+ |
public void testQuietlyInvoke(ForkJoinPool pool) { |
395 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
396 |
|
protected void realCompute() { |
397 |
|
AsyncFib f = new AsyncFib(8); |
398 |
|
f.quietlyInvoke(); |
399 |
< |
assertEquals(21, f.number); |
371 |
< |
checkCompletedNormally(f); |
399 |
> |
f.checkCompletedNormally(); |
400 |
|
}}; |
401 |
< |
testInvokeOnPool(mainPool(), a); |
401 |
> |
testInvokeOnPool(pool, a); |
402 |
|
} |
403 |
|
|
404 |
|
/** |
405 |
|
* join of a forked task returns when task completes |
406 |
|
*/ |
407 |
|
public void testForkJoin() { |
408 |
+ |
testForkJoin(mainPool()); |
409 |
+ |
} |
410 |
+ |
public void testForkJoin_Singleton() { |
411 |
+ |
testForkJoin(singletonPool()); |
412 |
+ |
} |
413 |
+ |
public void testForkJoin(ForkJoinPool pool) { |
414 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
415 |
|
protected void realCompute() { |
416 |
|
AsyncFib f = new AsyncFib(8); |
417 |
|
assertSame(f, f.fork()); |
418 |
|
assertNull(f.join()); |
419 |
< |
assertEquals(21, f.number); |
386 |
< |
checkCompletedNormally(f); |
419 |
> |
f.checkCompletedNormally(); |
420 |
|
}}; |
421 |
< |
testInvokeOnPool(mainPool(), a); |
421 |
> |
testInvokeOnPool(pool, a); |
422 |
|
} |
423 |
|
|
424 |
|
/** |
425 |
|
* get of a forked task returns when task completes |
426 |
|
*/ |
427 |
|
public void testForkGet() { |
428 |
+ |
testForkGet(mainPool()); |
429 |
+ |
} |
430 |
+ |
public void testForkGet_Singleton() { |
431 |
+ |
testForkGet(singletonPool()); |
432 |
+ |
} |
433 |
+ |
public void testForkGet(ForkJoinPool pool) { |
434 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
435 |
|
protected void realCompute() throws Exception { |
436 |
|
AsyncFib f = new AsyncFib(8); |
437 |
|
assertSame(f, f.fork()); |
438 |
|
assertNull(f.get()); |
439 |
< |
assertEquals(21, f.number); |
401 |
< |
checkCompletedNormally(f); |
439 |
> |
f.checkCompletedNormally(); |
440 |
|
}}; |
441 |
< |
testInvokeOnPool(mainPool(), a); |
441 |
> |
testInvokeOnPool(pool, a); |
442 |
|
} |
443 |
|
|
444 |
|
/** |
445 |
|
* timed get of a forked task returns when task completes |
446 |
|
*/ |
447 |
|
public void testForkTimedGet() { |
448 |
+ |
testForkTimedGet(mainPool()); |
449 |
+ |
} |
450 |
+ |
public void testForkTimedGet_Singleton() { |
451 |
+ |
testForkTimedGet(singletonPool()); |
452 |
+ |
} |
453 |
+ |
public void testForkTimedGet(ForkJoinPool pool) { |
454 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
455 |
|
protected void realCompute() throws Exception { |
456 |
|
AsyncFib f = new AsyncFib(8); |
457 |
|
assertSame(f, f.fork()); |
458 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
459 |
< |
assertEquals(21, f.number); |
416 |
< |
checkCompletedNormally(f); |
459 |
> |
f.checkCompletedNormally(); |
460 |
|
}}; |
461 |
< |
testInvokeOnPool(mainPool(), a); |
461 |
> |
testInvokeOnPool(pool, a); |
462 |
|
} |
463 |
|
|
464 |
|
/** |
465 |
< |
* timed get with null time unit throws NPE |
465 |
> |
* timed get with null time unit throws NullPointerException |
466 |
|
*/ |
467 |
< |
public void testForkTimedGetNPE() { |
467 |
> |
public void testForkTimedGetNullTimeUnit() { |
468 |
> |
testForkTimedGetNullTimeUnit(mainPool()); |
469 |
> |
} |
470 |
> |
public void testForkTimedGetNullTimeUnit_Singleton() { |
471 |
> |
testForkTimedGet(singletonPool()); |
472 |
> |
} |
473 |
> |
public void testForkTimedGetNullTimeUnit(ForkJoinPool pool) { |
474 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
475 |
|
protected void realCompute() throws Exception { |
476 |
|
AsyncFib f = new AsyncFib(8); |
480 |
|
shouldThrow(); |
481 |
|
} catch (NullPointerException success) {} |
482 |
|
}}; |
483 |
< |
testInvokeOnPool(mainPool(), a); |
483 |
> |
testInvokeOnPool(pool, a); |
484 |
|
} |
485 |
|
|
486 |
|
/** |
487 |
|
* quietlyJoin of a forked task returns when task completes |
488 |
|
*/ |
489 |
|
public void testForkQuietlyJoin() { |
490 |
+ |
testForkQuietlyJoin(mainPool()); |
491 |
+ |
} |
492 |
+ |
public void testForkQuietlyJoin_Singleton() { |
493 |
+ |
testForkQuietlyJoin(singletonPool()); |
494 |
+ |
} |
495 |
+ |
public void testForkQuietlyJoin(ForkJoinPool pool) { |
496 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
497 |
|
protected void realCompute() { |
498 |
|
AsyncFib f = new AsyncFib(8); |
499 |
|
assertSame(f, f.fork()); |
500 |
|
f.quietlyJoin(); |
501 |
< |
assertEquals(21, f.number); |
447 |
< |
checkCompletedNormally(f); |
501 |
> |
f.checkCompletedNormally(); |
502 |
|
}}; |
503 |
< |
testInvokeOnPool(mainPool(), a); |
503 |
> |
testInvokeOnPool(pool, a); |
504 |
|
} |
505 |
|
|
506 |
|
/** |
508 |
|
* getQueuedTaskCount returns 0 when quiescent |
509 |
|
*/ |
510 |
|
public void testForkHelpQuiesce() { |
511 |
+ |
testForkHelpQuiesce(mainPool()); |
512 |
+ |
} |
513 |
+ |
public void testForkHelpQuiesce_Singleton() { |
514 |
+ |
testForkHelpQuiesce(singletonPool()); |
515 |
+ |
} |
516 |
+ |
public void testForkHelpQuiesce(ForkJoinPool pool) { |
517 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
518 |
|
protected void realCompute() { |
519 |
|
AsyncFib f = new AsyncFib(8); |
520 |
|
assertSame(f, f.fork()); |
521 |
|
helpQuiesce(); |
462 |
– |
assertEquals(21, f.number); |
522 |
|
assertEquals(0, getQueuedTaskCount()); |
523 |
< |
checkCompletedNormally(f); |
523 |
> |
f.checkCompletedNormally(); |
524 |
|
}}; |
525 |
< |
testInvokeOnPool(mainPool(), a); |
525 |
> |
testInvokeOnPool(pool, a); |
526 |
|
} |
527 |
|
|
528 |
|
/** |
529 |
|
* invoke task throws exception when task completes abnormally |
530 |
|
*/ |
531 |
|
public void testAbnormalInvoke() { |
532 |
+ |
testAbnormalInvoke(mainPool()); |
533 |
+ |
} |
534 |
+ |
public void testAbnormalInvoke_Singleton() { |
535 |
+ |
testAbnormalInvoke(singletonPool()); |
536 |
+ |
} |
537 |
+ |
public void testAbnormalInvoke(ForkJoinPool pool) { |
538 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
539 |
|
protected void realCompute() { |
540 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
545 |
|
checkCompletedAbnormally(f, success); |
546 |
|
} |
547 |
|
}}; |
548 |
< |
testInvokeOnPool(mainPool(), a); |
548 |
> |
testInvokeOnPool(pool, a); |
549 |
|
} |
550 |
|
|
551 |
|
/** |
552 |
|
* quietlyInvoke task returns when task completes abnormally |
553 |
|
*/ |
554 |
|
public void testAbnormalQuietlyInvoke() { |
555 |
+ |
testAbnormalQuietlyInvoke(mainPool()); |
556 |
+ |
} |
557 |
+ |
public void testAbnormalQuietlyInvoke_Singleton() { |
558 |
+ |
testAbnormalQuietlyInvoke(singletonPool()); |
559 |
+ |
} |
560 |
+ |
public void testAbnormalQuietlyInvoke(ForkJoinPool pool) { |
561 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
562 |
|
protected void realCompute() { |
563 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
565 |
|
assertTrue(f.getException() instanceof FJException); |
566 |
|
checkCompletedAbnormally(f, f.getException()); |
567 |
|
}}; |
568 |
< |
testInvokeOnPool(mainPool(), a); |
568 |
> |
testInvokeOnPool(pool, a); |
569 |
|
} |
570 |
|
|
571 |
|
/** |
572 |
|
* join of a forked task throws exception when task completes abnormally |
573 |
|
*/ |
574 |
|
public void testAbnormalForkJoin() { |
575 |
+ |
testAbnormalForkJoin(mainPool()); |
576 |
+ |
} |
577 |
+ |
public void testAbnormalForkJoin_Singleton() { |
578 |
+ |
testAbnormalForkJoin(singletonPool()); |
579 |
+ |
} |
580 |
+ |
public void testAbnormalForkJoin(ForkJoinPool pool) { |
581 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
582 |
|
protected void realCompute() { |
583 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
589 |
|
checkCompletedAbnormally(f, success); |
590 |
|
} |
591 |
|
}}; |
592 |
< |
testInvokeOnPool(mainPool(), a); |
592 |
> |
testInvokeOnPool(pool, a); |
593 |
|
} |
594 |
|
|
595 |
|
/** |
596 |
|
* get of a forked task throws exception when task completes abnormally |
597 |
|
*/ |
598 |
|
public void testAbnormalForkGet() { |
599 |
+ |
testAbnormalForkGet(mainPool()); |
600 |
+ |
} |
601 |
+ |
public void testAbnormalForkGet_Singleton() { |
602 |
+ |
testAbnormalForkJoin(singletonPool()); |
603 |
+ |
} |
604 |
+ |
public void testAbnormalForkGet(ForkJoinPool pool) { |
605 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
606 |
|
protected void realCompute() throws Exception { |
607 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
615 |
|
checkCompletedAbnormally(f, cause); |
616 |
|
} |
617 |
|
}}; |
618 |
< |
testInvokeOnPool(mainPool(), a); |
618 |
> |
testInvokeOnPool(pool, a); |
619 |
|
} |
620 |
|
|
621 |
|
/** |
622 |
|
* timed get of a forked task throws exception when task completes abnormally |
623 |
|
*/ |
624 |
|
public void testAbnormalForkTimedGet() { |
625 |
+ |
testAbnormalForkTimedGet(mainPool()); |
626 |
+ |
} |
627 |
+ |
public void testAbnormalForkTimedGet_Singleton() { |
628 |
+ |
testAbnormalForkTimedGet(singletonPool()); |
629 |
+ |
} |
630 |
+ |
public void testAbnormalForkTimedGet(ForkJoinPool pool) { |
631 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
632 |
|
protected void realCompute() throws Exception { |
633 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
641 |
|
checkCompletedAbnormally(f, cause); |
642 |
|
} |
643 |
|
}}; |
644 |
< |
testInvokeOnPool(mainPool(), a); |
644 |
> |
testInvokeOnPool(pool, a); |
645 |
|
} |
646 |
|
|
647 |
|
/** |
648 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
649 |
|
*/ |
650 |
|
public void testAbnormalForkQuietlyJoin() { |
651 |
+ |
testAbnormalForkQuietlyJoin(mainPool()); |
652 |
+ |
} |
653 |
+ |
public void testAbnormalForkQuietlyJoin_Singleton() { |
654 |
+ |
testAbnormalForkQuietlyJoin(singletonPool()); |
655 |
+ |
} |
656 |
+ |
public void testAbnormalForkQuietlyJoin(ForkJoinPool pool) { |
657 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
658 |
|
protected void realCompute() { |
659 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
662 |
|
assertTrue(f.getException() instanceof FJException); |
663 |
|
checkCompletedAbnormally(f, f.getException()); |
664 |
|
}}; |
665 |
< |
testInvokeOnPool(mainPool(), a); |
665 |
> |
testInvokeOnPool(pool, a); |
666 |
|
} |
667 |
|
|
668 |
|
/** |
669 |
|
* getPool of executing task returns its pool |
670 |
|
*/ |
671 |
|
public void testGetPool() { |
672 |
< |
final ForkJoinPool mainPool = mainPool(); |
672 |
> |
testGetPool(mainPool()); |
673 |
> |
} |
674 |
> |
public void testGetPool_Singleton() { |
675 |
> |
testGetPool(singletonPool()); |
676 |
> |
} |
677 |
> |
public void testGetPool(ForkJoinPool pool) { |
678 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
679 |
|
protected void realCompute() { |
680 |
< |
assertSame(mainPool, getPool()); |
680 |
> |
assertSame(pool, getPool()); |
681 |
|
}}; |
682 |
< |
testInvokeOnPool(mainPool, a); |
682 |
> |
testInvokeOnPool(pool, a); |
683 |
|
} |
684 |
|
|
685 |
|
/** |
697 |
|
* inForkJoinPool of executing task returns true |
698 |
|
*/ |
699 |
|
public void testInForkJoinPool() { |
700 |
+ |
testInForkJoinPool(mainPool()); |
701 |
+ |
} |
702 |
+ |
public void testInForkJoinPool_Singleton() { |
703 |
+ |
testInForkJoinPool(singletonPool()); |
704 |
+ |
} |
705 |
+ |
public void testInForkJoinPool(ForkJoinPool pool) { |
706 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
707 |
|
protected void realCompute() { |
708 |
|
assertTrue(inForkJoinPool()); |
709 |
|
}}; |
710 |
< |
testInvokeOnPool(mainPool(), a); |
710 |
> |
testInvokeOnPool(pool, a); |
711 |
|
} |
712 |
|
|
713 |
|
/** |
737 |
|
* invoke task throws exception after invoking completeExceptionally |
738 |
|
*/ |
739 |
|
public void testCompleteExceptionally() { |
740 |
+ |
testCompleteExceptionally(mainPool()); |
741 |
+ |
} |
742 |
+ |
public void testCompleteExceptionally_Singleton() { |
743 |
+ |
testCompleteExceptionally(singletonPool()); |
744 |
+ |
} |
745 |
+ |
public void testCompleteExceptionally(ForkJoinPool pool) { |
746 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
747 |
|
protected void realCompute() { |
748 |
|
AsyncFib f = new AsyncFib(8); |
754 |
|
checkCompletedAbnormally(f, success); |
755 |
|
} |
756 |
|
}}; |
757 |
< |
testInvokeOnPool(mainPool(), a); |
757 |
> |
testInvokeOnPool(pool, a); |
758 |
|
} |
759 |
|
|
760 |
|
/** |
761 |
< |
* invokeAll(t1, t2) invokes all task arguments |
761 |
> |
* invokeAll(tasks) with 1 argument invokes task |
762 |
|
*/ |
763 |
< |
public void testInvokeAll2() { |
763 |
> |
public void testInvokeAll1() { |
764 |
> |
testInvokeAll1(mainPool()); |
765 |
> |
} |
766 |
> |
public void testInvokeAll1_Singleton() { |
767 |
> |
testInvokeAll1(singletonPool()); |
768 |
> |
} |
769 |
> |
public void testInvokeAll1(ForkJoinPool pool) { |
770 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
771 |
|
protected void realCompute() { |
772 |
|
AsyncFib f = new AsyncFib(8); |
773 |
< |
AsyncFib g = new AsyncFib(9); |
774 |
< |
invokeAll(f, g); |
657 |
< |
assertEquals(21, f.number); |
658 |
< |
assertEquals(34, g.number); |
659 |
< |
checkCompletedNormally(f); |
660 |
< |
checkCompletedNormally(g); |
773 |
> |
invokeAll(f); |
774 |
> |
f.checkCompletedNormally(); |
775 |
|
}}; |
776 |
< |
testInvokeOnPool(mainPool(), a); |
776 |
> |
testInvokeOnPool(pool, a); |
777 |
|
} |
778 |
|
|
779 |
|
/** |
780 |
< |
* invokeAll(tasks) with 1 argument invokes task |
780 |
> |
* invokeAll(t1, t2) invokes all task arguments |
781 |
|
*/ |
782 |
< |
public void testInvokeAll1() { |
782 |
> |
public void testInvokeAll2() { |
783 |
> |
testInvokeAll2(mainPool()); |
784 |
> |
} |
785 |
> |
public void testInvokeAll2_Singleton() { |
786 |
> |
testInvokeAll2(singletonPool()); |
787 |
> |
} |
788 |
> |
public void testInvokeAll2(ForkJoinPool pool) { |
789 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
790 |
|
protected void realCompute() { |
791 |
< |
AsyncFib f = new AsyncFib(8); |
792 |
< |
invokeAll(f); |
793 |
< |
checkCompletedNormally(f); |
794 |
< |
assertEquals(21, f.number); |
791 |
> |
AsyncFib[] tasks = { |
792 |
> |
new AsyncFib(8), |
793 |
> |
new AsyncFib(9), |
794 |
> |
}; |
795 |
> |
invokeAll(tasks[0], tasks[1]); |
796 |
> |
for (AsyncFib task : tasks) assertTrue(task.isDone()); |
797 |
> |
for (AsyncFib task : tasks) task.checkCompletedNormally(); |
798 |
|
}}; |
799 |
< |
testInvokeOnPool(mainPool(), a); |
799 |
> |
testInvokeOnPool(pool, a); |
800 |
|
} |
801 |
|
|
802 |
|
/** |
803 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
804 |
|
*/ |
805 |
|
public void testInvokeAll3() { |
806 |
+ |
testInvokeAll3(mainPool()); |
807 |
+ |
} |
808 |
+ |
public void testInvokeAll3_Singleton() { |
809 |
+ |
testInvokeAll3(singletonPool()); |
810 |
+ |
} |
811 |
+ |
public void testInvokeAll3(ForkJoinPool pool) { |
812 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
813 |
|
protected void realCompute() { |
814 |
< |
AsyncFib f = new AsyncFib(8); |
815 |
< |
AsyncFib g = new AsyncFib(9); |
816 |
< |
AsyncFib h = new AsyncFib(7); |
817 |
< |
invokeAll(f, g, h); |
818 |
< |
assertEquals(21, f.number); |
819 |
< |
assertEquals(34, g.number); |
820 |
< |
assertEquals(13, h.number); |
821 |
< |
checkCompletedNormally(f); |
693 |
< |
checkCompletedNormally(g); |
694 |
< |
checkCompletedNormally(h); |
814 |
> |
AsyncFib[] tasks = { |
815 |
> |
new AsyncFib(8), |
816 |
> |
new AsyncFib(9), |
817 |
> |
new AsyncFib(7), |
818 |
> |
}; |
819 |
> |
invokeAll(tasks[0], tasks[1], tasks[2]); |
820 |
> |
for (AsyncFib task : tasks) assertTrue(task.isDone()); |
821 |
> |
for (AsyncFib task : tasks) task.checkCompletedNormally(); |
822 |
|
}}; |
823 |
< |
testInvokeOnPool(mainPool(), a); |
823 |
> |
testInvokeOnPool(pool, a); |
824 |
|
} |
825 |
|
|
826 |
|
/** |
827 |
|
* invokeAll(collection) invokes all tasks in the collection |
828 |
|
*/ |
829 |
|
public void testInvokeAllCollection() { |
830 |
+ |
testInvokeAllCollection(mainPool()); |
831 |
+ |
} |
832 |
+ |
public void testInvokeAllCollection_Singleton() { |
833 |
+ |
testInvokeAllCollection(singletonPool()); |
834 |
+ |
} |
835 |
+ |
public void testInvokeAllCollection(ForkJoinPool pool) { |
836 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
837 |
|
protected void realCompute() { |
838 |
< |
AsyncFib f = new AsyncFib(8); |
839 |
< |
AsyncFib g = new AsyncFib(9); |
840 |
< |
AsyncFib h = new AsyncFib(7); |
841 |
< |
HashSet set = new HashSet(); |
842 |
< |
set.add(f); |
843 |
< |
set.add(g); |
844 |
< |
set.add(h); |
845 |
< |
invokeAll(set); |
713 |
< |
assertEquals(21, f.number); |
714 |
< |
assertEquals(34, g.number); |
715 |
< |
assertEquals(13, h.number); |
716 |
< |
checkCompletedNormally(f); |
717 |
< |
checkCompletedNormally(g); |
718 |
< |
checkCompletedNormally(h); |
838 |
> |
AsyncFib[] tasks = { |
839 |
> |
new AsyncFib(8), |
840 |
> |
new AsyncFib(9), |
841 |
> |
new AsyncFib(7), |
842 |
> |
}; |
843 |
> |
invokeAll(Arrays.asList(tasks)); |
844 |
> |
for (AsyncFib task : tasks) assertTrue(task.isDone()); |
845 |
> |
for (AsyncFib task : tasks) task.checkCompletedNormally(); |
846 |
|
}}; |
847 |
< |
testInvokeOnPool(mainPool(), a); |
847 |
> |
testInvokeOnPool(pool, a); |
848 |
|
} |
849 |
|
|
850 |
|
/** |
851 |
|
* invokeAll(tasks) with any null task throws NullPointerException |
852 |
|
*/ |
853 |
|
public void testInvokeAllNullTask() { |
854 |
+ |
testInvokeAllNullTask(mainPool()); |
855 |
+ |
} |
856 |
+ |
public void testInvokeAllNullTask_Singleton() { |
857 |
+ |
testInvokeAllNullTask(singletonPool()); |
858 |
+ |
} |
859 |
+ |
public void testInvokeAllNullTask(ForkJoinPool pool) { |
860 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
861 |
|
protected void realCompute() { |
729 |
– |
AsyncFib f = new AsyncFib(8); |
730 |
– |
AsyncFib g = new AsyncFib(9); |
862 |
|
AsyncFib nul = null; |
863 |
|
Runnable[] throwingActions = { |
864 |
|
() -> invokeAll(nul), |
865 |
|
() -> invokeAll(nul, nul), |
866 |
< |
() -> invokeAll(f, g, nul), |
867 |
< |
() -> invokeAll(f, nul, g), |
868 |
< |
() -> invokeAll(nul, f, g), |
866 |
> |
() -> invokeAll(new AsyncFib(8), new AsyncFib(9), nul), |
867 |
> |
() -> invokeAll(new AsyncFib(8), nul, new AsyncFib(9)), |
868 |
> |
() -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)), |
869 |
|
}; |
870 |
|
assertThrows(NullPointerException.class, throwingActions); |
871 |
|
}}; |
872 |
< |
testInvokeOnPool(mainPool(), a); |
872 |
> |
testInvokeOnPool(pool, a); |
873 |
|
} |
874 |
|
|
875 |
|
/** |
876 |
|
* invokeAll(t1, t2) throw exception if any task does |
877 |
|
*/ |
878 |
|
public void testAbnormalInvokeAll2() { |
879 |
+ |
testAbnormalInvokeAll2(mainPool()); |
880 |
+ |
} |
881 |
+ |
public void testAbnormalInvokeAll2_Singleton() { |
882 |
+ |
testAbnormalInvokeAll2(singletonPool()); |
883 |
+ |
} |
884 |
+ |
public void testAbnormalInvokeAll2(ForkJoinPool pool) { |
885 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
886 |
|
protected void realCompute() { |
887 |
|
AsyncFib f = new AsyncFib(8); |
893 |
|
checkCompletedAbnormally(g, success); |
894 |
|
} |
895 |
|
}}; |
896 |
< |
testInvokeOnPool(mainPool(), a); |
896 |
> |
testInvokeOnPool(pool, a); |
897 |
|
} |
898 |
|
|
899 |
|
/** |
900 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
901 |
|
*/ |
902 |
|
public void testAbnormalInvokeAll1() { |
903 |
+ |
testAbnormalInvokeAll1(mainPool()); |
904 |
+ |
} |
905 |
+ |
public void testAbnormalInvokeAll1_Singleton() { |
906 |
+ |
testAbnormalInvokeAll1(singletonPool()); |
907 |
+ |
} |
908 |
+ |
public void testAbnormalInvokeAll1(ForkJoinPool pool) { |
909 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
910 |
|
protected void realCompute() { |
911 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
916 |
|
checkCompletedAbnormally(g, success); |
917 |
|
} |
918 |
|
}}; |
919 |
< |
testInvokeOnPool(mainPool(), a); |
919 |
> |
testInvokeOnPool(pool, a); |
920 |
|
} |
921 |
|
|
922 |
|
/** |
923 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
924 |
|
*/ |
925 |
|
public void testAbnormalInvokeAll3() { |
926 |
+ |
testAbnormalInvokeAll3(mainPool()); |
927 |
+ |
} |
928 |
+ |
public void testAbnormalInvokeAll3_Singleton() { |
929 |
+ |
testAbnormalInvokeAll3(singletonPool()); |
930 |
+ |
} |
931 |
+ |
public void testAbnormalInvokeAll3(ForkJoinPool pool) { |
932 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
933 |
|
protected void realCompute() { |
934 |
|
AsyncFib f = new AsyncFib(8); |
941 |
|
checkCompletedAbnormally(g, success); |
942 |
|
} |
943 |
|
}}; |
944 |
< |
testInvokeOnPool(mainPool(), a); |
944 |
> |
testInvokeOnPool(pool, a); |
945 |
|
} |
946 |
|
|
947 |
|
/** |
948 |
|
* invokeAll(collection) throws exception if any task does |
949 |
|
*/ |
950 |
|
public void testAbnormalInvokeAllCollection() { |
951 |
+ |
testAbnormalInvokeAllCollection(mainPool()); |
952 |
+ |
} |
953 |
+ |
public void testAbnormalInvokeAllCollection_Singleton() { |
954 |
+ |
testAbnormalInvokeAllCollection(singletonPool()); |
955 |
+ |
} |
956 |
+ |
public void testAbnormalInvokeAllCollection(ForkJoinPool pool) { |
957 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
958 |
|
protected void realCompute() { |
959 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
960 |
|
AsyncFib g = new AsyncFib(9); |
961 |
|
AsyncFib h = new AsyncFib(7); |
962 |
< |
HashSet set = new HashSet(); |
808 |
< |
set.add(f); |
809 |
< |
set.add(g); |
810 |
< |
set.add(h); |
962 |
> |
ForkJoinTask[] tasks = { f, g, h }; |
963 |
|
try { |
964 |
< |
invokeAll(set); |
964 |
> |
invokeAll(Arrays.asList(tasks)); |
965 |
|
shouldThrow(); |
966 |
|
} catch (FJException success) { |
967 |
|
checkCompletedAbnormally(f, success); |
968 |
|
} |
969 |
|
}}; |
970 |
< |
testInvokeOnPool(mainPool(), a); |
970 |
> |
testInvokeOnPool(pool, a); |
971 |
|
} |
972 |
|
|
973 |
|
/** |
984 |
|
assertTrue(f.tryUnfork()); |
985 |
|
helpQuiesce(); |
986 |
|
checkNotDone(f); |
987 |
< |
checkCompletedNormally(g); |
987 |
> |
g.checkCompletedNormally(); |
988 |
|
}}; |
989 |
|
testInvokeOnPool(singletonPool(), a); |
990 |
|
} |
1005 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
1006 |
|
helpQuiesce(); |
1007 |
|
assertEquals(0, getSurplusQueuedTaskCount()); |
1008 |
< |
checkCompletedNormally(f); |
1009 |
< |
checkCompletedNormally(g); |
1010 |
< |
checkCompletedNormally(h); |
1008 |
> |
f.checkCompletedNormally(); |
1009 |
> |
g.checkCompletedNormally(); |
1010 |
> |
h.checkCompletedNormally(); |
1011 |
|
}}; |
1012 |
|
testInvokeOnPool(singletonPool(), a); |
1013 |
|
} |
1024 |
|
assertSame(f, f.fork()); |
1025 |
|
assertSame(f, peekNextLocalTask()); |
1026 |
|
assertNull(f.join()); |
1027 |
< |
checkCompletedNormally(f); |
1027 |
> |
f.checkCompletedNormally(); |
1028 |
|
helpQuiesce(); |
1029 |
< |
checkCompletedNormally(g); |
1029 |
> |
g.checkCompletedNormally(); |
1030 |
|
}}; |
1031 |
|
testInvokeOnPool(singletonPool(), a); |
1032 |
|
} |
1045 |
|
assertSame(f, pollNextLocalTask()); |
1046 |
|
helpQuiesce(); |
1047 |
|
checkNotDone(f); |
1048 |
< |
assertEquals(34, g.number); |
897 |
< |
checkCompletedNormally(g); |
1048 |
> |
g.checkCompletedNormally(); |
1049 |
|
}}; |
1050 |
|
testInvokeOnPool(singletonPool(), a); |
1051 |
|
} |
1063 |
|
assertSame(f, pollTask()); |
1064 |
|
helpQuiesce(); |
1065 |
|
checkNotDone(f); |
1066 |
< |
checkCompletedNormally(g); |
1066 |
> |
g.checkCompletedNormally(); |
1067 |
|
}}; |
1068 |
|
testInvokeOnPool(singletonPool(), a); |
1069 |
|
} |
1081 |
|
assertSame(g, peekNextLocalTask()); |
1082 |
|
assertNull(f.join()); |
1083 |
|
helpQuiesce(); |
1084 |
< |
checkCompletedNormally(f); |
1085 |
< |
assertEquals(34, g.number); |
935 |
< |
checkCompletedNormally(g); |
1084 |
> |
f.checkCompletedNormally(); |
1085 |
> |
g.checkCompletedNormally(); |
1086 |
|
}}; |
1087 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1088 |
|
} |
1100 |
|
assertSame(f, f.fork()); |
1101 |
|
assertSame(g, pollNextLocalTask()); |
1102 |
|
helpQuiesce(); |
1103 |
< |
assertEquals(21, f.number); |
954 |
< |
checkCompletedNormally(f); |
1103 |
> |
f.checkCompletedNormally(); |
1104 |
|
checkNotDone(g); |
1105 |
|
}}; |
1106 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1119 |
|
assertSame(f, f.fork()); |
1120 |
|
assertSame(g, pollTask()); |
1121 |
|
helpQuiesce(); |
1122 |
< |
assertEquals(21, f.number); |
974 |
< |
checkCompletedNormally(f); |
1122 |
> |
f.checkCompletedNormally(); |
1123 |
|
checkNotDone(g); |
1124 |
|
}}; |
1125 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1126 |
|
} |
1127 |
|
|
980 |
– |
// versions for singleton pools |
981 |
– |
|
982 |
– |
/** |
983 |
– |
* invoke returns when task completes normally. |
984 |
– |
* isCompletedAbnormally and isCancelled return false for normally |
985 |
– |
* completed tasks; getRawResult returns null. |
986 |
– |
*/ |
987 |
– |
public void testInvokeSingleton() { |
988 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
989 |
– |
protected void realCompute() { |
990 |
– |
AsyncFib f = new AsyncFib(8); |
991 |
– |
assertNull(f.invoke()); |
992 |
– |
assertEquals(21, f.number); |
993 |
– |
checkCompletedNormally(f); |
994 |
– |
}}; |
995 |
– |
testInvokeOnPool(singletonPool(), a); |
996 |
– |
} |
997 |
– |
|
998 |
– |
/** |
999 |
– |
* quietlyInvoke task returns when task completes normally. |
1000 |
– |
* isCompletedAbnormally and isCancelled return false for normally |
1001 |
– |
* completed tasks |
1002 |
– |
*/ |
1003 |
– |
public void testQuietlyInvokeSingleton() { |
1004 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1005 |
– |
protected void realCompute() { |
1006 |
– |
AsyncFib f = new AsyncFib(8); |
1007 |
– |
f.quietlyInvoke(); |
1008 |
– |
assertEquals(21, f.number); |
1009 |
– |
checkCompletedNormally(f); |
1010 |
– |
}}; |
1011 |
– |
testInvokeOnPool(singletonPool(), a); |
1012 |
– |
} |
1013 |
– |
|
1014 |
– |
/** |
1015 |
– |
* join of a forked task returns when task completes |
1016 |
– |
*/ |
1017 |
– |
public void testForkJoinSingleton() { |
1018 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1019 |
– |
protected void realCompute() { |
1020 |
– |
AsyncFib f = new AsyncFib(8); |
1021 |
– |
assertSame(f, f.fork()); |
1022 |
– |
assertNull(f.join()); |
1023 |
– |
assertEquals(21, f.number); |
1024 |
– |
checkCompletedNormally(f); |
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 |
– |
protected 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 |
– |
checkCompletedNormally(f); |
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 |
– |
protected 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 |
– |
checkCompletedNormally(f); |
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 |
– |
protected 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 |
– |
protected void realCompute() { |
1081 |
– |
AsyncFib f = new AsyncFib(8); |
1082 |
– |
assertSame(f, f.fork()); |
1083 |
– |
f.quietlyJoin(); |
1084 |
– |
assertEquals(21, f.number); |
1085 |
– |
checkCompletedNormally(f); |
1086 |
– |
}}; |
1087 |
– |
testInvokeOnPool(singletonPool(), a); |
1088 |
– |
} |
1089 |
– |
|
1090 |
– |
/** |
1091 |
– |
* helpQuiesce returns when tasks are complete. |
1092 |
– |
* getQueuedTaskCount returns 0 when quiescent |
1093 |
– |
*/ |
1094 |
– |
public void testForkHelpQuiesceSingleton() { |
1095 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1096 |
– |
protected void realCompute() { |
1097 |
– |
AsyncFib f = new AsyncFib(8); |
1098 |
– |
assertSame(f, f.fork()); |
1099 |
– |
helpQuiesce(); |
1100 |
– |
assertEquals(0, getQueuedTaskCount()); |
1101 |
– |
assertEquals(21, f.number); |
1102 |
– |
checkCompletedNormally(f); |
1103 |
– |
}}; |
1104 |
– |
testInvokeOnPool(singletonPool(), a); |
1105 |
– |
} |
1106 |
– |
|
1107 |
– |
/** |
1108 |
– |
* invoke task throws exception when task completes abnormally |
1109 |
– |
*/ |
1110 |
– |
public void testAbnormalInvokeSingleton() { |
1111 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1112 |
– |
protected void realCompute() { |
1113 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1114 |
– |
try { |
1115 |
– |
f.invoke(); |
1116 |
– |
shouldThrow(); |
1117 |
– |
} catch (FJException success) { |
1118 |
– |
checkCompletedAbnormally(f, success); |
1119 |
– |
} |
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 |
– |
protected void realCompute() { |
1130 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1131 |
– |
f.quietlyInvoke(); |
1132 |
– |
assertTrue(f.getException() instanceof FJException); |
1133 |
– |
checkCompletedAbnormally(f, f.getException()); |
1134 |
– |
}}; |
1135 |
– |
testInvokeOnPool(singletonPool(), a); |
1136 |
– |
} |
1137 |
– |
|
1138 |
– |
/** |
1139 |
– |
* join of a forked task throws exception when task completes abnormally |
1140 |
– |
*/ |
1141 |
– |
public void testAbnormalForkJoinSingleton() { |
1142 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1143 |
– |
protected void realCompute() { |
1144 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1145 |
– |
assertSame(f, f.fork()); |
1146 |
– |
try { |
1147 |
– |
f.join(); |
1148 |
– |
shouldThrow(); |
1149 |
– |
} catch (FJException success) { |
1150 |
– |
checkCompletedAbnormally(f, success); |
1151 |
– |
} |
1152 |
– |
}}; |
1153 |
– |
testInvokeOnPool(singletonPool(), a); |
1154 |
– |
} |
1155 |
– |
|
1156 |
– |
/** |
1157 |
– |
* get of a forked task throws exception when task completes abnormally |
1158 |
– |
*/ |
1159 |
– |
public void testAbnormalForkGetSingleton() { |
1160 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1161 |
– |
protected void realCompute() throws Exception { |
1162 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1163 |
– |
assertSame(f, f.fork()); |
1164 |
– |
try { |
1165 |
– |
f.get(); |
1166 |
– |
shouldThrow(); |
1167 |
– |
} catch (ExecutionException success) { |
1168 |
– |
Throwable cause = success.getCause(); |
1169 |
– |
assertTrue(cause instanceof FJException); |
1170 |
– |
checkCompletedAbnormally(f, cause); |
1171 |
– |
} |
1172 |
– |
}}; |
1173 |
– |
testInvokeOnPool(singletonPool(), a); |
1174 |
– |
} |
1175 |
– |
|
1176 |
– |
/** |
1177 |
– |
* timed get of a forked task throws exception when task completes abnormally |
1178 |
– |
*/ |
1179 |
– |
public void testAbnormalForkTimedGetSingleton() { |
1180 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1181 |
– |
protected void realCompute() throws Exception { |
1182 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1183 |
– |
assertSame(f, f.fork()); |
1184 |
– |
try { |
1185 |
– |
f.get(LONG_DELAY_MS, MILLISECONDS); |
1186 |
– |
shouldThrow(); |
1187 |
– |
} catch (ExecutionException success) { |
1188 |
– |
Throwable cause = success.getCause(); |
1189 |
– |
assertTrue(cause instanceof FJException); |
1190 |
– |
checkCompletedAbnormally(f, cause); |
1191 |
– |
} |
1192 |
– |
}}; |
1193 |
– |
testInvokeOnPool(singletonPool(), a); |
1194 |
– |
} |
1195 |
– |
|
1196 |
– |
/** |
1197 |
– |
* quietlyJoin of a forked task returns when task completes abnormally |
1198 |
– |
*/ |
1199 |
– |
public void testAbnormalForkQuietlyJoinSingleton() { |
1200 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1201 |
– |
protected void realCompute() { |
1202 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1203 |
– |
assertSame(f, f.fork()); |
1204 |
– |
f.quietlyJoin(); |
1205 |
– |
assertTrue(f.getException() instanceof FJException); |
1206 |
– |
checkCompletedAbnormally(f, f.getException()); |
1207 |
– |
}}; |
1208 |
– |
testInvokeOnPool(singletonPool(), a); |
1209 |
– |
} |
1210 |
– |
|
1211 |
– |
/** |
1212 |
– |
* invoke task throws exception after invoking completeExceptionally |
1213 |
– |
*/ |
1214 |
– |
public void testCompleteExceptionallySingleton() { |
1215 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1216 |
– |
protected void realCompute() { |
1217 |
– |
AsyncFib f = new AsyncFib(8); |
1218 |
– |
f.completeExceptionally(new FJException()); |
1219 |
– |
try { |
1220 |
– |
f.invoke(); |
1221 |
– |
shouldThrow(); |
1222 |
– |
} catch (FJException success) { |
1223 |
– |
checkCompletedAbnormally(f, success); |
1224 |
– |
} |
1225 |
– |
}}; |
1226 |
– |
testInvokeOnPool(singletonPool(), a); |
1227 |
– |
} |
1228 |
– |
|
1229 |
– |
/** |
1230 |
– |
* invokeAll(t1, t2) invokes all task arguments |
1231 |
– |
*/ |
1232 |
– |
public void testInvokeAll2Singleton() { |
1233 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1234 |
– |
protected void realCompute() { |
1235 |
– |
AsyncFib f = new AsyncFib(8); |
1236 |
– |
AsyncFib g = new AsyncFib(9); |
1237 |
– |
invokeAll(f, g); |
1238 |
– |
assertEquals(21, f.number); |
1239 |
– |
assertEquals(34, g.number); |
1240 |
– |
checkCompletedNormally(f); |
1241 |
– |
checkCompletedNormally(g); |
1242 |
– |
}}; |
1243 |
– |
testInvokeOnPool(singletonPool(), a); |
1244 |
– |
} |
1245 |
– |
|
1246 |
– |
/** |
1247 |
– |
* invokeAll(tasks) with 1 argument invokes task |
1248 |
– |
*/ |
1249 |
– |
public void testInvokeAll1Singleton() { |
1250 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1251 |
– |
protected void realCompute() { |
1252 |
– |
AsyncFib f = new AsyncFib(8); |
1253 |
– |
invokeAll(f); |
1254 |
– |
checkCompletedNormally(f); |
1255 |
– |
assertEquals(21, f.number); |
1256 |
– |
}}; |
1257 |
– |
testInvokeOnPool(singletonPool(), a); |
1258 |
– |
} |
1259 |
– |
|
1260 |
– |
/** |
1261 |
– |
* invokeAll(tasks) with > 2 argument invokes tasks |
1262 |
– |
*/ |
1263 |
– |
public void testInvokeAll3Singleton() { |
1264 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1265 |
– |
protected void realCompute() { |
1266 |
– |
AsyncFib f = new AsyncFib(8); |
1267 |
– |
AsyncFib g = new AsyncFib(9); |
1268 |
– |
AsyncFib h = new AsyncFib(7); |
1269 |
– |
invokeAll(f, g, h); |
1270 |
– |
assertEquals(21, f.number); |
1271 |
– |
assertEquals(34, g.number); |
1272 |
– |
assertEquals(13, h.number); |
1273 |
– |
checkCompletedNormally(f); |
1274 |
– |
checkCompletedNormally(g); |
1275 |
– |
checkCompletedNormally(h); |
1276 |
– |
}}; |
1277 |
– |
testInvokeOnPool(singletonPool(), a); |
1278 |
– |
} |
1279 |
– |
|
1280 |
– |
/** |
1281 |
– |
* invokeAll(collection) invokes all tasks in the collection |
1282 |
– |
*/ |
1283 |
– |
public void testInvokeAllCollectionSingleton() { |
1284 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1285 |
– |
protected void realCompute() { |
1286 |
– |
AsyncFib f = new AsyncFib(8); |
1287 |
– |
AsyncFib g = new AsyncFib(9); |
1288 |
– |
AsyncFib h = new AsyncFib(7); |
1289 |
– |
HashSet set = new HashSet(); |
1290 |
– |
set.add(f); |
1291 |
– |
set.add(g); |
1292 |
– |
set.add(h); |
1293 |
– |
invokeAll(set); |
1294 |
– |
assertEquals(21, f.number); |
1295 |
– |
assertEquals(34, g.number); |
1296 |
– |
assertEquals(13, h.number); |
1297 |
– |
checkCompletedNormally(f); |
1298 |
– |
checkCompletedNormally(g); |
1299 |
– |
checkCompletedNormally(h); |
1300 |
– |
}}; |
1301 |
– |
testInvokeOnPool(singletonPool(), a); |
1302 |
– |
} |
1303 |
– |
|
1304 |
– |
/** |
1305 |
– |
* invokeAll(tasks) with any null task throws NullPointerException |
1306 |
– |
*/ |
1307 |
– |
public void testInvokeAllNullTaskSingleton() { |
1308 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1309 |
– |
protected void realCompute() { |
1310 |
– |
AsyncFib f = new AsyncFib(8); |
1311 |
– |
AsyncFib g = new AsyncFib(9); |
1312 |
– |
AsyncFib nul = null; |
1313 |
– |
Runnable[] throwingActions = { |
1314 |
– |
() -> invokeAll(nul), |
1315 |
– |
() -> invokeAll(nul, nul), |
1316 |
– |
() -> invokeAll(f, g, nul), |
1317 |
– |
() -> invokeAll(f, nul, g), |
1318 |
– |
() -> invokeAll(nul, f, g), |
1319 |
– |
}; |
1320 |
– |
assertThrows(NullPointerException.class, throwingActions); |
1321 |
– |
}}; |
1322 |
– |
testInvokeOnPool(singletonPool(), a); |
1323 |
– |
} |
1324 |
– |
|
1325 |
– |
/** |
1326 |
– |
* invokeAll(t1, t2) throw exception if any task does |
1327 |
– |
*/ |
1328 |
– |
public void testAbnormalInvokeAll2Singleton() { |
1329 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1330 |
– |
protected void realCompute() { |
1331 |
– |
AsyncFib f = new AsyncFib(8); |
1332 |
– |
FailingAsyncFib g = new FailingAsyncFib(9); |
1333 |
– |
try { |
1334 |
– |
invokeAll(f, g); |
1335 |
– |
shouldThrow(); |
1336 |
– |
} catch (FJException success) { |
1337 |
– |
checkCompletedAbnormally(g, success); |
1338 |
– |
} |
1339 |
– |
}}; |
1340 |
– |
testInvokeOnPool(singletonPool(), a); |
1341 |
– |
} |
1342 |
– |
|
1343 |
– |
/** |
1344 |
– |
* invokeAll(tasks) with 1 argument throws exception if task does |
1345 |
– |
*/ |
1346 |
– |
public void testAbnormalInvokeAll1Singleton() { |
1347 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1348 |
– |
protected void realCompute() { |
1349 |
– |
FailingAsyncFib g = new FailingAsyncFib(9); |
1350 |
– |
try { |
1351 |
– |
invokeAll(g); |
1352 |
– |
shouldThrow(); |
1353 |
– |
} catch (FJException success) { |
1354 |
– |
checkCompletedAbnormally(g, success); |
1355 |
– |
} |
1356 |
– |
}}; |
1357 |
– |
testInvokeOnPool(singletonPool(), a); |
1358 |
– |
} |
1359 |
– |
|
1360 |
– |
/** |
1361 |
– |
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1362 |
– |
*/ |
1363 |
– |
public void testAbnormalInvokeAll3Singleton() { |
1364 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1365 |
– |
protected void realCompute() { |
1366 |
– |
AsyncFib f = new AsyncFib(8); |
1367 |
– |
FailingAsyncFib g = new FailingAsyncFib(9); |
1368 |
– |
AsyncFib h = new AsyncFib(7); |
1369 |
– |
try { |
1370 |
– |
invokeAll(f, g, h); |
1371 |
– |
shouldThrow(); |
1372 |
– |
} catch (FJException success) { |
1373 |
– |
checkCompletedAbnormally(g, success); |
1374 |
– |
} |
1375 |
– |
}}; |
1376 |
– |
testInvokeOnPool(singletonPool(), a); |
1377 |
– |
} |
1378 |
– |
|
1379 |
– |
/** |
1380 |
– |
* invokeAll(collection) throws exception if any task does |
1381 |
– |
*/ |
1382 |
– |
public void testAbnormalInvokeAllCollectionSingleton() { |
1383 |
– |
RecursiveAction a = new CheckedRecursiveAction() { |
1384 |
– |
protected void realCompute() { |
1385 |
– |
FailingAsyncFib f = new FailingAsyncFib(8); |
1386 |
– |
AsyncFib g = new AsyncFib(9); |
1387 |
– |
AsyncFib h = new AsyncFib(7); |
1388 |
– |
HashSet set = new HashSet(); |
1389 |
– |
set.add(f); |
1390 |
– |
set.add(g); |
1391 |
– |
set.add(h); |
1392 |
– |
try { |
1393 |
– |
invokeAll(set); |
1394 |
– |
shouldThrow(); |
1395 |
– |
} catch (FJException success) { |
1396 |
– |
checkCompletedAbnormally(f, success); |
1397 |
– |
} |
1398 |
– |
}}; |
1399 |
– |
testInvokeOnPool(singletonPool(), a); |
1400 |
– |
} |
1401 |
– |
|
1128 |
|
/** |
1129 |
|
* ForkJoinTask.quietlyComplete returns when task completes |
1130 |
|
* normally without setting a value. The most recent value |