105 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
106 |
|
} |
107 |
|
|
108 |
< |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
109 |
< |
CFException ex) { |
108 |
> |
<U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f, |
109 |
> |
Throwable ex) { |
110 |
|
try { |
111 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
112 |
|
shouldThrow(); |
131 |
|
} catch (ExecutionException success) { |
132 |
|
assertSame(ex, success.getCause()); |
133 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
134 |
+ |
|
135 |
|
assertTrue(f.isDone()); |
136 |
|
assertFalse(f.isCancelled()); |
137 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
138 |
|
} |
139 |
|
|
140 |
+ |
<U> void checkCompletedWithWrappedException(CompletableFuture<U> f, |
141 |
+ |
Throwable ex) { |
142 |
+ |
checkCompletedExceptionallyWithRootCause(f, ex); |
143 |
+ |
try { |
144 |
+ |
CompletableFuture<Throwable> spy = f.handle |
145 |
+ |
((U u, Throwable t) -> t); |
146 |
+ |
assertTrue(spy.join() instanceof CompletionException); |
147 |
+ |
assertSame(ex, spy.join().getCause()); |
148 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
<U> void checkCompletedExceptionally(CompletableFuture<U> f, Throwable ex) { |
152 |
+ |
checkCompletedExceptionallyWithRootCause(f, ex); |
153 |
+ |
try { |
154 |
+ |
CompletableFuture<Throwable> spy = f.handle |
155 |
+ |
((U u, Throwable t) -> t); |
156 |
+ |
assertSame(ex, spy.join()); |
157 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
158 |
+ |
} |
159 |
+ |
|
160 |
|
void checkCancelled(CompletableFuture<?> f) { |
161 |
|
try { |
162 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
239 |
|
*/ |
240 |
|
public void testCompleteExceptionally() { |
241 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
242 |
+ |
CFException ex = new CFException(); |
243 |
|
checkIncomplete(f); |
244 |
< |
f.completeExceptionally(new CFException()); |
245 |
< |
checkCompletedWithWrappedCFException(f); |
244 |
> |
f.completeExceptionally(ex); |
245 |
> |
checkCompletedExceptionally(f, ex); |
246 |
|
} |
247 |
|
|
248 |
|
/** |
283 |
|
* obtrudeException forces completion with given exception |
284 |
|
*/ |
285 |
|
public void testObtrudeException() { |
286 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
287 |
< |
checkIncomplete(f); |
288 |
< |
f.complete(one); |
289 |
< |
checkCompletedNormally(f, one); |
290 |
< |
f.obtrudeException(new CFException()); |
269 |
< |
checkCompletedWithWrappedCFException(f); |
286 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
287 |
> |
{ |
288 |
> |
CFException ex; |
289 |
> |
CompletableFuture<Integer> f; |
290 |
> |
|
291 |
|
f = new CompletableFuture<>(); |
292 |
< |
f.obtrudeException(new CFException()); |
293 |
< |
checkCompletedWithWrappedCFException(f); |
292 |
> |
f.complete(v1); |
293 |
> |
for (int i = 0; i < 2; i++) { |
294 |
> |
f.obtrudeException(ex = new CFException()); |
295 |
> |
checkCompletedExceptionally(f, ex); |
296 |
> |
} |
297 |
> |
|
298 |
> |
f = new CompletableFuture<>(); |
299 |
> |
for (int i = 0; i < 2; i++) { |
300 |
> |
f.obtrudeException(ex = new CFException()); |
301 |
> |
checkCompletedExceptionally(f, ex); |
302 |
> |
} |
303 |
> |
|
304 |
|
f = new CompletableFuture<>(); |
305 |
+ |
f.completeExceptionally(ex = new CFException()); |
306 |
+ |
f.obtrudeValue(v1); |
307 |
+ |
checkCompletedNormally(f, v1); |
308 |
+ |
f.obtrudeException(ex = new CFException()); |
309 |
+ |
checkCompletedExceptionally(f, ex); |
310 |
|
f.completeExceptionally(new CFException()); |
311 |
< |
f.obtrudeValue(four); |
312 |
< |
checkCompletedNormally(f, four); |
313 |
< |
f.obtrudeException(new CFException()); |
314 |
< |
checkCompletedWithWrappedCFException(f); |
279 |
< |
} |
311 |
> |
checkCompletedExceptionally(f, ex); |
312 |
> |
f.complete(v1); |
313 |
> |
checkCompletedExceptionally(f, ex); |
314 |
> |
}} |
315 |
|
|
316 |
|
/** |
317 |
|
* getNumberOfDependents returns number of dependent tasks |
345 |
|
f = new CompletableFuture<String>(); |
346 |
|
f.completeExceptionally(new IndexOutOfBoundsException()); |
347 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
348 |
+ |
|
349 |
+ |
f = new CompletableFuture<String>(); |
350 |
+ |
f.cancel(true); |
351 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
352 |
+ |
|
353 |
+ |
f = new CompletableFuture<String>(); |
354 |
+ |
f.cancel(false); |
355 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
356 |
|
} |
357 |
|
|
358 |
|
/** |
403 |
|
return (x == null) ? null : x + 1; |
404 |
|
} |
405 |
|
|
406 |
< |
class IncAction extends CheckedIntegerAction |
406 |
> |
class NoopConsumer extends CheckedIntegerAction |
407 |
|
implements Consumer<Integer> |
408 |
|
{ |
409 |
< |
IncAction(ExecutionMode m) { super(m); } |
409 |
> |
NoopConsumer(ExecutionMode m) { super(m); } |
410 |
|
public void accept(Integer x) { |
411 |
|
invoked(); |
412 |
< |
value = inc(x); |
412 |
> |
value = x; |
413 |
|
} |
414 |
|
} |
415 |
|
|
895 |
|
}); |
896 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
897 |
|
|
898 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
898 |
> |
checkCompletedWithWrappedException(g, ex2); |
899 |
|
assertEquals(1, a.get()); |
900 |
|
}} |
901 |
|
|
952 |
|
if (createIncomplete) f.completeExceptionally(ex); |
953 |
|
|
954 |
|
checkCompletedNormally(g, v1); |
955 |
< |
checkCompletedWithWrappedCFException(f, ex); |
955 |
> |
checkCompletedExceptionally(f, ex); |
956 |
|
assertEquals(1, a.get()); |
957 |
|
}} |
958 |
|
|
1008 |
|
}); |
1009 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
1010 |
|
|
1011 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
1012 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
1011 |
> |
checkCompletedWithWrappedException(g, ex2); |
1012 |
> |
checkCompletedExceptionally(f, ex1); |
1013 |
|
assertEquals(1, a.get()); |
1014 |
|
}} |
1015 |
|
|
1033 |
|
}); |
1034 |
|
if (createIncomplete) f.complete(v1); |
1035 |
|
|
1036 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1036 |
> |
checkCompletedWithWrappedException(g, ex); |
1037 |
|
checkCompletedNormally(f, v1); |
1038 |
|
assertEquals(1, a.get()); |
1039 |
|
}} |
1147 |
|
f.completeExceptionally(ex); |
1148 |
|
} |
1149 |
|
|
1150 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1151 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1150 |
> |
checkCompletedWithWrappedException(g, ex); |
1151 |
> |
checkCompletedExceptionally(f, ex); |
1152 |
|
r.assertNotInvoked(); |
1153 |
|
}} |
1154 |
|
|
1214 |
|
|
1215 |
|
checkCompletedNormally(g, inc(v1)); |
1216 |
|
checkCompletedNormally(f, v1); |
1217 |
< |
r.assertInvoked(); |
1217 |
> |
r.assertValue(inc(v1)); |
1218 |
|
}} |
1219 |
|
|
1220 |
|
/** |
1235 |
|
f.completeExceptionally(ex); |
1236 |
|
} |
1237 |
|
|
1238 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1239 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1238 |
> |
checkCompletedWithWrappedException(g, ex); |
1239 |
> |
checkCompletedExceptionally(f, ex); |
1240 |
|
r.assertNotInvoked(); |
1241 |
|
}} |
1242 |
|
|
1292 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1293 |
|
{ |
1294 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1295 |
< |
final IncAction r = new IncAction(m); |
1295 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1296 |
|
if (!createIncomplete) f.complete(v1); |
1297 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1298 |
|
if (createIncomplete) { |
1301 |
|
} |
1302 |
|
|
1303 |
|
checkCompletedNormally(g, null); |
1304 |
+ |
r.assertValue(v1); |
1305 |
|
checkCompletedNormally(f, v1); |
1262 |
– |
r.assertInvoked(); |
1263 |
– |
r.assertValue(inc(v1)); |
1306 |
|
}} |
1307 |
|
|
1308 |
|
/** |
1315 |
|
{ |
1316 |
|
final CFException ex = new CFException(); |
1317 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1318 |
< |
final IncAction r = new IncAction(m); |
1318 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1319 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1320 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1321 |
|
if (createIncomplete) { |
1323 |
|
f.completeExceptionally(ex); |
1324 |
|
} |
1325 |
|
|
1326 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1327 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1326 |
> |
checkCompletedWithWrappedException(g, ex); |
1327 |
> |
checkCompletedExceptionally(f, ex); |
1328 |
|
r.assertNotInvoked(); |
1329 |
|
}} |
1330 |
|
|
1337 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1338 |
|
{ |
1339 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1340 |
< |
final IncAction r = new IncAction(m); |
1340 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1341 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1342 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1343 |
|
if (createIncomplete) { |
1399 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1400 |
|
checkCompletedNormally(f, v1); |
1401 |
|
checkCompletedNormally(g, v2); |
1402 |
< |
r.assertInvoked(); |
1402 |
> |
r.assertValue(subtract(v1, v2)); |
1403 |
|
}} |
1404 |
|
|
1405 |
|
/** |
1426 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1427 |
|
} |
1428 |
|
|
1429 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1429 |
> |
checkCompletedWithWrappedException(h, ex); |
1430 |
|
r.assertNotInvoked(); |
1431 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1432 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1432 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1433 |
|
}} |
1434 |
|
|
1435 |
|
/** |
1543 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1544 |
|
} |
1545 |
|
|
1546 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1546 |
> |
checkCompletedWithWrappedException(h, ex); |
1547 |
|
r.assertNotInvoked(); |
1548 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1549 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1549 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1550 |
|
}} |
1551 |
|
|
1552 |
|
/** |
1660 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1661 |
|
} |
1662 |
|
|
1663 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1663 |
> |
checkCompletedWithWrappedException(h, ex); |
1664 |
|
r.assertNotInvoked(); |
1665 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1666 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1666 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1667 |
|
}} |
1668 |
|
|
1669 |
|
/** |
1795 |
|
rs[0].assertNotInvoked(); |
1796 |
|
rs[1].assertNotInvoked(); |
1797 |
|
f.completeExceptionally(ex); |
1798 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1799 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1798 |
> |
checkCompletedWithWrappedException(h0, ex); |
1799 |
> |
checkCompletedWithWrappedException(h1, ex); |
1800 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1801 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1802 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1803 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1802 |
> |
checkCompletedWithWrappedException(h2, ex); |
1803 |
> |
checkCompletedWithWrappedException(h3, ex); |
1804 |
|
g.complete(v1); |
1805 |
|
|
1806 |
|
// unspecified behavior - both source completions available |
1808 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1809 |
|
try { |
1810 |
|
assertEquals(inc(v1), h4.join()); |
1811 |
< |
rs[4].assertInvoked(); |
1811 |
> |
rs[4].assertValue(inc(v1)); |
1812 |
|
} catch (CompletionException ok) { |
1813 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1813 |
> |
checkCompletedWithWrappedException(h4, ex); |
1814 |
|
rs[4].assertNotInvoked(); |
1815 |
|
} |
1816 |
|
try { |
1817 |
|
assertEquals(inc(v1), h5.join()); |
1818 |
< |
rs[5].assertInvoked(); |
1818 |
> |
rs[5].assertValue(inc(v1)); |
1819 |
|
} catch (CompletionException ok) { |
1820 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
1820 |
> |
checkCompletedWithWrappedException(h5, ex); |
1821 |
|
rs[5].assertNotInvoked(); |
1822 |
|
} |
1823 |
|
|
1824 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1824 |
> |
checkCompletedExceptionally(f, ex); |
1825 |
|
checkCompletedNormally(g, v1); |
1826 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1827 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1828 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1829 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1830 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1826 |
> |
checkCompletedWithWrappedException(h0, ex); |
1827 |
> |
checkCompletedWithWrappedException(h1, ex); |
1828 |
> |
checkCompletedWithWrappedException(h2, ex); |
1829 |
> |
checkCompletedWithWrappedException(h3, ex); |
1830 |
> |
checkCompletedWithWrappedException(h4, ex); |
1831 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1832 |
|
}} |
1833 |
|
|
1834 |
+ |
public void testApplyToEither_exceptionalCompletion2() { |
1835 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1836 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1837 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1838 |
+ |
{ |
1839 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1840 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1841 |
+ |
final CFException ex = new CFException(); |
1842 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1843 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1844 |
+ |
|
1845 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1846 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1847 |
+ |
if (fFirst) { |
1848 |
+ |
f.complete(v1); |
1849 |
+ |
g.completeExceptionally(ex); |
1850 |
+ |
} else { |
1851 |
+ |
g.completeExceptionally(ex); |
1852 |
+ |
f.complete(v1); |
1853 |
+ |
} |
1854 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1855 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1856 |
+ |
|
1857 |
+ |
// unspecified behavior - both source completions available |
1858 |
+ |
try { |
1859 |
+ |
assertEquals(inc(v1), h0.join()); |
1860 |
+ |
rs[0].assertValue(inc(v1)); |
1861 |
+ |
} catch (CompletionException ok) { |
1862 |
+ |
checkCompletedWithWrappedException(h0, ex); |
1863 |
+ |
rs[0].assertNotInvoked(); |
1864 |
+ |
} |
1865 |
+ |
try { |
1866 |
+ |
assertEquals(inc(v1), h1.join()); |
1867 |
+ |
rs[1].assertValue(inc(v1)); |
1868 |
+ |
} catch (CompletionException ok) { |
1869 |
+ |
checkCompletedWithWrappedException(h1, ex); |
1870 |
+ |
rs[1].assertNotInvoked(); |
1871 |
+ |
} |
1872 |
+ |
try { |
1873 |
+ |
assertEquals(inc(v1), h2.join()); |
1874 |
+ |
rs[2].assertValue(inc(v1)); |
1875 |
+ |
} catch (CompletionException ok) { |
1876 |
+ |
checkCompletedWithWrappedException(h2, ex); |
1877 |
+ |
rs[2].assertNotInvoked(); |
1878 |
+ |
} |
1879 |
+ |
try { |
1880 |
+ |
assertEquals(inc(v1), h3.join()); |
1881 |
+ |
rs[3].assertValue(inc(v1)); |
1882 |
+ |
} catch (CompletionException ok) { |
1883 |
+ |
checkCompletedWithWrappedException(h3, ex); |
1884 |
+ |
rs[3].assertNotInvoked(); |
1885 |
+ |
} |
1886 |
+ |
|
1887 |
+ |
checkCompletedNormally(f, v1); |
1888 |
+ |
checkCompletedExceptionally(g, ex); |
1889 |
+ |
}} |
1890 |
+ |
|
1891 |
|
/** |
1892 |
|
* applyToEither result completes exceptionally if either source cancelled |
1893 |
|
*/ |
1921 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1922 |
|
try { |
1923 |
|
assertEquals(inc(v1), h4.join()); |
1924 |
< |
rs[4].assertInvoked(); |
1924 |
> |
rs[4].assertValue(inc(v1)); |
1925 |
|
} catch (CompletionException ok) { |
1926 |
|
checkCompletedWithWrappedCancellationException(h4); |
1927 |
|
rs[4].assertNotInvoked(); |
1928 |
|
} |
1929 |
|
try { |
1930 |
|
assertEquals(inc(v1), h5.join()); |
1931 |
< |
rs[5].assertInvoked(); |
1931 |
> |
rs[5].assertValue(inc(v1)); |
1932 |
|
} catch (CompletionException ok) { |
1933 |
|
checkCompletedWithWrappedCancellationException(h5); |
1934 |
|
rs[5].assertNotInvoked(); |
1943 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1944 |
|
}} |
1945 |
|
|
1946 |
+ |
public void testApplyToEither_sourceCancelled2() { |
1947 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1948 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1949 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1950 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1951 |
+ |
{ |
1952 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1953 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1954 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1955 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1956 |
+ |
|
1957 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1958 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1959 |
+ |
if (fFirst) { |
1960 |
+ |
f.complete(v1); |
1961 |
+ |
g.cancel(mayInterruptIfRunning); |
1962 |
+ |
} else { |
1963 |
+ |
g.cancel(mayInterruptIfRunning); |
1964 |
+ |
f.complete(v1); |
1965 |
+ |
} |
1966 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1967 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1968 |
+ |
|
1969 |
+ |
// unspecified behavior - both source completions available |
1970 |
+ |
try { |
1971 |
+ |
assertEquals(inc(v1), h0.join()); |
1972 |
+ |
rs[0].assertValue(inc(v1)); |
1973 |
+ |
} catch (CompletionException ok) { |
1974 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
1975 |
+ |
rs[0].assertNotInvoked(); |
1976 |
+ |
} |
1977 |
+ |
try { |
1978 |
+ |
assertEquals(inc(v1), h1.join()); |
1979 |
+ |
rs[1].assertValue(inc(v1)); |
1980 |
+ |
} catch (CompletionException ok) { |
1981 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
1982 |
+ |
rs[1].assertNotInvoked(); |
1983 |
+ |
} |
1984 |
+ |
try { |
1985 |
+ |
assertEquals(inc(v1), h2.join()); |
1986 |
+ |
rs[2].assertValue(inc(v1)); |
1987 |
+ |
} catch (CompletionException ok) { |
1988 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
1989 |
+ |
rs[2].assertNotInvoked(); |
1990 |
+ |
} |
1991 |
+ |
try { |
1992 |
+ |
assertEquals(inc(v1), h3.join()); |
1993 |
+ |
rs[3].assertValue(inc(v1)); |
1994 |
+ |
} catch (CompletionException ok) { |
1995 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
1996 |
+ |
rs[3].assertNotInvoked(); |
1997 |
+ |
} |
1998 |
+ |
|
1999 |
+ |
checkCompletedNormally(f, v1); |
2000 |
+ |
checkCancelled(g); |
2001 |
+ |
}} |
2002 |
+ |
|
2003 |
|
/** |
2004 |
|
* applyToEither result completes exceptionally if action does |
2005 |
|
*/ |
2052 |
|
{ |
2053 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2054 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2055 |
< |
final IncAction[] rs = new IncAction[6]; |
2056 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2055 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2056 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2057 |
|
|
2058 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2059 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2064 |
|
f.complete(v1); |
2065 |
|
checkCompletedNormally(h0, null); |
2066 |
|
checkCompletedNormally(h1, null); |
2067 |
< |
rs[0].assertValue(inc(v1)); |
2068 |
< |
rs[1].assertValue(inc(v1)); |
2067 |
> |
rs[0].assertValue(v1); |
2068 |
> |
rs[1].assertValue(v1); |
2069 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2070 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2071 |
|
checkCompletedNormally(h2, null); |
2072 |
|
checkCompletedNormally(h3, null); |
2073 |
< |
rs[2].assertValue(inc(v1)); |
2074 |
< |
rs[3].assertValue(inc(v1)); |
2073 |
> |
rs[2].assertValue(v1); |
2074 |
> |
rs[3].assertValue(v1); |
2075 |
|
g.complete(v2); |
2076 |
|
|
2077 |
|
// unspecified behavior - both source completions available |
2079 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2080 |
|
checkCompletedNormally(h4, null); |
2081 |
|
checkCompletedNormally(h5, null); |
2082 |
< |
assertTrue(Objects.equals(inc(v1), rs[4].value) || |
2083 |
< |
Objects.equals(inc(v2), rs[4].value)); |
2084 |
< |
assertTrue(Objects.equals(inc(v1), rs[5].value) || |
2085 |
< |
Objects.equals(inc(v2), rs[5].value)); |
2082 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2083 |
> |
Objects.equals(v2, rs[4].value)); |
2084 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2085 |
> |
Objects.equals(v2, rs[5].value)); |
2086 |
|
|
2087 |
|
checkCompletedNormally(f, v1); |
2088 |
|
checkCompletedNormally(g, v2); |
2090 |
|
checkCompletedNormally(h1, null); |
2091 |
|
checkCompletedNormally(h2, null); |
2092 |
|
checkCompletedNormally(h3, null); |
2093 |
< |
for (int i = 0; i < 4; i++) rs[i].assertValue(inc(v1)); |
2093 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2094 |
|
}} |
2095 |
|
|
2096 |
|
/** |
2104 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2105 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2106 |
|
final CFException ex = new CFException(); |
2107 |
< |
final IncAction[] rs = new IncAction[6]; |
2108 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2107 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2108 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2109 |
|
|
2110 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2111 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2114 |
|
rs[0].assertNotInvoked(); |
2115 |
|
rs[1].assertNotInvoked(); |
2116 |
|
f.completeExceptionally(ex); |
2117 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2118 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2117 |
> |
checkCompletedWithWrappedException(h0, ex); |
2118 |
> |
checkCompletedWithWrappedException(h1, ex); |
2119 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2120 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2121 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2122 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2121 |
> |
checkCompletedWithWrappedException(h2, ex); |
2122 |
> |
checkCompletedWithWrappedException(h3, ex); |
2123 |
|
|
2124 |
|
g.complete(v1); |
2125 |
|
|
2128 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2129 |
|
try { |
2130 |
|
assertNull(h4.join()); |
2131 |
< |
rs[4].assertValue(inc(v1)); |
2131 |
> |
rs[4].assertValue(v1); |
2132 |
|
} catch (CompletionException ok) { |
2133 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2133 |
> |
checkCompletedWithWrappedException(h4, ex); |
2134 |
|
rs[4].assertNotInvoked(); |
2135 |
|
} |
2136 |
|
try { |
2137 |
|
assertNull(h5.join()); |
2138 |
< |
rs[5].assertValue(inc(v1)); |
2138 |
> |
rs[5].assertValue(v1); |
2139 |
|
} catch (CompletionException ok) { |
2140 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
2140 |
> |
checkCompletedWithWrappedException(h5, ex); |
2141 |
|
rs[5].assertNotInvoked(); |
2142 |
|
} |
2143 |
|
|
2144 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2144 |
> |
checkCompletedExceptionally(f, ex); |
2145 |
|
checkCompletedNormally(g, v1); |
2146 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2147 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2148 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2149 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2150 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2146 |
> |
checkCompletedWithWrappedException(h0, ex); |
2147 |
> |
checkCompletedWithWrappedException(h1, ex); |
2148 |
> |
checkCompletedWithWrappedException(h2, ex); |
2149 |
> |
checkCompletedWithWrappedException(h3, ex); |
2150 |
> |
checkCompletedWithWrappedException(h4, ex); |
2151 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2152 |
|
}} |
2153 |
|
|
2154 |
+ |
public void testAcceptEither_exceptionalCompletion2() { |
2155 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2156 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2157 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2158 |
+ |
{ |
2159 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2160 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2161 |
+ |
final CFException ex = new CFException(); |
2162 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2163 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2164 |
+ |
|
2165 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2166 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2167 |
+ |
if (fFirst) { |
2168 |
+ |
f.complete(v1); |
2169 |
+ |
g.completeExceptionally(ex); |
2170 |
+ |
} else { |
2171 |
+ |
g.completeExceptionally(ex); |
2172 |
+ |
f.complete(v1); |
2173 |
+ |
} |
2174 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2175 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2176 |
+ |
|
2177 |
+ |
// unspecified behavior - both source completions available |
2178 |
+ |
try { |
2179 |
+ |
assertEquals(null, h0.join()); |
2180 |
+ |
rs[0].assertValue(v1); |
2181 |
+ |
} catch (CompletionException ok) { |
2182 |
+ |
checkCompletedWithWrappedException(h0, ex); |
2183 |
+ |
rs[0].assertNotInvoked(); |
2184 |
+ |
} |
2185 |
+ |
try { |
2186 |
+ |
assertEquals(null, h1.join()); |
2187 |
+ |
rs[1].assertValue(v1); |
2188 |
+ |
} catch (CompletionException ok) { |
2189 |
+ |
checkCompletedWithWrappedException(h1, ex); |
2190 |
+ |
rs[1].assertNotInvoked(); |
2191 |
+ |
} |
2192 |
+ |
try { |
2193 |
+ |
assertEquals(null, h2.join()); |
2194 |
+ |
rs[2].assertValue(v1); |
2195 |
+ |
} catch (CompletionException ok) { |
2196 |
+ |
checkCompletedWithWrappedException(h2, ex); |
2197 |
+ |
rs[2].assertNotInvoked(); |
2198 |
+ |
} |
2199 |
+ |
try { |
2200 |
+ |
assertEquals(null, h3.join()); |
2201 |
+ |
rs[3].assertValue(v1); |
2202 |
+ |
} catch (CompletionException ok) { |
2203 |
+ |
checkCompletedWithWrappedException(h3, ex); |
2204 |
+ |
rs[3].assertNotInvoked(); |
2205 |
+ |
} |
2206 |
+ |
|
2207 |
+ |
checkCompletedNormally(f, v1); |
2208 |
+ |
checkCompletedExceptionally(g, ex); |
2209 |
+ |
}} |
2210 |
+ |
|
2211 |
|
/** |
2212 |
|
* acceptEither result completes exceptionally if either source cancelled |
2213 |
|
*/ |
2218 |
|
{ |
2219 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2220 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2221 |
< |
final IncAction[] rs = new IncAction[6]; |
2222 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new IncAction(m); |
2221 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2222 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2223 |
|
|
2224 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2225 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2242 |
|
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2243 |
|
try { |
2244 |
|
assertNull(h4.join()); |
2245 |
< |
rs[4].assertValue(inc(v1)); |
2245 |
> |
rs[4].assertValue(v1); |
2246 |
|
} catch (CompletionException ok) { |
2247 |
|
checkCompletedWithWrappedCancellationException(h4); |
2248 |
|
rs[4].assertNotInvoked(); |
2249 |
|
} |
2250 |
|
try { |
2251 |
|
assertNull(h5.join()); |
2252 |
< |
rs[5].assertValue(inc(v1)); |
2252 |
> |
rs[5].assertValue(v1); |
2253 |
|
} catch (CompletionException ok) { |
2254 |
|
checkCompletedWithWrappedCancellationException(h5); |
2255 |
|
rs[5].assertNotInvoked(); |
2309 |
|
* runAfterEither result completes normally after normal completion |
2310 |
|
* of either source |
2311 |
|
*/ |
2312 |
< |
public void testRunAfterEither_normalCompletion1() { |
2312 |
> |
public void testRunAfterEither_normalCompletion() { |
2313 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2314 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2315 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2316 |
|
{ |
2317 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2318 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2319 |
< |
final Noop r = new Noop(m); |
2320 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2319 |
> |
final Noop[] rs = new Noop[6]; |
2320 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2321 |
|
|
2322 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2323 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2324 |
+ |
checkIncomplete(h0); |
2325 |
+ |
checkIncomplete(h1); |
2326 |
+ |
rs[0].assertNotInvoked(); |
2327 |
+ |
rs[1].assertNotInvoked(); |
2328 |
|
f.complete(v1); |
2329 |
< |
checkCompletedNormally(h, null); |
2330 |
< |
r.assertInvoked(); |
2331 |
< |
g.complete(v2); |
2332 |
< |
|
2333 |
< |
checkCompletedNormally(f, v1); |
2334 |
< |
checkCompletedNormally(g, v2); |
2335 |
< |
checkCompletedNormally(h, null); |
2336 |
< |
r.assertInvoked(); |
2337 |
< |
}} |
2338 |
< |
|
2120 |
< |
public void testRunAfterEither_normalCompletion2() { |
2121 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2122 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2123 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2124 |
< |
{ |
2125 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2126 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2127 |
< |
final Noop r = new Noop(m); |
2128 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2329 |
> |
checkCompletedNormally(h0, null); |
2330 |
> |
checkCompletedNormally(h1, null); |
2331 |
> |
rs[0].assertInvoked(); |
2332 |
> |
rs[1].assertInvoked(); |
2333 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2334 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2335 |
> |
checkCompletedNormally(h2, null); |
2336 |
> |
checkCompletedNormally(h3, null); |
2337 |
> |
rs[2].assertInvoked(); |
2338 |
> |
rs[3].assertInvoked(); |
2339 |
|
|
2340 |
|
g.complete(v2); |
2131 |
– |
checkCompletedNormally(h, null); |
2132 |
– |
r.assertInvoked(); |
2133 |
– |
f.complete(v1); |
2134 |
– |
|
2135 |
– |
checkCompletedNormally(f, v1); |
2136 |
– |
checkCompletedNormally(g, v2); |
2137 |
– |
checkCompletedNormally(h, null); |
2138 |
– |
r.assertInvoked(); |
2139 |
– |
}} |
2140 |
– |
|
2141 |
– |
public void testRunAfterEither_normalCompletion3() { |
2142 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2143 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2144 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
2145 |
– |
{ |
2146 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2147 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2148 |
– |
final Noop r = new Noop(m); |
2341 |
|
|
2342 |
< |
f.complete(v1); |
2343 |
< |
g.complete(v2); |
2152 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2342 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2343 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2344 |
|
|
2154 |
– |
checkCompletedNormally(h, null); |
2345 |
|
checkCompletedNormally(f, v1); |
2346 |
|
checkCompletedNormally(g, v2); |
2347 |
< |
r.assertInvoked(); |
2347 |
> |
checkCompletedNormally(h0, null); |
2348 |
> |
checkCompletedNormally(h1, null); |
2349 |
> |
checkCompletedNormally(h2, null); |
2350 |
> |
checkCompletedNormally(h3, null); |
2351 |
> |
checkCompletedNormally(h4, null); |
2352 |
> |
checkCompletedNormally(h5, null); |
2353 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2354 |
|
}} |
2355 |
|
|
2356 |
|
/** |
2357 |
|
* runAfterEither result completes exceptionally after exceptional |
2358 |
|
* completion of either source |
2359 |
|
*/ |
2360 |
< |
public void testRunAfterEither_exceptionalCompletion1() { |
2360 |
> |
public void testRunAfterEither_exceptionalCompletion() { |
2361 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2362 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2363 |
|
{ |
2364 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2365 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2170 |
– |
final Noop r = new Noop(m); |
2171 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2366 |
|
final CFException ex = new CFException(); |
2367 |
+ |
final Noop[] rs = new Noop[6]; |
2368 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2369 |
|
|
2370 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2371 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2372 |
+ |
checkIncomplete(h0); |
2373 |
+ |
checkIncomplete(h1); |
2374 |
+ |
rs[0].assertNotInvoked(); |
2375 |
+ |
rs[1].assertNotInvoked(); |
2376 |
|
f.completeExceptionally(ex); |
2377 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2377 |
> |
checkCompletedWithWrappedException(h0, ex); |
2378 |
> |
checkCompletedWithWrappedException(h1, ex); |
2379 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2380 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2381 |
> |
checkCompletedWithWrappedException(h2, ex); |
2382 |
> |
checkCompletedWithWrappedException(h3, ex); |
2383 |
> |
|
2384 |
|
g.complete(v1); |
2385 |
|
|
2386 |
< |
r.assertNotInvoked(); |
2386 |
> |
// unspecified behavior - both source completions available |
2387 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2388 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2389 |
> |
try { |
2390 |
> |
assertNull(h4.join()); |
2391 |
> |
rs[4].assertInvoked(); |
2392 |
> |
} catch (CompletionException ok) { |
2393 |
> |
checkCompletedWithWrappedException(h4, ex); |
2394 |
> |
rs[4].assertNotInvoked(); |
2395 |
> |
} |
2396 |
> |
try { |
2397 |
> |
assertNull(h5.join()); |
2398 |
> |
rs[5].assertInvoked(); |
2399 |
> |
} catch (CompletionException ok) { |
2400 |
> |
checkCompletedWithWrappedException(h5, ex); |
2401 |
> |
rs[5].assertNotInvoked(); |
2402 |
> |
} |
2403 |
> |
|
2404 |
> |
checkCompletedExceptionally(f, ex); |
2405 |
|
checkCompletedNormally(g, v1); |
2406 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2407 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2406 |
> |
checkCompletedWithWrappedException(h0, ex); |
2407 |
> |
checkCompletedWithWrappedException(h1, ex); |
2408 |
> |
checkCompletedWithWrappedException(h2, ex); |
2409 |
> |
checkCompletedWithWrappedException(h3, ex); |
2410 |
> |
checkCompletedWithWrappedException(h4, ex); |
2411 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2412 |
|
}} |
2413 |
|
|
2414 |
|
public void testRunAfterEither_exceptionalCompletion2() { |
2415 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2416 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2417 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2418 |
|
{ |
2419 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2420 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2190 |
– |
final Noop r = new Noop(m); |
2191 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2421 |
|
final CFException ex = new CFException(); |
2422 |
+ |
final Noop[] rs = new Noop[6]; |
2423 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2424 |
|
|
2425 |
< |
g.completeExceptionally(ex); |
2426 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2427 |
< |
f.complete(v1); |
2428 |
< |
|
2429 |
< |
r.assertNotInvoked(); |
2430 |
< |
checkCompletedNormally(f, v1); |
2431 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2432 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2433 |
< |
}} |
2434 |
< |
|
2435 |
< |
public void testRunAfterEither_exceptionalCompletion3() { |
2205 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2206 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2207 |
< |
{ |
2208 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2209 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2210 |
< |
final Noop r = new Noop(m); |
2211 |
< |
final CFException ex = new CFException(); |
2212 |
< |
|
2213 |
< |
g.completeExceptionally(ex); |
2214 |
< |
f.complete(v1); |
2215 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2425 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2426 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2427 |
> |
if (fFirst) { |
2428 |
> |
f.complete(v1); |
2429 |
> |
g.completeExceptionally(ex); |
2430 |
> |
} else { |
2431 |
> |
g.completeExceptionally(ex); |
2432 |
> |
f.complete(v1); |
2433 |
> |
} |
2434 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2435 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2436 |
|
|
2437 |
< |
// unspecified behavior |
2218 |
< |
Integer v; |
2437 |
> |
// unspecified behavior - both source completions available |
2438 |
|
try { |
2439 |
< |
assertNull(h.join()); |
2440 |
< |
r.assertInvoked(); |
2439 |
> |
assertEquals(null, h0.join()); |
2440 |
> |
rs[0].assertInvoked(); |
2441 |
|
} catch (CompletionException ok) { |
2442 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2443 |
< |
r.assertNotInvoked(); |
2442 |
> |
checkCompletedWithWrappedException(h0, ex); |
2443 |
> |
rs[0].assertNotInvoked(); |
2444 |
> |
} |
2445 |
> |
try { |
2446 |
> |
assertEquals(null, h1.join()); |
2447 |
> |
rs[1].assertInvoked(); |
2448 |
> |
} catch (CompletionException ok) { |
2449 |
> |
checkCompletedWithWrappedException(h1, ex); |
2450 |
> |
rs[1].assertNotInvoked(); |
2451 |
> |
} |
2452 |
> |
try { |
2453 |
> |
assertEquals(null, h2.join()); |
2454 |
> |
rs[2].assertInvoked(); |
2455 |
> |
} catch (CompletionException ok) { |
2456 |
> |
checkCompletedWithWrappedException(h2, ex); |
2457 |
> |
rs[2].assertNotInvoked(); |
2458 |
> |
} |
2459 |
> |
try { |
2460 |
> |
assertEquals(null, h3.join()); |
2461 |
> |
rs[3].assertInvoked(); |
2462 |
> |
} catch (CompletionException ok) { |
2463 |
> |
checkCompletedWithWrappedException(h3, ex); |
2464 |
> |
rs[3].assertNotInvoked(); |
2465 |
|
} |
2466 |
|
|
2227 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2467 |
|
checkCompletedNormally(f, v1); |
2468 |
+ |
checkCompletedExceptionally(g, ex); |
2469 |
|
}} |
2470 |
|
|
2471 |
< |
public void testRunAfterEither_exceptionalCompletion4() { |
2471 |
> |
/** |
2472 |
> |
* runAfterEither result completes exceptionally if either source cancelled |
2473 |
> |
*/ |
2474 |
> |
public void testRunAfterEither_sourceCancelled() { |
2475 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2476 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2477 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2478 |
|
{ |
2479 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2480 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2481 |
< |
final Noop r = new Noop(m); |
2482 |
< |
final CFException ex = new CFException(); |
2481 |
> |
final Noop[] rs = new Noop[6]; |
2482 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2483 |
> |
|
2484 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2485 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2486 |
> |
checkIncomplete(h0); |
2487 |
> |
checkIncomplete(h1); |
2488 |
> |
rs[0].assertNotInvoked(); |
2489 |
> |
rs[1].assertNotInvoked(); |
2490 |
> |
f.cancel(mayInterruptIfRunning); |
2491 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2492 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2493 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2494 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2495 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2496 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2497 |
|
|
2240 |
– |
f.completeExceptionally(ex); |
2498 |
|
g.complete(v1); |
2242 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2499 |
|
|
2500 |
< |
// unspecified behavior |
2501 |
< |
Integer v; |
2500 |
> |
// unspecified behavior - both source completions available |
2501 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2502 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2503 |
|
try { |
2504 |
< |
assertNull(h.join()); |
2505 |
< |
r.assertInvoked(); |
2504 |
> |
assertNull(h4.join()); |
2505 |
> |
rs[4].assertInvoked(); |
2506 |
|
} catch (CompletionException ok) { |
2507 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2508 |
< |
r.assertNotInvoked(); |
2507 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2508 |
> |
rs[4].assertNotInvoked(); |
2509 |
> |
} |
2510 |
> |
try { |
2511 |
> |
assertNull(h5.join()); |
2512 |
> |
rs[5].assertInvoked(); |
2513 |
> |
} catch (CompletionException ok) { |
2514 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2515 |
> |
rs[5].assertNotInvoked(); |
2516 |
|
} |
2517 |
|
|
2518 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2518 |
> |
checkCancelled(f); |
2519 |
|
checkCompletedNormally(g, v1); |
2520 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
2521 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
2522 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
2523 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
2524 |
+ |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2525 |
|
}} |
2526 |
|
|
2527 |
|
/** |
2528 |
|
* runAfterEither result completes exceptionally if action does |
2529 |
|
*/ |
2530 |
< |
public void testRunAfterEither_actionFailed1() { |
2530 |
> |
public void testRunAfterEither_actionFailed() { |
2531 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2532 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2533 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2534 |
|
{ |
2535 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2536 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2537 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2538 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2537 |
> |
final FailingRunnable[] rs = new FailingRunnable[6]; |
2538 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m); |
2539 |
|
|
2540 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2541 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2542 |
|
f.complete(v1); |
2543 |
< |
checkCompletedWithWrappedCFException(h); |
2543 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2544 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2545 |
> |
checkCompletedWithWrappedCFException(h0); |
2546 |
> |
checkCompletedWithWrappedCFException(h1); |
2547 |
> |
checkCompletedWithWrappedCFException(h2); |
2548 |
> |
checkCompletedWithWrappedCFException(h3); |
2549 |
> |
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2550 |
|
g.complete(v2); |
2551 |
< |
checkCompletedNormally(f, v1); |
2552 |
< |
checkCompletedNormally(g, v2); |
2553 |
< |
}} |
2554 |
< |
|
2278 |
< |
public void testRunAfterEither_actionFailed2() { |
2279 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2280 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2281 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2282 |
< |
{ |
2283 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2284 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2285 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2286 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2551 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2552 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2553 |
> |
checkCompletedWithWrappedCFException(h4); |
2554 |
> |
checkCompletedWithWrappedCFException(h5); |
2555 |
|
|
2288 |
– |
g.complete(v2); |
2289 |
– |
checkCompletedWithWrappedCFException(h); |
2290 |
– |
f.complete(v1); |
2556 |
|
checkCompletedNormally(f, v1); |
2557 |
|
checkCompletedNormally(g, v2); |
2558 |
< |
}} |
2294 |
< |
|
2295 |
< |
/** |
2296 |
< |
* runAfterEither result completes exceptionally if either source cancelled |
2297 |
< |
*/ |
2298 |
< |
public void testRunAfterEither_sourceCancelled1() { |
2299 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2300 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2301 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2302 |
< |
{ |
2303 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2304 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2305 |
< |
final Noop r = new Noop(m); |
2306 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2307 |
< |
|
2308 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2309 |
< |
checkCompletedWithWrappedCancellationException(h); |
2310 |
< |
g.complete(v1); |
2311 |
< |
|
2312 |
< |
checkCancelled(f); |
2313 |
< |
r.assertNotInvoked(); |
2314 |
< |
checkCompletedNormally(g, v1); |
2315 |
< |
checkCompletedWithWrappedCancellationException(h); |
2316 |
< |
}} |
2317 |
< |
|
2318 |
< |
public void testRunAfterEither_sourceCancelled2() { |
2319 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2320 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2321 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2322 |
< |
{ |
2323 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2324 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2325 |
< |
final Noop r = new Noop(m); |
2326 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2327 |
< |
|
2328 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2329 |
< |
checkCompletedWithWrappedCancellationException(h); |
2330 |
< |
f.complete(v1); |
2331 |
< |
|
2332 |
< |
checkCancelled(g); |
2333 |
< |
r.assertNotInvoked(); |
2334 |
< |
checkCompletedNormally(f, v1); |
2335 |
< |
checkCompletedWithWrappedCancellationException(h); |
2336 |
< |
}} |
2337 |
< |
|
2338 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2339 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2340 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2341 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2342 |
< |
{ |
2343 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2344 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2345 |
< |
final Noop r = new Noop(m); |
2346 |
< |
|
2347 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2348 |
< |
f.complete(v1); |
2349 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2350 |
< |
|
2351 |
< |
// unspecified behavior |
2352 |
< |
Integer v; |
2353 |
< |
try { |
2354 |
< |
assertNull(h.join()); |
2355 |
< |
r.assertInvoked(); |
2356 |
< |
} catch (CompletionException ok) { |
2357 |
< |
checkCompletedWithWrappedCancellationException(h); |
2358 |
< |
r.assertNotInvoked(); |
2359 |
< |
} |
2360 |
< |
|
2361 |
< |
checkCancelled(g); |
2362 |
< |
checkCompletedNormally(f, v1); |
2363 |
< |
}} |
2364 |
< |
|
2365 |
< |
public void testRunAfterEither_sourceCancelled4() { |
2366 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2367 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2368 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2369 |
< |
{ |
2370 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2371 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2372 |
< |
final Noop r = new Noop(m); |
2373 |
< |
|
2374 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2375 |
< |
g.complete(v1); |
2376 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2377 |
< |
|
2378 |
< |
// unspecified behavior |
2379 |
< |
Integer v; |
2380 |
< |
try { |
2381 |
< |
assertNull(h.join()); |
2382 |
< |
r.assertInvoked(); |
2383 |
< |
} catch (CompletionException ok) { |
2384 |
< |
checkCompletedWithWrappedCancellationException(h); |
2385 |
< |
r.assertNotInvoked(); |
2386 |
< |
} |
2387 |
< |
|
2388 |
< |
checkCancelled(f); |
2389 |
< |
checkCompletedNormally(g, v1); |
2558 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2559 |
|
}} |
2560 |
|
|
2561 |
|
/** |
2574 |
|
|
2575 |
|
checkCompletedNormally(g, inc(v1)); |
2576 |
|
checkCompletedNormally(f, v1); |
2577 |
< |
r.assertInvoked(); |
2577 |
> |
r.assertValue(v1); |
2578 |
|
}} |
2579 |
|
|
2580 |
|
/** |
2592 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2593 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2594 |
|
|
2595 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2596 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2595 |
> |
checkCompletedWithWrappedException(g, ex); |
2596 |
> |
checkCompletedExceptionally(f, ex); |
2597 |
|
r.assertNotInvoked(); |
2598 |
|
}} |
2599 |
|
|
2864 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2865 |
|
(f, |
2866 |
|
(Integer x, Throwable t) -> { |
2867 |
+ |
m.checkExecutionMode(); |
2868 |
|
threadAssertSame(x, v1); |
2869 |
|
threadAssertNull(t); |
2870 |
|
a.getAndIncrement(); |
2892 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2893 |
|
(f, |
2894 |
|
(Integer x, Throwable t) -> { |
2895 |
+ |
m.checkExecutionMode(); |
2896 |
|
threadAssertNull(x); |
2897 |
|
threadAssertSame(t, ex); |
2898 |
|
a.getAndIncrement(); |
2899 |
|
}); |
2900 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2901 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2902 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2901 |
> |
checkCompletedExceptionally(f, ex); |
2902 |
> |
checkCompletedWithWrappedException(g, ex); |
2903 |
|
assertEquals(1, a.get()); |
2904 |
|
}} |
2905 |
|
|
2918 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2919 |
|
(f, |
2920 |
|
(Integer x, Throwable t) -> { |
2921 |
+ |
m.checkExecutionMode(); |
2922 |
|
threadAssertNull(x); |
2923 |
|
threadAssertTrue(t instanceof CancellationException); |
2924 |
|
a.getAndIncrement(); |
2925 |
|
}); |
2926 |
|
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2927 |
|
|
2756 |
– |
//try { g.join(); } catch (Throwable t) { throw new Error(t); } |
2928 |
|
checkCompletedWithWrappedCancellationException(g); |
2929 |
|
checkCancelled(f); |
2930 |
|
assertEquals(1, a.get()); |
2946 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2947 |
|
(f, |
2948 |
|
(Integer x, Throwable t) -> { |
2949 |
+ |
m.checkExecutionMode(); |
2950 |
|
threadAssertSame(x, v1); |
2951 |
|
threadAssertNull(t); |
2952 |
|
a.getAndIncrement(); |
2954 |
|
}); |
2955 |
|
if (createIncomplete) f.complete(v1); |
2956 |
|
checkCompletedNormally(f, v1); |
2957 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2957 |
> |
checkCompletedWithWrappedException(g, ex); |
2958 |
|
assertEquals(1, a.get()); |
2959 |
|
}} |
2960 |
|
|
2977 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2978 |
|
(f, |
2979 |
|
(Integer x, Throwable t) -> { |
2980 |
+ |
m.checkExecutionMode(); |
2981 |
|
threadAssertSame(t, ex1); |
2982 |
|
threadAssertNull(x); |
2983 |
|
a.getAndIncrement(); |
2985 |
|
}); |
2986 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
2987 |
|
|
2988 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
2989 |
< |
checkCompletedWithWrappedCFException(g, ex1); |
2988 |
> |
checkCompletedExceptionally(f, ex1); |
2989 |
> |
checkCompletedWithWrappedException(g, ex1); |
2990 |
|
assertEquals(1, a.get()); |
2991 |
|
}} |
2992 |
|
|