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 |
+ |
try { |
98 |
+ |
assertSame(expected, a.get()); |
99 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
100 |
+ |
try { |
101 |
+ |
assertSame(expected, a.get(5L, SECONDS)); |
102 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
103 |
+ |
} |
104 |
+ |
|
105 |
+ |
void checkCancelled(ForkJoinTask a) { |
106 |
+ |
assertTrue(a.isDone()); |
107 |
+ |
assertTrue(a.isCancelled()); |
108 |
+ |
assertFalse(a.isCompletedNormally()); |
109 |
+ |
assertTrue(a.isCompletedAbnormally()); |
110 |
+ |
assertTrue(a.getException() instanceof CancellationException); |
111 |
+ |
assertNull(a.getRawResult()); |
112 |
+ |
|
113 |
+ |
try { |
114 |
+ |
a.join(); |
115 |
+ |
shouldThrow(); |
116 |
+ |
} catch (CancellationException success) { |
117 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
118 |
+ |
|
119 |
+ |
try { |
120 |
+ |
a.get(); |
121 |
+ |
shouldThrow(); |
122 |
+ |
} catch (CancellationException success) { |
123 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
124 |
+ |
|
125 |
+ |
try { |
126 |
+ |
a.get(5L, SECONDS); |
127 |
+ |
shouldThrow(); |
128 |
+ |
} catch (CancellationException success) { |
129 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
130 |
+ |
} |
131 |
+ |
|
132 |
+ |
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { |
133 |
+ |
assertTrue(a.isDone()); |
134 |
+ |
assertFalse(a.isCancelled()); |
135 |
+ |
assertFalse(a.isCompletedNormally()); |
136 |
+ |
assertTrue(a.isCompletedAbnormally()); |
137 |
+ |
assertSame(t, a.getException()); |
138 |
+ |
assertNull(a.getRawResult()); |
139 |
+ |
|
140 |
+ |
try { |
141 |
+ |
a.join(); |
142 |
+ |
shouldThrow(); |
143 |
+ |
} catch (Throwable expected) { |
144 |
+ |
assertSame(t, expected); |
145 |
+ |
} |
146 |
+ |
|
147 |
+ |
try { |
148 |
+ |
a.get(); |
149 |
+ |
shouldThrow(); |
150 |
+ |
} catch (ExecutionException success) { |
151 |
+ |
assertSame(t, success.getCause()); |
152 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
153 |
+ |
|
154 |
+ |
try { |
155 |
+ |
a.get(5L, SECONDS); |
156 |
+ |
shouldThrow(); |
157 |
+ |
} catch (ExecutionException success) { |
158 |
+ |
assertSame(t, success.getCause()); |
159 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
160 |
+ |
} |
161 |
+ |
|
162 |
|
/* |
163 |
|
* Testing coverage notes: |
164 |
|
* |
351 |
|
AsyncFib f = new AsyncFib(8); |
352 |
|
assertNull(f.invoke()); |
353 |
|
assertEquals(21, f.number); |
354 |
< |
assertTrue(f.isDone()); |
259 |
< |
assertFalse(f.isCancelled()); |
260 |
< |
assertFalse(f.isCompletedAbnormally()); |
261 |
< |
assertNull(f.getRawResult()); |
354 |
> |
checkCompletedNormally(f); |
355 |
|
}}; |
356 |
|
testInvokeOnPool(mainPool(), a); |
357 |
|
} |
367 |
|
AsyncFib f = new AsyncFib(8); |
368 |
|
f.quietlyInvoke(); |
369 |
|
assertEquals(21, f.number); |
370 |
< |
assertTrue(f.isDone()); |
278 |
< |
assertFalse(f.isCancelled()); |
279 |
< |
assertFalse(f.isCompletedAbnormally()); |
280 |
< |
assertNull(f.getRawResult()); |
370 |
> |
checkCompletedNormally(f); |
371 |
|
}}; |
372 |
|
testInvokeOnPool(mainPool(), a); |
373 |
|
} |
382 |
|
assertSame(f, f.fork()); |
383 |
|
assertNull(f.join()); |
384 |
|
assertEquals(21, f.number); |
385 |
< |
assertTrue(f.isDone()); |
296 |
< |
assertNull(f.getRawResult()); |
385 |
> |
checkCompletedNormally(f); |
386 |
|
}}; |
387 |
|
testInvokeOnPool(mainPool(), a); |
388 |
|
} |
397 |
|
assertSame(f, f.fork()); |
398 |
|
assertNull(f.get()); |
399 |
|
assertEquals(21, f.number); |
400 |
< |
assertTrue(f.isDone()); |
400 |
> |
checkCompletedNormally(f); |
401 |
|
}}; |
402 |
|
testInvokeOnPool(mainPool(), a); |
403 |
|
} |
412 |
|
assertSame(f, f.fork()); |
413 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
414 |
|
assertEquals(21, f.number); |
415 |
< |
assertTrue(f.isDone()); |
415 |
> |
checkCompletedNormally(f); |
416 |
|
}}; |
417 |
|
testInvokeOnPool(mainPool(), a); |
418 |
|
} |
443 |
|
assertSame(f, f.fork()); |
444 |
|
f.quietlyJoin(); |
445 |
|
assertEquals(21, f.number); |
446 |
< |
assertTrue(f.isDone()); |
446 |
> |
checkCompletedNormally(f); |
447 |
|
}}; |
448 |
|
testInvokeOnPool(mainPool(), a); |
449 |
|
} |
460 |
|
assertSame(f, f.fork()); |
461 |
|
f.helpQuiesce(); |
462 |
|
assertEquals(21, f.number); |
374 |
– |
assertTrue(f.isDone()); |
463 |
|
assertEquals(0, getQueuedTaskCount()); |
464 |
+ |
checkCompletedNormally(f); |
465 |
|
}}; |
466 |
|
testInvokeOnPool(mainPool(), a); |
467 |
|
} |
477 |
|
try { |
478 |
|
f.invoke(); |
479 |
|
shouldThrow(); |
480 |
< |
} catch (FJException success) {} |
480 |
> |
} catch (FJException success) { |
481 |
> |
checkCompletedAbnormally(f, success); |
482 |
> |
} |
483 |
|
}}; |
484 |
|
testInvokeOnPool(mainPool(), a); |
485 |
|
} |
492 |
|
public void realCompute() { |
493 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
494 |
|
f.quietlyInvoke(); |
495 |
< |
assertTrue(f.isDone()); |
495 |
> |
assertTrue(f.getException() instanceof FJException); |
496 |
> |
checkCompletedAbnormally(f, f.getException()); |
497 |
|
}}; |
498 |
|
testInvokeOnPool(mainPool(), a); |
499 |
|
} |
509 |
|
try { |
510 |
|
f.join(); |
511 |
|
shouldThrow(); |
512 |
< |
} catch (FJException success) {} |
512 |
> |
} catch (FJException success) { |
513 |
> |
checkCompletedAbnormally(f, success); |
514 |
> |
} |
515 |
|
}}; |
516 |
|
testInvokeOnPool(mainPool(), a); |
517 |
|
} |
530 |
|
} catch (ExecutionException success) { |
531 |
|
Throwable cause = success.getCause(); |
532 |
|
assertTrue(cause instanceof FJException); |
533 |
< |
assertTrue(f.isDone()); |
440 |
< |
assertTrue(f.isCompletedAbnormally()); |
441 |
< |
assertSame(cause, f.getException()); |
533 |
> |
checkCompletedAbnormally(f, cause); |
534 |
|
} |
535 |
|
}}; |
536 |
|
testInvokeOnPool(mainPool(), a); |
550 |
|
} catch (ExecutionException success) { |
551 |
|
Throwable cause = success.getCause(); |
552 |
|
assertTrue(cause instanceof FJException); |
553 |
< |
assertTrue(f.isDone()); |
462 |
< |
assertTrue(f.isCompletedAbnormally()); |
463 |
< |
assertSame(cause, f.getException()); |
553 |
> |
checkCompletedAbnormally(f, cause); |
554 |
|
} |
555 |
|
}}; |
556 |
|
testInvokeOnPool(mainPool(), a); |
565 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
566 |
|
assertSame(f, f.fork()); |
567 |
|
f.quietlyJoin(); |
478 |
– |
assertTrue(f.isDone()); |
479 |
– |
assertTrue(f.isCompletedAbnormally()); |
568 |
|
assertTrue(f.getException() instanceof FJException); |
569 |
+ |
checkCompletedAbnormally(f, f.getException()); |
570 |
|
}}; |
571 |
|
testInvokeOnPool(mainPool(), a); |
572 |
|
} |
583 |
|
f.invoke(); |
584 |
|
shouldThrow(); |
585 |
|
} catch (CancellationException success) { |
586 |
< |
assertTrue(f.isDone()); |
498 |
< |
assertTrue(f.isCancelled()); |
499 |
< |
assertTrue(f.isCompletedAbnormally()); |
500 |
< |
assertTrue(f.getException() instanceof CancellationException); |
586 |
> |
checkCancelled(f); |
587 |
|
} |
588 |
|
}}; |
589 |
|
testInvokeOnPool(mainPool(), a); |
602 |
|
f.join(); |
603 |
|
shouldThrow(); |
604 |
|
} catch (CancellationException success) { |
605 |
< |
assertTrue(f.isDone()); |
520 |
< |
assertTrue(f.isCancelled()); |
521 |
< |
assertTrue(f.isCompletedAbnormally()); |
522 |
< |
assertTrue(f.getException() instanceof CancellationException); |
605 |
> |
checkCancelled(f); |
606 |
|
} |
607 |
|
}}; |
608 |
|
testInvokeOnPool(mainPool(), a); |
621 |
|
f.get(); |
622 |
|
shouldThrow(); |
623 |
|
} catch (CancellationException success) { |
624 |
< |
assertTrue(f.isDone()); |
542 |
< |
assertTrue(f.isCancelled()); |
543 |
< |
assertTrue(f.isCompletedAbnormally()); |
544 |
< |
assertTrue(f.getException() instanceof CancellationException); |
624 |
> |
checkCancelled(f); |
625 |
|
} |
626 |
|
}}; |
627 |
|
testInvokeOnPool(mainPool(), a); |
640 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
641 |
|
shouldThrow(); |
642 |
|
} catch (CancellationException success) { |
643 |
< |
assertTrue(f.isDone()); |
564 |
< |
assertTrue(f.isCancelled()); |
565 |
< |
assertTrue(f.isCompletedAbnormally()); |
566 |
< |
assertTrue(f.getException() instanceof CancellationException); |
643 |
> |
checkCancelled(f); |
644 |
|
} |
645 |
|
}}; |
646 |
|
testInvokeOnPool(mainPool(), a); |
656 |
|
assertTrue(f.cancel(true)); |
657 |
|
assertSame(f, f.fork()); |
658 |
|
f.quietlyJoin(); |
659 |
< |
assertTrue(f.isDone()); |
583 |
< |
assertTrue(f.isCompletedAbnormally()); |
584 |
< |
assertTrue(f.isCancelled()); |
585 |
< |
assertTrue(f.getException() instanceof CancellationException); |
659 |
> |
checkCancelled(f); |
660 |
|
}}; |
661 |
|
testInvokeOnPool(mainPool(), a); |
662 |
|
} |
701 |
|
public void testInForkJoinPool2() { |
702 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
703 |
|
public void realCompute() { |
704 |
< |
assertTrue(!inForkJoinPool()); |
704 |
> |
assertFalse(inForkJoinPool()); |
705 |
|
}}; |
706 |
|
assertNull(a.invoke()); |
707 |
|
} |
728 |
|
try { |
729 |
|
f.invoke(); |
730 |
|
shouldThrow(); |
731 |
< |
} catch (FJException success) {} |
731 |
> |
} catch (FJException success) { |
732 |
> |
checkCompletedAbnormally(f, success); |
733 |
> |
} |
734 |
|
}}; |
735 |
|
testInvokeOnPool(mainPool(), a); |
736 |
|
} |
744 |
|
AsyncFib f = new AsyncFib(8); |
745 |
|
AsyncFib g = new AsyncFib(9); |
746 |
|
invokeAll(f, g); |
671 |
– |
assertTrue(f.isDone()); |
747 |
|
assertEquals(21, f.number); |
673 |
– |
assertTrue(g.isDone()); |
748 |
|
assertEquals(34, g.number); |
749 |
+ |
checkCompletedNormally(f); |
750 |
+ |
checkCompletedNormally(g); |
751 |
|
}}; |
752 |
|
testInvokeOnPool(mainPool(), a); |
753 |
|
} |
760 |
|
public void realCompute() { |
761 |
|
AsyncFib f = new AsyncFib(8); |
762 |
|
invokeAll(f); |
763 |
< |
assertTrue(f.isDone()); |
763 |
> |
checkCompletedNormally(f); |
764 |
|
assertEquals(21, f.number); |
765 |
|
}}; |
766 |
|
testInvokeOnPool(mainPool(), a); |
776 |
|
AsyncFib g = new AsyncFib(9); |
777 |
|
AsyncFib h = new AsyncFib(7); |
778 |
|
invokeAll(f, g, h); |
703 |
– |
assertTrue(f.isDone()); |
779 |
|
assertEquals(21, f.number); |
705 |
– |
assertTrue(g.isDone()); |
780 |
|
assertEquals(34, g.number); |
707 |
– |
assertTrue(h.isDone()); |
781 |
|
assertEquals(13, h.number); |
782 |
+ |
checkCompletedNormally(f); |
783 |
+ |
checkCompletedNormally(g); |
784 |
+ |
checkCompletedNormally(h); |
785 |
|
}}; |
786 |
|
testInvokeOnPool(mainPool(), a); |
787 |
|
} |
800 |
|
set.add(g); |
801 |
|
set.add(h); |
802 |
|
invokeAll(set); |
727 |
– |
assertTrue(f.isDone()); |
803 |
|
assertEquals(21, f.number); |
729 |
– |
assertTrue(g.isDone()); |
804 |
|
assertEquals(34, g.number); |
731 |
– |
assertTrue(h.isDone()); |
805 |
|
assertEquals(13, h.number); |
806 |
+ |
checkCompletedNormally(f); |
807 |
+ |
checkCompletedNormally(g); |
808 |
+ |
checkCompletedNormally(h); |
809 |
|
}}; |
810 |
|
testInvokeOnPool(mainPool(), a); |
811 |
|
} |
839 |
|
try { |
840 |
|
invokeAll(f, g); |
841 |
|
shouldThrow(); |
842 |
< |
} catch (FJException success) {} |
842 |
> |
} catch (FJException success) { |
843 |
> |
checkCompletedAbnormally(g, success); |
844 |
> |
} |
845 |
|
}}; |
846 |
|
testInvokeOnPool(mainPool(), a); |
847 |
|
} |
856 |
|
try { |
857 |
|
invokeAll(g); |
858 |
|
shouldThrow(); |
859 |
< |
} catch (FJException success) {} |
859 |
> |
} catch (FJException success) { |
860 |
> |
checkCompletedAbnormally(g, success); |
861 |
> |
} |
862 |
|
}}; |
863 |
|
testInvokeOnPool(mainPool(), a); |
864 |
|
} |
875 |
|
try { |
876 |
|
invokeAll(f, g, h); |
877 |
|
shouldThrow(); |
878 |
< |
} catch (FJException success) {} |
878 |
> |
} catch (FJException success) { |
879 |
> |
checkCompletedAbnormally(g, success); |
880 |
> |
} |
881 |
|
}}; |
882 |
|
testInvokeOnPool(mainPool(), a); |
883 |
|
} |
898 |
|
try { |
899 |
|
invokeAll(set); |
900 |
|
shouldThrow(); |
901 |
< |
} catch (FJException success) {} |
901 |
> |
} catch (FJException success) { |
902 |
> |
checkCompletedAbnormally(f, success); |
903 |
> |
} |
904 |
|
}}; |
905 |
|
testInvokeOnPool(mainPool(), a); |
906 |
|
} |
918 |
|
assertSame(f, f.fork()); |
919 |
|
assertTrue(f.tryUnfork()); |
920 |
|
helpQuiesce(); |
921 |
< |
assertFalse(f.isDone()); |
922 |
< |
assertTrue(g.isDone()); |
921 |
> |
checkNotDone(f); |
922 |
> |
checkCompletedNormally(g); |
923 |
|
}}; |
924 |
|
testInvokeOnPool(singletonPool(), a); |
925 |
|
} |
939 |
|
assertSame(f, f.fork()); |
940 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
941 |
|
helpQuiesce(); |
942 |
+ |
assertEquals(0, getSurplusQueuedTaskCount()); |
943 |
+ |
checkCompletedNormally(f); |
944 |
+ |
checkCompletedNormally(g); |
945 |
+ |
checkCompletedNormally(h); |
946 |
|
}}; |
947 |
|
testInvokeOnPool(singletonPool(), a); |
948 |
|
} |
959 |
|
assertSame(f, f.fork()); |
960 |
|
assertSame(f, peekNextLocalTask()); |
961 |
|
assertNull(f.join()); |
962 |
< |
assertTrue(f.isDone()); |
962 |
> |
checkCompletedNormally(f); |
963 |
|
helpQuiesce(); |
964 |
+ |
checkCompletedNormally(g); |
965 |
|
}}; |
966 |
|
testInvokeOnPool(singletonPool(), a); |
967 |
|
} |
968 |
|
|
969 |
|
/** |
970 |
< |
* pollNextLocalTask returns most recent unexecuted task |
971 |
< |
* without executing it |
970 |
> |
* pollNextLocalTask returns most recent unexecuted task without |
971 |
> |
* executing it |
972 |
|
*/ |
973 |
|
public void testPollNextLocalTask() { |
974 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
979 |
|
assertSame(f, f.fork()); |
980 |
|
assertSame(f, pollNextLocalTask()); |
981 |
|
helpQuiesce(); |
982 |
< |
assertFalse(f.isDone()); |
982 |
> |
checkNotDone(f); |
983 |
> |
assertEquals(34, g.number); |
984 |
> |
checkCompletedNormally(g); |
985 |
|
}}; |
986 |
|
testInvokeOnPool(singletonPool(), a); |
987 |
|
} |
988 |
|
|
989 |
|
/** |
990 |
< |
* pollTask returns an unexecuted task |
900 |
< |
* without executing it |
990 |
> |
* pollTask returns an unexecuted task without executing it |
991 |
|
*/ |
992 |
|
public void testPollTask() { |
993 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
998 |
|
assertSame(f, f.fork()); |
999 |
|
assertSame(f, pollTask()); |
1000 |
|
helpQuiesce(); |
1001 |
< |
assertFalse(f.isDone()); |
1002 |
< |
assertTrue(g.isDone()); |
1001 |
> |
checkNotDone(f); |
1002 |
> |
checkCompletedNormally(g); |
1003 |
|
}}; |
1004 |
|
testInvokeOnPool(singletonPool(), a); |
1005 |
|
} |
1017 |
|
assertSame(g, peekNextLocalTask()); |
1018 |
|
assertNull(f.join()); |
1019 |
|
helpQuiesce(); |
1020 |
< |
assertTrue(f.isDone()); |
1020 |
> |
checkCompletedNormally(f); |
1021 |
> |
assertEquals(34, g.number); |
1022 |
> |
checkCompletedNormally(g); |
1023 |
|
}}; |
1024 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1025 |
|
} |
1026 |
|
|
1027 |
|
/** |
1028 |
< |
* pollNextLocalTask returns least recent unexecuted task |
1029 |
< |
* without executing it, in async mode |
1028 |
> |
* pollNextLocalTask returns least recent unexecuted task without |
1029 |
> |
* executing it, in async mode |
1030 |
|
*/ |
1031 |
|
public void testPollNextLocalTaskAsync() { |
1032 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1037 |
|
assertSame(f, f.fork()); |
1038 |
|
assertSame(g, pollNextLocalTask()); |
1039 |
|
helpQuiesce(); |
1040 |
< |
assertTrue(f.isDone()); |
1041 |
< |
assertFalse(g.isDone()); |
1040 |
> |
assertEquals(21, f.number); |
1041 |
> |
checkCompletedNormally(f); |
1042 |
> |
checkNotDone(g); |
1043 |
|
}}; |
1044 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1045 |
|
} |
1046 |
|
|
1047 |
|
/** |
1048 |
< |
* pollTask returns an unexecuted task |
1049 |
< |
* without executing it, in async mode |
1048 |
> |
* pollTask returns an unexecuted task without executing it, in |
1049 |
> |
* async mode |
1050 |
|
*/ |
1051 |
|
public void testPollTaskAsync() { |
1052 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1057 |
|
assertSame(f, f.fork()); |
1058 |
|
assertSame(g, pollTask()); |
1059 |
|
helpQuiesce(); |
1060 |
< |
assertTrue(f.isDone()); |
1061 |
< |
assertFalse(g.isDone()); |
1060 |
> |
assertEquals(21, f.number); |
1061 |
> |
checkCompletedNormally(f); |
1062 |
> |
checkNotDone(g); |
1063 |
|
}}; |
1064 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1065 |
|
} |
1077 |
|
AsyncFib f = new AsyncFib(8); |
1078 |
|
assertNull(f.invoke()); |
1079 |
|
assertEquals(21, f.number); |
1080 |
< |
assertTrue(f.isDone()); |
987 |
< |
assertFalse(f.isCancelled()); |
988 |
< |
assertFalse(f.isCompletedAbnormally()); |
989 |
< |
assertNull(f.getRawResult()); |
1080 |
> |
checkCompletedNormally(f); |
1081 |
|
}}; |
1082 |
|
testInvokeOnPool(singletonPool(), a); |
1083 |
|
} |
1093 |
|
AsyncFib f = new AsyncFib(8); |
1094 |
|
f.quietlyInvoke(); |
1095 |
|
assertEquals(21, f.number); |
1096 |
< |
assertTrue(f.isDone()); |
1006 |
< |
assertFalse(f.isCancelled()); |
1007 |
< |
assertFalse(f.isCompletedAbnormally()); |
1008 |
< |
assertNull(f.getRawResult()); |
1096 |
> |
checkCompletedNormally(f); |
1097 |
|
}}; |
1098 |
|
testInvokeOnPool(singletonPool(), a); |
1099 |
|
} |
1108 |
|
assertSame(f, f.fork()); |
1109 |
|
assertNull(f.join()); |
1110 |
|
assertEquals(21, f.number); |
1111 |
< |
assertTrue(f.isDone()); |
1024 |
< |
assertNull(f.getRawResult()); |
1111 |
> |
checkCompletedNormally(f); |
1112 |
|
}}; |
1113 |
|
testInvokeOnPool(singletonPool(), a); |
1114 |
|
} |
1123 |
|
assertSame(f, f.fork()); |
1124 |
|
assertNull(f.get()); |
1125 |
|
assertEquals(21, f.number); |
1126 |
< |
assertTrue(f.isDone()); |
1126 |
> |
checkCompletedNormally(f); |
1127 |
|
}}; |
1128 |
|
testInvokeOnPool(singletonPool(), a); |
1129 |
|
} |
1138 |
|
assertSame(f, f.fork()); |
1139 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1140 |
|
assertEquals(21, f.number); |
1141 |
< |
assertTrue(f.isDone()); |
1141 |
> |
checkCompletedNormally(f); |
1142 |
|
}}; |
1143 |
|
testInvokeOnPool(singletonPool(), a); |
1144 |
|
} |
1169 |
|
assertSame(f, f.fork()); |
1170 |
|
f.quietlyJoin(); |
1171 |
|
assertEquals(21, f.number); |
1172 |
< |
assertTrue(f.isDone()); |
1172 |
> |
checkCompletedNormally(f); |
1173 |
|
}}; |
1174 |
|
testInvokeOnPool(singletonPool(), a); |
1175 |
|
} |
1185 |
|
AsyncFib f = new AsyncFib(8); |
1186 |
|
assertSame(f, f.fork()); |
1187 |
|
f.helpQuiesce(); |
1101 |
– |
assertEquals(21, f.number); |
1102 |
– |
assertTrue(f.isDone()); |
1188 |
|
assertEquals(0, getQueuedTaskCount()); |
1189 |
+ |
assertEquals(21, f.number); |
1190 |
+ |
checkCompletedNormally(f); |
1191 |
|
}}; |
1192 |
|
testInvokeOnPool(singletonPool(), a); |
1193 |
|
} |
1203 |
|
try { |
1204 |
|
f.invoke(); |
1205 |
|
shouldThrow(); |
1206 |
< |
} catch (FJException success) {} |
1206 |
> |
} catch (FJException success) { |
1207 |
> |
checkCompletedAbnormally(f, success); |
1208 |
> |
} |
1209 |
|
}}; |
1210 |
|
testInvokeOnPool(singletonPool(), a); |
1211 |
|
} |
1218 |
|
public void realCompute() { |
1219 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1220 |
|
f.quietlyInvoke(); |
1221 |
< |
assertTrue(f.isDone()); |
1221 |
> |
assertTrue(f.getException() instanceof FJException); |
1222 |
> |
checkCompletedAbnormally(f, f.getException()); |
1223 |
|
}}; |
1224 |
|
testInvokeOnPool(singletonPool(), a); |
1225 |
|
} |
1235 |
|
try { |
1236 |
|
f.join(); |
1237 |
|
shouldThrow(); |
1238 |
< |
} catch (FJException success) {} |
1238 |
> |
} catch (FJException success) { |
1239 |
> |
checkCompletedAbnormally(f, success); |
1240 |
> |
} |
1241 |
|
}}; |
1242 |
|
testInvokeOnPool(singletonPool(), a); |
1243 |
|
} |
1256 |
|
} catch (ExecutionException success) { |
1257 |
|
Throwable cause = success.getCause(); |
1258 |
|
assertTrue(cause instanceof FJException); |
1259 |
< |
assertTrue(f.isDone()); |
1168 |
< |
assertTrue(f.isCompletedAbnormally()); |
1169 |
< |
assertSame(cause, f.getException()); |
1259 |
> |
checkCompletedAbnormally(f, cause); |
1260 |
|
} |
1261 |
|
}}; |
1262 |
|
testInvokeOnPool(singletonPool(), a); |
1276 |
|
} catch (ExecutionException success) { |
1277 |
|
Throwable cause = success.getCause(); |
1278 |
|
assertTrue(cause instanceof FJException); |
1279 |
< |
assertTrue(f.isDone()); |
1190 |
< |
assertTrue(f.isCompletedAbnormally()); |
1191 |
< |
assertSame(cause, f.getException()); |
1279 |
> |
checkCompletedAbnormally(f, cause); |
1280 |
|
} |
1281 |
|
}}; |
1282 |
|
testInvokeOnPool(singletonPool(), a); |
1291 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1292 |
|
assertSame(f, f.fork()); |
1293 |
|
f.quietlyJoin(); |
1206 |
– |
assertTrue(f.isDone()); |
1207 |
– |
assertTrue(f.isCompletedAbnormally()); |
1294 |
|
assertTrue(f.getException() instanceof FJException); |
1295 |
+ |
checkCompletedAbnormally(f, f.getException()); |
1296 |
|
}}; |
1297 |
|
testInvokeOnPool(singletonPool(), a); |
1298 |
|
} |
1309 |
|
f.invoke(); |
1310 |
|
shouldThrow(); |
1311 |
|
} catch (CancellationException success) { |
1312 |
< |
assertTrue(f.isDone()); |
1226 |
< |
assertTrue(f.isCancelled()); |
1227 |
< |
assertTrue(f.isCompletedAbnormally()); |
1228 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1312 |
> |
checkCancelled(f); |
1313 |
|
} |
1314 |
|
}}; |
1315 |
|
testInvokeOnPool(singletonPool(), a); |
1328 |
|
f.join(); |
1329 |
|
shouldThrow(); |
1330 |
|
} catch (CancellationException success) { |
1331 |
< |
assertTrue(f.isDone()); |
1248 |
< |
assertTrue(f.isCancelled()); |
1249 |
< |
assertTrue(f.isCompletedAbnormally()); |
1250 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1331 |
> |
checkCancelled(f); |
1332 |
|
} |
1333 |
|
}}; |
1334 |
|
testInvokeOnPool(singletonPool(), a); |
1347 |
|
f.get(); |
1348 |
|
shouldThrow(); |
1349 |
|
} catch (CancellationException success) { |
1350 |
< |
assertTrue(f.isDone()); |
1270 |
< |
assertTrue(f.isCancelled()); |
1271 |
< |
assertTrue(f.isCompletedAbnormally()); |
1272 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1350 |
> |
checkCancelled(f); |
1351 |
|
} |
1352 |
|
}}; |
1353 |
|
testInvokeOnPool(singletonPool(), a); |
1366 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1367 |
|
shouldThrow(); |
1368 |
|
} catch (CancellationException success) { |
1369 |
< |
assertTrue(f.isDone()); |
1292 |
< |
assertTrue(f.isCancelled()); |
1293 |
< |
assertTrue(f.isCompletedAbnormally()); |
1294 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1369 |
> |
checkCancelled(f); |
1370 |
|
} |
1371 |
|
}}; |
1372 |
|
testInvokeOnPool(singletonPool(), a); |
1382 |
|
assertTrue(f.cancel(true)); |
1383 |
|
assertSame(f, f.fork()); |
1384 |
|
f.quietlyJoin(); |
1385 |
< |
assertTrue(f.isDone()); |
1311 |
< |
assertTrue(f.isCompletedAbnormally()); |
1312 |
< |
assertTrue(f.isCancelled()); |
1313 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1385 |
> |
checkCancelled(f); |
1386 |
|
}}; |
1387 |
|
testInvokeOnPool(singletonPool(), a); |
1388 |
|
} |
1398 |
|
try { |
1399 |
|
f.invoke(); |
1400 |
|
shouldThrow(); |
1401 |
< |
} catch (FJException success) {} |
1401 |
> |
} catch (FJException success) { |
1402 |
> |
checkCompletedAbnormally(f, success); |
1403 |
> |
} |
1404 |
|
}}; |
1405 |
|
testInvokeOnPool(singletonPool(), a); |
1406 |
|
} |
1414 |
|
AsyncFib f = new AsyncFib(8); |
1415 |
|
AsyncFib g = new AsyncFib(9); |
1416 |
|
invokeAll(f, g); |
1343 |
– |
assertTrue(f.isDone()); |
1417 |
|
assertEquals(21, f.number); |
1345 |
– |
assertTrue(g.isDone()); |
1418 |
|
assertEquals(34, g.number); |
1419 |
+ |
checkCompletedNormally(f); |
1420 |
+ |
checkCompletedNormally(g); |
1421 |
|
}}; |
1422 |
|
testInvokeOnPool(singletonPool(), a); |
1423 |
|
} |
1430 |
|
public void realCompute() { |
1431 |
|
AsyncFib f = new AsyncFib(8); |
1432 |
|
invokeAll(f); |
1433 |
< |
assertTrue(f.isDone()); |
1433 |
> |
checkCompletedNormally(f); |
1434 |
|
assertEquals(21, f.number); |
1435 |
|
}}; |
1436 |
|
testInvokeOnPool(singletonPool(), a); |
1446 |
|
AsyncFib g = new AsyncFib(9); |
1447 |
|
AsyncFib h = new AsyncFib(7); |
1448 |
|
invokeAll(f, g, h); |
1375 |
– |
assertTrue(f.isDone()); |
1449 |
|
assertEquals(21, f.number); |
1377 |
– |
assertTrue(g.isDone()); |
1450 |
|
assertEquals(34, g.number); |
1379 |
– |
assertTrue(h.isDone()); |
1451 |
|
assertEquals(13, h.number); |
1452 |
+ |
checkCompletedNormally(f); |
1453 |
+ |
checkCompletedNormally(g); |
1454 |
+ |
checkCompletedNormally(h); |
1455 |
|
}}; |
1456 |
|
testInvokeOnPool(singletonPool(), a); |
1457 |
|
} |
1470 |
|
set.add(g); |
1471 |
|
set.add(h); |
1472 |
|
invokeAll(set); |
1399 |
– |
assertTrue(f.isDone()); |
1473 |
|
assertEquals(21, f.number); |
1401 |
– |
assertTrue(g.isDone()); |
1474 |
|
assertEquals(34, g.number); |
1403 |
– |
assertTrue(h.isDone()); |
1475 |
|
assertEquals(13, h.number); |
1476 |
+ |
checkCompletedNormally(f); |
1477 |
+ |
checkCompletedNormally(g); |
1478 |
+ |
checkCompletedNormally(h); |
1479 |
|
}}; |
1480 |
|
testInvokeOnPool(singletonPool(), a); |
1481 |
|
} |
1509 |
|
try { |
1510 |
|
invokeAll(f, g); |
1511 |
|
shouldThrow(); |
1512 |
< |
} catch (FJException success) {} |
1512 |
> |
} catch (FJException success) { |
1513 |
> |
checkCompletedAbnormally(g, success); |
1514 |
> |
} |
1515 |
|
}}; |
1516 |
|
testInvokeOnPool(singletonPool(), a); |
1517 |
|
} |
1526 |
|
try { |
1527 |
|
invokeAll(g); |
1528 |
|
shouldThrow(); |
1529 |
< |
} catch (FJException success) {} |
1529 |
> |
} catch (FJException success) { |
1530 |
> |
checkCompletedAbnormally(g, success); |
1531 |
> |
} |
1532 |
|
}}; |
1533 |
|
testInvokeOnPool(singletonPool(), a); |
1534 |
|
} |
1545 |
|
try { |
1546 |
|
invokeAll(f, g, h); |
1547 |
|
shouldThrow(); |
1548 |
< |
} catch (FJException success) {} |
1548 |
> |
} catch (FJException success) { |
1549 |
> |
checkCompletedAbnormally(g, success); |
1550 |
> |
} |
1551 |
|
}}; |
1552 |
|
testInvokeOnPool(singletonPool(), a); |
1553 |
|
} |
1568 |
|
try { |
1569 |
|
invokeAll(set); |
1570 |
|
shouldThrow(); |
1571 |
< |
} catch (FJException success) {} |
1571 |
> |
} catch (FJException success) { |
1572 |
> |
checkCompletedAbnormally(f, success); |
1573 |
> |
} |
1574 |
|
}}; |
1575 |
|
testInvokeOnPool(singletonPool(), a); |
1576 |
|
} |