57 |
|
} |
58 |
|
|
59 |
|
<T> void checkCompletedNormally(CompletableFuture<T> f, T value) { |
60 |
< |
try { |
61 |
< |
assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS)); |
62 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
60 |
> |
checkTimedGet(f, value); |
61 |
> |
|
62 |
|
try { |
63 |
|
assertEquals(value, f.join()); |
64 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
75 |
|
} |
76 |
|
|
77 |
|
void checkCompletedWithWrappedCFException(CompletableFuture<?> f) { |
78 |
+ |
long startTime = System.nanoTime(); |
79 |
+ |
long timeoutMillis = LONG_DELAY_MS; |
80 |
|
try { |
81 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
81 |
> |
f.get(timeoutMillis, MILLISECONDS); |
82 |
|
shouldThrow(); |
83 |
|
} catch (ExecutionException success) { |
84 |
|
assertTrue(success.getCause() instanceof CFException); |
85 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
86 |
+ |
assertTrue(millisElapsedSince(startTime) < timeoutMillis/2); |
87 |
+ |
|
88 |
|
try { |
89 |
|
f.join(); |
90 |
|
shouldThrow(); |
110 |
|
|
111 |
|
<U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f, |
112 |
|
Throwable ex) { |
113 |
+ |
long startTime = System.nanoTime(); |
114 |
+ |
long timeoutMillis = LONG_DELAY_MS; |
115 |
|
try { |
116 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
116 |
> |
f.get(timeoutMillis, MILLISECONDS); |
117 |
|
shouldThrow(); |
118 |
|
} catch (ExecutionException success) { |
119 |
|
assertSame(ex, success.getCause()); |
120 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
121 |
+ |
assertTrue(millisElapsedSince(startTime) < timeoutMillis/2); |
122 |
+ |
|
123 |
|
try { |
124 |
|
f.join(); |
125 |
|
shouldThrow(); |
165 |
|
} |
166 |
|
|
167 |
|
void checkCancelled(CompletableFuture<?> f) { |
168 |
+ |
long startTime = System.nanoTime(); |
169 |
+ |
long timeoutMillis = LONG_DELAY_MS; |
170 |
|
try { |
171 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
171 |
> |
f.get(timeoutMillis, MILLISECONDS); |
172 |
|
shouldThrow(); |
173 |
|
} catch (CancellationException success) { |
174 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
175 |
+ |
assertTrue(millisElapsedSince(startTime) < timeoutMillis/2); |
176 |
+ |
|
177 |
|
try { |
178 |
|
f.join(); |
179 |
|
shouldThrow(); |
194 |
|
} |
195 |
|
|
196 |
|
void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) { |
197 |
+ |
long startTime = System.nanoTime(); |
198 |
+ |
long timeoutMillis = LONG_DELAY_MS; |
199 |
|
try { |
200 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
200 |
> |
f.get(timeoutMillis, MILLISECONDS); |
201 |
|
shouldThrow(); |
202 |
|
} catch (ExecutionException success) { |
203 |
|
assertTrue(success.getCause() instanceof CancellationException); |
204 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
205 |
+ |
assertTrue(millisElapsedSince(startTime) < timeoutMillis/2); |
206 |
+ |
|
207 |
|
try { |
208 |
|
f.join(); |
209 |
|
shouldThrow(); |
584 |
|
} |
585 |
|
} |
586 |
|
|
587 |
+ |
static final boolean defaultExecutorIsCommonPool |
588 |
+ |
= ForkJoinPool.getCommonPoolParallelism() > 1; |
589 |
+ |
|
590 |
|
/** |
591 |
|
* Permits the testing of parallel code for the 3 different |
592 |
|
* execution modes without copy/pasting all the test methods. |
593 |
|
*/ |
594 |
|
enum ExecutionMode { |
595 |
< |
DEFAULT { |
595 |
> |
SYNC { |
596 |
|
public void checkExecutionMode() { |
597 |
|
assertFalse(ThreadExecutor.startedCurrentThread()); |
598 |
|
assertNull(ForkJoinTask.getPool()); |
668 |
|
|
669 |
|
ASYNC { |
670 |
|
public void checkExecutionMode() { |
671 |
< |
assertSame(ForkJoinPool.commonPool(), |
672 |
< |
ForkJoinTask.getPool()); |
671 |
> |
assertEquals(defaultExecutorIsCommonPool, |
672 |
> |
(ForkJoinPool.commonPool() == ForkJoinTask.getPool())); |
673 |
|
} |
674 |
|
public CompletableFuture<Void> runAsync(Runnable a) { |
675 |
|
return CompletableFuture.runAsync(a); |
893 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
894 |
|
final CompletableFuture<Integer> g = f.exceptionally |
895 |
|
((Throwable t) -> { |
896 |
< |
ExecutionMode.DEFAULT.checkExecutionMode(); |
896 |
> |
ExecutionMode.SYNC.checkExecutionMode(); |
897 |
|
threadAssertSame(t, ex); |
898 |
|
a.getAndIncrement(); |
899 |
|
return v1; |
915 |
|
if (!createIncomplete) f.completeExceptionally(ex1); |
916 |
|
final CompletableFuture<Integer> g = f.exceptionally |
917 |
|
((Throwable t) -> { |
918 |
< |
ExecutionMode.DEFAULT.checkExecutionMode(); |
918 |
> |
ExecutionMode.SYNC.checkExecutionMode(); |
919 |
|
threadAssertSame(t, ex1); |
920 |
|
a.getAndIncrement(); |
921 |
|
throw ex2; |
1282 |
|
*/ |
1283 |
|
public void testThenRun_normalCompletion() { |
1284 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1267 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1285 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1286 |
|
{ |
1287 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1288 |
< |
final Noop r = new Noop(m); |
1289 |
< |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1273 |
< |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1274 |
< |
if (createIncomplete) { |
1275 |
< |
checkIncomplete(g); |
1276 |
< |
assertTrue(f.complete(v1)); |
1277 |
< |
} |
1288 |
> |
final Noop[] rs = new Noop[6]; |
1289 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
1290 |
|
|
1291 |
< |
checkCompletedNormally(g, null); |
1291 |
> |
final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]); |
1292 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]); |
1293 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]); |
1294 |
> |
checkIncomplete(h0); |
1295 |
> |
checkIncomplete(h1); |
1296 |
> |
checkIncomplete(h2); |
1297 |
> |
assertTrue(f.complete(v1)); |
1298 |
> |
final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]); |
1299 |
> |
final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]); |
1300 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]); |
1301 |
> |
|
1302 |
> |
checkCompletedNormally(h0, null); |
1303 |
> |
checkCompletedNormally(h1, null); |
1304 |
> |
checkCompletedNormally(h2, null); |
1305 |
> |
checkCompletedNormally(h3, null); |
1306 |
> |
checkCompletedNormally(h4, null); |
1307 |
> |
checkCompletedNormally(h5, null); |
1308 |
|
checkCompletedNormally(f, v1); |
1309 |
< |
r.assertInvoked(); |
1309 |
> |
for (Noop r : rs) r.assertInvoked(); |
1310 |
|
}} |
1311 |
|
|
1312 |
|
/** |
1315 |
|
*/ |
1316 |
|
public void testThenRun_exceptionalCompletion() { |
1317 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1290 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1318 |
|
{ |
1319 |
|
final CFException ex = new CFException(); |
1320 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1321 |
< |
final Noop r = new Noop(m); |
1322 |
< |
if (!createIncomplete) f.completeExceptionally(ex); |
1296 |
< |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1297 |
< |
if (createIncomplete) { |
1298 |
< |
checkIncomplete(g); |
1299 |
< |
f.completeExceptionally(ex); |
1300 |
< |
} |
1321 |
> |
final Noop[] rs = new Noop[6]; |
1322 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
1323 |
|
|
1324 |
< |
checkCompletedWithWrappedException(g, ex); |
1324 |
> |
final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]); |
1325 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]); |
1326 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]); |
1327 |
> |
checkIncomplete(h0); |
1328 |
> |
checkIncomplete(h1); |
1329 |
> |
checkIncomplete(h2); |
1330 |
> |
assertTrue(f.completeExceptionally(ex)); |
1331 |
> |
final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]); |
1332 |
> |
final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]); |
1333 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]); |
1334 |
> |
|
1335 |
> |
checkCompletedWithWrappedException(h0, ex); |
1336 |
> |
checkCompletedWithWrappedException(h1, ex); |
1337 |
> |
checkCompletedWithWrappedException(h2, ex); |
1338 |
> |
checkCompletedWithWrappedException(h3, ex); |
1339 |
> |
checkCompletedWithWrappedException(h4, ex); |
1340 |
> |
checkCompletedWithWrappedException(h5, ex); |
1341 |
|
checkCompletedExceptionally(f, ex); |
1342 |
< |
r.assertNotInvoked(); |
1342 |
> |
for (Noop r : rs) r.assertNotInvoked(); |
1343 |
|
}} |
1344 |
|
|
1345 |
|
/** |
1347 |
|
*/ |
1348 |
|
public void testThenRun_sourceCancelled() { |
1349 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1312 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1350 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1351 |
|
{ |
1352 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1353 |
< |
final Noop r = new Noop(m); |
1354 |
< |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1318 |
< |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1319 |
< |
if (createIncomplete) { |
1320 |
< |
checkIncomplete(g); |
1321 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1322 |
< |
} |
1353 |
> |
final Noop[] rs = new Noop[6]; |
1354 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
1355 |
|
|
1356 |
< |
checkCompletedWithWrappedCancellationException(g); |
1356 |
> |
final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]); |
1357 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]); |
1358 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]); |
1359 |
> |
checkIncomplete(h0); |
1360 |
> |
checkIncomplete(h1); |
1361 |
> |
checkIncomplete(h2); |
1362 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1363 |
> |
final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]); |
1364 |
> |
final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]); |
1365 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]); |
1366 |
> |
|
1367 |
> |
checkCompletedWithWrappedCancellationException(h0); |
1368 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1369 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1370 |
> |
checkCompletedWithWrappedCancellationException(h3); |
1371 |
> |
checkCompletedWithWrappedCancellationException(h4); |
1372 |
> |
checkCompletedWithWrappedCancellationException(h5); |
1373 |
|
checkCancelled(f); |
1374 |
< |
r.assertNotInvoked(); |
1374 |
> |
for (Noop r : rs) r.assertNotInvoked(); |
1375 |
|
}} |
1376 |
|
|
1377 |
|
/** |
1379 |
|
*/ |
1380 |
|
public void testThenRun_actionFailed() { |
1381 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1334 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1382 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1383 |
|
{ |
1384 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1385 |
< |
final FailingRunnable r = new FailingRunnable(m); |
1386 |
< |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1340 |
< |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1341 |
< |
if (createIncomplete) { |
1342 |
< |
checkIncomplete(g); |
1343 |
< |
assertTrue(f.complete(v1)); |
1344 |
< |
} |
1385 |
> |
final FailingRunnable[] rs = new FailingRunnable[6]; |
1386 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m); |
1387 |
|
|
1388 |
< |
checkCompletedWithWrappedCFException(g); |
1388 |
> |
final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]); |
1389 |
> |
final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]); |
1390 |
> |
final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]); |
1391 |
> |
assertTrue(f.complete(v1)); |
1392 |
> |
final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]); |
1393 |
> |
final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]); |
1394 |
> |
final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]); |
1395 |
> |
|
1396 |
> |
checkCompletedWithWrappedCFException(h0); |
1397 |
> |
checkCompletedWithWrappedCFException(h1); |
1398 |
> |
checkCompletedWithWrappedCFException(h2); |
1399 |
> |
checkCompletedWithWrappedCFException(h3); |
1400 |
> |
checkCompletedWithWrappedCFException(h4); |
1401 |
> |
checkCompletedWithWrappedCFException(h5); |
1402 |
|
checkCompletedNormally(f, v1); |
1403 |
|
}} |
1404 |
|
|
1407 |
|
*/ |
1408 |
|
public void testThenApply_normalCompletion() { |
1409 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1355 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1410 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1411 |
|
{ |
1412 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1413 |
< |
final IncFunction r = new IncFunction(m); |
1414 |
< |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1361 |
< |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1362 |
< |
if (createIncomplete) { |
1363 |
< |
checkIncomplete(g); |
1364 |
< |
assertTrue(f.complete(v1)); |
1365 |
< |
} |
1413 |
> |
final IncFunction[] rs = new IncFunction[4]; |
1414 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1415 |
|
|
1416 |
< |
checkCompletedNormally(g, inc(v1)); |
1416 |
> |
final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]); |
1417 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]); |
1418 |
> |
checkIncomplete(h0); |
1419 |
> |
checkIncomplete(h1); |
1420 |
> |
assertTrue(f.complete(v1)); |
1421 |
> |
final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]); |
1422 |
> |
final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]); |
1423 |
> |
|
1424 |
> |
checkCompletedNormally(h0, inc(v1)); |
1425 |
> |
checkCompletedNormally(h1, inc(v1)); |
1426 |
> |
checkCompletedNormally(h2, inc(v1)); |
1427 |
> |
checkCompletedNormally(h3, inc(v1)); |
1428 |
|
checkCompletedNormally(f, v1); |
1429 |
< |
r.assertValue(inc(v1)); |
1429 |
> |
for (IncFunction r : rs) r.assertValue(inc(v1)); |
1430 |
|
}} |
1431 |
|
|
1432 |
|
/** |
1435 |
|
*/ |
1436 |
|
public void testThenApply_exceptionalCompletion() { |
1437 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1378 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1438 |
|
{ |
1439 |
|
final CFException ex = new CFException(); |
1440 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1441 |
< |
final IncFunction r = new IncFunction(m); |
1442 |
< |
if (!createIncomplete) f.completeExceptionally(ex); |
1384 |
< |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1385 |
< |
if (createIncomplete) { |
1386 |
< |
checkIncomplete(g); |
1387 |
< |
f.completeExceptionally(ex); |
1388 |
< |
} |
1441 |
> |
final IncFunction[] rs = new IncFunction[4]; |
1442 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1443 |
|
|
1444 |
< |
checkCompletedWithWrappedException(g, ex); |
1444 |
> |
final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]); |
1445 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]); |
1446 |
> |
assertTrue(f.completeExceptionally(ex)); |
1447 |
> |
final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]); |
1448 |
> |
final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]); |
1449 |
> |
|
1450 |
> |
checkCompletedWithWrappedException(h0, ex); |
1451 |
> |
checkCompletedWithWrappedException(h1, ex); |
1452 |
> |
checkCompletedWithWrappedException(h2, ex); |
1453 |
> |
checkCompletedWithWrappedException(h3, ex); |
1454 |
|
checkCompletedExceptionally(f, ex); |
1455 |
< |
r.assertNotInvoked(); |
1455 |
> |
for (IncFunction r : rs) r.assertNotInvoked(); |
1456 |
|
}} |
1457 |
|
|
1458 |
|
/** |
1460 |
|
*/ |
1461 |
|
public void testThenApply_sourceCancelled() { |
1462 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1400 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1463 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1464 |
|
{ |
1465 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1466 |
< |
final IncFunction r = new IncFunction(m); |
1467 |
< |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1406 |
< |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1407 |
< |
if (createIncomplete) { |
1408 |
< |
checkIncomplete(g); |
1409 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1410 |
< |
} |
1466 |
> |
final IncFunction[] rs = new IncFunction[4]; |
1467 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1468 |
|
|
1469 |
< |
checkCompletedWithWrappedCancellationException(g); |
1469 |
> |
final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]); |
1470 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]); |
1471 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1472 |
> |
final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]); |
1473 |
> |
final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]); |
1474 |
> |
|
1475 |
> |
checkCompletedWithWrappedCancellationException(h0); |
1476 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1477 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1478 |
> |
checkCompletedWithWrappedCancellationException(h3); |
1479 |
|
checkCancelled(f); |
1480 |
< |
r.assertNotInvoked(); |
1480 |
> |
for (IncFunction r : rs) r.assertNotInvoked(); |
1481 |
|
}} |
1482 |
|
|
1483 |
|
/** |
1485 |
|
*/ |
1486 |
|
public void testThenApply_actionFailed() { |
1487 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1422 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1488 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1489 |
|
{ |
1490 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1491 |
< |
final FailingFunction r = new FailingFunction(m); |
1492 |
< |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1428 |
< |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1429 |
< |
if (createIncomplete) { |
1430 |
< |
checkIncomplete(g); |
1431 |
< |
assertTrue(f.complete(v1)); |
1432 |
< |
} |
1491 |
> |
final FailingFunction[] rs = new FailingFunction[4]; |
1492 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingFunction(m); |
1493 |
|
|
1494 |
< |
checkCompletedWithWrappedCFException(g); |
1494 |
> |
final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]); |
1495 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]); |
1496 |
> |
assertTrue(f.complete(v1)); |
1497 |
> |
final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]); |
1498 |
> |
final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]); |
1499 |
> |
|
1500 |
> |
checkCompletedWithWrappedCFException(h0); |
1501 |
> |
checkCompletedWithWrappedCFException(h1); |
1502 |
> |
checkCompletedWithWrappedCFException(h2); |
1503 |
> |
checkCompletedWithWrappedCFException(h3); |
1504 |
|
checkCompletedNormally(f, v1); |
1505 |
|
}} |
1506 |
|
|
1509 |
|
*/ |
1510 |
|
public void testThenAccept_normalCompletion() { |
1511 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1443 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1512 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1513 |
|
{ |
1514 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1515 |
< |
final NoopConsumer r = new NoopConsumer(m); |
1516 |
< |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1449 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1450 |
< |
if (createIncomplete) { |
1451 |
< |
checkIncomplete(g); |
1452 |
< |
assertTrue(f.complete(v1)); |
1453 |
< |
} |
1515 |
> |
final NoopConsumer[] rs = new NoopConsumer[4]; |
1516 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1517 |
|
|
1518 |
< |
checkCompletedNormally(g, null); |
1519 |
< |
r.assertValue(v1); |
1518 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1519 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1520 |
> |
checkIncomplete(h0); |
1521 |
> |
checkIncomplete(h1); |
1522 |
> |
assertTrue(f.complete(v1)); |
1523 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1524 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1525 |
> |
|
1526 |
> |
checkCompletedNormally(h0, null); |
1527 |
> |
checkCompletedNormally(h1, null); |
1528 |
> |
checkCompletedNormally(h2, null); |
1529 |
> |
checkCompletedNormally(h3, null); |
1530 |
|
checkCompletedNormally(f, v1); |
1531 |
+ |
for (NoopConsumer r : rs) r.assertValue(v1); |
1532 |
|
}} |
1533 |
|
|
1534 |
|
/** |
1537 |
|
*/ |
1538 |
|
public void testThenAccept_exceptionalCompletion() { |
1539 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1466 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1540 |
|
{ |
1541 |
|
final CFException ex = new CFException(); |
1542 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1543 |
< |
final NoopConsumer r = new NoopConsumer(m); |
1544 |
< |
if (!createIncomplete) f.completeExceptionally(ex); |
1472 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1473 |
< |
if (createIncomplete) { |
1474 |
< |
checkIncomplete(g); |
1475 |
< |
f.completeExceptionally(ex); |
1476 |
< |
} |
1543 |
> |
final NoopConsumer[] rs = new NoopConsumer[4]; |
1544 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1545 |
|
|
1546 |
< |
checkCompletedWithWrappedException(g, ex); |
1546 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1547 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1548 |
> |
assertTrue(f.completeExceptionally(ex)); |
1549 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1550 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1551 |
> |
|
1552 |
> |
checkCompletedWithWrappedException(h0, ex); |
1553 |
> |
checkCompletedWithWrappedException(h1, ex); |
1554 |
> |
checkCompletedWithWrappedException(h2, ex); |
1555 |
> |
checkCompletedWithWrappedException(h3, ex); |
1556 |
|
checkCompletedExceptionally(f, ex); |
1557 |
< |
r.assertNotInvoked(); |
1557 |
> |
for (NoopConsumer r : rs) r.assertNotInvoked(); |
1558 |
|
}} |
1559 |
|
|
1560 |
|
/** |
1562 |
|
*/ |
1563 |
|
public void testThenAccept_sourceCancelled() { |
1564 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1488 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1565 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1566 |
|
{ |
1567 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1568 |
< |
final NoopConsumer r = new NoopConsumer(m); |
1569 |
< |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1494 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1495 |
< |
if (createIncomplete) { |
1496 |
< |
checkIncomplete(g); |
1497 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1498 |
< |
} |
1568 |
> |
final NoopConsumer[] rs = new NoopConsumer[4]; |
1569 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
1570 |
|
|
1571 |
< |
checkCompletedWithWrappedCancellationException(g); |
1571 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1572 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1573 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1574 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1575 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1576 |
> |
|
1577 |
> |
checkCompletedWithWrappedCancellationException(h0); |
1578 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1579 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1580 |
> |
checkCompletedWithWrappedCancellationException(h3); |
1581 |
|
checkCancelled(f); |
1582 |
< |
r.assertNotInvoked(); |
1582 |
> |
for (NoopConsumer r : rs) r.assertNotInvoked(); |
1583 |
|
}} |
1584 |
|
|
1585 |
|
/** |
1587 |
|
*/ |
1588 |
|
public void testThenAccept_actionFailed() { |
1589 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1510 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
1590 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1591 |
|
{ |
1592 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1593 |
< |
final FailingConsumer r = new FailingConsumer(m); |
1594 |
< |
if (!createIncomplete) f.complete(v1); |
1516 |
< |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1517 |
< |
if (createIncomplete) { |
1518 |
< |
checkIncomplete(g); |
1519 |
< |
f.complete(v1); |
1520 |
< |
} |
1593 |
> |
final FailingConsumer[] rs = new FailingConsumer[4]; |
1594 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m); |
1595 |
|
|
1596 |
< |
checkCompletedWithWrappedCFException(g); |
1596 |
> |
final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]); |
1597 |
> |
final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]); |
1598 |
> |
assertTrue(f.complete(v1)); |
1599 |
> |
final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]); |
1600 |
> |
final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]); |
1601 |
> |
|
1602 |
> |
checkCompletedWithWrappedCFException(h0); |
1603 |
> |
checkCompletedWithWrappedCFException(h1); |
1604 |
> |
checkCompletedWithWrappedCFException(h2); |
1605 |
> |
checkCompletedWithWrappedCFException(h3); |
1606 |
|
checkCompletedNormally(f, v1); |
1607 |
|
}} |
1608 |
|
|
1618 |
|
{ |
1619 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1620 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1621 |
< |
final SubtractFunction r1 = new SubtractFunction(m); |
1622 |
< |
final SubtractFunction r2 = new SubtractFunction(m); |
1540 |
< |
final SubtractFunction r3 = new SubtractFunction(m); |
1621 |
> |
final SubtractFunction[] rs = new SubtractFunction[6]; |
1622 |
> |
for (int i = 0; i < rs.length; i++) rs[i] = new SubtractFunction(m); |
1623 |
|
|
1624 |
|
final CompletableFuture<Integer> fst = fFirst ? f : g; |
1625 |
|
final CompletableFuture<Integer> snd = !fFirst ? f : g; |
1626 |
|
final Integer w1 = fFirst ? v1 : v2; |
1627 |
|
final Integer w2 = !fFirst ? v1 : v2; |
1628 |
|
|
1629 |
< |
final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1); |
1629 |
> |
final CompletableFuture<Integer> h0 = m.thenCombine(f, g, rs[0]); |
1630 |
> |
final CompletableFuture<Integer> h1 = m.thenCombine(fst, fst, rs[1]); |
1631 |
|
assertTrue(fst.complete(w1)); |
1632 |
< |
final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2); |
1633 |
< |
checkIncomplete(h1); |
1634 |
< |
checkIncomplete(h2); |
1635 |
< |
r1.assertNotInvoked(); |
1636 |
< |
r2.assertNotInvoked(); |
1632 |
> |
final CompletableFuture<Integer> h2 = m.thenCombine(f, g, rs[2]); |
1633 |
> |
final CompletableFuture<Integer> h3 = m.thenCombine(fst, fst, rs[3]); |
1634 |
> |
checkIncomplete(h0); rs[0].assertNotInvoked(); |
1635 |
> |
checkIncomplete(h2); rs[2].assertNotInvoked(); |
1636 |
> |
checkCompletedNormally(h1, subtract(w1, w1)); |
1637 |
> |
checkCompletedNormally(h3, subtract(w1, w1)); |
1638 |
> |
rs[1].assertValue(subtract(w1, w1)); |
1639 |
> |
rs[3].assertValue(subtract(w1, w1)); |
1640 |
|
assertTrue(snd.complete(w2)); |
1641 |
< |
final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3); |
1641 |
> |
final CompletableFuture<Integer> h4 = m.thenCombine(f, g, rs[4]); |
1642 |
|
|
1643 |
< |
checkCompletedNormally(h1, subtract(v1, v2)); |
1643 |
> |
checkCompletedNormally(h0, subtract(v1, v2)); |
1644 |
|
checkCompletedNormally(h2, subtract(v1, v2)); |
1645 |
< |
checkCompletedNormally(h3, subtract(v1, v2)); |
1646 |
< |
r1.assertValue(subtract(v1, v2)); |
1647 |
< |
r2.assertValue(subtract(v1, v2)); |
1648 |
< |
r3.assertValue(subtract(v1, v2)); |
1645 |
> |
checkCompletedNormally(h4, subtract(v1, v2)); |
1646 |
> |
rs[0].assertValue(subtract(v1, v2)); |
1647 |
> |
rs[2].assertValue(subtract(v1, v2)); |
1648 |
> |
rs[4].assertValue(subtract(v1, v2)); |
1649 |
> |
|
1650 |
|
checkCompletedNormally(f, v1); |
1651 |
|
checkCompletedNormally(g, v2); |
1652 |
|
}} |
3009 |
|
* when all components complete normally |
3010 |
|
*/ |
3011 |
|
public void testAllOf_normal() throws Exception { |
3012 |
< |
for (int k = 1; k < 20; k++) { |
3012 |
> |
for (int k = 1; k < 10; k++) { |
3013 |
|
CompletableFuture<Integer>[] fs |
3014 |
|
= (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
3015 |
|
for (int i = 0; i < k; i++) |
3026 |
|
} |
3027 |
|
|
3028 |
|
public void testAllOf_backwards() throws Exception { |
3029 |
< |
for (int k = 1; k < 20; k++) { |
3029 |
> |
for (int k = 1; k < 10; k++) { |
3030 |
|
CompletableFuture<Integer>[] fs |
3031 |
|
= (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
3032 |
|
for (int i = 0; i < k; i++) |
3042 |
|
} |
3043 |
|
} |
3044 |
|
|
3045 |
+ |
public void testAllOf_exceptional() throws Exception { |
3046 |
+ |
for (int k = 1; k < 10; k++) { |
3047 |
+ |
CompletableFuture<Integer>[] fs |
3048 |
+ |
= (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
3049 |
+ |
CFException ex = new CFException(); |
3050 |
+ |
for (int i = 0; i < k; i++) |
3051 |
+ |
fs[i] = new CompletableFuture<>(); |
3052 |
+ |
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
3053 |
+ |
for (int i = 0; i < k; i++) { |
3054 |
+ |
checkIncomplete(f); |
3055 |
+ |
checkIncomplete(CompletableFuture.allOf(fs)); |
3056 |
+ |
if (i != k/2) { |
3057 |
+ |
fs[i].complete(i); |
3058 |
+ |
checkCompletedNormally(fs[i], i); |
3059 |
+ |
} else { |
3060 |
+ |
fs[i].completeExceptionally(ex); |
3061 |
+ |
checkCompletedExceptionally(fs[i], ex); |
3062 |
+ |
} |
3063 |
+ |
} |
3064 |
+ |
checkCompletedWithWrappedException(f, ex); |
3065 |
+ |
checkCompletedWithWrappedException(CompletableFuture.allOf(fs), ex); |
3066 |
+ |
} |
3067 |
+ |
} |
3068 |
+ |
|
3069 |
|
/** |
3070 |
|
* anyOf(no component futures) returns an incomplete future |
3071 |
|
*/ |
3120 |
|
public void testAnyOf_exceptional() throws Exception { |
3121 |
|
for (int k = 0; k < 10; k++) { |
3122 |
|
CompletableFuture[] fs = new CompletableFuture[k]; |
3123 |
< |
for (int i = 0; i < k; i++) |
3123 |
> |
CFException[] exs = new CFException[k]; |
3124 |
> |
for (int i = 0; i < k; i++) { |
3125 |
|
fs[i] = new CompletableFuture<>(); |
3126 |
+ |
exs[i] = new CFException(); |
3127 |
+ |
} |
3128 |
|
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
3129 |
|
checkIncomplete(f); |
3130 |
|
for (int i = 0; i < k; i++) { |
3131 |
< |
fs[i].completeExceptionally(new CFException()); |
3132 |
< |
checkCompletedWithWrappedCFException(f); |
3131 |
> |
fs[i].completeExceptionally(exs[i]); |
3132 |
> |
checkCompletedWithWrappedException(f, exs[0]); |
3133 |
> |
checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs)); |
3134 |
> |
} |
3135 |
> |
} |
3136 |
> |
} |
3137 |
> |
|
3138 |
> |
public void testAnyOf_exceptional_backwards() throws Exception { |
3139 |
> |
for (int k = 0; k < 10; k++) { |
3140 |
> |
CompletableFuture[] fs = new CompletableFuture[k]; |
3141 |
> |
CFException[] exs = new CFException[k]; |
3142 |
> |
for (int i = 0; i < k; i++) { |
3143 |
> |
fs[i] = new CompletableFuture<>(); |
3144 |
> |
exs[i] = new CFException(); |
3145 |
> |
} |
3146 |
> |
CompletableFuture<Object> f = CompletableFuture.anyOf(fs); |
3147 |
> |
checkIncomplete(f); |
3148 |
> |
for (int i = k - 1; i >= 0; i--) { |
3149 |
> |
fs[i].completeExceptionally(exs[i]); |
3150 |
> |
checkCompletedWithWrappedException(f, exs[k - 1]); |
3151 |
|
checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs)); |
3152 |
|
} |
3153 |
|
} |
3166 |
|
Runnable[] throwingActions = { |
3167 |
|
() -> CompletableFuture.supplyAsync(null), |
3168 |
|
() -> CompletableFuture.supplyAsync(null, exec), |
3169 |
< |
() -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.DEFAULT, 42), null), |
3169 |
> |
() -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.SYNC, 42), null), |
3170 |
|
|
3171 |
|
() -> CompletableFuture.runAsync(null), |
3172 |
|
() -> CompletableFuture.runAsync(null, exec), |
3290 |
|
final CompletableFuture<Integer> v42 = CompletableFuture.completedFuture(42); |
3291 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
3292 |
|
|
3293 |
< |
List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> dependentFactories |
3293 |
> |
List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> funs |
3294 |
|
= new ArrayList<>(); |
3295 |
|
|
3296 |
< |
dependentFactories.add((y) -> m.thenRun(y, new Noop(m))); |
3297 |
< |
dependentFactories.add((y) -> m.thenAccept(y, new NoopConsumer(m))); |
3298 |
< |
dependentFactories.add((y) -> m.thenApply(y, new IncFunction(m))); |
3296 |
> |
funs.add((y) -> m.thenRun(y, new Noop(m))); |
3297 |
> |
funs.add((y) -> m.thenAccept(y, new NoopConsumer(m))); |
3298 |
> |
funs.add((y) -> m.thenApply(y, new IncFunction(m))); |
3299 |
|
|
3300 |
< |
dependentFactories.add((y) -> m.runAfterEither(y, incomplete, new Noop(m))); |
3301 |
< |
dependentFactories.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m))); |
3302 |
< |
dependentFactories.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m))); |
3300 |
> |
funs.add((y) -> m.runAfterEither(y, incomplete, new Noop(m))); |
3301 |
> |
funs.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m))); |
3302 |
> |
funs.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m))); |
3303 |
|
|
3304 |
< |
dependentFactories.add((y) -> m.runAfterBoth(y, v42, new Noop(m))); |
3305 |
< |
dependentFactories.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m))); |
3306 |
< |
dependentFactories.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m))); |
3304 |
> |
funs.add((y) -> m.runAfterBoth(y, v42, new Noop(m))); |
3305 |
> |
funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m))); |
3306 |
> |
funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m))); |
3307 |
|
|
3308 |
< |
dependentFactories.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {})); |
3308 |
> |
funs.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {})); |
3309 |
|
|
3310 |
< |
dependentFactories.add((y) -> m.thenCompose(y, new CompletableFutureInc(m))); |
3310 |
> |
funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m))); |
3311 |
|
|
3312 |
< |
dependentFactories.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42})); |
3313 |
< |
dependentFactories.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete})); |
3312 |
> |
funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42})); |
3313 |
> |
funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete})); |
3314 |
|
|
3315 |
|
for (Function<CompletableFuture<Integer>, CompletableFuture<?>> |
3316 |
< |
dependentFactory : dependentFactories) { |
3316 |
> |
fun : funs) { |
3317 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3318 |
|
f.completeExceptionally(ex); |
3319 |
|
CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m)); |
3320 |
|
checkCompletedWithWrappedException(src, ex); |
3321 |
< |
CompletableFuture<?> dep = dependentFactory.apply(src); |
3321 |
> |
CompletableFuture<?> dep = fun.apply(src); |
3322 |
|
checkCompletedWithWrappedException(dep, ex); |
3323 |
|
assertSame(resultOf(src), resultOf(dep)); |
3324 |
|
} |
3325 |
|
|
3326 |
|
for (Function<CompletableFuture<Integer>, CompletableFuture<?>> |
3327 |
< |
dependentFactory : dependentFactories) { |
3327 |
> |
fun : funs) { |
3328 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3329 |
|
CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m)); |
3330 |
< |
CompletableFuture<?> dep = dependentFactory.apply(src); |
3330 |
> |
CompletableFuture<?> dep = fun.apply(src); |
3331 |
|
f.completeExceptionally(ex); |
3332 |
|
checkCompletedWithWrappedException(src, ex); |
3333 |
|
checkCompletedWithWrappedException(dep, ex); |
3336 |
|
|
3337 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
3338 |
|
for (Function<CompletableFuture<Integer>, CompletableFuture<?>> |
3339 |
< |
dependentFactory : dependentFactories) { |
3339 |
> |
fun : funs) { |
3340 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3341 |
|
f.cancel(mayInterruptIfRunning); |
3342 |
|
checkCancelled(f); |
3343 |
|
CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m)); |
3344 |
|
checkCompletedWithWrappedCancellationException(src); |
3345 |
< |
CompletableFuture<?> dep = dependentFactory.apply(src); |
3345 |
> |
CompletableFuture<?> dep = fun.apply(src); |
3346 |
|
checkCompletedWithWrappedCancellationException(dep); |
3347 |
|
assertSame(resultOf(src), resultOf(dep)); |
3348 |
|
} |
3349 |
|
|
3350 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
3351 |
|
for (Function<CompletableFuture<Integer>, CompletableFuture<?>> |
3352 |
< |
dependentFactory : dependentFactories) { |
3352 |
> |
fun : funs) { |
3353 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3354 |
|
CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m)); |
3355 |
< |
CompletableFuture<?> dep = dependentFactory.apply(src); |
3355 |
> |
CompletableFuture<?> dep = fun.apply(src); |
3356 |
|
f.cancel(mayInterruptIfRunning); |
3357 |
|
checkCancelled(f); |
3358 |
|
checkCompletedWithWrappedCancellationException(src); |