1271 |
|
* thenCombine result completes exceptionally after exceptional |
1272 |
|
* completion of either source |
1273 |
|
*/ |
1274 |
< |
public void testThenCombine_exceptionalCompletion1() { |
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<>(); |
1280 |
– |
final SubtractFunction r = new SubtractFunction(); |
1281 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1282 |
– |
final CFException ex = new CFException(); |
1283 |
– |
|
1284 |
– |
f.completeExceptionally(ex); |
1285 |
– |
checkIncomplete(h); |
1286 |
– |
g.complete(v1); |
1287 |
– |
|
1288 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1289 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1290 |
– |
assertEquals(0, r.invocationCount); |
1291 |
– |
checkCompletedNormally(g, v1); |
1292 |
– |
}} |
1293 |
– |
|
1294 |
– |
public void testThenCombine_exceptionalCompletion2() { |
1295 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1296 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1297 |
– |
{ |
1298 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1299 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1300 |
– |
final SubtractFunction r = new SubtractFunction(); |
1301 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1302 |
– |
final CFException ex = new CFException(); |
1303 |
– |
|
1304 |
– |
g.completeExceptionally(ex); |
1305 |
– |
checkIncomplete(h); |
1306 |
– |
f.complete(v1); |
1307 |
– |
|
1308 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1309 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1310 |
– |
assertEquals(0, r.invocationCount); |
1311 |
– |
checkCompletedNormally(f, v1); |
1312 |
– |
}} |
1313 |
– |
|
1314 |
– |
public void testThenCombine_exceptionalCompletion3() { |
1315 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1317 |
– |
{ |
1318 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1319 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1320 |
– |
final SubtractFunction r = new SubtractFunction(); |
1282 |
|
final CFException ex = new CFException(); |
1322 |
– |
|
1323 |
– |
g.completeExceptionally(ex); |
1324 |
– |
f.complete(v1); |
1325 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1326 |
– |
|
1327 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1328 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1329 |
– |
assertEquals(0, r.invocationCount); |
1330 |
– |
checkCompletedNormally(f, v1); |
1331 |
– |
}} |
1332 |
– |
|
1333 |
– |
public void testThenCombine_exceptionalCompletion4() { |
1334 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1335 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1336 |
– |
{ |
1337 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1283 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
– |
final CFException ex = new CFException(); |
1284 |
|
|
1285 |
< |
f.completeExceptionally(ex); |
1286 |
< |
g.complete(v1); |
1287 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
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); |
1347 |
– |
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() { |
1356 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1357 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1358 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1359 |
< |
{ |
1360 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1361 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1362 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1363 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1364 |
< |
|
1365 |
< |
f.complete(v1); |
1366 |
< |
checkIncomplete(h); |
1367 |
< |
g.complete(v2); |
1368 |
< |
|
1369 |
< |
checkCompletedWithWrappedCFException(h); |
1370 |
< |
checkCompletedNormally(f, v1); |
1371 |
< |
checkCompletedNormally(g, v2); |
1372 |
< |
}} |
1373 |
< |
|
1374 |
< |
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() { |
1397 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1398 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1399 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1400 |
< |
{ |
1401 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1402 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
< |
final SubtractFunction r = new SubtractFunction(); |
1404 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1405 |
< |
|
1406 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1407 |
< |
checkIncomplete(h); |
1408 |
< |
g.complete(v1); |
1409 |
< |
|
1410 |
< |
checkCompletedWithWrappedCancellationException(h); |
1411 |
< |
checkCancelled(f); |
1412 |
< |
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1414 |
< |
}} |
1415 |
< |
|
1416 |
< |
public void testThenCombine_sourceCancelled2() { |
1417 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1418 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1419 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1420 |
< |
{ |
1421 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1422 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1423 |
< |
final SubtractFunction r = new SubtractFunction(); |
1424 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1425 |
< |
|
1426 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1427 |
< |
checkIncomplete(h); |
1428 |
< |
f.complete(v1); |
1429 |
< |
|
1430 |
< |
checkCompletedWithWrappedCancellationException(h); |
1431 |
< |
checkCancelled(g); |
1432 |
< |
assertEquals(0, r.invocationCount); |
1433 |
< |
checkCompletedNormally(f, v1); |
1434 |
< |
}} |
1435 |
< |
|
1436 |
< |
public void testThenCombine_sourceCancelled3() { |
1437 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1438 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1439 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1440 |
< |
{ |
1441 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1442 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1443 |
< |
final SubtractFunction r = new SubtractFunction(); |
1444 |
< |
|
1445 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1446 |
< |
f.complete(v1); |
1447 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1448 |
< |
|
1449 |
< |
checkCompletedWithWrappedCancellationException(h); |
1450 |
< |
checkCancelled(g); |
1451 |
< |
assertEquals(0, r.invocationCount); |
1452 |
< |
checkCompletedNormally(f, v1); |
1453 |
< |
}} |
1454 |
< |
|
1455 |
< |
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 |
|
/** |