11 |
|
import java.util.concurrent.ForkJoinWorkerThread; |
12 |
|
import java.util.concurrent.RecursiveAction; |
13 |
|
import java.util.concurrent.TimeUnit; |
14 |
+ |
import java.util.concurrent.TimeoutException; |
15 |
+ |
import static java.util.concurrent.TimeUnit.SECONDS; |
16 |
|
import java.util.HashSet; |
17 |
|
|
18 |
|
public class RecursiveActionTest extends JSR166TestCase { |
41 |
|
|
42 |
|
private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { |
43 |
|
try { |
44 |
< |
assertFalse(a.isDone()); |
43 |
< |
assertFalse(a.isCompletedNormally()); |
44 |
< |
assertFalse(a.isCompletedAbnormally()); |
45 |
< |
assertFalse(a.isCancelled()); |
46 |
< |
assertNull(a.getException()); |
44 |
> |
checkNotDone(a); |
45 |
|
|
46 |
|
assertNull(pool.invoke(a)); |
47 |
|
|
48 |
< |
assertTrue(a.isDone()); |
51 |
< |
assertTrue(a.isCompletedNormally()); |
52 |
< |
assertFalse(a.isCompletedAbnormally()); |
53 |
< |
assertFalse(a.isCancelled()); |
54 |
< |
assertNull(a.getException()); |
48 |
> |
checkCompletedNormally(a); |
49 |
|
} finally { |
50 |
|
joinPool(pool); |
51 |
|
} |
52 |
|
} |
53 |
|
|
54 |
+ |
void checkNotDone(RecursiveAction a) { |
55 |
+ |
assertFalse(a.isDone()); |
56 |
+ |
assertFalse(a.isCompletedNormally()); |
57 |
+ |
assertFalse(a.isCompletedAbnormally()); |
58 |
+ |
assertFalse(a.isCancelled()); |
59 |
+ |
assertNull(a.getException()); |
60 |
+ |
assertNull(a.getRawResult()); |
61 |
+ |
|
62 |
+ |
if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) { |
63 |
+ |
Thread.currentThread().interrupt(); |
64 |
+ |
try { |
65 |
+ |
a.get(); |
66 |
+ |
shouldThrow(); |
67 |
+ |
} catch (InterruptedException success) { |
68 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
69 |
+ |
|
70 |
+ |
Thread.currentThread().interrupt(); |
71 |
+ |
try { |
72 |
+ |
a.get(5L, SECONDS); |
73 |
+ |
shouldThrow(); |
74 |
+ |
} catch (InterruptedException success) { |
75 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
76 |
+ |
} |
77 |
+ |
|
78 |
+ |
try { |
79 |
+ |
a.get(0L, SECONDS); |
80 |
+ |
shouldThrow(); |
81 |
+ |
} catch (TimeoutException success) { |
82 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
83 |
+ |
} |
84 |
+ |
|
85 |
+ |
void checkCompletedNormally(RecursiveAction a) { |
86 |
+ |
assertTrue(a.isDone()); |
87 |
+ |
assertFalse(a.isCancelled()); |
88 |
+ |
assertTrue(a.isCompletedNormally()); |
89 |
+ |
assertFalse(a.isCompletedAbnormally()); |
90 |
+ |
assertNull(a.getException()); |
91 |
+ |
assertNull(a.getRawResult()); |
92 |
+ |
assertNull(a.join()); |
93 |
+ |
assertFalse(a.cancel(false)); |
94 |
+ |
assertFalse(a.cancel(true)); |
95 |
+ |
try { |
96 |
+ |
assertNull(a.get()); |
97 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
98 |
+ |
try { |
99 |
+ |
assertNull(a.get(5L, SECONDS)); |
100 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
101 |
+ |
} |
102 |
+ |
|
103 |
+ |
void checkCancelled(RecursiveAction a) { |
104 |
+ |
assertTrue(a.isDone()); |
105 |
+ |
assertTrue(a.isCancelled()); |
106 |
+ |
assertFalse(a.isCompletedNormally()); |
107 |
+ |
assertTrue(a.isCompletedAbnormally()); |
108 |
+ |
assertTrue(a.getException() instanceof CancellationException); |
109 |
+ |
assertNull(a.getRawResult()); |
110 |
+ |
|
111 |
+ |
try { |
112 |
+ |
a.join(); |
113 |
+ |
shouldThrow(); |
114 |
+ |
} catch (CancellationException success) { |
115 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
116 |
+ |
|
117 |
+ |
try { |
118 |
+ |
a.get(); |
119 |
+ |
shouldThrow(); |
120 |
+ |
} catch (CancellationException success) { |
121 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
122 |
+ |
|
123 |
+ |
try { |
124 |
+ |
a.get(5L, SECONDS); |
125 |
+ |
shouldThrow(); |
126 |
+ |
} catch (CancellationException success) { |
127 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
128 |
+ |
} |
129 |
+ |
|
130 |
+ |
void checkCompletedAbnormally(RecursiveAction a, Throwable t) { |
131 |
+ |
assertTrue(a.isDone()); |
132 |
+ |
assertFalse(a.isCancelled()); |
133 |
+ |
assertFalse(a.isCompletedNormally()); |
134 |
+ |
assertTrue(a.isCompletedAbnormally()); |
135 |
+ |
assertSame(t, a.getException()); |
136 |
+ |
assertNull(a.getRawResult()); |
137 |
+ |
assertFalse(a.cancel(false)); |
138 |
+ |
assertFalse(a.cancel(true)); |
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 |
|
static final class FJException extends RuntimeException { |
163 |
|
FJException() { super(); } |
164 |
|
} |
210 |
|
FibAction f = new FibAction(8); |
211 |
|
assertNull(f.invoke()); |
212 |
|
assertEquals(21, f.result); |
213 |
< |
assertTrue(f.isDone()); |
112 |
< |
assertFalse(f.isCancelled()); |
113 |
< |
assertFalse(f.isCompletedAbnormally()); |
114 |
< |
assertNull(f.getRawResult()); |
213 |
> |
checkCompletedNormally(f); |
214 |
|
}}; |
215 |
|
testInvokeOnPool(mainPool(), a); |
216 |
|
} |
226 |
|
FibAction f = new FibAction(8); |
227 |
|
f.quietlyInvoke(); |
228 |
|
assertEquals(21, f.result); |
229 |
< |
assertTrue(f.isDone()); |
131 |
< |
assertFalse(f.isCancelled()); |
132 |
< |
assertFalse(f.isCompletedAbnormally()); |
133 |
< |
assertNull(f.getRawResult()); |
229 |
> |
checkCompletedNormally(f); |
230 |
|
}}; |
231 |
|
testInvokeOnPool(mainPool(), a); |
232 |
|
} |
241 |
|
assertSame(f, f.fork()); |
242 |
|
assertNull(f.join()); |
243 |
|
assertEquals(21, f.result); |
244 |
< |
assertTrue(f.isDone()); |
149 |
< |
assertNull(f.getRawResult()); |
244 |
> |
checkCompletedNormally(f); |
245 |
|
}}; |
246 |
|
testInvokeOnPool(mainPool(), a); |
247 |
|
} |
248 |
|
|
249 |
|
/** |
250 |
+ |
* join/quietlyJoin of a forked task ignores interrupts |
251 |
+ |
*/ |
252 |
+ |
public void testJoinIgnoresInterrupts() { |
253 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
254 |
+ |
public void realCompute() { |
255 |
+ |
FibAction f = new FibAction(8); |
256 |
+ |
|
257 |
+ |
// test join() |
258 |
+ |
assertSame(f, f.fork()); |
259 |
+ |
Thread.currentThread().interrupt(); |
260 |
+ |
assertNull(f.join()); |
261 |
+ |
assertTrue(Thread.interrupted()); |
262 |
+ |
assertEquals(21, f.result); |
263 |
+ |
checkCompletedNormally(f); |
264 |
+ |
|
265 |
+ |
f.reinitialize(); |
266 |
+ |
f.cancel(true); |
267 |
+ |
assertSame(f, f.fork()); |
268 |
+ |
Thread.currentThread().interrupt(); |
269 |
+ |
try { |
270 |
+ |
f.join(); |
271 |
+ |
shouldThrow(); |
272 |
+ |
} catch (CancellationException success) { |
273 |
+ |
assertTrue(Thread.interrupted()); |
274 |
+ |
checkCancelled(f); |
275 |
+ |
} |
276 |
+ |
|
277 |
+ |
f.reinitialize(); |
278 |
+ |
f.completeExceptionally(new FJException()); |
279 |
+ |
assertSame(f, f.fork()); |
280 |
+ |
Thread.currentThread().interrupt(); |
281 |
+ |
try { |
282 |
+ |
f.join(); |
283 |
+ |
shouldThrow(); |
284 |
+ |
} catch (FJException success) { |
285 |
+ |
assertTrue(Thread.interrupted()); |
286 |
+ |
checkCompletedAbnormally(f, success); |
287 |
+ |
} |
288 |
+ |
|
289 |
+ |
// test quietlyJoin() |
290 |
+ |
f.reinitialize(); |
291 |
+ |
assertSame(f, f.fork()); |
292 |
+ |
Thread.currentThread().interrupt(); |
293 |
+ |
f.quietlyJoin(); |
294 |
+ |
assertTrue(Thread.interrupted()); |
295 |
+ |
assertEquals(21, f.result); |
296 |
+ |
checkCompletedNormally(f); |
297 |
+ |
|
298 |
+ |
f.reinitialize(); |
299 |
+ |
f.cancel(true); |
300 |
+ |
assertSame(f, f.fork()); |
301 |
+ |
Thread.currentThread().interrupt(); |
302 |
+ |
f.quietlyJoin(); |
303 |
+ |
assertTrue(Thread.interrupted()); |
304 |
+ |
checkCancelled(f); |
305 |
+ |
|
306 |
+ |
f.reinitialize(); |
307 |
+ |
f.completeExceptionally(new FJException()); |
308 |
+ |
assertSame(f, f.fork()); |
309 |
+ |
Thread.currentThread().interrupt(); |
310 |
+ |
f.quietlyJoin(); |
311 |
+ |
assertTrue(Thread.interrupted()); |
312 |
+ |
checkCompletedAbnormally(f, f.getException()); |
313 |
+ |
}}; |
314 |
+ |
testInvokeOnPool(mainPool(), a); |
315 |
+ |
a.reinitialize(); |
316 |
+ |
testInvokeOnPool(singletonPool(), a); |
317 |
+ |
} |
318 |
+ |
|
319 |
+ |
/** |
320 |
|
* get of a forked task returns when task completes |
321 |
|
*/ |
322 |
|
public void testForkGet() { |
326 |
|
assertSame(f, f.fork()); |
327 |
|
assertNull(f.get()); |
328 |
|
assertEquals(21, f.result); |
329 |
< |
assertTrue(f.isDone()); |
329 |
> |
checkCompletedNormally(f); |
330 |
|
}}; |
331 |
|
testInvokeOnPool(mainPool(), a); |
332 |
|
} |
339 |
|
public void realCompute() throws Exception { |
340 |
|
FibAction f = new FibAction(8); |
341 |
|
assertSame(f, f.fork()); |
342 |
< |
assertNull(f.get(5L, TimeUnit.SECONDS)); |
342 |
> |
assertNull(f.get(5L, SECONDS)); |
343 |
|
assertEquals(21, f.result); |
344 |
< |
assertTrue(f.isDone()); |
344 |
> |
checkCompletedNormally(f); |
345 |
|
}}; |
346 |
|
testInvokeOnPool(mainPool(), a); |
347 |
|
} |
372 |
|
assertSame(f, f.fork()); |
373 |
|
f.quietlyJoin(); |
374 |
|
assertEquals(21, f.result); |
375 |
< |
assertTrue(f.isDone()); |
375 |
> |
checkCompletedNormally(f); |
376 |
|
}}; |
377 |
|
testInvokeOnPool(mainPool(), a); |
378 |
|
} |
389 |
|
assertSame(f, f.fork()); |
390 |
|
f.helpQuiesce(); |
391 |
|
assertEquals(21, f.result); |
227 |
– |
assertTrue(f.isDone()); |
392 |
|
assertEquals(0, getQueuedTaskCount()); |
393 |
+ |
checkCompletedNormally(f); |
394 |
|
}}; |
395 |
|
testInvokeOnPool(mainPool(), a); |
396 |
|
} |
406 |
|
try { |
407 |
|
f.invoke(); |
408 |
|
shouldThrow(); |
409 |
< |
} catch (FJException success) {} |
409 |
> |
} catch (FJException success) { |
410 |
> |
checkCompletedAbnormally(f, success); |
411 |
> |
} |
412 |
|
}}; |
413 |
|
testInvokeOnPool(mainPool(), a); |
414 |
|
} |
421 |
|
public void realCompute() { |
422 |
|
FailingFibAction f = new FailingFibAction(8); |
423 |
|
f.quietlyInvoke(); |
424 |
< |
assertTrue(f.isDone()); |
424 |
> |
assertTrue(f.getException() instanceof FJException); |
425 |
> |
checkCompletedAbnormally(f, f.getException()); |
426 |
|
}}; |
427 |
|
testInvokeOnPool(mainPool(), a); |
428 |
|
} |
438 |
|
try { |
439 |
|
f.join(); |
440 |
|
shouldThrow(); |
441 |
< |
} catch (FJException success) {} |
441 |
> |
} catch (FJException success) { |
442 |
> |
checkCompletedAbnormally(f, success); |
443 |
> |
} |
444 |
|
}}; |
445 |
|
testInvokeOnPool(mainPool(), a); |
446 |
|
} |
456 |
|
try { |
457 |
|
f.get(); |
458 |
|
shouldThrow(); |
459 |
< |
} catch (ExecutionException success) {} |
459 |
> |
} catch (ExecutionException success) { |
460 |
> |
Throwable cause = success.getCause(); |
461 |
> |
assertTrue(cause instanceof FJException); |
462 |
> |
checkCompletedAbnormally(f, cause); |
463 |
> |
} |
464 |
|
}}; |
465 |
|
testInvokeOnPool(mainPool(), a); |
466 |
|
} |
476 |
|
try { |
477 |
|
f.get(5L, TimeUnit.SECONDS); |
478 |
|
shouldThrow(); |
479 |
< |
} catch (ExecutionException success) {} |
479 |
> |
} catch (ExecutionException success) { |
480 |
> |
Throwable cause = success.getCause(); |
481 |
> |
assertTrue(cause instanceof FJException); |
482 |
> |
checkCompletedAbnormally(f, cause); |
483 |
> |
} |
484 |
|
}}; |
485 |
|
testInvokeOnPool(mainPool(), a); |
486 |
|
} |
494 |
|
FailingFibAction f = new FailingFibAction(8); |
495 |
|
assertSame(f, f.fork()); |
496 |
|
f.quietlyJoin(); |
319 |
– |
assertTrue(f.isDone()); |
320 |
– |
assertTrue(f.isCompletedAbnormally()); |
497 |
|
assertTrue(f.getException() instanceof FJException); |
498 |
+ |
checkCompletedAbnormally(f, f.getException()); |
499 |
|
}}; |
500 |
|
testInvokeOnPool(mainPool(), a); |
501 |
|
} |
511 |
|
try { |
512 |
|
f.invoke(); |
513 |
|
shouldThrow(); |
514 |
< |
} catch (CancellationException success) {} |
514 |
> |
} catch (CancellationException success) { |
515 |
> |
checkCancelled(f); |
516 |
> |
} |
517 |
|
}}; |
518 |
|
testInvokeOnPool(mainPool(), a); |
519 |
|
} |
530 |
|
try { |
531 |
|
f.join(); |
532 |
|
shouldThrow(); |
533 |
< |
} catch (CancellationException success) {} |
533 |
> |
} catch (CancellationException success) { |
534 |
> |
checkCancelled(f); |
535 |
> |
} |
536 |
|
}}; |
537 |
|
testInvokeOnPool(mainPool(), a); |
538 |
|
} |
549 |
|
try { |
550 |
|
f.get(); |
551 |
|
shouldThrow(); |
552 |
< |
} catch (CancellationException success) {} |
552 |
> |
} catch (CancellationException success) { |
553 |
> |
checkCancelled(f); |
554 |
> |
} |
555 |
|
}}; |
556 |
|
testInvokeOnPool(mainPool(), a); |
557 |
|
} |
566 |
|
assertTrue(f.cancel(true)); |
567 |
|
assertSame(f, f.fork()); |
568 |
|
try { |
569 |
< |
f.get(5L, TimeUnit.SECONDS); |
569 |
> |
f.get(5L, SECONDS); |
570 |
|
shouldThrow(); |
571 |
< |
} catch (CancellationException success) {} |
571 |
> |
} catch (CancellationException success) { |
572 |
> |
checkCancelled(f); |
573 |
> |
} |
574 |
|
}}; |
575 |
|
testInvokeOnPool(mainPool(), a); |
576 |
|
} |
585 |
|
assertTrue(f.cancel(true)); |
586 |
|
assertSame(f, f.fork()); |
587 |
|
f.quietlyJoin(); |
588 |
< |
assertTrue(f.isDone()); |
404 |
< |
assertTrue(f.isCompletedAbnormally()); |
405 |
< |
assertTrue(f.isCancelled()); |
406 |
< |
assertTrue(f.getException() instanceof CancellationException); |
588 |
> |
checkCancelled(f); |
589 |
|
}}; |
590 |
|
testInvokeOnPool(mainPool(), a); |
591 |
|
} |
658 |
|
public void realCompute() { |
659 |
|
ForkJoinWorkerThread w = |
660 |
|
(ForkJoinWorkerThread)(Thread.currentThread()); |
661 |
< |
int idx = w.getPoolIndex(); |
662 |
< |
assertTrue(idx >= 0); |
481 |
< |
assertTrue(idx < mainPool.getPoolSize()); |
661 |
> |
assertTrue(w.getPoolIndex() >= 0); |
662 |
> |
assertTrue(w.getPoolIndex() < mainPool.getPoolSize()); |
663 |
|
}}; |
664 |
|
testInvokeOnPool(mainPool, a); |
665 |
|
} |
672 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
673 |
|
public void realCompute() { |
674 |
|
setRawResult(null); |
675 |
+ |
assertNull(getRawResult()); |
676 |
|
}}; |
677 |
|
assertNull(a.invoke()); |
678 |
|
} |
684 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
685 |
|
public void realCompute() { |
686 |
|
FibAction f = new FibAction(8); |
687 |
< |
assertNull(f.invoke()); |
688 |
< |
assertEquals(21, f.result); |
689 |
< |
assertTrue(f.isDone()); |
690 |
< |
assertFalse(f.isCancelled()); |
691 |
< |
assertFalse(f.isCompletedAbnormally()); |
692 |
< |
f.reinitialize(); |
693 |
< |
assertNull(f.invoke()); |
694 |
< |
assertEquals(21, f.result); |
687 |
> |
checkNotDone(f); |
688 |
> |
|
689 |
> |
for (int i = 0; i < 3; i++) { |
690 |
> |
assertNull(f.invoke()); |
691 |
> |
assertEquals(21, f.result); |
692 |
> |
checkCompletedNormally(f); |
693 |
> |
f.reinitialize(); |
694 |
> |
checkNotDone(f); |
695 |
> |
} |
696 |
|
}}; |
697 |
|
testInvokeOnPool(mainPool(), a); |
698 |
|
} |
708 |
|
try { |
709 |
|
f.invoke(); |
710 |
|
shouldThrow(); |
711 |
< |
} catch (FJException success) {} |
711 |
> |
} catch (FJException success) { |
712 |
> |
checkCompletedAbnormally(f, success); |
713 |
> |
} |
714 |
|
}}; |
715 |
|
testInvokeOnPool(mainPool(), a); |
716 |
|
} |
724 |
|
FibAction f = new FibAction(8); |
725 |
|
f.complete(null); |
726 |
|
assertNull(f.invoke()); |
542 |
– |
assertTrue(f.isDone()); |
727 |
|
assertEquals(0, f.result); |
728 |
+ |
checkCompletedNormally(f); |
729 |
|
}}; |
730 |
|
testInvokeOnPool(mainPool(), a); |
731 |
|
} |
739 |
|
FibAction f = new FibAction(8); |
740 |
|
FibAction g = new FibAction(9); |
741 |
|
invokeAll(f, g); |
742 |
< |
assertTrue(f.isDone()); |
742 |
> |
checkCompletedNormally(f); |
743 |
|
assertEquals(21, f.result); |
744 |
< |
assertTrue(g.isDone()); |
744 |
> |
checkCompletedNormally(g); |
745 |
|
assertEquals(34, g.result); |
746 |
|
}}; |
747 |
|
testInvokeOnPool(mainPool(), a); |
755 |
|
public void realCompute() { |
756 |
|
FibAction f = new FibAction(8); |
757 |
|
invokeAll(f); |
758 |
< |
assertTrue(f.isDone()); |
758 |
> |
checkCompletedNormally(f); |
759 |
|
assertEquals(21, f.result); |
760 |
|
}}; |
761 |
|
testInvokeOnPool(mainPool(), a); |
772 |
|
FibAction h = new FibAction(7); |
773 |
|
invokeAll(f, g, h); |
774 |
|
assertTrue(f.isDone()); |
590 |
– |
assertEquals(21, f.result); |
775 |
|
assertTrue(g.isDone()); |
592 |
– |
assertEquals(34, g.result); |
776 |
|
assertTrue(h.isDone()); |
777 |
+ |
checkCompletedNormally(f); |
778 |
+ |
assertEquals(21, f.result); |
779 |
+ |
checkCompletedNormally(g); |
780 |
+ |
assertEquals(34, g.result); |
781 |
+ |
checkCompletedNormally(g); |
782 |
|
assertEquals(13, h.result); |
783 |
|
}}; |
784 |
|
testInvokeOnPool(mainPool(), a); |
799 |
|
set.add(h); |
800 |
|
invokeAll(set); |
801 |
|
assertTrue(f.isDone()); |
614 |
– |
assertEquals(21, f.result); |
802 |
|
assertTrue(g.isDone()); |
616 |
– |
assertEquals(34, g.result); |
803 |
|
assertTrue(h.isDone()); |
804 |
+ |
checkCompletedNormally(f); |
805 |
+ |
assertEquals(21, f.result); |
806 |
+ |
checkCompletedNormally(g); |
807 |
+ |
assertEquals(34, g.result); |
808 |
+ |
checkCompletedNormally(g); |
809 |
|
assertEquals(13, h.result); |
810 |
|
}}; |
811 |
|
testInvokeOnPool(mainPool(), a); |
840 |
|
try { |
841 |
|
invokeAll(f, g); |
842 |
|
shouldThrow(); |
843 |
< |
} catch (FJException success) {} |
843 |
> |
} catch (FJException success) { |
844 |
> |
checkCompletedAbnormally(g, success); |
845 |
> |
} |
846 |
|
}}; |
847 |
|
testInvokeOnPool(mainPool(), a); |
848 |
|
} |
857 |
|
try { |
858 |
|
invokeAll(g); |
859 |
|
shouldThrow(); |
860 |
< |
} catch (FJException success) {} |
860 |
> |
} catch (FJException success) { |
861 |
> |
checkCompletedAbnormally(g, success); |
862 |
> |
} |
863 |
|
}}; |
864 |
|
testInvokeOnPool(mainPool(), a); |
865 |
|
} |
876 |
|
try { |
877 |
|
invokeAll(f, g, h); |
878 |
|
shouldThrow(); |
879 |
< |
} catch (FJException success) {} |
879 |
> |
} catch (FJException success) { |
880 |
> |
checkCompletedAbnormally(g, success); |
881 |
> |
} |
882 |
|
}}; |
883 |
|
testInvokeOnPool(mainPool(), a); |
884 |
|
} |
899 |
|
try { |
900 |
|
invokeAll(set); |
901 |
|
shouldThrow(); |
902 |
< |
} catch (FJException success) {} |
902 |
> |
} catch (FJException success) { |
903 |
> |
checkCompletedAbnormally(f, success); |
904 |
> |
} |
905 |
|
}}; |
906 |
|
testInvokeOnPool(mainPool(), a); |
907 |
|
} |
919 |
|
assertSame(f, f.fork()); |
920 |
|
assertTrue(f.tryUnfork()); |
921 |
|
helpQuiesce(); |
922 |
< |
assertFalse(f.isDone()); |
923 |
< |
assertTrue(g.isDone()); |
922 |
> |
checkNotDone(f); |
923 |
> |
checkCompletedNormally(g); |
924 |
|
}}; |
925 |
|
testInvokeOnPool(singletonPool(), a); |
926 |
|
} |
940 |
|
assertSame(f, f.fork()); |
941 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
942 |
|
helpQuiesce(); |
943 |
+ |
assertEquals(0, getSurplusQueuedTaskCount()); |
944 |
+ |
checkCompletedNormally(f); |
945 |
+ |
checkCompletedNormally(g); |
946 |
+ |
checkCompletedNormally(h); |
947 |
|
}}; |
948 |
|
testInvokeOnPool(singletonPool(), a); |
949 |
|
} |
960 |
|
assertSame(f, f.fork()); |
961 |
|
assertSame(f, peekNextLocalTask()); |
962 |
|
assertNull(f.join()); |
963 |
< |
assertTrue(f.isDone()); |
963 |
> |
checkCompletedNormally(f); |
964 |
|
helpQuiesce(); |
965 |
+ |
checkCompletedNormally(f); |
966 |
+ |
checkCompletedNormally(g); |
967 |
|
}}; |
968 |
|
testInvokeOnPool(singletonPool(), a); |
969 |
|
} |
981 |
|
assertSame(f, f.fork()); |
982 |
|
assertSame(f, pollNextLocalTask()); |
983 |
|
helpQuiesce(); |
984 |
< |
assertFalse(f.isDone()); |
984 |
> |
checkNotDone(f); |
985 |
> |
checkCompletedNormally(g); |
986 |
|
}}; |
987 |
|
testInvokeOnPool(singletonPool(), a); |
988 |
|
} |
989 |
|
|
990 |
|
/** |
991 |
< |
* pollTask returns an unexecuted task |
786 |
< |
* without executing it |
991 |
> |
* pollTask returns an unexecuted task without executing it |
992 |
|
*/ |
993 |
|
public void testPollTask() { |
994 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
999 |
|
assertSame(f, f.fork()); |
1000 |
|
assertSame(f, pollTask()); |
1001 |
|
helpQuiesce(); |
1002 |
< |
assertFalse(f.isDone()); |
1003 |
< |
assertTrue(g.isDone()); |
1002 |
> |
checkNotDone(f); |
1003 |
> |
checkCompletedNormally(g); |
1004 |
|
}}; |
1005 |
|
testInvokeOnPool(singletonPool(), a); |
1006 |
|
} |
1018 |
|
assertSame(g, peekNextLocalTask()); |
1019 |
|
assertNull(f.join()); |
1020 |
|
helpQuiesce(); |
1021 |
< |
assertTrue(f.isDone()); |
1021 |
> |
checkCompletedNormally(f); |
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 |
> |
checkCompletedNormally(f); |
1041 |
> |
checkNotDone(g); |
1042 |
|
}}; |
1043 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1044 |
|
} |
1045 |
|
|
1046 |
|
/** |
1047 |
< |
* pollTask returns an unexecuted task |
1048 |
< |
* without executing it, in async mode |
1047 |
> |
* pollTask returns an unexecuted task without executing it, in |
1048 |
> |
* async mode |
1049 |
|
*/ |
1050 |
|
public void testPollTaskAsync() { |
1051 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1056 |
|
assertSame(f, f.fork()); |
1057 |
|
assertSame(g, pollTask()); |
1058 |
|
helpQuiesce(); |
1059 |
< |
assertTrue(f.isDone()); |
1060 |
< |
assertFalse(g.isDone()); |
1059 |
> |
checkCompletedNormally(f); |
1060 |
> |
checkNotDone(g); |
1061 |
|
}}; |
1062 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1063 |
|
} |