105 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
106 |
|
} |
107 |
|
|
108 |
< |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
109 |
< |
CFException ex) { |
108 |
> |
<U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f, |
109 |
> |
Throwable ex) { |
110 |
|
try { |
111 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
112 |
|
shouldThrow(); |
131 |
|
} catch (ExecutionException success) { |
132 |
|
assertSame(ex, success.getCause()); |
133 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
134 |
+ |
|
135 |
|
assertTrue(f.isDone()); |
136 |
|
assertFalse(f.isCancelled()); |
137 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
138 |
|
} |
139 |
|
|
140 |
+ |
<U> void checkCompletedWithWrappedException(CompletableFuture<U> f, |
141 |
+ |
Throwable ex) { |
142 |
+ |
checkCompletedExceptionallyWithRootCause(f, ex); |
143 |
+ |
try { |
144 |
+ |
CompletableFuture<Throwable> spy = f.handle |
145 |
+ |
((U u, Throwable t) -> t); |
146 |
+ |
assertTrue(spy.join() instanceof CompletionException); |
147 |
+ |
assertSame(ex, spy.join().getCause()); |
148 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
<U> void checkCompletedExceptionally(CompletableFuture<U> f, Throwable ex) { |
152 |
+ |
checkCompletedExceptionallyWithRootCause(f, ex); |
153 |
+ |
try { |
154 |
+ |
CompletableFuture<Throwable> spy = f.handle |
155 |
+ |
((U u, Throwable t) -> t); |
156 |
+ |
assertSame(ex, spy.join()); |
157 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
158 |
+ |
} |
159 |
+ |
|
160 |
|
void checkCancelled(CompletableFuture<?> f) { |
161 |
|
try { |
162 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
239 |
|
*/ |
240 |
|
public void testCompleteExceptionally() { |
241 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
242 |
+ |
CFException ex = new CFException(); |
243 |
|
checkIncomplete(f); |
244 |
< |
f.completeExceptionally(new CFException()); |
245 |
< |
checkCompletedWithWrappedCFException(f); |
244 |
> |
f.completeExceptionally(ex); |
245 |
> |
checkCompletedExceptionally(f, ex); |
246 |
|
} |
247 |
|
|
248 |
|
/** |
283 |
|
* obtrudeException forces completion with given exception |
284 |
|
*/ |
285 |
|
public void testObtrudeException() { |
286 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
287 |
< |
checkIncomplete(f); |
288 |
< |
f.complete(one); |
289 |
< |
checkCompletedNormally(f, one); |
290 |
< |
f.obtrudeException(new CFException()); |
269 |
< |
checkCompletedWithWrappedCFException(f); |
286 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
287 |
> |
{ |
288 |
> |
CFException ex; |
289 |
> |
CompletableFuture<Integer> f; |
290 |
> |
|
291 |
|
f = new CompletableFuture<>(); |
292 |
< |
f.obtrudeException(new CFException()); |
293 |
< |
checkCompletedWithWrappedCFException(f); |
292 |
> |
f.complete(v1); |
293 |
> |
for (int i = 0; i < 2; i++) { |
294 |
> |
f.obtrudeException(ex = new CFException()); |
295 |
> |
checkCompletedExceptionally(f, ex); |
296 |
> |
} |
297 |
> |
|
298 |
|
f = new CompletableFuture<>(); |
299 |
+ |
for (int i = 0; i < 2; i++) { |
300 |
+ |
f.obtrudeException(ex = new CFException()); |
301 |
+ |
checkCompletedExceptionally(f, ex); |
302 |
+ |
} |
303 |
+ |
|
304 |
+ |
f = new CompletableFuture<>(); |
305 |
+ |
f.completeExceptionally(ex = new CFException()); |
306 |
+ |
f.obtrudeValue(v1); |
307 |
+ |
checkCompletedNormally(f, v1); |
308 |
+ |
f.obtrudeException(ex = new CFException()); |
309 |
+ |
checkCompletedExceptionally(f, ex); |
310 |
|
f.completeExceptionally(new CFException()); |
311 |
< |
f.obtrudeValue(four); |
312 |
< |
checkCompletedNormally(f, four); |
313 |
< |
f.obtrudeException(new CFException()); |
314 |
< |
checkCompletedWithWrappedCFException(f); |
279 |
< |
} |
311 |
> |
checkCompletedExceptionally(f, ex); |
312 |
> |
f.complete(v1); |
313 |
> |
checkCompletedExceptionally(f, ex); |
314 |
> |
}} |
315 |
|
|
316 |
|
/** |
317 |
|
* getNumberOfDependents returns number of dependent tasks |
395 |
|
return (x == null) ? null : x + 1; |
396 |
|
} |
397 |
|
|
398 |
< |
class IncAction extends CheckedIntegerAction |
398 |
> |
class NoopConsumer extends CheckedIntegerAction |
399 |
|
implements Consumer<Integer> |
400 |
|
{ |
401 |
< |
IncAction(ExecutionMode m) { super(m); } |
401 |
> |
NoopConsumer(ExecutionMode m) { super(m); } |
402 |
|
public void accept(Integer x) { |
403 |
|
invoked(); |
404 |
< |
value = inc(x); |
404 |
> |
value = x; |
405 |
|
} |
406 |
|
} |
407 |
|
|
450 |
|
} |
451 |
|
} |
452 |
|
|
453 |
< |
class FailingSupplier extends CheckedAction implements Supplier<Integer> |
453 |
> |
class FailingSupplier extends CheckedAction |
454 |
> |
implements Supplier<Integer> |
455 |
|
{ |
456 |
|
FailingSupplier(ExecutionMode m) { super(m); } |
457 |
|
public Integer get() { |
460 |
|
} |
461 |
|
} |
462 |
|
|
463 |
< |
class FailingConsumer extends CheckedAction implements Consumer<Integer> { |
463 |
> |
class FailingConsumer extends CheckedIntegerAction |
464 |
> |
implements Consumer<Integer> |
465 |
> |
{ |
466 |
|
FailingConsumer(ExecutionMode m) { super(m); } |
467 |
|
public void accept(Integer x) { |
468 |
|
invoked(); |
469 |
+ |
value = x; |
470 |
|
throw new CFException(); |
471 |
|
} |
472 |
|
} |
473 |
|
|
474 |
< |
class FailingBiConsumer extends CheckedAction |
474 |
> |
class FailingBiConsumer extends CheckedIntegerAction |
475 |
|
implements BiConsumer<Integer, Integer> |
476 |
|
{ |
477 |
|
FailingBiConsumer(ExecutionMode m) { super(m); } |
478 |
|
public void accept(Integer x, Integer y) { |
479 |
|
invoked(); |
480 |
+ |
value = subtract(x, y); |
481 |
|
throw new CFException(); |
482 |
|
} |
483 |
|
} |
484 |
|
|
485 |
< |
class FailingFunction extends CheckedAction |
485 |
> |
class FailingFunction extends CheckedIntegerAction |
486 |
|
implements Function<Integer, Integer> |
487 |
|
{ |
488 |
|
FailingFunction(ExecutionMode m) { super(m); } |
489 |
|
public Integer apply(Integer x) { |
490 |
|
invoked(); |
491 |
+ |
value = x; |
492 |
|
throw new CFException(); |
493 |
|
} |
494 |
|
} |
495 |
|
|
496 |
< |
class FailingBiFunction extends CheckedAction |
496 |
> |
class FailingBiFunction extends CheckedIntegerAction |
497 |
|
implements BiFunction<Integer, Integer, Integer> |
498 |
|
{ |
499 |
|
FailingBiFunction(ExecutionMode m) { super(m); } |
500 |
|
public Integer apply(Integer x, Integer y) { |
501 |
|
invoked(); |
502 |
+ |
value = subtract(x, y); |
503 |
|
throw new CFException(); |
504 |
|
} |
505 |
|
} |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
< |
class CompletableFutureInc extends CheckedAction |
516 |
> |
class CompletableFutureInc extends CheckedIntegerAction |
517 |
|
implements Function<Integer, CompletableFuture<Integer>> |
518 |
|
{ |
519 |
|
CompletableFutureInc(ExecutionMode m) { super(m); } |
520 |
|
public CompletableFuture<Integer> apply(Integer x) { |
521 |
|
invoked(); |
522 |
+ |
value = x; |
523 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
524 |
|
f.complete(inc(x)); |
525 |
|
return f; |
526 |
|
} |
527 |
|
} |
528 |
|
|
529 |
< |
class FailingCompletableFutureFunction extends CheckedAction |
529 |
> |
class FailingCompletableFutureFunction extends CheckedIntegerAction |
530 |
|
implements Function<Integer, CompletableFuture<Integer>> |
531 |
|
{ |
532 |
|
FailingCompletableFutureFunction(ExecutionMode m) { super(m); } |
533 |
|
public CompletableFuture<Integer> apply(Integer x) { |
534 |
|
invoked(); |
535 |
+ |
value = x; |
536 |
|
throw new CFException(); |
537 |
|
} |
538 |
|
} |
887 |
|
}); |
888 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
889 |
|
|
890 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
890 |
> |
checkCompletedWithWrappedException(g, ex2); |
891 |
|
assertEquals(1, a.get()); |
892 |
|
}} |
893 |
|
|
944 |
|
if (createIncomplete) f.completeExceptionally(ex); |
945 |
|
|
946 |
|
checkCompletedNormally(g, v1); |
947 |
< |
checkCompletedWithWrappedCFException(f, ex); |
947 |
> |
checkCompletedExceptionally(f, ex); |
948 |
|
assertEquals(1, a.get()); |
949 |
|
}} |
950 |
|
|
1000 |
|
}); |
1001 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
1002 |
|
|
1003 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
1004 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
1003 |
> |
checkCompletedWithWrappedException(g, ex2); |
1004 |
> |
checkCompletedExceptionally(f, ex1); |
1005 |
|
assertEquals(1, a.get()); |
1006 |
|
}} |
1007 |
|
|
1025 |
|
}); |
1026 |
|
if (createIncomplete) f.complete(v1); |
1027 |
|
|
1028 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1028 |
> |
checkCompletedWithWrappedException(g, ex); |
1029 |
|
checkCompletedNormally(f, v1); |
1030 |
|
assertEquals(1, a.get()); |
1031 |
|
}} |
1139 |
|
f.completeExceptionally(ex); |
1140 |
|
} |
1141 |
|
|
1142 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1143 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1142 |
> |
checkCompletedWithWrappedException(g, ex); |
1143 |
> |
checkCompletedExceptionally(f, ex); |
1144 |
|
r.assertNotInvoked(); |
1145 |
|
}} |
1146 |
|
|
1206 |
|
|
1207 |
|
checkCompletedNormally(g, inc(v1)); |
1208 |
|
checkCompletedNormally(f, v1); |
1209 |
< |
r.assertInvoked(); |
1209 |
> |
r.assertValue(inc(v1)); |
1210 |
|
}} |
1211 |
|
|
1212 |
|
/** |
1227 |
|
f.completeExceptionally(ex); |
1228 |
|
} |
1229 |
|
|
1230 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1231 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1230 |
> |
checkCompletedWithWrappedException(g, ex); |
1231 |
> |
checkCompletedExceptionally(f, ex); |
1232 |
|
r.assertNotInvoked(); |
1233 |
|
}} |
1234 |
|
|
1284 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1285 |
|
{ |
1286 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1287 |
< |
final IncAction r = new IncAction(m); |
1287 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1288 |
|
if (!createIncomplete) f.complete(v1); |
1289 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1290 |
|
if (createIncomplete) { |
1293 |
|
} |
1294 |
|
|
1295 |
|
checkCompletedNormally(g, null); |
1296 |
+ |
r.assertValue(v1); |
1297 |
|
checkCompletedNormally(f, v1); |
1253 |
– |
r.assertInvoked(); |
1254 |
– |
r.assertValue(inc(v1)); |
1298 |
|
}} |
1299 |
|
|
1300 |
|
/** |
1307 |
|
{ |
1308 |
|
final CFException ex = new CFException(); |
1309 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1310 |
< |
final IncAction r = new IncAction(m); |
1310 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1311 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1312 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1313 |
|
if (createIncomplete) { |
1315 |
|
f.completeExceptionally(ex); |
1316 |
|
} |
1317 |
|
|
1318 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1319 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1318 |
> |
checkCompletedWithWrappedException(g, ex); |
1319 |
> |
checkCompletedExceptionally(f, ex); |
1320 |
|
r.assertNotInvoked(); |
1321 |
|
}} |
1322 |
|
|
1329 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1330 |
|
{ |
1331 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1332 |
< |
final IncAction r = new IncAction(m); |
1332 |
> |
final NoopConsumer r = new NoopConsumer(m); |
1333 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1334 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1335 |
|
if (createIncomplete) { |
1391 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1392 |
|
checkCompletedNormally(f, v1); |
1393 |
|
checkCompletedNormally(g, v2); |
1394 |
< |
r.assertInvoked(); |
1394 |
> |
r.assertValue(subtract(v1, v2)); |
1395 |
|
}} |
1396 |
|
|
1397 |
|
/** |
1418 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1419 |
|
} |
1420 |
|
|
1421 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1421 |
> |
checkCompletedWithWrappedException(h, ex); |
1422 |
|
r.assertNotInvoked(); |
1423 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1424 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1424 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1425 |
|
}} |
1426 |
|
|
1427 |
|
/** |
1535 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1536 |
|
} |
1537 |
|
|
1538 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1538 |
> |
checkCompletedWithWrappedException(h, ex); |
1539 |
|
r.assertNotInvoked(); |
1540 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1541 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1541 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1542 |
|
}} |
1543 |
|
|
1544 |
|
/** |
1652 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1653 |
|
} |
1654 |
|
|
1655 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1655 |
> |
checkCompletedWithWrappedException(h, ex); |
1656 |
|
r.assertNotInvoked(); |
1657 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1658 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1658 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1659 |
|
}} |
1660 |
|
|
1661 |
|
/** |
1787 |
|
rs[0].assertNotInvoked(); |
1788 |
|
rs[1].assertNotInvoked(); |
1789 |
|
f.completeExceptionally(ex); |
1790 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1791 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1790 |
> |
checkCompletedWithWrappedException(h0, ex); |
1791 |
> |
checkCompletedWithWrappedException(h1, ex); |
1792 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1793 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1794 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1795 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1794 |
> |
checkCompletedWithWrappedException(h2, ex); |
1795 |
> |
checkCompletedWithWrappedException(h3, ex); |
1796 |
|
g.complete(v1); |
1797 |
|
|
1798 |
|
// unspecified behavior - both source completions available |
1800 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1801 |
|
try { |
1802 |
|
assertEquals(inc(v1), h4.join()); |
1803 |
< |
rs[4].assertInvoked(); |
1803 |
> |
rs[4].assertValue(inc(v1)); |
1804 |
|
} catch (CompletionException ok) { |
1805 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1805 |
> |
checkCompletedWithWrappedException(h4, ex); |
1806 |
|
rs[4].assertNotInvoked(); |
1807 |
|
} |
1808 |
|
try { |
1809 |
|
assertEquals(inc(v1), h5.join()); |
1810 |
< |
rs[5].assertInvoked(); |
1810 |
> |
rs[5].assertValue(inc(v1)); |
1811 |
|
} catch (CompletionException ok) { |
1812 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
1812 |
> |
checkCompletedWithWrappedException(h5, ex); |
1813 |
|
rs[5].assertNotInvoked(); |
1814 |
|
} |
1815 |
|
|
1816 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1816 |
> |
checkCompletedExceptionally(f, ex); |
1817 |
|
checkCompletedNormally(g, v1); |
1818 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1819 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1820 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1821 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1822 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1818 |
> |
checkCompletedWithWrappedException(h0, ex); |
1819 |
> |
checkCompletedWithWrappedException(h1, ex); |
1820 |
> |
checkCompletedWithWrappedException(h2, ex); |
1821 |
> |
checkCompletedWithWrappedException(h3, ex); |
1822 |
> |
checkCompletedWithWrappedException(h4, ex); |
1823 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1824 |
|
}} |
1825 |
|
|
1826 |
+ |
public void testApplyToEither_exceptionalCompletion2() { |
1827 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1828 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1829 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1830 |
+ |
{ |
1831 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1832 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1833 |
+ |
final CFException ex = new CFException(); |
1834 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1835 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1836 |
+ |
|
1837 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1838 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1839 |
+ |
if (fFirst) { |
1840 |
+ |
f.complete(v1); |
1841 |
+ |
g.completeExceptionally(ex); |
1842 |
+ |
} else { |
1843 |
+ |
g.completeExceptionally(ex); |
1844 |
+ |
f.complete(v1); |
1845 |
+ |
} |
1846 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1847 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1848 |
+ |
|
1849 |
+ |
// unspecified behavior - both source completions available |
1850 |
+ |
try { |
1851 |
+ |
assertEquals(inc(v1), h0.join()); |
1852 |
+ |
rs[0].assertValue(inc(v1)); |
1853 |
+ |
} catch (CompletionException ok) { |
1854 |
+ |
checkCompletedWithWrappedException(h0, ex); |
1855 |
+ |
rs[0].assertNotInvoked(); |
1856 |
+ |
} |
1857 |
+ |
try { |
1858 |
+ |
assertEquals(inc(v1), h1.join()); |
1859 |
+ |
rs[1].assertValue(inc(v1)); |
1860 |
+ |
} catch (CompletionException ok) { |
1861 |
+ |
checkCompletedWithWrappedException(h1, ex); |
1862 |
+ |
rs[1].assertNotInvoked(); |
1863 |
+ |
} |
1864 |
+ |
try { |
1865 |
+ |
assertEquals(inc(v1), h2.join()); |
1866 |
+ |
rs[2].assertValue(inc(v1)); |
1867 |
+ |
} catch (CompletionException ok) { |
1868 |
+ |
checkCompletedWithWrappedException(h2, ex); |
1869 |
+ |
rs[2].assertNotInvoked(); |
1870 |
+ |
} |
1871 |
+ |
try { |
1872 |
+ |
assertEquals(inc(v1), h3.join()); |
1873 |
+ |
rs[3].assertValue(inc(v1)); |
1874 |
+ |
} catch (CompletionException ok) { |
1875 |
+ |
checkCompletedWithWrappedException(h3, ex); |
1876 |
+ |
rs[3].assertNotInvoked(); |
1877 |
+ |
} |
1878 |
+ |
|
1879 |
+ |
checkCompletedNormally(f, v1); |
1880 |
+ |
checkCompletedExceptionally(g, ex); |
1881 |
+ |
}} |
1882 |
+ |
|
1883 |
|
/** |
1884 |
|
* applyToEither result completes exceptionally if either source cancelled |
1885 |
|
*/ |
1913 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1914 |
|
try { |
1915 |
|
assertEquals(inc(v1), h4.join()); |
1916 |
< |
rs[4].assertInvoked(); |
1916 |
> |
rs[4].assertValue(inc(v1)); |
1917 |
|
} catch (CompletionException ok) { |
1918 |
|
checkCompletedWithWrappedCancellationException(h4); |
1919 |
|
rs[4].assertNotInvoked(); |
1920 |
|
} |
1921 |
|
try { |
1922 |
|
assertEquals(inc(v1), h5.join()); |
1923 |
< |
rs[5].assertInvoked(); |
1923 |
> |
rs[5].assertValue(inc(v1)); |
1924 |
|
} catch (CompletionException ok) { |
1925 |
|
checkCompletedWithWrappedCancellationException(h5); |
1926 |
|
rs[5].assertNotInvoked(); |
1935 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1936 |
|
}} |
1937 |
|
|
1938 |
< |
/** |
1839 |
< |
* applyToEither result completes exceptionally if action does |
1840 |
< |
*/ |
1841 |
< |
public void testApplyToEither_actionFailed() { |
1938 |
> |
public void testApplyToEither_sourceCancelled2() { |
1939 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1940 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1941 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1942 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1844 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1943 |
|
{ |
1944 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1945 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1946 |
< |
final FailingFunction[] rs = new FailingFunction[6]; |
1947 |
< |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingFunction(m); |
1946 |
> |
final IncFunction[] rs = new IncFunction[6]; |
1947 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1948 |
|
|
1949 |
|
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1950 |
|
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1951 |
< |
f.complete(v1); |
1951 |
> |
if (fFirst) { |
1952 |
> |
f.complete(v1); |
1953 |
> |
g.cancel(mayInterruptIfRunning); |
1954 |
> |
} else { |
1955 |
> |
g.cancel(mayInterruptIfRunning); |
1956 |
> |
f.complete(v1); |
1957 |
> |
} |
1958 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1959 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1960 |
< |
g.complete(v2); |
1961 |
< |
final CompletableFuture<Integer> h4 = m.applyToEither(f, g, rs[4]); |
1962 |
< |
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1963 |
< |
|
1960 |
> |
|
1961 |
> |
// unspecified behavior - both source completions available |
1962 |
> |
try { |
1963 |
> |
assertEquals(inc(v1), h0.join()); |
1964 |
> |
rs[0].assertValue(inc(v1)); |
1965 |
> |
} catch (CompletionException ok) { |
1966 |
> |
checkCompletedWithWrappedCancellationException(h0); |
1967 |
> |
rs[0].assertNotInvoked(); |
1968 |
> |
} |
1969 |
> |
try { |
1970 |
> |
assertEquals(inc(v1), h1.join()); |
1971 |
> |
rs[1].assertValue(inc(v1)); |
1972 |
> |
} catch (CompletionException ok) { |
1973 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1974 |
> |
rs[1].assertNotInvoked(); |
1975 |
> |
} |
1976 |
> |
try { |
1977 |
> |
assertEquals(inc(v1), h2.join()); |
1978 |
> |
rs[2].assertValue(inc(v1)); |
1979 |
> |
} catch (CompletionException ok) { |
1980 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1981 |
> |
rs[2].assertNotInvoked(); |
1982 |
> |
} |
1983 |
> |
try { |
1984 |
> |
assertEquals(inc(v1), h3.join()); |
1985 |
> |
rs[3].assertValue(inc(v1)); |
1986 |
> |
} catch (CompletionException ok) { |
1987 |
> |
checkCompletedWithWrappedCancellationException(h3); |
1988 |
> |
rs[3].assertNotInvoked(); |
1989 |
> |
} |
1990 |
> |
|
1991 |
|
checkCompletedNormally(f, v1); |
1992 |
< |
checkCompletedNormally(g, v2); |
1862 |
< |
checkCompletedWithWrappedCFException(h0); |
1863 |
< |
checkCompletedWithWrappedCFException(h1); |
1864 |
< |
checkCompletedWithWrappedCFException(h2); |
1865 |
< |
checkCompletedWithWrappedCFException(h3); |
1866 |
< |
checkCompletedWithWrappedCFException(h4); |
1867 |
< |
checkCompletedWithWrappedCFException(h5); |
1868 |
< |
for (int i = 0; i < rs.length; i++) rs[i].assertInvoked(); |
1992 |
> |
checkCancelled(g); |
1993 |
|
}} |
1994 |
|
|
1995 |
|
/** |
1996 |
< |
* acceptEither result completes normally after normal completion |
1873 |
< |
* of either source |
1996 |
> |
* applyToEither result completes exceptionally if action does |
1997 |
|
*/ |
1998 |
< |
public void testAcceptEither_normalCompletion1() { |
1998 |
> |
public void testApplyToEither_actionFailed() { |
1999 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2000 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2001 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2002 |
|
{ |
2003 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2004 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2005 |
< |
final IncAction r = new IncAction(m); |
2006 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2005 |
> |
final FailingFunction[] rs = new FailingFunction[6]; |
2006 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingFunction(m); |
2007 |
|
|
2008 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
2009 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
2010 |
|
f.complete(v1); |
2011 |
< |
checkCompletedNormally(h, null); |
2012 |
< |
assertEquals(inc(v1), r.value); |
2013 |
< |
g.complete(v2); |
2011 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
2012 |
> |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
2013 |
> |
checkCompletedWithWrappedCFException(h0); |
2014 |
> |
checkCompletedWithWrappedCFException(h1); |
2015 |
> |
checkCompletedWithWrappedCFException(h2); |
2016 |
> |
checkCompletedWithWrappedCFException(h3); |
2017 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2018 |
|
|
2019 |
< |
checkCompletedNormally(f, v1); |
1891 |
< |
checkCompletedNormally(g, v2); |
1892 |
< |
checkCompletedNormally(h, null); |
1893 |
< |
}} |
2019 |
> |
g.complete(v2); |
2020 |
|
|
2021 |
< |
public void testAcceptEither_normalCompletion2() { |
2022 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2023 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1898 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1899 |
< |
{ |
1900 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1901 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1902 |
< |
final IncAction r = new IncAction(m); |
1903 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2021 |
> |
// unspecified behavior - both source completions available |
2022 |
> |
final CompletableFuture<Integer> h4 = m.applyToEither(f, g, rs[4]); |
2023 |
> |
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
2024 |
|
|
2025 |
< |
g.complete(v2); |
2026 |
< |
checkCompletedNormally(h, null); |
2027 |
< |
assertEquals(inc(v2), r.value); |
2028 |
< |
f.complete(v1); |
2025 |
> |
checkCompletedWithWrappedCFException(h4); |
2026 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2027 |
> |
Objects.equals(v2, rs[4].value)); |
2028 |
> |
checkCompletedWithWrappedCFException(h5); |
2029 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2030 |
> |
Objects.equals(v2, rs[5].value)); |
2031 |
|
|
2032 |
|
checkCompletedNormally(f, v1); |
2033 |
|
checkCompletedNormally(g, v2); |
1912 |
– |
checkCompletedNormally(h, null); |
2034 |
|
}} |
2035 |
|
|
2036 |
< |
public void testAcceptEither_normalCompletion3() { |
2036 |
> |
/** |
2037 |
> |
* acceptEither result completes normally after normal completion |
2038 |
> |
* of either source |
2039 |
> |
*/ |
2040 |
> |
public void testAcceptEither_normalCompletion() { |
2041 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2042 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2043 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2044 |
|
{ |
2045 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2046 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2047 |
< |
final IncAction r = new IncAction(m); |
2047 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2048 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2049 |
|
|
2050 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2051 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2052 |
+ |
checkIncomplete(h0); |
2053 |
+ |
checkIncomplete(h1); |
2054 |
+ |
rs[0].assertNotInvoked(); |
2055 |
+ |
rs[1].assertNotInvoked(); |
2056 |
|
f.complete(v1); |
2057 |
+ |
checkCompletedNormally(h0, null); |
2058 |
+ |
checkCompletedNormally(h1, null); |
2059 |
+ |
rs[0].assertValue(v1); |
2060 |
+ |
rs[1].assertValue(v1); |
2061 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2062 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2063 |
+ |
checkCompletedNormally(h2, null); |
2064 |
+ |
checkCompletedNormally(h3, null); |
2065 |
+ |
rs[2].assertValue(v1); |
2066 |
+ |
rs[3].assertValue(v1); |
2067 |
|
g.complete(v2); |
1926 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2068 |
|
|
2069 |
< |
checkCompletedNormally(h, null); |
2069 |
> |
// unspecified behavior - both source completions available |
2070 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2071 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2072 |
> |
checkCompletedNormally(h4, null); |
2073 |
> |
checkCompletedNormally(h5, null); |
2074 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2075 |
> |
Objects.equals(v2, rs[4].value)); |
2076 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2077 |
> |
Objects.equals(v2, rs[5].value)); |
2078 |
> |
|
2079 |
|
checkCompletedNormally(f, v1); |
2080 |
|
checkCompletedNormally(g, v2); |
2081 |
< |
|
2082 |
< |
// unspecified behavior |
2083 |
< |
assertTrue(Objects.equals(r.value, inc(v1)) || |
2084 |
< |
Objects.equals(r.value, inc(v2))); |
2081 |
> |
checkCompletedNormally(h0, null); |
2082 |
> |
checkCompletedNormally(h1, null); |
2083 |
> |
checkCompletedNormally(h2, null); |
2084 |
> |
checkCompletedNormally(h3, null); |
2085 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2086 |
|
}} |
2087 |
|
|
2088 |
|
/** |
2089 |
|
* acceptEither result completes exceptionally after exceptional |
2090 |
|
* completion of either source |
2091 |
|
*/ |
2092 |
< |
public void testAcceptEither_exceptionalCompletion1() { |
2092 |
> |
public void testAcceptEither_exceptionalCompletion() { |
2093 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2094 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2095 |
|
{ |
2096 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2097 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1947 |
– |
final IncAction r = new IncAction(m); |
1948 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2098 |
|
final CFException ex = new CFException(); |
2099 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2100 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2101 |
|
|
2102 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2103 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2104 |
+ |
checkIncomplete(h0); |
2105 |
+ |
checkIncomplete(h1); |
2106 |
+ |
rs[0].assertNotInvoked(); |
2107 |
+ |
rs[1].assertNotInvoked(); |
2108 |
|
f.completeExceptionally(ex); |
2109 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2109 |
> |
checkCompletedWithWrappedException(h0, ex); |
2110 |
> |
checkCompletedWithWrappedException(h1, ex); |
2111 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2112 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2113 |
> |
checkCompletedWithWrappedException(h2, ex); |
2114 |
> |
checkCompletedWithWrappedException(h3, ex); |
2115 |
> |
|
2116 |
|
g.complete(v1); |
2117 |
|
|
2118 |
< |
r.assertNotInvoked(); |
2118 |
> |
// unspecified behavior - both source completions available |
2119 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2120 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2121 |
> |
try { |
2122 |
> |
assertNull(h4.join()); |
2123 |
> |
rs[4].assertValue(v1); |
2124 |
> |
} catch (CompletionException ok) { |
2125 |
> |
checkCompletedWithWrappedException(h4, ex); |
2126 |
> |
rs[4].assertNotInvoked(); |
2127 |
> |
} |
2128 |
> |
try { |
2129 |
> |
assertNull(h5.join()); |
2130 |
> |
rs[5].assertValue(v1); |
2131 |
> |
} catch (CompletionException ok) { |
2132 |
> |
checkCompletedWithWrappedException(h5, ex); |
2133 |
> |
rs[5].assertNotInvoked(); |
2134 |
> |
} |
2135 |
> |
|
2136 |
> |
checkCompletedExceptionally(f, ex); |
2137 |
|
checkCompletedNormally(g, v1); |
2138 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2139 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2138 |
> |
checkCompletedWithWrappedException(h0, ex); |
2139 |
> |
checkCompletedWithWrappedException(h1, ex); |
2140 |
> |
checkCompletedWithWrappedException(h2, ex); |
2141 |
> |
checkCompletedWithWrappedException(h3, ex); |
2142 |
> |
checkCompletedWithWrappedException(h4, ex); |
2143 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2144 |
|
}} |
2145 |
|
|
2146 |
|
public void testAcceptEither_exceptionalCompletion2() { |
2147 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2148 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2149 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2150 |
|
{ |
2151 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2152 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1967 |
– |
final IncAction r = new IncAction(m); |
1968 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
1969 |
– |
final CFException ex = new CFException(); |
1970 |
– |
|
1971 |
– |
g.completeExceptionally(ex); |
1972 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1973 |
– |
f.complete(v1); |
1974 |
– |
|
1975 |
– |
r.assertNotInvoked(); |
1976 |
– |
checkCompletedNormally(f, v1); |
1977 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1978 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1979 |
– |
}} |
1980 |
– |
|
1981 |
– |
public void testAcceptEither_exceptionalCompletion3() { |
1982 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1983 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1984 |
– |
{ |
1985 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1986 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1987 |
– |
final IncAction r = new IncAction(m); |
2153 |
|
final CFException ex = new CFException(); |
2154 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2155 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2156 |
|
|
2157 |
< |
g.completeExceptionally(ex); |
2158 |
< |
f.complete(v1); |
2159 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2157 |
> |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2158 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2159 |
> |
if (fFirst) { |
2160 |
> |
f.complete(v1); |
2161 |
> |
g.completeExceptionally(ex); |
2162 |
> |
} else { |
2163 |
> |
g.completeExceptionally(ex); |
2164 |
> |
f.complete(v1); |
2165 |
> |
} |
2166 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2167 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2168 |
|
|
2169 |
< |
// unspecified behavior |
1995 |
< |
Integer v; |
2169 |
> |
// unspecified behavior - both source completions available |
2170 |
|
try { |
2171 |
< |
assertNull(h.join()); |
2172 |
< |
r.assertInvoked(); |
1999 |
< |
assertEquals(inc(v1), r.value); |
2171 |
> |
assertEquals(null, h0.join()); |
2172 |
> |
rs[0].assertValue(v1); |
2173 |
|
} catch (CompletionException ok) { |
2174 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2175 |
< |
r.assertNotInvoked(); |
2174 |
> |
checkCompletedWithWrappedException(h0, ex); |
2175 |
> |
rs[0].assertNotInvoked(); |
2176 |
|
} |
2004 |
– |
|
2005 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2006 |
– |
checkCompletedNormally(f, v1); |
2007 |
– |
}} |
2008 |
– |
|
2009 |
– |
public void testAcceptEither_exceptionalCompletion4() { |
2010 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2011 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2012 |
– |
{ |
2013 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2014 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2015 |
– |
final IncAction r = new IncAction(m); |
2016 |
– |
final CFException ex = new CFException(); |
2017 |
– |
|
2018 |
– |
f.completeExceptionally(ex); |
2019 |
– |
g.complete(v1); |
2020 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2021 |
– |
|
2022 |
– |
// unspecified behavior |
2023 |
– |
Integer v; |
2177 |
|
try { |
2178 |
< |
assertNull(h.join()); |
2179 |
< |
r.assertInvoked(); |
2027 |
< |
assertEquals(inc(v1), r.value); |
2178 |
> |
assertEquals(null, h1.join()); |
2179 |
> |
rs[1].assertValue(v1); |
2180 |
|
} catch (CompletionException ok) { |
2181 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2182 |
< |
r.assertNotInvoked(); |
2181 |
> |
checkCompletedWithWrappedException(h1, ex); |
2182 |
> |
rs[1].assertNotInvoked(); |
2183 |
> |
} |
2184 |
> |
try { |
2185 |
> |
assertEquals(null, h2.join()); |
2186 |
> |
rs[2].assertValue(v1); |
2187 |
> |
} catch (CompletionException ok) { |
2188 |
> |
checkCompletedWithWrappedException(h2, ex); |
2189 |
> |
rs[2].assertNotInvoked(); |
2190 |
> |
} |
2191 |
> |
try { |
2192 |
> |
assertEquals(null, h3.join()); |
2193 |
> |
rs[3].assertValue(v1); |
2194 |
> |
} catch (CompletionException ok) { |
2195 |
> |
checkCompletedWithWrappedException(h3, ex); |
2196 |
> |
rs[3].assertNotInvoked(); |
2197 |
|
} |
2198 |
|
|
2033 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2034 |
– |
checkCompletedNormally(g, v1); |
2035 |
– |
}} |
2036 |
– |
|
2037 |
– |
/** |
2038 |
– |
* acceptEither result completes exceptionally if action does |
2039 |
– |
*/ |
2040 |
– |
public void testAcceptEither_actionFailed1() { |
2041 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2042 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2043 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
2044 |
– |
{ |
2045 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2046 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2047 |
– |
final FailingConsumer r = new FailingConsumer(m); |
2048 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2049 |
– |
|
2050 |
– |
f.complete(v1); |
2051 |
– |
checkCompletedWithWrappedCFException(h); |
2052 |
– |
g.complete(v2); |
2053 |
– |
checkCompletedNormally(f, v1); |
2054 |
– |
checkCompletedNormally(g, v2); |
2055 |
– |
}} |
2056 |
– |
|
2057 |
– |
public void testAcceptEither_actionFailed2() { |
2058 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2059 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2060 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
2061 |
– |
{ |
2062 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2063 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2064 |
– |
final FailingConsumer r = new FailingConsumer(m); |
2065 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2066 |
– |
|
2067 |
– |
g.complete(v2); |
2068 |
– |
checkCompletedWithWrappedCFException(h); |
2069 |
– |
f.complete(v1); |
2199 |
|
checkCompletedNormally(f, v1); |
2200 |
< |
checkCompletedNormally(g, v2); |
2200 |
> |
checkCompletedExceptionally(g, ex); |
2201 |
|
}} |
2202 |
|
|
2203 |
|
/** |
2204 |
|
* acceptEither result completes exceptionally if either source cancelled |
2205 |
|
*/ |
2206 |
< |
public void testAcceptEither_sourceCancelled1() { |
2206 |
> |
public void testAcceptEither_sourceCancelled() { |
2207 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2208 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2209 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2210 |
|
{ |
2211 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2212 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2213 |
< |
final IncAction r = new IncAction(m); |
2214 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2086 |
< |
|
2087 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2088 |
< |
checkCompletedWithWrappedCancellationException(h); |
2089 |
< |
g.complete(v1); |
2090 |
< |
|
2091 |
< |
checkCancelled(f); |
2092 |
< |
r.assertNotInvoked(); |
2093 |
< |
checkCompletedNormally(g, v1); |
2094 |
< |
checkCompletedWithWrappedCancellationException(h); |
2095 |
< |
}} |
2096 |
< |
|
2097 |
< |
public void testAcceptEither_sourceCancelled2() { |
2098 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2099 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2100 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2101 |
< |
{ |
2102 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2103 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2104 |
< |
final IncAction r = new IncAction(m); |
2105 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2106 |
< |
|
2107 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2108 |
< |
checkCompletedWithWrappedCancellationException(h); |
2109 |
< |
f.complete(v1); |
2213 |
> |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2214 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2215 |
|
|
2216 |
< |
checkCancelled(g); |
2217 |
< |
r.assertNotInvoked(); |
2218 |
< |
checkCompletedNormally(f, v1); |
2219 |
< |
checkCompletedWithWrappedCancellationException(h); |
2220 |
< |
}} |
2221 |
< |
|
2222 |
< |
public void testAcceptEither_sourceCancelled3() { |
2223 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2224 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2225 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2226 |
< |
{ |
2227 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2228 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
< |
final IncAction r = new IncAction(m); |
2216 |
> |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2217 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2218 |
> |
checkIncomplete(h0); |
2219 |
> |
checkIncomplete(h1); |
2220 |
> |
rs[0].assertNotInvoked(); |
2221 |
> |
rs[1].assertNotInvoked(); |
2222 |
> |
f.cancel(mayInterruptIfRunning); |
2223 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2224 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2225 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2226 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2227 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2228 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2229 |
|
|
2230 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2127 |
< |
f.complete(v1); |
2128 |
< |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2230 |
> |
g.complete(v1); |
2231 |
|
|
2232 |
< |
// unspecified behavior |
2233 |
< |
Integer v; |
2232 |
> |
// unspecified behavior - both source completions available |
2233 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2234 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2235 |
|
try { |
2236 |
< |
assertNull(h.join()); |
2237 |
< |
r.assertInvoked(); |
2135 |
< |
assertEquals(inc(v1), r.value); |
2236 |
> |
assertNull(h4.join()); |
2237 |
> |
rs[4].assertValue(v1); |
2238 |
|
} catch (CompletionException ok) { |
2239 |
< |
checkCompletedWithWrappedCancellationException(h); |
2240 |
< |
r.assertNotInvoked(); |
2239 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2240 |
> |
rs[4].assertNotInvoked(); |
2241 |
|
} |
2140 |
– |
|
2141 |
– |
checkCancelled(g); |
2142 |
– |
checkCompletedNormally(f, v1); |
2143 |
– |
}} |
2144 |
– |
|
2145 |
– |
public void testAcceptEither_sourceCancelled4() { |
2146 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2147 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2148 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2149 |
– |
{ |
2150 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2151 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2152 |
– |
final IncAction r = new IncAction(m); |
2153 |
– |
|
2154 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2155 |
– |
g.complete(v1); |
2156 |
– |
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2157 |
– |
|
2158 |
– |
// unspecified behavior |
2159 |
– |
Integer v; |
2242 |
|
try { |
2243 |
< |
assertNull(h.join()); |
2244 |
< |
r.assertInvoked(); |
2163 |
< |
assertEquals(inc(v1), r.value); |
2243 |
> |
assertNull(h5.join()); |
2244 |
> |
rs[5].assertValue(v1); |
2245 |
|
} catch (CompletionException ok) { |
2246 |
< |
checkCompletedWithWrappedCancellationException(h); |
2247 |
< |
r.assertNotInvoked(); |
2246 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2247 |
> |
rs[5].assertNotInvoked(); |
2248 |
|
} |
2249 |
|
|
2250 |
|
checkCancelled(f); |
2251 |
|
checkCompletedNormally(g, v1); |
2252 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
2253 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
2254 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
2255 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
2256 |
+ |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2257 |
|
}} |
2258 |
|
|
2259 |
|
/** |
2260 |
< |
* runAfterEither result completes normally after normal completion |
2175 |
< |
* of either source |
2260 |
> |
* acceptEither result completes exceptionally if action does |
2261 |
|
*/ |
2262 |
< |
public void testRunAfterEither_normalCompletion1() { |
2262 |
> |
public void testAcceptEither_actionFailed() { |
2263 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2264 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2265 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2266 |
|
{ |
2267 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2268 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2269 |
< |
final Noop r = new Noop(m); |
2270 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2269 |
> |
final FailingConsumer[] rs = new FailingConsumer[6]; |
2270 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m); |
2271 |
|
|
2272 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2273 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2274 |
|
f.complete(v1); |
2275 |
< |
checkCompletedNormally(h, null); |
2276 |
< |
r.assertInvoked(); |
2277 |
< |
g.complete(v2); |
2275 |
> |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2276 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2277 |
> |
checkCompletedWithWrappedCFException(h0); |
2278 |
> |
checkCompletedWithWrappedCFException(h1); |
2279 |
> |
checkCompletedWithWrappedCFException(h2); |
2280 |
> |
checkCompletedWithWrappedCFException(h3); |
2281 |
> |
for (int i = 0; i < 4; i++) rs[i].assertValue(v1); |
2282 |
|
|
2283 |
< |
checkCompletedNormally(f, v1); |
2193 |
< |
checkCompletedNormally(g, v2); |
2194 |
< |
checkCompletedNormally(h, null); |
2195 |
< |
r.assertInvoked(); |
2196 |
< |
}} |
2283 |
> |
g.complete(v2); |
2284 |
|
|
2285 |
< |
public void testRunAfterEither_normalCompletion2() { |
2286 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2287 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2201 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2202 |
< |
{ |
2203 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2204 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2205 |
< |
final Noop r = new Noop(m); |
2206 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2285 |
> |
// unspecified behavior - both source completions available |
2286 |
> |
final CompletableFuture<Void> h4 = m.acceptEither(f, g, rs[4]); |
2287 |
> |
final CompletableFuture<Void> h5 = m.acceptEither(g, f, rs[5]); |
2288 |
|
|
2289 |
< |
g.complete(v2); |
2290 |
< |
checkCompletedNormally(h, null); |
2291 |
< |
r.assertInvoked(); |
2292 |
< |
f.complete(v1); |
2289 |
> |
checkCompletedWithWrappedCFException(h4); |
2290 |
> |
assertTrue(Objects.equals(v1, rs[4].value) || |
2291 |
> |
Objects.equals(v2, rs[4].value)); |
2292 |
> |
checkCompletedWithWrappedCFException(h5); |
2293 |
> |
assertTrue(Objects.equals(v1, rs[5].value) || |
2294 |
> |
Objects.equals(v2, rs[5].value)); |
2295 |
|
|
2296 |
|
checkCompletedNormally(f, v1); |
2297 |
|
checkCompletedNormally(g, v2); |
2298 |
< |
checkCompletedNormally(h, null); |
2216 |
< |
r.assertInvoked(); |
2217 |
< |
}} |
2298 |
> |
}} |
2299 |
|
|
2300 |
< |
public void testRunAfterEither_normalCompletion3() { |
2300 |
> |
/** |
2301 |
> |
* runAfterEither result completes normally after normal completion |
2302 |
> |
* of either source |
2303 |
> |
*/ |
2304 |
> |
public void testRunAfterEither_normalCompletion() { |
2305 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2306 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2307 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2308 |
|
{ |
2309 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2310 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2311 |
< |
final Noop r = new Noop(m); |
2311 |
> |
final Noop[] rs = new Noop[6]; |
2312 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2313 |
|
|
2314 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2315 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2316 |
+ |
checkIncomplete(h0); |
2317 |
+ |
checkIncomplete(h1); |
2318 |
+ |
rs[0].assertNotInvoked(); |
2319 |
+ |
rs[1].assertNotInvoked(); |
2320 |
|
f.complete(v1); |
2321 |
+ |
checkCompletedNormally(h0, null); |
2322 |
+ |
checkCompletedNormally(h1, null); |
2323 |
+ |
rs[0].assertInvoked(); |
2324 |
+ |
rs[1].assertInvoked(); |
2325 |
+ |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2326 |
+ |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2327 |
+ |
checkCompletedNormally(h2, null); |
2328 |
+ |
checkCompletedNormally(h3, null); |
2329 |
+ |
rs[2].assertInvoked(); |
2330 |
+ |
rs[3].assertInvoked(); |
2331 |
+ |
|
2332 |
|
g.complete(v2); |
2230 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2333 |
|
|
2334 |
< |
checkCompletedNormally(h, null); |
2334 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2335 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2336 |
> |
|
2337 |
|
checkCompletedNormally(f, v1); |
2338 |
|
checkCompletedNormally(g, v2); |
2339 |
< |
r.assertInvoked(); |
2339 |
> |
checkCompletedNormally(h0, null); |
2340 |
> |
checkCompletedNormally(h1, null); |
2341 |
> |
checkCompletedNormally(h2, null); |
2342 |
> |
checkCompletedNormally(h3, null); |
2343 |
> |
checkCompletedNormally(h4, null); |
2344 |
> |
checkCompletedNormally(h5, null); |
2345 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2346 |
|
}} |
2347 |
|
|
2348 |
|
/** |
2349 |
|
* runAfterEither result completes exceptionally after exceptional |
2350 |
|
* completion of either source |
2351 |
|
*/ |
2352 |
< |
public void testRunAfterEither_exceptionalCompletion1() { |
2352 |
> |
public void testRunAfterEither_exceptionalCompletion() { |
2353 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2354 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2355 |
|
{ |
2356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2357 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2248 |
– |
final Noop r = new Noop(m); |
2249 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2358 |
|
final CFException ex = new CFException(); |
2359 |
+ |
final Noop[] rs = new Noop[6]; |
2360 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2361 |
|
|
2362 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2363 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2364 |
+ |
checkIncomplete(h0); |
2365 |
+ |
checkIncomplete(h1); |
2366 |
+ |
rs[0].assertNotInvoked(); |
2367 |
+ |
rs[1].assertNotInvoked(); |
2368 |
|
f.completeExceptionally(ex); |
2369 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2369 |
> |
checkCompletedWithWrappedException(h0, ex); |
2370 |
> |
checkCompletedWithWrappedException(h1, ex); |
2371 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2372 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2373 |
> |
checkCompletedWithWrappedException(h2, ex); |
2374 |
> |
checkCompletedWithWrappedException(h3, ex); |
2375 |
> |
|
2376 |
|
g.complete(v1); |
2377 |
|
|
2378 |
< |
r.assertNotInvoked(); |
2378 |
> |
// unspecified behavior - both source completions available |
2379 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2380 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2381 |
> |
try { |
2382 |
> |
assertNull(h4.join()); |
2383 |
> |
rs[4].assertInvoked(); |
2384 |
> |
} catch (CompletionException ok) { |
2385 |
> |
checkCompletedWithWrappedException(h4, ex); |
2386 |
> |
rs[4].assertNotInvoked(); |
2387 |
> |
} |
2388 |
> |
try { |
2389 |
> |
assertNull(h5.join()); |
2390 |
> |
rs[5].assertInvoked(); |
2391 |
> |
} catch (CompletionException ok) { |
2392 |
> |
checkCompletedWithWrappedException(h5, ex); |
2393 |
> |
rs[5].assertNotInvoked(); |
2394 |
> |
} |
2395 |
> |
|
2396 |
> |
checkCompletedExceptionally(f, ex); |
2397 |
|
checkCompletedNormally(g, v1); |
2398 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2399 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2398 |
> |
checkCompletedWithWrappedException(h0, ex); |
2399 |
> |
checkCompletedWithWrappedException(h1, ex); |
2400 |
> |
checkCompletedWithWrappedException(h2, ex); |
2401 |
> |
checkCompletedWithWrappedException(h3, ex); |
2402 |
> |
checkCompletedWithWrappedException(h4, ex); |
2403 |
> |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2404 |
|
}} |
2405 |
|
|
2406 |
|
public void testRunAfterEither_exceptionalCompletion2() { |
2407 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2408 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2409 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2410 |
|
{ |
2411 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2412 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2268 |
– |
final Noop r = new Noop(m); |
2269 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2270 |
– |
final CFException ex = new CFException(); |
2271 |
– |
|
2272 |
– |
g.completeExceptionally(ex); |
2273 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2274 |
– |
f.complete(v1); |
2275 |
– |
|
2276 |
– |
r.assertNotInvoked(); |
2277 |
– |
checkCompletedNormally(f, v1); |
2278 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2279 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2280 |
– |
}} |
2281 |
– |
|
2282 |
– |
public void testRunAfterEither_exceptionalCompletion3() { |
2283 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2284 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2285 |
– |
{ |
2286 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2287 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2288 |
– |
final Noop r = new Noop(m); |
2413 |
|
final CFException ex = new CFException(); |
2414 |
+ |
final Noop[] rs = new Noop[6]; |
2415 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2416 |
|
|
2417 |
< |
g.completeExceptionally(ex); |
2418 |
< |
f.complete(v1); |
2419 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2417 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2418 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2419 |
> |
if (fFirst) { |
2420 |
> |
f.complete(v1); |
2421 |
> |
g.completeExceptionally(ex); |
2422 |
> |
} else { |
2423 |
> |
g.completeExceptionally(ex); |
2424 |
> |
f.complete(v1); |
2425 |
> |
} |
2426 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2427 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2428 |
|
|
2429 |
< |
// unspecified behavior |
2296 |
< |
Integer v; |
2429 |
> |
// unspecified behavior - both source completions available |
2430 |
|
try { |
2431 |
< |
assertNull(h.join()); |
2432 |
< |
r.assertInvoked(); |
2431 |
> |
assertEquals(null, h0.join()); |
2432 |
> |
rs[0].assertInvoked(); |
2433 |
|
} catch (CompletionException ok) { |
2434 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2435 |
< |
r.assertNotInvoked(); |
2434 |
> |
checkCompletedWithWrappedException(h0, ex); |
2435 |
> |
rs[0].assertNotInvoked(); |
2436 |
> |
} |
2437 |
> |
try { |
2438 |
> |
assertEquals(null, h1.join()); |
2439 |
> |
rs[1].assertInvoked(); |
2440 |
> |
} catch (CompletionException ok) { |
2441 |
> |
checkCompletedWithWrappedException(h1, ex); |
2442 |
> |
rs[1].assertNotInvoked(); |
2443 |
> |
} |
2444 |
> |
try { |
2445 |
> |
assertEquals(null, h2.join()); |
2446 |
> |
rs[2].assertInvoked(); |
2447 |
> |
} catch (CompletionException ok) { |
2448 |
> |
checkCompletedWithWrappedException(h2, ex); |
2449 |
> |
rs[2].assertNotInvoked(); |
2450 |
> |
} |
2451 |
> |
try { |
2452 |
> |
assertEquals(null, h3.join()); |
2453 |
> |
rs[3].assertInvoked(); |
2454 |
> |
} catch (CompletionException ok) { |
2455 |
> |
checkCompletedWithWrappedException(h3, ex); |
2456 |
> |
rs[3].assertNotInvoked(); |
2457 |
|
} |
2458 |
|
|
2305 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2459 |
|
checkCompletedNormally(f, v1); |
2460 |
+ |
checkCompletedExceptionally(g, ex); |
2461 |
|
}} |
2462 |
|
|
2463 |
< |
public void testRunAfterEither_exceptionalCompletion4() { |
2463 |
> |
/** |
2464 |
> |
* runAfterEither result completes exceptionally if either source cancelled |
2465 |
> |
*/ |
2466 |
> |
public void testRunAfterEither_sourceCancelled() { |
2467 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2468 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2469 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2470 |
|
{ |
2471 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2472 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2473 |
< |
final Noop r = new Noop(m); |
2474 |
< |
final CFException ex = new CFException(); |
2473 |
> |
final Noop[] rs = new Noop[6]; |
2474 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2475 |
> |
|
2476 |
> |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2477 |
> |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2478 |
> |
checkIncomplete(h0); |
2479 |
> |
checkIncomplete(h1); |
2480 |
> |
rs[0].assertNotInvoked(); |
2481 |
> |
rs[1].assertNotInvoked(); |
2482 |
> |
f.cancel(mayInterruptIfRunning); |
2483 |
> |
checkCompletedWithWrappedCancellationException(h0); |
2484 |
> |
checkCompletedWithWrappedCancellationException(h1); |
2485 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2486 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2487 |
> |
checkCompletedWithWrappedCancellationException(h2); |
2488 |
> |
checkCompletedWithWrappedCancellationException(h3); |
2489 |
|
|
2318 |
– |
f.completeExceptionally(ex); |
2490 |
|
g.complete(v1); |
2320 |
– |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2491 |
|
|
2492 |
< |
// unspecified behavior |
2493 |
< |
Integer v; |
2492 |
> |
// unspecified behavior - both source completions available |
2493 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2494 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2495 |
|
try { |
2496 |
< |
assertNull(h.join()); |
2497 |
< |
r.assertInvoked(); |
2496 |
> |
assertNull(h4.join()); |
2497 |
> |
rs[4].assertInvoked(); |
2498 |
|
} catch (CompletionException ok) { |
2499 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2500 |
< |
r.assertNotInvoked(); |
2499 |
> |
checkCompletedWithWrappedCancellationException(h4); |
2500 |
> |
rs[4].assertNotInvoked(); |
2501 |
> |
} |
2502 |
> |
try { |
2503 |
> |
assertNull(h5.join()); |
2504 |
> |
rs[5].assertInvoked(); |
2505 |
> |
} catch (CompletionException ok) { |
2506 |
> |
checkCompletedWithWrappedCancellationException(h5); |
2507 |
> |
rs[5].assertNotInvoked(); |
2508 |
|
} |
2509 |
|
|
2510 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2510 |
> |
checkCancelled(f); |
2511 |
|
checkCompletedNormally(g, v1); |
2512 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
2513 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
2514 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
2515 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
2516 |
+ |
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2517 |
|
}} |
2518 |
|
|
2519 |
|
/** |
2520 |
|
* runAfterEither result completes exceptionally if action does |
2521 |
|
*/ |
2522 |
< |
public void testRunAfterEither_actionFailed1() { |
2522 |
> |
public void testRunAfterEither_actionFailed() { |
2523 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2524 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2525 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2526 |
|
{ |
2527 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2528 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2529 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2530 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2529 |
> |
final FailingRunnable[] rs = new FailingRunnable[6]; |
2530 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m); |
2531 |
|
|
2532 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2533 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2534 |
|
f.complete(v1); |
2535 |
< |
checkCompletedWithWrappedCFException(h); |
2535 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2536 |
> |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2537 |
> |
checkCompletedWithWrappedCFException(h0); |
2538 |
> |
checkCompletedWithWrappedCFException(h1); |
2539 |
> |
checkCompletedWithWrappedCFException(h2); |
2540 |
> |
checkCompletedWithWrappedCFException(h3); |
2541 |
> |
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2542 |
|
g.complete(v2); |
2543 |
< |
checkCompletedNormally(f, v1); |
2544 |
< |
checkCompletedNormally(g, v2); |
2545 |
< |
}} |
2546 |
< |
|
2356 |
< |
public void testRunAfterEither_actionFailed2() { |
2357 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2358 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2359 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2360 |
< |
{ |
2361 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2362 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2363 |
< |
final FailingRunnable r = new FailingRunnable(m); |
2364 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2543 |
> |
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2544 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2545 |
> |
checkCompletedWithWrappedCFException(h4); |
2546 |
> |
checkCompletedWithWrappedCFException(h5); |
2547 |
|
|
2366 |
– |
g.complete(v2); |
2367 |
– |
checkCompletedWithWrappedCFException(h); |
2368 |
– |
f.complete(v1); |
2548 |
|
checkCompletedNormally(f, v1); |
2549 |
|
checkCompletedNormally(g, v2); |
2550 |
< |
}} |
2372 |
< |
|
2373 |
< |
/** |
2374 |
< |
* runAfterEither result completes exceptionally if either source cancelled |
2375 |
< |
*/ |
2376 |
< |
public void testRunAfterEither_sourceCancelled1() { |
2377 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2378 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2379 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2380 |
< |
{ |
2381 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2382 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2383 |
< |
final Noop r = new Noop(m); |
2384 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2385 |
< |
|
2386 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2387 |
< |
checkCompletedWithWrappedCancellationException(h); |
2388 |
< |
g.complete(v1); |
2389 |
< |
|
2390 |
< |
checkCancelled(f); |
2391 |
< |
r.assertNotInvoked(); |
2392 |
< |
checkCompletedNormally(g, v1); |
2393 |
< |
checkCompletedWithWrappedCancellationException(h); |
2394 |
< |
}} |
2395 |
< |
|
2396 |
< |
public void testRunAfterEither_sourceCancelled2() { |
2397 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2398 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2399 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2400 |
< |
{ |
2401 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2402 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2403 |
< |
final Noop r = new Noop(m); |
2404 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2405 |
< |
|
2406 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2407 |
< |
checkCompletedWithWrappedCancellationException(h); |
2408 |
< |
f.complete(v1); |
2409 |
< |
|
2410 |
< |
checkCancelled(g); |
2411 |
< |
r.assertNotInvoked(); |
2412 |
< |
checkCompletedNormally(f, v1); |
2413 |
< |
checkCompletedWithWrappedCancellationException(h); |
2414 |
< |
}} |
2415 |
< |
|
2416 |
< |
public void testRunAfterEither_sourceCancelled3() { |
2417 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2418 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2419 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2420 |
< |
{ |
2421 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2422 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2423 |
< |
final Noop r = new Noop(m); |
2424 |
< |
|
2425 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2426 |
< |
f.complete(v1); |
2427 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2428 |
< |
|
2429 |
< |
// unspecified behavior |
2430 |
< |
Integer v; |
2431 |
< |
try { |
2432 |
< |
assertNull(h.join()); |
2433 |
< |
r.assertInvoked(); |
2434 |
< |
} catch (CompletionException ok) { |
2435 |
< |
checkCompletedWithWrappedCancellationException(h); |
2436 |
< |
r.assertNotInvoked(); |
2437 |
< |
} |
2438 |
< |
|
2439 |
< |
checkCancelled(g); |
2440 |
< |
checkCompletedNormally(f, v1); |
2441 |
< |
}} |
2442 |
< |
|
2443 |
< |
public void testRunAfterEither_sourceCancelled4() { |
2444 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2445 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2446 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2447 |
< |
{ |
2448 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2449 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2450 |
< |
final Noop r = new Noop(m); |
2451 |
< |
|
2452 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2453 |
< |
g.complete(v1); |
2454 |
< |
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2455 |
< |
|
2456 |
< |
// unspecified behavior |
2457 |
< |
Integer v; |
2458 |
< |
try { |
2459 |
< |
assertNull(h.join()); |
2460 |
< |
r.assertInvoked(); |
2461 |
< |
} catch (CompletionException ok) { |
2462 |
< |
checkCompletedWithWrappedCancellationException(h); |
2463 |
< |
r.assertNotInvoked(); |
2464 |
< |
} |
2465 |
< |
|
2466 |
< |
checkCancelled(f); |
2467 |
< |
checkCompletedNormally(g, v1); |
2550 |
> |
for (int i = 0; i < 6; i++) rs[i].assertInvoked(); |
2551 |
|
}} |
2552 |
|
|
2553 |
|
/** |
2566 |
|
|
2567 |
|
checkCompletedNormally(g, inc(v1)); |
2568 |
|
checkCompletedNormally(f, v1); |
2569 |
< |
r.assertInvoked(); |
2569 |
> |
r.assertValue(v1); |
2570 |
|
}} |
2571 |
|
|
2572 |
|
/** |
2584 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2585 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2586 |
|
|
2587 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2588 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2587 |
> |
checkCompletedWithWrappedException(g, ex); |
2588 |
> |
checkCompletedExceptionally(f, ex); |
2589 |
|
r.assertNotInvoked(); |
2590 |
|
}} |
2591 |
|
|
2856 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2857 |
|
(f, |
2858 |
|
(Integer x, Throwable t) -> { |
2859 |
+ |
m.checkExecutionMode(); |
2860 |
|
threadAssertSame(x, v1); |
2861 |
|
threadAssertNull(t); |
2862 |
|
a.getAndIncrement(); |
2884 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2885 |
|
(f, |
2886 |
|
(Integer x, Throwable t) -> { |
2887 |
+ |
m.checkExecutionMode(); |
2888 |
|
threadAssertNull(x); |
2889 |
|
threadAssertSame(t, ex); |
2890 |
|
a.getAndIncrement(); |
2891 |
|
}); |
2892 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2893 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2894 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2893 |
> |
checkCompletedExceptionally(f, ex); |
2894 |
> |
checkCompletedWithWrappedException(g, ex); |
2895 |
|
assertEquals(1, a.get()); |
2896 |
|
}} |
2897 |
|
|
2910 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2911 |
|
(f, |
2912 |
|
(Integer x, Throwable t) -> { |
2913 |
+ |
m.checkExecutionMode(); |
2914 |
|
threadAssertNull(x); |
2915 |
|
threadAssertTrue(t instanceof CancellationException); |
2916 |
|
a.getAndIncrement(); |
2917 |
|
}); |
2918 |
|
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2919 |
|
|
2834 |
– |
//try { g.join(); } catch (Throwable t) { throw new Error(t); } |
2920 |
|
checkCompletedWithWrappedCancellationException(g); |
2921 |
|
checkCancelled(f); |
2922 |
|
assertEquals(1, a.get()); |
2938 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2939 |
|
(f, |
2940 |
|
(Integer x, Throwable t) -> { |
2941 |
+ |
m.checkExecutionMode(); |
2942 |
|
threadAssertSame(x, v1); |
2943 |
|
threadAssertNull(t); |
2944 |
|
a.getAndIncrement(); |
2946 |
|
}); |
2947 |
|
if (createIncomplete) f.complete(v1); |
2948 |
|
checkCompletedNormally(f, v1); |
2949 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2949 |
> |
checkCompletedWithWrappedException(g, ex); |
2950 |
|
assertEquals(1, a.get()); |
2951 |
|
}} |
2952 |
|
|
2969 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2970 |
|
(f, |
2971 |
|
(Integer x, Throwable t) -> { |
2972 |
+ |
m.checkExecutionMode(); |
2973 |
|
threadAssertSame(t, ex1); |
2974 |
|
threadAssertNull(x); |
2975 |
|
a.getAndIncrement(); |
2977 |
|
}); |
2978 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
2979 |
|
|
2980 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
2981 |
< |
checkCompletedWithWrappedCFException(g, ex1); |
2980 |
> |
checkCompletedExceptionally(f, ex1); |
2981 |
> |
checkCompletedWithWrappedException(g, ex1); |
2982 |
|
assertEquals(1, a.get()); |
2983 |
|
}} |
2984 |
|
|