10 |
|
import java.util.concurrent.ForkJoinWorkerThread; |
11 |
|
import java.util.concurrent.RecursiveAction; |
12 |
|
import java.util.concurrent.TimeUnit; |
13 |
+ |
import java.util.concurrent.TimeoutException; |
14 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
15 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
16 |
+ |
import static java.util.concurrent.TimeUnit.SECONDS; |
17 |
|
import java.util.HashSet; |
18 |
|
import junit.framework.*; |
19 |
|
|
52 |
|
assertFalse(a.isCompletedAbnormally()); |
53 |
|
assertFalse(a.isCancelled()); |
54 |
|
assertNull(a.getException()); |
55 |
+ |
assertNull(a.getRawResult()); |
56 |
|
|
57 |
|
assertNull(pool.invoke(a)); |
58 |
|
|
61 |
|
assertFalse(a.isCompletedAbnormally()); |
62 |
|
assertFalse(a.isCancelled()); |
63 |
|
assertNull(a.getException()); |
64 |
+ |
assertNull(a.getRawResult()); |
65 |
|
} finally { |
66 |
|
joinPool(pool); |
67 |
|
} |
68 |
|
} |
69 |
|
|
70 |
+ |
void checkNotDone(ForkJoinTask a) { |
71 |
+ |
assertFalse(a.isDone()); |
72 |
+ |
assertFalse(a.isCompletedNormally()); |
73 |
+ |
assertFalse(a.isCompletedAbnormally()); |
74 |
+ |
assertFalse(a.isCancelled()); |
75 |
+ |
assertNull(a.getException()); |
76 |
+ |
assertNull(a.getRawResult()); |
77 |
+ |
|
78 |
+ |
try { |
79 |
+ |
a.get(0L, SECONDS); |
80 |
+ |
shouldThrow(); |
81 |
+ |
} catch (TimeoutException success) { |
82 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
83 |
+ |
} |
84 |
+ |
|
85 |
+ |
<T> void checkCompletedNormally(ForkJoinTask<T> a) { |
86 |
+ |
checkCompletedNormally(a, null); |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) { |
90 |
+ |
assertTrue(a.isDone()); |
91 |
+ |
assertFalse(a.isCancelled()); |
92 |
+ |
assertTrue(a.isCompletedNormally()); |
93 |
+ |
assertFalse(a.isCompletedAbnormally()); |
94 |
+ |
assertNull(a.getException()); |
95 |
+ |
assertSame(expected, a.getRawResult()); |
96 |
+ |
assertSame(expected, a.join()); |
97 |
+ |
assertFalse(a.cancel(false)); |
98 |
+ |
assertFalse(a.cancel(true)); |
99 |
+ |
try { |
100 |
+ |
assertSame(expected, a.get()); |
101 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
102 |
+ |
try { |
103 |
+ |
assertSame(expected, a.get(5L, SECONDS)); |
104 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
105 |
+ |
} |
106 |
+ |
|
107 |
+ |
void checkCancelled(ForkJoinTask a) { |
108 |
+ |
assertTrue(a.isDone()); |
109 |
+ |
assertTrue(a.isCancelled()); |
110 |
+ |
assertFalse(a.isCompletedNormally()); |
111 |
+ |
assertTrue(a.isCompletedAbnormally()); |
112 |
+ |
assertTrue(a.getException() instanceof CancellationException); |
113 |
+ |
assertNull(a.getRawResult()); |
114 |
+ |
assertTrue(a.cancel(false)); |
115 |
+ |
assertTrue(a.cancel(true)); |
116 |
+ |
|
117 |
+ |
try { |
118 |
+ |
a.join(); |
119 |
+ |
shouldThrow(); |
120 |
+ |
} catch (CancellationException success) { |
121 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
122 |
+ |
|
123 |
+ |
try { |
124 |
+ |
a.get(); |
125 |
+ |
shouldThrow(); |
126 |
+ |
} catch (CancellationException success) { |
127 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
128 |
+ |
|
129 |
+ |
try { |
130 |
+ |
a.get(5L, SECONDS); |
131 |
+ |
shouldThrow(); |
132 |
+ |
} catch (CancellationException success) { |
133 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
134 |
+ |
} |
135 |
+ |
|
136 |
+ |
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { |
137 |
+ |
assertTrue(a.isDone()); |
138 |
+ |
assertFalse(a.isCancelled()); |
139 |
+ |
assertFalse(a.isCompletedNormally()); |
140 |
+ |
assertTrue(a.isCompletedAbnormally()); |
141 |
+ |
assertSame(t, a.getException()); |
142 |
+ |
assertNull(a.getRawResult()); |
143 |
+ |
assertFalse(a.cancel(false)); |
144 |
+ |
assertFalse(a.cancel(true)); |
145 |
+ |
|
146 |
+ |
try { |
147 |
+ |
a.join(); |
148 |
+ |
shouldThrow(); |
149 |
+ |
} catch (Throwable expected) { |
150 |
+ |
assertSame(t, expected); |
151 |
+ |
} |
152 |
+ |
|
153 |
+ |
try { |
154 |
+ |
a.get(); |
155 |
+ |
shouldThrow(); |
156 |
+ |
} catch (ExecutionException success) { |
157 |
+ |
assertSame(t, success.getCause()); |
158 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
159 |
+ |
|
160 |
+ |
try { |
161 |
+ |
a.get(5L, SECONDS); |
162 |
+ |
shouldThrow(); |
163 |
+ |
} catch (ExecutionException success) { |
164 |
+ |
assertSame(t, success.getCause()); |
165 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
166 |
+ |
} |
167 |
+ |
|
168 |
|
/* |
169 |
|
* Testing coverage notes: |
170 |
|
* |
349 |
|
/** |
350 |
|
* invoke returns when task completes normally. |
351 |
|
* isCompletedAbnormally and isCancelled return false for normally |
352 |
< |
* completed tasks. getRawResult of a RecursiveAction returns null; |
352 |
> |
* completed tasks; getRawResult returns null. |
353 |
|
*/ |
354 |
|
public void testInvoke() { |
355 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
357 |
|
AsyncFib f = new AsyncFib(8); |
358 |
|
assertNull(f.invoke()); |
359 |
|
assertEquals(21, f.number); |
360 |
< |
assertTrue(f.isDone()); |
259 |
< |
assertFalse(f.isCancelled()); |
260 |
< |
assertFalse(f.isCompletedAbnormally()); |
261 |
< |
assertNull(f.getRawResult()); |
360 |
> |
checkCompletedNormally(f); |
361 |
|
}}; |
362 |
|
testInvokeOnPool(mainPool(), a); |
363 |
|
} |
373 |
|
AsyncFib f = new AsyncFib(8); |
374 |
|
f.quietlyInvoke(); |
375 |
|
assertEquals(21, f.number); |
376 |
< |
assertTrue(f.isDone()); |
278 |
< |
assertFalse(f.isCancelled()); |
279 |
< |
assertFalse(f.isCompletedAbnormally()); |
280 |
< |
assertNull(f.getRawResult()); |
376 |
> |
checkCompletedNormally(f); |
377 |
|
}}; |
378 |
|
testInvokeOnPool(mainPool(), a); |
379 |
|
} |
388 |
|
assertSame(f, f.fork()); |
389 |
|
assertNull(f.join()); |
390 |
|
assertEquals(21, f.number); |
391 |
< |
assertTrue(f.isDone()); |
296 |
< |
assertNull(f.getRawResult()); |
391 |
> |
checkCompletedNormally(f); |
392 |
|
}}; |
393 |
|
testInvokeOnPool(mainPool(), a); |
394 |
|
} |
403 |
|
assertSame(f, f.fork()); |
404 |
|
assertNull(f.get()); |
405 |
|
assertEquals(21, f.number); |
406 |
< |
assertTrue(f.isDone()); |
406 |
> |
checkCompletedNormally(f); |
407 |
|
}}; |
408 |
|
testInvokeOnPool(mainPool(), a); |
409 |
|
} |
418 |
|
assertSame(f, f.fork()); |
419 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
420 |
|
assertEquals(21, f.number); |
421 |
< |
assertTrue(f.isDone()); |
421 |
> |
checkCompletedNormally(f); |
422 |
|
}}; |
423 |
|
testInvokeOnPool(mainPool(), a); |
424 |
|
} |
449 |
|
assertSame(f, f.fork()); |
450 |
|
f.quietlyJoin(); |
451 |
|
assertEquals(21, f.number); |
452 |
< |
assertTrue(f.isDone()); |
452 |
> |
checkCompletedNormally(f); |
453 |
|
}}; |
454 |
|
testInvokeOnPool(mainPool(), a); |
455 |
|
} |
466 |
|
assertSame(f, f.fork()); |
467 |
|
f.helpQuiesce(); |
468 |
|
assertEquals(21, f.number); |
374 |
– |
assertTrue(f.isDone()); |
469 |
|
assertEquals(0, getQueuedTaskCount()); |
470 |
+ |
checkCompletedNormally(f); |
471 |
|
}}; |
472 |
|
testInvokeOnPool(mainPool(), a); |
473 |
|
} |
483 |
|
try { |
484 |
|
f.invoke(); |
485 |
|
shouldThrow(); |
486 |
< |
} catch (FJException success) {} |
486 |
> |
} catch (FJException success) { |
487 |
> |
checkCompletedAbnormally(f, success); |
488 |
> |
} |
489 |
|
}}; |
490 |
|
testInvokeOnPool(mainPool(), a); |
491 |
|
} |
498 |
|
public void realCompute() { |
499 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
500 |
|
f.quietlyInvoke(); |
501 |
< |
assertTrue(f.isDone()); |
501 |
> |
assertTrue(f.getException() instanceof FJException); |
502 |
> |
checkCompletedAbnormally(f, f.getException()); |
503 |
|
}}; |
504 |
|
testInvokeOnPool(mainPool(), a); |
505 |
|
} |
515 |
|
try { |
516 |
|
f.join(); |
517 |
|
shouldThrow(); |
518 |
< |
} catch (FJException success) {} |
518 |
> |
} catch (FJException success) { |
519 |
> |
checkCompletedAbnormally(f, success); |
520 |
> |
} |
521 |
|
}}; |
522 |
|
testInvokeOnPool(mainPool(), a); |
523 |
|
} |
536 |
|
} catch (ExecutionException success) { |
537 |
|
Throwable cause = success.getCause(); |
538 |
|
assertTrue(cause instanceof FJException); |
539 |
< |
assertTrue(f.isDone()); |
440 |
< |
assertTrue(f.isCompletedAbnormally()); |
441 |
< |
assertSame(cause, f.getException()); |
539 |
> |
checkCompletedAbnormally(f, cause); |
540 |
|
} |
541 |
|
}}; |
542 |
|
testInvokeOnPool(mainPool(), a); |
556 |
|
} catch (ExecutionException success) { |
557 |
|
Throwable cause = success.getCause(); |
558 |
|
assertTrue(cause instanceof FJException); |
559 |
< |
assertTrue(f.isDone()); |
462 |
< |
assertTrue(f.isCompletedAbnormally()); |
463 |
< |
assertSame(cause, f.getException()); |
559 |
> |
checkCompletedAbnormally(f, cause); |
560 |
|
} |
561 |
|
}}; |
562 |
|
testInvokeOnPool(mainPool(), a); |
571 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
572 |
|
assertSame(f, f.fork()); |
573 |
|
f.quietlyJoin(); |
478 |
– |
assertTrue(f.isDone()); |
479 |
– |
assertTrue(f.isCompletedAbnormally()); |
574 |
|
assertTrue(f.getException() instanceof FJException); |
575 |
+ |
checkCompletedAbnormally(f, f.getException()); |
576 |
|
}}; |
577 |
|
testInvokeOnPool(mainPool(), a); |
578 |
|
} |
589 |
|
f.invoke(); |
590 |
|
shouldThrow(); |
591 |
|
} catch (CancellationException success) { |
592 |
< |
assertTrue(f.isDone()); |
498 |
< |
assertTrue(f.isCancelled()); |
499 |
< |
assertTrue(f.isCompletedAbnormally()); |
500 |
< |
assertTrue(f.getException() instanceof CancellationException); |
592 |
> |
checkCancelled(f); |
593 |
|
} |
594 |
|
}}; |
595 |
|
testInvokeOnPool(mainPool(), a); |
608 |
|
f.join(); |
609 |
|
shouldThrow(); |
610 |
|
} catch (CancellationException success) { |
611 |
< |
assertTrue(f.isDone()); |
520 |
< |
assertTrue(f.isCancelled()); |
521 |
< |
assertTrue(f.isCompletedAbnormally()); |
522 |
< |
assertTrue(f.getException() instanceof CancellationException); |
611 |
> |
checkCancelled(f); |
612 |
|
} |
613 |
|
}}; |
614 |
|
testInvokeOnPool(mainPool(), a); |
627 |
|
f.get(); |
628 |
|
shouldThrow(); |
629 |
|
} catch (CancellationException success) { |
630 |
< |
assertTrue(f.isDone()); |
542 |
< |
assertTrue(f.isCancelled()); |
543 |
< |
assertTrue(f.isCompletedAbnormally()); |
544 |
< |
assertTrue(f.getException() instanceof CancellationException); |
630 |
> |
checkCancelled(f); |
631 |
|
} |
632 |
|
}}; |
633 |
|
testInvokeOnPool(mainPool(), a); |
646 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
647 |
|
shouldThrow(); |
648 |
|
} catch (CancellationException success) { |
649 |
< |
assertTrue(f.isDone()); |
564 |
< |
assertTrue(f.isCancelled()); |
565 |
< |
assertTrue(f.isCompletedAbnormally()); |
566 |
< |
assertTrue(f.getException() instanceof CancellationException); |
649 |
> |
checkCancelled(f); |
650 |
|
} |
651 |
|
}}; |
652 |
|
testInvokeOnPool(mainPool(), a); |
662 |
|
assertTrue(f.cancel(true)); |
663 |
|
assertSame(f, f.fork()); |
664 |
|
f.quietlyJoin(); |
665 |
< |
assertTrue(f.isDone()); |
583 |
< |
assertTrue(f.isCompletedAbnormally()); |
584 |
< |
assertTrue(f.isCancelled()); |
585 |
< |
assertTrue(f.getException() instanceof CancellationException); |
665 |
> |
checkCancelled(f); |
666 |
|
}}; |
667 |
|
testInvokeOnPool(mainPool(), a); |
668 |
|
} |
707 |
|
public void testInForkJoinPool2() { |
708 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
709 |
|
public void realCompute() { |
710 |
< |
assertTrue(!inForkJoinPool()); |
710 |
> |
assertFalse(inForkJoinPool()); |
711 |
|
}}; |
712 |
|
assertNull(a.invoke()); |
713 |
|
} |
734 |
|
try { |
735 |
|
f.invoke(); |
736 |
|
shouldThrow(); |
737 |
< |
} catch (FJException success) {} |
737 |
> |
} catch (FJException success) { |
738 |
> |
checkCompletedAbnormally(f, success); |
739 |
> |
} |
740 |
|
}}; |
741 |
|
testInvokeOnPool(mainPool(), a); |
742 |
|
} |
750 |
|
AsyncFib f = new AsyncFib(8); |
751 |
|
AsyncFib g = new AsyncFib(9); |
752 |
|
invokeAll(f, g); |
671 |
– |
assertTrue(f.isDone()); |
753 |
|
assertEquals(21, f.number); |
673 |
– |
assertTrue(g.isDone()); |
754 |
|
assertEquals(34, g.number); |
755 |
+ |
checkCompletedNormally(f); |
756 |
+ |
checkCompletedNormally(g); |
757 |
|
}}; |
758 |
|
testInvokeOnPool(mainPool(), a); |
759 |
|
} |
766 |
|
public void realCompute() { |
767 |
|
AsyncFib f = new AsyncFib(8); |
768 |
|
invokeAll(f); |
769 |
< |
assertTrue(f.isDone()); |
769 |
> |
checkCompletedNormally(f); |
770 |
|
assertEquals(21, f.number); |
771 |
|
}}; |
772 |
|
testInvokeOnPool(mainPool(), a); |
782 |
|
AsyncFib g = new AsyncFib(9); |
783 |
|
AsyncFib h = new AsyncFib(7); |
784 |
|
invokeAll(f, g, h); |
703 |
– |
assertTrue(f.isDone()); |
785 |
|
assertEquals(21, f.number); |
705 |
– |
assertTrue(g.isDone()); |
786 |
|
assertEquals(34, g.number); |
707 |
– |
assertTrue(h.isDone()); |
787 |
|
assertEquals(13, h.number); |
788 |
+ |
checkCompletedNormally(f); |
789 |
+ |
checkCompletedNormally(g); |
790 |
+ |
checkCompletedNormally(h); |
791 |
|
}}; |
792 |
|
testInvokeOnPool(mainPool(), a); |
793 |
|
} |
806 |
|
set.add(g); |
807 |
|
set.add(h); |
808 |
|
invokeAll(set); |
727 |
– |
assertTrue(f.isDone()); |
809 |
|
assertEquals(21, f.number); |
729 |
– |
assertTrue(g.isDone()); |
810 |
|
assertEquals(34, g.number); |
731 |
– |
assertTrue(h.isDone()); |
811 |
|
assertEquals(13, h.number); |
812 |
+ |
checkCompletedNormally(f); |
813 |
+ |
checkCompletedNormally(g); |
814 |
+ |
checkCompletedNormally(h); |
815 |
|
}}; |
816 |
|
testInvokeOnPool(mainPool(), a); |
817 |
|
} |
845 |
|
try { |
846 |
|
invokeAll(f, g); |
847 |
|
shouldThrow(); |
848 |
< |
} catch (FJException success) {} |
848 |
> |
} catch (FJException success) { |
849 |
> |
checkCompletedAbnormally(g, success); |
850 |
> |
} |
851 |
|
}}; |
852 |
|
testInvokeOnPool(mainPool(), a); |
853 |
|
} |
862 |
|
try { |
863 |
|
invokeAll(g); |
864 |
|
shouldThrow(); |
865 |
< |
} catch (FJException success) {} |
865 |
> |
} catch (FJException success) { |
866 |
> |
checkCompletedAbnormally(g, success); |
867 |
> |
} |
868 |
|
}}; |
869 |
|
testInvokeOnPool(mainPool(), a); |
870 |
|
} |
881 |
|
try { |
882 |
|
invokeAll(f, g, h); |
883 |
|
shouldThrow(); |
884 |
< |
} catch (FJException success) {} |
884 |
> |
} catch (FJException success) { |
885 |
> |
checkCompletedAbnormally(g, success); |
886 |
> |
} |
887 |
|
}}; |
888 |
|
testInvokeOnPool(mainPool(), a); |
889 |
|
} |
904 |
|
try { |
905 |
|
invokeAll(set); |
906 |
|
shouldThrow(); |
907 |
< |
} catch (FJException success) {} |
907 |
> |
} catch (FJException success) { |
908 |
> |
checkCompletedAbnormally(f, success); |
909 |
> |
} |
910 |
|
}}; |
911 |
|
testInvokeOnPool(mainPool(), a); |
912 |
|
} |
924 |
|
assertSame(f, f.fork()); |
925 |
|
assertTrue(f.tryUnfork()); |
926 |
|
helpQuiesce(); |
927 |
< |
assertFalse(f.isDone()); |
928 |
< |
assertTrue(g.isDone()); |
927 |
> |
checkNotDone(f); |
928 |
> |
checkCompletedNormally(g); |
929 |
|
}}; |
930 |
|
testInvokeOnPool(singletonPool(), a); |
931 |
|
} |
945 |
|
assertSame(f, f.fork()); |
946 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
947 |
|
helpQuiesce(); |
948 |
+ |
assertEquals(0, getSurplusQueuedTaskCount()); |
949 |
+ |
checkCompletedNormally(f); |
950 |
+ |
checkCompletedNormally(g); |
951 |
+ |
checkCompletedNormally(h); |
952 |
|
}}; |
953 |
|
testInvokeOnPool(singletonPool(), a); |
954 |
|
} |
965 |
|
assertSame(f, f.fork()); |
966 |
|
assertSame(f, peekNextLocalTask()); |
967 |
|
assertNull(f.join()); |
968 |
< |
assertTrue(f.isDone()); |
968 |
> |
checkCompletedNormally(f); |
969 |
|
helpQuiesce(); |
970 |
+ |
checkCompletedNormally(g); |
971 |
|
}}; |
972 |
|
testInvokeOnPool(singletonPool(), a); |
973 |
|
} |
974 |
|
|
975 |
|
/** |
976 |
< |
* pollNextLocalTask returns most recent unexecuted task |
977 |
< |
* without executing it |
976 |
> |
* pollNextLocalTask returns most recent unexecuted task without |
977 |
> |
* executing it |
978 |
|
*/ |
979 |
|
public void testPollNextLocalTask() { |
980 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
985 |
|
assertSame(f, f.fork()); |
986 |
|
assertSame(f, pollNextLocalTask()); |
987 |
|
helpQuiesce(); |
988 |
< |
assertFalse(f.isDone()); |
988 |
> |
checkNotDone(f); |
989 |
> |
assertEquals(34, g.number); |
990 |
> |
checkCompletedNormally(g); |
991 |
|
}}; |
992 |
|
testInvokeOnPool(singletonPool(), a); |
993 |
|
} |
994 |
|
|
995 |
|
/** |
996 |
< |
* pollTask returns an unexecuted task |
900 |
< |
* without executing it |
996 |
> |
* pollTask returns an unexecuted task without executing it |
997 |
|
*/ |
998 |
|
public void testPollTask() { |
999 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1004 |
|
assertSame(f, f.fork()); |
1005 |
|
assertSame(f, pollTask()); |
1006 |
|
helpQuiesce(); |
1007 |
< |
assertFalse(f.isDone()); |
1008 |
< |
assertTrue(g.isDone()); |
1007 |
> |
checkNotDone(f); |
1008 |
> |
checkCompletedNormally(g); |
1009 |
|
}}; |
1010 |
|
testInvokeOnPool(singletonPool(), a); |
1011 |
|
} |
1023 |
|
assertSame(g, peekNextLocalTask()); |
1024 |
|
assertNull(f.join()); |
1025 |
|
helpQuiesce(); |
1026 |
< |
assertTrue(f.isDone()); |
1026 |
> |
checkCompletedNormally(f); |
1027 |
> |
assertEquals(34, g.number); |
1028 |
> |
checkCompletedNormally(g); |
1029 |
|
}}; |
1030 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1031 |
|
} |
1032 |
|
|
1033 |
|
/** |
1034 |
< |
* pollNextLocalTask returns least recent unexecuted task |
1035 |
< |
* without executing it, in async mode |
1034 |
> |
* pollNextLocalTask returns least recent unexecuted task without |
1035 |
> |
* executing it, in async mode |
1036 |
|
*/ |
1037 |
|
public void testPollNextLocalTaskAsync() { |
1038 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1043 |
|
assertSame(f, f.fork()); |
1044 |
|
assertSame(g, pollNextLocalTask()); |
1045 |
|
helpQuiesce(); |
1046 |
< |
assertTrue(f.isDone()); |
1047 |
< |
assertFalse(g.isDone()); |
1046 |
> |
assertEquals(21, f.number); |
1047 |
> |
checkCompletedNormally(f); |
1048 |
> |
checkNotDone(g); |
1049 |
|
}}; |
1050 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1051 |
|
} |
1052 |
|
|
1053 |
|
/** |
1054 |
< |
* pollTask returns an unexecuted task |
1055 |
< |
* without executing it, in async mode |
1054 |
> |
* pollTask returns an unexecuted task without executing it, in |
1055 |
> |
* async mode |
1056 |
|
*/ |
1057 |
|
public void testPollTaskAsync() { |
1058 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1063 |
|
assertSame(f, f.fork()); |
1064 |
|
assertSame(g, pollTask()); |
1065 |
|
helpQuiesce(); |
1066 |
< |
assertTrue(f.isDone()); |
1067 |
< |
assertFalse(g.isDone()); |
1066 |
> |
assertEquals(21, f.number); |
1067 |
> |
checkCompletedNormally(f); |
1068 |
> |
checkNotDone(g); |
1069 |
|
}}; |
1070 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1071 |
|
} |
1075 |
|
/** |
1076 |
|
* invoke returns when task completes normally. |
1077 |
|
* isCompletedAbnormally and isCancelled return false for normally |
1078 |
< |
* completed tasks. getRawResult of a RecursiveAction returns null; |
1078 |
> |
* completed tasks; getRawResult returns null. |
1079 |
|
*/ |
1080 |
|
public void testInvokeSingleton() { |
1081 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1083 |
|
AsyncFib f = new AsyncFib(8); |
1084 |
|
assertNull(f.invoke()); |
1085 |
|
assertEquals(21, f.number); |
1086 |
< |
assertTrue(f.isDone()); |
987 |
< |
assertFalse(f.isCancelled()); |
988 |
< |
assertFalse(f.isCompletedAbnormally()); |
989 |
< |
assertNull(f.getRawResult()); |
1086 |
> |
checkCompletedNormally(f); |
1087 |
|
}}; |
1088 |
|
testInvokeOnPool(singletonPool(), a); |
1089 |
|
} |
1099 |
|
AsyncFib f = new AsyncFib(8); |
1100 |
|
f.quietlyInvoke(); |
1101 |
|
assertEquals(21, f.number); |
1102 |
< |
assertTrue(f.isDone()); |
1006 |
< |
assertFalse(f.isCancelled()); |
1007 |
< |
assertFalse(f.isCompletedAbnormally()); |
1008 |
< |
assertNull(f.getRawResult()); |
1102 |
> |
checkCompletedNormally(f); |
1103 |
|
}}; |
1104 |
|
testInvokeOnPool(singletonPool(), a); |
1105 |
|
} |
1114 |
|
assertSame(f, f.fork()); |
1115 |
|
assertNull(f.join()); |
1116 |
|
assertEquals(21, f.number); |
1117 |
< |
assertTrue(f.isDone()); |
1024 |
< |
assertNull(f.getRawResult()); |
1117 |
> |
checkCompletedNormally(f); |
1118 |
|
}}; |
1119 |
|
testInvokeOnPool(singletonPool(), a); |
1120 |
|
} |
1129 |
|
assertSame(f, f.fork()); |
1130 |
|
assertNull(f.get()); |
1131 |
|
assertEquals(21, f.number); |
1132 |
< |
assertTrue(f.isDone()); |
1132 |
> |
checkCompletedNormally(f); |
1133 |
|
}}; |
1134 |
|
testInvokeOnPool(singletonPool(), a); |
1135 |
|
} |
1144 |
|
assertSame(f, f.fork()); |
1145 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1146 |
|
assertEquals(21, f.number); |
1147 |
< |
assertTrue(f.isDone()); |
1147 |
> |
checkCompletedNormally(f); |
1148 |
|
}}; |
1149 |
|
testInvokeOnPool(singletonPool(), a); |
1150 |
|
} |
1175 |
|
assertSame(f, f.fork()); |
1176 |
|
f.quietlyJoin(); |
1177 |
|
assertEquals(21, f.number); |
1178 |
< |
assertTrue(f.isDone()); |
1178 |
> |
checkCompletedNormally(f); |
1179 |
|
}}; |
1180 |
|
testInvokeOnPool(singletonPool(), a); |
1181 |
|
} |
1191 |
|
AsyncFib f = new AsyncFib(8); |
1192 |
|
assertSame(f, f.fork()); |
1193 |
|
f.helpQuiesce(); |
1101 |
– |
assertEquals(21, f.number); |
1102 |
– |
assertTrue(f.isDone()); |
1194 |
|
assertEquals(0, getQueuedTaskCount()); |
1195 |
+ |
assertEquals(21, f.number); |
1196 |
+ |
checkCompletedNormally(f); |
1197 |
|
}}; |
1198 |
|
testInvokeOnPool(singletonPool(), a); |
1199 |
|
} |
1209 |
|
try { |
1210 |
|
f.invoke(); |
1211 |
|
shouldThrow(); |
1212 |
< |
} catch (FJException success) {} |
1212 |
> |
} catch (FJException success) { |
1213 |
> |
checkCompletedAbnormally(f, success); |
1214 |
> |
} |
1215 |
|
}}; |
1216 |
|
testInvokeOnPool(singletonPool(), a); |
1217 |
|
} |
1224 |
|
public void realCompute() { |
1225 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1226 |
|
f.quietlyInvoke(); |
1227 |
< |
assertTrue(f.isDone()); |
1227 |
> |
assertTrue(f.getException() instanceof FJException); |
1228 |
> |
checkCompletedAbnormally(f, f.getException()); |
1229 |
|
}}; |
1230 |
|
testInvokeOnPool(singletonPool(), a); |
1231 |
|
} |
1241 |
|
try { |
1242 |
|
f.join(); |
1243 |
|
shouldThrow(); |
1244 |
< |
} catch (FJException success) {} |
1244 |
> |
} catch (FJException success) { |
1245 |
> |
checkCompletedAbnormally(f, success); |
1246 |
> |
} |
1247 |
|
}}; |
1248 |
|
testInvokeOnPool(singletonPool(), a); |
1249 |
|
} |
1262 |
|
} catch (ExecutionException success) { |
1263 |
|
Throwable cause = success.getCause(); |
1264 |
|
assertTrue(cause instanceof FJException); |
1265 |
< |
assertTrue(f.isDone()); |
1168 |
< |
assertTrue(f.isCompletedAbnormally()); |
1169 |
< |
assertSame(cause, f.getException()); |
1265 |
> |
checkCompletedAbnormally(f, cause); |
1266 |
|
} |
1267 |
|
}}; |
1268 |
|
testInvokeOnPool(singletonPool(), a); |
1282 |
|
} catch (ExecutionException success) { |
1283 |
|
Throwable cause = success.getCause(); |
1284 |
|
assertTrue(cause instanceof FJException); |
1285 |
< |
assertTrue(f.isDone()); |
1190 |
< |
assertTrue(f.isCompletedAbnormally()); |
1191 |
< |
assertSame(cause, f.getException()); |
1285 |
> |
checkCompletedAbnormally(f, cause); |
1286 |
|
} |
1287 |
|
}}; |
1288 |
|
testInvokeOnPool(singletonPool(), a); |
1297 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1298 |
|
assertSame(f, f.fork()); |
1299 |
|
f.quietlyJoin(); |
1206 |
– |
assertTrue(f.isDone()); |
1207 |
– |
assertTrue(f.isCompletedAbnormally()); |
1300 |
|
assertTrue(f.getException() instanceof FJException); |
1301 |
+ |
checkCompletedAbnormally(f, f.getException()); |
1302 |
|
}}; |
1303 |
|
testInvokeOnPool(singletonPool(), a); |
1304 |
|
} |
1315 |
|
f.invoke(); |
1316 |
|
shouldThrow(); |
1317 |
|
} catch (CancellationException success) { |
1318 |
< |
assertTrue(f.isDone()); |
1226 |
< |
assertTrue(f.isCancelled()); |
1227 |
< |
assertTrue(f.isCompletedAbnormally()); |
1228 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1318 |
> |
checkCancelled(f); |
1319 |
|
} |
1320 |
|
}}; |
1321 |
|
testInvokeOnPool(singletonPool(), a); |
1334 |
|
f.join(); |
1335 |
|
shouldThrow(); |
1336 |
|
} catch (CancellationException success) { |
1337 |
< |
assertTrue(f.isDone()); |
1248 |
< |
assertTrue(f.isCancelled()); |
1249 |
< |
assertTrue(f.isCompletedAbnormally()); |
1250 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1337 |
> |
checkCancelled(f); |
1338 |
|
} |
1339 |
|
}}; |
1340 |
|
testInvokeOnPool(singletonPool(), a); |
1353 |
|
f.get(); |
1354 |
|
shouldThrow(); |
1355 |
|
} catch (CancellationException success) { |
1356 |
< |
assertTrue(f.isDone()); |
1270 |
< |
assertTrue(f.isCancelled()); |
1271 |
< |
assertTrue(f.isCompletedAbnormally()); |
1272 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1356 |
> |
checkCancelled(f); |
1357 |
|
} |
1358 |
|
}}; |
1359 |
|
testInvokeOnPool(singletonPool(), a); |
1372 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1373 |
|
shouldThrow(); |
1374 |
|
} catch (CancellationException success) { |
1375 |
< |
assertTrue(f.isDone()); |
1292 |
< |
assertTrue(f.isCancelled()); |
1293 |
< |
assertTrue(f.isCompletedAbnormally()); |
1294 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1375 |
> |
checkCancelled(f); |
1376 |
|
} |
1377 |
|
}}; |
1378 |
|
testInvokeOnPool(singletonPool(), a); |
1388 |
|
assertTrue(f.cancel(true)); |
1389 |
|
assertSame(f, f.fork()); |
1390 |
|
f.quietlyJoin(); |
1391 |
< |
assertTrue(f.isDone()); |
1311 |
< |
assertTrue(f.isCompletedAbnormally()); |
1312 |
< |
assertTrue(f.isCancelled()); |
1313 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1391 |
> |
checkCancelled(f); |
1392 |
|
}}; |
1393 |
|
testInvokeOnPool(singletonPool(), a); |
1394 |
|
} |
1404 |
|
try { |
1405 |
|
f.invoke(); |
1406 |
|
shouldThrow(); |
1407 |
< |
} catch (FJException success) {} |
1407 |
> |
} catch (FJException success) { |
1408 |
> |
checkCompletedAbnormally(f, success); |
1409 |
> |
} |
1410 |
|
}}; |
1411 |
|
testInvokeOnPool(singletonPool(), a); |
1412 |
|
} |
1420 |
|
AsyncFib f = new AsyncFib(8); |
1421 |
|
AsyncFib g = new AsyncFib(9); |
1422 |
|
invokeAll(f, g); |
1343 |
– |
assertTrue(f.isDone()); |
1423 |
|
assertEquals(21, f.number); |
1345 |
– |
assertTrue(g.isDone()); |
1424 |
|
assertEquals(34, g.number); |
1425 |
+ |
checkCompletedNormally(f); |
1426 |
+ |
checkCompletedNormally(g); |
1427 |
|
}}; |
1428 |
|
testInvokeOnPool(singletonPool(), a); |
1429 |
|
} |
1436 |
|
public void realCompute() { |
1437 |
|
AsyncFib f = new AsyncFib(8); |
1438 |
|
invokeAll(f); |
1439 |
< |
assertTrue(f.isDone()); |
1439 |
> |
checkCompletedNormally(f); |
1440 |
|
assertEquals(21, f.number); |
1441 |
|
}}; |
1442 |
|
testInvokeOnPool(singletonPool(), a); |
1452 |
|
AsyncFib g = new AsyncFib(9); |
1453 |
|
AsyncFib h = new AsyncFib(7); |
1454 |
|
invokeAll(f, g, h); |
1375 |
– |
assertTrue(f.isDone()); |
1455 |
|
assertEquals(21, f.number); |
1377 |
– |
assertTrue(g.isDone()); |
1456 |
|
assertEquals(34, g.number); |
1379 |
– |
assertTrue(h.isDone()); |
1457 |
|
assertEquals(13, h.number); |
1458 |
+ |
checkCompletedNormally(f); |
1459 |
+ |
checkCompletedNormally(g); |
1460 |
+ |
checkCompletedNormally(h); |
1461 |
|
}}; |
1462 |
|
testInvokeOnPool(singletonPool(), a); |
1463 |
|
} |
1476 |
|
set.add(g); |
1477 |
|
set.add(h); |
1478 |
|
invokeAll(set); |
1399 |
– |
assertTrue(f.isDone()); |
1479 |
|
assertEquals(21, f.number); |
1401 |
– |
assertTrue(g.isDone()); |
1480 |
|
assertEquals(34, g.number); |
1403 |
– |
assertTrue(h.isDone()); |
1481 |
|
assertEquals(13, h.number); |
1482 |
+ |
checkCompletedNormally(f); |
1483 |
+ |
checkCompletedNormally(g); |
1484 |
+ |
checkCompletedNormally(h); |
1485 |
|
}}; |
1486 |
|
testInvokeOnPool(singletonPool(), a); |
1487 |
|
} |
1515 |
|
try { |
1516 |
|
invokeAll(f, g); |
1517 |
|
shouldThrow(); |
1518 |
< |
} catch (FJException success) {} |
1518 |
> |
} catch (FJException success) { |
1519 |
> |
checkCompletedAbnormally(g, success); |
1520 |
> |
} |
1521 |
|
}}; |
1522 |
|
testInvokeOnPool(singletonPool(), a); |
1523 |
|
} |
1532 |
|
try { |
1533 |
|
invokeAll(g); |
1534 |
|
shouldThrow(); |
1535 |
< |
} catch (FJException success) {} |
1535 |
> |
} catch (FJException success) { |
1536 |
> |
checkCompletedAbnormally(g, success); |
1537 |
> |
} |
1538 |
|
}}; |
1539 |
|
testInvokeOnPool(singletonPool(), a); |
1540 |
|
} |
1551 |
|
try { |
1552 |
|
invokeAll(f, g, h); |
1553 |
|
shouldThrow(); |
1554 |
< |
} catch (FJException success) {} |
1554 |
> |
} catch (FJException success) { |
1555 |
> |
checkCompletedAbnormally(g, success); |
1556 |
> |
} |
1557 |
|
}}; |
1558 |
|
testInvokeOnPool(singletonPool(), a); |
1559 |
|
} |
1574 |
|
try { |
1575 |
|
invokeAll(set); |
1576 |
|
shouldThrow(); |
1577 |
< |
} catch (FJException success) {} |
1577 |
> |
} catch (FJException success) { |
1578 |
> |
checkCompletedAbnormally(f, success); |
1579 |
> |
} |
1580 |
|
}}; |
1581 |
|
testInvokeOnPool(singletonPool(), a); |
1582 |
|
} |