64 |
|
assertNull(f.getNow(null)); |
65 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
66 |
|
try { |
67 |
< |
f.get(0L, SECONDS); |
67 |
> |
f.get(randomExpiredTimeout(), randomTimeUnit()); |
68 |
|
shouldThrow(); |
69 |
|
} |
70 |
|
catch (TimeoutException success) {} |
76 |
|
|
77 |
|
try { |
78 |
|
assertEquals(value, f.join()); |
79 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
80 |
– |
try { |
79 |
|
assertEquals(value, f.getNow(null)); |
82 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
83 |
– |
try { |
80 |
|
assertEquals(value, f.get()); |
81 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
82 |
|
assertTrue(f.isDone()); |
89 |
|
* Returns the "raw" internal exceptional completion of f, |
90 |
|
* without any additional wrapping with CompletionException. |
91 |
|
*/ |
92 |
< |
<U> Throwable exceptionalCompletion(CompletableFuture<U> f) { |
93 |
< |
// handle (and whenComplete) can distinguish between "direct" |
94 |
< |
// and "wrapped" exceptional completion |
95 |
< |
return f.handle((U u, Throwable t) -> t).join(); |
92 |
> |
Throwable exceptionalCompletion(CompletableFuture<?> f) { |
93 |
> |
// handle (and whenComplete and exceptionally) can distinguish |
94 |
> |
// between "direct" and "wrapped" exceptional completion |
95 |
> |
return f.handle((u, t) -> t).join(); |
96 |
|
} |
97 |
|
|
98 |
|
void checkCompletedExceptionally(CompletableFuture<?> f, |
1238 |
|
r.assertInvoked(); |
1239 |
|
}} |
1240 |
|
|
1241 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
1242 |
|
public void testRunAsync_rejectingExecutor() { |
1243 |
|
CountingRejectingExecutor e = new CountingRejectingExecutor(); |
1244 |
|
try { |
1285 |
|
r.assertInvoked(); |
1286 |
|
}} |
1287 |
|
|
1288 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
1289 |
|
public void testSupplyAsync_rejectingExecutor() { |
1290 |
|
CountingRejectingExecutor e = new CountingRejectingExecutor(); |
1291 |
|
try { |
2560 |
|
|
2561 |
|
// unspecified behavior - both source completions available |
2562 |
|
try { |
2563 |
< |
assertEquals(null, h0.join()); |
2563 |
> |
assertNull(h0.join()); |
2564 |
|
rs[0].assertValue(v1); |
2565 |
|
} catch (CompletionException ok) { |
2566 |
|
checkCompletedWithWrappedException(h0, ex); |
2567 |
|
rs[0].assertNotInvoked(); |
2568 |
|
} |
2569 |
|
try { |
2570 |
< |
assertEquals(null, h1.join()); |
2570 |
> |
assertNull(h1.join()); |
2571 |
|
rs[1].assertValue(v1); |
2572 |
|
} catch (CompletionException ok) { |
2573 |
|
checkCompletedWithWrappedException(h1, ex); |
2574 |
|
rs[1].assertNotInvoked(); |
2575 |
|
} |
2576 |
|
try { |
2577 |
< |
assertEquals(null, h2.join()); |
2577 |
> |
assertNull(h2.join()); |
2578 |
|
rs[2].assertValue(v1); |
2579 |
|
} catch (CompletionException ok) { |
2580 |
|
checkCompletedWithWrappedException(h2, ex); |
2581 |
|
rs[2].assertNotInvoked(); |
2582 |
|
} |
2583 |
|
try { |
2584 |
< |
assertEquals(null, h3.join()); |
2584 |
> |
assertNull(h3.join()); |
2585 |
|
rs[3].assertValue(v1); |
2586 |
|
} catch (CompletionException ok) { |
2587 |
|
checkCompletedWithWrappedException(h3, ex); |
2820 |
|
|
2821 |
|
// unspecified behavior - both source completions available |
2822 |
|
try { |
2823 |
< |
assertEquals(null, h0.join()); |
2823 |
> |
assertNull(h0.join()); |
2824 |
|
rs[0].assertInvoked(); |
2825 |
|
} catch (CompletionException ok) { |
2826 |
|
checkCompletedWithWrappedException(h0, ex); |
2827 |
|
rs[0].assertNotInvoked(); |
2828 |
|
} |
2829 |
|
try { |
2830 |
< |
assertEquals(null, h1.join()); |
2830 |
> |
assertNull(h1.join()); |
2831 |
|
rs[1].assertInvoked(); |
2832 |
|
} catch (CompletionException ok) { |
2833 |
|
checkCompletedWithWrappedException(h1, ex); |
2834 |
|
rs[1].assertNotInvoked(); |
2835 |
|
} |
2836 |
|
try { |
2837 |
< |
assertEquals(null, h2.join()); |
2837 |
> |
assertNull(h2.join()); |
2838 |
|
rs[2].assertInvoked(); |
2839 |
|
} catch (CompletionException ok) { |
2840 |
|
checkCompletedWithWrappedException(h2, ex); |
2841 |
|
rs[2].assertNotInvoked(); |
2842 |
|
} |
2843 |
|
try { |
2844 |
< |
assertEquals(null, h3.join()); |
2844 |
> |
assertNull(h3.join()); |
2845 |
|
rs[3].assertInvoked(); |
2846 |
|
} catch (CompletionException ok) { |
2847 |
|
checkCompletedWithWrappedException(h3, ex); |
3236 |
|
/** |
3237 |
|
* Completion methods throw NullPointerException with null arguments |
3238 |
|
*/ |
3239 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
3240 |
|
public void testNPE() { |
3241 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3242 |
|
CompletableFuture<Integer> g = new CompletableFuture<>(); |
3531 |
|
*/ |
3532 |
|
public void testCompletedStage() { |
3533 |
|
AtomicInteger x = new AtomicInteger(0); |
3534 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3534 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3535 |
|
CompletionStage<Integer> f = CompletableFuture.completedStage(1); |
3536 |
|
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3537 |
|
assertEquals(x.get(), 1); |
3633 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3634 |
|
CompletionStage<Integer> g = f.minimalCompletionStage(); |
3635 |
|
AtomicInteger x = new AtomicInteger(0); |
3636 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3636 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3637 |
|
checkIncomplete(f); |
3638 |
|
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3639 |
|
f.complete(1); |
3650 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3651 |
|
CompletionStage<Integer> g = f.minimalCompletionStage(); |
3652 |
|
AtomicInteger x = new AtomicInteger(0); |
3653 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3653 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3654 |
|
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3655 |
|
checkIncomplete(f); |
3656 |
|
CFException ex = new CFException(); |
3668 |
|
CFException ex = new CFException(); |
3669 |
|
CompletionStage<Integer> f = CompletableFuture.failedStage(ex); |
3670 |
|
AtomicInteger x = new AtomicInteger(0); |
3671 |
< |
AtomicReference<Throwable> r = new AtomicReference<Throwable>(); |
3671 |
> |
AtomicReference<Throwable> r = new AtomicReference<>(); |
3672 |
|
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);}); |
3673 |
|
assertEquals(x.get(), 0); |
3674 |
|
assertEquals(r.get(), ex); |
4298 |
|
} |
4299 |
|
|
4300 |
|
/** Test long recursive chains of CompletableFutures with cascading completions */ |
4301 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
4302 |
|
public void testRecursiveChains() throws Throwable { |
4303 |
|
for (ExecutionMode m : ExecutionMode.values()) |
4304 |
|
for (boolean addDeadEnds : new boolean[] { true, false }) |
4323 |
|
* A single CompletableFuture with many dependents. |
4324 |
|
* A demo of scalability - runtime is O(n). |
4325 |
|
*/ |
4326 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
4327 |
|
public void testManyDependents() throws Throwable { |
4328 |
|
final int n = expensiveTests ? 1_000_000 : 10; |
4329 |
|
final CompletableFuture<Void> head = new CompletableFuture<>(); |
4353 |
|
} |
4354 |
|
|
4355 |
|
/** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */ |
4356 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
4357 |
|
public void testCoCompletionGarbageRetention() throws Throwable { |
4358 |
|
final int n = expensiveTests ? 1_000_000 : 10; |
4359 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |