360 |
|
return (x == null) ? null : x + 1; |
361 |
|
} |
362 |
|
|
363 |
< |
class IncAction extends CheckedIntegerAction |
363 |
> |
class NoopConsumer extends CheckedIntegerAction |
364 |
|
implements Consumer<Integer> |
365 |
|
{ |
366 |
< |
IncAction(ExecutionMode m) { super(m); } |
366 |
> |
NoopConsumer(ExecutionMode m) { super(m); } |
367 |
|
public void accept(Integer x) { |
368 |
|
invoked(); |
369 |
< |
value = inc(x); |
369 |
> |
value = x; |
370 |
|
} |
371 |
|
} |
372 |
|
|
1249 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1250 |
|
{ |
1251 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1252 |
< |
final IncAction r = new IncAction(m); |
1252 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1253 |
|
if (!createIncomplete) f.complete(v1); |
1254 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1255 |
|
if (createIncomplete) { |
1258 |
|
} |
1259 |
|
|
1260 |
|
checkCompletedNormally(g, null); |
1261 |
+ |
r.assertValue(v1); |
1262 |
|
checkCompletedNormally(f, v1); |
1262 |
– |
r.assertInvoked(); |
1263 |
– |
r.assertValue(inc(v1)); |
1263 |
|
}} |
1264 |
|
|
1265 |
|
/** |
1272 |
|
{ |
1273 |
|
final CFException ex = new CFException(); |
1274 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1275 |
< |
final IncAction r = new IncAction(m); |
1275 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1276 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1277 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1278 |
|
if (createIncomplete) { |
1294 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1295 |
|
{ |
1296 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1297 |
< |
final IncAction r = new IncAction(m); |
1297 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1298 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1299 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1300 |
|
if (createIncomplete) { |
1765 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1766 |
|
try { |
1767 |
|
assertEquals(inc(v1), h4.join()); |
1768 |
< |
rs[4].assertInvoked(); |
1768 |
> |
rs[4].assertValue(inc(v1)); |
1769 |
|
} catch (CompletionException ok) { |
1770 |
|
checkCompletedWithWrappedCFException(h4, ex); |
1771 |
|
rs[4].assertNotInvoked(); |
1772 |
|
} |
1773 |
|
try { |
1774 |
|
assertEquals(inc(v1), h5.join()); |
1775 |
< |
rs[5].assertInvoked(); |
1775 |
> |
rs[5].assertValue(inc(v1)); |
1776 |
|
} catch (CompletionException ok) { |
1777 |
|
checkCompletedWithWrappedCFException(h5, ex); |
1778 |
|
rs[5].assertNotInvoked(); |
1788 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1789 |
|
}} |
1790 |
|
|
1791 |
+ |
public void testApplyToEither_exceptionalCompletion2() { |
1792 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1793 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1794 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1795 |
+ |
{ |
1796 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1797 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1798 |
+ |
final CFException ex = new CFException(); |
1799 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1800 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1801 |
+ |
|
1802 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1803 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1804 |
+ |
if (fFirst) { |
1805 |
+ |
f.complete(v1); |
1806 |
+ |
g.completeExceptionally(ex); |
1807 |
+ |
} else { |
1808 |
+ |
g.completeExceptionally(ex); |
1809 |
+ |
f.complete(v1); |
1810 |
+ |
} |
1811 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1812 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1813 |
+ |
|
1814 |
+ |
// unspecified behavior - both source completions available |
1815 |
+ |
try { |
1816 |
+ |
assertEquals(inc(v1), h0.join()); |
1817 |
+ |
rs[0].assertValue(inc(v1)); |
1818 |
+ |
} catch (CompletionException ok) { |
1819 |
+ |
checkCompletedWithWrappedCFException(h0, ex); |
1820 |
+ |
rs[0].assertNotInvoked(); |
1821 |
+ |
} |
1822 |
+ |
try { |
1823 |
+ |
assertEquals(inc(v1), h1.join()); |
1824 |
+ |
rs[1].assertValue(inc(v1)); |
1825 |
+ |
} catch (CompletionException ok) { |
1826 |
+ |
checkCompletedWithWrappedCFException(h1, ex); |
1827 |
+ |
rs[1].assertNotInvoked(); |
1828 |
+ |
} |
1829 |
+ |
try { |
1830 |
+ |
assertEquals(inc(v1), h2.join()); |
1831 |
+ |
rs[2].assertValue(inc(v1)); |
1832 |
+ |
} catch (CompletionException ok) { |
1833 |
+ |
checkCompletedWithWrappedCFException(h2, ex); |
1834 |
+ |
rs[2].assertNotInvoked(); |
1835 |
+ |
} |
1836 |
+ |
try { |
1837 |
+ |
assertEquals(inc(v1), h3.join()); |
1838 |
+ |
rs[3].assertValue(inc(v1)); |
1839 |
+ |
} catch (CompletionException ok) { |
1840 |
+ |
checkCompletedWithWrappedCFException(h3, ex); |
1841 |
+ |
rs[3].assertNotInvoked(); |
1842 |
+ |
} |
1843 |
+ |
|
1844 |
+ |
checkCompletedNormally(f, v1); |
1845 |
+ |
checkCompletedWithWrappedCFException(g, ex); |
1846 |
+ |
}} |
1847 |
+ |
|
1848 |
|
/** |
1849 |
|
* applyToEither result completes exceptionally if either source cancelled |
1850 |
|
*/ |
1878 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1879 |
|
try { |
1880 |
|
assertEquals(inc(v1), h4.join()); |
1881 |
< |
rs[4].assertInvoked(); |
1881 |
> |
rs[4].assertValue(inc(v1)); |
1882 |
|
} catch (CompletionException ok) { |
1883 |
|
checkCompletedWithWrappedCancellationException(h4); |
1884 |
|
rs[4].assertNotInvoked(); |
1885 |
|
} |
1886 |
|
try { |
1887 |
|
assertEquals(inc(v1), h5.join()); |
1888 |
< |
rs[5].assertInvoked(); |
1888 |
> |
rs[5].assertValue(inc(v1)); |
1889 |
|
} catch (CompletionException ok) { |
1890 |
|
checkCompletedWithWrappedCancellationException(h5); |
1891 |
|
rs[5].assertNotInvoked(); |
1900 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1901 |
|
}} |
1902 |
|
|
1903 |
+ |
public void testApplyToEither_sourceCancelled2() { |
1904 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1905 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1906 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1907 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1908 |
+ |
{ |
1909 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1910 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1911 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1912 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1913 |
+ |
|
1914 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1915 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1916 |
+ |
if (fFirst) { |
1917 |
+ |
f.complete(v1); |
1918 |
+ |
g.cancel(mayInterruptIfRunning); |
1919 |
+ |
} else { |
1920 |
+ |
g.cancel(mayInterruptIfRunning); |
1921 |
+ |
f.complete(v1); |
1922 |
+ |
} |
1923 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1924 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1925 |
+ |
|
1926 |
+ |
// unspecified behavior - both source completions available |
1927 |
+ |
try { |
1928 |
+ |
assertEquals(inc(v1), h0.join()); |
1929 |
+ |
rs[0].assertValue(inc(v1)); |
1930 |
+ |
} catch (CompletionException ok) { |
1931 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
1932 |
+ |
rs[0].assertNotInvoked(); |
1933 |
+ |
} |
1934 |
+ |
try { |
1935 |
+ |
assertEquals(inc(v1), h1.join()); |
1936 |
+ |
rs[1].assertValue(inc(v1)); |
1937 |
+ |
} catch (CompletionException ok) { |
1938 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
1939 |
+ |
rs[1].assertNotInvoked(); |
1940 |
+ |
} |
1941 |
+ |
try { |
1942 |
+ |
assertEquals(inc(v1), h2.join()); |
1943 |
+ |
rs[2].assertValue(inc(v1)); |
1944 |
+ |
} catch (CompletionException ok) { |
1945 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
1946 |
+ |
rs[2].assertNotInvoked(); |
1947 |
+ |
} |
1948 |
+ |
try { |
1949 |
+ |
assertEquals(inc(v1), h3.join()); |
1950 |
+ |
rs[3].assertValue(inc(v1)); |
1951 |
+ |
} catch (CompletionException ok) { |
1952 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
1953 |
+ |
rs[3].assertNotInvoked(); |
1954 |
+ |
} |
1955 |
+ |
|
1956 |
+ |
checkCompletedNormally(f, v1); |
1957 |
+ |
checkCancelled(g); |
1958 |
+ |
}} |
1959 |
+ |
|
1960 |
|
/** |
1961 |
|
* applyToEither result completes exceptionally if action does |
1962 |
|
*/ |
2009 |
|
{ |
2010 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2011 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2012 |
< |
final IncAction[] rs = new IncAction[6]; |
2013 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2012 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2013 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2014 |
|
|
2015 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2016 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2021 |
|
f.complete(v1); |
2022 |
|
checkCompletedNormally(h0, null); |
2023 |
|
checkCompletedNormally(h1, null); |
2024 |
< |
rs[0].assertValue(inc(v1)); |
2025 |
< |
rs[1].assertValue(inc(v1)); |
2024 |
> |
rs[0].assertValue(v1); |
2025 |
> |
rs[1].assertValue(v1); |
2026 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2027 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2028 |
|
checkCompletedNormally(h2, null); |
2029 |
|
checkCompletedNormally(h3, null); |
2030 |
< |
rs[2].assertValue(inc(v1)); |
2031 |
< |
rs[3].assertValue(inc(v1)); |
2030 |
> |
rs[2].assertValue(v1); |
2031 |
> |
rs[3].assertValue(v1); |
2032 |
|
g.complete(v2); |
2033 |
|
|
2034 |
|
// unspecified behavior - both source completions available |
2036 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2037 |
|
checkCompletedNormally(h4, null); |
2038 |
|
checkCompletedNormally(h5, null); |
2039 |
< |
assertTrue(Objects.equals(inc(v1), rs[4].value) || |
2040 |
< |
Objects.equals(inc(v2), rs[4].value)); |
2041 |
< |
assertTrue(Objects.equals(inc(v1), rs[5].value) || |
2042 |
< |
Objects.equals(inc(v2), rs[5].value)); |
2039 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2040 |
> |
Objects.equals(v2, rs[4].value)); |
2041 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2042 |
> |
Objects.equals(v2, rs[5].value)); |
2043 |
|
|
2044 |
|
checkCompletedNormally(f, v1); |
2045 |
|
checkCompletedNormally(g, v2); |
2047 |
|
checkCompletedNormally(h1, null); |
2048 |
|
checkCompletedNormally(h2, null); |
2049 |
|
checkCompletedNormally(h3, null); |
2050 |
< |
for (int i = 0; i < 4; i++) rs[i].assertValue(inc(v1)); |
2050 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2051 |
|
}} |
2052 |
|
|
2053 |
|
/** |
2061 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2062 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2063 |
|
final CFException ex = new CFException(); |
2064 |
< |
final IncAction[] rs = new IncAction[6]; |
2065 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2064 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2065 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2066 |
|
|
2067 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2068 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2085 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2086 |
|
try { |
2087 |
|
assertNull(h4.join()); |
2088 |
< |
rs[4].assertValue(inc(v1)); |
2088 |
> |
rs[4].assertValue(v1); |
2089 |
|
} catch (CompletionException ok) { |
2090 |
|
checkCompletedWithWrappedCFException(h4, ex); |
2091 |
|
rs[4].assertNotInvoked(); |
2092 |
|
} |
2093 |
|
try { |
2094 |
|
assertNull(h5.join()); |
2095 |
< |
rs[5].assertValue(inc(v1)); |
2095 |
> |
rs[5].assertValue(v1); |
2096 |
|
} catch (CompletionException ok) { |
2097 |
|
checkCompletedWithWrappedCFException(h5, ex); |
2098 |
|
rs[5].assertNotInvoked(); |
2118 |
|
{ |
2119 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2120 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2121 |
< |
final IncAction[] rs = new IncAction[6]; |
2122 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2121 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2122 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2123 |
|
|
2124 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2125 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2142 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2143 |
|
try { |
2144 |
|
assertNull(h4.join()); |
2145 |
< |
rs[4].assertValue(inc(v1)); |
2145 |
> |
rs[4].assertValue(v1); |
2146 |
|
} catch (CompletionException ok) { |
2147 |
|
checkCompletedWithWrappedCancellationException(h4); |
2148 |
|
rs[4].assertNotInvoked(); |
2149 |
|
} |
2150 |
|
try { |
2151 |
|
assertNull(h5.join()); |
2152 |
< |
rs[5].assertValue(inc(v1)); |
2152 |
> |
rs[5].assertValue(v1); |
2153 |
|
} catch (CompletionException ok) { |
2154 |
|
checkCompletedWithWrappedCancellationException(h5); |
2155 |
|
rs[5].assertNotInvoked(); |
2209 |
|
* runAfterEither result completes normally after normal completion |
2210 |
|
* of either source |
2211 |
|
*/ |
2212 |
< |
public void testRunAfterEither_normalCompletion1() { |
2212 |
> |
public void testRunAfterEither_normalCompletion() { |
2213 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2214 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2215 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2216 |
|
{ |
2217 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2218 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2219 |
< |
final Noop r = new Noop(m); |
2220 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2219 |
> |
final Noop[] rs = new Noop[6]; |
2220 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2221 |
|
|
2222 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2223 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2224 |
+ |
checkIncomplete(h0); |
2225 |
+ |
checkIncomplete(h1); |
2226 |
+ |
rs[0].assertNotInvoked(); |
2227 |
+ |
rs[1].assertNotInvoked(); |
2228 |
|
f.complete(v1); |
2229 |
< |
checkCompletedNormally(h, null); |
2230 |
< |
r.assertInvoked(); |
2231 |
< |
g.complete(v2); |
2232 |
< |
|
2233 |
< |
checkCompletedNormally(f, v1); |
2234 |
< |
checkCompletedNormally(g, v2); |
2235 |
< |
checkCompletedNormally(h, null); |
2236 |
< |
r.assertInvoked(); |
2237 |
< |
}} |
2238 |
< |
|
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); |
2229 |
> |
checkCompletedNormally(h0, null); |
2230 |
> |
checkCompletedNormally(h1, null); |
2231 |
> |
rs[0].assertInvoked(); |
2232 |
> |
rs[1].assertInvoked(); |
2233 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2234 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2235 |
> |
checkCompletedNormally(h2, null); |
2236 |
> |
checkCompletedNormally(h3, null); |
2237 |
> |
rs[2].assertInvoked(); |
2238 |
> |
rs[3].assertInvoked(); |
2239 |
|
|
2240 |
|
g.complete(v2); |
2131 |
– |
checkCompletedNormally(h, null); |
2132 |
– |
r.assertInvoked(); |
2133 |
– |
f.complete(v1); |
2241 |
|
|
2242 |
< |
checkCompletedNormally(f, v1); |
2243 |
< |
checkCompletedNormally(g, v2); |
2137 |
< |
checkCompletedNormally(h, null); |
2138 |
< |
r.assertInvoked(); |
2139 |
< |
}} |
2242 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2243 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2244 |
|
|
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); |
2149 |
– |
|
2150 |
– |
f.complete(v1); |
2151 |
– |
g.complete(v2); |
2152 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2153 |
– |
|
2154 |
– |
checkCompletedNormally(h, null); |
2245 |
|
checkCompletedNormally(f, v1); |
2246 |
|
checkCompletedNormally(g, v2); |
2247 |
< |
r.assertInvoked(); |
2247 |
> |
checkCompletedNormally(h0, null); |
2248 |
> |
checkCompletedNormally(h1, null); |
2249 |
> |
checkCompletedNormally(h2, null); |
2250 |
> |
checkCompletedNormally(h3, null); |
2251 |
> |
checkCompletedNormally(h4, null); |
2252 |
> |
checkCompletedNormally(h5, null); |
2253 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2254 |
|
}} |
2255 |
|
|
2256 |
|
/** |
2257 |
|
* runAfterEither result completes exceptionally after exceptional |
2258 |
|
* completion of either source |
2259 |
|
*/ |
2260 |
< |
public void testRunAfterEither_exceptionalCompletion1() { |
2260 |
> |
public void testRunAfterEither_exceptionalCompletion() { |
2261 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2262 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2263 |
|
{ |
2264 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2265 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2170 |
– |
final Noop r = new Noop(m); |
2171 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2266 |
|
final CFException ex = new CFException(); |
2267 |
+ |
final Noop[] rs = new Noop[6]; |
2268 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2269 |
|
|
2270 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2271 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2272 |
+ |
checkIncomplete(h0); |
2273 |
+ |
checkIncomplete(h1); |
2274 |
+ |
rs[0].assertNotInvoked(); |
2275 |
+ |
rs[1].assertNotInvoked(); |
2276 |
|
f.completeExceptionally(ex); |
2277 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2278 |
< |
g.complete(v1); |
2279 |
< |
|
2280 |
< |
r.assertNotInvoked(); |
2281 |
< |
checkCompletedNormally(g, v1); |
2282 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2181 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2182 |
< |
}} |
2183 |
< |
|
2184 |
< |
public void testRunAfterEither_exceptionalCompletion2() { |
2185 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2186 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2187 |
< |
{ |
2188 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2189 |
< |
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); |
2211 |
< |
final CFException ex = new CFException(); |
2277 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2278 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2279 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2280 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2281 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2282 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2283 |
|
|
2284 |
< |
g.completeExceptionally(ex); |
2214 |
< |
f.complete(v1); |
2215 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2284 |
> |
g.complete(v1); |
2285 |
|
|
2286 |
< |
// unspecified behavior |
2287 |
< |
Integer v; |
2286 |
> |
// unspecified behavior - both source completions available |
2287 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2288 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2289 |
|
try { |
2290 |
< |
assertNull(h.join()); |
2291 |
< |
r.assertInvoked(); |
2290 |
> |
assertNull(h4.join()); |
2291 |
> |
rs[4].assertInvoked(); |
2292 |
|
} catch (CompletionException ok) { |
2293 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2294 |
< |
r.assertNotInvoked(); |
2293 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2294 |
> |
rs[4].assertNotInvoked(); |
2295 |
|
} |
2226 |
– |
|
2227 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2228 |
– |
checkCompletedNormally(f, v1); |
2229 |
– |
}} |
2230 |
– |
|
2231 |
– |
public void testRunAfterEither_exceptionalCompletion4() { |
2232 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2233 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2234 |
– |
{ |
2235 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2236 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2237 |
– |
final Noop r = new Noop(m); |
2238 |
– |
final CFException ex = new CFException(); |
2239 |
– |
|
2240 |
– |
f.completeExceptionally(ex); |
2241 |
– |
g.complete(v1); |
2242 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2243 |
– |
|
2244 |
– |
// unspecified behavior |
2245 |
– |
Integer v; |
2296 |
|
try { |
2297 |
< |
assertNull(h.join()); |
2298 |
< |
r.assertInvoked(); |
2297 |
> |
assertNull(h5.join()); |
2298 |
> |
rs[5].assertInvoked(); |
2299 |
|
} catch (CompletionException ok) { |
2300 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2301 |
< |
r.assertNotInvoked(); |
2300 |
> |
checkCompletedWithWrappedCFException(h5, ex); |
2301 |
> |
rs[5].assertNotInvoked(); |
2302 |
|
} |
2303 |
|
|
2304 |
|
checkCompletedWithWrappedCFException(f, ex); |
2305 |
|
checkCompletedNormally(g, v1); |
2306 |
< |
}} |
2307 |
< |
|
2308 |
< |
/** |
2309 |
< |
* runAfterEither result completes exceptionally if action does |
2310 |
< |
*/ |
2311 |
< |
public void testRunAfterEither_actionFailed1() { |
2262 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2263 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2264 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2265 |
< |
{ |
2266 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2267 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2268 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2269 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2270 |
< |
|
2271 |
< |
f.complete(v1); |
2272 |
< |
checkCompletedWithWrappedCFException(h); |
2273 |
< |
g.complete(v2); |
2274 |
< |
checkCompletedNormally(f, v1); |
2275 |
< |
checkCompletedNormally(g, v2); |
2276 |
< |
}} |
2277 |
< |
|
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); |
2287 |
< |
|
2288 |
< |
g.complete(v2); |
2289 |
< |
checkCompletedWithWrappedCFException(h); |
2290 |
< |
f.complete(v1); |
2291 |
< |
checkCompletedNormally(f, v1); |
2292 |
< |
checkCompletedNormally(g, v2); |
2306 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2307 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2308 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2309 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2310 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2311 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2312 |
|
}} |
2313 |
|
|
2314 |
|
/** |
2315 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2316 |
|
*/ |
2317 |
< |
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() { |
2317 |
> |
public void testRunAfterEither_sourceCancelled() { |
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); |
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 |
< |
}} |
2324 |
> |
final Noop[] rs = new Noop[6]; |
2325 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2326 |
|
|
2327 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2328 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2329 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2330 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2331 |
< |
{ |
2332 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2333 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2334 |
< |
final Noop r = new Noop(m); |
2327 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2328 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2329 |
> |
checkIncomplete(h0); |
2330 |
> |
checkIncomplete(h1); |
2331 |
> |
rs[0].assertNotInvoked(); |
2332 |
> |
rs[1].assertNotInvoked(); |
2333 |
> |
f.cancel(mayInterruptIfRunning); |
2334 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2335 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2336 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2337 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2338 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2339 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2340 |
|
|
2341 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2348 |
< |
f.complete(v1); |
2349 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2341 |
> |
g.complete(v1); |
2342 |
|
|
2343 |
< |
// unspecified behavior |
2344 |
< |
Integer v; |
2343 |
> |
// unspecified behavior - both source completions available |
2344 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2345 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2346 |
|
try { |
2347 |
< |
assertNull(h.join()); |
2348 |
< |
r.assertInvoked(); |
2347 |
> |
assertNull(h4.join()); |
2348 |
> |
rs[4].assertInvoked(); |
2349 |
|
} catch (CompletionException ok) { |
2350 |
< |
checkCompletedWithWrappedCancellationException(h); |
2351 |
< |
r.assertNotInvoked(); |
2350 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2351 |
> |
rs[4].assertNotInvoked(); |
2352 |
> |
} |
2353 |
> |
try { |
2354 |
> |
assertNull(h5.join()); |
2355 |
> |
rs[5].assertInvoked(); |
2356 |
> |
} catch (CompletionException ok) { |
2357 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2358 |
> |
rs[5].assertNotInvoked(); |
2359 |
|
} |
2360 |
|
|
2361 |
< |
checkCancelled(g); |
2362 |
< |
checkCompletedNormally(f, v1); |
2361 |
> |
checkCancelled(f); |
2362 |
> |
checkCompletedNormally(g, v1); |
2363 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2364 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2365 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2366 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2367 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2368 |
|
}} |
2369 |
|
|
2370 |
< |
public void testRunAfterEither_sourceCancelled4() { |
2370 |
> |
/** |
2371 |
> |
* runAfterEither result completes exceptionally if action does |
2372 |
> |
*/ |
2373 |
> |
public void testRunAfterEither_actionFailed() { |
2374 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2367 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2375 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2376 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
2377 |
|
{ |
2378 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2379 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2380 |
< |
final Noop r = new Noop(m); |
2380 |
> |
final FailingRunnable[] rs = new FailingRunnable[6]; |
2381 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m); |
2382 |
|
|
2383 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2384 |
< |
g.complete(v1); |
2385 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2386 |
< |
|
2387 |
< |
// unspecified behavior |
2388 |
< |
Integer v; |
2389 |
< |
try { |
2390 |
< |
assertNull(h.join()); |
2391 |
< |
r.assertInvoked(); |
2392 |
< |
} catch (CompletionException ok) { |
2393 |
< |
checkCompletedWithWrappedCancellationException(h); |
2394 |
< |
r.assertNotInvoked(); |
2395 |
< |
} |
2383 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2384 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2385 |
> |
f.complete(v1); |
2386 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2387 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2388 |
> |
checkCompletedWithWrappedCFException(h0); |
2389 |
> |
checkCompletedWithWrappedCFException(h1); |
2390 |
> |
checkCompletedWithWrappedCFException(h2); |
2391 |
> |
checkCompletedWithWrappedCFException(h3); |
2392 |
> |
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2393 |
> |
g.complete(v2); |
2394 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2395 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2396 |
> |
checkCompletedWithWrappedCFException(h4); |
2397 |
> |
checkCompletedWithWrappedCFException(h5); |
2398 |
|
|
2399 |
< |
checkCancelled(f); |
2400 |
< |
checkCompletedNormally(g, v1); |
2399 |
> |
checkCompletedNormally(f, v1); |
2400 |
> |
checkCompletedNormally(g, v2); |
2401 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2402 |
|
}} |
2403 |
|
|
2404 |
|
/** |