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); } |
127 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
128 |
|
} |
129 |
|
|
130 |
< |
void checkTaskThrew(RecursiveAction a, Throwable t) { |
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(); |
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() { |
407 |
|
f.invoke(); |
408 |
|
shouldThrow(); |
409 |
|
} catch (FJException success) { |
410 |
< |
checkTaskThrew(f, success); |
410 |
> |
checkCompletedAbnormally(f, success); |
411 |
|
} |
412 |
|
}}; |
413 |
|
testInvokeOnPool(mainPool(), a); |
422 |
|
FailingFibAction f = new FailingFibAction(8); |
423 |
|
f.quietlyInvoke(); |
424 |
|
assertTrue(f.getException() instanceof FJException); |
425 |
< |
checkTaskThrew(f, f.getException()); |
425 |
> |
checkCompletedAbnormally(f, f.getException()); |
426 |
|
}}; |
427 |
|
testInvokeOnPool(mainPool(), a); |
428 |
|
} |
439 |
|
f.join(); |
440 |
|
shouldThrow(); |
441 |
|
} catch (FJException success) { |
442 |
< |
checkTaskThrew(f, success); |
442 |
> |
checkCompletedAbnormally(f, success); |
443 |
|
} |
444 |
|
}}; |
445 |
|
testInvokeOnPool(mainPool(), a); |
457 |
|
f.get(); |
458 |
|
shouldThrow(); |
459 |
|
} catch (ExecutionException success) { |
460 |
< |
checkTaskThrew(f, success.getCause()); |
460 |
> |
Throwable cause = success.getCause(); |
461 |
> |
assertTrue(cause instanceof FJException); |
462 |
> |
checkCompletedAbnormally(f, cause); |
463 |
|
} |
464 |
|
}}; |
465 |
|
testInvokeOnPool(mainPool(), a); |
477 |
|
f.get(5L, TimeUnit.SECONDS); |
478 |
|
shouldThrow(); |
479 |
|
} catch (ExecutionException success) { |
480 |
< |
checkTaskThrew(f, success.getCause()); |
480 |
> |
Throwable cause = success.getCause(); |
481 |
> |
assertTrue(cause instanceof FJException); |
482 |
> |
checkCompletedAbnormally(f, cause); |
483 |
|
} |
484 |
|
}}; |
485 |
|
testInvokeOnPool(mainPool(), a); |
495 |
|
assertSame(f, f.fork()); |
496 |
|
f.quietlyJoin(); |
497 |
|
assertTrue(f.getException() instanceof FJException); |
498 |
< |
checkTaskThrew(f, f.getException()); |
498 |
> |
checkCompletedAbnormally(f, f.getException()); |
499 |
|
}}; |
500 |
|
testInvokeOnPool(mainPool(), a); |
501 |
|
} |
672 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
673 |
|
public void realCompute() { |
674 |
|
setRawResult(null); |
675 |
+ |
assertNull(getRawResult()); |
676 |
|
}}; |
677 |
|
assertNull(a.invoke()); |
678 |
|
} |
709 |
|
f.invoke(); |
710 |
|
shouldThrow(); |
711 |
|
} catch (FJException success) { |
712 |
< |
checkTaskThrew(f, success); |
712 |
> |
checkCompletedAbnormally(f, success); |
713 |
|
} |
714 |
|
}}; |
715 |
|
testInvokeOnPool(mainPool(), a); |
841 |
|
invokeAll(f, g); |
842 |
|
shouldThrow(); |
843 |
|
} catch (FJException success) { |
844 |
< |
checkTaskThrew(g, success); |
844 |
> |
checkCompletedAbnormally(g, success); |
845 |
|
} |
846 |
|
}}; |
847 |
|
testInvokeOnPool(mainPool(), a); |
858 |
|
invokeAll(g); |
859 |
|
shouldThrow(); |
860 |
|
} catch (FJException success) { |
861 |
< |
checkTaskThrew(g, success); |
861 |
> |
checkCompletedAbnormally(g, success); |
862 |
|
} |
863 |
|
}}; |
864 |
|
testInvokeOnPool(mainPool(), a); |
877 |
|
invokeAll(f, g, h); |
878 |
|
shouldThrow(); |
879 |
|
} catch (FJException success) { |
880 |
< |
checkTaskThrew(g, success); |
880 |
> |
checkCompletedAbnormally(g, success); |
881 |
|
} |
882 |
|
}}; |
883 |
|
testInvokeOnPool(mainPool(), a); |
900 |
|
invokeAll(set); |
901 |
|
shouldThrow(); |
902 |
|
} catch (FJException success) { |
903 |
< |
checkTaskThrew(f, success); |
903 |
> |
checkCompletedAbnormally(f, success); |
904 |
|
} |
905 |
|
}}; |
906 |
|
testInvokeOnPool(mainPool(), a); |
940 |
|
assertSame(f, f.fork()); |
941 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
942 |
|
helpQuiesce(); |
943 |
+ |
assertEquals(0, getSurplusQueuedTaskCount()); |
944 |
|
checkCompletedNormally(f); |
945 |
|
checkCompletedNormally(g); |
946 |
|
checkCompletedNormally(h); |