318 |
|
|
319 |
|
// Choose non-commutative actions for better coverage |
320 |
|
|
321 |
< |
// A non-commutative function that handles null values as well, |
322 |
< |
// and produces null values occasionally. |
323 |
< |
public static Integer subtract(Integer x, Integer y) { |
321 |
> |
// A non-commutative function that handles and produces null values as well. |
322 |
> |
static Integer subtract(Integer x, Integer y) { |
323 |
|
return (x == null && y == null) ? null : |
324 |
|
((x == null) ? 42 : x.intValue()) |
325 |
|
- ((y == null) ? 99 : y.intValue()); |
326 |
|
} |
327 |
|
|
328 |
+ |
// A function that handles and produces null values as well. |
329 |
+ |
static Integer inc(Integer x) { |
330 |
+ |
return (x == null) ? null : x + 1; |
331 |
+ |
} |
332 |
+ |
|
333 |
|
static final Supplier<Integer> supplyOne = |
334 |
|
() -> Integer.valueOf(1); |
335 |
|
static final Function<Integer, Integer> inc = |
337 |
|
static final BiFunction<Integer, Integer, Integer> subtract = |
338 |
|
(Integer x, Integer y) -> subtract(x, y); |
339 |
|
static final class IncAction implements Consumer<Integer> { |
340 |
< |
int value; |
341 |
< |
public void accept(Integer x) { value = x.intValue() + 1; } |
340 |
> |
int invocationCount = 0; |
341 |
> |
Integer value; |
342 |
> |
public boolean ran() { return invocationCount == 1; } |
343 |
> |
public void accept(Integer x) { |
344 |
> |
invocationCount++; |
345 |
> |
value = inc(x); |
346 |
> |
} |
347 |
> |
} |
348 |
> |
static final class IncFunction implements Function<Integer,Integer> { |
349 |
> |
int invocationCount = 0; |
350 |
> |
Integer value; |
351 |
> |
public boolean ran() { return invocationCount == 1; } |
352 |
> |
public Integer apply(Integer x) { |
353 |
> |
invocationCount++; |
354 |
> |
return value = inc(x); |
355 |
> |
} |
356 |
|
} |
357 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
358 |
|
int invocationCount = 0; |
467 |
|
BiFunction<? super T,? super U,? extends V> a) { |
468 |
|
return f.thenCombine(g, a); |
469 |
|
} |
470 |
+ |
public <T,U> CompletableFuture<U> applyToEither |
471 |
+ |
(CompletableFuture<T> f, |
472 |
+ |
CompletionStage<? extends T> g, |
473 |
+ |
Function<? super T,U> a) { |
474 |
+ |
return f.applyToEither(g, a); |
475 |
+ |
} |
476 |
+ |
public <T> CompletableFuture<Void> acceptEither |
477 |
+ |
(CompletableFuture<T> f, |
478 |
+ |
CompletionStage<? extends T> g, |
479 |
+ |
Consumer<? super T> a) { |
480 |
+ |
return f.acceptEither(g, a); |
481 |
+ |
} |
482 |
+ |
public <T> CompletableFuture<Void> runAfterEither |
483 |
+ |
(CompletableFuture<T> f, |
484 |
+ |
CompletionStage<?> g, |
485 |
+ |
java.lang.Runnable a) { |
486 |
+ |
return f.runAfterEither(g, a); |
487 |
+ |
} |
488 |
+ |
public <T,U> CompletableFuture<U> thenCompose |
489 |
+ |
(CompletableFuture<T> f, |
490 |
+ |
Function<? super T,? extends CompletionStage<U>> a) { |
491 |
+ |
return f.thenCompose(a); |
492 |
+ |
} |
493 |
+ |
public <T> CompletableFuture<T> whenComplete |
494 |
+ |
(CompletableFuture<T> f, |
495 |
+ |
BiConsumer<? super T,? super Throwable> a) { |
496 |
+ |
return f.whenComplete(a); |
497 |
+ |
} |
498 |
|
}, |
499 |
|
|
500 |
|
// /** Experimental way to do more testing */ |
528 |
|
BiFunction<? super T,? super U,? extends V> a) { |
529 |
|
return f.thenCombineAsync(g, a); |
530 |
|
} |
531 |
+ |
public <T,U> CompletableFuture<U> applyToEither |
532 |
+ |
(CompletableFuture<T> f, |
533 |
+ |
CompletionStage<? extends T> g, |
534 |
+ |
Function<? super T,U> a) { |
535 |
+ |
return f.applyToEitherAsync(g, a); |
536 |
+ |
} |
537 |
+ |
public <T> CompletableFuture<Void> acceptEither |
538 |
+ |
(CompletableFuture<T> f, |
539 |
+ |
CompletionStage<? extends T> g, |
540 |
+ |
Consumer<? super T> a) { |
541 |
+ |
return f.acceptEitherAsync(g, a); |
542 |
+ |
} |
543 |
+ |
public <T> CompletableFuture<Void> runAfterEither |
544 |
+ |
(CompletableFuture<T> f, |
545 |
+ |
CompletionStage<?> g, |
546 |
+ |
java.lang.Runnable a) { |
547 |
+ |
return f.runAfterEitherAsync(g, a); |
548 |
+ |
} |
549 |
+ |
public <T,U> CompletableFuture<U> thenCompose |
550 |
+ |
(CompletableFuture<T> f, |
551 |
+ |
Function<? super T,? extends CompletionStage<U>> a) { |
552 |
+ |
return f.thenComposeAsync(a); |
553 |
+ |
} |
554 |
+ |
public <T> CompletableFuture<T> whenComplete |
555 |
+ |
(CompletableFuture<T> f, |
556 |
+ |
BiConsumer<? super T,? super Throwable> a) { |
557 |
+ |
return f.whenCompleteAsync(a); |
558 |
+ |
} |
559 |
|
}, |
560 |
|
|
561 |
|
// REVERSE_DEFAULT_ASYNC { |
588 |
|
BiFunction<? super T,? super U,? extends V> a) { |
589 |
|
return f.thenCombineAsync(g, a, new ThreadExecutor()); |
590 |
|
} |
591 |
+ |
public <T,U> CompletableFuture<U> applyToEither |
592 |
+ |
(CompletableFuture<T> f, |
593 |
+ |
CompletionStage<? extends T> g, |
594 |
+ |
Function<? super T,U> a) { |
595 |
+ |
return f.applyToEitherAsync(g, a, new ThreadExecutor()); |
596 |
+ |
} |
597 |
+ |
public <T> CompletableFuture<Void> acceptEither |
598 |
+ |
(CompletableFuture<T> f, |
599 |
+ |
CompletionStage<? extends T> g, |
600 |
+ |
Consumer<? super T> a) { |
601 |
+ |
return f.acceptEitherAsync(g, a, new ThreadExecutor()); |
602 |
+ |
} |
603 |
+ |
public <T> CompletableFuture<Void> runAfterEither |
604 |
+ |
(CompletableFuture<T> f, |
605 |
+ |
CompletionStage<?> g, |
606 |
+ |
java.lang.Runnable a) { |
607 |
+ |
return f.runAfterEitherAsync(g, a, new ThreadExecutor()); |
608 |
+ |
} |
609 |
+ |
public <T,U> CompletableFuture<U> thenCompose |
610 |
+ |
(CompletableFuture<T> f, |
611 |
+ |
Function<? super T,? extends CompletionStage<U>> a) { |
612 |
+ |
return f.thenComposeAsync(a, new ThreadExecutor()); |
613 |
+ |
} |
614 |
+ |
public <T> CompletableFuture<T> whenComplete |
615 |
+ |
(CompletableFuture<T> f, |
616 |
+ |
BiConsumer<? super T,? super Throwable> a) { |
617 |
+ |
return f.whenCompleteAsync(a, new ThreadExecutor()); |
618 |
+ |
} |
619 |
|
}; |
620 |
|
|
621 |
|
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
628 |
|
(CompletableFuture<T> f, |
629 |
|
CompletionStage<? extends U> g, |
630 |
|
BiFunction<? super T,? super U,? extends V> a); |
631 |
+ |
public abstract <T,U> CompletableFuture<U> applyToEither |
632 |
+ |
(CompletableFuture<T> f, |
633 |
+ |
CompletionStage<? extends T> g, |
634 |
+ |
Function<? super T,U> a); |
635 |
+ |
public abstract <T> CompletableFuture<Void> acceptEither |
636 |
+ |
(CompletableFuture<T> f, |
637 |
+ |
CompletionStage<? extends T> g, |
638 |
+ |
Consumer<? super T> a); |
639 |
+ |
public abstract <T> CompletableFuture<Void> runAfterEither |
640 |
+ |
(CompletableFuture<T> f, |
641 |
+ |
CompletionStage<?> g, |
642 |
+ |
java.lang.Runnable a); |
643 |
+ |
public abstract <T,U> CompletableFuture<U> thenCompose |
644 |
+ |
(CompletableFuture<T> f, |
645 |
+ |
Function<? super T,? extends CompletionStage<U>> a); |
646 |
+ |
public abstract <T> CompletableFuture<T> whenComplete |
647 |
+ |
(CompletableFuture<T> f, |
648 |
+ |
BiConsumer<? super T,? super Throwable> a); |
649 |
+ |
|
650 |
+ |
|
651 |
|
} |
652 |
|
|
653 |
|
/** |
900 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
901 |
|
f.complete(one); |
902 |
|
checkCompletedNormally(g, null); |
903 |
< |
assertEquals(r.value, 2); |
903 |
> |
assertEquals(r.value, (Integer) 2); |
904 |
|
} |
905 |
|
|
906 |
|
/** |
1844 |
|
* applyToEither result completes normally after normal completion |
1845 |
|
* of either source |
1846 |
|
*/ |
1847 |
< |
public void testApplyToEither() { |
1848 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1849 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1850 |
< |
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1729 |
< |
f.complete(one); |
1730 |
< |
checkCompletedNormally(g, two); |
1731 |
< |
f2.complete(one); |
1732 |
< |
checkCompletedNormally(g, two); |
1847 |
> |
public void testApplyToEither_normalCompletion1() { |
1848 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1849 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1850 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1851 |
|
|
1852 |
< |
f = new CompletableFuture<>(); |
1853 |
< |
f.complete(one); |
1854 |
< |
f2 = new CompletableFuture<>(); |
1855 |
< |
g = f.applyToEither(f2, inc); |
1856 |
< |
checkCompletedNormally(g, two); |
1852 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1853 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1854 |
> |
final IncFunction r = new IncFunction(); |
1855 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1856 |
> |
|
1857 |
> |
f.complete(v1); |
1858 |
> |
checkCompletedNormally(h, inc(v1)); |
1859 |
> |
g.complete(v2); |
1860 |
> |
|
1861 |
> |
checkCompletedNormally(f, v1); |
1862 |
> |
checkCompletedNormally(g, v2); |
1863 |
> |
checkCompletedNormally(h, inc(v1)); |
1864 |
> |
} |
1865 |
> |
} |
1866 |
> |
|
1867 |
> |
public void testApplyToEither_normalCompletion2() { |
1868 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1869 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1870 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1871 |
> |
|
1872 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1873 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1874 |
> |
final IncFunction r = new IncFunction(); |
1875 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1876 |
> |
|
1877 |
> |
g.complete(v2); |
1878 |
> |
checkCompletedNormally(h, inc(v2)); |
1879 |
> |
f.complete(v1); |
1880 |
> |
|
1881 |
> |
checkCompletedNormally(f, v1); |
1882 |
> |
checkCompletedNormally(g, v2); |
1883 |
> |
checkCompletedNormally(h, inc(v2)); |
1884 |
> |
} |
1885 |
> |
} |
1886 |
> |
public void testApplyToEither_normalCompletion3() { |
1887 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1888 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1889 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1890 |
> |
|
1891 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1892 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1893 |
> |
final IncFunction r = new IncFunction(); |
1894 |
> |
|
1895 |
> |
f.complete(v1); |
1896 |
> |
g.complete(v2); |
1897 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1898 |
> |
|
1899 |
> |
checkCompletedNormally(f, v1); |
1900 |
> |
checkCompletedNormally(g, v2); |
1901 |
> |
|
1902 |
> |
// unspecified behavior |
1903 |
> |
assertTrue(Objects.equals(h.join(), inc(v1)) || |
1904 |
> |
Objects.equals(h.join(), inc(v2))); |
1905 |
> |
} |
1906 |
|
} |
1907 |
|
|
1908 |
|
/** |
1909 |
|
* applyToEither result completes exceptionally after exceptional |
1910 |
|
* completion of either source |
1911 |
|
*/ |
1912 |
< |
public void testApplyToEither2() { |
1913 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1914 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1748 |
< |
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
1749 |
< |
f.completeExceptionally(new CFException()); |
1750 |
< |
f2.complete(one); |
1751 |
< |
checkCompletedWithWrappedCFException(g); |
1912 |
> |
public void testApplyToEither_exceptionalCompletion1() { |
1913 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1914 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1915 |
|
|
1916 |
< |
f = new CompletableFuture<>(); |
1917 |
< |
f2 = new CompletableFuture<>(); |
1918 |
< |
f2.completeExceptionally(new CFException()); |
1919 |
< |
g = f.applyToEither(f2, inc); |
1920 |
< |
checkCompletedWithWrappedCFException(g); |
1916 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1917 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1918 |
> |
final IncFunction r = new IncFunction(); |
1919 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1920 |
> |
final CFException ex = new CFException(); |
1921 |
> |
|
1922 |
> |
f.completeExceptionally(ex); |
1923 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1924 |
> |
g.complete(v1); |
1925 |
> |
|
1926 |
> |
assertFalse(r.ran()); |
1927 |
> |
checkCompletedNormally(g, v1); |
1928 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1929 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1930 |
> |
} |
1931 |
> |
} |
1932 |
> |
|
1933 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1934 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1935 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1936 |
> |
|
1937 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1938 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1939 |
> |
final IncFunction r = new IncFunction(); |
1940 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1941 |
> |
final CFException ex = new CFException(); |
1942 |
> |
|
1943 |
> |
g.completeExceptionally(ex); |
1944 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1945 |
> |
f.complete(v1); |
1946 |
> |
|
1947 |
> |
assertFalse(r.ran()); |
1948 |
> |
checkCompletedNormally(f, v1); |
1949 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1950 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1951 |
> |
} |
1952 |
> |
} |
1953 |
> |
|
1954 |
> |
public void testApplyToEither_exceptionalCompletion3() { |
1955 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1956 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1957 |
> |
|
1958 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1959 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1960 |
> |
final IncFunction r = new IncFunction(); |
1961 |
> |
final CFException ex = new CFException(); |
1962 |
> |
|
1963 |
> |
g.completeExceptionally(ex); |
1964 |
> |
f.complete(v1); |
1965 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1966 |
> |
|
1967 |
> |
// unspecified behavior |
1968 |
> |
Integer v; |
1969 |
> |
try { |
1970 |
> |
assertEquals(h.join(), inc(v1)); |
1971 |
> |
assertTrue(r.ran()); |
1972 |
> |
} catch (CompletionException ok) { |
1973 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1974 |
> |
assertFalse(r.ran()); |
1975 |
> |
} |
1976 |
> |
|
1977 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1978 |
> |
checkCompletedNormally(f, v1); |
1979 |
> |
} |
1980 |
> |
} |
1981 |
> |
|
1982 |
> |
public void testApplyToEither_exceptionalCompletion4() { |
1983 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1984 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1985 |
> |
|
1986 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1987 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1988 |
> |
final IncFunction r = new IncFunction(); |
1989 |
> |
final CFException ex = new CFException(); |
1990 |
> |
|
1991 |
> |
f.completeExceptionally(ex); |
1992 |
> |
g.complete(v1); |
1993 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1994 |
> |
|
1995 |
> |
// unspecified behavior |
1996 |
> |
Integer v; |
1997 |
> |
try { |
1998 |
> |
assertEquals(h.join(), inc(v1)); |
1999 |
> |
assertTrue(r.ran()); |
2000 |
> |
} catch (CompletionException ok) { |
2001 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2002 |
> |
assertFalse(r.ran()); |
2003 |
> |
} |
2004 |
> |
|
2005 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2006 |
> |
assertFalse(r.ran()); |
2007 |
> |
checkCompletedNormally(g, v1); |
2008 |
> |
} |
2009 |
|
} |
2010 |
|
|
2011 |
|
/** |
2012 |
|
* applyToEither result completes exceptionally if action does |
2013 |
|
*/ |
2014 |
< |
public void testApplyToEither3() { |
2015 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2016 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2017 |
< |
FailingFunction r = new FailingFunction(); |
2018 |
< |
CompletableFuture<Integer> g = f.applyToEither(f2, r); |
2019 |
< |
f2.complete(two); |
2020 |
< |
checkCompletedWithWrappedCFException(g); |
2014 |
> |
public void testApplyToEither_actionFailed1() { |
2015 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2016 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2017 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2018 |
> |
|
2019 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2020 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2021 |
> |
final FailingFunction r = new FailingFunction(); |
2022 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2023 |
> |
|
2024 |
> |
f.complete(v1); |
2025 |
> |
checkCompletedWithWrappedCFException(h); |
2026 |
> |
g.complete(v2); |
2027 |
> |
checkCompletedNormally(f, v1); |
2028 |
> |
checkCompletedNormally(g, v2); |
2029 |
> |
} |
2030 |
> |
} |
2031 |
> |
|
2032 |
> |
public void testApplyToEither_actionFailed2() { |
2033 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2034 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2035 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2036 |
> |
|
2037 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2038 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2039 |
> |
final FailingFunction r = new FailingFunction(); |
2040 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2041 |
> |
|
2042 |
> |
g.complete(v2); |
2043 |
> |
checkCompletedWithWrappedCFException(h); |
2044 |
> |
f.complete(v1); |
2045 |
> |
checkCompletedNormally(f, v1); |
2046 |
> |
checkCompletedNormally(g, v2); |
2047 |
> |
} |
2048 |
|
} |
2049 |
|
|
2050 |
|
/** |
2051 |
|
* applyToEither result completes exceptionally if either source cancelled |
2052 |
|
*/ |
2053 |
< |
public void testApplyToEither4() { |
2054 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2055 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2056 |
< |
CompletableFuture<Integer> g = f.applyToEither(f2, inc); |
2057 |
< |
assertTrue(f.cancel(true)); |
2058 |
< |
checkCompletedWithWrappedCancellationException(g); |
2059 |
< |
f = new CompletableFuture<>(); |
2060 |
< |
f2 = new CompletableFuture<>(); |
2061 |
< |
assertTrue(f2.cancel(true)); |
2062 |
< |
checkCompletedWithWrappedCancellationException(g); |
2053 |
> |
public void testApplyToEither_sourceCancelled1() { |
2054 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2055 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2056 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2057 |
> |
|
2058 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2059 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2060 |
> |
final IncFunction r = new IncFunction(); |
2061 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2062 |
> |
|
2063 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2064 |
> |
checkCompletedWithWrappedCancellationException(h); |
2065 |
> |
g.complete(v1); |
2066 |
> |
|
2067 |
> |
checkCancelled(f); |
2068 |
> |
assertFalse(r.ran()); |
2069 |
> |
checkCompletedNormally(g, v1); |
2070 |
> |
checkCompletedWithWrappedCancellationException(h); |
2071 |
> |
} |
2072 |
> |
} |
2073 |
> |
|
2074 |
> |
public void testApplyToEither_sourceCancelled2() { |
2075 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2076 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2077 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2078 |
> |
|
2079 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2080 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2081 |
> |
final IncFunction r = new IncFunction(); |
2082 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2083 |
> |
|
2084 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2085 |
> |
checkCompletedWithWrappedCancellationException(h); |
2086 |
> |
f.complete(v1); |
2087 |
> |
|
2088 |
> |
checkCancelled(g); |
2089 |
> |
assertFalse(r.ran()); |
2090 |
> |
checkCompletedNormally(f, v1); |
2091 |
> |
checkCompletedWithWrappedCancellationException(h); |
2092 |
> |
} |
2093 |
> |
} |
2094 |
> |
|
2095 |
> |
public void testApplyToEither_sourceCancelled3() { |
2096 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2097 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2098 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2099 |
> |
|
2100 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2101 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2102 |
> |
final IncFunction r = new IncFunction(); |
2103 |
> |
|
2104 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2105 |
> |
f.complete(v1); |
2106 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2107 |
> |
|
2108 |
> |
// unspecified behavior |
2109 |
> |
Integer v; |
2110 |
> |
try { |
2111 |
> |
assertEquals(h.join(), inc(v1)); |
2112 |
> |
assertTrue(r.ran()); |
2113 |
> |
} catch (CompletionException ok) { |
2114 |
> |
checkCompletedWithWrappedCancellationException(h); |
2115 |
> |
assertFalse(r.ran()); |
2116 |
> |
} |
2117 |
> |
|
2118 |
> |
checkCancelled(g); |
2119 |
> |
checkCompletedNormally(f, v1); |
2120 |
> |
} |
2121 |
> |
} |
2122 |
> |
|
2123 |
> |
public void testApplyToEither_sourceCancelled4() { |
2124 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2125 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2126 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2127 |
> |
|
2128 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2129 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2130 |
> |
final IncFunction r = new IncFunction(); |
2131 |
> |
|
2132 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2133 |
> |
g.complete(v1); |
2134 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2135 |
> |
|
2136 |
> |
// unspecified behavior |
2137 |
> |
Integer v; |
2138 |
> |
try { |
2139 |
> |
assertEquals(h.join(), inc(v1)); |
2140 |
> |
assertTrue(r.ran()); |
2141 |
> |
} catch (CompletionException ok) { |
2142 |
> |
checkCompletedWithWrappedCancellationException(h); |
2143 |
> |
assertFalse(r.ran()); |
2144 |
> |
} |
2145 |
> |
|
2146 |
> |
checkCancelled(f); |
2147 |
> |
checkCompletedNormally(g, v1); |
2148 |
> |
} |
2149 |
|
} |
2150 |
|
|
2151 |
|
/** |
2152 |
|
* acceptEither result completes normally after normal completion |
2153 |
|
* of either source |
2154 |
|
*/ |
2155 |
< |
public void testAcceptEither() { |
2156 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2157 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2158 |
< |
IncAction r = new IncAction(); |
1795 |
< |
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1796 |
< |
f.complete(one); |
1797 |
< |
checkCompletedNormally(g, null); |
1798 |
< |
f2.complete(one); |
1799 |
< |
checkCompletedNormally(g, null); |
1800 |
< |
assertEquals(r.value, 2); |
2155 |
> |
public void testAcceptEither_normalCompletion1() { |
2156 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2157 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2158 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2159 |
|
|
2160 |
< |
r = new IncAction(); |
2161 |
< |
f = new CompletableFuture<>(); |
2162 |
< |
f.complete(one); |
2163 |
< |
f2 = new CompletableFuture<>(); |
2164 |
< |
g = f.acceptEither(f2, r); |
2165 |
< |
checkCompletedNormally(g, null); |
2166 |
< |
assertEquals(r.value, 2); |
2160 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2161 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2162 |
> |
final IncAction r = new IncAction(); |
2163 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2164 |
> |
|
2165 |
> |
f.complete(v1); |
2166 |
> |
checkCompletedNormally(h, null); |
2167 |
> |
assertEquals(r.value, inc(v1)); |
2168 |
> |
g.complete(v2); |
2169 |
> |
|
2170 |
> |
checkCompletedNormally(f, v1); |
2171 |
> |
checkCompletedNormally(g, v2); |
2172 |
> |
checkCompletedNormally(h, null); |
2173 |
> |
} |
2174 |
> |
} |
2175 |
> |
|
2176 |
> |
public void testAcceptEither_normalCompletion2() { |
2177 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2178 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2179 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2180 |
> |
|
2181 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2182 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2183 |
> |
final IncAction r = new IncAction(); |
2184 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2185 |
> |
|
2186 |
> |
g.complete(v2); |
2187 |
> |
checkCompletedNormally(h, null); |
2188 |
> |
assertEquals(r.value, inc(v2)); |
2189 |
> |
f.complete(v1); |
2190 |
> |
|
2191 |
> |
checkCompletedNormally(f, v1); |
2192 |
> |
checkCompletedNormally(g, v2); |
2193 |
> |
checkCompletedNormally(h, null); |
2194 |
> |
} |
2195 |
> |
} |
2196 |
> |
public void testAcceptEither_normalCompletion3() { |
2197 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2198 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2199 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2200 |
> |
|
2201 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2202 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2203 |
> |
final IncAction r = new IncAction(); |
2204 |
> |
|
2205 |
> |
f.complete(v1); |
2206 |
> |
g.complete(v2); |
2207 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2208 |
> |
|
2209 |
> |
checkCompletedNormally(h, null); |
2210 |
> |
checkCompletedNormally(f, v1); |
2211 |
> |
checkCompletedNormally(g, v2); |
2212 |
> |
|
2213 |
> |
// unspecified behavior |
2214 |
> |
assertTrue(Objects.equals(r.value, inc(v1)) || |
2215 |
> |
Objects.equals(r.value, inc(v2))); |
2216 |
> |
} |
2217 |
|
} |
2218 |
|
|
2219 |
|
/** |
2220 |
|
* acceptEither result completes exceptionally after exceptional |
2221 |
|
* completion of either source |
2222 |
|
*/ |
2223 |
< |
public void testAcceptEither2() { |
2224 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2225 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1818 |
< |
IncAction r = new IncAction(); |
1819 |
< |
CompletableFuture<Void> g = f.acceptEither(f2, r); |
1820 |
< |
f.completeExceptionally(new CFException()); |
1821 |
< |
f2.complete(one); |
1822 |
< |
checkCompletedWithWrappedCFException(g); |
2223 |
> |
public void testAcceptEither_exceptionalCompletion1() { |
2224 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2225 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2226 |
|
|
2227 |
< |
r = new IncAction(); |
2228 |
< |
f = new CompletableFuture<>(); |
2229 |
< |
f2 = new CompletableFuture<>(); |
2230 |
< |
f2.completeExceptionally(new CFException()); |
2231 |
< |
g = f.acceptEither(f2, r); |
2232 |
< |
checkCompletedWithWrappedCFException(g); |
2227 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2228 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2229 |
> |
final IncAction r = new IncAction(); |
2230 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2231 |
> |
final CFException ex = new CFException(); |
2232 |
> |
|
2233 |
> |
f.completeExceptionally(ex); |
2234 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2235 |
> |
g.complete(v1); |
2236 |
> |
|
2237 |
> |
assertFalse(r.ran()); |
2238 |
> |
checkCompletedNormally(g, v1); |
2239 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2240 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2241 |
> |
} |
2242 |
> |
} |
2243 |
> |
|
2244 |
> |
public void testAcceptEither_exceptionalCompletion2() { |
2245 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2246 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2247 |
> |
|
2248 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2249 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2250 |
> |
final IncAction r = new IncAction(); |
2251 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2252 |
> |
final CFException ex = new CFException(); |
2253 |
> |
|
2254 |
> |
g.completeExceptionally(ex); |
2255 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2256 |
> |
f.complete(v1); |
2257 |
> |
|
2258 |
> |
assertFalse(r.ran()); |
2259 |
> |
checkCompletedNormally(f, v1); |
2260 |
> |
checkCompletedWithWrappedCFException(g, ex); |
2261 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2262 |
> |
} |
2263 |
> |
} |
2264 |
> |
|
2265 |
> |
public void testAcceptEither_exceptionalCompletion3() { |
2266 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2267 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2268 |
> |
|
2269 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2270 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2271 |
> |
final IncAction r = new IncAction(); |
2272 |
> |
final CFException ex = new CFException(); |
2273 |
> |
|
2274 |
> |
g.completeExceptionally(ex); |
2275 |
> |
f.complete(v1); |
2276 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2277 |
> |
|
2278 |
> |
// unspecified behavior |
2279 |
> |
Integer v; |
2280 |
> |
try { |
2281 |
> |
assertEquals(h.join(), null); |
2282 |
> |
assertTrue(r.ran()); |
2283 |
> |
assertEquals(inc(v1), r.value); |
2284 |
> |
} catch (CompletionException ok) { |
2285 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2286 |
> |
assertFalse(r.ran()); |
2287 |
> |
} |
2288 |
> |
|
2289 |
> |
checkCompletedWithWrappedCFException(g, ex); |
2290 |
> |
checkCompletedNormally(f, v1); |
2291 |
> |
} |
2292 |
> |
} |
2293 |
> |
|
2294 |
> |
public void testAcceptEither_exceptionalCompletion4() { |
2295 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2296 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2297 |
> |
|
2298 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2299 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2300 |
> |
final IncAction r = new IncAction(); |
2301 |
> |
final CFException ex = new CFException(); |
2302 |
> |
|
2303 |
> |
f.completeExceptionally(ex); |
2304 |
> |
g.complete(v1); |
2305 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2306 |
> |
|
2307 |
> |
// unspecified behavior |
2308 |
> |
Integer v; |
2309 |
> |
try { |
2310 |
> |
assertEquals(h.join(), null); |
2311 |
> |
assertTrue(r.ran()); |
2312 |
> |
assertEquals(inc(v1), r.value); |
2313 |
> |
} catch (CompletionException ok) { |
2314 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2315 |
> |
assertFalse(r.ran()); |
2316 |
> |
} |
2317 |
> |
|
2318 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2319 |
> |
assertFalse(r.ran()); |
2320 |
> |
checkCompletedNormally(g, v1); |
2321 |
> |
} |
2322 |
|
} |
2323 |
|
|
2324 |
|
/** |
2325 |
|
* acceptEither result completes exceptionally if action does |
2326 |
|
*/ |
2327 |
< |
public void testAcceptEither3() { |
2328 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2329 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2330 |
< |
FailingConsumer r = new FailingConsumer(); |
2331 |
< |
CompletableFuture<Void> g = f.acceptEither(f2, r); |
2332 |
< |
f2.complete(two); |
2333 |
< |
checkCompletedWithWrappedCFException(g); |
2327 |
> |
public void testAcceptEither_actionFailed1() { |
2328 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2329 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2330 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2331 |
> |
|
2332 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2333 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2334 |
> |
final FailingConsumer r = new FailingConsumer(); |
2335 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2336 |
> |
|
2337 |
> |
f.complete(v1); |
2338 |
> |
checkCompletedWithWrappedCFException(h); |
2339 |
> |
g.complete(v2); |
2340 |
> |
checkCompletedNormally(f, v1); |
2341 |
> |
checkCompletedNormally(g, v2); |
2342 |
> |
} |
2343 |
> |
} |
2344 |
> |
|
2345 |
> |
public void testAcceptEither_actionFailed2() { |
2346 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2347 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2348 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2349 |
> |
|
2350 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2351 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2352 |
> |
final FailingConsumer r = new FailingConsumer(); |
2353 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2354 |
> |
|
2355 |
> |
g.complete(v2); |
2356 |
> |
checkCompletedWithWrappedCFException(h); |
2357 |
> |
f.complete(v1); |
2358 |
> |
checkCompletedNormally(f, v1); |
2359 |
> |
checkCompletedNormally(g, v2); |
2360 |
> |
} |
2361 |
|
} |
2362 |
|
|
2363 |
|
/** |
2364 |
|
* acceptEither result completes exceptionally if either source cancelled |
2365 |
|
*/ |
2366 |
< |
public void testAcceptEither4() { |
2367 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2368 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2369 |
< |
IncAction r = new IncAction(); |
2370 |
< |
CompletableFuture<Void> g = f.acceptEither(f2, r); |
2371 |
< |
assertTrue(f.cancel(true)); |
2372 |
< |
checkCompletedWithWrappedCancellationException(g); |
2373 |
< |
f = new CompletableFuture<>(); |
2374 |
< |
f2 = new CompletableFuture<>(); |
2375 |
< |
assertTrue(f2.cancel(true)); |
2376 |
< |
checkCompletedWithWrappedCancellationException(g); |
2366 |
> |
public void testAcceptEither_sourceCancelled1() { |
2367 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2368 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2369 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2370 |
> |
|
2371 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2372 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2373 |
> |
final IncAction r = new IncAction(); |
2374 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2375 |
> |
|
2376 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2377 |
> |
checkCompletedWithWrappedCancellationException(h); |
2378 |
> |
g.complete(v1); |
2379 |
> |
|
2380 |
> |
checkCancelled(f); |
2381 |
> |
assertFalse(r.ran()); |
2382 |
> |
checkCompletedNormally(g, v1); |
2383 |
> |
checkCompletedWithWrappedCancellationException(h); |
2384 |
> |
} |
2385 |
> |
} |
2386 |
> |
|
2387 |
> |
public void testAcceptEither_sourceCancelled2() { |
2388 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2389 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2390 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2391 |
> |
|
2392 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2393 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2394 |
> |
final IncAction r = new IncAction(); |
2395 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2396 |
> |
|
2397 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2398 |
> |
checkCompletedWithWrappedCancellationException(h); |
2399 |
> |
f.complete(v1); |
2400 |
> |
|
2401 |
> |
checkCancelled(g); |
2402 |
> |
assertFalse(r.ran()); |
2403 |
> |
checkCompletedNormally(f, v1); |
2404 |
> |
checkCompletedWithWrappedCancellationException(h); |
2405 |
> |
} |
2406 |
> |
} |
2407 |
> |
|
2408 |
> |
public void testAcceptEither_sourceCancelled3() { |
2409 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2410 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2411 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2412 |
> |
|
2413 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2414 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2415 |
> |
final IncAction r = new IncAction(); |
2416 |
> |
|
2417 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2418 |
> |
f.complete(v1); |
2419 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2420 |
> |
|
2421 |
> |
// unspecified behavior |
2422 |
> |
Integer v; |
2423 |
> |
try { |
2424 |
> |
assertEquals(h.join(), null); |
2425 |
> |
assertTrue(r.ran()); |
2426 |
> |
assertEquals(inc(v1), r.value); |
2427 |
> |
} catch (CompletionException ok) { |
2428 |
> |
checkCompletedWithWrappedCancellationException(h); |
2429 |
> |
assertFalse(r.ran()); |
2430 |
> |
} |
2431 |
> |
|
2432 |
> |
checkCancelled(g); |
2433 |
> |
checkCompletedNormally(f, v1); |
2434 |
> |
} |
2435 |
> |
} |
2436 |
> |
|
2437 |
> |
public void testAcceptEither_sourceCancelled4() { |
2438 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2439 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2440 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2441 |
> |
|
2442 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2443 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2444 |
> |
final IncAction r = new IncAction(); |
2445 |
> |
|
2446 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2447 |
> |
g.complete(v1); |
2448 |
> |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2449 |
> |
|
2450 |
> |
// unspecified behavior |
2451 |
> |
Integer v; |
2452 |
> |
try { |
2453 |
> |
assertEquals(h.join(), null); |
2454 |
> |
assertTrue(r.ran()); |
2455 |
> |
assertEquals(inc(v1), r.value); |
2456 |
> |
} catch (CompletionException ok) { |
2457 |
> |
checkCompletedWithWrappedCancellationException(h); |
2458 |
> |
assertFalse(r.ran()); |
2459 |
> |
} |
2460 |
> |
|
2461 |
> |
checkCancelled(f); |
2462 |
> |
checkCompletedNormally(g, v1); |
2463 |
> |
} |
2464 |
|
} |
2465 |
|
|
2466 |
|
/** |
2721 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2722 |
|
f.complete(one); |
2723 |
|
checkCompletedNormally(g, null); |
2724 |
< |
assertEquals(r.value, 2); |
2724 |
> |
assertEquals(r.value, (Integer) 2); |
2725 |
|
} |
2726 |
|
|
2727 |
|
/** |
2759 |
|
} |
2760 |
|
|
2761 |
|
/** |
2156 |
– |
* applyToEitherAsync result completes normally after normal |
2157 |
– |
* completion of sources |
2158 |
– |
*/ |
2159 |
– |
public void testApplyToEitherAsync() { |
2160 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2161 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2162 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
2163 |
– |
f.complete(one); |
2164 |
– |
checkCompletedNormally(g, two); |
2165 |
– |
|
2166 |
– |
f = new CompletableFuture<>(); |
2167 |
– |
f.complete(one); |
2168 |
– |
f2 = new CompletableFuture<>(); |
2169 |
– |
g = f.applyToEitherAsync(f2, inc); |
2170 |
– |
checkCompletedNormally(g, two); |
2171 |
– |
} |
2172 |
– |
|
2173 |
– |
/** |
2174 |
– |
* applyToEitherAsync result completes exceptionally after exceptional |
2175 |
– |
* completion of source |
2176 |
– |
*/ |
2177 |
– |
public void testApplyToEitherAsync2() { |
2178 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2179 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2180 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
2181 |
– |
f.completeExceptionally(new CFException()); |
2182 |
– |
checkCompletedWithWrappedCFException(g); |
2183 |
– |
|
2184 |
– |
f = new CompletableFuture<>(); |
2185 |
– |
f2 = new CompletableFuture<>(); |
2186 |
– |
f2.completeExceptionally(new CFException()); |
2187 |
– |
g = f.applyToEitherAsync(f2, inc); |
2188 |
– |
f.complete(one); |
2189 |
– |
checkCompletedWithWrappedCFException(g); |
2190 |
– |
} |
2191 |
– |
|
2192 |
– |
/** |
2193 |
– |
* applyToEitherAsync result completes exceptionally if action does |
2194 |
– |
*/ |
2195 |
– |
public void testApplyToEitherAsync3() { |
2196 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2197 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2198 |
– |
FailingFunction r = new FailingFunction(); |
2199 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r); |
2200 |
– |
f.complete(one); |
2201 |
– |
checkCompletedWithWrappedCFException(g); |
2202 |
– |
} |
2203 |
– |
|
2204 |
– |
/** |
2205 |
– |
* applyToEitherAsync result completes exceptionally if either source cancelled |
2206 |
– |
*/ |
2207 |
– |
public void testApplyToEitherAsync4() { |
2208 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2209 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2210 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
2211 |
– |
assertTrue(f.cancel(true)); |
2212 |
– |
checkCompletedWithWrappedCancellationException(g); |
2213 |
– |
|
2214 |
– |
f = new CompletableFuture<>(); |
2215 |
– |
f2 = new CompletableFuture<>(); |
2216 |
– |
assertTrue(f2.cancel(true)); |
2217 |
– |
g = f.applyToEitherAsync(f2, inc); |
2218 |
– |
checkCompletedWithWrappedCancellationException(g); |
2219 |
– |
} |
2220 |
– |
|
2221 |
– |
/** |
2222 |
– |
* acceptEitherAsync result completes normally after normal |
2223 |
– |
* completion of sources |
2224 |
– |
*/ |
2225 |
– |
public void testAcceptEitherAsync() { |
2226 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2227 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2228 |
– |
IncAction r = new IncAction(); |
2229 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2230 |
– |
f.complete(one); |
2231 |
– |
checkCompletedNormally(g, null); |
2232 |
– |
assertEquals(r.value, 2); |
2233 |
– |
|
2234 |
– |
r = new IncAction(); |
2235 |
– |
f = new CompletableFuture<>(); |
2236 |
– |
f.complete(one); |
2237 |
– |
f2 = new CompletableFuture<>(); |
2238 |
– |
g = f.acceptEitherAsync(f2, r); |
2239 |
– |
checkCompletedNormally(g, null); |
2240 |
– |
assertEquals(r.value, 2); |
2241 |
– |
} |
2242 |
– |
|
2243 |
– |
/** |
2244 |
– |
* acceptEitherAsync result completes exceptionally after exceptional |
2245 |
– |
* completion of source |
2246 |
– |
*/ |
2247 |
– |
public void testAcceptEitherAsync2() { |
2248 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2249 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2250 |
– |
IncAction r = new IncAction(); |
2251 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2252 |
– |
f.completeExceptionally(new CFException()); |
2253 |
– |
checkCompletedWithWrappedCFException(g); |
2254 |
– |
|
2255 |
– |
r = new IncAction(); |
2256 |
– |
f = new CompletableFuture<>(); |
2257 |
– |
f2 = new CompletableFuture<>(); |
2258 |
– |
f2.completeExceptionally(new CFException()); |
2259 |
– |
g = f.acceptEitherAsync(f2, r); |
2260 |
– |
f.complete(one); |
2261 |
– |
checkCompletedWithWrappedCFException(g); |
2262 |
– |
} |
2263 |
– |
|
2264 |
– |
/** |
2265 |
– |
* acceptEitherAsync result completes exceptionally if action does |
2266 |
– |
*/ |
2267 |
– |
public void testAcceptEitherAsync3() { |
2268 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2269 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2270 |
– |
FailingConsumer r = new FailingConsumer(); |
2271 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2272 |
– |
f.complete(one); |
2273 |
– |
checkCompletedWithWrappedCFException(g); |
2274 |
– |
} |
2275 |
– |
|
2276 |
– |
/** |
2277 |
– |
* acceptEitherAsync result completes exceptionally if either |
2278 |
– |
* source cancelled |
2279 |
– |
*/ |
2280 |
– |
public void testAcceptEitherAsync4() { |
2281 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2282 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2283 |
– |
IncAction r = new IncAction(); |
2284 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
2285 |
– |
assertTrue(f.cancel(true)); |
2286 |
– |
checkCompletedWithWrappedCancellationException(g); |
2287 |
– |
|
2288 |
– |
r = new IncAction(); |
2289 |
– |
f = new CompletableFuture<>(); |
2290 |
– |
f2 = new CompletableFuture<>(); |
2291 |
– |
assertTrue(f2.cancel(true)); |
2292 |
– |
g = f.acceptEitherAsync(f2, r); |
2293 |
– |
checkCompletedWithWrappedCancellationException(g); |
2294 |
– |
} |
2295 |
– |
|
2296 |
– |
/** |
2762 |
|
* runAfterEitherAsync result completes normally after normal |
2763 |
|
* completion of sources |
2764 |
|
*/ |
3019 |
|
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3020 |
|
f.complete(one); |
3021 |
|
checkCompletedNormally(g, null); |
3022 |
< |
assertEquals(r.value, 2); |
3022 |
> |
assertEquals(r.value, (Integer) 2); |
3023 |
|
} |
3024 |
|
|
3025 |
|
/** |
3056 |
|
checkCompletedWithWrappedCancellationException(g); |
3057 |
|
} |
3058 |
|
|
2594 |
– |
/** |
2595 |
– |
* applyToEitherAsync result completes normally after normal |
2596 |
– |
* completion of sources |
2597 |
– |
*/ |
2598 |
– |
public void testApplyToEitherAsyncE() { |
2599 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2600 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2601 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2602 |
– |
f.complete(one); |
2603 |
– |
checkCompletedNormally(g, two); |
2604 |
– |
|
2605 |
– |
f = new CompletableFuture<>(); |
2606 |
– |
f.complete(one); |
2607 |
– |
f2 = new CompletableFuture<>(); |
2608 |
– |
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2609 |
– |
checkCompletedNormally(g, two); |
2610 |
– |
} |
2611 |
– |
|
2612 |
– |
/** |
2613 |
– |
* applyToEitherAsync result completes exceptionally after exceptional |
2614 |
– |
* completion of source |
2615 |
– |
*/ |
2616 |
– |
public void testApplyToEitherAsync2E() { |
2617 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2618 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2619 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2620 |
– |
f.completeExceptionally(new CFException()); |
2621 |
– |
checkCompletedWithWrappedCFException(g); |
2622 |
– |
|
2623 |
– |
f = new CompletableFuture<>(); |
2624 |
– |
f2 = new CompletableFuture<>(); |
2625 |
– |
f2.completeExceptionally(new CFException()); |
2626 |
– |
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2627 |
– |
f.complete(one); |
2628 |
– |
checkCompletedWithWrappedCFException(g); |
2629 |
– |
} |
2630 |
– |
|
2631 |
– |
/** |
2632 |
– |
* applyToEitherAsync result completes exceptionally if action does |
2633 |
– |
*/ |
2634 |
– |
public void testApplyToEitherAsync3E() { |
2635 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2636 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2637 |
– |
FailingFunction r = new FailingFunction(); |
2638 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); |
2639 |
– |
f.complete(one); |
2640 |
– |
checkCompletedWithWrappedCFException(g); |
2641 |
– |
} |
2642 |
– |
|
2643 |
– |
/** |
2644 |
– |
* applyToEitherAsync result completes exceptionally if either source cancelled |
2645 |
– |
*/ |
2646 |
– |
public void testApplyToEitherAsync4E() { |
2647 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2648 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2649 |
– |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2650 |
– |
assertTrue(f.cancel(true)); |
2651 |
– |
checkCompletedWithWrappedCancellationException(g); |
2652 |
– |
|
2653 |
– |
f = new CompletableFuture<>(); |
2654 |
– |
f2 = new CompletableFuture<>(); |
2655 |
– |
assertTrue(f2.cancel(true)); |
2656 |
– |
g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2657 |
– |
checkCompletedWithWrappedCancellationException(g); |
2658 |
– |
} |
2659 |
– |
|
2660 |
– |
/** |
2661 |
– |
* acceptEitherAsync result completes normally after normal |
2662 |
– |
* completion of sources |
2663 |
– |
*/ |
2664 |
– |
public void testAcceptEitherAsyncE() { |
2665 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2666 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2667 |
– |
IncAction r = new IncAction(); |
2668 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2669 |
– |
f.complete(one); |
2670 |
– |
checkCompletedNormally(g, null); |
2671 |
– |
assertEquals(r.value, 2); |
2672 |
– |
|
2673 |
– |
r = new IncAction(); |
2674 |
– |
f = new CompletableFuture<>(); |
2675 |
– |
f.complete(one); |
2676 |
– |
f2 = new CompletableFuture<>(); |
2677 |
– |
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2678 |
– |
checkCompletedNormally(g, null); |
2679 |
– |
assertEquals(r.value, 2); |
2680 |
– |
} |
2681 |
– |
|
2682 |
– |
/** |
2683 |
– |
* acceptEitherAsync result completes exceptionally after exceptional |
2684 |
– |
* completion of source |
2685 |
– |
*/ |
2686 |
– |
public void testAcceptEitherAsync2E() { |
2687 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2688 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2689 |
– |
IncAction r = new IncAction(); |
2690 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2691 |
– |
f.completeExceptionally(new CFException()); |
2692 |
– |
checkCompletedWithWrappedCFException(g); |
2693 |
– |
|
2694 |
– |
r = new IncAction(); |
2695 |
– |
f = new CompletableFuture<>(); |
2696 |
– |
f2 = new CompletableFuture<>(); |
2697 |
– |
f2.completeExceptionally(new CFException()); |
2698 |
– |
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2699 |
– |
f.complete(one); |
2700 |
– |
checkCompletedWithWrappedCFException(g); |
2701 |
– |
} |
2702 |
– |
|
2703 |
– |
/** |
2704 |
– |
* acceptEitherAsync result completes exceptionally if action does |
2705 |
– |
*/ |
2706 |
– |
public void testAcceptEitherAsync3E() { |
2707 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2708 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2709 |
– |
FailingConsumer r = new FailingConsumer(); |
2710 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2711 |
– |
f.complete(one); |
2712 |
– |
checkCompletedWithWrappedCFException(g); |
2713 |
– |
} |
2714 |
– |
|
2715 |
– |
/** |
2716 |
– |
* acceptEitherAsync result completes exceptionally if either |
2717 |
– |
* source cancelled |
2718 |
– |
*/ |
2719 |
– |
public void testAcceptEitherAsync4E() { |
2720 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2721 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2722 |
– |
IncAction r = new IncAction(); |
2723 |
– |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2724 |
– |
assertTrue(f.cancel(true)); |
2725 |
– |
checkCompletedWithWrappedCancellationException(g); |
2726 |
– |
|
2727 |
– |
r = new IncAction(); |
2728 |
– |
f = new CompletableFuture<>(); |
2729 |
– |
f2 = new CompletableFuture<>(); |
2730 |
– |
assertTrue(f2.cancel(true)); |
2731 |
– |
g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2732 |
– |
checkCompletedWithWrappedCancellationException(g); |
2733 |
– |
} |
2734 |
– |
|
3059 |
|
/** |
3060 |
|
* runAfterEitherAsync result completes normally after normal |
3061 |
|
* completion of sources |