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); |
1374 |
– |
|
1375 |
– |
checkCompletedNormally(h, null); |
1376 |
– |
assertEquals(subtract(v1, v2), r.value); |
1377 |
– |
checkCompletedNormally(f, v1); |
1378 |
– |
checkCompletedNormally(g, v2); |
1379 |
– |
}} |
1370 |
|
|
1371 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1372 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1373 |
< |
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() { |
1445 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1446 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1447 |
< |
{ |
1448 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1449 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1450 |
< |
final SubtractAction r = new SubtractAction(); |
1451 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1452 |
< |
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<>(); |
1470 |
< |
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); |
1477 |
< |
|
1478 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1479 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1480 |
< |
assertEquals(0, r.invocationCount); |
1481 |
< |
checkCompletedNormally(f, v1); |
1482 |
< |
}} |
1483 |
< |
|
1484 |
< |
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<>(); |
1490 |
– |
final SubtractAction r = new SubtractAction(); |
1399 |
|
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<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1510 |
– |
final CFException ex = new CFException(); |
1401 |
|
|
1402 |
< |
f.completeExceptionally(ex); |
1403 |
< |
g.complete(v1); |
1404 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
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() { |
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 |
< |
f.complete(v1); |
1432 |
< |
checkIncomplete(h); |
1433 |
< |
g.complete(v2); |
1434 |
< |
|
1435 |
< |
checkCompletedWithWrappedCFException(h); |
1436 |
< |
checkCompletedNormally(f, v1); |
1437 |
< |
checkCompletedNormally(g, v2); |
1542 |
< |
}} |
1543 |
< |
|
1544 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1545 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1546 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1547 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1548 |
< |
{ |
1549 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1550 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1551 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1552 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1553 |
< |
|
1554 |
< |
g.complete(v2); |
1555 |
< |
checkIncomplete(h); |
1556 |
< |
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 |
|
/** |