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() { |
672 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
673 |
|
public void realCompute() { |
674 |
|
setRawResult(null); |
675 |
+ |
assertNull(getRawResult()); |
676 |
|
}}; |
677 |
|
assertNull(a.invoke()); |
678 |
|
} |