375 |
|
} |
376 |
|
} |
377 |
|
static final class Noop implements Runnable { |
378 |
+ |
int invocationCount = 0; |
379 |
|
boolean ran; |
380 |
< |
public void run() { ran = true; } |
380 |
> |
public void run() { |
381 |
> |
invocationCount++; |
382 |
> |
ran = true; |
383 |
> |
} |
384 |
|
} |
385 |
|
|
386 |
|
static final class FailingSupplier implements Supplier<Integer> { |
947 |
|
* of sources |
948 |
|
*/ |
949 |
|
public void testThenCombine_normalCompletion1() { |
950 |
+ |
for (boolean createdIncomplete : new boolean[] { true, false }) |
951 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
952 |
|
for (ExecutionMode m : ExecutionMode.values()) |
953 |
|
for (Integer v1 : new Integer[] { 1, null }) |
954 |
|
for (Integer v2 : new Integer[] { 2, null }) { |
956 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
957 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
958 |
|
final SubtractFunction r = new SubtractFunction(); |
959 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
959 |
> |
CompletableFuture<Integer> h = null; |
960 |
> |
if (createdIncomplete) h = m.thenCombine(f, g, r); |
961 |
|
|
962 |
< |
f.complete(v1); |
963 |
< |
checkIncomplete(h); |
964 |
< |
assertFalse(r.ran()); |
965 |
< |
g.complete(v2); |
966 |
< |
|
967 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
968 |
< |
checkCompletedNormally(f, v1); |
969 |
< |
checkCompletedNormally(g, v2); |
970 |
< |
} |
971 |
< |
} |
972 |
< |
|
966 |
< |
public void testThenCombine_normalCompletion2() { |
967 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
968 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
969 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
970 |
< |
|
971 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
972 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
973 |
< |
final SubtractFunction r = new SubtractFunction(); |
974 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
975 |
< |
|
976 |
< |
g.complete(v2); |
977 |
< |
checkIncomplete(h); |
978 |
< |
assertFalse(r.ran()); |
979 |
< |
f.complete(v1); |
980 |
< |
|
981 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
982 |
< |
checkCompletedNormally(f, v1); |
983 |
< |
checkCompletedNormally(g, v2); |
984 |
< |
} |
985 |
< |
} |
986 |
< |
|
987 |
< |
public void testThenCombine_normalCompletion3() { |
988 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
989 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
990 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
991 |
< |
|
992 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
993 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
994 |
< |
final SubtractFunction r = new SubtractFunction(); |
995 |
< |
|
996 |
< |
g.complete(v2); |
997 |
< |
f.complete(v1); |
998 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
999 |
< |
|
1000 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
1001 |
< |
checkCompletedNormally(f, v1); |
1002 |
< |
checkCompletedNormally(g, v2); |
1003 |
< |
} |
1004 |
< |
} |
1005 |
< |
|
1006 |
< |
public void testThenCombine_normalCompletion4() { |
1007 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1008 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1009 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1010 |
< |
|
1011 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1012 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1013 |
< |
final SubtractFunction r = new SubtractFunction(); |
1014 |
< |
|
1015 |
< |
f.complete(v1); |
1016 |
< |
g.complete(v2); |
1017 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
962 |
> |
if (fFirst) |
963 |
> |
f.complete(v1); |
964 |
> |
else |
965 |
> |
g.complete(v2); |
966 |
> |
if (createdIncomplete) checkIncomplete(h); |
967 |
> |
assertEquals(r.invocationCount, 0); |
968 |
> |
if (!fFirst) |
969 |
> |
f.complete(v1); |
970 |
> |
else |
971 |
> |
g.complete(v2); |
972 |
> |
if (!createdIncomplete) h = m.thenCombine(f, g, r); |
973 |
|
|
974 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
975 |
|
checkCompletedNormally(f, v1); |
976 |
|
checkCompletedNormally(g, v2); |
977 |
+ |
assertEquals(r.invocationCount, 1); |
978 |
|
} |
979 |
|
} |
980 |
|
|
998 |
|
|
999 |
|
checkCompletedWithWrappedCFException(h, ex); |
1000 |
|
checkCompletedWithWrappedCFException(f, ex); |
1001 |
< |
assertFalse(r.ran()); |
1001 |
> |
assertEquals(r.invocationCount, 0); |
1002 |
|
checkCompletedNormally(g, v1); |
1003 |
|
} |
1004 |
|
} |
1019 |
|
|
1020 |
|
checkCompletedWithWrappedCFException(h, ex); |
1021 |
|
checkCompletedWithWrappedCFException(g, ex); |
1022 |
< |
assertFalse(r.ran()); |
1022 |
> |
assertEquals(r.invocationCount, 0); |
1023 |
|
checkCompletedNormally(f, v1); |
1024 |
|
} |
1025 |
|
} |
1039 |
|
|
1040 |
|
checkCompletedWithWrappedCFException(h, ex); |
1041 |
|
checkCompletedWithWrappedCFException(g, ex); |
1042 |
< |
assertFalse(r.ran()); |
1042 |
> |
assertEquals(r.invocationCount, 0); |
1043 |
|
checkCompletedNormally(f, v1); |
1044 |
|
} |
1045 |
|
} |
1059 |
|
|
1060 |
|
checkCompletedWithWrappedCFException(h, ex); |
1061 |
|
checkCompletedWithWrappedCFException(f, ex); |
1062 |
< |
assertFalse(r.ran()); |
1062 |
> |
assertEquals(r.invocationCount, 0); |
1063 |
|
checkCompletedNormally(g, v1); |
1064 |
|
} |
1065 |
|
} |
1126 |
|
|
1127 |
|
checkCompletedWithWrappedCancellationException(h); |
1128 |
|
checkCancelled(f); |
1129 |
< |
assertFalse(r.ran()); |
1129 |
> |
assertEquals(r.invocationCount, 0); |
1130 |
|
checkCompletedNormally(g, v1); |
1131 |
|
} |
1132 |
|
} |
1147 |
|
|
1148 |
|
checkCompletedWithWrappedCancellationException(h); |
1149 |
|
checkCancelled(g); |
1150 |
< |
assertFalse(r.ran()); |
1150 |
> |
assertEquals(r.invocationCount, 0); |
1151 |
|
checkCompletedNormally(f, v1); |
1152 |
|
} |
1153 |
|
} |
1167 |
|
|
1168 |
|
checkCompletedWithWrappedCancellationException(h); |
1169 |
|
checkCancelled(g); |
1170 |
< |
assertFalse(r.ran()); |
1170 |
> |
assertEquals(r.invocationCount, 0); |
1171 |
|
checkCompletedNormally(f, v1); |
1172 |
|
} |
1173 |
|
} |
1187 |
|
|
1188 |
|
checkCompletedWithWrappedCancellationException(h); |
1189 |
|
checkCancelled(f); |
1190 |
< |
assertFalse(r.ran()); |
1190 |
> |
assertEquals(r.invocationCount, 0); |
1191 |
|
checkCompletedNormally(g, v1); |
1192 |
|
} |
1193 |
|
} |
1300 |
|
|
1301 |
|
checkCompletedWithWrappedCFException(h, ex); |
1302 |
|
checkCompletedWithWrappedCFException(f, ex); |
1303 |
< |
assertFalse(r.ran()); |
1303 |
> |
assertEquals(r.invocationCount, 0); |
1304 |
|
checkCompletedNormally(g, v1); |
1305 |
|
} |
1306 |
|
} |
1321 |
|
|
1322 |
|
checkCompletedWithWrappedCFException(h, ex); |
1323 |
|
checkCompletedWithWrappedCFException(g, ex); |
1324 |
< |
assertFalse(r.ran()); |
1324 |
> |
assertEquals(r.invocationCount, 0); |
1325 |
|
checkCompletedNormally(f, v1); |
1326 |
|
} |
1327 |
|
} |
1341 |
|
|
1342 |
|
checkCompletedWithWrappedCFException(h, ex); |
1343 |
|
checkCompletedWithWrappedCFException(g, ex); |
1344 |
< |
assertFalse(r.ran()); |
1344 |
> |
assertEquals(r.invocationCount, 0); |
1345 |
|
checkCompletedNormally(f, v1); |
1346 |
|
} |
1347 |
|
} |
1428 |
|
|
1429 |
|
checkCompletedWithWrappedCancellationException(h); |
1430 |
|
checkCancelled(f); |
1431 |
< |
assertFalse(r.ran()); |
1431 |
> |
assertEquals(r.invocationCount, 0); |
1432 |
|
checkCompletedNormally(g, v1); |
1433 |
|
} |
1434 |
|
} |
1449 |
|
|
1450 |
|
checkCompletedWithWrappedCancellationException(h); |
1451 |
|
checkCancelled(g); |
1452 |
< |
assertFalse(r.ran()); |
1452 |
> |
assertEquals(r.invocationCount, 0); |
1453 |
|
checkCompletedNormally(f, v1); |
1454 |
|
} |
1455 |
|
} |
1469 |
|
|
1470 |
|
checkCompletedWithWrappedCancellationException(h); |
1471 |
|
checkCancelled(g); |
1472 |
< |
assertFalse(r.ran()); |
1472 |
> |
assertEquals(r.invocationCount, 0); |
1473 |
|
checkCompletedNormally(f, v1); |
1474 |
|
} |
1475 |
|
} |
1489 |
|
|
1490 |
|
checkCompletedWithWrappedCancellationException(h); |
1491 |
|
checkCancelled(f); |
1492 |
< |
assertFalse(r.ran()); |
1492 |
> |
assertEquals(r.invocationCount, 0); |
1493 |
|
checkCompletedNormally(g, v1); |
1494 |
|
} |
1495 |
|
} |
1514 |
|
g.complete(v2); |
1515 |
|
|
1516 |
|
checkCompletedNormally(h, null); |
1517 |
< |
assertTrue(r.ran); |
1517 |
> |
assertEquals(r.invocationCount, 1); |
1518 |
|
checkCompletedNormally(f, v1); |
1519 |
|
checkCompletedNormally(g, v2); |
1520 |
|
} |
1536 |
|
f.complete(v1); |
1537 |
|
|
1538 |
|
checkCompletedNormally(h, null); |
1539 |
< |
assertTrue(r.ran); |
1539 |
> |
assertEquals(r.invocationCount, 1); |
1540 |
|
checkCompletedNormally(f, v1); |
1541 |
|
checkCompletedNormally(g, v2); |
1542 |
|
} |
1576 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1577 |
|
|
1578 |
|
checkCompletedNormally(h, null); |
1579 |
< |
assertTrue(r.ran); |
1579 |
> |
assertEquals(r.invocationCount, 1); |
1580 |
|
checkCompletedNormally(f, v1); |
1581 |
|
checkCompletedNormally(g, v2); |
1582 |
|
} |
1602 |
|
|
1603 |
|
checkCompletedWithWrappedCFException(h, ex); |
1604 |
|
checkCompletedWithWrappedCFException(f, ex); |
1605 |
< |
assertFalse(r.ran); |
1605 |
> |
assertEquals(r.invocationCount, 0); |
1606 |
|
checkCompletedNormally(g, v1); |
1607 |
|
} |
1608 |
|
} |
1623 |
|
|
1624 |
|
checkCompletedWithWrappedCFException(h, ex); |
1625 |
|
checkCompletedWithWrappedCFException(g, ex); |
1626 |
< |
assertFalse(r.ran); |
1626 |
> |
assertEquals(r.invocationCount, 0); |
1627 |
|
checkCompletedNormally(f, v1); |
1628 |
|
} |
1629 |
|
} |
1643 |
|
|
1644 |
|
checkCompletedWithWrappedCFException(h, ex); |
1645 |
|
checkCompletedWithWrappedCFException(g, ex); |
1646 |
< |
assertFalse(r.ran); |
1646 |
> |
assertEquals(r.invocationCount, 0); |
1647 |
|
checkCompletedNormally(f, v1); |
1648 |
|
} |
1649 |
|
} |
1663 |
|
|
1664 |
|
checkCompletedWithWrappedCFException(h, ex); |
1665 |
|
checkCompletedWithWrappedCFException(f, ex); |
1666 |
< |
assertFalse(r.ran); |
1666 |
> |
assertEquals(r.invocationCount, 0); |
1667 |
|
checkCompletedNormally(g, v1); |
1668 |
|
} |
1669 |
|
} |
1730 |
|
|
1731 |
|
checkCompletedWithWrappedCancellationException(h); |
1732 |
|
checkCancelled(f); |
1733 |
< |
assertFalse(r.ran); |
1733 |
> |
assertEquals(r.invocationCount, 0); |
1734 |
|
checkCompletedNormally(g, v1); |
1735 |
|
} |
1736 |
|
} |
1751 |
|
|
1752 |
|
checkCompletedWithWrappedCancellationException(h); |
1753 |
|
checkCancelled(g); |
1754 |
< |
assertFalse(r.ran); |
1754 |
> |
assertEquals(r.invocationCount, 0); |
1755 |
|
checkCompletedNormally(f, v1); |
1756 |
|
} |
1757 |
|
} |
1771 |
|
|
1772 |
|
checkCompletedWithWrappedCancellationException(h); |
1773 |
|
checkCancelled(g); |
1774 |
< |
assertFalse(r.ran); |
1774 |
> |
assertEquals(r.invocationCount, 0); |
1775 |
|
checkCompletedNormally(f, v1); |
1776 |
|
} |
1777 |
|
} |
1791 |
|
|
1792 |
|
checkCompletedWithWrappedCancellationException(h); |
1793 |
|
checkCancelled(f); |
1794 |
< |
assertFalse(r.ran); |
1794 |
> |
assertEquals(r.invocationCount, 0); |
1795 |
|
checkCompletedNormally(g, v1); |
1796 |
|
} |
1797 |
|
} |
1858 |
|
// unspecified behavior |
1859 |
|
assertTrue(Objects.equals(h.join(), inc(v1)) || |
1860 |
|
Objects.equals(h.join(), inc(v2))); |
1861 |
+ |
assertEquals(r.invocationCount, 1); |
1862 |
|
} |
1863 |
|
} |
1864 |
|
|
1880 |
|
checkCompletedWithWrappedCFException(h, ex); |
1881 |
|
g.complete(v1); |
1882 |
|
|
1883 |
< |
assertFalse(r.ran()); |
1883 |
> |
assertEquals(r.invocationCount, 0); |
1884 |
|
checkCompletedNormally(g, v1); |
1885 |
|
checkCompletedWithWrappedCFException(f, ex); |
1886 |
|
checkCompletedWithWrappedCFException(h, ex); |
1901 |
|
checkCompletedWithWrappedCFException(h, ex); |
1902 |
|
f.complete(v1); |
1903 |
|
|
1904 |
< |
assertFalse(r.ran()); |
1904 |
> |
assertEquals(r.invocationCount, 0); |
1905 |
|
checkCompletedNormally(f, v1); |
1906 |
|
checkCompletedWithWrappedCFException(g, ex); |
1907 |
|
checkCompletedWithWrappedCFException(h, ex); |
1925 |
|
Integer v; |
1926 |
|
try { |
1927 |
|
assertEquals(h.join(), inc(v1)); |
1928 |
< |
assertTrue(r.ran()); |
1928 |
> |
assertEquals(r.invocationCount, 1); |
1929 |
|
} catch (CompletionException ok) { |
1930 |
|
checkCompletedWithWrappedCFException(h, ex); |
1931 |
< |
assertFalse(r.ran()); |
1931 |
> |
assertEquals(r.invocationCount, 0); |
1932 |
|
} |
1933 |
|
|
1934 |
|
checkCompletedWithWrappedCFException(g, ex); |
1953 |
|
Integer v; |
1954 |
|
try { |
1955 |
|
assertEquals(h.join(), inc(v1)); |
1956 |
< |
assertTrue(r.ran()); |
1956 |
> |
assertEquals(r.invocationCount, 1); |
1957 |
|
} catch (CompletionException ok) { |
1958 |
|
checkCompletedWithWrappedCFException(h, ex); |
1959 |
< |
assertFalse(r.ran()); |
1959 |
> |
assertEquals(r.invocationCount, 0); |
1960 |
|
} |
1961 |
|
|
1962 |
|
checkCompletedWithWrappedCFException(f, ex); |
2006 |
– |
assertFalse(r.ran()); |
1963 |
|
checkCompletedNormally(g, v1); |
1964 |
|
} |
1965 |
|
} |
2021 |
|
g.complete(v1); |
2022 |
|
|
2023 |
|
checkCancelled(f); |
2024 |
< |
assertFalse(r.ran()); |
2024 |
> |
assertEquals(r.invocationCount, 0); |
2025 |
|
checkCompletedNormally(g, v1); |
2026 |
|
checkCompletedWithWrappedCancellationException(h); |
2027 |
|
} |
2042 |
|
f.complete(v1); |
2043 |
|
|
2044 |
|
checkCancelled(g); |
2045 |
< |
assertFalse(r.ran()); |
2045 |
> |
assertEquals(r.invocationCount, 0); |
2046 |
|
checkCompletedNormally(f, v1); |
2047 |
|
checkCompletedWithWrappedCancellationException(h); |
2048 |
|
} |
2065 |
|
Integer v; |
2066 |
|
try { |
2067 |
|
assertEquals(h.join(), inc(v1)); |
2068 |
< |
assertTrue(r.ran()); |
2068 |
> |
assertEquals(r.invocationCount, 1); |
2069 |
|
} catch (CompletionException ok) { |
2070 |
|
checkCompletedWithWrappedCancellationException(h); |
2071 |
< |
assertFalse(r.ran()); |
2071 |
> |
assertEquals(r.invocationCount, 0); |
2072 |
|
} |
2073 |
|
|
2074 |
|
checkCancelled(g); |
2093 |
|
Integer v; |
2094 |
|
try { |
2095 |
|
assertEquals(h.join(), inc(v1)); |
2096 |
< |
assertTrue(r.ran()); |
2096 |
> |
assertEquals(r.invocationCount, 1); |
2097 |
|
} catch (CompletionException ok) { |
2098 |
|
checkCompletedWithWrappedCancellationException(h); |
2099 |
< |
assertFalse(r.ran()); |
2099 |
> |
assertEquals(r.invocationCount, 0); |
2100 |
|
} |
2101 |
|
|
2102 |
|
checkCancelled(f); |
2190 |
|
checkCompletedWithWrappedCFException(h, ex); |
2191 |
|
g.complete(v1); |
2192 |
|
|
2193 |
< |
assertFalse(r.ran()); |
2193 |
> |
assertEquals(r.invocationCount, 0); |
2194 |
|
checkCompletedNormally(g, v1); |
2195 |
|
checkCompletedWithWrappedCFException(f, ex); |
2196 |
|
checkCompletedWithWrappedCFException(h, ex); |
2211 |
|
checkCompletedWithWrappedCFException(h, ex); |
2212 |
|
f.complete(v1); |
2213 |
|
|
2214 |
< |
assertFalse(r.ran()); |
2214 |
> |
assertEquals(r.invocationCount, 0); |
2215 |
|
checkCompletedNormally(f, v1); |
2216 |
|
checkCompletedWithWrappedCFException(g, ex); |
2217 |
|
checkCompletedWithWrappedCFException(h, ex); |
2235 |
|
Integer v; |
2236 |
|
try { |
2237 |
|
assertEquals(h.join(), null); |
2238 |
< |
assertTrue(r.ran()); |
2238 |
> |
assertEquals(r.invocationCount, 1); |
2239 |
|
assertEquals(inc(v1), r.value); |
2240 |
|
} catch (CompletionException ok) { |
2241 |
|
checkCompletedWithWrappedCFException(h, ex); |
2242 |
< |
assertFalse(r.ran()); |
2242 |
> |
assertEquals(r.invocationCount, 0); |
2243 |
|
} |
2244 |
|
|
2245 |
|
checkCompletedWithWrappedCFException(g, ex); |
2264 |
|
Integer v; |
2265 |
|
try { |
2266 |
|
assertEquals(h.join(), null); |
2267 |
< |
assertTrue(r.ran()); |
2267 |
> |
assertEquals(r.invocationCount, 1); |
2268 |
|
assertEquals(inc(v1), r.value); |
2269 |
|
} catch (CompletionException ok) { |
2270 |
|
checkCompletedWithWrappedCFException(h, ex); |
2271 |
< |
assertFalse(r.ran()); |
2271 |
> |
assertEquals(r.invocationCount, 0); |
2272 |
|
} |
2273 |
|
|
2274 |
|
checkCompletedWithWrappedCFException(f, ex); |
2319 |
– |
assertFalse(r.ran()); |
2275 |
|
checkCompletedNormally(g, v1); |
2276 |
|
} |
2277 |
|
} |
2333 |
|
g.complete(v1); |
2334 |
|
|
2335 |
|
checkCancelled(f); |
2336 |
< |
assertFalse(r.ran()); |
2336 |
> |
assertEquals(r.invocationCount, 0); |
2337 |
|
checkCompletedNormally(g, v1); |
2338 |
|
checkCompletedWithWrappedCancellationException(h); |
2339 |
|
} |
2354 |
|
f.complete(v1); |
2355 |
|
|
2356 |
|
checkCancelled(g); |
2357 |
< |
assertFalse(r.ran()); |
2357 |
> |
assertEquals(r.invocationCount, 0); |
2358 |
|
checkCompletedNormally(f, v1); |
2359 |
|
checkCompletedWithWrappedCancellationException(h); |
2360 |
|
} |
2377 |
|
Integer v; |
2378 |
|
try { |
2379 |
|
assertEquals(h.join(), null); |
2380 |
< |
assertTrue(r.ran()); |
2380 |
> |
assertEquals(r.invocationCount, 1); |
2381 |
|
assertEquals(inc(v1), r.value); |
2382 |
|
} catch (CompletionException ok) { |
2383 |
|
checkCompletedWithWrappedCancellationException(h); |
2384 |
< |
assertFalse(r.ran()); |
2384 |
> |
assertEquals(r.invocationCount, 0); |
2385 |
|
} |
2386 |
|
|
2387 |
|
checkCancelled(g); |
2406 |
|
Integer v; |
2407 |
|
try { |
2408 |
|
assertEquals(h.join(), null); |
2409 |
< |
assertTrue(r.ran()); |
2409 |
> |
assertEquals(r.invocationCount, 1); |
2410 |
|
assertEquals(inc(v1), r.value); |
2411 |
|
} catch (CompletionException ok) { |
2412 |
|
checkCompletedWithWrappedCancellationException(h); |
2413 |
< |
assertFalse(r.ran()); |
2413 |
> |
assertEquals(r.invocationCount, 0); |
2414 |
|
} |
2415 |
|
|
2416 |
|
checkCancelled(f); |
2422 |
|
* runAfterEither result completes normally after normal completion |
2423 |
|
* of either source |
2424 |
|
*/ |
2425 |
< |
public void testRunAfterEither() { |
2426 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2427 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2428 |
< |
Noop r = new Noop(); |
2474 |
< |
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
2475 |
< |
f.complete(one); |
2476 |
< |
checkCompletedNormally(g, null); |
2477 |
< |
f2.complete(one); |
2478 |
< |
checkCompletedNormally(g, null); |
2479 |
< |
assertTrue(r.ran); |
2425 |
> |
public void testRunAfterEither_normalCompletion1() { |
2426 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2427 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2428 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2429 |
|
|
2430 |
< |
r = new Noop(); |
2431 |
< |
f = new CompletableFuture<>(); |
2432 |
< |
f.complete(one); |
2433 |
< |
f2 = new CompletableFuture<>(); |
2434 |
< |
g = f.runAfterEither(f2, r); |
2435 |
< |
checkCompletedNormally(g, null); |
2436 |
< |
assertTrue(r.ran); |
2430 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2431 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2432 |
> |
final Noop r = new Noop(); |
2433 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2434 |
> |
|
2435 |
> |
f.complete(v1); |
2436 |
> |
checkCompletedNormally(h, null); |
2437 |
> |
assertEquals(r.invocationCount, 1); |
2438 |
> |
g.complete(v2); |
2439 |
> |
|
2440 |
> |
checkCompletedNormally(f, v1); |
2441 |
> |
checkCompletedNormally(g, v2); |
2442 |
> |
checkCompletedNormally(h, null); |
2443 |
> |
assertEquals(r.invocationCount, 1); |
2444 |
> |
} |
2445 |
> |
} |
2446 |
> |
|
2447 |
> |
public void testRunAfterEither_normalCompletion2() { |
2448 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2449 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2450 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2451 |
> |
|
2452 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2453 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2454 |
> |
final Noop r = new Noop(); |
2455 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2456 |
> |
|
2457 |
> |
g.complete(v2); |
2458 |
> |
checkCompletedNormally(h, null); |
2459 |
> |
assertEquals(r.invocationCount, 1); |
2460 |
> |
f.complete(v1); |
2461 |
> |
|
2462 |
> |
checkCompletedNormally(f, v1); |
2463 |
> |
checkCompletedNormally(g, v2); |
2464 |
> |
checkCompletedNormally(h, null); |
2465 |
> |
assertEquals(r.invocationCount, 1); |
2466 |
> |
} |
2467 |
> |
} |
2468 |
> |
public void testRunAfterEither_normalCompletion3() { |
2469 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2470 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2471 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2472 |
> |
|
2473 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2474 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2475 |
> |
final Noop r = new Noop(); |
2476 |
> |
|
2477 |
> |
f.complete(v1); |
2478 |
> |
g.complete(v2); |
2479 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2480 |
> |
|
2481 |
> |
checkCompletedNormally(h, null); |
2482 |
> |
checkCompletedNormally(f, v1); |
2483 |
> |
checkCompletedNormally(g, v2); |
2484 |
> |
assertEquals(r.invocationCount, 1); |
2485 |
> |
} |
2486 |
|
} |
2487 |
|
|
2488 |
|
/** |
2489 |
|
* runAfterEither result completes exceptionally after exceptional |
2490 |
|
* completion of either source |
2491 |
|
*/ |
2492 |
< |
public void testRunAfterEither2() { |
2493 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2494 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2497 |
< |
Noop r = new Noop(); |
2498 |
< |
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
2499 |
< |
f.completeExceptionally(new CFException()); |
2500 |
< |
f2.complete(one); |
2501 |
< |
checkCompletedWithWrappedCFException(g); |
2492 |
> |
public void testRunAfterEither_exceptionalCompletion1() { |
2493 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2494 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2495 |
|
|
2496 |
< |
r = new Noop(); |
2497 |
< |
f = new CompletableFuture<>(); |
2498 |
< |
f2 = new CompletableFuture<>(); |
2499 |
< |
f2.completeExceptionally(new CFException()); |
2500 |
< |
g = f.runAfterEither(f2, r); |
2501 |
< |
checkCompletedWithWrappedCFException(g); |
2496 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2497 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2498 |
> |
final Noop r = new Noop(); |
2499 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2500 |
> |
final CFException ex = new CFException(); |
2501 |
> |
|
2502 |
> |
f.completeExceptionally(ex); |
2503 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2504 |
> |
g.complete(v1); |
2505 |
> |
|
2506 |
> |
assertEquals(r.invocationCount, 0); |
2507 |
> |
checkCompletedNormally(g, v1); |
2508 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2509 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2510 |
> |
} |
2511 |
> |
} |
2512 |
> |
|
2513 |
> |
public void testRunAfterEither_exceptionalCompletion2() { |
2514 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2515 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2516 |
> |
|
2517 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2518 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2519 |
> |
final Noop r = new Noop(); |
2520 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2521 |
> |
final CFException ex = new CFException(); |
2522 |
> |
|
2523 |
> |
g.completeExceptionally(ex); |
2524 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2525 |
> |
f.complete(v1); |
2526 |
> |
|
2527 |
> |
assertEquals(r.invocationCount, 0); |
2528 |
> |
checkCompletedNormally(f, v1); |
2529 |
> |
checkCompletedWithWrappedCFException(g, ex); |
2530 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2531 |
> |
} |
2532 |
> |
} |
2533 |
> |
|
2534 |
> |
public void testRunAfterEither_exceptionalCompletion3() { |
2535 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2536 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2537 |
> |
|
2538 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2539 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2540 |
> |
final Noop r = new Noop(); |
2541 |
> |
final CFException ex = new CFException(); |
2542 |
> |
|
2543 |
> |
g.completeExceptionally(ex); |
2544 |
> |
f.complete(v1); |
2545 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2546 |
> |
|
2547 |
> |
// unspecified behavior |
2548 |
> |
Integer v; |
2549 |
> |
try { |
2550 |
> |
assertEquals(h.join(), null); |
2551 |
> |
assertEquals(r.invocationCount, 1); |
2552 |
> |
} catch (CompletionException ok) { |
2553 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2554 |
> |
assertEquals(r.invocationCount, 0); |
2555 |
> |
} |
2556 |
> |
|
2557 |
> |
checkCompletedWithWrappedCFException(g, ex); |
2558 |
> |
checkCompletedNormally(f, v1); |
2559 |
> |
} |
2560 |
> |
} |
2561 |
> |
|
2562 |
> |
public void testRunAfterEither_exceptionalCompletion4() { |
2563 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2564 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2565 |
> |
|
2566 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2567 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2568 |
> |
final Noop r = new Noop(); |
2569 |
> |
final CFException ex = new CFException(); |
2570 |
> |
|
2571 |
> |
f.completeExceptionally(ex); |
2572 |
> |
g.complete(v1); |
2573 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2574 |
> |
|
2575 |
> |
// unspecified behavior |
2576 |
> |
Integer v; |
2577 |
> |
try { |
2578 |
> |
assertEquals(h.join(), null); |
2579 |
> |
assertEquals(r.invocationCount, 1); |
2580 |
> |
} catch (CompletionException ok) { |
2581 |
> |
checkCompletedWithWrappedCFException(h, ex); |
2582 |
> |
assertEquals(r.invocationCount, 0); |
2583 |
> |
} |
2584 |
> |
|
2585 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2586 |
> |
checkCompletedNormally(g, v1); |
2587 |
> |
} |
2588 |
|
} |
2589 |
|
|
2590 |
|
/** |
2591 |
|
* runAfterEither result completes exceptionally if action does |
2592 |
|
*/ |
2593 |
< |
public void testRunAfterEither3() { |
2594 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2595 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2596 |
< |
FailingNoop r = new FailingNoop(); |
2597 |
< |
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
2598 |
< |
f2.complete(two); |
2599 |
< |
checkCompletedWithWrappedCFException(g); |
2593 |
> |
public void testRunAfterEither_actionFailed1() { |
2594 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2595 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2596 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2597 |
> |
|
2598 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2599 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2600 |
> |
final FailingNoop r = new FailingNoop(); |
2601 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2602 |
> |
|
2603 |
> |
f.complete(v1); |
2604 |
> |
checkCompletedWithWrappedCFException(h); |
2605 |
> |
g.complete(v2); |
2606 |
> |
checkCompletedNormally(f, v1); |
2607 |
> |
checkCompletedNormally(g, v2); |
2608 |
> |
} |
2609 |
> |
} |
2610 |
> |
|
2611 |
> |
public void testRunAfterEither_actionFailed2() { |
2612 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2613 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2614 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
2615 |
> |
|
2616 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2617 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2618 |
> |
final FailingNoop r = new FailingNoop(); |
2619 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2620 |
> |
|
2621 |
> |
g.complete(v2); |
2622 |
> |
checkCompletedWithWrappedCFException(h); |
2623 |
> |
f.complete(v1); |
2624 |
> |
checkCompletedNormally(f, v1); |
2625 |
> |
checkCompletedNormally(g, v2); |
2626 |
> |
} |
2627 |
|
} |
2628 |
|
|
2629 |
|
/** |
2630 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2631 |
|
*/ |
2632 |
< |
public void testRunAfterEither4() { |
2633 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2634 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2635 |
< |
Noop r = new Noop(); |
2636 |
< |
CompletableFuture<Void> g = f.runAfterEither(f2, r); |
2637 |
< |
assertTrue(f.cancel(true)); |
2638 |
< |
checkCompletedWithWrappedCancellationException(g); |
2639 |
< |
f = new CompletableFuture<>(); |
2640 |
< |
f2 = new CompletableFuture<>(); |
2641 |
< |
assertTrue(f2.cancel(true)); |
2642 |
< |
checkCompletedWithWrappedCancellationException(g); |
2632 |
> |
public void testRunAfterEither_sourceCancelled1() { |
2633 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2634 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2635 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2636 |
> |
|
2637 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2638 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2639 |
> |
final Noop r = new Noop(); |
2640 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2641 |
> |
|
2642 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2643 |
> |
checkCompletedWithWrappedCancellationException(h); |
2644 |
> |
g.complete(v1); |
2645 |
> |
|
2646 |
> |
checkCancelled(f); |
2647 |
> |
assertEquals(r.invocationCount, 0); |
2648 |
> |
checkCompletedNormally(g, v1); |
2649 |
> |
checkCompletedWithWrappedCancellationException(h); |
2650 |
> |
} |
2651 |
> |
} |
2652 |
> |
|
2653 |
> |
public void testRunAfterEither_sourceCancelled2() { |
2654 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2655 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2656 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2657 |
> |
|
2658 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2659 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2660 |
> |
final Noop r = new Noop(); |
2661 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2662 |
> |
|
2663 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2664 |
> |
checkCompletedWithWrappedCancellationException(h); |
2665 |
> |
f.complete(v1); |
2666 |
> |
|
2667 |
> |
checkCancelled(g); |
2668 |
> |
assertEquals(r.invocationCount, 0); |
2669 |
> |
checkCompletedNormally(f, v1); |
2670 |
> |
checkCompletedWithWrappedCancellationException(h); |
2671 |
> |
} |
2672 |
> |
} |
2673 |
> |
|
2674 |
> |
public void testRunAfterEither_sourceCancelled3() { |
2675 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2676 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2677 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2678 |
> |
|
2679 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2680 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2681 |
> |
final Noop r = new Noop(); |
2682 |
> |
|
2683 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2684 |
> |
f.complete(v1); |
2685 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2686 |
> |
|
2687 |
> |
// unspecified behavior |
2688 |
> |
Integer v; |
2689 |
> |
try { |
2690 |
> |
assertEquals(h.join(), null); |
2691 |
> |
assertEquals(r.invocationCount, 1); |
2692 |
> |
} catch (CompletionException ok) { |
2693 |
> |
checkCompletedWithWrappedCancellationException(h); |
2694 |
> |
assertEquals(r.invocationCount, 0); |
2695 |
> |
} |
2696 |
> |
|
2697 |
> |
checkCancelled(g); |
2698 |
> |
checkCompletedNormally(f, v1); |
2699 |
> |
} |
2700 |
> |
} |
2701 |
> |
|
2702 |
> |
public void testRunAfterEither_sourceCancelled4() { |
2703 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2704 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2705 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2706 |
> |
|
2707 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2708 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2709 |
> |
final Noop r = new Noop(); |
2710 |
> |
|
2711 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2712 |
> |
g.complete(v1); |
2713 |
> |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2714 |
> |
|
2715 |
> |
// unspecified behavior |
2716 |
> |
Integer v; |
2717 |
> |
try { |
2718 |
> |
assertEquals(h.join(), null); |
2719 |
> |
assertEquals(r.invocationCount, 1); |
2720 |
> |
} catch (CompletionException ok) { |
2721 |
> |
checkCompletedWithWrappedCancellationException(h); |
2722 |
> |
assertEquals(r.invocationCount, 0); |
2723 |
> |
} |
2724 |
> |
|
2725 |
> |
checkCancelled(f); |
2726 |
> |
checkCompletedNormally(g, v1); |
2727 |
> |
} |
2728 |
|
} |
2729 |
|
|
2730 |
|
/** |
2950 |
|
} |
2951 |
|
|
2952 |
|
/** |
2762 |
– |
* runAfterEitherAsync result completes normally after normal |
2763 |
– |
* completion of sources |
2764 |
– |
*/ |
2765 |
– |
public void testRunAfterEitherAsync() { |
2766 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2767 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2768 |
– |
Noop r = new Noop(); |
2769 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2770 |
– |
f.complete(one); |
2771 |
– |
checkCompletedNormally(g, null); |
2772 |
– |
assertTrue(r.ran); |
2773 |
– |
|
2774 |
– |
r = new Noop(); |
2775 |
– |
f = new CompletableFuture<>(); |
2776 |
– |
f.complete(one); |
2777 |
– |
f2 = new CompletableFuture<>(); |
2778 |
– |
g = f.runAfterEitherAsync(f2, r); |
2779 |
– |
checkCompletedNormally(g, null); |
2780 |
– |
assertTrue(r.ran); |
2781 |
– |
} |
2782 |
– |
|
2783 |
– |
/** |
2784 |
– |
* runAfterEitherAsync result completes exceptionally after exceptional |
2785 |
– |
* completion of source |
2786 |
– |
*/ |
2787 |
– |
public void testRunAfterEitherAsync2() { |
2788 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2789 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2790 |
– |
Noop r = new Noop(); |
2791 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2792 |
– |
f.completeExceptionally(new CFException()); |
2793 |
– |
checkCompletedWithWrappedCFException(g); |
2794 |
– |
|
2795 |
– |
r = new Noop(); |
2796 |
– |
f = new CompletableFuture<>(); |
2797 |
– |
f2 = new CompletableFuture<>(); |
2798 |
– |
f2.completeExceptionally(new CFException()); |
2799 |
– |
g = f.runAfterEitherAsync(f2, r); |
2800 |
– |
f.complete(one); |
2801 |
– |
checkCompletedWithWrappedCFException(g); |
2802 |
– |
} |
2803 |
– |
|
2804 |
– |
/** |
2805 |
– |
* runAfterEitherAsync result completes exceptionally if action does |
2806 |
– |
*/ |
2807 |
– |
public void testRunAfterEitherAsync3() { |
2808 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2809 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2810 |
– |
FailingNoop r = new FailingNoop(); |
2811 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2812 |
– |
f.complete(one); |
2813 |
– |
checkCompletedWithWrappedCFException(g); |
2814 |
– |
} |
2815 |
– |
|
2816 |
– |
/** |
2817 |
– |
* runAfterEitherAsync result completes exceptionally if either |
2818 |
– |
* source cancelled |
2819 |
– |
*/ |
2820 |
– |
public void testRunAfterEitherAsync4() { |
2821 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2822 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2823 |
– |
Noop r = new Noop(); |
2824 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
2825 |
– |
assertTrue(f.cancel(true)); |
2826 |
– |
checkCompletedWithWrappedCancellationException(g); |
2827 |
– |
|
2828 |
– |
r = new Noop(); |
2829 |
– |
f = new CompletableFuture<>(); |
2830 |
– |
f2 = new CompletableFuture<>(); |
2831 |
– |
assertTrue(f2.cancel(true)); |
2832 |
– |
g = f.runAfterEitherAsync(f2, r); |
2833 |
– |
checkCompletedWithWrappedCancellationException(g); |
2834 |
– |
} |
2835 |
– |
|
2836 |
– |
/** |
2953 |
|
* thenComposeAsync result completes normally after normal |
2954 |
|
* completion of source |
2955 |
|
*/ |
3173 |
|
} |
3174 |
|
|
3175 |
|
/** |
3060 |
– |
* runAfterEitherAsync result completes normally after normal |
3061 |
– |
* completion of sources |
3062 |
– |
*/ |
3063 |
– |
public void testRunAfterEitherAsyncE() { |
3064 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3065 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
3066 |
– |
Noop r = new Noop(); |
3067 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3068 |
– |
f.complete(one); |
3069 |
– |
checkCompletedNormally(g, null); |
3070 |
– |
assertTrue(r.ran); |
3071 |
– |
|
3072 |
– |
r = new Noop(); |
3073 |
– |
f = new CompletableFuture<>(); |
3074 |
– |
f.complete(one); |
3075 |
– |
f2 = new CompletableFuture<>(); |
3076 |
– |
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3077 |
– |
checkCompletedNormally(g, null); |
3078 |
– |
assertTrue(r.ran); |
3079 |
– |
} |
3080 |
– |
|
3081 |
– |
/** |
3082 |
– |
* runAfterEitherAsync result completes exceptionally after exceptional |
3083 |
– |
* completion of source |
3084 |
– |
*/ |
3085 |
– |
public void testRunAfterEitherAsync2E() { |
3086 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3087 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
3088 |
– |
Noop r = new Noop(); |
3089 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3090 |
– |
f.completeExceptionally(new CFException()); |
3091 |
– |
checkCompletedWithWrappedCFException(g); |
3092 |
– |
|
3093 |
– |
r = new Noop(); |
3094 |
– |
f = new CompletableFuture<>(); |
3095 |
– |
f2 = new CompletableFuture<>(); |
3096 |
– |
f2.completeExceptionally(new CFException()); |
3097 |
– |
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3098 |
– |
f.complete(one); |
3099 |
– |
checkCompletedWithWrappedCFException(g); |
3100 |
– |
} |
3101 |
– |
|
3102 |
– |
/** |
3103 |
– |
* runAfterEitherAsync result completes exceptionally if action does |
3104 |
– |
*/ |
3105 |
– |
public void testRunAfterEitherAsync3E() { |
3106 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3107 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
3108 |
– |
FailingNoop r = new FailingNoop(); |
3109 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3110 |
– |
f.complete(one); |
3111 |
– |
checkCompletedWithWrappedCFException(g); |
3112 |
– |
} |
3113 |
– |
|
3114 |
– |
/** |
3115 |
– |
* runAfterEitherAsync result completes exceptionally if either |
3116 |
– |
* source cancelled |
3117 |
– |
*/ |
3118 |
– |
public void testRunAfterEitherAsync4E() { |
3119 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3120 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
3121 |
– |
Noop r = new Noop(); |
3122 |
– |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3123 |
– |
assertTrue(f.cancel(true)); |
3124 |
– |
checkCompletedWithWrappedCancellationException(g); |
3125 |
– |
|
3126 |
– |
r = new Noop(); |
3127 |
– |
f = new CompletableFuture<>(); |
3128 |
– |
f2 = new CompletableFuture<>(); |
3129 |
– |
assertTrue(f2.cancel(true)); |
3130 |
– |
g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
3131 |
– |
checkCompletedWithWrappedCancellationException(g); |
3132 |
– |
} |
3133 |
– |
|
3134 |
– |
/** |
3176 |
|
* thenComposeAsync result completes normally after normal |
3177 |
|
* completion of source |
3178 |
|
*/ |
3416 |
|
* whenComplete action executes on normal completion, propagating |
3417 |
|
* source result. |
3418 |
|
*/ |
3419 |
< |
public void testWhenComplete1() { |
3419 |
> |
public void testWhenComplete_normalCompletion1() { |
3420 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
3421 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
3422 |
> |
|
3423 |
|
final AtomicInteger a = new AtomicInteger(); |
3424 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3425 |
< |
CompletableFuture<Integer> g = |
3426 |
< |
f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement()); |
3427 |
< |
f.complete(three); |
3428 |
< |
checkCompletedNormally(f, three); |
3429 |
< |
checkCompletedNormally(g, three); |
3424 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3425 |
> |
final CompletableFuture<Integer> g = |
3426 |
> |
m.whenComplete(f, |
3427 |
> |
(Integer x, Throwable t) -> { |
3428 |
> |
threadAssertSame(x, v1); |
3429 |
> |
threadAssertNull(t); |
3430 |
> |
a.getAndIncrement(); |
3431 |
> |
}); |
3432 |
> |
f.complete(v1); |
3433 |
> |
checkCompletedNormally(f, v1); |
3434 |
> |
checkCompletedNormally(g, v1); |
3435 |
|
assertEquals(a.get(), 1); |
3436 |
+ |
} |
3437 |
|
} |
3438 |
|
|
3439 |
|
/** |
3440 |
|
* whenComplete action executes on exceptional completion, propagating |
3441 |
|
* source result. |
3442 |
|
*/ |
3443 |
< |
public void testWhenComplete2() { |
3443 |
> |
public void testWhenComplete_exceptionalCompletion() { |
3444 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
3445 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
3446 |
> |
|
3447 |
|
final AtomicInteger a = new AtomicInteger(); |
3448 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3449 |
< |
CompletableFuture<Integer> g = |
3450 |
< |
f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement()); |
3451 |
< |
f.completeExceptionally(new CFException()); |
3452 |
< |
assertTrue(f.isCompletedExceptionally()); |
3453 |
< |
assertTrue(g.isCompletedExceptionally()); |
3448 |
> |
final CFException ex = new CFException(); |
3449 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3450 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
3451 |
> |
(f, |
3452 |
> |
(Integer x, Throwable t) -> { |
3453 |
> |
threadAssertNull(x); |
3454 |
> |
threadAssertSame(t, ex); |
3455 |
> |
a.getAndIncrement(); |
3456 |
> |
}); |
3457 |
> |
f.completeExceptionally(ex); |
3458 |
> |
checkCompletedWithWrappedCFException(f, ex); |
3459 |
> |
checkCompletedWithWrappedCFException(g, ex); |
3460 |
|
assertEquals(a.get(), 1); |
3461 |
+ |
} |
3462 |
|
} |
3463 |
|
|
3464 |
|
/** |
3465 |
|
* If a whenComplete action throws an exception when triggered by |
3466 |
|
* a normal completion, it completes exceptionally |
3467 |
|
*/ |
3468 |
< |
public void testWhenComplete3() { |
3469 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3470 |
< |
CompletableFuture<Integer> g = |
3411 |
< |
f.whenComplete((Integer x, Throwable t) -> |
3412 |
< |
{ throw new CFException(); } ); |
3413 |
< |
f.complete(three); |
3414 |
< |
checkCompletedNormally(f, three); |
3415 |
< |
assertTrue(g.isCompletedExceptionally()); |
3416 |
< |
checkCompletedWithWrappedCFException(g); |
3417 |
< |
} |
3418 |
< |
|
3419 |
< |
/** |
3420 |
< |
* whenCompleteAsync action executes on normal completion, propagating |
3421 |
< |
* source result. |
3422 |
< |
*/ |
3423 |
< |
public void testWhenCompleteAsync1() { |
3424 |
< |
final AtomicInteger a = new AtomicInteger(); |
3425 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3426 |
< |
CompletableFuture<Integer> g = |
3427 |
< |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement()); |
3428 |
< |
f.complete(three); |
3429 |
< |
checkCompletedNormally(f, three); |
3430 |
< |
checkCompletedNormally(g, three); |
3431 |
< |
assertEquals(a.get(), 1); |
3432 |
< |
} |
3433 |
< |
|
3434 |
< |
/** |
3435 |
< |
* whenCompleteAsync action executes on exceptional completion, propagating |
3436 |
< |
* source result. |
3437 |
< |
*/ |
3438 |
< |
public void testWhenCompleteAsync2() { |
3439 |
< |
final AtomicInteger a = new AtomicInteger(); |
3440 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3441 |
< |
CompletableFuture<Integer> g = |
3442 |
< |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement()); |
3443 |
< |
f.completeExceptionally(new CFException()); |
3444 |
< |
checkCompletedWithWrappedCFException(f); |
3445 |
< |
checkCompletedWithWrappedCFException(g); |
3446 |
< |
} |
3447 |
< |
|
3448 |
< |
/** |
3449 |
< |
* If a whenCompleteAsync action throws an exception when |
3450 |
< |
* triggered by a normal completion, it completes exceptionally |
3451 |
< |
*/ |
3452 |
< |
public void testWhenCompleteAsync3() { |
3453 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3454 |
< |
CompletableFuture<Integer> g = |
3455 |
< |
f.whenCompleteAsync((Integer x, Throwable t) -> |
3456 |
< |
{ throw new CFException(); } ); |
3457 |
< |
f.complete(three); |
3458 |
< |
checkCompletedNormally(f, three); |
3459 |
< |
checkCompletedWithWrappedCFException(g); |
3460 |
< |
} |
3468 |
> |
public void testWhenComplete_actionFailed() { |
3469 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
3470 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
3471 |
|
|
3472 |
< |
/** |
3473 |
< |
* whenCompleteAsync action executes on normal completion, propagating |
3474 |
< |
* source result. |
3475 |
< |
*/ |
3476 |
< |
public void testWhenCompleteAsync1e() { |
3477 |
< |
final AtomicInteger a = new AtomicInteger(); |
3478 |
< |
ThreadExecutor exec = new ThreadExecutor(); |
3479 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3480 |
< |
CompletableFuture<Integer> g = |
3481 |
< |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(), |
3482 |
< |
exec); |
3483 |
< |
f.complete(three); |
3484 |
< |
checkCompletedNormally(f, three); |
3475 |
< |
checkCompletedNormally(g, three); |
3476 |
< |
assertEquals(a.get(), 1); |
3472 |
> |
final CFException ex = new CFException(); |
3473 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3474 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
3475 |
> |
(f, |
3476 |
> |
(Integer x, Throwable t) -> { |
3477 |
> |
threadAssertSame(x, v1); |
3478 |
> |
threadAssertNull(t); |
3479 |
> |
throw ex; |
3480 |
> |
}); |
3481 |
> |
f.complete(v1); |
3482 |
> |
checkCompletedNormally(f, v1); |
3483 |
> |
checkCompletedWithWrappedCFException(g, ex); |
3484 |
> |
} |
3485 |
|
} |
3486 |
|
|
3487 |
|
/** |
3488 |
< |
* whenCompleteAsync action executes on exceptional completion, propagating |
3489 |
< |
* source result. |
3488 |
> |
* If a whenComplete action throws an exception when triggered by |
3489 |
> |
* a source completion that also throws an exception, the source |
3490 |
> |
* exception takes precedence. |
3491 |
|
*/ |
3492 |
< |
public void testWhenCompleteAsync2e() { |
3493 |
< |
final AtomicInteger a = new AtomicInteger(); |
3494 |
< |
ThreadExecutor exec = new ThreadExecutor(); |
3486 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3487 |
< |
CompletableFuture<Integer> g = |
3488 |
< |
f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(), |
3489 |
< |
exec); |
3490 |
< |
f.completeExceptionally(new CFException()); |
3491 |
< |
checkCompletedWithWrappedCFException(f); |
3492 |
< |
checkCompletedWithWrappedCFException(g); |
3493 |
< |
} |
3492 |
> |
public void testWhenComplete_actionFailedSourceFailed() { |
3493 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
3494 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
3495 |
|
|
3496 |
< |
/** |
3497 |
< |
* If a whenCompleteAsync action throws an exception when triggered |
3498 |
< |
* by a normal completion, it completes exceptionally |
3499 |
< |
*/ |
3500 |
< |
public void testWhenCompleteAsync3e() { |
3501 |
< |
ThreadExecutor exec = new ThreadExecutor(); |
3502 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3503 |
< |
CompletableFuture<Integer> g = |
3504 |
< |
f.whenCompleteAsync((Integer x, Throwable t) -> |
3505 |
< |
{ throw new CFException(); }, |
3506 |
< |
exec); |
3507 |
< |
f.complete(three); |
3508 |
< |
checkCompletedNormally(f, three); |
3509 |
< |
checkCompletedWithWrappedCFException(g); |
3496 |
> |
final CFException ex1 = new CFException(); |
3497 |
> |
final CFException ex2 = new CFException(); |
3498 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3499 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
3500 |
> |
(f, |
3501 |
> |
(Integer x, Throwable t) -> { |
3502 |
> |
threadAssertSame(t, ex1); |
3503 |
> |
threadAssertNull(x); |
3504 |
> |
throw ex2; |
3505 |
> |
}); |
3506 |
> |
f.completeExceptionally(ex1); |
3507 |
> |
checkCompletedWithWrappedCFException(f, ex1); |
3508 |
> |
checkCompletedWithWrappedCFException(g, ex1); |
3509 |
> |
} |
3510 |
|
} |
3511 |
|
|
3512 |
|
/** |