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(); |