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, |
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); |