16 |
|
import java.util.concurrent.Future; |
17 |
|
import java.util.concurrent.CompletableFuture; |
18 |
|
import java.util.concurrent.CompletionException; |
19 |
+ |
import java.util.concurrent.CompletionStage; |
20 |
|
import java.util.concurrent.TimeoutException; |
21 |
|
import java.util.concurrent.atomic.AtomicInteger; |
22 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
69 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
70 |
|
assertTrue(f.isDone()); |
71 |
|
assertFalse(f.isCancelled()); |
72 |
+ |
assertFalse(f.isCompletedExceptionally()); |
73 |
|
assertTrue(f.toString().contains("[Completed normally]")); |
74 |
|
} |
75 |
|
|
103 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
104 |
|
} |
105 |
|
|
106 |
+ |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
107 |
+ |
CFException ex) { |
108 |
+ |
try { |
109 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
110 |
+ |
shouldThrow(); |
111 |
+ |
} catch (ExecutionException success) { |
112 |
+ |
assertSame(ex, success.getCause()); |
113 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
114 |
+ |
try { |
115 |
+ |
f.join(); |
116 |
+ |
shouldThrow(); |
117 |
+ |
} catch (CompletionException success) { |
118 |
+ |
assertSame(ex, success.getCause()); |
119 |
+ |
} |
120 |
+ |
try { |
121 |
+ |
f.getNow(null); |
122 |
+ |
shouldThrow(); |
123 |
+ |
} catch (CompletionException success) { |
124 |
+ |
assertSame(ex, success.getCause()); |
125 |
+ |
} |
126 |
+ |
try { |
127 |
+ |
f.get(); |
128 |
+ |
shouldThrow(); |
129 |
+ |
} catch (ExecutionException success) { |
130 |
+ |
assertSame(ex, success.getCause()); |
131 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
132 |
+ |
assertTrue(f.isDone()); |
133 |
+ |
assertFalse(f.isCancelled()); |
134 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
135 |
+ |
} |
136 |
+ |
|
137 |
|
void checkCancelled(CompletableFuture<?> f) { |
138 |
|
try { |
139 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
154 |
|
} catch (CancellationException success) { |
155 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
156 |
|
assertTrue(f.isDone()); |
157 |
+ |
assertTrue(f.isCompletedExceptionally()); |
158 |
|
assertTrue(f.isCancelled()); |
159 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
160 |
|
} |
186 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
187 |
|
assertTrue(f.isDone()); |
188 |
|
assertFalse(f.isCancelled()); |
189 |
+ |
assertTrue(f.isCompletedExceptionally()); |
190 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
191 |
|
} |
192 |
|
|
291 |
|
assertEquals(g.getNumberOfDependents(), 0); |
292 |
|
} |
293 |
|
|
259 |
– |
|
294 |
|
/** |
295 |
|
* toString indicates current completion state |
296 |
|
*/ |
318 |
|
|
319 |
|
// Choose non-commutative actions for better coverage |
320 |
|
|
321 |
+ |
// A non-commutative function that handles null values as well |
322 |
+ |
public static int subtract(Integer x, Integer y) { |
323 |
+ |
return ((x == null) ? 42 : x.intValue()) |
324 |
+ |
- ((y == null) ? 99 : y.intValue()); |
325 |
+ |
} |
326 |
+ |
|
327 |
|
static final Supplier<Integer> supplyOne = |
328 |
|
() -> Integer.valueOf(1); |
329 |
|
static final Function<Integer, Integer> inc = |
330 |
|
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
331 |
|
static final BiFunction<Integer, Integer, Integer> subtract = |
332 |
< |
(Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue()); |
332 |
> |
(Integer x, Integer y) -> subtract(x, y); |
333 |
|
static final class IncAction implements Consumer<Integer> { |
334 |
|
int value; |
335 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
336 |
|
} |
337 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
338 |
+ |
volatile int invocationCount = 0; |
339 |
|
int value; |
340 |
+ |
// Check this action was invoked exactly once when result is computed. |
341 |
+ |
public boolean ran() { return invocationCount == 1; } |
342 |
|
public void accept(Integer x, Integer y) { |
343 |
< |
value = x.intValue() - y.intValue(); |
343 |
> |
invocationCount++; |
344 |
> |
value = subtract(x, y); |
345 |
> |
} |
346 |
> |
} |
347 |
> |
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
348 |
> |
volatile int invocationCount = 0; |
349 |
> |
int value; |
350 |
> |
// Check this action was invoked exactly once when result is computed. |
351 |
> |
public boolean ran() { return invocationCount == 1; } |
352 |
> |
public Integer apply(Integer x, Integer y) { |
353 |
> |
invocationCount++; |
354 |
> |
return subtract(x, y); |
355 |
|
} |
356 |
|
} |
357 |
|
static final class Noop implements Runnable { |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
+ |
/** |
429 |
+ |
* Permits the testing of parallel code for the 3 different |
430 |
+ |
* execution modes without repeating all the testing code. |
431 |
+ |
*/ |
432 |
+ |
enum ExecutionMode { |
433 |
+ |
DEFAULT { |
434 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
435 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
436 |
+ |
return f.runAfterBoth(g, a); |
437 |
+ |
} |
438 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
439 |
+ |
(CompletableFuture<T> f, |
440 |
+ |
CompletionStage<? extends U> g, |
441 |
+ |
BiConsumer<? super T,? super U> a) { |
442 |
+ |
return f.thenAcceptBoth(g, a); |
443 |
+ |
} |
444 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
445 |
+ |
(CompletableFuture<T> f, |
446 |
+ |
CompletionStage<? extends U> g, |
447 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
448 |
+ |
return f.thenCombine(g, a); |
449 |
+ |
} |
450 |
+ |
}, |
451 |
+ |
|
452 |
+ |
// /** Experimental way to do more testing */ |
453 |
+ |
// REVERSE_DEFAULT { |
454 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
455 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
456 |
+ |
// return g.runAfterBoth(f, a); |
457 |
+ |
// } |
458 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
459 |
+ |
// (CompletableFuture<T> f, |
460 |
+ |
// CompletionStage<? extends U> g, |
461 |
+ |
// BiConsumer<? super T,? super U> a) { |
462 |
+ |
// return DEFAULT.thenAcceptBoth(f, g, a); |
463 |
+ |
// } |
464 |
+ |
// }, |
465 |
+ |
|
466 |
+ |
DEFAULT_ASYNC { |
467 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
468 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
469 |
+ |
return f.runAfterBothAsync(g, a); |
470 |
+ |
} |
471 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
472 |
+ |
(CompletableFuture<T> f, |
473 |
+ |
CompletionStage<? extends U> g, |
474 |
+ |
BiConsumer<? super T,? super U> a) { |
475 |
+ |
return f.thenAcceptBothAsync(g, a); |
476 |
+ |
} |
477 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
478 |
+ |
(CompletableFuture<T> f, |
479 |
+ |
CompletionStage<? extends U> g, |
480 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
481 |
+ |
return f.thenCombineAsync(g, a); |
482 |
+ |
} |
483 |
+ |
}, |
484 |
+ |
|
485 |
+ |
// REVERSE_DEFAULT_ASYNC { |
486 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
487 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
488 |
+ |
// return f.runAfterBothAsync(g, a); |
489 |
+ |
// } |
490 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
491 |
+ |
// (CompletableFuture<T> f, |
492 |
+ |
// CompletionStage<? extends U> g, |
493 |
+ |
// BiConsumer<? super T,? super U> a) { |
494 |
+ |
// return DEFAULT_ASYNC.thenAcceptBoth(f, g, a); |
495 |
+ |
// } |
496 |
+ |
// }, |
497 |
+ |
|
498 |
+ |
EXECUTOR { |
499 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
500 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
501 |
+ |
return f.runAfterBothAsync(g, a, new ThreadExecutor()); |
502 |
+ |
} |
503 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
504 |
+ |
(CompletableFuture<T> f, |
505 |
+ |
CompletionStage<? extends U> g, |
506 |
+ |
BiConsumer<? super T,? super U> a) { |
507 |
+ |
return f.thenAcceptBothAsync(g, a, new ThreadExecutor()); |
508 |
+ |
} |
509 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
510 |
+ |
(CompletableFuture<T> f, |
511 |
+ |
CompletionStage<? extends U> g, |
512 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
513 |
+ |
return f.thenCombineAsync(g, a, new ThreadExecutor()); |
514 |
+ |
} |
515 |
+ |
}; |
516 |
+ |
|
517 |
+ |
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
518 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a); |
519 |
+ |
public abstract <T,U> CompletableFuture<Void> thenAcceptBoth |
520 |
+ |
(CompletableFuture<T> f, |
521 |
+ |
CompletionStage<? extends U> g, |
522 |
+ |
BiConsumer<? super T,? super U> a); |
523 |
+ |
public abstract <T,U,V> CompletableFuture<V> thenCombine |
524 |
+ |
(CompletableFuture<T> f, |
525 |
+ |
CompletionStage<? extends U> g, |
526 |
+ |
BiFunction<? super T,? super U,? extends V> a); |
527 |
+ |
} |
528 |
|
|
529 |
|
/** |
530 |
|
* exceptionally action completes with function value on source |
531 |
< |
* exception; otherwise with source value |
531 |
> |
* exception; otherwise with source value |
532 |
|
*/ |
533 |
|
public void testExceptionally() { |
534 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
649 |
|
* thenRun result completes normally after normal completion of source |
650 |
|
*/ |
651 |
|
public void testThenRun() { |
652 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
653 |
< |
Noop r = new Noop(); |
654 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
652 |
> |
CompletableFuture<Integer> f; |
653 |
> |
CompletableFuture<Void> g; |
654 |
> |
Noop r; |
655 |
> |
|
656 |
> |
f = new CompletableFuture<>(); |
657 |
> |
g = f.thenRun(r = new Noop()); |
658 |
|
f.complete(null); |
659 |
|
checkCompletedNormally(g, null); |
660 |
< |
// reordered version |
660 |
> |
assertTrue(r.ran); |
661 |
> |
|
662 |
|
f = new CompletableFuture<>(); |
663 |
|
f.complete(null); |
664 |
< |
r = new Noop(); |
507 |
< |
g = f.thenRun(r); |
664 |
> |
g = f.thenRun(r = new Noop()); |
665 |
|
checkCompletedNormally(g, null); |
666 |
+ |
assertTrue(r.ran); |
667 |
|
} |
668 |
|
|
669 |
|
/** |
671 |
|
* completion of source |
672 |
|
*/ |
673 |
|
public void testThenRun2() { |
674 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
675 |
< |
Noop r = new Noop(); |
676 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
674 |
> |
CompletableFuture<Integer> f; |
675 |
> |
CompletableFuture<Void> g; |
676 |
> |
Noop r; |
677 |
> |
|
678 |
> |
f = new CompletableFuture<>(); |
679 |
> |
g = f.thenRun(r = new Noop()); |
680 |
|
f.completeExceptionally(new CFException()); |
681 |
|
checkCompletedWithWrappedCFException(g); |
682 |
+ |
assertFalse(r.ran); |
683 |
+ |
|
684 |
+ |
f = new CompletableFuture<>(); |
685 |
+ |
f.completeExceptionally(new CFException()); |
686 |
+ |
g = f.thenRun(r = new Noop()); |
687 |
+ |
checkCompletedWithWrappedCFException(g); |
688 |
+ |
assertFalse(r.ran); |
689 |
|
} |
690 |
|
|
691 |
|
/** |
692 |
|
* thenRun result completes exceptionally if action does |
693 |
|
*/ |
694 |
|
public void testThenRun3() { |
695 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
696 |
< |
FailingNoop r = new FailingNoop(); |
697 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
695 |
> |
CompletableFuture<Integer> f; |
696 |
> |
CompletableFuture<Void> g; |
697 |
> |
FailingNoop r; |
698 |
> |
|
699 |
> |
f = new CompletableFuture<>(); |
700 |
> |
g = f.thenRun(r = new FailingNoop()); |
701 |
> |
f.complete(null); |
702 |
> |
checkCompletedWithWrappedCFException(g); |
703 |
> |
|
704 |
> |
f = new CompletableFuture<>(); |
705 |
|
f.complete(null); |
706 |
+ |
g = f.thenRun(r = new FailingNoop()); |
707 |
|
checkCompletedWithWrappedCFException(g); |
708 |
|
} |
709 |
|
|
711 |
|
* thenRun result completes exceptionally if source cancelled |
712 |
|
*/ |
713 |
|
public void testThenRun4() { |
714 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
715 |
< |
Noop r = new Noop(); |
716 |
< |
CompletableFuture<Void> g = f.thenRun(r); |
714 |
> |
CompletableFuture<Integer> f; |
715 |
> |
CompletableFuture<Void> g; |
716 |
> |
Noop r; |
717 |
> |
|
718 |
> |
f = new CompletableFuture<>(); |
719 |
> |
g = f.thenRun(r = new Noop()); |
720 |
|
assertTrue(f.cancel(true)); |
721 |
|
checkCompletedWithWrappedCancellationException(g); |
722 |
+ |
|
723 |
+ |
f = new CompletableFuture<>(); |
724 |
+ |
assertTrue(f.cancel(true)); |
725 |
+ |
g = f.thenRun(r = new Noop()); |
726 |
+ |
checkCompletedWithWrappedCancellationException(g); |
727 |
|
} |
728 |
|
|
729 |
|
/** |
814 |
|
checkCompletedWithWrappedCancellationException(g); |
815 |
|
} |
816 |
|
|
633 |
– |
|
817 |
|
/** |
818 |
|
* thenCombine result completes normally after normal completion |
819 |
|
* of sources |
820 |
|
*/ |
821 |
< |
public void testThenCombine() { |
822 |
< |
CompletableFuture<Integer> f, g, h; |
821 |
> |
public void testThenCombine_normalCompletion1() { |
822 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
823 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
824 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
825 |
> |
|
826 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
827 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
828 |
> |
final SubtractFunction r = new SubtractFunction(); |
829 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
830 |
> |
|
831 |
> |
f.complete(v1); |
832 |
> |
checkIncomplete(h); |
833 |
> |
assertFalse(r.ran()); |
834 |
> |
g.complete(v2); |
835 |
> |
|
836 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
837 |
> |
checkCompletedNormally(f, v1); |
838 |
> |
checkCompletedNormally(g, v2); |
839 |
> |
} |
840 |
> |
} |
841 |
|
|
842 |
< |
f = new CompletableFuture<>(); |
843 |
< |
g = new CompletableFuture<>(); |
844 |
< |
h = f.thenCombine(g, subtract); |
845 |
< |
f.complete(3); |
846 |
< |
checkIncomplete(h); |
847 |
< |
g.complete(1); |
848 |
< |
checkCompletedNormally(h, 2); |
842 |
> |
public void testThenCombine_normalCompletion2() { |
843 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
844 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
845 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
846 |
> |
|
847 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
848 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
849 |
> |
final SubtractFunction r = new SubtractFunction(); |
850 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
851 |
> |
|
852 |
> |
g.complete(v2); |
853 |
> |
checkIncomplete(h); |
854 |
> |
assertFalse(r.ran()); |
855 |
> |
f.complete(v1); |
856 |
> |
|
857 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
858 |
> |
checkCompletedNormally(f, v1); |
859 |
> |
checkCompletedNormally(g, v2); |
860 |
> |
} |
861 |
> |
} |
862 |
|
|
863 |
< |
f = new CompletableFuture<>(); |
864 |
< |
g = new CompletableFuture<>(); |
865 |
< |
h = f.thenCombine(g, subtract); |
866 |
< |
g.complete(1); |
867 |
< |
checkIncomplete(h); |
868 |
< |
f.complete(3); |
869 |
< |
checkCompletedNormally(h, 2); |
863 |
> |
public void testThenCombine_normalCompletion3() { |
864 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
865 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
866 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
867 |
> |
|
868 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
869 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
870 |
> |
final SubtractFunction r = new SubtractFunction(); |
871 |
> |
|
872 |
> |
g.complete(v2); |
873 |
> |
f.complete(v1); |
874 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
875 |
> |
|
876 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
877 |
> |
checkCompletedNormally(f, v1); |
878 |
> |
checkCompletedNormally(g, v2); |
879 |
> |
} |
880 |
> |
} |
881 |
|
|
882 |
< |
f = new CompletableFuture<>(); |
883 |
< |
g = new CompletableFuture<>(); |
884 |
< |
g.complete(1); |
885 |
< |
f.complete(3); |
886 |
< |
h = f.thenCombine(g, subtract); |
887 |
< |
checkCompletedNormally(h, 2); |
882 |
> |
public void testThenCombine_normalCompletion4() { |
883 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
884 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
885 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
886 |
> |
|
887 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
888 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
889 |
> |
final SubtractFunction r = new SubtractFunction(); |
890 |
> |
|
891 |
> |
f.complete(v1); |
892 |
> |
g.complete(v2); |
893 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
894 |
> |
|
895 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
896 |
> |
checkCompletedNormally(f, v1); |
897 |
> |
checkCompletedNormally(g, v2); |
898 |
> |
} |
899 |
|
} |
900 |
|
|
901 |
|
/** |
902 |
|
* thenCombine result completes exceptionally after exceptional |
903 |
|
* completion of either source |
904 |
|
*/ |
905 |
< |
public void testThenCombine2() { |
906 |
< |
CompletableFuture<Integer> f, g, h; |
907 |
< |
|
908 |
< |
f = new CompletableFuture<>(); |
909 |
< |
g = new CompletableFuture<>(); |
910 |
< |
h = f.thenCombine(g, subtract); |
911 |
< |
f.completeExceptionally(new CFException()); |
912 |
< |
checkIncomplete(h); |
913 |
< |
g.complete(1); |
914 |
< |
checkCompletedWithWrappedCFException(h); |
905 |
> |
public void testThenCombine_exceptionalCompletion1() { |
906 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
907 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
908 |
> |
|
909 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
910 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
911 |
> |
final SubtractFunction r = new SubtractFunction(); |
912 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
913 |
> |
final CFException ex = new CFException(); |
914 |
> |
|
915 |
> |
f.completeExceptionally(ex); |
916 |
> |
checkIncomplete(h); |
917 |
> |
g.complete(v1); |
918 |
> |
|
919 |
> |
checkCompletedWithWrappedCFException(h, ex); |
920 |
> |
checkCompletedWithWrappedCFException(f, ex); |
921 |
> |
assertFalse(r.ran()); |
922 |
> |
checkCompletedNormally(g, v1); |
923 |
> |
} |
924 |
> |
} |
925 |
|
|
926 |
< |
f = new CompletableFuture<>(); |
927 |
< |
g = new CompletableFuture<>(); |
928 |
< |
h = f.thenCombine(g, subtract); |
929 |
< |
g.completeExceptionally(new CFException()); |
930 |
< |
checkIncomplete(h); |
931 |
< |
f.complete(3); |
932 |
< |
checkCompletedWithWrappedCFException(h); |
926 |
> |
public void testThenCombine_exceptionalCompletion2() { |
927 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
928 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
929 |
> |
|
930 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
931 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
932 |
> |
final SubtractFunction r = new SubtractFunction(); |
933 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, subtract); |
934 |
> |
final CFException ex = new CFException(); |
935 |
> |
|
936 |
> |
g.completeExceptionally(ex); |
937 |
> |
checkIncomplete(h); |
938 |
> |
f.complete(v1); |
939 |
> |
|
940 |
> |
checkCompletedWithWrappedCFException(h, ex); |
941 |
> |
checkCompletedWithWrappedCFException(g, ex); |
942 |
> |
assertFalse(r.ran()); |
943 |
> |
checkCompletedNormally(f, v1); |
944 |
> |
} |
945 |
> |
} |
946 |
|
|
947 |
< |
f = new CompletableFuture<>(); |
948 |
< |
g = new CompletableFuture<>(); |
949 |
< |
f.complete(3); |
950 |
< |
g.completeExceptionally(new CFException()); |
951 |
< |
h = f.thenCombine(g, subtract); |
952 |
< |
checkCompletedWithWrappedCFException(h); |
947 |
> |
public void testThenCombine_exceptionalCompletion3() { |
948 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
949 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
950 |
> |
|
951 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
952 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
953 |
> |
final SubtractFunction r = new SubtractFunction(); |
954 |
> |
final CFException ex = new CFException(); |
955 |
> |
|
956 |
> |
g.completeExceptionally(ex); |
957 |
> |
f.complete(v1); |
958 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
959 |
> |
|
960 |
> |
checkCompletedWithWrappedCFException(h, ex); |
961 |
> |
checkCompletedWithWrappedCFException(g, ex); |
962 |
> |
assertFalse(r.ran()); |
963 |
> |
checkCompletedNormally(f, v1); |
964 |
> |
} |
965 |
> |
} |
966 |
|
|
967 |
< |
f = new CompletableFuture<>(); |
968 |
< |
g = new CompletableFuture<>(); |
969 |
< |
f.completeExceptionally(new CFException()); |
970 |
< |
g.complete(3); |
971 |
< |
h = f.thenCombine(g, subtract); |
972 |
< |
checkCompletedWithWrappedCFException(h); |
967 |
> |
public void testThenCombine_exceptionalCompletion4() { |
968 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
969 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
970 |
> |
|
971 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
972 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
973 |
> |
final SubtractFunction r = new SubtractFunction(); |
974 |
> |
final CFException ex = new CFException(); |
975 |
> |
|
976 |
> |
f.completeExceptionally(ex); |
977 |
> |
g.complete(v1); |
978 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, subtract); |
979 |
> |
|
980 |
> |
checkCompletedWithWrappedCFException(h, ex); |
981 |
> |
checkCompletedWithWrappedCFException(f, ex); |
982 |
> |
assertFalse(r.ran()); |
983 |
> |
checkCompletedNormally(g, v1); |
984 |
> |
} |
985 |
|
} |
986 |
|
|
987 |
|
/** |
988 |
|
* thenCombine result completes exceptionally if action does |
989 |
|
*/ |
990 |
< |
public void testThenCombine3() { |
991 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
992 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
993 |
< |
FailingBiFunction r = new FailingBiFunction(); |
994 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
995 |
< |
f.complete(one); |
996 |
< |
checkIncomplete(g); |
997 |
< |
assertFalse(r.ran); |
998 |
< |
f2.complete(two); |
999 |
< |
checkCompletedWithWrappedCFException(g); |
1000 |
< |
assertTrue(r.ran); |
990 |
> |
public void testThenCombine_actionFailed1() { |
991 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
992 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
993 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
994 |
> |
|
995 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
996 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
997 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
998 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
999 |
> |
|
1000 |
> |
f.complete(v1); |
1001 |
> |
checkIncomplete(h); |
1002 |
> |
g.complete(v2); |
1003 |
> |
|
1004 |
> |
checkCompletedWithWrappedCFException(h); |
1005 |
> |
checkCompletedNormally(f, v1); |
1006 |
> |
checkCompletedNormally(g, v2); |
1007 |
> |
} |
1008 |
> |
} |
1009 |
> |
|
1010 |
> |
public void testThenCombine_actionFailed2() { |
1011 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1012 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1013 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1014 |
> |
|
1015 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1016 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1017 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1018 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1019 |
> |
|
1020 |
> |
g.complete(v2); |
1021 |
> |
checkIncomplete(h); |
1022 |
> |
f.complete(v1); |
1023 |
> |
|
1024 |
> |
checkCompletedWithWrappedCFException(h); |
1025 |
> |
checkCompletedNormally(f, v1); |
1026 |
> |
checkCompletedNormally(g, v2); |
1027 |
> |
} |
1028 |
|
} |
1029 |
|
|
1030 |
|
/** |
1031 |
|
* thenCombine result completes exceptionally if either source cancelled |
1032 |
|
*/ |
1033 |
< |
public void testThenCombine4() { |
1034 |
< |
CompletableFuture<Integer> f, g, h; |
1033 |
> |
public void testThenCombine_sourceCancelled1() { |
1034 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1035 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1036 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1037 |
> |
|
1038 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1039 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1040 |
> |
final SubtractFunction r = new SubtractFunction(); |
1041 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1042 |
|
|
1043 |
< |
f = new CompletableFuture<>(); |
726 |
< |
g = new CompletableFuture<>(); |
727 |
< |
h = f.thenCombine(g, subtract); |
728 |
< |
assertTrue(f.cancel(true)); |
1043 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1044 |
|
checkIncomplete(h); |
1045 |
< |
g.complete(1); |
1045 |
> |
g.complete(v1); |
1046 |
> |
|
1047 |
|
checkCompletedWithWrappedCancellationException(h); |
1048 |
+ |
checkCancelled(f); |
1049 |
+ |
assertFalse(r.ran()); |
1050 |
+ |
checkCompletedNormally(g, v1); |
1051 |
+ |
} |
1052 |
+ |
} |
1053 |
|
|
1054 |
< |
f = new CompletableFuture<>(); |
1055 |
< |
g = new CompletableFuture<>(); |
1056 |
< |
h = f.thenCombine(g, subtract); |
1057 |
< |
assertTrue(g.cancel(true)); |
1054 |
> |
public void testThenCombine_sourceCancelled2() { |
1055 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1056 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1057 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1058 |
> |
|
1059 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1060 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1061 |
> |
final SubtractFunction r = new SubtractFunction(); |
1062 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1063 |
> |
|
1064 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1065 |
|
checkIncomplete(h); |
1066 |
< |
f.complete(3); |
1066 |
> |
f.complete(v1); |
1067 |
> |
|
1068 |
|
checkCompletedWithWrappedCancellationException(h); |
1069 |
+ |
checkCancelled(g); |
1070 |
+ |
assertFalse(r.ran()); |
1071 |
+ |
checkCompletedNormally(f, v1); |
1072 |
+ |
} |
1073 |
+ |
} |
1074 |
+ |
|
1075 |
+ |
public void testThenCombine_sourceCancelled3() { |
1076 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1077 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1078 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1079 |
+ |
|
1080 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1081 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1082 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1083 |
+ |
|
1084 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1085 |
+ |
f.complete(v1); |
1086 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1087 |
+ |
|
1088 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1089 |
+ |
checkCancelled(g); |
1090 |
+ |
assertFalse(r.ran()); |
1091 |
+ |
checkCompletedNormally(f, v1); |
1092 |
+ |
} |
1093 |
+ |
} |
1094 |
+ |
|
1095 |
+ |
public void testThenCombine_sourceCancelled4() { |
1096 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1097 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1098 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1099 |
+ |
|
1100 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1101 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1102 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1103 |
+ |
|
1104 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1105 |
+ |
g.complete(v1); |
1106 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1107 |
|
|
741 |
– |
f = new CompletableFuture<>(); |
742 |
– |
g = new CompletableFuture<>(); |
743 |
– |
assertTrue(f.cancel(true)); |
744 |
– |
assertTrue(g.cancel(true)); |
745 |
– |
h = f.thenCombine(g, subtract); |
1108 |
|
checkCompletedWithWrappedCancellationException(h); |
1109 |
+ |
checkCancelled(f); |
1110 |
+ |
assertFalse(r.ran()); |
1111 |
+ |
checkCompletedNormally(g, v1); |
1112 |
+ |
} |
1113 |
|
} |
1114 |
|
|
1115 |
|
/** |
1116 |
|
* thenAcceptBoth result completes normally after normal |
1117 |
|
* completion of sources |
1118 |
|
*/ |
1119 |
< |
public void testThenAcceptBoth() { |
1120 |
< |
CompletableFuture<Integer> f, g; |
1121 |
< |
CompletableFuture<Void> h; |
1122 |
< |
SubtractAction r; |
1119 |
> |
public void testThenAcceptBoth_normalCompletion1() { |
1120 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1121 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1122 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1123 |
> |
|
1124 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1125 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1126 |
> |
final SubtractAction r = new SubtractAction(); |
1127 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1128 |
|
|
1129 |
< |
f = new CompletableFuture<>(); |
759 |
< |
g = new CompletableFuture<>(); |
760 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
761 |
< |
f.complete(3); |
1129 |
> |
f.complete(v1); |
1130 |
|
checkIncomplete(h); |
1131 |
< |
g.complete(1); |
1131 |
> |
assertEquals(r.value, 0); |
1132 |
> |
g.complete(v2); |
1133 |
> |
|
1134 |
|
checkCompletedNormally(h, null); |
1135 |
< |
assertEquals(r.value, 2); |
1135 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1136 |
> |
checkCompletedNormally(f, v1); |
1137 |
> |
checkCompletedNormally(g, v2); |
1138 |
> |
} |
1139 |
> |
} |
1140 |
|
|
1141 |
< |
f = new CompletableFuture<>(); |
1142 |
< |
g = new CompletableFuture<>(); |
1143 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1144 |
< |
g.complete(1); |
1141 |
> |
public void testThenAcceptBoth_normalCompletion2() { |
1142 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1143 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1144 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1145 |
> |
|
1146 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1147 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1148 |
> |
final SubtractAction r = new SubtractAction(); |
1149 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1150 |
> |
|
1151 |
> |
g.complete(v2); |
1152 |
|
checkIncomplete(h); |
1153 |
< |
f.complete(3); |
1153 |
> |
assertEquals(r.value, 0); |
1154 |
> |
f.complete(v1); |
1155 |
> |
|
1156 |
|
checkCompletedNormally(h, null); |
1157 |
< |
assertEquals(r.value, 2); |
1157 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1158 |
> |
checkCompletedNormally(f, v1); |
1159 |
> |
checkCompletedNormally(g, v2); |
1160 |
> |
} |
1161 |
> |
} |
1162 |
> |
|
1163 |
> |
public void testThenAcceptBoth_normalCompletion3() { |
1164 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1165 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1166 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1167 |
> |
|
1168 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1169 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1170 |
> |
final SubtractAction r = new SubtractAction(); |
1171 |
> |
|
1172 |
> |
g.complete(v2); |
1173 |
> |
f.complete(v1); |
1174 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1175 |
|
|
776 |
– |
f = new CompletableFuture<>(); |
777 |
– |
g = new CompletableFuture<>(); |
778 |
– |
g.complete(1); |
779 |
– |
f.complete(3); |
780 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1176 |
|
checkCompletedNormally(h, null); |
1177 |
< |
assertEquals(r.value, 2); |
1177 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1178 |
> |
checkCompletedNormally(f, v1); |
1179 |
> |
checkCompletedNormally(g, v2); |
1180 |
> |
} |
1181 |
> |
} |
1182 |
> |
|
1183 |
> |
public void testThenAcceptBoth_normalCompletion4() { |
1184 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1185 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1186 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1187 |
> |
|
1188 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1189 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1190 |
> |
final SubtractAction r = new SubtractAction(); |
1191 |
> |
|
1192 |
> |
f.complete(v1); |
1193 |
> |
g.complete(v2); |
1194 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1195 |
> |
|
1196 |
> |
checkCompletedNormally(h, null); |
1197 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1198 |
> |
checkCompletedNormally(f, v1); |
1199 |
> |
checkCompletedNormally(g, v2); |
1200 |
> |
} |
1201 |
|
} |
1202 |
|
|
1203 |
|
/** |
1204 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1205 |
|
* completion of either source |
1206 |
|
*/ |
1207 |
< |
public void testThenAcceptBoth2() { |
1208 |
< |
CompletableFuture<Integer> f, g; |
1209 |
< |
CompletableFuture<Void> h; |
1210 |
< |
SubtractAction r; |
1211 |
< |
|
1212 |
< |
f = new CompletableFuture<>(); |
1213 |
< |
g = new CompletableFuture<>(); |
1214 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1215 |
< |
f.completeExceptionally(new CFException()); |
1216 |
< |
checkIncomplete(h); |
1217 |
< |
g.complete(1); |
1218 |
< |
checkCompletedWithWrappedCFException(h); |
1207 |
> |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1208 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1209 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1210 |
> |
|
1211 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1212 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1213 |
> |
final SubtractAction r = new SubtractAction(); |
1214 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1215 |
> |
final CFException ex = new CFException(); |
1216 |
> |
|
1217 |
> |
f.completeExceptionally(ex); |
1218 |
> |
checkIncomplete(h); |
1219 |
> |
g.complete(v1); |
1220 |
> |
|
1221 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1222 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1223 |
> |
assertFalse(r.ran()); |
1224 |
> |
checkCompletedNormally(g, v1); |
1225 |
> |
} |
1226 |
> |
} |
1227 |
|
|
1228 |
< |
f = new CompletableFuture<>(); |
1229 |
< |
g = new CompletableFuture<>(); |
1230 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1231 |
< |
g.completeExceptionally(new CFException()); |
1232 |
< |
checkIncomplete(h); |
1233 |
< |
f.complete(3); |
1234 |
< |
checkCompletedWithWrappedCFException(h); |
1228 |
> |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1229 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1230 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1231 |
> |
|
1232 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1233 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1234 |
> |
final SubtractAction r = new SubtractAction(); |
1235 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1236 |
> |
final CFException ex = new CFException(); |
1237 |
> |
|
1238 |
> |
g.completeExceptionally(ex); |
1239 |
> |
checkIncomplete(h); |
1240 |
> |
f.complete(v1); |
1241 |
> |
|
1242 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1243 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1244 |
> |
assertFalse(r.ran()); |
1245 |
> |
checkCompletedNormally(f, v1); |
1246 |
> |
} |
1247 |
> |
} |
1248 |
|
|
1249 |
< |
f = new CompletableFuture<>(); |
1250 |
< |
g = new CompletableFuture<>(); |
1251 |
< |
f.complete(3); |
1252 |
< |
g.completeExceptionally(new CFException()); |
1253 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1254 |
< |
checkCompletedWithWrappedCFException(h); |
1249 |
> |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1250 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1251 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1252 |
> |
|
1253 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1254 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1255 |
> |
final SubtractAction r = new SubtractAction(); |
1256 |
> |
final CFException ex = new CFException(); |
1257 |
> |
|
1258 |
> |
g.completeExceptionally(ex); |
1259 |
> |
f.complete(v1); |
1260 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1261 |
> |
|
1262 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1263 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1264 |
> |
assertFalse(r.ran()); |
1265 |
> |
checkCompletedNormally(f, v1); |
1266 |
> |
} |
1267 |
> |
} |
1268 |
|
|
1269 |
< |
f = new CompletableFuture<>(); |
1270 |
< |
g = new CompletableFuture<>(); |
1271 |
< |
f.completeExceptionally(new CFException()); |
1272 |
< |
g.complete(3); |
1273 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1274 |
< |
checkCompletedWithWrappedCFException(h); |
1269 |
> |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1270 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1271 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1272 |
> |
|
1273 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1274 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1275 |
> |
final SubtractAction r = new SubtractAction(); |
1276 |
> |
final CFException ex = new CFException(); |
1277 |
> |
|
1278 |
> |
f.completeExceptionally(ex); |
1279 |
> |
g.complete(v1); |
1280 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1281 |
> |
|
1282 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1283 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1284 |
> |
assertFalse(r.ran()); |
1285 |
> |
checkCompletedNormally(g, v1); |
1286 |
> |
} |
1287 |
|
} |
1288 |
|
|
1289 |
|
/** |
1290 |
|
* thenAcceptBoth result completes exceptionally if action does |
1291 |
|
*/ |
1292 |
< |
public void testThenAcceptBoth3() { |
1293 |
< |
CompletableFuture<Integer> f, g; |
1294 |
< |
CompletableFuture<Void> h; |
1295 |
< |
FailingBiConsumer r; |
1292 |
> |
public void testThenAcceptBoth_actionFailed1() { |
1293 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1294 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1295 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1296 |
|
|
1297 |
< |
f = new CompletableFuture<>(); |
1298 |
< |
g = new CompletableFuture<>(); |
1299 |
< |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1300 |
< |
f.complete(3); |
1297 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1298 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1299 |
> |
final FailingBiConsumer r = new FailingBiConsumer(); |
1300 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1301 |
> |
|
1302 |
> |
f.complete(v1); |
1303 |
|
checkIncomplete(h); |
1304 |
< |
g.complete(1); |
1304 |
> |
g.complete(v2); |
1305 |
> |
|
1306 |
|
checkCompletedWithWrappedCFException(h); |
1307 |
+ |
checkCompletedNormally(f, v1); |
1308 |
+ |
checkCompletedNormally(g, v2); |
1309 |
+ |
} |
1310 |
+ |
} |
1311 |
+ |
|
1312 |
+ |
public void testThenAcceptBoth_actionFailed2() { |
1313 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1314 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1315 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1316 |
+ |
|
1317 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1318 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1319 |
+ |
final FailingBiConsumer r = new FailingBiConsumer(); |
1320 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1321 |
+ |
|
1322 |
+ |
g.complete(v2); |
1323 |
+ |
checkIncomplete(h); |
1324 |
+ |
f.complete(v1); |
1325 |
|
|
841 |
– |
f = new CompletableFuture<>(); |
842 |
– |
g = new CompletableFuture<>(); |
843 |
– |
f.complete(3); |
844 |
– |
g.complete(1); |
845 |
– |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1326 |
|
checkCompletedWithWrappedCFException(h); |
1327 |
+ |
checkCompletedNormally(f, v1); |
1328 |
+ |
checkCompletedNormally(g, v2); |
1329 |
+ |
} |
1330 |
|
} |
1331 |
|
|
1332 |
|
/** |
1333 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1334 |
|
*/ |
1335 |
< |
public void testThenAcceptBoth4() { |
1336 |
< |
CompletableFuture<Integer> f, g; |
1337 |
< |
CompletableFuture<Void> h; |
1338 |
< |
SubtractAction r; |
1335 |
> |
public void testThenAcceptBoth_sourceCancelled1() { |
1336 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1337 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1338 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1339 |
> |
|
1340 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1341 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1342 |
> |
final SubtractAction r = new SubtractAction(); |
1343 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1344 |
|
|
1345 |
< |
f = new CompletableFuture<>(); |
858 |
< |
g = new CompletableFuture<>(); |
859 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
860 |
< |
assertTrue(f.cancel(true)); |
1345 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1346 |
|
checkIncomplete(h); |
1347 |
< |
g.complete(1); |
1347 |
> |
g.complete(v1); |
1348 |
> |
|
1349 |
|
checkCompletedWithWrappedCancellationException(h); |
1350 |
+ |
checkCancelled(f); |
1351 |
+ |
assertFalse(r.ran()); |
1352 |
+ |
checkCompletedNormally(g, v1); |
1353 |
+ |
} |
1354 |
+ |
} |
1355 |
|
|
1356 |
< |
f = new CompletableFuture<>(); |
1357 |
< |
g = new CompletableFuture<>(); |
1358 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1359 |
< |
assertTrue(g.cancel(true)); |
1356 |
> |
public void testThenAcceptBoth_sourceCancelled2() { |
1357 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1358 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1359 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1360 |
> |
|
1361 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1362 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1363 |
> |
final SubtractAction r = new SubtractAction(); |
1364 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1365 |
> |
|
1366 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1367 |
|
checkIncomplete(h); |
1368 |
< |
f.complete(3); |
871 |
< |
checkCompletedWithWrappedCancellationException(h); |
1368 |
> |
f.complete(v1); |
1369 |
|
|
873 |
– |
f = new CompletableFuture<>(); |
874 |
– |
g = new CompletableFuture<>(); |
875 |
– |
f.complete(3); |
876 |
– |
assertTrue(g.cancel(true)); |
877 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1370 |
|
checkCompletedWithWrappedCancellationException(h); |
1371 |
+ |
checkCancelled(g); |
1372 |
+ |
assertFalse(r.ran()); |
1373 |
+ |
checkCompletedNormally(f, v1); |
1374 |
+ |
} |
1375 |
+ |
} |
1376 |
+ |
|
1377 |
+ |
public void testThenAcceptBoth_sourceCancelled3() { |
1378 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1379 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1380 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1381 |
+ |
|
1382 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1383 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1384 |
+ |
final SubtractAction r = new SubtractAction(); |
1385 |
+ |
|
1386 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1387 |
+ |
f.complete(v1); |
1388 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1389 |
+ |
|
1390 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1391 |
+ |
checkCancelled(g); |
1392 |
+ |
assertFalse(r.ran()); |
1393 |
+ |
checkCompletedNormally(f, v1); |
1394 |
+ |
} |
1395 |
+ |
} |
1396 |
+ |
|
1397 |
+ |
public void testThenAcceptBoth_sourceCancelled4() { |
1398 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1399 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1400 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1401 |
+ |
|
1402 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1403 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1404 |
+ |
final SubtractAction r = new SubtractAction(); |
1405 |
+ |
|
1406 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1407 |
+ |
g.complete(v1); |
1408 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1409 |
|
|
880 |
– |
f = new CompletableFuture<>(); |
881 |
– |
g = new CompletableFuture<>(); |
882 |
– |
assertTrue(f.cancel(true)); |
883 |
– |
g.complete(3); |
884 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1410 |
|
checkCompletedWithWrappedCancellationException(h); |
1411 |
+ |
checkCancelled(f); |
1412 |
+ |
assertFalse(r.ran()); |
1413 |
+ |
checkCompletedNormally(g, v1); |
1414 |
+ |
} |
1415 |
|
} |
1416 |
|
|
1417 |
|
/** |
1418 |
|
* runAfterBoth result completes normally after normal |
1419 |
|
* completion of sources |
1420 |
|
*/ |
1421 |
< |
public void testRunAfterBoth() { |
1422 |
< |
CompletableFuture<Integer> f, g; |
1423 |
< |
CompletableFuture<Void> h; |
1424 |
< |
Noop r; |
1421 |
> |
public void testRunAfterBoth_normalCompletion1() { |
1422 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1423 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1424 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1425 |
> |
|
1426 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1427 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1428 |
> |
final Noop r = new Noop(); |
1429 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1430 |
|
|
1431 |
< |
f = new CompletableFuture<>(); |
898 |
< |
g = new CompletableFuture<>(); |
899 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
900 |
< |
f.complete(3); |
1431 |
> |
f.complete(v1); |
1432 |
|
checkIncomplete(h); |
1433 |
< |
g.complete(1); |
1433 |
> |
assertFalse(r.ran); |
1434 |
> |
g.complete(v2); |
1435 |
> |
|
1436 |
|
checkCompletedNormally(h, null); |
1437 |
|
assertTrue(r.ran); |
1438 |
+ |
checkCompletedNormally(f, v1); |
1439 |
+ |
checkCompletedNormally(g, v2); |
1440 |
+ |
} |
1441 |
+ |
} |
1442 |
|
|
1443 |
< |
f = new CompletableFuture<>(); |
1444 |
< |
g = new CompletableFuture<>(); |
1445 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1446 |
< |
g.complete(1); |
1443 |
> |
public void testRunAfterBoth_normalCompletion2() { |
1444 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1445 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1446 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1447 |
> |
|
1448 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1449 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1450 |
> |
final Noop r = new Noop(); |
1451 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1452 |
> |
|
1453 |
> |
g.complete(v2); |
1454 |
|
checkIncomplete(h); |
1455 |
< |
f.complete(3); |
1455 |
> |
assertFalse(r.ran); |
1456 |
> |
f.complete(v1); |
1457 |
> |
|
1458 |
|
checkCompletedNormally(h, null); |
1459 |
|
assertTrue(r.ran); |
1460 |
+ |
checkCompletedNormally(f, v1); |
1461 |
+ |
checkCompletedNormally(g, v2); |
1462 |
+ |
} |
1463 |
+ |
} |
1464 |
+ |
|
1465 |
+ |
public void testRunAfterBoth_normalCompletion3() { |
1466 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1467 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1468 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1469 |
+ |
|
1470 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1471 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1472 |
+ |
final Noop r = new Noop(); |
1473 |
+ |
|
1474 |
+ |
g.complete(v2); |
1475 |
+ |
f.complete(v1); |
1476 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1477 |
|
|
915 |
– |
f = new CompletableFuture<>(); |
916 |
– |
g = new CompletableFuture<>(); |
917 |
– |
g.complete(1); |
918 |
– |
f.complete(3); |
919 |
– |
h = f.runAfterBoth(g, r = new Noop()); |
1478 |
|
checkCompletedNormally(h, null); |
1479 |
|
assertTrue(r.ran); |
1480 |
+ |
checkCompletedNormally(f, v1); |
1481 |
+ |
checkCompletedNormally(g, v2); |
1482 |
+ |
} |
1483 |
+ |
} |
1484 |
+ |
|
1485 |
+ |
public void testRunAfterBoth_normalCompletion4() { |
1486 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1487 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1488 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1489 |
+ |
|
1490 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1491 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1492 |
+ |
final Noop r = new Noop(); |
1493 |
+ |
|
1494 |
+ |
f.complete(v1); |
1495 |
+ |
g.complete(v2); |
1496 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1497 |
+ |
|
1498 |
+ |
checkCompletedNormally(h, null); |
1499 |
+ |
assertTrue(r.ran); |
1500 |
+ |
checkCompletedNormally(f, v1); |
1501 |
+ |
checkCompletedNormally(g, v2); |
1502 |
+ |
} |
1503 |
|
} |
1504 |
|
|
1505 |
|
/** |
1506 |
|
* runAfterBoth result completes exceptionally after exceptional |
1507 |
|
* completion of either source |
1508 |
|
*/ |
1509 |
< |
public void testRunAfterBoth2() { |
1510 |
< |
CompletableFuture<Integer> f, g; |
1511 |
< |
CompletableFuture<Void> h; |
1512 |
< |
Noop r; |
1509 |
> |
public void testRunAfterBoth_exceptionalCompletion1() { |
1510 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1511 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1512 |
> |
|
1513 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1514 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1515 |
> |
final Noop r = new Noop(); |
1516 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1517 |
> |
final CFException ex = new CFException(); |
1518 |
|
|
1519 |
< |
f = new CompletableFuture<>(); |
934 |
< |
g = new CompletableFuture<>(); |
935 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
936 |
< |
f.completeExceptionally(new CFException()); |
1519 |
> |
f.completeExceptionally(ex); |
1520 |
|
checkIncomplete(h); |
1521 |
< |
g.complete(1); |
1522 |
< |
checkCompletedWithWrappedCFException(h); |
1521 |
> |
g.complete(v1); |
1522 |
> |
|
1523 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1524 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1525 |
|
assertFalse(r.ran); |
1526 |
+ |
checkCompletedNormally(g, v1); |
1527 |
+ |
} |
1528 |
+ |
} |
1529 |
|
|
1530 |
< |
f = new CompletableFuture<>(); |
1531 |
< |
g = new CompletableFuture<>(); |
1532 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1533 |
< |
g.completeExceptionally(new CFException()); |
1530 |
> |
public void testRunAfterBoth_exceptionalCompletion2() { |
1531 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1532 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1533 |
> |
|
1534 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1535 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1536 |
> |
final Noop r = new Noop(); |
1537 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1538 |
> |
final CFException ex = new CFException(); |
1539 |
> |
|
1540 |
> |
g.completeExceptionally(ex); |
1541 |
|
checkIncomplete(h); |
1542 |
< |
f.complete(3); |
1543 |
< |
checkCompletedWithWrappedCFException(h); |
1542 |
> |
f.complete(v1); |
1543 |
> |
|
1544 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1545 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1546 |
|
assertFalse(r.ran); |
1547 |
+ |
checkCompletedNormally(f, v1); |
1548 |
+ |
} |
1549 |
+ |
} |
1550 |
|
|
1551 |
< |
f = new CompletableFuture<>(); |
1552 |
< |
g = new CompletableFuture<>(); |
1553 |
< |
g.completeExceptionally(new CFException()); |
1554 |
< |
f.complete(3); |
1555 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1556 |
< |
checkCompletedWithWrappedCFException(h); |
1551 |
> |
public void testRunAfterBoth_exceptionalCompletion3() { |
1552 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1553 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1554 |
> |
|
1555 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1556 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1557 |
> |
final Noop r = new Noop(); |
1558 |
> |
final CFException ex = new CFException(); |
1559 |
> |
|
1560 |
> |
g.completeExceptionally(ex); |
1561 |
> |
f.complete(v1); |
1562 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1563 |
> |
|
1564 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1565 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1566 |
|
assertFalse(r.ran); |
1567 |
+ |
checkCompletedNormally(f, v1); |
1568 |
+ |
} |
1569 |
+ |
} |
1570 |
|
|
1571 |
< |
f = new CompletableFuture<>(); |
1572 |
< |
g = new CompletableFuture<>(); |
1573 |
< |
f.completeExceptionally(new CFException()); |
1574 |
< |
g.complete(1); |
1575 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1576 |
< |
checkCompletedWithWrappedCFException(h); |
1571 |
> |
public void testRunAfterBoth_exceptionalCompletion4() { |
1572 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1573 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1574 |
> |
|
1575 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1576 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1577 |
> |
final Noop r = new Noop(); |
1578 |
> |
final CFException ex = new CFException(); |
1579 |
> |
|
1580 |
> |
f.completeExceptionally(ex); |
1581 |
> |
g.complete(v1); |
1582 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1583 |
> |
|
1584 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1585 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1586 |
|
assertFalse(r.ran); |
1587 |
+ |
checkCompletedNormally(g, v1); |
1588 |
+ |
} |
1589 |
|
} |
1590 |
|
|
1591 |
|
/** |
1592 |
|
* runAfterBoth result completes exceptionally if action does |
1593 |
|
*/ |
1594 |
< |
public void testRunAfterBoth3() { |
1595 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1596 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1597 |
< |
FailingNoop r = new FailingNoop(); |
1598 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1599 |
< |
f.complete(one); |
1600 |
< |
checkIncomplete(g); |
1601 |
< |
f2.complete(two); |
1602 |
< |
checkCompletedWithWrappedCFException(g); |
1594 |
> |
public void testRunAfterBoth_actionFailed1() { |
1595 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1596 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1597 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1598 |
> |
|
1599 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1600 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1601 |
> |
final FailingNoop r = new FailingNoop(); |
1602 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1603 |
> |
|
1604 |
> |
f.complete(v1); |
1605 |
> |
checkIncomplete(h); |
1606 |
> |
g.complete(v2); |
1607 |
> |
|
1608 |
> |
checkCompletedWithWrappedCFException(h); |
1609 |
> |
checkCompletedNormally(f, v1); |
1610 |
> |
checkCompletedNormally(g, v2); |
1611 |
> |
} |
1612 |
> |
} |
1613 |
> |
|
1614 |
> |
public void testRunAfterBoth_actionFailed2() { |
1615 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1616 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1617 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1618 |
> |
|
1619 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1620 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1621 |
> |
final FailingNoop r = new FailingNoop(); |
1622 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1623 |
> |
|
1624 |
> |
g.complete(v2); |
1625 |
> |
checkIncomplete(h); |
1626 |
> |
f.complete(v1); |
1627 |
> |
|
1628 |
> |
checkCompletedWithWrappedCFException(h); |
1629 |
> |
checkCompletedNormally(f, v1); |
1630 |
> |
checkCompletedNormally(g, v2); |
1631 |
> |
} |
1632 |
|
} |
1633 |
|
|
1634 |
|
/** |
1635 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1636 |
|
*/ |
1637 |
< |
public void testRunAfterBoth4() { |
1638 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1639 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1640 |
< |
Noop r = new Noop(); |
1641 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1642 |
< |
assertTrue(f.cancel(true)); |
1643 |
< |
f2.complete(two); |
1644 |
< |
checkCompletedWithWrappedCancellationException(g); |
1645 |
< |
f = new CompletableFuture<>(); |
1646 |
< |
f2 = new CompletableFuture<>(); |
1647 |
< |
r = new Noop(); |
1648 |
< |
g = f.runAfterBoth(f2, r); |
1649 |
< |
f.complete(one); |
1650 |
< |
assertTrue(f2.cancel(true)); |
1651 |
< |
checkCompletedWithWrappedCancellationException(g); |
1637 |
> |
public void testRunAfterBoth_sourceCancelled1() { |
1638 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1639 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1640 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1641 |
> |
|
1642 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1643 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1644 |
> |
final Noop r = new Noop(); |
1645 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1646 |
> |
|
1647 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1648 |
> |
checkIncomplete(h); |
1649 |
> |
g.complete(v1); |
1650 |
> |
|
1651 |
> |
checkCompletedWithWrappedCancellationException(h); |
1652 |
> |
checkCancelled(f); |
1653 |
> |
assertFalse(r.ran); |
1654 |
> |
checkCompletedNormally(g, v1); |
1655 |
> |
} |
1656 |
> |
} |
1657 |
> |
|
1658 |
> |
public void testRunAfterBoth_sourceCancelled2() { |
1659 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1660 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1661 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1662 |
> |
|
1663 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1664 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1665 |
> |
final Noop r = new Noop(); |
1666 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1667 |
> |
|
1668 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1669 |
> |
checkIncomplete(h); |
1670 |
> |
f.complete(v1); |
1671 |
> |
|
1672 |
> |
checkCompletedWithWrappedCancellationException(h); |
1673 |
> |
checkCancelled(g); |
1674 |
> |
assertFalse(r.ran); |
1675 |
> |
checkCompletedNormally(f, v1); |
1676 |
> |
} |
1677 |
> |
} |
1678 |
> |
|
1679 |
> |
public void testRunAfterBoth_sourceCancelled3() { |
1680 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1681 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1682 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1683 |
> |
|
1684 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1685 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1686 |
> |
final Noop r = new Noop(); |
1687 |
> |
|
1688 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1689 |
> |
f.complete(v1); |
1690 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1691 |
> |
|
1692 |
> |
checkCompletedWithWrappedCancellationException(h); |
1693 |
> |
checkCancelled(g); |
1694 |
> |
assertFalse(r.ran); |
1695 |
> |
checkCompletedNormally(f, v1); |
1696 |
> |
} |
1697 |
> |
} |
1698 |
> |
|
1699 |
> |
public void testRunAfterBoth_sourceCancelled4() { |
1700 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1701 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1702 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1703 |
> |
|
1704 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1705 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1706 |
> |
final Noop r = new Noop(); |
1707 |
> |
|
1708 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1709 |
> |
g.complete(v1); |
1710 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1711 |
> |
|
1712 |
> |
checkCompletedWithWrappedCancellationException(h); |
1713 |
> |
checkCancelled(f); |
1714 |
> |
assertFalse(r.ran); |
1715 |
> |
checkCompletedNormally(g, v1); |
1716 |
> |
} |
1717 |
|
} |
1718 |
|
|
1719 |
|
/** |
1855 |
|
checkCompletedWithWrappedCancellationException(g); |
1856 |
|
} |
1857 |
|
|
1141 |
– |
|
1858 |
|
/** |
1859 |
|
* runAfterEither result completes normally after normal completion |
1860 |
|
* of either source |
2003 |
|
checkCompletedWithWrappedCancellationException(g); |
2004 |
|
} |
2005 |
|
|
1290 |
– |
|
2006 |
|
// asyncs |
2007 |
|
|
2008 |
|
/** |
2035 |
|
try { |
2036 |
|
g.join(); |
2037 |
|
shouldThrow(); |
2038 |
< |
} catch (Exception ok) { |
1324 |
< |
} |
2038 |
> |
} catch (CompletionException success) {} |
2039 |
|
checkCompletedWithWrappedCFException(g); |
2040 |
|
} |
2041 |
|
|
2151 |
|
} |
2152 |
|
|
2153 |
|
/** |
1440 |
– |
* thenCombineAsync result completes normally after normal |
1441 |
– |
* completion of sources |
1442 |
– |
*/ |
1443 |
– |
public void testThenCombineAsync() { |
1444 |
– |
CompletableFuture<Integer> f, g, h; |
1445 |
– |
|
1446 |
– |
f = new CompletableFuture<>(); |
1447 |
– |
g = new CompletableFuture<>(); |
1448 |
– |
h = f.thenCombineAsync(g, subtract); |
1449 |
– |
f.complete(3); |
1450 |
– |
checkIncomplete(h); |
1451 |
– |
g.complete(1); |
1452 |
– |
checkCompletedNormally(h, 2); |
1453 |
– |
|
1454 |
– |
f = new CompletableFuture<>(); |
1455 |
– |
g = new CompletableFuture<>(); |
1456 |
– |
h = f.thenCombineAsync(g, subtract); |
1457 |
– |
g.complete(1); |
1458 |
– |
checkIncomplete(h); |
1459 |
– |
f.complete(3); |
1460 |
– |
checkCompletedNormally(h, 2); |
1461 |
– |
|
1462 |
– |
f = new CompletableFuture<>(); |
1463 |
– |
g = new CompletableFuture<>(); |
1464 |
– |
g.complete(1); |
1465 |
– |
f.complete(3); |
1466 |
– |
h = f.thenCombineAsync(g, subtract); |
1467 |
– |
checkCompletedNormally(h, 2); |
1468 |
– |
} |
1469 |
– |
|
1470 |
– |
/** |
1471 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
1472 |
– |
* completion of either source |
1473 |
– |
*/ |
1474 |
– |
public void testThenCombineAsync2() { |
1475 |
– |
CompletableFuture<Integer> f, g, h; |
1476 |
– |
|
1477 |
– |
f = new CompletableFuture<>(); |
1478 |
– |
g = new CompletableFuture<>(); |
1479 |
– |
h = f.thenCombineAsync(g, subtract); |
1480 |
– |
f.completeExceptionally(new CFException()); |
1481 |
– |
checkIncomplete(h); |
1482 |
– |
g.complete(1); |
1483 |
– |
checkCompletedWithWrappedCFException(h); |
1484 |
– |
|
1485 |
– |
f = new CompletableFuture<>(); |
1486 |
– |
g = new CompletableFuture<>(); |
1487 |
– |
h = f.thenCombineAsync(g, subtract); |
1488 |
– |
g.completeExceptionally(new CFException()); |
1489 |
– |
checkIncomplete(h); |
1490 |
– |
f.complete(3); |
1491 |
– |
checkCompletedWithWrappedCFException(h); |
1492 |
– |
|
1493 |
– |
f = new CompletableFuture<>(); |
1494 |
– |
g = new CompletableFuture<>(); |
1495 |
– |
g.completeExceptionally(new CFException()); |
1496 |
– |
f.complete(3); |
1497 |
– |
h = f.thenCombineAsync(g, subtract); |
1498 |
– |
checkCompletedWithWrappedCFException(h); |
1499 |
– |
} |
1500 |
– |
|
1501 |
– |
/** |
1502 |
– |
* thenCombineAsync result completes exceptionally if action does |
1503 |
– |
*/ |
1504 |
– |
public void testThenCombineAsync3() { |
1505 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1506 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1507 |
– |
FailingBiFunction r = new FailingBiFunction(); |
1508 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1509 |
– |
f.complete(one); |
1510 |
– |
checkIncomplete(g); |
1511 |
– |
assertFalse(r.ran); |
1512 |
– |
f2.complete(two); |
1513 |
– |
checkCompletedWithWrappedCFException(g); |
1514 |
– |
assertTrue(r.ran); |
1515 |
– |
} |
1516 |
– |
|
1517 |
– |
/** |
1518 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
1519 |
– |
*/ |
1520 |
– |
public void testThenCombineAsync4() { |
1521 |
– |
CompletableFuture<Integer> f, g, h; |
1522 |
– |
|
1523 |
– |
f = new CompletableFuture<>(); |
1524 |
– |
g = new CompletableFuture<>(); |
1525 |
– |
h = f.thenCombineAsync(g, subtract); |
1526 |
– |
assertTrue(f.cancel(true)); |
1527 |
– |
checkIncomplete(h); |
1528 |
– |
g.complete(1); |
1529 |
– |
checkCompletedWithWrappedCancellationException(h); |
1530 |
– |
|
1531 |
– |
f = new CompletableFuture<>(); |
1532 |
– |
g = new CompletableFuture<>(); |
1533 |
– |
h = f.thenCombineAsync(g, subtract); |
1534 |
– |
assertTrue(g.cancel(true)); |
1535 |
– |
checkIncomplete(h); |
1536 |
– |
f.complete(3); |
1537 |
– |
checkCompletedWithWrappedCancellationException(h); |
1538 |
– |
|
1539 |
– |
f = new CompletableFuture<>(); |
1540 |
– |
g = new CompletableFuture<>(); |
1541 |
– |
g.complete(3); |
1542 |
– |
assertTrue(f.cancel(true)); |
1543 |
– |
h = f.thenCombineAsync(g, subtract); |
1544 |
– |
checkCompletedWithWrappedCancellationException(h); |
1545 |
– |
|
1546 |
– |
f = new CompletableFuture<>(); |
1547 |
– |
g = new CompletableFuture<>(); |
1548 |
– |
f.complete(3); |
1549 |
– |
assertTrue(g.cancel(true)); |
1550 |
– |
h = f.thenCombineAsync(g, subtract); |
1551 |
– |
checkCompletedWithWrappedCancellationException(h); |
1552 |
– |
} |
1553 |
– |
|
1554 |
– |
/** |
1555 |
– |
* thenAcceptBothAsync result completes normally after normal |
1556 |
– |
* completion of sources |
1557 |
– |
*/ |
1558 |
– |
public void testThenAcceptBothAsync() { |
1559 |
– |
CompletableFuture<Integer> f, g; |
1560 |
– |
CompletableFuture<Void> h; |
1561 |
– |
SubtractAction r; |
1562 |
– |
|
1563 |
– |
f = new CompletableFuture<>(); |
1564 |
– |
g = new CompletableFuture<>(); |
1565 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1566 |
– |
f.complete(3); |
1567 |
– |
checkIncomplete(h); |
1568 |
– |
g.complete(1); |
1569 |
– |
checkCompletedNormally(h, null); |
1570 |
– |
assertEquals(r.value, 2); |
1571 |
– |
|
1572 |
– |
f = new CompletableFuture<>(); |
1573 |
– |
g = new CompletableFuture<>(); |
1574 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1575 |
– |
g.complete(1); |
1576 |
– |
checkIncomplete(h); |
1577 |
– |
f.complete(3); |
1578 |
– |
checkCompletedNormally(h, null); |
1579 |
– |
assertEquals(r.value, 2); |
1580 |
– |
|
1581 |
– |
f = new CompletableFuture<>(); |
1582 |
– |
g = new CompletableFuture<>(); |
1583 |
– |
g.complete(1); |
1584 |
– |
f.complete(3); |
1585 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1586 |
– |
checkCompletedNormally(h, null); |
1587 |
– |
assertEquals(r.value, 2); |
1588 |
– |
} |
1589 |
– |
|
1590 |
– |
/** |
1591 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
1592 |
– |
* completion of source |
1593 |
– |
*/ |
1594 |
– |
public void testThenAcceptBothAsync2() { |
1595 |
– |
CompletableFuture<Integer> f, g; |
1596 |
– |
CompletableFuture<Void> h; |
1597 |
– |
SubtractAction r; |
1598 |
– |
|
1599 |
– |
f = new CompletableFuture<>(); |
1600 |
– |
g = new CompletableFuture<>(); |
1601 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1602 |
– |
f.completeExceptionally(new CFException()); |
1603 |
– |
checkIncomplete(h); |
1604 |
– |
g.complete(1); |
1605 |
– |
checkCompletedWithWrappedCFException(h); |
1606 |
– |
|
1607 |
– |
f = new CompletableFuture<>(); |
1608 |
– |
g = new CompletableFuture<>(); |
1609 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1610 |
– |
g.completeExceptionally(new CFException()); |
1611 |
– |
checkIncomplete(h); |
1612 |
– |
f.complete(3); |
1613 |
– |
checkCompletedWithWrappedCFException(h); |
1614 |
– |
|
1615 |
– |
f = new CompletableFuture<>(); |
1616 |
– |
g = new CompletableFuture<>(); |
1617 |
– |
f.complete(3); |
1618 |
– |
g.completeExceptionally(new CFException()); |
1619 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1620 |
– |
checkCompletedWithWrappedCFException(h); |
1621 |
– |
|
1622 |
– |
f = new CompletableFuture<>(); |
1623 |
– |
g = new CompletableFuture<>(); |
1624 |
– |
f.completeExceptionally(new CFException()); |
1625 |
– |
g.complete(3); |
1626 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1627 |
– |
checkCompletedWithWrappedCFException(h); |
1628 |
– |
} |
1629 |
– |
|
1630 |
– |
/** |
1631 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
1632 |
– |
*/ |
1633 |
– |
public void testThenAcceptBothAsync3() { |
1634 |
– |
CompletableFuture<Integer> f, g; |
1635 |
– |
CompletableFuture<Void> h; |
1636 |
– |
FailingBiConsumer r; |
1637 |
– |
|
1638 |
– |
f = new CompletableFuture<>(); |
1639 |
– |
g = new CompletableFuture<>(); |
1640 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1641 |
– |
f.complete(3); |
1642 |
– |
checkIncomplete(h); |
1643 |
– |
g.complete(1); |
1644 |
– |
checkCompletedWithWrappedCFException(h); |
1645 |
– |
|
1646 |
– |
f = new CompletableFuture<>(); |
1647 |
– |
g = new CompletableFuture<>(); |
1648 |
– |
f.complete(3); |
1649 |
– |
g.complete(1); |
1650 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1651 |
– |
checkCompletedWithWrappedCFException(h); |
1652 |
– |
} |
1653 |
– |
|
1654 |
– |
/** |
1655 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1656 |
– |
*/ |
1657 |
– |
public void testThenAcceptBothAsync4() { |
1658 |
– |
CompletableFuture<Integer> f, g; |
1659 |
– |
CompletableFuture<Void> h; |
1660 |
– |
SubtractAction r; |
1661 |
– |
|
1662 |
– |
f = new CompletableFuture<>(); |
1663 |
– |
g = new CompletableFuture<>(); |
1664 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1665 |
– |
assertTrue(f.cancel(true)); |
1666 |
– |
checkIncomplete(h); |
1667 |
– |
g.complete(1); |
1668 |
– |
checkCompletedWithWrappedCancellationException(h); |
1669 |
– |
|
1670 |
– |
f = new CompletableFuture<>(); |
1671 |
– |
g = new CompletableFuture<>(); |
1672 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1673 |
– |
assertTrue(g.cancel(true)); |
1674 |
– |
checkIncomplete(h); |
1675 |
– |
f.complete(3); |
1676 |
– |
checkCompletedWithWrappedCancellationException(h); |
1677 |
– |
|
1678 |
– |
f = new CompletableFuture<>(); |
1679 |
– |
g = new CompletableFuture<>(); |
1680 |
– |
f.complete(3); |
1681 |
– |
assertTrue(g.cancel(true)); |
1682 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1683 |
– |
checkCompletedWithWrappedCancellationException(h); |
1684 |
– |
|
1685 |
– |
f = new CompletableFuture<>(); |
1686 |
– |
g = new CompletableFuture<>(); |
1687 |
– |
assertTrue(f.cancel(true)); |
1688 |
– |
g.complete(3); |
1689 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1690 |
– |
checkCompletedWithWrappedCancellationException(h); |
1691 |
– |
} |
1692 |
– |
|
1693 |
– |
/** |
1694 |
– |
* runAfterBothAsync result completes normally after normal |
1695 |
– |
* completion of sources |
1696 |
– |
*/ |
1697 |
– |
public void testRunAfterBothAsync() { |
1698 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1699 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1700 |
– |
Noop r = new Noop(); |
1701 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1702 |
– |
f.complete(one); |
1703 |
– |
checkIncomplete(g); |
1704 |
– |
f2.complete(two); |
1705 |
– |
checkCompletedNormally(g, null); |
1706 |
– |
assertTrue(r.ran); |
1707 |
– |
} |
1708 |
– |
|
1709 |
– |
/** |
1710 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
1711 |
– |
* completion of source |
1712 |
– |
*/ |
1713 |
– |
public void testRunAfterBothAsync2() { |
1714 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1715 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1716 |
– |
Noop r = new Noop(); |
1717 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1718 |
– |
f.completeExceptionally(new CFException()); |
1719 |
– |
f2.complete(two); |
1720 |
– |
checkCompletedWithWrappedCFException(g); |
1721 |
– |
|
1722 |
– |
r = new Noop(); |
1723 |
– |
f = new CompletableFuture<>(); |
1724 |
– |
f2 = new CompletableFuture<>(); |
1725 |
– |
g = f.runAfterBothAsync(f2, r); |
1726 |
– |
f.complete(one); |
1727 |
– |
f2.completeExceptionally(new CFException()); |
1728 |
– |
checkCompletedWithWrappedCFException(g); |
1729 |
– |
} |
1730 |
– |
|
1731 |
– |
/** |
1732 |
– |
* runAfterBothAsync result completes exceptionally if action does |
1733 |
– |
*/ |
1734 |
– |
public void testRunAfterBothAsync3() { |
1735 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1736 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1737 |
– |
FailingNoop r = new FailingNoop(); |
1738 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1739 |
– |
f.complete(one); |
1740 |
– |
checkIncomplete(g); |
1741 |
– |
f2.complete(two); |
1742 |
– |
checkCompletedWithWrappedCFException(g); |
1743 |
– |
} |
1744 |
– |
|
1745 |
– |
/** |
1746 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
1747 |
– |
*/ |
1748 |
– |
public void testRunAfterBothAsync4() { |
1749 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1750 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1751 |
– |
Noop r = new Noop(); |
1752 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1753 |
– |
assertTrue(f.cancel(true)); |
1754 |
– |
f2.complete(two); |
1755 |
– |
checkCompletedWithWrappedCancellationException(g); |
1756 |
– |
|
1757 |
– |
r = new Noop(); |
1758 |
– |
f = new CompletableFuture<>(); |
1759 |
– |
f2 = new CompletableFuture<>(); |
1760 |
– |
g = f.runAfterBothAsync(f2, r); |
1761 |
– |
f.complete(one); |
1762 |
– |
assertTrue(f2.cancel(true)); |
1763 |
– |
checkCompletedWithWrappedCancellationException(g); |
1764 |
– |
} |
1765 |
– |
|
1766 |
– |
/** |
2154 |
|
* applyToEitherAsync result completes normally after normal |
2155 |
|
* completion of sources |
2156 |
|
*/ |
2442 |
|
checkCompletedWithWrappedCancellationException(g); |
2443 |
|
} |
2444 |
|
|
2058 |
– |
|
2445 |
|
// async with explicit executors |
2446 |
|
|
2447 |
|
/** |
2474 |
|
try { |
2475 |
|
g.join(); |
2476 |
|
shouldThrow(); |
2477 |
< |
} catch (Exception ok) { |
2092 |
< |
} |
2477 |
> |
} catch (CompletionException success) {} |
2478 |
|
checkCompletedWithWrappedCFException(g); |
2479 |
|
} |
2480 |
|
|
2590 |
|
} |
2591 |
|
|
2592 |
|
/** |
2208 |
– |
* thenCombineAsync result completes normally after normal |
2209 |
– |
* completion of sources |
2210 |
– |
*/ |
2211 |
– |
public void testThenCombineAsyncE() { |
2212 |
– |
CompletableFuture<Integer> f, g, h; |
2213 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2214 |
– |
int count = 0; |
2215 |
– |
|
2216 |
– |
f = new CompletableFuture<>(); |
2217 |
– |
g = new CompletableFuture<>(); |
2218 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2219 |
– |
f.complete(3); |
2220 |
– |
checkIncomplete(h); |
2221 |
– |
g.complete(1); |
2222 |
– |
checkCompletedNormally(h, 2); |
2223 |
– |
assertEquals(++count, e.count.get()); |
2224 |
– |
|
2225 |
– |
f = new CompletableFuture<>(); |
2226 |
– |
g = new CompletableFuture<>(); |
2227 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2228 |
– |
g.complete(1); |
2229 |
– |
checkIncomplete(h); |
2230 |
– |
f.complete(3); |
2231 |
– |
checkCompletedNormally(h, 2); |
2232 |
– |
assertEquals(++count, e.count.get()); |
2233 |
– |
|
2234 |
– |
f = new CompletableFuture<>(); |
2235 |
– |
g = new CompletableFuture<>(); |
2236 |
– |
g.complete(1); |
2237 |
– |
f.complete(3); |
2238 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2239 |
– |
checkCompletedNormally(h, 2); |
2240 |
– |
assertEquals(++count, e.count.get()); |
2241 |
– |
} |
2242 |
– |
|
2243 |
– |
/** |
2244 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
2245 |
– |
* completion of either source |
2246 |
– |
*/ |
2247 |
– |
public void testThenCombineAsync2E() { |
2248 |
– |
CompletableFuture<Integer> f, g, h; |
2249 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2250 |
– |
int count = 0; |
2251 |
– |
|
2252 |
– |
f = new CompletableFuture<>(); |
2253 |
– |
g = new CompletableFuture<>(); |
2254 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2255 |
– |
f.completeExceptionally(new CFException()); |
2256 |
– |
checkIncomplete(h); |
2257 |
– |
g.complete(1); |
2258 |
– |
checkCompletedWithWrappedCFException(h); |
2259 |
– |
|
2260 |
– |
f = new CompletableFuture<>(); |
2261 |
– |
g = new CompletableFuture<>(); |
2262 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2263 |
– |
g.completeExceptionally(new CFException()); |
2264 |
– |
checkIncomplete(h); |
2265 |
– |
f.complete(3); |
2266 |
– |
checkCompletedWithWrappedCFException(h); |
2267 |
– |
|
2268 |
– |
f = new CompletableFuture<>(); |
2269 |
– |
g = new CompletableFuture<>(); |
2270 |
– |
g.completeExceptionally(new CFException()); |
2271 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2272 |
– |
checkIncomplete(h); |
2273 |
– |
f.complete(3); |
2274 |
– |
checkCompletedWithWrappedCFException(h); |
2275 |
– |
|
2276 |
– |
assertEquals(0, e.count.get()); |
2277 |
– |
} |
2278 |
– |
|
2279 |
– |
/** |
2280 |
– |
* thenCombineAsync result completes exceptionally if action does |
2281 |
– |
*/ |
2282 |
– |
public void testThenCombineAsync3E() { |
2283 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2284 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2285 |
– |
FailingBiFunction r = new FailingBiFunction(); |
2286 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2287 |
– |
f.complete(one); |
2288 |
– |
checkIncomplete(g); |
2289 |
– |
assertFalse(r.ran); |
2290 |
– |
f2.complete(two); |
2291 |
– |
checkCompletedWithWrappedCFException(g); |
2292 |
– |
assertTrue(r.ran); |
2293 |
– |
} |
2294 |
– |
|
2295 |
– |
/** |
2296 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
2297 |
– |
*/ |
2298 |
– |
public void testThenCombineAsync4E() { |
2299 |
– |
CompletableFuture<Integer> f, g, h; |
2300 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2301 |
– |
|
2302 |
– |
f = new CompletableFuture<>(); |
2303 |
– |
g = new CompletableFuture<>(); |
2304 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2305 |
– |
assertTrue(f.cancel(true)); |
2306 |
– |
checkIncomplete(h); |
2307 |
– |
g.complete(1); |
2308 |
– |
checkCompletedWithWrappedCancellationException(h); |
2309 |
– |
|
2310 |
– |
f = new CompletableFuture<>(); |
2311 |
– |
g = new CompletableFuture<>(); |
2312 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2313 |
– |
assertTrue(g.cancel(true)); |
2314 |
– |
checkIncomplete(h); |
2315 |
– |
f.complete(3); |
2316 |
– |
checkCompletedWithWrappedCancellationException(h); |
2317 |
– |
|
2318 |
– |
f = new CompletableFuture<>(); |
2319 |
– |
g = new CompletableFuture<>(); |
2320 |
– |
assertTrue(g.cancel(true)); |
2321 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2322 |
– |
checkIncomplete(h); |
2323 |
– |
f.complete(3); |
2324 |
– |
checkCompletedWithWrappedCancellationException(h); |
2325 |
– |
|
2326 |
– |
f = new CompletableFuture<>(); |
2327 |
– |
g = new CompletableFuture<>(); |
2328 |
– |
assertTrue(f.cancel(true)); |
2329 |
– |
assertTrue(g.cancel(true)); |
2330 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2331 |
– |
checkCompletedWithWrappedCancellationException(h); |
2332 |
– |
|
2333 |
– |
assertEquals(0, e.count.get()); |
2334 |
– |
} |
2335 |
– |
|
2336 |
– |
/** |
2337 |
– |
* thenAcceptBothAsync result completes normally after normal |
2338 |
– |
* completion of sources |
2339 |
– |
*/ |
2340 |
– |
public void testThenAcceptBothAsyncE() { |
2341 |
– |
CompletableFuture<Integer> f, g; |
2342 |
– |
CompletableFuture<Void> h; |
2343 |
– |
SubtractAction r; |
2344 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2345 |
– |
|
2346 |
– |
f = new CompletableFuture<>(); |
2347 |
– |
g = new CompletableFuture<>(); |
2348 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2349 |
– |
f.complete(3); |
2350 |
– |
checkIncomplete(h); |
2351 |
– |
g.complete(1); |
2352 |
– |
checkCompletedNormally(h, null); |
2353 |
– |
assertEquals(r.value, 2); |
2354 |
– |
|
2355 |
– |
f = new CompletableFuture<>(); |
2356 |
– |
g = new CompletableFuture<>(); |
2357 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2358 |
– |
g.complete(1); |
2359 |
– |
checkIncomplete(h); |
2360 |
– |
f.complete(3); |
2361 |
– |
checkCompletedNormally(h, null); |
2362 |
– |
assertEquals(r.value, 2); |
2363 |
– |
|
2364 |
– |
f = new CompletableFuture<>(); |
2365 |
– |
g = new CompletableFuture<>(); |
2366 |
– |
g.complete(1); |
2367 |
– |
f.complete(3); |
2368 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2369 |
– |
checkCompletedNormally(h, null); |
2370 |
– |
assertEquals(r.value, 2); |
2371 |
– |
|
2372 |
– |
assertEquals(3, e.count.get()); |
2373 |
– |
} |
2374 |
– |
|
2375 |
– |
/** |
2376 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
2377 |
– |
* completion of source |
2378 |
– |
*/ |
2379 |
– |
public void testThenAcceptBothAsync2E() { |
2380 |
– |
CompletableFuture<Integer> f, g; |
2381 |
– |
CompletableFuture<Void> h; |
2382 |
– |
SubtractAction r; |
2383 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2384 |
– |
|
2385 |
– |
f = new CompletableFuture<>(); |
2386 |
– |
g = new CompletableFuture<>(); |
2387 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2388 |
– |
f.completeExceptionally(new CFException()); |
2389 |
– |
checkIncomplete(h); |
2390 |
– |
g.complete(1); |
2391 |
– |
checkCompletedWithWrappedCFException(h); |
2392 |
– |
|
2393 |
– |
f = new CompletableFuture<>(); |
2394 |
– |
g = new CompletableFuture<>(); |
2395 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2396 |
– |
g.completeExceptionally(new CFException()); |
2397 |
– |
checkIncomplete(h); |
2398 |
– |
f.complete(3); |
2399 |
– |
checkCompletedWithWrappedCFException(h); |
2400 |
– |
|
2401 |
– |
f = new CompletableFuture<>(); |
2402 |
– |
g = new CompletableFuture<>(); |
2403 |
– |
f.complete(3); |
2404 |
– |
g.completeExceptionally(new CFException()); |
2405 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2406 |
– |
checkCompletedWithWrappedCFException(h); |
2407 |
– |
|
2408 |
– |
f = new CompletableFuture<>(); |
2409 |
– |
g = new CompletableFuture<>(); |
2410 |
– |
f.completeExceptionally(new CFException()); |
2411 |
– |
g.complete(3); |
2412 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2413 |
– |
checkCompletedWithWrappedCFException(h); |
2414 |
– |
|
2415 |
– |
assertEquals(0, e.count.get()); |
2416 |
– |
} |
2417 |
– |
|
2418 |
– |
/** |
2419 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
2420 |
– |
*/ |
2421 |
– |
public void testThenAcceptBothAsync3E() { |
2422 |
– |
CompletableFuture<Integer> f, g; |
2423 |
– |
CompletableFuture<Void> h; |
2424 |
– |
FailingBiConsumer r; |
2425 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2426 |
– |
|
2427 |
– |
f = new CompletableFuture<>(); |
2428 |
– |
g = new CompletableFuture<>(); |
2429 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2430 |
– |
f.complete(3); |
2431 |
– |
checkIncomplete(h); |
2432 |
– |
g.complete(1); |
2433 |
– |
checkCompletedWithWrappedCFException(h); |
2434 |
– |
|
2435 |
– |
f = new CompletableFuture<>(); |
2436 |
– |
g = new CompletableFuture<>(); |
2437 |
– |
f.complete(3); |
2438 |
– |
g.complete(1); |
2439 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2440 |
– |
checkCompletedWithWrappedCFException(h); |
2441 |
– |
|
2442 |
– |
assertEquals(2, e.count.get()); |
2443 |
– |
} |
2444 |
– |
|
2445 |
– |
/** |
2446 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2447 |
– |
*/ |
2448 |
– |
public void testThenAcceptBothAsync4E() { |
2449 |
– |
CompletableFuture<Integer> f, g; |
2450 |
– |
CompletableFuture<Void> h; |
2451 |
– |
SubtractAction r; |
2452 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2453 |
– |
|
2454 |
– |
f = new CompletableFuture<>(); |
2455 |
– |
g = new CompletableFuture<>(); |
2456 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2457 |
– |
assertTrue(f.cancel(true)); |
2458 |
– |
checkIncomplete(h); |
2459 |
– |
g.complete(1); |
2460 |
– |
checkCompletedWithWrappedCancellationException(h); |
2461 |
– |
|
2462 |
– |
f = new CompletableFuture<>(); |
2463 |
– |
g = new CompletableFuture<>(); |
2464 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2465 |
– |
assertTrue(g.cancel(true)); |
2466 |
– |
checkIncomplete(h); |
2467 |
– |
f.complete(3); |
2468 |
– |
checkCompletedWithWrappedCancellationException(h); |
2469 |
– |
|
2470 |
– |
f = new CompletableFuture<>(); |
2471 |
– |
g = new CompletableFuture<>(); |
2472 |
– |
f.complete(3); |
2473 |
– |
assertTrue(g.cancel(true)); |
2474 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2475 |
– |
checkCompletedWithWrappedCancellationException(h); |
2476 |
– |
|
2477 |
– |
f = new CompletableFuture<>(); |
2478 |
– |
g = new CompletableFuture<>(); |
2479 |
– |
assertTrue(f.cancel(true)); |
2480 |
– |
g.complete(3); |
2481 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2482 |
– |
checkCompletedWithWrappedCancellationException(h); |
2483 |
– |
|
2484 |
– |
assertEquals(0, e.count.get()); |
2485 |
– |
} |
2486 |
– |
|
2487 |
– |
/** |
2488 |
– |
* runAfterBothAsync result completes normally after normal |
2489 |
– |
* completion of sources |
2490 |
– |
*/ |
2491 |
– |
public void testRunAfterBothAsyncE() { |
2492 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2493 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2494 |
– |
Noop r = new Noop(); |
2495 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2496 |
– |
f.complete(one); |
2497 |
– |
checkIncomplete(g); |
2498 |
– |
f2.complete(two); |
2499 |
– |
checkCompletedNormally(g, null); |
2500 |
– |
assertTrue(r.ran); |
2501 |
– |
} |
2502 |
– |
|
2503 |
– |
/** |
2504 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
2505 |
– |
* completion of source |
2506 |
– |
*/ |
2507 |
– |
public void testRunAfterBothAsync2E() { |
2508 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2509 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2510 |
– |
Noop r = new Noop(); |
2511 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2512 |
– |
f.completeExceptionally(new CFException()); |
2513 |
– |
f2.complete(two); |
2514 |
– |
checkCompletedWithWrappedCFException(g); |
2515 |
– |
|
2516 |
– |
r = new Noop(); |
2517 |
– |
f = new CompletableFuture<>(); |
2518 |
– |
f2 = new CompletableFuture<>(); |
2519 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2520 |
– |
f.complete(one); |
2521 |
– |
f2.completeExceptionally(new CFException()); |
2522 |
– |
checkCompletedWithWrappedCFException(g); |
2523 |
– |
} |
2524 |
– |
|
2525 |
– |
/** |
2526 |
– |
* runAfterBothAsync result completes exceptionally if action does |
2527 |
– |
*/ |
2528 |
– |
public void testRunAfterBothAsync3E() { |
2529 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2530 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2531 |
– |
FailingNoop r = new FailingNoop(); |
2532 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2533 |
– |
f.complete(one); |
2534 |
– |
checkIncomplete(g); |
2535 |
– |
f2.complete(two); |
2536 |
– |
checkCompletedWithWrappedCFException(g); |
2537 |
– |
} |
2538 |
– |
|
2539 |
– |
/** |
2540 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
2541 |
– |
*/ |
2542 |
– |
public void testRunAfterBothAsync4E() { |
2543 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2544 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2545 |
– |
Noop r = new Noop(); |
2546 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2547 |
– |
assertTrue(f.cancel(true)); |
2548 |
– |
f2.complete(two); |
2549 |
– |
checkCompletedWithWrappedCancellationException(g); |
2550 |
– |
|
2551 |
– |
r = new Noop(); |
2552 |
– |
f = new CompletableFuture<>(); |
2553 |
– |
f2 = new CompletableFuture<>(); |
2554 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2555 |
– |
f.complete(one); |
2556 |
– |
assertTrue(f2.cancel(true)); |
2557 |
– |
checkCompletedWithWrappedCancellationException(g); |
2558 |
– |
} |
2559 |
– |
|
2560 |
– |
/** |
2593 |
|
* applyToEitherAsync result completes normally after normal |
2594 |
|
* completion of sources |
2595 |
|
*/ |
2858 |
|
* with the value null |
2859 |
|
*/ |
2860 |
|
public void testAllOf_empty() throws Exception { |
2861 |
< |
CompletableFuture<?> f = CompletableFuture.allOf(); |
2861 |
> |
CompletableFuture<Void> f = CompletableFuture.allOf(); |
2862 |
|
checkCompletedNormally(f, null); |
2863 |
|
} |
2864 |
|
|
2865 |
|
/** |
2866 |
< |
* allOf returns a future completed when all components complete |
2866 |
> |
* allOf returns a future completed normally with the value null |
2867 |
> |
* when all components complete normally |
2868 |
|
*/ |
2869 |
< |
public void testAllOf() throws Exception { |
2869 |
> |
public void testAllOf_normal() throws Exception { |
2870 |
|
for (int k = 1; k < 20; ++k) { |
2871 |
|
CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
2872 |
|
for (int i = 0; i < k; ++i) |
2874 |
|
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
2875 |
|
for (int i = 0; i < k; ++i) { |
2876 |
|
checkIncomplete(f); |
2877 |
+ |
checkIncomplete(CompletableFuture.allOf(fs)); |
2878 |
|
fs[i].complete(one); |
2879 |
|
} |
2880 |
|
checkCompletedNormally(f, null); |
2881 |
+ |
checkCompletedNormally(CompletableFuture.allOf(fs), null); |
2882 |
|
} |
2883 |
|
} |
2884 |
|
|
2886 |
|
* anyOf(no component futures) returns an incomplete future |
2887 |
|
*/ |
2888 |
|
public void testAnyOf_empty() throws Exception { |
2889 |
< |
CompletableFuture<?> f = CompletableFuture.anyOf(); |
2889 |
> |
CompletableFuture<Object> f = CompletableFuture.anyOf(); |
2890 |
|
checkIncomplete(f); |
2891 |
|
} |
2892 |
|
|
2893 |
|
/** |
2894 |
< |
* anyOf returns a future completed when any components complete |
2894 |
> |
* anyOf returns a future completed normally with a value when |
2895 |
> |
* a component future does |
2896 |
|
*/ |
2897 |
< |
public void testAnyOf() throws Exception { |
2898 |
< |
for (int k = 1; k < 20; ++k) { |
2897 |
> |
public void testAnyOf_normal() throws Exception { |
2898 |
> |
for (int k = 0; k < 10; ++k) { |
2899 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
2900 |
|
for (int i = 0; i < k; ++i) |
2901 |
|
fs[i] = new CompletableFuture<>(); |
2904 |
|
for (int i = 0; i < k; ++i) { |
2905 |
|
fs[i].complete(one); |
2906 |
|
checkCompletedNormally(f, one); |
2907 |
+ |
checkCompletedNormally(CompletableFuture.anyOf(fs), one); |
2908 |
+ |
} |
2909 |
+ |
} |
2910 |
+ |
} |
2911 |
+ |
|
2912 |
+ |
/** |
2913 |
+ |
* anyOf result completes exceptionally when any component does. |
2914 |
+ |
*/ |
2915 |
+ |
public void testAnyOf_exceptional() throws Exception { |
2916 |
+ |
for (int k = 0; k < 10; ++k) { |
2917 |
+ |
CompletableFuture[] fs = new CompletableFuture[k]; |
2918 |
+ |
for (int i = 0; i < k; ++i) |
2919 |
+ |
fs[i] = new CompletableFuture<>(); |
2920 |
+ |
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
2921 |
+ |
checkIncomplete(f); |
2922 |
+ |
for (int i = 0; i < k; ++i) { |
2923 |
+ |
fs[i].completeExceptionally(new CFException()); |
2924 |
+ |
checkCompletedWithWrappedCFException(f); |
2925 |
+ |
checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs)); |
2926 |
|
} |
2927 |
|
} |
2928 |
|
} |
2938 |
|
ThreadExecutor exec = new ThreadExecutor(); |
2939 |
|
|
2940 |
|
Runnable[] throwingActions = { |
2941 |
< |
() -> { CompletableFuture.supplyAsync(null); }, |
2942 |
< |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
2943 |
< |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
2944 |
< |
|
2945 |
< |
() -> { CompletableFuture.runAsync(null); }, |
2946 |
< |
() -> { CompletableFuture.runAsync(null, exec); }, |
2947 |
< |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
2948 |
< |
|
2949 |
< |
() -> { f.completeExceptionally(null); }, |
2950 |
< |
|
2951 |
< |
() -> { f.thenApply(null); }, |
2952 |
< |
() -> { f.thenApplyAsync(null); }, |
2953 |
< |
() -> { f.thenApplyAsync((x) -> x, null); }, |
2954 |
< |
() -> { f.thenApplyAsync(null, exec); }, |
2955 |
< |
|
2956 |
< |
() -> { f.thenAccept(null); }, |
2957 |
< |
() -> { f.thenAcceptAsync(null); }, |
2958 |
< |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
2959 |
< |
() -> { f.thenAcceptAsync(null, exec); }, |
2960 |
< |
|
2961 |
< |
() -> { f.thenRun(null); }, |
2962 |
< |
() -> { f.thenRunAsync(null); }, |
2963 |
< |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
2964 |
< |
() -> { f.thenRunAsync(null, exec); }, |
2965 |
< |
|
2966 |
< |
() -> { f.thenCombine(g, null); }, |
2967 |
< |
() -> { f.thenCombineAsync(g, null); }, |
2968 |
< |
() -> { f.thenCombineAsync(g, null, exec); }, |
2969 |
< |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
2970 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
2971 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
2972 |
< |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
2973 |
< |
|
2974 |
< |
() -> { f.thenAcceptBoth(g, null); }, |
2975 |
< |
() -> { f.thenAcceptBothAsync(g, null); }, |
2976 |
< |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
2977 |
< |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
2978 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
2979 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
2980 |
< |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
2981 |
< |
|
2982 |
< |
() -> { f.runAfterBoth(g, null); }, |
2983 |
< |
() -> { f.runAfterBothAsync(g, null); }, |
2984 |
< |
() -> { f.runAfterBothAsync(g, null, exec); }, |
2985 |
< |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
2986 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
2987 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
2988 |
< |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
2989 |
< |
|
2990 |
< |
() -> { f.applyToEither(g, null); }, |
2991 |
< |
() -> { f.applyToEitherAsync(g, null); }, |
2992 |
< |
() -> { f.applyToEitherAsync(g, null, exec); }, |
2993 |
< |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
2994 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
2995 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
2996 |
< |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
2997 |
< |
|
2998 |
< |
() -> { f.acceptEither(g, null); }, |
2999 |
< |
() -> { f.acceptEitherAsync(g, null); }, |
3000 |
< |
() -> { f.acceptEitherAsync(g, null, exec); }, |
3001 |
< |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
3002 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
3003 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
3004 |
< |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
3005 |
< |
|
3006 |
< |
() -> { f.runAfterEither(g, null); }, |
3007 |
< |
() -> { f.runAfterEitherAsync(g, null); }, |
3008 |
< |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
3009 |
< |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
3010 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
3011 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
3012 |
< |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
3013 |
< |
|
3014 |
< |
() -> { f.thenCompose(null); }, |
3015 |
< |
() -> { f.thenComposeAsync(null); }, |
3016 |
< |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
3017 |
< |
() -> { f.thenComposeAsync(null, exec); }, |
3018 |
< |
|
3019 |
< |
() -> { f.exceptionally(null); }, |
3020 |
< |
|
3021 |
< |
() -> { f.handle(null); }, |
3022 |
< |
|
3023 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
3024 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
3025 |
< |
() -> { CompletableFuture.allOf(f, null); }, |
3026 |
< |
() -> { CompletableFuture.allOf(null, f); }, |
3027 |
< |
|
3028 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
3029 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
3030 |
< |
() -> { CompletableFuture.anyOf(f, null); }, |
3031 |
< |
() -> { CompletableFuture.anyOf(null, f); }, |
2941 |
> |
() -> CompletableFuture.supplyAsync(null), |
2942 |
> |
() -> CompletableFuture.supplyAsync(null, exec), |
2943 |
> |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
2944 |
> |
|
2945 |
> |
() -> CompletableFuture.runAsync(null), |
2946 |
> |
() -> CompletableFuture.runAsync(null, exec), |
2947 |
> |
() -> CompletableFuture.runAsync(() -> {}, null), |
2948 |
> |
|
2949 |
> |
() -> f.completeExceptionally(null), |
2950 |
> |
|
2951 |
> |
() -> f.thenApply(null), |
2952 |
> |
() -> f.thenApplyAsync(null), |
2953 |
> |
() -> f.thenApplyAsync((x) -> x, null), |
2954 |
> |
() -> f.thenApplyAsync(null, exec), |
2955 |
> |
|
2956 |
> |
() -> f.thenAccept(null), |
2957 |
> |
() -> f.thenAcceptAsync(null), |
2958 |
> |
() -> f.thenAcceptAsync((x) -> {} , null), |
2959 |
> |
() -> f.thenAcceptAsync(null, exec), |
2960 |
> |
|
2961 |
> |
() -> f.thenRun(null), |
2962 |
> |
() -> f.thenRunAsync(null), |
2963 |
> |
() -> f.thenRunAsync(() -> {} , null), |
2964 |
> |
() -> f.thenRunAsync(null, exec), |
2965 |
> |
|
2966 |
> |
() -> f.thenCombine(g, null), |
2967 |
> |
() -> f.thenCombineAsync(g, null), |
2968 |
> |
() -> f.thenCombineAsync(g, null, exec), |
2969 |
> |
() -> f.thenCombine(nullFuture, (x, y) -> x), |
2970 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x), |
2971 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec), |
2972 |
> |
() -> f.thenCombineAsync(g, (x, y) -> x, null), |
2973 |
> |
|
2974 |
> |
() -> f.thenAcceptBoth(g, null), |
2975 |
> |
() -> f.thenAcceptBothAsync(g, null), |
2976 |
> |
() -> f.thenAcceptBothAsync(g, null, exec), |
2977 |
> |
() -> f.thenAcceptBoth(nullFuture, (x, y) -> {}), |
2978 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}), |
2979 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec), |
2980 |
> |
() -> f.thenAcceptBothAsync(g, (x, y) -> {}, null), |
2981 |
> |
|
2982 |
> |
() -> f.runAfterBoth(g, null), |
2983 |
> |
() -> f.runAfterBothAsync(g, null), |
2984 |
> |
() -> f.runAfterBothAsync(g, null, exec), |
2985 |
> |
() -> f.runAfterBoth(nullFuture, () -> {}), |
2986 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}), |
2987 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}, exec), |
2988 |
> |
() -> f.runAfterBothAsync(g, () -> {}, null), |
2989 |
> |
|
2990 |
> |
() -> f.applyToEither(g, null), |
2991 |
> |
() -> f.applyToEitherAsync(g, null), |
2992 |
> |
() -> f.applyToEitherAsync(g, null, exec), |
2993 |
> |
() -> f.applyToEither(nullFuture, (x) -> x), |
2994 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
2995 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
2996 |
> |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
2997 |
> |
|
2998 |
> |
() -> f.acceptEither(g, null), |
2999 |
> |
() -> f.acceptEitherAsync(g, null), |
3000 |
> |
() -> f.acceptEitherAsync(g, null, exec), |
3001 |
> |
() -> f.acceptEither(nullFuture, (x) -> {}), |
3002 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
3003 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
3004 |
> |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
3005 |
> |
|
3006 |
> |
() -> f.runAfterEither(g, null), |
3007 |
> |
() -> f.runAfterEitherAsync(g, null), |
3008 |
> |
() -> f.runAfterEitherAsync(g, null, exec), |
3009 |
> |
() -> f.runAfterEither(nullFuture, () -> {}), |
3010 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}), |
3011 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}, exec), |
3012 |
> |
() -> f.runAfterEitherAsync(g, () -> {}, null), |
3013 |
> |
|
3014 |
> |
() -> f.thenCompose(null), |
3015 |
> |
() -> f.thenComposeAsync(null), |
3016 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
3017 |
> |
() -> f.thenComposeAsync(null, exec), |
3018 |
> |
|
3019 |
> |
() -> f.exceptionally(null), |
3020 |
> |
|
3021 |
> |
() -> f.handle(null), |
3022 |
> |
|
3023 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>)null), |
3024 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>[])null), |
3025 |
> |
() -> CompletableFuture.allOf(f, null), |
3026 |
> |
() -> CompletableFuture.allOf(null, f), |
3027 |
> |
|
3028 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>)null), |
3029 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>[])null), |
3030 |
> |
() -> CompletableFuture.anyOf(f, null), |
3031 |
> |
() -> CompletableFuture.anyOf(null, f), |
3032 |
> |
|
3033 |
> |
() -> f.obtrudeException(null), |
3034 |
|
}; |
3035 |
|
|
3036 |
|
assertThrows(NullPointerException.class, throwingActions); |
3037 |
|
assertEquals(0, exec.count.get()); |
3038 |
|
} |
3039 |
|
|
3040 |
+ |
/** |
3041 |
+ |
* toCompletableFuture returns this CompletableFuture. |
3042 |
+ |
*/ |
3043 |
+ |
public void testToCompletableFuture() { |
3044 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3045 |
+ |
assertSame(f, f.toCompletableFuture()); |
3046 |
+ |
} |
3047 |
+ |
|
3048 |
+ |
/** |
3049 |
+ |
* whenComplete action executes on normal completion, propagating |
3050 |
+ |
* source result. |
3051 |
+ |
*/ |
3052 |
+ |
public void testWhenComplete1() { |
3053 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3054 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3055 |
+ |
CompletableFuture<Integer> g = |
3056 |
+ |
f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement()); |
3057 |
+ |
f.complete(three); |
3058 |
+ |
checkCompletedNormally(f, three); |
3059 |
+ |
checkCompletedNormally(g, three); |
3060 |
+ |
assertEquals(a.get(), 1); |
3061 |
+ |
} |
3062 |
+ |
|
3063 |
+ |
/** |
3064 |
+ |
* whenComplete action executes on exceptional completion, propagating |
3065 |
+ |
* source result. |
3066 |
+ |
*/ |
3067 |
+ |
public void testWhenComplete2() { |
3068 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3069 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3070 |
+ |
CompletableFuture<Integer> g = |
3071 |
+ |
f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement()); |
3072 |
+ |
f.completeExceptionally(new CFException()); |
3073 |
+ |
assertTrue(f.isCompletedExceptionally()); |
3074 |
+ |
assertTrue(g.isCompletedExceptionally()); |
3075 |
+ |
assertEquals(a.get(), 1); |
3076 |
+ |
} |
3077 |
+ |
|
3078 |
+ |
/** |
3079 |
+ |
* If a whenComplete action throws an exception when triggered by |
3080 |
+ |
* a normal completion, it completes exceptionally |
3081 |
+ |
*/ |
3082 |
+ |
public void testWhenComplete3() { |
3083 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3084 |
+ |
CompletableFuture<Integer> g = |
3085 |
+ |
f.whenComplete((Integer x, Throwable t) -> |
3086 |
+ |
{ throw new CFException(); } ); |
3087 |
+ |
f.complete(three); |
3088 |
+ |
checkCompletedNormally(f, three); |
3089 |
+ |
assertTrue(g.isCompletedExceptionally()); |
3090 |
+ |
checkCompletedWithWrappedCFException(g); |
3091 |
+ |
} |
3092 |
+ |
|
3093 |
+ |
/** |
3094 |
+ |
* whenCompleteAsync action executes on normal completion, propagating |
3095 |
+ |
* source result. |
3096 |
+ |
*/ |
3097 |
+ |
public void testWhenCompleteAsync1() { |
3098 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3099 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3100 |
+ |
CompletableFuture<Integer> g = |
3101 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement()); |
3102 |
+ |
f.complete(three); |
3103 |
+ |
checkCompletedNormally(f, three); |
3104 |
+ |
checkCompletedNormally(g, three); |
3105 |
+ |
assertEquals(a.get(), 1); |
3106 |
+ |
} |
3107 |
+ |
|
3108 |
+ |
/** |
3109 |
+ |
* whenCompleteAsync action executes on exceptional completion, propagating |
3110 |
+ |
* source result. |
3111 |
+ |
*/ |
3112 |
+ |
public void testWhenCompleteAsync2() { |
3113 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3114 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3115 |
+ |
CompletableFuture<Integer> g = |
3116 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement()); |
3117 |
+ |
f.completeExceptionally(new CFException()); |
3118 |
+ |
checkCompletedWithWrappedCFException(f); |
3119 |
+ |
checkCompletedWithWrappedCFException(g); |
3120 |
+ |
} |
3121 |
+ |
|
3122 |
+ |
/** |
3123 |
+ |
* If a whenCompleteAsync action throws an exception when |
3124 |
+ |
* triggered by a normal completion, it completes exceptionally |
3125 |
+ |
*/ |
3126 |
+ |
public void testWhenCompleteAsync3() { |
3127 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3128 |
+ |
CompletableFuture<Integer> g = |
3129 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> |
3130 |
+ |
{ throw new CFException(); } ); |
3131 |
+ |
f.complete(three); |
3132 |
+ |
checkCompletedNormally(f, three); |
3133 |
+ |
checkCompletedWithWrappedCFException(g); |
3134 |
+ |
} |
3135 |
+ |
|
3136 |
+ |
/** |
3137 |
+ |
* whenCompleteAsync action executes on normal completion, propagating |
3138 |
+ |
* source result. |
3139 |
+ |
*/ |
3140 |
+ |
public void testWhenCompleteAsync1e() { |
3141 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3142 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3143 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3144 |
+ |
CompletableFuture<Integer> g = |
3145 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(), |
3146 |
+ |
exec); |
3147 |
+ |
f.complete(three); |
3148 |
+ |
checkCompletedNormally(f, three); |
3149 |
+ |
checkCompletedNormally(g, three); |
3150 |
+ |
assertEquals(a.get(), 1); |
3151 |
+ |
} |
3152 |
+ |
|
3153 |
+ |
/** |
3154 |
+ |
* whenCompleteAsync action executes on exceptional completion, propagating |
3155 |
+ |
* source result. |
3156 |
+ |
*/ |
3157 |
+ |
public void testWhenCompleteAsync2e() { |
3158 |
+ |
final AtomicInteger a = new AtomicInteger(); |
3159 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3160 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3161 |
+ |
CompletableFuture<Integer> g = |
3162 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(), |
3163 |
+ |
exec); |
3164 |
+ |
f.completeExceptionally(new CFException()); |
3165 |
+ |
checkCompletedWithWrappedCFException(f); |
3166 |
+ |
checkCompletedWithWrappedCFException(g); |
3167 |
+ |
} |
3168 |
+ |
|
3169 |
+ |
/** |
3170 |
+ |
* If a whenCompleteAsync action throws an exception when triggered |
3171 |
+ |
* by a normal completion, it completes exceptionally |
3172 |
+ |
*/ |
3173 |
+ |
public void testWhenCompleteAsync3e() { |
3174 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3175 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3176 |
+ |
CompletableFuture<Integer> g = |
3177 |
+ |
f.whenCompleteAsync((Integer x, Throwable t) -> |
3178 |
+ |
{ throw new CFException(); }, |
3179 |
+ |
exec); |
3180 |
+ |
f.complete(three); |
3181 |
+ |
checkCompletedNormally(f, three); |
3182 |
+ |
checkCompletedWithWrappedCFException(g); |
3183 |
+ |
} |
3184 |
+ |
|
3185 |
+ |
/** |
3186 |
+ |
* handleAsync action completes normally with function value on |
3187 |
+ |
* either normal or exceptional completion of source |
3188 |
+ |
*/ |
3189 |
+ |
public void testHandleAsync() { |
3190 |
+ |
CompletableFuture<Integer> f, g; |
3191 |
+ |
IntegerHandler r; |
3192 |
+ |
|
3193 |
+ |
f = new CompletableFuture<>(); |
3194 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3195 |
+ |
assertFalse(r.ran); |
3196 |
+ |
f.completeExceptionally(new CFException()); |
3197 |
+ |
checkCompletedWithWrappedCFException(f); |
3198 |
+ |
checkCompletedNormally(g, three); |
3199 |
+ |
assertTrue(r.ran); |
3200 |
+ |
|
3201 |
+ |
f = new CompletableFuture<>(); |
3202 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3203 |
+ |
assertFalse(r.ran); |
3204 |
+ |
f.completeExceptionally(new CFException()); |
3205 |
+ |
checkCompletedWithWrappedCFException(f); |
3206 |
+ |
checkCompletedNormally(g, three); |
3207 |
+ |
assertTrue(r.ran); |
3208 |
+ |
|
3209 |
+ |
f = new CompletableFuture<>(); |
3210 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3211 |
+ |
assertFalse(r.ran); |
3212 |
+ |
f.complete(one); |
3213 |
+ |
checkCompletedNormally(f, one); |
3214 |
+ |
checkCompletedNormally(g, two); |
3215 |
+ |
assertTrue(r.ran); |
3216 |
+ |
|
3217 |
+ |
f = new CompletableFuture<>(); |
3218 |
+ |
g = f.handleAsync(r = new IntegerHandler()); |
3219 |
+ |
assertFalse(r.ran); |
3220 |
+ |
f.complete(one); |
3221 |
+ |
checkCompletedNormally(f, one); |
3222 |
+ |
checkCompletedNormally(g, two); |
3223 |
+ |
assertTrue(r.ran); |
3224 |
+ |
} |
3225 |
+ |
|
3226 |
+ |
/** |
3227 |
+ |
* handleAsync action with Executor completes normally with |
3228 |
+ |
* function value on either normal or exceptional completion of |
3229 |
+ |
* source |
3230 |
+ |
*/ |
3231 |
+ |
public void testHandleAsync2() { |
3232 |
+ |
CompletableFuture<Integer> f, g; |
3233 |
+ |
ThreadExecutor exec = new ThreadExecutor(); |
3234 |
+ |
IntegerHandler r; |
3235 |
+ |
|
3236 |
+ |
f = new CompletableFuture<>(); |
3237 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3238 |
+ |
assertFalse(r.ran); |
3239 |
+ |
f.completeExceptionally(new CFException()); |
3240 |
+ |
checkCompletedWithWrappedCFException(f); |
3241 |
+ |
checkCompletedNormally(g, three); |
3242 |
+ |
assertTrue(r.ran); |
3243 |
+ |
|
3244 |
+ |
f = new CompletableFuture<>(); |
3245 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3246 |
+ |
assertFalse(r.ran); |
3247 |
+ |
f.completeExceptionally(new CFException()); |
3248 |
+ |
checkCompletedWithWrappedCFException(f); |
3249 |
+ |
checkCompletedNormally(g, three); |
3250 |
+ |
assertTrue(r.ran); |
3251 |
+ |
|
3252 |
+ |
f = new CompletableFuture<>(); |
3253 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3254 |
+ |
assertFalse(r.ran); |
3255 |
+ |
f.complete(one); |
3256 |
+ |
checkCompletedNormally(f, one); |
3257 |
+ |
checkCompletedNormally(g, two); |
3258 |
+ |
assertTrue(r.ran); |
3259 |
+ |
|
3260 |
+ |
f = new CompletableFuture<>(); |
3261 |
+ |
g = f.handleAsync(r = new IntegerHandler(), exec); |
3262 |
+ |
assertFalse(r.ran); |
3263 |
+ |
f.complete(one); |
3264 |
+ |
checkCompletedNormally(f, one); |
3265 |
+ |
checkCompletedNormally(g, two); |
3266 |
+ |
assertTrue(r.ran); |
3267 |
+ |
} |
3268 |
+ |
|
3269 |
|
} |