53 |
|
catch (Throwable fail) { threadUnexpectedException(fail); } |
54 |
|
} |
55 |
|
|
56 |
< |
void checkCompletedNormally(CompletableFuture<?> f, Object value) { |
56 |
> |
<T> void checkCompletedNormally(CompletableFuture<T> f, T value) { |
57 |
> |
try { |
58 |
> |
assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS)); |
59 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
60 |
|
try { |
61 |
|
assertEquals(value, f.join()); |
62 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
66 |
|
try { |
67 |
|
assertEquals(value, f.get()); |
68 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
66 |
– |
try { |
67 |
– |
assertEquals(value, f.get(0L, SECONDS)); |
68 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
69 |
|
assertTrue(f.isDone()); |
70 |
|
assertFalse(f.isCancelled()); |
71 |
|
assertTrue(f.toString().contains("[Completed normally]")); |
73 |
|
|
74 |
|
void checkCompletedWithWrappedCFException(CompletableFuture<?> f) { |
75 |
|
try { |
76 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
77 |
+ |
shouldThrow(); |
78 |
+ |
} catch (ExecutionException success) { |
79 |
+ |
assertTrue(success.getCause() instanceof CFException); |
80 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
81 |
+ |
try { |
82 |
|
f.join(); |
83 |
|
shouldThrow(); |
84 |
< |
} catch (Throwable ex) { |
85 |
< |
assertTrue(ex instanceof CompletionException && |
80 |
< |
((CompletionException)ex).getCause() instanceof CFException); |
84 |
> |
} catch (CompletionException success) { |
85 |
> |
assertTrue(success.getCause() instanceof CFException); |
86 |
|
} |
87 |
|
try { |
88 |
|
f.getNow(null); |
89 |
|
shouldThrow(); |
90 |
< |
} catch (Throwable ex) { |
91 |
< |
assertTrue(ex instanceof CompletionException && |
87 |
< |
((CompletionException)ex).getCause() instanceof CFException); |
90 |
> |
} catch (CompletionException success) { |
91 |
> |
assertTrue(success.getCause() instanceof CFException); |
92 |
|
} |
93 |
|
try { |
94 |
|
f.get(); |
95 |
|
shouldThrow(); |
96 |
< |
} catch (Throwable ex) { |
97 |
< |
assertTrue(ex instanceof ExecutionException && |
98 |
< |
((ExecutionException)ex).getCause() instanceof CFException); |
95 |
< |
} |
96 |
< |
try { |
97 |
< |
f.get(0L, SECONDS); |
98 |
< |
shouldThrow(); |
99 |
< |
} catch (Throwable ex) { |
100 |
< |
assertTrue(ex instanceof ExecutionException && |
101 |
< |
((ExecutionException)ex).getCause() instanceof CFException); |
102 |
< |
} |
96 |
> |
} catch (ExecutionException success) { |
97 |
> |
assertTrue(success.getCause() instanceof CFException); |
98 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
99 |
|
assertTrue(f.isDone()); |
100 |
|
assertFalse(f.isCancelled()); |
101 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
102 |
|
} |
103 |
|
|
104 |
|
void checkCancelled(CompletableFuture<?> f) { |
105 |
|
try { |
106 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
107 |
+ |
shouldThrow(); |
108 |
+ |
} catch (CancellationException success) { |
109 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
110 |
+ |
try { |
111 |
|
f.join(); |
112 |
|
shouldThrow(); |
113 |
< |
} catch (Throwable ex) { |
112 |
< |
assertTrue(ex instanceof CancellationException); |
113 |
< |
} |
113 |
> |
} catch (CancellationException success) {} |
114 |
|
try { |
115 |
|
f.getNow(null); |
116 |
|
shouldThrow(); |
117 |
< |
} catch (Throwable ex) { |
118 |
< |
assertTrue(ex instanceof CancellationException); |
119 |
< |
} |
117 |
> |
} catch (CancellationException success) {} |
118 |
|
try { |
119 |
|
f.get(); |
120 |
|
shouldThrow(); |
121 |
< |
} catch (Throwable ex) { |
122 |
< |
assertTrue(ex instanceof CancellationException); |
125 |
< |
} |
126 |
< |
try { |
127 |
< |
f.get(0L, SECONDS); |
128 |
< |
shouldThrow(); |
129 |
< |
} catch (Throwable ex) { |
130 |
< |
assertTrue(ex instanceof CancellationException); |
131 |
< |
} |
121 |
> |
} catch (CancellationException success) { |
122 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
123 |
|
assertTrue(f.isDone()); |
124 |
|
assertTrue(f.isCancelled()); |
125 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
126 |
|
} |
127 |
|
|
128 |
|
void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) { |
129 |
|
try { |
130 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
131 |
+ |
shouldThrow(); |
132 |
+ |
} catch (ExecutionException success) { |
133 |
+ |
assertTrue(success.getCause() instanceof CancellationException); |
134 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
135 |
+ |
try { |
136 |
|
f.join(); |
137 |
|
shouldThrow(); |
138 |
< |
} catch (Throwable ex) { |
139 |
< |
assertTrue(ex instanceof CompletionException && |
142 |
< |
((CompletionException)ex).getCause() instanceof CancellationException); |
138 |
> |
} catch (CompletionException success) { |
139 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
140 |
|
} |
141 |
|
try { |
142 |
|
f.getNow(null); |
143 |
|
shouldThrow(); |
144 |
< |
} catch (Throwable ex) { |
145 |
< |
assertTrue(ex instanceof CompletionException && |
149 |
< |
((CompletionException)ex).getCause() instanceof CancellationException); |
144 |
> |
} catch (CompletionException success) { |
145 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
146 |
|
} |
147 |
|
try { |
148 |
|
f.get(); |
149 |
|
shouldThrow(); |
150 |
< |
} catch (Throwable ex) { |
151 |
< |
assertTrue(ex instanceof ExecutionException && |
152 |
< |
((ExecutionException)ex).getCause() instanceof CancellationException); |
157 |
< |
} |
158 |
< |
try { |
159 |
< |
f.get(0L, SECONDS); |
160 |
< |
shouldThrow(); |
161 |
< |
} catch (Throwable ex) { |
162 |
< |
assertTrue(ex instanceof ExecutionException && |
163 |
< |
((ExecutionException)ex).getCause() instanceof CancellationException); |
164 |
< |
} |
150 |
> |
} catch (ExecutionException success) { |
151 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
152 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
153 |
|
assertTrue(f.isDone()); |
154 |
|
assertFalse(f.isCancelled()); |
155 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
156 |
|
} |
157 |
|
|
158 |
|
/** |
160 |
|
* by methods isDone, isCancelled, and getNow |
161 |
|
*/ |
162 |
|
public void testConstructor() { |
163 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
163 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
164 |
|
checkIncomplete(f); |
165 |
|
} |
166 |
|
|
169 |
|
* isCancelled, join, get, and getNow |
170 |
|
*/ |
171 |
|
public void testComplete() { |
172 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
172 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
173 |
|
checkIncomplete(f); |
174 |
|
f.complete(one); |
175 |
|
checkCompletedNormally(f, one); |
180 |
|
* methods isDone, isCancelled, join, get, and getNow |
181 |
|
*/ |
182 |
|
public void testCompleteExceptionally() { |
183 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
183 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
184 |
|
checkIncomplete(f); |
185 |
|
f.completeExceptionally(new CFException()); |
186 |
|
checkCompletedWithWrappedCFException(f); |
191 |
|
* methods isDone, isCancelled, join, get, and getNow |
192 |
|
*/ |
193 |
|
public void testCancel() { |
194 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
194 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
195 |
|
checkIncomplete(f); |
196 |
|
assertTrue(f.cancel(true)); |
197 |
|
checkCancelled(f); |
201 |
|
* obtrudeValue forces completion with given value |
202 |
|
*/ |
203 |
|
public void testObtrudeValue() { |
204 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
204 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
205 |
|
checkIncomplete(f); |
206 |
|
f.complete(one); |
207 |
|
checkCompletedNormally(f, one); |
209 |
|
checkCompletedNormally(f, three); |
210 |
|
f.obtrudeValue(two); |
211 |
|
checkCompletedNormally(f, two); |
212 |
< |
f = new CompletableFuture<Integer>(); |
212 |
> |
f = new CompletableFuture<>(); |
213 |
|
f.obtrudeValue(three); |
214 |
|
checkCompletedNormally(f, three); |
215 |
< |
f = new CompletableFuture<Integer>(); |
215 |
> |
f = new CompletableFuture<>(); |
216 |
|
f.completeExceptionally(new CFException()); |
217 |
|
f.obtrudeValue(four); |
218 |
|
checkCompletedNormally(f, four); |
222 |
|
* obtrudeException forces completion with given exception |
223 |
|
*/ |
224 |
|
public void testObtrudeException() { |
225 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
225 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
226 |
|
checkIncomplete(f); |
227 |
|
f.complete(one); |
228 |
|
checkCompletedNormally(f, one); |
229 |
|
f.obtrudeException(new CFException()); |
230 |
|
checkCompletedWithWrappedCFException(f); |
231 |
< |
f = new CompletableFuture<Integer>(); |
231 |
> |
f = new CompletableFuture<>(); |
232 |
|
f.obtrudeException(new CFException()); |
233 |
|
checkCompletedWithWrappedCFException(f); |
234 |
< |
f = new CompletableFuture<Integer>(); |
234 |
> |
f = new CompletableFuture<>(); |
235 |
|
f.completeExceptionally(new CFException()); |
236 |
|
f.obtrudeValue(four); |
237 |
|
checkCompletedNormally(f, four); |
243 |
|
* getNumberOfDependents returns number of dependent tasks |
244 |
|
*/ |
245 |
|
public void testGetNumberOfDependents() { |
246 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
246 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
247 |
|
assertEquals(f.getNumberOfDependents(), 0); |
248 |
|
CompletableFuture g = f.thenRun(new Noop()); |
249 |
|
assertEquals(f.getNumberOfDependents(), 1); |
274 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
275 |
|
} |
276 |
|
|
277 |
+ |
/** |
278 |
+ |
* completedFuture returns a completed CompletableFuture with given value |
279 |
+ |
*/ |
280 |
+ |
public void testCompletedFuture() { |
281 |
+ |
CompletableFuture<String> f = CompletableFuture.completedFuture("test"); |
282 |
+ |
checkCompletedNormally(f, "test"); |
283 |
+ |
} |
284 |
+ |
|
285 |
+ |
// Choose non-commutative actions for better coverage |
286 |
+ |
|
287 |
|
static final Supplier<Integer> supplyOne = |
288 |
|
() -> Integer.valueOf(1); |
289 |
|
static final Function<Integer, Integer> inc = |
290 |
|
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
291 |
< |
static final BiFunction<Integer, Integer, Integer> add = |
292 |
< |
(Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue()); |
291 |
> |
static final BiFunction<Integer, Integer, Integer> subtract = |
292 |
> |
(Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue()); |
293 |
|
static final class IncAction implements Consumer<Integer> { |
294 |
|
int value; |
295 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
296 |
|
} |
297 |
< |
static final class AddAction implements BiConsumer<Integer, Integer> { |
297 |
> |
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
298 |
|
int value; |
299 |
|
public void accept(Integer x, Integer y) { |
300 |
< |
value = x.intValue() + y.intValue(); |
300 |
> |
value = x.intValue() - y.intValue(); |
301 |
|
} |
302 |
|
} |
303 |
|
static final class Noop implements Runnable { |
330 |
|
public void run() { ran = true; throw new CFException(); } |
331 |
|
} |
332 |
|
|
333 |
< |
static final class CompletableFutureInc implements Function<Integer, CompletableFuture<Integer>> { |
333 |
> |
static final class CompletableFutureInc |
334 |
> |
implements Function<Integer, CompletableFuture<Integer>> { |
335 |
> |
boolean ran; |
336 |
|
public CompletableFuture<Integer> apply(Integer x) { |
337 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
337 |
> |
ran = true; |
338 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
339 |
|
f.complete(Integer.valueOf(x.intValue() + 1)); |
340 |
|
return f; |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
< |
static final class FailingCompletableFutureFunction implements Function<Integer, CompletableFuture<Integer>> { |
344 |
> |
static final class FailingCompletableFutureFunction |
345 |
> |
implements Function<Integer, CompletableFuture<Integer>> { |
346 |
|
boolean ran; |
347 |
|
public CompletableFuture<Integer> apply(Integer x) { |
348 |
|
ran = true; throw new CFException(); |
351 |
|
|
352 |
|
// Used for explicit executor tests |
353 |
|
static final class ThreadExecutor implements Executor { |
354 |
+ |
AtomicInteger count = new AtomicInteger(0); |
355 |
+ |
|
356 |
|
public void execute(Runnable r) { |
357 |
+ |
count.getAndIncrement(); |
358 |
|
new Thread(r).start(); |
359 |
|
} |
360 |
|
} |
364 |
|
} |
365 |
|
|
366 |
|
static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> { |
367 |
+ |
boolean ran; |
368 |
|
public Integer apply(Integer x, Throwable t) { |
369 |
+ |
ran = true; |
370 |
|
return (t == null) ? two : three; |
371 |
|
} |
372 |
|
} |
377 |
|
* exception; otherwise with source value |
378 |
|
*/ |
379 |
|
public void testExceptionally() { |
380 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
380 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
381 |
|
ExceptionToInteger r = new ExceptionToInteger(); |
382 |
|
CompletableFuture<Integer> g = f.exceptionally(r); |
383 |
|
f.completeExceptionally(new CFException()); |
384 |
|
checkCompletedNormally(g, three); |
385 |
|
|
386 |
< |
f = new CompletableFuture<Integer>(); |
386 |
> |
f = new CompletableFuture<>(); |
387 |
|
r = new ExceptionToInteger(); |
388 |
|
g = f.exceptionally(r); |
389 |
|
f.complete(one); |
395 |
|
* normal or exceptional completion of source |
396 |
|
*/ |
397 |
|
public void testHandle() { |
398 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
399 |
< |
IntegerHandler r = new IntegerHandler(); |
400 |
< |
CompletableFuture<Integer> g = f.handle(r); |
398 |
> |
CompletableFuture<Integer> f, g; |
399 |
> |
IntegerHandler r; |
400 |
> |
|
401 |
> |
f = new CompletableFuture<>(); |
402 |
|
f.completeExceptionally(new CFException()); |
403 |
+ |
g = f.handle(r = new IntegerHandler()); |
404 |
+ |
assertTrue(r.ran); |
405 |
|
checkCompletedNormally(g, three); |
406 |
|
|
407 |
< |
f = new CompletableFuture<Integer>(); |
408 |
< |
r = new IntegerHandler(); |
409 |
< |
g = f.handle(r); |
407 |
> |
f = new CompletableFuture<>(); |
408 |
> |
g = f.handle(r = new IntegerHandler()); |
409 |
> |
assertFalse(r.ran); |
410 |
> |
f.completeExceptionally(new CFException()); |
411 |
> |
checkCompletedNormally(g, three); |
412 |
> |
assertTrue(r.ran); |
413 |
> |
|
414 |
> |
f = new CompletableFuture<>(); |
415 |
> |
f.complete(one); |
416 |
> |
g = f.handle(r = new IntegerHandler()); |
417 |
> |
assertTrue(r.ran); |
418 |
> |
checkCompletedNormally(g, two); |
419 |
> |
|
420 |
> |
f = new CompletableFuture<>(); |
421 |
> |
g = f.handle(r = new IntegerHandler()); |
422 |
> |
assertFalse(r.ran); |
423 |
|
f.complete(one); |
424 |
+ |
assertTrue(r.ran); |
425 |
|
checkCompletedNormally(g, two); |
426 |
|
} |
427 |
|
|
433 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
434 |
|
assertNull(f.join()); |
435 |
|
assertTrue(r.ran); |
436 |
+ |
checkCompletedNormally(f, null); |
437 |
|
} |
438 |
|
|
439 |
|
/** |
441 |
|
*/ |
442 |
|
public void testRunAsync2() { |
443 |
|
Noop r = new Noop(); |
444 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor()); |
444 |
> |
ThreadExecutor exec = new ThreadExecutor(); |
445 |
> |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
446 |
|
assertNull(f.join()); |
447 |
|
assertTrue(r.ran); |
448 |
+ |
checkCompletedNormally(f, null); |
449 |
+ |
assertEquals(1, exec.count.get()); |
450 |
|
} |
451 |
|
|
452 |
|
/** |
463 |
|
* supplyAsync completes with result of supplier |
464 |
|
*/ |
465 |
|
public void testSupplyAsync() { |
466 |
< |
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne); |
466 |
> |
CompletableFuture<Integer> f; |
467 |
> |
f = CompletableFuture.supplyAsync(supplyOne); |
468 |
|
assertEquals(f.join(), one); |
469 |
+ |
checkCompletedNormally(f, one); |
470 |
|
} |
471 |
|
|
472 |
|
/** |
473 |
|
* supplyAsync with executor completes with result of supplier |
474 |
|
*/ |
475 |
|
public void testSupplyAsync2() { |
476 |
< |
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); |
476 |
> |
CompletableFuture<Integer> f; |
477 |
> |
f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); |
478 |
|
assertEquals(f.join(), one); |
479 |
+ |
checkCompletedNormally(f, one); |
480 |
|
} |
481 |
|
|
482 |
|
/** |
489 |
|
assertTrue(r.ran); |
490 |
|
} |
491 |
|
|
492 |
< |
// seq conmpletion methods |
492 |
> |
// seq completion methods |
493 |
|
|
494 |
|
/** |
495 |
|
* thenRun result completes normally after normal completion of source |
496 |
|
*/ |
497 |
|
public void testThenRun() { |
498 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
498 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
499 |
|
Noop r = new Noop(); |
500 |
|
CompletableFuture<Void> g = f.thenRun(r); |
501 |
|
f.complete(null); |
502 |
|
checkCompletedNormally(g, null); |
503 |
|
// reordered version |
504 |
< |
f = new CompletableFuture<Integer>(); |
504 |
> |
f = new CompletableFuture<>(); |
505 |
|
f.complete(null); |
506 |
|
r = new Noop(); |
507 |
|
g = f.thenRun(r); |
513 |
|
* completion of source |
514 |
|
*/ |
515 |
|
public void testThenRun2() { |
516 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
516 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
517 |
|
Noop r = new Noop(); |
518 |
|
CompletableFuture<Void> g = f.thenRun(r); |
519 |
|
f.completeExceptionally(new CFException()); |
524 |
|
* thenRun result completes exceptionally if action does |
525 |
|
*/ |
526 |
|
public void testThenRun3() { |
527 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
527 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
528 |
|
FailingNoop r = new FailingNoop(); |
529 |
|
CompletableFuture<Void> g = f.thenRun(r); |
530 |
|
f.complete(null); |
535 |
|
* thenRun result completes exceptionally if source cancelled |
536 |
|
*/ |
537 |
|
public void testThenRun4() { |
538 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
538 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
539 |
|
Noop r = new Noop(); |
540 |
|
CompletableFuture<Void> g = f.thenRun(r); |
541 |
|
assertTrue(f.cancel(true)); |
546 |
|
* thenApply result completes normally after normal completion of source |
547 |
|
*/ |
548 |
|
public void testThenApply() { |
549 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
549 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
550 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
551 |
|
f.complete(one); |
552 |
|
checkCompletedNormally(g, two); |
557 |
|
* completion of source |
558 |
|
*/ |
559 |
|
public void testThenApply2() { |
560 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
560 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
561 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
562 |
|
f.completeExceptionally(new CFException()); |
563 |
|
checkCompletedWithWrappedCFException(g); |
567 |
|
* thenApply result completes exceptionally if action does |
568 |
|
*/ |
569 |
|
public void testThenApply3() { |
570 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
570 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
571 |
|
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
572 |
|
f.complete(one); |
573 |
|
checkCompletedWithWrappedCFException(g); |
577 |
|
* thenApply result completes exceptionally if source cancelled |
578 |
|
*/ |
579 |
|
public void testThenApply4() { |
580 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
580 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
581 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
582 |
|
assertTrue(f.cancel(true)); |
583 |
|
checkCompletedWithWrappedCancellationException(g); |
587 |
|
* thenAccept result completes normally after normal completion of source |
588 |
|
*/ |
589 |
|
public void testThenAccept() { |
590 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
590 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
591 |
|
IncAction r = new IncAction(); |
592 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
593 |
|
f.complete(one); |
600 |
|
* completion of source |
601 |
|
*/ |
602 |
|
public void testThenAccept2() { |
603 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
603 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
604 |
|
IncAction r = new IncAction(); |
605 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
606 |
|
f.completeExceptionally(new CFException()); |
611 |
|
* thenAccept result completes exceptionally if action does |
612 |
|
*/ |
613 |
|
public void testThenAccept3() { |
614 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
614 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
615 |
|
FailingConsumer r = new FailingConsumer(); |
616 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
617 |
|
f.complete(one); |
623 |
|
* thenAccept result completes exceptionally if source cancelled |
624 |
|
*/ |
625 |
|
public void testThenAccept4() { |
626 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
626 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
627 |
|
IncAction r = new IncAction(); |
628 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
629 |
|
assertTrue(f.cancel(true)); |
632 |
|
|
633 |
|
|
634 |
|
/** |
635 |
< |
* thenCombine result completes normally after normal completion of sources |
635 |
> |
* thenCombine result completes normally after normal completion |
636 |
> |
* of sources |
637 |
|
*/ |
638 |
|
public void testThenCombine() { |
639 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
606 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
607 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, add); |
608 |
< |
f.complete(one); |
609 |
< |
checkIncomplete(g); |
610 |
< |
f2.complete(two); |
611 |
< |
checkCompletedNormally(g, three); |
639 |
> |
CompletableFuture<Integer> f, g, h; |
640 |
|
|
641 |
< |
f = new CompletableFuture<Integer>(); |
642 |
< |
f.complete(one); |
643 |
< |
f2 = new CompletableFuture<Integer>(); |
644 |
< |
g = f.thenCombine(f2, add); |
645 |
< |
checkIncomplete(g); |
646 |
< |
f2.complete(two); |
647 |
< |
checkCompletedNormally(g, three); |
641 |
> |
f = new CompletableFuture<>(); |
642 |
> |
g = new CompletableFuture<>(); |
643 |
> |
h = f.thenCombine(g, subtract); |
644 |
> |
f.complete(3); |
645 |
> |
checkIncomplete(h); |
646 |
> |
g.complete(1); |
647 |
> |
checkCompletedNormally(h, 2); |
648 |
> |
|
649 |
> |
f = new CompletableFuture<>(); |
650 |
> |
g = new CompletableFuture<>(); |
651 |
> |
h = f.thenCombine(g, subtract); |
652 |
> |
g.complete(1); |
653 |
> |
checkIncomplete(h); |
654 |
> |
f.complete(3); |
655 |
> |
checkCompletedNormally(h, 2); |
656 |
> |
|
657 |
> |
f = new CompletableFuture<>(); |
658 |
> |
g = new CompletableFuture<>(); |
659 |
> |
g.complete(1); |
660 |
> |
f.complete(3); |
661 |
> |
h = f.thenCombine(g, subtract); |
662 |
> |
checkCompletedNormally(h, 2); |
663 |
|
} |
664 |
|
|
665 |
|
/** |
667 |
|
* completion of either source |
668 |
|
*/ |
669 |
|
public void testThenCombine2() { |
670 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
628 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
629 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, add); |
630 |
< |
f.completeExceptionally(new CFException()); |
631 |
< |
f2.complete(two); |
632 |
< |
checkCompletedWithWrappedCFException(g); |
670 |
> |
CompletableFuture<Integer> f, g, h; |
671 |
|
|
672 |
< |
f = new CompletableFuture<Integer>(); |
673 |
< |
f.complete(one); |
674 |
< |
f2 = new CompletableFuture<Integer>(); |
675 |
< |
g = f.thenCombine(f2, add); |
676 |
< |
f2.completeExceptionally(new CFException()); |
677 |
< |
checkCompletedWithWrappedCFException(g); |
672 |
> |
f = new CompletableFuture<>(); |
673 |
> |
g = new CompletableFuture<>(); |
674 |
> |
h = f.thenCombine(g, subtract); |
675 |
> |
f.completeExceptionally(new CFException()); |
676 |
> |
checkIncomplete(h); |
677 |
> |
g.complete(1); |
678 |
> |
checkCompletedWithWrappedCFException(h); |
679 |
> |
|
680 |
> |
f = new CompletableFuture<>(); |
681 |
> |
g = new CompletableFuture<>(); |
682 |
> |
h = f.thenCombine(g, subtract); |
683 |
> |
g.completeExceptionally(new CFException()); |
684 |
> |
checkIncomplete(h); |
685 |
> |
f.complete(3); |
686 |
> |
checkCompletedWithWrappedCFException(h); |
687 |
> |
|
688 |
> |
f = new CompletableFuture<>(); |
689 |
> |
g = new CompletableFuture<>(); |
690 |
> |
f.complete(3); |
691 |
> |
g.completeExceptionally(new CFException()); |
692 |
> |
h = f.thenCombine(g, subtract); |
693 |
> |
checkCompletedWithWrappedCFException(h); |
694 |
> |
|
695 |
> |
f = new CompletableFuture<>(); |
696 |
> |
g = new CompletableFuture<>(); |
697 |
> |
f.completeExceptionally(new CFException()); |
698 |
> |
g.complete(3); |
699 |
> |
h = f.thenCombine(g, subtract); |
700 |
> |
checkCompletedWithWrappedCFException(h); |
701 |
|
} |
702 |
|
|
703 |
|
/** |
704 |
|
* thenCombine result completes exceptionally if action does |
705 |
|
*/ |
706 |
|
public void testThenCombine3() { |
707 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
708 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
707 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
708 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
709 |
|
FailingBiFunction r = new FailingBiFunction(); |
710 |
|
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
711 |
|
f.complete(one); |
712 |
|
checkIncomplete(g); |
713 |
+ |
assertFalse(r.ran); |
714 |
|
f2.complete(two); |
715 |
|
checkCompletedWithWrappedCFException(g); |
716 |
+ |
assertTrue(r.ran); |
717 |
|
} |
718 |
|
|
719 |
|
/** |
720 |
|
* thenCombine result completes exceptionally if either source cancelled |
721 |
|
*/ |
722 |
|
public void testThenCombine4() { |
723 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
724 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
725 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, add); |
726 |
< |
assertTrue(f.cancel(true)); |
727 |
< |
f2.complete(two); |
728 |
< |
checkCompletedWithWrappedCancellationException(g); |
729 |
< |
f = new CompletableFuture<Integer>(); |
730 |
< |
f2 = new CompletableFuture<Integer>(); |
731 |
< |
g = f.thenCombine(f2, add); |
732 |
< |
f.complete(one); |
733 |
< |
assertTrue(f2.cancel(true)); |
734 |
< |
checkCompletedWithWrappedCancellationException(g); |
723 |
> |
CompletableFuture<Integer> f, g, h; |
724 |
> |
|
725 |
> |
f = new CompletableFuture<>(); |
726 |
> |
g = new CompletableFuture<>(); |
727 |
> |
h = f.thenCombine(g, subtract); |
728 |
> |
assertTrue(f.cancel(true)); |
729 |
> |
checkIncomplete(h); |
730 |
> |
g.complete(1); |
731 |
> |
checkCompletedWithWrappedCancellationException(h); |
732 |
> |
|
733 |
> |
f = new CompletableFuture<>(); |
734 |
> |
g = new CompletableFuture<>(); |
735 |
> |
h = f.thenCombine(g, subtract); |
736 |
> |
assertTrue(g.cancel(true)); |
737 |
> |
checkIncomplete(h); |
738 |
> |
f.complete(3); |
739 |
> |
checkCompletedWithWrappedCancellationException(h); |
740 |
> |
|
741 |
> |
f = new CompletableFuture<>(); |
742 |
> |
g = new CompletableFuture<>(); |
743 |
> |
assertTrue(f.cancel(true)); |
744 |
> |
assertTrue(g.cancel(true)); |
745 |
> |
h = f.thenCombine(g, subtract); |
746 |
> |
checkCompletedWithWrappedCancellationException(h); |
747 |
|
} |
748 |
|
|
749 |
|
/** |
751 |
|
* completion of sources |
752 |
|
*/ |
753 |
|
public void testThenAcceptBoth() { |
754 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
755 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
756 |
< |
AddAction r = new AddAction(); |
757 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
758 |
< |
f.complete(one); |
759 |
< |
checkIncomplete(g); |
760 |
< |
f2.complete(two); |
761 |
< |
checkCompletedNormally(g, null); |
762 |
< |
assertEquals(r.value, 3); |
754 |
> |
CompletableFuture<Integer> f, g; |
755 |
> |
CompletableFuture<Void> h; |
756 |
> |
SubtractAction r; |
757 |
> |
|
758 |
> |
f = new CompletableFuture<>(); |
759 |
> |
g = new CompletableFuture<>(); |
760 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
761 |
> |
f.complete(3); |
762 |
> |
checkIncomplete(h); |
763 |
> |
g.complete(1); |
764 |
> |
checkCompletedNormally(h, null); |
765 |
> |
assertEquals(r.value, 2); |
766 |
|
|
767 |
< |
r = new AddAction(); |
768 |
< |
f = new CompletableFuture<Integer>(); |
769 |
< |
f.complete(one); |
770 |
< |
f2 = new CompletableFuture<Integer>(); |
771 |
< |
g = f.thenAcceptBoth(f2, r); |
772 |
< |
checkIncomplete(g); |
773 |
< |
f2.complete(two); |
774 |
< |
checkCompletedNormally(g, null); |
775 |
< |
assertEquals(r.value, 3); |
767 |
> |
f = new CompletableFuture<>(); |
768 |
> |
g = new CompletableFuture<>(); |
769 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
770 |
> |
g.complete(1); |
771 |
> |
checkIncomplete(h); |
772 |
> |
f.complete(3); |
773 |
> |
checkCompletedNormally(h, null); |
774 |
> |
assertEquals(r.value, 2); |
775 |
> |
|
776 |
> |
f = new CompletableFuture<>(); |
777 |
> |
g = new CompletableFuture<>(); |
778 |
> |
g.complete(1); |
779 |
> |
f.complete(3); |
780 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
781 |
> |
checkCompletedNormally(h, null); |
782 |
> |
assertEquals(r.value, 2); |
783 |
|
} |
784 |
|
|
785 |
|
/** |
787 |
|
* completion of either source |
788 |
|
*/ |
789 |
|
public void testThenAcceptBoth2() { |
790 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
791 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
792 |
< |
AddAction r = new AddAction(); |
793 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
794 |
< |
f.completeExceptionally(new CFException()); |
795 |
< |
f2.complete(two); |
796 |
< |
checkCompletedWithWrappedCFException(g); |
797 |
< |
|
798 |
< |
r = new AddAction(); |
799 |
< |
f = new CompletableFuture<Integer>(); |
800 |
< |
f.complete(one); |
801 |
< |
f2 = new CompletableFuture<Integer>(); |
802 |
< |
g = f.thenAcceptBoth(f2, r); |
803 |
< |
f2.completeExceptionally(new CFException()); |
804 |
< |
checkCompletedWithWrappedCFException(g); |
790 |
> |
CompletableFuture<Integer> f, g; |
791 |
> |
CompletableFuture<Void> h; |
792 |
> |
SubtractAction r; |
793 |
> |
|
794 |
> |
f = new CompletableFuture<>(); |
795 |
> |
g = new CompletableFuture<>(); |
796 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
797 |
> |
f.completeExceptionally(new CFException()); |
798 |
> |
checkIncomplete(h); |
799 |
> |
g.complete(1); |
800 |
> |
checkCompletedWithWrappedCFException(h); |
801 |
> |
|
802 |
> |
f = new CompletableFuture<>(); |
803 |
> |
g = new CompletableFuture<>(); |
804 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
805 |
> |
g.completeExceptionally(new CFException()); |
806 |
> |
checkIncomplete(h); |
807 |
> |
f.complete(3); |
808 |
> |
checkCompletedWithWrappedCFException(h); |
809 |
> |
|
810 |
> |
f = new CompletableFuture<>(); |
811 |
> |
g = new CompletableFuture<>(); |
812 |
> |
f.complete(3); |
813 |
> |
g.completeExceptionally(new CFException()); |
814 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
815 |
> |
checkCompletedWithWrappedCFException(h); |
816 |
> |
|
817 |
> |
f = new CompletableFuture<>(); |
818 |
> |
g = new CompletableFuture<>(); |
819 |
> |
f.completeExceptionally(new CFException()); |
820 |
> |
g.complete(3); |
821 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
822 |
> |
checkCompletedWithWrappedCFException(h); |
823 |
|
} |
824 |
|
|
825 |
|
/** |
826 |
|
* thenAcceptBoth result completes exceptionally if action does |
827 |
|
*/ |
828 |
|
public void testThenAcceptBoth3() { |
829 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
830 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
831 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
832 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
833 |
< |
f.complete(one); |
834 |
< |
checkIncomplete(g); |
835 |
< |
f2.complete(two); |
836 |
< |
checkCompletedWithWrappedCFException(g); |
829 |
> |
CompletableFuture<Integer> f, g; |
830 |
> |
CompletableFuture<Void> h; |
831 |
> |
FailingBiConsumer r; |
832 |
> |
|
833 |
> |
f = new CompletableFuture<>(); |
834 |
> |
g = new CompletableFuture<>(); |
835 |
> |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
836 |
> |
f.complete(3); |
837 |
> |
checkIncomplete(h); |
838 |
> |
g.complete(1); |
839 |
> |
checkCompletedWithWrappedCFException(h); |
840 |
> |
|
841 |
> |
f = new CompletableFuture<>(); |
842 |
> |
g = new CompletableFuture<>(); |
843 |
> |
f.complete(3); |
844 |
> |
g.complete(1); |
845 |
> |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
846 |
> |
checkCompletedWithWrappedCFException(h); |
847 |
|
} |
848 |
|
|
849 |
|
/** |
850 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
851 |
|
*/ |
852 |
|
public void testThenAcceptBoth4() { |
853 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
854 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
855 |
< |
AddAction r = new AddAction(); |
856 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
857 |
< |
assertTrue(f.cancel(true)); |
858 |
< |
f2.complete(two); |
859 |
< |
checkCompletedWithWrappedCancellationException(g); |
860 |
< |
f = new CompletableFuture<Integer>(); |
861 |
< |
f2 = new CompletableFuture<Integer>(); |
862 |
< |
r = new AddAction(); |
863 |
< |
g = f.thenAcceptBoth(f2, r); |
864 |
< |
f.complete(one); |
865 |
< |
assertTrue(f2.cancel(true)); |
866 |
< |
checkCompletedWithWrappedCancellationException(g); |
853 |
> |
CompletableFuture<Integer> f, g; |
854 |
> |
CompletableFuture<Void> h; |
855 |
> |
SubtractAction r; |
856 |
> |
|
857 |
> |
f = new CompletableFuture<>(); |
858 |
> |
g = new CompletableFuture<>(); |
859 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
860 |
> |
assertTrue(f.cancel(true)); |
861 |
> |
checkIncomplete(h); |
862 |
> |
g.complete(1); |
863 |
> |
checkCompletedWithWrappedCancellationException(h); |
864 |
> |
|
865 |
> |
f = new CompletableFuture<>(); |
866 |
> |
g = new CompletableFuture<>(); |
867 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
868 |
> |
assertTrue(g.cancel(true)); |
869 |
> |
checkIncomplete(h); |
870 |
> |
f.complete(3); |
871 |
> |
checkCompletedWithWrappedCancellationException(h); |
872 |
> |
|
873 |
> |
f = new CompletableFuture<>(); |
874 |
> |
g = new CompletableFuture<>(); |
875 |
> |
f.complete(3); |
876 |
> |
assertTrue(g.cancel(true)); |
877 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
878 |
> |
checkCompletedWithWrappedCancellationException(h); |
879 |
> |
|
880 |
> |
f = new CompletableFuture<>(); |
881 |
> |
g = new CompletableFuture<>(); |
882 |
> |
assertTrue(f.cancel(true)); |
883 |
> |
g.complete(3); |
884 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
885 |
> |
checkCompletedWithWrappedCancellationException(h); |
886 |
|
} |
887 |
|
|
888 |
|
/** |
890 |
|
* completion of sources |
891 |
|
*/ |
892 |
|
public void testRunAfterBoth() { |
893 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
894 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
895 |
< |
Noop r = new Noop(); |
896 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
897 |
< |
f.complete(one); |
898 |
< |
checkIncomplete(g); |
899 |
< |
f2.complete(two); |
900 |
< |
checkCompletedNormally(g, null); |
893 |
> |
CompletableFuture<Integer> f, g; |
894 |
> |
CompletableFuture<Void> h; |
895 |
> |
Noop r; |
896 |
> |
|
897 |
> |
f = new CompletableFuture<>(); |
898 |
> |
g = new CompletableFuture<>(); |
899 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
900 |
> |
f.complete(3); |
901 |
> |
checkIncomplete(h); |
902 |
> |
g.complete(1); |
903 |
> |
checkCompletedNormally(h, null); |
904 |
|
assertTrue(r.ran); |
905 |
|
|
906 |
< |
r = new Noop(); |
907 |
< |
f = new CompletableFuture<Integer>(); |
908 |
< |
f.complete(one); |
909 |
< |
f2 = new CompletableFuture<Integer>(); |
910 |
< |
g = f.runAfterBoth(f2, r); |
911 |
< |
checkIncomplete(g); |
912 |
< |
f2.complete(two); |
913 |
< |
checkCompletedNormally(g, null); |
906 |
> |
f = new CompletableFuture<>(); |
907 |
> |
g = new CompletableFuture<>(); |
908 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
909 |
> |
g.complete(1); |
910 |
> |
checkIncomplete(h); |
911 |
> |
f.complete(3); |
912 |
> |
checkCompletedNormally(h, null); |
913 |
> |
assertTrue(r.ran); |
914 |
> |
|
915 |
> |
f = new CompletableFuture<>(); |
916 |
> |
g = new CompletableFuture<>(); |
917 |
> |
g.complete(1); |
918 |
> |
f.complete(3); |
919 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
920 |
> |
checkCompletedNormally(h, null); |
921 |
|
assertTrue(r.ran); |
922 |
|
} |
923 |
|
|
926 |
|
* completion of either source |
927 |
|
*/ |
928 |
|
public void testRunAfterBoth2() { |
929 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
930 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
931 |
< |
Noop r = new Noop(); |
932 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
933 |
< |
f.completeExceptionally(new CFException()); |
934 |
< |
f2.complete(two); |
935 |
< |
checkCompletedWithWrappedCFException(g); |
936 |
< |
|
937 |
< |
r = new Noop(); |
938 |
< |
f = new CompletableFuture<Integer>(); |
939 |
< |
f.complete(one); |
940 |
< |
f2 = new CompletableFuture<Integer>(); |
941 |
< |
g = f.runAfterBoth(f2, r); |
942 |
< |
f2.completeExceptionally(new CFException()); |
943 |
< |
checkCompletedWithWrappedCFException(g); |
929 |
> |
CompletableFuture<Integer> f, g; |
930 |
> |
CompletableFuture<Void> h; |
931 |
> |
Noop r; |
932 |
> |
|
933 |
> |
f = new CompletableFuture<>(); |
934 |
> |
g = new CompletableFuture<>(); |
935 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
936 |
> |
f.completeExceptionally(new CFException()); |
937 |
> |
checkIncomplete(h); |
938 |
> |
g.complete(1); |
939 |
> |
checkCompletedWithWrappedCFException(h); |
940 |
> |
assertFalse(r.ran); |
941 |
> |
|
942 |
> |
f = new CompletableFuture<>(); |
943 |
> |
g = new CompletableFuture<>(); |
944 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
945 |
> |
g.completeExceptionally(new CFException()); |
946 |
> |
checkIncomplete(h); |
947 |
> |
f.complete(3); |
948 |
> |
checkCompletedWithWrappedCFException(h); |
949 |
> |
assertFalse(r.ran); |
950 |
> |
|
951 |
> |
f = new CompletableFuture<>(); |
952 |
> |
g = new CompletableFuture<>(); |
953 |
> |
g.completeExceptionally(new CFException()); |
954 |
> |
f.complete(3); |
955 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
956 |
> |
checkCompletedWithWrappedCFException(h); |
957 |
> |
assertFalse(r.ran); |
958 |
> |
|
959 |
> |
f = new CompletableFuture<>(); |
960 |
> |
g = new CompletableFuture<>(); |
961 |
> |
f.completeExceptionally(new CFException()); |
962 |
> |
g.complete(1); |
963 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
964 |
> |
checkCompletedWithWrappedCFException(h); |
965 |
> |
assertFalse(r.ran); |
966 |
|
} |
967 |
|
|
968 |
|
/** |
969 |
|
* runAfterBoth result completes exceptionally if action does |
970 |
|
*/ |
971 |
|
public void testRunAfterBoth3() { |
972 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
973 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
972 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
973 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
974 |
|
FailingNoop r = new FailingNoop(); |
975 |
|
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
976 |
|
f.complete(one); |
983 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
984 |
|
*/ |
985 |
|
public void testRunAfterBoth4() { |
986 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
987 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
986 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
987 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
988 |
|
Noop r = new Noop(); |
989 |
|
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
990 |
|
assertTrue(f.cancel(true)); |
991 |
|
f2.complete(two); |
992 |
|
checkCompletedWithWrappedCancellationException(g); |
993 |
< |
f = new CompletableFuture<Integer>(); |
994 |
< |
f2 = new CompletableFuture<Integer>(); |
993 |
> |
f = new CompletableFuture<>(); |
994 |
> |
f2 = new CompletableFuture<>(); |
995 |
|
r = new Noop(); |
996 |
|
g = f.runAfterBoth(f2, r); |
997 |
|
f.complete(one); |
1004 |
|
* of either source |
1005 |
|
*/ |
1006 |
|
public void testApplyToEither() { |
1007 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1008 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1007 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1008 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1009 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1010 |
|
f.complete(one); |
1011 |
|
checkCompletedNormally(g, two); |
1012 |
|
f2.complete(one); |
1013 |
|
checkCompletedNormally(g, two); |
1014 |
|
|
1015 |
< |
f = new CompletableFuture<Integer>(); |
1015 |
> |
f = new CompletableFuture<>(); |
1016 |
|
f.complete(one); |
1017 |
< |
f2 = new CompletableFuture<Integer>(); |
1017 |
> |
f2 = new CompletableFuture<>(); |
1018 |
|
g = f.applyToEither(f2, inc); |
1019 |
|
checkCompletedNormally(g, two); |
1020 |
|
} |
1024 |
|
* completion of either source |
1025 |
|
*/ |
1026 |
|
public void testApplyToEither2() { |
1027 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1028 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1027 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1028 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1029 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1030 |
|
f.completeExceptionally(new CFException()); |
1031 |
|
f2.complete(one); |
1032 |
|
checkCompletedWithWrappedCFException(g); |
1033 |
|
|
1034 |
< |
f = new CompletableFuture<Integer>(); |
1035 |
< |
f2 = new CompletableFuture<Integer>(); |
1034 |
> |
f = new CompletableFuture<>(); |
1035 |
> |
f2 = new CompletableFuture<>(); |
1036 |
|
f2.completeExceptionally(new CFException()); |
1037 |
|
g = f.applyToEither(f2, inc); |
1038 |
|
checkCompletedWithWrappedCFException(g); |
1042 |
|
* applyToEither result completes exceptionally if action does |
1043 |
|
*/ |
1044 |
|
public void testApplyToEither3() { |
1045 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1046 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1045 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1046 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1047 |
|
FailingFunction r = new FailingFunction(); |
1048 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, r); |
1049 |
|
f2.complete(two); |
1054 |
|
* applyToEither result completes exceptionally if either source cancelled |
1055 |
|
*/ |
1056 |
|
public void testApplyToEither4() { |
1057 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1058 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1057 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1058 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1059 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1060 |
|
assertTrue(f.cancel(true)); |
1061 |
|
checkCompletedWithWrappedCancellationException(g); |
1062 |
< |
f = new CompletableFuture<Integer>(); |
1063 |
< |
f2 = new CompletableFuture<Integer>(); |
1062 |
> |
f = new CompletableFuture<>(); |
1063 |
> |
f2 = new CompletableFuture<>(); |
1064 |
|
assertTrue(f2.cancel(true)); |
1065 |
|
checkCompletedWithWrappedCancellationException(g); |
1066 |
|
} |
1070 |
|
* of either source |
1071 |
|
*/ |
1072 |
|
public void testAcceptEither() { |
1073 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1074 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1073 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1074 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1075 |
|
IncAction r = new IncAction(); |
1076 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1077 |
|
f.complete(one); |
1081 |
|
assertEquals(r.value, 2); |
1082 |
|
|
1083 |
|
r = new IncAction(); |
1084 |
< |
f = new CompletableFuture<Integer>(); |
1084 |
> |
f = new CompletableFuture<>(); |
1085 |
|
f.complete(one); |
1086 |
< |
f2 = new CompletableFuture<Integer>(); |
1086 |
> |
f2 = new CompletableFuture<>(); |
1087 |
|
g = f.acceptEither(f2, r); |
1088 |
|
checkCompletedNormally(g, null); |
1089 |
|
assertEquals(r.value, 2); |
1094 |
|
* completion of either source |
1095 |
|
*/ |
1096 |
|
public void testAcceptEither2() { |
1097 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1098 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1097 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1098 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1099 |
|
IncAction r = new IncAction(); |
1100 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1101 |
|
f.completeExceptionally(new CFException()); |
1103 |
|
checkCompletedWithWrappedCFException(g); |
1104 |
|
|
1105 |
|
r = new IncAction(); |
1106 |
< |
f = new CompletableFuture<Integer>(); |
1107 |
< |
f2 = new CompletableFuture<Integer>(); |
1106 |
> |
f = new CompletableFuture<>(); |
1107 |
> |
f2 = new CompletableFuture<>(); |
1108 |
|
f2.completeExceptionally(new CFException()); |
1109 |
|
g = f.acceptEither(f2, r); |
1110 |
|
checkCompletedWithWrappedCFException(g); |
1114 |
|
* acceptEither result completes exceptionally if action does |
1115 |
|
*/ |
1116 |
|
public void testAcceptEither3() { |
1117 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1118 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1117 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1118 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1119 |
|
FailingConsumer r = new FailingConsumer(); |
1120 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1121 |
|
f2.complete(two); |
1126 |
|
* acceptEither result completes exceptionally if either source cancelled |
1127 |
|
*/ |
1128 |
|
public void testAcceptEither4() { |
1129 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1130 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1129 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1130 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1131 |
|
IncAction r = new IncAction(); |
1132 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1133 |
|
assertTrue(f.cancel(true)); |
1134 |
|
checkCompletedWithWrappedCancellationException(g); |
1135 |
< |
f = new CompletableFuture<Integer>(); |
1136 |
< |
f2 = new CompletableFuture<Integer>(); |
1135 |
> |
f = new CompletableFuture<>(); |
1136 |
> |
f2 = new CompletableFuture<>(); |
1137 |
|
assertTrue(f2.cancel(true)); |
1138 |
|
checkCompletedWithWrappedCancellationException(g); |
1139 |
|
} |
1144 |
|
* of either source |
1145 |
|
*/ |
1146 |
|
public void testRunAfterEither() { |
1147 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1148 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1147 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1148 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1149 |
|
Noop r = new Noop(); |
1150 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1151 |
|
f.complete(one); |
1155 |
|
assertTrue(r.ran); |
1156 |
|
|
1157 |
|
r = new Noop(); |
1158 |
< |
f = new CompletableFuture<Integer>(); |
1158 |
> |
f = new CompletableFuture<>(); |
1159 |
|
f.complete(one); |
1160 |
< |
f2 = new CompletableFuture<Integer>(); |
1160 |
> |
f2 = new CompletableFuture<>(); |
1161 |
|
g = f.runAfterEither(f2, r); |
1162 |
|
checkCompletedNormally(g, null); |
1163 |
|
assertTrue(r.ran); |
1168 |
|
* completion of either source |
1169 |
|
*/ |
1170 |
|
public void testRunAfterEither2() { |
1171 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1172 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1171 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1172 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1173 |
|
Noop r = new Noop(); |
1174 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1175 |
|
f.completeExceptionally(new CFException()); |
1177 |
|
checkCompletedWithWrappedCFException(g); |
1178 |
|
|
1179 |
|
r = new Noop(); |
1180 |
< |
f = new CompletableFuture<Integer>(); |
1181 |
< |
f2 = new CompletableFuture<Integer>(); |
1180 |
> |
f = new CompletableFuture<>(); |
1181 |
> |
f2 = new CompletableFuture<>(); |
1182 |
|
f2.completeExceptionally(new CFException()); |
1183 |
|
g = f.runAfterEither(f2, r); |
1184 |
|
checkCompletedWithWrappedCFException(g); |
1188 |
|
* runAfterEither result completes exceptionally if action does |
1189 |
|
*/ |
1190 |
|
public void testRunAfterEither3() { |
1191 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1192 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1191 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1192 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1193 |
|
FailingNoop r = new FailingNoop(); |
1194 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1195 |
|
f2.complete(two); |
1200 |
|
* runAfterEither result completes exceptionally if either source cancelled |
1201 |
|
*/ |
1202 |
|
public void testRunAfterEither4() { |
1203 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1204 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1203 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1204 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1205 |
|
Noop r = new Noop(); |
1206 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1207 |
|
assertTrue(f.cancel(true)); |
1208 |
|
checkCompletedWithWrappedCancellationException(g); |
1209 |
< |
f = new CompletableFuture<Integer>(); |
1210 |
< |
f2 = new CompletableFuture<Integer>(); |
1209 |
> |
f = new CompletableFuture<>(); |
1210 |
> |
f2 = new CompletableFuture<>(); |
1211 |
|
assertTrue(f2.cancel(true)); |
1212 |
|
checkCompletedWithWrappedCancellationException(g); |
1213 |
|
} |
1216 |
|
* thenCompose result completes normally after normal completion of source |
1217 |
|
*/ |
1218 |
|
public void testThenCompose() { |
1219 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1220 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1221 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1219 |
> |
CompletableFuture<Integer> f, g; |
1220 |
> |
CompletableFutureInc r; |
1221 |
> |
|
1222 |
> |
f = new CompletableFuture<>(); |
1223 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1224 |
> |
f.complete(one); |
1225 |
> |
checkCompletedNormally(g, two); |
1226 |
> |
assertTrue(r.ran); |
1227 |
> |
|
1228 |
> |
f = new CompletableFuture<>(); |
1229 |
|
f.complete(one); |
1230 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1231 |
|
checkCompletedNormally(g, two); |
1232 |
+ |
assertTrue(r.ran); |
1233 |
|
} |
1234 |
|
|
1235 |
|
/** |
1237 |
|
* completion of source |
1238 |
|
*/ |
1239 |
|
public void testThenCompose2() { |
1240 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1241 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1242 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1240 |
> |
CompletableFuture<Integer> f, g; |
1241 |
> |
CompletableFutureInc r; |
1242 |
> |
|
1243 |
> |
f = new CompletableFuture<>(); |
1244 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1245 |
|
f.completeExceptionally(new CFException()); |
1246 |
|
checkCompletedWithWrappedCFException(g); |
1247 |
+ |
|
1248 |
+ |
f = new CompletableFuture<>(); |
1249 |
+ |
f.completeExceptionally(new CFException()); |
1250 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1251 |
+ |
checkCompletedWithWrappedCFException(g); |
1252 |
|
} |
1253 |
|
|
1254 |
|
/** |
1255 |
|
* thenCompose result completes exceptionally if action does |
1256 |
|
*/ |
1257 |
|
public void testThenCompose3() { |
1258 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1259 |
< |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
1260 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1258 |
> |
CompletableFuture<Integer> f, g; |
1259 |
> |
FailingCompletableFutureFunction r; |
1260 |
> |
|
1261 |
> |
f = new CompletableFuture<>(); |
1262 |
> |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
1263 |
> |
f.complete(one); |
1264 |
> |
checkCompletedWithWrappedCFException(g); |
1265 |
> |
|
1266 |
> |
f = new CompletableFuture<>(); |
1267 |
|
f.complete(one); |
1268 |
+ |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
1269 |
|
checkCompletedWithWrappedCFException(g); |
1270 |
|
} |
1271 |
|
|
1273 |
|
* thenCompose result completes exceptionally if source cancelled |
1274 |
|
*/ |
1275 |
|
public void testThenCompose4() { |
1276 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1277 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1278 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1276 |
> |
CompletableFuture<Integer> f, g; |
1277 |
> |
CompletableFutureInc r; |
1278 |
> |
|
1279 |
> |
f = new CompletableFuture<>(); |
1280 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1281 |
|
assertTrue(f.cancel(true)); |
1282 |
|
checkCompletedWithWrappedCancellationException(g); |
1283 |
+ |
|
1284 |
+ |
f = new CompletableFuture<>(); |
1285 |
+ |
assertTrue(f.cancel(true)); |
1286 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1287 |
+ |
checkCompletedWithWrappedCancellationException(g); |
1288 |
|
} |
1289 |
|
|
1290 |
|
|
1294 |
|
* thenRunAsync result completes normally after normal completion of source |
1295 |
|
*/ |
1296 |
|
public void testThenRunAsync() { |
1297 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1297 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1298 |
|
Noop r = new Noop(); |
1299 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1300 |
|
f.complete(null); |
1301 |
|
checkCompletedNormally(g, null); |
1302 |
|
|
1303 |
|
// reordered version |
1304 |
< |
f = new CompletableFuture<Integer>(); |
1304 |
> |
f = new CompletableFuture<>(); |
1305 |
|
f.complete(null); |
1306 |
|
r = new Noop(); |
1307 |
|
g = f.thenRunAsync(r); |
1313 |
|
* completion of source |
1314 |
|
*/ |
1315 |
|
public void testThenRunAsync2() { |
1316 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1316 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1317 |
|
Noop r = new Noop(); |
1318 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1319 |
|
f.completeExceptionally(new CFException()); |
1329 |
|
* thenRunAsync result completes exceptionally if action does |
1330 |
|
*/ |
1331 |
|
public void testThenRunAsync3() { |
1332 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1332 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1333 |
|
FailingNoop r = new FailingNoop(); |
1334 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1335 |
|
f.complete(null); |
1340 |
|
* thenRunAsync result completes exceptionally if source cancelled |
1341 |
|
*/ |
1342 |
|
public void testThenRunAsync4() { |
1343 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1343 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1344 |
|
Noop r = new Noop(); |
1345 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1346 |
|
assertTrue(f.cancel(true)); |
1351 |
|
* thenApplyAsync result completes normally after normal completion of source |
1352 |
|
*/ |
1353 |
|
public void testThenApplyAsync() { |
1354 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1354 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1355 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1356 |
|
f.complete(one); |
1357 |
|
checkCompletedNormally(g, two); |
1362 |
|
* completion of source |
1363 |
|
*/ |
1364 |
|
public void testThenApplyAsync2() { |
1365 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1365 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1366 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1367 |
|
f.completeExceptionally(new CFException()); |
1368 |
|
checkCompletedWithWrappedCFException(g); |
1372 |
|
* thenApplyAsync result completes exceptionally if action does |
1373 |
|
*/ |
1374 |
|
public void testThenApplyAsync3() { |
1375 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1375 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1376 |
|
FailingFunction r = new FailingFunction(); |
1377 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
1378 |
|
f.complete(null); |
1383 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
1384 |
|
*/ |
1385 |
|
public void testThenApplyAsync4() { |
1386 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1386 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1387 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1388 |
|
assertTrue(f.cancel(true)); |
1389 |
|
checkCompletedWithWrappedCancellationException(g); |
1394 |
|
* completion of source |
1395 |
|
*/ |
1396 |
|
public void testThenAcceptAsync() { |
1397 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1397 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1398 |
|
IncAction r = new IncAction(); |
1399 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1400 |
|
f.complete(one); |
1407 |
|
* completion of source |
1408 |
|
*/ |
1409 |
|
public void testThenAcceptAsync2() { |
1410 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1410 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1411 |
|
IncAction r = new IncAction(); |
1412 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1413 |
|
f.completeExceptionally(new CFException()); |
1418 |
|
* thenAcceptAsync result completes exceptionally if action does |
1419 |
|
*/ |
1420 |
|
public void testThenAcceptAsync3() { |
1421 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1421 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1422 |
|
FailingConsumer r = new FailingConsumer(); |
1423 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1424 |
|
f.complete(null); |
1429 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
1430 |
|
*/ |
1431 |
|
public void testThenAcceptAsync4() { |
1432 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1432 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1433 |
|
IncAction r = new IncAction(); |
1434 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1435 |
|
assertTrue(f.cancel(true)); |
1436 |
|
checkCompletedWithWrappedCancellationException(g); |
1437 |
|
} |
1438 |
+ |
|
1439 |
|
/** |
1440 |
|
* thenCombineAsync result completes normally after normal |
1441 |
|
* completion of sources |
1442 |
|
*/ |
1443 |
|
public void testThenCombineAsync() { |
1444 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1445 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1446 |
< |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, add); |
1447 |
< |
f.complete(one); |
1448 |
< |
checkIncomplete(g); |
1449 |
< |
f2.complete(two); |
1450 |
< |
checkCompletedNormally(g, three); |
1444 |
> |
CompletableFuture<Integer> f, g, h; |
1445 |
> |
|
1446 |
> |
f = new CompletableFuture<>(); |
1447 |
> |
g = new CompletableFuture<>(); |
1448 |
> |
h = f.thenCombineAsync(g, subtract); |
1449 |
> |
f.complete(3); |
1450 |
> |
checkIncomplete(h); |
1451 |
> |
g.complete(1); |
1452 |
> |
checkCompletedNormally(h, 2); |
1453 |
> |
|
1454 |
> |
f = new CompletableFuture<>(); |
1455 |
> |
g = new CompletableFuture<>(); |
1456 |
> |
h = f.thenCombineAsync(g, subtract); |
1457 |
> |
g.complete(1); |
1458 |
> |
checkIncomplete(h); |
1459 |
> |
f.complete(3); |
1460 |
> |
checkCompletedNormally(h, 2); |
1461 |
> |
|
1462 |
> |
f = new CompletableFuture<>(); |
1463 |
> |
g = new CompletableFuture<>(); |
1464 |
> |
g.complete(1); |
1465 |
> |
f.complete(3); |
1466 |
> |
h = f.thenCombineAsync(g, subtract); |
1467 |
> |
checkCompletedNormally(h, 2); |
1468 |
|
} |
1469 |
|
|
1470 |
|
/** |
1471 |
|
* thenCombineAsync result completes exceptionally after exceptional |
1472 |
< |
* completion of source |
1472 |
> |
* completion of either source |
1473 |
|
*/ |
1474 |
|
public void testThenCombineAsync2() { |
1475 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1264 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1265 |
< |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, add); |
1266 |
< |
f.completeExceptionally(new CFException()); |
1267 |
< |
f2.complete(two); |
1268 |
< |
checkCompletedWithWrappedCFException(g); |
1475 |
> |
CompletableFuture<Integer> f, g, h; |
1476 |
|
|
1477 |
< |
f = new CompletableFuture<Integer>(); |
1478 |
< |
f2 = new CompletableFuture<Integer>(); |
1479 |
< |
g = f.thenCombineAsync(f2, add); |
1480 |
< |
f.complete(one); |
1481 |
< |
f2.completeExceptionally(new CFException()); |
1482 |
< |
checkCompletedWithWrappedCFException(g); |
1477 |
> |
f = new CompletableFuture<>(); |
1478 |
> |
g = new CompletableFuture<>(); |
1479 |
> |
h = f.thenCombineAsync(g, subtract); |
1480 |
> |
f.completeExceptionally(new CFException()); |
1481 |
> |
checkIncomplete(h); |
1482 |
> |
g.complete(1); |
1483 |
> |
checkCompletedWithWrappedCFException(h); |
1484 |
> |
|
1485 |
> |
f = new CompletableFuture<>(); |
1486 |
> |
g = new CompletableFuture<>(); |
1487 |
> |
h = f.thenCombineAsync(g, subtract); |
1488 |
> |
g.completeExceptionally(new CFException()); |
1489 |
> |
checkIncomplete(h); |
1490 |
> |
f.complete(3); |
1491 |
> |
checkCompletedWithWrappedCFException(h); |
1492 |
> |
|
1493 |
> |
f = new CompletableFuture<>(); |
1494 |
> |
g = new CompletableFuture<>(); |
1495 |
> |
g.completeExceptionally(new CFException()); |
1496 |
> |
f.complete(3); |
1497 |
> |
h = f.thenCombineAsync(g, subtract); |
1498 |
> |
checkCompletedWithWrappedCFException(h); |
1499 |
|
} |
1500 |
|
|
1501 |
|
/** |
1502 |
|
* thenCombineAsync result completes exceptionally if action does |
1503 |
|
*/ |
1504 |
|
public void testThenCombineAsync3() { |
1505 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1506 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1505 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1506 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1507 |
|
FailingBiFunction r = new FailingBiFunction(); |
1508 |
|
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1509 |
|
f.complete(one); |
1510 |
|
checkIncomplete(g); |
1511 |
+ |
assertFalse(r.ran); |
1512 |
|
f2.complete(two); |
1513 |
|
checkCompletedWithWrappedCFException(g); |
1514 |
+ |
assertTrue(r.ran); |
1515 |
|
} |
1516 |
|
|
1517 |
|
/** |
1518 |
|
* thenCombineAsync result completes exceptionally if either source cancelled |
1519 |
|
*/ |
1520 |
|
public void testThenCombineAsync4() { |
1521 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1297 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1298 |
< |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, add); |
1299 |
< |
assertTrue(f.cancel(true)); |
1300 |
< |
f2.complete(two); |
1301 |
< |
checkCompletedWithWrappedCancellationException(g); |
1521 |
> |
CompletableFuture<Integer> f, g, h; |
1522 |
|
|
1523 |
< |
f = new CompletableFuture<Integer>(); |
1524 |
< |
f2 = new CompletableFuture<Integer>(); |
1525 |
< |
g = f.thenCombineAsync(f2, add); |
1526 |
< |
f.complete(one); |
1527 |
< |
assertTrue(f2.cancel(true)); |
1528 |
< |
checkCompletedWithWrappedCancellationException(g); |
1523 |
> |
f = new CompletableFuture<>(); |
1524 |
> |
g = new CompletableFuture<>(); |
1525 |
> |
h = f.thenCombineAsync(g, subtract); |
1526 |
> |
assertTrue(f.cancel(true)); |
1527 |
> |
checkIncomplete(h); |
1528 |
> |
g.complete(1); |
1529 |
> |
checkCompletedWithWrappedCancellationException(h); |
1530 |
> |
|
1531 |
> |
f = new CompletableFuture<>(); |
1532 |
> |
g = new CompletableFuture<>(); |
1533 |
> |
h = f.thenCombineAsync(g, subtract); |
1534 |
> |
assertTrue(g.cancel(true)); |
1535 |
> |
checkIncomplete(h); |
1536 |
> |
f.complete(3); |
1537 |
> |
checkCompletedWithWrappedCancellationException(h); |
1538 |
> |
|
1539 |
> |
f = new CompletableFuture<>(); |
1540 |
> |
g = new CompletableFuture<>(); |
1541 |
> |
g.complete(3); |
1542 |
> |
assertTrue(f.cancel(true)); |
1543 |
> |
h = f.thenCombineAsync(g, subtract); |
1544 |
> |
checkCompletedWithWrappedCancellationException(h); |
1545 |
> |
|
1546 |
> |
f = new CompletableFuture<>(); |
1547 |
> |
g = new CompletableFuture<>(); |
1548 |
> |
f.complete(3); |
1549 |
> |
assertTrue(g.cancel(true)); |
1550 |
> |
h = f.thenCombineAsync(g, subtract); |
1551 |
> |
checkCompletedWithWrappedCancellationException(h); |
1552 |
|
} |
1553 |
|
|
1554 |
|
/** |
1556 |
|
* completion of sources |
1557 |
|
*/ |
1558 |
|
public void testThenAcceptBothAsync() { |
1559 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1560 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1561 |
< |
AddAction r = new AddAction(); |
1562 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1563 |
< |
f.complete(one); |
1564 |
< |
checkIncomplete(g); |
1565 |
< |
f2.complete(two); |
1566 |
< |
checkCompletedNormally(g, null); |
1567 |
< |
assertEquals(r.value, 3); |
1559 |
> |
CompletableFuture<Integer> f, g; |
1560 |
> |
CompletableFuture<Void> h; |
1561 |
> |
SubtractAction r; |
1562 |
> |
|
1563 |
> |
f = new CompletableFuture<>(); |
1564 |
> |
g = new CompletableFuture<>(); |
1565 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1566 |
> |
f.complete(3); |
1567 |
> |
checkIncomplete(h); |
1568 |
> |
g.complete(1); |
1569 |
> |
checkCompletedNormally(h, null); |
1570 |
> |
assertEquals(r.value, 2); |
1571 |
> |
|
1572 |
> |
f = new CompletableFuture<>(); |
1573 |
> |
g = new CompletableFuture<>(); |
1574 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1575 |
> |
g.complete(1); |
1576 |
> |
checkIncomplete(h); |
1577 |
> |
f.complete(3); |
1578 |
> |
checkCompletedNormally(h, null); |
1579 |
> |
assertEquals(r.value, 2); |
1580 |
> |
|
1581 |
> |
f = new CompletableFuture<>(); |
1582 |
> |
g = new CompletableFuture<>(); |
1583 |
> |
g.complete(1); |
1584 |
> |
f.complete(3); |
1585 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1586 |
> |
checkCompletedNormally(h, null); |
1587 |
> |
assertEquals(r.value, 2); |
1588 |
|
} |
1589 |
|
|
1590 |
|
/** |
1592 |
|
* completion of source |
1593 |
|
*/ |
1594 |
|
public void testThenAcceptBothAsync2() { |
1595 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1596 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1597 |
< |
AddAction r = new AddAction(); |
1598 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1599 |
< |
f.completeExceptionally(new CFException()); |
1600 |
< |
f2.complete(two); |
1601 |
< |
checkCompletedWithWrappedCFException(g); |
1602 |
< |
|
1603 |
< |
r = new AddAction(); |
1604 |
< |
f = new CompletableFuture<Integer>(); |
1605 |
< |
f2 = new CompletableFuture<Integer>(); |
1606 |
< |
g = f.thenAcceptBothAsync(f2, r); |
1607 |
< |
f.complete(one); |
1608 |
< |
f2.completeExceptionally(new CFException()); |
1609 |
< |
checkCompletedWithWrappedCFException(g); |
1595 |
> |
CompletableFuture<Integer> f, g; |
1596 |
> |
CompletableFuture<Void> h; |
1597 |
> |
SubtractAction r; |
1598 |
> |
|
1599 |
> |
f = new CompletableFuture<>(); |
1600 |
> |
g = new CompletableFuture<>(); |
1601 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1602 |
> |
f.completeExceptionally(new CFException()); |
1603 |
> |
checkIncomplete(h); |
1604 |
> |
g.complete(1); |
1605 |
> |
checkCompletedWithWrappedCFException(h); |
1606 |
> |
|
1607 |
> |
f = new CompletableFuture<>(); |
1608 |
> |
g = new CompletableFuture<>(); |
1609 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1610 |
> |
g.completeExceptionally(new CFException()); |
1611 |
> |
checkIncomplete(h); |
1612 |
> |
f.complete(3); |
1613 |
> |
checkCompletedWithWrappedCFException(h); |
1614 |
> |
|
1615 |
> |
f = new CompletableFuture<>(); |
1616 |
> |
g = new CompletableFuture<>(); |
1617 |
> |
f.complete(3); |
1618 |
> |
g.completeExceptionally(new CFException()); |
1619 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1620 |
> |
checkCompletedWithWrappedCFException(h); |
1621 |
> |
|
1622 |
> |
f = new CompletableFuture<>(); |
1623 |
> |
g = new CompletableFuture<>(); |
1624 |
> |
f.completeExceptionally(new CFException()); |
1625 |
> |
g.complete(3); |
1626 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1627 |
> |
checkCompletedWithWrappedCFException(h); |
1628 |
|
} |
1629 |
|
|
1630 |
|
/** |
1631 |
|
* thenAcceptBothAsync result completes exceptionally if action does |
1632 |
|
*/ |
1633 |
|
public void testThenAcceptBothAsync3() { |
1634 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1635 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1636 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
1637 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1638 |
< |
f.complete(one); |
1639 |
< |
checkIncomplete(g); |
1640 |
< |
f2.complete(two); |
1641 |
< |
checkCompletedWithWrappedCFException(g); |
1634 |
> |
CompletableFuture<Integer> f, g; |
1635 |
> |
CompletableFuture<Void> h; |
1636 |
> |
FailingBiConsumer r; |
1637 |
> |
|
1638 |
> |
f = new CompletableFuture<>(); |
1639 |
> |
g = new CompletableFuture<>(); |
1640 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1641 |
> |
f.complete(3); |
1642 |
> |
checkIncomplete(h); |
1643 |
> |
g.complete(1); |
1644 |
> |
checkCompletedWithWrappedCFException(h); |
1645 |
> |
|
1646 |
> |
f = new CompletableFuture<>(); |
1647 |
> |
g = new CompletableFuture<>(); |
1648 |
> |
f.complete(3); |
1649 |
> |
g.complete(1); |
1650 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1651 |
> |
checkCompletedWithWrappedCFException(h); |
1652 |
|
} |
1653 |
|
|
1654 |
|
/** |
1655 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1656 |
|
*/ |
1657 |
|
public void testThenAcceptBothAsync4() { |
1658 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1659 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1660 |
< |
AddAction r = new AddAction(); |
1661 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1662 |
< |
assertTrue(f.cancel(true)); |
1663 |
< |
f2.complete(two); |
1664 |
< |
checkCompletedWithWrappedCancellationException(g); |
1665 |
< |
|
1666 |
< |
r = new AddAction(); |
1667 |
< |
f = new CompletableFuture<Integer>(); |
1668 |
< |
f2 = new CompletableFuture<Integer>(); |
1669 |
< |
g = f.thenAcceptBothAsync(f2, r); |
1670 |
< |
f.complete(one); |
1671 |
< |
assertTrue(f2.cancel(true)); |
1672 |
< |
checkCompletedWithWrappedCancellationException(g); |
1658 |
> |
CompletableFuture<Integer> f, g; |
1659 |
> |
CompletableFuture<Void> h; |
1660 |
> |
SubtractAction r; |
1661 |
> |
|
1662 |
> |
f = new CompletableFuture<>(); |
1663 |
> |
g = new CompletableFuture<>(); |
1664 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1665 |
> |
assertTrue(f.cancel(true)); |
1666 |
> |
checkIncomplete(h); |
1667 |
> |
g.complete(1); |
1668 |
> |
checkCompletedWithWrappedCancellationException(h); |
1669 |
> |
|
1670 |
> |
f = new CompletableFuture<>(); |
1671 |
> |
g = new CompletableFuture<>(); |
1672 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1673 |
> |
assertTrue(g.cancel(true)); |
1674 |
> |
checkIncomplete(h); |
1675 |
> |
f.complete(3); |
1676 |
> |
checkCompletedWithWrappedCancellationException(h); |
1677 |
> |
|
1678 |
> |
f = new CompletableFuture<>(); |
1679 |
> |
g = new CompletableFuture<>(); |
1680 |
> |
f.complete(3); |
1681 |
> |
assertTrue(g.cancel(true)); |
1682 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1683 |
> |
checkCompletedWithWrappedCancellationException(h); |
1684 |
> |
|
1685 |
> |
f = new CompletableFuture<>(); |
1686 |
> |
g = new CompletableFuture<>(); |
1687 |
> |
assertTrue(f.cancel(true)); |
1688 |
> |
g.complete(3); |
1689 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1690 |
> |
checkCompletedWithWrappedCancellationException(h); |
1691 |
|
} |
1692 |
|
|
1693 |
|
/** |
1695 |
|
* completion of sources |
1696 |
|
*/ |
1697 |
|
public void testRunAfterBothAsync() { |
1698 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1699 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1698 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1699 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1700 |
|
Noop r = new Noop(); |
1701 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1702 |
|
f.complete(one); |
1711 |
|
* completion of source |
1712 |
|
*/ |
1713 |
|
public void testRunAfterBothAsync2() { |
1714 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1715 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1714 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1715 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1716 |
|
Noop r = new Noop(); |
1717 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1718 |
|
f.completeExceptionally(new CFException()); |
1720 |
|
checkCompletedWithWrappedCFException(g); |
1721 |
|
|
1722 |
|
r = new Noop(); |
1723 |
< |
f = new CompletableFuture<Integer>(); |
1724 |
< |
f2 = new CompletableFuture<Integer>(); |
1723 |
> |
f = new CompletableFuture<>(); |
1724 |
> |
f2 = new CompletableFuture<>(); |
1725 |
|
g = f.runAfterBothAsync(f2, r); |
1726 |
|
f.complete(one); |
1727 |
|
f2.completeExceptionally(new CFException()); |
1732 |
|
* runAfterBothAsync result completes exceptionally if action does |
1733 |
|
*/ |
1734 |
|
public void testRunAfterBothAsync3() { |
1735 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1736 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1735 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1736 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1737 |
|
FailingNoop r = new FailingNoop(); |
1738 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1739 |
|
f.complete(one); |
1746 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
1747 |
|
*/ |
1748 |
|
public void testRunAfterBothAsync4() { |
1749 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1750 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1749 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1750 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1751 |
|
Noop r = new Noop(); |
1752 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1753 |
|
assertTrue(f.cancel(true)); |
1755 |
|
checkCompletedWithWrappedCancellationException(g); |
1756 |
|
|
1757 |
|
r = new Noop(); |
1758 |
< |
f = new CompletableFuture<Integer>(); |
1759 |
< |
f2 = new CompletableFuture<Integer>(); |
1758 |
> |
f = new CompletableFuture<>(); |
1759 |
> |
f2 = new CompletableFuture<>(); |
1760 |
|
g = f.runAfterBothAsync(f2, r); |
1761 |
|
f.complete(one); |
1762 |
|
assertTrue(f2.cancel(true)); |
1768 |
|
* completion of sources |
1769 |
|
*/ |
1770 |
|
public void testApplyToEitherAsync() { |
1771 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1772 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1771 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1772 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1773 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1774 |
|
f.complete(one); |
1775 |
|
checkCompletedNormally(g, two); |
1776 |
|
|
1777 |
< |
f = new CompletableFuture<Integer>(); |
1777 |
> |
f = new CompletableFuture<>(); |
1778 |
|
f.complete(one); |
1779 |
< |
f2 = new CompletableFuture<Integer>(); |
1779 |
> |
f2 = new CompletableFuture<>(); |
1780 |
|
g = f.applyToEitherAsync(f2, inc); |
1781 |
|
checkCompletedNormally(g, two); |
1782 |
|
} |
1786 |
|
* completion of source |
1787 |
|
*/ |
1788 |
|
public void testApplyToEitherAsync2() { |
1789 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1790 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1789 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1790 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1791 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1792 |
|
f.completeExceptionally(new CFException()); |
1793 |
|
checkCompletedWithWrappedCFException(g); |
1794 |
|
|
1795 |
< |
f = new CompletableFuture<Integer>(); |
1796 |
< |
f2 = new CompletableFuture<Integer>(); |
1795 |
> |
f = new CompletableFuture<>(); |
1796 |
> |
f2 = new CompletableFuture<>(); |
1797 |
|
f2.completeExceptionally(new CFException()); |
1798 |
|
g = f.applyToEitherAsync(f2, inc); |
1799 |
|
f.complete(one); |
1804 |
|
* applyToEitherAsync result completes exceptionally if action does |
1805 |
|
*/ |
1806 |
|
public void testApplyToEitherAsync3() { |
1807 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1808 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1807 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1808 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1809 |
|
FailingFunction r = new FailingFunction(); |
1810 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r); |
1811 |
|
f.complete(one); |
1816 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
1817 |
|
*/ |
1818 |
|
public void testApplyToEitherAsync4() { |
1819 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1820 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1819 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1820 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1821 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1822 |
|
assertTrue(f.cancel(true)); |
1823 |
|
checkCompletedWithWrappedCancellationException(g); |
1824 |
|
|
1825 |
< |
f = new CompletableFuture<Integer>(); |
1826 |
< |
f2 = new CompletableFuture<Integer>(); |
1825 |
> |
f = new CompletableFuture<>(); |
1826 |
> |
f2 = new CompletableFuture<>(); |
1827 |
|
assertTrue(f2.cancel(true)); |
1828 |
|
g = f.applyToEitherAsync(f2, inc); |
1829 |
|
checkCompletedWithWrappedCancellationException(g); |
1834 |
|
* completion of sources |
1835 |
|
*/ |
1836 |
|
public void testAcceptEitherAsync() { |
1837 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1838 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1837 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1838 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1839 |
|
IncAction r = new IncAction(); |
1840 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1841 |
|
f.complete(one); |
1843 |
|
assertEquals(r.value, 2); |
1844 |
|
|
1845 |
|
r = new IncAction(); |
1846 |
< |
f = new CompletableFuture<Integer>(); |
1846 |
> |
f = new CompletableFuture<>(); |
1847 |
|
f.complete(one); |
1848 |
< |
f2 = new CompletableFuture<Integer>(); |
1848 |
> |
f2 = new CompletableFuture<>(); |
1849 |
|
g = f.acceptEitherAsync(f2, r); |
1850 |
|
checkCompletedNormally(g, null); |
1851 |
|
assertEquals(r.value, 2); |
1856 |
|
* completion of source |
1857 |
|
*/ |
1858 |
|
public void testAcceptEitherAsync2() { |
1859 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1860 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1859 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1860 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1861 |
|
IncAction r = new IncAction(); |
1862 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1863 |
|
f.completeExceptionally(new CFException()); |
1864 |
|
checkCompletedWithWrappedCFException(g); |
1865 |
|
|
1866 |
|
r = new IncAction(); |
1867 |
< |
f = new CompletableFuture<Integer>(); |
1868 |
< |
f2 = new CompletableFuture<Integer>(); |
1867 |
> |
f = new CompletableFuture<>(); |
1868 |
> |
f2 = new CompletableFuture<>(); |
1869 |
|
f2.completeExceptionally(new CFException()); |
1870 |
|
g = f.acceptEitherAsync(f2, r); |
1871 |
|
f.complete(one); |
1876 |
|
* acceptEitherAsync result completes exceptionally if action does |
1877 |
|
*/ |
1878 |
|
public void testAcceptEitherAsync3() { |
1879 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1880 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1879 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1880 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1881 |
|
FailingConsumer r = new FailingConsumer(); |
1882 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1883 |
|
f.complete(one); |
1889 |
|
* source cancelled |
1890 |
|
*/ |
1891 |
|
public void testAcceptEitherAsync4() { |
1892 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1893 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1892 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1893 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1894 |
|
IncAction r = new IncAction(); |
1895 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1896 |
|
assertTrue(f.cancel(true)); |
1897 |
|
checkCompletedWithWrappedCancellationException(g); |
1898 |
|
|
1899 |
|
r = new IncAction(); |
1900 |
< |
f = new CompletableFuture<Integer>(); |
1901 |
< |
f2 = new CompletableFuture<Integer>(); |
1900 |
> |
f = new CompletableFuture<>(); |
1901 |
> |
f2 = new CompletableFuture<>(); |
1902 |
|
assertTrue(f2.cancel(true)); |
1903 |
|
g = f.acceptEitherAsync(f2, r); |
1904 |
|
checkCompletedWithWrappedCancellationException(g); |
1909 |
|
* completion of sources |
1910 |
|
*/ |
1911 |
|
public void testRunAfterEitherAsync() { |
1912 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1913 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1912 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1913 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1914 |
|
Noop r = new Noop(); |
1915 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1916 |
|
f.complete(one); |
1918 |
|
assertTrue(r.ran); |
1919 |
|
|
1920 |
|
r = new Noop(); |
1921 |
< |
f = new CompletableFuture<Integer>(); |
1921 |
> |
f = new CompletableFuture<>(); |
1922 |
|
f.complete(one); |
1923 |
< |
f2 = new CompletableFuture<Integer>(); |
1923 |
> |
f2 = new CompletableFuture<>(); |
1924 |
|
g = f.runAfterEitherAsync(f2, r); |
1925 |
|
checkCompletedNormally(g, null); |
1926 |
|
assertTrue(r.ran); |
1931 |
|
* completion of source |
1932 |
|
*/ |
1933 |
|
public void testRunAfterEitherAsync2() { |
1934 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1935 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1934 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1935 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1936 |
|
Noop r = new Noop(); |
1937 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1938 |
|
f.completeExceptionally(new CFException()); |
1939 |
|
checkCompletedWithWrappedCFException(g); |
1940 |
|
|
1941 |
|
r = new Noop(); |
1942 |
< |
f = new CompletableFuture<Integer>(); |
1943 |
< |
f2 = new CompletableFuture<Integer>(); |
1942 |
> |
f = new CompletableFuture<>(); |
1943 |
> |
f2 = new CompletableFuture<>(); |
1944 |
|
f2.completeExceptionally(new CFException()); |
1945 |
|
g = f.runAfterEitherAsync(f2, r); |
1946 |
|
f.complete(one); |
1951 |
|
* runAfterEitherAsync result completes exceptionally if action does |
1952 |
|
*/ |
1953 |
|
public void testRunAfterEitherAsync3() { |
1954 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1955 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1954 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1955 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1956 |
|
FailingNoop r = new FailingNoop(); |
1957 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1958 |
|
f.complete(one); |
1964 |
|
* source cancelled |
1965 |
|
*/ |
1966 |
|
public void testRunAfterEitherAsync4() { |
1967 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1968 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1967 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1968 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1969 |
|
Noop r = new Noop(); |
1970 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1971 |
|
assertTrue(f.cancel(true)); |
1972 |
|
checkCompletedWithWrappedCancellationException(g); |
1973 |
|
|
1974 |
|
r = new Noop(); |
1975 |
< |
f = new CompletableFuture<Integer>(); |
1976 |
< |
f2 = new CompletableFuture<Integer>(); |
1975 |
> |
f = new CompletableFuture<>(); |
1976 |
> |
f2 = new CompletableFuture<>(); |
1977 |
|
assertTrue(f2.cancel(true)); |
1978 |
|
g = f.runAfterEitherAsync(f2, r); |
1979 |
|
checkCompletedWithWrappedCancellationException(g); |
1980 |
|
} |
1981 |
|
|
1982 |
|
/** |
1983 |
< |
* thenCompse result completes normally after normal completion of source |
1983 |
> |
* thenComposeAsync result completes normally after normal |
1984 |
> |
* completion of source |
1985 |
|
*/ |
1986 |
|
public void testThenComposeAsync() { |
1987 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1988 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1989 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
1987 |
> |
CompletableFuture<Integer> f, g; |
1988 |
> |
CompletableFutureInc r; |
1989 |
> |
|
1990 |
> |
f = new CompletableFuture<>(); |
1991 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
1992 |
> |
f.complete(one); |
1993 |
> |
checkCompletedNormally(g, two); |
1994 |
> |
|
1995 |
> |
f = new CompletableFuture<>(); |
1996 |
|
f.complete(one); |
1997 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
1998 |
|
checkCompletedNormally(g, two); |
1999 |
|
} |
2000 |
|
|
2001 |
|
/** |
2002 |
< |
* thenComposeAsync result completes exceptionally after exceptional |
2003 |
< |
* completion of source |
2002 |
> |
* thenComposeAsync result completes exceptionally after |
2003 |
> |
* exceptional completion of source |
2004 |
|
*/ |
2005 |
|
public void testThenComposeAsync2() { |
2006 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2007 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2008 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2006 |
> |
CompletableFuture<Integer> f, g; |
2007 |
> |
CompletableFutureInc r; |
2008 |
> |
|
2009 |
> |
f = new CompletableFuture<>(); |
2010 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2011 |
|
f.completeExceptionally(new CFException()); |
2012 |
|
checkCompletedWithWrappedCFException(g); |
2013 |
+ |
assertFalse(r.ran); |
2014 |
+ |
|
2015 |
+ |
f = new CompletableFuture<>(); |
2016 |
+ |
f.completeExceptionally(new CFException()); |
2017 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2018 |
+ |
checkCompletedWithWrappedCFException(g); |
2019 |
+ |
assertFalse(r.ran); |
2020 |
|
} |
2021 |
|
|
2022 |
|
/** |
2023 |
|
* thenComposeAsync result completes exceptionally if action does |
2024 |
|
*/ |
2025 |
|
public void testThenComposeAsync3() { |
2026 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2027 |
< |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
2028 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2026 |
> |
CompletableFuture<Integer> f, g; |
2027 |
> |
FailingCompletableFutureFunction r; |
2028 |
> |
|
2029 |
> |
f = new CompletableFuture<>(); |
2030 |
> |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
2031 |
|
f.complete(one); |
2032 |
|
checkCompletedWithWrappedCFException(g); |
2033 |
+ |
|
2034 |
+ |
f = new CompletableFuture<>(); |
2035 |
+ |
f.complete(one); |
2036 |
+ |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
2037 |
+ |
checkCompletedWithWrappedCFException(g); |
2038 |
|
} |
2039 |
|
|
2040 |
|
/** |
2041 |
|
* thenComposeAsync result completes exceptionally if source cancelled |
2042 |
|
*/ |
2043 |
|
public void testThenComposeAsync4() { |
2044 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2045 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2046 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2044 |
> |
CompletableFuture<Integer> f, g; |
2045 |
> |
CompletableFutureInc r; |
2046 |
> |
|
2047 |
> |
f = new CompletableFuture<>(); |
2048 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2049 |
|
assertTrue(f.cancel(true)); |
2050 |
|
checkCompletedWithWrappedCancellationException(g); |
2051 |
+ |
|
2052 |
+ |
f = new CompletableFuture<>(); |
2053 |
+ |
assertTrue(f.cancel(true)); |
2054 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2055 |
+ |
checkCompletedWithWrappedCancellationException(g); |
2056 |
|
} |
2057 |
|
|
2058 |
|
|
2059 |
< |
// aaync with explicit executors |
2059 |
> |
// async with explicit executors |
2060 |
|
|
2061 |
|
/** |
2062 |
|
* thenRunAsync result completes normally after normal completion of source |
2063 |
|
*/ |
2064 |
|
public void testThenRunAsyncE() { |
2065 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2065 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2066 |
|
Noop r = new Noop(); |
2067 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2068 |
|
f.complete(null); |
2069 |
|
checkCompletedNormally(g, null); |
2070 |
|
|
2071 |
|
// reordered version |
2072 |
< |
f = new CompletableFuture<Integer>(); |
2072 |
> |
f = new CompletableFuture<>(); |
2073 |
|
f.complete(null); |
2074 |
|
r = new Noop(); |
2075 |
|
g = f.thenRunAsync(r, new ThreadExecutor()); |
2081 |
|
* completion of source |
2082 |
|
*/ |
2083 |
|
public void testThenRunAsync2E() { |
2084 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2084 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2085 |
|
Noop r = new Noop(); |
2086 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2087 |
|
f.completeExceptionally(new CFException()); |
2097 |
|
* thenRunAsync result completes exceptionally if action does |
2098 |
|
*/ |
2099 |
|
public void testThenRunAsync3E() { |
2100 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2100 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2101 |
|
FailingNoop r = new FailingNoop(); |
2102 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2103 |
|
f.complete(null); |
2108 |
|
* thenRunAsync result completes exceptionally if source cancelled |
2109 |
|
*/ |
2110 |
|
public void testThenRunAsync4E() { |
2111 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2111 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2112 |
|
Noop r = new Noop(); |
2113 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2114 |
|
assertTrue(f.cancel(true)); |
2119 |
|
* thenApplyAsync result completes normally after normal completion of source |
2120 |
|
*/ |
2121 |
|
public void testThenApplyAsyncE() { |
2122 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2122 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2123 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2124 |
|
f.complete(one); |
2125 |
|
checkCompletedNormally(g, two); |
2130 |
|
* completion of source |
2131 |
|
*/ |
2132 |
|
public void testThenApplyAsync2E() { |
2133 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2133 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2134 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2135 |
|
f.completeExceptionally(new CFException()); |
2136 |
|
checkCompletedWithWrappedCFException(g); |
2140 |
|
* thenApplyAsync result completes exceptionally if action does |
2141 |
|
*/ |
2142 |
|
public void testThenApplyAsync3E() { |
2143 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2143 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2144 |
|
FailingFunction r = new FailingFunction(); |
2145 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
2146 |
|
f.complete(null); |
2151 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
2152 |
|
*/ |
2153 |
|
public void testThenApplyAsync4E() { |
2154 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2154 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2155 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2156 |
|
assertTrue(f.cancel(true)); |
2157 |
|
checkCompletedWithWrappedCancellationException(g); |
2162 |
|
* completion of source |
2163 |
|
*/ |
2164 |
|
public void testThenAcceptAsyncE() { |
2165 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2165 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2166 |
|
IncAction r = new IncAction(); |
2167 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2168 |
|
f.complete(one); |
2175 |
|
* completion of source |
2176 |
|
*/ |
2177 |
|
public void testThenAcceptAsync2E() { |
2178 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2178 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2179 |
|
IncAction r = new IncAction(); |
2180 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2181 |
|
f.completeExceptionally(new CFException()); |
2186 |
|
* thenAcceptAsync result completes exceptionally if action does |
2187 |
|
*/ |
2188 |
|
public void testThenAcceptAsync3E() { |
2189 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2189 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2190 |
|
FailingConsumer r = new FailingConsumer(); |
2191 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2192 |
|
f.complete(null); |
2197 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
2198 |
|
*/ |
2199 |
|
public void testThenAcceptAsync4E() { |
2200 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2200 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2201 |
|
IncAction r = new IncAction(); |
2202 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2203 |
|
assertTrue(f.cancel(true)); |
2204 |
|
checkCompletedWithWrappedCancellationException(g); |
2205 |
|
} |
2206 |
+ |
|
2207 |
|
/** |
2208 |
|
* thenCombineAsync result completes normally after normal |
2209 |
|
* completion of sources |
2210 |
|
*/ |
2211 |
|
public void testThenCombineAsyncE() { |
2212 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2213 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2214 |
< |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor()); |
2215 |
< |
f.complete(one); |
2216 |
< |
checkIncomplete(g); |
2217 |
< |
f2.complete(two); |
2218 |
< |
checkCompletedNormally(g, three); |
2212 |
> |
CompletableFuture<Integer> f, g, h; |
2213 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2214 |
> |
int count = 0; |
2215 |
> |
|
2216 |
> |
f = new CompletableFuture<>(); |
2217 |
> |
g = new CompletableFuture<>(); |
2218 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2219 |
> |
f.complete(3); |
2220 |
> |
checkIncomplete(h); |
2221 |
> |
g.complete(1); |
2222 |
> |
checkCompletedNormally(h, 2); |
2223 |
> |
assertEquals(++count, e.count.get()); |
2224 |
> |
|
2225 |
> |
f = new CompletableFuture<>(); |
2226 |
> |
g = new CompletableFuture<>(); |
2227 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2228 |
> |
g.complete(1); |
2229 |
> |
checkIncomplete(h); |
2230 |
> |
f.complete(3); |
2231 |
> |
checkCompletedNormally(h, 2); |
2232 |
> |
assertEquals(++count, e.count.get()); |
2233 |
> |
|
2234 |
> |
f = new CompletableFuture<>(); |
2235 |
> |
g = new CompletableFuture<>(); |
2236 |
> |
g.complete(1); |
2237 |
> |
f.complete(3); |
2238 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2239 |
> |
checkCompletedNormally(h, 2); |
2240 |
> |
assertEquals(++count, e.count.get()); |
2241 |
|
} |
2242 |
|
|
2243 |
|
/** |
2244 |
|
* thenCombineAsync result completes exceptionally after exceptional |
2245 |
< |
* completion of source |
2245 |
> |
* completion of either source |
2246 |
|
*/ |
2247 |
|
public void testThenCombineAsync2E() { |
2248 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2249 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2250 |
< |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor()); |
2251 |
< |
f.completeExceptionally(new CFException()); |
2252 |
< |
f2.complete(two); |
2253 |
< |
checkCompletedWithWrappedCFException(g); |
2248 |
> |
CompletableFuture<Integer> f, g, h; |
2249 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2250 |
> |
int count = 0; |
2251 |
> |
|
2252 |
> |
f = new CompletableFuture<>(); |
2253 |
> |
g = new CompletableFuture<>(); |
2254 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2255 |
> |
f.completeExceptionally(new CFException()); |
2256 |
> |
checkIncomplete(h); |
2257 |
> |
g.complete(1); |
2258 |
> |
checkCompletedWithWrappedCFException(h); |
2259 |
> |
|
2260 |
> |
f = new CompletableFuture<>(); |
2261 |
> |
g = new CompletableFuture<>(); |
2262 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2263 |
> |
g.completeExceptionally(new CFException()); |
2264 |
> |
checkIncomplete(h); |
2265 |
> |
f.complete(3); |
2266 |
> |
checkCompletedWithWrappedCFException(h); |
2267 |
> |
|
2268 |
> |
f = new CompletableFuture<>(); |
2269 |
> |
g = new CompletableFuture<>(); |
2270 |
> |
g.completeExceptionally(new CFException()); |
2271 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2272 |
> |
checkIncomplete(h); |
2273 |
> |
f.complete(3); |
2274 |
> |
checkCompletedWithWrappedCFException(h); |
2275 |
|
|
2276 |
< |
f = new CompletableFuture<Integer>(); |
1893 |
< |
f2 = new CompletableFuture<Integer>(); |
1894 |
< |
g = f.thenCombineAsync(f2, add, new ThreadExecutor()); |
1895 |
< |
f.complete(one); |
1896 |
< |
f2.completeExceptionally(new CFException()); |
1897 |
< |
checkCompletedWithWrappedCFException(g); |
2276 |
> |
assertEquals(0, e.count.get()); |
2277 |
|
} |
2278 |
|
|
2279 |
|
/** |
2280 |
|
* thenCombineAsync result completes exceptionally if action does |
2281 |
|
*/ |
2282 |
|
public void testThenCombineAsync3E() { |
2283 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2284 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2283 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2284 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2285 |
|
FailingBiFunction r = new FailingBiFunction(); |
2286 |
|
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2287 |
|
f.complete(one); |
2288 |
|
checkIncomplete(g); |
2289 |
+ |
assertFalse(r.ran); |
2290 |
|
f2.complete(two); |
2291 |
|
checkCompletedWithWrappedCFException(g); |
2292 |
+ |
assertTrue(r.ran); |
2293 |
|
} |
2294 |
|
|
2295 |
|
/** |
2296 |
|
* thenCombineAsync result completes exceptionally if either source cancelled |
2297 |
|
*/ |
2298 |
|
public void testThenCombineAsync4E() { |
2299 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2300 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1920 |
< |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor()); |
1921 |
< |
assertTrue(f.cancel(true)); |
1922 |
< |
f2.complete(two); |
1923 |
< |
checkCompletedWithWrappedCancellationException(g); |
2299 |
> |
CompletableFuture<Integer> f, g, h; |
2300 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2301 |
|
|
2302 |
< |
f = new CompletableFuture<Integer>(); |
2303 |
< |
f2 = new CompletableFuture<Integer>(); |
2304 |
< |
g = f.thenCombineAsync(f2, add, new ThreadExecutor()); |
2305 |
< |
f.complete(one); |
2306 |
< |
assertTrue(f2.cancel(true)); |
2307 |
< |
checkCompletedWithWrappedCancellationException(g); |
2302 |
> |
f = new CompletableFuture<>(); |
2303 |
> |
g = new CompletableFuture<>(); |
2304 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2305 |
> |
assertTrue(f.cancel(true)); |
2306 |
> |
checkIncomplete(h); |
2307 |
> |
g.complete(1); |
2308 |
> |
checkCompletedWithWrappedCancellationException(h); |
2309 |
> |
|
2310 |
> |
f = new CompletableFuture<>(); |
2311 |
> |
g = new CompletableFuture<>(); |
2312 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2313 |
> |
assertTrue(g.cancel(true)); |
2314 |
> |
checkIncomplete(h); |
2315 |
> |
f.complete(3); |
2316 |
> |
checkCompletedWithWrappedCancellationException(h); |
2317 |
> |
|
2318 |
> |
f = new CompletableFuture<>(); |
2319 |
> |
g = new CompletableFuture<>(); |
2320 |
> |
assertTrue(g.cancel(true)); |
2321 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2322 |
> |
checkIncomplete(h); |
2323 |
> |
f.complete(3); |
2324 |
> |
checkCompletedWithWrappedCancellationException(h); |
2325 |
> |
|
2326 |
> |
f = new CompletableFuture<>(); |
2327 |
> |
g = new CompletableFuture<>(); |
2328 |
> |
assertTrue(f.cancel(true)); |
2329 |
> |
assertTrue(g.cancel(true)); |
2330 |
> |
h = f.thenCombineAsync(g, subtract, e); |
2331 |
> |
checkCompletedWithWrappedCancellationException(h); |
2332 |
> |
|
2333 |
> |
assertEquals(0, e.count.get()); |
2334 |
|
} |
2335 |
|
|
2336 |
|
/** |
2338 |
|
* completion of sources |
2339 |
|
*/ |
2340 |
|
public void testThenAcceptBothAsyncE() { |
2341 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2342 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2343 |
< |
AddAction r = new AddAction(); |
2344 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2345 |
< |
f.complete(one); |
2346 |
< |
checkIncomplete(g); |
2347 |
< |
f2.complete(two); |
2348 |
< |
checkCompletedNormally(g, null); |
2349 |
< |
assertEquals(r.value, 3); |
2341 |
> |
CompletableFuture<Integer> f, g; |
2342 |
> |
CompletableFuture<Void> h; |
2343 |
> |
SubtractAction r; |
2344 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2345 |
> |
|
2346 |
> |
f = new CompletableFuture<>(); |
2347 |
> |
g = new CompletableFuture<>(); |
2348 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2349 |
> |
f.complete(3); |
2350 |
> |
checkIncomplete(h); |
2351 |
> |
g.complete(1); |
2352 |
> |
checkCompletedNormally(h, null); |
2353 |
> |
assertEquals(r.value, 2); |
2354 |
> |
|
2355 |
> |
f = new CompletableFuture<>(); |
2356 |
> |
g = new CompletableFuture<>(); |
2357 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2358 |
> |
g.complete(1); |
2359 |
> |
checkIncomplete(h); |
2360 |
> |
f.complete(3); |
2361 |
> |
checkCompletedNormally(h, null); |
2362 |
> |
assertEquals(r.value, 2); |
2363 |
> |
|
2364 |
> |
f = new CompletableFuture<>(); |
2365 |
> |
g = new CompletableFuture<>(); |
2366 |
> |
g.complete(1); |
2367 |
> |
f.complete(3); |
2368 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2369 |
> |
checkCompletedNormally(h, null); |
2370 |
> |
assertEquals(r.value, 2); |
2371 |
> |
|
2372 |
> |
assertEquals(3, e.count.get()); |
2373 |
|
} |
2374 |
|
|
2375 |
|
/** |
2377 |
|
* completion of source |
2378 |
|
*/ |
2379 |
|
public void testThenAcceptBothAsync2E() { |
2380 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2381 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2382 |
< |
AddAction r = new AddAction(); |
2383 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2384 |
< |
f.completeExceptionally(new CFException()); |
2385 |
< |
f2.complete(two); |
2386 |
< |
checkCompletedWithWrappedCFException(g); |
2380 |
> |
CompletableFuture<Integer> f, g; |
2381 |
> |
CompletableFuture<Void> h; |
2382 |
> |
SubtractAction r; |
2383 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2384 |
> |
|
2385 |
> |
f = new CompletableFuture<>(); |
2386 |
> |
g = new CompletableFuture<>(); |
2387 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2388 |
> |
f.completeExceptionally(new CFException()); |
2389 |
> |
checkIncomplete(h); |
2390 |
> |
g.complete(1); |
2391 |
> |
checkCompletedWithWrappedCFException(h); |
2392 |
> |
|
2393 |
> |
f = new CompletableFuture<>(); |
2394 |
> |
g = new CompletableFuture<>(); |
2395 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2396 |
> |
g.completeExceptionally(new CFException()); |
2397 |
> |
checkIncomplete(h); |
2398 |
> |
f.complete(3); |
2399 |
> |
checkCompletedWithWrappedCFException(h); |
2400 |
> |
|
2401 |
> |
f = new CompletableFuture<>(); |
2402 |
> |
g = new CompletableFuture<>(); |
2403 |
> |
f.complete(3); |
2404 |
> |
g.completeExceptionally(new CFException()); |
2405 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2406 |
> |
checkCompletedWithWrappedCFException(h); |
2407 |
> |
|
2408 |
> |
f = new CompletableFuture<>(); |
2409 |
> |
g = new CompletableFuture<>(); |
2410 |
> |
f.completeExceptionally(new CFException()); |
2411 |
> |
g.complete(3); |
2412 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2413 |
> |
checkCompletedWithWrappedCFException(h); |
2414 |
|
|
2415 |
< |
r = new AddAction(); |
1963 |
< |
f = new CompletableFuture<Integer>(); |
1964 |
< |
f2 = new CompletableFuture<Integer>(); |
1965 |
< |
g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
1966 |
< |
f.complete(one); |
1967 |
< |
f2.completeExceptionally(new CFException()); |
1968 |
< |
checkCompletedWithWrappedCFException(g); |
2415 |
> |
assertEquals(0, e.count.get()); |
2416 |
|
} |
2417 |
|
|
2418 |
|
/** |
2419 |
|
* thenAcceptBothAsync result completes exceptionally if action does |
2420 |
|
*/ |
2421 |
|
public void testThenAcceptBothAsync3E() { |
2422 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2423 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2424 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
2425 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2426 |
< |
f.complete(one); |
2427 |
< |
checkIncomplete(g); |
2428 |
< |
f2.complete(two); |
2429 |
< |
checkCompletedWithWrappedCFException(g); |
2422 |
> |
CompletableFuture<Integer> f, g; |
2423 |
> |
CompletableFuture<Void> h; |
2424 |
> |
FailingBiConsumer r; |
2425 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2426 |
> |
|
2427 |
> |
f = new CompletableFuture<>(); |
2428 |
> |
g = new CompletableFuture<>(); |
2429 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2430 |
> |
f.complete(3); |
2431 |
> |
checkIncomplete(h); |
2432 |
> |
g.complete(1); |
2433 |
> |
checkCompletedWithWrappedCFException(h); |
2434 |
> |
|
2435 |
> |
f = new CompletableFuture<>(); |
2436 |
> |
g = new CompletableFuture<>(); |
2437 |
> |
f.complete(3); |
2438 |
> |
g.complete(1); |
2439 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2440 |
> |
checkCompletedWithWrappedCFException(h); |
2441 |
> |
|
2442 |
> |
assertEquals(2, e.count.get()); |
2443 |
|
} |
2444 |
|
|
2445 |
|
/** |
2446 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2447 |
|
*/ |
2448 |
|
public void testThenAcceptBothAsync4E() { |
2449 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2450 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2451 |
< |
AddAction r = new AddAction(); |
2452 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2453 |
< |
assertTrue(f.cancel(true)); |
2454 |
< |
f2.complete(two); |
2455 |
< |
checkCompletedWithWrappedCancellationException(g); |
2449 |
> |
CompletableFuture<Integer> f, g; |
2450 |
> |
CompletableFuture<Void> h; |
2451 |
> |
SubtractAction r; |
2452 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2453 |
> |
|
2454 |
> |
f = new CompletableFuture<>(); |
2455 |
> |
g = new CompletableFuture<>(); |
2456 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2457 |
> |
assertTrue(f.cancel(true)); |
2458 |
> |
checkIncomplete(h); |
2459 |
> |
g.complete(1); |
2460 |
> |
checkCompletedWithWrappedCancellationException(h); |
2461 |
> |
|
2462 |
> |
f = new CompletableFuture<>(); |
2463 |
> |
g = new CompletableFuture<>(); |
2464 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2465 |
> |
assertTrue(g.cancel(true)); |
2466 |
> |
checkIncomplete(h); |
2467 |
> |
f.complete(3); |
2468 |
> |
checkCompletedWithWrappedCancellationException(h); |
2469 |
> |
|
2470 |
> |
f = new CompletableFuture<>(); |
2471 |
> |
g = new CompletableFuture<>(); |
2472 |
> |
f.complete(3); |
2473 |
> |
assertTrue(g.cancel(true)); |
2474 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2475 |
> |
checkCompletedWithWrappedCancellationException(h); |
2476 |
> |
|
2477 |
> |
f = new CompletableFuture<>(); |
2478 |
> |
g = new CompletableFuture<>(); |
2479 |
> |
assertTrue(f.cancel(true)); |
2480 |
> |
g.complete(3); |
2481 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2482 |
> |
checkCompletedWithWrappedCancellationException(h); |
2483 |
|
|
2484 |
< |
r = new AddAction(); |
1998 |
< |
f = new CompletableFuture<Integer>(); |
1999 |
< |
f2 = new CompletableFuture<Integer>(); |
2000 |
< |
g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2001 |
< |
f.complete(one); |
2002 |
< |
assertTrue(f2.cancel(true)); |
2003 |
< |
checkCompletedWithWrappedCancellationException(g); |
2484 |
> |
assertEquals(0, e.count.get()); |
2485 |
|
} |
2486 |
|
|
2487 |
|
/** |
2489 |
|
* completion of sources |
2490 |
|
*/ |
2491 |
|
public void testRunAfterBothAsyncE() { |
2492 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2493 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2492 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2493 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2494 |
|
Noop r = new Noop(); |
2495 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2496 |
|
f.complete(one); |
2505 |
|
* completion of source |
2506 |
|
*/ |
2507 |
|
public void testRunAfterBothAsync2E() { |
2508 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2509 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2508 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2509 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2510 |
|
Noop r = new Noop(); |
2511 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2512 |
|
f.completeExceptionally(new CFException()); |
2514 |
|
checkCompletedWithWrappedCFException(g); |
2515 |
|
|
2516 |
|
r = new Noop(); |
2517 |
< |
f = new CompletableFuture<Integer>(); |
2518 |
< |
f2 = new CompletableFuture<Integer>(); |
2517 |
> |
f = new CompletableFuture<>(); |
2518 |
> |
f2 = new CompletableFuture<>(); |
2519 |
|
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2520 |
|
f.complete(one); |
2521 |
|
f2.completeExceptionally(new CFException()); |
2526 |
|
* runAfterBothAsync result completes exceptionally if action does |
2527 |
|
*/ |
2528 |
|
public void testRunAfterBothAsync3E() { |
2529 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2530 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2529 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2530 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2531 |
|
FailingNoop r = new FailingNoop(); |
2532 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2533 |
|
f.complete(one); |
2540 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
2541 |
|
*/ |
2542 |
|
public void testRunAfterBothAsync4E() { |
2543 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2544 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2543 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2544 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2545 |
|
Noop r = new Noop(); |
2546 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2547 |
|
assertTrue(f.cancel(true)); |
2549 |
|
checkCompletedWithWrappedCancellationException(g); |
2550 |
|
|
2551 |
|
r = new Noop(); |
2552 |
< |
f = new CompletableFuture<Integer>(); |
2553 |
< |
f2 = new CompletableFuture<Integer>(); |
2552 |
> |
f = new CompletableFuture<>(); |
2553 |
> |
f2 = new CompletableFuture<>(); |
2554 |
|
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2555 |
|
f.complete(one); |
2556 |
|
assertTrue(f2.cancel(true)); |
2562 |
|
* completion of sources |
2563 |
|
*/ |
2564 |
|
public void testApplyToEitherAsyncE() { |
2565 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2566 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2565 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2566 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2567 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2568 |
|
f.complete(one); |
2569 |
|
checkCompletedNormally(g, two); |
2570 |
|
|
2571 |
< |
f = new CompletableFuture<Integer>(); |
2571 |
> |
f = new CompletableFuture<>(); |
2572 |
|
f.complete(one); |
2573 |
< |
f2 = new CompletableFuture<Integer>(); |
2573 |
> |
f2 = new CompletableFuture<>(); |
2574 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2575 |
|
checkCompletedNormally(g, two); |
2576 |
|
} |
2580 |
|
* completion of source |
2581 |
|
*/ |
2582 |
|
public void testApplyToEitherAsync2E() { |
2583 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2584 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2583 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2584 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2585 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2586 |
|
f.completeExceptionally(new CFException()); |
2587 |
|
checkCompletedWithWrappedCFException(g); |
2588 |
|
|
2589 |
< |
f = new CompletableFuture<Integer>(); |
2590 |
< |
f2 = new CompletableFuture<Integer>(); |
2589 |
> |
f = new CompletableFuture<>(); |
2590 |
> |
f2 = new CompletableFuture<>(); |
2591 |
|
f2.completeExceptionally(new CFException()); |
2592 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2593 |
|
f.complete(one); |
2598 |
|
* applyToEitherAsync result completes exceptionally if action does |
2599 |
|
*/ |
2600 |
|
public void testApplyToEitherAsync3E() { |
2601 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2602 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2601 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2602 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2603 |
|
FailingFunction r = new FailingFunction(); |
2604 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); |
2605 |
|
f.complete(one); |
2610 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
2611 |
|
*/ |
2612 |
|
public void testApplyToEitherAsync4E() { |
2613 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2614 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2613 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2614 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2615 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2616 |
|
assertTrue(f.cancel(true)); |
2617 |
|
checkCompletedWithWrappedCancellationException(g); |
2618 |
|
|
2619 |
< |
f = new CompletableFuture<Integer>(); |
2620 |
< |
f2 = new CompletableFuture<Integer>(); |
2619 |
> |
f = new CompletableFuture<>(); |
2620 |
> |
f2 = new CompletableFuture<>(); |
2621 |
|
assertTrue(f2.cancel(true)); |
2622 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2623 |
|
checkCompletedWithWrappedCancellationException(g); |
2628 |
|
* completion of sources |
2629 |
|
*/ |
2630 |
|
public void testAcceptEitherAsyncE() { |
2631 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2632 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2631 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2632 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2633 |
|
IncAction r = new IncAction(); |
2634 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2635 |
|
f.complete(one); |
2637 |
|
assertEquals(r.value, 2); |
2638 |
|
|
2639 |
|
r = new IncAction(); |
2640 |
< |
f = new CompletableFuture<Integer>(); |
2640 |
> |
f = new CompletableFuture<>(); |
2641 |
|
f.complete(one); |
2642 |
< |
f2 = new CompletableFuture<Integer>(); |
2642 |
> |
f2 = new CompletableFuture<>(); |
2643 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2644 |
|
checkCompletedNormally(g, null); |
2645 |
|
assertEquals(r.value, 2); |
2650 |
|
* completion of source |
2651 |
|
*/ |
2652 |
|
public void testAcceptEitherAsync2E() { |
2653 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2654 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2653 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2654 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2655 |
|
IncAction r = new IncAction(); |
2656 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2657 |
|
f.completeExceptionally(new CFException()); |
2658 |
|
checkCompletedWithWrappedCFException(g); |
2659 |
|
|
2660 |
|
r = new IncAction(); |
2661 |
< |
f = new CompletableFuture<Integer>(); |
2662 |
< |
f2 = new CompletableFuture<Integer>(); |
2661 |
> |
f = new CompletableFuture<>(); |
2662 |
> |
f2 = new CompletableFuture<>(); |
2663 |
|
f2.completeExceptionally(new CFException()); |
2664 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2665 |
|
f.complete(one); |
2670 |
|
* acceptEitherAsync result completes exceptionally if action does |
2671 |
|
*/ |
2672 |
|
public void testAcceptEitherAsync3E() { |
2673 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2674 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2673 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2674 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2675 |
|
FailingConsumer r = new FailingConsumer(); |
2676 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2677 |
|
f.complete(one); |
2683 |
|
* source cancelled |
2684 |
|
*/ |
2685 |
|
public void testAcceptEitherAsync4E() { |
2686 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2687 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2686 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2687 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2688 |
|
IncAction r = new IncAction(); |
2689 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2690 |
|
assertTrue(f.cancel(true)); |
2691 |
|
checkCompletedWithWrappedCancellationException(g); |
2692 |
|
|
2693 |
|
r = new IncAction(); |
2694 |
< |
f = new CompletableFuture<Integer>(); |
2695 |
< |
f2 = new CompletableFuture<Integer>(); |
2694 |
> |
f = new CompletableFuture<>(); |
2695 |
> |
f2 = new CompletableFuture<>(); |
2696 |
|
assertTrue(f2.cancel(true)); |
2697 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2698 |
|
checkCompletedWithWrappedCancellationException(g); |
2703 |
|
* completion of sources |
2704 |
|
*/ |
2705 |
|
public void testRunAfterEitherAsyncE() { |
2706 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2707 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2706 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2707 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2708 |
|
Noop r = new Noop(); |
2709 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2710 |
|
f.complete(one); |
2712 |
|
assertTrue(r.ran); |
2713 |
|
|
2714 |
|
r = new Noop(); |
2715 |
< |
f = new CompletableFuture<Integer>(); |
2715 |
> |
f = new CompletableFuture<>(); |
2716 |
|
f.complete(one); |
2717 |
< |
f2 = new CompletableFuture<Integer>(); |
2717 |
> |
f2 = new CompletableFuture<>(); |
2718 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2719 |
|
checkCompletedNormally(g, null); |
2720 |
|
assertTrue(r.ran); |
2725 |
|
* completion of source |
2726 |
|
*/ |
2727 |
|
public void testRunAfterEitherAsync2E() { |
2728 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2729 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2728 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2729 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2730 |
|
Noop r = new Noop(); |
2731 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2732 |
|
f.completeExceptionally(new CFException()); |
2733 |
|
checkCompletedWithWrappedCFException(g); |
2734 |
|
|
2735 |
|
r = new Noop(); |
2736 |
< |
f = new CompletableFuture<Integer>(); |
2737 |
< |
f2 = new CompletableFuture<Integer>(); |
2736 |
> |
f = new CompletableFuture<>(); |
2737 |
> |
f2 = new CompletableFuture<>(); |
2738 |
|
f2.completeExceptionally(new CFException()); |
2739 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2740 |
|
f.complete(one); |
2745 |
|
* runAfterEitherAsync result completes exceptionally if action does |
2746 |
|
*/ |
2747 |
|
public void testRunAfterEitherAsync3E() { |
2748 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2749 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2748 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2749 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2750 |
|
FailingNoop r = new FailingNoop(); |
2751 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2752 |
|
f.complete(one); |
2758 |
|
* source cancelled |
2759 |
|
*/ |
2760 |
|
public void testRunAfterEitherAsync4E() { |
2761 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2762 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2761 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2762 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2763 |
|
Noop r = new Noop(); |
2764 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2765 |
|
assertTrue(f.cancel(true)); |
2766 |
|
checkCompletedWithWrappedCancellationException(g); |
2767 |
|
|
2768 |
|
r = new Noop(); |
2769 |
< |
f = new CompletableFuture<Integer>(); |
2770 |
< |
f2 = new CompletableFuture<Integer>(); |
2769 |
> |
f = new CompletableFuture<>(); |
2770 |
> |
f2 = new CompletableFuture<>(); |
2771 |
|
assertTrue(f2.cancel(true)); |
2772 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2773 |
|
checkCompletedWithWrappedCancellationException(g); |
2774 |
|
} |
2775 |
|
|
2776 |
|
/** |
2777 |
< |
* thenCompse result completes normally after normal completion of source |
2777 |
> |
* thenComposeAsync result completes normally after normal |
2778 |
> |
* completion of source |
2779 |
|
*/ |
2780 |
|
public void testThenComposeAsyncE() { |
2781 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2781 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2782 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
2783 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2784 |
|
f.complete(one); |
2786 |
|
} |
2787 |
|
|
2788 |
|
/** |
2789 |
< |
* thenComposeAsync result completes exceptionally after exceptional |
2790 |
< |
* completion of source |
2789 |
> |
* thenComposeAsync result completes exceptionally after |
2790 |
> |
* exceptional completion of source |
2791 |
|
*/ |
2792 |
|
public void testThenComposeAsync2E() { |
2793 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2793 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2794 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
2795 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2796 |
|
f.completeExceptionally(new CFException()); |
2801 |
|
* thenComposeAsync result completes exceptionally if action does |
2802 |
|
*/ |
2803 |
|
public void testThenComposeAsync3E() { |
2804 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2804 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2805 |
|
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
2806 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2807 |
|
f.complete(one); |
2812 |
|
* thenComposeAsync result completes exceptionally if source cancelled |
2813 |
|
*/ |
2814 |
|
public void testThenComposeAsync4E() { |
2815 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2815 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2816 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
2817 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2818 |
|
assertTrue(f.cancel(true)); |
2835 |
|
*/ |
2836 |
|
public void testAllOf() throws Exception { |
2837 |
|
for (int k = 1; k < 20; ++k) { |
2838 |
< |
CompletableFuture[] fs = new CompletableFuture[k]; |
2838 |
> |
CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
2839 |
|
for (int i = 0; i < k; ++i) |
2840 |
< |
fs[i] = new CompletableFuture<Integer>(); |
2841 |
< |
CompletableFuture<?> f = CompletableFuture.allOf(fs); |
2840 |
> |
fs[i] = new CompletableFuture<>(); |
2841 |
> |
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
2842 |
|
for (int i = 0; i < k; ++i) { |
2843 |
|
checkIncomplete(f); |
2844 |
|
fs[i].complete(one); |
2845 |
|
} |
2846 |
< |
assertTrue(f.isDone()); |
2365 |
< |
assertFalse(f.isCancelled()); |
2846 |
> |
checkCompletedNormally(f, null); |
2847 |
|
} |
2848 |
|
} |
2849 |
|
|
2856 |
|
} |
2857 |
|
|
2858 |
|
/** |
2859 |
< |
* allOf returns a future completed when any components complete |
2859 |
> |
* anyOf returns a future completed when any components complete |
2860 |
|
*/ |
2861 |
|
public void testAnyOf() throws Exception { |
2862 |
|
for (int k = 1; k < 20; ++k) { |
2863 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
2864 |
|
for (int i = 0; i < k; ++i) |
2865 |
< |
fs[i] = new CompletableFuture<Integer>(); |
2866 |
< |
CompletableFuture<?> f = CompletableFuture.anyOf(fs); |
2865 |
> |
fs[i] = new CompletableFuture<>(); |
2866 |
> |
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
2867 |
|
checkIncomplete(f); |
2868 |
|
for (int i = 0; i < k; ++i) { |
2869 |
|
fs[i].complete(one); |
2870 |
< |
assertTrue(f.isDone()); |
2870 |
> |
checkCompletedNormally(f, one); |
2871 |
|
} |
2872 |
|
} |
2873 |
|
} |
2876 |
|
* Completion methods throw NullPointerException with null arguments |
2877 |
|
*/ |
2878 |
|
public void testNPE() { |
2879 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2880 |
< |
CompletableFuture<Integer> g = new CompletableFuture<Integer>(); |
2881 |
< |
CompletableFuture h; |
2882 |
< |
try { h = f.thenApply(null); } catch (NullPointerException ok) {} |
2883 |
< |
try { h = f.thenAccept(null); } catch (NullPointerException ok) {} |
2884 |
< |
try { h = f.thenRun(null); } catch (NullPointerException ok) {} |
2885 |
< |
try { h = f.thenCombine(g, null); } catch (NullPointerException ok) {} |
2886 |
< |
try { h = f.thenCombine(null, null); } catch (NullPointerException ok) {} |
2887 |
< |
try { h = f.applyToEither(g, null); } catch (NullPointerException ok) {} |
2888 |
< |
try { h = f.applyToEither(null, null); } catch (NullPointerException ok) {} |
2889 |
< |
try { h = f.thenAcceptBoth(g, null); } catch (NullPointerException ok) {} |
2890 |
< |
try { h = f.thenAcceptBoth(null, null); } catch (NullPointerException ok) {} |
2891 |
< |
try { h = f.runAfterEither(g, null); } catch (NullPointerException ok) {} |
2892 |
< |
try { h = f.runAfterEither(null, null); } catch (NullPointerException ok) {} |
2893 |
< |
try { h = f.runAfterBoth(g, null); } catch (NullPointerException ok) {} |
2894 |
< |
try { h = f.runAfterBoth(null, null); } catch (NullPointerException ok) {} |
2895 |
< |
try { h = f.exceptionally(null); } catch (NullPointerException ok) {} |
2896 |
< |
try { h = f.handle(null); } catch (NullPointerException ok) {} |
2897 |
< |
try { h = f.thenCompose(null); } catch (NullPointerException ok) {} |
2898 |
< |
|
2899 |
< |
try { h = f.thenApplyAsync(null); } catch (NullPointerException ok) {} |
2900 |
< |
try { h = f.thenAcceptAsync(null); } catch (NullPointerException ok) {} |
2901 |
< |
try { h = f.thenRunAsync(null); } catch (NullPointerException ok) {} |
2902 |
< |
try { h = f.thenCombineAsync(g, null); } catch (NullPointerException ok) {} |
2903 |
< |
try { h = f.thenCombineAsync(null, null); } catch (NullPointerException ok) {} |
2904 |
< |
try { h = f.applyToEitherAsync(g, null); } catch (NullPointerException ok) {} |
2905 |
< |
try { h = f.applyToEitherAsync(null, null); } catch (NullPointerException ok) {} |
2906 |
< |
try { h = f.thenAcceptBothAsync(g, null); } catch (NullPointerException ok) {} |
2907 |
< |
try { h = f.thenAcceptBothAsync(null, null); } catch (NullPointerException ok) {} |
2908 |
< |
try { h = f.runAfterEitherAsync(g, null); } catch (NullPointerException ok) {} |
2909 |
< |
try { h = f.runAfterEitherAsync(null, null); } catch (NullPointerException ok) {} |
2910 |
< |
try { h = f.runAfterBothAsync(g, null); } catch (NullPointerException ok) {} |
2911 |
< |
try { h = f.runAfterBothAsync(null, null); } catch (NullPointerException ok) {} |
2879 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2880 |
> |
CompletableFuture<Integer> g = new CompletableFuture<>(); |
2881 |
> |
CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null; |
2882 |
> |
CompletableFuture<?> h; |
2883 |
> |
ThreadExecutor exec = new ThreadExecutor(); |
2884 |
> |
|
2885 |
> |
Runnable[] throwingActions = { |
2886 |
> |
() -> { CompletableFuture.supplyAsync(null); }, |
2887 |
> |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
2888 |
> |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
2889 |
> |
|
2890 |
> |
() -> { CompletableFuture.runAsync(null); }, |
2891 |
> |
() -> { CompletableFuture.runAsync(null, exec); }, |
2892 |
> |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
2893 |
> |
|
2894 |
> |
() -> { f.completeExceptionally(null); }, |
2895 |
> |
|
2896 |
> |
() -> { f.thenApply(null); }, |
2897 |
> |
() -> { f.thenApplyAsync(null); }, |
2898 |
> |
() -> { f.thenApplyAsync((x) -> x, null); }, |
2899 |
> |
() -> { f.thenApplyAsync(null, exec); }, |
2900 |
> |
|
2901 |
> |
() -> { f.thenAccept(null); }, |
2902 |
> |
() -> { f.thenAcceptAsync(null); }, |
2903 |
> |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
2904 |
> |
() -> { f.thenAcceptAsync(null, exec); }, |
2905 |
> |
|
2906 |
> |
() -> { f.thenRun(null); }, |
2907 |
> |
() -> { f.thenRunAsync(null); }, |
2908 |
> |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
2909 |
> |
() -> { f.thenRunAsync(null, exec); }, |
2910 |
> |
|
2911 |
> |
() -> { f.thenCombine(g, null); }, |
2912 |
> |
() -> { f.thenCombineAsync(g, null); }, |
2913 |
> |
() -> { f.thenCombineAsync(g, null, exec); }, |
2914 |
> |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
2915 |
> |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
2916 |
> |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
2917 |
> |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
2918 |
> |
|
2919 |
> |
() -> { f.thenAcceptBoth(g, null); }, |
2920 |
> |
() -> { f.thenAcceptBothAsync(g, null); }, |
2921 |
> |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
2922 |
> |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
2923 |
> |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
2924 |
> |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
2925 |
> |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
2926 |
> |
|
2927 |
> |
() -> { f.runAfterBoth(g, null); }, |
2928 |
> |
() -> { f.runAfterBothAsync(g, null); }, |
2929 |
> |
() -> { f.runAfterBothAsync(g, null, exec); }, |
2930 |
> |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
2931 |
> |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
2932 |
> |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
2933 |
> |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
2934 |
> |
|
2935 |
> |
() -> { f.applyToEither(g, null); }, |
2936 |
> |
() -> { f.applyToEitherAsync(g, null); }, |
2937 |
> |
() -> { f.applyToEitherAsync(g, null, exec); }, |
2938 |
> |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
2939 |
> |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
2940 |
> |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
2941 |
> |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
2942 |
> |
|
2943 |
> |
() -> { f.acceptEither(g, null); }, |
2944 |
> |
() -> { f.acceptEitherAsync(g, null); }, |
2945 |
> |
() -> { f.acceptEitherAsync(g, null, exec); }, |
2946 |
> |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
2947 |
> |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
2948 |
> |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
2949 |
> |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
2950 |
> |
|
2951 |
> |
() -> { f.runAfterEither(g, null); }, |
2952 |
> |
() -> { f.runAfterEitherAsync(g, null); }, |
2953 |
> |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
2954 |
> |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
2955 |
> |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
2956 |
> |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
2957 |
> |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
2958 |
> |
|
2959 |
> |
() -> { f.thenCompose(null); }, |
2960 |
> |
() -> { f.thenComposeAsync(null); }, |
2961 |
> |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
2962 |
> |
() -> { f.thenComposeAsync(null, exec); }, |
2963 |
> |
|
2964 |
> |
() -> { f.exceptionally(null); }, |
2965 |
> |
|
2966 |
> |
() -> { f.handle(null); }, |
2967 |
> |
|
2968 |
> |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
2969 |
> |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
2970 |
> |
() -> { CompletableFuture.allOf(f, null); }, |
2971 |
> |
() -> { CompletableFuture.allOf(null, f); }, |
2972 |
> |
|
2973 |
> |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
2974 |
> |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
2975 |
> |
() -> { CompletableFuture.anyOf(f, null); }, |
2976 |
> |
() -> { CompletableFuture.anyOf(null, f); }, |
2977 |
> |
}; |
2978 |
|
|
2979 |
+ |
assertThrows(NullPointerException.class, throwingActions); |
2980 |
+ |
assertEquals(0, exec.count.get()); |
2981 |
|
} |
2982 |
|
|
2434 |
– |
|
2983 |
|
} |