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); |
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); |
1159 |
|
final IncAction r = new IncAction(); |
1160 |
|
if (!createIncomplete) f.complete(v1); |
1161 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1162 |
< |
if (createIncomplete) f.complete(v1); |
1162 |
> |
if (createIncomplete) { |
1163 |
> |
checkIncomplete(g); |
1164 |
> |
f.complete(v1); |
1165 |
> |
} |
1166 |
|
|
1167 |
|
checkCompletedNormally(g, null); |
1168 |
|
checkCompletedNormally(f, v1); |
1183 |
|
final IncAction r = new IncAction(); |
1184 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1185 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1186 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1186 |
> |
if (createIncomplete) { |
1187 |
> |
checkIncomplete(g); |
1188 |
> |
f.completeExceptionally(ex); |
1189 |
> |
} |
1190 |
|
|
1191 |
|
checkCompletedWithWrappedCFException(g, ex); |
1192 |
|
checkCompletedWithWrappedCFException(f, ex); |
1205 |
|
final FailingConsumer r = new FailingConsumer(); |
1206 |
|
if (!createIncomplete) f.complete(v1); |
1207 |
|
final CompletableFuture<Void> g = f.thenAccept(r); |
1208 |
< |
if (createIncomplete) f.complete(v1); |
1208 |
> |
if (createIncomplete) { |
1209 |
> |
checkIncomplete(g); |
1210 |
> |
f.complete(v1); |
1211 |
> |
} |
1212 |
|
|
1213 |
|
checkCompletedWithWrappedCFException(g); |
1214 |
|
checkCompletedNormally(f, v1); |
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 }) |
1216 |
– |
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(); |
1223 |
– |
CompletableFuture<Integer> h = null; |
1224 |
– |
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 |
1235 |
< |
g.complete(v2); |
1236 |
< |
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() { |
1249 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1250 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1251 |
< |
{ |
1252 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1253 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1254 |
< |
final SubtractFunction r = new SubtractFunction(); |
1255 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1256 |
< |
final CFException ex = new CFException(); |
1257 |
< |
|
1258 |
< |
f.completeExceptionally(ex); |
1259 |
< |
checkIncomplete(h); |
1260 |
< |
g.complete(v1); |
1261 |
< |
|
1262 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1263 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1264 |
< |
assertEquals(0, r.invocationCount); |
1265 |
< |
checkCompletedNormally(g, v1); |
1266 |
< |
}} |
1267 |
< |
|
1268 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1269 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1270 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1271 |
< |
{ |
1272 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1273 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1274 |
< |
final SubtractFunction r = new SubtractFunction(); |
1275 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1276 |
< |
final CFException ex = new CFException(); |
1277 |
< |
|
1278 |
< |
g.completeExceptionally(ex); |
1279 |
< |
checkIncomplete(h); |
1280 |
< |
f.complete(v1); |
1281 |
< |
|
1282 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1283 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1284 |
< |
assertEquals(0, r.invocationCount); |
1285 |
< |
checkCompletedNormally(f, v1); |
1286 |
< |
}} |
1287 |
< |
|
1288 |
< |
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<>(); |
1294 |
– |
final SubtractFunction r = new SubtractFunction(); |
1282 |
|
final CFException ex = new CFException(); |
1296 |
– |
|
1297 |
– |
g.completeExceptionally(ex); |
1298 |
– |
f.complete(v1); |
1299 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1300 |
– |
|
1301 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1302 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1303 |
– |
assertEquals(0, r.invocationCount); |
1304 |
– |
checkCompletedNormally(f, v1); |
1305 |
– |
}} |
1306 |
– |
|
1307 |
– |
public void testThenCombine_exceptionalCompletion4() { |
1308 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1309 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1310 |
– |
{ |
1311 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1312 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1283 |
|
final SubtractFunction r = new SubtractFunction(); |
1314 |
– |
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); |
1321 |
– |
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() { |
1330 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1331 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1332 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1333 |
< |
{ |
1334 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1335 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1336 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1337 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1338 |
< |
|
1339 |
< |
f.complete(v1); |
1340 |
< |
checkIncomplete(h); |
1341 |
< |
g.complete(v2); |
1342 |
< |
|
1343 |
< |
checkCompletedWithWrappedCFException(h); |
1344 |
< |
checkCompletedNormally(f, v1); |
1345 |
< |
checkCompletedNormally(g, v2); |
1346 |
< |
}} |
1347 |
< |
|
1348 |
< |
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() { |
1371 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1372 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1373 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1374 |
< |
{ |
1375 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1376 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1377 |
< |
final SubtractFunction r = new SubtractFunction(); |
1378 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1379 |
< |
|
1380 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1381 |
< |
checkIncomplete(h); |
1382 |
< |
g.complete(v1); |
1383 |
< |
|
1384 |
< |
checkCompletedWithWrappedCancellationException(h); |
1385 |
< |
checkCancelled(f); |
1386 |
< |
assertEquals(0, r.invocationCount); |
1387 |
< |
checkCompletedNormally(g, v1); |
1388 |
< |
}} |
1389 |
< |
|
1390 |
< |
public void testThenCombine_sourceCancelled2() { |
1391 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1392 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1393 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1394 |
< |
{ |
1395 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1396 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1397 |
< |
final SubtractFunction r = new SubtractFunction(); |
1398 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1399 |
< |
|
1400 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1401 |
< |
checkIncomplete(h); |
1402 |
< |
f.complete(v1); |
1403 |
< |
|
1404 |
< |
checkCompletedWithWrappedCancellationException(h); |
1405 |
< |
checkCancelled(g); |
1406 |
< |
assertEquals(0, r.invocationCount); |
1407 |
< |
checkCompletedNormally(f, v1); |
1408 |
< |
}} |
1409 |
< |
|
1410 |
< |
public void testThenCombine_sourceCancelled3() { |
1411 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1412 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1413 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1414 |
< |
{ |
1415 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1416 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1417 |
< |
final SubtractFunction r = new SubtractFunction(); |
1418 |
< |
|
1419 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1420 |
< |
f.complete(v1); |
1421 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1422 |
< |
|
1423 |
< |
checkCompletedWithWrappedCancellationException(h); |
1424 |
< |
checkCancelled(g); |
1425 |
< |
assertEquals(0, r.invocationCount); |
1426 |
< |
checkCompletedNormally(f, v1); |
1427 |
< |
}} |
1428 |
< |
|
1429 |
< |
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() { |
1453 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1454 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1455 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1456 |
< |
{ |
1457 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1458 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1459 |
< |
final SubtractAction r = new SubtractAction(); |
1460 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1461 |
< |
|
1462 |
< |
f.complete(v1); |
1463 |
< |
checkIncomplete(h); |
1464 |
< |
assertEquals(0, r.invocationCount); |
1465 |
< |
g.complete(v2); |
1466 |
< |
|
1467 |
< |
checkCompletedNormally(h, null); |
1468 |
< |
assertEquals(subtract(v1, v2), r.value); |
1469 |
< |
checkCompletedNormally(f, v1); |
1470 |
< |
checkCompletedNormally(g, v2); |
1471 |
< |
}} |
1472 |
< |
|
1473 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1474 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1475 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1476 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1477 |
< |
{ |
1478 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1479 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1480 |
< |
final SubtractAction r = new SubtractAction(); |
1481 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1482 |
< |
|
1483 |
< |
g.complete(v2); |
1484 |
< |
checkIncomplete(h); |
1485 |
< |
assertEquals(0, r.invocationCount); |
1486 |
< |
f.complete(v1); |
1487 |
< |
|
1488 |
< |
checkCompletedNormally(h, null); |
1489 |
< |
assertEquals(subtract(v1, v2), r.value); |
1490 |
< |
checkCompletedNormally(f, v1); |
1491 |
< |
checkCompletedNormally(g, v2); |
1492 |
< |
}} |
1493 |
< |
|
1494 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1495 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1496 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1497 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1498 |
< |
{ |
1499 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1500 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1501 |
< |
final SubtractAction r = new SubtractAction(); |
1502 |
< |
|
1503 |
< |
g.complete(v2); |
1504 |
< |
f.complete(v1); |
1505 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1506 |
< |
|
1507 |
< |
checkCompletedNormally(h, null); |
1508 |
< |
assertEquals(subtract(v1, v2), r.value); |
1509 |
< |
checkCompletedNormally(f, v1); |
1510 |
< |
checkCompletedNormally(g, v2); |
1511 |
< |
}} |
1512 |
< |
|
1513 |
< |
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() { |
1537 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1538 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1539 |
< |
{ |
1540 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1541 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1542 |
< |
final SubtractAction r = new SubtractAction(); |
1543 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1544 |
< |
final CFException ex = new CFException(); |
1545 |
< |
|
1546 |
< |
f.completeExceptionally(ex); |
1547 |
< |
checkIncomplete(h); |
1548 |
< |
g.complete(v1); |
1549 |
< |
|
1550 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1551 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1552 |
< |
assertEquals(0, r.invocationCount); |
1553 |
< |
checkCompletedNormally(g, v1); |
1554 |
< |
}} |
1555 |
< |
|
1556 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
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<>(); |
1562 |
– |
final SubtractAction r = new SubtractAction(); |
1563 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1399 |
|
final CFException ex = new CFException(); |
1565 |
– |
|
1566 |
– |
g.completeExceptionally(ex); |
1567 |
– |
checkIncomplete(h); |
1568 |
– |
f.complete(v1); |
1569 |
– |
|
1570 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1571 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1572 |
– |
assertEquals(0, r.invocationCount); |
1573 |
– |
checkCompletedNormally(f, v1); |
1574 |
– |
}} |
1575 |
– |
|
1576 |
– |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1577 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1578 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1579 |
– |
{ |
1580 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1581 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1583 |
– |
final CFException ex = new CFException(); |
1401 |
|
|
1402 |
< |
g.completeExceptionally(ex); |
1403 |
< |
f.complete(v1); |
1404 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1588 |
< |
|
1589 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1590 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1591 |
< |
assertEquals(0, r.invocationCount); |
1592 |
< |
checkCompletedNormally(f, v1); |
1593 |
< |
}} |
1594 |
< |
|
1595 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1596 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1597 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1598 |
< |
{ |
1599 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1600 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1601 |
< |
final SubtractAction r = new SubtractAction(); |
1602 |
< |
final CFException ex = new CFException(); |
1603 |
< |
|
1604 |
< |
f.completeExceptionally(ex); |
1605 |
< |
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); |
1609 |
– |
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() { |
1618 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1619 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1620 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1621 |
< |
{ |
1622 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1623 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1624 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1625 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1626 |
< |
|
1627 |
< |
f.complete(v1); |
1628 |
< |
checkIncomplete(h); |
1629 |
< |
g.complete(v2); |
1630 |
< |
|
1631 |
< |
checkCompletedWithWrappedCFException(h); |
1632 |
< |
checkCompletedNormally(f, v1); |
1633 |
< |
checkCompletedNormally(g, v2); |
1634 |
< |
}} |
1635 |
< |
|
1636 |
< |
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() { |
1659 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1660 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1661 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1662 |
< |
{ |
1663 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1664 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1665 |
< |
final SubtractAction r = new SubtractAction(); |
1666 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1667 |
< |
|
1668 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1669 |
< |
checkIncomplete(h); |
1670 |
< |
g.complete(v1); |
1671 |
< |
|
1672 |
< |
checkCompletedWithWrappedCancellationException(h); |
1673 |
< |
checkCancelled(f); |
1674 |
< |
assertEquals(0, r.invocationCount); |
1675 |
< |
checkCompletedNormally(g, v1); |
1676 |
< |
}} |
1677 |
< |
|
1678 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1679 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1680 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1681 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1682 |
< |
{ |
1683 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1684 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1685 |
< |
final SubtractAction r = new SubtractAction(); |
1686 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1687 |
< |
|
1688 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1689 |
< |
checkIncomplete(h); |
1690 |
< |
f.complete(v1); |
1691 |
< |
|
1692 |
< |
checkCompletedWithWrappedCancellationException(h); |
1693 |
< |
checkCancelled(g); |
1694 |
< |
assertEquals(0, r.invocationCount); |
1695 |
< |
checkCompletedNormally(f, v1); |
1696 |
< |
}} |
1697 |
< |
|
1698 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1699 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1700 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1701 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1702 |
< |
{ |
1703 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1704 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1705 |
< |
final SubtractAction r = new SubtractAction(); |
1706 |
< |
|
1707 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1708 |
< |
f.complete(v1); |
1709 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1710 |
< |
|
1711 |
< |
checkCompletedWithWrappedCancellationException(h); |
1712 |
< |
checkCancelled(g); |
1713 |
< |
assertEquals(0, r.invocationCount); |
1714 |
< |
checkCompletedNormally(f, v1); |
1715 |
< |
}} |
1716 |
< |
|
1717 |
< |
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 |
|
/** |