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.79 by jsr166, Mon Jun 16 17:08:15 2014 UTC vs.
Revision 1.80 by jsr166, Mon Jun 16 17:29:03 2014 UTC

# Line 1690 | Line 1690 | public class CompletableFutureTest exten
1690       */
1691      public void testThenAcceptBoth_normalCompletion() {
1692          for (ExecutionMode m : ExecutionMode.values())
1693        for (boolean createIncomplete : new boolean[] { true, false })
1693          for (boolean fFirst : new boolean[] { true, false })
1694          for (Integer v1 : new Integer[] { 1, null })
1695          for (Integer v2 : new Integer[] { 2, null })
1696      {
1697          final CompletableFuture<Integer> f = new CompletableFuture<>();
1698          final CompletableFuture<Integer> g = new CompletableFuture<>();
1699 <        final SubtractAction r = new SubtractAction(m);
1700 <
1701 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1702 <        if (!createIncomplete)
1703 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1704 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1705 <        if (createIncomplete) {
1706 <            checkIncomplete(h);
1707 <            r.assertNotInvoked();
1708 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1709 <        }
1710 <
1711 <        checkCompletedNormally(h, null);
1712 <        r.assertValue(subtract(v1, v2));
1699 >        final SubtractAction r1 = new SubtractAction(m);
1700 >        final SubtractAction r2 = new SubtractAction(m);
1701 >        final SubtractAction r3 = new SubtractAction(m);
1702 >
1703 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1704 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1705 >        final Integer w1 =  fFirst ? v1 : v2;
1706 >        final Integer w2 = !fFirst ? v1 : v2;
1707 >
1708 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1709 >        assertTrue(fst.complete(w1));
1710 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1711 >        checkIncomplete(h1);
1712 >        checkIncomplete(h2);
1713 >        r1.assertNotInvoked();
1714 >        r2.assertNotInvoked();
1715 >        assertTrue(snd.complete(w2));
1716 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1717 >
1718 >        checkCompletedNormally(h1, null);
1719 >        checkCompletedNormally(h2, null);
1720 >        checkCompletedNormally(h3, null);
1721 >        r1.assertValue(subtract(v1, v2));
1722 >        r2.assertValue(subtract(v1, v2));
1723 >        r3.assertValue(subtract(v1, v2));
1724          checkCompletedNormally(f, v1);
1725          checkCompletedNormally(g, v2);
1726      }}
# Line 1719 | Line 1729 | public class CompletableFutureTest exten
1729       * thenAcceptBoth result completes exceptionally after exceptional
1730       * completion of either source
1731       */
1732 <    public void testThenAcceptBoth_exceptionalCompletion() {
1732 >    public void testThenAcceptBoth_exceptionalCompletion() throws Throwable {
1733          for (ExecutionMode m : ExecutionMode.values())
1724        for (boolean createIncomplete : new boolean[] { true, false })
1734          for (boolean fFirst : new boolean[] { true, false })
1735 +        for (boolean failFirst : new boolean[] { true, false })
1736          for (Integer v1 : new Integer[] { 1, null })
1737      {
1738          final CompletableFuture<Integer> f = new CompletableFuture<>();
1739          final CompletableFuture<Integer> g = new CompletableFuture<>();
1740          final CFException ex = new CFException();
1741 <        final SubtractAction r = new SubtractAction(m);
1742 <
1743 <        assertTrue((fFirst ? f : g).complete(v1));
1744 <        if (!createIncomplete)
1745 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1746 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1747 <        if (createIncomplete) {
1748 <            checkIncomplete(h);
1749 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1750 <        }
1751 <
1752 <        checkCompletedWithWrappedException(h, ex);
1753 <        r.assertNotInvoked();
1754 <        checkCompletedNormally(fFirst ? f : g, v1);
1755 <        checkCompletedExceptionally(!fFirst ? f : g, ex);
1741 >        final SubtractAction r1 = new SubtractAction(m);
1742 >        final SubtractAction r2 = new SubtractAction(m);
1743 >        final SubtractAction r3 = new SubtractAction(m);
1744 >
1745 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1746 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1747 >        final Callable<Boolean> complete1 = failFirst ?
1748 >            () -> fst.completeExceptionally(ex) :
1749 >            () -> fst.complete(v1);
1750 >        final Callable<Boolean> complete2 = failFirst ?
1751 >            () -> snd.complete(v1) :
1752 >            () -> snd.completeExceptionally(ex);
1753 >
1754 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1755 >        assertTrue(complete1.call());
1756 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1757 >        checkIncomplete(h1);
1758 >        checkIncomplete(h2);
1759 >        assertTrue(complete2.call());
1760 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1761 >
1762 >        checkCompletedWithWrappedException(h1, ex);
1763 >        checkCompletedWithWrappedException(h2, ex);
1764 >        checkCompletedWithWrappedException(h3, ex);
1765 >        r1.assertNotInvoked();
1766 >        r2.assertNotInvoked();
1767 >        r3.assertNotInvoked();
1768 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1769 >        checkCompletedExceptionally(failFirst ? fst : snd, ex);
1770      }}
1771  
1772      /**
1773       * thenAcceptBoth result completes exceptionally if either source cancelled
1774       */
1775 <    public void testThenAcceptBoth_sourceCancelled() {
1775 >    public void testThenAcceptBoth_sourceCancelled() throws Throwable {
1776          for (ExecutionMode m : ExecutionMode.values())
1777          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1754        for (boolean createIncomplete : new boolean[] { true, false })
1778          for (boolean fFirst : new boolean[] { true, false })
1779 +        for (boolean failFirst : new boolean[] { true, false })
1780          for (Integer v1 : new Integer[] { 1, null })
1781      {
1782          final CompletableFuture<Integer> f = new CompletableFuture<>();
1783          final CompletableFuture<Integer> g = new CompletableFuture<>();
1784 <        final SubtractAction r = new SubtractAction(m);
1785 <
1786 <        assertTrue((fFirst ? f : g).complete(v1));
1787 <        if (!createIncomplete)
1788 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1789 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1790 <        if (createIncomplete) {
1791 <            checkIncomplete(h);
1792 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1793 <        }
1794 <
1795 <        checkCompletedWithWrappedCancellationException(h);
1796 <        checkCancelled(!fFirst ? f : g);
1797 <        r.assertNotInvoked();
1798 <        checkCompletedNormally(fFirst ? f : g, v1);
1784 >        final SubtractAction r1 = new SubtractAction(m);
1785 >        final SubtractAction r2 = new SubtractAction(m);
1786 >        final SubtractAction r3 = new SubtractAction(m);
1787 >
1788 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1789 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1790 >        final Callable<Boolean> complete1 = failFirst ?
1791 >            () -> fst.cancel(mayInterruptIfRunning) :
1792 >            () -> fst.complete(v1);
1793 >        final Callable<Boolean> complete2 = failFirst ?
1794 >            () -> snd.complete(v1) :
1795 >            () -> snd.cancel(mayInterruptIfRunning);
1796 >
1797 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1798 >        assertTrue(complete1.call());
1799 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1800 >        checkIncomplete(h1);
1801 >        checkIncomplete(h2);
1802 >        assertTrue(complete2.call());
1803 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1804 >
1805 >        checkCompletedWithWrappedCancellationException(h1);
1806 >        checkCompletedWithWrappedCancellationException(h2);
1807 >        checkCompletedWithWrappedCancellationException(h3);
1808 >        r1.assertNotInvoked();
1809 >        r2.assertNotInvoked();
1810 >        r3.assertNotInvoked();
1811 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1812 >        checkCancelled(failFirst ? fst : snd);
1813      }}
1814  
1815      /**
# Line 1785 | Line 1823 | public class CompletableFutureTest exten
1823      {
1824          final CompletableFuture<Integer> f = new CompletableFuture<>();
1825          final CompletableFuture<Integer> g = new CompletableFuture<>();
1826 <        final FailingBiConsumer r = new FailingBiConsumer(m);
1827 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1828 <
1829 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1830 <        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1831 <
1832 <        checkCompletedWithWrappedCFException(h);
1826 >        final FailingBiConsumer r1 = new FailingBiConsumer(m);
1827 >        final FailingBiConsumer r2 = new FailingBiConsumer(m);
1828 >        final FailingBiConsumer r3 = new FailingBiConsumer(m);
1829 >
1830 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1831 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1832 >        final Integer w1 =  fFirst ? v1 : v2;
1833 >        final Integer w2 = !fFirst ? v1 : v2;
1834 >
1835 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1836 >        assertTrue(fst.complete(w1));
1837 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1838 >        assertTrue(snd.complete(w2));
1839 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1840 >
1841 >        checkCompletedWithWrappedCFException(h1);
1842 >        checkCompletedWithWrappedCFException(h2);
1843 >        checkCompletedWithWrappedCFException(h3);
1844          checkCompletedNormally(f, v1);
1845          checkCompletedNormally(g, v2);
1846      }}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines