227 |
|
* isCancelled, join, get, and getNow |
228 |
|
*/ |
229 |
|
public void testComplete() { |
230 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
231 |
+ |
{ |
232 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
233 |
|
checkIncomplete(f); |
234 |
< |
f.complete(one); |
235 |
< |
checkCompletedNormally(f, one); |
236 |
< |
} |
234 |
> |
assertTrue(f.complete(v1)); |
235 |
> |
assertFalse(f.complete(v1)); |
236 |
> |
checkCompletedNormally(f, v1); |
237 |
> |
}} |
238 |
|
|
239 |
|
/** |
240 |
|
* completeExceptionally completes exceptionally, as indicated by |
253 |
|
* methods isDone, isCancelled, join, get, and getNow |
254 |
|
*/ |
255 |
|
public void testCancel() { |
256 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
257 |
+ |
{ |
258 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
259 |
|
checkIncomplete(f); |
260 |
|
assertTrue(f.cancel(true)); |
261 |
+ |
assertTrue(f.cancel(true)); |
262 |
|
checkCancelled(f); |
263 |
< |
} |
263 |
> |
}} |
264 |
|
|
265 |
|
/** |
266 |
|
* obtrudeValue forces completion with given value |
268 |
|
public void testObtrudeValue() { |
269 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
270 |
|
checkIncomplete(f); |
271 |
< |
f.complete(one); |
271 |
> |
assertTrue(f.complete(one)); |
272 |
|
checkCompletedNormally(f, one); |
273 |
|
f.obtrudeValue(three); |
274 |
|
checkCompletedNormally(f, three); |
295 |
|
CompletableFuture<Integer> f; |
296 |
|
|
297 |
|
f = new CompletableFuture<>(); |
298 |
< |
f.complete(v1); |
298 |
> |
assertTrue(f.complete(v1)); |
299 |
|
for (int i = 0; i < 2; i++) { |
300 |
|
f.obtrudeException(ex = new CFException()); |
301 |
|
checkCompletedExceptionally(f, ex); |
315 |
|
checkCompletedExceptionally(f, ex); |
316 |
|
f.completeExceptionally(new CFException()); |
317 |
|
checkCompletedExceptionally(f, ex); |
318 |
< |
f.complete(v1); |
318 |
> |
assertFalse(f.complete(v1)); |
319 |
|
checkCompletedExceptionally(f, ex); |
320 |
|
}} |
321 |
|
|
324 |
|
*/ |
325 |
|
public void testGetNumberOfDependents() { |
326 |
|
for (ExecutionMode m : ExecutionMode.values()) |
327 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
328 |
|
{ |
329 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
330 |
|
assertEquals(0, f.getNumberOfDependents()); |
334 |
|
final CompletableFuture<Void> h = m.thenRun(f, new Noop(m)); |
335 |
|
assertEquals(2, f.getNumberOfDependents()); |
336 |
|
assertEquals(0, h.getNumberOfDependents()); |
337 |
< |
f.complete(1); |
337 |
> |
assertTrue(f.complete(v1)); |
338 |
|
checkCompletedNormally(g, null); |
339 |
|
checkCompletedNormally(h, null); |
340 |
|
assertEquals(0, f.getNumberOfDependents()); |
351 |
|
f = new CompletableFuture<String>(); |
352 |
|
assertTrue(f.toString().contains("[Not completed]")); |
353 |
|
|
354 |
< |
f.complete("foo"); |
354 |
> |
assertTrue(f.complete("foo")); |
355 |
|
assertTrue(f.toString().contains("[Completed normally]")); |
356 |
|
|
357 |
|
f = new CompletableFuture<String>(); |
358 |
< |
f.completeExceptionally(new IndexOutOfBoundsException()); |
358 |
> |
assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); |
359 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
360 |
|
|
361 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
362 |
|
f = new CompletableFuture<String>(); |
363 |
< |
f.cancel(mayInterruptIfRunning); |
363 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
364 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
365 |
|
} |
366 |
|
} |
539 |
|
invoked(); |
540 |
|
value = x; |
541 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
542 |
< |
f.complete(inc(x)); |
542 |
> |
assertTrue(f.complete(inc(x))); |
543 |
|
return f; |
544 |
|
} |
545 |
|
} |
847 |
|
{ |
848 |
|
final AtomicInteger a = new AtomicInteger(0); |
849 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
850 |
< |
if (!createIncomplete) f.complete(v1); |
850 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
851 |
|
final CompletableFuture<Integer> g = f.exceptionally |
852 |
|
((Throwable t) -> { |
853 |
|
// Should not be called |
854 |
|
a.getAndIncrement(); |
855 |
|
throw new AssertionError(); |
856 |
|
}); |
857 |
< |
if (createIncomplete) f.complete(v1); |
857 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
858 |
|
|
859 |
|
checkCompletedNormally(g, v1); |
860 |
|
checkCompletedNormally(f, v1); |
919 |
|
{ |
920 |
|
final AtomicInteger a = new AtomicInteger(0); |
921 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
922 |
< |
if (!createIncomplete) f.complete(v1); |
922 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
923 |
|
final CompletableFuture<Integer> g = m.whenComplete |
924 |
|
(f, |
925 |
|
(Integer x, Throwable t) -> { |
928 |
|
threadAssertNull(t); |
929 |
|
a.getAndIncrement(); |
930 |
|
}); |
931 |
< |
if (createIncomplete) f.complete(v1); |
931 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
932 |
|
|
933 |
|
checkCompletedNormally(g, v1); |
934 |
|
checkCompletedNormally(f, v1); |
1002 |
|
final AtomicInteger a = new AtomicInteger(0); |
1003 |
|
final CFException ex = new CFException(); |
1004 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1005 |
< |
if (!createIncomplete) f.complete(v1); |
1005 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1006 |
|
final CompletableFuture<Integer> g = m.whenComplete |
1007 |
|
(f, |
1008 |
|
(Integer x, Throwable t) -> { |
1012 |
|
a.getAndIncrement(); |
1013 |
|
throw ex; |
1014 |
|
}); |
1015 |
< |
if (createIncomplete) f.complete(v1); |
1015 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
1016 |
|
|
1017 |
|
checkCompletedWithWrappedException(g, ex); |
1018 |
|
checkCompletedNormally(f, v1); |
1062 |
|
{ |
1063 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1064 |
|
final AtomicInteger a = new AtomicInteger(0); |
1065 |
< |
if (!createIncomplete) f.complete(v1); |
1065 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1066 |
|
final CompletableFuture<Integer> g = m.handle |
1067 |
|
(f, |
1068 |
|
(Integer x, Throwable t) -> { |
1072 |
|
a.getAndIncrement(); |
1073 |
|
return inc(v1); |
1074 |
|
}); |
1075 |
< |
if (createIncomplete) f.complete(v1); |
1075 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
1076 |
|
|
1077 |
|
checkCompletedNormally(g, inc(v1)); |
1078 |
|
checkCompletedNormally(f, v1); |
1173 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1174 |
|
final AtomicInteger a = new AtomicInteger(0); |
1175 |
|
final CFException ex = new CFException(); |
1176 |
< |
if (!createIncomplete) f.complete(v1); |
1176 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1177 |
|
final CompletableFuture<Integer> g = m.handle |
1178 |
|
(f, |
1179 |
|
(Integer x, Throwable t) -> { |
1183 |
|
a.getAndIncrement(); |
1184 |
|
throw ex; |
1185 |
|
}); |
1186 |
< |
if (createIncomplete) f.complete(v1); |
1186 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
1187 |
|
|
1188 |
|
checkCompletedWithWrappedException(g, ex); |
1189 |
|
checkCompletedNormally(f, v1); |
1269 |
|
{ |
1270 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1271 |
|
final Noop r = new Noop(m); |
1272 |
< |
if (!createIncomplete) f.complete(v1); |
1272 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1273 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1274 |
|
if (createIncomplete) { |
1275 |
|
checkIncomplete(g); |
1276 |
< |
f.complete(v1); |
1276 |
> |
assertTrue(f.complete(v1)); |
1277 |
|
} |
1278 |
|
|
1279 |
|
checkCompletedNormally(g, null); |
1336 |
|
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final FailingRunnable r = new FailingRunnable(m); |
1339 |
< |
if (!createIncomplete) f.complete(v1); |
1339 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1340 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1341 |
|
if (createIncomplete) { |
1342 |
|
checkIncomplete(g); |
1343 |
< |
f.complete(v1); |
1343 |
> |
assertTrue(f.complete(v1)); |
1344 |
|
} |
1345 |
|
|
1346 |
|
checkCompletedWithWrappedCFException(g); |
1357 |
|
{ |
1358 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1359 |
|
final IncFunction r = new IncFunction(m); |
1360 |
< |
if (!createIncomplete) f.complete(v1); |
1360 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1361 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1362 |
|
if (createIncomplete) { |
1363 |
|
checkIncomplete(g); |
1364 |
< |
f.complete(v1); |
1364 |
> |
assertTrue(f.complete(v1)); |
1365 |
|
} |
1366 |
|
|
1367 |
|
checkCompletedNormally(g, inc(v1)); |
1424 |
|
{ |
1425 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1426 |
|
final FailingFunction r = new FailingFunction(m); |
1427 |
< |
if (!createIncomplete) f.complete(v1); |
1427 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1428 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1429 |
|
if (createIncomplete) { |
1430 |
|
checkIncomplete(g); |
1431 |
< |
f.complete(v1); |
1431 |
> |
assertTrue(f.complete(v1)); |
1432 |
|
} |
1433 |
|
|
1434 |
|
checkCompletedWithWrappedCFException(g); |
1445 |
|
{ |
1446 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1447 |
|
final NoopConsumer r = new NoopConsumer(m); |
1448 |
< |
if (!createIncomplete) f.complete(v1); |
1448 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1449 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1450 |
|
if (createIncomplete) { |
1451 |
|
checkIncomplete(g); |
1452 |
< |
f.complete(v1); |
1452 |
> |
assertTrue(f.complete(v1)); |
1453 |
|
} |
1454 |
|
|
1455 |
|
checkCompletedNormally(g, null); |
1538 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1539 |
|
final SubtractFunction r = new SubtractFunction(m); |
1540 |
|
|
1541 |
< |
if (fFirst) f.complete(v1); else g.complete(v2); |
1541 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1542 |
|
if (!createIncomplete) |
1543 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1543 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1544 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1545 |
|
if (createIncomplete) { |
1546 |
|
checkIncomplete(h); |
1547 |
|
r.assertNotInvoked(); |
1548 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1548 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1549 |
|
} |
1550 |
|
|
1551 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1569 |
|
final CFException ex = new CFException(); |
1570 |
|
final SubtractFunction r = new SubtractFunction(m); |
1571 |
|
|
1572 |
< |
(fFirst ? f : g).complete(v1); |
1572 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1573 |
|
if (!createIncomplete) |
1574 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1574 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1575 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1576 |
|
if (createIncomplete) { |
1577 |
|
checkIncomplete(h); |
1578 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1578 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1579 |
|
} |
1580 |
|
|
1581 |
|
checkCompletedWithWrappedException(h, ex); |
1598 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1599 |
|
final SubtractFunction r = new SubtractFunction(m); |
1600 |
|
|
1601 |
< |
(fFirst ? f : g).complete(v1); |
1601 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1602 |
|
if (!createIncomplete) |
1603 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1604 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1627 |
|
final FailingBiFunction r = new FailingBiFunction(m); |
1628 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1629 |
|
|
1630 |
< |
if (fFirst) { |
1631 |
< |
f.complete(v1); |
1625 |
< |
g.complete(v2); |
1626 |
< |
} else { |
1627 |
< |
g.complete(v2); |
1628 |
< |
f.complete(v1); |
1629 |
< |
} |
1630 |
> |
assertTrue( fFirst ? f.complete(v1) : g.complete(v2)); |
1631 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1632 |
|
|
1633 |
|
checkCompletedWithWrappedCFException(h); |
1634 |
|
checkCompletedNormally(f, v1); |
1650 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1651 |
|
final SubtractAction r = new SubtractAction(m); |
1652 |
|
|
1653 |
< |
if (fFirst) f.complete(v1); else g.complete(v2); |
1653 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1654 |
|
if (!createIncomplete) |
1655 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1655 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1656 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1657 |
|
if (createIncomplete) { |
1658 |
|
checkIncomplete(h); |
1659 |
|
r.assertNotInvoked(); |
1660 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1660 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1661 |
|
} |
1662 |
|
|
1663 |
|
checkCompletedNormally(h, null); |
1681 |
|
final CFException ex = new CFException(); |
1682 |
|
final SubtractAction r = new SubtractAction(m); |
1683 |
|
|
1684 |
< |
(fFirst ? f : g).complete(v1); |
1684 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1685 |
|
if (!createIncomplete) |
1686 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1686 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1687 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1688 |
|
if (createIncomplete) { |
1689 |
|
checkIncomplete(h); |
1690 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1690 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1691 |
|
} |
1692 |
|
|
1693 |
|
checkCompletedWithWrappedException(h, ex); |
1710 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
|
final SubtractAction r = new SubtractAction(m); |
1712 |
|
|
1713 |
< |
(fFirst ? f : g).complete(v1); |
1713 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1714 |
|
if (!createIncomplete) |
1715 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1716 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1739 |
|
final FailingBiConsumer r = new FailingBiConsumer(m); |
1740 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1741 |
|
|
1742 |
< |
if (fFirst) { |
1743 |
< |
f.complete(v1); |
1742 |
< |
g.complete(v2); |
1743 |
< |
} else { |
1744 |
< |
g.complete(v2); |
1745 |
< |
f.complete(v1); |
1746 |
< |
} |
1742 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1743 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1744 |
|
|
1745 |
|
checkCompletedWithWrappedCFException(h); |
1746 |
|
checkCompletedNormally(f, v1); |
1762 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1763 |
|
final Noop r = new Noop(m); |
1764 |
|
|
1765 |
< |
if (fFirst) f.complete(v1); else g.complete(v2); |
1765 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1766 |
|
if (!createIncomplete) |
1767 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1767 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1768 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1769 |
|
if (createIncomplete) { |
1770 |
|
checkIncomplete(h); |
1771 |
|
r.assertNotInvoked(); |
1772 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1772 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1773 |
|
} |
1774 |
|
|
1775 |
|
checkCompletedNormally(h, null); |
1793 |
|
final CFException ex = new CFException(); |
1794 |
|
final Noop r = new Noop(m); |
1795 |
|
|
1796 |
< |
(fFirst ? f : g).complete(v1); |
1796 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1797 |
|
if (!createIncomplete) |
1798 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1798 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1799 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1800 |
|
if (createIncomplete) { |
1801 |
|
checkIncomplete(h); |
1802 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1802 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1803 |
|
} |
1804 |
|
|
1805 |
|
checkCompletedWithWrappedException(h, ex); |
1822 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1823 |
|
final Noop r = new Noop(m); |
1824 |
|
|
1825 |
< |
(fFirst ? f : g).complete(v1); |
1825 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1826 |
|
if (!createIncomplete) |
1827 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1828 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1852 |
|
final FailingRunnable r2 = new FailingRunnable(m); |
1853 |
|
|
1854 |
|
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
1855 |
< |
if (fFirst) { |
1856 |
< |
f.complete(v1); |
1860 |
< |
g.complete(v2); |
1861 |
< |
} else { |
1862 |
< |
g.complete(v2); |
1863 |
< |
f.complete(v1); |
1864 |
< |
} |
1855 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1856 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1857 |
|
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
1858 |
|
|
1859 |
|
checkCompletedWithWrappedCFException(h1); |
1980 |
|
|
1981 |
|
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1982 |
|
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1983 |
< |
if (fFirst) { |
1984 |
< |
f.complete(v1); |
1993 |
< |
g.completeExceptionally(ex); |
1994 |
< |
} else { |
1995 |
< |
g.completeExceptionally(ex); |
1996 |
< |
f.complete(v1); |
1997 |
< |
} |
1983 |
> |
assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
1984 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
1985 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1986 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1987 |
|
|
2087 |
|
|
2088 |
|
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
2089 |
|
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
2090 |
< |
if (fFirst) { |
2091 |
< |
f.complete(v1); |
2105 |
< |
g.cancel(mayInterruptIfRunning); |
2106 |
< |
} else { |
2107 |
< |
g.cancel(mayInterruptIfRunning); |
2108 |
< |
f.complete(v1); |
2109 |
< |
} |
2090 |
> |
assertTrue(fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning)); |
2091 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning)); |
2092 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
2093 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
2094 |
|
|
2290 |
|
|
2291 |
|
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2292 |
|
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2293 |
< |
if (fFirst) { |
2294 |
< |
f.complete(v1); |
2313 |
< |
g.completeExceptionally(ex); |
2314 |
< |
} else { |
2315 |
< |
g.completeExceptionally(ex); |
2316 |
< |
f.complete(v1); |
2317 |
< |
} |
2293 |
> |
assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2294 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2295 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2296 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2297 |
|
|
2494 |
|
checkIncomplete(h1); |
2495 |
|
rs[0].assertNotInvoked(); |
2496 |
|
rs[1].assertNotInvoked(); |
2497 |
< |
f.completeExceptionally(ex); |
2497 |
> |
assertTrue(f.completeExceptionally(ex)); |
2498 |
|
checkCompletedWithWrappedException(h0, ex); |
2499 |
|
checkCompletedWithWrappedException(h1, ex); |
2500 |
|
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2502 |
|
checkCompletedWithWrappedException(h2, ex); |
2503 |
|
checkCompletedWithWrappedException(h3, ex); |
2504 |
|
|
2505 |
< |
g.complete(v1); |
2505 |
> |
assertTrue(g.complete(v1)); |
2506 |
|
|
2507 |
|
// unspecified behavior - both source completions available |
2508 |
|
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2545 |
|
|
2546 |
|
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2547 |
|
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2548 |
< |
if (fFirst) { |
2549 |
< |
f.complete(v1); |
2573 |
< |
g.completeExceptionally(ex); |
2574 |
< |
} else { |
2575 |
< |
g.completeExceptionally(ex); |
2576 |
< |
f.complete(v1); |
2577 |
< |
} |
2548 |
> |
assertTrue( fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2549 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2550 |
|
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2551 |
|
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2552 |
|
|
2611 |
|
checkCompletedWithWrappedCancellationException(h2); |
2612 |
|
checkCompletedWithWrappedCancellationException(h3); |
2613 |
|
|
2614 |
< |
g.complete(v1); |
2614 |
> |
assertTrue(g.complete(v1)); |
2615 |
|
|
2616 |
|
// unspecified behavior - both source completions available |
2617 |
|
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2655 |
|
|
2656 |
|
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2657 |
|
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2658 |
< |
f.complete(v1); |
2658 |
> |
assertTrue(f.complete(v1)); |
2659 |
|
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2660 |
|
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2661 |
|
checkCompletedWithWrappedCFException(h0); |
2663 |
|
checkCompletedWithWrappedCFException(h2); |
2664 |
|
checkCompletedWithWrappedCFException(h3); |
2665 |
|
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2666 |
< |
g.complete(v2); |
2666 |
> |
assertTrue(g.complete(v2)); |
2667 |
|
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2668 |
|
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2669 |
|
checkCompletedWithWrappedCFException(h4); |
2684 |
|
{ |
2685 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2686 |
|
final CompletableFutureInc r = new CompletableFutureInc(m); |
2687 |
< |
if (!createIncomplete) f.complete(v1); |
2687 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
2688 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2689 |
< |
if (createIncomplete) f.complete(v1); |
2689 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
2690 |
|
|
2691 |
|
checkCompletedNormally(g, inc(v1)); |
2692 |
|
checkCompletedNormally(f, v1); |
2724 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2725 |
|
final FailingCompletableFutureFunction r |
2726 |
|
= new FailingCompletableFutureFunction(m); |
2727 |
< |
if (!createIncomplete) f.complete(v1); |
2727 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
2728 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2729 |
< |
if (createIncomplete) f.complete(v1); |
2729 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
2730 |
|
|
2731 |
|
checkCompletedWithWrappedCFException(g); |
2732 |
|
checkCompletedNormally(f, v1); |
2965 |
|
assertSame(f, f.toCompletableFuture()); |
2966 |
|
} |
2967 |
|
|
2968 |
+ |
// public void testRunAfterEither_resultDeterminedAtTimeOfCreation() { |
2969 |
+ |
// for (ExecutionMode m : ExecutionMode.values()) |
2970 |
+ |
// for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2971 |
+ |
// for (Integer v1 : new Integer[] { 1, null }) |
2972 |
+ |
// { |
2973 |
+ |
// final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2974 |
+ |
// final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2975 |
+ |
// final Noop[] rs = new Noop[2]; |
2976 |
+ |
// for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2977 |
+ |
// f.complete(v1); |
2978 |
+ |
// final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2979 |
+ |
// final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2980 |
+ |
// assertTrue(g.cancel(mayInterruptIfRunning)); |
2981 |
+ |
// checkCompletedNormally(h0, null); |
2982 |
+ |
// checkCompletedNormally(h1, null); |
2983 |
+ |
// for (Noop r : rs) r.assertInvoked(); |
2984 |
+ |
// }} |
2985 |
+ |
|
2986 |
|
} |