1491 |
|
*/ |
1492 |
|
public void testThenAccept_normalCompletion() { |
1493 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1494 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1494 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1495 |
|
{ |
1496 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1497 |
< |
final NoopConsumer r = new NoopConsumer(m); |
1498 |
< |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1500 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1501 |
< |
if (createIncomplete) { |
1502 |
< |
checkIncomplete(g); |
1503 |
< |
assertTrue(f.complete(v1)); |
1504 |
< |
} |
1497 |
> |
final NoopConsumer[] rs = new NoopConsumer[4]; |
1498 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1499 |
|
|
1500 |
< |
checkCompletedNormally(g, null); |
1501 |
< |
r.assertValue(v1); |
1500 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1501 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1502 |
> |
checkIncomplete(h0); |
1503 |
> |
checkIncomplete(h1); |
1504 |
> |
assertTrue(f.complete(v1)); |
1505 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1506 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1507 |
> |
|
1508 |
> |
checkCompletedNormally(h0, null); |
1509 |
> |
checkCompletedNormally(h1, null); |
1510 |
> |
checkCompletedNormally(h2, null); |
1511 |
> |
checkCompletedNormally(h3, null); |
1512 |
|
checkCompletedNormally(f, v1); |
1513 |
+ |
for (NoopConsumer r : rs) r.assertValue(v1); |
1514 |
|
}} |
1515 |
|
|
1516 |
|
/** |
1519 |
|
*/ |
1520 |
|
public void testThenAccept_exceptionalCompletion() { |
1521 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1517 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1522 |
|
{ |
1523 |
|
final CFException ex = new CFException(); |
1524 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1525 |
< |
final NoopConsumer r = new NoopConsumer(m); |
1526 |
< |
if (!createIncomplete) f.completeExceptionally(ex); |
1523 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1524 |
< |
if (createIncomplete) { |
1525 |
< |
checkIncomplete(g); |
1526 |
< |
f.completeExceptionally(ex); |
1527 |
< |
} |
1525 |
> |
final NoopConsumer[] rs = new NoopConsumer[4]; |
1526 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1527 |
|
|
1528 |
< |
checkCompletedWithWrappedException(g, ex); |
1528 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1529 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1530 |
> |
assertTrue(f.completeExceptionally(ex)); |
1531 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1532 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1533 |
> |
|
1534 |
> |
checkCompletedWithWrappedException(h0, ex); |
1535 |
> |
checkCompletedWithWrappedException(h1, ex); |
1536 |
> |
checkCompletedWithWrappedException(h2, ex); |
1537 |
> |
checkCompletedWithWrappedException(h3, ex); |
1538 |
|
checkCompletedExceptionally(f, ex); |
1539 |
< |
r.assertNotInvoked(); |
1539 |
> |
for (NoopConsumer r : rs) r.assertNotInvoked(); |
1540 |
|
}} |
1541 |
|
|
1542 |
|
/** |
1544 |
|
*/ |
1545 |
|
public void testThenAccept_sourceCancelled() { |
1546 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1539 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1547 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1548 |
|
{ |
1549 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1550 |
< |
final NoopConsumer r = new NoopConsumer(m); |
1551 |
< |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1545 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1546 |
< |
if (createIncomplete) { |
1547 |
< |
checkIncomplete(g); |
1548 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1549 |
< |
} |
1550 |
> |
final NoopConsumer[] rs = new NoopConsumer[4]; |
1551 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1552 |
|
|
1553 |
< |
checkCompletedWithWrappedCancellationException(g); |
1553 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1554 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1555 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1556 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1557 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1558 |
> |
|
1559 |
> |
checkCompletedWithWrappedCancellationException(h0); |
1560 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1561 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1562 |
> |
checkCompletedWithWrappedCancellationException(h3); |
1563 |
|
checkCancelled(f); |
1564 |
< |
r.assertNotInvoked(); |
1564 |
> |
for (NoopConsumer r : rs) r.assertNotInvoked(); |
1565 |
|
}} |
1566 |
|
|
1567 |
|
/** |
1569 |
|
*/ |
1570 |
|
public void testThenAccept_actionFailed() { |
1571 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1561 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1572 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1573 |
|
{ |
1574 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1575 |
< |
final FailingConsumer r = new FailingConsumer(m); |
1576 |
< |
if (!createIncomplete) f.complete(v1); |
1567 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1568 |
< |
if (createIncomplete) { |
1569 |
< |
checkIncomplete(g); |
1570 |
< |
f.complete(v1); |
1571 |
< |
} |
1575 |
> |
final FailingConsumer[] rs = new FailingConsumer[4]; |
1576 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m); |
1577 |
|
|
1578 |
< |
checkCompletedWithWrappedCFException(g); |
1578 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1579 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1580 |
> |
assertTrue(f.complete(v1)); |
1581 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1582 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1583 |
> |
|
1584 |
> |
checkCompletedWithWrappedCFException(h0); |
1585 |
> |
checkCompletedWithWrappedCFException(h1); |
1586 |
> |
checkCompletedWithWrappedCFException(h2); |
1587 |
> |
checkCompletedWithWrappedCFException(h3); |
1588 |
|
checkCompletedNormally(f, v1); |
1589 |
|
}} |
1590 |
|
|
1600 |
|
{ |
1601 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1602 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1603 |
< |
final SubtractFunction r1 = new SubtractFunction(m); |
1604 |
< |
final SubtractFunction r2 = new SubtractFunction(m); |
1591 |
< |
final SubtractFunction r3 = new SubtractFunction(m); |
1603 |
> |
final SubtractFunction[] rs = new SubtractFunction[6]; |
1604 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new SubtractFunction(m); |
1605 |
|
|
1606 |
|
final CompletableFuture<Integer> fst = fFirst ? f : g; |
1607 |
|
final CompletableFuture<Integer> snd = !fFirst ? f : g; |
1608 |
|
final Integer w1 = fFirst ? v1 : v2; |
1609 |
|
final Integer w2 = !fFirst ? v1 : v2; |
1610 |
|
|
1611 |
< |
final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1); |
1611 |
> |
final CompletableFuture<Integer> h0 = m.thenCombine(f, g, rs[0]); |
1612 |
> |
final CompletableFuture<Integer> h1 = m.thenCombine(fst, fst, rs[1]); |
1613 |
|
assertTrue(fst.complete(w1)); |
1614 |
< |
final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2); |
1615 |
< |
checkIncomplete(h1); |
1616 |
< |
checkIncomplete(h2); |
1617 |
< |
r1.assertNotInvoked(); |
1618 |
< |
r2.assertNotInvoked(); |
1614 |
> |
final CompletableFuture<Integer> h2 = m.thenCombine(f, g, rs[2]); |
1615 |
> |
final CompletableFuture<Integer> h3 = m.thenCombine(fst, fst, rs[3]); |
1616 |
> |
checkIncomplete(h0); rs[0].assertNotInvoked(); |
1617 |
> |
checkIncomplete(h2); rs[2].assertNotInvoked(); |
1618 |
> |
checkCompletedNormally(h1, subtract(w1, w1)); |
1619 |
> |
checkCompletedNormally(h3, subtract(w1, w1)); |
1620 |
> |
rs[1].assertValue(subtract(w1, w1)); |
1621 |
> |
rs[3].assertValue(subtract(w1, w1)); |
1622 |
|
assertTrue(snd.complete(w2)); |
1623 |
< |
final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3); |
1623 |
> |
final CompletableFuture<Integer> h4 = m.thenCombine(f, g, rs[4]); |
1624 |
|
|
1625 |
< |
checkCompletedNormally(h1, subtract(v1, v2)); |
1625 |
> |
checkCompletedNormally(h0, subtract(v1, v2)); |
1626 |
|
checkCompletedNormally(h2, subtract(v1, v2)); |
1627 |
< |
checkCompletedNormally(h3, subtract(v1, v2)); |
1628 |
< |
r1.assertValue(subtract(v1, v2)); |
1629 |
< |
r2.assertValue(subtract(v1, v2)); |
1630 |
< |
r3.assertValue(subtract(v1, v2)); |
1627 |
> |
checkCompletedNormally(h4, subtract(v1, v2)); |
1628 |
> |
rs[0].assertValue(subtract(v1, v2)); |
1629 |
> |
rs[2].assertValue(subtract(v1, v2)); |
1630 |
> |
rs[4].assertValue(subtract(v1, v2)); |
1631 |
> |
|
1632 |
|
checkCompletedNormally(f, v1); |
1633 |
|
checkCompletedNormally(g, v2); |
1634 |
|
}} |