1171 |
|
|
1172 |
|
checkCompletedNormally(g, inc(v1)); |
1173 |
|
checkCompletedNormally(f, v1); |
1174 |
< |
r.assertInvoked(); |
1174 |
> |
r.assertValue(inc(v1)); |
1175 |
|
}} |
1176 |
|
|
1177 |
|
/** |
1356 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1357 |
|
checkCompletedNormally(f, v1); |
1358 |
|
checkCompletedNormally(g, v2); |
1359 |
< |
r.assertInvoked(); |
1359 |
> |
r.assertValue(subtract(v1, v2)); |
1360 |
|
}} |
1361 |
|
|
1362 |
|
/** |
1900 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1901 |
|
}} |
1902 |
|
|
1903 |
+ |
public void testApplyToEither_sourceCancelled2() { |
1904 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1905 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1906 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1907 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1908 |
+ |
{ |
1909 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1910 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1911 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1912 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1913 |
+ |
|
1914 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1915 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1916 |
+ |
if (fFirst) { |
1917 |
+ |
f.complete(v1); |
1918 |
+ |
g.cancel(mayInterruptIfRunning); |
1919 |
+ |
} else { |
1920 |
+ |
g.cancel(mayInterruptIfRunning); |
1921 |
+ |
f.complete(v1); |
1922 |
+ |
} |
1923 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1924 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1925 |
+ |
|
1926 |
+ |
// unspecified behavior - both source completions available |
1927 |
+ |
try { |
1928 |
+ |
assertEquals(inc(v1), h0.join()); |
1929 |
+ |
rs[0].assertValue(inc(v1)); |
1930 |
+ |
} catch (CompletionException ok) { |
1931 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
1932 |
+ |
rs[0].assertNotInvoked(); |
1933 |
+ |
} |
1934 |
+ |
try { |
1935 |
+ |
assertEquals(inc(v1), h1.join()); |
1936 |
+ |
rs[1].assertValue(inc(v1)); |
1937 |
+ |
} catch (CompletionException ok) { |
1938 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
1939 |
+ |
rs[1].assertNotInvoked(); |
1940 |
+ |
} |
1941 |
+ |
try { |
1942 |
+ |
assertEquals(inc(v1), h2.join()); |
1943 |
+ |
rs[2].assertValue(inc(v1)); |
1944 |
+ |
} catch (CompletionException ok) { |
1945 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
1946 |
+ |
rs[2].assertNotInvoked(); |
1947 |
+ |
} |
1948 |
+ |
try { |
1949 |
+ |
assertEquals(inc(v1), h3.join()); |
1950 |
+ |
rs[3].assertValue(inc(v1)); |
1951 |
+ |
} catch (CompletionException ok) { |
1952 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
1953 |
+ |
rs[3].assertNotInvoked(); |
1954 |
+ |
} |
1955 |
+ |
|
1956 |
+ |
checkCompletedNormally(f, v1); |
1957 |
+ |
checkCancelled(g); |
1958 |
+ |
}} |
1959 |
+ |
|
1960 |
|
/** |
1961 |
|
* applyToEither result completes exceptionally if action does |
1962 |
|
*/ |
2108 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2109 |
|
}} |
2110 |
|
|
2111 |
+ |
public void testAcceptEither_exceptionalCompletion2() { |
2112 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2113 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2114 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2115 |
+ |
{ |
2116 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2117 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2118 |
+ |
final CFException ex = new CFException(); |
2119 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2120 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2121 |
+ |
|
2122 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2123 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2124 |
+ |
if (fFirst) { |
2125 |
+ |
f.complete(v1); |
2126 |
+ |
g.completeExceptionally(ex); |
2127 |
+ |
} else { |
2128 |
+ |
g.completeExceptionally(ex); |
2129 |
+ |
f.complete(v1); |
2130 |
+ |
} |
2131 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2132 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2133 |
+ |
|
2134 |
+ |
// unspecified behavior - both source completions available |
2135 |
+ |
try { |
2136 |
+ |
assertEquals(null, h0.join()); |
2137 |
+ |
rs[0].assertValue(v1); |
2138 |
+ |
} catch (CompletionException ok) { |
2139 |
+ |
checkCompletedWithWrappedCFException(h0, ex); |
2140 |
+ |
rs[0].assertNotInvoked(); |
2141 |
+ |
} |
2142 |
+ |
try { |
2143 |
+ |
assertEquals(null, h1.join()); |
2144 |
+ |
rs[1].assertValue(v1); |
2145 |
+ |
} catch (CompletionException ok) { |
2146 |
+ |
checkCompletedWithWrappedCFException(h1, ex); |
2147 |
+ |
rs[1].assertNotInvoked(); |
2148 |
+ |
} |
2149 |
+ |
try { |
2150 |
+ |
assertEquals(null, h2.join()); |
2151 |
+ |
rs[2].assertValue(v1); |
2152 |
+ |
} catch (CompletionException ok) { |
2153 |
+ |
checkCompletedWithWrappedCFException(h2, ex); |
2154 |
+ |
rs[2].assertNotInvoked(); |
2155 |
+ |
} |
2156 |
+ |
try { |
2157 |
+ |
assertEquals(null, h3.join()); |
2158 |
+ |
rs[3].assertValue(v1); |
2159 |
+ |
} catch (CompletionException ok) { |
2160 |
+ |
checkCompletedWithWrappedCFException(h3, ex); |
2161 |
+ |
rs[3].assertNotInvoked(); |
2162 |
+ |
} |
2163 |
+ |
|
2164 |
+ |
checkCompletedNormally(f, v1); |
2165 |
+ |
checkCompletedWithWrappedCFException(g, ex); |
2166 |
+ |
}} |
2167 |
+ |
|
2168 |
|
/** |
2169 |
|
* acceptEither result completes exceptionally if either source cancelled |
2170 |
|
*/ |
2368 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2369 |
|
}} |
2370 |
|
|
2371 |
+ |
public void testRunAfterEither_exceptionalCompletion2() { |
2372 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2373 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2374 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2375 |
+ |
{ |
2376 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2377 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2378 |
+ |
final CFException ex = new CFException(); |
2379 |
+ |
final Noop[] rs = new Noop[6]; |
2380 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2381 |
+ |
|
2382 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2383 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2384 |
+ |
if (fFirst) { |
2385 |
+ |
f.complete(v1); |
2386 |
+ |
g.completeExceptionally(ex); |
2387 |
+ |
} else { |
2388 |
+ |
g.completeExceptionally(ex); |
2389 |
+ |
f.complete(v1); |
2390 |
+ |
} |
2391 |
+ |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2392 |
+ |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2393 |
+ |
|
2394 |
+ |
// unspecified behavior - both source completions available |
2395 |
+ |
try { |
2396 |
+ |
assertEquals(null, h0.join()); |
2397 |
+ |
rs[0].assertInvoked(); |
2398 |
+ |
} catch (CompletionException ok) { |
2399 |
+ |
checkCompletedWithWrappedCFException(h0, ex); |
2400 |
+ |
rs[0].assertNotInvoked(); |
2401 |
+ |
} |
2402 |
+ |
try { |
2403 |
+ |
assertEquals(null, h1.join()); |
2404 |
+ |
rs[1].assertInvoked(); |
2405 |
+ |
} catch (CompletionException ok) { |
2406 |
+ |
checkCompletedWithWrappedCFException(h1, ex); |
2407 |
+ |
rs[1].assertNotInvoked(); |
2408 |
+ |
} |
2409 |
+ |
try { |
2410 |
+ |
assertEquals(null, h2.join()); |
2411 |
+ |
rs[2].assertInvoked(); |
2412 |
+ |
} catch (CompletionException ok) { |
2413 |
+ |
checkCompletedWithWrappedCFException(h2, ex); |
2414 |
+ |
rs[2].assertNotInvoked(); |
2415 |
+ |
} |
2416 |
+ |
try { |
2417 |
+ |
assertEquals(null, h3.join()); |
2418 |
+ |
rs[3].assertInvoked(); |
2419 |
+ |
} catch (CompletionException ok) { |
2420 |
+ |
checkCompletedWithWrappedCFException(h3, ex); |
2421 |
+ |
rs[3].assertNotInvoked(); |
2422 |
+ |
} |
2423 |
+ |
|
2424 |
+ |
checkCompletedNormally(f, v1); |
2425 |
+ |
checkCompletedWithWrappedCFException(g, ex); |
2426 |
+ |
}} |
2427 |
+ |
|
2428 |
|
/** |
2429 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2430 |
|
*/ |
2531 |
|
|
2532 |
|
checkCompletedNormally(g, inc(v1)); |
2533 |
|
checkCompletedNormally(f, v1); |
2534 |
< |
r.assertInvoked(); |
2534 |
> |
r.assertValue(v1); |
2535 |
|
}} |
2536 |
|
|
2537 |
|
/** |