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.63 by jsr166, Fri Jun 6 16:54:16 2014 UTC vs.
Revision 1.73 by jsr166, Fri Jun 6 21:11:10 2014 UTC

# Line 105 | Line 105 | public class CompletableFutureTest exten
105          assertTrue(f.toString().contains("[Completed exceptionally]"));
106      }
107  
108 <    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
109 <                                              CFException ex) {
108 >    <U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f,
109 >                                                      Throwable ex) {
110          try {
111              f.get(LONG_DELAY_MS, MILLISECONDS);
112              shouldThrow();
# Line 131 | Line 131 | public class CompletableFutureTest exten
131          } catch (ExecutionException success) {
132              assertSame(ex, success.getCause());
133          } catch (Throwable fail) { threadUnexpectedException(fail); }
134 +
135          assertTrue(f.isDone());
136          assertFalse(f.isCancelled());
137          assertTrue(f.toString().contains("[Completed exceptionally]"));
138      }
139  
140 +    <U> void checkCompletedWithWrappedException(CompletableFuture<U> f,
141 +                                                Throwable ex) {
142 +        checkCompletedExceptionallyWithRootCause(f, ex);
143 +        try {
144 +            CompletableFuture<Throwable> spy = f.handle
145 +                ((U u, Throwable t) -> t);
146 +            assertTrue(spy.join() instanceof CompletionException);
147 +            assertSame(ex, spy.join().getCause());
148 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
149 +    }
150 +
151 +    <U> void checkCompletedExceptionally(CompletableFuture<U> f, Throwable ex) {
152 +        checkCompletedExceptionallyWithRootCause(f, ex);
153 +        try {
154 +            CompletableFuture<Throwable> spy = f.handle
155 +                ((U u, Throwable t) -> t);
156 +            assertSame(ex, spy.join());
157 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
158 +    }
159 +
160      void checkCancelled(CompletableFuture<?> f) {
161          try {
162              f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 218 | Line 239 | public class CompletableFutureTest exten
239       */
240      public void testCompleteExceptionally() {
241          CompletableFuture<Integer> f = new CompletableFuture<>();
242 +        CFException ex = new CFException();
243          checkIncomplete(f);
244 <        f.completeExceptionally(new CFException());
245 <        checkCompletedWithWrappedCFException(f);
244 >        f.completeExceptionally(ex);
245 >        checkCompletedExceptionally(f, ex);
246      }
247  
248      /**
# Line 261 | Line 283 | public class CompletableFutureTest exten
283       * obtrudeException forces completion with given exception
284       */
285      public void testObtrudeException() {
286 <        CompletableFuture<Integer> f = new CompletableFuture<>();
287 <        checkIncomplete(f);
288 <        f.complete(one);
289 <        checkCompletedNormally(f, one);
290 <        f.obtrudeException(new CFException());
269 <        checkCompletedWithWrappedCFException(f);
286 >        for (Integer v1 : new Integer[] { 1, null })
287 >    {
288 >        CFException ex;
289 >        CompletableFuture<Integer> f;
290 >
291          f = new CompletableFuture<>();
292 <        f.obtrudeException(new CFException());
293 <        checkCompletedWithWrappedCFException(f);
292 >        f.complete(v1);
293 >        for (int i = 0; i < 2; i++) {
294 >            f.obtrudeException(ex = new CFException());
295 >            checkCompletedExceptionally(f, ex);
296 >        }
297 >
298 >        f = new CompletableFuture<>();
299 >        for (int i = 0; i < 2; i++) {
300 >            f.obtrudeException(ex = new CFException());
301 >            checkCompletedExceptionally(f, ex);
302 >        }
303 >
304          f = new CompletableFuture<>();
305 +        f.completeExceptionally(ex = new CFException());
306 +        f.obtrudeValue(v1);
307 +        checkCompletedNormally(f, v1);
308 +        f.obtrudeException(ex = new CFException());
309 +        checkCompletedExceptionally(f, ex);
310          f.completeExceptionally(new CFException());
311 <        f.obtrudeValue(four);
312 <        checkCompletedNormally(f, four);
313 <        f.obtrudeException(new CFException());
314 <        checkCompletedWithWrappedCFException(f);
279 <    }
311 >        checkCompletedExceptionally(f, ex);
312 >        f.complete(v1);
313 >        checkCompletedExceptionally(f, ex);
314 >    }}
315  
316      /**
317       * getNumberOfDependents returns number of dependent tasks
# Line 360 | Line 395 | public class CompletableFutureTest exten
395          return (x == null) ? null : x + 1;
396      }
397  
398 <    class IncAction extends CheckedIntegerAction
398 >    class NoopConsumer extends CheckedIntegerAction
399          implements Consumer<Integer>
400      {
401 <        IncAction(ExecutionMode m) { super(m); }
401 >        NoopConsumer(ExecutionMode m) { super(m); }
402          public void accept(Integer x) {
403              invoked();
404 <            value = inc(x);
404 >            value = x;
405          }
406      }
407  
# Line 852 | Line 887 | public class CompletableFutureTest exten
887              });
888          if (createIncomplete) f.completeExceptionally(ex1);
889  
890 <        checkCompletedWithWrappedCFException(g, ex2);
890 >        checkCompletedWithWrappedException(g, ex2);
891          assertEquals(1, a.get());
892      }}
893  
# Line 909 | Line 944 | public class CompletableFutureTest exten
944          if (createIncomplete) f.completeExceptionally(ex);
945  
946          checkCompletedNormally(g, v1);
947 <        checkCompletedWithWrappedCFException(f, ex);
947 >        checkCompletedExceptionally(f, ex);
948          assertEquals(1, a.get());
949      }}
950  
# Line 965 | Line 1000 | public class CompletableFutureTest exten
1000              });
1001          if (createIncomplete) f.completeExceptionally(ex1);
1002  
1003 <        checkCompletedWithWrappedCFException(g, ex2);
1004 <        checkCompletedWithWrappedCFException(f, ex1);
1003 >        checkCompletedWithWrappedException(g, ex2);
1004 >        checkCompletedExceptionally(f, ex1);
1005          assertEquals(1, a.get());
1006      }}
1007  
# Line 990 | Line 1025 | public class CompletableFutureTest exten
1025              });
1026          if (createIncomplete) f.complete(v1);
1027  
1028 <        checkCompletedWithWrappedCFException(g, ex);
1028 >        checkCompletedWithWrappedException(g, ex);
1029          checkCompletedNormally(f, v1);
1030          assertEquals(1, a.get());
1031      }}
# Line 1104 | Line 1139 | public class CompletableFutureTest exten
1139              f.completeExceptionally(ex);
1140          }
1141  
1142 <        checkCompletedWithWrappedCFException(g, ex);
1143 <        checkCompletedWithWrappedCFException(f, ex);
1142 >        checkCompletedWithWrappedException(g, ex);
1143 >        checkCompletedExceptionally(f, ex);
1144          r.assertNotInvoked();
1145      }}
1146  
# Line 1171 | Line 1206 | public class CompletableFutureTest exten
1206  
1207          checkCompletedNormally(g, inc(v1));
1208          checkCompletedNormally(f, v1);
1209 <        r.assertInvoked();
1209 >        r.assertValue(inc(v1));
1210      }}
1211  
1212      /**
# Line 1192 | Line 1227 | public class CompletableFutureTest exten
1227              f.completeExceptionally(ex);
1228          }
1229  
1230 <        checkCompletedWithWrappedCFException(g, ex);
1231 <        checkCompletedWithWrappedCFException(f, ex);
1230 >        checkCompletedWithWrappedException(g, ex);
1231 >        checkCompletedExceptionally(f, ex);
1232          r.assertNotInvoked();
1233      }}
1234  
# Line 1249 | Line 1284 | public class CompletableFutureTest exten
1284          for (Integer v1 : new Integer[] { 1, null })
1285      {
1286          final CompletableFuture<Integer> f = new CompletableFuture<>();
1287 <        final IncAction r = new IncAction(m);
1287 >        final NoopConsumer r = new NoopConsumer(m);
1288          if (!createIncomplete) f.complete(v1);
1289          final CompletableFuture<Void> g = m.thenAccept(f, r);
1290          if (createIncomplete) {
# Line 1258 | Line 1293 | public class CompletableFutureTest exten
1293          }
1294  
1295          checkCompletedNormally(g, null);
1296 +        r.assertValue(v1);
1297          checkCompletedNormally(f, v1);
1262        r.assertInvoked();
1263        r.assertValue(inc(v1));
1298      }}
1299  
1300      /**
# Line 1273 | Line 1307 | public class CompletableFutureTest exten
1307      {
1308          final CFException ex = new CFException();
1309          final CompletableFuture<Integer> f = new CompletableFuture<>();
1310 <        final IncAction r = new IncAction(m);
1310 >        final NoopConsumer r = new NoopConsumer(m);
1311          if (!createIncomplete) f.completeExceptionally(ex);
1312          final CompletableFuture<Void> g = m.thenAccept(f, r);
1313          if (createIncomplete) {
# Line 1281 | Line 1315 | public class CompletableFutureTest exten
1315              f.completeExceptionally(ex);
1316          }
1317  
1318 <        checkCompletedWithWrappedCFException(g, ex);
1319 <        checkCompletedWithWrappedCFException(f, ex);
1318 >        checkCompletedWithWrappedException(g, ex);
1319 >        checkCompletedExceptionally(f, ex);
1320          r.assertNotInvoked();
1321      }}
1322  
# Line 1295 | Line 1329 | public class CompletableFutureTest exten
1329          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1330      {
1331          final CompletableFuture<Integer> f = new CompletableFuture<>();
1332 <        final IncAction r = new IncAction(m);
1332 >        final NoopConsumer r = new NoopConsumer(m);
1333          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1334          final CompletableFuture<Void> g = m.thenAccept(f, r);
1335          if (createIncomplete) {
# Line 1357 | Line 1391 | public class CompletableFutureTest exten
1391          checkCompletedNormally(h, subtract(v1, v2));
1392          checkCompletedNormally(f, v1);
1393          checkCompletedNormally(g, v2);
1394 <        r.assertInvoked();
1394 >        r.assertValue(subtract(v1, v2));
1395      }}
1396  
1397      /**
# Line 1384 | Line 1418 | public class CompletableFutureTest exten
1418              (!fFirst ? f : g).completeExceptionally(ex);
1419          }
1420  
1421 <        checkCompletedWithWrappedCFException(h, ex);
1421 >        checkCompletedWithWrappedException(h, ex);
1422          r.assertNotInvoked();
1423          checkCompletedNormally(fFirst ? f : g, v1);
1424 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1424 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1425      }}
1426  
1427      /**
# Line 1501 | Line 1535 | public class CompletableFutureTest exten
1535              (!fFirst ? f : g).completeExceptionally(ex);
1536          }
1537  
1538 <        checkCompletedWithWrappedCFException(h, ex);
1538 >        checkCompletedWithWrappedException(h, ex);
1539          r.assertNotInvoked();
1540          checkCompletedNormally(fFirst ? f : g, v1);
1541 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1541 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1542      }}
1543  
1544      /**
# Line 1618 | Line 1652 | public class CompletableFutureTest exten
1652              (!fFirst ? f : g).completeExceptionally(ex);
1653          }
1654  
1655 <        checkCompletedWithWrappedCFException(h, ex);
1655 >        checkCompletedWithWrappedException(h, ex);
1656          r.assertNotInvoked();
1657          checkCompletedNormally(fFirst ? f : g, v1);
1658 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1658 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1659      }}
1660  
1661      /**
# Line 1753 | Line 1787 | public class CompletableFutureTest exten
1787          rs[0].assertNotInvoked();
1788          rs[1].assertNotInvoked();
1789          f.completeExceptionally(ex);
1790 <        checkCompletedWithWrappedCFException(h0, ex);
1791 <        checkCompletedWithWrappedCFException(h1, ex);
1790 >        checkCompletedWithWrappedException(h0, ex);
1791 >        checkCompletedWithWrappedException(h1, ex);
1792          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
1793          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
1794 <        checkCompletedWithWrappedCFException(h2, ex);
1795 <        checkCompletedWithWrappedCFException(h3, ex);
1794 >        checkCompletedWithWrappedException(h2, ex);
1795 >        checkCompletedWithWrappedException(h3, ex);
1796          g.complete(v1);
1797  
1798          // unspecified behavior - both source completions available
# Line 1766 | Line 1800 | public class CompletableFutureTest exten
1800          final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]);
1801          try {
1802              assertEquals(inc(v1), h4.join());
1803 <            rs[4].assertInvoked();
1803 >            rs[4].assertValue(inc(v1));
1804          } catch (CompletionException ok) {
1805 <            checkCompletedWithWrappedCFException(h4, ex);
1805 >            checkCompletedWithWrappedException(h4, ex);
1806              rs[4].assertNotInvoked();
1807          }
1808          try {
1809              assertEquals(inc(v1), h5.join());
1810 <            rs[5].assertInvoked();
1810 >            rs[5].assertValue(inc(v1));
1811          } catch (CompletionException ok) {
1812 <            checkCompletedWithWrappedCFException(h5, ex);
1812 >            checkCompletedWithWrappedException(h5, ex);
1813              rs[5].assertNotInvoked();
1814          }
1815  
1816 <        checkCompletedWithWrappedCFException(f, ex);
1816 >        checkCompletedExceptionally(f, ex);
1817          checkCompletedNormally(g, v1);
1818 <        checkCompletedWithWrappedCFException(h0, ex);
1819 <        checkCompletedWithWrappedCFException(h1, ex);
1820 <        checkCompletedWithWrappedCFException(h2, ex);
1821 <        checkCompletedWithWrappedCFException(h3, ex);
1822 <        checkCompletedWithWrappedCFException(h4, ex);
1818 >        checkCompletedWithWrappedException(h0, ex);
1819 >        checkCompletedWithWrappedException(h1, ex);
1820 >        checkCompletedWithWrappedException(h2, ex);
1821 >        checkCompletedWithWrappedException(h3, ex);
1822 >        checkCompletedWithWrappedException(h4, ex);
1823          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
1824      }}
1825  
1826 +    public void testApplyToEither_exceptionalCompletion2() {
1827 +        for (ExecutionMode m : ExecutionMode.values())
1828 +        for (boolean fFirst : new boolean[] { true, false })
1829 +        for (Integer v1 : new Integer[] { 1, null })
1830 +    {
1831 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1832 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1833 +        final CFException ex = new CFException();
1834 +        final IncFunction[] rs = new IncFunction[6];
1835 +        for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m);
1836 +
1837 +        final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
1838 +        final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
1839 +        if (fFirst) {
1840 +            f.complete(v1);
1841 +            g.completeExceptionally(ex);
1842 +        } else {
1843 +            g.completeExceptionally(ex);
1844 +            f.complete(v1);
1845 +        }
1846 +        final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
1847 +        final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
1848 +
1849 +        // unspecified behavior - both source completions available
1850 +        try {
1851 +            assertEquals(inc(v1), h0.join());
1852 +            rs[0].assertValue(inc(v1));
1853 +        } catch (CompletionException ok) {
1854 +            checkCompletedWithWrappedException(h0, ex);
1855 +            rs[0].assertNotInvoked();
1856 +        }
1857 +        try {
1858 +            assertEquals(inc(v1), h1.join());
1859 +            rs[1].assertValue(inc(v1));
1860 +        } catch (CompletionException ok) {
1861 +            checkCompletedWithWrappedException(h1, ex);
1862 +            rs[1].assertNotInvoked();
1863 +        }
1864 +        try {
1865 +            assertEquals(inc(v1), h2.join());
1866 +            rs[2].assertValue(inc(v1));
1867 +        } catch (CompletionException ok) {
1868 +            checkCompletedWithWrappedException(h2, ex);
1869 +            rs[2].assertNotInvoked();
1870 +        }
1871 +        try {
1872 +            assertEquals(inc(v1), h3.join());
1873 +            rs[3].assertValue(inc(v1));
1874 +        } catch (CompletionException ok) {
1875 +            checkCompletedWithWrappedException(h3, ex);
1876 +            rs[3].assertNotInvoked();
1877 +        }
1878 +
1879 +        checkCompletedNormally(f, v1);
1880 +        checkCompletedExceptionally(g, ex);
1881 +    }}
1882 +
1883      /**
1884       * applyToEither result completes exceptionally if either source cancelled
1885       */
# Line 1822 | Line 1913 | public class CompletableFutureTest exten
1913          final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]);
1914          try {
1915              assertEquals(inc(v1), h4.join());
1916 <            rs[4].assertInvoked();
1916 >            rs[4].assertValue(inc(v1));
1917          } catch (CompletionException ok) {
1918              checkCompletedWithWrappedCancellationException(h4);
1919              rs[4].assertNotInvoked();
1920          }
1921          try {
1922              assertEquals(inc(v1), h5.join());
1923 <            rs[5].assertInvoked();
1923 >            rs[5].assertValue(inc(v1));
1924          } catch (CompletionException ok) {
1925              checkCompletedWithWrappedCancellationException(h5);
1926              rs[5].assertNotInvoked();
# Line 1844 | Line 1935 | public class CompletableFutureTest exten
1935          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
1936      }}
1937  
1938 +    public void testApplyToEither_sourceCancelled2() {
1939 +        for (ExecutionMode m : ExecutionMode.values())
1940 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1941 +        for (boolean fFirst : new boolean[] { true, false })
1942 +        for (Integer v1 : new Integer[] { 1, null })
1943 +    {
1944 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1945 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1946 +        final IncFunction[] rs = new IncFunction[6];
1947 +        for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m);
1948 +
1949 +        final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
1950 +        final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
1951 +        if (fFirst) {
1952 +            f.complete(v1);
1953 +            g.cancel(mayInterruptIfRunning);
1954 +        } else {
1955 +            g.cancel(mayInterruptIfRunning);
1956 +            f.complete(v1);
1957 +        }
1958 +        final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
1959 +        final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
1960 +
1961 +        // unspecified behavior - both source completions available
1962 +        try {
1963 +            assertEquals(inc(v1), h0.join());
1964 +            rs[0].assertValue(inc(v1));
1965 +        } catch (CompletionException ok) {
1966 +            checkCompletedWithWrappedCancellationException(h0);
1967 +            rs[0].assertNotInvoked();
1968 +        }
1969 +        try {
1970 +            assertEquals(inc(v1), h1.join());
1971 +            rs[1].assertValue(inc(v1));
1972 +        } catch (CompletionException ok) {
1973 +            checkCompletedWithWrappedCancellationException(h1);
1974 +            rs[1].assertNotInvoked();
1975 +        }
1976 +        try {
1977 +            assertEquals(inc(v1), h2.join());
1978 +            rs[2].assertValue(inc(v1));
1979 +        } catch (CompletionException ok) {
1980 +            checkCompletedWithWrappedCancellationException(h2);
1981 +            rs[2].assertNotInvoked();
1982 +        }
1983 +        try {
1984 +            assertEquals(inc(v1), h3.join());
1985 +            rs[3].assertValue(inc(v1));
1986 +        } catch (CompletionException ok) {
1987 +            checkCompletedWithWrappedCancellationException(h3);
1988 +            rs[3].assertNotInvoked();
1989 +        }
1990 +
1991 +        checkCompletedNormally(f, v1);
1992 +        checkCancelled(g);
1993 +    }}
1994 +
1995      /**
1996       * applyToEither result completes exceptionally if action does
1997       */
# Line 1896 | Line 2044 | public class CompletableFutureTest exten
2044      {
2045          final CompletableFuture<Integer> f = new CompletableFuture<>();
2046          final CompletableFuture<Integer> g = new CompletableFuture<>();
2047 <        final IncAction[] rs = new IncAction[6];
2048 <        for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m);
2047 >        final NoopConsumer[] rs = new NoopConsumer[6];
2048 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
2049  
2050          final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]);
2051          final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]);
# Line 1908 | Line 2056 | public class CompletableFutureTest exten
2056          f.complete(v1);
2057          checkCompletedNormally(h0, null);
2058          checkCompletedNormally(h1, null);
2059 <        rs[0].assertValue(inc(v1));
2060 <        rs[1].assertValue(inc(v1));
2059 >        rs[0].assertValue(v1);
2060 >        rs[1].assertValue(v1);
2061          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2062          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2063          checkCompletedNormally(h2, null);
2064          checkCompletedNormally(h3, null);
2065 <        rs[2].assertValue(inc(v1));
2066 <        rs[3].assertValue(inc(v1));
2065 >        rs[2].assertValue(v1);
2066 >        rs[3].assertValue(v1);
2067          g.complete(v2);
2068  
2069          // unspecified behavior - both source completions available
# Line 1923 | Line 2071 | public class CompletableFutureTest exten
2071          final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]);
2072          checkCompletedNormally(h4, null);
2073          checkCompletedNormally(h5, null);
2074 <        assertTrue(Objects.equals(inc(v1), rs[4].value) ||
2075 <                   Objects.equals(inc(v2), rs[4].value));
2076 <        assertTrue(Objects.equals(inc(v1), rs[5].value) ||
2077 <                   Objects.equals(inc(v2), rs[5].value));
2074 >        assertTrue(Objects.equals(v1, rs[4].value) ||
2075 >                   Objects.equals(v2, rs[4].value));
2076 >        assertTrue(Objects.equals(v1, rs[5].value) ||
2077 >                   Objects.equals(v2, rs[5].value));
2078  
2079          checkCompletedNormally(f, v1);
2080          checkCompletedNormally(g, v2);
# Line 1934 | Line 2082 | public class CompletableFutureTest exten
2082          checkCompletedNormally(h1, null);
2083          checkCompletedNormally(h2, null);
2084          checkCompletedNormally(h3, null);
2085 <        for (int i = 0; i < 4; i++) rs[i].assertValue(inc(v1));
2085 >        for (int i = 0; i < 4; i++) rs[i].assertValue(v1);
2086      }}
2087  
2088      /**
# Line 1948 | Line 2096 | public class CompletableFutureTest exten
2096          final CompletableFuture<Integer> f = new CompletableFuture<>();
2097          final CompletableFuture<Integer> g = new CompletableFuture<>();
2098          final CFException ex = new CFException();
2099 <        final IncAction[] rs = new IncAction[6];
2100 <        for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m);
2099 >        final NoopConsumer[] rs = new NoopConsumer[6];
2100 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
2101  
2102          final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]);
2103          final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]);
# Line 1958 | Line 2106 | public class CompletableFutureTest exten
2106          rs[0].assertNotInvoked();
2107          rs[1].assertNotInvoked();
2108          f.completeExceptionally(ex);
2109 <        checkCompletedWithWrappedCFException(h0, ex);
2110 <        checkCompletedWithWrappedCFException(h1, ex);
2109 >        checkCompletedWithWrappedException(h0, ex);
2110 >        checkCompletedWithWrappedException(h1, ex);
2111          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2112          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2113 <        checkCompletedWithWrappedCFException(h2, ex);
2114 <        checkCompletedWithWrappedCFException(h3, ex);
2113 >        checkCompletedWithWrappedException(h2, ex);
2114 >        checkCompletedWithWrappedException(h3, ex);
2115  
2116          g.complete(v1);
2117  
# Line 1972 | Line 2120 | public class CompletableFutureTest exten
2120          final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]);
2121          try {
2122              assertNull(h4.join());
2123 <            rs[4].assertValue(inc(v1));
2123 >            rs[4].assertValue(v1);
2124          } catch (CompletionException ok) {
2125 <            checkCompletedWithWrappedCFException(h4, ex);
2125 >            checkCompletedWithWrappedException(h4, ex);
2126              rs[4].assertNotInvoked();
2127          }
2128          try {
2129              assertNull(h5.join());
2130 <            rs[5].assertValue(inc(v1));
2130 >            rs[5].assertValue(v1);
2131          } catch (CompletionException ok) {
2132 <            checkCompletedWithWrappedCFException(h5, ex);
2132 >            checkCompletedWithWrappedException(h5, ex);
2133              rs[5].assertNotInvoked();
2134          }
2135  
2136 <        checkCompletedWithWrappedCFException(f, ex);
2136 >        checkCompletedExceptionally(f, ex);
2137          checkCompletedNormally(g, v1);
2138 <        checkCompletedWithWrappedCFException(h0, ex);
2139 <        checkCompletedWithWrappedCFException(h1, ex);
2140 <        checkCompletedWithWrappedCFException(h2, ex);
2141 <        checkCompletedWithWrappedCFException(h3, ex);
2142 <        checkCompletedWithWrappedCFException(h4, ex);
2138 >        checkCompletedWithWrappedException(h0, ex);
2139 >        checkCompletedWithWrappedException(h1, ex);
2140 >        checkCompletedWithWrappedException(h2, ex);
2141 >        checkCompletedWithWrappedException(h3, ex);
2142 >        checkCompletedWithWrappedException(h4, ex);
2143          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2144      }}
2145  
2146 +    public void testAcceptEither_exceptionalCompletion2() {
2147 +        for (ExecutionMode m : ExecutionMode.values())
2148 +        for (boolean fFirst : new boolean[] { true, false })
2149 +        for (Integer v1 : new Integer[] { 1, null })
2150 +    {
2151 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
2152 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
2153 +        final CFException ex = new CFException();
2154 +        final NoopConsumer[] rs = new NoopConsumer[6];
2155 +        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
2156 +
2157 +        final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]);
2158 +        final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]);
2159 +        if (fFirst) {
2160 +            f.complete(v1);
2161 +            g.completeExceptionally(ex);
2162 +        } else {
2163 +            g.completeExceptionally(ex);
2164 +            f.complete(v1);
2165 +        }
2166 +        final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2167 +        final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2168 +
2169 +        // unspecified behavior - both source completions available
2170 +        try {
2171 +            assertEquals(null, h0.join());
2172 +            rs[0].assertValue(v1);
2173 +        } catch (CompletionException ok) {
2174 +            checkCompletedWithWrappedException(h0, ex);
2175 +            rs[0].assertNotInvoked();
2176 +        }
2177 +        try {
2178 +            assertEquals(null, h1.join());
2179 +            rs[1].assertValue(v1);
2180 +        } catch (CompletionException ok) {
2181 +            checkCompletedWithWrappedException(h1, ex);
2182 +            rs[1].assertNotInvoked();
2183 +        }
2184 +        try {
2185 +            assertEquals(null, h2.join());
2186 +            rs[2].assertValue(v1);
2187 +        } catch (CompletionException ok) {
2188 +            checkCompletedWithWrappedException(h2, ex);
2189 +            rs[2].assertNotInvoked();
2190 +        }
2191 +        try {
2192 +            assertEquals(null, h3.join());
2193 +            rs[3].assertValue(v1);
2194 +        } catch (CompletionException ok) {
2195 +            checkCompletedWithWrappedException(h3, ex);
2196 +            rs[3].assertNotInvoked();
2197 +        }
2198 +
2199 +        checkCompletedNormally(f, v1);
2200 +        checkCompletedExceptionally(g, ex);
2201 +    }}
2202 +
2203      /**
2204       * acceptEither result completes exceptionally if either source cancelled
2205       */
# Line 2005 | Line 2210 | public class CompletableFutureTest exten
2210      {
2211          final CompletableFuture<Integer> f = new CompletableFuture<>();
2212          final CompletableFuture<Integer> g = new CompletableFuture<>();
2213 <        final IncAction[] rs = new IncAction[6];
2214 <        for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m);
2213 >        final NoopConsumer[] rs = new NoopConsumer[6];
2214 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
2215  
2216          final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]);
2217          final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]);
# Line 2029 | Line 2234 | public class CompletableFutureTest exten
2234          final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]);
2235          try {
2236              assertNull(h4.join());
2237 <            rs[4].assertValue(inc(v1));
2237 >            rs[4].assertValue(v1);
2238          } catch (CompletionException ok) {
2239              checkCompletedWithWrappedCancellationException(h4);
2240              rs[4].assertNotInvoked();
2241          }
2242          try {
2243              assertNull(h5.join());
2244 <            rs[5].assertValue(inc(v1));
2244 >            rs[5].assertValue(v1);
2245          } catch (CompletionException ok) {
2246              checkCompletedWithWrappedCancellationException(h5);
2247              rs[5].assertNotInvoked();
# Line 2096 | Line 2301 | public class CompletableFutureTest exten
2301       * runAfterEither result completes normally after normal completion
2302       * of either source
2303       */
2304 <    public void testRunAfterEither_normalCompletion1() {
2304 >    public void testRunAfterEither_normalCompletion() {
2305          for (ExecutionMode m : ExecutionMode.values())
2306          for (Integer v1 : new Integer[] { 1, null })
2307          for (Integer v2 : new Integer[] { 2, null })
2308      {
2309          final CompletableFuture<Integer> f = new CompletableFuture<>();
2310          final CompletableFuture<Integer> g = new CompletableFuture<>();
2311 <        final Noop r = new Noop(m);
2312 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2311 >        final Noop[] rs = new Noop[6];
2312 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2313  
2314 +        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2315 +        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2316 +        checkIncomplete(h0);
2317 +        checkIncomplete(h1);
2318 +        rs[0].assertNotInvoked();
2319 +        rs[1].assertNotInvoked();
2320          f.complete(v1);
2321 <        checkCompletedNormally(h, null);
2322 <        r.assertInvoked();
2323 <        g.complete(v2);
2324 <
2325 <        checkCompletedNormally(f, v1);
2326 <        checkCompletedNormally(g, v2);
2327 <        checkCompletedNormally(h, null);
2328 <        r.assertInvoked();
2329 <    }}
2330 <
2120 <    public void testRunAfterEither_normalCompletion2() {
2121 <        for (ExecutionMode m : ExecutionMode.values())
2122 <        for (Integer v1 : new Integer[] { 1, null })
2123 <        for (Integer v2 : new Integer[] { 2, null })
2124 <    {
2125 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2126 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2127 <        final Noop r = new Noop(m);
2128 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2321 >        checkCompletedNormally(h0, null);
2322 >        checkCompletedNormally(h1, null);
2323 >        rs[0].assertInvoked();
2324 >        rs[1].assertInvoked();
2325 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2326 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2327 >        checkCompletedNormally(h2, null);
2328 >        checkCompletedNormally(h3, null);
2329 >        rs[2].assertInvoked();
2330 >        rs[3].assertInvoked();
2331  
2332          g.complete(v2);
2131        checkCompletedNormally(h, null);
2132        r.assertInvoked();
2133        f.complete(v1);
2134
2135        checkCompletedNormally(f, v1);
2136        checkCompletedNormally(g, v2);
2137        checkCompletedNormally(h, null);
2138        r.assertInvoked();
2139        }}
2140
2141    public void testRunAfterEither_normalCompletion3() {
2142        for (ExecutionMode m : ExecutionMode.values())
2143        for (Integer v1 : new Integer[] { 1, null })
2144        for (Integer v2 : new Integer[] { 2, null })
2145    {
2146        final CompletableFuture<Integer> f = new CompletableFuture<>();
2147        final CompletableFuture<Integer> g = new CompletableFuture<>();
2148        final Noop r = new Noop(m);
2333  
2334 <        f.complete(v1);
2335 <        g.complete(v2);
2152 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2334 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2335 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2336  
2154        checkCompletedNormally(h, null);
2337          checkCompletedNormally(f, v1);
2338          checkCompletedNormally(g, v2);
2339 <        r.assertInvoked();
2339 >        checkCompletedNormally(h0, null);
2340 >        checkCompletedNormally(h1, null);
2341 >        checkCompletedNormally(h2, null);
2342 >        checkCompletedNormally(h3, null);
2343 >        checkCompletedNormally(h4, null);
2344 >        checkCompletedNormally(h5, null);
2345 >        for (int i = 0; i < 6; i++) rs[i].assertInvoked();
2346      }}
2347  
2348      /**
2349       * runAfterEither result completes exceptionally after exceptional
2350       * completion of either source
2351       */
2352 <    public void testRunAfterEither_exceptionalCompletion1() {
2352 >    public void testRunAfterEither_exceptionalCompletion() {
2353          for (ExecutionMode m : ExecutionMode.values())
2354          for (Integer v1 : new Integer[] { 1, null })
2355      {
2356          final CompletableFuture<Integer> f = new CompletableFuture<>();
2357          final CompletableFuture<Integer> g = new CompletableFuture<>();
2170        final Noop r = new Noop(m);
2171        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2358          final CFException ex = new CFException();
2359 +        final Noop[] rs = new Noop[6];
2360 +        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2361  
2362 +        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2363 +        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2364 +        checkIncomplete(h0);
2365 +        checkIncomplete(h1);
2366 +        rs[0].assertNotInvoked();
2367 +        rs[1].assertNotInvoked();
2368          f.completeExceptionally(ex);
2369 <        checkCompletedWithWrappedCFException(h, ex);
2369 >        checkCompletedWithWrappedException(h0, ex);
2370 >        checkCompletedWithWrappedException(h1, ex);
2371 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2372 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2373 >        checkCompletedWithWrappedException(h2, ex);
2374 >        checkCompletedWithWrappedException(h3, ex);
2375 >
2376          g.complete(v1);
2377  
2378 <        r.assertNotInvoked();
2378 >        // unspecified behavior - both source completions available
2379 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2380 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2381 >        try {
2382 >            assertNull(h4.join());
2383 >            rs[4].assertInvoked();
2384 >        } catch (CompletionException ok) {
2385 >            checkCompletedWithWrappedException(h4, ex);
2386 >            rs[4].assertNotInvoked();
2387 >        }
2388 >        try {
2389 >            assertNull(h5.join());
2390 >            rs[5].assertInvoked();
2391 >        } catch (CompletionException ok) {
2392 >            checkCompletedWithWrappedException(h5, ex);
2393 >            rs[5].assertNotInvoked();
2394 >        }
2395 >
2396 >        checkCompletedExceptionally(f, ex);
2397          checkCompletedNormally(g, v1);
2398 <        checkCompletedWithWrappedCFException(f, ex);
2399 <        checkCompletedWithWrappedCFException(h, ex);
2398 >        checkCompletedWithWrappedException(h0, ex);
2399 >        checkCompletedWithWrappedException(h1, ex);
2400 >        checkCompletedWithWrappedException(h2, ex);
2401 >        checkCompletedWithWrappedException(h3, ex);
2402 >        checkCompletedWithWrappedException(h4, ex);
2403 >        for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2404      }}
2405  
2406      public void testRunAfterEither_exceptionalCompletion2() {
2407          for (ExecutionMode m : ExecutionMode.values())
2408 +        for (boolean fFirst : new boolean[] { true, false })
2409          for (Integer v1 : new Integer[] { 1, null })
2410      {
2411          final CompletableFuture<Integer> f = new CompletableFuture<>();
2412          final CompletableFuture<Integer> g = new CompletableFuture<>();
2190        final Noop r = new Noop(m);
2191        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2192        final CFException ex = new CFException();
2193
2194        g.completeExceptionally(ex);
2195        checkCompletedWithWrappedCFException(h, ex);
2196        f.complete(v1);
2197
2198        r.assertNotInvoked();
2199        checkCompletedNormally(f, v1);
2200        checkCompletedWithWrappedCFException(g, ex);
2201        checkCompletedWithWrappedCFException(h, ex);
2202    }}
2203
2204    public void testRunAfterEither_exceptionalCompletion3() {
2205        for (ExecutionMode m : ExecutionMode.values())
2206        for (Integer v1 : new Integer[] { 1, null })
2207    {
2208        final CompletableFuture<Integer> f = new CompletableFuture<>();
2209        final CompletableFuture<Integer> g = new CompletableFuture<>();
2210        final Noop r = new Noop(m);
2413          final CFException ex = new CFException();
2414 +        final Noop[] rs = new Noop[6];
2415 +        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2416  
2417 <        g.completeExceptionally(ex);
2418 <        f.complete(v1);
2419 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2417 >        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2418 >        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2419 >        if (fFirst) {
2420 >            f.complete(v1);
2421 >            g.completeExceptionally(ex);
2422 >        } else {
2423 >            g.completeExceptionally(ex);
2424 >            f.complete(v1);
2425 >        }
2426 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2427 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2428  
2429 <        // unspecified behavior
2218 <        Integer v;
2429 >        // unspecified behavior - both source completions available
2430          try {
2431 <            assertNull(h.join());
2432 <            r.assertInvoked();
2431 >            assertEquals(null, h0.join());
2432 >            rs[0].assertInvoked();
2433          } catch (CompletionException ok) {
2434 <            checkCompletedWithWrappedCFException(h, ex);
2435 <            r.assertNotInvoked();
2434 >            checkCompletedWithWrappedException(h0, ex);
2435 >            rs[0].assertNotInvoked();
2436 >        }
2437 >        try {
2438 >            assertEquals(null, h1.join());
2439 >            rs[1].assertInvoked();
2440 >        } catch (CompletionException ok) {
2441 >            checkCompletedWithWrappedException(h1, ex);
2442 >            rs[1].assertNotInvoked();
2443 >        }
2444 >        try {
2445 >            assertEquals(null, h2.join());
2446 >            rs[2].assertInvoked();
2447 >        } catch (CompletionException ok) {
2448 >            checkCompletedWithWrappedException(h2, ex);
2449 >            rs[2].assertNotInvoked();
2450 >        }
2451 >        try {
2452 >            assertEquals(null, h3.join());
2453 >            rs[3].assertInvoked();
2454 >        } catch (CompletionException ok) {
2455 >            checkCompletedWithWrappedException(h3, ex);
2456 >            rs[3].assertNotInvoked();
2457          }
2458  
2227        checkCompletedWithWrappedCFException(g, ex);
2459          checkCompletedNormally(f, v1);
2460 +        checkCompletedExceptionally(g, ex);
2461      }}
2462  
2463 <    public void testRunAfterEither_exceptionalCompletion4() {
2463 >    /**
2464 >     * runAfterEither result completes exceptionally if either source cancelled
2465 >     */
2466 >    public void testRunAfterEither_sourceCancelled() {
2467          for (ExecutionMode m : ExecutionMode.values())
2468 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2469          for (Integer v1 : new Integer[] { 1, null })
2470      {
2471          final CompletableFuture<Integer> f = new CompletableFuture<>();
2472          final CompletableFuture<Integer> g = new CompletableFuture<>();
2473 <        final Noop r = new Noop(m);
2474 <        final CFException ex = new CFException();
2473 >        final Noop[] rs = new Noop[6];
2474 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2475 >
2476 >        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2477 >        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2478 >        checkIncomplete(h0);
2479 >        checkIncomplete(h1);
2480 >        rs[0].assertNotInvoked();
2481 >        rs[1].assertNotInvoked();
2482 >        f.cancel(mayInterruptIfRunning);
2483 >        checkCompletedWithWrappedCancellationException(h0);
2484 >        checkCompletedWithWrappedCancellationException(h1);
2485 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2486 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2487 >        checkCompletedWithWrappedCancellationException(h2);
2488 >        checkCompletedWithWrappedCancellationException(h3);
2489  
2240        f.completeExceptionally(ex);
2490          g.complete(v1);
2242        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2491  
2492 <        // unspecified behavior
2493 <        Integer v;
2492 >        // unspecified behavior - both source completions available
2493 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2494 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2495          try {
2496 <            assertNull(h.join());
2497 <            r.assertInvoked();
2496 >            assertNull(h4.join());
2497 >            rs[4].assertInvoked();
2498          } catch (CompletionException ok) {
2499 <            checkCompletedWithWrappedCFException(h, ex);
2500 <            r.assertNotInvoked();
2499 >            checkCompletedWithWrappedCancellationException(h4);
2500 >            rs[4].assertNotInvoked();
2501 >        }
2502 >        try {
2503 >            assertNull(h5.join());
2504 >            rs[5].assertInvoked();
2505 >        } catch (CompletionException ok) {
2506 >            checkCompletedWithWrappedCancellationException(h5);
2507 >            rs[5].assertNotInvoked();
2508          }
2509  
2510 <        checkCompletedWithWrappedCFException(f, ex);
2510 >        checkCancelled(f);
2511          checkCompletedNormally(g, v1);
2512 +        checkCompletedWithWrappedCancellationException(h0);
2513 +        checkCompletedWithWrappedCancellationException(h1);
2514 +        checkCompletedWithWrappedCancellationException(h2);
2515 +        checkCompletedWithWrappedCancellationException(h3);
2516 +        for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2517      }}
2518  
2519      /**
2520       * runAfterEither result completes exceptionally if action does
2521       */
2522 <    public void testRunAfterEither_actionFailed1() {
2522 >    public void testRunAfterEither_actionFailed() {
2523          for (ExecutionMode m : ExecutionMode.values())
2524          for (Integer v1 : new Integer[] { 1, null })
2525          for (Integer v2 : new Integer[] { 2, null })
2526      {
2527          final CompletableFuture<Integer> f = new CompletableFuture<>();
2528          final CompletableFuture<Integer> g = new CompletableFuture<>();
2529 <        final FailingRunnable r = new FailingRunnable(m);
2530 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2529 >        final FailingRunnable[] rs = new FailingRunnable[6];
2530 >        for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m);
2531  
2532 +        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2533 +        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2534          f.complete(v1);
2535 <        checkCompletedWithWrappedCFException(h);
2535 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2536 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2537 >        checkCompletedWithWrappedCFException(h0);
2538 >        checkCompletedWithWrappedCFException(h1);
2539 >        checkCompletedWithWrappedCFException(h2);
2540 >        checkCompletedWithWrappedCFException(h3);
2541 >        for (int i = 0; i < 4; i++) rs[i].assertInvoked();
2542          g.complete(v2);
2543 <        checkCompletedNormally(f, v1);
2544 <        checkCompletedNormally(g, v2);
2545 <    }}
2546 <
2278 <    public void testRunAfterEither_actionFailed2() {
2279 <        for (ExecutionMode m : ExecutionMode.values())
2280 <        for (Integer v1 : new Integer[] { 1, null })
2281 <        for (Integer v2 : new Integer[] { 2, null })
2282 <    {
2283 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2284 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2285 <        final FailingRunnable r = new FailingRunnable(m);
2286 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2543 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2544 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2545 >        checkCompletedWithWrappedCFException(h4);
2546 >        checkCompletedWithWrappedCFException(h5);
2547  
2288        g.complete(v2);
2289        checkCompletedWithWrappedCFException(h);
2290        f.complete(v1);
2548          checkCompletedNormally(f, v1);
2549          checkCompletedNormally(g, v2);
2550 <    }}
2294 <
2295 <    /**
2296 <     * runAfterEither result completes exceptionally if either source cancelled
2297 <     */
2298 <    public void testRunAfterEither_sourceCancelled1() {
2299 <        for (ExecutionMode m : ExecutionMode.values())
2300 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2301 <        for (Integer v1 : new Integer[] { 1, null })
2302 <    {
2303 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2304 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2305 <        final Noop r = new Noop(m);
2306 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2307 <
2308 <        assertTrue(f.cancel(mayInterruptIfRunning));
2309 <        checkCompletedWithWrappedCancellationException(h);
2310 <        g.complete(v1);
2311 <
2312 <        checkCancelled(f);
2313 <        r.assertNotInvoked();
2314 <        checkCompletedNormally(g, v1);
2315 <        checkCompletedWithWrappedCancellationException(h);
2316 <    }}
2317 <
2318 <    public void testRunAfterEither_sourceCancelled2() {
2319 <        for (ExecutionMode m : ExecutionMode.values())
2320 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2321 <        for (Integer v1 : new Integer[] { 1, null })
2322 <    {
2323 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2324 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2325 <        final Noop r = new Noop(m);
2326 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2327 <
2328 <        assertTrue(g.cancel(mayInterruptIfRunning));
2329 <        checkCompletedWithWrappedCancellationException(h);
2330 <        f.complete(v1);
2331 <
2332 <        checkCancelled(g);
2333 <        r.assertNotInvoked();
2334 <        checkCompletedNormally(f, v1);
2335 <        checkCompletedWithWrappedCancellationException(h);
2336 <    }}
2337 <
2338 <    public void testRunAfterEither_sourceCancelled3() {
2339 <        for (ExecutionMode m : ExecutionMode.values())
2340 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2341 <        for (Integer v1 : new Integer[] { 1, null })
2342 <    {
2343 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2344 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2345 <        final Noop r = new Noop(m);
2346 <
2347 <        assertTrue(g.cancel(mayInterruptIfRunning));
2348 <        f.complete(v1);
2349 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2350 <
2351 <        // unspecified behavior
2352 <        Integer v;
2353 <        try {
2354 <            assertNull(h.join());
2355 <            r.assertInvoked();
2356 <        } catch (CompletionException ok) {
2357 <            checkCompletedWithWrappedCancellationException(h);
2358 <            r.assertNotInvoked();
2359 <        }
2360 <
2361 <        checkCancelled(g);
2362 <        checkCompletedNormally(f, v1);
2363 <    }}
2364 <
2365 <    public void testRunAfterEither_sourceCancelled4() {
2366 <        for (ExecutionMode m : ExecutionMode.values())
2367 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2368 <        for (Integer v1 : new Integer[] { 1, null })
2369 <    {
2370 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2371 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2372 <        final Noop r = new Noop(m);
2373 <
2374 <        assertTrue(f.cancel(mayInterruptIfRunning));
2375 <        g.complete(v1);
2376 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2377 <
2378 <        // unspecified behavior
2379 <        Integer v;
2380 <        try {
2381 <            assertNull(h.join());
2382 <            r.assertInvoked();
2383 <        } catch (CompletionException ok) {
2384 <            checkCompletedWithWrappedCancellationException(h);
2385 <            r.assertNotInvoked();
2386 <        }
2387 <
2388 <        checkCancelled(f);
2389 <        checkCompletedNormally(g, v1);
2550 >        for (int i = 0; i < 6; i++) rs[i].assertInvoked();
2551      }}
2552  
2553      /**
# Line 2405 | Line 2566 | public class CompletableFutureTest exten
2566  
2567          checkCompletedNormally(g, inc(v1));
2568          checkCompletedNormally(f, v1);
2569 <        r.assertInvoked();
2569 >        r.assertValue(v1);
2570      }}
2571  
2572      /**
# Line 2423 | Line 2584 | public class CompletableFutureTest exten
2584          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2585          if (createIncomplete) f.completeExceptionally(ex);
2586  
2587 <        checkCompletedWithWrappedCFException(g, ex);
2588 <        checkCompletedWithWrappedCFException(f, ex);
2587 >        checkCompletedWithWrappedException(g, ex);
2588 >        checkCompletedExceptionally(f, ex);
2589          r.assertNotInvoked();
2590      }}
2591  
# Line 2695 | Line 2856 | public class CompletableFutureTest exten
2856          final CompletableFuture<Integer> g = m.whenComplete
2857              (f,
2858               (Integer x, Throwable t) -> {
2859 +                m.checkExecutionMode();
2860                  threadAssertSame(x, v1);
2861                  threadAssertNull(t);
2862                  a.getAndIncrement();
# Line 2722 | Line 2884 | public class CompletableFutureTest exten
2884          final CompletableFuture<Integer> g = m.whenComplete
2885              (f,
2886               (Integer x, Throwable t) -> {
2887 +                m.checkExecutionMode();
2888                  threadAssertNull(x);
2889                  threadAssertSame(t, ex);
2890                  a.getAndIncrement();
2891              });
2892          if (createIncomplete) f.completeExceptionally(ex);
2893 <        checkCompletedWithWrappedCFException(f, ex);
2894 <        checkCompletedWithWrappedCFException(g, ex);
2893 >        checkCompletedExceptionally(f, ex);
2894 >        checkCompletedWithWrappedException(g, ex);
2895          assertEquals(1, a.get());
2896      }}
2897  
# Line 2747 | Line 2910 | public class CompletableFutureTest exten
2910          final CompletableFuture<Integer> g = m.whenComplete
2911              (f,
2912               (Integer x, Throwable t) -> {
2913 +                m.checkExecutionMode();
2914                  threadAssertNull(x);
2915                  threadAssertTrue(t instanceof CancellationException);
2916                  a.getAndIncrement();
2917              });
2918          if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2919  
2756        //try { g.join(); } catch (Throwable t) { throw new Error(t); }
2920          checkCompletedWithWrappedCancellationException(g);
2921          checkCancelled(f);
2922          assertEquals(1, a.get());
# Line 2775 | Line 2938 | public class CompletableFutureTest exten
2938          final CompletableFuture<Integer> g = m.whenComplete
2939              (f,
2940               (Integer x, Throwable t) -> {
2941 +                m.checkExecutionMode();
2942                  threadAssertSame(x, v1);
2943                  threadAssertNull(t);
2944                  a.getAndIncrement();
# Line 2782 | Line 2946 | public class CompletableFutureTest exten
2946              });
2947          if (createIncomplete) f.complete(v1);
2948          checkCompletedNormally(f, v1);
2949 <        checkCompletedWithWrappedCFException(g, ex);
2949 >        checkCompletedWithWrappedException(g, ex);
2950          assertEquals(1, a.get());
2951      }}
2952  
# Line 2805 | Line 2969 | public class CompletableFutureTest exten
2969          final CompletableFuture<Integer> g = m.whenComplete
2970              (f,
2971               (Integer x, Throwable t) -> {
2972 +                m.checkExecutionMode();
2973                  threadAssertSame(t, ex1);
2974                  threadAssertNull(x);
2975                  a.getAndIncrement();
# Line 2812 | Line 2977 | public class CompletableFutureTest exten
2977              });
2978          if (createIncomplete) f.completeExceptionally(ex1);
2979  
2980 <        checkCompletedWithWrappedCFException(f, ex1);
2981 <        checkCompletedWithWrappedCFException(g, ex1);
2980 >        checkCompletedExceptionally(f, ex1);
2981 >        checkCompletedWithWrappedException(g, ex1);
2982          assertEquals(1, a.get());
2983      }}
2984  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines