416 |
|
throw new CFException(); |
417 |
|
} |
418 |
|
} |
419 |
< |
static final class FailingNoop implements Runnable { |
419 |
> |
static final class FailingRunnable implements Runnable { |
420 |
|
int invocationCount = 0; |
421 |
|
public void run() { |
422 |
|
invocationCount++; |
933 |
|
* failing runAsync completes exceptionally after running Runnable |
934 |
|
*/ |
935 |
|
public void testRunAsync3() { |
936 |
< |
FailingNoop r = new FailingNoop(); |
936 |
> |
FailingRunnable r = new FailingRunnable(); |
937 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
938 |
|
checkCompletedWithWrappedCFException(f); |
939 |
|
assertEquals(1, r.invocationCount); |
983 |
|
final Noop r = new Noop(); |
984 |
|
if (!createIncomplete) f.complete(v1); |
985 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
986 |
< |
if (createIncomplete) f.complete(v1); |
986 |
> |
if (createIncomplete) { |
987 |
> |
checkIncomplete(g); |
988 |
> |
f.complete(v1); |
989 |
> |
} |
990 |
|
|
991 |
|
checkCompletedNormally(g, null); |
992 |
|
checkCompletedNormally(f, v1); |
1006 |
|
final Noop r = new Noop(); |
1007 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1008 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1009 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1009 |
> |
if (createIncomplete) { |
1010 |
> |
checkIncomplete(g); |
1011 |
> |
f.completeExceptionally(ex); |
1012 |
> |
} |
1013 |
|
|
1014 |
|
checkCompletedWithWrappedCFException(g, ex); |
1015 |
|
checkCompletedWithWrappedCFException(f, ex); |
1028 |
|
final Noop r = new Noop(); |
1029 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1030 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1031 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1031 |
> |
if (createIncomplete) { |
1032 |
> |
checkIncomplete(g); |
1033 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1034 |
> |
} |
1035 |
|
|
1036 |
|
checkCompletedWithWrappedCancellationException(g); |
1037 |
|
checkCancelled(f); |
1047 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1048 |
|
{ |
1049 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1050 |
< |
final FailingNoop r = new FailingNoop(); |
1050 |
> |
final FailingRunnable r = new FailingRunnable(); |
1051 |
|
if (!createIncomplete) f.complete(v1); |
1052 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1053 |
< |
if (createIncomplete) f.complete(v1); |
1053 |
> |
if (createIncomplete) { |
1054 |
> |
checkIncomplete(g); |
1055 |
> |
f.complete(v1); |
1056 |
> |
} |
1057 |
|
|
1058 |
|
checkCompletedWithWrappedCFException(g); |
1059 |
|
checkCompletedNormally(f, v1); |
1094 |
|
final IncFunction r = new IncFunction(); |
1095 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1096 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1097 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1097 |
> |
if (createIncomplete) { |
1098 |
> |
checkIncomplete(g); |
1099 |
> |
f.completeExceptionally(ex); |
1100 |
> |
} |
1101 |
|
|
1102 |
|
checkCompletedWithWrappedCFException(g, ex); |
1103 |
|
checkCompletedWithWrappedCFException(f, ex); |
1116 |
|
final IncFunction r = new IncFunction(); |
1117 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1118 |
|
final CompletableFuture<Integer> g = f.thenApply(r); |
1119 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1119 |
> |
if (createIncomplete) { |
1120 |
> |
checkIncomplete(g); |
1121 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1122 |
> |
} |
1123 |
|
|
1124 |
|
checkCompletedWithWrappedCancellationException(g); |
1125 |
|
checkCancelled(f); |
1138 |
|
final FailingFunction r = new FailingFunction(); |
1139 |
|
if (!createIncomplete) f.complete(v1); |
1140 |
|
final CompletableFuture<Integer> g = f.thenApply(r); |
1141 |
< |
if (createIncomplete) f.complete(v1); |
1141 |
> |
if (createIncomplete) { |
1142 |
> |
checkIncomplete(g); |
1143 |
> |
f.complete(v1); |
1144 |
> |
} |
1145 |
|
|
1146 |
|
checkCompletedWithWrappedCFException(g); |
1147 |
|
checkCompletedNormally(f, v1); |
1150 |
|
/** |
1151 |
|
* thenAccept result completes normally after normal completion of source |
1152 |
|
*/ |
1153 |
< |
public void testThenAccept() { |
1154 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1155 |
< |
IncAction r = new IncAction(); |
1156 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1157 |
< |
f.complete(one); |
1153 |
> |
public void testThenAccept_normalCompletion() { |
1154 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1155 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1156 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1157 |
> |
{ |
1158 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1159 |
> |
final IncAction r = new IncAction(); |
1160 |
> |
if (!createIncomplete) f.complete(v1); |
1161 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1162 |
> |
if (createIncomplete) { |
1163 |
> |
checkIncomplete(g); |
1164 |
> |
f.complete(v1); |
1165 |
> |
} |
1166 |
> |
|
1167 |
|
checkCompletedNormally(g, null); |
1168 |
< |
assertEquals(r.value, (Integer) 2); |
1169 |
< |
} |
1168 |
> |
checkCompletedNormally(f, v1); |
1169 |
> |
assertEquals(1, r.invocationCount); |
1170 |
> |
assertEquals(inc(v1), r.value); |
1171 |
> |
}} |
1172 |
|
|
1173 |
|
/** |
1174 |
|
* thenAccept result completes exceptionally after exceptional |
1175 |
|
* completion of source |
1176 |
|
*/ |
1177 |
< |
public void testThenAccept2() { |
1178 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1179 |
< |
IncAction r = new IncAction(); |
1180 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1181 |
< |
f.completeExceptionally(new CFException()); |
1182 |
< |
checkCompletedWithWrappedCFException(g); |
1183 |
< |
} |
1177 |
> |
public void testThenAccept_exceptionalCompletion() { |
1178 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1179 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1180 |
> |
{ |
1181 |
> |
final CFException ex = new CFException(); |
1182 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1183 |
> |
final IncAction r = new IncAction(); |
1184 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1185 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1186 |
> |
if (createIncomplete) { |
1187 |
> |
checkIncomplete(g); |
1188 |
> |
f.completeExceptionally(ex); |
1189 |
> |
} |
1190 |
> |
|
1191 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1192 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1193 |
> |
assertEquals(0, r.invocationCount); |
1194 |
> |
}} |
1195 |
|
|
1196 |
|
/** |
1197 |
|
* thenAccept result completes exceptionally if action does |
1198 |
|
*/ |
1199 |
< |
public void testThenAccept3() { |
1200 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1201 |
< |
FailingConsumer r = new FailingConsumer(); |
1202 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1203 |
< |
f.complete(one); |
1199 |
> |
public void testThenAccept_actionFailed() { |
1200 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1201 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1202 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1203 |
> |
{ |
1204 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1205 |
> |
final FailingConsumer r = new FailingConsumer(); |
1206 |
> |
if (!createIncomplete) f.complete(v1); |
1207 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1208 |
> |
if (createIncomplete) { |
1209 |
> |
checkIncomplete(g); |
1210 |
> |
f.complete(v1); |
1211 |
> |
} |
1212 |
> |
|
1213 |
|
checkCompletedWithWrappedCFException(g); |
1214 |
< |
assertEquals(1, r.invocationCount); |
1215 |
< |
} |
1214 |
> |
checkCompletedNormally(f, v1); |
1215 |
> |
}} |
1216 |
|
|
1217 |
|
/** |
1218 |
|
* thenAccept result completes exceptionally if source cancelled |
1219 |
|
*/ |
1220 |
< |
public void testThenAccept4() { |
1221 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1222 |
< |
IncAction r = new IncAction(); |
1223 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1224 |
< |
assertTrue(f.cancel(true)); |
1220 |
> |
public void testThenAccept_sourceCancelled() { |
1221 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1222 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1223 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1224 |
> |
{ |
1225 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1226 |
> |
final IncAction r = new IncAction(); |
1227 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1228 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1229 |
> |
if (createIncomplete) { |
1230 |
> |
checkIncomplete(g); |
1231 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1232 |
> |
} |
1233 |
> |
|
1234 |
|
checkCompletedWithWrappedCancellationException(g); |
1235 |
< |
} |
1235 |
> |
checkCancelled(f); |
1236 |
> |
assertEquals(0, r.invocationCount); |
1237 |
> |
}} |
1238 |
|
|
1239 |
|
/** |
1240 |
|
* thenCombine result completes normally after normal completion |
1241 |
|
* of sources |
1242 |
|
*/ |
1243 |
< |
public void testThenCombine_normalCompletion1() { |
1243 |
> |
public void testThenCombine_normalCompletion() { |
1244 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1245 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
1246 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1183 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1247 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1248 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1249 |
|
{ |
1250 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1251 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1252 |
|
final SubtractFunction r = new SubtractFunction(); |
1190 |
– |
CompletableFuture<Integer> h = null; |
1191 |
– |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1253 |
|
|
1254 |
< |
if (fFirst) |
1255 |
< |
f.complete(v1); |
1256 |
< |
else |
1257 |
< |
g.complete(v2); |
1258 |
< |
if (createIncomplete) checkIncomplete(h); |
1259 |
< |
assertEquals(0, r.invocationCount); |
1260 |
< |
if (!fFirst) |
1261 |
< |
f.complete(v1); |
1262 |
< |
else |
1202 |
< |
g.complete(v2); |
1203 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1254 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1255 |
> |
if (!createIncomplete) |
1256 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1257 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1258 |
> |
if (createIncomplete) { |
1259 |
> |
checkIncomplete(h); |
1260 |
> |
assertEquals(0, r.invocationCount); |
1261 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1262 |
> |
} |
1263 |
|
|
1264 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1265 |
|
checkCompletedNormally(f, v1); |
1271 |
|
* thenCombine result completes exceptionally after exceptional |
1272 |
|
* completion of either source |
1273 |
|
*/ |
1274 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1216 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1217 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1218 |
< |
{ |
1219 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1220 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1221 |
< |
final SubtractFunction r = new SubtractFunction(); |
1222 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1223 |
< |
final CFException ex = new CFException(); |
1224 |
< |
|
1225 |
< |
f.completeExceptionally(ex); |
1226 |
< |
checkIncomplete(h); |
1227 |
< |
g.complete(v1); |
1228 |
< |
|
1229 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1230 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1231 |
< |
assertEquals(0, r.invocationCount); |
1232 |
< |
checkCompletedNormally(g, v1); |
1233 |
< |
}} |
1234 |
< |
|
1235 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1236 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1237 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1238 |
< |
{ |
1239 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1240 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1241 |
< |
final SubtractFunction r = new SubtractFunction(); |
1242 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1243 |
< |
final CFException ex = new CFException(); |
1244 |
< |
|
1245 |
< |
g.completeExceptionally(ex); |
1246 |
< |
checkIncomplete(h); |
1247 |
< |
f.complete(v1); |
1248 |
< |
|
1249 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1250 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1251 |
< |
assertEquals(0, r.invocationCount); |
1252 |
< |
checkCompletedNormally(f, v1); |
1253 |
< |
}} |
1254 |
< |
|
1255 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1274 |
> |
public void testThenCombine_exceptionalCompletion() { |
1275 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1277 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1278 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1279 |
|
{ |
1280 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1281 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1261 |
– |
final SubtractFunction r = new SubtractFunction(); |
1282 |
|
final CFException ex = new CFException(); |
1263 |
– |
|
1264 |
– |
g.completeExceptionally(ex); |
1265 |
– |
f.complete(v1); |
1266 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1267 |
– |
|
1268 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1269 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1270 |
– |
assertEquals(0, r.invocationCount); |
1271 |
– |
checkCompletedNormally(f, v1); |
1272 |
– |
}} |
1273 |
– |
|
1274 |
– |
public void testThenCombine_exceptionalCompletion4() { |
1275 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1277 |
– |
{ |
1278 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1279 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1283 |
|
final SubtractFunction r = new SubtractFunction(); |
1281 |
– |
final CFException ex = new CFException(); |
1284 |
|
|
1285 |
< |
f.completeExceptionally(ex); |
1286 |
< |
g.complete(v1); |
1285 |
> |
(fFirst ? f : g).complete(v1); |
1286 |
> |
if (!createIncomplete) |
1287 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1288 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1289 |
+ |
if (createIncomplete) { |
1290 |
+ |
checkIncomplete(h); |
1291 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1292 |
+ |
} |
1293 |
|
|
1294 |
|
checkCompletedWithWrappedCFException(h, ex); |
1288 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1295 |
|
assertEquals(0, r.invocationCount); |
1296 |
< |
checkCompletedNormally(g, v1); |
1296 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1297 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1298 |
|
}} |
1299 |
|
|
1300 |
|
/** |
1301 |
|
* thenCombine result completes exceptionally if action does |
1302 |
|
*/ |
1303 |
< |
public void testThenCombine_actionFailed1() { |
1297 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1298 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1299 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1300 |
< |
{ |
1301 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1302 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1303 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1304 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1305 |
< |
|
1306 |
< |
f.complete(v1); |
1307 |
< |
checkIncomplete(h); |
1308 |
< |
g.complete(v2); |
1309 |
< |
|
1310 |
< |
checkCompletedWithWrappedCFException(h); |
1311 |
< |
checkCompletedNormally(f, v1); |
1312 |
< |
checkCompletedNormally(g, v2); |
1313 |
< |
}} |
1314 |
< |
|
1315 |
< |
public void testThenCombine_actionFailed2() { |
1303 |
> |
public void testThenCombine_actionFailed() { |
1304 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1305 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1306 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1307 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1308 |
|
{ |
1311 |
|
final FailingBiFunction r = new FailingBiFunction(); |
1312 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1313 |
|
|
1314 |
< |
g.complete(v2); |
1315 |
< |
checkIncomplete(h); |
1316 |
< |
f.complete(v1); |
1314 |
> |
if (fFirst) { |
1315 |
> |
f.complete(v1); |
1316 |
> |
g.complete(v2); |
1317 |
> |
} else { |
1318 |
> |
g.complete(v2); |
1319 |
> |
f.complete(v1); |
1320 |
> |
} |
1321 |
|
|
1322 |
|
checkCompletedWithWrappedCFException(h); |
1323 |
|
checkCompletedNormally(f, v1); |
1327 |
|
/** |
1328 |
|
* thenCombine result completes exceptionally if either source cancelled |
1329 |
|
*/ |
1330 |
< |
public void testThenCombine_sourceCancelled1() { |
1338 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1339 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1340 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1341 |
< |
{ |
1342 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1343 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1344 |
< |
final SubtractFunction r = new SubtractFunction(); |
1345 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1346 |
< |
|
1347 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1348 |
< |
checkIncomplete(h); |
1349 |
< |
g.complete(v1); |
1350 |
< |
|
1351 |
< |
checkCompletedWithWrappedCancellationException(h); |
1352 |
< |
checkCancelled(f); |
1353 |
< |
assertEquals(0, r.invocationCount); |
1354 |
< |
checkCompletedNormally(g, v1); |
1355 |
< |
}} |
1356 |
< |
|
1357 |
< |
public void testThenCombine_sourceCancelled2() { |
1358 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1359 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1360 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1361 |
< |
{ |
1362 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1363 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1364 |
< |
final SubtractFunction r = new SubtractFunction(); |
1365 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1366 |
< |
|
1367 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1368 |
< |
checkIncomplete(h); |
1369 |
< |
f.complete(v1); |
1370 |
< |
|
1371 |
< |
checkCompletedWithWrappedCancellationException(h); |
1372 |
< |
checkCancelled(g); |
1373 |
< |
assertEquals(0, r.invocationCount); |
1374 |
< |
checkCompletedNormally(f, v1); |
1375 |
< |
}} |
1376 |
< |
|
1377 |
< |
public void testThenCombine_sourceCancelled3() { |
1378 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1379 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1380 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1381 |
< |
{ |
1382 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1383 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1384 |
< |
final SubtractFunction r = new SubtractFunction(); |
1385 |
< |
|
1386 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1387 |
< |
f.complete(v1); |
1388 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1389 |
< |
|
1390 |
< |
checkCompletedWithWrappedCancellationException(h); |
1391 |
< |
checkCancelled(g); |
1392 |
< |
assertEquals(0, r.invocationCount); |
1393 |
< |
checkCompletedNormally(f, v1); |
1394 |
< |
}} |
1395 |
< |
|
1396 |
< |
public void testThenCombine_sourceCancelled4() { |
1330 |
> |
public void testThenCombine_sourceCancelled() { |
1331 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1332 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1333 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1334 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1335 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1336 |
|
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
|
|
1341 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1342 |
< |
g.complete(v1); |
1341 |
> |
(fFirst ? f : g).complete(v1); |
1342 |
> |
if (!createIncomplete) |
1343 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1344 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1345 |
+ |
if (createIncomplete) { |
1346 |
+ |
checkIncomplete(h); |
1347 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1348 |
+ |
} |
1349 |
|
|
1350 |
|
checkCompletedWithWrappedCancellationException(h); |
1351 |
< |
checkCancelled(f); |
1351 |
> |
checkCancelled(!fFirst ? f : g); |
1352 |
|
assertEquals(0, r.invocationCount); |
1353 |
< |
checkCompletedNormally(g, v1); |
1353 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1354 |
|
}} |
1355 |
|
|
1356 |
|
/** |
1357 |
|
* thenAcceptBoth result completes normally after normal |
1358 |
|
* completion of sources |
1359 |
|
*/ |
1360 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1420 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1421 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1422 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1423 |
< |
{ |
1424 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1425 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1426 |
< |
final SubtractAction r = new SubtractAction(); |
1427 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1428 |
< |
|
1429 |
< |
f.complete(v1); |
1430 |
< |
checkIncomplete(h); |
1431 |
< |
assertEquals(0, r.invocationCount); |
1432 |
< |
g.complete(v2); |
1433 |
< |
|
1434 |
< |
checkCompletedNormally(h, null); |
1435 |
< |
assertEquals(subtract(v1, v2), r.value); |
1436 |
< |
checkCompletedNormally(f, v1); |
1437 |
< |
checkCompletedNormally(g, v2); |
1438 |
< |
}} |
1439 |
< |
|
1440 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1441 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1442 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1443 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1444 |
< |
{ |
1445 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1446 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1447 |
< |
final SubtractAction r = new SubtractAction(); |
1448 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1449 |
< |
|
1450 |
< |
g.complete(v2); |
1451 |
< |
checkIncomplete(h); |
1452 |
< |
assertEquals(0, r.invocationCount); |
1453 |
< |
f.complete(v1); |
1454 |
< |
|
1455 |
< |
checkCompletedNormally(h, null); |
1456 |
< |
assertEquals(subtract(v1, v2), r.value); |
1457 |
< |
checkCompletedNormally(f, v1); |
1458 |
< |
checkCompletedNormally(g, v2); |
1459 |
< |
}} |
1460 |
< |
|
1461 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1462 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1463 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1464 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1465 |
< |
{ |
1466 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1467 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1468 |
< |
final SubtractAction r = new SubtractAction(); |
1469 |
< |
|
1470 |
< |
g.complete(v2); |
1471 |
< |
f.complete(v1); |
1472 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1473 |
< |
|
1474 |
< |
checkCompletedNormally(h, null); |
1475 |
< |
assertEquals(subtract(v1, v2), r.value); |
1476 |
< |
checkCompletedNormally(f, v1); |
1477 |
< |
checkCompletedNormally(g, v2); |
1478 |
< |
}} |
1479 |
< |
|
1480 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1360 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1361 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1362 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1363 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1364 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1365 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1366 |
|
{ |
1368 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1369 |
|
final SubtractAction r = new SubtractAction(); |
1370 |
|
|
1371 |
< |
f.complete(v1); |
1372 |
< |
g.complete(v2); |
1371 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1372 |
> |
if (!createIncomplete) |
1373 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1374 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1375 |
+ |
if (createIncomplete) { |
1376 |
+ |
checkIncomplete(h); |
1377 |
+ |
assertEquals(0, r.invocationCount); |
1378 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1379 |
+ |
} |
1380 |
|
|
1381 |
|
checkCompletedNormally(h, null); |
1382 |
|
assertEquals(subtract(v1, v2), r.value); |
1388 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1389 |
|
* completion of either source |
1390 |
|
*/ |
1391 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1504 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1505 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1506 |
< |
{ |
1507 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1508 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1509 |
< |
final SubtractAction r = new SubtractAction(); |
1510 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1511 |
< |
final CFException ex = new CFException(); |
1512 |
< |
|
1513 |
< |
f.completeExceptionally(ex); |
1514 |
< |
checkIncomplete(h); |
1515 |
< |
g.complete(v1); |
1516 |
< |
|
1517 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1518 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1519 |
< |
assertEquals(0, r.invocationCount); |
1520 |
< |
checkCompletedNormally(g, v1); |
1521 |
< |
}} |
1522 |
< |
|
1523 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1524 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1525 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1526 |
< |
{ |
1527 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1528 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1529 |
< |
final SubtractAction r = new SubtractAction(); |
1530 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1531 |
< |
final CFException ex = new CFException(); |
1532 |
< |
|
1533 |
< |
g.completeExceptionally(ex); |
1534 |
< |
checkIncomplete(h); |
1535 |
< |
f.complete(v1); |
1536 |
< |
|
1537 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1538 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1539 |
< |
assertEquals(0, r.invocationCount); |
1540 |
< |
checkCompletedNormally(f, v1); |
1541 |
< |
}} |
1542 |
< |
|
1543 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1391 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1392 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1393 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1394 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1395 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1396 |
|
{ |
1397 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1398 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1549 |
– |
final SubtractAction r = new SubtractAction(); |
1399 |
|
final CFException ex = new CFException(); |
1551 |
– |
|
1552 |
– |
g.completeExceptionally(ex); |
1553 |
– |
f.complete(v1); |
1554 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1555 |
– |
|
1556 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1557 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1558 |
– |
assertEquals(0, r.invocationCount); |
1559 |
– |
checkCompletedNormally(f, v1); |
1560 |
– |
}} |
1561 |
– |
|
1562 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1563 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1564 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1565 |
– |
{ |
1566 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1567 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1569 |
– |
final CFException ex = new CFException(); |
1401 |
|
|
1402 |
< |
f.completeExceptionally(ex); |
1403 |
< |
g.complete(v1); |
1402 |
> |
(fFirst ? f : g).complete(v1); |
1403 |
> |
if (!createIncomplete) |
1404 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1405 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1406 |
+ |
if (createIncomplete) { |
1407 |
+ |
checkIncomplete(h); |
1408 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1409 |
+ |
} |
1410 |
|
|
1411 |
|
checkCompletedWithWrappedCFException(h, ex); |
1576 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1412 |
|
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1413 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1414 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1415 |
|
}} |
1416 |
|
|
1417 |
|
/** |
1418 |
|
* thenAcceptBoth result completes exceptionally if action does |
1419 |
|
*/ |
1420 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1585 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1586 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1587 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1588 |
< |
{ |
1589 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1590 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1591 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1592 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1593 |
< |
|
1594 |
< |
f.complete(v1); |
1595 |
< |
checkIncomplete(h); |
1596 |
< |
g.complete(v2); |
1597 |
< |
|
1598 |
< |
checkCompletedWithWrappedCFException(h); |
1599 |
< |
checkCompletedNormally(f, v1); |
1600 |
< |
checkCompletedNormally(g, v2); |
1601 |
< |
}} |
1602 |
< |
|
1603 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1420 |
> |
public void testThenAcceptBoth_actionFailed() { |
1421 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1422 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1423 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1424 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1425 |
|
{ |
1428 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1429 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1430 |
|
|
1431 |
< |
g.complete(v2); |
1432 |
< |
checkIncomplete(h); |
1433 |
< |
f.complete(v1); |
1431 |
> |
if (fFirst) { |
1432 |
> |
f.complete(v1); |
1433 |
> |
g.complete(v2); |
1434 |
> |
} else { |
1435 |
> |
g.complete(v2); |
1436 |
> |
f.complete(v1); |
1437 |
> |
} |
1438 |
|
|
1439 |
|
checkCompletedWithWrappedCFException(h); |
1440 |
|
checkCompletedNormally(f, v1); |
1444 |
|
/** |
1445 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1446 |
|
*/ |
1447 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1626 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1627 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1628 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1629 |
< |
{ |
1630 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1631 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1632 |
< |
final SubtractAction r = new SubtractAction(); |
1633 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1634 |
< |
|
1635 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1636 |
< |
checkIncomplete(h); |
1637 |
< |
g.complete(v1); |
1638 |
< |
|
1639 |
< |
checkCompletedWithWrappedCancellationException(h); |
1640 |
< |
checkCancelled(f); |
1641 |
< |
assertEquals(0, r.invocationCount); |
1642 |
< |
checkCompletedNormally(g, v1); |
1643 |
< |
}} |
1644 |
< |
|
1645 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1646 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1647 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1648 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1649 |
< |
{ |
1650 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1651 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1652 |
< |
final SubtractAction r = new SubtractAction(); |
1653 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1654 |
< |
|
1655 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1656 |
< |
checkIncomplete(h); |
1657 |
< |
f.complete(v1); |
1658 |
< |
|
1659 |
< |
checkCompletedWithWrappedCancellationException(h); |
1660 |
< |
checkCancelled(g); |
1661 |
< |
assertEquals(0, r.invocationCount); |
1662 |
< |
checkCompletedNormally(f, v1); |
1663 |
< |
}} |
1664 |
< |
|
1665 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1666 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1667 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1668 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1669 |
< |
{ |
1670 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1671 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1672 |
< |
final SubtractAction r = new SubtractAction(); |
1673 |
< |
|
1674 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1675 |
< |
f.complete(v1); |
1676 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1677 |
< |
|
1678 |
< |
checkCompletedWithWrappedCancellationException(h); |
1679 |
< |
checkCancelled(g); |
1680 |
< |
assertEquals(0, r.invocationCount); |
1681 |
< |
checkCompletedNormally(f, v1); |
1682 |
< |
}} |
1683 |
< |
|
1684 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1447 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1448 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1449 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1450 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1451 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1452 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1453 |
|
{ |
1454 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1455 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1456 |
|
final SubtractAction r = new SubtractAction(); |
1457 |
|
|
1458 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1459 |
< |
g.complete(v1); |
1458 |
> |
(fFirst ? f : g).complete(v1); |
1459 |
> |
if (!createIncomplete) |
1460 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1461 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1462 |
+ |
if (createIncomplete) { |
1463 |
+ |
checkIncomplete(h); |
1464 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1465 |
+ |
} |
1466 |
|
|
1467 |
|
checkCompletedWithWrappedCancellationException(h); |
1468 |
< |
checkCancelled(f); |
1468 |
> |
checkCancelled(!fFirst ? f : g); |
1469 |
|
assertEquals(0, r.invocationCount); |
1470 |
< |
checkCompletedNormally(g, v1); |
1470 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1471 |
|
}} |
1472 |
|
|
1473 |
|
/** |
1474 |
|
* runAfterBoth result completes normally after normal |
1475 |
|
* completion of sources |
1476 |
|
*/ |
1477 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1708 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1709 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1710 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1711 |
< |
{ |
1712 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1713 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1714 |
< |
final Noop r = new Noop(); |
1715 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1716 |
< |
|
1717 |
< |
f.complete(v1); |
1718 |
< |
checkIncomplete(h); |
1719 |
< |
assertEquals(0, r.invocationCount); |
1720 |
< |
g.complete(v2); |
1721 |
< |
|
1722 |
< |
checkCompletedNormally(h, null); |
1723 |
< |
assertEquals(1, r.invocationCount); |
1724 |
< |
checkCompletedNormally(f, v1); |
1725 |
< |
checkCompletedNormally(g, v2); |
1726 |
< |
}} |
1727 |
< |
|
1728 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1729 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1730 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1731 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1732 |
< |
{ |
1733 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1734 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1735 |
< |
final Noop r = new Noop(); |
1736 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1737 |
< |
|
1738 |
< |
g.complete(v2); |
1739 |
< |
checkIncomplete(h); |
1740 |
< |
assertEquals(0, r.invocationCount); |
1741 |
< |
f.complete(v1); |
1742 |
< |
|
1743 |
< |
checkCompletedNormally(h, null); |
1744 |
< |
assertEquals(1, r.invocationCount); |
1745 |
< |
checkCompletedNormally(f, v1); |
1746 |
< |
checkCompletedNormally(g, v2); |
1747 |
< |
}} |
1748 |
< |
|
1749 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1750 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1751 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1752 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1753 |
< |
{ |
1754 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1755 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1756 |
< |
final Noop r = new Noop(); |
1757 |
< |
|
1758 |
< |
g.complete(v2); |
1759 |
< |
f.complete(v1); |
1760 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1761 |
< |
|
1762 |
< |
checkCompletedNormally(h, null); |
1763 |
< |
assertEquals(1, r.invocationCount); |
1764 |
< |
checkCompletedNormally(f, v1); |
1765 |
< |
checkCompletedNormally(g, v2); |
1766 |
< |
}} |
1767 |
< |
|
1768 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1477 |
> |
public void testRunAfterBoth_normalCompletion() { |
1478 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1479 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1480 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1481 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1482 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1483 |
|
{ |
1485 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1486 |
|
final Noop r = new Noop(); |
1487 |
|
|
1488 |
< |
f.complete(v1); |
1489 |
< |
g.complete(v2); |
1488 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1489 |
> |
if (!createIncomplete) |
1490 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1491 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1492 |
+ |
if (createIncomplete) { |
1493 |
+ |
checkIncomplete(h); |
1494 |
+ |
assertEquals(0, r.invocationCount); |
1495 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1496 |
+ |
} |
1497 |
|
|
1498 |
|
checkCompletedNormally(h, null); |
1499 |
|
assertEquals(1, r.invocationCount); |
1505 |
|
* runAfterBoth result completes exceptionally after exceptional |
1506 |
|
* completion of either source |
1507 |
|
*/ |
1508 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1792 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1793 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1794 |
< |
{ |
1795 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1796 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1797 |
< |
final Noop r = new Noop(); |
1798 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1799 |
< |
final CFException ex = new CFException(); |
1800 |
< |
|
1801 |
< |
f.completeExceptionally(ex); |
1802 |
< |
checkIncomplete(h); |
1803 |
< |
g.complete(v1); |
1804 |
< |
|
1805 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1806 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1807 |
< |
assertEquals(0, r.invocationCount); |
1808 |
< |
checkCompletedNormally(g, v1); |
1809 |
< |
}} |
1810 |
< |
|
1811 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1812 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1813 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1814 |
< |
{ |
1815 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1816 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1817 |
< |
final Noop r = new Noop(); |
1818 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1819 |
< |
final CFException ex = new CFException(); |
1820 |
< |
|
1821 |
< |
g.completeExceptionally(ex); |
1822 |
< |
checkIncomplete(h); |
1823 |
< |
f.complete(v1); |
1824 |
< |
|
1825 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1826 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1827 |
< |
assertEquals(0, r.invocationCount); |
1828 |
< |
checkCompletedNormally(f, v1); |
1829 |
< |
}} |
1830 |
< |
|
1831 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1508 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1509 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1510 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1511 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1512 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1513 |
|
{ |
1514 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1515 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1837 |
– |
final Noop r = new Noop(); |
1516 |
|
final CFException ex = new CFException(); |
1839 |
– |
|
1840 |
– |
g.completeExceptionally(ex); |
1841 |
– |
f.complete(v1); |
1842 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1843 |
– |
|
1844 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1845 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1846 |
– |
assertEquals(0, r.invocationCount); |
1847 |
– |
checkCompletedNormally(f, v1); |
1848 |
– |
}} |
1849 |
– |
|
1850 |
– |
public void testRunAfterBoth_exceptionalCompletion4() { |
1851 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1852 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1853 |
– |
{ |
1854 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1855 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1517 |
|
final Noop r = new Noop(); |
1857 |
– |
final CFException ex = new CFException(); |
1518 |
|
|
1519 |
< |
f.completeExceptionally(ex); |
1520 |
< |
g.complete(v1); |
1519 |
> |
(fFirst ? f : g).complete(v1); |
1520 |
> |
if (!createIncomplete) |
1521 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1522 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1523 |
+ |
if (createIncomplete) { |
1524 |
+ |
checkIncomplete(h); |
1525 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1526 |
+ |
} |
1527 |
|
|
1528 |
|
checkCompletedWithWrappedCFException(h, ex); |
1864 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1529 |
|
assertEquals(0, r.invocationCount); |
1530 |
< |
checkCompletedNormally(g, v1); |
1530 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1531 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1532 |
|
}} |
1533 |
|
|
1534 |
|
/** |
1535 |
|
* runAfterBoth result completes exceptionally if action does |
1536 |
|
*/ |
1537 |
< |
public void testRunAfterBoth_actionFailed1() { |
1873 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1874 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1875 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1876 |
< |
{ |
1877 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1878 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1879 |
< |
final FailingNoop r = new FailingNoop(); |
1880 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1881 |
< |
|
1882 |
< |
f.complete(v1); |
1883 |
< |
checkIncomplete(h); |
1884 |
< |
g.complete(v2); |
1885 |
< |
|
1886 |
< |
checkCompletedWithWrappedCFException(h); |
1887 |
< |
checkCompletedNormally(f, v1); |
1888 |
< |
checkCompletedNormally(g, v2); |
1889 |
< |
}} |
1890 |
< |
|
1891 |
< |
public void testRunAfterBoth_actionFailed2() { |
1537 |
> |
public void testRunAfterBoth_actionFailed() { |
1538 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1539 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1540 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1541 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1542 |
|
{ |
1543 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1544 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1545 |
< |
final FailingNoop r = new FailingNoop(); |
1899 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1545 |
> |
final FailingRunnable r = new FailingRunnable(); |
1546 |
|
|
1547 |
< |
g.complete(v2); |
1548 |
< |
checkIncomplete(h); |
1549 |
< |
f.complete(v1); |
1547 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1548 |
> |
if (fFirst) { |
1549 |
> |
f.complete(v1); |
1550 |
> |
g.complete(v2); |
1551 |
> |
} else { |
1552 |
> |
g.complete(v2); |
1553 |
> |
f.complete(v1); |
1554 |
> |
} |
1555 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1556 |
|
|
1557 |
< |
checkCompletedWithWrappedCFException(h); |
1557 |
> |
checkCompletedWithWrappedCFException(h1); |
1558 |
> |
checkCompletedWithWrappedCFException(h2); |
1559 |
|
checkCompletedNormally(f, v1); |
1560 |
|
checkCompletedNormally(g, v2); |
1561 |
|
}} |
1563 |
|
/** |
1564 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1565 |
|
*/ |
1566 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1914 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1915 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1916 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1917 |
< |
{ |
1918 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1919 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1920 |
< |
final Noop r = new Noop(); |
1921 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1922 |
< |
|
1923 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1924 |
< |
checkIncomplete(h); |
1925 |
< |
g.complete(v1); |
1926 |
< |
|
1927 |
< |
checkCompletedWithWrappedCancellationException(h); |
1928 |
< |
checkCancelled(f); |
1929 |
< |
assertEquals(0, r.invocationCount); |
1930 |
< |
checkCompletedNormally(g, v1); |
1931 |
< |
}} |
1932 |
< |
|
1933 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1566 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1567 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1568 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1569 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1570 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1571 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1572 |
|
{ |
1573 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1574 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1575 |
|
final Noop r = new Noop(); |
1941 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1942 |
– |
|
1943 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1944 |
– |
checkIncomplete(h); |
1945 |
– |
f.complete(v1); |
1946 |
– |
|
1947 |
– |
checkCompletedWithWrappedCancellationException(h); |
1948 |
– |
checkCancelled(g); |
1949 |
– |
assertEquals(0, r.invocationCount); |
1950 |
– |
checkCompletedNormally(f, v1); |
1951 |
– |
}} |
1576 |
|
|
1953 |
– |
public void testRunAfterBoth_sourceCancelled3() { |
1954 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1955 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1956 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1957 |
– |
{ |
1958 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1959 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1960 |
– |
final Noop r = new Noop(); |
1577 |
|
|
1578 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1579 |
< |
f.complete(v1); |
1580 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1965 |
< |
|
1966 |
< |
checkCompletedWithWrappedCancellationException(h); |
1967 |
< |
checkCancelled(g); |
1968 |
< |
assertEquals(0, r.invocationCount); |
1969 |
< |
checkCompletedNormally(f, v1); |
1970 |
< |
}} |
1971 |
< |
|
1972 |
< |
public void testRunAfterBoth_sourceCancelled4() { |
1973 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1974 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1975 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1976 |
< |
{ |
1977 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1978 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1979 |
< |
final Noop r = new Noop(); |
1980 |
< |
|
1981 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1982 |
< |
g.complete(v1); |
1578 |
> |
(fFirst ? f : g).complete(v1); |
1579 |
> |
if (!createIncomplete) |
1580 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1581 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1582 |
+ |
if (createIncomplete) { |
1583 |
+ |
checkIncomplete(h); |
1584 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1585 |
+ |
} |
1586 |
|
|
1587 |
|
checkCompletedWithWrappedCancellationException(h); |
1588 |
< |
checkCancelled(f); |
1588 |
> |
checkCancelled(!fFirst ? f : g); |
1589 |
|
assertEquals(0, r.invocationCount); |
1590 |
< |
checkCompletedNormally(g, v1); |
1590 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1591 |
|
}} |
1592 |
|
|
1593 |
|
/** |
1594 |
|
* applyToEither result completes normally after normal completion |
1595 |
|
* of either source |
1596 |
|
*/ |
1597 |
< |
public void testApplyToEither_normalCompletion1() { |
1597 |
> |
public void testApplyToEither_normalCompletion() { |
1598 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1599 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1600 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1601 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1602 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1603 |
|
{ |
1604 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1605 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1606 |
|
final IncFunction r = new IncFunction(); |
2003 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1607 |
|
|
1608 |
< |
f.complete(v1); |
1609 |
< |
checkCompletedNormally(h, inc(v1)); |
1610 |
< |
g.complete(v2); |
1608 |
> |
if (!createIncomplete) |
1609 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1610 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1611 |
> |
if (createIncomplete) { |
1612 |
> |
checkIncomplete(h); |
1613 |
> |
assertEquals(0, r.invocationCount); |
1614 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1615 |
> |
} |
1616 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1617 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1618 |
|
|
1619 |
|
checkCompletedNormally(f, v1); |
1620 |
|
checkCompletedNormally(g, v2); |
1621 |
< |
checkCompletedNormally(h, inc(v1)); |
1621 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1622 |
|
}} |
1623 |
|
|
1624 |
< |
public void testApplyToEither_normalCompletion2() { |
1624 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1625 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1626 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1627 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1628 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1629 |
|
{ |
1630 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1631 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1632 |
|
final IncFunction r = new IncFunction(); |
2022 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2023 |
– |
|
2024 |
– |
g.complete(v2); |
2025 |
– |
checkCompletedNormally(h, inc(v2)); |
2026 |
– |
f.complete(v1); |
2027 |
– |
|
2028 |
– |
checkCompletedNormally(f, v1); |
2029 |
– |
checkCompletedNormally(g, v2); |
2030 |
– |
checkCompletedNormally(h, inc(v2)); |
2031 |
– |
}} |
1633 |
|
|
1634 |
< |
public void testApplyToEither_normalCompletion3() { |
1635 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1636 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1637 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1638 |
< |
{ |
1639 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1640 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2040 |
< |
final IncFunction r = new IncFunction(); |
1634 |
> |
if (fFirst) { |
1635 |
> |
f.complete(v1); |
1636 |
> |
g.complete(v2); |
1637 |
> |
} else { |
1638 |
> |
g.complete(v2); |
1639 |
> |
f.complete(v1); |
1640 |
> |
} |
1641 |
|
|
2042 |
– |
f.complete(v1); |
2043 |
– |
g.complete(v2); |
1642 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1643 |
|
|
1644 |
|
checkCompletedNormally(f, v1); |
1656 |
|
*/ |
1657 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1658 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1659 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1660 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1661 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1662 |
|
{ |
1663 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1664 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2065 |
– |
final IncFunction r = new IncFunction(); |
2066 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1665 |
|
final CFException ex = new CFException(); |
2068 |
– |
|
2069 |
– |
f.completeExceptionally(ex); |
2070 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2071 |
– |
g.complete(v1); |
2072 |
– |
|
2073 |
– |
assertEquals(0, r.invocationCount); |
2074 |
– |
checkCompletedNormally(g, v1); |
2075 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2076 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2077 |
– |
}} |
2078 |
– |
|
2079 |
– |
public void testApplyToEither_exceptionalCompletion2() { |
2080 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2081 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2082 |
– |
{ |
2083 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2084 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1666 |
|
final IncFunction r = new IncFunction(); |
1667 |
+ |
|
1668 |
+ |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1669 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1670 |
< |
final CFException ex = new CFException(); |
1670 |
> |
if (createIncomplete) { |
1671 |
> |
checkIncomplete(h); |
1672 |
> |
assertEquals(0, r.invocationCount); |
1673 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1674 |
> |
} |
1675 |
|
|
2089 |
– |
g.completeExceptionally(ex); |
1676 |
|
checkCompletedWithWrappedCFException(h, ex); |
1677 |
< |
f.complete(v1); |
1677 |
> |
(!fFirst ? f : g).complete(v1); |
1678 |
|
|
1679 |
|
assertEquals(0, r.invocationCount); |
1680 |
< |
checkCompletedNormally(f, v1); |
1681 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1680 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1681 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1682 |
|
checkCompletedWithWrappedCFException(h, ex); |
1683 |
|
}} |
1684 |
|
|
1685 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1685 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1686 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1687 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1688 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1689 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1690 |
|
{ |
1691 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1692 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1693 |
< |
final IncFunction r = new IncFunction(); |
1693 |
> |
final IncFunction r1 = new IncFunction(); |
1694 |
> |
final IncFunction r2 = new IncFunction(); |
1695 |
|
final CFException ex = new CFException(); |
1696 |
< |
|
1697 |
< |
g.completeExceptionally(ex); |
1698 |
< |
f.complete(v1); |
1699 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1696 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1697 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1698 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1699 |
> |
if (fFirst) { |
1700 |
> |
f.complete(v1); |
1701 |
> |
g.completeExceptionally(ex); |
1702 |
> |
} else { |
1703 |
> |
g.completeExceptionally(ex); |
1704 |
> |
f.complete(v1); |
1705 |
> |
} |
1706 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1707 |
|
|
1708 |
|
// unspecified behavior |
2113 |
– |
Integer v; |
1709 |
|
try { |
1710 |
< |
assertEquals(inc(v1), h.join()); |
1711 |
< |
assertEquals(1, r.invocationCount); |
1710 |
> |
assertEquals(inc(v1), h1.join()); |
1711 |
> |
assertEquals(1, r1.invocationCount); |
1712 |
|
} catch (CompletionException ok) { |
1713 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1714 |
< |
assertEquals(0, r.invocationCount); |
1713 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1714 |
> |
assertEquals(0, r1.invocationCount); |
1715 |
|
} |
1716 |
|
|
2122 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2123 |
– |
checkCompletedNormally(f, v1); |
2124 |
– |
}} |
2125 |
– |
|
2126 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2127 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2128 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2129 |
– |
{ |
2130 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2131 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2132 |
– |
final IncFunction r = new IncFunction(); |
2133 |
– |
final CFException ex = new CFException(); |
2134 |
– |
|
2135 |
– |
f.completeExceptionally(ex); |
2136 |
– |
g.complete(v1); |
2137 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2138 |
– |
|
2139 |
– |
// unspecified behavior |
2140 |
– |
Integer v; |
1717 |
|
try { |
1718 |
< |
assertEquals(inc(v1), h.join()); |
1719 |
< |
assertEquals(1, r.invocationCount); |
1718 |
> |
assertEquals(inc(v1), h2.join()); |
1719 |
> |
assertEquals(1, r2.invocationCount); |
1720 |
|
} catch (CompletionException ok) { |
1721 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1722 |
< |
assertEquals(0, r.invocationCount); |
1721 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1722 |
> |
assertEquals(0, r2.invocationCount); |
1723 |
|
} |
1724 |
|
|
1725 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1726 |
< |
checkCompletedNormally(g, v1); |
1725 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1726 |
> |
checkCompletedNormally(f, v1); |
1727 |
|
}} |
1728 |
|
|
1729 |
|
/** |
1769 |
|
public void testApplyToEither_sourceCancelled1() { |
1770 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1771 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1772 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1773 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1774 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1775 |
|
{ |
1776 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1777 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1778 |
|
final IncFunction r = new IncFunction(); |
2201 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2202 |
– |
|
2203 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2204 |
– |
checkCompletedWithWrappedCancellationException(h); |
2205 |
– |
g.complete(v1); |
2206 |
– |
|
2207 |
– |
checkCancelled(f); |
2208 |
– |
assertEquals(0, r.invocationCount); |
2209 |
– |
checkCompletedNormally(g, v1); |
2210 |
– |
checkCompletedWithWrappedCancellationException(h); |
2211 |
– |
}} |
1779 |
|
|
1780 |
< |
public void testApplyToEither_sourceCancelled2() { |
2214 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2215 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2216 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2217 |
< |
{ |
2218 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2219 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2220 |
< |
final IncFunction r = new IncFunction(); |
1780 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1781 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1782 |
+ |
if (createIncomplete) { |
1783 |
+ |
checkIncomplete(h); |
1784 |
+ |
assertEquals(0, r.invocationCount); |
1785 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1786 |
+ |
} |
1787 |
|
|
2223 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1788 |
|
checkCompletedWithWrappedCancellationException(h); |
1789 |
< |
f.complete(v1); |
1789 |
> |
(!fFirst ? f : g).complete(v1); |
1790 |
|
|
2227 |
– |
checkCancelled(g); |
1791 |
|
assertEquals(0, r.invocationCount); |
1792 |
< |
checkCompletedNormally(f, v1); |
1792 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1793 |
> |
checkCancelled(fFirst ? f : g); |
1794 |
|
checkCompletedWithWrappedCancellationException(h); |
1795 |
|
}} |
1796 |
|
|
1797 |
< |
public void testApplyToEither_sourceCancelled3() { |
1797 |
> |
public void testApplyToEither_sourceCancelled2() { |
1798 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1799 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1800 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1801 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1802 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1803 |
|
{ |
1804 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1805 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1806 |
< |
final IncFunction r = new IncFunction(); |
1806 |
> |
final IncFunction r1 = new IncFunction(); |
1807 |
> |
final IncFunction r2 = new IncFunction(); |
1808 |
> |
final CFException ex = new CFException(); |
1809 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1810 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1811 |
|
|
1812 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1813 |
< |
f.complete(v1); |
1814 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1812 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1813 |
> |
if (fFirst) { |
1814 |
> |
f.complete(v1); |
1815 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1816 |
> |
} else { |
1817 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1818 |
> |
f.complete(v1); |
1819 |
> |
} |
1820 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1821 |
|
|
1822 |
|
// unspecified behavior |
2247 |
– |
Integer v; |
1823 |
|
try { |
1824 |
< |
assertEquals(inc(v1), h.join()); |
1825 |
< |
assertEquals(1, r.invocationCount); |
1824 |
> |
assertEquals(inc(v1), h1.join()); |
1825 |
> |
assertEquals(1, r1.invocationCount); |
1826 |
|
} catch (CompletionException ok) { |
1827 |
< |
checkCompletedWithWrappedCancellationException(h); |
1828 |
< |
assertEquals(0, r.invocationCount); |
1827 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1828 |
> |
assertEquals(0, r1.invocationCount); |
1829 |
|
} |
1830 |
|
|
2256 |
– |
checkCancelled(g); |
2257 |
– |
checkCompletedNormally(f, v1); |
2258 |
– |
}} |
2259 |
– |
|
2260 |
– |
public void testApplyToEither_sourceCancelled4() { |
2261 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2262 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2263 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2264 |
– |
{ |
2265 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2266 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2267 |
– |
final IncFunction r = new IncFunction(); |
2268 |
– |
|
2269 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2270 |
– |
g.complete(v1); |
2271 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2272 |
– |
|
2273 |
– |
// unspecified behavior |
2274 |
– |
Integer v; |
1831 |
|
try { |
1832 |
< |
assertEquals(inc(v1), h.join()); |
1833 |
< |
assertEquals(1, r.invocationCount); |
1832 |
> |
assertEquals(inc(v1), h2.join()); |
1833 |
> |
assertEquals(1, r2.invocationCount); |
1834 |
|
} catch (CompletionException ok) { |
1835 |
< |
checkCompletedWithWrappedCancellationException(h); |
1836 |
< |
assertEquals(0, r.invocationCount); |
1835 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1836 |
> |
assertEquals(0, r2.invocationCount); |
1837 |
|
} |
1838 |
|
|
1839 |
< |
checkCancelled(f); |
1840 |
< |
checkCompletedNormally(g, v1); |
1839 |
> |
checkCancelled(g); |
1840 |
> |
checkCompletedNormally(f, v1); |
1841 |
|
}} |
1842 |
|
|
1843 |
|
/** |
2315 |
|
{ |
2316 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2317 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2318 |
< |
final FailingNoop r = new FailingNoop(); |
2318 |
> |
final FailingRunnable r = new FailingRunnable(); |
2319 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2320 |
|
|
2321 |
|
f.complete(v1); |
2332 |
|
{ |
2333 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2334 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2335 |
< |
final FailingNoop r = new FailingNoop(); |
2335 |
> |
final FailingRunnable r = new FailingRunnable(); |
2336 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2337 |
|
|
2338 |
|
g.complete(v2); |
2509 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2510 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2511 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2512 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2512 |
> |
if (createIncomplete) { |
2513 |
> |
checkIncomplete(g); |
2514 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2515 |
> |
} |
2516 |
|
|
2517 |
|
checkCompletedWithWrappedCancellationException(g); |
2518 |
|
checkCancelled(f); |
2519 |
|
}} |
2520 |
|
|
2962 |
– |
// asyncs |
2963 |
– |
|
2964 |
– |
/** |
2965 |
– |
* thenAcceptAsync result completes normally after normal |
2966 |
– |
* completion of source |
2967 |
– |
*/ |
2968 |
– |
public void testThenAcceptAsync() { |
2969 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2970 |
– |
IncAction r = new IncAction(); |
2971 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2972 |
– |
f.complete(one); |
2973 |
– |
checkCompletedNormally(g, null); |
2974 |
– |
assertEquals(r.value, (Integer) 2); |
2975 |
– |
} |
2976 |
– |
|
2977 |
– |
/** |
2978 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
2979 |
– |
* completion of source |
2980 |
– |
*/ |
2981 |
– |
public void testThenAcceptAsync2() { |
2982 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2983 |
– |
IncAction r = new IncAction(); |
2984 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2985 |
– |
f.completeExceptionally(new CFException()); |
2986 |
– |
checkCompletedWithWrappedCFException(g); |
2987 |
– |
} |
2988 |
– |
|
2989 |
– |
/** |
2990 |
– |
* thenAcceptAsync result completes exceptionally if action does |
2991 |
– |
*/ |
2992 |
– |
public void testThenAcceptAsync3() { |
2993 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2994 |
– |
FailingConsumer r = new FailingConsumer(); |
2995 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2996 |
– |
f.complete(null); |
2997 |
– |
checkCompletedWithWrappedCFException(g); |
2998 |
– |
} |
2999 |
– |
|
3000 |
– |
/** |
3001 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3002 |
– |
*/ |
3003 |
– |
public void testThenAcceptAsync4() { |
3004 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3005 |
– |
IncAction r = new IncAction(); |
3006 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3007 |
– |
assertTrue(f.cancel(true)); |
3008 |
– |
checkCompletedWithWrappedCancellationException(g); |
3009 |
– |
} |
3010 |
– |
|
3011 |
– |
// async with explicit executors |
3012 |
– |
|
3013 |
– |
/** |
3014 |
– |
* thenAcceptAsync result completes normally after normal |
3015 |
– |
* completion of source |
3016 |
– |
*/ |
3017 |
– |
public void testThenAcceptAsyncE() { |
3018 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3019 |
– |
IncAction r = new IncAction(); |
3020 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3021 |
– |
f.complete(one); |
3022 |
– |
checkCompletedNormally(g, null); |
3023 |
– |
assertEquals(r.value, (Integer) 2); |
3024 |
– |
} |
3025 |
– |
|
3026 |
– |
/** |
3027 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3028 |
– |
* completion of source |
3029 |
– |
*/ |
3030 |
– |
public void testThenAcceptAsync2E() { |
3031 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3032 |
– |
IncAction r = new IncAction(); |
3033 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3034 |
– |
f.completeExceptionally(new CFException()); |
3035 |
– |
checkCompletedWithWrappedCFException(g); |
3036 |
– |
} |
3037 |
– |
|
3038 |
– |
/** |
3039 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3040 |
– |
*/ |
3041 |
– |
public void testThenAcceptAsync3E() { |
3042 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3043 |
– |
FailingConsumer r = new FailingConsumer(); |
3044 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3045 |
– |
f.complete(null); |
3046 |
– |
checkCompletedWithWrappedCFException(g); |
3047 |
– |
} |
3048 |
– |
|
3049 |
– |
/** |
3050 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3051 |
– |
*/ |
3052 |
– |
public void testThenAcceptAsync4E() { |
3053 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3054 |
– |
IncAction r = new IncAction(); |
3055 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3056 |
– |
assertTrue(f.cancel(true)); |
3057 |
– |
checkCompletedWithWrappedCancellationException(g); |
3058 |
– |
} |
3059 |
– |
|
2521 |
|
// other static methods |
2522 |
|
|
2523 |
|
/** |