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.83 by jsr166, Mon Jun 16 20:16:32 2014 UTC

# Line 1680 | Line 1680 | public class CompletableFutureTest exten
1680          checkCompletedWithWrappedCFException(h1);
1681          checkCompletedWithWrappedCFException(h2);
1682          checkCompletedWithWrappedCFException(h3);
1683 +        r1.assertInvoked();
1684 +        r2.assertInvoked();
1685 +        r3.assertInvoked();
1686          checkCompletedNormally(f, v1);
1687          checkCompletedNormally(g, v2);
1688      }}
# Line 1690 | Line 1693 | public class CompletableFutureTest exten
1693       */
1694      public void testThenAcceptBoth_normalCompletion() {
1695          for (ExecutionMode m : ExecutionMode.values())
1693        for (boolean createIncomplete : new boolean[] { true, false })
1696          for (boolean fFirst : new boolean[] { true, false })
1697          for (Integer v1 : new Integer[] { 1, null })
1698          for (Integer v2 : new Integer[] { 2, null })
1699      {
1700          final CompletableFuture<Integer> f = new CompletableFuture<>();
1701          final CompletableFuture<Integer> g = new CompletableFuture<>();
1702 <        final SubtractAction r = new SubtractAction(m);
1703 <
1704 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1705 <        if (!createIncomplete)
1706 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1707 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1708 <        if (createIncomplete) {
1709 <            checkIncomplete(h);
1710 <            r.assertNotInvoked();
1711 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1712 <        }
1702 >        final SubtractAction r1 = new SubtractAction(m);
1703 >        final SubtractAction r2 = new SubtractAction(m);
1704 >        final SubtractAction r3 = new SubtractAction(m);
1705 >
1706 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1707 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1708 >        final Integer w1 =  fFirst ? v1 : v2;
1709 >        final Integer w2 = !fFirst ? v1 : v2;
1710 >
1711 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1712 >        assertTrue(fst.complete(w1));
1713 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1714 >        checkIncomplete(h1);
1715 >        checkIncomplete(h2);
1716 >        r1.assertNotInvoked();
1717 >        r2.assertNotInvoked();
1718 >        assertTrue(snd.complete(w2));
1719 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1720  
1721 <        checkCompletedNormally(h, null);
1722 <        r.assertValue(subtract(v1, v2));
1721 >        checkCompletedNormally(h1, null);
1722 >        checkCompletedNormally(h2, null);
1723 >        checkCompletedNormally(h3, null);
1724 >        r1.assertValue(subtract(v1, v2));
1725 >        r2.assertValue(subtract(v1, v2));
1726 >        r3.assertValue(subtract(v1, v2));
1727          checkCompletedNormally(f, v1);
1728          checkCompletedNormally(g, v2);
1729      }}
# Line 1719 | Line 1732 | public class CompletableFutureTest exten
1732       * thenAcceptBoth result completes exceptionally after exceptional
1733       * completion of either source
1734       */
1735 <    public void testThenAcceptBoth_exceptionalCompletion() {
1735 >    public void testThenAcceptBoth_exceptionalCompletion() throws Throwable {
1736          for (ExecutionMode m : ExecutionMode.values())
1724        for (boolean createIncomplete : new boolean[] { true, false })
1737          for (boolean fFirst : new boolean[] { true, false })
1738 +        for (boolean failFirst : new boolean[] { true, false })
1739          for (Integer v1 : new Integer[] { 1, null })
1740      {
1741          final CompletableFuture<Integer> f = new CompletableFuture<>();
1742          final CompletableFuture<Integer> g = new CompletableFuture<>();
1743          final CFException ex = new CFException();
1744 <        final SubtractAction r = new SubtractAction(m);
1745 <
1746 <        assertTrue((fFirst ? f : g).complete(v1));
1747 <        if (!createIncomplete)
1748 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1749 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1750 <        if (createIncomplete) {
1751 <            checkIncomplete(h);
1752 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1753 <        }
1744 >        final SubtractAction r1 = new SubtractAction(m);
1745 >        final SubtractAction r2 = new SubtractAction(m);
1746 >        final SubtractAction r3 = new SubtractAction(m);
1747 >
1748 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1749 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1750 >        final Callable<Boolean> complete1 = failFirst ?
1751 >            () -> fst.completeExceptionally(ex) :
1752 >            () -> fst.complete(v1);
1753 >        final Callable<Boolean> complete2 = failFirst ?
1754 >            () -> snd.complete(v1) :
1755 >            () -> snd.completeExceptionally(ex);
1756 >
1757 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1758 >        assertTrue(complete1.call());
1759 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1760 >        checkIncomplete(h1);
1761 >        checkIncomplete(h2);
1762 >        assertTrue(complete2.call());
1763 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1764  
1765 <        checkCompletedWithWrappedException(h, ex);
1766 <        r.assertNotInvoked();
1767 <        checkCompletedNormally(fFirst ? f : g, v1);
1768 <        checkCompletedExceptionally(!fFirst ? f : g, ex);
1765 >        checkCompletedWithWrappedException(h1, ex);
1766 >        checkCompletedWithWrappedException(h2, ex);
1767 >        checkCompletedWithWrappedException(h3, ex);
1768 >        r1.assertNotInvoked();
1769 >        r2.assertNotInvoked();
1770 >        r3.assertNotInvoked();
1771 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1772 >        checkCompletedExceptionally(failFirst ? fst : snd, ex);
1773      }}
1774  
1775      /**
1776       * thenAcceptBoth result completes exceptionally if either source cancelled
1777       */
1778 <    public void testThenAcceptBoth_sourceCancelled() {
1778 >    public void testThenAcceptBoth_sourceCancelled() throws Throwable {
1779          for (ExecutionMode m : ExecutionMode.values())
1780          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1754        for (boolean createIncomplete : new boolean[] { true, false })
1781          for (boolean fFirst : new boolean[] { true, false })
1782 +        for (boolean failFirst : new boolean[] { true, false })
1783          for (Integer v1 : new Integer[] { 1, null })
1784      {
1785          final CompletableFuture<Integer> f = new CompletableFuture<>();
1786          final CompletableFuture<Integer> g = new CompletableFuture<>();
1787 <        final SubtractAction r = new SubtractAction(m);
1787 >        final SubtractAction r1 = new SubtractAction(m);
1788 >        final SubtractAction r2 = new SubtractAction(m);
1789 >        final SubtractAction r3 = new SubtractAction(m);
1790  
1791 <        assertTrue((fFirst ? f : g).complete(v1));
1792 <        if (!createIncomplete)
1793 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1794 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1795 <        if (createIncomplete) {
1796 <            checkIncomplete(h);
1797 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1798 <        }
1791 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1792 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1793 >        final Callable<Boolean> complete1 = failFirst ?
1794 >            () -> fst.cancel(mayInterruptIfRunning) :
1795 >            () -> fst.complete(v1);
1796 >        final Callable<Boolean> complete2 = failFirst ?
1797 >            () -> snd.complete(v1) :
1798 >            () -> snd.cancel(mayInterruptIfRunning);
1799  
1800 <        checkCompletedWithWrappedCancellationException(h);
1801 <        checkCancelled(!fFirst ? f : g);
1802 <        r.assertNotInvoked();
1803 <        checkCompletedNormally(fFirst ? f : g, v1);
1800 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1801 >        assertTrue(complete1.call());
1802 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1803 >        checkIncomplete(h1);
1804 >        checkIncomplete(h2);
1805 >        assertTrue(complete2.call());
1806 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1807 >
1808 >        checkCompletedWithWrappedCancellationException(h1);
1809 >        checkCompletedWithWrappedCancellationException(h2);
1810 >        checkCompletedWithWrappedCancellationException(h3);
1811 >        r1.assertNotInvoked();
1812 >        r2.assertNotInvoked();
1813 >        r3.assertNotInvoked();
1814 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1815 >        checkCancelled(failFirst ? fst : snd);
1816      }}
1817  
1818      /**
# Line 1785 | Line 1826 | public class CompletableFutureTest exten
1826      {
1827          final CompletableFuture<Integer> f = new CompletableFuture<>();
1828          final CompletableFuture<Integer> g = new CompletableFuture<>();
1829 <        final FailingBiConsumer r = new FailingBiConsumer(m);
1830 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1831 <
1832 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1833 <        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1829 >        final FailingBiConsumer r1 = new FailingBiConsumer(m);
1830 >        final FailingBiConsumer r2 = new FailingBiConsumer(m);
1831 >        final FailingBiConsumer r3 = new FailingBiConsumer(m);
1832 >
1833 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1834 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1835 >        final Integer w1 =  fFirst ? v1 : v2;
1836 >        final Integer w2 = !fFirst ? v1 : v2;
1837 >
1838 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1839 >        assertTrue(fst.complete(w1));
1840 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1841 >        assertTrue(snd.complete(w2));
1842 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1843  
1844 <        checkCompletedWithWrappedCFException(h);
1844 >        checkCompletedWithWrappedCFException(h1);
1845 >        checkCompletedWithWrappedCFException(h2);
1846 >        checkCompletedWithWrappedCFException(h3);
1847 >        r1.assertInvoked();
1848 >        r2.assertInvoked();
1849 >        r3.assertInvoked();
1850          checkCompletedNormally(f, v1);
1851          checkCompletedNormally(g, v2);
1852      }}
# Line 1802 | Line 1857 | public class CompletableFutureTest exten
1857       */
1858      public void testRunAfterBoth_normalCompletion() {
1859          for (ExecutionMode m : ExecutionMode.values())
1805        for (boolean createIncomplete : new boolean[] { true, false })
1860          for (boolean fFirst : new boolean[] { true, false })
1861          for (Integer v1 : new Integer[] { 1, null })
1862          for (Integer v2 : new Integer[] { 2, null })
1863      {
1864          final CompletableFuture<Integer> f = new CompletableFuture<>();
1865          final CompletableFuture<Integer> g = new CompletableFuture<>();
1866 <        final Noop r = new Noop(m);
1867 <
1868 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1869 <        if (!createIncomplete)
1870 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1871 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1872 <        if (createIncomplete) {
1873 <            checkIncomplete(h);
1874 <            r.assertNotInvoked();
1875 <            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1876 <        }
1866 >        final Noop r1 = new Noop(m);
1867 >        final Noop r2 = new Noop(m);
1868 >        final Noop r3 = new Noop(m);
1869 >
1870 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1871 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1872 >        final Integer w1 =  fFirst ? v1 : v2;
1873 >        final Integer w2 = !fFirst ? v1 : v2;
1874 >
1875 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
1876 >        assertTrue(fst.complete(w1));
1877 >        final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
1878 >        checkIncomplete(h1);
1879 >        checkIncomplete(h2);
1880 >        r1.assertNotInvoked();
1881 >        r2.assertNotInvoked();
1882 >        assertTrue(snd.complete(w2));
1883 >        final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3);
1884  
1885 <        checkCompletedNormally(h, null);
1886 <        r.assertInvoked();
1885 >        checkCompletedNormally(h1, null);
1886 >        checkCompletedNormally(h2, null);
1887 >        checkCompletedNormally(h3, null);
1888 >        r1.assertInvoked();
1889 >        r2.assertInvoked();
1890 >        r3.assertInvoked();
1891          checkCompletedNormally(f, v1);
1892          checkCompletedNormally(g, v2);
1893      }}
# Line 1831 | Line 1896 | public class CompletableFutureTest exten
1896       * runAfterBoth result completes exceptionally after exceptional
1897       * completion of either source
1898       */
1899 <    public void testRunAfterBoth_exceptionalCompletion() {
1899 >    public void testRunAfterBoth_exceptionalCompletion() throws Throwable {
1900          for (ExecutionMode m : ExecutionMode.values())
1836        for (boolean createIncomplete : new boolean[] { true, false })
1901          for (boolean fFirst : new boolean[] { true, false })
1902 +        for (boolean failFirst : new boolean[] { true, false })
1903          for (Integer v1 : new Integer[] { 1, null })
1904      {
1905          final CompletableFuture<Integer> f = new CompletableFuture<>();
1906          final CompletableFuture<Integer> g = new CompletableFuture<>();
1907          final CFException ex = new CFException();
1908 <        final Noop r = new Noop(m);
1909 <
1910 <        assertTrue((fFirst ? f : g).complete(v1));
1911 <        if (!createIncomplete)
1912 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1913 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1914 <        if (createIncomplete) {
1915 <            checkIncomplete(h);
1916 <            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1917 <        }
1908 >        final Noop r1 = new Noop(m);
1909 >        final Noop r2 = new Noop(m);
1910 >        final Noop r3 = new Noop(m);
1911 >
1912 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1913 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1914 >        final Callable<Boolean> complete1 = failFirst ?
1915 >            () -> fst.completeExceptionally(ex) :
1916 >            () -> fst.complete(v1);
1917 >        final Callable<Boolean> complete2 = failFirst ?
1918 >            () -> snd.complete(v1) :
1919 >            () -> snd.completeExceptionally(ex);
1920 >
1921 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
1922 >        assertTrue(complete1.call());
1923 >        final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
1924 >        checkIncomplete(h1);
1925 >        checkIncomplete(h2);
1926 >        assertTrue(complete2.call());
1927 >        final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3);
1928  
1929 <        checkCompletedWithWrappedException(h, ex);
1930 <        r.assertNotInvoked();
1931 <        checkCompletedNormally(fFirst ? f : g, v1);
1932 <        checkCompletedExceptionally(!fFirst ? f : g, ex);
1929 >        checkCompletedWithWrappedException(h1, ex);
1930 >        checkCompletedWithWrappedException(h2, ex);
1931 >        checkCompletedWithWrappedException(h3, ex);
1932 >        r1.assertNotInvoked();
1933 >        r2.assertNotInvoked();
1934 >        r3.assertNotInvoked();
1935 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1936 >        checkCompletedExceptionally(failFirst ? fst : snd, ex);
1937      }}
1938  
1939      /**
1940       * runAfterBoth result completes exceptionally if either source cancelled
1941       */
1942 <    public void testRunAfterBoth_sourceCancelled() {
1942 >    public void testRunAfterBoth_sourceCancelled() throws Throwable {
1943          for (ExecutionMode m : ExecutionMode.values())
1944          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1866        for (boolean createIncomplete : new boolean[] { true, false })
1945          for (boolean fFirst : new boolean[] { true, false })
1946 +        for (boolean failFirst : new boolean[] { true, false })
1947          for (Integer v1 : new Integer[] { 1, null })
1948      {
1949          final CompletableFuture<Integer> f = new CompletableFuture<>();
1950          final CompletableFuture<Integer> g = new CompletableFuture<>();
1951 <        final Noop r = new Noop(m);
1951 >        final Noop r1 = new Noop(m);
1952 >        final Noop r2 = new Noop(m);
1953 >        final Noop r3 = new Noop(m);
1954  
1955 <        assertTrue((fFirst ? f : g).complete(v1));
1956 <        if (!createIncomplete)
1957 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1958 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1959 <        if (createIncomplete) {
1960 <            checkIncomplete(h);
1961 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1962 <        }
1955 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1956 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1957 >        final Callable<Boolean> complete1 = failFirst ?
1958 >            () -> fst.cancel(mayInterruptIfRunning) :
1959 >            () -> fst.complete(v1);
1960 >        final Callable<Boolean> complete2 = failFirst ?
1961 >            () -> snd.complete(v1) :
1962 >            () -> snd.cancel(mayInterruptIfRunning);
1963  
1964 <        checkCompletedWithWrappedCancellationException(h);
1965 <        checkCancelled(!fFirst ? f : g);
1966 <        r.assertNotInvoked();
1967 <        checkCompletedNormally(fFirst ? f : g, v1);
1964 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
1965 >        assertTrue(complete1.call());
1966 >        final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
1967 >        checkIncomplete(h1);
1968 >        checkIncomplete(h2);
1969 >        assertTrue(complete2.call());
1970 >        final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3);
1971 >
1972 >        checkCompletedWithWrappedCancellationException(h1);
1973 >        checkCompletedWithWrappedCancellationException(h2);
1974 >        checkCompletedWithWrappedCancellationException(h3);
1975 >        r1.assertNotInvoked();
1976 >        r2.assertNotInvoked();
1977 >        r3.assertNotInvoked();
1978 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1979 >        checkCancelled(failFirst ? fst : snd);
1980      }}
1981  
1982      /**
# Line 1899 | Line 1992 | public class CompletableFutureTest exten
1992          final CompletableFuture<Integer> g = new CompletableFuture<>();
1993          final FailingRunnable r1 = new FailingRunnable(m);
1994          final FailingRunnable r2 = new FailingRunnable(m);
1995 +        final FailingRunnable r3 = new FailingRunnable(m);
1996  
1997 <        CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
1998 <        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1999 <        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
2000 <        CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
1997 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1998 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1999 >        final Integer w1 =  fFirst ? v1 : v2;
2000 >        final Integer w2 = !fFirst ? v1 : v2;
2001 >
2002 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
2003 >        assertTrue(fst.complete(w1));
2004 >        final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
2005 >        assertTrue(snd.complete(w2));
2006 >        final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3);
2007  
2008          checkCompletedWithWrappedCFException(h1);
2009          checkCompletedWithWrappedCFException(h2);
2010 +        checkCompletedWithWrappedCFException(h3);
2011 +        r1.assertInvoked();
2012 +        r2.assertInvoked();
2013 +        r3.assertInvoked();
2014          checkCompletedNormally(f, v1);
2015          checkCompletedNormally(g, v2);
2016      }}
# Line 3014 | Line 3118 | public class CompletableFutureTest exten
3118          assertSame(f, f.toCompletableFuture());
3119      }
3120  
3121 +    //--- tests of implementation details; not part of official tck ---
3122 +
3123 +    Object resultOf(CompletableFuture<?> f) {
3124 +        try {
3125 +            java.lang.reflect.Field resultField
3126 +                = CompletableFuture.class.getDeclaredField("result");
3127 +            resultField.setAccessible(true);
3128 +            return resultField.get(f);
3129 +        } catch (Throwable t) { throw new AssertionError(t); }
3130 +    }
3131 +
3132 +    public void testExceptionPropagationReusesResultObject() {
3133 +        if (!testImplementationDetails) return;
3134 +        for (ExecutionMode m : ExecutionMode.values())
3135 +    {
3136 +        final CFException ex = new CFException();
3137 +        final CompletableFuture<Integer> v42 = CompletableFuture.completedFuture(42);
3138 +        final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3139 +
3140 +        List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> dependentFactories
3141 +            = new ArrayList<>();
3142 +
3143 +        dependentFactories.add((y) -> m.thenRun(y, new Noop(m)));
3144 +        dependentFactories.add((y) -> m.thenAccept(y, new NoopConsumer(m)));
3145 +        dependentFactories.add((y) -> m.thenApply(y, new IncFunction(m)));
3146 +
3147 +        dependentFactories.add((y) -> m.runAfterEither(y, incomplete, new Noop(m)));
3148 +        dependentFactories.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m)));
3149 +        dependentFactories.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3150 +
3151 +        dependentFactories.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3152 +        dependentFactories.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3153 +        dependentFactories.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
3154 +
3155 +        dependentFactories.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {}));
3156 +
3157 +        dependentFactories.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3158 +
3159 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3160 +                 dependentFactory : dependentFactories) {
3161 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3162 +            f.completeExceptionally(ex);
3163 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3164 +            checkCompletedWithWrappedException(src, ex);
3165 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3166 +            checkCompletedWithWrappedException(dep, ex);
3167 +            assertSame(resultOf(src), resultOf(dep));
3168 +        }
3169 +
3170 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3171 +                 dependentFactory : dependentFactories) {
3172 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3173 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3174 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3175 +            f.completeExceptionally(ex);
3176 +            checkCompletedWithWrappedException(src, ex);
3177 +            checkCompletedWithWrappedException(dep, ex);
3178 +            assertSame(resultOf(src), resultOf(dep));
3179 +        }
3180 +
3181 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3182 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3183 +                 dependentFactory : dependentFactories) {
3184 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3185 +            f.cancel(mayInterruptIfRunning);
3186 +            checkCancelled(f);
3187 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3188 +            checkCompletedWithWrappedCancellationException(src);
3189 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3190 +            checkCompletedWithWrappedCancellationException(dep);
3191 +            assertSame(resultOf(src), resultOf(dep));
3192 +        }
3193 +
3194 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3195 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3196 +                 dependentFactory : dependentFactories) {
3197 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3198 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3199 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3200 +            f.cancel(mayInterruptIfRunning);
3201 +            checkCancelled(f);
3202 +            checkCompletedWithWrappedCancellationException(src);
3203 +            checkCompletedWithWrappedCancellationException(dep);
3204 +            assertSame(resultOf(src), resultOf(dep));
3205 +        }
3206 +    }}
3207 +
3208   //     public void testRunAfterEither_resultDeterminedAtTimeOfCreation() {
3209   //         for (ExecutionMode m : ExecutionMode.values())
3210   //         for (boolean mayInterruptIfRunning : new boolean[] { true, false })

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines