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; |
329 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
330 |
|
} |
331 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
332 |
+ |
// Handle null values as well |
333 |
+ |
public int subtract(Integer x, Integer y) { |
334 |
+ |
return ((x == null) ? 42 : x.intValue()) |
335 |
+ |
- ((y == null) ? 99 : y.intValue()); |
336 |
+ |
} |
337 |
|
int value; |
338 |
+ |
public boolean ran() { return value != 0; } |
339 |
|
public void accept(Integer x, Integer y) { |
340 |
< |
value = x.intValue() - y.intValue(); |
340 |
> |
value = subtract(x, y); |
341 |
|
} |
342 |
|
} |
343 |
|
static final class Noop implements Runnable { |
412 |
|
} |
413 |
|
|
414 |
|
/** |
415 |
+ |
* Permits the testing of parallel code for the 3 different |
416 |
+ |
* execution modes without repeating all the testing code. |
417 |
+ |
*/ |
418 |
+ |
enum ExecutionMode { |
419 |
+ |
DEFAULT { |
420 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
421 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
422 |
+ |
return f.runAfterBoth(g, a); |
423 |
+ |
} |
424 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
425 |
+ |
(CompletableFuture<T> f, |
426 |
+ |
CompletionStage<? extends U> g, |
427 |
+ |
BiConsumer<? super T,? super U> a) { |
428 |
+ |
return f.thenAcceptBoth(g, a); |
429 |
+ |
} |
430 |
+ |
}, |
431 |
+ |
|
432 |
+ |
// /** Experimental way to do more testing */ |
433 |
+ |
// REVERSE_DEFAULT { |
434 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
435 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
436 |
+ |
// return g.runAfterBoth(f, 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 DEFAULT.thenAcceptBoth(f, g, a); |
443 |
+ |
// } |
444 |
+ |
// }, |
445 |
+ |
|
446 |
+ |
DEFAULT_ASYNC { |
447 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
448 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
449 |
+ |
return f.runAfterBothAsync(g, a); |
450 |
+ |
} |
451 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
452 |
+ |
(CompletableFuture<T> f, |
453 |
+ |
CompletionStage<? extends U> g, |
454 |
+ |
BiConsumer<? super T,? super U> a) { |
455 |
+ |
return f.thenAcceptBothAsync(g, a); |
456 |
+ |
} |
457 |
+ |
}, |
458 |
+ |
|
459 |
+ |
// REVERSE_DEFAULT_ASYNC { |
460 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
461 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
462 |
+ |
// return f.runAfterBothAsync(g, a); |
463 |
+ |
// } |
464 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
465 |
+ |
// (CompletableFuture<T> f, |
466 |
+ |
// CompletionStage<? extends U> g, |
467 |
+ |
// BiConsumer<? super T,? super U> a) { |
468 |
+ |
// return DEFAULT_ASYNC.thenAcceptBoth(f, g, a); |
469 |
+ |
// } |
470 |
+ |
// }, |
471 |
+ |
|
472 |
+ |
EXECUTOR { |
473 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
474 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
475 |
+ |
return f.runAfterBothAsync(g, a, new ThreadExecutor()); |
476 |
+ |
} |
477 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
478 |
+ |
(CompletableFuture<T> f, |
479 |
+ |
CompletionStage<? extends U> g, |
480 |
+ |
BiConsumer<? super T,? super U> a) { |
481 |
+ |
return f.thenAcceptBothAsync(g, a, new ThreadExecutor()); |
482 |
+ |
} |
483 |
+ |
}; |
484 |
+ |
|
485 |
+ |
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
486 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a); |
487 |
+ |
public abstract <T,U> CompletableFuture<Void> thenAcceptBoth |
488 |
+ |
(CompletableFuture<T> f, |
489 |
+ |
CompletionStage<? extends U> g, |
490 |
+ |
BiConsumer<? super T,? super U> a); |
491 |
+ |
} |
492 |
+ |
|
493 |
+ |
/** |
494 |
|
* exceptionally action completes with function value on source |
495 |
|
* exception; otherwise with source value |
496 |
|
*/ |
897 |
|
* thenAcceptBoth result completes normally after normal |
898 |
|
* completion of sources |
899 |
|
*/ |
900 |
< |
public void testThenAcceptBoth() { |
901 |
< |
CompletableFuture<Integer> f, g; |
902 |
< |
CompletableFuture<Void> h; |
903 |
< |
SubtractAction r; |
900 |
> |
public void testThenAcceptBoth_normalCompletion1() { |
901 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
902 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
903 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
904 |
|
|
905 |
< |
f = new CompletableFuture<>(); |
906 |
< |
g = new CompletableFuture<>(); |
907 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
908 |
< |
f.complete(3); |
905 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
906 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
907 |
> |
final SubtractAction r = new SubtractAction(); |
908 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
909 |
> |
|
910 |
> |
f.complete(v1); |
911 |
|
checkIncomplete(h); |
912 |
< |
g.complete(1); |
912 |
> |
assertEquals(r.value, 0); |
913 |
> |
g.complete(v2); |
914 |
> |
|
915 |
|
checkCompletedNormally(h, null); |
916 |
< |
assertEquals(r.value, 2); |
916 |
> |
assertEquals(r.value, r.subtract(v1, v2)); |
917 |
> |
checkCompletedNormally(f, v1); |
918 |
> |
checkCompletedNormally(g, v2); |
919 |
> |
} |
920 |
> |
} |
921 |
|
|
922 |
< |
f = new CompletableFuture<>(); |
923 |
< |
g = new CompletableFuture<>(); |
924 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
925 |
< |
g.complete(1); |
922 |
> |
public void testThenAcceptBoth_normalCompletion2() { |
923 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
924 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
925 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
926 |
> |
|
927 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
928 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
929 |
> |
final SubtractAction r = new SubtractAction(); |
930 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
931 |
> |
|
932 |
> |
g.complete(v2); |
933 |
|
checkIncomplete(h); |
934 |
< |
f.complete(3); |
934 |
> |
assertEquals(r.value, 0); |
935 |
> |
f.complete(v1); |
936 |
> |
|
937 |
|
checkCompletedNormally(h, null); |
938 |
< |
assertEquals(r.value, 2); |
938 |
> |
assertEquals(r.value, r.subtract(v1, v2)); |
939 |
> |
checkCompletedNormally(f, v1); |
940 |
> |
checkCompletedNormally(g, v2); |
941 |
> |
} |
942 |
> |
} |
943 |
> |
|
944 |
> |
public void testThenAcceptBoth_normalCompletion3() { |
945 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
946 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
947 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
948 |
> |
|
949 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
950 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
951 |
> |
final SubtractAction r = new SubtractAction(); |
952 |
> |
|
953 |
> |
g.complete(v2); |
954 |
> |
f.complete(v1); |
955 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
956 |
|
|
837 |
– |
f = new CompletableFuture<>(); |
838 |
– |
g = new CompletableFuture<>(); |
839 |
– |
g.complete(1); |
840 |
– |
f.complete(3); |
841 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
957 |
|
checkCompletedNormally(h, null); |
958 |
< |
assertEquals(r.value, 2); |
958 |
> |
assertEquals(r.value, r.subtract(v1, v2)); |
959 |
> |
checkCompletedNormally(f, v1); |
960 |
> |
checkCompletedNormally(g, v2); |
961 |
> |
} |
962 |
> |
} |
963 |
> |
|
964 |
> |
public void testThenAcceptBoth_normalCompletion4() { |
965 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
966 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
967 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
968 |
> |
|
969 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
970 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
971 |
> |
final SubtractAction r = new SubtractAction(); |
972 |
> |
|
973 |
> |
f.complete(v1); |
974 |
> |
g.complete(v2); |
975 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
976 |
> |
|
977 |
> |
checkCompletedNormally(h, null); |
978 |
> |
assertEquals(r.value, r.subtract(v1, v2)); |
979 |
> |
checkCompletedNormally(f, v1); |
980 |
> |
checkCompletedNormally(g, v2); |
981 |
> |
} |
982 |
|
} |
983 |
|
|
984 |
|
/** |
985 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
986 |
|
* completion of either source |
987 |
|
*/ |
988 |
< |
public void testThenAcceptBoth2() { |
989 |
< |
CompletableFuture<Integer> f, g; |
990 |
< |
CompletableFuture<Void> h; |
853 |
< |
SubtractAction r; |
988 |
> |
public void testThenAcceptBoth_exceptionalCompletion1() { |
989 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
990 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
991 |
|
|
992 |
< |
f = new CompletableFuture<>(); |
993 |
< |
g = new CompletableFuture<>(); |
994 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
995 |
< |
f.completeExceptionally(new CFException()); |
992 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
993 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
994 |
> |
final SubtractAction r = new SubtractAction(); |
995 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
996 |
> |
final CFException ex = new CFException(); |
997 |
> |
|
998 |
> |
f.completeExceptionally(ex); |
999 |
|
checkIncomplete(h); |
1000 |
< |
g.complete(1); |
861 |
< |
checkCompletedWithWrappedCFException(h); |
1000 |
> |
g.complete(v1); |
1001 |
|
|
1002 |
< |
f = new CompletableFuture<>(); |
1003 |
< |
g = new CompletableFuture<>(); |
1004 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1005 |
< |
g.completeExceptionally(new CFException()); |
1002 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1003 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1004 |
> |
assertFalse(r.ran()); |
1005 |
> |
checkCompletedNormally(g, v1); |
1006 |
> |
} |
1007 |
> |
} |
1008 |
> |
|
1009 |
> |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1010 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1011 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1012 |
> |
|
1013 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1014 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1015 |
> |
final SubtractAction r = new SubtractAction(); |
1016 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1017 |
> |
final CFException ex = new CFException(); |
1018 |
> |
|
1019 |
> |
g.completeExceptionally(ex); |
1020 |
|
checkIncomplete(h); |
1021 |
< |
f.complete(3); |
869 |
< |
checkCompletedWithWrappedCFException(h); |
1021 |
> |
f.complete(v1); |
1022 |
|
|
1023 |
< |
f = new CompletableFuture<>(); |
1024 |
< |
g = new CompletableFuture<>(); |
1025 |
< |
f.complete(3); |
1026 |
< |
g.completeExceptionally(new CFException()); |
1027 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1028 |
< |
checkCompletedWithWrappedCFException(h); |
1023 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1024 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1025 |
> |
assertFalse(r.ran()); |
1026 |
> |
checkCompletedNormally(f, v1); |
1027 |
> |
} |
1028 |
> |
} |
1029 |
|
|
1030 |
< |
f = new CompletableFuture<>(); |
1031 |
< |
g = new CompletableFuture<>(); |
1032 |
< |
f.completeExceptionally(new CFException()); |
1033 |
< |
g.complete(3); |
1034 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1035 |
< |
checkCompletedWithWrappedCFException(h); |
1030 |
> |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1031 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1032 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1033 |
> |
|
1034 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1035 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1036 |
> |
final SubtractAction r = new SubtractAction(); |
1037 |
> |
final CFException ex = new CFException(); |
1038 |
> |
|
1039 |
> |
g.completeExceptionally(ex); |
1040 |
> |
f.complete(v1); |
1041 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1042 |
> |
|
1043 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1044 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1045 |
> |
assertFalse(r.ran()); |
1046 |
> |
checkCompletedNormally(f, v1); |
1047 |
> |
} |
1048 |
> |
} |
1049 |
> |
|
1050 |
> |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1051 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1052 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1053 |
> |
|
1054 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1055 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1056 |
> |
final SubtractAction r = new SubtractAction(); |
1057 |
> |
final CFException ex = new CFException(); |
1058 |
> |
|
1059 |
> |
f.completeExceptionally(ex); |
1060 |
> |
g.complete(v1); |
1061 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1062 |
> |
|
1063 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1064 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1065 |
> |
assertFalse(r.ran()); |
1066 |
> |
checkCompletedNormally(g, v1); |
1067 |
> |
} |
1068 |
|
} |
1069 |
|
|
1070 |
|
/** |
1071 |
|
* thenAcceptBoth result completes exceptionally if action does |
1072 |
|
*/ |
1073 |
< |
public void testThenAcceptBoth3() { |
1074 |
< |
CompletableFuture<Integer> f, g; |
1075 |
< |
CompletableFuture<Void> h; |
1076 |
< |
FailingBiConsumer r; |
1073 |
> |
public void testThenAcceptBoth_actionFailed1() { |
1074 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1075 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1076 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1077 |
|
|
1078 |
< |
f = new CompletableFuture<>(); |
1079 |
< |
g = new CompletableFuture<>(); |
1080 |
< |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1081 |
< |
f.complete(3); |
1078 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1079 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1080 |
> |
final FailingBiConsumer r = new FailingBiConsumer(); |
1081 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1082 |
> |
|
1083 |
> |
f.complete(v1); |
1084 |
|
checkIncomplete(h); |
1085 |
< |
g.complete(1); |
1085 |
> |
g.complete(v2); |
1086 |
> |
|
1087 |
|
checkCompletedWithWrappedCFException(h); |
1088 |
+ |
checkCompletedNormally(f, v1); |
1089 |
+ |
checkCompletedNormally(g, v2); |
1090 |
+ |
} |
1091 |
+ |
} |
1092 |
+ |
|
1093 |
+ |
public void testThenAcceptBoth_actionFailed2() { |
1094 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1095 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1096 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1097 |
+ |
|
1098 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1099 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1100 |
+ |
final FailingBiConsumer r = new FailingBiConsumer(); |
1101 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1102 |
+ |
|
1103 |
+ |
g.complete(v2); |
1104 |
+ |
checkIncomplete(h); |
1105 |
+ |
f.complete(v1); |
1106 |
|
|
902 |
– |
f = new CompletableFuture<>(); |
903 |
– |
g = new CompletableFuture<>(); |
904 |
– |
f.complete(3); |
905 |
– |
g.complete(1); |
906 |
– |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1107 |
|
checkCompletedWithWrappedCFException(h); |
1108 |
+ |
checkCompletedNormally(f, v1); |
1109 |
+ |
checkCompletedNormally(g, v2); |
1110 |
+ |
} |
1111 |
|
} |
1112 |
|
|
1113 |
|
/** |
1114 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1115 |
|
*/ |
1116 |
< |
public void testThenAcceptBoth4() { |
1117 |
< |
CompletableFuture<Integer> f, g; |
1118 |
< |
CompletableFuture<Void> h; |
1119 |
< |
SubtractAction r; |
1116 |
> |
public void testThenAcceptBoth_sourceCancelled1() { |
1117 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1118 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1119 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1120 |
|
|
1121 |
< |
f = new CompletableFuture<>(); |
1122 |
< |
g = new CompletableFuture<>(); |
1123 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1124 |
< |
assertTrue(f.cancel(true)); |
1121 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1122 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1123 |
> |
final SubtractAction r = new SubtractAction(); |
1124 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1125 |
> |
|
1126 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1127 |
|
checkIncomplete(h); |
1128 |
< |
g.complete(1); |
1128 |
> |
g.complete(v1); |
1129 |
> |
|
1130 |
|
checkCompletedWithWrappedCancellationException(h); |
1131 |
+ |
checkCancelled(f); |
1132 |
+ |
assertFalse(r.ran()); |
1133 |
+ |
checkCompletedNormally(g, v1); |
1134 |
+ |
} |
1135 |
+ |
} |
1136 |
|
|
1137 |
< |
f = new CompletableFuture<>(); |
1138 |
< |
g = new CompletableFuture<>(); |
1139 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1140 |
< |
assertTrue(g.cancel(true)); |
1137 |
> |
public void testThenAcceptBoth_sourceCancelled2() { |
1138 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1139 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1140 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1141 |
> |
|
1142 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1143 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1144 |
> |
final SubtractAction r = new SubtractAction(); |
1145 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1146 |
> |
|
1147 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1148 |
|
checkIncomplete(h); |
1149 |
< |
f.complete(3); |
1149 |
> |
f.complete(v1); |
1150 |
> |
|
1151 |
|
checkCompletedWithWrappedCancellationException(h); |
1152 |
+ |
checkCancelled(g); |
1153 |
+ |
assertFalse(r.ran()); |
1154 |
+ |
checkCompletedNormally(f, v1); |
1155 |
+ |
} |
1156 |
+ |
} |
1157 |
+ |
|
1158 |
+ |
public void testThenAcceptBoth_sourceCancelled3() { |
1159 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1160 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1161 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1162 |
+ |
|
1163 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1164 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1165 |
+ |
final SubtractAction r = new SubtractAction(); |
1166 |
+ |
|
1167 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1168 |
+ |
f.complete(v1); |
1169 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1170 |
|
|
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()); |
1171 |
|
checkCompletedWithWrappedCancellationException(h); |
1172 |
+ |
checkCancelled(g); |
1173 |
+ |
assertFalse(r.ran()); |
1174 |
+ |
checkCompletedNormally(f, v1); |
1175 |
+ |
} |
1176 |
+ |
} |
1177 |
+ |
|
1178 |
+ |
public void testThenAcceptBoth_sourceCancelled4() { |
1179 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1180 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1181 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1182 |
+ |
|
1183 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1184 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1185 |
+ |
final SubtractAction r = new SubtractAction(); |
1186 |
+ |
|
1187 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1188 |
+ |
g.complete(v1); |
1189 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1190 |
|
|
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()); |
1191 |
|
checkCompletedWithWrappedCancellationException(h); |
1192 |
+ |
checkCancelled(f); |
1193 |
+ |
assertFalse(r.ran()); |
1194 |
+ |
checkCompletedNormally(g, v1); |
1195 |
+ |
} |
1196 |
|
} |
1197 |
|
|
1198 |
|
/** |
1200 |
|
* completion of sources |
1201 |
|
*/ |
1202 |
|
public void testRunAfterBoth_normalCompletion1() { |
1203 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1204 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1205 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1206 |
|
|
1207 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1208 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1209 |
|
final Noop r = new Noop(); |
1210 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1210 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1211 |
|
|
1212 |
|
f.complete(v1); |
1213 |
|
checkIncomplete(h); |
1222 |
|
} |
1223 |
|
|
1224 |
|
public void testRunAfterBoth_normalCompletion2() { |
1225 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1226 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1227 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1228 |
|
|
1229 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1230 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1231 |
|
final Noop r = new Noop(); |
1232 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1232 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1233 |
|
|
1234 |
|
g.complete(v2); |
1235 |
|
checkIncomplete(h); |
1244 |
|
} |
1245 |
|
|
1246 |
|
public void testRunAfterBoth_normalCompletion3() { |
1247 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1248 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1249 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1250 |
|
|
1254 |
|
|
1255 |
|
g.complete(v2); |
1256 |
|
f.complete(v1); |
1257 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1257 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1258 |
|
|
1259 |
|
checkCompletedNormally(h, null); |
1260 |
|
assertTrue(r.ran); |
1264 |
|
} |
1265 |
|
|
1266 |
|
public void testRunAfterBoth_normalCompletion4() { |
1267 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1268 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1269 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1270 |
|
|
1274 |
|
|
1275 |
|
f.complete(v1); |
1276 |
|
g.complete(v2); |
1277 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1277 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1278 |
|
|
1279 |
|
checkCompletedNormally(h, null); |
1280 |
|
assertTrue(r.ran); |
1288 |
|
* completion of either source |
1289 |
|
*/ |
1290 |
|
public void testRunAfterBoth_exceptionalCompletion1() { |
1291 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1292 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1293 |
|
|
1294 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1295 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1296 |
|
final Noop r = new Noop(); |
1297 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1297 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1298 |
|
final CFException ex = new CFException(); |
1299 |
|
|
1300 |
|
f.completeExceptionally(ex); |
1309 |
|
} |
1310 |
|
|
1311 |
|
public void testRunAfterBoth_exceptionalCompletion2() { |
1312 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1313 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1314 |
|
|
1315 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1316 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1317 |
|
final Noop r = new Noop(); |
1318 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1318 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1319 |
|
final CFException ex = new CFException(); |
1320 |
|
|
1321 |
|
g.completeExceptionally(ex); |
1330 |
|
} |
1331 |
|
|
1332 |
|
public void testRunAfterBoth_exceptionalCompletion3() { |
1333 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1334 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1335 |
|
|
1336 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1340 |
|
|
1341 |
|
g.completeExceptionally(ex); |
1342 |
|
f.complete(v1); |
1343 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1343 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1344 |
|
|
1345 |
|
checkCompletedWithWrappedCFException(h, ex); |
1346 |
|
checkCompletedWithWrappedCFException(g, ex); |
1350 |
|
} |
1351 |
|
|
1352 |
|
public void testRunAfterBoth_exceptionalCompletion4() { |
1353 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1354 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1355 |
|
|
1356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1360 |
|
|
1361 |
|
f.completeExceptionally(ex); |
1362 |
|
g.complete(v1); |
1363 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1363 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1364 |
|
|
1365 |
|
checkCompletedWithWrappedCFException(h, ex); |
1366 |
|
checkCompletedWithWrappedCFException(f, ex); |
1373 |
|
* runAfterBoth result completes exceptionally if action does |
1374 |
|
*/ |
1375 |
|
public void testRunAfterBoth_actionFailed1() { |
1376 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1377 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1378 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1379 |
|
|
1380 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1381 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1382 |
|
final FailingNoop r = new FailingNoop(); |
1383 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1383 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1384 |
|
|
1385 |
|
f.complete(v1); |
1386 |
|
checkIncomplete(h); |
1393 |
|
} |
1394 |
|
|
1395 |
|
public void testRunAfterBoth_actionFailed2() { |
1396 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1397 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1398 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
1399 |
|
|
1400 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1401 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1402 |
|
final FailingNoop r = new FailingNoop(); |
1403 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1403 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1404 |
|
|
1405 |
|
g.complete(v2); |
1406 |
|
checkIncomplete(h); |
1416 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1417 |
|
*/ |
1418 |
|
public void testRunAfterBoth_sourceCancelled1() { |
1419 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1420 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1421 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1422 |
|
|
1423 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1424 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1425 |
|
final Noop r = new Noop(); |
1426 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1426 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1427 |
|
|
1428 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1429 |
|
checkIncomplete(h); |
1437 |
|
} |
1438 |
|
|
1439 |
|
public void testRunAfterBoth_sourceCancelled2() { |
1440 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1441 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1442 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1443 |
|
|
1444 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1445 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1446 |
|
final Noop r = new Noop(); |
1447 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1447 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1448 |
|
|
1449 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
1450 |
|
checkIncomplete(h); |
1458 |
|
} |
1459 |
|
|
1460 |
|
public void testRunAfterBoth_sourceCancelled3() { |
1461 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1462 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1463 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1464 |
|
|
1468 |
|
|
1469 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
1470 |
|
f.complete(v1); |
1471 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1471 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1472 |
|
|
1473 |
|
checkCompletedWithWrappedCancellationException(h); |
1474 |
|
checkCancelled(g); |
1478 |
|
} |
1479 |
|
|
1480 |
|
public void testRunAfterBoth_sourceCancelled4() { |
1481 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1482 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1483 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
1484 |
|
|
1488 |
|
|
1489 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1490 |
|
g.complete(v1); |
1491 |
< |
final CompletableFuture<Void> h = f.runAfterBoth(g, r); |
1491 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1492 |
|
|
1493 |
|
checkCompletedWithWrappedCancellationException(h); |
1494 |
|
checkCancelled(f); |
2047 |
|
} |
2048 |
|
|
2049 |
|
/** |
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 |
– |
/** |
2050 |
|
* applyToEitherAsync result completes normally after normal |
2051 |
|
* completion of sources |
2052 |
|
*/ |
2615 |
|
} |
2616 |
|
|
2617 |
|
/** |
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 |
– |
|
2790 |
– |
/** |
2618 |
|
* applyToEitherAsync result completes normally after normal |
2619 |
|
* completion of sources |
2620 |
|
*/ |