ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.52 by jsr166, Mon Jun 2 20:10:04 2014 UTC vs.
Revision 1.55 by jsr166, Mon Jun 2 21:41:37 2014 UTC

# Line 284 | Line 284 | public class CompletableFutureTest exten
284      public void testGetNumberOfDependents() {
285          CompletableFuture<Integer> f = new CompletableFuture<>();
286          assertEquals(0, f.getNumberOfDependents());
287 <        CompletableFuture g = f.thenRun(new Noop());
287 >        CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT));
288          assertEquals(1, f.getNumberOfDependents());
289          assertEquals(0, g.getNumberOfDependents());
290 <        CompletableFuture h = f.thenRun(new Noop());
290 >        CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT));
291          assertEquals(2, f.getNumberOfDependents());
292          f.complete(1);
293          checkCompletedNormally(g, null);
# Line 375 | Line 375 | public class CompletableFutureTest exten
375          }
376      }
377      static final class Noop implements Runnable {
378 +        final ExecutionMode m;
379          int invocationCount = 0;
380 +        Noop(ExecutionMode m) { this.m = m; }
381          public void run() {
382 +            m.checkExecutionMode();
383              invocationCount++;
384          }
385      }
# Line 909 | Line 912 | public class CompletableFutureTest exten
912       * runAsync completes after running Runnable
913       */
914      public void testRunAsync() {
915 <        Noop r = new Noop();
915 >        Noop r = new Noop(ExecutionMode.ASYNC);
916          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
917          assertNull(f.join());
918          assertEquals(1, r.invocationCount);
# Line 920 | Line 923 | public class CompletableFutureTest exten
923       * runAsync with executor completes after running Runnable
924       */
925      public void testRunAsync2() {
926 <        Noop r = new Noop();
926 >        Noop r = new Noop(ExecutionMode.EXECUTOR);
927          ThreadExecutor exec = new ThreadExecutor();
928          CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
929          assertNull(f.join());
# Line 980 | Line 983 | public class CompletableFutureTest exten
983          for (Integer v1 : new Integer[] { 1, null })
984      {
985          final CompletableFuture<Integer> f = new CompletableFuture<>();
986 <        final Noop r = new Noop();
986 >        final Noop r = new Noop(m);
987          if (!createIncomplete) f.complete(v1);
988          final CompletableFuture<Void> g = m.thenRun(f, r);
989          if (createIncomplete) {
# Line 1003 | Line 1006 | public class CompletableFutureTest exten
1006      {
1007          final CFException ex = new CFException();
1008          final CompletableFuture<Integer> f = new CompletableFuture<>();
1009 <        final Noop r = new Noop();
1009 >        final Noop r = new Noop(m);
1010          if (!createIncomplete) f.completeExceptionally(ex);
1011          final CompletableFuture<Void> g = m.thenRun(f, r);
1012          if (createIncomplete) {
# Line 1025 | Line 1028 | public class CompletableFutureTest exten
1028          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1029      {
1030          final CompletableFuture<Integer> f = new CompletableFuture<>();
1031 <        final Noop r = new Noop();
1031 >        final Noop r = new Noop(m);
1032          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1033          final CompletableFuture<Void> g = f.thenRun(r);
1034          if (createIncomplete) {
# Line 1357 | Line 1360 | public class CompletableFutureTest exten
1360       * thenAcceptBoth result completes normally after normal
1361       * completion of sources
1362       */
1363 <    public void testThenAcceptBoth_normalCompletion1() {
1361 <        for (ExecutionMode m : ExecutionMode.values())
1362 <        for (Integer v1 : new Integer[] { 1, null })
1363 <        for (Integer v2 : new Integer[] { 2, null })
1364 <    {
1365 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1366 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1367 <        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 <    }}
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() {
1363 >    public void testThenAcceptBoth_normalCompletion() {
1364          for (ExecutionMode m : ExecutionMode.values())
1365 +        for (boolean createIncomplete : new boolean[] { true, false })
1366 +        for (boolean fFirst : new boolean[] { true, false })
1367          for (Integer v1 : new Integer[] { 1, null })
1368          for (Integer v2 : new Integer[] { 2, null })
1369      {
# Line 1427 | Line 1371 | public class CompletableFutureTest exten
1371          final CompletableFuture<Integer> g = new CompletableFuture<>();
1372          final SubtractAction r = new SubtractAction();
1373  
1374 <        f.complete(v1);
1375 <        g.complete(v2);
1374 >        if (fFirst) f.complete(v1); else g.complete(v2);
1375 >        if (!createIncomplete)
1376 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1377          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1378 +        if (createIncomplete) {
1379 +            checkIncomplete(h);
1380 +            assertEquals(0, r.invocationCount);
1381 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1382 +        }
1383  
1384          checkCompletedNormally(h, null);
1385          assertEquals(subtract(v1, v2), r.value);
# Line 1441 | Line 1391 | public class CompletableFutureTest exten
1391       * thenAcceptBoth result completes exceptionally after exceptional
1392       * completion of either source
1393       */
1394 <    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() {
1394 >    public void testThenAcceptBoth_exceptionalCompletion() {
1395          for (ExecutionMode m : ExecutionMode.values())
1396 +        for (boolean createIncomplete : new boolean[] { true, false })
1397 +        for (boolean fFirst : new boolean[] { true, false })
1398          for (Integer v1 : new Integer[] { 1, null })
1399      {
1400          final CompletableFuture<Integer> f = new CompletableFuture<>();
1401          final CompletableFuture<Integer> g = new CompletableFuture<>();
1470        final SubtractAction r = new SubtractAction();
1471        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1402          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() {
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<>();
1403          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);
1404  
1405 <        checkCompletedWithWrappedCFException(h, ex);
1406 <        checkCompletedWithWrappedCFException(g, ex);
1407 <        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);
1405 >        (fFirst ? f : g).complete(v1);
1406 >        if (!createIncomplete)
1407 >            (!fFirst ? f : g).completeExceptionally(ex);
1408          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1409 +        if (createIncomplete) {
1410 +            checkIncomplete(h);
1411 +            (!fFirst ? f : g).completeExceptionally(ex);
1412 +        }
1413  
1414          checkCompletedWithWrappedCFException(h, ex);
1517        checkCompletedWithWrappedCFException(f, ex);
1415          assertEquals(0, r.invocationCount);
1416 <        checkCompletedNormally(g, v1);
1416 >        checkCompletedNormally(fFirst ? f : g, v1);
1417 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1418      }}
1419  
1420      /**
1421       * thenAcceptBoth result completes exceptionally if action does
1422       */
1423 <    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() {
1423 >    public void testThenAcceptBoth_actionFailed() {
1424          for (ExecutionMode m : ExecutionMode.values())
1425 +        for (boolean fFirst : new boolean[] { true, false })
1426          for (Integer v1 : new Integer[] { 1, null })
1427          for (Integer v2 : new Integer[] { 2, null })
1428      {
# Line 1551 | Line 1431 | public class CompletableFutureTest exten
1431          final FailingBiConsumer r = new FailingBiConsumer();
1432          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1433  
1434 <        g.complete(v2);
1435 <        checkIncomplete(h);
1436 <        f.complete(v1);
1434 >        if (fFirst) {
1435 >            f.complete(v1);
1436 >            g.complete(v2);
1437 >        } else {
1438 >            g.complete(v2);
1439 >            f.complete(v1);
1440 >        }
1441  
1442          checkCompletedWithWrappedCFException(h);
1443          checkCompletedNormally(f, v1);
# Line 1563 | Line 1447 | public class CompletableFutureTest exten
1447      /**
1448       * thenAcceptBoth result completes exceptionally if either source cancelled
1449       */
1450 <    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() {
1450 >    public void testThenAcceptBoth_sourceCancelled() {
1451          for (ExecutionMode m : ExecutionMode.values())
1452          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1453 +        for (boolean createIncomplete : new boolean[] { true, false })
1454 +        for (boolean fFirst : new boolean[] { true, false })
1455          for (Integer v1 : new Integer[] { 1, null })
1456      {
1457          final CompletableFuture<Integer> f = new CompletableFuture<>();
1458          final CompletableFuture<Integer> g = new CompletableFuture<>();
1459          final SubtractAction r = new SubtractAction();
1460  
1461 <        assertTrue(f.cancel(mayInterruptIfRunning));
1462 <        g.complete(v1);
1461 >        (fFirst ? f : g).complete(v1);
1462 >        if (!createIncomplete)
1463 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1464          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1465 +        if (createIncomplete) {
1466 +            checkIncomplete(h);
1467 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1468 +        }
1469  
1470          checkCompletedWithWrappedCancellationException(h);
1471 <        checkCancelled(f);
1471 >        checkCancelled(!fFirst ? f : g);
1472          assertEquals(0, r.invocationCount);
1473 <        checkCompletedNormally(g, v1);
1473 >        checkCompletedNormally(fFirst ? f : g, v1);
1474      }}
1475  
1476      /**
1477       * runAfterBoth result completes normally after normal
1478       * completion of sources
1479       */
1480 <    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() {
1670 <        for (ExecutionMode m : ExecutionMode.values())
1671 <        for (Integer v1 : new Integer[] { 1, null })
1672 <        for (Integer v2 : new Integer[] { 2, null })
1673 <    {
1674 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1675 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1676 <        final Noop r = new Noop();
1677 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1678 <
1679 <        g.complete(v2);
1680 <        checkIncomplete(h);
1681 <        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() {
1480 >    public void testRunAfterBoth_normalCompletion() {
1481          for (ExecutionMode m : ExecutionMode.values())
1482 +        for (boolean createIncomplete : new boolean[] { true, false })
1483 +        for (boolean fFirst : new boolean[] { true, false })
1484          for (Integer v1 : new Integer[] { 1, null })
1485          for (Integer v2 : new Integer[] { 2, null })
1486      {
1487          final CompletableFuture<Integer> f = new CompletableFuture<>();
1488          final CompletableFuture<Integer> g = new CompletableFuture<>();
1489 <        final Noop r = new Noop();
1489 >        final Noop r = new Noop(m);
1490  
1491 <        f.complete(v1);
1492 <        g.complete(v2);
1491 >        if (fFirst) f.complete(v1); else g.complete(v2);
1492 >        if (!createIncomplete)
1493 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1494          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1495 +        if (createIncomplete) {
1496 +            checkIncomplete(h);
1497 +            assertEquals(0, r.invocationCount);
1498 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1499 +        }
1500  
1501          checkCompletedNormally(h, null);
1502          assertEquals(1, r.invocationCount);
# Line 1729 | Line 1508 | public class CompletableFutureTest exten
1508       * runAfterBoth result completes exceptionally after exceptional
1509       * completion of either source
1510       */
1511 <    public void testRunAfterBoth_exceptionalCompletion1() {
1733 <        for (ExecutionMode m : ExecutionMode.values())
1734 <        for (Integer v1 : new Integer[] { 1, null })
1735 <    {
1736 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1737 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1738 <        final Noop r = new Noop();
1739 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1740 <        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<>();
1758 <        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);
1765 <
1766 <        checkCompletedWithWrappedCFException(h, ex);
1767 <        checkCompletedWithWrappedCFException(g, ex);
1768 <        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() {
1511 >    public void testRunAfterBoth_exceptionalCompletion() {
1512          for (ExecutionMode m : ExecutionMode.values())
1513 +        for (boolean createIncomplete : new boolean[] { true, false })
1514 +        for (boolean fFirst : new boolean[] { true, false })
1515          for (Integer v1 : new Integer[] { 1, null })
1516      {
1517          final CompletableFuture<Integer> f = new CompletableFuture<>();
1518          final CompletableFuture<Integer> g = new CompletableFuture<>();
1797        final Noop r = new Noop();
1519          final CFException ex = new CFException();
1520 +        final Noop r = new Noop(m);
1521  
1522 <        f.completeExceptionally(ex);
1523 <        g.complete(v1);
1522 >        (fFirst ? f : g).complete(v1);
1523 >        if (!createIncomplete)
1524 >            (!fFirst ? f : g).completeExceptionally(ex);
1525          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1526 +        if (createIncomplete) {
1527 +            checkIncomplete(h);
1528 +            (!fFirst ? f : g).completeExceptionally(ex);
1529 +        }
1530  
1531          checkCompletedWithWrappedCFException(h, ex);
1805        checkCompletedWithWrappedCFException(f, ex);
1532          assertEquals(0, r.invocationCount);
1533 <        checkCompletedNormally(g, v1);
1533 >        checkCompletedNormally(fFirst ? f : g, v1);
1534 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1535      }}
1536  
1537      /**
1538       * runAfterBoth result completes exceptionally if action does
1539       */
1540 <    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() {
1540 >    public void testRunAfterBoth_actionFailed() {
1541          for (ExecutionMode m : ExecutionMode.values())
1542 +        for (boolean fFirst : new boolean[] { true, false })
1543          for (Integer v1 : new Integer[] { 1, null })
1544          for (Integer v2 : new Integer[] { 2, null })
1545      {
1546          final CompletableFuture<Integer> f = new CompletableFuture<>();
1547          final CompletableFuture<Integer> g = new CompletableFuture<>();
1548          final FailingRunnable r = new FailingRunnable();
1840        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1549  
1550 <        g.complete(v2);
1551 <        checkIncomplete(h);
1552 <        f.complete(v1);
1550 >        CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r);
1551 >        if (fFirst) {
1552 >            f.complete(v1);
1553 >            g.complete(v2);
1554 >        } else {
1555 >            g.complete(v2);
1556 >            f.complete(v1);
1557 >        }
1558 >        CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r);
1559  
1560 <        checkCompletedWithWrappedCFException(h);
1560 >        checkCompletedWithWrappedCFException(h1);
1561 >        checkCompletedWithWrappedCFException(h2);
1562          checkCompletedNormally(f, v1);
1563          checkCompletedNormally(g, v2);
1564      }}
# Line 1851 | Line 1566 | public class CompletableFutureTest exten
1566      /**
1567       * runAfterBoth result completes exceptionally if either source cancelled
1568       */
1569 <    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() {
1875 <        for (ExecutionMode m : ExecutionMode.values())
1876 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1877 <        for (Integer v1 : new Integer[] { 1, null })
1878 <    {
1879 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1880 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1881 <        final Noop r = new Noop();
1882 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1883 <
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() {
1569 >    public void testRunAfterBoth_sourceCancelled() {
1570          for (ExecutionMode m : ExecutionMode.values())
1571          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1572 +        for (boolean createIncomplete : new boolean[] { true, false })
1573 +        for (boolean fFirst : new boolean[] { true, false })
1574          for (Integer v1 : new Integer[] { 1, null })
1575      {
1576          final CompletableFuture<Integer> f = new CompletableFuture<>();
1577          final CompletableFuture<Integer> g = new CompletableFuture<>();
1578 <        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);
1578 >        final Noop r = new Noop(m);
1579  
1907        checkCompletedWithWrappedCancellationException(h);
1908        checkCancelled(g);
1909        assertEquals(0, r.invocationCount);
1910        checkCompletedNormally(f, v1);
1911    }}
1580  
1581 <    public void testRunAfterBoth_sourceCancelled4() {
1582 <        for (ExecutionMode m : ExecutionMode.values())
1583 <        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();
1921 <
1922 <        assertTrue(f.cancel(mayInterruptIfRunning));
1923 <        g.complete(v1);
1581 >        (fFirst ? f : g).complete(v1);
1582 >        if (!createIncomplete)
1583 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1584          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1585 +        if (createIncomplete) {
1586 +            checkIncomplete(h);
1587 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1588 +        }
1589  
1590          checkCompletedWithWrappedCancellationException(h);
1591 <        checkCancelled(f);
1591 >        checkCancelled(!fFirst ? f : g);
1592          assertEquals(0, r.invocationCount);
1593 <        checkCompletedNormally(g, v1);
1593 >        checkCompletedNormally(fFirst ? f : g, v1);
1594      }}
1595  
1596      /**
1597       * applyToEither result completes normally after normal completion
1598       * of either source
1599       */
1600 <    public void testApplyToEither_normalCompletion1() {
1600 >    public void testApplyToEither_normalCompletion() {
1601          for (ExecutionMode m : ExecutionMode.values())
1602 +        for (boolean createIncomplete : new boolean[] { true, false })
1603 +        for (boolean fFirst : new boolean[] { true, false })
1604          for (Integer v1 : new Integer[] { 1, null })
1605          for (Integer v2 : new Integer[] { 2, null })
1606      {
1607          final CompletableFuture<Integer> f = new CompletableFuture<>();
1608          final CompletableFuture<Integer> g = new CompletableFuture<>();
1609          final IncFunction r = new IncFunction();
1944        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1610  
1611 <        f.complete(v1);
1612 <        checkCompletedNormally(h, inc(v1));
1613 <        g.complete(v2);
1611 >        if (!createIncomplete)
1612 >            if (fFirst) f.complete(v1); else g.complete(v2);
1613 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1614 >        if (createIncomplete) {
1615 >            checkIncomplete(h);
1616 >            assertEquals(0, r.invocationCount);
1617 >            if (fFirst) f.complete(v1); else g.complete(v2);
1618 >        }
1619 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1620 >        if (!fFirst) f.complete(v1); else g.complete(v2);
1621  
1622          checkCompletedNormally(f, v1);
1623          checkCompletedNormally(g, v2);
1624 <        checkCompletedNormally(h, inc(v1));
1624 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1625      }}
1626  
1627 <    public void testApplyToEither_normalCompletion2() {
1627 >    public void testApplyToEither_normalCompletionBothAvailable() {
1628          for (ExecutionMode m : ExecutionMode.values())
1629 +        for (boolean fFirst : new boolean[] { true, false })
1630          for (Integer v1 : new Integer[] { 1, null })
1631          for (Integer v2 : new Integer[] { 2, null })
1632      {
1633          final CompletableFuture<Integer> f = new CompletableFuture<>();
1634          final CompletableFuture<Integer> g = new CompletableFuture<>();
1635          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        }}
1636  
1637 <    public void testApplyToEither_normalCompletion3() {
1638 <        for (ExecutionMode m : ExecutionMode.values())
1639 <        for (Integer v1 : new Integer[] { 1, null })
1640 <        for (Integer v2 : new Integer[] { 2, null })
1641 <    {
1642 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1643 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1981 <        final IncFunction r = new IncFunction();
1637 >        if (fFirst) {
1638 >            f.complete(v1);
1639 >            g.complete(v2);
1640 >        } else {
1641 >            g.complete(v2);
1642 >            f.complete(v1);
1643 >        }
1644  
1983        f.complete(v1);
1984        g.complete(v2);
1645          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1646  
1647          checkCompletedNormally(f, v1);
# Line 1999 | Line 1659 | public class CompletableFutureTest exten
1659       */
1660      public void testApplyToEither_exceptionalCompletion1() {
1661          for (ExecutionMode m : ExecutionMode.values())
1662 +        for (boolean createIncomplete : new boolean[] { true, false })
1663 +        for (boolean fFirst : new boolean[] { true, false })
1664          for (Integer v1 : new Integer[] { 1, null })
1665      {
1666          final CompletableFuture<Integer> f = new CompletableFuture<>();
1667          final CompletableFuture<Integer> g = new CompletableFuture<>();
2006        final IncFunction r = new IncFunction();
2007        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1668          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<>();
1669          final IncFunction r = new IncFunction();
1670 +
1671 +        if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex);
1672          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1673 <        final CFException ex = new CFException();
1673 >        if (createIncomplete) {
1674 >            checkIncomplete(h);
1675 >            assertEquals(0, r.invocationCount);
1676 >            (fFirst ? f : g).completeExceptionally(ex);
1677 >        }
1678  
2030        g.completeExceptionally(ex);
1679          checkCompletedWithWrappedCFException(h, ex);
1680 <        f.complete(v1);
1680 >        (!fFirst ? f : g).complete(v1);
1681  
1682          assertEquals(0, r.invocationCount);
1683 <        checkCompletedNormally(f, v1);
1684 <        checkCompletedWithWrappedCFException(g, ex);
1683 >        checkCompletedNormally(!fFirst ? f : g, v1);
1684 >        checkCompletedWithWrappedCFException(fFirst ? f : g, ex);
1685          checkCompletedWithWrappedCFException(h, ex);
1686      }}
1687  
1688 <    public void testApplyToEither_exceptionalCompletion3() {
1688 >    public void testApplyToEither_exceptionalCompletion2() {
1689          for (ExecutionMode m : ExecutionMode.values())
1690 +        for (boolean reverseArgs : new boolean[] { true, false })
1691 +        for (boolean fFirst : new boolean[] { true, false })
1692          for (Integer v1 : new Integer[] { 1, null })
1693      {
1694          final CompletableFuture<Integer> f = new CompletableFuture<>();
1695          final CompletableFuture<Integer> g = new CompletableFuture<>();
1696 <        final IncFunction r = new IncFunction();
1696 >        final IncFunction r1 = new IncFunction();
1697 >        final IncFunction r2 = new IncFunction();
1698          final CFException ex = new CFException();
1699 <
1700 <        g.completeExceptionally(ex);
1701 <        f.complete(v1);
1702 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1699 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1700 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1701 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1702 >        if (fFirst) {
1703 >            f.complete(v1);
1704 >            g.completeExceptionally(ex);
1705 >        } else {
1706 >            g.completeExceptionally(ex);
1707 >            f.complete(v1);
1708 >        }
1709 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1710  
1711          // unspecified behavior
2054        Integer v;
1712          try {
1713 <            assertEquals(inc(v1), h.join());
1714 <            assertEquals(1, r.invocationCount);
1713 >            assertEquals(inc(v1), h1.join());
1714 >            assertEquals(1, r1.invocationCount);
1715          } catch (CompletionException ok) {
1716 <            checkCompletedWithWrappedCFException(h, ex);
1717 <            assertEquals(0, r.invocationCount);
1716 >            checkCompletedWithWrappedCFException(h1, ex);
1717 >            assertEquals(0, r1.invocationCount);
1718          }
1719  
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;
1720          try {
1721 <            assertEquals(inc(v1), h.join());
1722 <            assertEquals(1, r.invocationCount);
1721 >            assertEquals(inc(v1), h2.join());
1722 >            assertEquals(1, r2.invocationCount);
1723          } catch (CompletionException ok) {
1724 <            checkCompletedWithWrappedCFException(h, ex);
1725 <            assertEquals(0, r.invocationCount);
1724 >            checkCompletedWithWrappedCFException(h2, ex);
1725 >            assertEquals(0, r2.invocationCount);
1726          }
1727  
1728 <        checkCompletedWithWrappedCFException(f, ex);
1729 <        checkCompletedNormally(g, v1);
1728 >        checkCompletedWithWrappedCFException(g, ex);
1729 >        checkCompletedNormally(f, v1);
1730      }}
1731  
1732      /**
# Line 2134 | Line 1772 | public class CompletableFutureTest exten
1772      public void testApplyToEither_sourceCancelled1() {
1773          for (ExecutionMode m : ExecutionMode.values())
1774          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1775 +        for (boolean createIncomplete : new boolean[] { true, false })
1776 +        for (boolean fFirst : new boolean[] { true, false })
1777          for (Integer v1 : new Integer[] { 1, null })
1778      {
1779          final CompletableFuture<Integer> f = new CompletableFuture<>();
1780          final CompletableFuture<Integer> g = new CompletableFuture<>();
1781          final IncFunction r = new IncFunction();
2142        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2143
2144        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    }}
1782  
1783 <    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();
1783 >        if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1784          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1785 +        if (createIncomplete) {
1786 +            checkIncomplete(h);
1787 +            assertEquals(0, r.invocationCount);
1788 +            assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1789 +        }
1790  
2164        assertTrue(g.cancel(mayInterruptIfRunning));
1791          checkCompletedWithWrappedCancellationException(h);
1792 <        f.complete(v1);
1792 >        (!fFirst ? f : g).complete(v1);
1793  
2168        checkCancelled(g);
1794          assertEquals(0, r.invocationCount);
1795 <        checkCompletedNormally(f, v1);
1795 >        checkCompletedNormally(!fFirst ? f : g, v1);
1796 >        checkCancelled(fFirst ? f : g);
1797          checkCompletedWithWrappedCancellationException(h);
1798      }}
1799  
1800 <    public void testApplyToEither_sourceCancelled3() {
1800 >    public void testApplyToEither_sourceCancelled2() {
1801          for (ExecutionMode m : ExecutionMode.values())
1802          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1803 +        for (boolean reverseArgs : new boolean[] { true, false })
1804 +        for (boolean fFirst : new boolean[] { true, false })
1805          for (Integer v1 : new Integer[] { 1, null })
1806      {
1807          final CompletableFuture<Integer> f = new CompletableFuture<>();
1808          final CompletableFuture<Integer> g = new CompletableFuture<>();
1809 <        final IncFunction r = new IncFunction();
1809 >        final IncFunction r1 = new IncFunction();
1810 >        final IncFunction r2 = new IncFunction();
1811 >        final CFException ex = new CFException();
1812 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1813 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1814  
1815 <        assertTrue(g.cancel(mayInterruptIfRunning));
1816 <        f.complete(v1);
1817 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1815 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1816 >        if (fFirst) {
1817 >            f.complete(v1);
1818 >            assertTrue(g.cancel(mayInterruptIfRunning));
1819 >        } else {
1820 >            assertTrue(g.cancel(mayInterruptIfRunning));
1821 >            f.complete(v1);
1822 >        }
1823 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1824  
1825          // unspecified behavior
2188        Integer v;
1826          try {
1827 <            assertEquals(inc(v1), h.join());
1828 <            assertEquals(1, r.invocationCount);
1827 >            assertEquals(inc(v1), h1.join());
1828 >            assertEquals(1, r1.invocationCount);
1829          } catch (CompletionException ok) {
1830 <            checkCompletedWithWrappedCancellationException(h);
1831 <            assertEquals(0, r.invocationCount);
1830 >            checkCompletedWithWrappedCancellationException(h1);
1831 >            assertEquals(0, r1.invocationCount);
1832          }
1833  
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;
1834          try {
1835 <            assertEquals(inc(v1), h.join());
1836 <            assertEquals(1, r.invocationCount);
1835 >            assertEquals(inc(v1), h2.join());
1836 >            assertEquals(1, r2.invocationCount);
1837          } catch (CompletionException ok) {
1838 <            checkCompletedWithWrappedCancellationException(h);
1839 <            assertEquals(0, r.invocationCount);
1838 >            checkCompletedWithWrappedCancellationException(h2);
1839 >            assertEquals(0, r2.invocationCount);
1840          }
1841  
1842 <        checkCancelled(f);
1843 <        checkCompletedNormally(g, v1);
1842 >        checkCancelled(g);
1843 >        checkCompletedNormally(f, v1);
1844      }}
1845  
1846      /**
# Line 2538 | Line 2156 | public class CompletableFutureTest exten
2156      {
2157          final CompletableFuture<Integer> f = new CompletableFuture<>();
2158          final CompletableFuture<Integer> g = new CompletableFuture<>();
2159 <        final Noop r = new Noop();
2159 >        final Noop r = new Noop(m);
2160          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2161  
2162          f.complete(v1);
# Line 2559 | Line 2177 | public class CompletableFutureTest exten
2177      {
2178          final CompletableFuture<Integer> f = new CompletableFuture<>();
2179          final CompletableFuture<Integer> g = new CompletableFuture<>();
2180 <        final Noop r = new Noop();
2180 >        final Noop r = new Noop(m);
2181          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2182  
2183          g.complete(v2);
# Line 2580 | Line 2198 | public class CompletableFutureTest exten
2198      {
2199          final CompletableFuture<Integer> f = new CompletableFuture<>();
2200          final CompletableFuture<Integer> g = new CompletableFuture<>();
2201 <        final Noop r = new Noop();
2201 >        final Noop r = new Noop(m);
2202  
2203          f.complete(v1);
2204          g.complete(v2);
# Line 2602 | Line 2220 | public class CompletableFutureTest exten
2220      {
2221          final CompletableFuture<Integer> f = new CompletableFuture<>();
2222          final CompletableFuture<Integer> g = new CompletableFuture<>();
2223 <        final Noop r = new Noop();
2223 >        final Noop r = new Noop(m);
2224          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2225          final CFException ex = new CFException();
2226  
# Line 2622 | Line 2240 | public class CompletableFutureTest exten
2240      {
2241          final CompletableFuture<Integer> f = new CompletableFuture<>();
2242          final CompletableFuture<Integer> g = new CompletableFuture<>();
2243 <        final Noop r = new Noop();
2243 >        final Noop r = new Noop(m);
2244          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2245          final CFException ex = new CFException();
2246  
# Line 2642 | Line 2260 | public class CompletableFutureTest exten
2260      {
2261          final CompletableFuture<Integer> f = new CompletableFuture<>();
2262          final CompletableFuture<Integer> g = new CompletableFuture<>();
2263 <        final Noop r = new Noop();
2263 >        final Noop r = new Noop(m);
2264          final CFException ex = new CFException();
2265  
2266          g.completeExceptionally(ex);
# Line 2669 | Line 2287 | public class CompletableFutureTest exten
2287      {
2288          final CompletableFuture<Integer> f = new CompletableFuture<>();
2289          final CompletableFuture<Integer> g = new CompletableFuture<>();
2290 <        final Noop r = new Noop();
2290 >        final Noop r = new Noop(m);
2291          final CFException ex = new CFException();
2292  
2293          f.completeExceptionally(ex);
# Line 2737 | Line 2355 | public class CompletableFutureTest exten
2355      {
2356          final CompletableFuture<Integer> f = new CompletableFuture<>();
2357          final CompletableFuture<Integer> g = new CompletableFuture<>();
2358 <        final Noop r = new Noop();
2358 >        final Noop r = new Noop(m);
2359          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2360  
2361          assertTrue(f.cancel(mayInterruptIfRunning));
# Line 2757 | Line 2375 | public class CompletableFutureTest exten
2375      {
2376          final CompletableFuture<Integer> f = new CompletableFuture<>();
2377          final CompletableFuture<Integer> g = new CompletableFuture<>();
2378 <        final Noop r = new Noop();
2378 >        final Noop r = new Noop(m);
2379          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2380  
2381          assertTrue(g.cancel(mayInterruptIfRunning));
# Line 2777 | Line 2395 | public class CompletableFutureTest exten
2395      {
2396          final CompletableFuture<Integer> f = new CompletableFuture<>();
2397          final CompletableFuture<Integer> g = new CompletableFuture<>();
2398 <        final Noop r = new Noop();
2398 >        final Noop r = new Noop(m);
2399  
2400          assertTrue(g.cancel(mayInterruptIfRunning));
2401          f.complete(v1);
# Line 2804 | Line 2422 | public class CompletableFutureTest exten
2422      {
2423          final CompletableFuture<Integer> f = new CompletableFuture<>();
2424          final CompletableFuture<Integer> g = new CompletableFuture<>();
2425 <        final Noop r = new Noop();
2425 >        final Noop r = new Noop(m);
2426  
2427          assertTrue(f.cancel(mayInterruptIfRunning));
2428          g.complete(v1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines