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 |
|
assertTrue(f.toString().contains("[Completed normally]")); |
73 |
|
|
74 |
|
void checkCompletedWithWrappedCFException(CompletableFuture<?> f) { |
75 |
|
try { |
76 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
77 |
+ |
shouldThrow(); |
78 |
+ |
} catch (ExecutionException success) { |
79 |
+ |
assertTrue(success.getCause() instanceof CFException); |
80 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
81 |
+ |
try { |
82 |
|
f.join(); |
83 |
|
shouldThrow(); |
84 |
|
} catch (CompletionException success) { |
96 |
|
} catch (ExecutionException success) { |
97 |
|
assertTrue(success.getCause() instanceof CFException); |
98 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
93 |
– |
try { |
94 |
– |
f.get(0L, SECONDS); |
95 |
– |
shouldThrow(); |
96 |
– |
} catch (ExecutionException success) { |
97 |
– |
assertTrue(success.getCause() instanceof CFException); |
98 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
99 |
|
assertTrue(f.isDone()); |
100 |
|
assertFalse(f.isCancelled()); |
101 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
103 |
|
|
104 |
|
void checkCancelled(CompletableFuture<?> f) { |
105 |
|
try { |
106 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
107 |
+ |
shouldThrow(); |
108 |
+ |
} catch (CancellationException success) { |
109 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
110 |
+ |
try { |
111 |
|
f.join(); |
112 |
|
shouldThrow(); |
113 |
|
} catch (CancellationException success) {} |
120 |
|
shouldThrow(); |
121 |
|
} catch (CancellationException success) { |
122 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
118 |
– |
try { |
119 |
– |
f.get(0L, SECONDS); |
120 |
– |
shouldThrow(); |
121 |
– |
} catch (CancellationException success) { |
122 |
– |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
123 |
|
assertTrue(f.isDone()); |
124 |
|
assertTrue(f.isCancelled()); |
125 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
127 |
|
|
128 |
|
void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) { |
129 |
|
try { |
130 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
131 |
+ |
shouldThrow(); |
132 |
+ |
} catch (ExecutionException success) { |
133 |
+ |
assertTrue(success.getCause() instanceof CancellationException); |
134 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
135 |
+ |
try { |
136 |
|
f.join(); |
137 |
|
shouldThrow(); |
138 |
|
} catch (CompletionException success) { |
150 |
|
} catch (ExecutionException success) { |
151 |
|
assertTrue(success.getCause() instanceof CancellationException); |
152 |
|
} 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); } |
153 |
|
assertTrue(f.isDone()); |
154 |
|
assertFalse(f.isCancelled()); |
155 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
160 |
|
* by methods isDone, isCancelled, and getNow |
161 |
|
*/ |
162 |
|
public void testConstructor() { |
163 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
163 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
164 |
|
checkIncomplete(f); |
165 |
|
} |
166 |
|
|
169 |
|
* isCancelled, join, get, and getNow |
170 |
|
*/ |
171 |
|
public void testComplete() { |
172 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
172 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
173 |
|
checkIncomplete(f); |
174 |
|
f.complete(one); |
175 |
|
checkCompletedNormally(f, one); |
180 |
|
* methods isDone, isCancelled, join, get, and getNow |
181 |
|
*/ |
182 |
|
public void testCompleteExceptionally() { |
183 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
183 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
184 |
|
checkIncomplete(f); |
185 |
|
f.completeExceptionally(new CFException()); |
186 |
|
checkCompletedWithWrappedCFException(f); |
191 |
|
* methods isDone, isCancelled, join, get, and getNow |
192 |
|
*/ |
193 |
|
public void testCancel() { |
194 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
194 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
195 |
|
checkIncomplete(f); |
196 |
|
assertTrue(f.cancel(true)); |
197 |
|
checkCancelled(f); |
201 |
|
* obtrudeValue forces completion with given value |
202 |
|
*/ |
203 |
|
public void testObtrudeValue() { |
204 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
204 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
205 |
|
checkIncomplete(f); |
206 |
|
f.complete(one); |
207 |
|
checkCompletedNormally(f, one); |
209 |
|
checkCompletedNormally(f, three); |
210 |
|
f.obtrudeValue(two); |
211 |
|
checkCompletedNormally(f, two); |
212 |
< |
f = new CompletableFuture<Integer>(); |
212 |
> |
f = new CompletableFuture<>(); |
213 |
|
f.obtrudeValue(three); |
214 |
|
checkCompletedNormally(f, three); |
215 |
< |
f = new CompletableFuture<Integer>(); |
215 |
> |
f = new CompletableFuture<>(); |
216 |
|
f.completeExceptionally(new CFException()); |
217 |
|
f.obtrudeValue(four); |
218 |
|
checkCompletedNormally(f, four); |
222 |
|
* obtrudeException forces completion with given exception |
223 |
|
*/ |
224 |
|
public void testObtrudeException() { |
225 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
225 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
226 |
|
checkIncomplete(f); |
227 |
|
f.complete(one); |
228 |
|
checkCompletedNormally(f, one); |
229 |
|
f.obtrudeException(new CFException()); |
230 |
|
checkCompletedWithWrappedCFException(f); |
231 |
< |
f = new CompletableFuture<Integer>(); |
231 |
> |
f = new CompletableFuture<>(); |
232 |
|
f.obtrudeException(new CFException()); |
233 |
|
checkCompletedWithWrappedCFException(f); |
234 |
< |
f = new CompletableFuture<Integer>(); |
234 |
> |
f = new CompletableFuture<>(); |
235 |
|
f.completeExceptionally(new CFException()); |
236 |
|
f.obtrudeValue(four); |
237 |
|
checkCompletedNormally(f, four); |
243 |
|
* getNumberOfDependents returns number of dependent tasks |
244 |
|
*/ |
245 |
|
public void testGetNumberOfDependents() { |
246 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
246 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
247 |
|
assertEquals(f.getNumberOfDependents(), 0); |
248 |
|
CompletableFuture g = f.thenRun(new Noop()); |
249 |
|
assertEquals(f.getNumberOfDependents(), 1); |
294 |
|
int value; |
295 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
296 |
|
} |
297 |
< |
static final class AddAction implements BiConsumer<Integer, Integer> { |
297 |
> |
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
298 |
|
int value; |
299 |
|
public void accept(Integer x, Integer y) { |
300 |
< |
value = x.intValue() + y.intValue(); |
300 |
> |
value = x.intValue() - y.intValue(); |
301 |
|
} |
302 |
|
} |
303 |
|
static final class Noop implements Runnable { |
332 |
|
|
333 |
|
static final class CompletableFutureInc |
334 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
335 |
+ |
boolean ran; |
336 |
|
public CompletableFuture<Integer> apply(Integer x) { |
337 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
337 |
> |
ran = true; |
338 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
339 |
|
f.complete(Integer.valueOf(x.intValue() + 1)); |
340 |
|
return f; |
341 |
|
} |
377 |
|
* exception; otherwise with source value |
378 |
|
*/ |
379 |
|
public void testExceptionally() { |
380 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
380 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
381 |
|
ExceptionToInteger r = new ExceptionToInteger(); |
382 |
|
CompletableFuture<Integer> g = f.exceptionally(r); |
383 |
|
f.completeExceptionally(new CFException()); |
384 |
|
checkCompletedNormally(g, three); |
385 |
|
|
386 |
< |
f = new CompletableFuture<Integer>(); |
386 |
> |
f = new CompletableFuture<>(); |
387 |
|
r = new ExceptionToInteger(); |
388 |
|
g = f.exceptionally(r); |
389 |
|
f.complete(one); |
398 |
|
CompletableFuture<Integer> f, g; |
399 |
|
IntegerHandler r; |
400 |
|
|
401 |
< |
f = new CompletableFuture<Integer>(); |
401 |
> |
f = new CompletableFuture<>(); |
402 |
|
f.completeExceptionally(new CFException()); |
403 |
|
g = f.handle(r = new IntegerHandler()); |
404 |
|
assertTrue(r.ran); |
405 |
|
checkCompletedNormally(g, three); |
406 |
|
|
407 |
< |
f = new CompletableFuture<Integer>(); |
407 |
> |
f = new CompletableFuture<>(); |
408 |
|
g = f.handle(r = new IntegerHandler()); |
409 |
|
assertFalse(r.ran); |
410 |
|
f.completeExceptionally(new CFException()); |
411 |
|
checkCompletedNormally(g, three); |
412 |
|
assertTrue(r.ran); |
413 |
|
|
414 |
< |
f = new CompletableFuture<Integer>(); |
414 |
> |
f = new CompletableFuture<>(); |
415 |
|
f.complete(one); |
416 |
|
g = f.handle(r = new IntegerHandler()); |
417 |
|
assertTrue(r.ran); |
418 |
|
checkCompletedNormally(g, two); |
419 |
|
|
420 |
< |
f = new CompletableFuture<Integer>(); |
420 |
> |
f = new CompletableFuture<>(); |
421 |
|
g = f.handle(r = new IntegerHandler()); |
422 |
|
assertFalse(r.ran); |
423 |
|
f.complete(one); |
495 |
|
* thenRun result completes normally after normal completion of source |
496 |
|
*/ |
497 |
|
public void testThenRun() { |
498 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
499 |
< |
Noop r = new Noop(); |
500 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
498 |
> |
CompletableFuture<Integer> f; |
499 |
> |
CompletableFuture<Void> g; |
500 |
> |
Noop r; |
501 |
> |
|
502 |
> |
f = new CompletableFuture<>(); |
503 |
> |
g = f.thenRun(r = new Noop()); |
504 |
|
f.complete(null); |
505 |
|
checkCompletedNormally(g, null); |
506 |
< |
// reordered version |
507 |
< |
f = new CompletableFuture<Integer>(); |
506 |
> |
assertTrue(r.ran); |
507 |
> |
|
508 |
> |
f = new CompletableFuture<>(); |
509 |
|
f.complete(null); |
510 |
< |
r = new Noop(); |
505 |
< |
g = f.thenRun(r); |
510 |
> |
g = f.thenRun(r = new Noop()); |
511 |
|
checkCompletedNormally(g, null); |
512 |
+ |
assertTrue(r.ran); |
513 |
|
} |
514 |
|
|
515 |
|
/** |
517 |
|
* completion of source |
518 |
|
*/ |
519 |
|
public void testThenRun2() { |
520 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
521 |
< |
Noop r = new Noop(); |
522 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
520 |
> |
CompletableFuture<Integer> f; |
521 |
> |
CompletableFuture<Void> g; |
522 |
> |
Noop r; |
523 |
> |
|
524 |
> |
f = new CompletableFuture<>(); |
525 |
> |
g = f.thenRun(r = new Noop()); |
526 |
|
f.completeExceptionally(new CFException()); |
527 |
|
checkCompletedWithWrappedCFException(g); |
528 |
+ |
assertFalse(r.ran); |
529 |
+ |
|
530 |
+ |
f = new CompletableFuture<>(); |
531 |
+ |
f.completeExceptionally(new CFException()); |
532 |
+ |
g = f.thenRun(r = new Noop()); |
533 |
+ |
checkCompletedWithWrappedCFException(g); |
534 |
+ |
assertFalse(r.ran); |
535 |
|
} |
536 |
|
|
537 |
|
/** |
538 |
|
* thenRun result completes exceptionally if action does |
539 |
|
*/ |
540 |
|
public void testThenRun3() { |
541 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
542 |
< |
FailingNoop r = new FailingNoop(); |
543 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
541 |
> |
CompletableFuture<Integer> f; |
542 |
> |
CompletableFuture<Void> g; |
543 |
> |
FailingNoop r; |
544 |
> |
|
545 |
> |
f = new CompletableFuture<>(); |
546 |
> |
g = f.thenRun(r = new FailingNoop()); |
547 |
|
f.complete(null); |
548 |
|
checkCompletedWithWrappedCFException(g); |
549 |
+ |
|
550 |
+ |
f = new CompletableFuture<>(); |
551 |
+ |
f.complete(null); |
552 |
+ |
g = f.thenRun(r = new FailingNoop()); |
553 |
+ |
checkCompletedWithWrappedCFException(g); |
554 |
|
} |
555 |
|
|
556 |
|
/** |
557 |
|
* thenRun result completes exceptionally if source cancelled |
558 |
|
*/ |
559 |
|
public void testThenRun4() { |
560 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
561 |
< |
Noop r = new Noop(); |
562 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
560 |
> |
CompletableFuture<Integer> f; |
561 |
> |
CompletableFuture<Void> g; |
562 |
> |
Noop r; |
563 |
> |
|
564 |
> |
f = new CompletableFuture<>(); |
565 |
> |
g = f.thenRun(r = new Noop()); |
566 |
> |
assertTrue(f.cancel(true)); |
567 |
> |
checkCompletedWithWrappedCancellationException(g); |
568 |
> |
|
569 |
> |
f = new CompletableFuture<>(); |
570 |
|
assertTrue(f.cancel(true)); |
571 |
+ |
g = f.thenRun(r = new Noop()); |
572 |
|
checkCompletedWithWrappedCancellationException(g); |
573 |
|
} |
574 |
|
|
576 |
|
* thenApply result completes normally after normal completion of source |
577 |
|
*/ |
578 |
|
public void testThenApply() { |
579 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
579 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
580 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
581 |
|
f.complete(one); |
582 |
|
checkCompletedNormally(g, two); |
587 |
|
* completion of source |
588 |
|
*/ |
589 |
|
public void testThenApply2() { |
590 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
590 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
591 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
592 |
|
f.completeExceptionally(new CFException()); |
593 |
|
checkCompletedWithWrappedCFException(g); |
597 |
|
* thenApply result completes exceptionally if action does |
598 |
|
*/ |
599 |
|
public void testThenApply3() { |
600 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
600 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
601 |
|
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
602 |
|
f.complete(one); |
603 |
|
checkCompletedWithWrappedCFException(g); |
607 |
|
* thenApply result completes exceptionally if source cancelled |
608 |
|
*/ |
609 |
|
public void testThenApply4() { |
610 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
610 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
611 |
|
CompletableFuture<Integer> g = f.thenApply(inc); |
612 |
|
assertTrue(f.cancel(true)); |
613 |
|
checkCompletedWithWrappedCancellationException(g); |
617 |
|
* thenAccept result completes normally after normal completion of source |
618 |
|
*/ |
619 |
|
public void testThenAccept() { |
620 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
620 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
621 |
|
IncAction r = new IncAction(); |
622 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
623 |
|
f.complete(one); |
630 |
|
* completion of source |
631 |
|
*/ |
632 |
|
public void testThenAccept2() { |
633 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
633 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
634 |
|
IncAction r = new IncAction(); |
635 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
636 |
|
f.completeExceptionally(new CFException()); |
641 |
|
* thenAccept result completes exceptionally if action does |
642 |
|
*/ |
643 |
|
public void testThenAccept3() { |
644 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
644 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
645 |
|
FailingConsumer r = new FailingConsumer(); |
646 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
647 |
|
f.complete(one); |
653 |
|
* thenAccept result completes exceptionally if source cancelled |
654 |
|
*/ |
655 |
|
public void testThenAccept4() { |
656 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
656 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
657 |
|
IncAction r = new IncAction(); |
658 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
659 |
|
assertTrue(f.cancel(true)); |
668 |
|
public void testThenCombine() { |
669 |
|
CompletableFuture<Integer> f, g, h; |
670 |
|
|
671 |
< |
f = new CompletableFuture<Integer>(); |
672 |
< |
g = new CompletableFuture<Integer>(); |
671 |
> |
f = new CompletableFuture<>(); |
672 |
> |
g = new CompletableFuture<>(); |
673 |
|
h = f.thenCombine(g, subtract); |
674 |
|
f.complete(3); |
675 |
|
checkIncomplete(h); |
676 |
|
g.complete(1); |
677 |
|
checkCompletedNormally(h, 2); |
678 |
|
|
679 |
< |
f = new CompletableFuture<Integer>(); |
680 |
< |
g = new CompletableFuture<Integer>(); |
679 |
> |
f = new CompletableFuture<>(); |
680 |
> |
g = new CompletableFuture<>(); |
681 |
|
h = f.thenCombine(g, subtract); |
682 |
|
g.complete(1); |
683 |
|
checkIncomplete(h); |
684 |
|
f.complete(3); |
685 |
|
checkCompletedNormally(h, 2); |
686 |
|
|
687 |
< |
f = new CompletableFuture<Integer>(); |
688 |
< |
g = new CompletableFuture<Integer>(); |
687 |
> |
f = new CompletableFuture<>(); |
688 |
> |
g = new CompletableFuture<>(); |
689 |
|
g.complete(1); |
690 |
|
f.complete(3); |
691 |
|
h = f.thenCombine(g, subtract); |
699 |
|
public void testThenCombine2() { |
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.completeExceptionally(new CFException()); |
706 |
|
checkIncomplete(h); |
707 |
|
g.complete(1); |
708 |
|
checkCompletedWithWrappedCFException(h); |
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.completeExceptionally(new CFException()); |
714 |
|
checkIncomplete(h); |
715 |
|
f.complete(3); |
716 |
|
checkCompletedWithWrappedCFException(h); |
717 |
|
|
718 |
< |
f = new CompletableFuture<Integer>(); |
719 |
< |
g = new CompletableFuture<Integer>(); |
718 |
> |
f = new CompletableFuture<>(); |
719 |
> |
g = new CompletableFuture<>(); |
720 |
|
f.complete(3); |
721 |
|
g.completeExceptionally(new CFException()); |
722 |
|
h = f.thenCombine(g, subtract); |
723 |
|
checkCompletedWithWrappedCFException(h); |
724 |
|
|
725 |
< |
f = new CompletableFuture<Integer>(); |
726 |
< |
g = new CompletableFuture<Integer>(); |
725 |
> |
f = new CompletableFuture<>(); |
726 |
> |
g = new CompletableFuture<>(); |
727 |
|
f.completeExceptionally(new CFException()); |
728 |
|
g.complete(3); |
729 |
|
h = f.thenCombine(g, subtract); |
734 |
|
* thenCombine result completes exceptionally if action does |
735 |
|
*/ |
736 |
|
public void testThenCombine3() { |
737 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
738 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
737 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
738 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
739 |
|
FailingBiFunction r = new FailingBiFunction(); |
740 |
|
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
741 |
|
f.complete(one); |
752 |
|
public void testThenCombine4() { |
753 |
|
CompletableFuture<Integer> f, g, h; |
754 |
|
|
755 |
< |
f = new CompletableFuture<Integer>(); |
756 |
< |
g = new CompletableFuture<Integer>(); |
755 |
> |
f = new CompletableFuture<>(); |
756 |
> |
g = new CompletableFuture<>(); |
757 |
|
h = f.thenCombine(g, subtract); |
758 |
|
assertTrue(f.cancel(true)); |
759 |
|
checkIncomplete(h); |
760 |
|
g.complete(1); |
761 |
|
checkCompletedWithWrappedCancellationException(h); |
762 |
|
|
763 |
< |
f = new CompletableFuture<Integer>(); |
764 |
< |
g = new CompletableFuture<Integer>(); |
763 |
> |
f = new CompletableFuture<>(); |
764 |
> |
g = new CompletableFuture<>(); |
765 |
|
h = f.thenCombine(g, subtract); |
766 |
|
assertTrue(g.cancel(true)); |
767 |
|
checkIncomplete(h); |
768 |
|
f.complete(3); |
769 |
|
checkCompletedWithWrappedCancellationException(h); |
770 |
|
|
771 |
< |
f = new CompletableFuture<Integer>(); |
772 |
< |
g = new CompletableFuture<Integer>(); |
771 |
> |
f = new CompletableFuture<>(); |
772 |
> |
g = new CompletableFuture<>(); |
773 |
|
assertTrue(f.cancel(true)); |
774 |
|
assertTrue(g.cancel(true)); |
775 |
|
h = f.thenCombine(g, subtract); |
781 |
|
* completion of sources |
782 |
|
*/ |
783 |
|
public void testThenAcceptBoth() { |
784 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
785 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
786 |
< |
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); |
784 |
> |
CompletableFuture<Integer> f, g; |
785 |
> |
CompletableFuture<Void> h; |
786 |
> |
SubtractAction r; |
787 |
|
|
788 |
< |
r = new AddAction(); |
789 |
< |
f = new CompletableFuture<Integer>(); |
790 |
< |
f.complete(one); |
791 |
< |
f2 = new CompletableFuture<Integer>(); |
792 |
< |
g = f.thenAcceptBoth(f2, r); |
793 |
< |
checkIncomplete(g); |
794 |
< |
f2.complete(two); |
795 |
< |
checkCompletedNormally(g, null); |
796 |
< |
assertEquals(r.value, 3); |
788 |
> |
f = new CompletableFuture<>(); |
789 |
> |
g = new CompletableFuture<>(); |
790 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
791 |
> |
f.complete(3); |
792 |
> |
checkIncomplete(h); |
793 |
> |
g.complete(1); |
794 |
> |
checkCompletedNormally(h, null); |
795 |
> |
assertEquals(r.value, 2); |
796 |
> |
|
797 |
> |
f = new CompletableFuture<>(); |
798 |
> |
g = new CompletableFuture<>(); |
799 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
800 |
> |
g.complete(1); |
801 |
> |
checkIncomplete(h); |
802 |
> |
f.complete(3); |
803 |
> |
checkCompletedNormally(h, null); |
804 |
> |
assertEquals(r.value, 2); |
805 |
> |
|
806 |
> |
f = new CompletableFuture<>(); |
807 |
> |
g = new CompletableFuture<>(); |
808 |
> |
g.complete(1); |
809 |
> |
f.complete(3); |
810 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
811 |
> |
checkCompletedNormally(h, null); |
812 |
> |
assertEquals(r.value, 2); |
813 |
|
} |
814 |
|
|
815 |
|
/** |
817 |
|
* completion of either source |
818 |
|
*/ |
819 |
|
public void testThenAcceptBoth2() { |
820 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
821 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
822 |
< |
AddAction r = new AddAction(); |
823 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
820 |
> |
CompletableFuture<Integer> f, g; |
821 |
> |
CompletableFuture<Void> h; |
822 |
> |
SubtractAction r; |
823 |
> |
|
824 |
> |
f = new CompletableFuture<>(); |
825 |
> |
g = new CompletableFuture<>(); |
826 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
827 |
|
f.completeExceptionally(new CFException()); |
828 |
< |
f2.complete(two); |
829 |
< |
checkCompletedWithWrappedCFException(g); |
828 |
> |
checkIncomplete(h); |
829 |
> |
g.complete(1); |
830 |
> |
checkCompletedWithWrappedCFException(h); |
831 |
|
|
832 |
< |
r = new AddAction(); |
833 |
< |
f = new CompletableFuture<Integer>(); |
834 |
< |
f.complete(one); |
835 |
< |
f2 = new CompletableFuture<Integer>(); |
836 |
< |
g = f.thenAcceptBoth(f2, r); |
837 |
< |
f2.completeExceptionally(new CFException()); |
838 |
< |
checkCompletedWithWrappedCFException(g); |
832 |
> |
f = new CompletableFuture<>(); |
833 |
> |
g = new CompletableFuture<>(); |
834 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
835 |
> |
g.completeExceptionally(new CFException()); |
836 |
> |
checkIncomplete(h); |
837 |
> |
f.complete(3); |
838 |
> |
checkCompletedWithWrappedCFException(h); |
839 |
> |
|
840 |
> |
f = new CompletableFuture<>(); |
841 |
> |
g = new CompletableFuture<>(); |
842 |
> |
f.complete(3); |
843 |
> |
g.completeExceptionally(new CFException()); |
844 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
845 |
> |
checkCompletedWithWrappedCFException(h); |
846 |
> |
|
847 |
> |
f = new CompletableFuture<>(); |
848 |
> |
g = new CompletableFuture<>(); |
849 |
> |
f.completeExceptionally(new CFException()); |
850 |
> |
g.complete(3); |
851 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
852 |
> |
checkCompletedWithWrappedCFException(h); |
853 |
|
} |
854 |
|
|
855 |
|
/** |
856 |
|
* thenAcceptBoth result completes exceptionally if action does |
857 |
|
*/ |
858 |
|
public void testThenAcceptBoth3() { |
859 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
860 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
861 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
862 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
863 |
< |
f.complete(one); |
864 |
< |
checkIncomplete(g); |
865 |
< |
f2.complete(two); |
866 |
< |
checkCompletedWithWrappedCFException(g); |
859 |
> |
CompletableFuture<Integer> f, g; |
860 |
> |
CompletableFuture<Void> h; |
861 |
> |
FailingBiConsumer r; |
862 |
> |
|
863 |
> |
f = new CompletableFuture<>(); |
864 |
> |
g = new CompletableFuture<>(); |
865 |
> |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
866 |
> |
f.complete(3); |
867 |
> |
checkIncomplete(h); |
868 |
> |
g.complete(1); |
869 |
> |
checkCompletedWithWrappedCFException(h); |
870 |
> |
|
871 |
> |
f = new CompletableFuture<>(); |
872 |
> |
g = new CompletableFuture<>(); |
873 |
> |
f.complete(3); |
874 |
> |
g.complete(1); |
875 |
> |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
876 |
> |
checkCompletedWithWrappedCFException(h); |
877 |
|
} |
878 |
|
|
879 |
|
/** |
880 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
881 |
|
*/ |
882 |
|
public void testThenAcceptBoth4() { |
883 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
884 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
885 |
< |
AddAction r = new AddAction(); |
886 |
< |
CompletableFuture<Void> g = f.thenAcceptBoth(f2, r); |
883 |
> |
CompletableFuture<Integer> f, g; |
884 |
> |
CompletableFuture<Void> h; |
885 |
> |
SubtractAction r; |
886 |
> |
|
887 |
> |
f = new CompletableFuture<>(); |
888 |
> |
g = new CompletableFuture<>(); |
889 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
890 |
|
assertTrue(f.cancel(true)); |
891 |
< |
f2.complete(two); |
892 |
< |
checkCompletedWithWrappedCancellationException(g); |
893 |
< |
f = new CompletableFuture<Integer>(); |
894 |
< |
f2 = new CompletableFuture<Integer>(); |
895 |
< |
r = new AddAction(); |
896 |
< |
g = f.thenAcceptBoth(f2, r); |
897 |
< |
f.complete(one); |
898 |
< |
assertTrue(f2.cancel(true)); |
899 |
< |
checkCompletedWithWrappedCancellationException(g); |
891 |
> |
checkIncomplete(h); |
892 |
> |
g.complete(1); |
893 |
> |
checkCompletedWithWrappedCancellationException(h); |
894 |
> |
|
895 |
> |
f = new CompletableFuture<>(); |
896 |
> |
g = new CompletableFuture<>(); |
897 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
898 |
> |
assertTrue(g.cancel(true)); |
899 |
> |
checkIncomplete(h); |
900 |
> |
f.complete(3); |
901 |
> |
checkCompletedWithWrappedCancellationException(h); |
902 |
> |
|
903 |
> |
f = new CompletableFuture<>(); |
904 |
> |
g = new CompletableFuture<>(); |
905 |
> |
f.complete(3); |
906 |
> |
assertTrue(g.cancel(true)); |
907 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
908 |
> |
checkCompletedWithWrappedCancellationException(h); |
909 |
> |
|
910 |
> |
f = new CompletableFuture<>(); |
911 |
> |
g = new CompletableFuture<>(); |
912 |
> |
assertTrue(f.cancel(true)); |
913 |
> |
g.complete(3); |
914 |
> |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
915 |
> |
checkCompletedWithWrappedCancellationException(h); |
916 |
|
} |
917 |
|
|
918 |
|
/** |
920 |
|
* completion of sources |
921 |
|
*/ |
922 |
|
public void testRunAfterBoth() { |
923 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
924 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
925 |
< |
Noop r = new Noop(); |
926 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
927 |
< |
f.complete(one); |
928 |
< |
checkIncomplete(g); |
929 |
< |
f2.complete(two); |
930 |
< |
checkCompletedNormally(g, null); |
923 |
> |
CompletableFuture<Integer> f, g; |
924 |
> |
CompletableFuture<Void> h; |
925 |
> |
Noop r; |
926 |
> |
|
927 |
> |
f = new CompletableFuture<>(); |
928 |
> |
g = new CompletableFuture<>(); |
929 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
930 |
> |
f.complete(3); |
931 |
> |
checkIncomplete(h); |
932 |
> |
g.complete(1); |
933 |
> |
checkCompletedNormally(h, null); |
934 |
|
assertTrue(r.ran); |
935 |
|
|
936 |
< |
r = new Noop(); |
937 |
< |
f = new CompletableFuture<Integer>(); |
938 |
< |
f.complete(one); |
939 |
< |
f2 = new CompletableFuture<Integer>(); |
940 |
< |
g = f.runAfterBoth(f2, r); |
941 |
< |
checkIncomplete(g); |
942 |
< |
f2.complete(two); |
943 |
< |
checkCompletedNormally(g, null); |
936 |
> |
f = new CompletableFuture<>(); |
937 |
> |
g = new CompletableFuture<>(); |
938 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
939 |
> |
g.complete(1); |
940 |
> |
checkIncomplete(h); |
941 |
> |
f.complete(3); |
942 |
> |
checkCompletedNormally(h, null); |
943 |
> |
assertTrue(r.ran); |
944 |
> |
|
945 |
> |
f = new CompletableFuture<>(); |
946 |
> |
g = new CompletableFuture<>(); |
947 |
> |
g.complete(1); |
948 |
> |
f.complete(3); |
949 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
950 |
> |
checkCompletedNormally(h, null); |
951 |
|
assertTrue(r.ran); |
952 |
|
} |
953 |
|
|
956 |
|
* completion of either source |
957 |
|
*/ |
958 |
|
public void testRunAfterBoth2() { |
959 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
960 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
961 |
< |
Noop r = new Noop(); |
962 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
959 |
> |
CompletableFuture<Integer> f, g; |
960 |
> |
CompletableFuture<Void> h; |
961 |
> |
Noop r; |
962 |
> |
|
963 |
> |
f = new CompletableFuture<>(); |
964 |
> |
g = new CompletableFuture<>(); |
965 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
966 |
|
f.completeExceptionally(new CFException()); |
967 |
< |
f2.complete(two); |
968 |
< |
checkCompletedWithWrappedCFException(g); |
967 |
> |
checkIncomplete(h); |
968 |
> |
g.complete(1); |
969 |
> |
checkCompletedWithWrappedCFException(h); |
970 |
> |
assertFalse(r.ran); |
971 |
|
|
972 |
< |
r = new Noop(); |
973 |
< |
f = new CompletableFuture<Integer>(); |
974 |
< |
f.complete(one); |
975 |
< |
f2 = new CompletableFuture<Integer>(); |
976 |
< |
g = f.runAfterBoth(f2, r); |
977 |
< |
f2.completeExceptionally(new CFException()); |
978 |
< |
checkCompletedWithWrappedCFException(g); |
972 |
> |
f = new CompletableFuture<>(); |
973 |
> |
g = new CompletableFuture<>(); |
974 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
975 |
> |
g.completeExceptionally(new CFException()); |
976 |
> |
checkIncomplete(h); |
977 |
> |
f.complete(3); |
978 |
> |
checkCompletedWithWrappedCFException(h); |
979 |
> |
assertFalse(r.ran); |
980 |
> |
|
981 |
> |
f = new CompletableFuture<>(); |
982 |
> |
g = new CompletableFuture<>(); |
983 |
> |
g.completeExceptionally(new CFException()); |
984 |
> |
f.complete(3); |
985 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
986 |
> |
checkCompletedWithWrappedCFException(h); |
987 |
> |
assertFalse(r.ran); |
988 |
> |
|
989 |
> |
f = new CompletableFuture<>(); |
990 |
> |
g = new CompletableFuture<>(); |
991 |
> |
f.completeExceptionally(new CFException()); |
992 |
> |
g.complete(1); |
993 |
> |
h = f.runAfterBoth(g, r = new Noop()); |
994 |
> |
checkCompletedWithWrappedCFException(h); |
995 |
> |
assertFalse(r.ran); |
996 |
|
} |
997 |
|
|
998 |
|
/** |
999 |
|
* runAfterBoth result completes exceptionally if action does |
1000 |
|
*/ |
1001 |
|
public void testRunAfterBoth3() { |
1002 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1003 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1002 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1003 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1004 |
|
FailingNoop r = new FailingNoop(); |
1005 |
|
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1006 |
|
f.complete(one); |
1013 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1014 |
|
*/ |
1015 |
|
public void testRunAfterBoth4() { |
1016 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1017 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1016 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1017 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1018 |
|
Noop r = new Noop(); |
1019 |
|
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1020 |
|
assertTrue(f.cancel(true)); |
1021 |
|
f2.complete(two); |
1022 |
|
checkCompletedWithWrappedCancellationException(g); |
1023 |
< |
f = new CompletableFuture<Integer>(); |
1024 |
< |
f2 = new CompletableFuture<Integer>(); |
1023 |
> |
f = new CompletableFuture<>(); |
1024 |
> |
f2 = new CompletableFuture<>(); |
1025 |
|
r = new Noop(); |
1026 |
|
g = f.runAfterBoth(f2, r); |
1027 |
|
f.complete(one); |
1034 |
|
* of either source |
1035 |
|
*/ |
1036 |
|
public void testApplyToEither() { |
1037 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1038 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1037 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1038 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1039 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1040 |
|
f.complete(one); |
1041 |
|
checkCompletedNormally(g, two); |
1042 |
|
f2.complete(one); |
1043 |
|
checkCompletedNormally(g, two); |
1044 |
|
|
1045 |
< |
f = new CompletableFuture<Integer>(); |
1045 |
> |
f = new CompletableFuture<>(); |
1046 |
|
f.complete(one); |
1047 |
< |
f2 = new CompletableFuture<Integer>(); |
1047 |
> |
f2 = new CompletableFuture<>(); |
1048 |
|
g = f.applyToEither(f2, inc); |
1049 |
|
checkCompletedNormally(g, two); |
1050 |
|
} |
1054 |
|
* completion of either source |
1055 |
|
*/ |
1056 |
|
public void testApplyToEither2() { |
1057 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1058 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1057 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1058 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1059 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1060 |
|
f.completeExceptionally(new CFException()); |
1061 |
|
f2.complete(one); |
1062 |
|
checkCompletedWithWrappedCFException(g); |
1063 |
|
|
1064 |
< |
f = new CompletableFuture<Integer>(); |
1065 |
< |
f2 = new CompletableFuture<Integer>(); |
1064 |
> |
f = new CompletableFuture<>(); |
1065 |
> |
f2 = new CompletableFuture<>(); |
1066 |
|
f2.completeExceptionally(new CFException()); |
1067 |
|
g = f.applyToEither(f2, inc); |
1068 |
|
checkCompletedWithWrappedCFException(g); |
1072 |
|
* applyToEither result completes exceptionally if action does |
1073 |
|
*/ |
1074 |
|
public void testApplyToEither3() { |
1075 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1076 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1075 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1076 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1077 |
|
FailingFunction r = new FailingFunction(); |
1078 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, r); |
1079 |
|
f2.complete(two); |
1084 |
|
* applyToEither result completes exceptionally if either source cancelled |
1085 |
|
*/ |
1086 |
|
public void testApplyToEither4() { |
1087 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1088 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1087 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1088 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1089 |
|
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1090 |
|
assertTrue(f.cancel(true)); |
1091 |
|
checkCompletedWithWrappedCancellationException(g); |
1092 |
< |
f = new CompletableFuture<Integer>(); |
1093 |
< |
f2 = new CompletableFuture<Integer>(); |
1092 |
> |
f = new CompletableFuture<>(); |
1093 |
> |
f2 = new CompletableFuture<>(); |
1094 |
|
assertTrue(f2.cancel(true)); |
1095 |
|
checkCompletedWithWrappedCancellationException(g); |
1096 |
|
} |
1100 |
|
* of either source |
1101 |
|
*/ |
1102 |
|
public void testAcceptEither() { |
1103 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1104 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1103 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1104 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1105 |
|
IncAction r = new IncAction(); |
1106 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1107 |
|
f.complete(one); |
1111 |
|
assertEquals(r.value, 2); |
1112 |
|
|
1113 |
|
r = new IncAction(); |
1114 |
< |
f = new CompletableFuture<Integer>(); |
1114 |
> |
f = new CompletableFuture<>(); |
1115 |
|
f.complete(one); |
1116 |
< |
f2 = new CompletableFuture<Integer>(); |
1116 |
> |
f2 = new CompletableFuture<>(); |
1117 |
|
g = f.acceptEither(f2, r); |
1118 |
|
checkCompletedNormally(g, null); |
1119 |
|
assertEquals(r.value, 2); |
1124 |
|
* completion of either source |
1125 |
|
*/ |
1126 |
|
public void testAcceptEither2() { |
1127 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1128 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1127 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1128 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1129 |
|
IncAction r = new IncAction(); |
1130 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1131 |
|
f.completeExceptionally(new CFException()); |
1133 |
|
checkCompletedWithWrappedCFException(g); |
1134 |
|
|
1135 |
|
r = new IncAction(); |
1136 |
< |
f = new CompletableFuture<Integer>(); |
1137 |
< |
f2 = new CompletableFuture<Integer>(); |
1136 |
> |
f = new CompletableFuture<>(); |
1137 |
> |
f2 = new CompletableFuture<>(); |
1138 |
|
f2.completeExceptionally(new CFException()); |
1139 |
|
g = f.acceptEither(f2, r); |
1140 |
|
checkCompletedWithWrappedCFException(g); |
1144 |
|
* acceptEither result completes exceptionally if action does |
1145 |
|
*/ |
1146 |
|
public void testAcceptEither3() { |
1147 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1148 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1147 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1148 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1149 |
|
FailingConsumer r = new FailingConsumer(); |
1150 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1151 |
|
f2.complete(two); |
1156 |
|
* acceptEither result completes exceptionally if either source cancelled |
1157 |
|
*/ |
1158 |
|
public void testAcceptEither4() { |
1159 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1160 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1159 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1160 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1161 |
|
IncAction r = new IncAction(); |
1162 |
|
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1163 |
|
assertTrue(f.cancel(true)); |
1164 |
|
checkCompletedWithWrappedCancellationException(g); |
1165 |
< |
f = new CompletableFuture<Integer>(); |
1166 |
< |
f2 = new CompletableFuture<Integer>(); |
1165 |
> |
f = new CompletableFuture<>(); |
1166 |
> |
f2 = new CompletableFuture<>(); |
1167 |
|
assertTrue(f2.cancel(true)); |
1168 |
|
checkCompletedWithWrappedCancellationException(g); |
1169 |
|
} |
1174 |
|
* of either source |
1175 |
|
*/ |
1176 |
|
public void testRunAfterEither() { |
1177 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1178 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1177 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1178 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1179 |
|
Noop r = new Noop(); |
1180 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1181 |
|
f.complete(one); |
1185 |
|
assertTrue(r.ran); |
1186 |
|
|
1187 |
|
r = new Noop(); |
1188 |
< |
f = new CompletableFuture<Integer>(); |
1188 |
> |
f = new CompletableFuture<>(); |
1189 |
|
f.complete(one); |
1190 |
< |
f2 = new CompletableFuture<Integer>(); |
1190 |
> |
f2 = new CompletableFuture<>(); |
1191 |
|
g = f.runAfterEither(f2, r); |
1192 |
|
checkCompletedNormally(g, null); |
1193 |
|
assertTrue(r.ran); |
1198 |
|
* completion of either source |
1199 |
|
*/ |
1200 |
|
public void testRunAfterEither2() { |
1201 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1202 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1201 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1202 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1203 |
|
Noop r = new Noop(); |
1204 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1205 |
|
f.completeExceptionally(new CFException()); |
1207 |
|
checkCompletedWithWrappedCFException(g); |
1208 |
|
|
1209 |
|
r = new Noop(); |
1210 |
< |
f = new CompletableFuture<Integer>(); |
1211 |
< |
f2 = new CompletableFuture<Integer>(); |
1210 |
> |
f = new CompletableFuture<>(); |
1211 |
> |
f2 = new CompletableFuture<>(); |
1212 |
|
f2.completeExceptionally(new CFException()); |
1213 |
|
g = f.runAfterEither(f2, r); |
1214 |
|
checkCompletedWithWrappedCFException(g); |
1218 |
|
* runAfterEither result completes exceptionally if action does |
1219 |
|
*/ |
1220 |
|
public void testRunAfterEither3() { |
1221 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1222 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1221 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1222 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1223 |
|
FailingNoop r = new FailingNoop(); |
1224 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1225 |
|
f2.complete(two); |
1230 |
|
* runAfterEither result completes exceptionally if either source cancelled |
1231 |
|
*/ |
1232 |
|
public void testRunAfterEither4() { |
1233 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1234 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1233 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1234 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1235 |
|
Noop r = new Noop(); |
1236 |
|
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
1237 |
|
assertTrue(f.cancel(true)); |
1238 |
|
checkCompletedWithWrappedCancellationException(g); |
1239 |
< |
f = new CompletableFuture<Integer>(); |
1240 |
< |
f2 = new CompletableFuture<Integer>(); |
1239 |
> |
f = new CompletableFuture<>(); |
1240 |
> |
f2 = new CompletableFuture<>(); |
1241 |
|
assertTrue(f2.cancel(true)); |
1242 |
|
checkCompletedWithWrappedCancellationException(g); |
1243 |
|
} |
1246 |
|
* thenCompose result completes normally after normal completion of source |
1247 |
|
*/ |
1248 |
|
public void testThenCompose() { |
1249 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1250 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1251 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1249 |
> |
CompletableFuture<Integer> f, g; |
1250 |
> |
CompletableFutureInc r; |
1251 |
> |
|
1252 |
> |
f = new CompletableFuture<>(); |
1253 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1254 |
|
f.complete(one); |
1255 |
|
checkCompletedNormally(g, two); |
1256 |
+ |
assertTrue(r.ran); |
1257 |
+ |
|
1258 |
+ |
f = new CompletableFuture<>(); |
1259 |
+ |
f.complete(one); |
1260 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1261 |
+ |
checkCompletedNormally(g, two); |
1262 |
+ |
assertTrue(r.ran); |
1263 |
|
} |
1264 |
|
|
1265 |
|
/** |
1267 |
|
* completion of source |
1268 |
|
*/ |
1269 |
|
public void testThenCompose2() { |
1270 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1271 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1272 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1270 |
> |
CompletableFuture<Integer> f, g; |
1271 |
> |
CompletableFutureInc r; |
1272 |
> |
|
1273 |
> |
f = new CompletableFuture<>(); |
1274 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1275 |
> |
f.completeExceptionally(new CFException()); |
1276 |
> |
checkCompletedWithWrappedCFException(g); |
1277 |
> |
|
1278 |
> |
f = new CompletableFuture<>(); |
1279 |
|
f.completeExceptionally(new CFException()); |
1280 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1281 |
|
checkCompletedWithWrappedCFException(g); |
1282 |
|
} |
1283 |
|
|
1285 |
|
* thenCompose result completes exceptionally if action does |
1286 |
|
*/ |
1287 |
|
public void testThenCompose3() { |
1288 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1289 |
< |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
1290 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1288 |
> |
CompletableFuture<Integer> f, g; |
1289 |
> |
FailingCompletableFutureFunction r; |
1290 |
> |
|
1291 |
> |
f = new CompletableFuture<>(); |
1292 |
> |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
1293 |
> |
f.complete(one); |
1294 |
> |
checkCompletedWithWrappedCFException(g); |
1295 |
> |
|
1296 |
> |
f = new CompletableFuture<>(); |
1297 |
|
f.complete(one); |
1298 |
+ |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
1299 |
|
checkCompletedWithWrappedCFException(g); |
1300 |
|
} |
1301 |
|
|
1303 |
|
* thenCompose result completes exceptionally if source cancelled |
1304 |
|
*/ |
1305 |
|
public void testThenCompose4() { |
1306 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1307 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
1308 |
< |
CompletableFuture<Integer> g = f.thenCompose(r); |
1306 |
> |
CompletableFuture<Integer> f, g; |
1307 |
> |
CompletableFutureInc r; |
1308 |
> |
|
1309 |
> |
f = new CompletableFuture<>(); |
1310 |
> |
g = f.thenCompose(r = new CompletableFutureInc()); |
1311 |
|
assertTrue(f.cancel(true)); |
1312 |
|
checkCompletedWithWrappedCancellationException(g); |
1313 |
+ |
|
1314 |
+ |
f = new CompletableFuture<>(); |
1315 |
+ |
assertTrue(f.cancel(true)); |
1316 |
+ |
g = f.thenCompose(r = new CompletableFutureInc()); |
1317 |
+ |
checkCompletedWithWrappedCancellationException(g); |
1318 |
|
} |
1319 |
|
|
1320 |
|
|
1324 |
|
* thenRunAsync result completes normally after normal completion of source |
1325 |
|
*/ |
1326 |
|
public void testThenRunAsync() { |
1327 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1327 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1328 |
|
Noop r = new Noop(); |
1329 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1330 |
|
f.complete(null); |
1331 |
|
checkCompletedNormally(g, null); |
1332 |
|
|
1333 |
|
// reordered version |
1334 |
< |
f = new CompletableFuture<Integer>(); |
1334 |
> |
f = new CompletableFuture<>(); |
1335 |
|
f.complete(null); |
1336 |
|
r = new Noop(); |
1337 |
|
g = f.thenRunAsync(r); |
1343 |
|
* completion of source |
1344 |
|
*/ |
1345 |
|
public void testThenRunAsync2() { |
1346 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1346 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1347 |
|
Noop r = new Noop(); |
1348 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1349 |
|
f.completeExceptionally(new CFException()); |
1359 |
|
* thenRunAsync result completes exceptionally if action does |
1360 |
|
*/ |
1361 |
|
public void testThenRunAsync3() { |
1362 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1362 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1363 |
|
FailingNoop r = new FailingNoop(); |
1364 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1365 |
|
f.complete(null); |
1370 |
|
* thenRunAsync result completes exceptionally if source cancelled |
1371 |
|
*/ |
1372 |
|
public void testThenRunAsync4() { |
1373 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1373 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1374 |
|
Noop r = new Noop(); |
1375 |
|
CompletableFuture<Void> g = f.thenRunAsync(r); |
1376 |
|
assertTrue(f.cancel(true)); |
1381 |
|
* thenApplyAsync result completes normally after normal completion of source |
1382 |
|
*/ |
1383 |
|
public void testThenApplyAsync() { |
1384 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1384 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1385 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1386 |
|
f.complete(one); |
1387 |
|
checkCompletedNormally(g, two); |
1392 |
|
* completion of source |
1393 |
|
*/ |
1394 |
|
public void testThenApplyAsync2() { |
1395 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1395 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1396 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1397 |
|
f.completeExceptionally(new CFException()); |
1398 |
|
checkCompletedWithWrappedCFException(g); |
1402 |
|
* thenApplyAsync result completes exceptionally if action does |
1403 |
|
*/ |
1404 |
|
public void testThenApplyAsync3() { |
1405 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1405 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1406 |
|
FailingFunction r = new FailingFunction(); |
1407 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
1408 |
|
f.complete(null); |
1413 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
1414 |
|
*/ |
1415 |
|
public void testThenApplyAsync4() { |
1416 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1416 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1417 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
1418 |
|
assertTrue(f.cancel(true)); |
1419 |
|
checkCompletedWithWrappedCancellationException(g); |
1424 |
|
* completion of source |
1425 |
|
*/ |
1426 |
|
public void testThenAcceptAsync() { |
1427 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1427 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1428 |
|
IncAction r = new IncAction(); |
1429 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1430 |
|
f.complete(one); |
1437 |
|
* completion of source |
1438 |
|
*/ |
1439 |
|
public void testThenAcceptAsync2() { |
1440 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1440 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1441 |
|
IncAction r = new IncAction(); |
1442 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1443 |
|
f.completeExceptionally(new CFException()); |
1448 |
|
* thenAcceptAsync result completes exceptionally if action does |
1449 |
|
*/ |
1450 |
|
public void testThenAcceptAsync3() { |
1451 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1451 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1452 |
|
FailingConsumer r = new FailingConsumer(); |
1453 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1454 |
|
f.complete(null); |
1459 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
1460 |
|
*/ |
1461 |
|
public void testThenAcceptAsync4() { |
1462 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1462 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1463 |
|
IncAction r = new IncAction(); |
1464 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
1465 |
|
assertTrue(f.cancel(true)); |
1473 |
|
public void testThenCombineAsync() { |
1474 |
|
CompletableFuture<Integer> f, g, h; |
1475 |
|
|
1476 |
< |
f = new CompletableFuture<Integer>(); |
1477 |
< |
g = new CompletableFuture<Integer>(); |
1476 |
> |
f = new CompletableFuture<>(); |
1477 |
> |
g = new CompletableFuture<>(); |
1478 |
|
h = f.thenCombineAsync(g, subtract); |
1479 |
|
f.complete(3); |
1480 |
|
checkIncomplete(h); |
1481 |
|
g.complete(1); |
1482 |
|
checkCompletedNormally(h, 2); |
1483 |
|
|
1484 |
< |
f = new CompletableFuture<Integer>(); |
1485 |
< |
g = new CompletableFuture<Integer>(); |
1484 |
> |
f = new CompletableFuture<>(); |
1485 |
> |
g = new CompletableFuture<>(); |
1486 |
|
h = f.thenCombineAsync(g, subtract); |
1487 |
|
g.complete(1); |
1488 |
|
checkIncomplete(h); |
1489 |
|
f.complete(3); |
1490 |
|
checkCompletedNormally(h, 2); |
1491 |
|
|
1492 |
< |
f = new CompletableFuture<Integer>(); |
1493 |
< |
g = new CompletableFuture<Integer>(); |
1492 |
> |
f = new CompletableFuture<>(); |
1493 |
> |
g = new CompletableFuture<>(); |
1494 |
|
g.complete(1); |
1495 |
|
f.complete(3); |
1496 |
|
h = f.thenCombineAsync(g, subtract); |
1504 |
|
public void testThenCombineAsync2() { |
1505 |
|
CompletableFuture<Integer> f, g, h; |
1506 |
|
|
1507 |
< |
f = new CompletableFuture<Integer>(); |
1508 |
< |
g = new CompletableFuture<Integer>(); |
1507 |
> |
f = new CompletableFuture<>(); |
1508 |
> |
g = new CompletableFuture<>(); |
1509 |
|
h = f.thenCombineAsync(g, subtract); |
1510 |
|
f.completeExceptionally(new CFException()); |
1511 |
|
checkIncomplete(h); |
1512 |
|
g.complete(1); |
1513 |
|
checkCompletedWithWrappedCFException(h); |
1514 |
|
|
1515 |
< |
f = new CompletableFuture<Integer>(); |
1516 |
< |
g = new CompletableFuture<Integer>(); |
1515 |
> |
f = new CompletableFuture<>(); |
1516 |
> |
g = new CompletableFuture<>(); |
1517 |
|
h = f.thenCombineAsync(g, subtract); |
1518 |
|
g.completeExceptionally(new CFException()); |
1519 |
|
checkIncomplete(h); |
1520 |
|
f.complete(3); |
1521 |
|
checkCompletedWithWrappedCFException(h); |
1522 |
|
|
1523 |
< |
f = new CompletableFuture<Integer>(); |
1524 |
< |
g = new CompletableFuture<Integer>(); |
1523 |
> |
f = new CompletableFuture<>(); |
1524 |
> |
g = new CompletableFuture<>(); |
1525 |
|
g.completeExceptionally(new CFException()); |
1526 |
|
f.complete(3); |
1527 |
|
h = f.thenCombineAsync(g, subtract); |
1532 |
|
* thenCombineAsync result completes exceptionally if action does |
1533 |
|
*/ |
1534 |
|
public void testThenCombineAsync3() { |
1535 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1536 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1535 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1536 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1537 |
|
FailingBiFunction r = new FailingBiFunction(); |
1538 |
|
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1539 |
|
f.complete(one); |
1550 |
|
public void testThenCombineAsync4() { |
1551 |
|
CompletableFuture<Integer> f, g, h; |
1552 |
|
|
1553 |
< |
f = new CompletableFuture<Integer>(); |
1554 |
< |
g = new CompletableFuture<Integer>(); |
1553 |
> |
f = new CompletableFuture<>(); |
1554 |
> |
g = new CompletableFuture<>(); |
1555 |
|
h = f.thenCombineAsync(g, subtract); |
1556 |
|
assertTrue(f.cancel(true)); |
1557 |
|
checkIncomplete(h); |
1558 |
|
g.complete(1); |
1559 |
|
checkCompletedWithWrappedCancellationException(h); |
1560 |
|
|
1561 |
< |
f = new CompletableFuture<Integer>(); |
1562 |
< |
g = new CompletableFuture<Integer>(); |
1561 |
> |
f = new CompletableFuture<>(); |
1562 |
> |
g = new CompletableFuture<>(); |
1563 |
|
h = f.thenCombineAsync(g, subtract); |
1564 |
|
assertTrue(g.cancel(true)); |
1565 |
|
checkIncomplete(h); |
1566 |
|
f.complete(3); |
1567 |
|
checkCompletedWithWrappedCancellationException(h); |
1568 |
|
|
1569 |
< |
f = new CompletableFuture<Integer>(); |
1570 |
< |
g = new CompletableFuture<Integer>(); |
1569 |
> |
f = new CompletableFuture<>(); |
1570 |
> |
g = new CompletableFuture<>(); |
1571 |
|
g.complete(3); |
1572 |
|
assertTrue(f.cancel(true)); |
1573 |
|
h = f.thenCombineAsync(g, subtract); |
1574 |
|
checkCompletedWithWrappedCancellationException(h); |
1575 |
|
|
1576 |
< |
f = new CompletableFuture<Integer>(); |
1577 |
< |
g = new CompletableFuture<Integer>(); |
1576 |
> |
f = new CompletableFuture<>(); |
1577 |
> |
g = new CompletableFuture<>(); |
1578 |
|
f.complete(3); |
1579 |
|
assertTrue(g.cancel(true)); |
1580 |
|
h = f.thenCombineAsync(g, subtract); |
1586 |
|
* completion of sources |
1587 |
|
*/ |
1588 |
|
public void testThenAcceptBothAsync() { |
1589 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1590 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1591 |
< |
AddAction r = new AddAction(); |
1592 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1593 |
< |
f.complete(one); |
1594 |
< |
checkIncomplete(g); |
1595 |
< |
f2.complete(two); |
1596 |
< |
checkCompletedNormally(g, null); |
1597 |
< |
assertEquals(r.value, 3); |
1589 |
> |
CompletableFuture<Integer> f, g; |
1590 |
> |
CompletableFuture<Void> h; |
1591 |
> |
SubtractAction r; |
1592 |
> |
|
1593 |
> |
f = new CompletableFuture<>(); |
1594 |
> |
g = new CompletableFuture<>(); |
1595 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1596 |
> |
f.complete(3); |
1597 |
> |
checkIncomplete(h); |
1598 |
> |
g.complete(1); |
1599 |
> |
checkCompletedNormally(h, null); |
1600 |
> |
assertEquals(r.value, 2); |
1601 |
> |
|
1602 |
> |
f = new CompletableFuture<>(); |
1603 |
> |
g = new CompletableFuture<>(); |
1604 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1605 |
> |
g.complete(1); |
1606 |
> |
checkIncomplete(h); |
1607 |
> |
f.complete(3); |
1608 |
> |
checkCompletedNormally(h, null); |
1609 |
> |
assertEquals(r.value, 2); |
1610 |
> |
|
1611 |
> |
f = new CompletableFuture<>(); |
1612 |
> |
g = new CompletableFuture<>(); |
1613 |
> |
g.complete(1); |
1614 |
> |
f.complete(3); |
1615 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1616 |
> |
checkCompletedNormally(h, null); |
1617 |
> |
assertEquals(r.value, 2); |
1618 |
|
} |
1619 |
|
|
1620 |
|
/** |
1622 |
|
* completion of source |
1623 |
|
*/ |
1624 |
|
public void testThenAcceptBothAsync2() { |
1625 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1626 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1627 |
< |
AddAction r = new AddAction(); |
1628 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1625 |
> |
CompletableFuture<Integer> f, g; |
1626 |
> |
CompletableFuture<Void> h; |
1627 |
> |
SubtractAction r; |
1628 |
> |
|
1629 |
> |
f = new CompletableFuture<>(); |
1630 |
> |
g = new CompletableFuture<>(); |
1631 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1632 |
|
f.completeExceptionally(new CFException()); |
1633 |
< |
f2.complete(two); |
1634 |
< |
checkCompletedWithWrappedCFException(g); |
1633 |
> |
checkIncomplete(h); |
1634 |
> |
g.complete(1); |
1635 |
> |
checkCompletedWithWrappedCFException(h); |
1636 |
|
|
1637 |
< |
r = new AddAction(); |
1638 |
< |
f = new CompletableFuture<Integer>(); |
1639 |
< |
f2 = new CompletableFuture<Integer>(); |
1640 |
< |
g = f.thenAcceptBothAsync(f2, r); |
1641 |
< |
f.complete(one); |
1642 |
< |
f2.completeExceptionally(new CFException()); |
1643 |
< |
checkCompletedWithWrappedCFException(g); |
1637 |
> |
f = new CompletableFuture<>(); |
1638 |
> |
g = new CompletableFuture<>(); |
1639 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1640 |
> |
g.completeExceptionally(new CFException()); |
1641 |
> |
checkIncomplete(h); |
1642 |
> |
f.complete(3); |
1643 |
> |
checkCompletedWithWrappedCFException(h); |
1644 |
> |
|
1645 |
> |
f = new CompletableFuture<>(); |
1646 |
> |
g = new CompletableFuture<>(); |
1647 |
> |
f.complete(3); |
1648 |
> |
g.completeExceptionally(new CFException()); |
1649 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1650 |
> |
checkCompletedWithWrappedCFException(h); |
1651 |
> |
|
1652 |
> |
f = new CompletableFuture<>(); |
1653 |
> |
g = new CompletableFuture<>(); |
1654 |
> |
f.completeExceptionally(new CFException()); |
1655 |
> |
g.complete(3); |
1656 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1657 |
> |
checkCompletedWithWrappedCFException(h); |
1658 |
|
} |
1659 |
|
|
1660 |
|
/** |
1661 |
|
* thenAcceptBothAsync result completes exceptionally if action does |
1662 |
|
*/ |
1663 |
|
public void testThenAcceptBothAsync3() { |
1664 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1665 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1666 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
1667 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1668 |
< |
f.complete(one); |
1669 |
< |
checkIncomplete(g); |
1670 |
< |
f2.complete(two); |
1671 |
< |
checkCompletedWithWrappedCFException(g); |
1664 |
> |
CompletableFuture<Integer> f, g; |
1665 |
> |
CompletableFuture<Void> h; |
1666 |
> |
FailingBiConsumer r; |
1667 |
> |
|
1668 |
> |
f = new CompletableFuture<>(); |
1669 |
> |
g = new CompletableFuture<>(); |
1670 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1671 |
> |
f.complete(3); |
1672 |
> |
checkIncomplete(h); |
1673 |
> |
g.complete(1); |
1674 |
> |
checkCompletedWithWrappedCFException(h); |
1675 |
> |
|
1676 |
> |
f = new CompletableFuture<>(); |
1677 |
> |
g = new CompletableFuture<>(); |
1678 |
> |
f.complete(3); |
1679 |
> |
g.complete(1); |
1680 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1681 |
> |
checkCompletedWithWrappedCFException(h); |
1682 |
|
} |
1683 |
|
|
1684 |
|
/** |
1685 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1686 |
|
*/ |
1687 |
|
public void testThenAcceptBothAsync4() { |
1688 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1689 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1690 |
< |
AddAction r = new AddAction(); |
1691 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1688 |
> |
CompletableFuture<Integer> f, g; |
1689 |
> |
CompletableFuture<Void> h; |
1690 |
> |
SubtractAction r; |
1691 |
> |
|
1692 |
> |
f = new CompletableFuture<>(); |
1693 |
> |
g = new CompletableFuture<>(); |
1694 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1695 |
|
assertTrue(f.cancel(true)); |
1696 |
< |
f2.complete(two); |
1697 |
< |
checkCompletedWithWrappedCancellationException(g); |
1696 |
> |
checkIncomplete(h); |
1697 |
> |
g.complete(1); |
1698 |
> |
checkCompletedWithWrappedCancellationException(h); |
1699 |
|
|
1700 |
< |
r = new AddAction(); |
1701 |
< |
f = new CompletableFuture<Integer>(); |
1702 |
< |
f2 = new CompletableFuture<Integer>(); |
1703 |
< |
g = f.thenAcceptBothAsync(f2, r); |
1704 |
< |
f.complete(one); |
1705 |
< |
assertTrue(f2.cancel(true)); |
1706 |
< |
checkCompletedWithWrappedCancellationException(g); |
1700 |
> |
f = new CompletableFuture<>(); |
1701 |
> |
g = new CompletableFuture<>(); |
1702 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1703 |
> |
assertTrue(g.cancel(true)); |
1704 |
> |
checkIncomplete(h); |
1705 |
> |
f.complete(3); |
1706 |
> |
checkCompletedWithWrappedCancellationException(h); |
1707 |
> |
|
1708 |
> |
f = new CompletableFuture<>(); |
1709 |
> |
g = new CompletableFuture<>(); |
1710 |
> |
f.complete(3); |
1711 |
> |
assertTrue(g.cancel(true)); |
1712 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1713 |
> |
checkCompletedWithWrappedCancellationException(h); |
1714 |
> |
|
1715 |
> |
f = new CompletableFuture<>(); |
1716 |
> |
g = new CompletableFuture<>(); |
1717 |
> |
assertTrue(f.cancel(true)); |
1718 |
> |
g.complete(3); |
1719 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1720 |
> |
checkCompletedWithWrappedCancellationException(h); |
1721 |
|
} |
1722 |
|
|
1723 |
|
/** |
1725 |
|
* completion of sources |
1726 |
|
*/ |
1727 |
|
public void testRunAfterBothAsync() { |
1728 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1729 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1728 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1729 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1730 |
|
Noop r = new Noop(); |
1731 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1732 |
|
f.complete(one); |
1741 |
|
* completion of source |
1742 |
|
*/ |
1743 |
|
public void testRunAfterBothAsync2() { |
1744 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1745 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1744 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1745 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1746 |
|
Noop r = new Noop(); |
1747 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1748 |
|
f.completeExceptionally(new CFException()); |
1750 |
|
checkCompletedWithWrappedCFException(g); |
1751 |
|
|
1752 |
|
r = new Noop(); |
1753 |
< |
f = new CompletableFuture<Integer>(); |
1754 |
< |
f2 = new CompletableFuture<Integer>(); |
1753 |
> |
f = new CompletableFuture<>(); |
1754 |
> |
f2 = new CompletableFuture<>(); |
1755 |
|
g = f.runAfterBothAsync(f2, r); |
1756 |
|
f.complete(one); |
1757 |
|
f2.completeExceptionally(new CFException()); |
1762 |
|
* runAfterBothAsync result completes exceptionally if action does |
1763 |
|
*/ |
1764 |
|
public void testRunAfterBothAsync3() { |
1765 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1766 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1765 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1766 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1767 |
|
FailingNoop r = new FailingNoop(); |
1768 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1769 |
|
f.complete(one); |
1776 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
1777 |
|
*/ |
1778 |
|
public void testRunAfterBothAsync4() { |
1779 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1780 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1779 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1780 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1781 |
|
Noop r = new Noop(); |
1782 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1783 |
|
assertTrue(f.cancel(true)); |
1785 |
|
checkCompletedWithWrappedCancellationException(g); |
1786 |
|
|
1787 |
|
r = new Noop(); |
1788 |
< |
f = new CompletableFuture<Integer>(); |
1789 |
< |
f2 = new CompletableFuture<Integer>(); |
1788 |
> |
f = new CompletableFuture<>(); |
1789 |
> |
f2 = new CompletableFuture<>(); |
1790 |
|
g = f.runAfterBothAsync(f2, r); |
1791 |
|
f.complete(one); |
1792 |
|
assertTrue(f2.cancel(true)); |
1798 |
|
* completion of sources |
1799 |
|
*/ |
1800 |
|
public void testApplyToEitherAsync() { |
1801 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1802 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1801 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1802 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1803 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1804 |
|
f.complete(one); |
1805 |
|
checkCompletedNormally(g, two); |
1806 |
|
|
1807 |
< |
f = new CompletableFuture<Integer>(); |
1807 |
> |
f = new CompletableFuture<>(); |
1808 |
|
f.complete(one); |
1809 |
< |
f2 = new CompletableFuture<Integer>(); |
1809 |
> |
f2 = new CompletableFuture<>(); |
1810 |
|
g = f.applyToEitherAsync(f2, inc); |
1811 |
|
checkCompletedNormally(g, two); |
1812 |
|
} |
1816 |
|
* completion of source |
1817 |
|
*/ |
1818 |
|
public void testApplyToEitherAsync2() { |
1819 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1820 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1819 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1820 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1821 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1822 |
|
f.completeExceptionally(new CFException()); |
1823 |
|
checkCompletedWithWrappedCFException(g); |
1824 |
|
|
1825 |
< |
f = new CompletableFuture<Integer>(); |
1826 |
< |
f2 = new CompletableFuture<Integer>(); |
1825 |
> |
f = new CompletableFuture<>(); |
1826 |
> |
f2 = new CompletableFuture<>(); |
1827 |
|
f2.completeExceptionally(new CFException()); |
1828 |
|
g = f.applyToEitherAsync(f2, inc); |
1829 |
|
f.complete(one); |
1834 |
|
* applyToEitherAsync result completes exceptionally if action does |
1835 |
|
*/ |
1836 |
|
public void testApplyToEitherAsync3() { |
1837 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1838 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1837 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1838 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1839 |
|
FailingFunction r = new FailingFunction(); |
1840 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r); |
1841 |
|
f.complete(one); |
1846 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
1847 |
|
*/ |
1848 |
|
public void testApplyToEitherAsync4() { |
1849 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1850 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1849 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1850 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1851 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1852 |
|
assertTrue(f.cancel(true)); |
1853 |
|
checkCompletedWithWrappedCancellationException(g); |
1854 |
|
|
1855 |
< |
f = new CompletableFuture<Integer>(); |
1856 |
< |
f2 = new CompletableFuture<Integer>(); |
1855 |
> |
f = new CompletableFuture<>(); |
1856 |
> |
f2 = new CompletableFuture<>(); |
1857 |
|
assertTrue(f2.cancel(true)); |
1858 |
|
g = f.applyToEitherAsync(f2, inc); |
1859 |
|
checkCompletedWithWrappedCancellationException(g); |
1864 |
|
* completion of sources |
1865 |
|
*/ |
1866 |
|
public void testAcceptEitherAsync() { |
1867 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1868 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1867 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1868 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1869 |
|
IncAction r = new IncAction(); |
1870 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1871 |
|
f.complete(one); |
1873 |
|
assertEquals(r.value, 2); |
1874 |
|
|
1875 |
|
r = new IncAction(); |
1876 |
< |
f = new CompletableFuture<Integer>(); |
1876 |
> |
f = new CompletableFuture<>(); |
1877 |
|
f.complete(one); |
1878 |
< |
f2 = new CompletableFuture<Integer>(); |
1878 |
> |
f2 = new CompletableFuture<>(); |
1879 |
|
g = f.acceptEitherAsync(f2, r); |
1880 |
|
checkCompletedNormally(g, null); |
1881 |
|
assertEquals(r.value, 2); |
1886 |
|
* completion of source |
1887 |
|
*/ |
1888 |
|
public void testAcceptEitherAsync2() { |
1889 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1890 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1889 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1890 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1891 |
|
IncAction r = new IncAction(); |
1892 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1893 |
|
f.completeExceptionally(new CFException()); |
1894 |
|
checkCompletedWithWrappedCFException(g); |
1895 |
|
|
1896 |
|
r = new IncAction(); |
1897 |
< |
f = new CompletableFuture<Integer>(); |
1898 |
< |
f2 = new CompletableFuture<Integer>(); |
1897 |
> |
f = new CompletableFuture<>(); |
1898 |
> |
f2 = new CompletableFuture<>(); |
1899 |
|
f2.completeExceptionally(new CFException()); |
1900 |
|
g = f.acceptEitherAsync(f2, r); |
1901 |
|
f.complete(one); |
1906 |
|
* acceptEitherAsync result completes exceptionally if action does |
1907 |
|
*/ |
1908 |
|
public void testAcceptEitherAsync3() { |
1909 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1910 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1909 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1910 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1911 |
|
FailingConsumer r = new FailingConsumer(); |
1912 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1913 |
|
f.complete(one); |
1919 |
|
* source cancelled |
1920 |
|
*/ |
1921 |
|
public void testAcceptEitherAsync4() { |
1922 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1923 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1922 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1923 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1924 |
|
IncAction r = new IncAction(); |
1925 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1926 |
|
assertTrue(f.cancel(true)); |
1927 |
|
checkCompletedWithWrappedCancellationException(g); |
1928 |
|
|
1929 |
|
r = new IncAction(); |
1930 |
< |
f = new CompletableFuture<Integer>(); |
1931 |
< |
f2 = new CompletableFuture<Integer>(); |
1930 |
> |
f = new CompletableFuture<>(); |
1931 |
> |
f2 = new CompletableFuture<>(); |
1932 |
|
assertTrue(f2.cancel(true)); |
1933 |
|
g = f.acceptEitherAsync(f2, r); |
1934 |
|
checkCompletedWithWrappedCancellationException(g); |
1939 |
|
* completion of sources |
1940 |
|
*/ |
1941 |
|
public void testRunAfterEitherAsync() { |
1942 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1943 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1942 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1943 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1944 |
|
Noop r = new Noop(); |
1945 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1946 |
|
f.complete(one); |
1948 |
|
assertTrue(r.ran); |
1949 |
|
|
1950 |
|
r = new Noop(); |
1951 |
< |
f = new CompletableFuture<Integer>(); |
1951 |
> |
f = new CompletableFuture<>(); |
1952 |
|
f.complete(one); |
1953 |
< |
f2 = new CompletableFuture<Integer>(); |
1953 |
> |
f2 = new CompletableFuture<>(); |
1954 |
|
g = f.runAfterEitherAsync(f2, r); |
1955 |
|
checkCompletedNormally(g, null); |
1956 |
|
assertTrue(r.ran); |
1961 |
|
* completion of source |
1962 |
|
*/ |
1963 |
|
public void testRunAfterEitherAsync2() { |
1964 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1965 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1964 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1965 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1966 |
|
Noop r = new Noop(); |
1967 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1968 |
|
f.completeExceptionally(new CFException()); |
1969 |
|
checkCompletedWithWrappedCFException(g); |
1970 |
|
|
1971 |
|
r = new Noop(); |
1972 |
< |
f = new CompletableFuture<Integer>(); |
1973 |
< |
f2 = new CompletableFuture<Integer>(); |
1972 |
> |
f = new CompletableFuture<>(); |
1973 |
> |
f2 = new CompletableFuture<>(); |
1974 |
|
f2.completeExceptionally(new CFException()); |
1975 |
|
g = f.runAfterEitherAsync(f2, r); |
1976 |
|
f.complete(one); |
1981 |
|
* runAfterEitherAsync result completes exceptionally if action does |
1982 |
|
*/ |
1983 |
|
public void testRunAfterEitherAsync3() { |
1984 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1985 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1984 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1985 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1986 |
|
FailingNoop r = new FailingNoop(); |
1987 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1988 |
|
f.complete(one); |
1994 |
|
* source cancelled |
1995 |
|
*/ |
1996 |
|
public void testRunAfterEitherAsync4() { |
1997 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1998 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1997 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1998 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1999 |
|
Noop r = new Noop(); |
2000 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2001 |
|
assertTrue(f.cancel(true)); |
2002 |
|
checkCompletedWithWrappedCancellationException(g); |
2003 |
|
|
2004 |
|
r = new Noop(); |
2005 |
< |
f = new CompletableFuture<Integer>(); |
2006 |
< |
f2 = new CompletableFuture<Integer>(); |
2005 |
> |
f = new CompletableFuture<>(); |
2006 |
> |
f2 = new CompletableFuture<>(); |
2007 |
|
assertTrue(f2.cancel(true)); |
2008 |
|
g = f.runAfterEitherAsync(f2, r); |
2009 |
|
checkCompletedWithWrappedCancellationException(g); |
2014 |
|
* completion of source |
2015 |
|
*/ |
2016 |
|
public void testThenComposeAsync() { |
2017 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2018 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2019 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2017 |
> |
CompletableFuture<Integer> f, g; |
2018 |
> |
CompletableFutureInc r; |
2019 |
> |
|
2020 |
> |
f = new CompletableFuture<>(); |
2021 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2022 |
> |
f.complete(one); |
2023 |
> |
checkCompletedNormally(g, two); |
2024 |
> |
|
2025 |
> |
f = new CompletableFuture<>(); |
2026 |
|
f.complete(one); |
2027 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2028 |
|
checkCompletedNormally(g, two); |
2029 |
|
} |
2030 |
|
|
2033 |
|
* exceptional completion of source |
2034 |
|
*/ |
2035 |
|
public void testThenComposeAsync2() { |
2036 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2037 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2038 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2036 |
> |
CompletableFuture<Integer> f, g; |
2037 |
> |
CompletableFutureInc r; |
2038 |
> |
|
2039 |
> |
f = new CompletableFuture<>(); |
2040 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2041 |
|
f.completeExceptionally(new CFException()); |
2042 |
|
checkCompletedWithWrappedCFException(g); |
2043 |
+ |
assertFalse(r.ran); |
2044 |
+ |
|
2045 |
+ |
f = new CompletableFuture<>(); |
2046 |
+ |
f.completeExceptionally(new CFException()); |
2047 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2048 |
+ |
checkCompletedWithWrappedCFException(g); |
2049 |
+ |
assertFalse(r.ran); |
2050 |
|
} |
2051 |
|
|
2052 |
|
/** |
2053 |
|
* thenComposeAsync result completes exceptionally if action does |
2054 |
|
*/ |
2055 |
|
public void testThenComposeAsync3() { |
2056 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2057 |
< |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
2058 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2056 |
> |
CompletableFuture<Integer> f, g; |
2057 |
> |
FailingCompletableFutureFunction r; |
2058 |
> |
|
2059 |
> |
f = new CompletableFuture<>(); |
2060 |
> |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
2061 |
> |
f.complete(one); |
2062 |
> |
checkCompletedWithWrappedCFException(g); |
2063 |
> |
|
2064 |
> |
f = new CompletableFuture<>(); |
2065 |
|
f.complete(one); |
2066 |
+ |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
2067 |
|
checkCompletedWithWrappedCFException(g); |
2068 |
|
} |
2069 |
|
|
2071 |
|
* thenComposeAsync result completes exceptionally if source cancelled |
2072 |
|
*/ |
2073 |
|
public void testThenComposeAsync4() { |
2074 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2075 |
< |
CompletableFutureInc r = new CompletableFutureInc(); |
2076 |
< |
CompletableFuture<Integer> g = f.thenComposeAsync(r); |
2074 |
> |
CompletableFuture<Integer> f, g; |
2075 |
> |
CompletableFutureInc r; |
2076 |
> |
|
2077 |
> |
f = new CompletableFuture<>(); |
2078 |
> |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2079 |
|
assertTrue(f.cancel(true)); |
2080 |
|
checkCompletedWithWrappedCancellationException(g); |
2081 |
+ |
|
2082 |
+ |
f = new CompletableFuture<>(); |
2083 |
+ |
assertTrue(f.cancel(true)); |
2084 |
+ |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2085 |
+ |
checkCompletedWithWrappedCancellationException(g); |
2086 |
|
} |
2087 |
|
|
2088 |
|
|
2092 |
|
* thenRunAsync result completes normally after normal completion of source |
2093 |
|
*/ |
2094 |
|
public void testThenRunAsyncE() { |
2095 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2095 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2096 |
|
Noop r = new Noop(); |
2097 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2098 |
|
f.complete(null); |
2099 |
|
checkCompletedNormally(g, null); |
2100 |
|
|
2101 |
|
// reordered version |
2102 |
< |
f = new CompletableFuture<Integer>(); |
2102 |
> |
f = new CompletableFuture<>(); |
2103 |
|
f.complete(null); |
2104 |
|
r = new Noop(); |
2105 |
|
g = f.thenRunAsync(r, new ThreadExecutor()); |
2111 |
|
* completion of source |
2112 |
|
*/ |
2113 |
|
public void testThenRunAsync2E() { |
2114 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2114 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2115 |
|
Noop r = new Noop(); |
2116 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2117 |
|
f.completeExceptionally(new CFException()); |
2127 |
|
* thenRunAsync result completes exceptionally if action does |
2128 |
|
*/ |
2129 |
|
public void testThenRunAsync3E() { |
2130 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2130 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2131 |
|
FailingNoop r = new FailingNoop(); |
2132 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2133 |
|
f.complete(null); |
2138 |
|
* thenRunAsync result completes exceptionally if source cancelled |
2139 |
|
*/ |
2140 |
|
public void testThenRunAsync4E() { |
2141 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2141 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2142 |
|
Noop r = new Noop(); |
2143 |
|
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
2144 |
|
assertTrue(f.cancel(true)); |
2149 |
|
* thenApplyAsync result completes normally after normal completion of source |
2150 |
|
*/ |
2151 |
|
public void testThenApplyAsyncE() { |
2152 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2152 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2153 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2154 |
|
f.complete(one); |
2155 |
|
checkCompletedNormally(g, two); |
2160 |
|
* completion of source |
2161 |
|
*/ |
2162 |
|
public void testThenApplyAsync2E() { |
2163 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2163 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2164 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2165 |
|
f.completeExceptionally(new CFException()); |
2166 |
|
checkCompletedWithWrappedCFException(g); |
2170 |
|
* thenApplyAsync result completes exceptionally if action does |
2171 |
|
*/ |
2172 |
|
public void testThenApplyAsync3E() { |
2173 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2173 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2174 |
|
FailingFunction r = new FailingFunction(); |
2175 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
2176 |
|
f.complete(null); |
2181 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
2182 |
|
*/ |
2183 |
|
public void testThenApplyAsync4E() { |
2184 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2184 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2185 |
|
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
2186 |
|
assertTrue(f.cancel(true)); |
2187 |
|
checkCompletedWithWrappedCancellationException(g); |
2192 |
|
* completion of source |
2193 |
|
*/ |
2194 |
|
public void testThenAcceptAsyncE() { |
2195 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2195 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2196 |
|
IncAction r = new IncAction(); |
2197 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2198 |
|
f.complete(one); |
2205 |
|
* completion of source |
2206 |
|
*/ |
2207 |
|
public void testThenAcceptAsync2E() { |
2208 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2208 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2209 |
|
IncAction r = new IncAction(); |
2210 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2211 |
|
f.completeExceptionally(new CFException()); |
2216 |
|
* thenAcceptAsync result completes exceptionally if action does |
2217 |
|
*/ |
2218 |
|
public void testThenAcceptAsync3E() { |
2219 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2219 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2220 |
|
FailingConsumer r = new FailingConsumer(); |
2221 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2222 |
|
f.complete(null); |
2227 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
2228 |
|
*/ |
2229 |
|
public void testThenAcceptAsync4E() { |
2230 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2230 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2231 |
|
IncAction r = new IncAction(); |
2232 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
2233 |
|
assertTrue(f.cancel(true)); |
2243 |
|
ThreadExecutor e = new ThreadExecutor(); |
2244 |
|
int count = 0; |
2245 |
|
|
2246 |
< |
f = new CompletableFuture<Integer>(); |
2247 |
< |
g = new CompletableFuture<Integer>(); |
2246 |
> |
f = new CompletableFuture<>(); |
2247 |
> |
g = new CompletableFuture<>(); |
2248 |
|
h = f.thenCombineAsync(g, subtract, e); |
2249 |
|
f.complete(3); |
2250 |
|
checkIncomplete(h); |
2252 |
|
checkCompletedNormally(h, 2); |
2253 |
|
assertEquals(++count, e.count.get()); |
2254 |
|
|
2255 |
< |
f = new CompletableFuture<Integer>(); |
2256 |
< |
g = new CompletableFuture<Integer>(); |
2255 |
> |
f = new CompletableFuture<>(); |
2256 |
> |
g = new CompletableFuture<>(); |
2257 |
|
h = f.thenCombineAsync(g, subtract, e); |
2258 |
|
g.complete(1); |
2259 |
|
checkIncomplete(h); |
2261 |
|
checkCompletedNormally(h, 2); |
2262 |
|
assertEquals(++count, e.count.get()); |
2263 |
|
|
2264 |
< |
f = new CompletableFuture<Integer>(); |
2265 |
< |
g = new CompletableFuture<Integer>(); |
2264 |
> |
f = new CompletableFuture<>(); |
2265 |
> |
g = new CompletableFuture<>(); |
2266 |
|
g.complete(1); |
2267 |
|
f.complete(3); |
2268 |
|
h = f.thenCombineAsync(g, subtract, e); |
2279 |
|
ThreadExecutor e = new ThreadExecutor(); |
2280 |
|
int count = 0; |
2281 |
|
|
2282 |
< |
f = new CompletableFuture<Integer>(); |
2283 |
< |
g = new CompletableFuture<Integer>(); |
2282 |
> |
f = new CompletableFuture<>(); |
2283 |
> |
g = new CompletableFuture<>(); |
2284 |
|
h = f.thenCombineAsync(g, subtract, e); |
2285 |
|
f.completeExceptionally(new CFException()); |
2286 |
|
checkIncomplete(h); |
2287 |
|
g.complete(1); |
2288 |
|
checkCompletedWithWrappedCFException(h); |
2289 |
|
|
2290 |
< |
f = new CompletableFuture<Integer>(); |
2291 |
< |
g = new CompletableFuture<Integer>(); |
2290 |
> |
f = new CompletableFuture<>(); |
2291 |
> |
g = new CompletableFuture<>(); |
2292 |
|
h = f.thenCombineAsync(g, subtract, e); |
2293 |
|
g.completeExceptionally(new CFException()); |
2294 |
|
checkIncomplete(h); |
2295 |
|
f.complete(3); |
2296 |
|
checkCompletedWithWrappedCFException(h); |
2297 |
|
|
2298 |
< |
f = new CompletableFuture<Integer>(); |
2299 |
< |
g = new CompletableFuture<Integer>(); |
2298 |
> |
f = new CompletableFuture<>(); |
2299 |
> |
g = new CompletableFuture<>(); |
2300 |
|
g.completeExceptionally(new CFException()); |
2301 |
|
h = f.thenCombineAsync(g, subtract, e); |
2302 |
|
checkIncomplete(h); |
2310 |
|
* thenCombineAsync result completes exceptionally if action does |
2311 |
|
*/ |
2312 |
|
public void testThenCombineAsync3E() { |
2313 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2314 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2313 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2314 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2315 |
|
FailingBiFunction r = new FailingBiFunction(); |
2316 |
|
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2317 |
|
f.complete(one); |
2329 |
|
CompletableFuture<Integer> f, g, h; |
2330 |
|
ThreadExecutor e = new ThreadExecutor(); |
2331 |
|
|
2332 |
< |
f = new CompletableFuture<Integer>(); |
2333 |
< |
g = new CompletableFuture<Integer>(); |
2332 |
> |
f = new CompletableFuture<>(); |
2333 |
> |
g = new CompletableFuture<>(); |
2334 |
|
h = f.thenCombineAsync(g, subtract, e); |
2335 |
|
assertTrue(f.cancel(true)); |
2336 |
|
checkIncomplete(h); |
2337 |
|
g.complete(1); |
2338 |
|
checkCompletedWithWrappedCancellationException(h); |
2339 |
|
|
2340 |
< |
f = new CompletableFuture<Integer>(); |
2341 |
< |
g = new CompletableFuture<Integer>(); |
2340 |
> |
f = new CompletableFuture<>(); |
2341 |
> |
g = new CompletableFuture<>(); |
2342 |
|
h = f.thenCombineAsync(g, subtract, e); |
2343 |
|
assertTrue(g.cancel(true)); |
2344 |
|
checkIncomplete(h); |
2345 |
|
f.complete(3); |
2346 |
|
checkCompletedWithWrappedCancellationException(h); |
2347 |
|
|
2348 |
< |
f = new CompletableFuture<Integer>(); |
2349 |
< |
g = new CompletableFuture<Integer>(); |
2348 |
> |
f = new CompletableFuture<>(); |
2349 |
> |
g = new CompletableFuture<>(); |
2350 |
|
assertTrue(g.cancel(true)); |
2351 |
|
h = f.thenCombineAsync(g, subtract, e); |
2352 |
|
checkIncomplete(h); |
2353 |
|
f.complete(3); |
2354 |
|
checkCompletedWithWrappedCancellationException(h); |
2355 |
|
|
2356 |
< |
f = new CompletableFuture<Integer>(); |
2357 |
< |
g = new CompletableFuture<Integer>(); |
2356 |
> |
f = new CompletableFuture<>(); |
2357 |
> |
g = new CompletableFuture<>(); |
2358 |
|
assertTrue(f.cancel(true)); |
2359 |
|
assertTrue(g.cancel(true)); |
2360 |
|
h = f.thenCombineAsync(g, subtract, e); |
2368 |
|
* completion of sources |
2369 |
|
*/ |
2370 |
|
public void testThenAcceptBothAsyncE() { |
2371 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2372 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2373 |
< |
AddAction r = new AddAction(); |
2374 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2375 |
< |
f.complete(one); |
2376 |
< |
checkIncomplete(g); |
2377 |
< |
f2.complete(two); |
2378 |
< |
checkCompletedNormally(g, null); |
2379 |
< |
assertEquals(r.value, 3); |
2371 |
> |
CompletableFuture<Integer> f, g; |
2372 |
> |
CompletableFuture<Void> h; |
2373 |
> |
SubtractAction r; |
2374 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2375 |
> |
|
2376 |
> |
f = new CompletableFuture<>(); |
2377 |
> |
g = new CompletableFuture<>(); |
2378 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2379 |
> |
f.complete(3); |
2380 |
> |
checkIncomplete(h); |
2381 |
> |
g.complete(1); |
2382 |
> |
checkCompletedNormally(h, null); |
2383 |
> |
assertEquals(r.value, 2); |
2384 |
> |
|
2385 |
> |
f = new CompletableFuture<>(); |
2386 |
> |
g = new CompletableFuture<>(); |
2387 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2388 |
> |
g.complete(1); |
2389 |
> |
checkIncomplete(h); |
2390 |
> |
f.complete(3); |
2391 |
> |
checkCompletedNormally(h, null); |
2392 |
> |
assertEquals(r.value, 2); |
2393 |
> |
|
2394 |
> |
f = new CompletableFuture<>(); |
2395 |
> |
g = new CompletableFuture<>(); |
2396 |
> |
g.complete(1); |
2397 |
> |
f.complete(3); |
2398 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2399 |
> |
checkCompletedNormally(h, null); |
2400 |
> |
assertEquals(r.value, 2); |
2401 |
> |
|
2402 |
> |
assertEquals(3, e.count.get()); |
2403 |
|
} |
2404 |
|
|
2405 |
|
/** |
2407 |
|
* completion of source |
2408 |
|
*/ |
2409 |
|
public void testThenAcceptBothAsync2E() { |
2410 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2411 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2412 |
< |
AddAction r = new AddAction(); |
2413 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2410 |
> |
CompletableFuture<Integer> f, g; |
2411 |
> |
CompletableFuture<Void> h; |
2412 |
> |
SubtractAction r; |
2413 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2414 |
> |
|
2415 |
> |
f = new CompletableFuture<>(); |
2416 |
> |
g = new CompletableFuture<>(); |
2417 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2418 |
|
f.completeExceptionally(new CFException()); |
2419 |
< |
f2.complete(two); |
2420 |
< |
checkCompletedWithWrappedCFException(g); |
2419 |
> |
checkIncomplete(h); |
2420 |
> |
g.complete(1); |
2421 |
> |
checkCompletedWithWrappedCFException(h); |
2422 |
|
|
2423 |
< |
r = new AddAction(); |
2424 |
< |
f = new CompletableFuture<Integer>(); |
2425 |
< |
f2 = new CompletableFuture<Integer>(); |
2426 |
< |
g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2427 |
< |
f.complete(one); |
2428 |
< |
f2.completeExceptionally(new CFException()); |
2429 |
< |
checkCompletedWithWrappedCFException(g); |
2423 |
> |
f = new CompletableFuture<>(); |
2424 |
> |
g = new CompletableFuture<>(); |
2425 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2426 |
> |
g.completeExceptionally(new CFException()); |
2427 |
> |
checkIncomplete(h); |
2428 |
> |
f.complete(3); |
2429 |
> |
checkCompletedWithWrappedCFException(h); |
2430 |
> |
|
2431 |
> |
f = new CompletableFuture<>(); |
2432 |
> |
g = new CompletableFuture<>(); |
2433 |
> |
f.complete(3); |
2434 |
> |
g.completeExceptionally(new CFException()); |
2435 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2436 |
> |
checkCompletedWithWrappedCFException(h); |
2437 |
> |
|
2438 |
> |
f = new CompletableFuture<>(); |
2439 |
> |
g = new CompletableFuture<>(); |
2440 |
> |
f.completeExceptionally(new CFException()); |
2441 |
> |
g.complete(3); |
2442 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2443 |
> |
checkCompletedWithWrappedCFException(h); |
2444 |
> |
|
2445 |
> |
assertEquals(0, e.count.get()); |
2446 |
|
} |
2447 |
|
|
2448 |
|
/** |
2449 |
|
* thenAcceptBothAsync result completes exceptionally if action does |
2450 |
|
*/ |
2451 |
|
public void testThenAcceptBothAsync3E() { |
2452 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2453 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2454 |
< |
FailingBiConsumer r = new FailingBiConsumer(); |
2455 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2456 |
< |
f.complete(one); |
2457 |
< |
checkIncomplete(g); |
2458 |
< |
f2.complete(two); |
2459 |
< |
checkCompletedWithWrappedCFException(g); |
2452 |
> |
CompletableFuture<Integer> f, g; |
2453 |
> |
CompletableFuture<Void> h; |
2454 |
> |
FailingBiConsumer r; |
2455 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2456 |
> |
|
2457 |
> |
f = new CompletableFuture<>(); |
2458 |
> |
g = new CompletableFuture<>(); |
2459 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2460 |
> |
f.complete(3); |
2461 |
> |
checkIncomplete(h); |
2462 |
> |
g.complete(1); |
2463 |
> |
checkCompletedWithWrappedCFException(h); |
2464 |
> |
|
2465 |
> |
f = new CompletableFuture<>(); |
2466 |
> |
g = new CompletableFuture<>(); |
2467 |
> |
f.complete(3); |
2468 |
> |
g.complete(1); |
2469 |
> |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2470 |
> |
checkCompletedWithWrappedCFException(h); |
2471 |
> |
|
2472 |
> |
assertEquals(2, e.count.get()); |
2473 |
|
} |
2474 |
|
|
2475 |
|
/** |
2476 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2477 |
|
*/ |
2478 |
|
public void testThenAcceptBothAsync4E() { |
2479 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2480 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2481 |
< |
AddAction r = new AddAction(); |
2482 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2479 |
> |
CompletableFuture<Integer> f, g; |
2480 |
> |
CompletableFuture<Void> h; |
2481 |
> |
SubtractAction r; |
2482 |
> |
ThreadExecutor e = new ThreadExecutor(); |
2483 |
> |
|
2484 |
> |
f = new CompletableFuture<>(); |
2485 |
> |
g = new CompletableFuture<>(); |
2486 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2487 |
|
assertTrue(f.cancel(true)); |
2488 |
< |
f2.complete(two); |
2489 |
< |
checkCompletedWithWrappedCancellationException(g); |
2488 |
> |
checkIncomplete(h); |
2489 |
> |
g.complete(1); |
2490 |
> |
checkCompletedWithWrappedCancellationException(h); |
2491 |
|
|
2492 |
< |
r = new AddAction(); |
2493 |
< |
f = new CompletableFuture<Integer>(); |
2494 |
< |
f2 = new CompletableFuture<Integer>(); |
2495 |
< |
g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
2496 |
< |
f.complete(one); |
2497 |
< |
assertTrue(f2.cancel(true)); |
2498 |
< |
checkCompletedWithWrappedCancellationException(g); |
2492 |
> |
f = new CompletableFuture<>(); |
2493 |
> |
g = new CompletableFuture<>(); |
2494 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2495 |
> |
assertTrue(g.cancel(true)); |
2496 |
> |
checkIncomplete(h); |
2497 |
> |
f.complete(3); |
2498 |
> |
checkCompletedWithWrappedCancellationException(h); |
2499 |
> |
|
2500 |
> |
f = new CompletableFuture<>(); |
2501 |
> |
g = new CompletableFuture<>(); |
2502 |
> |
f.complete(3); |
2503 |
> |
assertTrue(g.cancel(true)); |
2504 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2505 |
> |
checkCompletedWithWrappedCancellationException(h); |
2506 |
> |
|
2507 |
> |
f = new CompletableFuture<>(); |
2508 |
> |
g = new CompletableFuture<>(); |
2509 |
> |
assertTrue(f.cancel(true)); |
2510 |
> |
g.complete(3); |
2511 |
> |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2512 |
> |
checkCompletedWithWrappedCancellationException(h); |
2513 |
> |
|
2514 |
> |
assertEquals(0, e.count.get()); |
2515 |
|
} |
2516 |
|
|
2517 |
|
/** |
2519 |
|
* completion of sources |
2520 |
|
*/ |
2521 |
|
public void testRunAfterBothAsyncE() { |
2522 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2523 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2522 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2523 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2524 |
|
Noop r = new Noop(); |
2525 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2526 |
|
f.complete(one); |
2535 |
|
* completion of source |
2536 |
|
*/ |
2537 |
|
public void testRunAfterBothAsync2E() { |
2538 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2539 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2538 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2539 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2540 |
|
Noop r = new Noop(); |
2541 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2542 |
|
f.completeExceptionally(new CFException()); |
2544 |
|
checkCompletedWithWrappedCFException(g); |
2545 |
|
|
2546 |
|
r = new Noop(); |
2547 |
< |
f = new CompletableFuture<Integer>(); |
2548 |
< |
f2 = new CompletableFuture<Integer>(); |
2547 |
> |
f = new CompletableFuture<>(); |
2548 |
> |
f2 = new CompletableFuture<>(); |
2549 |
|
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2550 |
|
f.complete(one); |
2551 |
|
f2.completeExceptionally(new CFException()); |
2556 |
|
* runAfterBothAsync result completes exceptionally if action does |
2557 |
|
*/ |
2558 |
|
public void testRunAfterBothAsync3E() { |
2559 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2560 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2559 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2560 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2561 |
|
FailingNoop r = new FailingNoop(); |
2562 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2563 |
|
f.complete(one); |
2570 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
2571 |
|
*/ |
2572 |
|
public void testRunAfterBothAsync4E() { |
2573 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2574 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2573 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2574 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2575 |
|
Noop r = new Noop(); |
2576 |
|
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2577 |
|
assertTrue(f.cancel(true)); |
2579 |
|
checkCompletedWithWrappedCancellationException(g); |
2580 |
|
|
2581 |
|
r = new Noop(); |
2582 |
< |
f = new CompletableFuture<Integer>(); |
2583 |
< |
f2 = new CompletableFuture<Integer>(); |
2582 |
> |
f = new CompletableFuture<>(); |
2583 |
> |
f2 = new CompletableFuture<>(); |
2584 |
|
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2585 |
|
f.complete(one); |
2586 |
|
assertTrue(f2.cancel(true)); |
2592 |
|
* completion of sources |
2593 |
|
*/ |
2594 |
|
public void testApplyToEitherAsyncE() { |
2595 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2596 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2595 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2596 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2597 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2598 |
|
f.complete(one); |
2599 |
|
checkCompletedNormally(g, two); |
2600 |
|
|
2601 |
< |
f = new CompletableFuture<Integer>(); |
2601 |
> |
f = new CompletableFuture<>(); |
2602 |
|
f.complete(one); |
2603 |
< |
f2 = new CompletableFuture<Integer>(); |
2603 |
> |
f2 = new CompletableFuture<>(); |
2604 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2605 |
|
checkCompletedNormally(g, two); |
2606 |
|
} |
2610 |
|
* completion of source |
2611 |
|
*/ |
2612 |
|
public void testApplyToEitherAsync2E() { |
2613 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2614 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2613 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2614 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2615 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2616 |
|
f.completeExceptionally(new CFException()); |
2617 |
|
checkCompletedWithWrappedCFException(g); |
2618 |
|
|
2619 |
< |
f = new CompletableFuture<Integer>(); |
2620 |
< |
f2 = new CompletableFuture<Integer>(); |
2619 |
> |
f = new CompletableFuture<>(); |
2620 |
> |
f2 = new CompletableFuture<>(); |
2621 |
|
f2.completeExceptionally(new CFException()); |
2622 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2623 |
|
f.complete(one); |
2628 |
|
* applyToEitherAsync result completes exceptionally if action does |
2629 |
|
*/ |
2630 |
|
public void testApplyToEitherAsync3E() { |
2631 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2632 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2631 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2632 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2633 |
|
FailingFunction r = new FailingFunction(); |
2634 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); |
2635 |
|
f.complete(one); |
2640 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
2641 |
|
*/ |
2642 |
|
public void testApplyToEitherAsync4E() { |
2643 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2644 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2643 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2644 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2645 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2646 |
|
assertTrue(f.cancel(true)); |
2647 |
|
checkCompletedWithWrappedCancellationException(g); |
2648 |
|
|
2649 |
< |
f = new CompletableFuture<Integer>(); |
2650 |
< |
f2 = new CompletableFuture<Integer>(); |
2649 |
> |
f = new CompletableFuture<>(); |
2650 |
> |
f2 = new CompletableFuture<>(); |
2651 |
|
assertTrue(f2.cancel(true)); |
2652 |
|
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2653 |
|
checkCompletedWithWrappedCancellationException(g); |
2658 |
|
* completion of sources |
2659 |
|
*/ |
2660 |
|
public void testAcceptEitherAsyncE() { |
2661 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2662 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2661 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2662 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2663 |
|
IncAction r = new IncAction(); |
2664 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2665 |
|
f.complete(one); |
2667 |
|
assertEquals(r.value, 2); |
2668 |
|
|
2669 |
|
r = new IncAction(); |
2670 |
< |
f = new CompletableFuture<Integer>(); |
2670 |
> |
f = new CompletableFuture<>(); |
2671 |
|
f.complete(one); |
2672 |
< |
f2 = new CompletableFuture<Integer>(); |
2672 |
> |
f2 = new CompletableFuture<>(); |
2673 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2674 |
|
checkCompletedNormally(g, null); |
2675 |
|
assertEquals(r.value, 2); |
2680 |
|
* completion of source |
2681 |
|
*/ |
2682 |
|
public void testAcceptEitherAsync2E() { |
2683 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2684 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2683 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2684 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2685 |
|
IncAction r = new IncAction(); |
2686 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2687 |
|
f.completeExceptionally(new CFException()); |
2688 |
|
checkCompletedWithWrappedCFException(g); |
2689 |
|
|
2690 |
|
r = new IncAction(); |
2691 |
< |
f = new CompletableFuture<Integer>(); |
2692 |
< |
f2 = new CompletableFuture<Integer>(); |
2691 |
> |
f = new CompletableFuture<>(); |
2692 |
> |
f2 = new CompletableFuture<>(); |
2693 |
|
f2.completeExceptionally(new CFException()); |
2694 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2695 |
|
f.complete(one); |
2700 |
|
* acceptEitherAsync result completes exceptionally if action does |
2701 |
|
*/ |
2702 |
|
public void testAcceptEitherAsync3E() { |
2703 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2704 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2703 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2704 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2705 |
|
FailingConsumer r = new FailingConsumer(); |
2706 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2707 |
|
f.complete(one); |
2713 |
|
* source cancelled |
2714 |
|
*/ |
2715 |
|
public void testAcceptEitherAsync4E() { |
2716 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2717 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2716 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2717 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2718 |
|
IncAction r = new IncAction(); |
2719 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2720 |
|
assertTrue(f.cancel(true)); |
2721 |
|
checkCompletedWithWrappedCancellationException(g); |
2722 |
|
|
2723 |
|
r = new IncAction(); |
2724 |
< |
f = new CompletableFuture<Integer>(); |
2725 |
< |
f2 = new CompletableFuture<Integer>(); |
2724 |
> |
f = new CompletableFuture<>(); |
2725 |
> |
f2 = new CompletableFuture<>(); |
2726 |
|
assertTrue(f2.cancel(true)); |
2727 |
|
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2728 |
|
checkCompletedWithWrappedCancellationException(g); |
2733 |
|
* completion of sources |
2734 |
|
*/ |
2735 |
|
public void testRunAfterEitherAsyncE() { |
2736 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2737 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2736 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2737 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2738 |
|
Noop r = new Noop(); |
2739 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2740 |
|
f.complete(one); |
2742 |
|
assertTrue(r.ran); |
2743 |
|
|
2744 |
|
r = new Noop(); |
2745 |
< |
f = new CompletableFuture<Integer>(); |
2745 |
> |
f = new CompletableFuture<>(); |
2746 |
|
f.complete(one); |
2747 |
< |
f2 = new CompletableFuture<Integer>(); |
2747 |
> |
f2 = new CompletableFuture<>(); |
2748 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2749 |
|
checkCompletedNormally(g, null); |
2750 |
|
assertTrue(r.ran); |
2755 |
|
* completion of source |
2756 |
|
*/ |
2757 |
|
public void testRunAfterEitherAsync2E() { |
2758 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2759 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2758 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2759 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2760 |
|
Noop r = new Noop(); |
2761 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2762 |
|
f.completeExceptionally(new CFException()); |
2763 |
|
checkCompletedWithWrappedCFException(g); |
2764 |
|
|
2765 |
|
r = new Noop(); |
2766 |
< |
f = new CompletableFuture<Integer>(); |
2767 |
< |
f2 = new CompletableFuture<Integer>(); |
2766 |
> |
f = new CompletableFuture<>(); |
2767 |
> |
f2 = new CompletableFuture<>(); |
2768 |
|
f2.completeExceptionally(new CFException()); |
2769 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2770 |
|
f.complete(one); |
2775 |
|
* runAfterEitherAsync result completes exceptionally if action does |
2776 |
|
*/ |
2777 |
|
public void testRunAfterEitherAsync3E() { |
2778 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2779 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2778 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2779 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2780 |
|
FailingNoop r = new FailingNoop(); |
2781 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2782 |
|
f.complete(one); |
2788 |
|
* source cancelled |
2789 |
|
*/ |
2790 |
|
public void testRunAfterEitherAsync4E() { |
2791 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2792 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2791 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2792 |
> |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2793 |
|
Noop r = new Noop(); |
2794 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2795 |
|
assertTrue(f.cancel(true)); |
2796 |
|
checkCompletedWithWrappedCancellationException(g); |
2797 |
|
|
2798 |
|
r = new Noop(); |
2799 |
< |
f = new CompletableFuture<Integer>(); |
2800 |
< |
f2 = new CompletableFuture<Integer>(); |
2799 |
> |
f = new CompletableFuture<>(); |
2800 |
> |
f2 = new CompletableFuture<>(); |
2801 |
|
assertTrue(f2.cancel(true)); |
2802 |
|
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2803 |
|
checkCompletedWithWrappedCancellationException(g); |
2808 |
|
* completion of source |
2809 |
|
*/ |
2810 |
|
public void testThenComposeAsyncE() { |
2811 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2811 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2812 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
2813 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2814 |
|
f.complete(one); |
2820 |
|
* exceptional completion of source |
2821 |
|
*/ |
2822 |
|
public void testThenComposeAsync2E() { |
2823 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2823 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2824 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
2825 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2826 |
|
f.completeExceptionally(new CFException()); |
2831 |
|
* thenComposeAsync result completes exceptionally if action does |
2832 |
|
*/ |
2833 |
|
public void testThenComposeAsync3E() { |
2834 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2834 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2835 |
|
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
2836 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2837 |
|
f.complete(one); |
2842 |
|
* thenComposeAsync result completes exceptionally if source cancelled |
2843 |
|
*/ |
2844 |
|
public void testThenComposeAsync4E() { |
2845 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2845 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2846 |
|
CompletableFutureInc r = new CompletableFutureInc(); |
2847 |
|
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
2848 |
|
assertTrue(f.cancel(true)); |
2856 |
|
* with the value null |
2857 |
|
*/ |
2858 |
|
public void testAllOf_empty() throws Exception { |
2859 |
< |
CompletableFuture<?> f = CompletableFuture.allOf(); |
2859 |
> |
CompletableFuture<Void> f = CompletableFuture.allOf(); |
2860 |
|
checkCompletedNormally(f, null); |
2861 |
|
} |
2862 |
|
|
2863 |
|
/** |
2864 |
< |
* allOf returns a future completed when all components complete |
2864 |
> |
* allOf returns a future completed normally with the value null |
2865 |
> |
* when all components complete normally |
2866 |
|
*/ |
2867 |
< |
public void testAllOf() throws Exception { |
2867 |
> |
public void testAllOf_normal() throws Exception { |
2868 |
|
for (int k = 1; k < 20; ++k) { |
2869 |
< |
CompletableFuture[] fs = new CompletableFuture[k]; |
2869 |
> |
CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
2870 |
|
for (int i = 0; i < k; ++i) |
2871 |
< |
fs[i] = new CompletableFuture<Integer>(); |
2871 |
> |
fs[i] = new CompletableFuture<>(); |
2872 |
|
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
2873 |
|
for (int i = 0; i < k; ++i) { |
2874 |
|
checkIncomplete(f); |
2875 |
+ |
checkIncomplete(CompletableFuture.allOf(fs)); |
2876 |
|
fs[i].complete(one); |
2877 |
|
} |
2878 |
|
checkCompletedNormally(f, null); |
2879 |
+ |
checkCompletedNormally(CompletableFuture.allOf(fs), null); |
2880 |
|
} |
2881 |
|
} |
2882 |
|
|
2884 |
|
* anyOf(no component futures) returns an incomplete future |
2885 |
|
*/ |
2886 |
|
public void testAnyOf_empty() throws Exception { |
2887 |
< |
CompletableFuture<?> f = CompletableFuture.anyOf(); |
2887 |
> |
CompletableFuture<Object> f = CompletableFuture.anyOf(); |
2888 |
|
checkIncomplete(f); |
2889 |
|
} |
2890 |
|
|
2891 |
|
/** |
2892 |
< |
* anyOf returns a future completed when any components complete |
2892 |
> |
* anyOf returns a future completed normally with a value when |
2893 |
> |
* a component future does |
2894 |
|
*/ |
2895 |
< |
public void testAnyOf() throws Exception { |
2896 |
< |
for (int k = 1; k < 20; ++k) { |
2895 |
> |
public void testAnyOf_normal() throws Exception { |
2896 |
> |
for (int k = 0; k < 10; ++k) { |
2897 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
2898 |
|
for (int i = 0; i < k; ++i) |
2899 |
< |
fs[i] = new CompletableFuture<Integer>(); |
2899 |
> |
fs[i] = new CompletableFuture<>(); |
2900 |
|
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
2901 |
|
checkIncomplete(f); |
2902 |
|
for (int i = 0; i < k; ++i) { |
2903 |
|
fs[i].complete(one); |
2904 |
|
checkCompletedNormally(f, one); |
2905 |
+ |
checkCompletedNormally(CompletableFuture.anyOf(fs), one); |
2906 |
+ |
} |
2907 |
+ |
} |
2908 |
+ |
} |
2909 |
+ |
|
2910 |
+ |
/** |
2911 |
+ |
* anyOf result completes exceptionally when any component does. |
2912 |
+ |
*/ |
2913 |
+ |
public void testAnyOf_exceptional() throws Exception { |
2914 |
+ |
for (int k = 0; k < 10; ++k) { |
2915 |
+ |
CompletableFuture[] fs = new CompletableFuture[k]; |
2916 |
+ |
for (int i = 0; i < k; ++i) |
2917 |
+ |
fs[i] = new CompletableFuture<>(); |
2918 |
+ |
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
2919 |
+ |
checkIncomplete(f); |
2920 |
+ |
for (int i = 0; i < k; ++i) { |
2921 |
+ |
fs[i].completeExceptionally(new CFException()); |
2922 |
+ |
checkCompletedWithWrappedCFException(f); |
2923 |
+ |
checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs)); |
2924 |
|
} |
2925 |
|
} |
2926 |
|
} |
2929 |
|
* Completion methods throw NullPointerException with null arguments |
2930 |
|
*/ |
2931 |
|
public void testNPE() { |
2932 |
< |
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2933 |
< |
CompletableFuture<Integer> g = new CompletableFuture<Integer>(); |
2932 |
> |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2933 |
> |
CompletableFuture<Integer> g = new CompletableFuture<>(); |
2934 |
|
CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null; |
2935 |
|
CompletableFuture<?> h; |
2936 |
|
ThreadExecutor exec = new ThreadExecutor(); |