11 |
|
import java.util.concurrent.RecursiveAction; |
12 |
|
import java.util.concurrent.TimeUnit; |
13 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
14 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
15 |
|
import java.util.HashSet; |
16 |
|
import junit.framework.*; |
17 |
|
|
317 |
|
public void realCompute() throws Exception { |
318 |
|
AsyncFib f = new AsyncFib(8); |
319 |
|
assertSame(f, f.fork()); |
320 |
< |
assertNull(f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
320 |
> |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
321 |
|
assertEquals(21, f.number); |
322 |
|
assertTrue(f.isDone()); |
323 |
|
}}; |
429 |
|
try { |
430 |
|
f.get(); |
431 |
|
shouldThrow(); |
432 |
< |
} catch (ExecutionException success) {} |
432 |
> |
} catch (ExecutionException success) { |
433 |
> |
Throwable cause = success.getCause(); |
434 |
> |
assertTrue(cause instanceof FJException); |
435 |
> |
assertTrue(f.isDone()); |
436 |
> |
assertTrue(f.isCompletedAbnormally()); |
437 |
> |
assertSame(cause, f.getException()); |
438 |
> |
} |
439 |
|
}}; |
440 |
|
testInvokeOnPool(mainPool(), a); |
441 |
|
} |
449 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
450 |
|
assertSame(f, f.fork()); |
451 |
|
try { |
452 |
< |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
452 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
453 |
|
shouldThrow(); |
454 |
< |
} catch (ExecutionException success) {} |
454 |
> |
} catch (ExecutionException success) { |
455 |
> |
Throwable cause = success.getCause(); |
456 |
> |
assertTrue(cause instanceof FJException); |
457 |
> |
assertTrue(f.isDone()); |
458 |
> |
assertTrue(f.isCompletedAbnormally()); |
459 |
> |
assertSame(cause, f.getException()); |
460 |
> |
} |
461 |
|
}}; |
462 |
|
testInvokeOnPool(mainPool(), a); |
463 |
|
} |
489 |
|
try { |
490 |
|
f.invoke(); |
491 |
|
shouldThrow(); |
492 |
< |
} catch (CancellationException success) {} |
492 |
> |
} catch (CancellationException success) { |
493 |
> |
assertTrue(f.isDone()); |
494 |
> |
assertTrue(f.isCancelled()); |
495 |
> |
assertTrue(f.isCompletedAbnormally()); |
496 |
> |
assertTrue(f.getException() instanceof CancellationException); |
497 |
> |
} |
498 |
|
}}; |
499 |
|
testInvokeOnPool(mainPool(), a); |
500 |
|
} |
511 |
|
try { |
512 |
|
f.join(); |
513 |
|
shouldThrow(); |
514 |
< |
} catch (CancellationException success) {} |
514 |
> |
} catch (CancellationException success) { |
515 |
> |
assertTrue(f.isDone()); |
516 |
> |
assertTrue(f.isCancelled()); |
517 |
> |
assertTrue(f.isCompletedAbnormally()); |
518 |
> |
assertTrue(f.getException() instanceof CancellationException); |
519 |
> |
} |
520 |
|
}}; |
521 |
|
testInvokeOnPool(mainPool(), a); |
522 |
|
} |
533 |
|
try { |
534 |
|
f.get(); |
535 |
|
shouldThrow(); |
536 |
< |
} catch (CancellationException success) {} |
536 |
> |
} catch (CancellationException success) { |
537 |
> |
assertTrue(f.isDone()); |
538 |
> |
assertTrue(f.isCancelled()); |
539 |
> |
assertTrue(f.isCompletedAbnormally()); |
540 |
> |
assertTrue(f.getException() instanceof CancellationException); |
541 |
> |
} |
542 |
|
}}; |
543 |
|
testInvokeOnPool(mainPool(), a); |
544 |
|
} |
553 |
|
assertTrue(f.cancel(true)); |
554 |
|
assertSame(f, f.fork()); |
555 |
|
try { |
556 |
< |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
556 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
557 |
|
shouldThrow(); |
558 |
< |
} catch (CancellationException success) {} |
558 |
> |
} catch (CancellationException success) { |
559 |
> |
assertTrue(f.isDone()); |
560 |
> |
assertTrue(f.isCancelled()); |
561 |
> |
assertTrue(f.isCompletedAbnormally()); |
562 |
> |
assertTrue(f.getException() instanceof CancellationException); |
563 |
> |
} |
564 |
|
}}; |
565 |
|
testInvokeOnPool(mainPool(), a); |
566 |
|
} |