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); |
1282 |
|
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(); |
1321 |
– |
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); |
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 |
|
/** |
1357 |
|
* thenAcceptBoth result completes normally after normal |
1358 |
|
* completion of sources |
1359 |
|
*/ |
1360 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1479 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1480 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1481 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1482 |
< |
{ |
1483 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1484 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1485 |
< |
final SubtractAction r = new SubtractAction(); |
1486 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1487 |
< |
|
1488 |
< |
f.complete(v1); |
1489 |
< |
checkIncomplete(h); |
1490 |
< |
assertEquals(0, r.invocationCount); |
1491 |
< |
g.complete(v2); |
1492 |
< |
|
1493 |
< |
checkCompletedNormally(h, null); |
1494 |
< |
assertEquals(subtract(v1, v2), r.value); |
1495 |
< |
checkCompletedNormally(f, v1); |
1496 |
< |
checkCompletedNormally(g, v2); |
1497 |
< |
}} |
1498 |
< |
|
1499 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1500 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1501 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1502 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1503 |
< |
{ |
1504 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1505 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1506 |
< |
final SubtractAction r = new SubtractAction(); |
1507 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1508 |
< |
|
1509 |
< |
g.complete(v2); |
1510 |
< |
checkIncomplete(h); |
1511 |
< |
assertEquals(0, r.invocationCount); |
1512 |
< |
f.complete(v1); |
1513 |
< |
|
1514 |
< |
checkCompletedNormally(h, null); |
1515 |
< |
assertEquals(subtract(v1, v2), r.value); |
1516 |
< |
checkCompletedNormally(f, v1); |
1517 |
< |
checkCompletedNormally(g, v2); |
1518 |
< |
}} |
1519 |
< |
|
1520 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1521 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1522 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1523 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1524 |
< |
{ |
1525 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1526 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1527 |
< |
final SubtractAction r = new SubtractAction(); |
1528 |
< |
|
1529 |
< |
g.complete(v2); |
1530 |
< |
f.complete(v1); |
1531 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1532 |
< |
|
1533 |
< |
checkCompletedNormally(h, null); |
1534 |
< |
assertEquals(subtract(v1, v2), r.value); |
1535 |
< |
checkCompletedNormally(f, v1); |
1536 |
< |
checkCompletedNormally(g, v2); |
1537 |
< |
}} |
1538 |
< |
|
1539 |
< |
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() { |
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<>(); |
1568 |
< |
final SubtractAction r = new SubtractAction(); |
1569 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1570 |
< |
final CFException ex = new CFException(); |
1571 |
< |
|
1572 |
< |
f.completeExceptionally(ex); |
1573 |
< |
checkIncomplete(h); |
1574 |
< |
g.complete(v1); |
1575 |
< |
|
1576 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1577 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1578 |
< |
assertEquals(0, r.invocationCount); |
1579 |
< |
checkCompletedNormally(g, v1); |
1580 |
< |
}} |
1581 |
< |
|
1582 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1583 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1584 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1585 |
< |
{ |
1586 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1587 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1588 |
< |
final SubtractAction r = new SubtractAction(); |
1589 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1590 |
< |
final CFException ex = new CFException(); |
1591 |
< |
|
1592 |
< |
g.completeExceptionally(ex); |
1593 |
< |
checkIncomplete(h); |
1594 |
< |
f.complete(v1); |
1595 |
< |
|
1596 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1597 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1598 |
< |
assertEquals(0, r.invocationCount); |
1599 |
< |
checkCompletedNormally(f, v1); |
1600 |
< |
}} |
1601 |
< |
|
1602 |
< |
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<>(); |
1608 |
– |
final SubtractAction r = new SubtractAction(); |
1399 |
|
final CFException ex = new CFException(); |
1610 |
– |
|
1611 |
– |
g.completeExceptionally(ex); |
1612 |
– |
f.complete(v1); |
1613 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1614 |
– |
|
1615 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1616 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1617 |
– |
assertEquals(0, r.invocationCount); |
1618 |
– |
checkCompletedNormally(f, v1); |
1619 |
– |
}} |
1620 |
– |
|
1621 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1622 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1623 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1624 |
– |
{ |
1625 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1626 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1628 |
– |
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); |
1635 |
– |
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() { |
1644 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1645 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1646 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1647 |
< |
{ |
1648 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1649 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1650 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1651 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1652 |
< |
|
1653 |
< |
f.complete(v1); |
1654 |
< |
checkIncomplete(h); |
1655 |
< |
g.complete(v2); |
1656 |
< |
|
1657 |
< |
checkCompletedWithWrappedCFException(h); |
1658 |
< |
checkCompletedNormally(f, v1); |
1659 |
< |
checkCompletedNormally(g, v2); |
1660 |
< |
}} |
1661 |
< |
|
1662 |
< |
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() { |
1685 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1686 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1687 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1688 |
< |
{ |
1689 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1690 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1691 |
< |
final SubtractAction r = new SubtractAction(); |
1692 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1693 |
< |
|
1694 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1695 |
< |
checkIncomplete(h); |
1696 |
< |
g.complete(v1); |
1697 |
< |
|
1698 |
< |
checkCompletedWithWrappedCancellationException(h); |
1699 |
< |
checkCancelled(f); |
1700 |
< |
assertEquals(0, r.invocationCount); |
1701 |
< |
checkCompletedNormally(g, v1); |
1702 |
< |
}} |
1703 |
< |
|
1704 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1705 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1706 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1707 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1708 |
< |
{ |
1709 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1710 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
< |
final SubtractAction r = new SubtractAction(); |
1712 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1713 |
< |
|
1714 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1715 |
< |
checkIncomplete(h); |
1716 |
< |
f.complete(v1); |
1717 |
< |
|
1718 |
< |
checkCompletedWithWrappedCancellationException(h); |
1719 |
< |
checkCancelled(g); |
1720 |
< |
assertEquals(0, r.invocationCount); |
1721 |
< |
checkCompletedNormally(f, v1); |
1722 |
< |
}} |
1723 |
< |
|
1724 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1725 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1726 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1727 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1728 |
< |
{ |
1729 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1730 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1731 |
< |
final SubtractAction r = new SubtractAction(); |
1732 |
< |
|
1733 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1734 |
< |
f.complete(v1); |
1735 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1736 |
< |
|
1737 |
< |
checkCompletedWithWrappedCancellationException(h); |
1738 |
< |
checkCancelled(g); |
1739 |
< |
assertEquals(0, r.invocationCount); |
1740 |
< |
checkCompletedNormally(f, v1); |
1741 |
< |
}} |
1742 |
< |
|
1743 |
< |
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 |
|
/** |