1357 |
|
* thenAcceptBoth result completes normally after normal |
1358 |
|
* completion of sources |
1359 |
|
*/ |
1360 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
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 |
|
{ |
1367 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1368 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1369 |
|
final SubtractAction r = new SubtractAction(); |
1368 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1369 |
– |
|
1370 |
– |
f.complete(v1); |
1371 |
– |
checkIncomplete(h); |
1372 |
– |
assertEquals(0, r.invocationCount); |
1373 |
– |
g.complete(v2); |
1370 |
|
|
1371 |
< |
checkCompletedNormally(h, null); |
1372 |
< |
assertEquals(subtract(v1, v2), r.value); |
1373 |
< |
checkCompletedNormally(f, v1); |
1378 |
< |
checkCompletedNormally(g, v2); |
1379 |
< |
}} |
1380 |
< |
|
1381 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1382 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1383 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1384 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1385 |
< |
{ |
1386 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1387 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1388 |
< |
final SubtractAction r = new SubtractAction(); |
1389 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1390 |
< |
|
1391 |
< |
g.complete(v2); |
1392 |
< |
checkIncomplete(h); |
1393 |
< |
assertEquals(0, r.invocationCount); |
1394 |
< |
f.complete(v1); |
1395 |
< |
|
1396 |
< |
checkCompletedNormally(h, null); |
1397 |
< |
assertEquals(subtract(v1, v2), r.value); |
1398 |
< |
checkCompletedNormally(f, v1); |
1399 |
< |
checkCompletedNormally(g, v2); |
1400 |
< |
}} |
1401 |
< |
|
1402 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1403 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1404 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1405 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1406 |
< |
{ |
1407 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1408 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1409 |
< |
final SubtractAction r = new SubtractAction(); |
1410 |
< |
|
1411 |
< |
g.complete(v2); |
1412 |
< |
f.complete(v1); |
1413 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1414 |
< |
|
1415 |
< |
checkCompletedNormally(h, null); |
1416 |
< |
assertEquals(subtract(v1, v2), r.value); |
1417 |
< |
checkCompletedNormally(f, v1); |
1418 |
< |
checkCompletedNormally(g, v2); |
1419 |
< |
}} |
1420 |
< |
|
1421 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1422 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1423 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1424 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1425 |
< |
{ |
1426 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1427 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1428 |
< |
final SubtractAction r = new SubtractAction(); |
1429 |
< |
|
1430 |
< |
f.complete(v1); |
1431 |
< |
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() { |
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<>(); |
1450 |
– |
final SubtractAction r = new SubtractAction(); |
1451 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1399 |
|
final CFException ex = new CFException(); |
1453 |
– |
|
1454 |
– |
f.completeExceptionally(ex); |
1455 |
– |
checkIncomplete(h); |
1456 |
– |
g.complete(v1); |
1457 |
– |
|
1458 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1459 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1460 |
– |
assertEquals(0, r.invocationCount); |
1461 |
– |
checkCompletedNormally(g, v1); |
1462 |
– |
}} |
1463 |
– |
|
1464 |
– |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1465 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1466 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1467 |
– |
{ |
1468 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1469 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1471 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1472 |
– |
final CFException ex = new CFException(); |
1473 |
– |
|
1474 |
– |
g.completeExceptionally(ex); |
1475 |
– |
checkIncomplete(h); |
1476 |
– |
f.complete(v1); |
1401 |
|
|
1402 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1403 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1404 |
< |
assertEquals(0, r.invocationCount); |
1481 |
< |
checkCompletedNormally(f, v1); |
1482 |
< |
}} |
1483 |
< |
|
1484 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1485 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1486 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1487 |
< |
{ |
1488 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1489 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1490 |
< |
final SubtractAction r = new SubtractAction(); |
1491 |
< |
final CFException ex = new CFException(); |
1492 |
< |
|
1493 |
< |
g.completeExceptionally(ex); |
1494 |
< |
f.complete(v1); |
1495 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1496 |
< |
|
1497 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1498 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1499 |
< |
assertEquals(0, r.invocationCount); |
1500 |
< |
checkCompletedNormally(f, v1); |
1501 |
< |
}} |
1502 |
< |
|
1503 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
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 CFException ex = new CFException(); |
1511 |
< |
|
1512 |
< |
f.completeExceptionally(ex); |
1513 |
< |
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); |
1517 |
– |
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() { |
1526 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1527 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1528 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1529 |
< |
{ |
1530 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1531 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1532 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1533 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1534 |
< |
|
1535 |
< |
f.complete(v1); |
1536 |
< |
checkIncomplete(h); |
1537 |
< |
g.complete(v2); |
1538 |
< |
|
1539 |
< |
checkCompletedWithWrappedCFException(h); |
1540 |
< |
checkCompletedNormally(f, v1); |
1541 |
< |
checkCompletedNormally(g, v2); |
1542 |
< |
}} |
1543 |
< |
|
1544 |
< |
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() { |
1567 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1568 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1569 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1570 |
< |
{ |
1571 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1572 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1573 |
< |
final SubtractAction r = new SubtractAction(); |
1574 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1575 |
< |
|
1576 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1577 |
< |
checkIncomplete(h); |
1578 |
< |
g.complete(v1); |
1579 |
< |
|
1580 |
< |
checkCompletedWithWrappedCancellationException(h); |
1581 |
< |
checkCancelled(f); |
1582 |
< |
assertEquals(0, r.invocationCount); |
1583 |
< |
checkCompletedNormally(g, v1); |
1584 |
< |
}} |
1585 |
< |
|
1586 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1587 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1588 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1589 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1590 |
< |
{ |
1591 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1592 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1593 |
< |
final SubtractAction r = new SubtractAction(); |
1594 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1595 |
< |
|
1596 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1597 |
< |
checkIncomplete(h); |
1598 |
< |
f.complete(v1); |
1599 |
< |
|
1600 |
< |
checkCompletedWithWrappedCancellationException(h); |
1601 |
< |
checkCancelled(g); |
1602 |
< |
assertEquals(0, r.invocationCount); |
1603 |
< |
checkCompletedNormally(f, v1); |
1604 |
< |
}} |
1605 |
< |
|
1606 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1607 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1608 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1609 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1610 |
< |
{ |
1611 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1612 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1613 |
< |
final SubtractAction r = new SubtractAction(); |
1614 |
< |
|
1615 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1616 |
< |
f.complete(v1); |
1617 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1618 |
< |
|
1619 |
< |
checkCompletedWithWrappedCancellationException(h); |
1620 |
< |
checkCancelled(g); |
1621 |
< |
assertEquals(0, r.invocationCount); |
1622 |
< |
checkCompletedNormally(f, v1); |
1623 |
< |
}} |
1624 |
< |
|
1625 |
< |
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() { |
1649 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1650 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1651 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1652 |
< |
{ |
1653 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1654 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1655 |
< |
final Noop r = new Noop(); |
1656 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1657 |
< |
|
1658 |
< |
f.complete(v1); |
1659 |
< |
checkIncomplete(h); |
1660 |
< |
assertEquals(0, r.invocationCount); |
1661 |
< |
g.complete(v2); |
1662 |
< |
|
1663 |
< |
checkCompletedNormally(h, null); |
1664 |
< |
assertEquals(1, r.invocationCount); |
1665 |
< |
checkCompletedNormally(f, v1); |
1666 |
< |
checkCompletedNormally(g, v2); |
1667 |
< |
}} |
1668 |
< |
|
1669 |
< |
public void testRunAfterBoth_normalCompletion2() { |
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 |
|
{ |
1484 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1485 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1486 |
|
final Noop r = new Noop(); |
1677 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1487 |
|
|
1488 |
< |
g.complete(v2); |
1489 |
< |
checkIncomplete(h); |
1490 |
< |
assertEquals(0, r.invocationCount); |
1682 |
< |
f.complete(v1); |
1683 |
< |
|
1684 |
< |
checkCompletedNormally(h, null); |
1685 |
< |
assertEquals(1, r.invocationCount); |
1686 |
< |
checkCompletedNormally(f, v1); |
1687 |
< |
checkCompletedNormally(g, v2); |
1688 |
< |
}} |
1689 |
< |
|
1690 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1691 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1692 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1693 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1694 |
< |
{ |
1695 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1696 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1697 |
< |
final Noop r = new Noop(); |
1698 |
< |
|
1699 |
< |
g.complete(v2); |
1700 |
< |
f.complete(v1); |
1701 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1702 |
< |
|
1703 |
< |
checkCompletedNormally(h, null); |
1704 |
< |
assertEquals(1, r.invocationCount); |
1705 |
< |
checkCompletedNormally(f, v1); |
1706 |
< |
checkCompletedNormally(g, v2); |
1707 |
< |
}} |
1708 |
< |
|
1709 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1710 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1711 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1712 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1713 |
< |
{ |
1714 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1715 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1716 |
< |
final Noop r = new Noop(); |
1717 |
< |
|
1718 |
< |
f.complete(v1); |
1719 |
< |
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() { |
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<>(); |
1738 |
– |
final Noop r = new Noop(); |
1739 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1516 |
|
final CFException ex = new CFException(); |
1741 |
– |
|
1742 |
– |
f.completeExceptionally(ex); |
1743 |
– |
checkIncomplete(h); |
1744 |
– |
g.complete(v1); |
1745 |
– |
|
1746 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1747 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1748 |
– |
assertEquals(0, r.invocationCount); |
1749 |
– |
checkCompletedNormally(g, v1); |
1750 |
– |
}} |
1751 |
– |
|
1752 |
– |
public void testRunAfterBoth_exceptionalCompletion2() { |
1753 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1754 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1755 |
– |
{ |
1756 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1757 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1517 |
|
final Noop r = new Noop(); |
1759 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1760 |
– |
final CFException ex = new CFException(); |
1761 |
– |
|
1762 |
– |
g.completeExceptionally(ex); |
1763 |
– |
checkIncomplete(h); |
1764 |
– |
f.complete(v1); |
1518 |
|
|
1519 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1520 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1521 |
< |
assertEquals(0, r.invocationCount); |
1769 |
< |
checkCompletedNormally(f, v1); |
1770 |
< |
}} |
1771 |
< |
|
1772 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1773 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
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 Noop r = new Noop(); |
1779 |
< |
final CFException ex = new CFException(); |
1780 |
< |
|
1781 |
< |
g.completeExceptionally(ex); |
1782 |
< |
f.complete(v1); |
1783 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1784 |
< |
|
1785 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1786 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1787 |
< |
assertEquals(0, r.invocationCount); |
1788 |
< |
checkCompletedNormally(f, v1); |
1789 |
< |
}} |
1790 |
< |
|
1791 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
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 CFException ex = new CFException(); |
1799 |
< |
|
1800 |
< |
f.completeExceptionally(ex); |
1801 |
< |
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); |
1805 |
– |
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() { |
1814 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1815 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1816 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1817 |
< |
{ |
1818 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1819 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1820 |
< |
final FailingRunnable r = new FailingRunnable(); |
1821 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1822 |
< |
|
1823 |
< |
f.complete(v1); |
1824 |
< |
checkIncomplete(h); |
1825 |
< |
g.complete(v2); |
1826 |
< |
|
1827 |
< |
checkCompletedWithWrappedCFException(h); |
1828 |
< |
checkCompletedNormally(f, v1); |
1829 |
< |
checkCompletedNormally(g, v2); |
1830 |
< |
}} |
1831 |
< |
|
1832 |
< |
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 FailingRunnable r = new FailingRunnable(); |
1840 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
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() { |
1855 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1856 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1857 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1858 |
< |
{ |
1859 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1860 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1861 |
< |
final Noop r = new Noop(); |
1862 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1863 |
< |
|
1864 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1865 |
< |
checkIncomplete(h); |
1866 |
< |
g.complete(v1); |
1867 |
< |
|
1868 |
< |
checkCompletedWithWrappedCancellationException(h); |
1869 |
< |
checkCancelled(f); |
1870 |
< |
assertEquals(0, r.invocationCount); |
1871 |
< |
checkCompletedNormally(g, v1); |
1872 |
< |
}} |
1873 |
< |
|
1874 |
< |
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(); |
1882 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1576 |
|
|
1884 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1885 |
– |
checkIncomplete(h); |
1886 |
– |
f.complete(v1); |
1887 |
– |
|
1888 |
– |
checkCompletedWithWrappedCancellationException(h); |
1889 |
– |
checkCancelled(g); |
1890 |
– |
assertEquals(0, r.invocationCount); |
1891 |
– |
checkCompletedNormally(f, v1); |
1892 |
– |
}} |
1893 |
– |
|
1894 |
– |
public void testRunAfterBoth_sourceCancelled3() { |
1895 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1896 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1897 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1898 |
– |
{ |
1899 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1900 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1901 |
– |
final Noop r = new Noop(); |
1902 |
– |
|
1903 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1904 |
– |
f.complete(v1); |
1905 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1906 |
– |
|
1907 |
– |
checkCompletedWithWrappedCancellationException(h); |
1908 |
– |
checkCancelled(g); |
1909 |
– |
assertEquals(0, r.invocationCount); |
1910 |
– |
checkCompletedNormally(f, v1); |
1911 |
– |
}} |
1912 |
– |
|
1913 |
– |
public void testRunAfterBoth_sourceCancelled4() { |
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(); |
1577 |
|
|
1578 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1579 |
< |
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(); |
1944 |
– |
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(); |
1963 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1964 |
– |
|
1965 |
– |
g.complete(v2); |
1966 |
– |
checkCompletedNormally(h, inc(v2)); |
1967 |
– |
f.complete(v1); |
1968 |
– |
|
1969 |
– |
checkCompletedNormally(f, v1); |
1970 |
– |
checkCompletedNormally(g, v2); |
1971 |
– |
checkCompletedNormally(h, inc(v2)); |
1972 |
– |
}} |
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<>(); |
1981 |
< |
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 |
|
|
1983 |
– |
f.complete(v1); |
1984 |
– |
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<>(); |
2006 |
– |
final IncFunction r = new IncFunction(); |
2007 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1665 |
|
final CFException ex = new CFException(); |
2009 |
– |
|
2010 |
– |
f.completeExceptionally(ex); |
2011 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2012 |
– |
g.complete(v1); |
2013 |
– |
|
2014 |
– |
assertEquals(0, r.invocationCount); |
2015 |
– |
checkCompletedNormally(g, v1); |
2016 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2017 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2018 |
– |
}} |
2019 |
– |
|
2020 |
– |
public void testApplyToEither_exceptionalCompletion2() { |
2021 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2022 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2023 |
– |
{ |
2024 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2025 |
– |
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 |
|
|
2030 |
– |
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 |
2054 |
– |
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 |
|
|
2063 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2064 |
– |
checkCompletedNormally(f, v1); |
2065 |
– |
}} |
2066 |
– |
|
2067 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2068 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2069 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2070 |
– |
{ |
2071 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2072 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2073 |
– |
final IncFunction r = new IncFunction(); |
2074 |
– |
final CFException ex = new CFException(); |
2075 |
– |
|
2076 |
– |
f.completeExceptionally(ex); |
2077 |
– |
g.complete(v1); |
2078 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2079 |
– |
|
2080 |
– |
// unspecified behavior |
2081 |
– |
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(); |
2142 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1779 |
|
|
1780 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2145 |
< |
checkCompletedWithWrappedCancellationException(h); |
2146 |
< |
g.complete(v1); |
2147 |
< |
|
2148 |
< |
checkCancelled(f); |
2149 |
< |
assertEquals(0, r.invocationCount); |
2150 |
< |
checkCompletedNormally(g, v1); |
2151 |
< |
checkCompletedWithWrappedCancellationException(h); |
2152 |
< |
}} |
2153 |
< |
|
2154 |
< |
public void testApplyToEither_sourceCancelled2() { |
2155 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2156 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2157 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2158 |
< |
{ |
2159 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2160 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2161 |
< |
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 |
|
|
2164 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1788 |
|
checkCompletedWithWrappedCancellationException(h); |
1789 |
< |
f.complete(v1); |
1789 |
> |
(!fFirst ? f : g).complete(v1); |
1790 |
|
|
2168 |
– |
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 |
2188 |
– |
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 |
|
|
2197 |
– |
checkCancelled(g); |
2198 |
– |
checkCompletedNormally(f, v1); |
2199 |
– |
}} |
2200 |
– |
|
2201 |
– |
public void testApplyToEither_sourceCancelled4() { |
2202 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2203 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2204 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2205 |
– |
{ |
2206 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2207 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2208 |
– |
final IncFunction r = new IncFunction(); |
2209 |
– |
|
2210 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2211 |
– |
g.complete(v1); |
2212 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2213 |
– |
|
2214 |
– |
// unspecified behavior |
2215 |
– |
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 |
|
/** |