1680 |
|
checkCompletedWithWrappedCFException(h1); |
1681 |
|
checkCompletedWithWrappedCFException(h2); |
1682 |
|
checkCompletedWithWrappedCFException(h3); |
1683 |
+ |
r1.assertInvoked(); |
1684 |
+ |
r2.assertInvoked(); |
1685 |
+ |
r3.assertInvoked(); |
1686 |
|
checkCompletedNormally(f, v1); |
1687 |
|
checkCompletedNormally(g, v2); |
1688 |
|
}} |
1844 |
|
checkCompletedWithWrappedCFException(h1); |
1845 |
|
checkCompletedWithWrappedCFException(h2); |
1846 |
|
checkCompletedWithWrappedCFException(h3); |
1847 |
+ |
r1.assertInvoked(); |
1848 |
+ |
r2.assertInvoked(); |
1849 |
+ |
r3.assertInvoked(); |
1850 |
|
checkCompletedNormally(f, v1); |
1851 |
|
checkCompletedNormally(g, v2); |
1852 |
|
}} |
1857 |
|
*/ |
1858 |
|
public void testRunAfterBoth_normalCompletion() { |
1859 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1854 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1860 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1861 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1862 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1863 |
|
{ |
1864 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1865 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1866 |
< |
final Noop r = new Noop(m); |
1866 |
> |
final Noop r1 = new Noop(m); |
1867 |
> |
final Noop r2 = new Noop(m); |
1868 |
> |
final Noop r3 = new Noop(m); |
1869 |
|
|
1870 |
< |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1871 |
< |
if (!createIncomplete) |
1872 |
< |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1873 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1867 |
< |
if (createIncomplete) { |
1868 |
< |
checkIncomplete(h); |
1869 |
< |
r.assertNotInvoked(); |
1870 |
< |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1871 |
< |
} |
1870 |
> |
final CompletableFuture<Integer> fst = fFirst ? f : g; |
1871 |
> |
final CompletableFuture<Integer> snd = !fFirst ? f : g; |
1872 |
> |
final Integer w1 = fFirst ? v1 : v2; |
1873 |
> |
final Integer w2 = !fFirst ? v1 : v2; |
1874 |
|
|
1875 |
< |
checkCompletedNormally(h, null); |
1876 |
< |
r.assertInvoked(); |
1875 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
1876 |
> |
assertTrue(fst.complete(w1)); |
1877 |
> |
final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
1878 |
> |
checkIncomplete(h1); |
1879 |
> |
checkIncomplete(h2); |
1880 |
> |
r1.assertNotInvoked(); |
1881 |
> |
r2.assertNotInvoked(); |
1882 |
> |
assertTrue(snd.complete(w2)); |
1883 |
> |
final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3); |
1884 |
> |
|
1885 |
> |
checkCompletedNormally(h1, null); |
1886 |
> |
checkCompletedNormally(h2, null); |
1887 |
> |
checkCompletedNormally(h3, null); |
1888 |
> |
r1.assertInvoked(); |
1889 |
> |
r2.assertInvoked(); |
1890 |
> |
r3.assertInvoked(); |
1891 |
|
checkCompletedNormally(f, v1); |
1892 |
|
checkCompletedNormally(g, v2); |
1893 |
|
}} |
1896 |
|
* runAfterBoth result completes exceptionally after exceptional |
1897 |
|
* completion of either source |
1898 |
|
*/ |
1899 |
< |
public void testRunAfterBoth_exceptionalCompletion() { |
1899 |
> |
public void testRunAfterBoth_exceptionalCompletion() throws Throwable { |
1900 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1885 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1901 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1902 |
+ |
for (boolean failFirst : new boolean[] { true, false }) |
1903 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1904 |
|
{ |
1905 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1906 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1907 |
|
final CFException ex = new CFException(); |
1908 |
< |
final Noop r = new Noop(m); |
1908 |
> |
final Noop r1 = new Noop(m); |
1909 |
> |
final Noop r2 = new Noop(m); |
1910 |
> |
final Noop r3 = new Noop(m); |
1911 |
> |
|
1912 |
> |
final CompletableFuture<Integer> fst = fFirst ? f : g; |
1913 |
> |
final CompletableFuture<Integer> snd = !fFirst ? f : g; |
1914 |
> |
final Callable<Boolean> complete1 = failFirst ? |
1915 |
> |
() -> fst.completeExceptionally(ex) : |
1916 |
> |
() -> fst.complete(v1); |
1917 |
> |
final Callable<Boolean> complete2 = failFirst ? |
1918 |
> |
() -> snd.complete(v1) : |
1919 |
> |
() -> snd.completeExceptionally(ex); |
1920 |
|
|
1921 |
< |
assertTrue((fFirst ? f : g).complete(v1)); |
1922 |
< |
if (!createIncomplete) |
1923 |
< |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1924 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1925 |
< |
if (createIncomplete) { |
1926 |
< |
checkIncomplete(h); |
1927 |
< |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1928 |
< |
} |
1929 |
< |
|
1930 |
< |
checkCompletedWithWrappedException(h, ex); |
1931 |
< |
r.assertNotInvoked(); |
1932 |
< |
checkCompletedNormally(fFirst ? f : g, v1); |
1933 |
< |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1921 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
1922 |
> |
assertTrue(complete1.call()); |
1923 |
> |
final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
1924 |
> |
checkIncomplete(h1); |
1925 |
> |
checkIncomplete(h2); |
1926 |
> |
assertTrue(complete2.call()); |
1927 |
> |
final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3); |
1928 |
> |
|
1929 |
> |
checkCompletedWithWrappedException(h1, ex); |
1930 |
> |
checkCompletedWithWrappedException(h2, ex); |
1931 |
> |
checkCompletedWithWrappedException(h3, ex); |
1932 |
> |
r1.assertNotInvoked(); |
1933 |
> |
r2.assertNotInvoked(); |
1934 |
> |
r3.assertNotInvoked(); |
1935 |
> |
checkCompletedNormally(failFirst ? snd : fst, v1); |
1936 |
> |
checkCompletedExceptionally(failFirst ? fst : snd, ex); |
1937 |
|
}} |
1938 |
|
|
1939 |
|
/** |
1940 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1941 |
|
*/ |
1942 |
< |
public void testRunAfterBoth_sourceCancelled() { |
1942 |
> |
public void testRunAfterBoth_sourceCancelled() throws Throwable { |
1943 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1944 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1915 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1945 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1946 |
+ |
for (boolean failFirst : new boolean[] { true, false }) |
1947 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1948 |
|
{ |
1949 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1950 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1951 |
< |
final Noop r = new Noop(m); |
1951 |
> |
final Noop r1 = new Noop(m); |
1952 |
> |
final Noop r2 = new Noop(m); |
1953 |
> |
final Noop r3 = new Noop(m); |
1954 |
> |
|
1955 |
> |
final CompletableFuture<Integer> fst = fFirst ? f : g; |
1956 |
> |
final CompletableFuture<Integer> snd = !fFirst ? f : g; |
1957 |
> |
final Callable<Boolean> complete1 = failFirst ? |
1958 |
> |
() -> fst.cancel(mayInterruptIfRunning) : |
1959 |
> |
() -> fst.complete(v1); |
1960 |
> |
final Callable<Boolean> complete2 = failFirst ? |
1961 |
> |
() -> snd.complete(v1) : |
1962 |
> |
() -> snd.cancel(mayInterruptIfRunning); |
1963 |
> |
|
1964 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
1965 |
> |
assertTrue(complete1.call()); |
1966 |
> |
final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
1967 |
> |
checkIncomplete(h1); |
1968 |
> |
checkIncomplete(h2); |
1969 |
> |
assertTrue(complete2.call()); |
1970 |
> |
final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3); |
1971 |
|
|
1972 |
< |
assertTrue((fFirst ? f : g).complete(v1)); |
1973 |
< |
if (!createIncomplete) |
1974 |
< |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1975 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1976 |
< |
if (createIncomplete) { |
1977 |
< |
checkIncomplete(h); |
1978 |
< |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1979 |
< |
} |
1931 |
< |
|
1932 |
< |
checkCompletedWithWrappedCancellationException(h); |
1933 |
< |
checkCancelled(!fFirst ? f : g); |
1934 |
< |
r.assertNotInvoked(); |
1935 |
< |
checkCompletedNormally(fFirst ? f : g, v1); |
1972 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1973 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1974 |
> |
checkCompletedWithWrappedCancellationException(h3); |
1975 |
> |
r1.assertNotInvoked(); |
1976 |
> |
r2.assertNotInvoked(); |
1977 |
> |
r3.assertNotInvoked(); |
1978 |
> |
checkCompletedNormally(failFirst ? snd : fst, v1); |
1979 |
> |
checkCancelled(failFirst ? fst : snd); |
1980 |
|
}} |
1981 |
|
|
1982 |
|
/** |
1992 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1993 |
|
final FailingRunnable r1 = new FailingRunnable(m); |
1994 |
|
final FailingRunnable r2 = new FailingRunnable(m); |
1995 |
+ |
final FailingRunnable r3 = new FailingRunnable(m); |
1996 |
|
|
1997 |
< |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
1998 |
< |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1999 |
< |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
2000 |
< |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
1997 |
> |
final CompletableFuture<Integer> fst = fFirst ? f : g; |
1998 |
> |
final CompletableFuture<Integer> snd = !fFirst ? f : g; |
1999 |
> |
final Integer w1 = fFirst ? v1 : v2; |
2000 |
> |
final Integer w2 = !fFirst ? v1 : v2; |
2001 |
> |
|
2002 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
2003 |
> |
assertTrue(fst.complete(w1)); |
2004 |
> |
final CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
2005 |
> |
assertTrue(snd.complete(w2)); |
2006 |
> |
final CompletableFuture<Void> h3 = m.runAfterBoth(f, g, r3); |
2007 |
|
|
2008 |
|
checkCompletedWithWrappedCFException(h1); |
2009 |
|
checkCompletedWithWrappedCFException(h2); |
2010 |
+ |
checkCompletedWithWrappedCFException(h3); |
2011 |
+ |
r1.assertInvoked(); |
2012 |
+ |
r2.assertInvoked(); |
2013 |
+ |
r3.assertInvoked(); |
2014 |
|
checkCompletedNormally(f, v1); |
2015 |
|
checkCompletedNormally(g, v2); |
2016 |
|
}} |