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 |
|
/** |