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.78 by jsr166, Sat Jun 7 23:32:17 2014 UTC vs.
Revision 1.79 by jsr166, Mon Jun 16 17:08:15 2014 UTC

# Line 1529 | Line 1529 | public class CompletableFutureTest exten
1529       */
1530      public void testThenCombine_normalCompletion() {
1531          for (ExecutionMode m : ExecutionMode.values())
1532        for (boolean createIncomplete : new boolean[] { true, false })
1532          for (boolean fFirst : new boolean[] { true, false })
1533          for (Integer v1 : new Integer[] { 1, null })
1534          for (Integer v2 : new Integer[] { 2, null })
1535      {
1536          final CompletableFuture<Integer> f = new CompletableFuture<>();
1537          final CompletableFuture<Integer> g = new CompletableFuture<>();
1538 <        final SubtractFunction r = new SubtractFunction(m);
1539 <
1540 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1541 <        if (!createIncomplete)
1542 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1543 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1544 <        if (createIncomplete) {
1545 <            checkIncomplete(h);
1546 <            r.assertNotInvoked();
1547 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1548 <        }
1549 <
1550 <        checkCompletedNormally(h, subtract(v1, v2));
1538 >        final SubtractFunction r1 = new SubtractFunction(m);
1539 >        final SubtractFunction r2 = new SubtractFunction(m);
1540 >        final SubtractFunction r3 = new SubtractFunction(m);
1541 >
1542 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1543 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1544 >        final Integer w1 =  fFirst ? v1 : v2;
1545 >        final Integer w2 = !fFirst ? v1 : v2;
1546 >
1547 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1548 >        assertTrue(fst.complete(w1));
1549 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1550 >        checkIncomplete(h1);
1551 >        checkIncomplete(h2);
1552 >        r1.assertNotInvoked();
1553 >        r2.assertNotInvoked();
1554 >        assertTrue(snd.complete(w2));
1555 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1556 >
1557 >        checkCompletedNormally(h1, subtract(v1, v2));
1558 >        checkCompletedNormally(h2, subtract(v1, v2));
1559 >        checkCompletedNormally(h3, subtract(v1, v2));
1560 >        r1.assertValue(subtract(v1, v2));
1561 >        r2.assertValue(subtract(v1, v2));
1562 >        r3.assertValue(subtract(v1, v2));
1563          checkCompletedNormally(f, v1);
1564          checkCompletedNormally(g, v2);
1554        r.assertValue(subtract(v1, v2));
1565      }}
1566  
1567      /**
1568       * thenCombine result completes exceptionally after exceptional
1569       * completion of either source
1570       */
1571 <    public void testThenCombine_exceptionalCompletion() {
1571 >    public void testThenCombine_exceptionalCompletion() throws Throwable {
1572          for (ExecutionMode m : ExecutionMode.values())
1563        for (boolean createIncomplete : new boolean[] { true, false })
1573          for (boolean fFirst : new boolean[] { true, false })
1574 +        for (boolean failFirst : new boolean[] { true, false })
1575          for (Integer v1 : new Integer[] { 1, null })
1576      {
1577          final CompletableFuture<Integer> f = new CompletableFuture<>();
1578          final CompletableFuture<Integer> g = new CompletableFuture<>();
1579          final CFException ex = new CFException();
1580 <        final SubtractFunction r = new SubtractFunction(m);
1581 <
1582 <        assertTrue((fFirst ? f : g).complete(v1));
1583 <        if (!createIncomplete)
1584 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1585 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1586 <        if (createIncomplete) {
1587 <            checkIncomplete(h);
1588 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1589 <        }
1590 <
1591 <        checkCompletedWithWrappedException(h, ex);
1592 <        r.assertNotInvoked();
1593 <        checkCompletedNormally(fFirst ? f : g, v1);
1594 <        checkCompletedExceptionally(!fFirst ? f : g, ex);
1580 >        final SubtractFunction r1 = new SubtractFunction(m);
1581 >        final SubtractFunction r2 = new SubtractFunction(m);
1582 >        final SubtractFunction r3 = new SubtractFunction(m);
1583 >
1584 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1585 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1586 >        final Callable<Boolean> complete1 = failFirst ?
1587 >            () -> fst.completeExceptionally(ex) :
1588 >            () -> fst.complete(v1);
1589 >        final Callable<Boolean> complete2 = failFirst ?
1590 >            () -> snd.complete(v1) :
1591 >            () -> snd.completeExceptionally(ex);
1592 >
1593 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1594 >        assertTrue(complete1.call());
1595 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1596 >        checkIncomplete(h1);
1597 >        checkIncomplete(h2);
1598 >        assertTrue(complete2.call());
1599 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1600 >
1601 >        checkCompletedWithWrappedException(h1, ex);
1602 >        checkCompletedWithWrappedException(h2, ex);
1603 >        checkCompletedWithWrappedException(h3, ex);
1604 >        r1.assertNotInvoked();
1605 >        r2.assertNotInvoked();
1606 >        r3.assertNotInvoked();
1607 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1608 >        checkCompletedExceptionally(failFirst ? fst : snd, ex);
1609      }}
1610  
1611      /**
1612       * thenCombine result completes exceptionally if either source cancelled
1613       */
1614 <    public void testThenCombine_sourceCancelled() {
1614 >    public void testThenCombine_sourceCancelled() throws Throwable {
1615          for (ExecutionMode m : ExecutionMode.values())
1616          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1593        for (boolean createIncomplete : new boolean[] { true, false })
1617          for (boolean fFirst : new boolean[] { true, false })
1618 +        for (boolean failFirst : new boolean[] { true, false })
1619          for (Integer v1 : new Integer[] { 1, null })
1620      {
1621          final CompletableFuture<Integer> f = new CompletableFuture<>();
1622          final CompletableFuture<Integer> g = new CompletableFuture<>();
1623 <        final SubtractFunction r = new SubtractFunction(m);
1624 <
1625 <        assertTrue((fFirst ? f : g).complete(v1));
1626 <        if (!createIncomplete)
1627 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1628 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1629 <        if (createIncomplete) {
1630 <            checkIncomplete(h);
1631 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1632 <        }
1633 <
1634 <        checkCompletedWithWrappedCancellationException(h);
1635 <        checkCancelled(!fFirst ? f : g);
1636 <        r.assertNotInvoked();
1637 <        checkCompletedNormally(fFirst ? f : g, v1);
1623 >        final SubtractFunction r1 = new SubtractFunction(m);
1624 >        final SubtractFunction r2 = new SubtractFunction(m);
1625 >        final SubtractFunction r3 = new SubtractFunction(m);
1626 >
1627 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1628 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1629 >        final Callable<Boolean> complete1 = failFirst ?
1630 >            () -> fst.cancel(mayInterruptIfRunning) :
1631 >            () -> fst.complete(v1);
1632 >        final Callable<Boolean> complete2 = failFirst ?
1633 >            () -> snd.complete(v1) :
1634 >            () -> snd.cancel(mayInterruptIfRunning);
1635 >
1636 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1637 >        assertTrue(complete1.call());
1638 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1639 >        checkIncomplete(h1);
1640 >        checkIncomplete(h2);
1641 >        assertTrue(complete2.call());
1642 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1643 >
1644 >        checkCompletedWithWrappedCancellationException(h1);
1645 >        checkCompletedWithWrappedCancellationException(h2);
1646 >        checkCompletedWithWrappedCancellationException(h3);
1647 >        r1.assertNotInvoked();
1648 >        r2.assertNotInvoked();
1649 >        r3.assertNotInvoked();
1650 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1651 >        checkCancelled(failFirst ? fst : snd);
1652      }}
1653  
1654      /**
# Line 1624 | Line 1662 | public class CompletableFutureTest exten
1662      {
1663          final CompletableFuture<Integer> f = new CompletableFuture<>();
1664          final CompletableFuture<Integer> g = new CompletableFuture<>();
1665 <        final FailingBiFunction r = new FailingBiFunction(m);
1666 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1667 <
1668 <        assertTrue( fFirst ? f.complete(v1) : g.complete(v2));
1669 <        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1670 <
1671 <        checkCompletedWithWrappedCFException(h);
1665 >        final FailingBiFunction r1 = new FailingBiFunction(m);
1666 >        final FailingBiFunction r2 = new FailingBiFunction(m);
1667 >        final FailingBiFunction r3 = new FailingBiFunction(m);
1668 >
1669 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1670 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1671 >        final Integer w1 =  fFirst ? v1 : v2;
1672 >        final Integer w2 = !fFirst ? v1 : v2;
1673 >
1674 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1675 >        assertTrue(fst.complete(w1));
1676 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1677 >        assertTrue(snd.complete(w2));
1678 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1679 >
1680 >        checkCompletedWithWrappedCFException(h1);
1681 >        checkCompletedWithWrappedCFException(h2);
1682 >        checkCompletedWithWrappedCFException(h3);
1683          checkCompletedNormally(f, v1);
1684          checkCompletedNormally(g, v2);
1685      }}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines