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) { |
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(); |
1918 |
|
f.complete(v1); |
1919 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1920 |
|
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); |
1921 |
|
checkCompletedWithWrappedCFException(h0); |
1922 |
|
checkCompletedWithWrappedCFException(h1); |
1923 |
|
checkCompletedWithWrappedCFException(h2); |
1924 |
|
checkCompletedWithWrappedCFException(h3); |
1925 |
< |
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); |
1925 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
1926 |
|
|
1885 |
– |
f.complete(v1); |
1886 |
– |
checkCompletedNormally(h, null); |
1887 |
– |
assertEquals(inc(v1), r.value); |
1927 |
|
g.complete(v2); |
1928 |
|
|
1929 |
< |
checkCompletedNormally(f, v1); |
1930 |
< |
checkCompletedNormally(g, v2); |
1931 |
< |
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); |
1929 |
> |
// unspecified behavior - both source completions available |
1930 |
> |
final CompletableFuture<Integer> h4 = m.applyToEither(f, g, rs[4]); |
1931 |
> |
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1932 |
|
|
1933 |
< |
g.complete(v2); |
1934 |
< |
checkCompletedNormally(h, null); |
1935 |
< |
assertEquals(inc(v2), r.value); |
1936 |
< |
f.complete(v1); |
1933 |
> |
checkCompletedWithWrappedCFException(h4); |
1934 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
1935 |
> |
Objects.equals(v2, rs[4].value)); |
1936 |
> |
checkCompletedWithWrappedCFException(h5); |
1937 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
1938 |
> |
Objects.equals(v2, rs[5].value)); |
1939 |
|
|
1940 |
|
checkCompletedNormally(f, v1); |
1941 |
|
checkCompletedNormally(g, v2); |
1912 |
– |
checkCompletedNormally(h, null); |
1942 |
|
}} |
1943 |
|
|
1944 |
< |
public void testAcceptEither_normalCompletion3() { |
1944 |
> |
/** |
1945 |
> |
* acceptEither result completes normally after normal completion |
1946 |
> |
* of either source |
1947 |
> |
*/ |
1948 |
> |
public void testAcceptEither_normalCompletion() { |
1949 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1950 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1951 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1952 |
|
{ |
1953 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1954 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1955 |
< |
final IncAction r = new IncAction(m); |
1955 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
1956 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1957 |
|
|
1958 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
1959 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
1960 |
+ |
checkIncomplete(h0); |
1961 |
+ |
checkIncomplete(h1); |
1962 |
+ |
rs[0].assertNotInvoked(); |
1963 |
+ |
rs[1].assertNotInvoked(); |
1964 |
|
f.complete(v1); |
1965 |
+ |
checkCompletedNormally(h0, null); |
1966 |
+ |
checkCompletedNormally(h1, null); |
1967 |
+ |
rs[0].assertValue(v1); |
1968 |
+ |
rs[1].assertValue(v1); |
1969 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
1970 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
1971 |
+ |
checkCompletedNormally(h2, null); |
1972 |
+ |
checkCompletedNormally(h3, null); |
1973 |
+ |
rs[2].assertValue(v1); |
1974 |
+ |
rs[3].assertValue(v1); |
1975 |
|
g.complete(v2); |
1926 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1976 |
|
|
1977 |
< |
checkCompletedNormally(h, null); |
1977 |
> |
// unspecified behavior - both source completions available |
1978 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
1979 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
1980 |
> |
checkCompletedNormally(h4, null); |
1981 |
> |
checkCompletedNormally(h5, null); |
1982 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
1983 |
> |
Objects.equals(v2, rs[4].value)); |
1984 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
1985 |
> |
Objects.equals(v2, rs[5].value)); |
1986 |
> |
|
1987 |
|
checkCompletedNormally(f, v1); |
1988 |
|
checkCompletedNormally(g, v2); |
1989 |
< |
|
1990 |
< |
// unspecified behavior |
1991 |
< |
assertTrue(Objects.equals(r.value, inc(v1)) || |
1992 |
< |
Objects.equals(r.value, inc(v2))); |
1989 |
> |
checkCompletedNormally(h0, null); |
1990 |
> |
checkCompletedNormally(h1, null); |
1991 |
> |
checkCompletedNormally(h2, null); |
1992 |
> |
checkCompletedNormally(h3, null); |
1993 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
1994 |
|
}} |
1995 |
|
|
1996 |
|
/** |
1997 |
|
* acceptEither result completes exceptionally after exceptional |
1998 |
|
* completion of either source |
1999 |
|
*/ |
2000 |
< |
public void testAcceptEither_exceptionalCompletion1() { |
2000 |
> |
public void testAcceptEither_exceptionalCompletion() { |
2001 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2002 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2003 |
|
{ |
2004 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2005 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1947 |
– |
final IncAction r = new IncAction(m); |
1948 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2006 |
|
final CFException ex = new CFException(); |
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.completeExceptionally(ex); |
2017 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2018 |
< |
g.complete(v1); |
2019 |
< |
|
2020 |
< |
r.assertNotInvoked(); |
2021 |
< |
checkCompletedNormally(g, v1); |
2022 |
< |
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(); |
2017 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2018 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2019 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2020 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2021 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2022 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2023 |
|
|
2024 |
< |
g.completeExceptionally(ex); |
1991 |
< |
f.complete(v1); |
1992 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2024 |
> |
g.complete(v1); |
2025 |
|
|
2026 |
< |
// unspecified behavior |
2027 |
< |
Integer v; |
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(h.join()); |
2031 |
< |
r.assertInvoked(); |
1999 |
< |
assertEquals(inc(v1), r.value); |
2030 |
> |
assertNull(h4.join()); |
2031 |
> |
rs[4].assertValue(v1); |
2032 |
|
} catch (CompletionException ok) { |
2033 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2034 |
< |
r.assertNotInvoked(); |
2033 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2034 |
> |
rs[4].assertNotInvoked(); |
2035 |
|
} |
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; |
2036 |
|
try { |
2037 |
< |
assertNull(h.join()); |
2038 |
< |
r.assertInvoked(); |
2027 |
< |
assertEquals(inc(v1), r.value); |
2037 |
> |
assertNull(h5.join()); |
2038 |
> |
rs[5].assertValue(v1); |
2039 |
|
} catch (CompletionException ok) { |
2040 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2041 |
< |
r.assertNotInvoked(); |
2040 |
> |
checkCompletedWithWrappedCFException(h5, ex); |
2041 |
> |
rs[5].assertNotInvoked(); |
2042 |
|
} |
2043 |
|
|
2044 |
|
checkCompletedWithWrappedCFException(f, ex); |
2045 |
|
checkCompletedNormally(g, v1); |
2046 |
< |
}} |
2047 |
< |
|
2048 |
< |
/** |
2049 |
< |
* acceptEither result completes exceptionally if action does |
2050 |
< |
*/ |
2051 |
< |
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); |
2046 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2047 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2048 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2049 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2050 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2051 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2052 |
|
}} |
2053 |
|
|
2054 |
|
/** |
2055 |
|
* acceptEither result completes exceptionally if either source cancelled |
2056 |
|
*/ |
2057 |
< |
public void testAcceptEither_sourceCancelled1() { |
2078 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2079 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2080 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2081 |
< |
{ |
2082 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2083 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2084 |
< |
final IncAction r = new IncAction(m); |
2085 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2086 |
< |
|
2087 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2088 |
< |
checkCompletedWithWrappedCancellationException(h); |
2089 |
< |
g.complete(v1); |
2090 |
< |
|
2091 |
< |
checkCancelled(f); |
2092 |
< |
r.assertNotInvoked(); |
2093 |
< |
checkCompletedNormally(g, v1); |
2094 |
< |
checkCompletedWithWrappedCancellationException(h); |
2095 |
< |
}} |
2096 |
< |
|
2097 |
< |
public void testAcceptEither_sourceCancelled2() { |
2057 |
> |
public void testAcceptEither_sourceCancelled() { |
2058 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2059 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2060 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2061 |
|
{ |
2062 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2063 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2064 |
< |
final IncAction r = new IncAction(m); |
2065 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2106 |
< |
|
2107 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2108 |
< |
checkCompletedWithWrappedCancellationException(h); |
2109 |
< |
f.complete(v1); |
2064 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2065 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2066 |
|
|
2067 |
< |
checkCancelled(g); |
2068 |
< |
r.assertNotInvoked(); |
2069 |
< |
checkCompletedNormally(f, v1); |
2070 |
< |
checkCompletedWithWrappedCancellationException(h); |
2071 |
< |
}} |
2072 |
< |
|
2073 |
< |
public void testAcceptEither_sourceCancelled3() { |
2074 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2075 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2076 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2077 |
< |
{ |
2078 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2079 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
< |
final IncAction r = new IncAction(m); |
2067 |
> |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2068 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2069 |
> |
checkIncomplete(h0); |
2070 |
> |
checkIncomplete(h1); |
2071 |
> |
rs[0].assertNotInvoked(); |
2072 |
> |
rs[1].assertNotInvoked(); |
2073 |
> |
f.cancel(mayInterruptIfRunning); |
2074 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2075 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2076 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2077 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2078 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2079 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2080 |
|
|
2081 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2127 |
< |
f.complete(v1); |
2128 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2081 |
> |
g.complete(v1); |
2082 |
|
|
2083 |
< |
// unspecified behavior |
2084 |
< |
Integer v; |
2083 |
> |
// unspecified behavior - both source completions available |
2084 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2085 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2086 |
|
try { |
2087 |
< |
assertNull(h.join()); |
2088 |
< |
r.assertInvoked(); |
2135 |
< |
assertEquals(inc(v1), r.value); |
2087 |
> |
assertNull(h4.join()); |
2088 |
> |
rs[4].assertValue(v1); |
2089 |
|
} catch (CompletionException ok) { |
2090 |
< |
checkCompletedWithWrappedCancellationException(h); |
2091 |
< |
r.assertNotInvoked(); |
2090 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2091 |
> |
rs[4].assertNotInvoked(); |
2092 |
|
} |
2140 |
– |
|
2141 |
– |
checkCancelled(g); |
2142 |
– |
checkCompletedNormally(f, v1); |
2143 |
– |
}} |
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; |
2093 |
|
try { |
2094 |
< |
assertNull(h.join()); |
2095 |
< |
r.assertInvoked(); |
2163 |
< |
assertEquals(inc(v1), r.value); |
2094 |
> |
assertNull(h5.join()); |
2095 |
> |
rs[5].assertValue(v1); |
2096 |
|
} catch (CompletionException ok) { |
2097 |
< |
checkCompletedWithWrappedCancellationException(h); |
2098 |
< |
r.assertNotInvoked(); |
2097 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2098 |
> |
rs[5].assertNotInvoked(); |
2099 |
|
} |
2100 |
|
|
2101 |
|
checkCancelled(f); |
2102 |
|
checkCompletedNormally(g, v1); |
2103 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
2104 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
2105 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
2106 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
2107 |
+ |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2108 |
|
}} |
2109 |
|
|
2110 |
|
/** |
2111 |
< |
* runAfterEither result completes normally after normal completion |
2175 |
< |
* of either source |
2111 |
> |
* acceptEither result completes exceptionally if action does |
2112 |
|
*/ |
2113 |
< |
public void testRunAfterEither_normalCompletion1() { |
2113 |
> |
public void testAcceptEither_actionFailed() { |
2114 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2115 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2116 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2117 |
|
{ |
2118 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2119 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2120 |
< |
final Noop r = new Noop(m); |
2121 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2120 |
> |
final FailingConsumer[] rs = new FailingConsumer[6]; |
2121 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m); |
2122 |
|
|
2123 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2124 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2125 |
|
f.complete(v1); |
2126 |
< |
checkCompletedNormally(h, null); |
2127 |
< |
r.assertInvoked(); |
2128 |
< |
g.complete(v2); |
2126 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2127 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2128 |
> |
checkCompletedWithWrappedCFException(h0); |
2129 |
> |
checkCompletedWithWrappedCFException(h1); |
2130 |
> |
checkCompletedWithWrappedCFException(h2); |
2131 |
> |
checkCompletedWithWrappedCFException(h3); |
2132 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2133 |
|
|
2134 |
< |
checkCompletedNormally(f, v1); |
2193 |
< |
checkCompletedNormally(g, v2); |
2194 |
< |
checkCompletedNormally(h, null); |
2195 |
< |
r.assertInvoked(); |
2196 |
< |
}} |
2134 |
> |
g.complete(v2); |
2135 |
|
|
2136 |
< |
public void testRunAfterEither_normalCompletion2() { |
2137 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2138 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2201 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2202 |
< |
{ |
2203 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2204 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2205 |
< |
final Noop r = new Noop(m); |
2206 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2136 |
> |
// unspecified behavior - both source completions available |
2137 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2138 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2139 |
|
|
2140 |
< |
g.complete(v2); |
2141 |
< |
checkCompletedNormally(h, null); |
2142 |
< |
r.assertInvoked(); |
2143 |
< |
f.complete(v1); |
2140 |
> |
checkCompletedWithWrappedCFException(h4); |
2141 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2142 |
> |
Objects.equals(v2, rs[4].value)); |
2143 |
> |
checkCompletedWithWrappedCFException(h5); |
2144 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2145 |
> |
Objects.equals(v2, rs[5].value)); |
2146 |
|
|
2147 |
|
checkCompletedNormally(f, v1); |
2148 |
|
checkCompletedNormally(g, v2); |
2149 |
< |
checkCompletedNormally(h, null); |
2216 |
< |
r.assertInvoked(); |
2217 |
< |
}} |
2149 |
> |
}} |
2150 |
|
|
2151 |
< |
public void testRunAfterEither_normalCompletion3() { |
2151 |
> |
/** |
2152 |
> |
* runAfterEither result completes normally after normal completion |
2153 |
> |
* of either source |
2154 |
> |
*/ |
2155 |
> |
public void testRunAfterEither_normalCompletion() { |
2156 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2157 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2158 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2159 |
|
{ |
2160 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2161 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2162 |
< |
final Noop r = new Noop(m); |
2162 |
> |
final Noop[] rs = new Noop[6]; |
2163 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2164 |
|
|
2165 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2166 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2167 |
+ |
checkIncomplete(h0); |
2168 |
+ |
checkIncomplete(h1); |
2169 |
+ |
rs[0].assertNotInvoked(); |
2170 |
+ |
rs[1].assertNotInvoked(); |
2171 |
|
f.complete(v1); |
2172 |
+ |
checkCompletedNormally(h0, null); |
2173 |
+ |
checkCompletedNormally(h1, null); |
2174 |
+ |
rs[0].assertInvoked(); |
2175 |
+ |
rs[1].assertInvoked(); |
2176 |
+ |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2177 |
+ |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2178 |
+ |
checkCompletedNormally(h2, null); |
2179 |
+ |
checkCompletedNormally(h3, null); |
2180 |
+ |
rs[2].assertInvoked(); |
2181 |
+ |
rs[3].assertInvoked(); |
2182 |
+ |
|
2183 |
|
g.complete(v2); |
2230 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2184 |
|
|
2185 |
< |
checkCompletedNormally(h, null); |
2185 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2186 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2187 |
> |
|
2188 |
|
checkCompletedNormally(f, v1); |
2189 |
|
checkCompletedNormally(g, v2); |
2190 |
< |
r.assertInvoked(); |
2190 |
> |
checkCompletedNormally(h0, null); |
2191 |
> |
checkCompletedNormally(h1, null); |
2192 |
> |
checkCompletedNormally(h2, null); |
2193 |
> |
checkCompletedNormally(h3, null); |
2194 |
> |
checkCompletedNormally(h4, null); |
2195 |
> |
checkCompletedNormally(h5, null); |
2196 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2197 |
|
}} |
2198 |
|
|
2199 |
|
/** |
2200 |
|
* runAfterEither result completes exceptionally after exceptional |
2201 |
|
* completion of either source |
2202 |
|
*/ |
2203 |
< |
public void testRunAfterEither_exceptionalCompletion1() { |
2203 |
> |
public void testRunAfterEither_exceptionalCompletion() { |
2204 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2205 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2206 |
|
{ |
2207 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2208 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2248 |
– |
final Noop r = new Noop(m); |
2249 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2209 |
|
final CFException ex = new CFException(); |
2210 |
+ |
final Noop[] rs = new Noop[6]; |
2211 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2212 |
|
|
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.completeExceptionally(ex); |
2220 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2221 |
< |
g.complete(v1); |
2222 |
< |
|
2223 |
< |
r.assertNotInvoked(); |
2224 |
< |
checkCompletedNormally(g, v1); |
2225 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2259 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2260 |
< |
}} |
2261 |
< |
|
2262 |
< |
public void testRunAfterEither_exceptionalCompletion2() { |
2263 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2264 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2265 |
< |
{ |
2266 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2267 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2268 |
< |
final Noop r = new Noop(m); |
2269 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2270 |
< |
final CFException ex = new CFException(); |
2271 |
< |
|
2272 |
< |
g.completeExceptionally(ex); |
2273 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2274 |
< |
f.complete(v1); |
2275 |
< |
|
2276 |
< |
r.assertNotInvoked(); |
2277 |
< |
checkCompletedNormally(f, v1); |
2278 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2279 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2280 |
< |
}} |
2281 |
< |
|
2282 |
< |
public void testRunAfterEither_exceptionalCompletion3() { |
2283 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2284 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2285 |
< |
{ |
2286 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2287 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2288 |
< |
final Noop r = new Noop(m); |
2289 |
< |
final CFException ex = new CFException(); |
2220 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2221 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2222 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2223 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2224 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2225 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2226 |
|
|
2227 |
< |
g.completeExceptionally(ex); |
2292 |
< |
f.complete(v1); |
2293 |
< |
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 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2237 |
< |
r.assertNotInvoked(); |
2236 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2237 |
> |
rs[4].assertNotInvoked(); |
2238 |
|
} |
2304 |
– |
|
2305 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2306 |
– |
checkCompletedNormally(f, v1); |
2307 |
– |
}} |
2308 |
– |
|
2309 |
– |
public void testRunAfterEither_exceptionalCompletion4() { |
2310 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2311 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2312 |
– |
{ |
2313 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2314 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2315 |
– |
final Noop r = new Noop(m); |
2316 |
– |
final CFException ex = new CFException(); |
2317 |
– |
|
2318 |
– |
f.completeExceptionally(ex); |
2319 |
– |
g.complete(v1); |
2320 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2321 |
– |
|
2322 |
– |
// unspecified behavior |
2323 |
– |
Integer v; |
2239 |
|
try { |
2240 |
< |
assertNull(h.join()); |
2241 |
< |
r.assertInvoked(); |
2240 |
> |
assertNull(h5.join()); |
2241 |
> |
rs[5].assertInvoked(); |
2242 |
|
} catch (CompletionException ok) { |
2243 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2244 |
< |
r.assertNotInvoked(); |
2243 |
> |
checkCompletedWithWrappedCFException(h5, ex); |
2244 |
> |
rs[5].assertNotInvoked(); |
2245 |
|
} |
2246 |
|
|
2247 |
|
checkCompletedWithWrappedCFException(f, ex); |
2248 |
|
checkCompletedNormally(g, v1); |
2249 |
< |
}} |
2250 |
< |
|
2251 |
< |
/** |
2252 |
< |
* runAfterEither result completes exceptionally if action does |
2253 |
< |
*/ |
2254 |
< |
public void testRunAfterEither_actionFailed1() { |
2340 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2341 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2342 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2343 |
< |
{ |
2344 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2345 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2346 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2347 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2348 |
< |
|
2349 |
< |
f.complete(v1); |
2350 |
< |
checkCompletedWithWrappedCFException(h); |
2351 |
< |
g.complete(v2); |
2352 |
< |
checkCompletedNormally(f, v1); |
2353 |
< |
checkCompletedNormally(g, v2); |
2354 |
< |
}} |
2355 |
< |
|
2356 |
< |
public void testRunAfterEither_actionFailed2() { |
2357 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2358 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2359 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2360 |
< |
{ |
2361 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2362 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2363 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2364 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2365 |
< |
|
2366 |
< |
g.complete(v2); |
2367 |
< |
checkCompletedWithWrappedCFException(h); |
2368 |
< |
f.complete(v1); |
2369 |
< |
checkCompletedNormally(f, v1); |
2370 |
< |
checkCompletedNormally(g, v2); |
2249 |
> |
checkCompletedWithWrappedCFException(h0, ex); |
2250 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
2251 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
2252 |
> |
checkCompletedWithWrappedCFException(h3, ex); |
2253 |
> |
checkCompletedWithWrappedCFException(h4, ex); |
2254 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2255 |
|
}} |
2256 |
|
|
2257 |
|
/** |
2258 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2259 |
|
*/ |
2260 |
< |
public void testRunAfterEither_sourceCancelled1() { |
2377 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2378 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2379 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2380 |
< |
{ |
2381 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2382 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2383 |
< |
final Noop r = new Noop(m); |
2384 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2385 |
< |
|
2386 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2387 |
< |
checkCompletedWithWrappedCancellationException(h); |
2388 |
< |
g.complete(v1); |
2389 |
< |
|
2390 |
< |
checkCancelled(f); |
2391 |
< |
r.assertNotInvoked(); |
2392 |
< |
checkCompletedNormally(g, v1); |
2393 |
< |
checkCompletedWithWrappedCancellationException(h); |
2394 |
< |
}} |
2395 |
< |
|
2396 |
< |
public void testRunAfterEither_sourceCancelled2() { |
2260 |
> |
public void testRunAfterEither_sourceCancelled() { |
2261 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2262 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2263 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2264 |
|
{ |
2265 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2266 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2267 |
< |
final Noop r = new Noop(m); |
2268 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2405 |
< |
|
2406 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2407 |
< |
checkCompletedWithWrappedCancellationException(h); |
2408 |
< |
f.complete(v1); |
2267 |
> |
final Noop[] rs = new Noop[6]; |
2268 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2269 |
|
|
2270 |
< |
checkCancelled(g); |
2271 |
< |
r.assertNotInvoked(); |
2272 |
< |
checkCompletedNormally(f, v1); |
2273 |
< |
checkCompletedWithWrappedCancellationException(h); |
2274 |
< |
}} |
2275 |
< |
|
2276 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2277 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2278 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2279 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2280 |
< |
{ |
2281 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2282 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2423 |
< |
final Noop r = new Noop(m); |
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.cancel(mayInterruptIfRunning); |
2277 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2278 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2279 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2280 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2281 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2282 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2283 |
|
|
2284 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2426 |
< |
f.complete(v1); |
2427 |
< |
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 |
< |
checkCompletedWithWrappedCancellationException(h); |
2294 |
< |
r.assertNotInvoked(); |
2293 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2294 |
> |
rs[4].assertNotInvoked(); |
2295 |
> |
} |
2296 |
> |
try { |
2297 |
> |
assertNull(h5.join()); |
2298 |
> |
rs[5].assertInvoked(); |
2299 |
> |
} catch (CompletionException ok) { |
2300 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2301 |
> |
rs[5].assertNotInvoked(); |
2302 |
|
} |
2303 |
|
|
2304 |
< |
checkCancelled(g); |
2305 |
< |
checkCompletedNormally(f, v1); |
2304 |
> |
checkCancelled(f); |
2305 |
> |
checkCompletedNormally(g, v1); |
2306 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2307 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2308 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2309 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2310 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2311 |
|
}} |
2312 |
|
|
2313 |
< |
public void testRunAfterEither_sourceCancelled4() { |
2313 |
> |
/** |
2314 |
> |
* runAfterEither result completes exceptionally if action does |
2315 |
> |
*/ |
2316 |
> |
public void testRunAfterEither_actionFailed() { |
2317 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2445 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2318 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2319 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
2320 |
|
{ |
2321 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2322 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2323 |
< |
final Noop r = new Noop(m); |
2324 |
< |
|
2452 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2453 |
< |
g.complete(v1); |
2454 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2323 |
> |
final FailingRunnable[] rs = new FailingRunnable[6]; |
2324 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m); |
2325 |
|
|
2326 |
< |
// unspecified behavior |
2327 |
< |
Integer v; |
2328 |
< |
try { |
2329 |
< |
assertNull(h.join()); |
2330 |
< |
r.assertInvoked(); |
2331 |
< |
} catch (CompletionException ok) { |
2332 |
< |
checkCompletedWithWrappedCancellationException(h); |
2333 |
< |
r.assertNotInvoked(); |
2334 |
< |
} |
2326 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2327 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2328 |
> |
f.complete(v1); |
2329 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2330 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2331 |
> |
checkCompletedWithWrappedCFException(h0); |
2332 |
> |
checkCompletedWithWrappedCFException(h1); |
2333 |
> |
checkCompletedWithWrappedCFException(h2); |
2334 |
> |
checkCompletedWithWrappedCFException(h3); |
2335 |
> |
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2336 |
> |
g.complete(v2); |
2337 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2338 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2339 |
> |
checkCompletedWithWrappedCFException(h4); |
2340 |
> |
checkCompletedWithWrappedCFException(h5); |
2341 |
|
|
2342 |
< |
checkCancelled(f); |
2343 |
< |
checkCompletedNormally(g, v1); |
2342 |
> |
checkCompletedNormally(f, v1); |
2343 |
> |
checkCompletedNormally(g, v2); |
2344 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2345 |
|
}} |
2346 |
|
|
2347 |
|
/** |