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; |
318 |
|
|
319 |
|
// Choose non-commutative actions for better coverage |
320 |
|
|
321 |
+ |
// A non-commutative function that handles null values as well, |
322 |
+ |
// and produces null values occasionally. |
323 |
+ |
public static Integer subtract(Integer x, Integer y) { |
324 |
+ |
return (x == null && y == null) ? null : |
325 |
+ |
((x == null) ? 42 : x.intValue()) |
326 |
+ |
- ((y == null) ? 99 : y.intValue()); |
327 |
+ |
} |
328 |
+ |
|
329 |
|
static final Supplier<Integer> supplyOne = |
330 |
|
() -> Integer.valueOf(1); |
331 |
|
static final Function<Integer, Integer> inc = |
332 |
|
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
333 |
|
static final BiFunction<Integer, Integer, Integer> subtract = |
334 |
< |
(Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue()); |
334 |
> |
(Integer x, Integer y) -> subtract(x, y); |
335 |
|
static final class IncAction implements Consumer<Integer> { |
336 |
|
int value; |
337 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
338 |
|
} |
339 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
340 |
< |
int value; |
340 |
> |
int invocationCount = 0; |
341 |
> |
Integer value; |
342 |
> |
// Check this action was invoked exactly once when result is computed. |
343 |
> |
public boolean ran() { return invocationCount == 1; } |
344 |
|
public void accept(Integer x, Integer y) { |
345 |
< |
value = x.intValue() - y.intValue(); |
345 |
> |
invocationCount++; |
346 |
> |
value = subtract(x, y); |
347 |
> |
} |
348 |
> |
} |
349 |
> |
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
350 |
> |
int invocationCount = 0; |
351 |
> |
Integer value; |
352 |
> |
// Check this action was invoked exactly once when result is computed. |
353 |
> |
public boolean ran() { return invocationCount == 1; } |
354 |
> |
public Integer apply(Integer x, Integer y) { |
355 |
> |
invocationCount++; |
356 |
> |
return value = subtract(x, y); |
357 |
|
} |
358 |
|
} |
359 |
|
static final class Noop implements Runnable { |
428 |
|
} |
429 |
|
|
430 |
|
/** |
431 |
+ |
* Permits the testing of parallel code for the 3 different |
432 |
+ |
* execution modes without repeating all the testing code. |
433 |
+ |
*/ |
434 |
+ |
enum ExecutionMode { |
435 |
+ |
DEFAULT { |
436 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
437 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
438 |
+ |
return f.runAfterBoth(g, a); |
439 |
+ |
} |
440 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
441 |
+ |
(CompletableFuture<T> f, |
442 |
+ |
CompletionStage<? extends U> g, |
443 |
+ |
BiConsumer<? super T,? super U> a) { |
444 |
+ |
return f.thenAcceptBoth(g, a); |
445 |
+ |
} |
446 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
447 |
+ |
(CompletableFuture<T> f, |
448 |
+ |
CompletionStage<? extends U> g, |
449 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
450 |
+ |
return f.thenCombine(g, a); |
451 |
+ |
} |
452 |
+ |
}, |
453 |
+ |
|
454 |
+ |
// /** Experimental way to do more testing */ |
455 |
+ |
// REVERSE_DEFAULT { |
456 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
457 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
458 |
+ |
// return g.runAfterBoth(f, a); |
459 |
+ |
// } |
460 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
461 |
+ |
// (CompletableFuture<T> f, |
462 |
+ |
// CompletionStage<? extends U> g, |
463 |
+ |
// BiConsumer<? super T,? super U> a) { |
464 |
+ |
// return DEFAULT.thenAcceptBoth(f, g, a); |
465 |
+ |
// } |
466 |
+ |
// }, |
467 |
+ |
|
468 |
+ |
DEFAULT_ASYNC { |
469 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
470 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
471 |
+ |
return f.runAfterBothAsync(g, a); |
472 |
+ |
} |
473 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
474 |
+ |
(CompletableFuture<T> f, |
475 |
+ |
CompletionStage<? extends U> g, |
476 |
+ |
BiConsumer<? super T,? super U> a) { |
477 |
+ |
return f.thenAcceptBothAsync(g, a); |
478 |
+ |
} |
479 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
480 |
+ |
(CompletableFuture<T> f, |
481 |
+ |
CompletionStage<? extends U> g, |
482 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
483 |
+ |
return f.thenCombineAsync(g, a); |
484 |
+ |
} |
485 |
+ |
}, |
486 |
+ |
|
487 |
+ |
// REVERSE_DEFAULT_ASYNC { |
488 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
489 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
490 |
+ |
// return f.runAfterBothAsync(g, a); |
491 |
+ |
// } |
492 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
493 |
+ |
// (CompletableFuture<T> f, |
494 |
+ |
// CompletionStage<? extends U> g, |
495 |
+ |
// BiConsumer<? super T,? super U> a) { |
496 |
+ |
// return DEFAULT_ASYNC.thenAcceptBoth(f, g, a); |
497 |
+ |
// } |
498 |
+ |
// }, |
499 |
+ |
|
500 |
+ |
EXECUTOR { |
501 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
502 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
503 |
+ |
return f.runAfterBothAsync(g, a, new ThreadExecutor()); |
504 |
+ |
} |
505 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
506 |
+ |
(CompletableFuture<T> f, |
507 |
+ |
CompletionStage<? extends U> g, |
508 |
+ |
BiConsumer<? super T,? super U> a) { |
509 |
+ |
return f.thenAcceptBothAsync(g, a, new ThreadExecutor()); |
510 |
+ |
} |
511 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
512 |
+ |
(CompletableFuture<T> f, |
513 |
+ |
CompletionStage<? extends U> g, |
514 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
515 |
+ |
return f.thenCombineAsync(g, a, new ThreadExecutor()); |
516 |
+ |
} |
517 |
+ |
}; |
518 |
+ |
|
519 |
+ |
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
520 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a); |
521 |
+ |
public abstract <T,U> CompletableFuture<Void> thenAcceptBoth |
522 |
+ |
(CompletableFuture<T> f, |
523 |
+ |
CompletionStage<? extends U> g, |
524 |
+ |
BiConsumer<? super T,? super U> a); |
525 |
+ |
public abstract <T,U,V> CompletableFuture<V> thenCombine |
526 |
+ |
(CompletableFuture<T> f, |
527 |
+ |
CompletionStage<? extends U> g, |
528 |
+ |
BiFunction<? super T,? super U,? extends V> a); |
529 |
+ |
} |
530 |
+ |
|
531 |
+ |
/** |
532 |
|
* exceptionally action completes with function value on source |
533 |
|
* exception; otherwise with source value |
534 |
|
*/ |
820 |
|
* thenCombine result completes normally after normal completion |
821 |
|
* of sources |
822 |
|
*/ |
823 |
< |
public void testThenCombine() { |
824 |
< |
CompletableFuture<Integer> f, g, h; |
823 |
> |
public void testThenCombine_normalCompletion1() { |
824 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
825 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
826 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
827 |
|
|
828 |
< |
f = new CompletableFuture<>(); |
829 |
< |
g = new CompletableFuture<>(); |
830 |
< |
h = f.thenCombine(g, subtract); |
831 |
< |
f.complete(3); |
828 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
829 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
830 |
> |
final SubtractFunction r = new SubtractFunction(); |
831 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
832 |
> |
|
833 |
> |
f.complete(v1); |
834 |
|
checkIncomplete(h); |
835 |
< |
g.complete(1); |
836 |
< |
checkCompletedNormally(h, 2); |
835 |
> |
assertFalse(r.ran()); |
836 |
> |
g.complete(v2); |
837 |
|
|
838 |
< |
f = new CompletableFuture<>(); |
839 |
< |
g = new CompletableFuture<>(); |
840 |
< |
h = f.thenCombine(g, subtract); |
841 |
< |
g.complete(1); |
838 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
839 |
> |
checkCompletedNormally(f, v1); |
840 |
> |
checkCompletedNormally(g, v2); |
841 |
> |
} |
842 |
> |
} |
843 |
> |
|
844 |
> |
public void testThenCombine_normalCompletion2() { |
845 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
846 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
847 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
848 |
> |
|
849 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
850 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
851 |
> |
final SubtractFunction r = new SubtractFunction(); |
852 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
853 |
> |
|
854 |
> |
g.complete(v2); |
855 |
|
checkIncomplete(h); |
856 |
< |
f.complete(3); |
857 |
< |
checkCompletedNormally(h, 2); |
856 |
> |
assertFalse(r.ran()); |
857 |
> |
f.complete(v1); |
858 |
|
|
859 |
< |
f = new CompletableFuture<>(); |
860 |
< |
g = new CompletableFuture<>(); |
861 |
< |
g.complete(1); |
862 |
< |
f.complete(3); |
863 |
< |
h = f.thenCombine(g, subtract); |
864 |
< |
checkCompletedNormally(h, 2); |
859 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
860 |
> |
checkCompletedNormally(f, v1); |
861 |
> |
checkCompletedNormally(g, v2); |
862 |
> |
} |
863 |
> |
} |
864 |
> |
|
865 |
> |
public void testThenCombine_normalCompletion3() { |
866 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
867 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
868 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
869 |
> |
|
870 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
871 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
872 |
> |
final SubtractFunction r = new SubtractFunction(); |
873 |
> |
|
874 |
> |
g.complete(v2); |
875 |
> |
f.complete(v1); |
876 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
877 |
> |
|
878 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
879 |
> |
checkCompletedNormally(f, v1); |
880 |
> |
checkCompletedNormally(g, v2); |
881 |
> |
} |
882 |
> |
} |
883 |
> |
|
884 |
> |
public void testThenCombine_normalCompletion4() { |
885 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
886 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
887 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
888 |
> |
|
889 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
890 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
891 |
> |
final SubtractFunction r = new SubtractFunction(); |
892 |
> |
|
893 |
> |
f.complete(v1); |
894 |
> |
g.complete(v2); |
895 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
896 |
> |
|
897 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
898 |
> |
checkCompletedNormally(f, v1); |
899 |
> |
checkCompletedNormally(g, v2); |
900 |
> |
} |
901 |
|
} |
902 |
|
|
903 |
|
/** |
904 |
|
* thenCombine result completes exceptionally after exceptional |
905 |
|
* completion of either source |
906 |
|
*/ |
907 |
< |
public void testThenCombine2() { |
908 |
< |
CompletableFuture<Integer> f, g, h; |
907 |
> |
public void testThenCombine_exceptionalCompletion1() { |
908 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
909 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
910 |
|
|
911 |
< |
f = new CompletableFuture<>(); |
912 |
< |
g = new CompletableFuture<>(); |
913 |
< |
h = f.thenCombine(g, subtract); |
914 |
< |
f.completeExceptionally(new CFException()); |
911 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
912 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
913 |
> |
final SubtractFunction r = new SubtractFunction(); |
914 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
915 |
> |
final CFException ex = new CFException(); |
916 |
> |
|
917 |
> |
f.completeExceptionally(ex); |
918 |
|
checkIncomplete(h); |
919 |
< |
g.complete(1); |
739 |
< |
checkCompletedWithWrappedCFException(h); |
919 |
> |
g.complete(v1); |
920 |
|
|
921 |
< |
f = new CompletableFuture<>(); |
922 |
< |
g = new CompletableFuture<>(); |
923 |
< |
h = f.thenCombine(g, subtract); |
924 |
< |
g.completeExceptionally(new CFException()); |
921 |
> |
checkCompletedWithWrappedCFException(h, ex); |
922 |
> |
checkCompletedWithWrappedCFException(f, ex); |
923 |
> |
assertFalse(r.ran()); |
924 |
> |
checkCompletedNormally(g, v1); |
925 |
> |
} |
926 |
> |
} |
927 |
> |
|
928 |
> |
public void testThenCombine_exceptionalCompletion2() { |
929 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
930 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
931 |
> |
|
932 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
933 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
934 |
> |
final SubtractFunction r = new SubtractFunction(); |
935 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
936 |
> |
final CFException ex = new CFException(); |
937 |
> |
|
938 |
> |
g.completeExceptionally(ex); |
939 |
|
checkIncomplete(h); |
940 |
< |
f.complete(3); |
747 |
< |
checkCompletedWithWrappedCFException(h); |
940 |
> |
f.complete(v1); |
941 |
|
|
942 |
< |
f = new CompletableFuture<>(); |
943 |
< |
g = new CompletableFuture<>(); |
944 |
< |
f.complete(3); |
945 |
< |
g.completeExceptionally(new CFException()); |
946 |
< |
h = f.thenCombine(g, subtract); |
947 |
< |
checkCompletedWithWrappedCFException(h); |
942 |
> |
checkCompletedWithWrappedCFException(h, ex); |
943 |
> |
checkCompletedWithWrappedCFException(g, ex); |
944 |
> |
assertFalse(r.ran()); |
945 |
> |
checkCompletedNormally(f, v1); |
946 |
> |
} |
947 |
> |
} |
948 |
|
|
949 |
< |
f = new CompletableFuture<>(); |
950 |
< |
g = new CompletableFuture<>(); |
951 |
< |
f.completeExceptionally(new CFException()); |
952 |
< |
g.complete(3); |
953 |
< |
h = f.thenCombine(g, subtract); |
954 |
< |
checkCompletedWithWrappedCFException(h); |
949 |
> |
public void testThenCombine_exceptionalCompletion3() { |
950 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
951 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
952 |
> |
|
953 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
954 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
955 |
> |
final SubtractFunction r = new SubtractFunction(); |
956 |
> |
final CFException ex = new CFException(); |
957 |
> |
|
958 |
> |
g.completeExceptionally(ex); |
959 |
> |
f.complete(v1); |
960 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
961 |
> |
|
962 |
> |
checkCompletedWithWrappedCFException(h, ex); |
963 |
> |
checkCompletedWithWrappedCFException(g, ex); |
964 |
> |
assertFalse(r.ran()); |
965 |
> |
checkCompletedNormally(f, v1); |
966 |
> |
} |
967 |
> |
} |
968 |
> |
|
969 |
> |
public void testThenCombine_exceptionalCompletion4() { |
970 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
971 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
972 |
> |
|
973 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
974 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
975 |
> |
final SubtractFunction r = new SubtractFunction(); |
976 |
> |
final CFException ex = new CFException(); |
977 |
> |
|
978 |
> |
f.completeExceptionally(ex); |
979 |
> |
g.complete(v1); |
980 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
981 |
> |
|
982 |
> |
checkCompletedWithWrappedCFException(h, ex); |
983 |
> |
checkCompletedWithWrappedCFException(f, ex); |
984 |
> |
assertFalse(r.ran()); |
985 |
> |
checkCompletedNormally(g, v1); |
986 |
> |
} |
987 |
|
} |
988 |
|
|
989 |
|
/** |
990 |
|
* thenCombine result completes exceptionally if action does |
991 |
|
*/ |
992 |
< |
public void testThenCombine3() { |
993 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
994 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
995 |
< |
FailingBiFunction r = new FailingBiFunction(); |
996 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
997 |
< |
f.complete(one); |
998 |
< |
checkIncomplete(g); |
999 |
< |
assertFalse(r.ran); |
1000 |
< |
f2.complete(two); |
1001 |
< |
checkCompletedWithWrappedCFException(g); |
1002 |
< |
assertTrue(r.ran); |
992 |
> |
public void testThenCombine_actionFailed1() { |
993 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
994 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
995 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
996 |
> |
|
997 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
998 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
999 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1000 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1001 |
> |
|
1002 |
> |
f.complete(v1); |
1003 |
> |
checkIncomplete(h); |
1004 |
> |
g.complete(v2); |
1005 |
> |
|
1006 |
> |
checkCompletedWithWrappedCFException(h); |
1007 |
> |
checkCompletedNormally(f, v1); |
1008 |
> |
checkCompletedNormally(g, v2); |
1009 |
> |
} |
1010 |
> |
} |
1011 |
> |
|
1012 |
> |
public void testThenCombine_actionFailed2() { |
1013 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1014 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1015 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1016 |
> |
|
1017 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1018 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1019 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1020 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1021 |
> |
|
1022 |
> |
g.complete(v2); |
1023 |
> |
checkIncomplete(h); |
1024 |
> |
f.complete(v1); |
1025 |
> |
|
1026 |
> |
checkCompletedWithWrappedCFException(h); |
1027 |
> |
checkCompletedNormally(f, v1); |
1028 |
> |
checkCompletedNormally(g, v2); |
1029 |
> |
} |
1030 |
|
} |
1031 |
|
|
1032 |
|
/** |
1033 |
|
* thenCombine result completes exceptionally if either source cancelled |
1034 |
|
*/ |
1035 |
< |
public void testThenCombine4() { |
1036 |
< |
CompletableFuture<Integer> f, g, h; |
1035 |
> |
public void testThenCombine_sourceCancelled1() { |
1036 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1037 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1038 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1039 |
|
|
1040 |
< |
f = new CompletableFuture<>(); |
1041 |
< |
g = new CompletableFuture<>(); |
1042 |
< |
h = f.thenCombine(g, subtract); |
1043 |
< |
assertTrue(f.cancel(true)); |
1040 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1041 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1042 |
> |
final SubtractFunction r = new SubtractFunction(); |
1043 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1044 |
> |
|
1045 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1046 |
|
checkIncomplete(h); |
1047 |
< |
g.complete(1); |
1047 |
> |
g.complete(v1); |
1048 |
> |
|
1049 |
|
checkCompletedWithWrappedCancellationException(h); |
1050 |
+ |
checkCancelled(f); |
1051 |
+ |
assertFalse(r.ran()); |
1052 |
+ |
checkCompletedNormally(g, v1); |
1053 |
+ |
} |
1054 |
+ |
} |
1055 |
|
|
1056 |
< |
f = new CompletableFuture<>(); |
1057 |
< |
g = new CompletableFuture<>(); |
1058 |
< |
h = f.thenCombine(g, subtract); |
1059 |
< |
assertTrue(g.cancel(true)); |
1056 |
> |
public void testThenCombine_sourceCancelled2() { |
1057 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1058 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1059 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1060 |
> |
|
1061 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1062 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1063 |
> |
final SubtractFunction r = new SubtractFunction(); |
1064 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1065 |
> |
|
1066 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1067 |
|
checkIncomplete(h); |
1068 |
< |
f.complete(3); |
1068 |
> |
f.complete(v1); |
1069 |
> |
|
1070 |
|
checkCompletedWithWrappedCancellationException(h); |
1071 |
+ |
checkCancelled(g); |
1072 |
+ |
assertFalse(r.ran()); |
1073 |
+ |
checkCompletedNormally(f, v1); |
1074 |
+ |
} |
1075 |
+ |
} |
1076 |
+ |
|
1077 |
+ |
public void testThenCombine_sourceCancelled3() { |
1078 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1079 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1080 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1081 |
+ |
|
1082 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1083 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1084 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1085 |
+ |
|
1086 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1087 |
+ |
f.complete(v1); |
1088 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1089 |
+ |
|
1090 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1091 |
+ |
checkCancelled(g); |
1092 |
+ |
assertFalse(r.ran()); |
1093 |
+ |
checkCompletedNormally(f, v1); |
1094 |
+ |
} |
1095 |
+ |
} |
1096 |
+ |
|
1097 |
+ |
public void testThenCombine_sourceCancelled4() { |
1098 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1099 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1100 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1101 |
+ |
|
1102 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1103 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1104 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1105 |
+ |
|
1106 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1107 |
+ |
g.complete(v1); |
1108 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1109 |
|
|
802 |
– |
f = new CompletableFuture<>(); |
803 |
– |
g = new CompletableFuture<>(); |
804 |
– |
assertTrue(f.cancel(true)); |
805 |
– |
assertTrue(g.cancel(true)); |
806 |
– |
h = f.thenCombine(g, subtract); |
1110 |
|
checkCompletedWithWrappedCancellationException(h); |
1111 |
+ |
checkCancelled(f); |
1112 |
+ |
assertFalse(r.ran()); |
1113 |
+ |
checkCompletedNormally(g, v1); |
1114 |
+ |
} |
1115 |
|
} |
1116 |
|
|
1117 |
|
/** |
1118 |
|
* thenAcceptBoth result completes normally after normal |
1119 |
|
* completion of sources |
1120 |
|
*/ |
1121 |
< |
public void testThenAcceptBoth() { |
1122 |
< |
CompletableFuture<Integer> f, g; |
1123 |
< |
CompletableFuture<Void> h; |
1124 |
< |
SubtractAction r; |
1121 |
> |
public void testThenAcceptBoth_normalCompletion1() { |
1122 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1123 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1124 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1125 |
|
|
1126 |
< |
f = new CompletableFuture<>(); |
1127 |
< |
g = new CompletableFuture<>(); |
1128 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1129 |
< |
f.complete(3); |
1126 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1127 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1128 |
> |
final SubtractAction r = new SubtractAction(); |
1129 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1130 |
> |
|
1131 |
> |
f.complete(v1); |
1132 |
|
checkIncomplete(h); |
1133 |
< |
g.complete(1); |
1133 |
> |
assertFalse(r.ran()); |
1134 |
> |
g.complete(v2); |
1135 |
> |
|
1136 |
|
checkCompletedNormally(h, null); |
1137 |
< |
assertEquals(r.value, 2); |
1137 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1138 |
> |
checkCompletedNormally(f, v1); |
1139 |
> |
checkCompletedNormally(g, v2); |
1140 |
> |
} |
1141 |
> |
} |
1142 |
|
|
1143 |
< |
f = new CompletableFuture<>(); |
1144 |
< |
g = new CompletableFuture<>(); |
1145 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1146 |
< |
g.complete(1); |
1143 |
> |
public void testThenAcceptBoth_normalCompletion2() { |
1144 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1145 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1146 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1147 |
> |
|
1148 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1149 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1150 |
> |
final SubtractAction r = new SubtractAction(); |
1151 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1152 |
> |
|
1153 |
> |
g.complete(v2); |
1154 |
|
checkIncomplete(h); |
1155 |
< |
f.complete(3); |
1155 |
> |
assertFalse(r.ran()); |
1156 |
> |
f.complete(v1); |
1157 |
> |
|
1158 |
|
checkCompletedNormally(h, null); |
1159 |
< |
assertEquals(r.value, 2); |
1159 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1160 |
> |
checkCompletedNormally(f, v1); |
1161 |
> |
checkCompletedNormally(g, v2); |
1162 |
> |
} |
1163 |
> |
} |
1164 |
> |
|
1165 |
> |
public void testThenAcceptBoth_normalCompletion3() { |
1166 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1167 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1168 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1169 |
> |
|
1170 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1171 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1172 |
> |
final SubtractAction r = new SubtractAction(); |
1173 |
> |
|
1174 |
> |
g.complete(v2); |
1175 |
> |
f.complete(v1); |
1176 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1177 |
|
|
837 |
– |
f = new CompletableFuture<>(); |
838 |
– |
g = new CompletableFuture<>(); |
839 |
– |
g.complete(1); |
840 |
– |
f.complete(3); |
841 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1178 |
|
checkCompletedNormally(h, null); |
1179 |
< |
assertEquals(r.value, 2); |
1179 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1180 |
> |
checkCompletedNormally(f, v1); |
1181 |
> |
checkCompletedNormally(g, v2); |
1182 |
> |
} |
1183 |
> |
} |
1184 |
> |
|
1185 |
> |
public void testThenAcceptBoth_normalCompletion4() { |
1186 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1187 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1188 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1189 |
> |
|
1190 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1191 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1192 |
> |
final SubtractAction r = new SubtractAction(); |
1193 |
> |
|
1194 |
> |
f.complete(v1); |
1195 |
> |
g.complete(v2); |
1196 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1197 |
> |
|
1198 |
> |
checkCompletedNormally(h, null); |
1199 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1200 |
> |
checkCompletedNormally(f, v1); |
1201 |
> |
checkCompletedNormally(g, v2); |
1202 |
> |
} |
1203 |
|
} |
1204 |
|
|
1205 |
|
/** |
1206 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1207 |
|
* completion of either source |
1208 |
|
*/ |
1209 |
< |
public void testThenAcceptBoth2() { |
1210 |
< |
CompletableFuture<Integer> f, g; |
1211 |
< |
CompletableFuture<Void> h; |
853 |
< |
SubtractAction r; |
1209 |
> |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1210 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1211 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1212 |
|
|
1213 |
< |
f = new CompletableFuture<>(); |
1214 |
< |
g = new CompletableFuture<>(); |
1215 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1216 |
< |
f.completeExceptionally(new CFException()); |
1213 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1214 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1215 |
> |
final SubtractAction r = new SubtractAction(); |
1216 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1217 |
> |
final CFException ex = new CFException(); |
1218 |
> |
|
1219 |
> |
f.completeExceptionally(ex); |
1220 |
|
checkIncomplete(h); |
1221 |
< |
g.complete(1); |
861 |
< |
checkCompletedWithWrappedCFException(h); |
1221 |
> |
g.complete(v1); |
1222 |
|
|
1223 |
< |
f = new CompletableFuture<>(); |
1224 |
< |
g = new CompletableFuture<>(); |
1225 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1226 |
< |
g.completeExceptionally(new CFException()); |
1223 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1224 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1225 |
> |
assertFalse(r.ran()); |
1226 |
> |
checkCompletedNormally(g, v1); |
1227 |
> |
} |
1228 |
> |
} |
1229 |
> |
|
1230 |
> |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1231 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1232 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1233 |
> |
|
1234 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1235 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1236 |
> |
final SubtractAction r = new SubtractAction(); |
1237 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1238 |
> |
final CFException ex = new CFException(); |
1239 |
> |
|
1240 |
> |
g.completeExceptionally(ex); |
1241 |
|
checkIncomplete(h); |
1242 |
< |
f.complete(3); |
869 |
< |
checkCompletedWithWrappedCFException(h); |
1242 |
> |
f.complete(v1); |
1243 |
|
|
1244 |
< |
f = new CompletableFuture<>(); |
1245 |
< |
g = new CompletableFuture<>(); |
1246 |
< |
f.complete(3); |
1247 |
< |
g.completeExceptionally(new CFException()); |
1248 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1249 |
< |
checkCompletedWithWrappedCFException(h); |
1244 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1245 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1246 |
> |
assertFalse(r.ran()); |
1247 |
> |
checkCompletedNormally(f, v1); |
1248 |
> |
} |
1249 |
> |
} |
1250 |
|
|
1251 |
< |
f = new CompletableFuture<>(); |
1252 |
< |
g = new CompletableFuture<>(); |
1253 |
< |
f.completeExceptionally(new CFException()); |
1254 |
< |
g.complete(3); |
1255 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1256 |
< |
checkCompletedWithWrappedCFException(h); |
1251 |
> |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1252 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1253 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1254 |
> |
|
1255 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1256 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1257 |
> |
final SubtractAction r = new SubtractAction(); |
1258 |
> |
final CFException ex = new CFException(); |
1259 |
> |
|
1260 |
> |
g.completeExceptionally(ex); |
1261 |
> |
f.complete(v1); |
1262 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1263 |
> |
|
1264 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1265 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1266 |
> |
assertFalse(r.ran()); |
1267 |
> |
checkCompletedNormally(f, v1); |
1268 |
> |
} |
1269 |
> |
} |
1270 |
> |
|
1271 |
> |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1272 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1273 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1274 |
> |
|
1275 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1276 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1277 |
> |
final SubtractAction r = new SubtractAction(); |
1278 |
> |
final CFException ex = new CFException(); |
1279 |
> |
|
1280 |
> |
f.completeExceptionally(ex); |
1281 |
> |
g.complete(v1); |
1282 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1283 |
> |
|
1284 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1285 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1286 |
> |
assertFalse(r.ran()); |
1287 |
> |
checkCompletedNormally(g, v1); |
1288 |
> |
} |
1289 |
|
} |
1290 |
|
|
1291 |
|
/** |
1292 |
|
* thenAcceptBoth result completes exceptionally if action does |
1293 |
|
*/ |
1294 |
< |
public void testThenAcceptBoth3() { |
1295 |
< |
CompletableFuture<Integer> f, g; |
1296 |
< |
CompletableFuture<Void> h; |
1297 |
< |
FailingBiConsumer r; |
1294 |
> |
public void testThenAcceptBoth_actionFailed1() { |
1295 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1296 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1297 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1298 |
|
|
1299 |
< |
f = new CompletableFuture<>(); |
1300 |
< |
g = new CompletableFuture<>(); |
1301 |
< |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1302 |
< |
f.complete(3); |
1299 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1300 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1301 |
> |
final FailingBiConsumer r = new FailingBiConsumer(); |
1302 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1303 |
> |
|
1304 |
> |
f.complete(v1); |
1305 |
|
checkIncomplete(h); |
1306 |
< |
g.complete(1); |
1306 |
> |
g.complete(v2); |
1307 |
> |
|
1308 |
|
checkCompletedWithWrappedCFException(h); |
1309 |
+ |
checkCompletedNormally(f, v1); |
1310 |
+ |
checkCompletedNormally(g, v2); |
1311 |
+ |
} |
1312 |
+ |
} |
1313 |
+ |
|
1314 |
+ |
public void testThenAcceptBoth_actionFailed2() { |
1315 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1317 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1318 |
+ |
|
1319 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1320 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1321 |
+ |
final FailingBiConsumer r = new FailingBiConsumer(); |
1322 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1323 |
+ |
|
1324 |
+ |
g.complete(v2); |
1325 |
+ |
checkIncomplete(h); |
1326 |
+ |
f.complete(v1); |
1327 |
|
|
902 |
– |
f = new CompletableFuture<>(); |
903 |
– |
g = new CompletableFuture<>(); |
904 |
– |
f.complete(3); |
905 |
– |
g.complete(1); |
906 |
– |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1328 |
|
checkCompletedWithWrappedCFException(h); |
1329 |
+ |
checkCompletedNormally(f, v1); |
1330 |
+ |
checkCompletedNormally(g, v2); |
1331 |
+ |
} |
1332 |
|
} |
1333 |
|
|
1334 |
|
/** |
1335 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1336 |
|
*/ |
1337 |
< |
public void testThenAcceptBoth4() { |
1338 |
< |
CompletableFuture<Integer> f, g; |
1339 |
< |
CompletableFuture<Void> h; |
1340 |
< |
SubtractAction r; |
1337 |
> |
public void testThenAcceptBoth_sourceCancelled1() { |
1338 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1339 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1340 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1341 |
|
|
1342 |
< |
f = new CompletableFuture<>(); |
1343 |
< |
g = new CompletableFuture<>(); |
1344 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1345 |
< |
assertTrue(f.cancel(true)); |
1342 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1343 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1344 |
> |
final SubtractAction r = new SubtractAction(); |
1345 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1346 |
> |
|
1347 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1348 |
|
checkIncomplete(h); |
1349 |
< |
g.complete(1); |
1349 |
> |
g.complete(v1); |
1350 |
> |
|
1351 |
|
checkCompletedWithWrappedCancellationException(h); |
1352 |
+ |
checkCancelled(f); |
1353 |
+ |
assertFalse(r.ran()); |
1354 |
+ |
checkCompletedNormally(g, v1); |
1355 |
+ |
} |
1356 |
+ |
} |
1357 |
|
|
1358 |
< |
f = new CompletableFuture<>(); |
1359 |
< |
g = new CompletableFuture<>(); |
1360 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1361 |
< |
assertTrue(g.cancel(true)); |
1358 |
> |
public void testThenAcceptBoth_sourceCancelled2() { |
1359 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1360 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1361 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1362 |
> |
|
1363 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1364 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1365 |
> |
final SubtractAction r = new SubtractAction(); |
1366 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1367 |
> |
|
1368 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1369 |
|
checkIncomplete(h); |
1370 |
< |
f.complete(3); |
1370 |
> |
f.complete(v1); |
1371 |
> |
|
1372 |
|
checkCompletedWithWrappedCancellationException(h); |
1373 |
+ |
checkCancelled(g); |
1374 |
+ |
assertFalse(r.ran()); |
1375 |
+ |
checkCompletedNormally(f, v1); |
1376 |
+ |
} |
1377 |
+ |
} |
1378 |
+ |
|
1379 |
+ |
public void testThenAcceptBoth_sourceCancelled3() { |
1380 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1381 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1382 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1383 |
+ |
|
1384 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1385 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1386 |
+ |
final SubtractAction r = new SubtractAction(); |
1387 |
+ |
|
1388 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1389 |
+ |
f.complete(v1); |
1390 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1391 |
|
|
934 |
– |
f = new CompletableFuture<>(); |
935 |
– |
g = new CompletableFuture<>(); |
936 |
– |
f.complete(3); |
937 |
– |
assertTrue(g.cancel(true)); |
938 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1392 |
|
checkCompletedWithWrappedCancellationException(h); |
1393 |
+ |
checkCancelled(g); |
1394 |
+ |
assertFalse(r.ran()); |
1395 |
+ |
checkCompletedNormally(f, v1); |
1396 |
+ |
} |
1397 |
+ |
} |
1398 |
+ |
|
1399 |
+ |
public void testThenAcceptBoth_sourceCancelled4() { |
1400 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1401 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1402 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1403 |
+ |
|
1404 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1405 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1406 |
+ |
final SubtractAction r = new SubtractAction(); |
1407 |
+ |
|
1408 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1409 |
+ |
g.complete(v1); |
1410 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1411 |
|
|
941 |
– |
f = new CompletableFuture<>(); |
942 |
– |
g = new CompletableFuture<>(); |
943 |
– |
assertTrue(f.cancel(true)); |
944 |
– |
g.complete(3); |
945 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1412 |
|
checkCompletedWithWrappedCancellationException(h); |
1413 |
+ |
checkCancelled(f); |
1414 |
+ |
assertFalse(r.ran()); |
1415 |
+ |
checkCompletedNormally(g, v1); |
1416 |
+ |
} |
1417 |
|
} |
1418 |
|
|
1419 |
|
/** |
1421 |
|
* completion of sources |
1422 |
|
*/ |
1423 |
|
public void testRunAfterBoth_normalCompletion1() { |
1424 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1425 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1426 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1427 |
|
|
1428 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1429 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1430 |
|
final Noop r = new Noop(); |
1431 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1431 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1432 |
|
|
1433 |
|
f.complete(v1); |
1434 |
|
checkIncomplete(h); |
1443 |
|
} |
1444 |
|
|
1445 |
|
public void testRunAfterBoth_normalCompletion2() { |
1446 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1447 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1448 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1449 |
|
|
1450 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1451 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1452 |
|
final Noop r = new Noop(); |
1453 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1453 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1454 |
|
|
1455 |
|
g.complete(v2); |
1456 |
|
checkIncomplete(h); |
1465 |
|
} |
1466 |
|
|
1467 |
|
public void testRunAfterBoth_normalCompletion3() { |
1468 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1469 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1470 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1471 |
|
|
1475 |
|
|
1476 |
|
g.complete(v2); |
1477 |
|
f.complete(v1); |
1478 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1478 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1479 |
|
|
1480 |
|
checkCompletedNormally(h, null); |
1481 |
|
assertTrue(r.ran); |
1485 |
|
} |
1486 |
|
|
1487 |
|
public void testRunAfterBoth_normalCompletion4() { |
1488 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1489 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1490 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1491 |
|
|
1495 |
|
|
1496 |
|
f.complete(v1); |
1497 |
|
g.complete(v2); |
1498 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1498 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1499 |
|
|
1500 |
|
checkCompletedNormally(h, null); |
1501 |
|
assertTrue(r.ran); |
1509 |
|
* completion of either source |
1510 |
|
*/ |
1511 |
|
public void testRunAfterBoth_exceptionalCompletion1() { |
1512 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1513 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1514 |
|
|
1515 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1516 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1517 |
|
final Noop r = new Noop(); |
1518 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1518 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1519 |
|
final CFException ex = new CFException(); |
1520 |
|
|
1521 |
|
f.completeExceptionally(ex); |
1530 |
|
} |
1531 |
|
|
1532 |
|
public void testRunAfterBoth_exceptionalCompletion2() { |
1533 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1534 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1535 |
|
|
1536 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1537 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1538 |
|
final Noop r = new Noop(); |
1539 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1539 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1540 |
|
final CFException ex = new CFException(); |
1541 |
|
|
1542 |
|
g.completeExceptionally(ex); |
1551 |
|
} |
1552 |
|
|
1553 |
|
public void testRunAfterBoth_exceptionalCompletion3() { |
1554 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1555 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1556 |
|
|
1557 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1561 |
|
|
1562 |
|
g.completeExceptionally(ex); |
1563 |
|
f.complete(v1); |
1564 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1564 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1565 |
|
|
1566 |
|
checkCompletedWithWrappedCFException(h, ex); |
1567 |
|
checkCompletedWithWrappedCFException(g, ex); |
1571 |
|
} |
1572 |
|
|
1573 |
|
public void testRunAfterBoth_exceptionalCompletion4() { |
1574 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1575 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1576 |
|
|
1577 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1581 |
|
|
1582 |
|
f.completeExceptionally(ex); |
1583 |
|
g.complete(v1); |
1584 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1584 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
|
|
1586 |
|
checkCompletedWithWrappedCFException(h, ex); |
1587 |
|
checkCompletedWithWrappedCFException(f, ex); |
1594 |
|
* runAfterBoth result completes exceptionally if action does |
1595 |
|
*/ |
1596 |
|
public void testRunAfterBoth_actionFailed1() { |
1597 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1598 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1599 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1600 |
|
|
1601 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1602 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1603 |
|
final FailingNoop r = new FailingNoop(); |
1604 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1604 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1605 |
|
|
1606 |
|
f.complete(v1); |
1607 |
|
checkIncomplete(h); |
1614 |
|
} |
1615 |
|
|
1616 |
|
public void testRunAfterBoth_actionFailed2() { |
1617 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1618 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1619 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1620 |
|
|
1621 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1622 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1623 |
|
final FailingNoop r = new FailingNoop(); |
1624 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1624 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1625 |
|
|
1626 |
|
g.complete(v2); |
1627 |
|
checkIncomplete(h); |
1637 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1638 |
|
*/ |
1639 |
|
public void testRunAfterBoth_sourceCancelled1() { |
1640 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1641 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1642 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1643 |
|
|
1644 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1645 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1646 |
|
final Noop r = new Noop(); |
1647 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1647 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1648 |
|
|
1649 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1650 |
|
checkIncomplete(h); |
1658 |
|
} |
1659 |
|
|
1660 |
|
public void testRunAfterBoth_sourceCancelled2() { |
1661 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1662 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1663 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1664 |
|
|
1665 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1666 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1667 |
|
final Noop r = new Noop(); |
1668 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1668 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1669 |
|
|
1670 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
1671 |
|
checkIncomplete(h); |
1679 |
|
} |
1680 |
|
|
1681 |
|
public void testRunAfterBoth_sourceCancelled3() { |
1682 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1683 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1684 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1685 |
|
|
1689 |
|
|
1690 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
1691 |
|
f.complete(v1); |
1692 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1692 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1693 |
|
|
1694 |
|
checkCompletedWithWrappedCancellationException(h); |
1695 |
|
checkCancelled(g); |
1699 |
|
} |
1700 |
|
|
1701 |
|
public void testRunAfterBoth_sourceCancelled4() { |
1702 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1703 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1704 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1705 |
|
|
1709 |
|
|
1710 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1711 |
|
g.complete(v1); |
1712 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1712 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1713 |
|
|
1714 |
|
checkCompletedWithWrappedCancellationException(h); |
1715 |
|
checkCancelled(f); |
2153 |
|
} |
2154 |
|
|
2155 |
|
/** |
1672 |
– |
* thenCombineAsync result completes normally after normal |
1673 |
– |
* completion of sources |
1674 |
– |
*/ |
1675 |
– |
public void testThenCombineAsync() { |
1676 |
– |
CompletableFuture<Integer> f, g, h; |
1677 |
– |
|
1678 |
– |
f = new CompletableFuture<>(); |
1679 |
– |
g = new CompletableFuture<>(); |
1680 |
– |
h = f.thenCombineAsync(g, subtract); |
1681 |
– |
f.complete(3); |
1682 |
– |
checkIncomplete(h); |
1683 |
– |
g.complete(1); |
1684 |
– |
checkCompletedNormally(h, 2); |
1685 |
– |
|
1686 |
– |
f = new CompletableFuture<>(); |
1687 |
– |
g = new CompletableFuture<>(); |
1688 |
– |
h = f.thenCombineAsync(g, subtract); |
1689 |
– |
g.complete(1); |
1690 |
– |
checkIncomplete(h); |
1691 |
– |
f.complete(3); |
1692 |
– |
checkCompletedNormally(h, 2); |
1693 |
– |
|
1694 |
– |
f = new CompletableFuture<>(); |
1695 |
– |
g = new CompletableFuture<>(); |
1696 |
– |
g.complete(1); |
1697 |
– |
f.complete(3); |
1698 |
– |
h = f.thenCombineAsync(g, subtract); |
1699 |
– |
checkCompletedNormally(h, 2); |
1700 |
– |
} |
1701 |
– |
|
1702 |
– |
/** |
1703 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
1704 |
– |
* completion of either source |
1705 |
– |
*/ |
1706 |
– |
public void testThenCombineAsync2() { |
1707 |
– |
CompletableFuture<Integer> f, g, h; |
1708 |
– |
|
1709 |
– |
f = new CompletableFuture<>(); |
1710 |
– |
g = new CompletableFuture<>(); |
1711 |
– |
h = f.thenCombineAsync(g, subtract); |
1712 |
– |
f.completeExceptionally(new CFException()); |
1713 |
– |
checkIncomplete(h); |
1714 |
– |
g.complete(1); |
1715 |
– |
checkCompletedWithWrappedCFException(h); |
1716 |
– |
|
1717 |
– |
f = new CompletableFuture<>(); |
1718 |
– |
g = new CompletableFuture<>(); |
1719 |
– |
h = f.thenCombineAsync(g, subtract); |
1720 |
– |
g.completeExceptionally(new CFException()); |
1721 |
– |
checkIncomplete(h); |
1722 |
– |
f.complete(3); |
1723 |
– |
checkCompletedWithWrappedCFException(h); |
1724 |
– |
|
1725 |
– |
f = new CompletableFuture<>(); |
1726 |
– |
g = new CompletableFuture<>(); |
1727 |
– |
g.completeExceptionally(new CFException()); |
1728 |
– |
f.complete(3); |
1729 |
– |
h = f.thenCombineAsync(g, subtract); |
1730 |
– |
checkCompletedWithWrappedCFException(h); |
1731 |
– |
} |
1732 |
– |
|
1733 |
– |
/** |
1734 |
– |
* thenCombineAsync result completes exceptionally if action does |
1735 |
– |
*/ |
1736 |
– |
public void testThenCombineAsync3() { |
1737 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1738 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1739 |
– |
FailingBiFunction r = new FailingBiFunction(); |
1740 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1741 |
– |
f.complete(one); |
1742 |
– |
checkIncomplete(g); |
1743 |
– |
assertFalse(r.ran); |
1744 |
– |
f2.complete(two); |
1745 |
– |
checkCompletedWithWrappedCFException(g); |
1746 |
– |
assertTrue(r.ran); |
1747 |
– |
} |
1748 |
– |
|
1749 |
– |
/** |
1750 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
1751 |
– |
*/ |
1752 |
– |
public void testThenCombineAsync4() { |
1753 |
– |
CompletableFuture<Integer> f, g, h; |
1754 |
– |
|
1755 |
– |
f = new CompletableFuture<>(); |
1756 |
– |
g = new CompletableFuture<>(); |
1757 |
– |
h = f.thenCombineAsync(g, subtract); |
1758 |
– |
assertTrue(f.cancel(true)); |
1759 |
– |
checkIncomplete(h); |
1760 |
– |
g.complete(1); |
1761 |
– |
checkCompletedWithWrappedCancellationException(h); |
1762 |
– |
|
1763 |
– |
f = new CompletableFuture<>(); |
1764 |
– |
g = new CompletableFuture<>(); |
1765 |
– |
h = f.thenCombineAsync(g, subtract); |
1766 |
– |
assertTrue(g.cancel(true)); |
1767 |
– |
checkIncomplete(h); |
1768 |
– |
f.complete(3); |
1769 |
– |
checkCompletedWithWrappedCancellationException(h); |
1770 |
– |
|
1771 |
– |
f = new CompletableFuture<>(); |
1772 |
– |
g = new CompletableFuture<>(); |
1773 |
– |
g.complete(3); |
1774 |
– |
assertTrue(f.cancel(true)); |
1775 |
– |
h = f.thenCombineAsync(g, subtract); |
1776 |
– |
checkCompletedWithWrappedCancellationException(h); |
1777 |
– |
|
1778 |
– |
f = new CompletableFuture<>(); |
1779 |
– |
g = new CompletableFuture<>(); |
1780 |
– |
f.complete(3); |
1781 |
– |
assertTrue(g.cancel(true)); |
1782 |
– |
h = f.thenCombineAsync(g, subtract); |
1783 |
– |
checkCompletedWithWrappedCancellationException(h); |
1784 |
– |
} |
1785 |
– |
|
1786 |
– |
/** |
1787 |
– |
* thenAcceptBothAsync result completes normally after normal |
1788 |
– |
* completion of sources |
1789 |
– |
*/ |
1790 |
– |
public void testThenAcceptBothAsync() { |
1791 |
– |
CompletableFuture<Integer> f, g; |
1792 |
– |
CompletableFuture<Void> h; |
1793 |
– |
SubtractAction r; |
1794 |
– |
|
1795 |
– |
f = new CompletableFuture<>(); |
1796 |
– |
g = new CompletableFuture<>(); |
1797 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1798 |
– |
f.complete(3); |
1799 |
– |
checkIncomplete(h); |
1800 |
– |
g.complete(1); |
1801 |
– |
checkCompletedNormally(h, null); |
1802 |
– |
assertEquals(r.value, 2); |
1803 |
– |
|
1804 |
– |
f = new CompletableFuture<>(); |
1805 |
– |
g = new CompletableFuture<>(); |
1806 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1807 |
– |
g.complete(1); |
1808 |
– |
checkIncomplete(h); |
1809 |
– |
f.complete(3); |
1810 |
– |
checkCompletedNormally(h, null); |
1811 |
– |
assertEquals(r.value, 2); |
1812 |
– |
|
1813 |
– |
f = new CompletableFuture<>(); |
1814 |
– |
g = new CompletableFuture<>(); |
1815 |
– |
g.complete(1); |
1816 |
– |
f.complete(3); |
1817 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1818 |
– |
checkCompletedNormally(h, null); |
1819 |
– |
assertEquals(r.value, 2); |
1820 |
– |
} |
1821 |
– |
|
1822 |
– |
/** |
1823 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
1824 |
– |
* completion of source |
1825 |
– |
*/ |
1826 |
– |
public void testThenAcceptBothAsync2() { |
1827 |
– |
CompletableFuture<Integer> f, g; |
1828 |
– |
CompletableFuture<Void> h; |
1829 |
– |
SubtractAction r; |
1830 |
– |
|
1831 |
– |
f = new CompletableFuture<>(); |
1832 |
– |
g = new CompletableFuture<>(); |
1833 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1834 |
– |
f.completeExceptionally(new CFException()); |
1835 |
– |
checkIncomplete(h); |
1836 |
– |
g.complete(1); |
1837 |
– |
checkCompletedWithWrappedCFException(h); |
1838 |
– |
|
1839 |
– |
f = new CompletableFuture<>(); |
1840 |
– |
g = new CompletableFuture<>(); |
1841 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1842 |
– |
g.completeExceptionally(new CFException()); |
1843 |
– |
checkIncomplete(h); |
1844 |
– |
f.complete(3); |
1845 |
– |
checkCompletedWithWrappedCFException(h); |
1846 |
– |
|
1847 |
– |
f = new CompletableFuture<>(); |
1848 |
– |
g = new CompletableFuture<>(); |
1849 |
– |
f.complete(3); |
1850 |
– |
g.completeExceptionally(new CFException()); |
1851 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1852 |
– |
checkCompletedWithWrappedCFException(h); |
1853 |
– |
|
1854 |
– |
f = new CompletableFuture<>(); |
1855 |
– |
g = new CompletableFuture<>(); |
1856 |
– |
f.completeExceptionally(new CFException()); |
1857 |
– |
g.complete(3); |
1858 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1859 |
– |
checkCompletedWithWrappedCFException(h); |
1860 |
– |
} |
1861 |
– |
|
1862 |
– |
/** |
1863 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
1864 |
– |
*/ |
1865 |
– |
public void testThenAcceptBothAsync3() { |
1866 |
– |
CompletableFuture<Integer> f, g; |
1867 |
– |
CompletableFuture<Void> h; |
1868 |
– |
FailingBiConsumer r; |
1869 |
– |
|
1870 |
– |
f = new CompletableFuture<>(); |
1871 |
– |
g = new CompletableFuture<>(); |
1872 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1873 |
– |
f.complete(3); |
1874 |
– |
checkIncomplete(h); |
1875 |
– |
g.complete(1); |
1876 |
– |
checkCompletedWithWrappedCFException(h); |
1877 |
– |
|
1878 |
– |
f = new CompletableFuture<>(); |
1879 |
– |
g = new CompletableFuture<>(); |
1880 |
– |
f.complete(3); |
1881 |
– |
g.complete(1); |
1882 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1883 |
– |
checkCompletedWithWrappedCFException(h); |
1884 |
– |
} |
1885 |
– |
|
1886 |
– |
/** |
1887 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1888 |
– |
*/ |
1889 |
– |
public void testThenAcceptBothAsync4() { |
1890 |
– |
CompletableFuture<Integer> f, g; |
1891 |
– |
CompletableFuture<Void> h; |
1892 |
– |
SubtractAction r; |
1893 |
– |
|
1894 |
– |
f = new CompletableFuture<>(); |
1895 |
– |
g = new CompletableFuture<>(); |
1896 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1897 |
– |
assertTrue(f.cancel(true)); |
1898 |
– |
checkIncomplete(h); |
1899 |
– |
g.complete(1); |
1900 |
– |
checkCompletedWithWrappedCancellationException(h); |
1901 |
– |
|
1902 |
– |
f = new CompletableFuture<>(); |
1903 |
– |
g = new CompletableFuture<>(); |
1904 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1905 |
– |
assertTrue(g.cancel(true)); |
1906 |
– |
checkIncomplete(h); |
1907 |
– |
f.complete(3); |
1908 |
– |
checkCompletedWithWrappedCancellationException(h); |
1909 |
– |
|
1910 |
– |
f = new CompletableFuture<>(); |
1911 |
– |
g = new CompletableFuture<>(); |
1912 |
– |
f.complete(3); |
1913 |
– |
assertTrue(g.cancel(true)); |
1914 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1915 |
– |
checkCompletedWithWrappedCancellationException(h); |
1916 |
– |
|
1917 |
– |
f = new CompletableFuture<>(); |
1918 |
– |
g = new CompletableFuture<>(); |
1919 |
– |
assertTrue(f.cancel(true)); |
1920 |
– |
g.complete(3); |
1921 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1922 |
– |
checkCompletedWithWrappedCancellationException(h); |
1923 |
– |
} |
1924 |
– |
|
1925 |
– |
/** |
1926 |
– |
* runAfterBothAsync result completes normally after normal |
1927 |
– |
* completion of sources |
1928 |
– |
*/ |
1929 |
– |
public void testRunAfterBothAsync() { |
1930 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1931 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1932 |
– |
Noop r = new Noop(); |
1933 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1934 |
– |
f.complete(one); |
1935 |
– |
checkIncomplete(g); |
1936 |
– |
f2.complete(two); |
1937 |
– |
checkCompletedNormally(g, null); |
1938 |
– |
assertTrue(r.ran); |
1939 |
– |
} |
1940 |
– |
|
1941 |
– |
/** |
1942 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
1943 |
– |
* completion of source |
1944 |
– |
*/ |
1945 |
– |
public void testRunAfterBothAsync2() { |
1946 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1947 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1948 |
– |
Noop r = new Noop(); |
1949 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1950 |
– |
f.completeExceptionally(new CFException()); |
1951 |
– |
f2.complete(two); |
1952 |
– |
checkCompletedWithWrappedCFException(g); |
1953 |
– |
|
1954 |
– |
r = new Noop(); |
1955 |
– |
f = new CompletableFuture<>(); |
1956 |
– |
f2 = new CompletableFuture<>(); |
1957 |
– |
g = f.runAfterBothAsync(f2, r); |
1958 |
– |
f.complete(one); |
1959 |
– |
f2.completeExceptionally(new CFException()); |
1960 |
– |
checkCompletedWithWrappedCFException(g); |
1961 |
– |
} |
1962 |
– |
|
1963 |
– |
/** |
1964 |
– |
* runAfterBothAsync result completes exceptionally if action does |
1965 |
– |
*/ |
1966 |
– |
public void testRunAfterBothAsync3() { |
1967 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1968 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1969 |
– |
FailingNoop r = new FailingNoop(); |
1970 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1971 |
– |
f.complete(one); |
1972 |
– |
checkIncomplete(g); |
1973 |
– |
f2.complete(two); |
1974 |
– |
checkCompletedWithWrappedCFException(g); |
1975 |
– |
} |
1976 |
– |
|
1977 |
– |
/** |
1978 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
1979 |
– |
*/ |
1980 |
– |
public void testRunAfterBothAsync4() { |
1981 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1982 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1983 |
– |
Noop r = new Noop(); |
1984 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1985 |
– |
assertTrue(f.cancel(true)); |
1986 |
– |
f2.complete(two); |
1987 |
– |
checkCompletedWithWrappedCancellationException(g); |
1988 |
– |
|
1989 |
– |
r = new Noop(); |
1990 |
– |
f = new CompletableFuture<>(); |
1991 |
– |
f2 = new CompletableFuture<>(); |
1992 |
– |
g = f.runAfterBothAsync(f2, r); |
1993 |
– |
f.complete(one); |
1994 |
– |
assertTrue(f2.cancel(true)); |
1995 |
– |
checkCompletedWithWrappedCancellationException(g); |
1996 |
– |
} |
1997 |
– |
|
1998 |
– |
/** |
2156 |
|
* applyToEitherAsync result completes normally after normal |
2157 |
|
* completion of sources |
2158 |
|
*/ |
2591 |
|
checkCompletedWithWrappedCancellationException(g); |
2592 |
|
} |
2593 |
|
|
2437 |
– |
/** |
2438 |
– |
* thenCombineAsync result completes normally after normal |
2439 |
– |
* completion of sources |
2440 |
– |
*/ |
2441 |
– |
public void testThenCombineAsyncE() { |
2442 |
– |
CompletableFuture<Integer> f, g, h; |
2443 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2444 |
– |
int count = 0; |
2445 |
– |
|
2446 |
– |
f = new CompletableFuture<>(); |
2447 |
– |
g = new CompletableFuture<>(); |
2448 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2449 |
– |
f.complete(3); |
2450 |
– |
checkIncomplete(h); |
2451 |
– |
g.complete(1); |
2452 |
– |
checkCompletedNormally(h, 2); |
2453 |
– |
assertEquals(++count, e.count.get()); |
2454 |
– |
|
2455 |
– |
f = new CompletableFuture<>(); |
2456 |
– |
g = new CompletableFuture<>(); |
2457 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2458 |
– |
g.complete(1); |
2459 |
– |
checkIncomplete(h); |
2460 |
– |
f.complete(3); |
2461 |
– |
checkCompletedNormally(h, 2); |
2462 |
– |
assertEquals(++count, e.count.get()); |
2463 |
– |
|
2464 |
– |
f = new CompletableFuture<>(); |
2465 |
– |
g = new CompletableFuture<>(); |
2466 |
– |
g.complete(1); |
2467 |
– |
f.complete(3); |
2468 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2469 |
– |
checkCompletedNormally(h, 2); |
2470 |
– |
assertEquals(++count, e.count.get()); |
2471 |
– |
} |
2472 |
– |
|
2473 |
– |
/** |
2474 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
2475 |
– |
* completion of either source |
2476 |
– |
*/ |
2477 |
– |
public void testThenCombineAsync2E() { |
2478 |
– |
CompletableFuture<Integer> f, g, h; |
2479 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2480 |
– |
int count = 0; |
2481 |
– |
|
2482 |
– |
f = new CompletableFuture<>(); |
2483 |
– |
g = new CompletableFuture<>(); |
2484 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2485 |
– |
f.completeExceptionally(new CFException()); |
2486 |
– |
checkIncomplete(h); |
2487 |
– |
g.complete(1); |
2488 |
– |
checkCompletedWithWrappedCFException(h); |
2489 |
– |
|
2490 |
– |
f = new CompletableFuture<>(); |
2491 |
– |
g = new CompletableFuture<>(); |
2492 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2493 |
– |
g.completeExceptionally(new CFException()); |
2494 |
– |
checkIncomplete(h); |
2495 |
– |
f.complete(3); |
2496 |
– |
checkCompletedWithWrappedCFException(h); |
2497 |
– |
|
2498 |
– |
f = new CompletableFuture<>(); |
2499 |
– |
g = new CompletableFuture<>(); |
2500 |
– |
g.completeExceptionally(new CFException()); |
2501 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2502 |
– |
checkIncomplete(h); |
2503 |
– |
f.complete(3); |
2504 |
– |
checkCompletedWithWrappedCFException(h); |
2505 |
– |
|
2506 |
– |
assertEquals(0, e.count.get()); |
2507 |
– |
} |
2508 |
– |
|
2509 |
– |
/** |
2510 |
– |
* thenCombineAsync result completes exceptionally if action does |
2511 |
– |
*/ |
2512 |
– |
public void testThenCombineAsync3E() { |
2513 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2514 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2515 |
– |
FailingBiFunction r = new FailingBiFunction(); |
2516 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2517 |
– |
f.complete(one); |
2518 |
– |
checkIncomplete(g); |
2519 |
– |
assertFalse(r.ran); |
2520 |
– |
f2.complete(two); |
2521 |
– |
checkCompletedWithWrappedCFException(g); |
2522 |
– |
assertTrue(r.ran); |
2523 |
– |
} |
2524 |
– |
|
2525 |
– |
/** |
2526 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
2527 |
– |
*/ |
2528 |
– |
public void testThenCombineAsync4E() { |
2529 |
– |
CompletableFuture<Integer> f, g, h; |
2530 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2531 |
– |
|
2532 |
– |
f = new CompletableFuture<>(); |
2533 |
– |
g = new CompletableFuture<>(); |
2534 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2535 |
– |
assertTrue(f.cancel(true)); |
2536 |
– |
checkIncomplete(h); |
2537 |
– |
g.complete(1); |
2538 |
– |
checkCompletedWithWrappedCancellationException(h); |
2539 |
– |
|
2540 |
– |
f = new CompletableFuture<>(); |
2541 |
– |
g = new CompletableFuture<>(); |
2542 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2543 |
– |
assertTrue(g.cancel(true)); |
2544 |
– |
checkIncomplete(h); |
2545 |
– |
f.complete(3); |
2546 |
– |
checkCompletedWithWrappedCancellationException(h); |
2547 |
– |
|
2548 |
– |
f = new CompletableFuture<>(); |
2549 |
– |
g = new CompletableFuture<>(); |
2550 |
– |
assertTrue(g.cancel(true)); |
2551 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2552 |
– |
checkIncomplete(h); |
2553 |
– |
f.complete(3); |
2554 |
– |
checkCompletedWithWrappedCancellationException(h); |
2555 |
– |
|
2556 |
– |
f = new CompletableFuture<>(); |
2557 |
– |
g = new CompletableFuture<>(); |
2558 |
– |
assertTrue(f.cancel(true)); |
2559 |
– |
assertTrue(g.cancel(true)); |
2560 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2561 |
– |
checkCompletedWithWrappedCancellationException(h); |
2562 |
– |
|
2563 |
– |
assertEquals(0, e.count.get()); |
2564 |
– |
} |
2565 |
– |
|
2566 |
– |
/** |
2567 |
– |
* thenAcceptBothAsync result completes normally after normal |
2568 |
– |
* completion of sources |
2569 |
– |
*/ |
2570 |
– |
public void testThenAcceptBothAsyncE() { |
2571 |
– |
CompletableFuture<Integer> f, g; |
2572 |
– |
CompletableFuture<Void> h; |
2573 |
– |
SubtractAction r; |
2574 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2575 |
– |
|
2576 |
– |
f = new CompletableFuture<>(); |
2577 |
– |
g = new CompletableFuture<>(); |
2578 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2579 |
– |
f.complete(3); |
2580 |
– |
checkIncomplete(h); |
2581 |
– |
g.complete(1); |
2582 |
– |
checkCompletedNormally(h, null); |
2583 |
– |
assertEquals(r.value, 2); |
2584 |
– |
|
2585 |
– |
f = new CompletableFuture<>(); |
2586 |
– |
g = new CompletableFuture<>(); |
2587 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2588 |
– |
g.complete(1); |
2589 |
– |
checkIncomplete(h); |
2590 |
– |
f.complete(3); |
2591 |
– |
checkCompletedNormally(h, null); |
2592 |
– |
assertEquals(r.value, 2); |
2593 |
– |
|
2594 |
– |
f = new CompletableFuture<>(); |
2595 |
– |
g = new CompletableFuture<>(); |
2596 |
– |
g.complete(1); |
2597 |
– |
f.complete(3); |
2598 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2599 |
– |
checkCompletedNormally(h, null); |
2600 |
– |
assertEquals(r.value, 2); |
2601 |
– |
|
2602 |
– |
assertEquals(3, e.count.get()); |
2603 |
– |
} |
2604 |
– |
|
2605 |
– |
/** |
2606 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
2607 |
– |
* completion of source |
2608 |
– |
*/ |
2609 |
– |
public void testThenAcceptBothAsync2E() { |
2610 |
– |
CompletableFuture<Integer> f, g; |
2611 |
– |
CompletableFuture<Void> h; |
2612 |
– |
SubtractAction r; |
2613 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2614 |
– |
|
2615 |
– |
f = new CompletableFuture<>(); |
2616 |
– |
g = new CompletableFuture<>(); |
2617 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2618 |
– |
f.completeExceptionally(new CFException()); |
2619 |
– |
checkIncomplete(h); |
2620 |
– |
g.complete(1); |
2621 |
– |
checkCompletedWithWrappedCFException(h); |
2622 |
– |
|
2623 |
– |
f = new CompletableFuture<>(); |
2624 |
– |
g = new CompletableFuture<>(); |
2625 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2626 |
– |
g.completeExceptionally(new CFException()); |
2627 |
– |
checkIncomplete(h); |
2628 |
– |
f.complete(3); |
2629 |
– |
checkCompletedWithWrappedCFException(h); |
2630 |
– |
|
2631 |
– |
f = new CompletableFuture<>(); |
2632 |
– |
g = new CompletableFuture<>(); |
2633 |
– |
f.complete(3); |
2634 |
– |
g.completeExceptionally(new CFException()); |
2635 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2636 |
– |
checkCompletedWithWrappedCFException(h); |
2637 |
– |
|
2638 |
– |
f = new CompletableFuture<>(); |
2639 |
– |
g = new CompletableFuture<>(); |
2640 |
– |
f.completeExceptionally(new CFException()); |
2641 |
– |
g.complete(3); |
2642 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2643 |
– |
checkCompletedWithWrappedCFException(h); |
2644 |
– |
|
2645 |
– |
assertEquals(0, e.count.get()); |
2646 |
– |
} |
2647 |
– |
|
2648 |
– |
/** |
2649 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
2650 |
– |
*/ |
2651 |
– |
public void testThenAcceptBothAsync3E() { |
2652 |
– |
CompletableFuture<Integer> f, g; |
2653 |
– |
CompletableFuture<Void> h; |
2654 |
– |
FailingBiConsumer r; |
2655 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2656 |
– |
|
2657 |
– |
f = new CompletableFuture<>(); |
2658 |
– |
g = new CompletableFuture<>(); |
2659 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2660 |
– |
f.complete(3); |
2661 |
– |
checkIncomplete(h); |
2662 |
– |
g.complete(1); |
2663 |
– |
checkCompletedWithWrappedCFException(h); |
2664 |
– |
|
2665 |
– |
f = new CompletableFuture<>(); |
2666 |
– |
g = new CompletableFuture<>(); |
2667 |
– |
f.complete(3); |
2668 |
– |
g.complete(1); |
2669 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2670 |
– |
checkCompletedWithWrappedCFException(h); |
2671 |
– |
|
2672 |
– |
assertEquals(2, e.count.get()); |
2673 |
– |
} |
2674 |
– |
|
2675 |
– |
/** |
2676 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2677 |
– |
*/ |
2678 |
– |
public void testThenAcceptBothAsync4E() { |
2679 |
– |
CompletableFuture<Integer> f, g; |
2680 |
– |
CompletableFuture<Void> h; |
2681 |
– |
SubtractAction r; |
2682 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2683 |
– |
|
2684 |
– |
f = new CompletableFuture<>(); |
2685 |
– |
g = new CompletableFuture<>(); |
2686 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2687 |
– |
assertTrue(f.cancel(true)); |
2688 |
– |
checkIncomplete(h); |
2689 |
– |
g.complete(1); |
2690 |
– |
checkCompletedWithWrappedCancellationException(h); |
2691 |
– |
|
2692 |
– |
f = new CompletableFuture<>(); |
2693 |
– |
g = new CompletableFuture<>(); |
2694 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2695 |
– |
assertTrue(g.cancel(true)); |
2696 |
– |
checkIncomplete(h); |
2697 |
– |
f.complete(3); |
2698 |
– |
checkCompletedWithWrappedCancellationException(h); |
2699 |
– |
|
2700 |
– |
f = new CompletableFuture<>(); |
2701 |
– |
g = new CompletableFuture<>(); |
2702 |
– |
f.complete(3); |
2703 |
– |
assertTrue(g.cancel(true)); |
2704 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2705 |
– |
checkCompletedWithWrappedCancellationException(h); |
2706 |
– |
|
2707 |
– |
f = new CompletableFuture<>(); |
2708 |
– |
g = new CompletableFuture<>(); |
2709 |
– |
assertTrue(f.cancel(true)); |
2710 |
– |
g.complete(3); |
2711 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2712 |
– |
checkCompletedWithWrappedCancellationException(h); |
2713 |
– |
|
2714 |
– |
assertEquals(0, e.count.get()); |
2715 |
– |
} |
2716 |
– |
|
2717 |
– |
/** |
2718 |
– |
* runAfterBothAsync result completes normally after normal |
2719 |
– |
* completion of sources |
2720 |
– |
*/ |
2721 |
– |
public void testRunAfterBothAsyncE() { |
2722 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2723 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2724 |
– |
Noop r = new Noop(); |
2725 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2726 |
– |
f.complete(one); |
2727 |
– |
checkIncomplete(g); |
2728 |
– |
f2.complete(two); |
2729 |
– |
checkCompletedNormally(g, null); |
2730 |
– |
assertTrue(r.ran); |
2731 |
– |
} |
2732 |
– |
|
2733 |
– |
/** |
2734 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
2735 |
– |
* completion of source |
2736 |
– |
*/ |
2737 |
– |
public void testRunAfterBothAsync2E() { |
2738 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2739 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2740 |
– |
Noop r = new Noop(); |
2741 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2742 |
– |
f.completeExceptionally(new CFException()); |
2743 |
– |
f2.complete(two); |
2744 |
– |
checkCompletedWithWrappedCFException(g); |
2745 |
– |
|
2746 |
– |
r = new Noop(); |
2747 |
– |
f = new CompletableFuture<>(); |
2748 |
– |
f2 = new CompletableFuture<>(); |
2749 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2750 |
– |
f.complete(one); |
2751 |
– |
f2.completeExceptionally(new CFException()); |
2752 |
– |
checkCompletedWithWrappedCFException(g); |
2753 |
– |
} |
2754 |
– |
|
2755 |
– |
/** |
2756 |
– |
* runAfterBothAsync result completes exceptionally if action does |
2757 |
– |
*/ |
2758 |
– |
public void testRunAfterBothAsync3E() { |
2759 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2760 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2761 |
– |
FailingNoop r = new FailingNoop(); |
2762 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2763 |
– |
f.complete(one); |
2764 |
– |
checkIncomplete(g); |
2765 |
– |
f2.complete(two); |
2766 |
– |
checkCompletedWithWrappedCFException(g); |
2767 |
– |
} |
2768 |
– |
|
2769 |
– |
/** |
2770 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
2771 |
– |
*/ |
2772 |
– |
public void testRunAfterBothAsync4E() { |
2773 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2774 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2775 |
– |
Noop r = new Noop(); |
2776 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2777 |
– |
assertTrue(f.cancel(true)); |
2778 |
– |
f2.complete(two); |
2779 |
– |
checkCompletedWithWrappedCancellationException(g); |
2780 |
– |
|
2781 |
– |
r = new Noop(); |
2782 |
– |
f = new CompletableFuture<>(); |
2783 |
– |
f2 = new CompletableFuture<>(); |
2784 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2785 |
– |
f.complete(one); |
2786 |
– |
assertTrue(f2.cancel(true)); |
2787 |
– |
checkCompletedWithWrappedCancellationException(g); |
2788 |
– |
} |
2789 |
– |
|
2594 |
|
/** |
2595 |
|
* applyToEitherAsync result completes normally after normal |
2596 |
|
* completion of sources |