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(); |
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); |
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 |
|
/** |
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 |
887 |
|
}); |
888 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
889 |
|
|
890 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
890 |
> |
checkCompletedWithWrappedException(g, ex2); |
891 |
|
assertEquals(1, a.get()); |
892 |
|
}} |
893 |
|
|
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 |
|
|
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 |
|
|
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 |
|
}} |
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 |
|
|
1206 |
|
|
1207 |
|
checkCompletedNormally(g, inc(v1)); |
1208 |
|
checkCompletedNormally(f, v1); |
1209 |
< |
r.assertInvoked(); |
1209 |
> |
r.assertValue(inc(v1)); |
1210 |
|
}} |
1211 |
|
|
1212 |
|
/** |
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 |
|
|
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 |
|
|
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 |
|
/** |
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 |
|
/** |
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 |
|
/** |
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 |
|
/** |
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 |
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 |
|
*/ |
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(); |
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 |
|
*/ |
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 |
|
|
2122 |
|
assertNull(h4.join()); |
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(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 |
|
*/ |
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 |
< |
|
2119 |
< |
public void testRunAfterEither_normalCompletion2() { |
2120 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2121 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2122 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2123 |
< |
{ |
2124 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2125 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2126 |
< |
final Noop r = new Noop(m); |
2127 |
< |
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); |
2130 |
– |
checkCompletedNormally(h, null); |
2131 |
– |
r.assertInvoked(); |
2132 |
– |
f.complete(v1); |
2333 |
|
|
2334 |
< |
checkCompletedNormally(f, v1); |
2335 |
< |
checkCompletedNormally(g, v2); |
2136 |
< |
checkCompletedNormally(h, null); |
2137 |
< |
r.assertInvoked(); |
2138 |
< |
}} |
2334 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2335 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2336 |
|
|
2140 |
– |
public void testRunAfterEither_normalCompletion3() { |
2141 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2142 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2143 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
2144 |
– |
{ |
2145 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2146 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2147 |
– |
final Noop r = new Noop(m); |
2148 |
– |
|
2149 |
– |
f.complete(v1); |
2150 |
– |
g.complete(v2); |
2151 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2152 |
– |
|
2153 |
– |
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<>(); |
2169 |
– |
final Noop r = new Noop(m); |
2170 |
– |
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<>(); |
2189 |
– |
final Noop r = new Noop(m); |
2190 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2191 |
– |
final CFException ex = new CFException(); |
2192 |
– |
|
2193 |
– |
g.completeExceptionally(ex); |
2194 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2195 |
– |
f.complete(v1); |
2196 |
– |
|
2197 |
– |
r.assertNotInvoked(); |
2198 |
– |
checkCompletedNormally(f, v1); |
2199 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2200 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2201 |
– |
}} |
2202 |
– |
|
2203 |
– |
public void testRunAfterEither_exceptionalCompletion3() { |
2204 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2205 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2206 |
– |
{ |
2207 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2208 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2209 |
– |
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 |
2217 |
< |
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 |
|
|
2226 |
– |
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 |
|
|
2239 |
– |
f.completeExceptionally(ex); |
2490 |
|
g.complete(v1); |
2241 |
– |
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 |
< |
|
2277 |
< |
public void testRunAfterEither_actionFailed2() { |
2278 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2279 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2280 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2281 |
< |
{ |
2282 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2283 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2284 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2285 |
< |
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 |
|
|
2287 |
– |
g.complete(v2); |
2288 |
– |
checkCompletedWithWrappedCFException(h); |
2289 |
– |
f.complete(v1); |
2548 |
|
checkCompletedNormally(f, v1); |
2549 |
|
checkCompletedNormally(g, v2); |
2550 |
< |
}} |
2293 |
< |
|
2294 |
< |
/** |
2295 |
< |
* runAfterEither result completes exceptionally if either source cancelled |
2296 |
< |
*/ |
2297 |
< |
public void testRunAfterEither_sourceCancelled1() { |
2298 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2299 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2300 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2301 |
< |
{ |
2302 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2303 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2304 |
< |
final Noop r = new Noop(m); |
2305 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2306 |
< |
|
2307 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2308 |
< |
checkCompletedWithWrappedCancellationException(h); |
2309 |
< |
g.complete(v1); |
2310 |
< |
|
2311 |
< |
checkCancelled(f); |
2312 |
< |
r.assertNotInvoked(); |
2313 |
< |
checkCompletedNormally(g, v1); |
2314 |
< |
checkCompletedWithWrappedCancellationException(h); |
2315 |
< |
}} |
2316 |
< |
|
2317 |
< |
public void testRunAfterEither_sourceCancelled2() { |
2318 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2319 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2320 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2321 |
< |
{ |
2322 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2323 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2324 |
< |
final Noop r = new Noop(m); |
2325 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2326 |
< |
|
2327 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2328 |
< |
checkCompletedWithWrappedCancellationException(h); |
2329 |
< |
f.complete(v1); |
2330 |
< |
|
2331 |
< |
checkCancelled(g); |
2332 |
< |
r.assertNotInvoked(); |
2333 |
< |
checkCompletedNormally(f, v1); |
2334 |
< |
checkCompletedWithWrappedCancellationException(h); |
2335 |
< |
}} |
2336 |
< |
|
2337 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2338 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2339 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2340 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2341 |
< |
{ |
2342 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2343 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2344 |
< |
final Noop r = new Noop(m); |
2345 |
< |
|
2346 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2347 |
< |
f.complete(v1); |
2348 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2349 |
< |
|
2350 |
< |
// unspecified behavior |
2351 |
< |
Integer v; |
2352 |
< |
try { |
2353 |
< |
assertNull(h.join()); |
2354 |
< |
r.assertInvoked(); |
2355 |
< |
} catch (CompletionException ok) { |
2356 |
< |
checkCompletedWithWrappedCancellationException(h); |
2357 |
< |
r.assertNotInvoked(); |
2358 |
< |
} |
2359 |
< |
|
2360 |
< |
checkCancelled(g); |
2361 |
< |
checkCompletedNormally(f, v1); |
2362 |
< |
}} |
2363 |
< |
|
2364 |
< |
public void testRunAfterEither_sourceCancelled4() { |
2365 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2366 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2367 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2368 |
< |
{ |
2369 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2370 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2371 |
< |
final Noop r = new Noop(m); |
2372 |
< |
|
2373 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2374 |
< |
g.complete(v1); |
2375 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2376 |
< |
|
2377 |
< |
// unspecified behavior |
2378 |
< |
Integer v; |
2379 |
< |
try { |
2380 |
< |
assertNull(h.join()); |
2381 |
< |
r.assertInvoked(); |
2382 |
< |
} catch (CompletionException ok) { |
2383 |
< |
checkCompletedWithWrappedCancellationException(h); |
2384 |
< |
r.assertNotInvoked(); |
2385 |
< |
} |
2386 |
< |
|
2387 |
< |
checkCancelled(f); |
2388 |
< |
checkCompletedNormally(g, v1); |
2550 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2551 |
|
}} |
2552 |
|
|
2553 |
|
/** |
2566 |
|
|
2567 |
|
checkCompletedNormally(g, inc(v1)); |
2568 |
|
checkCompletedNormally(f, v1); |
2569 |
< |
r.assertInvoked(); |
2569 |
> |
r.assertValue(v1); |
2570 |
|
}} |
2571 |
|
|
2572 |
|
/** |
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 |
|
|
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(); |
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 |
|
|
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 |
|
|
2755 |
– |
//try { g.join(); } catch (Throwable t) { throw new Error(t); } |
2920 |
|
checkCompletedWithWrappedCancellationException(g); |
2921 |
|
checkCancelled(f); |
2922 |
|
assertEquals(1, a.get()); |
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(); |
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 |
|
|
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(); |
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 |
|
|