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(); |
2152 |
|
* runAfterEither result completes normally after normal completion |
2153 |
|
* of either source |
2154 |
|
*/ |
2155 |
< |
public void testRunAfterEither_normalCompletion1() { |
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); |
2163 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
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(h, null); |
2173 |
< |
r.assertInvoked(); |
2174 |
< |
g.complete(v2); |
2175 |
< |
|
2176 |
< |
checkCompletedNormally(f, v1); |
2177 |
< |
checkCompletedNormally(g, v2); |
2178 |
< |
checkCompletedNormally(h, null); |
2179 |
< |
r.assertInvoked(); |
2180 |
< |
}} |
2181 |
< |
|
2119 |
< |
public void testRunAfterEither_normalCompletion2() { |
2120 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2121 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2122 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2123 |
< |
{ |
2124 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2125 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2126 |
< |
final Noop r = new Noop(m); |
2127 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
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); |
2130 |
– |
checkCompletedNormally(h, null); |
2131 |
– |
r.assertInvoked(); |
2132 |
– |
f.complete(v1); |
2133 |
– |
|
2134 |
– |
checkCompletedNormally(f, v1); |
2135 |
– |
checkCompletedNormally(g, v2); |
2136 |
– |
checkCompletedNormally(h, null); |
2137 |
– |
r.assertInvoked(); |
2138 |
– |
}} |
2139 |
– |
|
2140 |
– |
public void testRunAfterEither_normalCompletion3() { |
2141 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2142 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2143 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
2144 |
– |
{ |
2145 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2146 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2147 |
– |
final Noop r = new Noop(m); |
2184 |
|
|
2185 |
< |
f.complete(v1); |
2186 |
< |
g.complete(v2); |
2151 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2185 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2186 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2187 |
|
|
2153 |
– |
checkCompletedNormally(h, null); |
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<>(); |
2169 |
– |
final Noop r = new Noop(m); |
2170 |
– |
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); |
2180 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2181 |
< |
}} |
2182 |
< |
|
2183 |
< |
public void testRunAfterEither_exceptionalCompletion2() { |
2184 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2185 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2186 |
< |
{ |
2187 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2188 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2189 |
< |
final Noop r = new Noop(m); |
2190 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2191 |
< |
final CFException ex = new CFException(); |
2192 |
< |
|
2193 |
< |
g.completeExceptionally(ex); |
2194 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2195 |
< |
f.complete(v1); |
2196 |
< |
|
2197 |
< |
r.assertNotInvoked(); |
2198 |
< |
checkCompletedNormally(f, v1); |
2199 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2200 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2201 |
< |
}} |
2202 |
< |
|
2203 |
< |
public void testRunAfterEither_exceptionalCompletion3() { |
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<>(); |
2209 |
< |
final Noop r = new Noop(m); |
2210 |
< |
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); |
2213 |
< |
f.complete(v1); |
2214 |
< |
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 |
|
} |
2225 |
– |
|
2226 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2227 |
– |
checkCompletedNormally(f, v1); |
2228 |
– |
}} |
2229 |
– |
|
2230 |
– |
public void testRunAfterEither_exceptionalCompletion4() { |
2231 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2232 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2233 |
– |
{ |
2234 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2235 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2236 |
– |
final Noop r = new Noop(m); |
2237 |
– |
final CFException ex = new CFException(); |
2238 |
– |
|
2239 |
– |
f.completeExceptionally(ex); |
2240 |
– |
g.complete(v1); |
2241 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2242 |
– |
|
2243 |
– |
// unspecified behavior |
2244 |
– |
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() { |
2261 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2262 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2263 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2264 |
< |
{ |
2265 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2266 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2267 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2268 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2269 |
< |
|
2270 |
< |
f.complete(v1); |
2271 |
< |
checkCompletedWithWrappedCFException(h); |
2272 |
< |
g.complete(v2); |
2273 |
< |
checkCompletedNormally(f, v1); |
2274 |
< |
checkCompletedNormally(g, v2); |
2275 |
< |
}} |
2276 |
< |
|
2277 |
< |
public void testRunAfterEither_actionFailed2() { |
2278 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2279 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2280 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2281 |
< |
{ |
2282 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2283 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2284 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2285 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2286 |
< |
|
2287 |
< |
g.complete(v2); |
2288 |
< |
checkCompletedWithWrappedCFException(h); |
2289 |
< |
f.complete(v1); |
2290 |
< |
checkCompletedNormally(f, v1); |
2291 |
< |
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() { |
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); |
2267 |
> |
final Noop[] rs = new Noop[6]; |
2268 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2269 |
|
|
2270 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2271 |
< |
checkCompletedWithWrappedCancellationException(h); |
2272 |
< |
g.complete(v1); |
2273 |
< |
|
2274 |
< |
checkCancelled(f); |
2275 |
< |
r.assertNotInvoked(); |
2276 |
< |
checkCompletedNormally(g, v1); |
2277 |
< |
checkCompletedWithWrappedCancellationException(h); |
2278 |
< |
}} |
2279 |
< |
|
2280 |
< |
public void testRunAfterEither_sourceCancelled2() { |
2281 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2282 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2320 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2321 |
< |
{ |
2322 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2323 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2324 |
< |
final Noop r = new Noop(m); |
2325 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2326 |
< |
|
2327 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2328 |
< |
checkCompletedWithWrappedCancellationException(h); |
2329 |
< |
f.complete(v1); |
2330 |
< |
|
2331 |
< |
checkCancelled(g); |
2332 |
< |
r.assertNotInvoked(); |
2333 |
< |
checkCompletedNormally(f, v1); |
2334 |
< |
checkCompletedWithWrappedCancellationException(h); |
2335 |
< |
}} |
2336 |
< |
|
2337 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2338 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2339 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2340 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2341 |
< |
{ |
2342 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2343 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2344 |
< |
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)); |
2347 |
< |
f.complete(v1); |
2348 |
< |
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()) |
2366 |
– |
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 |
< |
|
2373 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2374 |
< |
g.complete(v1); |
2375 |
< |
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 |
|
/** |