185 |
|
final int number; |
186 |
|
int result; |
187 |
|
FibAction(int n) { number = n; } |
188 |
< |
public void realCompute() { |
188 |
> |
protected void realCompute() { |
189 |
|
int n = number; |
190 |
|
if (n <= 1) |
191 |
|
result = n; |
223 |
|
*/ |
224 |
|
public void testInvoke() { |
225 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
226 |
< |
public void realCompute() { |
226 |
> |
protected void realCompute() { |
227 |
|
FibAction f = new FibAction(8); |
228 |
|
assertNull(f.invoke()); |
229 |
|
assertEquals(21, f.result); |
239 |
|
*/ |
240 |
|
public void testQuietlyInvoke() { |
241 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
242 |
< |
public void realCompute() { |
242 |
> |
protected void realCompute() { |
243 |
|
FibAction f = new FibAction(8); |
244 |
|
f.quietlyInvoke(); |
245 |
|
assertEquals(21, f.result); |
253 |
|
*/ |
254 |
|
public void testForkJoin() { |
255 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
256 |
< |
public void realCompute() { |
256 |
> |
protected void realCompute() { |
257 |
|
FibAction f = new FibAction(8); |
258 |
|
assertSame(f, f.fork()); |
259 |
|
assertNull(f.join()); |
268 |
|
*/ |
269 |
|
public void testJoinIgnoresInterrupts() { |
270 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
271 |
< |
public void realCompute() { |
271 |
> |
protected void realCompute() { |
272 |
|
FibAction f = new FibAction(8); |
273 |
|
final Thread myself = Thread.currentThread(); |
274 |
|
|
340 |
|
checkInvoke(a); |
341 |
|
} |
342 |
|
|
343 |
– |
|
343 |
|
/** |
344 |
|
* get of a forked task returns when task completes |
345 |
|
*/ |
346 |
|
public void testForkGet() { |
347 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
348 |
< |
public void realCompute() throws Exception { |
348 |
> |
protected void realCompute() throws Exception { |
349 |
|
FibAction f = new FibAction(8); |
350 |
|
assertSame(f, f.fork()); |
351 |
|
assertNull(f.get()); |
360 |
|
*/ |
361 |
|
public void testForkTimedGet() { |
362 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
363 |
< |
public void realCompute() throws Exception { |
363 |
> |
protected void realCompute() throws Exception { |
364 |
|
FibAction f = new FibAction(8); |
365 |
|
assertSame(f, f.fork()); |
366 |
|
assertNull(f.get(5L, SECONDS)); |
375 |
|
*/ |
376 |
|
public void testForkTimedGetNPE() { |
377 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
378 |
< |
public void realCompute() throws Exception { |
378 |
> |
protected void realCompute() throws Exception { |
379 |
|
FibAction f = new FibAction(8); |
380 |
|
assertSame(f, f.fork()); |
381 |
|
try { |
391 |
|
*/ |
392 |
|
public void testForkQuietlyJoin() { |
393 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
394 |
< |
public void realCompute() { |
394 |
> |
protected void realCompute() { |
395 |
|
FibAction f = new FibAction(8); |
396 |
|
assertSame(f, f.fork()); |
397 |
|
f.quietlyJoin(); |
406 |
|
*/ |
407 |
|
public void testAbnormalInvoke() { |
408 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
409 |
< |
public void realCompute() { |
409 |
> |
protected void realCompute() { |
410 |
|
FailingFibAction f = new FailingFibAction(8); |
411 |
|
try { |
412 |
|
f.invoke(); |
423 |
|
*/ |
424 |
|
public void testAbnormalQuietlyInvoke() { |
425 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
426 |
< |
public void realCompute() { |
426 |
> |
protected void realCompute() { |
427 |
|
FailingFibAction f = new FailingFibAction(8); |
428 |
|
f.quietlyInvoke(); |
429 |
|
assertTrue(f.getException() instanceof FJException); |
437 |
|
*/ |
438 |
|
public void testAbnormalForkJoin() { |
439 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
440 |
< |
public void realCompute() { |
440 |
> |
protected void realCompute() { |
441 |
|
FailingFibAction f = new FailingFibAction(8); |
442 |
|
assertSame(f, f.fork()); |
443 |
|
try { |
455 |
|
*/ |
456 |
|
public void testAbnormalForkGet() { |
457 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
458 |
< |
public void realCompute() throws Exception { |
458 |
> |
protected void realCompute() throws Exception { |
459 |
|
FailingFibAction f = new FailingFibAction(8); |
460 |
|
assertSame(f, f.fork()); |
461 |
|
try { |
475 |
|
*/ |
476 |
|
public void testAbnormalForkTimedGet() { |
477 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
478 |
< |
public void realCompute() throws Exception { |
478 |
> |
protected void realCompute() throws Exception { |
479 |
|
FailingFibAction f = new FailingFibAction(8); |
480 |
|
assertSame(f, f.fork()); |
481 |
|
try { |
495 |
|
*/ |
496 |
|
public void testAbnormalForkQuietlyJoin() { |
497 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
498 |
< |
public void realCompute() { |
498 |
> |
protected void realCompute() { |
499 |
|
FailingFibAction f = new FailingFibAction(8); |
500 |
|
assertSame(f, f.fork()); |
501 |
|
f.quietlyJoin(); |
510 |
|
*/ |
511 |
|
public void testCancelledInvoke() { |
512 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
513 |
< |
public void realCompute() { |
513 |
> |
protected void realCompute() { |
514 |
|
FibAction f = new FibAction(8); |
515 |
|
assertTrue(f.cancel(true)); |
516 |
|
try { |
528 |
|
*/ |
529 |
|
public void testCancelledForkJoin() { |
530 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
531 |
< |
public void realCompute() { |
531 |
> |
protected void realCompute() { |
532 |
|
FibAction f = new FibAction(8); |
533 |
|
assertTrue(f.cancel(true)); |
534 |
|
assertSame(f, f.fork()); |
547 |
|
*/ |
548 |
|
public void testCancelledForkGet() { |
549 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
550 |
< |
public void realCompute() throws Exception { |
550 |
> |
protected void realCompute() throws Exception { |
551 |
|
FibAction f = new FibAction(8); |
552 |
|
assertTrue(f.cancel(true)); |
553 |
|
assertSame(f, f.fork()); |
566 |
|
*/ |
567 |
|
public void testCancelledForkTimedGet() { |
568 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
569 |
< |
public void realCompute() throws Exception { |
569 |
> |
protected void realCompute() throws Exception { |
570 |
|
FibAction f = new FibAction(8); |
571 |
|
assertTrue(f.cancel(true)); |
572 |
|
assertSame(f, f.fork()); |
585 |
|
*/ |
586 |
|
public void testCancelledForkQuietlyJoin() { |
587 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
588 |
< |
public void realCompute() { |
588 |
> |
protected void realCompute() { |
589 |
|
FibAction f = new FibAction(8); |
590 |
|
assertTrue(f.cancel(true)); |
591 |
|
assertSame(f, f.fork()); |
600 |
|
*/ |
601 |
|
public void testInForkJoinPool2() { |
602 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
603 |
< |
public void realCompute() { |
603 |
> |
protected void realCompute() { |
604 |
|
assertFalse(inForkJoinPool()); |
605 |
|
}}; |
606 |
|
assertNull(a.invoke()); |
611 |
|
*/ |
612 |
|
public void testReinitialize() { |
613 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
614 |
< |
public void realCompute() { |
614 |
> |
protected void realCompute() { |
615 |
|
FibAction f = new FibAction(8); |
616 |
|
checkNotDone(f); |
617 |
|
|
631 |
|
*/ |
632 |
|
public void testReinitializeAbnormal() { |
633 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
634 |
< |
public void realCompute() { |
634 |
> |
protected void realCompute() { |
635 |
|
FailingFibAction f = new FailingFibAction(8); |
636 |
|
checkNotDone(f); |
637 |
|
|
654 |
|
*/ |
655 |
|
public void testCompleteExceptionally() { |
656 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
657 |
< |
public void realCompute() { |
657 |
> |
protected void realCompute() { |
658 |
|
FibAction f = new FibAction(8); |
659 |
|
f.completeExceptionally(new FJException()); |
660 |
|
try { |
672 |
|
*/ |
673 |
|
public void testComplete() { |
674 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
675 |
< |
public void realCompute() { |
675 |
> |
protected void realCompute() { |
676 |
|
FibAction f = new FibAction(8); |
677 |
|
f.complete(null); |
678 |
|
assertNull(f.invoke()); |
687 |
|
*/ |
688 |
|
public void testInvokeAll2() { |
689 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
690 |
< |
public void realCompute() { |
690 |
> |
protected void realCompute() { |
691 |
|
FibAction f = new FibAction(8); |
692 |
|
FibAction g = new FibAction(9); |
693 |
|
invokeAll(f, g); |
704 |
|
*/ |
705 |
|
public void testInvokeAll1() { |
706 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
707 |
< |
public void realCompute() { |
707 |
> |
protected void realCompute() { |
708 |
|
FibAction f = new FibAction(8); |
709 |
|
invokeAll(f); |
710 |
|
checkCompletedNormally(f); |
718 |
|
*/ |
719 |
|
public void testInvokeAll3() { |
720 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
721 |
< |
public void realCompute() { |
721 |
> |
protected void realCompute() { |
722 |
|
FibAction f = new FibAction(8); |
723 |
|
FibAction g = new FibAction(9); |
724 |
|
FibAction h = new FibAction(7); |
741 |
|
*/ |
742 |
|
public void testInvokeAllCollection() { |
743 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
744 |
< |
public void realCompute() { |
744 |
> |
protected void realCompute() { |
745 |
|
FibAction f = new FibAction(8); |
746 |
|
FibAction g = new FibAction(9); |
747 |
|
FibAction h = new FibAction(7); |
768 |
|
*/ |
769 |
|
public void testInvokeAllNPE() { |
770 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
771 |
< |
public void realCompute() { |
771 |
> |
protected void realCompute() { |
772 |
|
FibAction f = new FibAction(8); |
773 |
|
FibAction g = new FibAction(9); |
774 |
|
FibAction h = null; |
785 |
|
*/ |
786 |
|
public void testAbnormalInvokeAll2() { |
787 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
788 |
< |
public void realCompute() { |
788 |
> |
protected void realCompute() { |
789 |
|
FibAction f = new FibAction(8); |
790 |
|
FailingFibAction g = new FailingFibAction(9); |
791 |
|
try { |
803 |
|
*/ |
804 |
|
public void testAbnormalInvokeAll1() { |
805 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
806 |
< |
public void realCompute() { |
806 |
> |
protected void realCompute() { |
807 |
|
FailingFibAction g = new FailingFibAction(9); |
808 |
|
try { |
809 |
|
invokeAll(g); |
820 |
|
*/ |
821 |
|
public void testAbnormalInvokeAll3() { |
822 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
823 |
< |
public void realCompute() { |
823 |
> |
protected void realCompute() { |
824 |
|
FibAction f = new FibAction(8); |
825 |
|
FailingFibAction g = new FailingFibAction(9); |
826 |
|
FibAction h = new FibAction(7); |
839 |
|
*/ |
840 |
|
public void testAbnormalInvokeAllCollection() { |
841 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
842 |
< |
public void realCompute() { |
842 |
> |
protected void realCompute() { |
843 |
|
FailingFibAction f = new FailingFibAction(8); |
844 |
|
FibAction g = new FibAction(9); |
845 |
|
FibAction h = new FibAction(7); |
859 |
|
|
860 |
|
// CountedCompleter versions |
861 |
|
|
863 |
– |
public abstract class CheckedFJTask extends RecursiveAction { |
864 |
– |
protected abstract void realCompute() throws Throwable; |
865 |
– |
|
866 |
– |
public final void compute() { |
867 |
– |
try { |
868 |
– |
realCompute(); |
869 |
– |
} catch (Throwable t) { |
870 |
– |
threadUnexpectedException(t); |
871 |
– |
} |
872 |
– |
} |
873 |
– |
} |
874 |
– |
|
862 |
|
abstract static class CCF extends CountedCompleter { |
863 |
|
int number; |
864 |
|
int rnumber; |
967 |
|
* completed tasks; getRawResult returns null. |
968 |
|
*/ |
969 |
|
public void testInvokeCC() { |
970 |
< |
ForkJoinTask a = new CheckedFJTask() { |
971 |
< |
public void realCompute() { |
970 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
971 |
> |
protected void realCompute() { |
972 |
|
CCF f = new LCCF(null, 8); |
973 |
|
assertNull(f.invoke()); |
974 |
|
assertEquals(21, f.number); |
983 |
|
* completed tasks |
984 |
|
*/ |
985 |
|
public void testQuietlyInvokeCC() { |
986 |
< |
ForkJoinTask a = new CheckedFJTask() { |
987 |
< |
public void realCompute() { |
986 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
987 |
> |
protected void realCompute() { |
988 |
|
CCF f = new LCCF(null, 8); |
989 |
|
f.quietlyInvoke(); |
990 |
|
assertEquals(21, f.number); |
997 |
|
* join of a forked task returns when task completes |
998 |
|
*/ |
999 |
|
public void testForkJoinCC() { |
1000 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1001 |
< |
public void realCompute() { |
1000 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1001 |
> |
protected void realCompute() { |
1002 |
|
CCF f = new LCCF(null, 8); |
1003 |
|
assertSame(f, f.fork()); |
1004 |
|
assertNull(f.join()); |
1012 |
|
* get of a forked task returns when task completes |
1013 |
|
*/ |
1014 |
|
public void testForkGetCC() { |
1015 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1016 |
< |
public void realCompute() throws Exception { |
1015 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1016 |
> |
protected void realCompute() throws Exception { |
1017 |
|
CCF f = new LCCF(null, 8); |
1018 |
|
assertSame(f, f.fork()); |
1019 |
|
assertNull(f.get()); |
1027 |
|
* timed get of a forked task returns when task completes |
1028 |
|
*/ |
1029 |
|
public void testForkTimedGetCC() { |
1030 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1031 |
< |
public void realCompute() throws Exception { |
1030 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1031 |
> |
protected void realCompute() throws Exception { |
1032 |
|
CCF f = new LCCF(null, 8); |
1033 |
|
assertSame(f, f.fork()); |
1034 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1042 |
|
* timed get with null time unit throws NPE |
1043 |
|
*/ |
1044 |
|
public void testForkTimedGetNPECC() { |
1045 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1046 |
< |
public void realCompute() throws Exception { |
1045 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1046 |
> |
protected void realCompute() throws Exception { |
1047 |
|
CCF f = new LCCF(null, 8); |
1048 |
|
assertSame(f, f.fork()); |
1049 |
|
try { |
1058 |
|
* quietlyJoin of a forked task returns when task completes |
1059 |
|
*/ |
1060 |
|
public void testForkQuietlyJoinCC() { |
1061 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1062 |
< |
public void realCompute() { |
1061 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1062 |
> |
protected void realCompute() { |
1063 |
|
CCF f = new LCCF(null, 8); |
1064 |
|
assertSame(f, f.fork()); |
1065 |
|
f.quietlyJoin(); |
1073 |
|
* invoke task throws exception when task completes abnormally |
1074 |
|
*/ |
1075 |
|
public void testAbnormalInvokeCC() { |
1076 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1077 |
< |
public void realCompute() { |
1076 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1077 |
> |
protected void realCompute() { |
1078 |
|
FailingCCF f = new LFCCF(null, 8); |
1079 |
|
try { |
1080 |
|
f.invoke(); |
1090 |
|
* quietlyInvoke task returns when task completes abnormally |
1091 |
|
*/ |
1092 |
|
public void testAbnormalQuietlyInvokeCC() { |
1093 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1094 |
< |
public void realCompute() { |
1093 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1094 |
> |
protected void realCompute() { |
1095 |
|
FailingCCF f = new LFCCF(null, 8); |
1096 |
|
f.quietlyInvoke(); |
1097 |
|
assertTrue(f.getException() instanceof FJException); |
1104 |
|
* join of a forked task throws exception when task completes abnormally |
1105 |
|
*/ |
1106 |
|
public void testAbnormalForkJoinCC() { |
1107 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1108 |
< |
public void realCompute() { |
1107 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1108 |
> |
protected void realCompute() { |
1109 |
|
FailingCCF f = new LFCCF(null, 8); |
1110 |
|
assertSame(f, f.fork()); |
1111 |
|
try { |
1122 |
|
* get of a forked task throws exception when task completes abnormally |
1123 |
|
*/ |
1124 |
|
public void testAbnormalForkGetCC() { |
1125 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1126 |
< |
public void realCompute() throws Exception { |
1125 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1126 |
> |
protected void realCompute() throws Exception { |
1127 |
|
FailingCCF f = new LFCCF(null, 8); |
1128 |
|
assertSame(f, f.fork()); |
1129 |
|
try { |
1142 |
|
* timed get of a forked task throws exception when task completes abnormally |
1143 |
|
*/ |
1144 |
|
public void testAbnormalForkTimedGetCC() { |
1145 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1146 |
< |
public void realCompute() throws Exception { |
1145 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1146 |
> |
protected void realCompute() throws Exception { |
1147 |
|
FailingCCF f = new LFCCF(null, 8); |
1148 |
|
assertSame(f, f.fork()); |
1149 |
|
try { |
1162 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
1163 |
|
*/ |
1164 |
|
public void testAbnormalForkQuietlyJoinCC() { |
1165 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1166 |
< |
public void realCompute() { |
1165 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1166 |
> |
protected void realCompute() { |
1167 |
|
FailingCCF f = new LFCCF(null, 8); |
1168 |
|
assertSame(f, f.fork()); |
1169 |
|
f.quietlyJoin(); |
1177 |
|
* invoke task throws exception when task cancelled |
1178 |
|
*/ |
1179 |
|
public void testCancelledInvokeCC() { |
1180 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1181 |
< |
public void realCompute() { |
1180 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1181 |
> |
protected void realCompute() { |
1182 |
|
CCF f = new LCCF(null, 8); |
1183 |
|
assertTrue(f.cancel(true)); |
1184 |
|
try { |
1195 |
|
* join of a forked task throws exception when task cancelled |
1196 |
|
*/ |
1197 |
|
public void testCancelledForkJoinCC() { |
1198 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1199 |
< |
public void realCompute() { |
1198 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1199 |
> |
protected void realCompute() { |
1200 |
|
CCF f = new LCCF(null, 8); |
1201 |
|
assertTrue(f.cancel(true)); |
1202 |
|
assertSame(f, f.fork()); |
1214 |
|
* get of a forked task throws exception when task cancelled |
1215 |
|
*/ |
1216 |
|
public void testCancelledForkGetCC() { |
1217 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1218 |
< |
public void realCompute() throws Exception { |
1217 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1218 |
> |
protected void realCompute() throws Exception { |
1219 |
|
CCF f = new LCCF(null, 8); |
1220 |
|
assertTrue(f.cancel(true)); |
1221 |
|
assertSame(f, f.fork()); |
1233 |
|
* timed get of a forked task throws exception when task cancelled |
1234 |
|
*/ |
1235 |
|
public void testCancelledForkTimedGetCC() throws Exception { |
1236 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1237 |
< |
public void realCompute() throws Exception { |
1236 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1237 |
> |
protected void realCompute() throws Exception { |
1238 |
|
CCF f = new LCCF(null, 8); |
1239 |
|
assertTrue(f.cancel(true)); |
1240 |
|
assertSame(f, f.fork()); |
1252 |
|
* quietlyJoin of a forked task returns when task cancelled |
1253 |
|
*/ |
1254 |
|
public void testCancelledForkQuietlyJoinCC() { |
1255 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1256 |
< |
public void realCompute() { |
1255 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1256 |
> |
protected void realCompute() { |
1257 |
|
CCF f = new LCCF(null, 8); |
1258 |
|
assertTrue(f.cancel(true)); |
1259 |
|
assertSame(f, f.fork()); |
1267 |
|
* getPool of non-FJ task returns null |
1268 |
|
*/ |
1269 |
|
public void testGetPool2CC() { |
1270 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1271 |
< |
public void realCompute() { |
1270 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1271 |
> |
protected void realCompute() { |
1272 |
|
assertNull(getPool()); |
1273 |
|
}}; |
1274 |
|
assertNull(a.invoke()); |
1278 |
|
* inForkJoinPool of non-FJ task returns false |
1279 |
|
*/ |
1280 |
|
public void testInForkJoinPool2CC() { |
1281 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1282 |
< |
public void realCompute() { |
1281 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1282 |
> |
protected void realCompute() { |
1283 |
|
assertFalse(inForkJoinPool()); |
1284 |
|
}}; |
1285 |
|
assertNull(a.invoke()); |
1289 |
|
* setRawResult(null) succeeds |
1290 |
|
*/ |
1291 |
|
public void testSetRawResultCC() { |
1292 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1293 |
< |
public void realCompute() { |
1292 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1293 |
> |
protected void realCompute() { |
1294 |
|
setRawResult(null); |
1295 |
|
assertNull(getRawResult()); |
1296 |
|
}}; |
1301 |
|
* invoke task throws exception after invoking completeExceptionally |
1302 |
|
*/ |
1303 |
|
public void testCompleteExceptionally2CC() { |
1304 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1305 |
< |
public void realCompute() { |
1304 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1305 |
> |
protected void realCompute() { |
1306 |
|
CCF f = new LCCF(null, 8); |
1307 |
|
f.completeExceptionally(new FJException()); |
1308 |
|
try { |
1319 |
|
* invokeAll(t1, t2) invokes all task arguments |
1320 |
|
*/ |
1321 |
|
public void testInvokeAll2CC() { |
1322 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1323 |
< |
public void realCompute() { |
1322 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1323 |
> |
protected void realCompute() { |
1324 |
|
CCF f = new LCCF(null, 8); |
1325 |
|
CCF g = new LCCF(null, 9); |
1326 |
|
invokeAll(f, g); |
1336 |
|
* invokeAll(tasks) with 1 argument invokes task |
1337 |
|
*/ |
1338 |
|
public void testInvokeAll1CC() { |
1339 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1340 |
< |
public void realCompute() { |
1339 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1340 |
> |
protected void realCompute() { |
1341 |
|
CCF f = new LCCF(null, 8); |
1342 |
|
invokeAll(f); |
1343 |
|
checkCompletedNormally(f); |
1350 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1351 |
|
*/ |
1352 |
|
public void testInvokeAll3CC() { |
1353 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1354 |
< |
public void realCompute() { |
1353 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1354 |
> |
protected void realCompute() { |
1355 |
|
CCF f = new LCCF(null, 8); |
1356 |
|
CCF g = new LCCF(null, 9); |
1357 |
|
CCF h = new LCCF(null, 7); |
1370 |
|
* invokeAll(collection) invokes all tasks in the collection |
1371 |
|
*/ |
1372 |
|
public void testInvokeAllCollectionCC() { |
1373 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1374 |
< |
public void realCompute() { |
1373 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1374 |
> |
protected void realCompute() { |
1375 |
|
CCF f = new LCCF(null, 8); |
1376 |
|
CCF g = new LCCF(null, 9); |
1377 |
|
CCF h = new LCCF(null, 7); |
1394 |
|
* invokeAll(tasks) with any null task throws NPE |
1395 |
|
*/ |
1396 |
|
public void testInvokeAllNPECC() { |
1397 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1398 |
< |
public void realCompute() { |
1397 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1398 |
> |
protected void realCompute() { |
1399 |
|
CCF f = new LCCF(null, 8); |
1400 |
|
CCF g = new LCCF(null, 9); |
1401 |
|
CCF h = null; |
1411 |
|
* invokeAll(t1, t2) throw exception if any task does |
1412 |
|
*/ |
1413 |
|
public void testAbnormalInvokeAll2CC() { |
1414 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1415 |
< |
public void realCompute() { |
1414 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1415 |
> |
protected void realCompute() { |
1416 |
|
CCF f = new LCCF(null, 8); |
1417 |
|
FailingCCF g = new LFCCF(null, 9); |
1418 |
|
try { |
1429 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1430 |
|
*/ |
1431 |
|
public void testAbnormalInvokeAll1CC() { |
1432 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1433 |
< |
public void realCompute() { |
1432 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1433 |
> |
protected void realCompute() { |
1434 |
|
FailingCCF g = new LFCCF(null, 9); |
1435 |
|
try { |
1436 |
|
invokeAll(g); |
1446 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1447 |
|
*/ |
1448 |
|
public void testAbnormalInvokeAll3CC() { |
1449 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1450 |
< |
public void realCompute() { |
1449 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1450 |
> |
protected void realCompute() { |
1451 |
|
CCF f = new LCCF(null, 8); |
1452 |
|
FailingCCF g = new LFCCF(null, 9); |
1453 |
|
CCF h = new LCCF(null, 7); |
1462 |
|
} |
1463 |
|
|
1464 |
|
/** |
1465 |
< |
* invokeAll(collection) throws exception if any task does |
1465 |
> |
* invokeAll(collection) throws exception if any task does |
1466 |
|
*/ |
1467 |
|
public void testAbnormalInvokeAllCollectionCC() { |
1468 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1469 |
< |
public void realCompute() { |
1468 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1469 |
> |
protected void realCompute() { |
1470 |
|
FailingCCF f = new LFCCF(null, 8); |
1471 |
|
CCF g = new LCCF(null, 9); |
1472 |
|
CCF h = new LCCF(null, 7); |
1484 |
|
checkInvoke(a); |
1485 |
|
} |
1486 |
|
|
1487 |
+ |
/** |
1488 |
+ |
* awaitQuiescence by a worker is equivalent in effect to |
1489 |
+ |
* ForkJoinTask.helpQuiesce() |
1490 |
+ |
*/ |
1491 |
+ |
public void testAwaitQuiescence1() throws Exception { |
1492 |
+ |
final ForkJoinPool p = new ForkJoinPool(); |
1493 |
+ |
try { |
1494 |
+ |
final long startTime = System.nanoTime(); |
1495 |
+ |
assertTrue(p.isQuiescent()); |
1496 |
+ |
ForkJoinTask a = new CheckedRecursiveAction() { |
1497 |
+ |
protected void realCompute() { |
1498 |
+ |
FibAction f = new FibAction(8); |
1499 |
+ |
assertSame(f, f.fork()); |
1500 |
+ |
boolean t = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, TimeUnit.SECONDS); |
1501 |
+ |
assertTrue(t); |
1502 |
+ |
while (!f.isDone()) { |
1503 |
+ |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1504 |
+ |
threadFail("timed out"); |
1505 |
+ |
assertFalse(p.getAsyncMode()); |
1506 |
+ |
assertFalse(p.isShutdown()); |
1507 |
+ |
assertFalse(p.isTerminating()); |
1508 |
+ |
assertFalse(p.isTerminated()); |
1509 |
+ |
Thread.yield(); |
1510 |
+ |
} |
1511 |
+ |
assertFalse(p.isQuiescent()); |
1512 |
+ |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
1513 |
+ |
try { |
1514 |
+ |
assertEquals(21, f.result); |
1515 |
+ |
} catch (Throwable fail) { |
1516 |
+ |
threadFail(fail.getMessage()); |
1517 |
+ |
} |
1518 |
+ |
}}; |
1519 |
+ |
p.execute(a); |
1520 |
+ |
while (!a.isDone() || !p.isQuiescent()) { |
1521 |
+ |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1522 |
+ |
throw new AssertionFailedError("timed out"); |
1523 |
+ |
assertFalse(p.getAsyncMode()); |
1524 |
+ |
assertFalse(p.isShutdown()); |
1525 |
+ |
assertFalse(p.isTerminating()); |
1526 |
+ |
assertFalse(p.isTerminated()); |
1527 |
+ |
Thread.yield(); |
1528 |
+ |
} |
1529 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1530 |
+ |
assertFalse(p.getAsyncMode()); |
1531 |
+ |
assertEquals(0, p.getActiveThreadCount()); |
1532 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1533 |
+ |
assertEquals(0, p.getQueuedSubmissionCount()); |
1534 |
+ |
assertFalse(p.hasQueuedSubmissions()); |
1535 |
+ |
assertFalse(p.isShutdown()); |
1536 |
+ |
assertFalse(p.isTerminating()); |
1537 |
+ |
assertFalse(p.isTerminated()); |
1538 |
+ |
} finally { |
1539 |
+ |
joinPool(p); |
1540 |
+ |
} |
1541 |
+ |
} |
1542 |
+ |
|
1543 |
+ |
/** |
1544 |
+ |
* awaitQuiescence returns when pool isQuiescent() or the indicated |
1545 |
+ |
* timeout elapsed |
1546 |
+ |
*/ |
1547 |
+ |
public void testAwaitQuiescence2() throws Exception { |
1548 |
+ |
final ForkJoinPool p = new ForkJoinPool(); |
1549 |
+ |
try { |
1550 |
+ |
assertTrue(p.isQuiescent()); |
1551 |
+ |
for (;;) { |
1552 |
+ |
final long startTime = System.nanoTime(); |
1553 |
+ |
ForkJoinTask a = new CheckedRecursiveAction() { |
1554 |
+ |
protected void realCompute() { |
1555 |
+ |
FibAction f = new FibAction(8); |
1556 |
+ |
assertSame(f, f.fork()); |
1557 |
+ |
ForkJoinTask.helpQuiesce(); |
1558 |
+ |
while (!f.isDone()) { |
1559 |
+ |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1560 |
+ |
threadFail("timed out"); |
1561 |
+ |
assertFalse(p.getAsyncMode()); |
1562 |
+ |
assertFalse(p.isShutdown()); |
1563 |
+ |
assertFalse(p.isTerminating()); |
1564 |
+ |
assertFalse(p.isTerminated()); |
1565 |
+ |
Thread.yield(); |
1566 |
+ |
} |
1567 |
+ |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
1568 |
+ |
try { |
1569 |
+ |
assertEquals(21, f.result); |
1570 |
+ |
} catch (Throwable fail) { System.out.println("fail " + fail.getMessage()); } |
1571 |
+ |
}}; |
1572 |
+ |
p.execute(a); |
1573 |
+ |
if (a.isDone() || p.isQuiescent()) |
1574 |
+ |
continue; // Already done so cannot test; retry |
1575 |
+ |
while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) { |
1576 |
+ |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1577 |
+ |
threadFail("timed out"); |
1578 |
+ |
assertFalse(p.getAsyncMode()); |
1579 |
+ |
assertFalse(p.isShutdown()); |
1580 |
+ |
assertFalse(p.isTerminating()); |
1581 |
+ |
assertFalse(p.isTerminated()); |
1582 |
+ |
Thread.yield(); |
1583 |
+ |
} |
1584 |
+ |
assertTrue(p.isQuiescent()); |
1585 |
+ |
assertTrue(a.isDone()); |
1586 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1587 |
+ |
assertFalse(p.getAsyncMode()); |
1588 |
+ |
assertEquals(0, p.getActiveThreadCount()); |
1589 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1590 |
+ |
assertEquals(0, p.getQueuedSubmissionCount()); |
1591 |
+ |
assertFalse(p.hasQueuedSubmissions()); |
1592 |
+ |
assertFalse(p.isShutdown()); |
1593 |
+ |
assertFalse(p.isTerminating()); |
1594 |
+ |
assertFalse(p.isTerminated()); |
1595 |
+ |
break; |
1596 |
+ |
} |
1597 |
+ |
} finally { |
1598 |
+ |
joinPool(p); |
1599 |
+ |
} |
1600 |
+ |
} |
1601 |
+ |
|
1602 |
|
} |