93 |
|
* Returns the "raw" internal exceptional completion of f, |
94 |
|
* without any additional wrapping with CompletionException. |
95 |
|
*/ |
96 |
< |
<U> Throwable exceptionalCompletion(CompletableFuture<U> f) { |
97 |
< |
// handle (and whenComplete) can distinguish between "direct" |
98 |
< |
// and "wrapped" exceptional completion |
99 |
< |
return f.handle((U u, Throwable t) -> t).join(); |
96 |
> |
Throwable exceptionalCompletion(CompletableFuture<?> f) { |
97 |
> |
// handle (and whenComplete and exceptionally) can distinguish |
98 |
> |
// between "direct" and "wrapped" exceptional completion |
99 |
> |
return f.handle((u, t) -> t).join(); |
100 |
|
} |
101 |
|
|
102 |
|
void checkCompletedExceptionally(CompletableFuture<?> f, |
2562 |
|
|
2563 |
|
// unspecified behavior - both source completions available |
2564 |
|
try { |
2565 |
< |
assertEquals(null, h0.join()); |
2565 |
> |
assertNull(h0.join()); |
2566 |
|
rs[0].assertValue(v1); |
2567 |
|
} catch (CompletionException ok) { |
2568 |
|
checkCompletedWithWrappedException(h0, ex); |
2569 |
|
rs[0].assertNotInvoked(); |
2570 |
|
} |
2571 |
|
try { |
2572 |
< |
assertEquals(null, h1.join()); |
2572 |
> |
assertNull(h1.join()); |
2573 |
|
rs[1].assertValue(v1); |
2574 |
|
} catch (CompletionException ok) { |
2575 |
|
checkCompletedWithWrappedException(h1, ex); |
2576 |
|
rs[1].assertNotInvoked(); |
2577 |
|
} |
2578 |
|
try { |
2579 |
< |
assertEquals(null, h2.join()); |
2579 |
> |
assertNull(h2.join()); |
2580 |
|
rs[2].assertValue(v1); |
2581 |
|
} catch (CompletionException ok) { |
2582 |
|
checkCompletedWithWrappedException(h2, ex); |
2583 |
|
rs[2].assertNotInvoked(); |
2584 |
|
} |
2585 |
|
try { |
2586 |
< |
assertEquals(null, h3.join()); |
2586 |
> |
assertNull(h3.join()); |
2587 |
|
rs[3].assertValue(v1); |
2588 |
|
} catch (CompletionException ok) { |
2589 |
|
checkCompletedWithWrappedException(h3, ex); |
2822 |
|
|
2823 |
|
// unspecified behavior - both source completions available |
2824 |
|
try { |
2825 |
< |
assertEquals(null, h0.join()); |
2825 |
> |
assertNull(h0.join()); |
2826 |
|
rs[0].assertInvoked(); |
2827 |
|
} catch (CompletionException ok) { |
2828 |
|
checkCompletedWithWrappedException(h0, ex); |
2829 |
|
rs[0].assertNotInvoked(); |
2830 |
|
} |
2831 |
|
try { |
2832 |
< |
assertEquals(null, h1.join()); |
2832 |
> |
assertNull(h1.join()); |
2833 |
|
rs[1].assertInvoked(); |
2834 |
|
} catch (CompletionException ok) { |
2835 |
|
checkCompletedWithWrappedException(h1, ex); |
2836 |
|
rs[1].assertNotInvoked(); |
2837 |
|
} |
2838 |
|
try { |
2839 |
< |
assertEquals(null, h2.join()); |
2839 |
> |
assertNull(h2.join()); |
2840 |
|
rs[2].assertInvoked(); |
2841 |
|
} catch (CompletionException ok) { |
2842 |
|
checkCompletedWithWrappedException(h2, ex); |
2843 |
|
rs[2].assertNotInvoked(); |
2844 |
|
} |
2845 |
|
try { |
2846 |
< |
assertEquals(null, h3.join()); |
2846 |
> |
assertNull(h3.join()); |
2847 |
|
rs[3].assertInvoked(); |
2848 |
|
} catch (CompletionException ok) { |
2849 |
|
checkCompletedWithWrappedException(h3, ex); |
3532 |
|
*/ |
3533 |
|
public void testCompletedStage() { |
3534 |
|
AtomicInteger x = new AtomicInteger(0); |
3535 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3535 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3536 |
|
CompletionStage<Integer> f = CompletableFuture.completedStage(1); |
3537 |
|
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3538 |
|
assertEquals(x.get(), 1); |
3634 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3635 |
|
CompletionStage<Integer> g = f.minimalCompletionStage(); |
3636 |
|
AtomicInteger x = new AtomicInteger(0); |
3637 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3637 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3638 |
|
checkIncomplete(f); |
3639 |
|
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3640 |
|
f.complete(1); |
3651 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3652 |
|
CompletionStage<Integer> g = f.minimalCompletionStage(); |
3653 |
|
AtomicInteger x = new AtomicInteger(0); |
3654 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3654 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3655 |
|
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3656 |
|
checkIncomplete(f); |
3657 |
|
CFException ex = new CFException(); |
3669 |
|
CFException ex = new CFException(); |
3670 |
|
CompletionStage<Integer> f = CompletableFuture.failedStage(ex); |
3671 |
|
AtomicInteger x = new AtomicInteger(0); |
3672 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3672 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3673 |
|
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3674 |
|
assertEquals(x.get(), 0); |
3675 |
|
assertEquals(r.get(), ex); |