75 |
|
try { |
76 |
|
f.join(); |
77 |
|
shouldThrow(); |
78 |
< |
} catch (Throwable ex) { |
79 |
< |
assertTrue(ex instanceof CompletionException && |
80 |
< |
((CompletionException)ex).getCause() instanceof CFException); |
78 |
> |
} catch (CompletionException success) { |
79 |
> |
assertTrue(success.getCause() instanceof CFException); |
80 |
|
} |
81 |
|
try { |
82 |
|
f.getNow(null); |
83 |
|
shouldThrow(); |
84 |
< |
} catch (Throwable ex) { |
85 |
< |
assertTrue(ex instanceof CompletionException && |
87 |
< |
((CompletionException)ex).getCause() instanceof CFException); |
84 |
> |
} catch (CompletionException success) { |
85 |
> |
assertTrue(success.getCause() instanceof CFException); |
86 |
|
} |
87 |
|
try { |
88 |
|
f.get(); |
89 |
|
shouldThrow(); |
90 |
< |
} catch (Throwable ex) { |
91 |
< |
assertTrue(ex instanceof ExecutionException && |
92 |
< |
((ExecutionException)ex).getCause() instanceof CFException); |
95 |
< |
} |
90 |
> |
} catch (ExecutionException success) { |
91 |
> |
assertTrue(success.getCause() instanceof CFException); |
92 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
93 |
|
try { |
94 |
|
f.get(0L, SECONDS); |
95 |
|
shouldThrow(); |
96 |
< |
} catch (Throwable ex) { |
97 |
< |
assertTrue(ex instanceof ExecutionException && |
98 |
< |
((ExecutionException)ex).getCause() instanceof CFException); |
102 |
< |
} |
96 |
> |
} catch (ExecutionException success) { |
97 |
> |
assertTrue(success.getCause() instanceof CFException); |
98 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
99 |
|
assertTrue(f.isDone()); |
100 |
|
assertFalse(f.isCancelled()); |
101 |
|
} |
104 |
|
try { |
105 |
|
f.join(); |
106 |
|
shouldThrow(); |
107 |
< |
} catch (Throwable ex) { |
112 |
< |
assertTrue(ex instanceof CancellationException); |
113 |
< |
} |
107 |
> |
} catch (CancellationException success) {} |
108 |
|
try { |
109 |
|
f.getNow(null); |
110 |
|
shouldThrow(); |
111 |
< |
} catch (Throwable ex) { |
118 |
< |
assertTrue(ex instanceof CancellationException); |
119 |
< |
} |
111 |
> |
} catch (CancellationException success) {} |
112 |
|
try { |
113 |
|
f.get(); |
114 |
|
shouldThrow(); |
115 |
< |
} catch (Throwable ex) { |
116 |
< |
assertTrue(ex instanceof CancellationException); |
125 |
< |
} |
115 |
> |
} catch (CancellationException success) { |
116 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
117 |
|
try { |
118 |
|
f.get(0L, SECONDS); |
119 |
|
shouldThrow(); |
120 |
< |
} catch (Throwable ex) { |
121 |
< |
assertTrue(ex instanceof CancellationException); |
131 |
< |
} |
120 |
> |
} catch (CancellationException success) { |
121 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
122 |
|
assertTrue(f.isDone()); |
123 |
|
assertTrue(f.isCancelled()); |
124 |
|
} |
127 |
|
try { |
128 |
|
f.join(); |
129 |
|
shouldThrow(); |
130 |
< |
} catch (Throwable ex) { |
131 |
< |
assertTrue(ex instanceof CompletionException && |
142 |
< |
((CompletionException)ex).getCause() instanceof CancellationException); |
130 |
> |
} catch (CompletionException success) { |
131 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
132 |
|
} |
133 |
|
try { |
134 |
|
f.getNow(null); |
135 |
|
shouldThrow(); |
136 |
< |
} catch (Throwable ex) { |
137 |
< |
assertTrue(ex instanceof CompletionException && |
149 |
< |
((CompletionException)ex).getCause() instanceof CancellationException); |
136 |
> |
} catch (CompletionException success) { |
137 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
138 |
|
} |
139 |
|
try { |
140 |
|
f.get(); |
141 |
|
shouldThrow(); |
142 |
< |
} catch (Throwable ex) { |
143 |
< |
assertTrue(ex instanceof ExecutionException && |
144 |
< |
((ExecutionException)ex).getCause() instanceof CancellationException); |
157 |
< |
} |
142 |
> |
} catch (ExecutionException success) { |
143 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
144 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
145 |
|
try { |
146 |
|
f.get(0L, SECONDS); |
147 |
|
shouldThrow(); |
148 |
< |
} catch (Throwable ex) { |
149 |
< |
assertTrue(ex instanceof ExecutionException && |
150 |
< |
((ExecutionException)ex).getCause() instanceof CancellationException); |
164 |
< |
} |
148 |
> |
} catch (ExecutionException success) { |
149 |
> |
assertTrue(success.getCause() instanceof CancellationException); |
150 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
151 |
|
assertTrue(f.isDone()); |
152 |
|
assertFalse(f.isCancelled()); |
153 |
|
} |
235 |
|
f.obtrudeException(new CFException()); |
236 |
|
checkCompletedWithWrappedCFException(f); |
237 |
|
} |
238 |
< |
|
238 |
> |
|
239 |
|
/** |
240 |
|
* getNumberOfDependents returns number of dependent tasks |
241 |
|
*/ |
271 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
272 |
|
} |
273 |
|
|
274 |
< |
static final Supplier<Integer> supplyOne = |
274 |
> |
/** |
275 |
> |
* completedFuture returns a completed CompletableFuture with given value |
276 |
> |
*/ |
277 |
> |
public void testCompletedFuture() { |
278 |
> |
CompletableFuture<String> f = CompletableFuture.completedFuture("test"); |
279 |
> |
checkCompletedNormally(f, "test"); |
280 |
> |
} |
281 |
> |
|
282 |
> |
static final Supplier<Integer> supplyOne = |
283 |
|
() -> Integer.valueOf(1); |
284 |
< |
static final Function<Integer, Integer> inc = |
284 |
> |
static final Function<Integer, Integer> inc = |
285 |
|
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
286 |
< |
static final BiFunction<Integer, Integer, Integer> add = |
286 |
> |
static final BiFunction<Integer, Integer, Integer> add = |
287 |
|
(Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue()); |
288 |
|
static final class IncAction implements Consumer<Integer> { |
289 |
|
int value; |
291 |
|
} |
292 |
|
static final class AddAction implements BiConsumer<Integer, Integer> { |
293 |
|
int value; |
294 |
< |
public void accept(Integer x, Integer y) { |
295 |
< |
value = x.intValue() + y.intValue(); |
294 |
> |
public void accept(Integer x, Integer y) { |
295 |
> |
value = x.intValue() + y.intValue(); |
296 |
|
} |
297 |
|
} |
298 |
|
static final class Noop implements Runnable { |
339 |
|
ran = true; throw new CFException(); |
340 |
|
} |
341 |
|
} |
342 |
< |
|
342 |
> |
|
343 |
|
// Used for explicit executor tests |
344 |
|
static final class ThreadExecutor implements Executor { |
345 |
|
public void execute(Runnable r) { |
352 |
|
} |
353 |
|
|
354 |
|
static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> { |
355 |
< |
public Integer apply(Integer x, Throwable t) { |
355 |
> |
public Integer apply(Integer x, Throwable t) { |
356 |
|
return (t == null) ? two : three; |
357 |
|
} |
358 |
|
} |
450 |
|
assertTrue(r.ran); |
451 |
|
} |
452 |
|
|
453 |
< |
// seq conmpletion methods |
454 |
< |
|
453 |
> |
// seq completion methods |
454 |
> |
|
455 |
|
/** |
456 |
|
* thenRun result completes normally after normal completion of source |
457 |
|
*/ |
1120 |
|
try { |
1121 |
|
g.join(); |
1122 |
|
shouldThrow(); |
1123 |
< |
} catch(Exception ok) { |
1123 |
> |
} catch (Exception ok) { |
1124 |
|
} |
1125 |
|
checkCompletedWithWrappedCFException(g); |
1126 |
|
} |
1135 |
|
f.complete(null); |
1136 |
|
checkCompletedWithWrappedCFException(g); |
1137 |
|
} |
1138 |
< |
|
1138 |
> |
|
1139 |
|
/** |
1140 |
|
* thenRunAsync result completes exceptionally if source cancelled |
1141 |
|
*/ |
1178 |
|
f.complete(null); |
1179 |
|
checkCompletedWithWrappedCFException(g); |
1180 |
|
} |
1181 |
< |
|
1181 |
> |
|
1182 |
|
/** |
1183 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
1184 |
|
*/ |
1224 |
|
f.complete(null); |
1225 |
|
checkCompletedWithWrappedCFException(g); |
1226 |
|
} |
1227 |
< |
|
1227 |
> |
|
1228 |
|
/** |
1229 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
1230 |
|
*/ |
1282 |
|
f2.complete(two); |
1283 |
|
checkCompletedWithWrappedCFException(g); |
1284 |
|
} |
1285 |
< |
|
1285 |
> |
|
1286 |
|
/** |
1287 |
|
* thenCombineAsync result completes exceptionally if either source cancelled |
1288 |
|
*/ |
1293 |
|
assertTrue(f.cancel(true)); |
1294 |
|
f2.complete(two); |
1295 |
|
checkCompletedWithWrappedCancellationException(g); |
1296 |
< |
|
1296 |
> |
|
1297 |
|
f = new CompletableFuture<Integer>(); |
1298 |
|
f2 = new CompletableFuture<Integer>(); |
1299 |
|
g = f.thenCombineAsync(f2, add); |
1347 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1348 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1349 |
|
FailingBiConsumer r = new FailingBiConsumer(); |
1350 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1350 |
> |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r); |
1351 |
|
f.complete(one); |
1352 |
|
checkIncomplete(g); |
1353 |
|
f2.complete(two); |
1354 |
|
checkCompletedWithWrappedCFException(g); |
1355 |
|
} |
1356 |
< |
|
1356 |
> |
|
1357 |
|
/** |
1358 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1359 |
|
*/ |
1365 |
|
assertTrue(f.cancel(true)); |
1366 |
|
f2.complete(two); |
1367 |
|
checkCompletedWithWrappedCancellationException(g); |
1368 |
< |
|
1368 |
> |
|
1369 |
|
r = new AddAction(); |
1370 |
|
f = new CompletableFuture<Integer>(); |
1371 |
|
f2 = new CompletableFuture<Integer>(); |
1420 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1421 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1422 |
|
FailingNoop r = new FailingNoop(); |
1423 |
< |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1423 |
> |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1424 |
|
f.complete(one); |
1425 |
|
checkIncomplete(g); |
1426 |
|
f2.complete(two); |
1427 |
|
checkCompletedWithWrappedCFException(g); |
1428 |
|
} |
1429 |
< |
|
1429 |
> |
|
1430 |
|
/** |
1431 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
1432 |
|
*/ |
1438 |
|
assertTrue(f.cancel(true)); |
1439 |
|
f2.complete(two); |
1440 |
|
checkCompletedWithWrappedCancellationException(g); |
1441 |
< |
|
1441 |
> |
|
1442 |
|
r = new Noop(); |
1443 |
|
f = new CompletableFuture<Integer>(); |
1444 |
|
f2 = new CompletableFuture<Integer>(); |
1492 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1493 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1494 |
|
FailingFunction r = new FailingFunction(); |
1495 |
< |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r); |
1495 |
> |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r); |
1496 |
|
f.complete(one); |
1497 |
|
checkCompletedWithWrappedCFException(g); |
1498 |
|
} |
1499 |
< |
|
1499 |
> |
|
1500 |
|
/** |
1501 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
1502 |
|
*/ |
1506 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc); |
1507 |
|
assertTrue(f.cancel(true)); |
1508 |
|
checkCompletedWithWrappedCancellationException(g); |
1509 |
< |
|
1509 |
> |
|
1510 |
|
f = new CompletableFuture<Integer>(); |
1511 |
|
f2 = new CompletableFuture<Integer>(); |
1512 |
|
assertTrue(f2.cancel(true)); |
1564 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1565 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1566 |
|
FailingConsumer r = new FailingConsumer(); |
1567 |
< |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1567 |
> |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1568 |
|
f.complete(one); |
1569 |
|
checkCompletedWithWrappedCFException(g); |
1570 |
|
} |
1571 |
< |
|
1571 |
> |
|
1572 |
|
/** |
1573 |
|
* acceptEitherAsync result completes exceptionally if either |
1574 |
|
* source cancelled |
1580 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r); |
1581 |
|
assertTrue(f.cancel(true)); |
1582 |
|
checkCompletedWithWrappedCancellationException(g); |
1583 |
< |
|
1583 |
> |
|
1584 |
|
r = new IncAction(); |
1585 |
|
f = new CompletableFuture<Integer>(); |
1586 |
|
f2 = new CompletableFuture<Integer>(); |
1639 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1640 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1641 |
|
FailingNoop r = new FailingNoop(); |
1642 |
< |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1642 |
> |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1643 |
|
f.complete(one); |
1644 |
|
checkCompletedWithWrappedCFException(g); |
1645 |
|
} |
1646 |
< |
|
1646 |
> |
|
1647 |
|
/** |
1648 |
|
* runAfterEitherAsync result completes exceptionally if either |
1649 |
|
* source cancelled |
1655 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r); |
1656 |
|
assertTrue(f.cancel(true)); |
1657 |
|
checkCompletedWithWrappedCancellationException(g); |
1658 |
< |
|
1658 |
> |
|
1659 |
|
r = new Noop(); |
1660 |
|
f = new CompletableFuture<Integer>(); |
1661 |
|
f2 = new CompletableFuture<Integer>(); |
1665 |
|
} |
1666 |
|
|
1667 |
|
/** |
1668 |
< |
* thenCompse result completes normally after normal completion of source |
1668 |
> |
* thenComposeAsync result completes normally after normal |
1669 |
> |
* completion of source |
1670 |
|
*/ |
1671 |
|
public void testThenComposeAsync() { |
1672 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1677 |
|
} |
1678 |
|
|
1679 |
|
/** |
1680 |
< |
* thenComposeAsync result completes exceptionally after exceptional |
1681 |
< |
* completion of source |
1680 |
> |
* thenComposeAsync result completes exceptionally after |
1681 |
> |
* exceptional completion of source |
1682 |
|
*/ |
1683 |
|
public void testThenComposeAsync2() { |
1684 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1711 |
|
} |
1712 |
|
|
1713 |
|
|
1714 |
< |
// aaync with explicit executors |
1714 |
> |
// async with explicit executors |
1715 |
|
|
1716 |
|
/** |
1717 |
|
* thenRunAsync result completes normally after normal completion of source |
1743 |
|
try { |
1744 |
|
g.join(); |
1745 |
|
shouldThrow(); |
1746 |
< |
} catch(Exception ok) { |
1746 |
> |
} catch (Exception ok) { |
1747 |
|
} |
1748 |
|
checkCompletedWithWrappedCFException(g); |
1749 |
|
} |
1758 |
|
f.complete(null); |
1759 |
|
checkCompletedWithWrappedCFException(g); |
1760 |
|
} |
1761 |
< |
|
1761 |
> |
|
1762 |
|
/** |
1763 |
|
* thenRunAsync result completes exceptionally if source cancelled |
1764 |
|
*/ |
1801 |
|
f.complete(null); |
1802 |
|
checkCompletedWithWrappedCFException(g); |
1803 |
|
} |
1804 |
< |
|
1804 |
> |
|
1805 |
|
/** |
1806 |
|
* thenApplyAsync result completes exceptionally if source cancelled |
1807 |
|
*/ |
1847 |
|
f.complete(null); |
1848 |
|
checkCompletedWithWrappedCFException(g); |
1849 |
|
} |
1850 |
< |
|
1850 |
> |
|
1851 |
|
/** |
1852 |
|
* thenAcceptAsync result completes exceptionally if source cancelled |
1853 |
|
*/ |
1905 |
|
f2.complete(two); |
1906 |
|
checkCompletedWithWrappedCFException(g); |
1907 |
|
} |
1908 |
< |
|
1908 |
> |
|
1909 |
|
/** |
1910 |
|
* thenCombineAsync result completes exceptionally if either source cancelled |
1911 |
|
*/ |
1916 |
|
assertTrue(f.cancel(true)); |
1917 |
|
f2.complete(two); |
1918 |
|
checkCompletedWithWrappedCancellationException(g); |
1919 |
< |
|
1919 |
> |
|
1920 |
|
f = new CompletableFuture<Integer>(); |
1921 |
|
f2 = new CompletableFuture<Integer>(); |
1922 |
|
g = f.thenCombineAsync(f2, add, new ThreadExecutor()); |
1970 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
1971 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
1972 |
|
FailingBiConsumer r = new FailingBiConsumer(); |
1973 |
< |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
1973 |
> |
CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); |
1974 |
|
f.complete(one); |
1975 |
|
checkIncomplete(g); |
1976 |
|
f2.complete(two); |
1977 |
|
checkCompletedWithWrappedCFException(g); |
1978 |
|
} |
1979 |
< |
|
1979 |
> |
|
1980 |
|
/** |
1981 |
|
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1982 |
|
*/ |
1988 |
|
assertTrue(f.cancel(true)); |
1989 |
|
f2.complete(two); |
1990 |
|
checkCompletedWithWrappedCancellationException(g); |
1991 |
< |
|
1991 |
> |
|
1992 |
|
r = new AddAction(); |
1993 |
|
f = new CompletableFuture<Integer>(); |
1994 |
|
f2 = new CompletableFuture<Integer>(); |
2043 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2044 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2045 |
|
FailingNoop r = new FailingNoop(); |
2046 |
< |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2046 |
> |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2047 |
|
f.complete(one); |
2048 |
|
checkIncomplete(g); |
2049 |
|
f2.complete(two); |
2050 |
|
checkCompletedWithWrappedCFException(g); |
2051 |
|
} |
2052 |
< |
|
2052 |
> |
|
2053 |
|
/** |
2054 |
|
* runAfterBothAsync result completes exceptionally if either source cancelled |
2055 |
|
*/ |
2061 |
|
assertTrue(f.cancel(true)); |
2062 |
|
f2.complete(two); |
2063 |
|
checkCompletedWithWrappedCancellationException(g); |
2064 |
< |
|
2064 |
> |
|
2065 |
|
r = new Noop(); |
2066 |
|
f = new CompletableFuture<Integer>(); |
2067 |
|
f2 = new CompletableFuture<Integer>(); |
2115 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2116 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2117 |
|
FailingFunction r = new FailingFunction(); |
2118 |
< |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); |
2118 |
> |
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); |
2119 |
|
f.complete(one); |
2120 |
|
checkCompletedWithWrappedCFException(g); |
2121 |
|
} |
2122 |
< |
|
2122 |
> |
|
2123 |
|
/** |
2124 |
|
* applyToEitherAsync result completes exceptionally if either source cancelled |
2125 |
|
*/ |
2129 |
|
CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); |
2130 |
|
assertTrue(f.cancel(true)); |
2131 |
|
checkCompletedWithWrappedCancellationException(g); |
2132 |
< |
|
2132 |
> |
|
2133 |
|
f = new CompletableFuture<Integer>(); |
2134 |
|
f2 = new CompletableFuture<Integer>(); |
2135 |
|
assertTrue(f2.cancel(true)); |
2187 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2188 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2189 |
|
FailingConsumer r = new FailingConsumer(); |
2190 |
< |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2190 |
> |
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2191 |
|
f.complete(one); |
2192 |
|
checkCompletedWithWrappedCFException(g); |
2193 |
|
} |
2194 |
< |
|
2194 |
> |
|
2195 |
|
/** |
2196 |
|
* acceptEitherAsync result completes exceptionally if either |
2197 |
|
* source cancelled |
2203 |
|
CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); |
2204 |
|
assertTrue(f.cancel(true)); |
2205 |
|
checkCompletedWithWrappedCancellationException(g); |
2206 |
< |
|
2206 |
> |
|
2207 |
|
r = new IncAction(); |
2208 |
|
f = new CompletableFuture<Integer>(); |
2209 |
|
f2 = new CompletableFuture<Integer>(); |
2262 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2263 |
|
CompletableFuture<Integer> f2 = new CompletableFuture<Integer>(); |
2264 |
|
FailingNoop r = new FailingNoop(); |
2265 |
< |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2265 |
> |
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2266 |
|
f.complete(one); |
2267 |
|
checkCompletedWithWrappedCFException(g); |
2268 |
|
} |
2269 |
< |
|
2269 |
> |
|
2270 |
|
/** |
2271 |
|
* runAfterEitherAsync result completes exceptionally if either |
2272 |
|
* source cancelled |
2278 |
|
CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); |
2279 |
|
assertTrue(f.cancel(true)); |
2280 |
|
checkCompletedWithWrappedCancellationException(g); |
2281 |
< |
|
2281 |
> |
|
2282 |
|
r = new Noop(); |
2283 |
|
f = new CompletableFuture<Integer>(); |
2284 |
|
f2 = new CompletableFuture<Integer>(); |
2288 |
|
} |
2289 |
|
|
2290 |
|
/** |
2291 |
< |
* thenCompse result completes normally after normal completion of source |
2291 |
> |
* thenComposeAsync result completes normally after normal |
2292 |
> |
* completion of source |
2293 |
|
*/ |
2294 |
|
public void testThenComposeAsyncE() { |
2295 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2300 |
|
} |
2301 |
|
|
2302 |
|
/** |
2303 |
< |
* thenComposeAsync result completes exceptionally after exceptional |
2304 |
< |
* completion of source |
2303 |
> |
* thenComposeAsync result completes exceptionally after |
2304 |
> |
* exceptional completion of source |
2305 |
|
*/ |
2306 |
|
public void testThenComposeAsync2E() { |
2307 |
|
CompletableFuture<Integer> f = new CompletableFuture<Integer>(); |
2333 |
|
checkCompletedWithWrappedCancellationException(g); |
2334 |
|
} |
2335 |
|
|
2336 |
< |
// other static methods |
2336 |
> |
// other static methods |
2337 |
|
|
2338 |
|
/** |
2339 |
|
* allOf(no component futures) returns a future completed normally |
2350 |
|
public void testAllOf() throws Exception { |
2351 |
|
for (int k = 1; k < 20; ++k) { |
2352 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
2353 |
< |
for (int i = 0; i < k; ++i) |
2353 |
> |
for (int i = 0; i < k; ++i) |
2354 |
|
fs[i] = new CompletableFuture<Integer>(); |
2355 |
< |
CompletableFuture<?> f = CompletableFuture.allOf(fs); |
2355 |
> |
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
2356 |
|
for (int i = 0; i < k; ++i) { |
2357 |
|
checkIncomplete(f); |
2358 |
|
fs[i].complete(one); |
2359 |
|
} |
2360 |
< |
assertTrue(f.isDone()); |
2365 |
< |
assertFalse(f.isCancelled()); |
2360 |
> |
checkCompletedNormally(f, null); |
2361 |
|
} |
2362 |
|
} |
2363 |
|
|
2375 |
|
public void testAnyOf() throws Exception { |
2376 |
|
for (int k = 1; k < 20; ++k) { |
2377 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
2378 |
< |
for (int i = 0; i < k; ++i) |
2378 |
> |
for (int i = 0; i < k; ++i) |
2379 |
|
fs[i] = new CompletableFuture<Integer>(); |
2380 |
< |
CompletableFuture<?> f = CompletableFuture.anyOf(fs); |
2380 |
> |
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
2381 |
|
checkIncomplete(f); |
2382 |
|
for (int i = 0; i < k; ++i) { |
2383 |
|
fs[i].complete(one); |
2384 |
< |
assertTrue(f.isDone()); |
2384 |
> |
checkCompletedNormally(f, one); |
2385 |
|
} |
2386 |
|
} |
2387 |
|
} |