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 |
|
|
415 |
|
} |
416 |
|
} |
417 |
|
|
418 |
< |
class FailingSupplier extends CheckedAction implements Supplier<Integer> |
418 |
> |
class FailingSupplier extends CheckedAction |
419 |
> |
implements Supplier<Integer> |
420 |
|
{ |
421 |
|
FailingSupplier(ExecutionMode m) { super(m); } |
422 |
|
public Integer get() { |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
< |
class FailingConsumer extends CheckedAction implements Consumer<Integer> { |
428 |
> |
class FailingConsumer extends CheckedIntegerAction |
429 |
> |
implements Consumer<Integer> |
430 |
> |
{ |
431 |
|
FailingConsumer(ExecutionMode m) { super(m); } |
432 |
|
public void accept(Integer x) { |
433 |
|
invoked(); |
434 |
+ |
value = x; |
435 |
|
throw new CFException(); |
436 |
|
} |
437 |
|
} |
438 |
|
|
439 |
< |
class FailingBiConsumer extends CheckedAction |
439 |
> |
class FailingBiConsumer extends CheckedIntegerAction |
440 |
|
implements BiConsumer<Integer, Integer> |
441 |
|
{ |
442 |
|
FailingBiConsumer(ExecutionMode m) { super(m); } |
443 |
|
public void accept(Integer x, Integer y) { |
444 |
|
invoked(); |
445 |
+ |
value = subtract(x, y); |
446 |
|
throw new CFException(); |
447 |
|
} |
448 |
|
} |
449 |
|
|
450 |
< |
class FailingFunction extends CheckedAction |
450 |
> |
class FailingFunction extends CheckedIntegerAction |
451 |
|
implements Function<Integer, Integer> |
452 |
|
{ |
453 |
|
FailingFunction(ExecutionMode m) { super(m); } |
454 |
|
public Integer apply(Integer x) { |
455 |
|
invoked(); |
456 |
+ |
value = x; |
457 |
|
throw new CFException(); |
458 |
|
} |
459 |
|
} |
460 |
|
|
461 |
< |
class FailingBiFunction extends CheckedAction |
461 |
> |
class FailingBiFunction extends CheckedIntegerAction |
462 |
|
implements BiFunction<Integer, Integer, Integer> |
463 |
|
{ |
464 |
|
FailingBiFunction(ExecutionMode m) { super(m); } |
465 |
|
public Integer apply(Integer x, Integer y) { |
466 |
|
invoked(); |
467 |
+ |
value = subtract(x, y); |
468 |
|
throw new CFException(); |
469 |
|
} |
470 |
|
} |
478 |
|
} |
479 |
|
|
480 |
|
|
481 |
< |
class CompletableFutureInc extends CheckedAction |
481 |
> |
class CompletableFutureInc extends CheckedIntegerAction |
482 |
|
implements Function<Integer, CompletableFuture<Integer>> |
483 |
|
{ |
484 |
|
CompletableFutureInc(ExecutionMode m) { super(m); } |
485 |
|
public CompletableFuture<Integer> apply(Integer x) { |
486 |
|
invoked(); |
487 |
+ |
value = x; |
488 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
489 |
|
f.complete(inc(x)); |
490 |
|
return f; |
491 |
|
} |
492 |
|
} |
493 |
|
|
494 |
< |
class FailingCompletableFutureFunction extends CheckedAction |
494 |
> |
class FailingCompletableFutureFunction extends CheckedIntegerAction |
495 |
|
implements Function<Integer, CompletableFuture<Integer>> |
496 |
|
{ |
497 |
|
FailingCompletableFutureFunction(ExecutionMode m) { super(m); } |
498 |
|
public CompletableFuture<Integer> apply(Integer x) { |
499 |
|
invoked(); |
500 |
+ |
value = x; |
501 |
|
throw new CFException(); |
502 |
|
} |
503 |
|
} |
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); |
1253 |
– |
r.assertInvoked(); |
1254 |
– |
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) { |
1861 |
|
f.complete(v1); |
1862 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1863 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1856 |
– |
g.complete(v2); |
1857 |
– |
final CompletableFuture<Integer> h4 = m.applyToEither(f, g, rs[4]); |
1858 |
– |
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1859 |
– |
|
1860 |
– |
checkCompletedNormally(f, v1); |
1861 |
– |
checkCompletedNormally(g, v2); |
1864 |
|
checkCompletedWithWrappedCFException(h0); |
1865 |
|
checkCompletedWithWrappedCFException(h1); |
1866 |
|
checkCompletedWithWrappedCFException(h2); |
1867 |
|
checkCompletedWithWrappedCFException(h3); |
1868 |
< |
checkCompletedWithWrappedCFException(h4); |
1867 |
< |
checkCompletedWithWrappedCFException(h5); |
1868 |
< |
for (int i = 0; i < rs.length; i++) rs[i].assertInvoked(); |
1869 |
< |
}} |
1870 |
< |
|
1871 |
< |
/** |
1872 |
< |
* acceptEither result completes normally after normal completion |
1873 |
< |
* of either source |
1874 |
< |
*/ |
1875 |
< |
public void testAcceptEither_normalCompletion1() { |
1876 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1877 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1878 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1879 |
< |
{ |
1880 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1881 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1882 |
< |
final IncAction r = new IncAction(m); |
1883 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1868 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
1869 |
|
|
1885 |
– |
f.complete(v1); |
1886 |
– |
checkCompletedNormally(h, null); |
1887 |
– |
assertEquals(inc(v1), r.value); |
1870 |
|
g.complete(v2); |
1871 |
|
|
1872 |
< |
checkCompletedNormally(f, v1); |
1873 |
< |
checkCompletedNormally(g, v2); |
1874 |
< |
checkCompletedNormally(h, null); |
1893 |
< |
}} |
1894 |
< |
|
1895 |
< |
public void testAcceptEither_normalCompletion2() { |
1896 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1897 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1898 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1899 |
< |
{ |
1900 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1901 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1902 |
< |
final IncAction r = new IncAction(m); |
1903 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1872 |
> |
// unspecified behavior - both source completions available |
1873 |
> |
final CompletableFuture<Integer> h4 = m.applyToEither(f, g, rs[4]); |
1874 |
> |
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1875 |
|
|
1876 |
< |
g.complete(v2); |
1877 |
< |
checkCompletedNormally(h, null); |
1878 |
< |
assertEquals(inc(v2), r.value); |
1879 |
< |
f.complete(v1); |
1876 |
> |
checkCompletedWithWrappedCFException(h4); |
1877 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
1878 |
> |
Objects.equals(v2, rs[4].value)); |
1879 |
> |
checkCompletedWithWrappedCFException(h5); |
1880 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
1881 |
> |
Objects.equals(v2, rs[5].value)); |
1882 |
|
|
1883 |
|
checkCompletedNormally(f, v1); |
1884 |
|
checkCompletedNormally(g, v2); |
1912 |
– |
checkCompletedNormally(h, null); |
1885 |
|
}} |
1886 |
|
|
1887 |
< |
public void testAcceptEither_normalCompletion3() { |
1887 |
> |
/** |
1888 |
> |
* acceptEither result completes normally after normal completion |
1889 |
> |
* of either source |
1890 |
> |
*/ |
1891 |
> |
public void testAcceptEither_normalCompletion() { |
1892 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1893 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1894 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1895 |
|
{ |
1896 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1897 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1898 |
< |
final IncAction r = 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]); |
1903 |
+ |
checkIncomplete(h0); |
1904 |
+ |
checkIncomplete(h1); |
1905 |
+ |
rs[0].assertNotInvoked(); |
1906 |
+ |
rs[1].assertNotInvoked(); |
1907 |
|
f.complete(v1); |
1908 |
+ |
checkCompletedNormally(h0, null); |
1909 |
+ |
checkCompletedNormally(h1, null); |
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(v1); |
1917 |
+ |
rs[3].assertValue(v1); |
1918 |
|
g.complete(v2); |
1926 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1919 |
|
|
1920 |
< |
checkCompletedNormally(h, null); |
1920 |
> |
// unspecified behavior - both source completions available |
1921 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
1922 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
1923 |
> |
checkCompletedNormally(h4, null); |
1924 |
> |
checkCompletedNormally(h5, null); |
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); |
1932 |
< |
|
1933 |
< |
// unspecified behavior |
1934 |
< |
assertTrue(Objects.equals(r.value, inc(v1)) || |
1935 |
< |
Objects.equals(r.value, inc(v2))); |
1932 |
> |
checkCompletedNormally(h0, null); |
1933 |
> |
checkCompletedNormally(h1, null); |
1934 |
> |
checkCompletedNormally(h2, null); |
1935 |
> |
checkCompletedNormally(h3, null); |
1936 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
1937 |
|
}} |
1938 |
|
|
1939 |
|
/** |
1940 |
|
* acceptEither result completes exceptionally after exceptional |
1941 |
|
* completion of either source |
1942 |
|
*/ |
1943 |
< |
public void testAcceptEither_exceptionalCompletion1() { |
1943 |
> |
public void testAcceptEither_exceptionalCompletion() { |
1944 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1945 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1946 |
|
{ |
1947 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1948 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1947 |
– |
final IncAction r = new IncAction(m); |
1948 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1949 |
|
final CFException ex = new CFException(); |
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]); |
1955 |
+ |
checkIncomplete(h0); |
1956 |
+ |
checkIncomplete(h1); |
1957 |
+ |
rs[0].assertNotInvoked(); |
1958 |
+ |
rs[1].assertNotInvoked(); |
1959 |
|
f.completeExceptionally(ex); |
1960 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1961 |
< |
g.complete(v1); |
1962 |
< |
|
1963 |
< |
r.assertNotInvoked(); |
1964 |
< |
checkCompletedNormally(g, v1); |
1965 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1958 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1959 |
< |
}} |
1960 |
< |
|
1961 |
< |
public void testAcceptEither_exceptionalCompletion2() { |
1962 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1963 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1964 |
< |
{ |
1965 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1966 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1967 |
< |
final IncAction r = new IncAction(m); |
1968 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1969 |
< |
final CFException ex = new CFException(); |
1970 |
< |
|
1971 |
< |
g.completeExceptionally(ex); |
1972 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1973 |
< |
f.complete(v1); |
1974 |
< |
|
1975 |
< |
r.assertNotInvoked(); |
1976 |
< |
checkCompletedNormally(f, v1); |
1977 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1978 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1979 |
< |
}} |
1980 |
< |
|
1981 |
< |
public void testAcceptEither_exceptionalCompletion3() { |
1982 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1983 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1984 |
< |
{ |
1985 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1986 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1987 |
< |
final IncAction r = new IncAction(m); |
1988 |
< |
final CFException ex = new CFException(); |
1960 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
1961 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1962 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
1963 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
1964 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1965 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
1966 |
|
|
1967 |
< |
g.completeExceptionally(ex); |
1991 |
< |
f.complete(v1); |
1992 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1967 |
> |
g.complete(v1); |
1968 |
|
|
1969 |
< |
// unspecified behavior |
1970 |
< |
Integer v; |
1969 |
> |
// unspecified behavior - both source completions available |
1970 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
1971 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
1972 |
|
try { |
1973 |
< |
assertNull(h.join()); |
1974 |
< |
r.assertInvoked(); |
1999 |
< |
assertEquals(inc(v1), r.value); |
1973 |
> |
assertNull(h4.join()); |
1974 |
> |
rs[4].assertValue(v1); |
1975 |
|
} catch (CompletionException ok) { |
1976 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1977 |
< |
r.assertNotInvoked(); |
1976 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
1977 |
> |
rs[4].assertNotInvoked(); |
1978 |
|
} |
2004 |
– |
|
2005 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2006 |
– |
checkCompletedNormally(f, v1); |
2007 |
– |
}} |
2008 |
– |
|
2009 |
– |
public void testAcceptEither_exceptionalCompletion4() { |
2010 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2011 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2012 |
– |
{ |
2013 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2014 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2015 |
– |
final IncAction r = new IncAction(m); |
2016 |
– |
final CFException ex = new CFException(); |
2017 |
– |
|
2018 |
– |
f.completeExceptionally(ex); |
2019 |
– |
g.complete(v1); |
2020 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2021 |
– |
|
2022 |
– |
// unspecified behavior |
2023 |
– |
Integer v; |
1979 |
|
try { |
1980 |
< |
assertNull(h.join()); |
1981 |
< |
r.assertInvoked(); |
2027 |
< |
assertEquals(inc(v1), r.value); |
1980 |
> |
assertNull(h5.join()); |
1981 |
> |
rs[5].assertValue(v1); |
1982 |
|
} catch (CompletionException ok) { |
1983 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1984 |
< |
r.assertNotInvoked(); |
1983 |
> |
checkCompletedWithWrappedCFException(h5, ex); |
1984 |
> |
rs[5].assertNotInvoked(); |
1985 |
|
} |
1986 |
|
|
1987 |
|
checkCompletedWithWrappedCFException(f, ex); |
1988 |
|
checkCompletedNormally(g, v1); |
1989 |
< |
}} |
1990 |
< |
|
1991 |
< |
/** |
1992 |
< |
* acceptEither result completes exceptionally if action does |
1993 |
< |
*/ |
1994 |
< |
public void testAcceptEither_actionFailed1() { |
2041 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2042 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2043 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2044 |
< |
{ |
2045 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2046 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2047 |
< |
final FailingConsumer r = new FailingConsumer(m); |
2048 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2049 |
< |
|
2050 |
< |
f.complete(v1); |
2051 |
< |
checkCompletedWithWrappedCFException(h); |
2052 |
< |
g.complete(v2); |
2053 |
< |
checkCompletedNormally(f, v1); |
2054 |
< |
checkCompletedNormally(g, v2); |
2055 |
< |
}} |
2056 |
< |
|
2057 |
< |
public void testAcceptEither_actionFailed2() { |
2058 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2059 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2060 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2061 |
< |
{ |
2062 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2063 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2064 |
< |
final FailingConsumer r = new FailingConsumer(m); |
2065 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2066 |
< |
|
2067 |
< |
g.complete(v2); |
2068 |
< |
checkCompletedWithWrappedCFException(h); |
2069 |
< |
f.complete(v1); |
2070 |
< |
checkCompletedNormally(f, v1); |
2071 |
< |
checkCompletedNormally(g, v2); |
1989 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
1990 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1991 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1992 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
1993 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
1994 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1995 |
|
}} |
1996 |
|
|
1997 |
|
/** |
1998 |
|
* acceptEither result completes exceptionally if either source cancelled |
1999 |
|
*/ |
2000 |
< |
public void testAcceptEither_sourceCancelled1() { |
2000 |
> |
public void testAcceptEither_sourceCancelled() { |
2001 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2002 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2003 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2004 |
|
{ |
2005 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2006 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2007 |
< |
final IncAction r = new IncAction(m); |
2008 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
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]); |
2012 |
> |
checkIncomplete(h0); |
2013 |
> |
checkIncomplete(h1); |
2014 |
> |
rs[0].assertNotInvoked(); |
2015 |
> |
rs[1].assertNotInvoked(); |
2016 |
> |
f.cancel(mayInterruptIfRunning); |
2017 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2018 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2019 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2020 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2021 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2022 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2023 |
|
|
2087 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2088 |
– |
checkCompletedWithWrappedCancellationException(h); |
2024 |
|
g.complete(v1); |
2025 |
|
|
2026 |
+ |
// unspecified behavior - both source completions available |
2027 |
+ |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2028 |
+ |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2029 |
+ |
try { |
2030 |
+ |
assertNull(h4.join()); |
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(v1); |
2039 |
+ |
} catch (CompletionException ok) { |
2040 |
+ |
checkCompletedWithWrappedCancellationException(h5); |
2041 |
+ |
rs[5].assertNotInvoked(); |
2042 |
+ |
} |
2043 |
+ |
|
2044 |
|
checkCancelled(f); |
2092 |
– |
r.assertNotInvoked(); |
2045 |
|
checkCompletedNormally(g, v1); |
2046 |
< |
checkCompletedWithWrappedCancellationException(h); |
2046 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2047 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2048 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2049 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2050 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2051 |
|
}} |
2052 |
|
|
2053 |
< |
public void testAcceptEither_sourceCancelled2() { |
2053 |
> |
/** |
2054 |
> |
* acceptEither result completes exceptionally if action does |
2055 |
> |
*/ |
2056 |
> |
public void testAcceptEither_actionFailed() { |
2057 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2099 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2058 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2059 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
2060 |
|
{ |
2061 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2062 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2063 |
< |
final IncAction r = new IncAction(m); |
2064 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2063 |
> |
final FailingConsumer[] rs = new FailingConsumer[6]; |
2064 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m); |
2065 |
|
|
2066 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2067 |
< |
checkCompletedWithWrappedCancellationException(h); |
2066 |
> |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2067 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2068 |
|
f.complete(v1); |
2069 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2070 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2071 |
+ |
checkCompletedWithWrappedCFException(h0); |
2072 |
+ |
checkCompletedWithWrappedCFException(h1); |
2073 |
+ |
checkCompletedWithWrappedCFException(h2); |
2074 |
+ |
checkCompletedWithWrappedCFException(h3); |
2075 |
+ |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2076 |
|
|
2077 |
< |
checkCancelled(g); |
2112 |
< |
r.assertNotInvoked(); |
2113 |
< |
checkCompletedNormally(f, v1); |
2114 |
< |
checkCompletedWithWrappedCancellationException(h); |
2115 |
< |
}} |
2116 |
< |
|
2117 |
< |
public void testAcceptEither_sourceCancelled3() { |
2118 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2119 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2120 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2121 |
< |
{ |
2122 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2123 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
< |
final IncAction r = new IncAction(m); |
2077 |
> |
g.complete(v2); |
2078 |
|
|
2079 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2080 |
< |
f.complete(v1); |
2081 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2079 |
> |
// unspecified behavior - both source completions available |
2080 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2081 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2082 |
|
|
2083 |
< |
// unspecified behavior |
2084 |
< |
Integer v; |
2085 |
< |
try { |
2086 |
< |
assertNull(h.join()); |
2087 |
< |
r.assertInvoked(); |
2088 |
< |
assertEquals(inc(v1), r.value); |
2136 |
< |
} catch (CompletionException ok) { |
2137 |
< |
checkCompletedWithWrappedCancellationException(h); |
2138 |
< |
r.assertNotInvoked(); |
2139 |
< |
} |
2083 |
> |
checkCompletedWithWrappedCFException(h4); |
2084 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2085 |
> |
Objects.equals(v2, rs[4].value)); |
2086 |
> |
checkCompletedWithWrappedCFException(h5); |
2087 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2088 |
> |
Objects.equals(v2, rs[5].value)); |
2089 |
|
|
2141 |
– |
checkCancelled(g); |
2090 |
|
checkCompletedNormally(f, v1); |
2091 |
< |
}} |
2144 |
< |
|
2145 |
< |
public void testAcceptEither_sourceCancelled4() { |
2146 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2147 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2148 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2149 |
< |
{ |
2150 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2151 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2152 |
< |
final IncAction r = new IncAction(m); |
2153 |
< |
|
2154 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2155 |
< |
g.complete(v1); |
2156 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2157 |
< |
|
2158 |
< |
// unspecified behavior |
2159 |
< |
Integer v; |
2160 |
< |
try { |
2161 |
< |
assertNull(h.join()); |
2162 |
< |
r.assertInvoked(); |
2163 |
< |
assertEquals(inc(v1), r.value); |
2164 |
< |
} catch (CompletionException ok) { |
2165 |
< |
checkCompletedWithWrappedCancellationException(h); |
2166 |
< |
r.assertNotInvoked(); |
2167 |
< |
} |
2168 |
< |
|
2169 |
< |
checkCancelled(f); |
2170 |
< |
checkCompletedNormally(g, v1); |
2091 |
> |
checkCompletedNormally(g, v2); |
2092 |
|
}} |
2093 |
|
|
2094 |
|
/** |