284 |
|
public void testGetNumberOfDependents() { |
285 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
286 |
|
assertEquals(0, f.getNumberOfDependents()); |
287 |
< |
CompletableFuture g = f.thenRun(new Noop()); |
287 |
> |
CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
288 |
|
assertEquals(1, f.getNumberOfDependents()); |
289 |
|
assertEquals(0, g.getNumberOfDependents()); |
290 |
< |
CompletableFuture h = f.thenRun(new Noop()); |
290 |
> |
CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
291 |
|
assertEquals(2, f.getNumberOfDependents()); |
292 |
|
f.complete(1); |
293 |
|
checkCompletedNormally(g, null); |
375 |
|
} |
376 |
|
} |
377 |
|
static final class Noop implements Runnable { |
378 |
+ |
final ExecutionMode m; |
379 |
|
int invocationCount = 0; |
380 |
+ |
Noop(ExecutionMode m) { this.m = m; } |
381 |
|
public void run() { |
382 |
+ |
m.checkExecutionMode(); |
383 |
|
invocationCount++; |
384 |
|
} |
385 |
|
} |
419 |
|
throw new CFException(); |
420 |
|
} |
421 |
|
} |
422 |
< |
static final class FailingNoop implements Runnable { |
422 |
> |
static final class FailingRunnable implements Runnable { |
423 |
|
int invocationCount = 0; |
424 |
|
public void run() { |
425 |
|
invocationCount++; |
912 |
|
* runAsync completes after running Runnable |
913 |
|
*/ |
914 |
|
public void testRunAsync() { |
915 |
< |
Noop r = new Noop(); |
915 |
> |
Noop r = new Noop(ExecutionMode.ASYNC); |
916 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
917 |
|
assertNull(f.join()); |
918 |
|
assertEquals(1, r.invocationCount); |
923 |
|
* runAsync with executor completes after running Runnable |
924 |
|
*/ |
925 |
|
public void testRunAsync2() { |
926 |
< |
Noop r = new Noop(); |
926 |
> |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
927 |
|
ThreadExecutor exec = new ThreadExecutor(); |
928 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
929 |
|
assertNull(f.join()); |
936 |
|
* failing runAsync completes exceptionally after running Runnable |
937 |
|
*/ |
938 |
|
public void testRunAsync3() { |
939 |
< |
FailingNoop r = new FailingNoop(); |
939 |
> |
FailingRunnable r = new FailingRunnable(); |
940 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
941 |
|
checkCompletedWithWrappedCFException(f); |
942 |
|
assertEquals(1, r.invocationCount); |
983 |
|
for (Integer v1 : new Integer[] { 1, null }) |
984 |
|
{ |
985 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
986 |
< |
final Noop r = new Noop(); |
986 |
> |
final Noop r = new Noop(m); |
987 |
|
if (!createIncomplete) f.complete(v1); |
988 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
989 |
< |
if (createIncomplete) f.complete(v1); |
989 |
> |
if (createIncomplete) { |
990 |
> |
checkIncomplete(g); |
991 |
> |
f.complete(v1); |
992 |
> |
} |
993 |
|
|
994 |
|
checkCompletedNormally(g, null); |
995 |
|
checkCompletedNormally(f, v1); |
1006 |
|
{ |
1007 |
|
final CFException ex = new CFException(); |
1008 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1009 |
< |
final Noop r = new Noop(); |
1009 |
> |
final Noop r = new Noop(m); |
1010 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1011 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1012 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1012 |
> |
if (createIncomplete) { |
1013 |
> |
checkIncomplete(g); |
1014 |
> |
f.completeExceptionally(ex); |
1015 |
> |
} |
1016 |
|
|
1017 |
|
checkCompletedWithWrappedCFException(g, ex); |
1018 |
|
checkCompletedWithWrappedCFException(f, ex); |
1028 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1029 |
|
{ |
1030 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1031 |
< |
final Noop r = new Noop(); |
1031 |
> |
final Noop r = new Noop(m); |
1032 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1033 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1034 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1034 |
> |
if (createIncomplete) { |
1035 |
> |
checkIncomplete(g); |
1036 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1037 |
> |
} |
1038 |
|
|
1039 |
|
checkCompletedWithWrappedCancellationException(g); |
1040 |
|
checkCancelled(f); |
1050 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1051 |
|
{ |
1052 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1053 |
< |
final FailingNoop r = new FailingNoop(); |
1053 |
> |
final FailingRunnable r = new FailingRunnable(); |
1054 |
|
if (!createIncomplete) f.complete(v1); |
1055 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1056 |
< |
if (createIncomplete) f.complete(v1); |
1056 |
> |
if (createIncomplete) { |
1057 |
> |
checkIncomplete(g); |
1058 |
> |
f.complete(v1); |
1059 |
> |
} |
1060 |
|
|
1061 |
|
checkCompletedWithWrappedCFException(g); |
1062 |
|
checkCompletedNormally(f, v1); |
1065 |
|
/** |
1066 |
|
* thenApply result completes normally after normal completion of source |
1067 |
|
*/ |
1068 |
< |
public void testThenApply() { |
1054 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1055 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1056 |
< |
f.complete(one); |
1057 |
< |
checkCompletedNormally(g, two); |
1058 |
< |
} |
1059 |
< |
|
1060 |
< |
/** |
1061 |
< |
* thenApply result completes exceptionally after exceptional |
1062 |
< |
* completion of source |
1063 |
< |
*/ |
1064 |
< |
public void testThenApply2() { |
1065 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1066 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1067 |
< |
f.completeExceptionally(new CFException()); |
1068 |
< |
checkCompletedWithWrappedCFException(g); |
1069 |
< |
} |
1070 |
< |
|
1071 |
< |
/** |
1072 |
< |
* thenApply result completes exceptionally if action does |
1073 |
< |
*/ |
1074 |
< |
public void testThenApply3() { |
1075 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1076 |
< |
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
1077 |
< |
f.complete(one); |
1078 |
< |
checkCompletedWithWrappedCFException(g); |
1079 |
< |
} |
1080 |
< |
|
1081 |
< |
/** |
1082 |
< |
* thenApply result completes exceptionally if source cancelled |
1083 |
< |
*/ |
1084 |
< |
public void testThenApply4() { |
1085 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1086 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1087 |
< |
assertTrue(f.cancel(true)); |
1088 |
< |
checkCompletedWithWrappedCancellationException(g); |
1089 |
< |
} |
1090 |
< |
|
1091 |
< |
/** |
1092 |
< |
* thenAccept result completes normally after normal completion of source |
1093 |
< |
*/ |
1094 |
< |
public void testThenAccept() { |
1095 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1096 |
< |
IncAction r = new IncAction(); |
1097 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1098 |
< |
f.complete(one); |
1099 |
< |
checkCompletedNormally(g, null); |
1100 |
< |
assertEquals(r.value, (Integer) 2); |
1101 |
< |
} |
1102 |
< |
|
1103 |
< |
/** |
1104 |
< |
* thenAccept result completes exceptionally after exceptional |
1105 |
< |
* completion of source |
1106 |
< |
*/ |
1107 |
< |
public void testThenAccept2() { |
1108 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1109 |
< |
IncAction r = new IncAction(); |
1110 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1111 |
< |
f.completeExceptionally(new CFException()); |
1112 |
< |
checkCompletedWithWrappedCFException(g); |
1113 |
< |
} |
1114 |
< |
|
1115 |
< |
/** |
1116 |
< |
* thenAccept result completes exceptionally if action does |
1117 |
< |
*/ |
1118 |
< |
public void testThenAccept3() { |
1119 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1120 |
< |
FailingConsumer r = new FailingConsumer(); |
1121 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1122 |
< |
f.complete(one); |
1123 |
< |
checkCompletedWithWrappedCFException(g); |
1124 |
< |
assertEquals(1, r.invocationCount); |
1125 |
< |
} |
1126 |
< |
|
1127 |
< |
/** |
1128 |
< |
* thenAccept result completes exceptionally if source cancelled |
1129 |
< |
*/ |
1130 |
< |
public void testThenAccept4() { |
1131 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1132 |
< |
IncAction r = new IncAction(); |
1133 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1134 |
< |
assertTrue(f.cancel(true)); |
1135 |
< |
checkCompletedWithWrappedCancellationException(g); |
1136 |
< |
} |
1137 |
< |
|
1138 |
< |
/** |
1139 |
< |
* thenCombine result completes normally after normal completion |
1140 |
< |
* of sources |
1141 |
< |
*/ |
1142 |
< |
public void testThenCombine_normalCompletion1() { |
1143 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
1144 |
< |
for (boolean fFirst : new boolean[] { true, false }) |
1068 |
> |
public void testThenApply_normalCompletion() { |
1069 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1070 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1071 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1147 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1072 |
|
{ |
1073 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1074 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1075 |
< |
final SubtractFunction r = new SubtractFunction(); |
1076 |
< |
CompletableFuture<Integer> h = null; |
1077 |
< |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1078 |
< |
|
1155 |
< |
if (fFirst) |
1156 |
< |
f.complete(v1); |
1157 |
< |
else |
1158 |
< |
g.complete(v2); |
1159 |
< |
if (createIncomplete) checkIncomplete(h); |
1160 |
< |
assertEquals(0, r.invocationCount); |
1161 |
< |
if (!fFirst) |
1074 |
> |
final IncFunction r = new IncFunction(); |
1075 |
> |
if (!createIncomplete) f.complete(v1); |
1076 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1077 |
> |
if (createIncomplete) { |
1078 |
> |
checkIncomplete(g); |
1079 |
|
f.complete(v1); |
1080 |
< |
else |
1164 |
< |
g.complete(v2); |
1165 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1080 |
> |
} |
1081 |
|
|
1082 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
1082 |
> |
checkCompletedNormally(g, inc(v1)); |
1083 |
|
checkCompletedNormally(f, v1); |
1169 |
– |
checkCompletedNormally(g, v2); |
1084 |
|
assertEquals(1, r.invocationCount); |
1085 |
|
}} |
1086 |
|
|
1087 |
|
/** |
1088 |
< |
* thenCombine result completes exceptionally after exceptional |
1089 |
< |
* completion of either source |
1088 |
> |
* thenApply result completes exceptionally after exceptional |
1089 |
> |
* completion of source |
1090 |
|
*/ |
1091 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1091 |
> |
public void testThenApply_exceptionalCompletion() { |
1092 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1093 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1093 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1094 |
|
{ |
1181 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1182 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1183 |
– |
final SubtractFunction r = new SubtractFunction(); |
1184 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1095 |
|
final CFException ex = new CFException(); |
1096 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1097 |
+ |
final IncFunction r = new IncFunction(); |
1098 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
1099 |
+ |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1100 |
+ |
if (createIncomplete) { |
1101 |
+ |
checkIncomplete(g); |
1102 |
+ |
f.completeExceptionally(ex); |
1103 |
+ |
} |
1104 |
|
|
1105 |
< |
f.completeExceptionally(ex); |
1188 |
< |
checkIncomplete(h); |
1189 |
< |
g.complete(v1); |
1190 |
< |
|
1191 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1105 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1106 |
|
checkCompletedWithWrappedCFException(f, ex); |
1107 |
|
assertEquals(0, r.invocationCount); |
1194 |
– |
checkCompletedNormally(g, v1); |
1108 |
|
}} |
1109 |
|
|
1110 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1110 |
> |
/** |
1111 |
> |
* thenApply result completes exceptionally if source cancelled |
1112 |
> |
*/ |
1113 |
> |
public void testThenApply_sourceCancelled() { |
1114 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1115 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1115 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1116 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1117 |
|
{ |
1118 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1119 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1120 |
< |
final SubtractFunction r = new SubtractFunction(); |
1121 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1122 |
< |
final CFException ex = new CFException(); |
1123 |
< |
|
1124 |
< |
g.completeExceptionally(ex); |
1125 |
< |
checkIncomplete(h); |
1209 |
< |
f.complete(v1); |
1119 |
> |
final IncFunction r = new IncFunction(); |
1120 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1121 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1122 |
> |
if (createIncomplete) { |
1123 |
> |
checkIncomplete(g); |
1124 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1125 |
> |
} |
1126 |
|
|
1127 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1128 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1127 |
> |
checkCompletedWithWrappedCancellationException(g); |
1128 |
> |
checkCancelled(f); |
1129 |
|
assertEquals(0, r.invocationCount); |
1214 |
– |
checkCompletedNormally(f, v1); |
1130 |
|
}} |
1131 |
|
|
1132 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1132 |
> |
/** |
1133 |
> |
* thenApply result completes exceptionally if action does |
1134 |
> |
*/ |
1135 |
> |
public void testThenApply_actionFailed() { |
1136 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1137 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1138 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1139 |
|
{ |
1140 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1141 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1142 |
< |
final SubtractFunction r = new SubtractFunction(); |
1143 |
< |
final CFException ex = new CFException(); |
1144 |
< |
|
1145 |
< |
g.completeExceptionally(ex); |
1146 |
< |
f.complete(v1); |
1147 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1141 |
> |
final FailingFunction r = new FailingFunction(); |
1142 |
> |
if (!createIncomplete) f.complete(v1); |
1143 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1144 |
> |
if (createIncomplete) { |
1145 |
> |
checkIncomplete(g); |
1146 |
> |
f.complete(v1); |
1147 |
> |
} |
1148 |
|
|
1149 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1231 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1232 |
< |
assertEquals(0, r.invocationCount); |
1149 |
> |
checkCompletedWithWrappedCFException(g); |
1150 |
|
checkCompletedNormally(f, v1); |
1151 |
|
}} |
1152 |
|
|
1153 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1153 |
> |
/** |
1154 |
> |
* thenAccept result completes normally after normal completion of source |
1155 |
> |
*/ |
1156 |
> |
public void testThenAccept_normalCompletion() { |
1157 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1158 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1159 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1160 |
|
{ |
1161 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1162 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1163 |
< |
final SubtractFunction r = new SubtractFunction(); |
1164 |
< |
final CFException ex = new CFException(); |
1165 |
< |
|
1166 |
< |
f.completeExceptionally(ex); |
1167 |
< |
g.complete(v1); |
1168 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1162 |
> |
final IncAction r = new IncAction(); |
1163 |
> |
if (!createIncomplete) f.complete(v1); |
1164 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1165 |
> |
if (createIncomplete) { |
1166 |
> |
checkIncomplete(g); |
1167 |
> |
f.complete(v1); |
1168 |
> |
} |
1169 |
|
|
1170 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1171 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1172 |
< |
assertEquals(0, r.invocationCount); |
1173 |
< |
checkCompletedNormally(g, v1); |
1170 |
> |
checkCompletedNormally(g, null); |
1171 |
> |
checkCompletedNormally(f, v1); |
1172 |
> |
assertEquals(1, r.invocationCount); |
1173 |
> |
assertEquals(inc(v1), r.value); |
1174 |
|
}} |
1175 |
|
|
1176 |
|
/** |
1177 |
< |
* thenCombine result completes exceptionally if action does |
1177 |
> |
* thenAccept result completes exceptionally after exceptional |
1178 |
> |
* completion of source |
1179 |
|
*/ |
1180 |
< |
public void testThenCombine_actionFailed1() { |
1180 |
> |
public void testThenAccept_exceptionalCompletion() { |
1181 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1182 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1261 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1182 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1183 |
|
{ |
1184 |
+ |
final CFException ex = new CFException(); |
1185 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1186 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1187 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1188 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1189 |
< |
|
1190 |
< |
f.complete(v1); |
1191 |
< |
checkIncomplete(h); |
1192 |
< |
g.complete(v2); |
1186 |
> |
final IncAction r = new IncAction(); |
1187 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1188 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1189 |
> |
if (createIncomplete) { |
1190 |
> |
checkIncomplete(g); |
1191 |
> |
f.completeExceptionally(ex); |
1192 |
> |
} |
1193 |
|
|
1194 |
< |
checkCompletedWithWrappedCFException(h); |
1195 |
< |
checkCompletedNormally(f, v1); |
1196 |
< |
checkCompletedNormally(g, v2); |
1194 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1195 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1196 |
> |
assertEquals(0, r.invocationCount); |
1197 |
|
}} |
1198 |
|
|
1199 |
< |
public void testThenCombine_actionFailed2() { |
1199 |
> |
/** |
1200 |
> |
* thenAccept result completes exceptionally if action does |
1201 |
> |
*/ |
1202 |
> |
public void testThenAccept_actionFailed() { |
1203 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1204 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1205 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1280 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1206 |
|
{ |
1207 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1208 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1209 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1210 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1211 |
< |
|
1212 |
< |
g.complete(v2); |
1213 |
< |
checkIncomplete(h); |
1214 |
< |
f.complete(v1); |
1208 |
> |
final FailingConsumer r = new FailingConsumer(); |
1209 |
> |
if (!createIncomplete) f.complete(v1); |
1210 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1211 |
> |
if (createIncomplete) { |
1212 |
> |
checkIncomplete(g); |
1213 |
> |
f.complete(v1); |
1214 |
> |
} |
1215 |
|
|
1216 |
< |
checkCompletedWithWrappedCFException(h); |
1216 |
> |
checkCompletedWithWrappedCFException(g); |
1217 |
|
checkCompletedNormally(f, v1); |
1293 |
– |
checkCompletedNormally(g, v2); |
1218 |
|
}} |
1219 |
|
|
1220 |
|
/** |
1221 |
< |
* thenCombine result completes exceptionally if either source cancelled |
1221 |
> |
* thenAccept result completes exceptionally if source cancelled |
1222 |
|
*/ |
1223 |
< |
public void testThenCombine_sourceCancelled1() { |
1223 |
> |
public void testThenAccept_sourceCancelled() { |
1224 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1225 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1226 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1302 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1227 |
|
{ |
1228 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1229 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1230 |
< |
final SubtractFunction r = new SubtractFunction(); |
1231 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1232 |
< |
|
1233 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1234 |
< |
checkIncomplete(h); |
1235 |
< |
g.complete(v1); |
1229 |
> |
final IncAction r = new IncAction(); |
1230 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1231 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1232 |
> |
if (createIncomplete) { |
1233 |
> |
checkIncomplete(g); |
1234 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1235 |
> |
} |
1236 |
|
|
1237 |
< |
checkCompletedWithWrappedCancellationException(h); |
1237 |
> |
checkCompletedWithWrappedCancellationException(g); |
1238 |
|
checkCancelled(f); |
1239 |
|
assertEquals(0, r.invocationCount); |
1316 |
– |
checkCompletedNormally(g, v1); |
1317 |
– |
}} |
1318 |
– |
|
1319 |
– |
public void testThenCombine_sourceCancelled2() { |
1320 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1321 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1322 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1323 |
– |
{ |
1324 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1325 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1326 |
– |
final SubtractFunction r = new SubtractFunction(); |
1327 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1328 |
– |
|
1329 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1330 |
– |
checkIncomplete(h); |
1331 |
– |
f.complete(v1); |
1332 |
– |
|
1333 |
– |
checkCompletedWithWrappedCancellationException(h); |
1334 |
– |
checkCancelled(g); |
1335 |
– |
assertEquals(0, r.invocationCount); |
1336 |
– |
checkCompletedNormally(f, v1); |
1240 |
|
}} |
1241 |
|
|
1242 |
< |
public void testThenCombine_sourceCancelled3() { |
1242 |
> |
/** |
1243 |
> |
* thenCombine result completes normally after normal completion |
1244 |
> |
* of sources |
1245 |
> |
*/ |
1246 |
> |
public void testThenCombine_normalCompletion() { |
1247 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1248 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1248 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1249 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1250 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1251 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
1252 |
|
{ |
1253 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1254 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1255 |
|
final SubtractFunction r = new SubtractFunction(); |
1256 |
|
|
1257 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1258 |
< |
f.complete(v1); |
1257 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1258 |
> |
if (!createIncomplete) |
1259 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1260 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1261 |
+ |
if (createIncomplete) { |
1262 |
+ |
checkIncomplete(h); |
1263 |
+ |
assertEquals(0, r.invocationCount); |
1264 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1265 |
+ |
} |
1266 |
|
|
1267 |
< |
checkCompletedWithWrappedCancellationException(h); |
1353 |
< |
checkCancelled(g); |
1354 |
< |
assertEquals(0, r.invocationCount); |
1267 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
1268 |
|
checkCompletedNormally(f, v1); |
1269 |
+ |
checkCompletedNormally(g, v2); |
1270 |
+ |
assertEquals(1, r.invocationCount); |
1271 |
|
}} |
1272 |
|
|
1273 |
< |
public void testThenCombine_sourceCancelled4() { |
1273 |
> |
/** |
1274 |
> |
* thenCombine result completes exceptionally after exceptional |
1275 |
> |
* completion of either source |
1276 |
> |
*/ |
1277 |
> |
public void testThenCombine_exceptionalCompletion() { |
1278 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1279 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1279 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1280 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1281 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1282 |
|
{ |
1283 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1284 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1285 |
+ |
final CFException ex = new CFException(); |
1286 |
|
final SubtractFunction r = new SubtractFunction(); |
1287 |
|
|
1288 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1289 |
< |
g.complete(v1); |
1288 |
> |
(fFirst ? f : g).complete(v1); |
1289 |
> |
if (!createIncomplete) |
1290 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1291 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1292 |
+ |
if (createIncomplete) { |
1293 |
+ |
checkIncomplete(h); |
1294 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1295 |
+ |
} |
1296 |
|
|
1297 |
< |
checkCompletedWithWrappedCancellationException(h); |
1372 |
< |
checkCancelled(f); |
1297 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1298 |
|
assertEquals(0, r.invocationCount); |
1299 |
< |
checkCompletedNormally(g, v1); |
1299 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1300 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1301 |
|
}} |
1302 |
|
|
1303 |
|
/** |
1304 |
< |
* thenAcceptBoth result completes normally after normal |
1379 |
< |
* completion of sources |
1304 |
> |
* thenCombine result completes exceptionally if action does |
1305 |
|
*/ |
1306 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1382 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1383 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1384 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1385 |
< |
{ |
1386 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1387 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1388 |
< |
final SubtractAction r = new SubtractAction(); |
1389 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1390 |
< |
|
1391 |
< |
f.complete(v1); |
1392 |
< |
checkIncomplete(h); |
1393 |
< |
assertEquals(0, r.invocationCount); |
1394 |
< |
g.complete(v2); |
1395 |
< |
|
1396 |
< |
checkCompletedNormally(h, null); |
1397 |
< |
assertEquals(subtract(v1, v2), r.value); |
1398 |
< |
checkCompletedNormally(f, v1); |
1399 |
< |
checkCompletedNormally(g, v2); |
1400 |
< |
}} |
1401 |
< |
|
1402 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1306 |
> |
public void testThenCombine_actionFailed() { |
1307 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1308 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1309 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1310 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1311 |
|
{ |
1312 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1313 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1314 |
< |
final SubtractAction r = new SubtractAction(); |
1315 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1314 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1315 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1316 |
|
|
1317 |
< |
g.complete(v2); |
1318 |
< |
checkIncomplete(h); |
1319 |
< |
assertEquals(0, r.invocationCount); |
1320 |
< |
f.complete(v1); |
1317 |
> |
if (fFirst) { |
1318 |
> |
f.complete(v1); |
1319 |
> |
g.complete(v2); |
1320 |
> |
} else { |
1321 |
> |
g.complete(v2); |
1322 |
> |
f.complete(v1); |
1323 |
> |
} |
1324 |
|
|
1325 |
< |
checkCompletedNormally(h, null); |
1418 |
< |
assertEquals(subtract(v1, v2), r.value); |
1325 |
> |
checkCompletedWithWrappedCFException(h); |
1326 |
|
checkCompletedNormally(f, v1); |
1327 |
|
checkCompletedNormally(g, v2); |
1328 |
|
}} |
1329 |
|
|
1330 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1330 |
> |
/** |
1331 |
> |
* thenCombine result completes exceptionally if either source cancelled |
1332 |
> |
*/ |
1333 |
> |
public void testThenCombine_sourceCancelled() { |
1334 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1335 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1336 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1337 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1338 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1426 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1339 |
|
{ |
1340 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1341 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1342 |
< |
final SubtractAction r = new SubtractAction(); |
1342 |
> |
final SubtractFunction r = new SubtractFunction(); |
1343 |
|
|
1344 |
< |
g.complete(v2); |
1345 |
< |
f.complete(v1); |
1346 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1344 |
> |
(fFirst ? f : g).complete(v1); |
1345 |
> |
if (!createIncomplete) |
1346 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1347 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1348 |
> |
if (createIncomplete) { |
1349 |
> |
checkIncomplete(h); |
1350 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1351 |
> |
} |
1352 |
|
|
1353 |
< |
checkCompletedNormally(h, null); |
1354 |
< |
assertEquals(subtract(v1, v2), r.value); |
1355 |
< |
checkCompletedNormally(f, v1); |
1356 |
< |
checkCompletedNormally(g, v2); |
1353 |
> |
checkCompletedWithWrappedCancellationException(h); |
1354 |
> |
checkCancelled(!fFirst ? f : g); |
1355 |
> |
assertEquals(0, r.invocationCount); |
1356 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1357 |
|
}} |
1358 |
|
|
1359 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1359 |
> |
/** |
1360 |
> |
* thenAcceptBoth result completes normally after normal |
1361 |
> |
* completion of sources |
1362 |
> |
*/ |
1363 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1364 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1365 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1366 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1367 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1368 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1369 |
|
{ |
1371 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1372 |
|
final SubtractAction r = new SubtractAction(); |
1373 |
|
|
1374 |
< |
f.complete(v1); |
1375 |
< |
g.complete(v2); |
1374 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1375 |
> |
if (!createIncomplete) |
1376 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1377 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1378 |
+ |
if (createIncomplete) { |
1379 |
+ |
checkIncomplete(h); |
1380 |
+ |
assertEquals(0, r.invocationCount); |
1381 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1382 |
+ |
} |
1383 |
|
|
1384 |
|
checkCompletedNormally(h, null); |
1385 |
|
assertEquals(subtract(v1, v2), r.value); |
1391 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1392 |
|
* completion of either source |
1393 |
|
*/ |
1394 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1466 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1467 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1468 |
< |
{ |
1469 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1470 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1471 |
< |
final SubtractAction r = new SubtractAction(); |
1472 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1473 |
< |
final CFException ex = new CFException(); |
1474 |
< |
|
1475 |
< |
f.completeExceptionally(ex); |
1476 |
< |
checkIncomplete(h); |
1477 |
< |
g.complete(v1); |
1478 |
< |
|
1479 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1480 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1481 |
< |
assertEquals(0, r.invocationCount); |
1482 |
< |
checkCompletedNormally(g, v1); |
1483 |
< |
}} |
1484 |
< |
|
1485 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1486 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1487 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1488 |
< |
{ |
1489 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1490 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1491 |
< |
final SubtractAction r = new SubtractAction(); |
1492 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1493 |
< |
final CFException ex = new CFException(); |
1494 |
< |
|
1495 |
< |
g.completeExceptionally(ex); |
1496 |
< |
checkIncomplete(h); |
1497 |
< |
f.complete(v1); |
1498 |
< |
|
1499 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1500 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1501 |
< |
assertEquals(0, r.invocationCount); |
1502 |
< |
checkCompletedNormally(f, v1); |
1503 |
< |
}} |
1504 |
< |
|
1505 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1394 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1395 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1396 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1397 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1398 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1399 |
|
{ |
1400 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1401 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1511 |
– |
final SubtractAction r = new SubtractAction(); |
1402 |
|
final CFException ex = new CFException(); |
1513 |
– |
|
1514 |
– |
g.completeExceptionally(ex); |
1515 |
– |
f.complete(v1); |
1516 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1517 |
– |
|
1518 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1519 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1520 |
– |
assertEquals(0, r.invocationCount); |
1521 |
– |
checkCompletedNormally(f, v1); |
1522 |
– |
}} |
1523 |
– |
|
1524 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1525 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1526 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1527 |
– |
{ |
1528 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1529 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
|
final SubtractAction r = new SubtractAction(); |
1531 |
– |
final CFException ex = new CFException(); |
1404 |
|
|
1405 |
< |
f.completeExceptionally(ex); |
1406 |
< |
g.complete(v1); |
1405 |
> |
(fFirst ? f : g).complete(v1); |
1406 |
> |
if (!createIncomplete) |
1407 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1408 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1409 |
+ |
if (createIncomplete) { |
1410 |
+ |
checkIncomplete(h); |
1411 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1412 |
+ |
} |
1413 |
|
|
1414 |
|
checkCompletedWithWrappedCFException(h, ex); |
1538 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1415 |
|
assertEquals(0, r.invocationCount); |
1416 |
< |
checkCompletedNormally(g, v1); |
1416 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1417 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1418 |
|
}} |
1419 |
|
|
1420 |
|
/** |
1421 |
|
* thenAcceptBoth result completes exceptionally if action does |
1422 |
|
*/ |
1423 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1547 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1548 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1549 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1550 |
< |
{ |
1551 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1552 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1553 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1554 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1555 |
< |
|
1556 |
< |
f.complete(v1); |
1557 |
< |
checkIncomplete(h); |
1558 |
< |
g.complete(v2); |
1559 |
< |
|
1560 |
< |
checkCompletedWithWrappedCFException(h); |
1561 |
< |
checkCompletedNormally(f, v1); |
1562 |
< |
checkCompletedNormally(g, v2); |
1563 |
< |
}} |
1564 |
< |
|
1565 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1423 |
> |
public void testThenAcceptBoth_actionFailed() { |
1424 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1425 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1426 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1427 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1428 |
|
{ |
1431 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1432 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1433 |
|
|
1434 |
< |
g.complete(v2); |
1435 |
< |
checkIncomplete(h); |
1436 |
< |
f.complete(v1); |
1434 |
> |
if (fFirst) { |
1435 |
> |
f.complete(v1); |
1436 |
> |
g.complete(v2); |
1437 |
> |
} else { |
1438 |
> |
g.complete(v2); |
1439 |
> |
f.complete(v1); |
1440 |
> |
} |
1441 |
|
|
1442 |
|
checkCompletedWithWrappedCFException(h); |
1443 |
|
checkCompletedNormally(f, v1); |
1447 |
|
/** |
1448 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1449 |
|
*/ |
1450 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1588 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1589 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1590 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1591 |
< |
{ |
1592 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1593 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1594 |
< |
final SubtractAction r = new SubtractAction(); |
1595 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1596 |
< |
|
1597 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1598 |
< |
checkIncomplete(h); |
1599 |
< |
g.complete(v1); |
1600 |
< |
|
1601 |
< |
checkCompletedWithWrappedCancellationException(h); |
1602 |
< |
checkCancelled(f); |
1603 |
< |
assertEquals(0, r.invocationCount); |
1604 |
< |
checkCompletedNormally(g, v1); |
1605 |
< |
}} |
1606 |
< |
|
1607 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1608 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1609 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1610 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1611 |
< |
{ |
1612 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1613 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1614 |
< |
final SubtractAction r = new SubtractAction(); |
1615 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1616 |
< |
|
1617 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1618 |
< |
checkIncomplete(h); |
1619 |
< |
f.complete(v1); |
1620 |
< |
|
1621 |
< |
checkCompletedWithWrappedCancellationException(h); |
1622 |
< |
checkCancelled(g); |
1623 |
< |
assertEquals(0, r.invocationCount); |
1624 |
< |
checkCompletedNormally(f, v1); |
1625 |
< |
}} |
1626 |
< |
|
1627 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1628 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1629 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1630 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1631 |
< |
{ |
1632 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1633 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1634 |
< |
final SubtractAction r = new SubtractAction(); |
1635 |
< |
|
1636 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1637 |
< |
f.complete(v1); |
1638 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1639 |
< |
|
1640 |
< |
checkCompletedWithWrappedCancellationException(h); |
1641 |
< |
checkCancelled(g); |
1642 |
< |
assertEquals(0, r.invocationCount); |
1643 |
< |
checkCompletedNormally(f, v1); |
1644 |
< |
}} |
1645 |
< |
|
1646 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1450 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1451 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1452 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1453 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1454 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1455 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1456 |
|
{ |
1457 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1458 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1459 |
|
final SubtractAction r = new SubtractAction(); |
1460 |
|
|
1461 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1462 |
< |
g.complete(v1); |
1461 |
> |
(fFirst ? f : g).complete(v1); |
1462 |
> |
if (!createIncomplete) |
1463 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1464 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1465 |
+ |
if (createIncomplete) { |
1466 |
+ |
checkIncomplete(h); |
1467 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1468 |
+ |
} |
1469 |
|
|
1470 |
|
checkCompletedWithWrappedCancellationException(h); |
1471 |
< |
checkCancelled(f); |
1471 |
> |
checkCancelled(!fFirst ? f : g); |
1472 |
|
assertEquals(0, r.invocationCount); |
1473 |
< |
checkCompletedNormally(g, v1); |
1473 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1474 |
|
}} |
1475 |
|
|
1476 |
|
/** |
1477 |
|
* runAfterBoth result completes normally after normal |
1478 |
|
* completion of sources |
1479 |
|
*/ |
1480 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1670 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1671 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1672 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1673 |
< |
{ |
1674 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1675 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1676 |
< |
final Noop r = new Noop(); |
1677 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1678 |
< |
|
1679 |
< |
f.complete(v1); |
1680 |
< |
checkIncomplete(h); |
1681 |
< |
assertEquals(0, r.invocationCount); |
1682 |
< |
g.complete(v2); |
1683 |
< |
|
1684 |
< |
checkCompletedNormally(h, null); |
1685 |
< |
assertEquals(1, r.invocationCount); |
1686 |
< |
checkCompletedNormally(f, v1); |
1687 |
< |
checkCompletedNormally(g, v2); |
1688 |
< |
}} |
1689 |
< |
|
1690 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1691 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1692 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1693 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1694 |
< |
{ |
1695 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1696 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1697 |
< |
final Noop r = new Noop(); |
1698 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1699 |
< |
|
1700 |
< |
g.complete(v2); |
1701 |
< |
checkIncomplete(h); |
1702 |
< |
assertEquals(0, r.invocationCount); |
1703 |
< |
f.complete(v1); |
1704 |
< |
|
1705 |
< |
checkCompletedNormally(h, null); |
1706 |
< |
assertEquals(1, r.invocationCount); |
1707 |
< |
checkCompletedNormally(f, v1); |
1708 |
< |
checkCompletedNormally(g, v2); |
1709 |
< |
}} |
1710 |
< |
|
1711 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1712 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1713 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1714 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1715 |
< |
{ |
1716 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1717 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1718 |
< |
final Noop r = new Noop(); |
1719 |
< |
|
1720 |
< |
g.complete(v2); |
1721 |
< |
f.complete(v1); |
1722 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1723 |
< |
|
1724 |
< |
checkCompletedNormally(h, null); |
1725 |
< |
assertEquals(1, r.invocationCount); |
1726 |
< |
checkCompletedNormally(f, v1); |
1727 |
< |
checkCompletedNormally(g, v2); |
1728 |
< |
}} |
1729 |
< |
|
1730 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1480 |
> |
public void testRunAfterBoth_normalCompletion() { |
1481 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1482 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1483 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1484 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1485 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1486 |
|
{ |
1487 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1488 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1489 |
< |
final Noop r = new Noop(); |
1489 |
> |
final Noop r = new Noop(m); |
1490 |
|
|
1491 |
< |
f.complete(v1); |
1492 |
< |
g.complete(v2); |
1491 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1492 |
> |
if (!createIncomplete) |
1493 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1494 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1495 |
+ |
if (createIncomplete) { |
1496 |
+ |
checkIncomplete(h); |
1497 |
+ |
assertEquals(0, r.invocationCount); |
1498 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1499 |
+ |
} |
1500 |
|
|
1501 |
|
checkCompletedNormally(h, null); |
1502 |
|
assertEquals(1, r.invocationCount); |
1508 |
|
* runAfterBoth result completes exceptionally after exceptional |
1509 |
|
* completion of either source |
1510 |
|
*/ |
1511 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1754 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1755 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1756 |
< |
{ |
1757 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1758 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1759 |
< |
final Noop r = new Noop(); |
1760 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1761 |
< |
final CFException ex = new CFException(); |
1762 |
< |
|
1763 |
< |
f.completeExceptionally(ex); |
1764 |
< |
checkIncomplete(h); |
1765 |
< |
g.complete(v1); |
1766 |
< |
|
1767 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1768 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1769 |
< |
assertEquals(0, r.invocationCount); |
1770 |
< |
checkCompletedNormally(g, v1); |
1771 |
< |
}} |
1772 |
< |
|
1773 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1774 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1775 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1776 |
< |
{ |
1777 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1778 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1779 |
< |
final Noop r = new Noop(); |
1780 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1781 |
< |
final CFException ex = new CFException(); |
1782 |
< |
|
1783 |
< |
g.completeExceptionally(ex); |
1784 |
< |
checkIncomplete(h); |
1785 |
< |
f.complete(v1); |
1786 |
< |
|
1787 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1788 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1789 |
< |
assertEquals(0, r.invocationCount); |
1790 |
< |
checkCompletedNormally(f, v1); |
1791 |
< |
}} |
1792 |
< |
|
1793 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1794 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1795 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1796 |
< |
{ |
1797 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1798 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1799 |
< |
final Noop r = new Noop(); |
1800 |
< |
final CFException ex = new CFException(); |
1801 |
< |
|
1802 |
< |
g.completeExceptionally(ex); |
1803 |
< |
f.complete(v1); |
1804 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1805 |
< |
|
1806 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1807 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1808 |
< |
assertEquals(0, r.invocationCount); |
1809 |
< |
checkCompletedNormally(f, v1); |
1810 |
< |
}} |
1811 |
< |
|
1812 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1511 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1512 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1513 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1514 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1515 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1516 |
|
{ |
1517 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1518 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1818 |
– |
final Noop r = new Noop(); |
1519 |
|
final CFException ex = new CFException(); |
1520 |
+ |
final Noop r = new Noop(m); |
1521 |
|
|
1522 |
< |
f.completeExceptionally(ex); |
1523 |
< |
g.complete(v1); |
1522 |
> |
(fFirst ? f : g).complete(v1); |
1523 |
> |
if (!createIncomplete) |
1524 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1525 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1526 |
+ |
if (createIncomplete) { |
1527 |
+ |
checkIncomplete(h); |
1528 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1529 |
+ |
} |
1530 |
|
|
1531 |
|
checkCompletedWithWrappedCFException(h, ex); |
1826 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1532 |
|
assertEquals(0, r.invocationCount); |
1533 |
< |
checkCompletedNormally(g, v1); |
1533 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1534 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1535 |
|
}} |
1536 |
|
|
1537 |
|
/** |
1538 |
|
* runAfterBoth result completes exceptionally if action does |
1539 |
|
*/ |
1540 |
< |
public void testRunAfterBoth_actionFailed1() { |
1835 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1836 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1837 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1838 |
< |
{ |
1839 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1840 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1841 |
< |
final FailingNoop r = new FailingNoop(); |
1842 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1843 |
< |
|
1844 |
< |
f.complete(v1); |
1845 |
< |
checkIncomplete(h); |
1846 |
< |
g.complete(v2); |
1847 |
< |
|
1848 |
< |
checkCompletedWithWrappedCFException(h); |
1849 |
< |
checkCompletedNormally(f, v1); |
1850 |
< |
checkCompletedNormally(g, v2); |
1851 |
< |
}} |
1852 |
< |
|
1853 |
< |
public void testRunAfterBoth_actionFailed2() { |
1540 |
> |
public void testRunAfterBoth_actionFailed() { |
1541 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1542 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1543 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1544 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1545 |
|
{ |
1546 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1547 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1548 |
< |
final FailingNoop r = new FailingNoop(); |
1861 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1548 |
> |
final FailingRunnable r = new FailingRunnable(); |
1549 |
|
|
1550 |
< |
g.complete(v2); |
1551 |
< |
checkIncomplete(h); |
1552 |
< |
f.complete(v1); |
1550 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1551 |
> |
if (fFirst) { |
1552 |
> |
f.complete(v1); |
1553 |
> |
g.complete(v2); |
1554 |
> |
} else { |
1555 |
> |
g.complete(v2); |
1556 |
> |
f.complete(v1); |
1557 |
> |
} |
1558 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1559 |
|
|
1560 |
< |
checkCompletedWithWrappedCFException(h); |
1560 |
> |
checkCompletedWithWrappedCFException(h1); |
1561 |
> |
checkCompletedWithWrappedCFException(h2); |
1562 |
|
checkCompletedNormally(f, v1); |
1563 |
|
checkCompletedNormally(g, v2); |
1564 |
|
}} |
1566 |
|
/** |
1567 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1568 |
|
*/ |
1569 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1876 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1877 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1878 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1879 |
< |
{ |
1880 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1881 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1882 |
< |
final Noop r = new Noop(); |
1883 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1884 |
< |
|
1885 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1886 |
< |
checkIncomplete(h); |
1887 |
< |
g.complete(v1); |
1888 |
< |
|
1889 |
< |
checkCompletedWithWrappedCancellationException(h); |
1890 |
< |
checkCancelled(f); |
1891 |
< |
assertEquals(0, r.invocationCount); |
1892 |
< |
checkCompletedNormally(g, v1); |
1893 |
< |
}} |
1894 |
< |
|
1895 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1896 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1897 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1898 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1899 |
< |
{ |
1900 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1901 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1902 |
< |
final Noop r = new Noop(); |
1903 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1904 |
< |
|
1905 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1906 |
< |
checkIncomplete(h); |
1907 |
< |
f.complete(v1); |
1908 |
< |
|
1909 |
< |
checkCompletedWithWrappedCancellationException(h); |
1910 |
< |
checkCancelled(g); |
1911 |
< |
assertEquals(0, r.invocationCount); |
1912 |
< |
checkCompletedNormally(f, v1); |
1913 |
< |
}} |
1914 |
< |
|
1915 |
< |
public void testRunAfterBoth_sourceCancelled3() { |
1569 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1570 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1571 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1572 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1573 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1574 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1575 |
|
{ |
1576 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1577 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1578 |
< |
final Noop r = new Noop(); |
1923 |
< |
|
1924 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1925 |
< |
f.complete(v1); |
1926 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1927 |
< |
|
1928 |
< |
checkCompletedWithWrappedCancellationException(h); |
1929 |
< |
checkCancelled(g); |
1930 |
< |
assertEquals(0, r.invocationCount); |
1931 |
< |
checkCompletedNormally(f, v1); |
1932 |
< |
}} |
1578 |
> |
final Noop r = new Noop(m); |
1579 |
|
|
1934 |
– |
public void testRunAfterBoth_sourceCancelled4() { |
1935 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1936 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1937 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1938 |
– |
{ |
1939 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1940 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1941 |
– |
final Noop r = new Noop(); |
1580 |
|
|
1581 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1582 |
< |
g.complete(v1); |
1581 |
> |
(fFirst ? f : g).complete(v1); |
1582 |
> |
if (!createIncomplete) |
1583 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1584 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
+ |
if (createIncomplete) { |
1586 |
+ |
checkIncomplete(h); |
1587 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1588 |
+ |
} |
1589 |
|
|
1590 |
|
checkCompletedWithWrappedCancellationException(h); |
1591 |
< |
checkCancelled(f); |
1591 |
> |
checkCancelled(!fFirst ? f : g); |
1592 |
|
assertEquals(0, r.invocationCount); |
1593 |
< |
checkCompletedNormally(g, v1); |
1593 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1594 |
|
}} |
1595 |
|
|
1596 |
|
/** |
1597 |
|
* applyToEither result completes normally after normal completion |
1598 |
|
* of either source |
1599 |
|
*/ |
1600 |
< |
public void testApplyToEither_normalCompletion1() { |
1600 |
> |
public void testApplyToEither_normalCompletion() { |
1601 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1602 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1603 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1604 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1605 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1606 |
|
{ |
1607 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1608 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1609 |
|
final IncFunction r = new IncFunction(); |
1965 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1610 |
|
|
1611 |
< |
f.complete(v1); |
1612 |
< |
checkCompletedNormally(h, inc(v1)); |
1613 |
< |
g.complete(v2); |
1611 |
> |
if (!createIncomplete) |
1612 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1613 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1614 |
> |
if (createIncomplete) { |
1615 |
> |
checkIncomplete(h); |
1616 |
> |
assertEquals(0, r.invocationCount); |
1617 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1618 |
> |
} |
1619 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1620 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1621 |
|
|
1622 |
|
checkCompletedNormally(f, v1); |
1623 |
|
checkCompletedNormally(g, v2); |
1624 |
< |
checkCompletedNormally(h, inc(v1)); |
1624 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1625 |
|
}} |
1626 |
|
|
1627 |
< |
public void testApplyToEither_normalCompletion2() { |
1627 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1628 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1629 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1630 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1631 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1632 |
|
{ |
1633 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1634 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1635 |
|
final IncFunction r = new IncFunction(); |
1984 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1985 |
– |
|
1986 |
– |
g.complete(v2); |
1987 |
– |
checkCompletedNormally(h, inc(v2)); |
1988 |
– |
f.complete(v1); |
1989 |
– |
|
1990 |
– |
checkCompletedNormally(f, v1); |
1991 |
– |
checkCompletedNormally(g, v2); |
1992 |
– |
checkCompletedNormally(h, inc(v2)); |
1993 |
– |
}} |
1636 |
|
|
1637 |
< |
public void testApplyToEither_normalCompletion3() { |
1638 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1639 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1640 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1641 |
< |
{ |
1642 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1643 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2002 |
< |
final IncFunction r = new IncFunction(); |
1637 |
> |
if (fFirst) { |
1638 |
> |
f.complete(v1); |
1639 |
> |
g.complete(v2); |
1640 |
> |
} else { |
1641 |
> |
g.complete(v2); |
1642 |
> |
f.complete(v1); |
1643 |
> |
} |
1644 |
|
|
2004 |
– |
f.complete(v1); |
2005 |
– |
g.complete(v2); |
1645 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1646 |
|
|
1647 |
|
checkCompletedNormally(f, v1); |
1659 |
|
*/ |
1660 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1661 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1662 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1663 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1664 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1665 |
|
{ |
1666 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1667 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2027 |
– |
final IncFunction r = new IncFunction(); |
2028 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1668 |
|
final CFException ex = new CFException(); |
2030 |
– |
|
2031 |
– |
f.completeExceptionally(ex); |
2032 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2033 |
– |
g.complete(v1); |
2034 |
– |
|
2035 |
– |
assertEquals(0, r.invocationCount); |
2036 |
– |
checkCompletedNormally(g, v1); |
2037 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2038 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2039 |
– |
}} |
2040 |
– |
|
2041 |
– |
public void testApplyToEither_exceptionalCompletion2() { |
2042 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2043 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2044 |
– |
{ |
2045 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2046 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1669 |
|
final IncFunction r = new IncFunction(); |
1670 |
+ |
|
1671 |
+ |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1672 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1673 |
< |
final CFException ex = new CFException(); |
1673 |
> |
if (createIncomplete) { |
1674 |
> |
checkIncomplete(h); |
1675 |
> |
assertEquals(0, r.invocationCount); |
1676 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1677 |
> |
} |
1678 |
|
|
2051 |
– |
g.completeExceptionally(ex); |
1679 |
|
checkCompletedWithWrappedCFException(h, ex); |
1680 |
< |
f.complete(v1); |
1680 |
> |
(!fFirst ? f : g).complete(v1); |
1681 |
|
|
1682 |
|
assertEquals(0, r.invocationCount); |
1683 |
< |
checkCompletedNormally(f, v1); |
1684 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1683 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1684 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1685 |
|
checkCompletedWithWrappedCFException(h, ex); |
1686 |
|
}} |
1687 |
|
|
1688 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1688 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1689 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1690 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1691 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1692 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1693 |
|
{ |
1694 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1695 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1696 |
< |
final IncFunction r = new IncFunction(); |
1696 |
> |
final IncFunction r1 = new IncFunction(); |
1697 |
> |
final IncFunction r2 = new IncFunction(); |
1698 |
|
final CFException ex = new CFException(); |
1699 |
< |
|
1700 |
< |
g.completeExceptionally(ex); |
1701 |
< |
f.complete(v1); |
1702 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1699 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1700 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1701 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1702 |
> |
if (fFirst) { |
1703 |
> |
f.complete(v1); |
1704 |
> |
g.completeExceptionally(ex); |
1705 |
> |
} else { |
1706 |
> |
g.completeExceptionally(ex); |
1707 |
> |
f.complete(v1); |
1708 |
> |
} |
1709 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1710 |
|
|
1711 |
|
// unspecified behavior |
2075 |
– |
Integer v; |
1712 |
|
try { |
1713 |
< |
assertEquals(inc(v1), h.join()); |
1714 |
< |
assertEquals(1, r.invocationCount); |
1713 |
> |
assertEquals(inc(v1), h1.join()); |
1714 |
> |
assertEquals(1, r1.invocationCount); |
1715 |
|
} catch (CompletionException ok) { |
1716 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1717 |
< |
assertEquals(0, r.invocationCount); |
1716 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1717 |
> |
assertEquals(0, r1.invocationCount); |
1718 |
|
} |
1719 |
|
|
2084 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2085 |
– |
checkCompletedNormally(f, v1); |
2086 |
– |
}} |
2087 |
– |
|
2088 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2089 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2090 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2091 |
– |
{ |
2092 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2093 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2094 |
– |
final IncFunction r = new IncFunction(); |
2095 |
– |
final CFException ex = new CFException(); |
2096 |
– |
|
2097 |
– |
f.completeExceptionally(ex); |
2098 |
– |
g.complete(v1); |
2099 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2100 |
– |
|
2101 |
– |
// unspecified behavior |
2102 |
– |
Integer v; |
1720 |
|
try { |
1721 |
< |
assertEquals(inc(v1), h.join()); |
1722 |
< |
assertEquals(1, r.invocationCount); |
1721 |
> |
assertEquals(inc(v1), h2.join()); |
1722 |
> |
assertEquals(1, r2.invocationCount); |
1723 |
|
} catch (CompletionException ok) { |
1724 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1725 |
< |
assertEquals(0, r.invocationCount); |
1724 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1725 |
> |
assertEquals(0, r2.invocationCount); |
1726 |
|
} |
1727 |
|
|
1728 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1729 |
< |
checkCompletedNormally(g, v1); |
1728 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1729 |
> |
checkCompletedNormally(f, v1); |
1730 |
|
}} |
1731 |
|
|
1732 |
|
/** |
1772 |
|
public void testApplyToEither_sourceCancelled1() { |
1773 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1774 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1775 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1776 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1777 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1778 |
|
{ |
1779 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1780 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1781 |
|
final IncFunction r = new IncFunction(); |
2163 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2164 |
– |
|
2165 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2166 |
– |
checkCompletedWithWrappedCancellationException(h); |
2167 |
– |
g.complete(v1); |
2168 |
– |
|
2169 |
– |
checkCancelled(f); |
2170 |
– |
assertEquals(0, r.invocationCount); |
2171 |
– |
checkCompletedNormally(g, v1); |
2172 |
– |
checkCompletedWithWrappedCancellationException(h); |
2173 |
– |
}} |
1782 |
|
|
1783 |
< |
public void testApplyToEither_sourceCancelled2() { |
2176 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2177 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2178 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2179 |
< |
{ |
2180 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2181 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2182 |
< |
final IncFunction r = new IncFunction(); |
1783 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1784 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1785 |
+ |
if (createIncomplete) { |
1786 |
+ |
checkIncomplete(h); |
1787 |
+ |
assertEquals(0, r.invocationCount); |
1788 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1789 |
+ |
} |
1790 |
|
|
2185 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1791 |
|
checkCompletedWithWrappedCancellationException(h); |
1792 |
< |
f.complete(v1); |
1792 |
> |
(!fFirst ? f : g).complete(v1); |
1793 |
|
|
2189 |
– |
checkCancelled(g); |
1794 |
|
assertEquals(0, r.invocationCount); |
1795 |
< |
checkCompletedNormally(f, v1); |
1795 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1796 |
> |
checkCancelled(fFirst ? f : g); |
1797 |
|
checkCompletedWithWrappedCancellationException(h); |
1798 |
|
}} |
1799 |
|
|
1800 |
< |
public void testApplyToEither_sourceCancelled3() { |
1800 |
> |
public void testApplyToEither_sourceCancelled2() { |
1801 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1802 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1803 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1804 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1805 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1806 |
|
{ |
1807 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1808 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1809 |
< |
final IncFunction r = new IncFunction(); |
1809 |
> |
final IncFunction r1 = new IncFunction(); |
1810 |
> |
final IncFunction r2 = new IncFunction(); |
1811 |
> |
final CFException ex = new CFException(); |
1812 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1813 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1814 |
|
|
1815 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1816 |
< |
f.complete(v1); |
1817 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1815 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1816 |
> |
if (fFirst) { |
1817 |
> |
f.complete(v1); |
1818 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1819 |
> |
} else { |
1820 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1821 |
> |
f.complete(v1); |
1822 |
> |
} |
1823 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1824 |
|
|
1825 |
|
// unspecified behavior |
2209 |
– |
Integer v; |
1826 |
|
try { |
1827 |
< |
assertEquals(inc(v1), h.join()); |
1828 |
< |
assertEquals(1, r.invocationCount); |
1827 |
> |
assertEquals(inc(v1), h1.join()); |
1828 |
> |
assertEquals(1, r1.invocationCount); |
1829 |
|
} catch (CompletionException ok) { |
1830 |
< |
checkCompletedWithWrappedCancellationException(h); |
1831 |
< |
assertEquals(0, r.invocationCount); |
1830 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1831 |
> |
assertEquals(0, r1.invocationCount); |
1832 |
|
} |
1833 |
|
|
2218 |
– |
checkCancelled(g); |
2219 |
– |
checkCompletedNormally(f, v1); |
2220 |
– |
}} |
2221 |
– |
|
2222 |
– |
public void testApplyToEither_sourceCancelled4() { |
2223 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2224 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2225 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2226 |
– |
{ |
2227 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2228 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2229 |
– |
final IncFunction r = new IncFunction(); |
2230 |
– |
|
2231 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2232 |
– |
g.complete(v1); |
2233 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2234 |
– |
|
2235 |
– |
// unspecified behavior |
2236 |
– |
Integer v; |
1834 |
|
try { |
1835 |
< |
assertEquals(inc(v1), h.join()); |
1836 |
< |
assertEquals(1, r.invocationCount); |
1835 |
> |
assertEquals(inc(v1), h2.join()); |
1836 |
> |
assertEquals(1, r2.invocationCount); |
1837 |
|
} catch (CompletionException ok) { |
1838 |
< |
checkCompletedWithWrappedCancellationException(h); |
1839 |
< |
assertEquals(0, r.invocationCount); |
1838 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1839 |
> |
assertEquals(0, r2.invocationCount); |
1840 |
|
} |
1841 |
|
|
1842 |
< |
checkCancelled(f); |
1843 |
< |
checkCompletedNormally(g, v1); |
1842 |
> |
checkCancelled(g); |
1843 |
> |
checkCompletedNormally(f, v1); |
1844 |
|
}} |
1845 |
|
|
1846 |
|
/** |
2156 |
|
{ |
2157 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2158 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2159 |
< |
final Noop r = new Noop(); |
2159 |
> |
final Noop r = new Noop(m); |
2160 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2161 |
|
|
2162 |
|
f.complete(v1); |
2177 |
|
{ |
2178 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2179 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2180 |
< |
final Noop r = new Noop(); |
2180 |
> |
final Noop r = new Noop(m); |
2181 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2182 |
|
|
2183 |
|
g.complete(v2); |
2198 |
|
{ |
2199 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2200 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2201 |
< |
final Noop r = new Noop(); |
2201 |
> |
final Noop r = new Noop(m); |
2202 |
|
|
2203 |
|
f.complete(v1); |
2204 |
|
g.complete(v2); |
2220 |
|
{ |
2221 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2222 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2223 |
< |
final Noop r = new Noop(); |
2223 |
> |
final Noop r = new Noop(m); |
2224 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2225 |
|
final CFException ex = new CFException(); |
2226 |
|
|
2240 |
|
{ |
2241 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2242 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2243 |
< |
final Noop r = new Noop(); |
2243 |
> |
final Noop r = new Noop(m); |
2244 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2245 |
|
final CFException ex = new CFException(); |
2246 |
|
|
2260 |
|
{ |
2261 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2262 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2263 |
< |
final Noop r = new Noop(); |
2263 |
> |
final Noop r = new Noop(m); |
2264 |
|
final CFException ex = new CFException(); |
2265 |
|
|
2266 |
|
g.completeExceptionally(ex); |
2287 |
|
{ |
2288 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2289 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2290 |
< |
final Noop r = new Noop(); |
2290 |
> |
final Noop r = new Noop(m); |
2291 |
|
final CFException ex = new CFException(); |
2292 |
|
|
2293 |
|
f.completeExceptionally(ex); |
2318 |
|
{ |
2319 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2320 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2321 |
< |
final FailingNoop r = new FailingNoop(); |
2321 |
> |
final FailingRunnable r = new FailingRunnable(); |
2322 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2323 |
|
|
2324 |
|
f.complete(v1); |
2335 |
|
{ |
2336 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2337 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2338 |
< |
final FailingNoop r = new FailingNoop(); |
2338 |
> |
final FailingRunnable r = new FailingRunnable(); |
2339 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2340 |
|
|
2341 |
|
g.complete(v2); |
2355 |
|
{ |
2356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2357 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2358 |
< |
final Noop r = new Noop(); |
2358 |
> |
final Noop r = new Noop(m); |
2359 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2360 |
|
|
2361 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2375 |
|
{ |
2376 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2377 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2378 |
< |
final Noop r = new Noop(); |
2378 |
> |
final Noop r = new Noop(m); |
2379 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2380 |
|
|
2381 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2395 |
|
{ |
2396 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2397 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2398 |
< |
final Noop r = new Noop(); |
2398 |
> |
final Noop r = new Noop(m); |
2399 |
|
|
2400 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2401 |
|
f.complete(v1); |
2422 |
|
{ |
2423 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2424 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2425 |
< |
final Noop r = new Noop(); |
2425 |
> |
final Noop r = new Noop(m); |
2426 |
|
|
2427 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2428 |
|
g.complete(v1); |
2512 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2513 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2514 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2515 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2515 |
> |
if (createIncomplete) { |
2516 |
> |
checkIncomplete(g); |
2517 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2518 |
> |
} |
2519 |
|
|
2520 |
|
checkCompletedWithWrappedCancellationException(g); |
2521 |
|
checkCancelled(f); |
2522 |
|
}} |
2523 |
|
|
2924 |
– |
// asyncs |
2925 |
– |
|
2926 |
– |
/** |
2927 |
– |
* thenApplyAsync result completes normally after normal completion of source |
2928 |
– |
*/ |
2929 |
– |
public void testThenApplyAsync() { |
2930 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2931 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
2932 |
– |
f.complete(one); |
2933 |
– |
checkCompletedNormally(g, two); |
2934 |
– |
} |
2935 |
– |
|
2936 |
– |
/** |
2937 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
2938 |
– |
* completion of source |
2939 |
– |
*/ |
2940 |
– |
public void testThenApplyAsync2() { |
2941 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2942 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
2943 |
– |
f.completeExceptionally(new CFException()); |
2944 |
– |
checkCompletedWithWrappedCFException(g); |
2945 |
– |
} |
2946 |
– |
|
2947 |
– |
/** |
2948 |
– |
* thenApplyAsync result completes exceptionally if action does |
2949 |
– |
*/ |
2950 |
– |
public void testThenApplyAsync3() { |
2951 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2952 |
– |
FailingFunction r = new FailingFunction(); |
2953 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
2954 |
– |
f.complete(null); |
2955 |
– |
checkCompletedWithWrappedCFException(g); |
2956 |
– |
} |
2957 |
– |
|
2958 |
– |
/** |
2959 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
2960 |
– |
*/ |
2961 |
– |
public void testThenApplyAsync4() { |
2962 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2963 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
2964 |
– |
assertTrue(f.cancel(true)); |
2965 |
– |
checkCompletedWithWrappedCancellationException(g); |
2966 |
– |
} |
2967 |
– |
|
2968 |
– |
/** |
2969 |
– |
* thenAcceptAsync result completes normally after normal |
2970 |
– |
* completion of source |
2971 |
– |
*/ |
2972 |
– |
public void testThenAcceptAsync() { |
2973 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2974 |
– |
IncAction r = new IncAction(); |
2975 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2976 |
– |
f.complete(one); |
2977 |
– |
checkCompletedNormally(g, null); |
2978 |
– |
assertEquals(r.value, (Integer) 2); |
2979 |
– |
} |
2980 |
– |
|
2981 |
– |
/** |
2982 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
2983 |
– |
* completion of source |
2984 |
– |
*/ |
2985 |
– |
public void testThenAcceptAsync2() { |
2986 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2987 |
– |
IncAction r = new IncAction(); |
2988 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2989 |
– |
f.completeExceptionally(new CFException()); |
2990 |
– |
checkCompletedWithWrappedCFException(g); |
2991 |
– |
} |
2992 |
– |
|
2993 |
– |
/** |
2994 |
– |
* thenAcceptAsync result completes exceptionally if action does |
2995 |
– |
*/ |
2996 |
– |
public void testThenAcceptAsync3() { |
2997 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2998 |
– |
FailingConsumer r = new FailingConsumer(); |
2999 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3000 |
– |
f.complete(null); |
3001 |
– |
checkCompletedWithWrappedCFException(g); |
3002 |
– |
} |
3003 |
– |
|
3004 |
– |
/** |
3005 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3006 |
– |
*/ |
3007 |
– |
public void testThenAcceptAsync4() { |
3008 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3009 |
– |
IncAction r = new IncAction(); |
3010 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3011 |
– |
assertTrue(f.cancel(true)); |
3012 |
– |
checkCompletedWithWrappedCancellationException(g); |
3013 |
– |
} |
3014 |
– |
|
3015 |
– |
// async with explicit executors |
3016 |
– |
|
3017 |
– |
/** |
3018 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3019 |
– |
*/ |
3020 |
– |
public void testThenApplyAsyncE() { |
3021 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3022 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3023 |
– |
f.complete(one); |
3024 |
– |
checkCompletedNormally(g, two); |
3025 |
– |
} |
3026 |
– |
|
3027 |
– |
/** |
3028 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3029 |
– |
* completion of source |
3030 |
– |
*/ |
3031 |
– |
public void testThenApplyAsync2E() { |
3032 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3033 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3034 |
– |
f.completeExceptionally(new CFException()); |
3035 |
– |
checkCompletedWithWrappedCFException(g); |
3036 |
– |
} |
3037 |
– |
|
3038 |
– |
/** |
3039 |
– |
* thenApplyAsync result completes exceptionally if action does |
3040 |
– |
*/ |
3041 |
– |
public void testThenApplyAsync3E() { |
3042 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3043 |
– |
FailingFunction r = new FailingFunction(); |
3044 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
3045 |
– |
f.complete(null); |
3046 |
– |
checkCompletedWithWrappedCFException(g); |
3047 |
– |
} |
3048 |
– |
|
3049 |
– |
/** |
3050 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3051 |
– |
*/ |
3052 |
– |
public void testThenApplyAsync4E() { |
3053 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3054 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3055 |
– |
assertTrue(f.cancel(true)); |
3056 |
– |
checkCompletedWithWrappedCancellationException(g); |
3057 |
– |
} |
3058 |
– |
|
3059 |
– |
/** |
3060 |
– |
* thenAcceptAsync result completes normally after normal |
3061 |
– |
* completion of source |
3062 |
– |
*/ |
3063 |
– |
public void testThenAcceptAsyncE() { |
3064 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3065 |
– |
IncAction r = new IncAction(); |
3066 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3067 |
– |
f.complete(one); |
3068 |
– |
checkCompletedNormally(g, null); |
3069 |
– |
assertEquals(r.value, (Integer) 2); |
3070 |
– |
} |
3071 |
– |
|
3072 |
– |
/** |
3073 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3074 |
– |
* completion of source |
3075 |
– |
*/ |
3076 |
– |
public void testThenAcceptAsync2E() { |
3077 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3078 |
– |
IncAction r = new IncAction(); |
3079 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3080 |
– |
f.completeExceptionally(new CFException()); |
3081 |
– |
checkCompletedWithWrappedCFException(g); |
3082 |
– |
} |
3083 |
– |
|
3084 |
– |
/** |
3085 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3086 |
– |
*/ |
3087 |
– |
public void testThenAcceptAsync3E() { |
3088 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3089 |
– |
FailingConsumer r = new FailingConsumer(); |
3090 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3091 |
– |
f.complete(null); |
3092 |
– |
checkCompletedWithWrappedCFException(g); |
3093 |
– |
} |
3094 |
– |
|
3095 |
– |
/** |
3096 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3097 |
– |
*/ |
3098 |
– |
public void testThenAcceptAsync4E() { |
3099 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3100 |
– |
IncAction r = new IncAction(); |
3101 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3102 |
– |
assertTrue(f.cancel(true)); |
3103 |
– |
checkCompletedWithWrappedCancellationException(g); |
3104 |
– |
} |
3105 |
– |
|
2524 |
|
// other static methods |
2525 |
|
|
2526 |
|
/** |