3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
< |
import java.util.concurrent.ExecutionException; |
6 |
> |
|
7 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
> |
import static java.util.concurrent.TimeUnit.SECONDS; |
9 |
> |
|
10 |
> |
import java.util.HashSet; |
11 |
|
import java.util.concurrent.CancellationException; |
12 |
+ |
import java.util.concurrent.ExecutionException; |
13 |
|
import java.util.concurrent.ForkJoinPool; |
14 |
|
import java.util.concurrent.ForkJoinTask; |
10 |
– |
import java.util.concurrent.ForkJoinWorkerThread; |
15 |
|
import java.util.concurrent.RecursiveAction; |
12 |
– |
import java.util.concurrent.TimeUnit; |
16 |
|
import java.util.concurrent.TimeoutException; |
17 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
18 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
19 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
20 |
< |
import java.util.HashSet; |
18 |
< |
import junit.framework.*; |
18 |
> |
|
19 |
> |
import junit.framework.Test; |
20 |
> |
import junit.framework.TestSuite; |
21 |
|
|
22 |
|
public class ForkJoinTaskTest extends JSR166TestCase { |
23 |
|
|
351 |
|
} |
352 |
|
} |
353 |
|
|
352 |
– |
|
354 |
|
static final class FailingAsyncFib extends BinaryAsyncAction { |
355 |
|
int number; |
356 |
|
public FailingAsyncFib(int n) { |
386 |
|
*/ |
387 |
|
public void testInvoke() { |
388 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
389 |
< |
public void realCompute() { |
389 |
> |
protected void realCompute() { |
390 |
|
AsyncFib f = new AsyncFib(8); |
391 |
|
assertNull(f.invoke()); |
392 |
|
assertEquals(21, f.number); |
402 |
|
*/ |
403 |
|
public void testQuietlyInvoke() { |
404 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
405 |
< |
public void realCompute() { |
405 |
> |
protected void realCompute() { |
406 |
|
AsyncFib f = new AsyncFib(8); |
407 |
|
f.quietlyInvoke(); |
408 |
|
assertEquals(21, f.number); |
416 |
|
*/ |
417 |
|
public void testForkJoin() { |
418 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
419 |
< |
public void realCompute() { |
419 |
> |
protected void realCompute() { |
420 |
|
AsyncFib f = new AsyncFib(8); |
421 |
|
assertSame(f, f.fork()); |
422 |
|
assertNull(f.join()); |
431 |
|
*/ |
432 |
|
public void testForkGet() { |
433 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
434 |
< |
public void realCompute() throws Exception { |
434 |
> |
protected void realCompute() throws Exception { |
435 |
|
AsyncFib f = new AsyncFib(8); |
436 |
|
assertSame(f, f.fork()); |
437 |
|
assertNull(f.get()); |
446 |
|
*/ |
447 |
|
public void testForkTimedGet() { |
448 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
449 |
< |
public void realCompute() throws Exception { |
449 |
> |
protected void realCompute() throws Exception { |
450 |
|
AsyncFib f = new AsyncFib(8); |
451 |
|
assertSame(f, f.fork()); |
452 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
461 |
|
*/ |
462 |
|
public void testForkTimedGetNPE() { |
463 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
464 |
< |
public void realCompute() throws Exception { |
464 |
> |
protected void realCompute() throws Exception { |
465 |
|
AsyncFib f = new AsyncFib(8); |
466 |
|
assertSame(f, f.fork()); |
467 |
|
try { |
477 |
|
*/ |
478 |
|
public void testForkQuietlyJoin() { |
479 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
480 |
< |
public void realCompute() { |
480 |
> |
protected void realCompute() { |
481 |
|
AsyncFib f = new AsyncFib(8); |
482 |
|
assertSame(f, f.fork()); |
483 |
|
f.quietlyJoin(); |
487 |
|
testInvokeOnPool(mainPool(), a); |
488 |
|
} |
489 |
|
|
489 |
– |
|
490 |
|
/** |
491 |
|
* helpQuiesce returns when tasks are complete. |
492 |
|
* getQueuedTaskCount returns 0 when quiescent |
493 |
|
*/ |
494 |
|
public void testForkHelpQuiesce() { |
495 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
496 |
< |
public void realCompute() { |
496 |
> |
protected void realCompute() { |
497 |
|
AsyncFib f = new AsyncFib(8); |
498 |
|
assertSame(f, f.fork()); |
499 |
< |
f.helpQuiesce(); |
499 |
> |
helpQuiesce(); |
500 |
|
assertEquals(21, f.number); |
501 |
|
assertEquals(0, getQueuedTaskCount()); |
502 |
|
checkCompletedNormally(f); |
504 |
|
testInvokeOnPool(mainPool(), a); |
505 |
|
} |
506 |
|
|
507 |
– |
|
507 |
|
/** |
508 |
|
* invoke task throws exception when task completes abnormally |
509 |
|
*/ |
510 |
|
public void testAbnormalInvoke() { |
511 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
512 |
< |
public void realCompute() { |
512 |
> |
protected void realCompute() { |
513 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
514 |
|
try { |
515 |
|
f.invoke(); |
526 |
|
*/ |
527 |
|
public void testAbnormalQuietlyInvoke() { |
528 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
529 |
< |
public void realCompute() { |
529 |
> |
protected void realCompute() { |
530 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
531 |
|
f.quietlyInvoke(); |
532 |
|
assertTrue(f.getException() instanceof FJException); |
540 |
|
*/ |
541 |
|
public void testAbnormalForkJoin() { |
542 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
543 |
< |
public void realCompute() { |
543 |
> |
protected void realCompute() { |
544 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
545 |
|
assertSame(f, f.fork()); |
546 |
|
try { |
558 |
|
*/ |
559 |
|
public void testAbnormalForkGet() { |
560 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
561 |
< |
public void realCompute() throws Exception { |
561 |
> |
protected void realCompute() throws Exception { |
562 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
563 |
|
assertSame(f, f.fork()); |
564 |
|
try { |
578 |
|
*/ |
579 |
|
public void testAbnormalForkTimedGet() { |
580 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
581 |
< |
public void realCompute() throws Exception { |
581 |
> |
protected void realCompute() throws Exception { |
582 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
583 |
|
assertSame(f, f.fork()); |
584 |
|
try { |
598 |
|
*/ |
599 |
|
public void testAbnormalForkQuietlyJoin() { |
600 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
601 |
< |
public void realCompute() { |
601 |
> |
protected void realCompute() { |
602 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
603 |
|
assertSame(f, f.fork()); |
604 |
|
f.quietlyJoin(); |
613 |
|
*/ |
614 |
|
public void testCancelledInvoke() { |
615 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
616 |
< |
public void realCompute() { |
616 |
> |
protected void realCompute() { |
617 |
|
AsyncFib f = new AsyncFib(8); |
618 |
|
assertTrue(f.cancel(true)); |
619 |
|
try { |
631 |
|
*/ |
632 |
|
public void testCancelledForkJoin() { |
633 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
634 |
< |
public void realCompute() { |
634 |
> |
protected void realCompute() { |
635 |
|
AsyncFib f = new AsyncFib(8); |
636 |
|
assertTrue(f.cancel(true)); |
637 |
|
assertSame(f, f.fork()); |
650 |
|
*/ |
651 |
|
public void testCancelledForkGet() { |
652 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
653 |
< |
public void realCompute() throws Exception { |
653 |
> |
protected void realCompute() throws Exception { |
654 |
|
AsyncFib f = new AsyncFib(8); |
655 |
|
assertTrue(f.cancel(true)); |
656 |
|
assertSame(f, f.fork()); |
669 |
|
*/ |
670 |
|
public void testCancelledForkTimedGet() throws Exception { |
671 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
672 |
< |
public void realCompute() throws Exception { |
672 |
> |
protected void realCompute() throws Exception { |
673 |
|
AsyncFib f = new AsyncFib(8); |
674 |
|
assertTrue(f.cancel(true)); |
675 |
|
assertSame(f, f.fork()); |
688 |
|
*/ |
689 |
|
public void testCancelledForkQuietlyJoin() { |
690 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
691 |
< |
public void realCompute() { |
691 |
> |
protected void realCompute() { |
692 |
|
AsyncFib f = new AsyncFib(8); |
693 |
|
assertTrue(f.cancel(true)); |
694 |
|
assertSame(f, f.fork()); |
704 |
|
public void testGetPool() { |
705 |
|
final ForkJoinPool mainPool = mainPool(); |
706 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
707 |
< |
public void realCompute() { |
707 |
> |
protected void realCompute() { |
708 |
|
assertSame(mainPool, getPool()); |
709 |
|
}}; |
710 |
|
testInvokeOnPool(mainPool, a); |
715 |
|
*/ |
716 |
|
public void testGetPool2() { |
717 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
718 |
< |
public void realCompute() { |
718 |
> |
protected void realCompute() { |
719 |
|
assertNull(getPool()); |
720 |
|
}}; |
721 |
|
assertNull(a.invoke()); |
726 |
|
*/ |
727 |
|
public void testInForkJoinPool() { |
728 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
729 |
< |
public void realCompute() { |
729 |
> |
protected void realCompute() { |
730 |
|
assertTrue(inForkJoinPool()); |
731 |
|
}}; |
732 |
|
testInvokeOnPool(mainPool(), a); |
737 |
|
*/ |
738 |
|
public void testInForkJoinPool2() { |
739 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
740 |
< |
public void realCompute() { |
740 |
> |
protected void realCompute() { |
741 |
|
assertFalse(inForkJoinPool()); |
742 |
|
}}; |
743 |
|
assertNull(a.invoke()); |
748 |
|
*/ |
749 |
|
public void testSetRawResult() { |
750 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
751 |
< |
public void realCompute() { |
751 |
> |
protected void realCompute() { |
752 |
|
setRawResult(null); |
753 |
|
assertNull(getRawResult()); |
754 |
|
}}; |
760 |
|
*/ |
761 |
|
public void testCompleteExceptionally() { |
762 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
763 |
< |
public void realCompute() { |
763 |
> |
protected void realCompute() { |
764 |
|
AsyncFib f = new AsyncFib(8); |
765 |
|
f.completeExceptionally(new FJException()); |
766 |
|
try { |
778 |
|
*/ |
779 |
|
public void testInvokeAll2() { |
780 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
781 |
< |
public void realCompute() { |
781 |
> |
protected void realCompute() { |
782 |
|
AsyncFib f = new AsyncFib(8); |
783 |
|
AsyncFib g = new AsyncFib(9); |
784 |
|
invokeAll(f, g); |
795 |
|
*/ |
796 |
|
public void testInvokeAll1() { |
797 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
798 |
< |
public void realCompute() { |
798 |
> |
protected void realCompute() { |
799 |
|
AsyncFib f = new AsyncFib(8); |
800 |
|
invokeAll(f); |
801 |
|
checkCompletedNormally(f); |
809 |
|
*/ |
810 |
|
public void testInvokeAll3() { |
811 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
812 |
< |
public void realCompute() { |
812 |
> |
protected void realCompute() { |
813 |
|
AsyncFib f = new AsyncFib(8); |
814 |
|
AsyncFib g = new AsyncFib(9); |
815 |
|
AsyncFib h = new AsyncFib(7); |
829 |
|
*/ |
830 |
|
public void testInvokeAllCollection() { |
831 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
832 |
< |
public void realCompute() { |
832 |
> |
protected void realCompute() { |
833 |
|
AsyncFib f = new AsyncFib(8); |
834 |
|
AsyncFib g = new AsyncFib(9); |
835 |
|
AsyncFib h = new AsyncFib(7); |
848 |
|
testInvokeOnPool(mainPool(), a); |
849 |
|
} |
850 |
|
|
852 |
– |
|
851 |
|
/** |
852 |
|
* invokeAll(tasks) with any null task throws NPE |
853 |
|
*/ |
854 |
|
public void testInvokeAllNPE() { |
855 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
856 |
< |
public void realCompute() { |
856 |
> |
protected void realCompute() { |
857 |
|
AsyncFib f = new AsyncFib(8); |
858 |
|
AsyncFib g = new AsyncFib(9); |
859 |
|
AsyncFib h = null; |
870 |
|
*/ |
871 |
|
public void testAbnormalInvokeAll2() { |
872 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
873 |
< |
public void realCompute() { |
873 |
> |
protected void realCompute() { |
874 |
|
AsyncFib f = new AsyncFib(8); |
875 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
876 |
|
try { |
888 |
|
*/ |
889 |
|
public void testAbnormalInvokeAll1() { |
890 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
891 |
< |
public void realCompute() { |
891 |
> |
protected void realCompute() { |
892 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
893 |
|
try { |
894 |
|
invokeAll(g); |
905 |
|
*/ |
906 |
|
public void testAbnormalInvokeAll3() { |
907 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
908 |
< |
public void realCompute() { |
908 |
> |
protected void realCompute() { |
909 |
|
AsyncFib f = new AsyncFib(8); |
910 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
911 |
|
AsyncFib h = new AsyncFib(7); |
920 |
|
} |
921 |
|
|
922 |
|
/** |
923 |
< |
* invokeAll(collection) throws exception if any task does |
923 |
> |
* invokeAll(collection) throws exception if any task does |
924 |
|
*/ |
925 |
|
public void testAbnormalInvokeAllCollection() { |
926 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
927 |
< |
public void realCompute() { |
927 |
> |
protected void realCompute() { |
928 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
929 |
|
AsyncFib g = new AsyncFib(9); |
930 |
|
AsyncFib h = new AsyncFib(7); |
948 |
|
*/ |
949 |
|
public void testTryUnfork() { |
950 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
951 |
< |
public void realCompute() { |
951 |
> |
protected void realCompute() { |
952 |
|
AsyncFib g = new AsyncFib(9); |
953 |
|
assertSame(g, g.fork()); |
954 |
|
AsyncFib f = new AsyncFib(8); |
967 |
|
*/ |
968 |
|
public void testGetSurplusQueuedTaskCount() { |
969 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
970 |
< |
public void realCompute() { |
970 |
> |
protected void realCompute() { |
971 |
|
AsyncFib h = new AsyncFib(7); |
972 |
|
assertSame(h, h.fork()); |
973 |
|
AsyncFib g = new AsyncFib(9); |
989 |
|
*/ |
990 |
|
public void testPeekNextLocalTask() { |
991 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
992 |
< |
public void realCompute() { |
992 |
> |
protected void realCompute() { |
993 |
|
AsyncFib g = new AsyncFib(9); |
994 |
|
assertSame(g, g.fork()); |
995 |
|
AsyncFib f = new AsyncFib(8); |
1009 |
|
*/ |
1010 |
|
public void testPollNextLocalTask() { |
1011 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1012 |
< |
public void realCompute() { |
1012 |
> |
protected void realCompute() { |
1013 |
|
AsyncFib g = new AsyncFib(9); |
1014 |
|
assertSame(g, g.fork()); |
1015 |
|
AsyncFib f = new AsyncFib(8); |
1028 |
|
*/ |
1029 |
|
public void testPollTask() { |
1030 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1031 |
< |
public void realCompute() { |
1031 |
> |
protected void realCompute() { |
1032 |
|
AsyncFib g = new AsyncFib(9); |
1033 |
|
assertSame(g, g.fork()); |
1034 |
|
AsyncFib f = new AsyncFib(8); |
1046 |
|
*/ |
1047 |
|
public void testPeekNextLocalTaskAsync() { |
1048 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1049 |
< |
public void realCompute() { |
1049 |
> |
protected void realCompute() { |
1050 |
|
AsyncFib g = new AsyncFib(9); |
1051 |
|
assertSame(g, g.fork()); |
1052 |
|
AsyncFib f = new AsyncFib(8); |
1067 |
|
*/ |
1068 |
|
public void testPollNextLocalTaskAsync() { |
1069 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1070 |
< |
public void realCompute() { |
1070 |
> |
protected void realCompute() { |
1071 |
|
AsyncFib g = new AsyncFib(9); |
1072 |
|
assertSame(g, g.fork()); |
1073 |
|
AsyncFib f = new AsyncFib(8); |
1087 |
|
*/ |
1088 |
|
public void testPollTaskAsync() { |
1089 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1090 |
< |
public void realCompute() { |
1090 |
> |
protected void realCompute() { |
1091 |
|
AsyncFib g = new AsyncFib(9); |
1092 |
|
assertSame(g, g.fork()); |
1093 |
|
AsyncFib f = new AsyncFib(8); |
1110 |
|
*/ |
1111 |
|
public void testInvokeSingleton() { |
1112 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1113 |
< |
public void realCompute() { |
1113 |
> |
protected void realCompute() { |
1114 |
|
AsyncFib f = new AsyncFib(8); |
1115 |
|
assertNull(f.invoke()); |
1116 |
|
assertEquals(21, f.number); |
1126 |
|
*/ |
1127 |
|
public void testQuietlyInvokeSingleton() { |
1128 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1129 |
< |
public void realCompute() { |
1129 |
> |
protected void realCompute() { |
1130 |
|
AsyncFib f = new AsyncFib(8); |
1131 |
|
f.quietlyInvoke(); |
1132 |
|
assertEquals(21, f.number); |
1140 |
|
*/ |
1141 |
|
public void testForkJoinSingleton() { |
1142 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1143 |
< |
public void realCompute() { |
1143 |
> |
protected void realCompute() { |
1144 |
|
AsyncFib f = new AsyncFib(8); |
1145 |
|
assertSame(f, f.fork()); |
1146 |
|
assertNull(f.join()); |
1155 |
|
*/ |
1156 |
|
public void testForkGetSingleton() { |
1157 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1158 |
< |
public void realCompute() throws Exception { |
1158 |
> |
protected void realCompute() throws Exception { |
1159 |
|
AsyncFib f = new AsyncFib(8); |
1160 |
|
assertSame(f, f.fork()); |
1161 |
|
assertNull(f.get()); |
1170 |
|
*/ |
1171 |
|
public void testForkTimedGetSingleton() { |
1172 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1173 |
< |
public void realCompute() throws Exception { |
1173 |
> |
protected void realCompute() throws Exception { |
1174 |
|
AsyncFib f = new AsyncFib(8); |
1175 |
|
assertSame(f, f.fork()); |
1176 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1185 |
|
*/ |
1186 |
|
public void testForkTimedGetNPESingleton() { |
1187 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1188 |
< |
public void realCompute() throws Exception { |
1188 |
> |
protected void realCompute() throws Exception { |
1189 |
|
AsyncFib f = new AsyncFib(8); |
1190 |
|
assertSame(f, f.fork()); |
1191 |
|
try { |
1201 |
|
*/ |
1202 |
|
public void testForkQuietlyJoinSingleton() { |
1203 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1204 |
< |
public void realCompute() { |
1204 |
> |
protected void realCompute() { |
1205 |
|
AsyncFib f = new AsyncFib(8); |
1206 |
|
assertSame(f, f.fork()); |
1207 |
|
f.quietlyJoin(); |
1211 |
|
testInvokeOnPool(singletonPool(), a); |
1212 |
|
} |
1213 |
|
|
1216 |
– |
|
1214 |
|
/** |
1215 |
|
* helpQuiesce returns when tasks are complete. |
1216 |
|
* getQueuedTaskCount returns 0 when quiescent |
1217 |
|
*/ |
1218 |
|
public void testForkHelpQuiesceSingleton() { |
1219 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1220 |
< |
public void realCompute() { |
1220 |
> |
protected void realCompute() { |
1221 |
|
AsyncFib f = new AsyncFib(8); |
1222 |
|
assertSame(f, f.fork()); |
1223 |
< |
f.helpQuiesce(); |
1223 |
> |
helpQuiesce(); |
1224 |
|
assertEquals(0, getQueuedTaskCount()); |
1225 |
|
assertEquals(21, f.number); |
1226 |
|
checkCompletedNormally(f); |
1228 |
|
testInvokeOnPool(singletonPool(), a); |
1229 |
|
} |
1230 |
|
|
1234 |
– |
|
1231 |
|
/** |
1232 |
|
* invoke task throws exception when task completes abnormally |
1233 |
|
*/ |
1234 |
|
public void testAbnormalInvokeSingleton() { |
1235 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1236 |
< |
public void realCompute() { |
1236 |
> |
protected void realCompute() { |
1237 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1238 |
|
try { |
1239 |
|
f.invoke(); |
1250 |
|
*/ |
1251 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1252 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1253 |
< |
public void realCompute() { |
1253 |
> |
protected void realCompute() { |
1254 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1255 |
|
f.quietlyInvoke(); |
1256 |
|
assertTrue(f.getException() instanceof FJException); |
1264 |
|
*/ |
1265 |
|
public void testAbnormalForkJoinSingleton() { |
1266 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1267 |
< |
public void realCompute() { |
1267 |
> |
protected void realCompute() { |
1268 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1269 |
|
assertSame(f, f.fork()); |
1270 |
|
try { |
1282 |
|
*/ |
1283 |
|
public void testAbnormalForkGetSingleton() { |
1284 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1285 |
< |
public void realCompute() throws Exception { |
1285 |
> |
protected void realCompute() throws Exception { |
1286 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1287 |
|
assertSame(f, f.fork()); |
1288 |
|
try { |
1302 |
|
*/ |
1303 |
|
public void testAbnormalForkTimedGetSingleton() { |
1304 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1305 |
< |
public void realCompute() throws Exception { |
1305 |
> |
protected void realCompute() throws Exception { |
1306 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1307 |
|
assertSame(f, f.fork()); |
1308 |
|
try { |
1322 |
|
*/ |
1323 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1324 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1325 |
< |
public void realCompute() { |
1325 |
> |
protected void realCompute() { |
1326 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1327 |
|
assertSame(f, f.fork()); |
1328 |
|
f.quietlyJoin(); |
1337 |
|
*/ |
1338 |
|
public void testCancelledInvokeSingleton() { |
1339 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1340 |
< |
public void realCompute() { |
1340 |
> |
protected void realCompute() { |
1341 |
|
AsyncFib f = new AsyncFib(8); |
1342 |
|
assertTrue(f.cancel(true)); |
1343 |
|
try { |
1355 |
|
*/ |
1356 |
|
public void testCancelledForkJoinSingleton() { |
1357 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1358 |
< |
public void realCompute() { |
1358 |
> |
protected void realCompute() { |
1359 |
|
AsyncFib f = new AsyncFib(8); |
1360 |
|
assertTrue(f.cancel(true)); |
1361 |
|
assertSame(f, f.fork()); |
1374 |
|
*/ |
1375 |
|
public void testCancelledForkGetSingleton() { |
1376 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1377 |
< |
public void realCompute() throws Exception { |
1377 |
> |
protected void realCompute() throws Exception { |
1378 |
|
AsyncFib f = new AsyncFib(8); |
1379 |
|
assertTrue(f.cancel(true)); |
1380 |
|
assertSame(f, f.fork()); |
1393 |
|
*/ |
1394 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1395 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1396 |
< |
public void realCompute() throws Exception { |
1396 |
> |
protected void realCompute() throws Exception { |
1397 |
|
AsyncFib f = new AsyncFib(8); |
1398 |
|
assertTrue(f.cancel(true)); |
1399 |
|
assertSame(f, f.fork()); |
1412 |
|
*/ |
1413 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1414 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1415 |
< |
public void realCompute() { |
1415 |
> |
protected void realCompute() { |
1416 |
|
AsyncFib f = new AsyncFib(8); |
1417 |
|
assertTrue(f.cancel(true)); |
1418 |
|
assertSame(f, f.fork()); |
1427 |
|
*/ |
1428 |
|
public void testCompleteExceptionallySingleton() { |
1429 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1430 |
< |
public void realCompute() { |
1430 |
> |
protected void realCompute() { |
1431 |
|
AsyncFib f = new AsyncFib(8); |
1432 |
|
f.completeExceptionally(new FJException()); |
1433 |
|
try { |
1445 |
|
*/ |
1446 |
|
public void testInvokeAll2Singleton() { |
1447 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1448 |
< |
public void realCompute() { |
1448 |
> |
protected void realCompute() { |
1449 |
|
AsyncFib f = new AsyncFib(8); |
1450 |
|
AsyncFib g = new AsyncFib(9); |
1451 |
|
invokeAll(f, g); |
1462 |
|
*/ |
1463 |
|
public void testInvokeAll1Singleton() { |
1464 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1465 |
< |
public void realCompute() { |
1465 |
> |
protected void realCompute() { |
1466 |
|
AsyncFib f = new AsyncFib(8); |
1467 |
|
invokeAll(f); |
1468 |
|
checkCompletedNormally(f); |
1476 |
|
*/ |
1477 |
|
public void testInvokeAll3Singleton() { |
1478 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1479 |
< |
public void realCompute() { |
1479 |
> |
protected void realCompute() { |
1480 |
|
AsyncFib f = new AsyncFib(8); |
1481 |
|
AsyncFib g = new AsyncFib(9); |
1482 |
|
AsyncFib h = new AsyncFib(7); |
1496 |
|
*/ |
1497 |
|
public void testInvokeAllCollectionSingleton() { |
1498 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1499 |
< |
public void realCompute() { |
1499 |
> |
protected void realCompute() { |
1500 |
|
AsyncFib f = new AsyncFib(8); |
1501 |
|
AsyncFib g = new AsyncFib(9); |
1502 |
|
AsyncFib h = new AsyncFib(7); |
1515 |
|
testInvokeOnPool(singletonPool(), a); |
1516 |
|
} |
1517 |
|
|
1522 |
– |
|
1518 |
|
/** |
1519 |
|
* invokeAll(tasks) with any null task throws NPE |
1520 |
|
*/ |
1521 |
|
public void testInvokeAllNPESingleton() { |
1522 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1523 |
< |
public void realCompute() { |
1523 |
> |
protected void realCompute() { |
1524 |
|
AsyncFib f = new AsyncFib(8); |
1525 |
|
AsyncFib g = new AsyncFib(9); |
1526 |
|
AsyncFib h = null; |
1537 |
|
*/ |
1538 |
|
public void testAbnormalInvokeAll2Singleton() { |
1539 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1540 |
< |
public void realCompute() { |
1540 |
> |
protected void realCompute() { |
1541 |
|
AsyncFib f = new AsyncFib(8); |
1542 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1543 |
|
try { |
1555 |
|
*/ |
1556 |
|
public void testAbnormalInvokeAll1Singleton() { |
1557 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1558 |
< |
public void realCompute() { |
1558 |
> |
protected void realCompute() { |
1559 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1560 |
|
try { |
1561 |
|
invokeAll(g); |
1572 |
|
*/ |
1573 |
|
public void testAbnormalInvokeAll3Singleton() { |
1574 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1575 |
< |
public void realCompute() { |
1575 |
> |
protected void realCompute() { |
1576 |
|
AsyncFib f = new AsyncFib(8); |
1577 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1578 |
|
AsyncFib h = new AsyncFib(7); |
1587 |
|
} |
1588 |
|
|
1589 |
|
/** |
1590 |
< |
* invokeAll(collection) throws exception if any task does |
1590 |
> |
* invokeAll(collection) throws exception if any task does |
1591 |
|
*/ |
1592 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1593 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1594 |
< |
public void realCompute() { |
1594 |
> |
protected void realCompute() { |
1595 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1596 |
|
AsyncFib g = new AsyncFib(9); |
1597 |
|
AsyncFib h = new AsyncFib(7); |
1609 |
|
testInvokeOnPool(singletonPool(), a); |
1610 |
|
} |
1611 |
|
|
1612 |
+ |
/** |
1613 |
+ |
* ForkJoinTask.quietlyComplete returns when task completes |
1614 |
+ |
* normally without setting a value. The most recent value |
1615 |
+ |
* established by setRawResult(V) (or null by default) is returned |
1616 |
+ |
* from invoke. |
1617 |
+ |
*/ |
1618 |
+ |
public void testQuietlyComplete() { |
1619 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1620 |
+ |
protected void realCompute() { |
1621 |
+ |
AsyncFib f = new AsyncFib(8); |
1622 |
+ |
f.quietlyComplete(); |
1623 |
+ |
assertEquals(8, f.number); |
1624 |
+ |
checkCompletedNormally(f); |
1625 |
+ |
}}; |
1626 |
+ |
testInvokeOnPool(mainPool(), a); |
1627 |
+ |
} |
1628 |
+ |
|
1629 |
|
} |