284 |
|
public void testGetNumberOfDependents() { |
285 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
286 |
|
assertEquals(0, f.getNumberOfDependents()); |
287 |
< |
CompletableFuture g = f.thenRun(new Noop()); |
287 |
> |
CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
288 |
|
assertEquals(1, f.getNumberOfDependents()); |
289 |
|
assertEquals(0, g.getNumberOfDependents()); |
290 |
< |
CompletableFuture h = f.thenRun(new Noop()); |
290 |
> |
CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
291 |
|
assertEquals(2, f.getNumberOfDependents()); |
292 |
|
f.complete(1); |
293 |
|
checkCompletedNormally(g, null); |
375 |
|
} |
376 |
|
} |
377 |
|
static final class Noop implements Runnable { |
378 |
+ |
final ExecutionMode m; |
379 |
|
int invocationCount = 0; |
380 |
+ |
Noop(ExecutionMode m) { this.m = m; } |
381 |
|
public void run() { |
382 |
+ |
m.checkExecutionMode(); |
383 |
|
invocationCount++; |
384 |
|
} |
385 |
|
} |
912 |
|
* runAsync completes after running Runnable |
913 |
|
*/ |
914 |
|
public void testRunAsync() { |
915 |
< |
Noop r = new Noop(); |
915 |
> |
Noop r = new Noop(ExecutionMode.ASYNC); |
916 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
917 |
|
assertNull(f.join()); |
918 |
|
assertEquals(1, r.invocationCount); |
923 |
|
* runAsync with executor completes after running Runnable |
924 |
|
*/ |
925 |
|
public void testRunAsync2() { |
926 |
< |
Noop r = new Noop(); |
926 |
> |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
927 |
|
ThreadExecutor exec = new ThreadExecutor(); |
928 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
929 |
|
assertNull(f.join()); |
983 |
|
for (Integer v1 : new Integer[] { 1, null }) |
984 |
|
{ |
985 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
986 |
< |
final Noop r = new Noop(); |
986 |
> |
final Noop r = new Noop(m); |
987 |
|
if (!createIncomplete) f.complete(v1); |
988 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
989 |
|
if (createIncomplete) { |
1006 |
|
{ |
1007 |
|
final CFException ex = new CFException(); |
1008 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1009 |
< |
final Noop r = new Noop(); |
1009 |
> |
final Noop r = new Noop(m); |
1010 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1011 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1012 |
|
if (createIncomplete) { |
1028 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1029 |
|
{ |
1030 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1031 |
< |
final Noop r = new Noop(); |
1031 |
> |
final Noop r = new Noop(m); |
1032 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1033 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1034 |
|
if (createIncomplete) { |
1274 |
|
* thenCombine result completes exceptionally after exceptional |
1275 |
|
* completion of either source |
1276 |
|
*/ |
1277 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1275 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1277 |
< |
{ |
1278 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1279 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1280 |
< |
final SubtractFunction r = new SubtractFunction(); |
1281 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1282 |
< |
final CFException ex = new CFException(); |
1283 |
< |
|
1284 |
< |
f.completeExceptionally(ex); |
1285 |
< |
checkIncomplete(h); |
1286 |
< |
g.complete(v1); |
1287 |
< |
|
1288 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1289 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1290 |
< |
assertEquals(0, r.invocationCount); |
1291 |
< |
checkCompletedNormally(g, v1); |
1292 |
< |
}} |
1293 |
< |
|
1294 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1295 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1296 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1297 |
< |
{ |
1298 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1299 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1300 |
< |
final SubtractFunction r = new SubtractFunction(); |
1301 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1302 |
< |
final CFException ex = new CFException(); |
1303 |
< |
|
1304 |
< |
g.completeExceptionally(ex); |
1305 |
< |
checkIncomplete(h); |
1306 |
< |
f.complete(v1); |
1307 |
< |
|
1308 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1309 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1310 |
< |
assertEquals(0, r.invocationCount); |
1311 |
< |
checkCompletedNormally(f, v1); |
1312 |
< |
}} |
1313 |
< |
|
1314 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1277 |
> |
public void testThenCombine_exceptionalCompletion() { |
1278 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1279 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1280 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1281 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1282 |
|
{ |
1283 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1284 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1320 |
– |
final SubtractFunction r = new SubtractFunction(); |
1285 |
|
final CFException ex = new CFException(); |
1322 |
– |
|
1323 |
– |
g.completeExceptionally(ex); |
1324 |
– |
f.complete(v1); |
1325 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1326 |
– |
|
1327 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1328 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1329 |
– |
assertEquals(0, r.invocationCount); |
1330 |
– |
checkCompletedNormally(f, v1); |
1331 |
– |
}} |
1332 |
– |
|
1333 |
– |
public void testThenCombine_exceptionalCompletion4() { |
1334 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1335 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1336 |
– |
{ |
1337 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1286 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
– |
final CFException ex = new CFException(); |
1287 |
|
|
1288 |
< |
f.completeExceptionally(ex); |
1289 |
< |
g.complete(v1); |
1288 |
> |
(fFirst ? f : g).complete(v1); |
1289 |
> |
if (!createIncomplete) |
1290 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1291 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1292 |
+ |
if (createIncomplete) { |
1293 |
+ |
checkIncomplete(h); |
1294 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1295 |
+ |
} |
1296 |
|
|
1297 |
|
checkCompletedWithWrappedCFException(h, ex); |
1347 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1298 |
|
assertEquals(0, r.invocationCount); |
1299 |
< |
checkCompletedNormally(g, v1); |
1299 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1300 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1301 |
|
}} |
1302 |
|
|
1303 |
|
/** |
1304 |
|
* thenCombine result completes exceptionally if action does |
1305 |
|
*/ |
1306 |
< |
public void testThenCombine_actionFailed1() { |
1356 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1357 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1358 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1359 |
< |
{ |
1360 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1361 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1362 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1363 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1364 |
< |
|
1365 |
< |
f.complete(v1); |
1366 |
< |
checkIncomplete(h); |
1367 |
< |
g.complete(v2); |
1368 |
< |
|
1369 |
< |
checkCompletedWithWrappedCFException(h); |
1370 |
< |
checkCompletedNormally(f, v1); |
1371 |
< |
checkCompletedNormally(g, v2); |
1372 |
< |
}} |
1373 |
< |
|
1374 |
< |
public void testThenCombine_actionFailed2() { |
1306 |
> |
public void testThenCombine_actionFailed() { |
1307 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1308 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1309 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1310 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1311 |
|
{ |
1314 |
|
final FailingBiFunction r = new FailingBiFunction(); |
1315 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1316 |
|
|
1317 |
< |
g.complete(v2); |
1318 |
< |
checkIncomplete(h); |
1319 |
< |
f.complete(v1); |
1317 |
> |
if (fFirst) { |
1318 |
> |
f.complete(v1); |
1319 |
> |
g.complete(v2); |
1320 |
> |
} else { |
1321 |
> |
g.complete(v2); |
1322 |
> |
f.complete(v1); |
1323 |
> |
} |
1324 |
|
|
1325 |
|
checkCompletedWithWrappedCFException(h); |
1326 |
|
checkCompletedNormally(f, v1); |
1330 |
|
/** |
1331 |
|
* thenCombine result completes exceptionally if either source cancelled |
1332 |
|
*/ |
1333 |
< |
public void testThenCombine_sourceCancelled1() { |
1397 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1398 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1399 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1400 |
< |
{ |
1401 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1402 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
< |
final SubtractFunction r = new SubtractFunction(); |
1404 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1405 |
< |
|
1406 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1407 |
< |
checkIncomplete(h); |
1408 |
< |
g.complete(v1); |
1409 |
< |
|
1410 |
< |
checkCompletedWithWrappedCancellationException(h); |
1411 |
< |
checkCancelled(f); |
1412 |
< |
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1414 |
< |
}} |
1415 |
< |
|
1416 |
< |
public void testThenCombine_sourceCancelled2() { |
1417 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1418 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1419 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1420 |
< |
{ |
1421 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1422 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1423 |
< |
final SubtractFunction r = new SubtractFunction(); |
1424 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1425 |
< |
|
1426 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1427 |
< |
checkIncomplete(h); |
1428 |
< |
f.complete(v1); |
1429 |
< |
|
1430 |
< |
checkCompletedWithWrappedCancellationException(h); |
1431 |
< |
checkCancelled(g); |
1432 |
< |
assertEquals(0, r.invocationCount); |
1433 |
< |
checkCompletedNormally(f, v1); |
1434 |
< |
}} |
1435 |
< |
|
1436 |
< |
public void testThenCombine_sourceCancelled3() { |
1437 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1438 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1439 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1440 |
< |
{ |
1441 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1442 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1443 |
< |
final SubtractFunction r = new SubtractFunction(); |
1444 |
< |
|
1445 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1446 |
< |
f.complete(v1); |
1447 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1448 |
< |
|
1449 |
< |
checkCompletedWithWrappedCancellationException(h); |
1450 |
< |
checkCancelled(g); |
1451 |
< |
assertEquals(0, r.invocationCount); |
1452 |
< |
checkCompletedNormally(f, v1); |
1453 |
< |
}} |
1454 |
< |
|
1455 |
< |
public void testThenCombine_sourceCancelled4() { |
1333 |
> |
public void testThenCombine_sourceCancelled() { |
1334 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1335 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1336 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1337 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1338 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1339 |
|
{ |
1340 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1341 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1342 |
|
final SubtractFunction r = new SubtractFunction(); |
1343 |
|
|
1344 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1345 |
< |
g.complete(v1); |
1344 |
> |
(fFirst ? f : g).complete(v1); |
1345 |
> |
if (!createIncomplete) |
1346 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1347 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1348 |
+ |
if (createIncomplete) { |
1349 |
+ |
checkIncomplete(h); |
1350 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1351 |
+ |
} |
1352 |
|
|
1353 |
|
checkCompletedWithWrappedCancellationException(h); |
1354 |
< |
checkCancelled(f); |
1354 |
> |
checkCancelled(!fFirst ? f : g); |
1355 |
|
assertEquals(0, r.invocationCount); |
1356 |
< |
checkCompletedNormally(g, v1); |
1356 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1357 |
|
}} |
1358 |
|
|
1359 |
|
/** |
1360 |
|
* thenAcceptBoth result completes normally after normal |
1361 |
|
* completion of sources |
1362 |
|
*/ |
1363 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1479 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1480 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1481 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1482 |
< |
{ |
1483 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1484 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1485 |
< |
final SubtractAction r = new SubtractAction(); |
1486 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1487 |
< |
|
1488 |
< |
f.complete(v1); |
1489 |
< |
checkIncomplete(h); |
1490 |
< |
assertEquals(0, r.invocationCount); |
1491 |
< |
g.complete(v2); |
1492 |
< |
|
1493 |
< |
checkCompletedNormally(h, null); |
1494 |
< |
assertEquals(subtract(v1, v2), r.value); |
1495 |
< |
checkCompletedNormally(f, v1); |
1496 |
< |
checkCompletedNormally(g, v2); |
1497 |
< |
}} |
1498 |
< |
|
1499 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1500 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1501 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1502 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1503 |
< |
{ |
1504 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1505 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1506 |
< |
final SubtractAction r = new SubtractAction(); |
1507 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1508 |
< |
|
1509 |
< |
g.complete(v2); |
1510 |
< |
checkIncomplete(h); |
1511 |
< |
assertEquals(0, r.invocationCount); |
1512 |
< |
f.complete(v1); |
1513 |
< |
|
1514 |
< |
checkCompletedNormally(h, null); |
1515 |
< |
assertEquals(subtract(v1, v2), r.value); |
1516 |
< |
checkCompletedNormally(f, v1); |
1517 |
< |
checkCompletedNormally(g, v2); |
1518 |
< |
}} |
1519 |
< |
|
1520 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1521 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1522 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1523 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1524 |
< |
{ |
1525 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1526 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1527 |
< |
final SubtractAction r = new SubtractAction(); |
1528 |
< |
|
1529 |
< |
g.complete(v2); |
1530 |
< |
f.complete(v1); |
1531 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1532 |
< |
|
1533 |
< |
checkCompletedNormally(h, null); |
1534 |
< |
assertEquals(subtract(v1, v2), r.value); |
1535 |
< |
checkCompletedNormally(f, v1); |
1536 |
< |
checkCompletedNormally(g, v2); |
1537 |
< |
}} |
1538 |
< |
|
1539 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1363 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1364 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1365 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1366 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1367 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1368 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1369 |
|
{ |
1371 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1372 |
|
final SubtractAction r = new SubtractAction(); |
1373 |
|
|
1374 |
< |
f.complete(v1); |
1375 |
< |
g.complete(v2); |
1374 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1375 |
> |
if (!createIncomplete) |
1376 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1377 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1378 |
+ |
if (createIncomplete) { |
1379 |
+ |
checkIncomplete(h); |
1380 |
+ |
assertEquals(0, r.invocationCount); |
1381 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1382 |
+ |
} |
1383 |
|
|
1384 |
|
checkCompletedNormally(h, null); |
1385 |
|
assertEquals(subtract(v1, v2), r.value); |
1391 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1392 |
|
* completion of either source |
1393 |
|
*/ |
1394 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1563 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1564 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1565 |
< |
{ |
1566 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1567 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1568 |
< |
final SubtractAction r = new SubtractAction(); |
1569 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1570 |
< |
final CFException ex = new CFException(); |
1571 |
< |
|
1572 |
< |
f.completeExceptionally(ex); |
1573 |
< |
checkIncomplete(h); |
1574 |
< |
g.complete(v1); |
1575 |
< |
|
1576 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1577 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1578 |
< |
assertEquals(0, r.invocationCount); |
1579 |
< |
checkCompletedNormally(g, v1); |
1580 |
< |
}} |
1581 |
< |
|
1582 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1394 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1395 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1396 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1397 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1398 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1399 |
|
{ |
1400 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1401 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1588 |
– |
final SubtractAction r = new SubtractAction(); |
1589 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1402 |
|
final CFException ex = new CFException(); |
1591 |
– |
|
1592 |
– |
g.completeExceptionally(ex); |
1593 |
– |
checkIncomplete(h); |
1594 |
– |
f.complete(v1); |
1595 |
– |
|
1596 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1597 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1598 |
– |
assertEquals(0, r.invocationCount); |
1599 |
– |
checkCompletedNormally(f, v1); |
1600 |
– |
}} |
1601 |
– |
|
1602 |
– |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1603 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1604 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1605 |
– |
{ |
1606 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1607 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
|
final SubtractAction r = new SubtractAction(); |
1609 |
– |
final CFException ex = new CFException(); |
1404 |
|
|
1405 |
< |
g.completeExceptionally(ex); |
1406 |
< |
f.complete(v1); |
1407 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1614 |
< |
|
1615 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1616 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1617 |
< |
assertEquals(0, r.invocationCount); |
1618 |
< |
checkCompletedNormally(f, v1); |
1619 |
< |
}} |
1620 |
< |
|
1621 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1622 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1623 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1624 |
< |
{ |
1625 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1626 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1627 |
< |
final SubtractAction r = new SubtractAction(); |
1628 |
< |
final CFException ex = new CFException(); |
1629 |
< |
|
1630 |
< |
f.completeExceptionally(ex); |
1631 |
< |
g.complete(v1); |
1405 |
> |
(fFirst ? f : g).complete(v1); |
1406 |
> |
if (!createIncomplete) |
1407 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1408 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1409 |
+ |
if (createIncomplete) { |
1410 |
+ |
checkIncomplete(h); |
1411 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1412 |
+ |
} |
1413 |
|
|
1414 |
|
checkCompletedWithWrappedCFException(h, ex); |
1635 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1415 |
|
assertEquals(0, r.invocationCount); |
1416 |
< |
checkCompletedNormally(g, v1); |
1416 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1417 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1418 |
|
}} |
1419 |
|
|
1420 |
|
/** |
1421 |
|
* thenAcceptBoth result completes exceptionally if action does |
1422 |
|
*/ |
1423 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1644 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1645 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1646 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1647 |
< |
{ |
1648 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1649 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1650 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1651 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1652 |
< |
|
1653 |
< |
f.complete(v1); |
1654 |
< |
checkIncomplete(h); |
1655 |
< |
g.complete(v2); |
1656 |
< |
|
1657 |
< |
checkCompletedWithWrappedCFException(h); |
1658 |
< |
checkCompletedNormally(f, v1); |
1659 |
< |
checkCompletedNormally(g, v2); |
1660 |
< |
}} |
1661 |
< |
|
1662 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1423 |
> |
public void testThenAcceptBoth_actionFailed() { |
1424 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1425 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1426 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1427 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1428 |
|
{ |
1431 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1432 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1433 |
|
|
1434 |
< |
g.complete(v2); |
1435 |
< |
checkIncomplete(h); |
1436 |
< |
f.complete(v1); |
1434 |
> |
if (fFirst) { |
1435 |
> |
f.complete(v1); |
1436 |
> |
g.complete(v2); |
1437 |
> |
} else { |
1438 |
> |
g.complete(v2); |
1439 |
> |
f.complete(v1); |
1440 |
> |
} |
1441 |
|
|
1442 |
|
checkCompletedWithWrappedCFException(h); |
1443 |
|
checkCompletedNormally(f, v1); |
1447 |
|
/** |
1448 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1449 |
|
*/ |
1450 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1685 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1686 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1687 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1688 |
< |
{ |
1689 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1690 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1691 |
< |
final SubtractAction r = new SubtractAction(); |
1692 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1693 |
< |
|
1694 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1695 |
< |
checkIncomplete(h); |
1696 |
< |
g.complete(v1); |
1697 |
< |
|
1698 |
< |
checkCompletedWithWrappedCancellationException(h); |
1699 |
< |
checkCancelled(f); |
1700 |
< |
assertEquals(0, r.invocationCount); |
1701 |
< |
checkCompletedNormally(g, v1); |
1702 |
< |
}} |
1703 |
< |
|
1704 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1705 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1706 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1707 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1708 |
< |
{ |
1709 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1710 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
< |
final SubtractAction r = new SubtractAction(); |
1712 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1713 |
< |
|
1714 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1715 |
< |
checkIncomplete(h); |
1716 |
< |
f.complete(v1); |
1717 |
< |
|
1718 |
< |
checkCompletedWithWrappedCancellationException(h); |
1719 |
< |
checkCancelled(g); |
1720 |
< |
assertEquals(0, r.invocationCount); |
1721 |
< |
checkCompletedNormally(f, v1); |
1722 |
< |
}} |
1723 |
< |
|
1724 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1725 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1726 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1727 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1728 |
< |
{ |
1729 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1730 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1731 |
< |
final SubtractAction r = new SubtractAction(); |
1732 |
< |
|
1733 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1734 |
< |
f.complete(v1); |
1735 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1736 |
< |
|
1737 |
< |
checkCompletedWithWrappedCancellationException(h); |
1738 |
< |
checkCancelled(g); |
1739 |
< |
assertEquals(0, r.invocationCount); |
1740 |
< |
checkCompletedNormally(f, v1); |
1741 |
< |
}} |
1742 |
< |
|
1743 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1450 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1451 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1452 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1453 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1454 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1455 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1456 |
|
{ |
1457 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1458 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1459 |
|
final SubtractAction r = new SubtractAction(); |
1460 |
|
|
1461 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1462 |
< |
g.complete(v1); |
1461 |
> |
(fFirst ? f : g).complete(v1); |
1462 |
> |
if (!createIncomplete) |
1463 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1464 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1465 |
+ |
if (createIncomplete) { |
1466 |
+ |
checkIncomplete(h); |
1467 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1468 |
+ |
} |
1469 |
|
|
1470 |
|
checkCompletedWithWrappedCancellationException(h); |
1471 |
< |
checkCancelled(f); |
1471 |
> |
checkCancelled(!fFirst ? f : g); |
1472 |
|
assertEquals(0, r.invocationCount); |
1473 |
< |
checkCompletedNormally(g, v1); |
1473 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1474 |
|
}} |
1475 |
|
|
1476 |
|
/** |
1477 |
|
* runAfterBoth result completes normally after normal |
1478 |
|
* completion of sources |
1479 |
|
*/ |
1480 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1767 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1768 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1769 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1770 |
< |
{ |
1771 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1772 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1773 |
< |
final Noop r = new Noop(); |
1774 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1775 |
< |
|
1776 |
< |
f.complete(v1); |
1777 |
< |
checkIncomplete(h); |
1778 |
< |
assertEquals(0, r.invocationCount); |
1779 |
< |
g.complete(v2); |
1780 |
< |
|
1781 |
< |
checkCompletedNormally(h, null); |
1782 |
< |
assertEquals(1, r.invocationCount); |
1783 |
< |
checkCompletedNormally(f, v1); |
1784 |
< |
checkCompletedNormally(g, v2); |
1785 |
< |
}} |
1786 |
< |
|
1787 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1788 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1789 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1790 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1791 |
< |
{ |
1792 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1793 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1794 |
< |
final Noop r = new Noop(); |
1795 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1796 |
< |
|
1797 |
< |
g.complete(v2); |
1798 |
< |
checkIncomplete(h); |
1799 |
< |
assertEquals(0, r.invocationCount); |
1800 |
< |
f.complete(v1); |
1801 |
< |
|
1802 |
< |
checkCompletedNormally(h, null); |
1803 |
< |
assertEquals(1, r.invocationCount); |
1804 |
< |
checkCompletedNormally(f, v1); |
1805 |
< |
checkCompletedNormally(g, v2); |
1806 |
< |
}} |
1807 |
< |
|
1808 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1809 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1810 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1811 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1812 |
< |
{ |
1813 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1814 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1815 |
< |
final Noop r = new Noop(); |
1816 |
< |
|
1817 |
< |
g.complete(v2); |
1818 |
< |
f.complete(v1); |
1819 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1820 |
< |
|
1821 |
< |
checkCompletedNormally(h, null); |
1822 |
< |
assertEquals(1, r.invocationCount); |
1823 |
< |
checkCompletedNormally(f, v1); |
1824 |
< |
checkCompletedNormally(g, v2); |
1825 |
< |
}} |
1826 |
< |
|
1827 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1480 |
> |
public void testRunAfterBoth_normalCompletion() { |
1481 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1482 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1483 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1484 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1485 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1486 |
|
{ |
1487 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1488 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1489 |
< |
final Noop r = new Noop(); |
1489 |
> |
final Noop r = new Noop(m); |
1490 |
|
|
1491 |
< |
f.complete(v1); |
1492 |
< |
g.complete(v2); |
1491 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1492 |
> |
if (!createIncomplete) |
1493 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1494 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1495 |
+ |
if (createIncomplete) { |
1496 |
+ |
checkIncomplete(h); |
1497 |
+ |
assertEquals(0, r.invocationCount); |
1498 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1499 |
+ |
} |
1500 |
|
|
1501 |
|
checkCompletedNormally(h, null); |
1502 |
|
assertEquals(1, r.invocationCount); |
1508 |
|
* runAfterBoth result completes exceptionally after exceptional |
1509 |
|
* completion of either source |
1510 |
|
*/ |
1511 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1851 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1852 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1853 |
< |
{ |
1854 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1855 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1856 |
< |
final Noop r = new Noop(); |
1857 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1858 |
< |
final CFException ex = new CFException(); |
1859 |
< |
|
1860 |
< |
f.completeExceptionally(ex); |
1861 |
< |
checkIncomplete(h); |
1862 |
< |
g.complete(v1); |
1863 |
< |
|
1864 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1865 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1866 |
< |
assertEquals(0, r.invocationCount); |
1867 |
< |
checkCompletedNormally(g, v1); |
1868 |
< |
}} |
1869 |
< |
|
1870 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1871 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1872 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1873 |
< |
{ |
1874 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1875 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1876 |
< |
final Noop r = new Noop(); |
1877 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1878 |
< |
final CFException ex = new CFException(); |
1879 |
< |
|
1880 |
< |
g.completeExceptionally(ex); |
1881 |
< |
checkIncomplete(h); |
1882 |
< |
f.complete(v1); |
1883 |
< |
|
1884 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1885 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1886 |
< |
assertEquals(0, r.invocationCount); |
1887 |
< |
checkCompletedNormally(f, v1); |
1888 |
< |
}} |
1889 |
< |
|
1890 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1891 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1892 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1893 |
< |
{ |
1894 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1895 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1896 |
< |
final Noop r = new Noop(); |
1897 |
< |
final CFException ex = new CFException(); |
1898 |
< |
|
1899 |
< |
g.completeExceptionally(ex); |
1900 |
< |
f.complete(v1); |
1901 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1902 |
< |
|
1903 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1904 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1905 |
< |
assertEquals(0, r.invocationCount); |
1906 |
< |
checkCompletedNormally(f, v1); |
1907 |
< |
}} |
1908 |
< |
|
1909 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1511 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1512 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1513 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1514 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1515 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1516 |
|
{ |
1517 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1518 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1915 |
– |
final Noop r = new Noop(); |
1519 |
|
final CFException ex = new CFException(); |
1520 |
+ |
final Noop r = new Noop(m); |
1521 |
|
|
1522 |
< |
f.completeExceptionally(ex); |
1523 |
< |
g.complete(v1); |
1522 |
> |
(fFirst ? f : g).complete(v1); |
1523 |
> |
if (!createIncomplete) |
1524 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1525 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1526 |
+ |
if (createIncomplete) { |
1527 |
+ |
checkIncomplete(h); |
1528 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1529 |
+ |
} |
1530 |
|
|
1531 |
|
checkCompletedWithWrappedCFException(h, ex); |
1923 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1532 |
|
assertEquals(0, r.invocationCount); |
1533 |
< |
checkCompletedNormally(g, v1); |
1533 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1534 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1535 |
|
}} |
1536 |
|
|
1537 |
|
/** |
1538 |
|
* runAfterBoth result completes exceptionally if action does |
1539 |
|
*/ |
1540 |
< |
public void testRunAfterBoth_actionFailed1() { |
1932 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1933 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1934 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1935 |
< |
{ |
1936 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1937 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1938 |
< |
final FailingRunnable r = new FailingRunnable(); |
1939 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1940 |
< |
|
1941 |
< |
f.complete(v1); |
1942 |
< |
checkIncomplete(h); |
1943 |
< |
g.complete(v2); |
1944 |
< |
|
1945 |
< |
checkCompletedWithWrappedCFException(h); |
1946 |
< |
checkCompletedNormally(f, v1); |
1947 |
< |
checkCompletedNormally(g, v2); |
1948 |
< |
}} |
1949 |
< |
|
1950 |
< |
public void testRunAfterBoth_actionFailed2() { |
1540 |
> |
public void testRunAfterBoth_actionFailed() { |
1541 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1542 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1543 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1544 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1545 |
|
{ |
1546 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1547 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1548 |
|
final FailingRunnable r = new FailingRunnable(); |
1958 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1549 |
|
|
1550 |
< |
g.complete(v2); |
1551 |
< |
checkIncomplete(h); |
1552 |
< |
f.complete(v1); |
1550 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1551 |
> |
if (fFirst) { |
1552 |
> |
f.complete(v1); |
1553 |
> |
g.complete(v2); |
1554 |
> |
} else { |
1555 |
> |
g.complete(v2); |
1556 |
> |
f.complete(v1); |
1557 |
> |
} |
1558 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1559 |
|
|
1560 |
< |
checkCompletedWithWrappedCFException(h); |
1560 |
> |
checkCompletedWithWrappedCFException(h1); |
1561 |
> |
checkCompletedWithWrappedCFException(h2); |
1562 |
|
checkCompletedNormally(f, v1); |
1563 |
|
checkCompletedNormally(g, v2); |
1564 |
|
}} |
1566 |
|
/** |
1567 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1568 |
|
*/ |
1569 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1973 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1974 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1975 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1976 |
< |
{ |
1977 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1978 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1979 |
< |
final Noop r = new Noop(); |
1980 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1981 |
< |
|
1982 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1983 |
< |
checkIncomplete(h); |
1984 |
< |
g.complete(v1); |
1985 |
< |
|
1986 |
< |
checkCompletedWithWrappedCancellationException(h); |
1987 |
< |
checkCancelled(f); |
1988 |
< |
assertEquals(0, r.invocationCount); |
1989 |
< |
checkCompletedNormally(g, v1); |
1990 |
< |
}} |
1991 |
< |
|
1992 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1993 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1994 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1995 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1996 |
< |
{ |
1997 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1998 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1999 |
< |
final Noop r = new Noop(); |
2000 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
2001 |
< |
|
2002 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2003 |
< |
checkIncomplete(h); |
2004 |
< |
f.complete(v1); |
2005 |
< |
|
2006 |
< |
checkCompletedWithWrappedCancellationException(h); |
2007 |
< |
checkCancelled(g); |
2008 |
< |
assertEquals(0, r.invocationCount); |
2009 |
< |
checkCompletedNormally(f, v1); |
2010 |
< |
}} |
2011 |
< |
|
2012 |
< |
public void testRunAfterBoth_sourceCancelled3() { |
1569 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1570 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1571 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1572 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1573 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1574 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1575 |
|
{ |
1576 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1577 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1578 |
< |
final Noop r = new Noop(); |
1578 |
> |
final Noop r = new Noop(m); |
1579 |
|
|
2021 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2022 |
– |
f.complete(v1); |
2023 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1580 |
|
|
1581 |
< |
checkCompletedWithWrappedCancellationException(h); |
1582 |
< |
checkCancelled(g); |
1583 |
< |
assertEquals(0, r.invocationCount); |
2028 |
< |
checkCompletedNormally(f, v1); |
2029 |
< |
}} |
2030 |
< |
|
2031 |
< |
public void testRunAfterBoth_sourceCancelled4() { |
2032 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2033 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2034 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2035 |
< |
{ |
2036 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2037 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2038 |
< |
final Noop r = new Noop(); |
2039 |
< |
|
2040 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2041 |
< |
g.complete(v1); |
1581 |
> |
(fFirst ? f : g).complete(v1); |
1582 |
> |
if (!createIncomplete) |
1583 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1584 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
+ |
if (createIncomplete) { |
1586 |
+ |
checkIncomplete(h); |
1587 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1588 |
+ |
} |
1589 |
|
|
1590 |
|
checkCompletedWithWrappedCancellationException(h); |
1591 |
< |
checkCancelled(f); |
1591 |
> |
checkCancelled(!fFirst ? f : g); |
1592 |
|
assertEquals(0, r.invocationCount); |
1593 |
< |
checkCompletedNormally(g, v1); |
1593 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1594 |
|
}} |
1595 |
|
|
1596 |
|
/** |
1597 |
|
* applyToEither result completes normally after normal completion |
1598 |
|
* of either source |
1599 |
|
*/ |
1600 |
< |
public void testApplyToEither_normalCompletion1() { |
1600 |
> |
public void testApplyToEither_normalCompletion() { |
1601 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1602 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1603 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1604 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1605 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1606 |
|
{ |
1607 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1608 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1609 |
|
final IncFunction r = new IncFunction(); |
2062 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1610 |
|
|
1611 |
< |
f.complete(v1); |
1612 |
< |
checkCompletedNormally(h, inc(v1)); |
1613 |
< |
g.complete(v2); |
1611 |
> |
if (!createIncomplete) |
1612 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1613 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1614 |
> |
if (createIncomplete) { |
1615 |
> |
checkIncomplete(h); |
1616 |
> |
assertEquals(0, r.invocationCount); |
1617 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1618 |
> |
} |
1619 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1620 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1621 |
|
|
1622 |
|
checkCompletedNormally(f, v1); |
1623 |
|
checkCompletedNormally(g, v2); |
1624 |
< |
checkCompletedNormally(h, inc(v1)); |
1624 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1625 |
|
}} |
1626 |
|
|
1627 |
< |
public void testApplyToEither_normalCompletion2() { |
1627 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1628 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1629 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1630 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1631 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1632 |
|
{ |
1633 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1634 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1635 |
|
final IncFunction r = new IncFunction(); |
2081 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1636 |
|
|
1637 |
< |
g.complete(v2); |
1638 |
< |
checkCompletedNormally(h, inc(v2)); |
1639 |
< |
f.complete(v1); |
1640 |
< |
|
1641 |
< |
checkCompletedNormally(f, v1); |
1642 |
< |
checkCompletedNormally(g, v2); |
1643 |
< |
checkCompletedNormally(h, inc(v2)); |
2090 |
< |
}} |
2091 |
< |
|
2092 |
< |
public void testApplyToEither_normalCompletion3() { |
2093 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2094 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2095 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2096 |
< |
{ |
2097 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2098 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2099 |
< |
final IncFunction r = new IncFunction(); |
1637 |
> |
if (fFirst) { |
1638 |
> |
f.complete(v1); |
1639 |
> |
g.complete(v2); |
1640 |
> |
} else { |
1641 |
> |
g.complete(v2); |
1642 |
> |
f.complete(v1); |
1643 |
> |
} |
1644 |
|
|
2101 |
– |
f.complete(v1); |
2102 |
– |
g.complete(v2); |
1645 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1646 |
|
|
1647 |
|
checkCompletedNormally(f, v1); |
1659 |
|
*/ |
1660 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1661 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1662 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1663 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1664 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1665 |
|
{ |
1666 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1667 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
– |
final IncFunction r = new IncFunction(); |
2125 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1668 |
|
final CFException ex = new CFException(); |
2127 |
– |
|
2128 |
– |
f.completeExceptionally(ex); |
2129 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2130 |
– |
g.complete(v1); |
2131 |
– |
|
2132 |
– |
assertEquals(0, r.invocationCount); |
2133 |
– |
checkCompletedNormally(g, v1); |
2134 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2135 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2136 |
– |
}} |
2137 |
– |
|
2138 |
– |
public void testApplyToEither_exceptionalCompletion2() { |
2139 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2140 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2141 |
– |
{ |
2142 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2143 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1669 |
|
final IncFunction r = new IncFunction(); |
1670 |
+ |
|
1671 |
+ |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1672 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1673 |
< |
final CFException ex = new CFException(); |
1673 |
> |
if (createIncomplete) { |
1674 |
> |
checkIncomplete(h); |
1675 |
> |
assertEquals(0, r.invocationCount); |
1676 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1677 |
> |
} |
1678 |
|
|
2148 |
– |
g.completeExceptionally(ex); |
1679 |
|
checkCompletedWithWrappedCFException(h, ex); |
1680 |
< |
f.complete(v1); |
1680 |
> |
(!fFirst ? f : g).complete(v1); |
1681 |
|
|
1682 |
|
assertEquals(0, r.invocationCount); |
1683 |
< |
checkCompletedNormally(f, v1); |
1684 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1683 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1684 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1685 |
|
checkCompletedWithWrappedCFException(h, ex); |
1686 |
|
}} |
1687 |
|
|
1688 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1688 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1689 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1690 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1691 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1692 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1693 |
|
{ |
1694 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1695 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1696 |
< |
final IncFunction r = new IncFunction(); |
1696 |
> |
final IncFunction r1 = new IncFunction(); |
1697 |
> |
final IncFunction r2 = new IncFunction(); |
1698 |
|
final CFException ex = new CFException(); |
1699 |
< |
|
1700 |
< |
g.completeExceptionally(ex); |
1701 |
< |
f.complete(v1); |
1702 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1699 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1700 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1701 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1702 |
> |
if (fFirst) { |
1703 |
> |
f.complete(v1); |
1704 |
> |
g.completeExceptionally(ex); |
1705 |
> |
} else { |
1706 |
> |
g.completeExceptionally(ex); |
1707 |
> |
f.complete(v1); |
1708 |
> |
} |
1709 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1710 |
|
|
1711 |
|
// unspecified behavior |
2172 |
– |
Integer v; |
1712 |
|
try { |
1713 |
< |
assertEquals(inc(v1), h.join()); |
1714 |
< |
assertEquals(1, r.invocationCount); |
1713 |
> |
assertEquals(inc(v1), h1.join()); |
1714 |
> |
assertEquals(1, r1.invocationCount); |
1715 |
|
} catch (CompletionException ok) { |
1716 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1717 |
< |
assertEquals(0, r.invocationCount); |
1716 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1717 |
> |
assertEquals(0, r1.invocationCount); |
1718 |
|
} |
1719 |
|
|
2181 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2182 |
– |
checkCompletedNormally(f, v1); |
2183 |
– |
}} |
2184 |
– |
|
2185 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2186 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2187 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2188 |
– |
{ |
2189 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2190 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2191 |
– |
final IncFunction r = new IncFunction(); |
2192 |
– |
final CFException ex = new CFException(); |
2193 |
– |
|
2194 |
– |
f.completeExceptionally(ex); |
2195 |
– |
g.complete(v1); |
2196 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2197 |
– |
|
2198 |
– |
// unspecified behavior |
2199 |
– |
Integer v; |
1720 |
|
try { |
1721 |
< |
assertEquals(inc(v1), h.join()); |
1722 |
< |
assertEquals(1, r.invocationCount); |
1721 |
> |
assertEquals(inc(v1), h2.join()); |
1722 |
> |
assertEquals(1, r2.invocationCount); |
1723 |
|
} catch (CompletionException ok) { |
1724 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1725 |
< |
assertEquals(0, r.invocationCount); |
1724 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1725 |
> |
assertEquals(0, r2.invocationCount); |
1726 |
|
} |
1727 |
|
|
1728 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1729 |
< |
checkCompletedNormally(g, v1); |
1728 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1729 |
> |
checkCompletedNormally(f, v1); |
1730 |
|
}} |
1731 |
|
|
1732 |
|
/** |
1772 |
|
public void testApplyToEither_sourceCancelled1() { |
1773 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1774 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1775 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1776 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1777 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1778 |
|
{ |
1779 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1780 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1781 |
|
final IncFunction r = new IncFunction(); |
2260 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2261 |
– |
|
2262 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2263 |
– |
checkCompletedWithWrappedCancellationException(h); |
2264 |
– |
g.complete(v1); |
1782 |
|
|
1783 |
< |
checkCancelled(f); |
2267 |
< |
assertEquals(0, r.invocationCount); |
2268 |
< |
checkCompletedNormally(g, v1); |
2269 |
< |
checkCompletedWithWrappedCancellationException(h); |
2270 |
< |
}} |
2271 |
< |
|
2272 |
< |
public void testApplyToEither_sourceCancelled2() { |
2273 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2274 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2275 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2276 |
< |
{ |
2277 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2278 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2279 |
< |
final IncFunction r = new IncFunction(); |
1783 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1784 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1785 |
+ |
if (createIncomplete) { |
1786 |
+ |
checkIncomplete(h); |
1787 |
+ |
assertEquals(0, r.invocationCount); |
1788 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1789 |
+ |
} |
1790 |
|
|
2282 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1791 |
|
checkCompletedWithWrappedCancellationException(h); |
1792 |
< |
f.complete(v1); |
1792 |
> |
(!fFirst ? f : g).complete(v1); |
1793 |
|
|
2286 |
– |
checkCancelled(g); |
1794 |
|
assertEquals(0, r.invocationCount); |
1795 |
< |
checkCompletedNormally(f, v1); |
1795 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1796 |
> |
checkCancelled(fFirst ? f : g); |
1797 |
|
checkCompletedWithWrappedCancellationException(h); |
1798 |
|
}} |
1799 |
|
|
1800 |
< |
public void testApplyToEither_sourceCancelled3() { |
1800 |
> |
public void testApplyToEither_sourceCancelled2() { |
1801 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1802 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1803 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1804 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1805 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1806 |
|
{ |
1807 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1808 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1809 |
< |
final IncFunction r = new IncFunction(); |
1809 |
> |
final IncFunction r1 = new IncFunction(); |
1810 |
> |
final IncFunction r2 = new IncFunction(); |
1811 |
> |
final CFException ex = new CFException(); |
1812 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1813 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1814 |
|
|
1815 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1816 |
< |
f.complete(v1); |
1817 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1815 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1816 |
> |
if (fFirst) { |
1817 |
> |
f.complete(v1); |
1818 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1819 |
> |
} else { |
1820 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1821 |
> |
f.complete(v1); |
1822 |
> |
} |
1823 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1824 |
|
|
1825 |
|
// unspecified behavior |
2306 |
– |
Integer v; |
1826 |
|
try { |
1827 |
< |
assertEquals(inc(v1), h.join()); |
1828 |
< |
assertEquals(1, r.invocationCount); |
1827 |
> |
assertEquals(inc(v1), h1.join()); |
1828 |
> |
assertEquals(1, r1.invocationCount); |
1829 |
|
} catch (CompletionException ok) { |
1830 |
< |
checkCompletedWithWrappedCancellationException(h); |
1831 |
< |
assertEquals(0, r.invocationCount); |
1830 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1831 |
> |
assertEquals(0, r1.invocationCount); |
1832 |
|
} |
1833 |
|
|
2315 |
– |
checkCancelled(g); |
2316 |
– |
checkCompletedNormally(f, v1); |
2317 |
– |
}} |
2318 |
– |
|
2319 |
– |
public void testApplyToEither_sourceCancelled4() { |
2320 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2321 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2322 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2323 |
– |
{ |
2324 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2325 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2326 |
– |
final IncFunction r = new IncFunction(); |
2327 |
– |
|
2328 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2329 |
– |
g.complete(v1); |
2330 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2331 |
– |
|
2332 |
– |
// unspecified behavior |
2333 |
– |
Integer v; |
1834 |
|
try { |
1835 |
< |
assertEquals(inc(v1), h.join()); |
1836 |
< |
assertEquals(1, r.invocationCount); |
1835 |
> |
assertEquals(inc(v1), h2.join()); |
1836 |
> |
assertEquals(1, r2.invocationCount); |
1837 |
|
} catch (CompletionException ok) { |
1838 |
< |
checkCompletedWithWrappedCancellationException(h); |
1839 |
< |
assertEquals(0, r.invocationCount); |
1838 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1839 |
> |
assertEquals(0, r2.invocationCount); |
1840 |
|
} |
1841 |
|
|
1842 |
< |
checkCancelled(f); |
1843 |
< |
checkCompletedNormally(g, v1); |
1842 |
> |
checkCancelled(g); |
1843 |
> |
checkCompletedNormally(f, v1); |
1844 |
|
}} |
1845 |
|
|
1846 |
|
/** |
2156 |
|
{ |
2157 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2158 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2159 |
< |
final Noop r = new Noop(); |
2159 |
> |
final Noop r = new Noop(m); |
2160 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2161 |
|
|
2162 |
|
f.complete(v1); |
2177 |
|
{ |
2178 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2179 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2180 |
< |
final Noop r = new Noop(); |
2180 |
> |
final Noop r = new Noop(m); |
2181 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2182 |
|
|
2183 |
|
g.complete(v2); |
2198 |
|
{ |
2199 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2200 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2201 |
< |
final Noop r = new Noop(); |
2201 |
> |
final Noop r = new Noop(m); |
2202 |
|
|
2203 |
|
f.complete(v1); |
2204 |
|
g.complete(v2); |
2220 |
|
{ |
2221 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2222 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2223 |
< |
final Noop r = new Noop(); |
2223 |
> |
final Noop r = new Noop(m); |
2224 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2225 |
|
final CFException ex = new CFException(); |
2226 |
|
|
2240 |
|
{ |
2241 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2242 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2243 |
< |
final Noop r = new Noop(); |
2243 |
> |
final Noop r = new Noop(m); |
2244 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2245 |
|
final CFException ex = new CFException(); |
2246 |
|
|
2260 |
|
{ |
2261 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2262 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2263 |
< |
final Noop r = new Noop(); |
2263 |
> |
final Noop r = new Noop(m); |
2264 |
|
final CFException ex = new CFException(); |
2265 |
|
|
2266 |
|
g.completeExceptionally(ex); |
2287 |
|
{ |
2288 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2289 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2290 |
< |
final Noop r = new Noop(); |
2290 |
> |
final Noop r = new Noop(m); |
2291 |
|
final CFException ex = new CFException(); |
2292 |
|
|
2293 |
|
f.completeExceptionally(ex); |
2355 |
|
{ |
2356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2357 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2358 |
< |
final Noop r = new Noop(); |
2358 |
> |
final Noop r = new Noop(m); |
2359 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2360 |
|
|
2361 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2375 |
|
{ |
2376 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2377 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2378 |
< |
final Noop r = new Noop(); |
2378 |
> |
final Noop r = new Noop(m); |
2379 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2380 |
|
|
2381 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2395 |
|
{ |
2396 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2397 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2398 |
< |
final Noop r = new Noop(); |
2398 |
> |
final Noop r = new Noop(m); |
2399 |
|
|
2400 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2401 |
|
f.complete(v1); |
2422 |
|
{ |
2423 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2424 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2425 |
< |
final Noop r = new Noop(); |
2425 |
> |
final Noop r = new Noop(m); |
2426 |
|
|
2427 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2428 |
|
g.complete(v1); |