1271 |
|
* thenCombine result completes exceptionally after exceptional |
1272 |
|
* completion of either source |
1273 |
|
*/ |
1274 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1274 |
> |
public void testThenCombine_exceptionalCompletion() { |
1275 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1277 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1278 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1279 |
|
{ |
1280 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1281 |
|
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() { |
1315 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1317 |
– |
{ |
1318 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1319 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1320 |
– |
final SubtractFunction r = new SubtractFunction(); |
1321 |
– |
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<>(); |
1283 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
– |
final CFException ex = new CFException(); |
1284 |
|
|
1285 |
< |
f.completeExceptionally(ex); |
1286 |
< |
g.complete(v1); |
1285 |
> |
(fFirst ? f : g).complete(v1); |
1286 |
> |
if (!createIncomplete) |
1287 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1288 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1289 |
+ |
if (createIncomplete) { |
1290 |
+ |
checkIncomplete(h); |
1291 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1292 |
+ |
} |
1293 |
|
|
1294 |
|
checkCompletedWithWrappedCFException(h, ex); |
1347 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1295 |
|
assertEquals(0, r.invocationCount); |
1296 |
< |
checkCompletedNormally(g, v1); |
1296 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1297 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1298 |
|
}} |
1299 |
|
|
1300 |
|
/** |
1301 |
|
* thenCombine result completes exceptionally if action does |
1302 |
|
*/ |
1303 |
< |
public void testThenCombine_actionFailed1() { |
1303 |
> |
public void testThenCombine_actionFailed() { |
1304 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1305 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1306 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1307 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1308 |
|
{ |
1311 |
|
final FailingBiFunction r = new FailingBiFunction(); |
1312 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1313 |
|
|
1314 |
< |
f.complete(v1); |
1315 |
< |
checkIncomplete(h); |
1316 |
< |
g.complete(v2); |
1317 |
< |
|
1318 |
< |
checkCompletedWithWrappedCFException(h); |
1319 |
< |
checkCompletedNormally(f, v1); |
1320 |
< |
checkCompletedNormally(g, v2); |
1372 |
< |
}} |
1373 |
< |
|
1374 |
< |
public void testThenCombine_actionFailed2() { |
1375 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1376 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1377 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1378 |
< |
{ |
1379 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1380 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1381 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1382 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1383 |
< |
|
1384 |
< |
g.complete(v2); |
1385 |
< |
checkIncomplete(h); |
1386 |
< |
f.complete(v1); |
1314 |
> |
if (fFirst) { |
1315 |
> |
f.complete(v1); |
1316 |
> |
g.complete(v2); |
1317 |
> |
} else { |
1318 |
> |
g.complete(v2); |
1319 |
> |
f.complete(v1); |
1320 |
> |
} |
1321 |
|
|
1322 |
|
checkCompletedWithWrappedCFException(h); |
1323 |
|
checkCompletedNormally(f, v1); |
1327 |
|
/** |
1328 |
|
* thenCombine result completes exceptionally if either source cancelled |
1329 |
|
*/ |
1330 |
< |
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() { |
1330 |
> |
public void testThenCombine_sourceCancelled() { |
1331 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1332 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1333 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1334 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1335 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1336 |
|
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
|
|
1341 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1342 |
< |
g.complete(v1); |
1341 |
> |
(fFirst ? f : g).complete(v1); |
1342 |
> |
if (!createIncomplete) |
1343 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1344 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1345 |
+ |
if (createIncomplete) { |
1346 |
+ |
checkIncomplete(h); |
1347 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1348 |
+ |
} |
1349 |
|
|
1350 |
|
checkCompletedWithWrappedCancellationException(h); |
1351 |
< |
checkCancelled(f); |
1351 |
> |
checkCancelled(!fFirst ? f : g); |
1352 |
|
assertEquals(0, r.invocationCount); |
1353 |
< |
checkCompletedNormally(g, v1); |
1353 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1354 |
|
}} |
1355 |
|
|
1356 |
|
/** |
1357 |
|
* thenAcceptBoth result completes normally after normal |
1358 |
|
* completion of sources |
1359 |
|
*/ |
1360 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1360 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1361 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1362 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1363 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1364 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1365 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1366 |
|
{ |
1367 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1368 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1369 |
|
final SubtractAction r = new SubtractAction(); |
1486 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1370 |
|
|
1371 |
< |
f.complete(v1); |
1372 |
< |
checkIncomplete(h); |
1373 |
< |
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() { |
1540 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1541 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1542 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1543 |
< |
{ |
1544 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1545 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1546 |
< |
final SubtractAction r = new SubtractAction(); |
1547 |
< |
|
1548 |
< |
f.complete(v1); |
1549 |
< |
g.complete(v2); |
1371 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1372 |
> |
if (!createIncomplete) |
1373 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1374 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1375 |
+ |
if (createIncomplete) { |
1376 |
+ |
checkIncomplete(h); |
1377 |
+ |
assertEquals(0, r.invocationCount); |
1378 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1379 |
+ |
} |
1380 |
|
|
1381 |
|
checkCompletedNormally(h, null); |
1382 |
|
assertEquals(subtract(v1, v2), r.value); |
1388 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1389 |
|
* completion of either source |
1390 |
|
*/ |
1391 |
< |
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() { |
1391 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1392 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1393 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1394 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1395 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1396 |
|
{ |
1397 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1398 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1588 |
– |
final SubtractAction r = new SubtractAction(); |
1589 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1399 |
|
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<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1609 |
– |
final CFException ex = new CFException(); |
1401 |
|
|
1402 |
< |
g.completeExceptionally(ex); |
1403 |
< |
f.complete(v1); |
1404 |
< |
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); |
1402 |
> |
(fFirst ? f : g).complete(v1); |
1403 |
> |
if (!createIncomplete) |
1404 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1405 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1406 |
+ |
if (createIncomplete) { |
1407 |
+ |
checkIncomplete(h); |
1408 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1409 |
+ |
} |
1410 |
|
|
1411 |
|
checkCompletedWithWrappedCFException(h, ex); |
1635 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1412 |
|
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1413 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1414 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1415 |
|
}} |
1416 |
|
|
1417 |
|
/** |
1418 |
|
* thenAcceptBoth result completes exceptionally if action does |
1419 |
|
*/ |
1420 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1420 |
> |
public void testThenAcceptBoth_actionFailed() { |
1421 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1422 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1423 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1424 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1425 |
|
{ |
1428 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1429 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1430 |
|
|
1431 |
< |
f.complete(v1); |
1432 |
< |
checkIncomplete(h); |
1433 |
< |
g.complete(v2); |
1434 |
< |
|
1435 |
< |
checkCompletedWithWrappedCFException(h); |
1436 |
< |
checkCompletedNormally(f, v1); |
1437 |
< |
checkCompletedNormally(g, v2); |
1660 |
< |
}} |
1661 |
< |
|
1662 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1663 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1664 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1665 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1666 |
< |
{ |
1667 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1668 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1669 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1670 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1671 |
< |
|
1672 |
< |
g.complete(v2); |
1673 |
< |
checkIncomplete(h); |
1674 |
< |
f.complete(v1); |
1431 |
> |
if (fFirst) { |
1432 |
> |
f.complete(v1); |
1433 |
> |
g.complete(v2); |
1434 |
> |
} else { |
1435 |
> |
g.complete(v2); |
1436 |
> |
f.complete(v1); |
1437 |
> |
} |
1438 |
|
|
1439 |
|
checkCompletedWithWrappedCFException(h); |
1440 |
|
checkCompletedNormally(f, v1); |
1444 |
|
/** |
1445 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1446 |
|
*/ |
1447 |
< |
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() { |
1447 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1448 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1449 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1450 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1451 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1452 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1453 |
|
{ |
1454 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1455 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1456 |
|
final SubtractAction r = new SubtractAction(); |
1457 |
|
|
1458 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1459 |
< |
g.complete(v1); |
1458 |
> |
(fFirst ? f : g).complete(v1); |
1459 |
> |
if (!createIncomplete) |
1460 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1461 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1462 |
+ |
if (createIncomplete) { |
1463 |
+ |
checkIncomplete(h); |
1464 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1465 |
+ |
} |
1466 |
|
|
1467 |
|
checkCompletedWithWrappedCancellationException(h); |
1468 |
< |
checkCancelled(f); |
1468 |
> |
checkCancelled(!fFirst ? f : g); |
1469 |
|
assertEquals(0, r.invocationCount); |
1470 |
< |
checkCompletedNormally(g, v1); |
1470 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1471 |
|
}} |
1472 |
|
|
1473 |
|
/** |
1474 |
|
* runAfterBoth result completes normally after normal |
1475 |
|
* completion of sources |
1476 |
|
*/ |
1477 |
< |
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() { |
1477 |
> |
public void testRunAfterBoth_normalCompletion() { |
1478 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1479 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1480 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1481 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1482 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1483 |
|
{ |
1485 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1486 |
|
final Noop r = new Noop(); |
1487 |
|
|
1488 |
< |
g.complete(v2); |
1489 |
< |
f.complete(v1); |
1490 |
< |
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() { |
1828 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1829 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1830 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1831 |
< |
{ |
1832 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1833 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1834 |
< |
final Noop r = new Noop(); |
1835 |
< |
|
1836 |
< |
f.complete(v1); |
1837 |
< |
g.complete(v2); |
1488 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1489 |
> |
if (!createIncomplete) |
1490 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1491 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1492 |
+ |
if (createIncomplete) { |
1493 |
+ |
checkIncomplete(h); |
1494 |
+ |
assertEquals(0, r.invocationCount); |
1495 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1496 |
+ |
} |
1497 |
|
|
1498 |
|
checkCompletedNormally(h, null); |
1499 |
|
assertEquals(1, r.invocationCount); |
1505 |
|
* runAfterBoth result completes exceptionally after exceptional |
1506 |
|
* completion of either source |
1507 |
|
*/ |
1508 |
< |
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() { |
1508 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1509 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1510 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1511 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1512 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1513 |
|
{ |
1514 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1515 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1876 |
– |
final Noop r = new Noop(); |
1877 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1516 |
|
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<>(); |
1517 |
|
final Noop r = new Noop(); |
1897 |
– |
final CFException ex = new CFException(); |
1518 |
|
|
1519 |
< |
g.completeExceptionally(ex); |
1520 |
< |
f.complete(v1); |
1521 |
< |
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() { |
1910 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1911 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1912 |
< |
{ |
1913 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1914 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1915 |
< |
final Noop r = new Noop(); |
1916 |
< |
final CFException ex = new CFException(); |
1917 |
< |
|
1918 |
< |
f.completeExceptionally(ex); |
1919 |
< |
g.complete(v1); |
1519 |
> |
(fFirst ? f : g).complete(v1); |
1520 |
> |
if (!createIncomplete) |
1521 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1522 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1523 |
+ |
if (createIncomplete) { |
1524 |
+ |
checkIncomplete(h); |
1525 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1526 |
+ |
} |
1527 |
|
|
1528 |
|
checkCompletedWithWrappedCFException(h, ex); |
1923 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1529 |
|
assertEquals(0, r.invocationCount); |
1530 |
< |
checkCompletedNormally(g, v1); |
1530 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1531 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1532 |
|
}} |
1533 |
|
|
1534 |
|
/** |
1535 |
|
* runAfterBoth result completes exceptionally if action does |
1536 |
|
*/ |
1537 |
< |
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() { |
1537 |
> |
public void testRunAfterBoth_actionFailed() { |
1538 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1539 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1540 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1541 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1542 |
|
{ |
1543 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1544 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1545 |
|
final FailingRunnable r = new FailingRunnable(); |
1958 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1546 |
|
|
1547 |
< |
g.complete(v2); |
1548 |
< |
checkIncomplete(h); |
1549 |
< |
f.complete(v1); |
1547 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1548 |
> |
if (fFirst) { |
1549 |
> |
f.complete(v1); |
1550 |
> |
g.complete(v2); |
1551 |
> |
} else { |
1552 |
> |
g.complete(v2); |
1553 |
> |
f.complete(v1); |
1554 |
> |
} |
1555 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1556 |
|
|
1557 |
< |
checkCompletedWithWrappedCFException(h); |
1557 |
> |
checkCompletedWithWrappedCFException(h1); |
1558 |
> |
checkCompletedWithWrappedCFException(h2); |
1559 |
|
checkCompletedNormally(f, v1); |
1560 |
|
checkCompletedNormally(g, v2); |
1561 |
|
}} |
1563 |
|
/** |
1564 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1565 |
|
*/ |
1566 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1566 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1567 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1568 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1569 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1570 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1571 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1572 |
|
{ |
1573 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1574 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1575 |
|
final Noop r = new Noop(); |
1980 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1576 |
|
|
1982 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1983 |
– |
checkIncomplete(h); |
1984 |
– |
g.complete(v1); |
1577 |
|
|
1578 |
< |
checkCompletedWithWrappedCancellationException(h); |
1579 |
< |
checkCancelled(f); |
1580 |
< |
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() { |
2013 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2014 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2015 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2016 |
< |
{ |
2017 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2018 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2019 |
< |
final Noop r = new Noop(); |
2020 |
< |
|
2021 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2022 |
< |
f.complete(v1); |
2023 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
2024 |
< |
|
2025 |
< |
checkCompletedWithWrappedCancellationException(h); |
2026 |
< |
checkCancelled(g); |
2027 |
< |
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); |
1578 |
> |
(fFirst ? f : g).complete(v1); |
1579 |
> |
if (!createIncomplete) |
1580 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1581 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1582 |
+ |
if (createIncomplete) { |
1583 |
+ |
checkIncomplete(h); |
1584 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1585 |
+ |
} |
1586 |
|
|
1587 |
|
checkCompletedWithWrappedCancellationException(h); |
1588 |
< |
checkCancelled(f); |
1588 |
> |
checkCancelled(!fFirst ? f : g); |
1589 |
|
assertEquals(0, r.invocationCount); |
1590 |
< |
checkCompletedNormally(g, v1); |
1590 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1591 |
|
}} |
1592 |
|
|
1593 |
|
/** |
1594 |
|
* applyToEither result completes normally after normal completion |
1595 |
|
* of either source |
1596 |
|
*/ |
1597 |
< |
public void testApplyToEither_normalCompletion1() { |
1597 |
> |
public void testApplyToEither_normalCompletion() { |
1598 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1599 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1600 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1601 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1602 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1603 |
|
{ |
1604 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1605 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1606 |
|
final IncFunction r = new IncFunction(); |
2062 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1607 |
|
|
1608 |
< |
f.complete(v1); |
1609 |
< |
checkCompletedNormally(h, inc(v1)); |
1610 |
< |
g.complete(v2); |
1608 |
> |
if (!createIncomplete) |
1609 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1610 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1611 |
> |
if (createIncomplete) { |
1612 |
> |
checkIncomplete(h); |
1613 |
> |
assertEquals(0, r.invocationCount); |
1614 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1615 |
> |
} |
1616 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1617 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1618 |
|
|
1619 |
|
checkCompletedNormally(f, v1); |
1620 |
|
checkCompletedNormally(g, v2); |
1621 |
< |
checkCompletedNormally(h, inc(v1)); |
1621 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1622 |
|
}} |
1623 |
|
|
1624 |
< |
public void testApplyToEither_normalCompletion2() { |
1624 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1625 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1626 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1627 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1628 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1629 |
|
{ |
1630 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1631 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1632 |
|
final IncFunction r = new IncFunction(); |
2081 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2082 |
– |
|
2083 |
– |
g.complete(v2); |
2084 |
– |
checkCompletedNormally(h, inc(v2)); |
2085 |
– |
f.complete(v1); |
1633 |
|
|
1634 |
< |
checkCompletedNormally(f, v1); |
1635 |
< |
checkCompletedNormally(g, v2); |
1636 |
< |
checkCompletedNormally(h, inc(v2)); |
1637 |
< |
}} |
1638 |
< |
|
1639 |
< |
public void testApplyToEither_normalCompletion3() { |
1640 |
< |
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(); |
1634 |
> |
if (fFirst) { |
1635 |
> |
f.complete(v1); |
1636 |
> |
g.complete(v2); |
1637 |
> |
} else { |
1638 |
> |
g.complete(v2); |
1639 |
> |
f.complete(v1); |
1640 |
> |
} |
1641 |
|
|
2101 |
– |
f.complete(v1); |
2102 |
– |
g.complete(v2); |
1642 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1643 |
|
|
1644 |
|
checkCompletedNormally(f, v1); |
1656 |
|
*/ |
1657 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1658 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1659 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1660 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1661 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1662 |
|
{ |
1663 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1664 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
– |
final IncFunction r = new IncFunction(); |
2125 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1665 |
|
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<>(); |
1666 |
|
final IncFunction r = new IncFunction(); |
1667 |
+ |
|
1668 |
+ |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1669 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1670 |
< |
final CFException ex = new CFException(); |
1670 |
> |
if (createIncomplete) { |
1671 |
> |
checkIncomplete(h); |
1672 |
> |
assertEquals(0, r.invocationCount); |
1673 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1674 |
> |
} |
1675 |
|
|
2148 |
– |
g.completeExceptionally(ex); |
1676 |
|
checkCompletedWithWrappedCFException(h, ex); |
1677 |
< |
f.complete(v1); |
1677 |
> |
(!fFirst ? f : g).complete(v1); |
1678 |
|
|
1679 |
|
assertEquals(0, r.invocationCount); |
1680 |
< |
checkCompletedNormally(f, v1); |
1681 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1680 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1681 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1682 |
|
checkCompletedWithWrappedCFException(h, ex); |
1683 |
|
}} |
1684 |
|
|
1685 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1685 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1686 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1687 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1688 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1689 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1690 |
|
{ |
1691 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1692 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1693 |
< |
final IncFunction r = new IncFunction(); |
1693 |
> |
final IncFunction r1 = new IncFunction(); |
1694 |
> |
final IncFunction r2 = new IncFunction(); |
1695 |
|
final CFException ex = new CFException(); |
1696 |
< |
|
1697 |
< |
g.completeExceptionally(ex); |
1698 |
< |
f.complete(v1); |
1699 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1696 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1697 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1698 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1699 |
> |
if (fFirst) { |
1700 |
> |
f.complete(v1); |
1701 |
> |
g.completeExceptionally(ex); |
1702 |
> |
} else { |
1703 |
> |
g.completeExceptionally(ex); |
1704 |
> |
f.complete(v1); |
1705 |
> |
} |
1706 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1707 |
|
|
1708 |
|
// unspecified behavior |
2172 |
– |
Integer v; |
1709 |
|
try { |
1710 |
< |
assertEquals(inc(v1), h.join()); |
1711 |
< |
assertEquals(1, r.invocationCount); |
1710 |
> |
assertEquals(inc(v1), h1.join()); |
1711 |
> |
assertEquals(1, r1.invocationCount); |
1712 |
|
} catch (CompletionException ok) { |
1713 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1714 |
< |
assertEquals(0, r.invocationCount); |
1713 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1714 |
> |
assertEquals(0, r1.invocationCount); |
1715 |
|
} |
1716 |
|
|
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; |
1717 |
|
try { |
1718 |
< |
assertEquals(inc(v1), h.join()); |
1719 |
< |
assertEquals(1, r.invocationCount); |
1718 |
> |
assertEquals(inc(v1), h2.join()); |
1719 |
> |
assertEquals(1, r2.invocationCount); |
1720 |
|
} catch (CompletionException ok) { |
1721 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1722 |
< |
assertEquals(0, r.invocationCount); |
1721 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1722 |
> |
assertEquals(0, r2.invocationCount); |
1723 |
|
} |
1724 |
|
|
1725 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1726 |
< |
checkCompletedNormally(g, v1); |
1725 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1726 |
> |
checkCompletedNormally(f, v1); |
1727 |
|
}} |
1728 |
|
|
1729 |
|
/** |
1769 |
|
public void testApplyToEither_sourceCancelled1() { |
1770 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1771 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1772 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1773 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1774 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1775 |
|
{ |
1776 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1777 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1778 |
|
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); |
1779 |
|
|
1780 |
< |
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(); |
1780 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1781 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1782 |
+ |
if (createIncomplete) { |
1783 |
+ |
checkIncomplete(h); |
1784 |
+ |
assertEquals(0, r.invocationCount); |
1785 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1786 |
+ |
} |
1787 |
|
|
2282 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1788 |
|
checkCompletedWithWrappedCancellationException(h); |
1789 |
< |
f.complete(v1); |
1789 |
> |
(!fFirst ? f : g).complete(v1); |
1790 |
|
|
2286 |
– |
checkCancelled(g); |
1791 |
|
assertEquals(0, r.invocationCount); |
1792 |
< |
checkCompletedNormally(f, v1); |
1792 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1793 |
> |
checkCancelled(fFirst ? f : g); |
1794 |
|
checkCompletedWithWrappedCancellationException(h); |
1795 |
|
}} |
1796 |
|
|
1797 |
< |
public void testApplyToEither_sourceCancelled3() { |
1797 |
> |
public void testApplyToEither_sourceCancelled2() { |
1798 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1799 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1800 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1801 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1802 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1803 |
|
{ |
1804 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1805 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1806 |
< |
final IncFunction r = new IncFunction(); |
1806 |
> |
final IncFunction r1 = new IncFunction(); |
1807 |
> |
final IncFunction r2 = new IncFunction(); |
1808 |
> |
final CFException ex = new CFException(); |
1809 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1810 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1811 |
|
|
1812 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1813 |
< |
f.complete(v1); |
1814 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1812 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1813 |
> |
if (fFirst) { |
1814 |
> |
f.complete(v1); |
1815 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1816 |
> |
} else { |
1817 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1818 |
> |
f.complete(v1); |
1819 |
> |
} |
1820 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1821 |
|
|
1822 |
|
// unspecified behavior |
2306 |
– |
Integer v; |
1823 |
|
try { |
1824 |
< |
assertEquals(inc(v1), h.join()); |
1825 |
< |
assertEquals(1, r.invocationCount); |
1824 |
> |
assertEquals(inc(v1), h1.join()); |
1825 |
> |
assertEquals(1, r1.invocationCount); |
1826 |
|
} catch (CompletionException ok) { |
1827 |
< |
checkCompletedWithWrappedCancellationException(h); |
1828 |
< |
assertEquals(0, r.invocationCount); |
1827 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1828 |
> |
assertEquals(0, r1.invocationCount); |
1829 |
|
} |
1830 |
|
|
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; |
1831 |
|
try { |
1832 |
< |
assertEquals(inc(v1), h.join()); |
1833 |
< |
assertEquals(1, r.invocationCount); |
1832 |
> |
assertEquals(inc(v1), h2.join()); |
1833 |
> |
assertEquals(1, r2.invocationCount); |
1834 |
|
} catch (CompletionException ok) { |
1835 |
< |
checkCompletedWithWrappedCancellationException(h); |
1836 |
< |
assertEquals(0, r.invocationCount); |
1835 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1836 |
> |
assertEquals(0, r2.invocationCount); |
1837 |
|
} |
1838 |
|
|
1839 |
< |
checkCancelled(f); |
1840 |
< |
checkCompletedNormally(g, v1); |
1839 |
> |
checkCancelled(g); |
1840 |
> |
checkCompletedNormally(f, v1); |
1841 |
|
}} |
1842 |
|
|
1843 |
|
/** |