55 |
|
|
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); } |
63 |
|
try { |
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 |
+ |
assertFalse(f.isCompletedExceptionally()); |
72 |
|
assertTrue(f.toString().contains("[Completed normally]")); |
73 |
|
} |
74 |
|
|
75 |
|
void checkCompletedWithWrappedCFException(CompletableFuture<?> f) { |
76 |
|
try { |
77 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
78 |
+ |
shouldThrow(); |
79 |
+ |
} catch (ExecutionException success) { |
80 |
+ |
assertTrue(success.getCause() instanceof CFException); |
81 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
82 |
+ |
try { |
83 |
|
f.join(); |
84 |
|
shouldThrow(); |
85 |
|
} catch (CompletionException success) { |
97 |
|
} catch (ExecutionException success) { |
98 |
|
assertTrue(success.getCause() instanceof CFException); |
99 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
100 |
+ |
assertTrue(f.isDone()); |
101 |
+ |
assertFalse(f.isCancelled()); |
102 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
103 |
+ |
} |
104 |
+ |
|
105 |
+ |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
106 |
+ |
CFException ex) { |
107 |
|
try { |
108 |
< |
f.get(0L, SECONDS); |
108 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
109 |
|
shouldThrow(); |
110 |
|
} catch (ExecutionException success) { |
111 |
< |
assertTrue(success.getCause() instanceof CFException); |
111 |
> |
assertSame(ex, success.getCause()); |
112 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
113 |
> |
try { |
114 |
> |
f.join(); |
115 |
> |
shouldThrow(); |
116 |
> |
} catch (CompletionException success) { |
117 |
> |
assertSame(ex, success.getCause()); |
118 |
> |
} |
119 |
> |
try { |
120 |
> |
f.getNow(null); |
121 |
> |
shouldThrow(); |
122 |
> |
} catch (CompletionException success) { |
123 |
> |
assertSame(ex, success.getCause()); |
124 |
> |
} |
125 |
> |
try { |
126 |
> |
f.get(); |
127 |
> |
shouldThrow(); |
128 |
> |
} catch (ExecutionException success) { |
129 |
> |
assertSame(ex, success.getCause()); |
130 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
131 |
|
assertTrue(f.isDone()); |
132 |
|
assertFalse(f.isCancelled()); |
135 |
|
|
136 |
|
void checkCancelled(CompletableFuture<?> f) { |
137 |
|
try { |
138 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
139 |
+ |
shouldThrow(); |
140 |
+ |
} catch (CancellationException success) { |
141 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
142 |
+ |
try { |
143 |
|
f.join(); |
144 |
|
shouldThrow(); |
145 |
|
} catch (CancellationException success) {} |
152 |
|
shouldThrow(); |
153 |
|
} catch (CancellationException success) { |
154 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
118 |
– |
try { |
119 |
– |
f.get(0L, SECONDS); |
120 |
– |
shouldThrow(); |
121 |
– |
} catch (CancellationException success) { |
122 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
155 |
|
assertTrue(f.isDone()); |
156 |
+ |
assertTrue(f.isCompletedExceptionally()); |
157 |
|
assertTrue(f.isCancelled()); |
158 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
159 |
|
} |
160 |
|
|
161 |
|
void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) { |
162 |
|
try { |
163 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
164 |
+ |
shouldThrow(); |
165 |
+ |
} catch (ExecutionException success) { |
166 |
+ |
assertTrue(success.getCause() instanceof CancellationException); |
167 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
168 |
+ |
try { |
169 |
|
f.join(); |
170 |
|
shouldThrow(); |
171 |
|
} catch (CompletionException success) { |
183 |
|
} catch (ExecutionException success) { |
184 |
|
assertTrue(success.getCause() instanceof CancellationException); |
185 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
147 |
– |
try { |
148 |
– |
f.get(0L, SECONDS); |
149 |
– |
shouldThrow(); |
150 |
– |
} catch (ExecutionException success) { |
151 |
– |
assertTrue(success.getCause() instanceof CancellationException); |
152 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
186 |
|
assertTrue(f.isDone()); |
187 |
|
assertFalse(f.isCancelled()); |
188 |
+ |
assertTrue(f.isCompletedExceptionally()); |
189 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
190 |
|
} |
191 |
|
|
194 |
|
* by methods isDone, isCancelled, and getNow |
195 |
|
*/ |
196 |
|
public void testConstructor() { |
197 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
197 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
198 |
|
checkIncomplete(f); |
199 |
|
} |
200 |
|
|
203 |
|
* isCancelled, join, get, and getNow |
204 |
|
*/ |
205 |
|
public void testComplete() { |
206 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
206 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
207 |
|
checkIncomplete(f); |
208 |
|
f.complete(one); |
209 |
|
checkCompletedNormally(f, one); |
214 |
|
* methods isDone, isCancelled, join, get, and getNow |
215 |
|
*/ |
216 |
|
public void testCompleteExceptionally() { |
217 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
217 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
218 |
|
checkIncomplete(f); |
219 |
|
f.completeExceptionally(new CFException()); |
220 |
|
checkCompletedWithWrappedCFException(f); |
225 |
|
* methods isDone, isCancelled, join, get, and getNow |
226 |
|
*/ |
227 |
|
public void testCancel() { |
228 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
228 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
229 |
|
checkIncomplete(f); |
230 |
|
assertTrue(f.cancel(true)); |
231 |
|
checkCancelled(f); |
235 |
|
* obtrudeValue forces completion with given value |
236 |
|
*/ |
237 |
|
public void testObtrudeValue() { |
238 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
238 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
239 |
|
checkIncomplete(f); |
240 |
|
f.complete(one); |
241 |
|
checkCompletedNormally(f, one); |
243 |
|
checkCompletedNormally(f, three); |
244 |
|
f.obtrudeValue(two); |
245 |
|
checkCompletedNormally(f, two); |
246 |
< |
f = new CompletableFuture<Integer>(); |
246 |
> |
f = new CompletableFuture<>(); |
247 |
|
f.obtrudeValue(three); |
248 |
|
checkCompletedNormally(f, three); |
249 |
< |
f = new CompletableFuture<Integer>(); |
249 |
> |
f = new CompletableFuture<>(); |
250 |
|
f.completeExceptionally(new CFException()); |
251 |
|
f.obtrudeValue(four); |
252 |
|
checkCompletedNormally(f, four); |
256 |
|
* obtrudeException forces completion with given exception |
257 |
|
*/ |
258 |
|
public void testObtrudeException() { |
259 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
259 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
260 |
|
checkIncomplete(f); |
261 |
|
f.complete(one); |
262 |
|
checkCompletedNormally(f, one); |
263 |
|
f.obtrudeException(new CFException()); |
264 |
|
checkCompletedWithWrappedCFException(f); |
265 |
< |
f = new CompletableFuture<Integer>(); |
265 |
> |
f = new CompletableFuture<>(); |
266 |
|
f.obtrudeException(new CFException()); |
267 |
|
checkCompletedWithWrappedCFException(f); |
268 |
< |
f = new CompletableFuture<Integer>(); |
268 |
> |
f = new CompletableFuture<>(); |
269 |
|
f.completeExceptionally(new CFException()); |
270 |
|
f.obtrudeValue(four); |
271 |
|
checkCompletedNormally(f, four); |
277 |
|
* getNumberOfDependents returns number of dependent tasks |
278 |
|
*/ |
279 |
|
public void testGetNumberOfDependents() { |
280 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
280 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
281 |
|
assertEquals(f.getNumberOfDependents(), 0); |
282 |
|
CompletableFuture g = f.thenRun(new Noop()); |
283 |
|
assertEquals(f.getNumberOfDependents(), 1); |
290 |
|
assertEquals(g.getNumberOfDependents(), 0); |
291 |
|
} |
292 |
|
|
259 |
– |
|
293 |
|
/** |
294 |
|
* toString indicates current completion state |
295 |
|
*/ |
327 |
|
int value; |
328 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
329 |
|
} |
330 |
< |
static final class AddAction implements BiConsumer<Integer, Integer> { |
330 |
> |
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
331 |
|
int value; |
332 |
|
public void accept(Integer x, Integer y) { |
333 |
< |
value = x.intValue() + y.intValue(); |
333 |
> |
value = x.intValue() - y.intValue(); |
334 |
|
} |
335 |
|
} |
336 |
|
static final class Noop implements Runnable { |
365 |
|
|
366 |
|
static final class CompletableFutureInc |
367 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
368 |
+ |
boolean ran; |
369 |
|
public CompletableFuture<Integer> apply(Integer x) { |
370 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
370 |
> |
ran = true; |
371 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
372 |
|
f.complete(Integer.valueOf(x.intValue() + 1)); |
373 |
|
return f; |
374 |
|
} |
404 |
|
} |
405 |
|
} |
406 |
|
|
372 |
– |
|
407 |
|
/** |
408 |
|
* exceptionally action completes with function value on source |
409 |
< |
* exception; otherwise with source value |
409 |
> |
* exception; otherwise with source value |
410 |
|
*/ |
411 |
|
public void testExceptionally() { |
412 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
412 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
413 |
|
ExceptionToInteger r = new ExceptionToInteger(); |
414 |
|
CompletableFuture<Integer> g = f.exceptionally(r); |
415 |
|
f.completeExceptionally(new CFException()); |
416 |
|
checkCompletedNormally(g, three); |
417 |
|
|
418 |
< |
f = new CompletableFuture<Integer>(); |
418 |
> |
f = new CompletableFuture<>(); |
419 |
|
r = new ExceptionToInteger(); |
420 |
|
g = f.exceptionally(r); |
421 |
|
f.complete(one); |
430 |
|
CompletableFuture<Integer> f, g; |
431 |
|
IntegerHandler r; |
432 |
|
|
433 |
< |
f = new CompletableFuture<Integer>(); |
433 |
> |
f = new CompletableFuture<>(); |
434 |
|
f.completeExceptionally(new CFException()); |
435 |
|
g = f.handle(r = new IntegerHandler()); |
436 |
|
assertTrue(r.ran); |
437 |
|
checkCompletedNormally(g, three); |
438 |
|
|
439 |
< |
f = new CompletableFuture<Integer>(); |
439 |
> |
f = new CompletableFuture<>(); |
440 |
|
g = f.handle(r = new IntegerHandler()); |
441 |
|
assertFalse(r.ran); |
442 |
|
f.completeExceptionally(new CFException()); |
443 |
|
checkCompletedNormally(g, three); |
444 |
|
assertTrue(r.ran); |
445 |
|
|
446 |
< |
f = new CompletableFuture<Integer>(); |
446 |
> |
f = new CompletableFuture<>(); |
447 |
|
f.complete(one); |
448 |
|
g = f.handle(r = new IntegerHandler()); |
449 |
|
assertTrue(r.ran); |
450 |
|
checkCompletedNormally(g, two); |
451 |
|
|
452 |
< |
f = new CompletableFuture<Integer>(); |
452 |
> |
f = new CompletableFuture<>(); |
453 |
|
g = f.handle(r = new IntegerHandler()); |
454 |
|
assertFalse(r.ran); |
455 |
|
f.complete(one); |
527 |
|
* thenRun result completes normally after normal completion of source |
528 |
|
*/ |
529 |
|
public void testThenRun() { |
530 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
531 |
< |
Noop r = new Noop(); |
532 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
530 |
> |
CompletableFuture<Integer> f; |
531 |
> |
CompletableFuture<Void> g; |
532 |
> |
Noop r; |
533 |
> |
|
534 |
> |
f = new CompletableFuture<>(); |
535 |
> |
g = f.thenRun(r = new Noop()); |
536 |
|
f.complete(null); |
537 |
|
checkCompletedNormally(g, null); |
538 |
< |
// reordered version |
539 |
< |
f = new CompletableFuture<Integer>(); |
538 |
> |
assertTrue(r.ran); |
539 |
> |
|
540 |
> |
f = new CompletableFuture<>(); |
541 |
|
f.complete(null); |
542 |
< |
r = new Noop(); |
505 |
< |
g = f.thenRun(r); |
542 |
> |
g = f.thenRun(r = new Noop()); |
543 |
|
checkCompletedNormally(g, null); |
544 |
+ |
assertTrue(r.ran); |
545 |
|
} |
546 |
|
|
547 |
|
/** |
549 |
|
* completion of source |
550 |
|
*/ |
551 |
|
public void testThenRun2() { |
552 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
553 |
< |
Noop r = new Noop(); |
554 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
552 |
> |
CompletableFuture<Integer> f; |
553 |
> |
CompletableFuture<Void> g; |
554 |
> |
Noop r; |
555 |
> |
|
556 |
> |
f = new CompletableFuture<>(); |
557 |
> |
g = f.thenRun(r = new Noop()); |
558 |
> |
f.completeExceptionally(new CFException()); |
559 |
> |
checkCompletedWithWrappedCFException(g); |
560 |
> |
assertFalse(r.ran); |
561 |
> |
|
562 |
> |
f = new CompletableFuture<>(); |
563 |
|
f.completeExceptionally(new CFException()); |
564 |
+ |
g = f.thenRun(r = new Noop()); |
565 |
|
checkCompletedWithWrappedCFException(g); |
566 |
+ |
assertFalse(r.ran); |
567 |
|
} |
568 |
|
|
569 |
|
/** |
570 |
|
* thenRun result completes exceptionally if action does |
571 |
|
*/ |
572 |
|
public void testThenRun3() { |
573 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
574 |
< |
FailingNoop r = new FailingNoop(); |
575 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
573 |
> |
CompletableFuture<Integer> f; |
574 |
> |
CompletableFuture<Void> g; |
575 |
> |
FailingNoop r; |
576 |
> |
|
577 |
> |
f = new CompletableFuture<>(); |
578 |
> |
g = f.thenRun(r = new FailingNoop()); |
579 |
|
f.complete(null); |
580 |
|
checkCompletedWithWrappedCFException(g); |
581 |
+ |
|
582 |
+ |
f = new CompletableFuture<>(); |
583 |
+ |
f.complete(null); |
584 |
+ |
g = f.thenRun(r = new FailingNoop()); |
585 |
+ |
checkCompletedWithWrappedCFException(g); |
586 |
|
} |
587 |
|
|
588 |
|
/** |
589 |
|
* thenRun result completes exceptionally if source cancelled |
590 |
|
*/ |
591 |
|
public void testThenRun4() { |
592 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
593 |
< |
Noop r = new Noop(); |
594 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
592 |
> |
CompletableFuture<Integer> f; |
593 |
> |
CompletableFuture<Void> g; |
594 |
> |
Noop r; |
595 |
> |
|
596 |
> |
f = new CompletableFuture<>(); |
597 |
> |
g = f.thenRun(r = new Noop()); |
598 |
> |
assertTrue(f.cancel(true)); |
599 |
> |
checkCompletedWithWrappedCancellationException(g); |
600 |
> |
|
601 |
> |
f = new CompletableFuture<>(); |
602 |
|
assertTrue(f.cancel(true)); |
603 |
+ |
g = f.thenRun(r = new Noop()); |
604 |
|
checkCompletedWithWrappedCancellationException(g); |
605 |
|
} |
606 |
|
|
608 |
|
* thenApply result completes normally after normal completion of source |
609 |
|
*/ |
610 |
|
public void testThenApply() { |
611 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
611 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
612 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
613 |
|
f.complete(one); |
614 |
|
checkCompletedNormally(g, two); |
619 |
|
* completion of source |
620 |
|
*/ |
621 |
|
public void testThenApply2() { |
622 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
622 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
623 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
624 |
|
f.completeExceptionally(new CFException()); |
625 |
|
checkCompletedWithWrappedCFException(g); |
629 |
|
* thenApply result completes exceptionally if action does |
630 |
|
*/ |
631 |
|
public void testThenApply3() { |
632 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
632 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
633 |
|
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
634 |
|
f.complete(one); |
635 |
|
checkCompletedWithWrappedCFException(g); |
639 |
|
* thenApply result completes exceptionally if source cancelled |
640 |
|
*/ |
641 |
|
public void testThenApply4() { |
642 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
642 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
643 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
644 |
|
assertTrue(f.cancel(true)); |
645 |
|
checkCompletedWithWrappedCancellationException(g); |
649 |
|
* thenAccept result completes normally after normal completion of source |
650 |
|
*/ |
651 |
|
public void testThenAccept() { |
652 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
652 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
653 |
|
IncAction r = new IncAction(); |
654 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
655 |
|
f.complete(one); |
662 |
|
* completion of source |
663 |
|
*/ |
664 |
|
public void testThenAccept2() { |
665 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
665 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
666 |
|
IncAction r = new IncAction(); |
667 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
668 |
|
f.completeExceptionally(new CFException()); |
673 |
|
* thenAccept result completes exceptionally if action does |
674 |
|
*/ |
675 |
|
public void testThenAccept3() { |
676 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
676 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
677 |
|
FailingConsumer r = new FailingConsumer(); |
678 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
679 |
|
f.complete(one); |
685 |
|
* thenAccept result completes exceptionally if source cancelled |
686 |
|
*/ |
687 |
|
public void testThenAccept4() { |
688 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
688 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
689 |
|
IncAction r = new IncAction(); |
690 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
691 |
|
assertTrue(f.cancel(true)); |
692 |
|
checkCompletedWithWrappedCancellationException(g); |
693 |
|
} |
694 |
|
|
631 |
– |
|
695 |
|
/** |
696 |
|
* thenCombine result completes normally after normal completion |
697 |
|
* of sources |
699 |
|
public void testThenCombine() { |
700 |
|
CompletableFuture<Integer> f, g, h; |
701 |
|
|
702 |
< |
f = new CompletableFuture<Integer>(); |
703 |
< |
g = new CompletableFuture<Integer>(); |
702 |
> |
f = new CompletableFuture<>(); |
703 |
> |
g = new CompletableFuture<>(); |
704 |
|
h = f.thenCombine(g, subtract); |
705 |
|
f.complete(3); |
706 |
|
checkIncomplete(h); |
707 |
|
g.complete(1); |
708 |
|
checkCompletedNormally(h, 2); |
709 |
|
|
710 |
< |
f = new CompletableFuture<Integer>(); |
711 |
< |
g = new CompletableFuture<Integer>(); |
710 |
> |
f = new CompletableFuture<>(); |
711 |
> |
g = new CompletableFuture<>(); |
712 |
|
h = f.thenCombine(g, subtract); |
713 |
|
g.complete(1); |
714 |
|
checkIncomplete(h); |
715 |
|
f.complete(3); |
716 |
|
checkCompletedNormally(h, 2); |
717 |
|
|
718 |
< |
f = new CompletableFuture<Integer>(); |
719 |
< |
g = new CompletableFuture<Integer>(); |
718 |
> |
f = new CompletableFuture<>(); |
719 |
> |
g = new CompletableFuture<>(); |
720 |
|
g.complete(1); |
721 |
|
f.complete(3); |
722 |
|
h = f.thenCombine(g, subtract); |
730 |
|
public void testThenCombine2() { |
731 |
|
CompletableFuture<Integer> f, g, h; |
732 |
|
|
733 |
< |
f = new CompletableFuture<Integer>(); |
734 |
< |
g = new CompletableFuture<Integer>(); |
733 |
> |
f = new CompletableFuture<>(); |
734 |
> |
g = new CompletableFuture<>(); |
735 |
|
h = f.thenCombine(g, subtract); |
736 |
|
f.completeExceptionally(new CFException()); |
737 |
|
checkIncomplete(h); |
738 |
|
g.complete(1); |
739 |
|
checkCompletedWithWrappedCFException(h); |
740 |
|
|
741 |
< |
f = new CompletableFuture<Integer>(); |
742 |
< |
g = new CompletableFuture<Integer>(); |
741 |
> |
f = new CompletableFuture<>(); |
742 |
> |
g = new CompletableFuture<>(); |
743 |
|
h = f.thenCombine(g, subtract); |
744 |
|
g.completeExceptionally(new CFException()); |
745 |
|
checkIncomplete(h); |
746 |
|
f.complete(3); |
747 |
|
checkCompletedWithWrappedCFException(h); |
748 |
|
|
749 |
< |
f = new CompletableFuture<Integer>(); |
750 |
< |
g = new CompletableFuture<Integer>(); |
749 |
> |
f = new CompletableFuture<>(); |
750 |
> |
g = new CompletableFuture<>(); |
751 |
|
f.complete(3); |
752 |
|
g.completeExceptionally(new CFException()); |
753 |
|
h = f.thenCombine(g, subtract); |
754 |
|
checkCompletedWithWrappedCFException(h); |
755 |
|
|
756 |
< |
f = new CompletableFuture<Integer>(); |
757 |
< |
g = new CompletableFuture<Integer>(); |
756 |
> |
f = new CompletableFuture<>(); |
757 |
> |
g = new CompletableFuture<>(); |
758 |
|
f.completeExceptionally(new CFException()); |
759 |
|
g.complete(3); |
760 |
|
h = f.thenCombine(g, subtract); |
765 |
|
* thenCombine result completes exceptionally if action does |
766 |
|
*/ |
767 |
|
public void testThenCombine3() { |
768 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
769 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
768 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
769 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
770 |
|
FailingBiFunction r = new FailingBiFunction(); |
771 |
|
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
772 |
|
f.complete(one); |
783 |
|
public void testThenCombine4() { |
784 |
|
CompletableFuture<Integer> f, g, h; |
785 |
|
|
786 |
< |
f = new CompletableFuture<Integer>(); |
787 |
< |
g = new CompletableFuture<Integer>(); |
786 |
> |
f = new CompletableFuture<>(); |
787 |
> |
g = new CompletableFuture<>(); |
788 |
|
h = f.thenCombine(g, subtract); |
789 |
|
assertTrue(f.cancel(true)); |
790 |
|
checkIncomplete(h); |
791 |
|
g.complete(1); |
792 |
|
checkCompletedWithWrappedCancellationException(h); |
793 |
|
|
794 |
< |
f = new CompletableFuture<Integer>(); |
795 |
< |
g = new CompletableFuture<Integer>(); |
794 |
> |
f = new CompletableFuture<>(); |
795 |
> |
g = new CompletableFuture<>(); |
796 |
|
h = f.thenCombine(g, subtract); |
797 |
|
assertTrue(g.cancel(true)); |
798 |
|
checkIncomplete(h); |
799 |
|
f.complete(3); |
800 |
|
checkCompletedWithWrappedCancellationException(h); |
801 |
|
|
802 |
< |
f = new CompletableFuture<Integer>(); |
803 |
< |
g = new CompletableFuture<Integer>(); |
802 |
> |
f = new CompletableFuture<>(); |
803 |
> |
g = new CompletableFuture<>(); |
804 |
|
assertTrue(f.cancel(true)); |
805 |
|
assertTrue(g.cancel(true)); |
806 |
|
h = f.thenCombine(g, subtract); |
812 |
|
* completion of sources |
813 |
|
*/ |
814 |
|
public void testThenAcceptBoth() { |
815 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
816 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
817 |
< |
AddAction r = new AddAction(); |
755 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
756 |
< |
f.complete(one); |
757 |
< |
checkIncomplete(g); |
758 |
< |
f2.complete(two); |
759 |
< |
checkCompletedNormally(g, null); |
760 |
< |
assertEquals(r.value, 3); |
815 |
> |
CompletableFuture<Integer> f, g; |
816 |
> |
CompletableFuture<Void> h; |
817 |
> |
SubtractAction r; |
818 |
|
|
819 |
< |
r = new AddAction(); |
820 |
< |
f = new CompletableFuture<Integer>(); |
821 |
< |
f.complete(one); |
822 |
< |
f2 = new CompletableFuture<Integer>(); |
823 |
< |
g = f.thenAcceptBoth(f2, r); |
824 |
< |
checkIncomplete(g); |
825 |
< |
f2.complete(two); |
826 |
< |
checkCompletedNormally(g, null); |
827 |
< |
assertEquals(r.value, 3); |
819 |
> |
f = new CompletableFuture<>(); |
820 |
> |
g = new CompletableFuture<>(); |
821 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
822 |
> |
f.complete(3); |
823 |
> |
checkIncomplete(h); |
824 |
> |
g.complete(1); |
825 |
> |
checkCompletedNormally(h, null); |
826 |
> |
assertEquals(r.value, 2); |
827 |
> |
|
828 |
> |
f = new CompletableFuture<>(); |
829 |
> |
g = new CompletableFuture<>(); |
830 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
831 |
> |
g.complete(1); |
832 |
> |
checkIncomplete(h); |
833 |
> |
f.complete(3); |
834 |
> |
checkCompletedNormally(h, null); |
835 |
> |
assertEquals(r.value, 2); |
836 |
> |
|
837 |
> |
f = new CompletableFuture<>(); |
838 |
> |
g = new CompletableFuture<>(); |
839 |
> |
g.complete(1); |
840 |
> |
f.complete(3); |
841 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
842 |
> |
checkCompletedNormally(h, null); |
843 |
> |
assertEquals(r.value, 2); |
844 |
|
} |
845 |
|
|
846 |
|
/** |
848 |
|
* completion of either source |
849 |
|
*/ |
850 |
|
public void testThenAcceptBoth2() { |
851 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
852 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
853 |
< |
AddAction r = new AddAction(); |
854 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
851 |
> |
CompletableFuture<Integer> f, g; |
852 |
> |
CompletableFuture<Void> h; |
853 |
> |
SubtractAction r; |
854 |
> |
|
855 |
> |
f = new CompletableFuture<>(); |
856 |
> |
g = new CompletableFuture<>(); |
857 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
858 |
|
f.completeExceptionally(new CFException()); |
859 |
< |
f2.complete(two); |
860 |
< |
checkCompletedWithWrappedCFException(g); |
859 |
> |
checkIncomplete(h); |
860 |
> |
g.complete(1); |
861 |
> |
checkCompletedWithWrappedCFException(h); |
862 |
|
|
863 |
< |
r = new AddAction(); |
864 |
< |
f = new CompletableFuture<Integer>(); |
865 |
< |
f.complete(one); |
866 |
< |
f2 = new CompletableFuture<Integer>(); |
867 |
< |
g = f.thenAcceptBoth(f2, r); |
868 |
< |
f2.completeExceptionally(new CFException()); |
869 |
< |
checkCompletedWithWrappedCFException(g); |
863 |
> |
f = new CompletableFuture<>(); |
864 |
> |
g = new CompletableFuture<>(); |
865 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
866 |
> |
g.completeExceptionally(new CFException()); |
867 |
> |
checkIncomplete(h); |
868 |
> |
f.complete(3); |
869 |
> |
checkCompletedWithWrappedCFException(h); |
870 |
> |
|
871 |
> |
f = new CompletableFuture<>(); |
872 |
> |
g = new CompletableFuture<>(); |
873 |
> |
f.complete(3); |
874 |
> |
g.completeExceptionally(new CFException()); |
875 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
876 |
> |
checkCompletedWithWrappedCFException(h); |
877 |
> |
|
878 |
> |
f = new CompletableFuture<>(); |
879 |
> |
g = new CompletableFuture<>(); |
880 |
> |
f.completeExceptionally(new CFException()); |
881 |
> |
g.complete(3); |
882 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
883 |
> |
checkCompletedWithWrappedCFException(h); |
884 |
|
} |
885 |
|
|
886 |
|
/** |
887 |
|
* thenAcceptBoth result completes exceptionally if action does |
888 |
|
*/ |
889 |
|
public void testThenAcceptBoth3() { |
890 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
891 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
892 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
893 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
894 |
< |
f.complete(one); |
895 |
< |
checkIncomplete(g); |
896 |
< |
f2.complete(two); |
897 |
< |
checkCompletedWithWrappedCFException(g); |
890 |
> |
CompletableFuture<Integer> f, g; |
891 |
> |
CompletableFuture<Void> h; |
892 |
> |
FailingBiConsumer r; |
893 |
> |
|
894 |
> |
f = new CompletableFuture<>(); |
895 |
> |
g = new CompletableFuture<>(); |
896 |
> |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
897 |
> |
f.complete(3); |
898 |
> |
checkIncomplete(h); |
899 |
> |
g.complete(1); |
900 |
> |
checkCompletedWithWrappedCFException(h); |
901 |
> |
|
902 |
> |
f = new CompletableFuture<>(); |
903 |
> |
g = new CompletableFuture<>(); |
904 |
> |
f.complete(3); |
905 |
> |
g.complete(1); |
906 |
> |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
907 |
> |
checkCompletedWithWrappedCFException(h); |
908 |
|
} |
909 |
|
|
910 |
|
/** |
911 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
912 |
|
*/ |
913 |
|
public void testThenAcceptBoth4() { |
914 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
915 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
916 |
< |
AddAction r = new AddAction(); |
917 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
914 |
> |
CompletableFuture<Integer> f, g; |
915 |
> |
CompletableFuture<Void> h; |
916 |
> |
SubtractAction r; |
917 |
> |
|
918 |
> |
f = new CompletableFuture<>(); |
919 |
> |
g = new CompletableFuture<>(); |
920 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
921 |
|
assertTrue(f.cancel(true)); |
922 |
< |
f2.complete(two); |
923 |
< |
checkCompletedWithWrappedCancellationException(g); |
924 |
< |
f = new CompletableFuture<Integer>(); |
925 |
< |
f2 = new CompletableFuture<Integer>(); |
926 |
< |
r = new AddAction(); |
927 |
< |
g = f.thenAcceptBoth(f2, r); |
928 |
< |
f.complete(one); |
929 |
< |
assertTrue(f2.cancel(true)); |
930 |
< |
checkCompletedWithWrappedCancellationException(g); |
922 |
> |
checkIncomplete(h); |
923 |
> |
g.complete(1); |
924 |
> |
checkCompletedWithWrappedCancellationException(h); |
925 |
> |
|
926 |
> |
f = new CompletableFuture<>(); |
927 |
> |
g = new CompletableFuture<>(); |
928 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
929 |
> |
assertTrue(g.cancel(true)); |
930 |
> |
checkIncomplete(h); |
931 |
> |
f.complete(3); |
932 |
> |
checkCompletedWithWrappedCancellationException(h); |
933 |
> |
|
934 |
> |
f = new CompletableFuture<>(); |
935 |
> |
g = new CompletableFuture<>(); |
936 |
> |
f.complete(3); |
937 |
> |
assertTrue(g.cancel(true)); |
938 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
939 |
> |
checkCompletedWithWrappedCancellationException(h); |
940 |
> |
|
941 |
> |
f = new CompletableFuture<>(); |
942 |
> |
g = new CompletableFuture<>(); |
943 |
> |
assertTrue(f.cancel(true)); |
944 |
> |
g.complete(3); |
945 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
946 |
> |
checkCompletedWithWrappedCancellationException(h); |
947 |
|
} |
948 |
|
|
949 |
|
/** |
950 |
|
* runAfterBoth result completes normally after normal |
951 |
|
* completion of sources |
952 |
|
*/ |
953 |
< |
public void testRunAfterBoth() { |
954 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
955 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
956 |
< |
Noop r = new Noop(); |
957 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
958 |
< |
f.complete(one); |
959 |
< |
checkIncomplete(g); |
960 |
< |
f2.complete(two); |
961 |
< |
checkCompletedNormally(g, null); |
953 |
> |
public void testRunAfterBoth_normalCompletion1() { |
954 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
955 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
956 |
> |
|
957 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
958 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
959 |
> |
final Noop r = new Noop(); |
960 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
961 |
> |
|
962 |
> |
f.complete(v1); |
963 |
> |
checkIncomplete(h); |
964 |
> |
assertFalse(r.ran); |
965 |
> |
g.complete(v2); |
966 |
> |
|
967 |
> |
checkCompletedNormally(h, null); |
968 |
|
assertTrue(r.ran); |
969 |
+ |
checkCompletedNormally(f, v1); |
970 |
+ |
checkCompletedNormally(g, v2); |
971 |
+ |
} |
972 |
+ |
} |
973 |
|
|
974 |
< |
r = new Noop(); |
975 |
< |
f = new CompletableFuture<Integer>(); |
976 |
< |
f.complete(one); |
977 |
< |
f2 = new CompletableFuture<Integer>(); |
978 |
< |
g = f.runAfterBoth(f2, r); |
979 |
< |
checkIncomplete(g); |
980 |
< |
f2.complete(two); |
981 |
< |
checkCompletedNormally(g, null); |
974 |
> |
public void testRunAfterBoth_normalCompletion2() { |
975 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
976 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
977 |
> |
|
978 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
979 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
980 |
> |
final Noop r = new Noop(); |
981 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
982 |
> |
|
983 |
> |
g.complete(v2); |
984 |
> |
checkIncomplete(h); |
985 |
> |
assertFalse(r.ran); |
986 |
> |
f.complete(v1); |
987 |
> |
|
988 |
> |
checkCompletedNormally(h, null); |
989 |
> |
assertTrue(r.ran); |
990 |
> |
checkCompletedNormally(f, v1); |
991 |
> |
checkCompletedNormally(g, v2); |
992 |
> |
} |
993 |
> |
} |
994 |
> |
|
995 |
> |
public void testRunAfterBoth_normalCompletion3() { |
996 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
997 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
998 |
> |
|
999 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1000 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1001 |
> |
final Noop r = new Noop(); |
1002 |
> |
|
1003 |
> |
g.complete(v2); |
1004 |
> |
f.complete(v1); |
1005 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1006 |
> |
|
1007 |
> |
checkCompletedNormally(h, null); |
1008 |
> |
assertTrue(r.ran); |
1009 |
> |
checkCompletedNormally(f, v1); |
1010 |
> |
checkCompletedNormally(g, v2); |
1011 |
> |
} |
1012 |
> |
} |
1013 |
> |
|
1014 |
> |
public void testRunAfterBoth_normalCompletion4() { |
1015 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1016 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1017 |
> |
|
1018 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1019 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1020 |
> |
final Noop r = new Noop(); |
1021 |
> |
|
1022 |
> |
f.complete(v1); |
1023 |
> |
g.complete(v2); |
1024 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1025 |
> |
|
1026 |
> |
checkCompletedNormally(h, null); |
1027 |
|
assertTrue(r.ran); |
1028 |
+ |
checkCompletedNormally(f, v1); |
1029 |
+ |
checkCompletedNormally(g, v2); |
1030 |
+ |
} |
1031 |
|
} |
1032 |
|
|
1033 |
|
/** |
1034 |
|
* runAfterBoth result completes exceptionally after exceptional |
1035 |
|
* completion of either source |
1036 |
|
*/ |
1037 |
< |
public void testRunAfterBoth2() { |
1038 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
861 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
862 |
< |
Noop r = new Noop(); |
863 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
864 |
< |
f.completeExceptionally(new CFException()); |
865 |
< |
f2.complete(two); |
866 |
< |
checkCompletedWithWrappedCFException(g); |
1037 |
> |
public void testRunAfterBoth_exceptionalCompletion1() { |
1038 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1039 |
|
|
1040 |
< |
r = new Noop(); |
1041 |
< |
f = new CompletableFuture<Integer>(); |
1042 |
< |
f.complete(one); |
1043 |
< |
f2 = new CompletableFuture<Integer>(); |
1044 |
< |
g = f.runAfterBoth(f2, r); |
1045 |
< |
f2.completeExceptionally(new CFException()); |
1046 |
< |
checkCompletedWithWrappedCFException(g); |
1040 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1041 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1042 |
> |
final Noop r = new Noop(); |
1043 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1044 |
> |
final CFException ex = new CFException(); |
1045 |
> |
|
1046 |
> |
f.completeExceptionally(ex); |
1047 |
> |
checkIncomplete(h); |
1048 |
> |
g.complete(v1); |
1049 |
> |
|
1050 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1051 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1052 |
> |
assertFalse(r.ran); |
1053 |
> |
checkCompletedNormally(g, v1); |
1054 |
> |
} |
1055 |
> |
} |
1056 |
> |
|
1057 |
> |
public void testRunAfterBoth_exceptionalCompletion2() { |
1058 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1059 |
> |
|
1060 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1061 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1062 |
> |
final Noop r = new Noop(); |
1063 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1064 |
> |
final CFException ex = new CFException(); |
1065 |
> |
|
1066 |
> |
g.completeExceptionally(ex); |
1067 |
> |
checkIncomplete(h); |
1068 |
> |
f.complete(v1); |
1069 |
> |
|
1070 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1071 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1072 |
> |
assertFalse(r.ran); |
1073 |
> |
checkCompletedNormally(f, v1); |
1074 |
> |
} |
1075 |
> |
} |
1076 |
> |
|
1077 |
> |
public void testRunAfterBoth_exceptionalCompletion3() { |
1078 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1079 |
> |
|
1080 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1081 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1082 |
> |
final Noop r = new Noop(); |
1083 |
> |
final CFException ex = new CFException(); |
1084 |
> |
|
1085 |
> |
g.completeExceptionally(ex); |
1086 |
> |
f.complete(v1); |
1087 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1088 |
> |
|
1089 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1090 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1091 |
> |
assertFalse(r.ran); |
1092 |
> |
checkCompletedNormally(f, v1); |
1093 |
> |
} |
1094 |
> |
} |
1095 |
> |
|
1096 |
> |
public void testRunAfterBoth_exceptionalCompletion4() { |
1097 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1098 |
> |
|
1099 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1100 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1101 |
> |
final Noop r = new Noop(); |
1102 |
> |
final CFException ex = new CFException(); |
1103 |
> |
|
1104 |
> |
f.completeExceptionally(ex); |
1105 |
> |
g.complete(v1); |
1106 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1107 |
> |
|
1108 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1109 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1110 |
> |
assertFalse(r.ran); |
1111 |
> |
checkCompletedNormally(g, v1); |
1112 |
> |
} |
1113 |
|
} |
1114 |
|
|
1115 |
|
/** |
1116 |
|
* runAfterBoth result completes exceptionally if action does |
1117 |
|
*/ |
1118 |
< |
public void testRunAfterBoth3() { |
1119 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1120 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1121 |
< |
FailingNoop r = new FailingNoop(); |
1122 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1123 |
< |
f.complete(one); |
1124 |
< |
checkIncomplete(g); |
1125 |
< |
f2.complete(two); |
1126 |
< |
checkCompletedWithWrappedCFException(g); |
1118 |
> |
public void testRunAfterBoth_actionFailed1() { |
1119 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1120 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1121 |
> |
|
1122 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1123 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1124 |
> |
final FailingNoop r = new FailingNoop(); |
1125 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1126 |
> |
|
1127 |
> |
f.complete(v1); |
1128 |
> |
checkIncomplete(h); |
1129 |
> |
g.complete(v2); |
1130 |
> |
|
1131 |
> |
checkCompletedWithWrappedCFException(h); |
1132 |
> |
checkCompletedNormally(f, v1); |
1133 |
> |
checkCompletedNormally(g, v2); |
1134 |
> |
} |
1135 |
> |
} |
1136 |
> |
|
1137 |
> |
public void testRunAfterBoth_actionFailed2() { |
1138 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1139 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1140 |
> |
|
1141 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1142 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1143 |
> |
final FailingNoop r = new FailingNoop(); |
1144 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1145 |
> |
|
1146 |
> |
g.complete(v2); |
1147 |
> |
checkIncomplete(h); |
1148 |
> |
f.complete(v1); |
1149 |
> |
|
1150 |
> |
checkCompletedWithWrappedCFException(h); |
1151 |
> |
checkCompletedNormally(f, v1); |
1152 |
> |
checkCompletedNormally(g, v2); |
1153 |
> |
} |
1154 |
|
} |
1155 |
|
|
1156 |
|
/** |
1157 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1158 |
|
*/ |
1159 |
< |
public void testRunAfterBoth4() { |
1160 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1161 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1162 |
< |
Noop r = new Noop(); |
1163 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1164 |
< |
assertTrue(f.cancel(true)); |
1165 |
< |
f2.complete(two); |
1166 |
< |
checkCompletedWithWrappedCancellationException(g); |
1167 |
< |
f = new CompletableFuture<Integer>(); |
1168 |
< |
f2 = new CompletableFuture<Integer>(); |
1169 |
< |
r = new Noop(); |
1170 |
< |
g = f.runAfterBoth(f2, r); |
1171 |
< |
f.complete(one); |
1172 |
< |
assertTrue(f2.cancel(true)); |
1173 |
< |
checkCompletedWithWrappedCancellationException(g); |
1159 |
> |
public void testRunAfterBoth_sourceCancelled1() { |
1160 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1161 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1162 |
> |
|
1163 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1164 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1165 |
> |
final Noop r = new Noop(); |
1166 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1167 |
> |
|
1168 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1169 |
> |
checkIncomplete(h); |
1170 |
> |
g.complete(v1); |
1171 |
> |
|
1172 |
> |
checkCompletedWithWrappedCancellationException(h); |
1173 |
> |
checkCancelled(f); |
1174 |
> |
assertFalse(r.ran); |
1175 |
> |
checkCompletedNormally(g, v1); |
1176 |
> |
} |
1177 |
> |
} |
1178 |
> |
|
1179 |
> |
public void testRunAfterBoth_sourceCancelled2() { |
1180 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1181 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1182 |
> |
|
1183 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1184 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1185 |
> |
final Noop r = new Noop(); |
1186 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1187 |
> |
|
1188 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1189 |
> |
checkIncomplete(h); |
1190 |
> |
f.complete(v1); |
1191 |
> |
|
1192 |
> |
checkCompletedWithWrappedCancellationException(h); |
1193 |
> |
checkCancelled(g); |
1194 |
> |
assertFalse(r.ran); |
1195 |
> |
checkCompletedNormally(f, v1); |
1196 |
> |
} |
1197 |
> |
} |
1198 |
> |
|
1199 |
> |
public void testRunAfterBoth_sourceCancelled3() { |
1200 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1201 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1202 |
> |
|
1203 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1204 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1205 |
> |
final Noop r = new Noop(); |
1206 |
> |
|
1207 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1208 |
> |
f.complete(v1); |
1209 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1210 |
> |
|
1211 |
> |
checkCompletedWithWrappedCancellationException(h); |
1212 |
> |
checkCancelled(g); |
1213 |
> |
assertFalse(r.ran); |
1214 |
> |
checkCompletedNormally(f, v1); |
1215 |
> |
} |
1216 |
> |
} |
1217 |
> |
|
1218 |
> |
public void testRunAfterBoth_sourceCancelled4() { |
1219 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1220 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1221 |
> |
|
1222 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1223 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1224 |
> |
final Noop r = new Noop(); |
1225 |
> |
|
1226 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1227 |
> |
g.complete(v1); |
1228 |
> |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1229 |
> |
|
1230 |
> |
checkCompletedWithWrappedCancellationException(h); |
1231 |
> |
checkCancelled(f); |
1232 |
> |
assertFalse(r.ran); |
1233 |
> |
checkCompletedNormally(g, v1); |
1234 |
> |
} |
1235 |
|
} |
1236 |
|
|
1237 |
|
/** |
1239 |
|
* of either source |
1240 |
|
*/ |
1241 |
|
public void testApplyToEither() { |
1242 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1243 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1242 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1243 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1244 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1245 |
|
f.complete(one); |
1246 |
|
checkCompletedNormally(g, two); |
1247 |
|
f2.complete(one); |
1248 |
|
checkCompletedNormally(g, two); |
1249 |
|
|
1250 |
< |
f = new CompletableFuture<Integer>(); |
1250 |
> |
f = new CompletableFuture<>(); |
1251 |
|
f.complete(one); |
1252 |
< |
f2 = new CompletableFuture<Integer>(); |
1252 |
> |
f2 = new CompletableFuture<>(); |
1253 |
|
g = f.applyToEither(f2, inc); |
1254 |
|
checkCompletedNormally(g, two); |
1255 |
|
} |
1259 |
|
* completion of either source |
1260 |
|
*/ |
1261 |
|
public void testApplyToEither2() { |
1262 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1263 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1262 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1263 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1264 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1265 |
|
f.completeExceptionally(new CFException()); |
1266 |
|
f2.complete(one); |
1267 |
|
checkCompletedWithWrappedCFException(g); |
1268 |
|
|
1269 |
< |
f = new CompletableFuture<Integer>(); |
1270 |
< |
f2 = new CompletableFuture<Integer>(); |
1269 |
> |
f = new CompletableFuture<>(); |
1270 |
> |
f2 = new CompletableFuture<>(); |
1271 |
|
f2.completeExceptionally(new CFException()); |
1272 |
|
g = f.applyToEither(f2, inc); |
1273 |
|
checkCompletedWithWrappedCFException(g); |
1277 |
|
* applyToEither result completes exceptionally if action does |
1278 |
|
*/ |
1279 |
|
public void testApplyToEither3() { |
1280 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1281 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1280 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1281 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1282 |
|
FailingFunction r = new FailingFunction(); |
1283 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, r); |
1284 |
|
f2.complete(two); |
1289 |
|
* applyToEither result completes exceptionally if either source cancelled |
1290 |
|
*/ |
1291 |
|
public void testApplyToEither4() { |
1292 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1293 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1292 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1293 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1294 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1295 |
|
assertTrue(f.cancel(true)); |
1296 |
|
checkCompletedWithWrappedCancellationException(g); |
1297 |
< |
f = new CompletableFuture<Integer>(); |
1298 |
< |
f2 = new CompletableFuture<Integer>(); |
1297 |
> |
f = new CompletableFuture<>(); |
1298 |
> |
f2 = new CompletableFuture<>(); |
1299 |
|
assertTrue(f2.cancel(true)); |
1300 |
|
checkCompletedWithWrappedCancellationException(g); |
1301 |
|
} |
1305 |
|
* of either source |
1306 |
|
*/ |
1307 |
|
public void testAcceptEither() { |
1308 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1309 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1308 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1309 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1310 |
|
IncAction r = new IncAction(); |
1311 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1312 |
|
f.complete(one); |
1316 |
|
assertEquals(r.value, 2); |
1317 |
|
|
1318 |
|
r = new IncAction(); |
1319 |
< |
f = new CompletableFuture<Integer>(); |
1319 |
> |
f = new CompletableFuture<>(); |
1320 |
|
f.complete(one); |
1321 |
< |
f2 = new CompletableFuture<Integer>(); |
1321 |
> |
f2 = new CompletableFuture<>(); |
1322 |
|
g = f.acceptEither(f2, r); |
1323 |
|
checkCompletedNormally(g, null); |
1324 |
|
assertEquals(r.value, 2); |
1329 |
|
* completion of either source |
1330 |
|
*/ |
1331 |
|
public void testAcceptEither2() { |
1332 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1333 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1332 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1333 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1334 |
|
IncAction r = new IncAction(); |
1335 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1336 |
|
f.completeExceptionally(new CFException()); |
1338 |
|
checkCompletedWithWrappedCFException(g); |
1339 |
|
|
1340 |
|
r = new IncAction(); |
1341 |
< |
f = new CompletableFuture<Integer>(); |
1342 |
< |
f2 = new CompletableFuture<Integer>(); |
1341 |
> |
f = new CompletableFuture<>(); |
1342 |
> |
f2 = new CompletableFuture<>(); |
1343 |
|
f2.completeExceptionally(new CFException()); |
1344 |
|
g = f.acceptEither(f2, r); |
1345 |
|
checkCompletedWithWrappedCFException(g); |
1349 |
|
* acceptEither result completes exceptionally if action does |
1350 |
|
*/ |
1351 |
|
public void testAcceptEither3() { |
1352 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1353 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1352 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1353 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1354 |
|
FailingConsumer r = new FailingConsumer(); |
1355 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1356 |
|
f2.complete(two); |
1361 |
|
* acceptEither result completes exceptionally if either source cancelled |
1362 |
|
*/ |
1363 |
|
public void testAcceptEither4() { |
1364 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1365 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1364 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1365 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1366 |
|
IncAction r = new IncAction(); |
1367 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1368 |
|
assertTrue(f.cancel(true)); |
1369 |
|
checkCompletedWithWrappedCancellationException(g); |
1370 |
< |
f = new CompletableFuture<Integer>(); |
1371 |
< |
f2 = new CompletableFuture<Integer>(); |
1370 |
> |
f = new CompletableFuture<>(); |
1371 |
> |
f2 = new CompletableFuture<>(); |
1372 |
|
assertTrue(f2.cancel(true)); |
1373 |
|
checkCompletedWithWrappedCancellationException(g); |
1374 |
|
} |
1375 |
|
|
1050 |
– |
|
1376 |
|
/** |
1377 |
|
* runAfterEither result completes normally after normal completion |
1378 |
|
* of either source |
1379 |
|
*/ |
1380 |
|
public void testRunAfterEither() { |
1381 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1382 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1381 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1382 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1383 |
|
Noop r = new Noop(); |
1384 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1385 |
|
f.complete(one); |
1389 |
|
assertTrue(r.ran); |
1390 |
|
|
1391 |
|
r = new Noop(); |
1392 |
< |
f = new CompletableFuture<Integer>(); |
1392 |
> |
f = new CompletableFuture<>(); |
1393 |
|
f.complete(one); |
1394 |
< |
f2 = new CompletableFuture<Integer>(); |
1394 |
> |
f2 = new CompletableFuture<>(); |
1395 |
|
g = f.runAfterEither(f2, r); |
1396 |
|
checkCompletedNormally(g, null); |
1397 |
|
assertTrue(r.ran); |
1402 |
|
* completion of either source |
1403 |
|
*/ |
1404 |
|
public void testRunAfterEither2() { |
1405 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1406 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1405 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1406 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1407 |
|
Noop r = new Noop(); |
1408 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1409 |
|
f.completeExceptionally(new CFException()); |
1411 |
|
checkCompletedWithWrappedCFException(g); |
1412 |
|
|
1413 |
|
r = new Noop(); |
1414 |
< |
f = new CompletableFuture<Integer>(); |
1415 |
< |
f2 = new CompletableFuture<Integer>(); |
1414 |
> |
f = new CompletableFuture<>(); |
1415 |
> |
f2 = new CompletableFuture<>(); |
1416 |
|
f2.completeExceptionally(new CFException()); |
1417 |
|
g = f.runAfterEither(f2, r); |
1418 |
|
checkCompletedWithWrappedCFException(g); |
1422 |
|
* runAfterEither result completes exceptionally if action does |
1423 |
|
*/ |
1424 |
|
public void testRunAfterEither3() { |
1425 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1426 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1425 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1426 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1427 |
|
FailingNoop r = new FailingNoop(); |
1428 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1429 |
|
f2.complete(two); |
1434 |
|
* runAfterEither result completes exceptionally if either source cancelled |
1435 |
|
*/ |
1436 |
|
public void testRunAfterEither4() { |
1437 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1438 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1437 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1438 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1439 |
|
Noop r = new Noop(); |
1440 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1441 |
|
assertTrue(f.cancel(true)); |
1442 |
|
checkCompletedWithWrappedCancellationException(g); |
1443 |
< |
f = new CompletableFuture<Integer>(); |
1444 |
< |
f2 = new CompletableFuture<Integer>(); |
1443 |
> |
f = new CompletableFuture<>(); |
1444 |
> |
f2 = new CompletableFuture<>(); |
1445 |
|
assertTrue(f2.cancel(true)); |
1446 |
|
checkCompletedWithWrappedCancellationException(g); |
1447 |
|
} |
1450 |
|
* thenCompose result completes normally after normal completion of source |
1451 |
|
*/ |
1452 |
|
public void testThenCompose() { |
1453 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1454 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1455 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1453 |
> |
CompletableFuture<Integer> f, g; |
1454 |
> |
CompletableFutureInc r; |
1455 |
> |
|
1456 |
> |
f = new CompletableFuture<>(); |
1457 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1458 |
> |
f.complete(one); |
1459 |
> |
checkCompletedNormally(g, two); |
1460 |
> |
assertTrue(r.ran); |
1461 |
> |
|
1462 |
> |
f = new CompletableFuture<>(); |
1463 |
|
f.complete(one); |
1464 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1465 |
|
checkCompletedNormally(g, two); |
1466 |
+ |
assertTrue(r.ran); |
1467 |
|
} |
1468 |
|
|
1469 |
|
/** |
1471 |
|
* completion of source |
1472 |
|
*/ |
1473 |
|
public void testThenCompose2() { |
1474 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1475 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1476 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1474 |
> |
CompletableFuture<Integer> f, g; |
1475 |
> |
CompletableFutureInc r; |
1476 |
> |
|
1477 |
> |
f = new CompletableFuture<>(); |
1478 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1479 |
|
f.completeExceptionally(new CFException()); |
1480 |
|
checkCompletedWithWrappedCFException(g); |
1481 |
+ |
|
1482 |
+ |
f = new CompletableFuture<>(); |
1483 |
+ |
f.completeExceptionally(new CFException()); |
1484 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1485 |
+ |
checkCompletedWithWrappedCFException(g); |
1486 |
|
} |
1487 |
|
|
1488 |
|
/** |
1489 |
|
* thenCompose result completes exceptionally if action does |
1490 |
|
*/ |
1491 |
|
public void testThenCompose3() { |
1492 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1493 |
< |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
1494 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1492 |
> |
CompletableFuture<Integer> f, g; |
1493 |
> |
FailingCompletableFutureFunction r; |
1494 |
> |
|
1495 |
> |
f = new CompletableFuture<>(); |
1496 |
> |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
1497 |
> |
f.complete(one); |
1498 |
> |
checkCompletedWithWrappedCFException(g); |
1499 |
> |
|
1500 |
> |
f = new CompletableFuture<>(); |
1501 |
|
f.complete(one); |
1502 |
+ |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
1503 |
|
checkCompletedWithWrappedCFException(g); |
1504 |
|
} |
1505 |
|
|
1507 |
|
* thenCompose result completes exceptionally if source cancelled |
1508 |
|
*/ |
1509 |
|
public void testThenCompose4() { |
1510 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1511 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1512 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1510 |
> |
CompletableFuture<Integer> f, g; |
1511 |
> |
CompletableFutureInc r; |
1512 |
> |
|
1513 |
> |
f = new CompletableFuture<>(); |
1514 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1515 |
|
assertTrue(f.cancel(true)); |
1516 |
|
checkCompletedWithWrappedCancellationException(g); |
1167 |
– |
} |
1517 |
|
|
1518 |
+ |
f = new CompletableFuture<>(); |
1519 |
+ |
assertTrue(f.cancel(true)); |
1520 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1521 |
+ |
checkCompletedWithWrappedCancellationException(g); |
1522 |
+ |
} |
1523 |
|
|
1524 |
|
// asyncs |
1525 |
|
|
1527 |
|
* thenRunAsync result completes normally after normal completion of source |
1528 |
|
*/ |
1529 |
|
public void testThenRunAsync() { |
1530 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1530 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1531 |
|
Noop r = new Noop(); |
1532 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1533 |
|
f.complete(null); |
1534 |
|
checkCompletedNormally(g, null); |
1535 |
|
|
1536 |
|
// reordered version |
1537 |
< |
f = new CompletableFuture<Integer>(); |
1537 |
> |
f = new CompletableFuture<>(); |
1538 |
|
f.complete(null); |
1539 |
|
r = new Noop(); |
1540 |
|
g = f.thenRunAsync(r); |
1546 |
|
* completion of source |
1547 |
|
*/ |
1548 |
|
public void testThenRunAsync2() { |
1549 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1549 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1550 |
|
Noop r = new Noop(); |
1551 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1552 |
|
f.completeExceptionally(new CFException()); |
1553 |
|
try { |
1554 |
|
g.join(); |
1555 |
|
shouldThrow(); |
1556 |
< |
} catch (Exception ok) { |
1203 |
< |
} |
1556 |
> |
} catch (CompletionException success) {} |
1557 |
|
checkCompletedWithWrappedCFException(g); |
1558 |
|
} |
1559 |
|
|
1561 |
|
* thenRunAsync result completes exceptionally if action does |
1562 |
|
*/ |
1563 |
|
public void testThenRunAsync3() { |
1564 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1564 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1565 |
|
FailingNoop r = new FailingNoop(); |
1566 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1567 |
|
f.complete(null); |
1572 |
|
* thenRunAsync result completes exceptionally if source cancelled |
1573 |
|
*/ |
1574 |
|
public void testThenRunAsync4() { |
1575 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1575 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1576 |
|
Noop r = new Noop(); |
1577 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1578 |
|
assertTrue(f.cancel(true)); |
1583 |
|
* thenApplyAsync result completes normally after normal completion of source |
1584 |
|
*/ |
1585 |
|
public void testThenApplyAsync() { |
1586 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1586 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1587 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1588 |
|
f.complete(one); |
1589 |
|
checkCompletedNormally(g, two); |
1594 |
|
* completion of source |
1595 |
|
*/ |
1596 |
|
public void testThenApplyAsync2() { |
1597 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1597 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1598 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1599 |
|
f.completeExceptionally(new CFException()); |
1600 |
|
checkCompletedWithWrappedCFException(g); |
1604 |
|
* thenApplyAsync result completes exceptionally if action does |
1605 |
|
*/ |
1606 |
|
public void testThenApplyAsync3() { |
1607 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1607 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1608 |
|
FailingFunction r = new FailingFunction(); |
1609 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
1610 |
|
f.complete(null); |
1615 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
1616 |
|
*/ |
1617 |
|
public void testThenApplyAsync4() { |
1618 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1618 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1619 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1620 |
|
assertTrue(f.cancel(true)); |
1621 |
|
checkCompletedWithWrappedCancellationException(g); |
1626 |
|
* completion of source |
1627 |
|
*/ |
1628 |
|
public void testThenAcceptAsync() { |
1629 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1629 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1630 |
|
IncAction r = new IncAction(); |
1631 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1632 |
|
f.complete(one); |
1639 |
|
* completion of source |
1640 |
|
*/ |
1641 |
|
public void testThenAcceptAsync2() { |
1642 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1642 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1643 |
|
IncAction r = new IncAction(); |
1644 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1645 |
|
f.completeExceptionally(new CFException()); |
1650 |
|
* thenAcceptAsync result completes exceptionally if action does |
1651 |
|
*/ |
1652 |
|
public void testThenAcceptAsync3() { |
1653 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1653 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1654 |
|
FailingConsumer r = new FailingConsumer(); |
1655 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1656 |
|
f.complete(null); |
1661 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
1662 |
|
*/ |
1663 |
|
public void testThenAcceptAsync4() { |
1664 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1664 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1665 |
|
IncAction r = new IncAction(); |
1666 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1667 |
|
assertTrue(f.cancel(true)); |
1668 |
|
checkCompletedWithWrappedCancellationException(g); |
1669 |
|
} |
1670 |
+ |
|
1671 |
|
/** |
1672 |
|
* thenCombineAsync result completes normally after normal |
1673 |
|
* completion of sources |
1675 |
|
public void testThenCombineAsync() { |
1676 |
|
CompletableFuture<Integer> f, g, h; |
1677 |
|
|
1678 |
< |
f = new CompletableFuture<Integer>(); |
1679 |
< |
g = new CompletableFuture<Integer>(); |
1678 |
> |
f = new CompletableFuture<>(); |
1679 |
> |
g = new CompletableFuture<>(); |
1680 |
|
h = f.thenCombineAsync(g, subtract); |
1681 |
|
f.complete(3); |
1682 |
|
checkIncomplete(h); |
1683 |
|
g.complete(1); |
1684 |
|
checkCompletedNormally(h, 2); |
1685 |
|
|
1686 |
< |
f = new CompletableFuture<Integer>(); |
1687 |
< |
g = new CompletableFuture<Integer>(); |
1686 |
> |
f = new CompletableFuture<>(); |
1687 |
> |
g = new CompletableFuture<>(); |
1688 |
|
h = f.thenCombineAsync(g, subtract); |
1689 |
|
g.complete(1); |
1690 |
|
checkIncomplete(h); |
1691 |
|
f.complete(3); |
1692 |
|
checkCompletedNormally(h, 2); |
1693 |
|
|
1694 |
< |
f = new CompletableFuture<Integer>(); |
1695 |
< |
g = new CompletableFuture<Integer>(); |
1694 |
> |
f = new CompletableFuture<>(); |
1695 |
> |
g = new CompletableFuture<>(); |
1696 |
|
g.complete(1); |
1697 |
|
f.complete(3); |
1698 |
|
h = f.thenCombineAsync(g, subtract); |
1706 |
|
public void testThenCombineAsync2() { |
1707 |
|
CompletableFuture<Integer> f, g, h; |
1708 |
|
|
1709 |
< |
f = new CompletableFuture<Integer>(); |
1710 |
< |
g = new CompletableFuture<Integer>(); |
1709 |
> |
f = new CompletableFuture<>(); |
1710 |
> |
g = new CompletableFuture<>(); |
1711 |
|
h = f.thenCombineAsync(g, subtract); |
1712 |
|
f.completeExceptionally(new CFException()); |
1713 |
|
checkIncomplete(h); |
1714 |
|
g.complete(1); |
1715 |
|
checkCompletedWithWrappedCFException(h); |
1716 |
|
|
1717 |
< |
f = new CompletableFuture<Integer>(); |
1718 |
< |
g = new CompletableFuture<Integer>(); |
1717 |
> |
f = new CompletableFuture<>(); |
1718 |
> |
g = new CompletableFuture<>(); |
1719 |
|
h = f.thenCombineAsync(g, subtract); |
1720 |
|
g.completeExceptionally(new CFException()); |
1721 |
|
checkIncomplete(h); |
1722 |
|
f.complete(3); |
1723 |
|
checkCompletedWithWrappedCFException(h); |
1724 |
|
|
1725 |
< |
f = new CompletableFuture<Integer>(); |
1726 |
< |
g = new CompletableFuture<Integer>(); |
1725 |
> |
f = new CompletableFuture<>(); |
1726 |
> |
g = new CompletableFuture<>(); |
1727 |
|
g.completeExceptionally(new CFException()); |
1728 |
|
f.complete(3); |
1729 |
|
h = f.thenCombineAsync(g, subtract); |
1734 |
|
* thenCombineAsync result completes exceptionally if action does |
1735 |
|
*/ |
1736 |
|
public void testThenCombineAsync3() { |
1737 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1738 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1737 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1738 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1739 |
|
FailingBiFunction r = new FailingBiFunction(); |
1740 |
|
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1741 |
|
f.complete(one); |
1752 |
|
public void testThenCombineAsync4() { |
1753 |
|
CompletableFuture<Integer> f, g, h; |
1754 |
|
|
1755 |
< |
f = new CompletableFuture<Integer>(); |
1756 |
< |
g = new CompletableFuture<Integer>(); |
1755 |
> |
f = new CompletableFuture<>(); |
1756 |
> |
g = new CompletableFuture<>(); |
1757 |
|
h = f.thenCombineAsync(g, subtract); |
1758 |
|
assertTrue(f.cancel(true)); |
1759 |
|
checkIncomplete(h); |
1760 |
|
g.complete(1); |
1761 |
|
checkCompletedWithWrappedCancellationException(h); |
1762 |
|
|
1763 |
< |
f = new CompletableFuture<Integer>(); |
1764 |
< |
g = new CompletableFuture<Integer>(); |
1763 |
> |
f = new CompletableFuture<>(); |
1764 |
> |
g = new CompletableFuture<>(); |
1765 |
|
h = f.thenCombineAsync(g, subtract); |
1766 |
|
assertTrue(g.cancel(true)); |
1767 |
|
checkIncomplete(h); |
1768 |
|
f.complete(3); |
1769 |
|
checkCompletedWithWrappedCancellationException(h); |
1770 |
|
|
1771 |
< |
f = new CompletableFuture<Integer>(); |
1772 |
< |
g = new CompletableFuture<Integer>(); |
1771 |
> |
f = new CompletableFuture<>(); |
1772 |
> |
g = new CompletableFuture<>(); |
1773 |
|
g.complete(3); |
1774 |
|
assertTrue(f.cancel(true)); |
1775 |
|
h = f.thenCombineAsync(g, subtract); |
1776 |
|
checkCompletedWithWrappedCancellationException(h); |
1777 |
|
|
1778 |
< |
f = new CompletableFuture<Integer>(); |
1779 |
< |
g = new CompletableFuture<Integer>(); |
1778 |
> |
f = new CompletableFuture<>(); |
1779 |
> |
g = new CompletableFuture<>(); |
1780 |
|
f.complete(3); |
1781 |
|
assertTrue(g.cancel(true)); |
1782 |
|
h = f.thenCombineAsync(g, subtract); |
1788 |
|
* completion of sources |
1789 |
|
*/ |
1790 |
|
public void testThenAcceptBothAsync() { |
1791 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1792 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1793 |
< |
AddAction r = new AddAction(); |
1794 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1795 |
< |
f.complete(one); |
1796 |
< |
checkIncomplete(g); |
1797 |
< |
f2.complete(two); |
1798 |
< |
checkCompletedNormally(g, null); |
1799 |
< |
assertEquals(r.value, 3); |
1791 |
> |
CompletableFuture<Integer> f, g; |
1792 |
> |
CompletableFuture<Void> h; |
1793 |
> |
SubtractAction r; |
1794 |
> |
|
1795 |
> |
f = new CompletableFuture<>(); |
1796 |
> |
g = new CompletableFuture<>(); |
1797 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1798 |
> |
f.complete(3); |
1799 |
> |
checkIncomplete(h); |
1800 |
> |
g.complete(1); |
1801 |
> |
checkCompletedNormally(h, null); |
1802 |
> |
assertEquals(r.value, 2); |
1803 |
> |
|
1804 |
> |
f = new CompletableFuture<>(); |
1805 |
> |
g = new CompletableFuture<>(); |
1806 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1807 |
> |
g.complete(1); |
1808 |
> |
checkIncomplete(h); |
1809 |
> |
f.complete(3); |
1810 |
> |
checkCompletedNormally(h, null); |
1811 |
> |
assertEquals(r.value, 2); |
1812 |
> |
|
1813 |
> |
f = new CompletableFuture<>(); |
1814 |
> |
g = new CompletableFuture<>(); |
1815 |
> |
g.complete(1); |
1816 |
> |
f.complete(3); |
1817 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1818 |
> |
checkCompletedNormally(h, null); |
1819 |
> |
assertEquals(r.value, 2); |
1820 |
|
} |
1821 |
|
|
1822 |
|
/** |
1824 |
|
* completion of source |
1825 |
|
*/ |
1826 |
|
public void testThenAcceptBothAsync2() { |
1827 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1828 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1829 |
< |
AddAction r = new AddAction(); |
1830 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1827 |
> |
CompletableFuture<Integer> f, g; |
1828 |
> |
CompletableFuture<Void> h; |
1829 |
> |
SubtractAction r; |
1830 |
> |
|
1831 |
> |
f = new CompletableFuture<>(); |
1832 |
> |
g = new CompletableFuture<>(); |
1833 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1834 |
|
f.completeExceptionally(new CFException()); |
1835 |
< |
f2.complete(two); |
1836 |
< |
checkCompletedWithWrappedCFException(g); |
1835 |
> |
checkIncomplete(h); |
1836 |
> |
g.complete(1); |
1837 |
> |
checkCompletedWithWrappedCFException(h); |
1838 |
|
|
1839 |
< |
r = new AddAction(); |
1840 |
< |
f = new CompletableFuture<Integer>(); |
1841 |
< |
f2 = new CompletableFuture<Integer>(); |
1842 |
< |
g = f.thenAcceptBothAsync(f2, r); |
1843 |
< |
f.complete(one); |
1844 |
< |
f2.completeExceptionally(new CFException()); |
1845 |
< |
checkCompletedWithWrappedCFException(g); |
1839 |
> |
f = new CompletableFuture<>(); |
1840 |
> |
g = new CompletableFuture<>(); |
1841 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1842 |
> |
g.completeExceptionally(new CFException()); |
1843 |
> |
checkIncomplete(h); |
1844 |
> |
f.complete(3); |
1845 |
> |
checkCompletedWithWrappedCFException(h); |
1846 |
> |
|
1847 |
> |
f = new CompletableFuture<>(); |
1848 |
> |
g = new CompletableFuture<>(); |
1849 |
> |
f.complete(3); |
1850 |
> |
g.completeExceptionally(new CFException()); |
1851 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1852 |
> |
checkCompletedWithWrappedCFException(h); |
1853 |
> |
|
1854 |
> |
f = new CompletableFuture<>(); |
1855 |
> |
g = new CompletableFuture<>(); |
1856 |
> |
f.completeExceptionally(new CFException()); |
1857 |
> |
g.complete(3); |
1858 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1859 |
> |
checkCompletedWithWrappedCFException(h); |
1860 |
|
} |
1861 |
|
|
1862 |
|
/** |
1863 |
|
* thenAcceptBothAsync result completes exceptionally if action does |
1864 |
|
*/ |
1865 |
|
public void testThenAcceptBothAsync3() { |
1866 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1867 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1868 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
1869 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1870 |
< |
f.complete(one); |
1871 |
< |
checkIncomplete(g); |
1872 |
< |
f2.complete(two); |
1873 |
< |
checkCompletedWithWrappedCFException(g); |
1866 |
> |
CompletableFuture<Integer> f, g; |
1867 |
> |
CompletableFuture<Void> h; |
1868 |
> |
FailingBiConsumer r; |
1869 |
> |
|
1870 |
> |
f = new CompletableFuture<>(); |
1871 |
> |
g = new CompletableFuture<>(); |
1872 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1873 |
> |
f.complete(3); |
1874 |
> |
checkIncomplete(h); |
1875 |
> |
g.complete(1); |
1876 |
> |
checkCompletedWithWrappedCFException(h); |
1877 |
> |
|
1878 |
> |
f = new CompletableFuture<>(); |
1879 |
> |
g = new CompletableFuture<>(); |
1880 |
> |
f.complete(3); |
1881 |
> |
g.complete(1); |
1882 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1883 |
> |
checkCompletedWithWrappedCFException(h); |
1884 |
|
} |
1885 |
|
|
1886 |
|
/** |
1887 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1888 |
|
*/ |
1889 |
|
public void testThenAcceptBothAsync4() { |
1890 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1891 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1892 |
< |
AddAction r = new AddAction(); |
1893 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1890 |
> |
CompletableFuture<Integer> f, g; |
1891 |
> |
CompletableFuture<Void> h; |
1892 |
> |
SubtractAction r; |
1893 |
> |
|
1894 |
> |
f = new CompletableFuture<>(); |
1895 |
> |
g = new CompletableFuture<>(); |
1896 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1897 |
|
assertTrue(f.cancel(true)); |
1898 |
< |
f2.complete(two); |
1899 |
< |
checkCompletedWithWrappedCancellationException(g); |
1898 |
> |
checkIncomplete(h); |
1899 |
> |
g.complete(1); |
1900 |
> |
checkCompletedWithWrappedCancellationException(h); |
1901 |
|
|
1902 |
< |
r = new AddAction(); |
1903 |
< |
f = new CompletableFuture<Integer>(); |
1904 |
< |
f2 = new CompletableFuture<Integer>(); |
1905 |
< |
g = f.thenAcceptBothAsync(f2, r); |
1906 |
< |
f.complete(one); |
1907 |
< |
assertTrue(f2.cancel(true)); |
1908 |
< |
checkCompletedWithWrappedCancellationException(g); |
1902 |
> |
f = new CompletableFuture<>(); |
1903 |
> |
g = new CompletableFuture<>(); |
1904 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1905 |
> |
assertTrue(g.cancel(true)); |
1906 |
> |
checkIncomplete(h); |
1907 |
> |
f.complete(3); |
1908 |
> |
checkCompletedWithWrappedCancellationException(h); |
1909 |
> |
|
1910 |
> |
f = new CompletableFuture<>(); |
1911 |
> |
g = new CompletableFuture<>(); |
1912 |
> |
f.complete(3); |
1913 |
> |
assertTrue(g.cancel(true)); |
1914 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1915 |
> |
checkCompletedWithWrappedCancellationException(h); |
1916 |
> |
|
1917 |
> |
f = new CompletableFuture<>(); |
1918 |
> |
g = new CompletableFuture<>(); |
1919 |
> |
assertTrue(f.cancel(true)); |
1920 |
> |
g.complete(3); |
1921 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1922 |
> |
checkCompletedWithWrappedCancellationException(h); |
1923 |
|
} |
1924 |
|
|
1925 |
|
/** |
1927 |
|
* completion of sources |
1928 |
|
*/ |
1929 |
|
public void testRunAfterBothAsync() { |
1930 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1931 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1930 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1931 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1932 |
|
Noop r = new Noop(); |
1933 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1934 |
|
f.complete(one); |
1943 |
|
* completion of source |
1944 |
|
*/ |
1945 |
|
public void testRunAfterBothAsync2() { |
1946 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1947 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1946 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1947 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1948 |
|
Noop r = new Noop(); |
1949 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1950 |
|
f.completeExceptionally(new CFException()); |
1952 |
|
checkCompletedWithWrappedCFException(g); |
1953 |
|
|
1954 |
|
r = new Noop(); |
1955 |
< |
f = new CompletableFuture<Integer>(); |
1956 |
< |
f2 = new CompletableFuture<Integer>(); |
1955 |
> |
f = new CompletableFuture<>(); |
1956 |
> |
f2 = new CompletableFuture<>(); |
1957 |
|
g = f.runAfterBothAsync(f2, r); |
1958 |
|
f.complete(one); |
1959 |
|
f2.completeExceptionally(new CFException()); |
1964 |
|
* runAfterBothAsync result completes exceptionally if action does |
1965 |
|
*/ |
1966 |
|
public void testRunAfterBothAsync3() { |
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 |
|
FailingNoop r = new FailingNoop(); |
1970 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1971 |
|
f.complete(one); |
1978 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
1979 |
|
*/ |
1980 |
|
public void testRunAfterBothAsync4() { |
1981 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1982 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1981 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1982 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1983 |
|
Noop r = new Noop(); |
1984 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1985 |
|
assertTrue(f.cancel(true)); |
1987 |
|
checkCompletedWithWrappedCancellationException(g); |
1988 |
|
|
1989 |
|
r = new Noop(); |
1990 |
< |
f = new CompletableFuture<Integer>(); |
1991 |
< |
f2 = new CompletableFuture<Integer>(); |
1990 |
> |
f = new CompletableFuture<>(); |
1991 |
> |
f2 = new CompletableFuture<>(); |
1992 |
|
g = f.runAfterBothAsync(f2, r); |
1993 |
|
f.complete(one); |
1994 |
|
assertTrue(f2.cancel(true)); |
2000 |
|
* completion of sources |
2001 |
|
*/ |
2002 |
|
public void testApplyToEitherAsync() { |
2003 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2004 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2003 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2004 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2005 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
2006 |
|
f.complete(one); |
2007 |
|
checkCompletedNormally(g, two); |
2008 |
|
|
2009 |
< |
f = new CompletableFuture<Integer>(); |
2009 |
> |
f = new CompletableFuture<>(); |
2010 |
|
f.complete(one); |
2011 |
< |
f2 = new CompletableFuture<Integer>(); |
2011 |
> |
f2 = new CompletableFuture<>(); |
2012 |
|
g = f.applyToEitherAsync(f2, inc); |
2013 |
|
checkCompletedNormally(g, two); |
2014 |
|
} |
2018 |
|
* completion of source |
2019 |
|
*/ |
2020 |
|
public void testApplyToEitherAsync2() { |
2021 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2022 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2021 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2022 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2023 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
2024 |
|
f.completeExceptionally(new CFException()); |
2025 |
|
checkCompletedWithWrappedCFException(g); |
2026 |
|
|
2027 |
< |
f = new CompletableFuture<Integer>(); |
2028 |
< |
f2 = new CompletableFuture<Integer>(); |
2027 |
> |
f = new CompletableFuture<>(); |
2028 |
> |
f2 = new CompletableFuture<>(); |
2029 |
|
f2.completeExceptionally(new CFException()); |
2030 |
|
g = f.applyToEitherAsync(f2, inc); |
2031 |
|
f.complete(one); |
2036 |
|
* applyToEitherAsync result completes exceptionally if action does |
2037 |
|
*/ |
2038 |
|
public void testApplyToEitherAsync3() { |
2039 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2040 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2039 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2040 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2041 |
|
FailingFunction r = new FailingFunction(); |
2042 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r); |
2043 |
|
f.complete(one); |
2048 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
2049 |
|
*/ |
2050 |
|
public void testApplyToEitherAsync4() { |
2051 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2052 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2051 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2052 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2053 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
2054 |
|
assertTrue(f.cancel(true)); |
2055 |
|
checkCompletedWithWrappedCancellationException(g); |
2056 |
|
|
2057 |
< |
f = new CompletableFuture<Integer>(); |
2058 |
< |
f2 = new CompletableFuture<Integer>(); |
2057 |
> |
f = new CompletableFuture<>(); |
2058 |
> |
f2 = new CompletableFuture<>(); |
2059 |
|
assertTrue(f2.cancel(true)); |
2060 |
|
g = f.applyToEitherAsync(f2, inc); |
2061 |
|
checkCompletedWithWrappedCancellationException(g); |
2066 |
|
* completion of sources |
2067 |
|
*/ |
2068 |
|
public void testAcceptEitherAsync() { |
2069 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2070 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2069 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2070 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2071 |
|
IncAction r = new IncAction(); |
2072 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2073 |
|
f.complete(one); |
2075 |
|
assertEquals(r.value, 2); |
2076 |
|
|
2077 |
|
r = new IncAction(); |
2078 |
< |
f = new CompletableFuture<Integer>(); |
2078 |
> |
f = new CompletableFuture<>(); |
2079 |
|
f.complete(one); |
2080 |
< |
f2 = new CompletableFuture<Integer>(); |
2080 |
> |
f2 = new CompletableFuture<>(); |
2081 |
|
g = f.acceptEitherAsync(f2, r); |
2082 |
|
checkCompletedNormally(g, null); |
2083 |
|
assertEquals(r.value, 2); |
2088 |
|
* completion of source |
2089 |
|
*/ |
2090 |
|
public void testAcceptEitherAsync2() { |
2091 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2092 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2091 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2092 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2093 |
|
IncAction r = new IncAction(); |
2094 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2095 |
|
f.completeExceptionally(new CFException()); |
2096 |
|
checkCompletedWithWrappedCFException(g); |
2097 |
|
|
2098 |
|
r = new IncAction(); |
2099 |
< |
f = new CompletableFuture<Integer>(); |
2100 |
< |
f2 = new CompletableFuture<Integer>(); |
2099 |
> |
f = new CompletableFuture<>(); |
2100 |
> |
f2 = new CompletableFuture<>(); |
2101 |
|
f2.completeExceptionally(new CFException()); |
2102 |
|
g = f.acceptEitherAsync(f2, r); |
2103 |
|
f.complete(one); |
2108 |
|
* acceptEitherAsync result completes exceptionally if action does |
2109 |
|
*/ |
2110 |
|
public void testAcceptEitherAsync3() { |
2111 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2112 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2111 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2112 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2113 |
|
FailingConsumer r = new FailingConsumer(); |
2114 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2115 |
|
f.complete(one); |
2121 |
|
* source cancelled |
2122 |
|
*/ |
2123 |
|
public void testAcceptEitherAsync4() { |
2124 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2125 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2124 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2125 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2126 |
|
IncAction r = new IncAction(); |
2127 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2128 |
|
assertTrue(f.cancel(true)); |
2129 |
|
checkCompletedWithWrappedCancellationException(g); |
2130 |
|
|
2131 |
|
r = new IncAction(); |
2132 |
< |
f = new CompletableFuture<Integer>(); |
2133 |
< |
f2 = new CompletableFuture<Integer>(); |
2132 |
> |
f = new CompletableFuture<>(); |
2133 |
> |
f2 = new CompletableFuture<>(); |
2134 |
|
assertTrue(f2.cancel(true)); |
2135 |
|
g = f.acceptEitherAsync(f2, r); |
2136 |
|
checkCompletedWithWrappedCancellationException(g); |
2141 |
|
* completion of sources |
2142 |
|
*/ |
2143 |
|
public void testRunAfterEitherAsync() { |
2144 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2145 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2144 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2145 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2146 |
|
Noop r = new Noop(); |
2147 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2148 |
|
f.complete(one); |
2150 |
|
assertTrue(r.ran); |
2151 |
|
|
2152 |
|
r = new Noop(); |
2153 |
< |
f = new CompletableFuture<Integer>(); |
2153 |
> |
f = new CompletableFuture<>(); |
2154 |
|
f.complete(one); |
2155 |
< |
f2 = new CompletableFuture<Integer>(); |
2155 |
> |
f2 = new CompletableFuture<>(); |
2156 |
|
g = f.runAfterEitherAsync(f2, r); |
2157 |
|
checkCompletedNormally(g, null); |
2158 |
|
assertTrue(r.ran); |
2163 |
|
* completion of source |
2164 |
|
*/ |
2165 |
|
public void testRunAfterEitherAsync2() { |
2166 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2167 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2166 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2167 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2168 |
|
Noop r = new Noop(); |
2169 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2170 |
|
f.completeExceptionally(new CFException()); |
2171 |
|
checkCompletedWithWrappedCFException(g); |
2172 |
|
|
2173 |
|
r = new Noop(); |
2174 |
< |
f = new CompletableFuture<Integer>(); |
2175 |
< |
f2 = new CompletableFuture<Integer>(); |
2174 |
> |
f = new CompletableFuture<>(); |
2175 |
> |
f2 = new CompletableFuture<>(); |
2176 |
|
f2.completeExceptionally(new CFException()); |
2177 |
|
g = f.runAfterEitherAsync(f2, r); |
2178 |
|
f.complete(one); |
2183 |
|
* runAfterEitherAsync result completes exceptionally if action does |
2184 |
|
*/ |
2185 |
|
public void testRunAfterEitherAsync3() { |
2186 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2187 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2186 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2187 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2188 |
|
FailingNoop r = new FailingNoop(); |
2189 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2190 |
|
f.complete(one); |
2196 |
|
* source cancelled |
2197 |
|
*/ |
2198 |
|
public void testRunAfterEitherAsync4() { |
2199 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2200 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2199 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2200 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2201 |
|
Noop r = new Noop(); |
2202 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2203 |
|
assertTrue(f.cancel(true)); |
2204 |
|
checkCompletedWithWrappedCancellationException(g); |
2205 |
|
|
2206 |
|
r = new Noop(); |
2207 |
< |
f = new CompletableFuture<Integer>(); |
2208 |
< |
f2 = new CompletableFuture<Integer>(); |
2207 |
> |
f = new CompletableFuture<>(); |
2208 |
> |
f2 = new CompletableFuture<>(); |
2209 |
|
assertTrue(f2.cancel(true)); |
2210 |
|
g = f.runAfterEitherAsync(f2, r); |
2211 |
|
checkCompletedWithWrappedCancellationException(g); |
2216 |
|
* completion of source |
2217 |
|
*/ |
2218 |
|
public void testThenComposeAsync() { |
2219 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2220 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2221 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2219 |
> |
CompletableFuture<Integer> f, g; |
2220 |
> |
CompletableFutureInc r; |
2221 |
> |
|
2222 |
> |
f = new CompletableFuture<>(); |
2223 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2224 |
|
f.complete(one); |
2225 |
|
checkCompletedNormally(g, two); |
2226 |
+ |
|
2227 |
+ |
f = new CompletableFuture<>(); |
2228 |
+ |
f.complete(one); |
2229 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2230 |
+ |
checkCompletedNormally(g, two); |
2231 |
|
} |
2232 |
|
|
2233 |
|
/** |
2235 |
|
* exceptional completion of source |
2236 |
|
*/ |
2237 |
|
public void testThenComposeAsync2() { |
2238 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2239 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2240 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2238 |
> |
CompletableFuture<Integer> f, g; |
2239 |
> |
CompletableFutureInc r; |
2240 |
> |
|
2241 |
> |
f = new CompletableFuture<>(); |
2242 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2243 |
> |
f.completeExceptionally(new CFException()); |
2244 |
> |
checkCompletedWithWrappedCFException(g); |
2245 |
> |
assertFalse(r.ran); |
2246 |
> |
|
2247 |
> |
f = new CompletableFuture<>(); |
2248 |
|
f.completeExceptionally(new CFException()); |
2249 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2250 |
|
checkCompletedWithWrappedCFException(g); |
2251 |
+ |
assertFalse(r.ran); |
2252 |
|
} |
2253 |
|
|
2254 |
|
/** |
2255 |
|
* thenComposeAsync result completes exceptionally if action does |
2256 |
|
*/ |
2257 |
|
public void testThenComposeAsync3() { |
2258 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2259 |
< |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
2260 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2258 |
> |
CompletableFuture<Integer> f, g; |
2259 |
> |
FailingCompletableFutureFunction r; |
2260 |
> |
|
2261 |
> |
f = new CompletableFuture<>(); |
2262 |
> |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
2263 |
> |
f.complete(one); |
2264 |
> |
checkCompletedWithWrappedCFException(g); |
2265 |
> |
|
2266 |
> |
f = new CompletableFuture<>(); |
2267 |
|
f.complete(one); |
2268 |
+ |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
2269 |
|
checkCompletedWithWrappedCFException(g); |
2270 |
|
} |
2271 |
|
|
2273 |
|
* thenComposeAsync result completes exceptionally if source cancelled |
2274 |
|
*/ |
2275 |
|
public void testThenComposeAsync4() { |
2276 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2277 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2278 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2276 |
> |
CompletableFuture<Integer> f, g; |
2277 |
> |
CompletableFutureInc r; |
2278 |
> |
|
2279 |
> |
f = new CompletableFuture<>(); |
2280 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2281 |
|
assertTrue(f.cancel(true)); |
2282 |
|
checkCompletedWithWrappedCancellationException(g); |
1838 |
– |
} |
2283 |
|
|
2284 |
+ |
f = new CompletableFuture<>(); |
2285 |
+ |
assertTrue(f.cancel(true)); |
2286 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2287 |
+ |
checkCompletedWithWrappedCancellationException(g); |
2288 |
+ |
} |
2289 |
|
|
2290 |
|
// async with explicit executors |
2291 |
|
|
2293 |
|
* thenRunAsync result completes normally after normal completion of source |
2294 |
|
*/ |
2295 |
|
public void testThenRunAsyncE() { |
2296 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2296 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2297 |
|
Noop r = new Noop(); |
2298 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2299 |
|
f.complete(null); |
2300 |
|
checkCompletedNormally(g, null); |
2301 |
|
|
2302 |
|
// reordered version |
2303 |
< |
f = new CompletableFuture<Integer>(); |
2303 |
> |
f = new CompletableFuture<>(); |
2304 |
|
f.complete(null); |
2305 |
|
r = new Noop(); |
2306 |
|
g = f.thenRunAsync(r, new ThreadExecutor()); |
2312 |
|
* completion of source |
2313 |
|
*/ |
2314 |
|
public void testThenRunAsync2E() { |
2315 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2315 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2316 |
|
Noop r = new Noop(); |
2317 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2318 |
|
f.completeExceptionally(new CFException()); |
2319 |
|
try { |
2320 |
|
g.join(); |
2321 |
|
shouldThrow(); |
2322 |
< |
} catch (Exception ok) { |
1874 |
< |
} |
2322 |
> |
} catch (CompletionException success) {} |
2323 |
|
checkCompletedWithWrappedCFException(g); |
2324 |
|
} |
2325 |
|
|
2327 |
|
* thenRunAsync result completes exceptionally if action does |
2328 |
|
*/ |
2329 |
|
public void testThenRunAsync3E() { |
2330 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2330 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2331 |
|
FailingNoop r = new FailingNoop(); |
2332 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2333 |
|
f.complete(null); |
2338 |
|
* thenRunAsync result completes exceptionally if source cancelled |
2339 |
|
*/ |
2340 |
|
public void testThenRunAsync4E() { |
2341 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2341 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2342 |
|
Noop r = new Noop(); |
2343 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2344 |
|
assertTrue(f.cancel(true)); |
2349 |
|
* thenApplyAsync result completes normally after normal completion of source |
2350 |
|
*/ |
2351 |
|
public void testThenApplyAsyncE() { |
2352 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2352 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2353 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2354 |
|
f.complete(one); |
2355 |
|
checkCompletedNormally(g, two); |
2360 |
|
* completion of source |
2361 |
|
*/ |
2362 |
|
public void testThenApplyAsync2E() { |
2363 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2363 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2364 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2365 |
|
f.completeExceptionally(new CFException()); |
2366 |
|
checkCompletedWithWrappedCFException(g); |
2370 |
|
* thenApplyAsync result completes exceptionally if action does |
2371 |
|
*/ |
2372 |
|
public void testThenApplyAsync3E() { |
2373 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2373 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2374 |
|
FailingFunction r = new FailingFunction(); |
2375 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
2376 |
|
f.complete(null); |
2381 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
2382 |
|
*/ |
2383 |
|
public void testThenApplyAsync4E() { |
2384 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2384 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2385 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2386 |
|
assertTrue(f.cancel(true)); |
2387 |
|
checkCompletedWithWrappedCancellationException(g); |
2392 |
|
* completion of source |
2393 |
|
*/ |
2394 |
|
public void testThenAcceptAsyncE() { |
2395 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2395 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2396 |
|
IncAction r = new IncAction(); |
2397 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2398 |
|
f.complete(one); |
2405 |
|
* completion of source |
2406 |
|
*/ |
2407 |
|
public void testThenAcceptAsync2E() { |
2408 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2408 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2409 |
|
IncAction r = new IncAction(); |
2410 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2411 |
|
f.completeExceptionally(new CFException()); |
2416 |
|
* thenAcceptAsync result completes exceptionally if action does |
2417 |
|
*/ |
2418 |
|
public void testThenAcceptAsync3E() { |
2419 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2419 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2420 |
|
FailingConsumer r = new FailingConsumer(); |
2421 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2422 |
|
f.complete(null); |
2427 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
2428 |
|
*/ |
2429 |
|
public void testThenAcceptAsync4E() { |
2430 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2430 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2431 |
|
IncAction r = new IncAction(); |
2432 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2433 |
|
assertTrue(f.cancel(true)); |
2443 |
|
ThreadExecutor e = new ThreadExecutor(); |
2444 |
|
int count = 0; |
2445 |
|
|
2446 |
< |
f = new CompletableFuture<Integer>(); |
2447 |
< |
g = new CompletableFuture<Integer>(); |
2446 |
> |
f = new CompletableFuture<>(); |
2447 |
> |
g = new CompletableFuture<>(); |
2448 |
|
h = f.thenCombineAsync(g, subtract, e); |
2449 |
|
f.complete(3); |
2450 |
|
checkIncomplete(h); |
2452 |
|
checkCompletedNormally(h, 2); |
2453 |
|
assertEquals(++count, e.count.get()); |
2454 |
|
|
2455 |
< |
f = new CompletableFuture<Integer>(); |
2456 |
< |
g = new CompletableFuture<Integer>(); |
2455 |
> |
f = new CompletableFuture<>(); |
2456 |
> |
g = new CompletableFuture<>(); |
2457 |
|
h = f.thenCombineAsync(g, subtract, e); |
2458 |
|
g.complete(1); |
2459 |
|
checkIncomplete(h); |
2461 |
|
checkCompletedNormally(h, 2); |
2462 |
|
assertEquals(++count, e.count.get()); |
2463 |
|
|
2464 |
< |
f = new CompletableFuture<Integer>(); |
2465 |
< |
g = new CompletableFuture<Integer>(); |
2464 |
> |
f = new CompletableFuture<>(); |
2465 |
> |
g = new CompletableFuture<>(); |
2466 |
|
g.complete(1); |
2467 |
|
f.complete(3); |
2468 |
|
h = f.thenCombineAsync(g, subtract, e); |
2479 |
|
ThreadExecutor e = new ThreadExecutor(); |
2480 |
|
int count = 0; |
2481 |
|
|
2482 |
< |
f = new CompletableFuture<Integer>(); |
2483 |
< |
g = new CompletableFuture<Integer>(); |
2482 |
> |
f = new CompletableFuture<>(); |
2483 |
> |
g = new CompletableFuture<>(); |
2484 |
|
h = f.thenCombineAsync(g, subtract, e); |
2485 |
|
f.completeExceptionally(new CFException()); |
2486 |
|
checkIncomplete(h); |
2487 |
|
g.complete(1); |
2488 |
|
checkCompletedWithWrappedCFException(h); |
2489 |
|
|
2490 |
< |
f = new CompletableFuture<Integer>(); |
2491 |
< |
g = new CompletableFuture<Integer>(); |
2490 |
> |
f = new CompletableFuture<>(); |
2491 |
> |
g = new CompletableFuture<>(); |
2492 |
|
h = f.thenCombineAsync(g, subtract, e); |
2493 |
|
g.completeExceptionally(new CFException()); |
2494 |
|
checkIncomplete(h); |
2495 |
|
f.complete(3); |
2496 |
|
checkCompletedWithWrappedCFException(h); |
2497 |
|
|
2498 |
< |
f = new CompletableFuture<Integer>(); |
2499 |
< |
g = new CompletableFuture<Integer>(); |
2498 |
> |
f = new CompletableFuture<>(); |
2499 |
> |
g = new CompletableFuture<>(); |
2500 |
|
g.completeExceptionally(new CFException()); |
2501 |
|
h = f.thenCombineAsync(g, subtract, e); |
2502 |
|
checkIncomplete(h); |
2510 |
|
* thenCombineAsync result completes exceptionally if action does |
2511 |
|
*/ |
2512 |
|
public void testThenCombineAsync3E() { |
2513 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2514 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2513 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2514 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2515 |
|
FailingBiFunction r = new FailingBiFunction(); |
2516 |
|
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2517 |
|
f.complete(one); |
2529 |
|
CompletableFuture<Integer> f, g, h; |
2530 |
|
ThreadExecutor e = new ThreadExecutor(); |
2531 |
|
|
2532 |
< |
f = new CompletableFuture<Integer>(); |
2533 |
< |
g = new CompletableFuture<Integer>(); |
2532 |
> |
f = new CompletableFuture<>(); |
2533 |
> |
g = new CompletableFuture<>(); |
2534 |
|
h = f.thenCombineAsync(g, subtract, e); |
2535 |
|
assertTrue(f.cancel(true)); |
2536 |
|
checkIncomplete(h); |
2537 |
|
g.complete(1); |
2538 |
|
checkCompletedWithWrappedCancellationException(h); |
2539 |
|
|
2540 |
< |
f = new CompletableFuture<Integer>(); |
2541 |
< |
g = new CompletableFuture<Integer>(); |
2540 |
> |
f = new CompletableFuture<>(); |
2541 |
> |
g = new CompletableFuture<>(); |
2542 |
|
h = f.thenCombineAsync(g, subtract, e); |
2543 |
|
assertTrue(g.cancel(true)); |
2544 |
|
checkIncomplete(h); |
2545 |
|
f.complete(3); |
2546 |
|
checkCompletedWithWrappedCancellationException(h); |
2547 |
|
|
2548 |
< |
f = new CompletableFuture<Integer>(); |
2549 |
< |
g = new CompletableFuture<Integer>(); |
2548 |
> |
f = new CompletableFuture<>(); |
2549 |
> |
g = new CompletableFuture<>(); |
2550 |
|
assertTrue(g.cancel(true)); |
2551 |
|
h = f.thenCombineAsync(g, subtract, e); |
2552 |
|
checkIncomplete(h); |
2553 |
|
f.complete(3); |
2554 |
|
checkCompletedWithWrappedCancellationException(h); |
2555 |
|
|
2556 |
< |
f = new CompletableFuture<Integer>(); |
2557 |
< |
g = new CompletableFuture<Integer>(); |
2556 |
> |
f = new CompletableFuture<>(); |
2557 |
> |
g = new CompletableFuture<>(); |
2558 |
|
assertTrue(f.cancel(true)); |
2559 |
|
assertTrue(g.cancel(true)); |
2560 |
|
h = f.thenCombineAsync(g, subtract, e); |
2568 |
|
* completion of sources |
2569 |
|
*/ |
2570 |
|
public void testThenAcceptBothAsyncE() { |
2571 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2572 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2573 |
< |
AddAction r = new AddAction(); |
2574 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2575 |
< |
f.complete(one); |
2576 |
< |
checkIncomplete(g); |
2577 |
< |
f2.complete(two); |
2578 |
< |
checkCompletedNormally(g, null); |
2579 |
< |
assertEquals(r.value, 3); |
2571 |
> |
CompletableFuture<Integer> f, g; |
2572 |
> |
CompletableFuture<Void> h; |
2573 |
> |
SubtractAction r; |
2574 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2575 |
> |
|
2576 |
> |
f = new CompletableFuture<>(); |
2577 |
> |
g = new CompletableFuture<>(); |
2578 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2579 |
> |
f.complete(3); |
2580 |
> |
checkIncomplete(h); |
2581 |
> |
g.complete(1); |
2582 |
> |
checkCompletedNormally(h, null); |
2583 |
> |
assertEquals(r.value, 2); |
2584 |
> |
|
2585 |
> |
f = new CompletableFuture<>(); |
2586 |
> |
g = new CompletableFuture<>(); |
2587 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2588 |
> |
g.complete(1); |
2589 |
> |
checkIncomplete(h); |
2590 |
> |
f.complete(3); |
2591 |
> |
checkCompletedNormally(h, null); |
2592 |
> |
assertEquals(r.value, 2); |
2593 |
> |
|
2594 |
> |
f = new CompletableFuture<>(); |
2595 |
> |
g = new CompletableFuture<>(); |
2596 |
> |
g.complete(1); |
2597 |
> |
f.complete(3); |
2598 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2599 |
> |
checkCompletedNormally(h, null); |
2600 |
> |
assertEquals(r.value, 2); |
2601 |
> |
|
2602 |
> |
assertEquals(3, e.count.get()); |
2603 |
|
} |
2604 |
|
|
2605 |
|
/** |
2607 |
|
* completion of source |
2608 |
|
*/ |
2609 |
|
public void testThenAcceptBothAsync2E() { |
2610 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2611 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2612 |
< |
AddAction r = new AddAction(); |
2613 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2610 |
> |
CompletableFuture<Integer> f, g; |
2611 |
> |
CompletableFuture<Void> h; |
2612 |
> |
SubtractAction r; |
2613 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2614 |
> |
|
2615 |
> |
f = new CompletableFuture<>(); |
2616 |
> |
g = new CompletableFuture<>(); |
2617 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2618 |
|
f.completeExceptionally(new CFException()); |
2619 |
< |
f2.complete(two); |
2620 |
< |
checkCompletedWithWrappedCFException(g); |
2619 |
> |
checkIncomplete(h); |
2620 |
> |
g.complete(1); |
2621 |
> |
checkCompletedWithWrappedCFException(h); |
2622 |
|
|
2623 |
< |
r = new AddAction(); |
2624 |
< |
f = new CompletableFuture<Integer>(); |
2625 |
< |
f2 = new CompletableFuture<Integer>(); |
2626 |
< |
g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2627 |
< |
f.complete(one); |
2628 |
< |
f2.completeExceptionally(new CFException()); |
2629 |
< |
checkCompletedWithWrappedCFException(g); |
2623 |
> |
f = new CompletableFuture<>(); |
2624 |
> |
g = new CompletableFuture<>(); |
2625 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2626 |
> |
g.completeExceptionally(new CFException()); |
2627 |
> |
checkIncomplete(h); |
2628 |
> |
f.complete(3); |
2629 |
> |
checkCompletedWithWrappedCFException(h); |
2630 |
> |
|
2631 |
> |
f = new CompletableFuture<>(); |
2632 |
> |
g = new CompletableFuture<>(); |
2633 |
> |
f.complete(3); |
2634 |
> |
g.completeExceptionally(new CFException()); |
2635 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2636 |
> |
checkCompletedWithWrappedCFException(h); |
2637 |
> |
|
2638 |
> |
f = new CompletableFuture<>(); |
2639 |
> |
g = new CompletableFuture<>(); |
2640 |
> |
f.completeExceptionally(new CFException()); |
2641 |
> |
g.complete(3); |
2642 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2643 |
> |
checkCompletedWithWrappedCFException(h); |
2644 |
> |
|
2645 |
> |
assertEquals(0, e.count.get()); |
2646 |
|
} |
2647 |
|
|
2648 |
|
/** |
2649 |
|
* thenAcceptBothAsync result completes exceptionally if action does |
2650 |
|
*/ |
2651 |
|
public void testThenAcceptBothAsync3E() { |
2652 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2653 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2654 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
2655 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2656 |
< |
f.complete(one); |
2657 |
< |
checkIncomplete(g); |
2658 |
< |
f2.complete(two); |
2659 |
< |
checkCompletedWithWrappedCFException(g); |
2652 |
> |
CompletableFuture<Integer> f, g; |
2653 |
> |
CompletableFuture<Void> h; |
2654 |
> |
FailingBiConsumer r; |
2655 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2656 |
> |
|
2657 |
> |
f = new CompletableFuture<>(); |
2658 |
> |
g = new CompletableFuture<>(); |
2659 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2660 |
> |
f.complete(3); |
2661 |
> |
checkIncomplete(h); |
2662 |
> |
g.complete(1); |
2663 |
> |
checkCompletedWithWrappedCFException(h); |
2664 |
> |
|
2665 |
> |
f = new CompletableFuture<>(); |
2666 |
> |
g = new CompletableFuture<>(); |
2667 |
> |
f.complete(3); |
2668 |
> |
g.complete(1); |
2669 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2670 |
> |
checkCompletedWithWrappedCFException(h); |
2671 |
> |
|
2672 |
> |
assertEquals(2, e.count.get()); |
2673 |
|
} |
2674 |
|
|
2675 |
|
/** |
2676 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2677 |
|
*/ |
2678 |
|
public void testThenAcceptBothAsync4E() { |
2679 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2680 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2681 |
< |
AddAction r = new AddAction(); |
2682 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2679 |
> |
CompletableFuture<Integer> f, g; |
2680 |
> |
CompletableFuture<Void> h; |
2681 |
> |
SubtractAction r; |
2682 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2683 |
> |
|
2684 |
> |
f = new CompletableFuture<>(); |
2685 |
> |
g = new CompletableFuture<>(); |
2686 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2687 |
|
assertTrue(f.cancel(true)); |
2688 |
< |
f2.complete(two); |
2689 |
< |
checkCompletedWithWrappedCancellationException(g); |
2688 |
> |
checkIncomplete(h); |
2689 |
> |
g.complete(1); |
2690 |
> |
checkCompletedWithWrappedCancellationException(h); |
2691 |
|
|
2692 |
< |
r = new AddAction(); |
2693 |
< |
f = new CompletableFuture<Integer>(); |
2694 |
< |
f2 = new CompletableFuture<Integer>(); |
2695 |
< |
g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2696 |
< |
f.complete(one); |
2697 |
< |
assertTrue(f2.cancel(true)); |
2698 |
< |
checkCompletedWithWrappedCancellationException(g); |
2692 |
> |
f = new CompletableFuture<>(); |
2693 |
> |
g = new CompletableFuture<>(); |
2694 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2695 |
> |
assertTrue(g.cancel(true)); |
2696 |
> |
checkIncomplete(h); |
2697 |
> |
f.complete(3); |
2698 |
> |
checkCompletedWithWrappedCancellationException(h); |
2699 |
> |
|
2700 |
> |
f = new CompletableFuture<>(); |
2701 |
> |
g = new CompletableFuture<>(); |
2702 |
> |
f.complete(3); |
2703 |
> |
assertTrue(g.cancel(true)); |
2704 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2705 |
> |
checkCompletedWithWrappedCancellationException(h); |
2706 |
> |
|
2707 |
> |
f = new CompletableFuture<>(); |
2708 |
> |
g = new CompletableFuture<>(); |
2709 |
> |
assertTrue(f.cancel(true)); |
2710 |
> |
g.complete(3); |
2711 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2712 |
> |
checkCompletedWithWrappedCancellationException(h); |
2713 |
> |
|
2714 |
> |
assertEquals(0, e.count.get()); |
2715 |
|
} |
2716 |
|
|
2717 |
|
/** |
2719 |
|
* completion of sources |
2720 |
|
*/ |
2721 |
|
public void testRunAfterBothAsyncE() { |
2722 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2723 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2722 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2723 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2724 |
|
Noop r = new Noop(); |
2725 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2726 |
|
f.complete(one); |
2735 |
|
* completion of source |
2736 |
|
*/ |
2737 |
|
public void testRunAfterBothAsync2E() { |
2738 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2739 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2738 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2739 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2740 |
|
Noop r = new Noop(); |
2741 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2742 |
|
f.completeExceptionally(new CFException()); |
2744 |
|
checkCompletedWithWrappedCFException(g); |
2745 |
|
|
2746 |
|
r = new Noop(); |
2747 |
< |
f = new CompletableFuture<Integer>(); |
2748 |
< |
f2 = new CompletableFuture<Integer>(); |
2747 |
> |
f = new CompletableFuture<>(); |
2748 |
> |
f2 = new CompletableFuture<>(); |
2749 |
|
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2750 |
|
f.complete(one); |
2751 |
|
f2.completeExceptionally(new CFException()); |
2756 |
|
* runAfterBothAsync result completes exceptionally if action does |
2757 |
|
*/ |
2758 |
|
public void testRunAfterBothAsync3E() { |
2759 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2760 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2759 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2760 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2761 |
|
FailingNoop r = new FailingNoop(); |
2762 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2763 |
|
f.complete(one); |
2770 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
2771 |
|
*/ |
2772 |
|
public void testRunAfterBothAsync4E() { |
2773 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2774 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2773 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2774 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2775 |
|
Noop r = new Noop(); |
2776 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2777 |
|
assertTrue(f.cancel(true)); |
2779 |
|
checkCompletedWithWrappedCancellationException(g); |
2780 |
|
|
2781 |
|
r = new Noop(); |
2782 |
< |
f = new CompletableFuture<Integer>(); |
2783 |
< |
f2 = new CompletableFuture<Integer>(); |
2782 |
> |
f = new CompletableFuture<>(); |
2783 |
> |
f2 = new CompletableFuture<>(); |
2784 |
|
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2785 |
|
f.complete(one); |
2786 |
|
assertTrue(f2.cancel(true)); |
2792 |
|
* completion of sources |
2793 |
|
*/ |
2794 |
|
public void testApplyToEitherAsyncE() { |
2795 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2796 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2795 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2796 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2797 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2798 |
|
f.complete(one); |
2799 |
|
checkCompletedNormally(g, two); |
2800 |
|
|
2801 |
< |
f = new CompletableFuture<Integer>(); |
2801 |
> |
f = new CompletableFuture<>(); |
2802 |
|
f.complete(one); |
2803 |
< |
f2 = new CompletableFuture<Integer>(); |
2803 |
> |
f2 = new CompletableFuture<>(); |
2804 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2805 |
|
checkCompletedNormally(g, two); |
2806 |
|
} |
2810 |
|
* completion of source |
2811 |
|
*/ |
2812 |
|
public void testApplyToEitherAsync2E() { |
2813 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2814 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2813 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2814 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2815 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2816 |
|
f.completeExceptionally(new CFException()); |
2817 |
|
checkCompletedWithWrappedCFException(g); |
2818 |
|
|
2819 |
< |
f = new CompletableFuture<Integer>(); |
2820 |
< |
f2 = new CompletableFuture<Integer>(); |
2819 |
> |
f = new CompletableFuture<>(); |
2820 |
> |
f2 = new CompletableFuture<>(); |
2821 |
|
f2.completeExceptionally(new CFException()); |
2822 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2823 |
|
f.complete(one); |
2828 |
|
* applyToEitherAsync result completes exceptionally if action does |
2829 |
|
*/ |
2830 |
|
public void testApplyToEitherAsync3E() { |
2831 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2832 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2831 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2832 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2833 |
|
FailingFunction r = new FailingFunction(); |
2834 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); |
2835 |
|
f.complete(one); |
2840 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
2841 |
|
*/ |
2842 |
|
public void testApplyToEitherAsync4E() { |
2843 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2844 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2843 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2844 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2845 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2846 |
|
assertTrue(f.cancel(true)); |
2847 |
|
checkCompletedWithWrappedCancellationException(g); |
2848 |
|
|
2849 |
< |
f = new CompletableFuture<Integer>(); |
2850 |
< |
f2 = new CompletableFuture<Integer>(); |
2849 |
> |
f = new CompletableFuture<>(); |
2850 |
> |
f2 = new CompletableFuture<>(); |
2851 |
|
assertTrue(f2.cancel(true)); |
2852 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2853 |
|
checkCompletedWithWrappedCancellationException(g); |
2858 |
|
* completion of sources |
2859 |
|
*/ |
2860 |
|
public void testAcceptEitherAsyncE() { |
2861 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2862 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2861 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2862 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2863 |
|
IncAction r = new IncAction(); |
2864 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2865 |
|
f.complete(one); |
2867 |
|
assertEquals(r.value, 2); |
2868 |
|
|
2869 |
|
r = new IncAction(); |
2870 |
< |
f = new CompletableFuture<Integer>(); |
2870 |
> |
f = new CompletableFuture<>(); |
2871 |
|
f.complete(one); |
2872 |
< |
f2 = new CompletableFuture<Integer>(); |
2872 |
> |
f2 = new CompletableFuture<>(); |
2873 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2874 |
|
checkCompletedNormally(g, null); |
2875 |
|
assertEquals(r.value, 2); |
2880 |
|
* completion of source |
2881 |
|
*/ |
2882 |
|
public void testAcceptEitherAsync2E() { |
2883 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2884 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2883 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2884 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2885 |
|
IncAction r = new IncAction(); |
2886 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2887 |
|
f.completeExceptionally(new CFException()); |
2888 |
|
checkCompletedWithWrappedCFException(g); |
2889 |
|
|
2890 |
|
r = new IncAction(); |
2891 |
< |
f = new CompletableFuture<Integer>(); |
2892 |
< |
f2 = new CompletableFuture<Integer>(); |
2891 |
> |
f = new CompletableFuture<>(); |
2892 |
> |
f2 = new CompletableFuture<>(); |
2893 |
|
f2.completeExceptionally(new CFException()); |
2894 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2895 |
|
f.complete(one); |
2900 |
|
* acceptEitherAsync result completes exceptionally if action does |
2901 |
|
*/ |
2902 |
|
public void testAcceptEitherAsync3E() { |
2903 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2904 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2903 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2904 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2905 |
|
FailingConsumer r = new FailingConsumer(); |
2906 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2907 |
|
f.complete(one); |
2913 |
|
* source cancelled |
2914 |
|
*/ |
2915 |
|
public void testAcceptEitherAsync4E() { |
2916 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2917 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2916 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2917 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2918 |
|
IncAction r = new IncAction(); |
2919 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2920 |
|
assertTrue(f.cancel(true)); |
2921 |
|
checkCompletedWithWrappedCancellationException(g); |
2922 |
|
|
2923 |
|
r = new IncAction(); |
2924 |
< |
f = new CompletableFuture<Integer>(); |
2925 |
< |
f2 = new CompletableFuture<Integer>(); |
2924 |
> |
f = new CompletableFuture<>(); |
2925 |
> |
f2 = new CompletableFuture<>(); |
2926 |
|
assertTrue(f2.cancel(true)); |
2927 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2928 |
|
checkCompletedWithWrappedCancellationException(g); |
2933 |
|
* completion of sources |
2934 |
|
*/ |
2935 |
|
public void testRunAfterEitherAsyncE() { |
2936 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2937 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2936 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2937 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2938 |
|
Noop r = new Noop(); |
2939 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2940 |
|
f.complete(one); |
2942 |
|
assertTrue(r.ran); |
2943 |
|
|
2944 |
|
r = new Noop(); |
2945 |
< |
f = new CompletableFuture<Integer>(); |
2945 |
> |
f = new CompletableFuture<>(); |
2946 |
|
f.complete(one); |
2947 |
< |
f2 = new CompletableFuture<Integer>(); |
2947 |
> |
f2 = new CompletableFuture<>(); |
2948 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2949 |
|
checkCompletedNormally(g, null); |
2950 |
|
assertTrue(r.ran); |
2955 |
|
* completion of source |
2956 |
|
*/ |
2957 |
|
public void testRunAfterEitherAsync2E() { |
2958 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2959 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2958 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2959 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2960 |
|
Noop r = new Noop(); |
2961 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2962 |
|
f.completeExceptionally(new CFException()); |
2963 |
|
checkCompletedWithWrappedCFException(g); |
2964 |
|
|
2965 |
|
r = new Noop(); |
2966 |
< |
f = new CompletableFuture<Integer>(); |
2967 |
< |
f2 = new CompletableFuture<Integer>(); |
2966 |
> |
f = new CompletableFuture<>(); |
2967 |
> |
f2 = new CompletableFuture<>(); |
2968 |
|
f2.completeExceptionally(new CFException()); |
2969 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2970 |
|
f.complete(one); |
2975 |
|
* runAfterEitherAsync result completes exceptionally if action does |
2976 |
|
*/ |
2977 |
|
public void testRunAfterEitherAsync3E() { |
2978 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2979 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2978 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2979 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2980 |
|
FailingNoop r = new FailingNoop(); |
2981 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2982 |
|
f.complete(one); |
2988 |
|
* source cancelled |
2989 |
|
*/ |
2990 |
|
public void testRunAfterEitherAsync4E() { |
2991 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2992 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2991 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2992 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2993 |
|
Noop r = new Noop(); |
2994 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2995 |
|
assertTrue(f.cancel(true)); |
2996 |
|
checkCompletedWithWrappedCancellationException(g); |
2997 |
|
|
2998 |
|
r = new Noop(); |
2999 |
< |
f = new CompletableFuture<Integer>(); |
3000 |
< |
f2 = new CompletableFuture<Integer>(); |
2999 |
> |
f = new CompletableFuture<>(); |
3000 |
> |
f2 = new CompletableFuture<>(); |
3001 |
|
assertTrue(f2.cancel(true)); |
3002 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3003 |
|
checkCompletedWithWrappedCancellationException(g); |
3008 |
|
* completion of source |
3009 |
|
*/ |
3010 |
|
public void testThenComposeAsyncE() { |
3011 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
3011 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3012 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
3013 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3014 |
|
f.complete(one); |
3020 |
|
* exceptional completion of source |
3021 |
|
*/ |
3022 |
|
public void testThenComposeAsync2E() { |
3023 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
3023 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3024 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
3025 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3026 |
|
f.completeExceptionally(new CFException()); |
3031 |
|
* thenComposeAsync result completes exceptionally if action does |
3032 |
|
*/ |
3033 |
|
public void testThenComposeAsync3E() { |
3034 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
3034 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3035 |
|
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
3036 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3037 |
|
f.complete(one); |
3042 |
|
* thenComposeAsync result completes exceptionally if source cancelled |
3043 |
|
*/ |
3044 |
|
public void testThenComposeAsync4E() { |
3045 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
3045 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3046 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
3047 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3048 |
|
assertTrue(f.cancel(true)); |
3056 |
|
* with the value null |
3057 |
|
*/ |
3058 |
|
public void testAllOf_empty() throws Exception { |
3059 |
< |
CompletableFuture<?> f = CompletableFuture.allOf(); |
3059 |
> |
CompletableFuture<Void> f = CompletableFuture.allOf(); |
3060 |
|
checkCompletedNormally(f, null); |
3061 |
|
} |
3062 |
|
|
3063 |
|
/** |
3064 |
< |
* allOf returns a future completed when all components complete |
3064 |
> |
* allOf returns a future completed normally with the value null |
3065 |
> |
* when all components complete normally |
3066 |
|
*/ |
3067 |
< |
public void testAllOf() throws Exception { |
3067 |
> |
public void testAllOf_normal() throws Exception { |
3068 |
|
for (int k = 1; k < 20; ++k) { |
3069 |
< |
CompletableFuture[] fs = new CompletableFuture[k]; |
3069 |
> |
CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
3070 |
|
for (int i = 0; i < k; ++i) |
3071 |
< |
fs[i] = new CompletableFuture<Integer>(); |
3071 |
> |
fs[i] = new CompletableFuture<>(); |
3072 |
|
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
3073 |
|
for (int i = 0; i < k; ++i) { |
3074 |
|
checkIncomplete(f); |
3075 |
+ |
checkIncomplete(CompletableFuture.allOf(fs)); |
3076 |
|
fs[i].complete(one); |
3077 |
|
} |
3078 |
|
checkCompletedNormally(f, null); |
3079 |
+ |
checkCompletedNormally(CompletableFuture.allOf(fs), null); |
3080 |
|
} |
3081 |
|
} |
3082 |
|
|
3084 |
|
* anyOf(no component futures) returns an incomplete future |
3085 |
|
*/ |
3086 |
|
public void testAnyOf_empty() throws Exception { |
3087 |
< |
CompletableFuture<?> f = CompletableFuture.anyOf(); |
3087 |
> |
CompletableFuture<Object> f = CompletableFuture.anyOf(); |
3088 |
|
checkIncomplete(f); |
3089 |
|
} |
3090 |
|
|
3091 |
|
/** |
3092 |
< |
* anyOf returns a future completed when any components complete |
3092 |
> |
* anyOf returns a future completed normally with a value when |
3093 |
> |
* a component future does |
3094 |
|
*/ |
3095 |
< |
public void testAnyOf() throws Exception { |
3096 |
< |
for (int k = 1; k < 20; ++k) { |
3095 |
> |
public void testAnyOf_normal() throws Exception { |
3096 |
> |
for (int k = 0; k < 10; ++k) { |
3097 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
3098 |
|
for (int i = 0; i < k; ++i) |
3099 |
< |
fs[i] = new CompletableFuture<Integer>(); |
3099 |
> |
fs[i] = new CompletableFuture<>(); |
3100 |
|
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
3101 |
|
checkIncomplete(f); |
3102 |
|
for (int i = 0; i < k; ++i) { |
3103 |
|
fs[i].complete(one); |
3104 |
|
checkCompletedNormally(f, one); |
3105 |
+ |
checkCompletedNormally(CompletableFuture.anyOf(fs), one); |
3106 |
+ |
} |
3107 |
+ |
} |
3108 |
+ |
} |
3109 |
+ |
|
3110 |
+ |
/** |
3111 |
+ |
* anyOf result completes exceptionally when any component does. |
3112 |
+ |
*/ |
3113 |
+ |
public void testAnyOf_exceptional() throws Exception { |
3114 |
+ |
for (int k = 0; k < 10; ++k) { |
3115 |
+ |
CompletableFuture[] fs = new CompletableFuture[k]; |
3116 |
+ |
for (int i = 0; i < k; ++i) |
3117 |
+ |
fs[i] = new CompletableFuture<>(); |
3118 |
+ |
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
3119 |
+ |
checkIncomplete(f); |
3120 |
+ |
for (int i = 0; i < k; ++i) { |
3121 |
+ |
fs[i].completeExceptionally(new CFException()); |
3122 |
+ |
checkCompletedWithWrappedCFException(f); |
3123 |
+ |
checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs)); |
3124 |
|
} |
3125 |
|
} |
3126 |
|
} |
3129 |
|
* Completion methods throw NullPointerException with null arguments |
3130 |
|
*/ |
3131 |
|
public void testNPE() { |
3132 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
3133 |
< |
CompletableFuture<Integer> g = new CompletableFuture<Integer>(); |
3132 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3133 |
> |
CompletableFuture<Integer> g = new CompletableFuture<>(); |
3134 |
|
CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null; |
3135 |
|
CompletableFuture<?> h; |
3136 |
|
ThreadExecutor exec = new ThreadExecutor(); |
3137 |
|
|
3138 |
|
Runnable[] throwingActions = { |
3139 |
< |
() -> { CompletableFuture.supplyAsync(null); }, |
3140 |
< |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
3141 |
< |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
3142 |
< |
|
3143 |
< |
() -> { CompletableFuture.runAsync(null); }, |
3144 |
< |
() -> { CompletableFuture.runAsync(null, exec); }, |
3145 |
< |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
3146 |
< |
|
3147 |
< |
() -> { f.completeExceptionally(null); }, |
3148 |
< |
|
3149 |
< |
() -> { f.thenApply(null); }, |
3150 |
< |
() -> { f.thenApplyAsync(null); }, |
3151 |
< |
() -> { f.thenApplyAsync((x) -> x, null); }, |
3152 |
< |
() -> { f.thenApplyAsync(null, exec); }, |
3153 |
< |
|
3154 |
< |
() -> { f.thenAccept(null); }, |
3155 |
< |
() -> { f.thenAcceptAsync(null); }, |
3156 |
< |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
3157 |
< |
() -> { f.thenAcceptAsync(null, exec); }, |
3158 |
< |
|
3159 |
< |
() -> { f.thenRun(null); }, |
3160 |
< |
() -> { f.thenRunAsync(null); }, |
3161 |
< |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
3162 |
< |
() -> { f.thenRunAsync(null, exec); }, |
3163 |
< |
|
3164 |
< |
() -> { f.thenCombine(g, null); }, |
3165 |
< |
() -> { f.thenCombineAsync(g, null); }, |
3166 |
< |
() -> { f.thenCombineAsync(g, null, exec); }, |
3167 |
< |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
3168 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
3169 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
3170 |
< |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
3171 |
< |
|
3172 |
< |
() -> { f.thenAcceptBoth(g, null); }, |
3173 |
< |
() -> { f.thenAcceptBothAsync(g, null); }, |
3174 |
< |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
3175 |
< |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
3176 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
3177 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
3178 |
< |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
3179 |
< |
|
3180 |
< |
() -> { f.runAfterBoth(g, null); }, |
3181 |
< |
() -> { f.runAfterBothAsync(g, null); }, |
3182 |
< |
() -> { f.runAfterBothAsync(g, null, exec); }, |
3183 |
< |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
3184 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
3185 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
3186 |
< |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
3187 |
< |
|
3188 |
< |
() -> { f.applyToEither(g, null); }, |
3189 |
< |
() -> { f.applyToEitherAsync(g, null); }, |
3190 |
< |
() -> { f.applyToEitherAsync(g, null, exec); }, |
3191 |
< |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
3192 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
3193 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
3194 |
< |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
3195 |
< |
|
3196 |
< |
() -> { f.acceptEither(g, null); }, |
3197 |
< |
() -> { f.acceptEitherAsync(g, null); }, |
3198 |
< |
() -> { f.acceptEitherAsync(g, null, exec); }, |
3199 |
< |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
3200 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
3201 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
3202 |
< |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
3203 |
< |
|
3204 |
< |
() -> { f.runAfterEither(g, null); }, |
3205 |
< |
() -> { f.runAfterEitherAsync(g, null); }, |
3206 |
< |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
3207 |
< |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
3208 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
3209 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
3210 |
< |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
3211 |
< |
|
3212 |
< |
() -> { f.thenCompose(null); }, |
3213 |
< |
() -> { f.thenComposeAsync(null); }, |
3214 |
< |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
3215 |
< |
() -> { f.thenComposeAsync(null, exec); }, |
3216 |
< |
|
3217 |
< |
() -> { f.exceptionally(null); }, |
3218 |
< |
|
3219 |
< |
() -> { f.handle(null); }, |
3220 |
< |
|
3221 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
3222 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
3223 |
< |
() -> { CompletableFuture.allOf(f, null); }, |
3224 |
< |
() -> { CompletableFuture.allOf(null, f); }, |
3225 |
< |
|
3226 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
3227 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
3228 |
< |
() -> { CompletableFuture.anyOf(f, null); }, |
3229 |
< |
() -> { CompletableFuture.anyOf(null, f); }, |
3139 |
> |
() -> CompletableFuture.supplyAsync(null), |
3140 |
> |
() -> CompletableFuture.supplyAsync(null, exec), |
3141 |
> |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
3142 |
> |
|
3143 |
> |
() -> CompletableFuture.runAsync(null), |
3144 |
> |
() -> CompletableFuture.runAsync(null, exec), |
3145 |
> |
() -> CompletableFuture.runAsync(() -> {}, null), |
3146 |
> |
|
3147 |
> |
() -> f.completeExceptionally(null), |
3148 |
> |
|
3149 |
> |
() -> f.thenApply(null), |
3150 |
> |
() -> f.thenApplyAsync(null), |
3151 |
> |
() -> f.thenApplyAsync((x) -> x, null), |
3152 |
> |
() -> f.thenApplyAsync(null, exec), |
3153 |
> |
|
3154 |
> |
() -> f.thenAccept(null), |
3155 |
> |
() -> f.thenAcceptAsync(null), |
3156 |
> |
() -> f.thenAcceptAsync((x) -> {} , null), |
3157 |
> |
() -> f.thenAcceptAsync(null, exec), |
3158 |
> |
|
3159 |
> |
() -> f.thenRun(null), |
3160 |
> |
() -> f.thenRunAsync(null), |
3161 |
> |
() -> f.thenRunAsync(() -> {} , null), |
3162 |
> |
() -> f.thenRunAsync(null, exec), |
3163 |
> |
|
3164 |
> |
() -> f.thenCombine(g, null), |
3165 |
> |
() -> f.thenCombineAsync(g, null), |
3166 |
> |
() -> f.thenCombineAsync(g, null, exec), |
3167 |
> |
() -> f.thenCombine(nullFuture, (x, y) -> x), |
3168 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x), |
3169 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec), |
3170 |
> |
() -> f.thenCombineAsync(g, (x, y) -> x, null), |
3171 |
> |
|
3172 |
> |
() -> f.thenAcceptBoth(g, null), |
3173 |
> |
() -> f.thenAcceptBothAsync(g, null), |
3174 |
> |
() -> f.thenAcceptBothAsync(g, null, exec), |
3175 |
> |
() -> f.thenAcceptBoth(nullFuture, (x, y) -> {}), |
3176 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}), |
3177 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec), |
3178 |
> |
() -> f.thenAcceptBothAsync(g, (x, y) -> {}, null), |
3179 |
> |
|
3180 |
> |
() -> f.runAfterBoth(g, null), |
3181 |
> |
() -> f.runAfterBothAsync(g, null), |
3182 |
> |
() -> f.runAfterBothAsync(g, null, exec), |
3183 |
> |
() -> f.runAfterBoth(nullFuture, () -> {}), |
3184 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}), |
3185 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}, exec), |
3186 |
> |
() -> f.runAfterBothAsync(g, () -> {}, null), |
3187 |
> |
|
3188 |
> |
() -> f.applyToEither(g, null), |
3189 |
> |
() -> f.applyToEitherAsync(g, null), |
3190 |
> |
() -> f.applyToEitherAsync(g, null, exec), |
3191 |
> |
() -> f.applyToEither(nullFuture, (x) -> x), |
3192 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
3193 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
3194 |
> |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
3195 |
> |
|
3196 |
> |
() -> f.acceptEither(g, null), |
3197 |
> |
() -> f.acceptEitherAsync(g, null), |
3198 |
> |
() -> f.acceptEitherAsync(g, null, exec), |
3199 |
> |
() -> f.acceptEither(nullFuture, (x) -> {}), |
3200 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
3201 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
3202 |
> |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
3203 |
> |
|
3204 |
> |
() -> f.runAfterEither(g, null), |
3205 |
> |
() -> f.runAfterEitherAsync(g, null), |
3206 |
> |
() -> f.runAfterEitherAsync(g, null, exec), |
3207 |
> |
() -> f.runAfterEither(nullFuture, () -> {}), |
3208 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}), |
3209 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}, exec), |
3210 |
> |
() -> f.runAfterEitherAsync(g, () -> {}, null), |
3211 |
> |
|
3212 |
> |
() -> f.thenCompose(null), |
3213 |
> |
() -> f.thenComposeAsync(null), |
3214 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
3215 |
> |
() -> f.thenComposeAsync(null, exec), |
3216 |
> |
|
3217 |
> |
() -> f.exceptionally(null), |
3218 |
> |
|
3219 |
> |
() -> f.handle(null), |
3220 |
> |
|
3221 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>)null), |
3222 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>[])null), |
3223 |
> |
() -> CompletableFuture.allOf(f, null), |
3224 |
> |
() -> CompletableFuture.allOf(null, f), |
3225 |
> |
|
3226 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>)null), |
3227 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>[])null), |
3228 |
> |
() -> CompletableFuture.anyOf(f, null), |
3229 |
> |
() -> CompletableFuture.anyOf(null, f), |
3230 |
> |
|
3231 |
> |
() -> f.obtrudeException(null), |
3232 |
|
}; |
3233 |
|
|
3234 |
|
assertThrows(NullPointerException.class, throwingActions); |
3235 |
|
assertEquals(0, exec.count.get()); |
3236 |
|
} |
3237 |
|
|
3238 |
+ |
/** |
3239 |
+ |
* toCompletableFuture returns this CompletableFuture. |
3240 |
+ |
*/ |
3241 |
+ |
public void testToCompletableFuture() { |
3242 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3243 |
+ |
assertSame(f, f.toCompletableFuture()); |
3244 |
+ |
} |
3245 |
+ |
|
3246 |
+ |
/** |
3247 |
+ |
* whenComplete action executes on normal completion, propagating |
3248 |
+ |
* source result. |
3249 |
+ |
*/ |
3250 |
+ |
public void testWhenComplete1() { |
3251 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3252 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3253 |
+ |
CompletableFuture<Integer> g = |
3254 |
+ |
f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement()); |
3255 |
+ |
f.complete(three); |
3256 |
+ |
checkCompletedNormally(f, three); |
3257 |
+ |
checkCompletedNormally(g, three); |
3258 |
+ |
assertEquals(a.get(), 1); |
3259 |
+ |
} |
3260 |
+ |
|
3261 |
+ |
/** |
3262 |
+ |
* whenComplete action executes on exceptional completion, propagating |
3263 |
+ |
* source result. |
3264 |
+ |
*/ |
3265 |
+ |
public void testWhenComplete2() { |
3266 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3267 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3268 |
+ |
CompletableFuture<Integer> g = |
3269 |
+ |
f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement()); |
3270 |
+ |
f.completeExceptionally(new CFException()); |
3271 |
+ |
assertTrue(f.isCompletedExceptionally()); |
3272 |
+ |
assertTrue(g.isCompletedExceptionally()); |
3273 |
+ |
assertEquals(a.get(), 1); |
3274 |
+ |
} |
3275 |
+ |
|
3276 |
+ |
/** |
3277 |
+ |
* If a whenComplete action throws an exception when triggered by |
3278 |
+ |
* a normal completion, it completes exceptionally |
3279 |
+ |
*/ |
3280 |
+ |
public void testWhenComplete3() { |
3281 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3282 |
+ |
CompletableFuture<Integer> g = |
3283 |
+ |
f.whenComplete((Integer x, Throwable t) -> |
3284 |
+ |
{ throw new CFException(); } ); |
3285 |
+ |
f.complete(three); |
3286 |
+ |
checkCompletedNormally(f, three); |
3287 |
+ |
assertTrue(g.isCompletedExceptionally()); |
3288 |
+ |
checkCompletedWithWrappedCFException(g); |
3289 |
+ |
} |
3290 |
+ |
|
3291 |
+ |
/** |
3292 |
+ |
* whenCompleteAsync action executes on normal completion, propagating |
3293 |
+ |
* source result. |
3294 |
+ |
*/ |
3295 |
+ |
public void testWhenCompleteAsync1() { |
3296 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3297 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3298 |
+ |
CompletableFuture<Integer> g = |
3299 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement()); |
3300 |
+ |
f.complete(three); |
3301 |
+ |
checkCompletedNormally(f, three); |
3302 |
+ |
checkCompletedNormally(g, three); |
3303 |
+ |
assertEquals(a.get(), 1); |
3304 |
+ |
} |
3305 |
+ |
|
3306 |
+ |
/** |
3307 |
+ |
* whenCompleteAsync action executes on exceptional completion, propagating |
3308 |
+ |
* source result. |
3309 |
+ |
*/ |
3310 |
+ |
public void testWhenCompleteAsync2() { |
3311 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3312 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3313 |
+ |
CompletableFuture<Integer> g = |
3314 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement()); |
3315 |
+ |
f.completeExceptionally(new CFException()); |
3316 |
+ |
checkCompletedWithWrappedCFException(f); |
3317 |
+ |
checkCompletedWithWrappedCFException(g); |
3318 |
+ |
} |
3319 |
+ |
|
3320 |
+ |
/** |
3321 |
+ |
* If a whenCompleteAsync action throws an exception when |
3322 |
+ |
* triggered by a normal completion, it completes exceptionally |
3323 |
+ |
*/ |
3324 |
+ |
public void testWhenCompleteAsync3() { |
3325 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3326 |
+ |
CompletableFuture<Integer> g = |
3327 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> |
3328 |
+ |
{ throw new CFException(); } ); |
3329 |
+ |
f.complete(three); |
3330 |
+ |
checkCompletedNormally(f, three); |
3331 |
+ |
checkCompletedWithWrappedCFException(g); |
3332 |
+ |
} |
3333 |
+ |
|
3334 |
+ |
/** |
3335 |
+ |
* whenCompleteAsync action executes on normal completion, propagating |
3336 |
+ |
* source result. |
3337 |
+ |
*/ |
3338 |
+ |
public void testWhenCompleteAsync1e() { |
3339 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3340 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3341 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3342 |
+ |
CompletableFuture<Integer> g = |
3343 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(), |
3344 |
+ |
exec); |
3345 |
+ |
f.complete(three); |
3346 |
+ |
checkCompletedNormally(f, three); |
3347 |
+ |
checkCompletedNormally(g, three); |
3348 |
+ |
assertEquals(a.get(), 1); |
3349 |
+ |
} |
3350 |
+ |
|
3351 |
+ |
/** |
3352 |
+ |
* whenCompleteAsync action executes on exceptional completion, propagating |
3353 |
+ |
* source result. |
3354 |
+ |
*/ |
3355 |
+ |
public void testWhenCompleteAsync2e() { |
3356 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3357 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3358 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3359 |
+ |
CompletableFuture<Integer> g = |
3360 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(), |
3361 |
+ |
exec); |
3362 |
+ |
f.completeExceptionally(new CFException()); |
3363 |
+ |
checkCompletedWithWrappedCFException(f); |
3364 |
+ |
checkCompletedWithWrappedCFException(g); |
3365 |
+ |
} |
3366 |
+ |
|
3367 |
+ |
/** |
3368 |
+ |
* If a whenCompleteAsync action throws an exception when triggered |
3369 |
+ |
* by a normal completion, it completes exceptionally |
3370 |
+ |
*/ |
3371 |
+ |
public void testWhenCompleteAsync3e() { |
3372 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3373 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3374 |
+ |
CompletableFuture<Integer> g = |
3375 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> |
3376 |
+ |
{ throw new CFException(); }, |
3377 |
+ |
exec); |
3378 |
+ |
f.complete(three); |
3379 |
+ |
checkCompletedNormally(f, three); |
3380 |
+ |
checkCompletedWithWrappedCFException(g); |
3381 |
+ |
} |
3382 |
+ |
|
3383 |
+ |
/** |
3384 |
+ |
* handleAsync action completes normally with function value on |
3385 |
+ |
* either normal or exceptional completion of source |
3386 |
+ |
*/ |
3387 |
+ |
public void testHandleAsync() { |
3388 |
+ |
CompletableFuture<Integer> f, g; |
3389 |
+ |
IntegerHandler r; |
3390 |
+ |
|
3391 |
+ |
f = new CompletableFuture<>(); |
3392 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3393 |
+ |
assertFalse(r.ran); |
3394 |
+ |
f.completeExceptionally(new CFException()); |
3395 |
+ |
checkCompletedWithWrappedCFException(f); |
3396 |
+ |
checkCompletedNormally(g, three); |
3397 |
+ |
assertTrue(r.ran); |
3398 |
+ |
|
3399 |
+ |
f = new CompletableFuture<>(); |
3400 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3401 |
+ |
assertFalse(r.ran); |
3402 |
+ |
f.completeExceptionally(new CFException()); |
3403 |
+ |
checkCompletedWithWrappedCFException(f); |
3404 |
+ |
checkCompletedNormally(g, three); |
3405 |
+ |
assertTrue(r.ran); |
3406 |
+ |
|
3407 |
+ |
f = new CompletableFuture<>(); |
3408 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3409 |
+ |
assertFalse(r.ran); |
3410 |
+ |
f.complete(one); |
3411 |
+ |
checkCompletedNormally(f, one); |
3412 |
+ |
checkCompletedNormally(g, two); |
3413 |
+ |
assertTrue(r.ran); |
3414 |
+ |
|
3415 |
+ |
f = new CompletableFuture<>(); |
3416 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3417 |
+ |
assertFalse(r.ran); |
3418 |
+ |
f.complete(one); |
3419 |
+ |
checkCompletedNormally(f, one); |
3420 |
+ |
checkCompletedNormally(g, two); |
3421 |
+ |
assertTrue(r.ran); |
3422 |
+ |
} |
3423 |
+ |
|
3424 |
+ |
/** |
3425 |
+ |
* handleAsync action with Executor completes normally with |
3426 |
+ |
* function value on either normal or exceptional completion of |
3427 |
+ |
* source |
3428 |
+ |
*/ |
3429 |
+ |
public void testHandleAsync2() { |
3430 |
+ |
CompletableFuture<Integer> f, g; |
3431 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3432 |
+ |
IntegerHandler r; |
3433 |
+ |
|
3434 |
+ |
f = new CompletableFuture<>(); |
3435 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3436 |
+ |
assertFalse(r.ran); |
3437 |
+ |
f.completeExceptionally(new CFException()); |
3438 |
+ |
checkCompletedWithWrappedCFException(f); |
3439 |
+ |
checkCompletedNormally(g, three); |
3440 |
+ |
assertTrue(r.ran); |
3441 |
+ |
|
3442 |
+ |
f = new CompletableFuture<>(); |
3443 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3444 |
+ |
assertFalse(r.ran); |
3445 |
+ |
f.completeExceptionally(new CFException()); |
3446 |
+ |
checkCompletedWithWrappedCFException(f); |
3447 |
+ |
checkCompletedNormally(g, three); |
3448 |
+ |
assertTrue(r.ran); |
3449 |
+ |
|
3450 |
+ |
f = new CompletableFuture<>(); |
3451 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3452 |
+ |
assertFalse(r.ran); |
3453 |
+ |
f.complete(one); |
3454 |
+ |
checkCompletedNormally(f, one); |
3455 |
+ |
checkCompletedNormally(g, two); |
3456 |
+ |
assertTrue(r.ran); |
3457 |
+ |
|
3458 |
+ |
f = new CompletableFuture<>(); |
3459 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3460 |
+ |
assertFalse(r.ran); |
3461 |
+ |
f.complete(one); |
3462 |
+ |
checkCompletedNormally(f, one); |
3463 |
+ |
checkCompletedNormally(g, two); |
3464 |
+ |
assertTrue(r.ran); |
3465 |
+ |
} |
3466 |
+ |
|
3467 |
|
} |