41 |
|
import java.util.function.Predicate; |
42 |
|
import java.util.function.Supplier; |
43 |
|
|
44 |
– |
import junit.framework.AssertionFailedError; |
44 |
|
import junit.framework.Test; |
45 |
|
import junit.framework.TestSuite; |
46 |
|
|
58 |
|
void checkIncomplete(CompletableFuture<?> f) { |
59 |
|
assertFalse(f.isDone()); |
60 |
|
assertFalse(f.isCancelled()); |
61 |
< |
assertTrue(f.toString().contains("Not completed")); |
61 |
> |
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); |
62 |
> |
|
63 |
> |
Object result = null; |
64 |
|
try { |
65 |
< |
assertNull(f.getNow(null)); |
65 |
> |
result = f.getNow(null); |
66 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
67 |
+ |
assertNull(result); |
68 |
+ |
|
69 |
|
try { |
70 |
< |
f.get(0L, SECONDS); |
70 |
> |
f.get(randomExpiredTimeout(), randomTimeUnit()); |
71 |
|
shouldThrow(); |
72 |
|
} |
73 |
|
catch (TimeoutException success) {} |
74 |
|
catch (Throwable fail) { threadUnexpectedException(fail); } |
75 |
|
} |
76 |
|
|
77 |
< |
<T> void checkCompletedNormally(CompletableFuture<T> f, T value) { |
78 |
< |
checkTimedGet(f, value); |
77 |
> |
<T> void checkCompletedNormally(CompletableFuture<T> f, T expectedValue) { |
78 |
> |
checkTimedGet(f, expectedValue); |
79 |
|
|
80 |
+ |
assertEquals(expectedValue, f.join()); |
81 |
+ |
assertEquals(expectedValue, f.getNow(null)); |
82 |
+ |
|
83 |
+ |
T result = null; |
84 |
|
try { |
85 |
< |
assertEquals(value, f.join()); |
79 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
80 |
< |
try { |
81 |
< |
assertEquals(value, f.getNow(null)); |
82 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
83 |
< |
try { |
84 |
< |
assertEquals(value, f.get()); |
85 |
> |
result = f.get(); |
86 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
87 |
+ |
assertEquals(expectedValue, result); |
88 |
+ |
|
89 |
|
assertTrue(f.isDone()); |
90 |
|
assertFalse(f.isCancelled()); |
91 |
|
assertFalse(f.isCompletedExceptionally()); |
92 |
< |
assertTrue(f.toString().contains("[Completed normally]")); |
92 |
> |
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); |
93 |
|
} |
94 |
|
|
95 |
|
/** |
96 |
|
* Returns the "raw" internal exceptional completion of f, |
97 |
|
* without any additional wrapping with CompletionException. |
98 |
|
*/ |
99 |
< |
<U> Throwable exceptionalCompletion(CompletableFuture<U> f) { |
100 |
< |
// handle (and whenComplete) can distinguish between "direct" |
101 |
< |
// and "wrapped" exceptional completion |
102 |
< |
return f.handle((U u, Throwable t) -> t).join(); |
99 |
> |
Throwable exceptionalCompletion(CompletableFuture<?> f) { |
100 |
> |
// handle (and whenComplete and exceptionally) can distinguish |
101 |
> |
// between "direct" and "wrapped" exceptional completion |
102 |
> |
return f.handle((u, t) -> t).join(); |
103 |
|
} |
104 |
|
|
105 |
|
void checkCompletedExceptionally(CompletableFuture<?> f, |
145 |
|
assertFalse(f.isCancelled()); |
146 |
|
assertTrue(f.isDone()); |
147 |
|
assertTrue(f.isCompletedExceptionally()); |
148 |
< |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
148 |
> |
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
149 |
|
} |
150 |
|
|
151 |
|
void checkCompletedWithWrappedCFException(CompletableFuture<?> f) { |
152 |
|
checkCompletedExceptionally(f, true, |
153 |
< |
(t) -> assertTrue(t instanceof CFException)); |
153 |
> |
t -> assertTrue(t instanceof CFException)); |
154 |
|
} |
155 |
|
|
156 |
|
void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) { |
157 |
|
checkCompletedExceptionally(f, true, |
158 |
< |
(t) -> assertTrue(t instanceof CancellationException)); |
158 |
> |
t -> assertTrue(t instanceof CancellationException)); |
159 |
|
} |
160 |
|
|
161 |
|
void checkCompletedWithTimeoutException(CompletableFuture<?> f) { |
162 |
|
checkCompletedExceptionally(f, false, |
163 |
< |
(t) -> assertTrue(t instanceof TimeoutException)); |
163 |
> |
t -> assertTrue(t instanceof TimeoutException)); |
164 |
|
} |
165 |
|
|
166 |
|
void checkCompletedWithWrappedException(CompletableFuture<?> f, |
167 |
|
Throwable ex) { |
168 |
< |
checkCompletedExceptionally(f, true, (t) -> assertSame(t, ex)); |
168 |
> |
checkCompletedExceptionally(f, true, t -> assertSame(t, ex)); |
169 |
|
} |
170 |
|
|
171 |
|
void checkCompletedExceptionally(CompletableFuture<?> f, Throwable ex) { |
172 |
< |
checkCompletedExceptionally(f, false, (t) -> assertSame(t, ex)); |
172 |
> |
checkCompletedExceptionally(f, false, t -> assertSame(t, ex)); |
173 |
|
} |
174 |
|
|
175 |
|
void checkCancelled(CompletableFuture<?> f) { |
200 |
|
assertTrue(f.isDone()); |
201 |
|
assertTrue(f.isCompletedExceptionally()); |
202 |
|
assertTrue(f.isCancelled()); |
203 |
< |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
203 |
> |
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
204 |
|
} |
205 |
|
|
206 |
|
/** |
299 |
|
} |
300 |
|
|
301 |
|
f = new CompletableFuture<>(); |
302 |
< |
f.completeExceptionally(ex = new CFException()); |
302 |
> |
f.completeExceptionally(new CFException()); |
303 |
|
f.obtrudeValue(v1); |
304 |
|
checkCompletedNormally(f, v1); |
305 |
|
f.obtrudeException(ex = new CFException()); |
336 |
|
/** |
337 |
|
* toString indicates current completion state |
338 |
|
*/ |
339 |
< |
public void testToString() { |
340 |
< |
CompletableFuture<String> f; |
341 |
< |
|
342 |
< |
f = new CompletableFuture<String>(); |
343 |
< |
assertTrue(f.toString().contains("[Not completed]")); |
339 |
> |
public void testToString_incomplete() { |
340 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
341 |
> |
assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); |
342 |
> |
if (testImplementationDetails) |
343 |
> |
assertEquals(identityString(f) + "[Not completed]", |
344 |
> |
f.toString()); |
345 |
> |
} |
346 |
|
|
347 |
+ |
public void testToString_normal() { |
348 |
+ |
CompletableFuture<String> f = new CompletableFuture<>(); |
349 |
|
assertTrue(f.complete("foo")); |
350 |
< |
assertTrue(f.toString().contains("[Completed normally]")); |
350 |
> |
assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); |
351 |
> |
if (testImplementationDetails) |
352 |
> |
assertEquals(identityString(f) + "[Completed normally]", |
353 |
> |
f.toString()); |
354 |
> |
} |
355 |
|
|
356 |
< |
f = new CompletableFuture<String>(); |
356 |
> |
public void testToString_exception() { |
357 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
358 |
|
assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); |
359 |
< |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
359 |
> |
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
360 |
> |
if (testImplementationDetails) |
361 |
> |
assertTrue(f.toString().startsWith( |
362 |
> |
identityString(f) + "[Completed exceptionally: ")); |
363 |
> |
} |
364 |
|
|
365 |
+ |
public void testToString_cancelled() { |
366 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
367 |
< |
f = new CompletableFuture<String>(); |
367 |
> |
CompletableFuture<String> f = new CompletableFuture<>(); |
368 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
369 |
< |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
369 |
> |
assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); |
370 |
> |
if (testImplementationDetails) |
371 |
> |
assertTrue(f.toString().startsWith( |
372 |
> |
identityString(f) + "[Completed exceptionally: ")); |
373 |
|
} |
374 |
|
} |
375 |
|
|
1262 |
|
r.assertInvoked(); |
1263 |
|
}} |
1264 |
|
|
1265 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
1266 |
|
public void testRunAsync_rejectingExecutor() { |
1267 |
|
CountingRejectingExecutor e = new CountingRejectingExecutor(); |
1268 |
|
try { |
1309 |
|
r.assertInvoked(); |
1310 |
|
}} |
1311 |
|
|
1312 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
1313 |
|
public void testSupplyAsync_rejectingExecutor() { |
1314 |
|
CountingRejectingExecutor e = new CountingRejectingExecutor(); |
1315 |
|
try { |
2584 |
|
|
2585 |
|
// unspecified behavior - both source completions available |
2586 |
|
try { |
2587 |
< |
assertEquals(null, h0.join()); |
2587 |
> |
assertNull(h0.join()); |
2588 |
|
rs[0].assertValue(v1); |
2589 |
|
} catch (CompletionException ok) { |
2590 |
|
checkCompletedWithWrappedException(h0, ex); |
2591 |
|
rs[0].assertNotInvoked(); |
2592 |
|
} |
2593 |
|
try { |
2594 |
< |
assertEquals(null, h1.join()); |
2594 |
> |
assertNull(h1.join()); |
2595 |
|
rs[1].assertValue(v1); |
2596 |
|
} catch (CompletionException ok) { |
2597 |
|
checkCompletedWithWrappedException(h1, ex); |
2598 |
|
rs[1].assertNotInvoked(); |
2599 |
|
} |
2600 |
|
try { |
2601 |
< |
assertEquals(null, h2.join()); |
2601 |
> |
assertNull(h2.join()); |
2602 |
|
rs[2].assertValue(v1); |
2603 |
|
} catch (CompletionException ok) { |
2604 |
|
checkCompletedWithWrappedException(h2, ex); |
2605 |
|
rs[2].assertNotInvoked(); |
2606 |
|
} |
2607 |
|
try { |
2608 |
< |
assertEquals(null, h3.join()); |
2608 |
> |
assertNull(h3.join()); |
2609 |
|
rs[3].assertValue(v1); |
2610 |
|
} catch (CompletionException ok) { |
2611 |
|
checkCompletedWithWrappedException(h3, ex); |
2844 |
|
|
2845 |
|
// unspecified behavior - both source completions available |
2846 |
|
try { |
2847 |
< |
assertEquals(null, h0.join()); |
2847 |
> |
assertNull(h0.join()); |
2848 |
|
rs[0].assertInvoked(); |
2849 |
|
} catch (CompletionException ok) { |
2850 |
|
checkCompletedWithWrappedException(h0, ex); |
2851 |
|
rs[0].assertNotInvoked(); |
2852 |
|
} |
2853 |
|
try { |
2854 |
< |
assertEquals(null, h1.join()); |
2854 |
> |
assertNull(h1.join()); |
2855 |
|
rs[1].assertInvoked(); |
2856 |
|
} catch (CompletionException ok) { |
2857 |
|
checkCompletedWithWrappedException(h1, ex); |
2858 |
|
rs[1].assertNotInvoked(); |
2859 |
|
} |
2860 |
|
try { |
2861 |
< |
assertEquals(null, h2.join()); |
2861 |
> |
assertNull(h2.join()); |
2862 |
|
rs[2].assertInvoked(); |
2863 |
|
} catch (CompletionException ok) { |
2864 |
|
checkCompletedWithWrappedException(h2, ex); |
2865 |
|
rs[2].assertNotInvoked(); |
2866 |
|
} |
2867 |
|
try { |
2868 |
< |
assertEquals(null, h3.join()); |
2868 |
> |
assertNull(h3.join()); |
2869 |
|
rs[3].assertInvoked(); |
2870 |
|
} catch (CompletionException ok) { |
2871 |
|
checkCompletedWithWrappedException(h3, ex); |
3260 |
|
/** |
3261 |
|
* Completion methods throw NullPointerException with null arguments |
3262 |
|
*/ |
3263 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
3264 |
|
public void testNPE() { |
3265 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3266 |
|
CompletableFuture<Integer> g = new CompletableFuture<>(); |
3280 |
|
|
3281 |
|
() -> f.thenApply(null), |
3282 |
|
() -> f.thenApplyAsync(null), |
3283 |
< |
() -> f.thenApplyAsync((x) -> x, null), |
3283 |
> |
() -> f.thenApplyAsync(x -> x, null), |
3284 |
|
() -> f.thenApplyAsync(null, exec), |
3285 |
|
|
3286 |
|
() -> f.thenAccept(null), |
3287 |
|
() -> f.thenAcceptAsync(null), |
3288 |
< |
() -> f.thenAcceptAsync((x) -> {} , null), |
3288 |
> |
() -> f.thenAcceptAsync(x -> {} , null), |
3289 |
|
() -> f.thenAcceptAsync(null, exec), |
3290 |
|
|
3291 |
|
() -> f.thenRun(null), |
3320 |
|
() -> f.applyToEither(g, null), |
3321 |
|
() -> f.applyToEitherAsync(g, null), |
3322 |
|
() -> f.applyToEitherAsync(g, null, exec), |
3323 |
< |
() -> f.applyToEither(nullFuture, (x) -> x), |
3324 |
< |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
3325 |
< |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
3326 |
< |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
3323 |
> |
() -> f.applyToEither(nullFuture, x -> x), |
3324 |
> |
() -> f.applyToEitherAsync(nullFuture, x -> x), |
3325 |
> |
() -> f.applyToEitherAsync(nullFuture, x -> x, exec), |
3326 |
> |
() -> f.applyToEitherAsync(g, x -> x, null), |
3327 |
|
|
3328 |
|
() -> f.acceptEither(g, null), |
3329 |
|
() -> f.acceptEitherAsync(g, null), |
3330 |
|
() -> f.acceptEitherAsync(g, null, exec), |
3331 |
< |
() -> f.acceptEither(nullFuture, (x) -> {}), |
3332 |
< |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
3333 |
< |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
3334 |
< |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
3331 |
> |
() -> f.acceptEither(nullFuture, x -> {}), |
3332 |
> |
() -> f.acceptEitherAsync(nullFuture, x -> {}), |
3333 |
> |
() -> f.acceptEitherAsync(nullFuture, x -> {}, exec), |
3334 |
> |
() -> f.acceptEitherAsync(g, x -> {}, null), |
3335 |
|
|
3336 |
|
() -> f.runAfterEither(g, null), |
3337 |
|
() -> f.runAfterEitherAsync(g, null), |
3397 |
|
for (CompletableFuture<Integer> src : srcs) { |
3398 |
|
List<CompletableFuture<?>> fs = new ArrayList<>(); |
3399 |
|
fs.add(src.thenRunAsync(() -> {}, e)); |
3400 |
< |
fs.add(src.thenAcceptAsync((z) -> {}, e)); |
3401 |
< |
fs.add(src.thenApplyAsync((z) -> z, e)); |
3400 |
> |
fs.add(src.thenAcceptAsync(z -> {}, e)); |
3401 |
> |
fs.add(src.thenApplyAsync(z -> z, e)); |
3402 |
|
|
3403 |
|
fs.add(src.thenCombineAsync(src, (x, y) -> x, e)); |
3404 |
|
fs.add(src.thenAcceptBothAsync(src, (x, y) -> {}, e)); |
3405 |
|
fs.add(src.runAfterBothAsync(src, () -> {}, e)); |
3406 |
|
|
3407 |
< |
fs.add(src.applyToEitherAsync(src, (z) -> z, e)); |
3408 |
< |
fs.add(src.acceptEitherAsync(src, (z) -> {}, e)); |
3407 |
> |
fs.add(src.applyToEitherAsync(src, z -> z, e)); |
3408 |
> |
fs.add(src.acceptEitherAsync(src, z -> {}, e)); |
3409 |
|
fs.add(src.runAfterEitherAsync(src, () -> {}, e)); |
3410 |
|
|
3411 |
< |
fs.add(src.thenComposeAsync((z) -> null, e)); |
3411 |
> |
fs.add(src.thenComposeAsync(z -> null, e)); |
3412 |
|
fs.add(src.whenCompleteAsync((z, t) -> {}, e)); |
3413 |
|
fs.add(src.handleAsync((z, t) -> null, e)); |
3414 |
|
|
3441 |
|
{ |
3442 |
|
List<CompletableFuture<?>> fs = new ArrayList<>(); |
3443 |
|
|
3444 |
< |
fs.add(complete.applyToEitherAsync(incomplete, (z) -> z, e)); |
3445 |
< |
fs.add(incomplete.applyToEitherAsync(complete, (z) -> z, e)); |
3444 |
> |
fs.add(complete.applyToEitherAsync(incomplete, z -> z, e)); |
3445 |
> |
fs.add(incomplete.applyToEitherAsync(complete, z -> z, e)); |
3446 |
|
|
3447 |
< |
fs.add(complete.acceptEitherAsync(incomplete, (z) -> {}, e)); |
3448 |
< |
fs.add(incomplete.acceptEitherAsync(complete, (z) -> {}, e)); |
3447 |
> |
fs.add(complete.acceptEitherAsync(incomplete, z -> {}, e)); |
3448 |
> |
fs.add(incomplete.acceptEitherAsync(complete, z -> {}, e)); |
3449 |
|
|
3450 |
|
fs.add(complete.runAfterEitherAsync(incomplete, () -> {}, e)); |
3451 |
|
fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e)); |
3484 |
|
|
3485 |
|
List<CompletableFuture<?>> fs = new ArrayList<>(); |
3486 |
|
fs.add(incomplete.thenRunAsync(() -> {}, e)); |
3487 |
< |
fs.add(incomplete.thenAcceptAsync((z) -> {}, e)); |
3488 |
< |
fs.add(incomplete.thenApplyAsync((z) -> z, e)); |
3487 |
> |
fs.add(incomplete.thenAcceptAsync(z -> {}, e)); |
3488 |
> |
fs.add(incomplete.thenApplyAsync(z -> z, e)); |
3489 |
|
|
3490 |
|
fs.add(incomplete.thenCombineAsync(incomplete, (x, y) -> x, e)); |
3491 |
|
fs.add(incomplete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e)); |
3492 |
|
fs.add(incomplete.runAfterBothAsync(incomplete, () -> {}, e)); |
3493 |
|
|
3494 |
< |
fs.add(incomplete.applyToEitherAsync(incomplete, (z) -> z, e)); |
3495 |
< |
fs.add(incomplete.acceptEitherAsync(incomplete, (z) -> {}, e)); |
3494 |
> |
fs.add(incomplete.applyToEitherAsync(incomplete, z -> z, e)); |
3495 |
> |
fs.add(incomplete.acceptEitherAsync(incomplete, z -> {}, e)); |
3496 |
|
fs.add(incomplete.runAfterEitherAsync(incomplete, () -> {}, e)); |
3497 |
|
|
3498 |
< |
fs.add(incomplete.thenComposeAsync((z) -> null, e)); |
3498 |
> |
fs.add(incomplete.thenComposeAsync(z -> null, e)); |
3499 |
|
fs.add(incomplete.whenCompleteAsync((z, t) -> {}, e)); |
3500 |
|
fs.add(incomplete.handleAsync((z, t) -> null, e)); |
3501 |
|
|
3555 |
|
*/ |
3556 |
|
public void testCompletedStage() { |
3557 |
|
AtomicInteger x = new AtomicInteger(0); |
3558 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3558 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3559 |
|
CompletionStage<Integer> f = CompletableFuture.completedStage(1); |
3560 |
|
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3561 |
|
assertEquals(x.get(), 1); |
3600 |
|
* copy returns a CompletableFuture that is completed normally, |
3601 |
|
* with the same value, when source is. |
3602 |
|
*/ |
3603 |
< |
public void testCopy() { |
3603 |
> |
public void testCopy_normalCompletion() { |
3604 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
3605 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
3606 |
> |
{ |
3607 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3608 |
+ |
if (!createIncomplete) assertTrue(f.complete(v1)); |
3609 |
|
CompletableFuture<Integer> g = f.copy(); |
3610 |
< |
checkIncomplete(f); |
3611 |
< |
checkIncomplete(g); |
3612 |
< |
f.complete(1); |
3613 |
< |
checkCompletedNormally(f, 1); |
3614 |
< |
checkCompletedNormally(g, 1); |
3615 |
< |
} |
3610 |
> |
if (createIncomplete) { |
3611 |
> |
checkIncomplete(f); |
3612 |
> |
checkIncomplete(g); |
3613 |
> |
assertTrue(f.complete(v1)); |
3614 |
> |
} |
3615 |
> |
checkCompletedNormally(f, v1); |
3616 |
> |
checkCompletedNormally(g, v1); |
3617 |
> |
}} |
3618 |
|
|
3619 |
|
/** |
3620 |
|
* copy returns a CompletableFuture that is completed exceptionally |
3621 |
|
* when source is. |
3622 |
|
*/ |
3623 |
< |
public void testCopy2() { |
3623 |
> |
public void testCopy_exceptionalCompletion() { |
3624 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
3625 |
> |
{ |
3626 |
> |
CFException ex = new CFException(); |
3627 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3628 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
3629 |
|
CompletableFuture<Integer> g = f.copy(); |
3630 |
< |
checkIncomplete(f); |
3631 |
< |
checkIncomplete(g); |
3632 |
< |
CFException ex = new CFException(); |
3633 |
< |
f.completeExceptionally(ex); |
3630 |
> |
if (createIncomplete) { |
3631 |
> |
checkIncomplete(f); |
3632 |
> |
checkIncomplete(g); |
3633 |
> |
f.completeExceptionally(ex); |
3634 |
> |
} |
3635 |
|
checkCompletedExceptionally(f, ex); |
3636 |
|
checkCompletedWithWrappedException(g, ex); |
3637 |
+ |
}} |
3638 |
+ |
|
3639 |
+ |
/** |
3640 |
+ |
* Completion of a copy does not complete its source. |
3641 |
+ |
*/ |
3642 |
+ |
public void testCopy_oneWayPropagation() { |
3643 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3644 |
+ |
assertTrue(f.copy().complete(1)); |
3645 |
+ |
assertTrue(f.copy().complete(null)); |
3646 |
+ |
assertTrue(f.copy().cancel(true)); |
3647 |
+ |
assertTrue(f.copy().cancel(false)); |
3648 |
+ |
assertTrue(f.copy().completeExceptionally(new CFException())); |
3649 |
+ |
checkIncomplete(f); |
3650 |
|
} |
3651 |
|
|
3652 |
|
/** |
3657 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3658 |
|
CompletionStage<Integer> g = f.minimalCompletionStage(); |
3659 |
|
AtomicInteger x = new AtomicInteger(0); |
3660 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3660 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3661 |
|
checkIncomplete(f); |
3662 |
|
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3663 |
|
f.complete(1); |
3674 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3675 |
|
CompletionStage<Integer> g = f.minimalCompletionStage(); |
3676 |
|
AtomicInteger x = new AtomicInteger(0); |
3677 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3677 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3678 |
|
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3679 |
|
checkIncomplete(f); |
3680 |
|
CFException ex = new CFException(); |
3692 |
|
CFException ex = new CFException(); |
3693 |
|
CompletionStage<Integer> f = CompletableFuture.failedStage(ex); |
3694 |
|
AtomicInteger x = new AtomicInteger(0); |
3695 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3695 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3696 |
|
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3697 |
|
assertEquals(x.get(), 0); |
3698 |
|
assertEquals(r.get(), ex); |
3716 |
|
public void testCompleteAsync2() { |
3717 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3718 |
|
CFException ex = new CFException(); |
3719 |
< |
f.completeAsync(() -> {if (true) throw ex; return 1;}); |
3719 |
> |
f.completeAsync(() -> { throw ex; }); |
3720 |
|
try { |
3721 |
|
f.join(); |
3722 |
|
shouldThrow(); |
3746 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3747 |
|
CFException ex = new CFException(); |
3748 |
|
ThreadExecutor executor = new ThreadExecutor(); |
3749 |
< |
f.completeAsync(() -> {if (true) throw ex; return 1;}, executor); |
3749 |
> |
f.completeAsync(() -> { throw ex; }, executor); |
3750 |
|
try { |
3751 |
|
f.join(); |
3752 |
|
shouldThrow(); |
3905 |
|
List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> funs |
3906 |
|
= new ArrayList<>(); |
3907 |
|
|
3908 |
< |
funs.add((y) -> m.thenRun(y, noopRunnable)); |
3909 |
< |
funs.add((y) -> m.thenAccept(y, noopConsumer)); |
3910 |
< |
funs.add((y) -> m.thenApply(y, incFunction)); |
3911 |
< |
|
3912 |
< |
funs.add((y) -> m.runAfterEither(y, incomplete, noopRunnable)); |
3913 |
< |
funs.add((y) -> m.acceptEither(y, incomplete, noopConsumer)); |
3914 |
< |
funs.add((y) -> m.applyToEither(y, incomplete, incFunction)); |
3915 |
< |
|
3916 |
< |
funs.add((y) -> m.runAfterBoth(y, v42, noopRunnable)); |
3917 |
< |
funs.add((y) -> m.runAfterBoth(v42, y, noopRunnable)); |
3918 |
< |
funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m))); |
3919 |
< |
funs.add((y) -> m.thenAcceptBoth(v42, y, new SubtractAction(m))); |
3920 |
< |
funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m))); |
3921 |
< |
funs.add((y) -> m.thenCombine(v42, y, new SubtractFunction(m))); |
3922 |
< |
|
3923 |
< |
funs.add((y) -> m.whenComplete(y, (Integer r, Throwable t) -> {})); |
3924 |
< |
|
3925 |
< |
funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m))); |
3926 |
< |
|
3927 |
< |
funs.add((y) -> CompletableFuture.allOf(y)); |
3928 |
< |
funs.add((y) -> CompletableFuture.allOf(y, v42)); |
3929 |
< |
funs.add((y) -> CompletableFuture.allOf(v42, y)); |
3930 |
< |
funs.add((y) -> CompletableFuture.anyOf(y)); |
3931 |
< |
funs.add((y) -> CompletableFuture.anyOf(y, incomplete)); |
3932 |
< |
funs.add((y) -> CompletableFuture.anyOf(incomplete, y)); |
3908 |
> |
funs.add(y -> m.thenRun(y, noopRunnable)); |
3909 |
> |
funs.add(y -> m.thenAccept(y, noopConsumer)); |
3910 |
> |
funs.add(y -> m.thenApply(y, incFunction)); |
3911 |
> |
|
3912 |
> |
funs.add(y -> m.runAfterEither(y, incomplete, noopRunnable)); |
3913 |
> |
funs.add(y -> m.acceptEither(y, incomplete, noopConsumer)); |
3914 |
> |
funs.add(y -> m.applyToEither(y, incomplete, incFunction)); |
3915 |
> |
|
3916 |
> |
funs.add(y -> m.runAfterBoth(y, v42, noopRunnable)); |
3917 |
> |
funs.add(y -> m.runAfterBoth(v42, y, noopRunnable)); |
3918 |
> |
funs.add(y -> m.thenAcceptBoth(y, v42, new SubtractAction(m))); |
3919 |
> |
funs.add(y -> m.thenAcceptBoth(v42, y, new SubtractAction(m))); |
3920 |
> |
funs.add(y -> m.thenCombine(y, v42, new SubtractFunction(m))); |
3921 |
> |
funs.add(y -> m.thenCombine(v42, y, new SubtractFunction(m))); |
3922 |
> |
|
3923 |
> |
funs.add(y -> m.whenComplete(y, (Integer r, Throwable t) -> {})); |
3924 |
> |
|
3925 |
> |
funs.add(y -> m.thenCompose(y, new CompletableFutureInc(m))); |
3926 |
> |
|
3927 |
> |
funs.add(y -> CompletableFuture.allOf(y)); |
3928 |
> |
funs.add(y -> CompletableFuture.allOf(y, v42)); |
3929 |
> |
funs.add(y -> CompletableFuture.allOf(v42, y)); |
3930 |
> |
funs.add(y -> CompletableFuture.anyOf(y)); |
3931 |
> |
funs.add(y -> CompletableFuture.anyOf(y, incomplete)); |
3932 |
> |
funs.add(y -> CompletableFuture.anyOf(incomplete, y)); |
3933 |
|
|
3934 |
|
for (Function<CompletableFuture<Integer>, CompletableFuture<?>> |
3935 |
|
fun : funs) { |
3986 |
|
public void testMinimalCompletionStage_minimality() { |
3987 |
|
if (!testImplementationDetails) return; |
3988 |
|
Function<Method, String> toSignature = |
3989 |
< |
(method) -> method.getName() + Arrays.toString(method.getParameterTypes()); |
3989 |
> |
method -> method.getName() + Arrays.toString(method.getParameterTypes()); |
3990 |
|
Predicate<Method> isNotStatic = |
3991 |
< |
(method) -> (method.getModifiers() & Modifier.STATIC) == 0; |
3991 |
> |
method -> (method.getModifiers() & Modifier.STATIC) == 0; |
3992 |
|
List<Method> minimalMethods = |
3993 |
|
Stream.of(Object.class, CompletionStage.class) |
3994 |
< |
.flatMap((klazz) -> Stream.of(klazz.getMethods())) |
3994 |
> |
.flatMap(klazz -> Stream.of(klazz.getMethods())) |
3995 |
|
.filter(isNotStatic) |
3996 |
|
.collect(Collectors.toList()); |
3997 |
|
// Methods from CompletableFuture permitted NOT to throw UOE |
4007 |
|
.collect(Collectors.toSet()); |
4008 |
|
List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods()) |
4009 |
|
.filter(isNotStatic) |
4010 |
< |
.filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method))) |
4010 |
> |
.filter(method -> !permittedMethodSignatures.contains(toSignature.apply(method))) |
4011 |
|
.collect(Collectors.toList()); |
4012 |
|
|
4013 |
|
List<CompletionStage<Integer>> stages = new ArrayList<>(); |
4051 |
|
} |
4052 |
|
|
4053 |
|
/** |
4054 |
+ |
* minimalStage.toCompletableFuture() returns a CompletableFuture that |
4055 |
+ |
* is completed normally, with the same value, when source is. |
4056 |
+ |
*/ |
4057 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() { |
4058 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
4059 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
4060 |
+ |
{ |
4061 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4062 |
+ |
CompletionStage<Integer> minimal = f.minimalCompletionStage(); |
4063 |
+ |
if (!createIncomplete) assertTrue(f.complete(v1)); |
4064 |
+ |
CompletableFuture<Integer> g = minimal.toCompletableFuture(); |
4065 |
+ |
if (createIncomplete) { |
4066 |
+ |
checkIncomplete(f); |
4067 |
+ |
checkIncomplete(g); |
4068 |
+ |
assertTrue(f.complete(v1)); |
4069 |
+ |
} |
4070 |
+ |
checkCompletedNormally(f, v1); |
4071 |
+ |
checkCompletedNormally(g, v1); |
4072 |
+ |
}} |
4073 |
+ |
|
4074 |
+ |
/** |
4075 |
+ |
* minimalStage.toCompletableFuture() returns a CompletableFuture that |
4076 |
+ |
* is completed exceptionally when source is. |
4077 |
+ |
*/ |
4078 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() { |
4079 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
4080 |
+ |
{ |
4081 |
+ |
CFException ex = new CFException(); |
4082 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4083 |
+ |
CompletionStage<Integer> minimal = f.minimalCompletionStage(); |
4084 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
4085 |
+ |
CompletableFuture<Integer> g = minimal.toCompletableFuture(); |
4086 |
+ |
if (createIncomplete) { |
4087 |
+ |
checkIncomplete(f); |
4088 |
+ |
checkIncomplete(g); |
4089 |
+ |
f.completeExceptionally(ex); |
4090 |
+ |
} |
4091 |
+ |
checkCompletedExceptionally(f, ex); |
4092 |
+ |
checkCompletedWithWrappedException(g, ex); |
4093 |
+ |
}} |
4094 |
+ |
|
4095 |
+ |
/** |
4096 |
|
* minimalStage.toCompletableFuture() gives mutable CompletableFuture |
4097 |
|
*/ |
4098 |
|
public void testMinimalCompletionStage_toCompletableFuture_mutable() { |
4101 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4102 |
|
CompletionStage minimal = f.minimalCompletionStage(); |
4103 |
|
CompletableFuture<Integer> g = minimal.toCompletableFuture(); |
4104 |
< |
g.complete(v1); |
4104 |
> |
assertTrue(g.complete(v1)); |
4105 |
|
checkCompletedNormally(g, v1); |
4106 |
|
checkIncomplete(f); |
4107 |
|
checkIncomplete(minimal.toCompletableFuture()); |
4123 |
|
checkCompletedNormally(minimal.toCompletableFuture(), v1); |
4124 |
|
}} |
4125 |
|
|
4126 |
+ |
/** |
4127 |
+ |
* Completion of a toCompletableFuture copy of a minimal stage |
4128 |
+ |
* does not complete its source. |
4129 |
+ |
*/ |
4130 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() { |
4131 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4132 |
+ |
CompletionStage<Integer> g = f.minimalCompletionStage(); |
4133 |
+ |
assertTrue(g.toCompletableFuture().complete(1)); |
4134 |
+ |
assertTrue(g.toCompletableFuture().complete(null)); |
4135 |
+ |
assertTrue(g.toCompletableFuture().cancel(true)); |
4136 |
+ |
assertTrue(g.toCompletableFuture().cancel(false)); |
4137 |
+ |
assertTrue(g.toCompletableFuture().completeExceptionally(new CFException())); |
4138 |
+ |
checkIncomplete(g.toCompletableFuture()); |
4139 |
+ |
f.complete(1); |
4140 |
+ |
checkCompletedNormally(g.toCompletableFuture(), 1); |
4141 |
+ |
} |
4142 |
+ |
|
4143 |
|
/** Demo utility method for external reliable toCompletableFuture */ |
4144 |
|
static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) { |
4145 |
|
CompletableFuture<T> f = new CompletableFuture<>(); |
4167 |
|
CompletionStage<Integer> minimal = f.minimalCompletionStage(); |
4168 |
|
CompletableFuture<Integer> g = new CompletableFuture<>(); |
4169 |
|
if (!createIncomplete) assertTrue(f.complete(v1)); |
4170 |
< |
minimal.thenAccept((x) -> g.complete(x)); |
4170 |
> |
minimal.thenAccept(x -> g.complete(x)); |
4171 |
|
if (createIncomplete) assertTrue(f.complete(v1)); |
4172 |
|
g.join(); |
4173 |
|
checkCompletedNormally(g, v1); |
4191 |
|
static <T,U,V> Function<T, CompletableFuture<V>> compose |
4192 |
|
(Function<T, CompletableFuture<U>> f, |
4193 |
|
Function<U, CompletableFuture<V>> g) { |
4194 |
< |
return (x) -> f.apply(x).thenCompose(g); |
4194 |
> |
return x -> f.apply(x).thenCompose(g); |
4195 |
|
} |
4196 |
|
|
4197 |
|
static void assertZero(CompletableFuture<?> f) { |
4198 |
|
try { |
4199 |
|
f.getNow(null); |
4200 |
< |
throw new AssertionFailedError("should throw"); |
4200 |
> |
throw new AssertionError("should throw"); |
4201 |
|
} catch (CompletionException success) { |
4202 |
|
assertTrue(success.getCause() instanceof ZeroException); |
4203 |
|
} |
4271 |
|
|
4272 |
|
// Some mutually non-commutative functions |
4273 |
|
Function<Long, CompletableFuture<Long>> triple |
4274 |
< |
= (x) -> Monad.unit(3 * x); |
4274 |
> |
= x -> Monad.unit(3 * x); |
4275 |
|
Function<Long, CompletableFuture<Long>> inc |
4276 |
< |
= (x) -> Monad.unit(x + 1); |
4276 |
> |
= x -> Monad.unit(x + 1); |
4277 |
|
|
4278 |
|
// unit is a right identity: m >>= unit === m |
4279 |
|
Monad.assertFutureEquals(inc.apply(5L).thenCompose(unit), |
4285 |
|
// associativity: (m >>= f) >>= g === m >>= ( \x -> (f x >>= g) ) |
4286 |
|
Monad.assertFutureEquals( |
4287 |
|
unit.apply(5L).thenCompose(inc).thenCompose(triple), |
4288 |
< |
unit.apply(5L).thenCompose((x) -> inc.apply(x).thenCompose(triple))); |
4288 |
> |
unit.apply(5L).thenCompose(x -> inc.apply(x).thenCompose(triple))); |
4289 |
|
|
4290 |
|
// The case for CompletableFuture as an additive monad is weaker... |
4291 |
|
|
4295 |
|
// left zero: zero >>= f === zero |
4296 |
|
Monad.assertZero(zero.thenCompose(inc)); |
4297 |
|
// right zero: f >>= (\x -> zero) === zero |
4298 |
< |
Monad.assertZero(inc.apply(5L).thenCompose((x) -> zero)); |
4298 |
> |
Monad.assertZero(inc.apply(5L).thenCompose(x -> zero)); |
4299 |
|
|
4300 |
|
// f plus zero === f |
4301 |
|
Monad.assertFutureEquals(Monad.unit(5L), |
4322 |
|
} |
4323 |
|
|
4324 |
|
/** Test long recursive chains of CompletableFutures with cascading completions */ |
4325 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
4326 |
|
public void testRecursiveChains() throws Throwable { |
4327 |
|
for (ExecutionMode m : ExecutionMode.values()) |
4328 |
|
for (boolean addDeadEnds : new boolean[] { true, false }) |
4347 |
|
* A single CompletableFuture with many dependents. |
4348 |
|
* A demo of scalability - runtime is O(n). |
4349 |
|
*/ |
4350 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
4351 |
|
public void testManyDependents() throws Throwable { |
4352 |
|
final int n = expensiveTests ? 1_000_000 : 10; |
4353 |
|
final CompletableFuture<Void> head = new CompletableFuture<>(); |
4355 |
|
final AtomicInteger count = new AtomicInteger(0); |
4356 |
|
for (int i = 0; i < n; i++) { |
4357 |
|
head.thenRun(() -> count.getAndIncrement()); |
4358 |
< |
head.thenAccept((x) -> count.getAndIncrement()); |
4359 |
< |
head.thenApply((x) -> count.getAndIncrement()); |
4358 |
> |
head.thenAccept(x -> count.getAndIncrement()); |
4359 |
> |
head.thenApply(x -> count.getAndIncrement()); |
4360 |
|
|
4361 |
|
head.runAfterBoth(complete, () -> count.getAndIncrement()); |
4362 |
|
head.thenAcceptBoth(complete, (x, y) -> count.getAndIncrement()); |
4366 |
|
complete.thenCombine(head, (x, y) -> count.getAndIncrement()); |
4367 |
|
|
4368 |
|
head.runAfterEither(new CompletableFuture<Void>(), () -> count.getAndIncrement()); |
4369 |
< |
head.acceptEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement()); |
4370 |
< |
head.applyToEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement()); |
4369 |
> |
head.acceptEither(new CompletableFuture<Void>(), x -> count.getAndIncrement()); |
4370 |
> |
head.applyToEither(new CompletableFuture<Void>(), x -> count.getAndIncrement()); |
4371 |
|
new CompletableFuture<Void>().runAfterEither(head, () -> count.getAndIncrement()); |
4372 |
< |
new CompletableFuture<Void>().acceptEither(head, (x) -> count.getAndIncrement()); |
4373 |
< |
new CompletableFuture<Void>().applyToEither(head, (x) -> count.getAndIncrement()); |
4372 |
> |
new CompletableFuture<Void>().acceptEither(head, x -> count.getAndIncrement()); |
4373 |
> |
new CompletableFuture<Void>().applyToEither(head, x -> count.getAndIncrement()); |
4374 |
|
} |
4375 |
|
head.complete(null); |
4376 |
|
assertEquals(5 * 3 * n, count.get()); |
4377 |
|
} |
4378 |
|
|
4379 |
|
/** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */ |
4380 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
4381 |
|
public void testCoCompletionGarbageRetention() throws Throwable { |
4382 |
|
final int n = expensiveTests ? 1_000_000 : 10; |
4383 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
4388 |
|
f.complete(null); |
4389 |
|
|
4390 |
|
f = new CompletableFuture<>(); |
4391 |
< |
f.acceptEither(incomplete, (x) -> {}); |
4391 |
> |
f.acceptEither(incomplete, x -> {}); |
4392 |
|
f.complete(null); |
4393 |
|
|
4394 |
|
f = new CompletableFuture<>(); |
4395 |
< |
f.applyToEither(incomplete, (x) -> x); |
4395 |
> |
f.applyToEither(incomplete, x -> x); |
4396 |
|
f.complete(null); |
4397 |
|
|
4398 |
|
f = new CompletableFuture<>(); |
4399 |
< |
CompletableFuture.anyOf(new CompletableFuture<?>[] { f, incomplete }); |
4399 |
> |
CompletableFuture.anyOf(f, incomplete); |
4400 |
|
f.complete(null); |
4401 |
|
} |
4402 |
|
|
4406 |
|
f.complete(null); |
4407 |
|
|
4408 |
|
f = new CompletableFuture<>(); |
4409 |
< |
incomplete.acceptEither(f, (x) -> {}); |
4409 |
> |
incomplete.acceptEither(f, x -> {}); |
4410 |
|
f.complete(null); |
4411 |
|
|
4412 |
|
f = new CompletableFuture<>(); |
4413 |
< |
incomplete.applyToEither(f, (x) -> x); |
4413 |
> |
incomplete.applyToEither(f, x -> x); |
4414 |
|
f.complete(null); |
4415 |
|
|
4416 |
|
f = new CompletableFuture<>(); |
4417 |
< |
CompletableFuture.anyOf(new CompletableFuture<?>[] { incomplete, f }); |
4417 |
> |
CompletableFuture.anyOf(incomplete, f); |
4418 |
|
f.complete(null); |
4419 |
|
} |
4420 |
|
} |
4468 |
|
assertTrue(neverCompleted.thenRun(() -> {}).cancel(true)); |
4469 |
|
} |
4470 |
|
|
4471 |
+ |
/** |
4472 |
+ |
* Checks for garbage retention when MinimalStage.toCompletableFuture() |
4473 |
+ |
* is invoked many times. |
4474 |
+ |
* 8161600: Garbage retention when source CompletableFutures are never completed |
4475 |
+ |
* |
4476 |
+ |
* As of 2016-07, fails with OOME: |
4477 |
+ |
* ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testToCompletableFutureGarbageRetention tck |
4478 |
+ |
*/ |
4479 |
+ |
public void testToCompletableFutureGarbageRetention() throws Throwable { |
4480 |
+ |
final int n = expensiveTests ? 900_000 : 10; |
4481 |
+ |
CompletableFuture<Integer> neverCompleted = new CompletableFuture<>(); |
4482 |
+ |
CompletionStage minimal = neverCompleted.minimalCompletionStage(); |
4483 |
+ |
for (int i = 0; i < n; i++) |
4484 |
+ |
assertTrue(minimal.toCompletableFuture().cancel(true)); |
4485 |
+ |
} |
4486 |
+ |
|
4487 |
|
// static <U> U join(CompletionStage<U> stage) { |
4488 |
|
// CompletableFuture<U> f = new CompletableFuture<>(); |
4489 |
|
// stage.whenComplete((v, ex) -> { |