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) { |
1895 |
|
{ |
1896 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1897 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1898 |
< |
final IncAction[] rs = new IncAction[6]; |
1899 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
1898 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
1899 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1900 |
|
|
1901 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
1902 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
1907 |
|
f.complete(v1); |
1908 |
|
checkCompletedNormally(h0, null); |
1909 |
|
checkCompletedNormally(h1, null); |
1910 |
< |
rs[0].assertValue(inc(v1)); |
1911 |
< |
rs[1].assertValue(inc(v1)); |
1910 |
> |
rs[0].assertValue(v1); |
1911 |
> |
rs[1].assertValue(v1); |
1912 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
1913 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
1914 |
|
checkCompletedNormally(h2, null); |
1915 |
|
checkCompletedNormally(h3, null); |
1916 |
< |
rs[2].assertValue(inc(v1)); |
1917 |
< |
rs[3].assertValue(inc(v1)); |
1916 |
> |
rs[2].assertValue(v1); |
1917 |
> |
rs[3].assertValue(v1); |
1918 |
|
g.complete(v2); |
1919 |
|
|
1920 |
|
// unspecified behavior - both source completions available |
1922 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
1923 |
|
checkCompletedNormally(h4, null); |
1924 |
|
checkCompletedNormally(h5, null); |
1925 |
< |
assertTrue(Objects.equals(inc(v1), rs[4].value) || |
1926 |
< |
Objects.equals(inc(v2), rs[4].value)); |
1927 |
< |
assertTrue(Objects.equals(inc(v1), rs[5].value) || |
1928 |
< |
Objects.equals(inc(v2), rs[5].value)); |
1925 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
1926 |
> |
Objects.equals(v2, rs[4].value)); |
1927 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
1928 |
> |
Objects.equals(v2, rs[5].value)); |
1929 |
|
|
1930 |
|
checkCompletedNormally(f, v1); |
1931 |
|
checkCompletedNormally(g, v2); |
1933 |
|
checkCompletedNormally(h1, null); |
1934 |
|
checkCompletedNormally(h2, null); |
1935 |
|
checkCompletedNormally(h3, null); |
1936 |
< |
for (int i = 0; i < 4; i++) rs[i].assertValue(inc(v1)); |
1936 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
1937 |
|
}} |
1938 |
|
|
1939 |
|
/** |
1947 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1948 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1949 |
|
final CFException ex = new CFException(); |
1950 |
< |
final IncAction[] rs = new IncAction[6]; |
1951 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
1950 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
1951 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1952 |
|
|
1953 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
1954 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
1971 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
1972 |
|
try { |
1973 |
|
assertNull(h4.join()); |
1974 |
< |
rs[4].assertValue(inc(v1)); |
1974 |
> |
rs[4].assertValue(v1); |
1975 |
|
} catch (CompletionException ok) { |
1976 |
|
checkCompletedWithWrappedCFException(h4, ex); |
1977 |
|
rs[4].assertNotInvoked(); |
1978 |
|
} |
1979 |
|
try { |
1980 |
|
assertNull(h5.join()); |
1981 |
< |
rs[5].assertValue(inc(v1)); |
1981 |
> |
rs[5].assertValue(v1); |
1982 |
|
} catch (CompletionException ok) { |
1983 |
|
checkCompletedWithWrappedCFException(h5, ex); |
1984 |
|
rs[5].assertNotInvoked(); |
2004 |
|
{ |
2005 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2006 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2007 |
< |
final IncAction[] rs = new IncAction[6]; |
2008 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2007 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2008 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2009 |
|
|
2010 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2011 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2028 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2029 |
|
try { |
2030 |
|
assertNull(h4.join()); |
2031 |
< |
rs[4].assertValue(inc(v1)); |
2031 |
> |
rs[4].assertValue(v1); |
2032 |
|
} catch (CompletionException ok) { |
2033 |
|
checkCompletedWithWrappedCancellationException(h4); |
2034 |
|
rs[4].assertNotInvoked(); |
2035 |
|
} |
2036 |
|
try { |
2037 |
|
assertNull(h5.join()); |
2038 |
< |
rs[5].assertValue(inc(v1)); |
2038 |
> |
rs[5].assertValue(v1); |
2039 |
|
} catch (CompletionException ok) { |
2040 |
|
checkCompletedWithWrappedCancellationException(h5); |
2041 |
|
rs[5].assertNotInvoked(); |
2095 |
|
* runAfterEither result completes normally after normal completion |
2096 |
|
* of either source |
2097 |
|
*/ |
2098 |
< |
public void testRunAfterEither_normalCompletion1() { |
2098 |
> |
public void testRunAfterEither_normalCompletion() { |
2099 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2100 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2101 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2102 |
|
{ |
2103 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2104 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2105 |
< |
final Noop r = new Noop(m); |
2106 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2105 |
> |
final Noop[] rs = new Noop[6]; |
2106 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2107 |
|
|
2108 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2109 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2110 |
+ |
checkIncomplete(h0); |
2111 |
+ |
checkIncomplete(h1); |
2112 |
+ |
rs[0].assertNotInvoked(); |
2113 |
+ |
rs[1].assertNotInvoked(); |
2114 |
|
f.complete(v1); |
2115 |
< |
checkCompletedNormally(h, null); |
2116 |
< |
r.assertInvoked(); |
2117 |
< |
g.complete(v2); |
2118 |
< |
|
2119 |
< |
checkCompletedNormally(f, v1); |
2120 |
< |
checkCompletedNormally(g, v2); |
2121 |
< |
checkCompletedNormally(h, null); |
2122 |
< |
r.assertInvoked(); |
2123 |
< |
}} |
2124 |
< |
|
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); |
2115 |
> |
checkCompletedNormally(h0, null); |
2116 |
> |
checkCompletedNormally(h1, null); |
2117 |
> |
rs[0].assertInvoked(); |
2118 |
> |
rs[1].assertInvoked(); |
2119 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2120 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2121 |
> |
checkCompletedNormally(h2, null); |
2122 |
> |
checkCompletedNormally(h3, null); |
2123 |
> |
rs[2].assertInvoked(); |
2124 |
> |
rs[3].assertInvoked(); |
2125 |
|
|
2126 |
|
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); |
2127 |
|
|
2128 |
< |
f.complete(v1); |
2129 |
< |
g.complete(v2); |
2152 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2128 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2129 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2130 |
|
|
2154 |
– |
checkCompletedNormally(h, null); |
2131 |
|
checkCompletedNormally(f, v1); |
2132 |
|
checkCompletedNormally(g, v2); |
2133 |
< |
r.assertInvoked(); |
2133 |
> |
checkCompletedNormally(h0, null); |
2134 |
> |
checkCompletedNormally(h1, null); |
2135 |
> |
checkCompletedNormally(h2, null); |
2136 |
> |
checkCompletedNormally(h3, null); |
2137 |
> |
checkCompletedNormally(h4, null); |
2138 |
> |
checkCompletedNormally(h5, null); |
2139 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2140 |
|
}} |
2141 |
|
|
2142 |
|
/** |
2143 |
|
* runAfterEither result completes exceptionally after exceptional |
2144 |
|
* completion of either source |
2145 |
|
*/ |
2146 |
< |
public void testRunAfterEither_exceptionalCompletion1() { |
2146 |
> |
public void testRunAfterEither_exceptionalCompletion() { |
2147 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2148 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2149 |
|
{ |
2150 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2151 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2170 |
– |
final Noop r = new Noop(m); |
2171 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2152 |
|
final CFException ex = new CFException(); |
2153 |
+ |
final Noop[] rs = new Noop[6]; |
2154 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2155 |
|
|
2156 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2157 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2158 |
+ |
checkIncomplete(h0); |
2159 |
+ |
checkIncomplete(h1); |
2160 |
+ |
rs[0].assertNotInvoked(); |
2161 |
+ |
rs[1].assertNotInvoked(); |
2162 |
|
f.completeExceptionally(ex); |
2163 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2164 |
< |
g.complete(v1); |
2165 |
< |
|
2166 |
< |
r.assertNotInvoked(); |
2167 |
< |
checkCompletedNormally(g, v1); |
2168 |
< |
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(); |
2163 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2164 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2165 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2166 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2167 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2168 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2169 |
|
|
2170 |
< |
g.completeExceptionally(ex); |
2214 |
< |
f.complete(v1); |
2215 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2170 |
> |
g.complete(v1); |
2171 |
|
|
2172 |
< |
// unspecified behavior |
2173 |
< |
Integer v; |
2172 |
> |
// unspecified behavior - both source completions available |
2173 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2174 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2175 |
|
try { |
2176 |
< |
assertNull(h.join()); |
2177 |
< |
r.assertInvoked(); |
2176 |
> |
assertNull(h4.join()); |
2177 |
> |
rs[4].assertInvoked(); |
2178 |
|
} catch (CompletionException ok) { |
2179 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2180 |
< |
r.assertNotInvoked(); |
2179 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2180 |
> |
rs[4].assertNotInvoked(); |
2181 |
|
} |
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; |
2182 |
|
try { |
2183 |
< |
assertNull(h.join()); |
2184 |
< |
r.assertInvoked(); |
2183 |
> |
assertNull(h5.join()); |
2184 |
> |
rs[5].assertInvoked(); |
2185 |
|
} catch (CompletionException ok) { |
2186 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2187 |
< |
r.assertNotInvoked(); |
2186 |
> |
checkCompletedWithWrappedCFException(h5, ex); |
2187 |
> |
rs[5].assertNotInvoked(); |
2188 |
|
} |
2189 |
|
|
2190 |
|
checkCompletedWithWrappedCFException(f, ex); |
2191 |
|
checkCompletedNormally(g, v1); |
2192 |
< |
}} |
2193 |
< |
|
2194 |
< |
/** |
2195 |
< |
* runAfterEither result completes exceptionally if action does |
2196 |
< |
*/ |
2197 |
< |
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); |
2192 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2193 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2194 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2195 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2196 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2197 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2198 |
|
}} |
2199 |
|
|
2200 |
|
/** |
2201 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2202 |
|
*/ |
2203 |
< |
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() { |
2203 |
> |
public void testRunAfterEither_sourceCancelled() { |
2204 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2205 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
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 CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2327 |
< |
|
2328 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2329 |
< |
checkCompletedWithWrappedCancellationException(h); |
2330 |
< |
f.complete(v1); |
2210 |
> |
final Noop[] rs = new Noop[6]; |
2211 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2212 |
|
|
2213 |
< |
checkCancelled(g); |
2214 |
< |
r.assertNotInvoked(); |
2215 |
< |
checkCompletedNormally(f, v1); |
2216 |
< |
checkCompletedWithWrappedCancellationException(h); |
2217 |
< |
}} |
2218 |
< |
|
2219 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2220 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2221 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2222 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2223 |
< |
{ |
2224 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2225 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2345 |
< |
final Noop r = new Noop(m); |
2213 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2214 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2215 |
> |
checkIncomplete(h0); |
2216 |
> |
checkIncomplete(h1); |
2217 |
> |
rs[0].assertNotInvoked(); |
2218 |
> |
rs[1].assertNotInvoked(); |
2219 |
> |
f.cancel(mayInterruptIfRunning); |
2220 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2221 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2222 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2223 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2224 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2225 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2226 |
|
|
2227 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2348 |
< |
f.complete(v1); |
2349 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2227 |
> |
g.complete(v1); |
2228 |
|
|
2229 |
< |
// unspecified behavior |
2230 |
< |
Integer v; |
2229 |
> |
// unspecified behavior - both source completions available |
2230 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2231 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2232 |
|
try { |
2233 |
< |
assertNull(h.join()); |
2234 |
< |
r.assertInvoked(); |
2233 |
> |
assertNull(h4.join()); |
2234 |
> |
rs[4].assertInvoked(); |
2235 |
|
} catch (CompletionException ok) { |
2236 |
< |
checkCompletedWithWrappedCancellationException(h); |
2237 |
< |
r.assertNotInvoked(); |
2236 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2237 |
> |
rs[4].assertNotInvoked(); |
2238 |
> |
} |
2239 |
> |
try { |
2240 |
> |
assertNull(h5.join()); |
2241 |
> |
rs[5].assertInvoked(); |
2242 |
> |
} catch (CompletionException ok) { |
2243 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2244 |
> |
rs[5].assertNotInvoked(); |
2245 |
|
} |
2246 |
|
|
2247 |
< |
checkCancelled(g); |
2248 |
< |
checkCompletedNormally(f, v1); |
2247 |
> |
checkCancelled(f); |
2248 |
> |
checkCompletedNormally(g, v1); |
2249 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2250 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2251 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2252 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2253 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2254 |
|
}} |
2255 |
|
|
2256 |
< |
public void testRunAfterEither_sourceCancelled4() { |
2256 |
> |
/** |
2257 |
> |
* runAfterEither result completes exceptionally if action does |
2258 |
> |
*/ |
2259 |
> |
public void testRunAfterEither_actionFailed() { |
2260 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2367 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2261 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2262 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
2263 |
|
{ |
2264 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2265 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2266 |
< |
final Noop r = new Noop(m); |
2267 |
< |
|
2374 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2375 |
< |
g.complete(v1); |
2376 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2266 |
> |
final FailingRunnable[] rs = new FailingRunnable[6]; |
2267 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m); |
2268 |
|
|
2269 |
< |
// unspecified behavior |
2270 |
< |
Integer v; |
2271 |
< |
try { |
2272 |
< |
assertNull(h.join()); |
2273 |
< |
r.assertInvoked(); |
2274 |
< |
} catch (CompletionException ok) { |
2275 |
< |
checkCompletedWithWrappedCancellationException(h); |
2276 |
< |
r.assertNotInvoked(); |
2277 |
< |
} |
2269 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2270 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2271 |
> |
f.complete(v1); |
2272 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2273 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2274 |
> |
checkCompletedWithWrappedCFException(h0); |
2275 |
> |
checkCompletedWithWrappedCFException(h1); |
2276 |
> |
checkCompletedWithWrappedCFException(h2); |
2277 |
> |
checkCompletedWithWrappedCFException(h3); |
2278 |
> |
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2279 |
> |
g.complete(v2); |
2280 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2281 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2282 |
> |
checkCompletedWithWrappedCFException(h4); |
2283 |
> |
checkCompletedWithWrappedCFException(h5); |
2284 |
|
|
2285 |
< |
checkCancelled(f); |
2286 |
< |
checkCompletedNormally(g, v1); |
2285 |
> |
checkCompletedNormally(f, v1); |
2286 |
> |
checkCompletedNormally(g, v2); |
2287 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2288 |
|
}} |
2289 |
|
|
2290 |
|
/** |