339 |
|
static final class IncAction implements Consumer<Integer> { |
340 |
|
int invocationCount = 0; |
341 |
|
Integer value; |
342 |
– |
public boolean ran() { return invocationCount == 1; } |
342 |
|
public void accept(Integer x) { |
343 |
|
invocationCount++; |
344 |
|
value = inc(x); |
347 |
|
static final class IncFunction implements Function<Integer,Integer> { |
348 |
|
int invocationCount = 0; |
349 |
|
Integer value; |
351 |
– |
public boolean ran() { return invocationCount == 1; } |
350 |
|
public Integer apply(Integer x) { |
351 |
|
invocationCount++; |
352 |
|
return value = inc(x); |
356 |
|
int invocationCount = 0; |
357 |
|
Integer value; |
358 |
|
// Check this action was invoked exactly once when result is computed. |
361 |
– |
public boolean ran() { return invocationCount == 1; } |
359 |
|
public void accept(Integer x, Integer y) { |
360 |
|
invocationCount++; |
361 |
|
value = subtract(x, y); |
365 |
|
int invocationCount = 0; |
366 |
|
Integer value; |
367 |
|
// Check this action was invoked exactly once when result is computed. |
371 |
– |
public boolean ran() { return invocationCount == 1; } |
368 |
|
public Integer apply(Integer x, Integer y) { |
369 |
|
invocationCount++; |
370 |
|
return value = subtract(x, y); |
372 |
|
} |
373 |
|
static final class Noop implements Runnable { |
374 |
|
int invocationCount = 0; |
379 |
– |
boolean ran; |
375 |
|
public void run() { |
376 |
|
invocationCount++; |
382 |
– |
ran = true; |
377 |
|
} |
378 |
|
} |
379 |
|
|
380 |
|
static final class FailingSupplier implements Supplier<Integer> { |
381 |
< |
boolean ran; |
382 |
< |
public Integer get() { ran = true; throw new CFException(); } |
381 |
> |
int invocationCount = 0; |
382 |
> |
public Integer get() { |
383 |
> |
invocationCount++; |
384 |
> |
throw new CFException(); |
385 |
> |
} |
386 |
|
} |
387 |
|
static final class FailingConsumer implements Consumer<Integer> { |
388 |
< |
boolean ran; |
389 |
< |
public void accept(Integer x) { ran = true; throw new CFException(); } |
388 |
> |
int invocationCount = 0; |
389 |
> |
public void accept(Integer x) { |
390 |
> |
invocationCount++; |
391 |
> |
throw new CFException(); |
392 |
> |
} |
393 |
|
} |
394 |
|
static final class FailingBiConsumer implements BiConsumer<Integer, Integer> { |
395 |
< |
boolean ran; |
396 |
< |
public void accept(Integer x, Integer y) { ran = true; throw new CFException(); } |
395 |
> |
int invocationCount = 0; |
396 |
> |
public void accept(Integer x, Integer y) { |
397 |
> |
invocationCount++; |
398 |
> |
throw new CFException(); |
399 |
> |
} |
400 |
|
} |
401 |
|
static final class FailingFunction implements Function<Integer, Integer> { |
402 |
< |
boolean ran; |
403 |
< |
public Integer apply(Integer x) { ran = true; throw new CFException(); } |
402 |
> |
int invocationCount = 0; |
403 |
> |
public Integer apply(Integer x) { |
404 |
> |
invocationCount++; |
405 |
> |
throw new CFException(); |
406 |
> |
} |
407 |
|
} |
408 |
|
static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> { |
409 |
< |
boolean ran; |
410 |
< |
public Integer apply(Integer x, Integer y) { ran = true; throw new CFException(); } |
409 |
> |
int invocationCount = 0; |
410 |
> |
public Integer apply(Integer x, Integer y) { |
411 |
> |
invocationCount++; |
412 |
> |
throw new CFException(); |
413 |
> |
} |
414 |
|
} |
415 |
|
static final class FailingNoop implements Runnable { |
416 |
< |
boolean ran; |
417 |
< |
public void run() { ran = true; throw new CFException(); } |
416 |
> |
int invocationCount = 0; |
417 |
> |
public void run() { |
418 |
> |
invocationCount++; |
419 |
> |
throw new CFException(); |
420 |
> |
} |
421 |
|
} |
422 |
|
|
423 |
|
static final class CompletableFutureInc |
424 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
425 |
< |
boolean ran; |
425 |
> |
int invocationCount = 0; |
426 |
|
public CompletableFuture<Integer> apply(Integer x) { |
427 |
< |
ran = true; |
427 |
> |
invocationCount++; |
428 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
429 |
< |
f.complete(Integer.valueOf(x.intValue() + 1)); |
429 |
> |
f.complete(inc(x)); |
430 |
|
return f; |
431 |
|
} |
432 |
|
} |
433 |
|
|
434 |
|
static final class FailingCompletableFutureFunction |
435 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
436 |
< |
boolean ran; |
436 |
> |
int invocationCount = 0; |
437 |
|
public CompletableFuture<Integer> apply(Integer x) { |
438 |
< |
ran = true; throw new CFException(); |
438 |
> |
invocationCount++; |
439 |
> |
throw new CFException(); |
440 |
|
} |
441 |
|
} |
442 |
|
|
455 |
|
} |
456 |
|
|
457 |
|
static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> { |
458 |
< |
boolean ran; |
458 |
> |
int invocationCount = 0; |
459 |
|
public Integer apply(Integer x, Throwable t) { |
460 |
< |
ran = true; |
460 |
> |
invocationCount++; |
461 |
|
return (t == null) ? two : three; |
462 |
|
} |
463 |
|
} |
696 |
|
f = new CompletableFuture<>(); |
697 |
|
f.completeExceptionally(new CFException()); |
698 |
|
g = f.handle(r = new IntegerHandler()); |
699 |
< |
assertTrue(r.ran); |
699 |
> |
assertEquals(1, r.invocationCount); |
700 |
> |
assertEquals(1, r.invocationCount); |
701 |
|
checkCompletedNormally(g, three); |
702 |
|
|
703 |
|
f = new CompletableFuture<>(); |
704 |
|
g = f.handle(r = new IntegerHandler()); |
705 |
< |
assertFalse(r.ran); |
705 |
> |
assertEquals(0, r.invocationCount); |
706 |
|
f.completeExceptionally(new CFException()); |
707 |
|
checkCompletedNormally(g, three); |
708 |
< |
assertTrue(r.ran); |
708 |
> |
assertEquals(1, r.invocationCount); |
709 |
|
|
710 |
|
f = new CompletableFuture<>(); |
711 |
|
f.complete(one); |
712 |
|
g = f.handle(r = new IntegerHandler()); |
713 |
< |
assertTrue(r.ran); |
713 |
> |
assertEquals(1, r.invocationCount); |
714 |
|
checkCompletedNormally(g, two); |
715 |
|
|
716 |
|
f = new CompletableFuture<>(); |
717 |
|
g = f.handle(r = new IntegerHandler()); |
718 |
< |
assertFalse(r.ran); |
718 |
> |
assertEquals(0, r.invocationCount); |
719 |
|
f.complete(one); |
720 |
< |
assertTrue(r.ran); |
720 |
> |
assertEquals(1, r.invocationCount); |
721 |
|
checkCompletedNormally(g, two); |
722 |
|
} |
723 |
|
|
728 |
|
Noop r = new Noop(); |
729 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
730 |
|
assertNull(f.join()); |
731 |
< |
assertTrue(r.ran); |
731 |
> |
assertEquals(1, r.invocationCount); |
732 |
|
checkCompletedNormally(f, null); |
733 |
|
} |
734 |
|
|
740 |
|
ThreadExecutor exec = new ThreadExecutor(); |
741 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
742 |
|
assertNull(f.join()); |
743 |
< |
assertTrue(r.ran); |
743 |
> |
assertEquals(1, r.invocationCount); |
744 |
|
checkCompletedNormally(f, null); |
745 |
|
assertEquals(1, exec.count.get()); |
746 |
|
} |
752 |
|
FailingNoop r = new FailingNoop(); |
753 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
754 |
|
checkCompletedWithWrappedCFException(f); |
755 |
< |
assertTrue(r.ran); |
755 |
> |
assertEquals(1, r.invocationCount); |
756 |
|
} |
757 |
|
|
758 |
|
/** |
782 |
|
FailingSupplier r = new FailingSupplier(); |
783 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r); |
784 |
|
checkCompletedWithWrappedCFException(f); |
785 |
< |
assertTrue(r.ran); |
785 |
> |
assertEquals(1, r.invocationCount); |
786 |
|
} |
787 |
|
|
788 |
|
// seq completion methods |
799 |
|
g = f.thenRun(r = new Noop()); |
800 |
|
f.complete(null); |
801 |
|
checkCompletedNormally(g, null); |
802 |
< |
assertTrue(r.ran); |
802 |
> |
assertEquals(1, r.invocationCount); |
803 |
|
|
804 |
|
f = new CompletableFuture<>(); |
805 |
|
f.complete(null); |
806 |
|
g = f.thenRun(r = new Noop()); |
807 |
|
checkCompletedNormally(g, null); |
808 |
< |
assertTrue(r.ran); |
808 |
> |
assertEquals(1, r.invocationCount); |
809 |
|
} |
810 |
|
|
811 |
|
/** |
821 |
|
g = f.thenRun(r = new Noop()); |
822 |
|
f.completeExceptionally(new CFException()); |
823 |
|
checkCompletedWithWrappedCFException(g); |
824 |
< |
assertFalse(r.ran); |
824 |
> |
assertEquals(0, r.invocationCount); |
825 |
|
|
826 |
|
f = new CompletableFuture<>(); |
827 |
|
f.completeExceptionally(new CFException()); |
828 |
|
g = f.thenRun(r = new Noop()); |
829 |
|
checkCompletedWithWrappedCFException(g); |
830 |
< |
assertFalse(r.ran); |
830 |
> |
assertEquals(0, r.invocationCount); |
831 |
|
} |
832 |
|
|
833 |
|
/** |
942 |
|
CompletableFuture<Void> g = f.thenAccept(r); |
943 |
|
f.complete(one); |
944 |
|
checkCompletedWithWrappedCFException(g); |
945 |
< |
assertTrue(r.ran); |
945 |
> |
assertEquals(1, r.invocationCount); |
946 |
|
} |
947 |
|
|
948 |
|
/** |
961 |
|
* of sources |
962 |
|
*/ |
963 |
|
public void testThenCombine_normalCompletion1() { |
964 |
< |
for (boolean createdIncomplete : new boolean[] { true, false }) |
964 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
965 |
|
for (boolean fFirst : new boolean[] { true, false }) |
966 |
|
for (ExecutionMode m : ExecutionMode.values()) |
967 |
|
for (Integer v1 : new Integer[] { 1, null }) |
971 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
972 |
|
final SubtractFunction r = new SubtractFunction(); |
973 |
|
CompletableFuture<Integer> h = null; |
974 |
< |
if (createdIncomplete) h = m.thenCombine(f, g, r); |
974 |
> |
if (createIncomplete) h = m.thenCombine(f, g, r); |
975 |
|
|
976 |
|
if (fFirst) |
977 |
|
f.complete(v1); |
978 |
|
else |
979 |
|
g.complete(v2); |
980 |
< |
if (createdIncomplete) checkIncomplete(h); |
981 |
< |
assertEquals(r.invocationCount, 0); |
980 |
> |
if (createIncomplete) checkIncomplete(h); |
981 |
> |
assertEquals(0, r.invocationCount); |
982 |
|
if (!fFirst) |
983 |
|
f.complete(v1); |
984 |
|
else |
985 |
|
g.complete(v2); |
986 |
< |
if (!createdIncomplete) h = m.thenCombine(f, g, r); |
986 |
> |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
987 |
|
|
988 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
989 |
|
checkCompletedNormally(f, v1); |
990 |
|
checkCompletedNormally(g, v2); |
991 |
< |
assertEquals(r.invocationCount, 1); |
991 |
> |
assertEquals(1, r.invocationCount); |
992 |
|
} |
993 |
|
} |
994 |
|
|
1012 |
|
|
1013 |
|
checkCompletedWithWrappedCFException(h, ex); |
1014 |
|
checkCompletedWithWrappedCFException(f, ex); |
1015 |
< |
assertEquals(r.invocationCount, 0); |
1015 |
> |
assertEquals(0, r.invocationCount); |
1016 |
|
checkCompletedNormally(g, v1); |
1017 |
|
} |
1018 |
|
} |
1033 |
|
|
1034 |
|
checkCompletedWithWrappedCFException(h, ex); |
1035 |
|
checkCompletedWithWrappedCFException(g, ex); |
1036 |
< |
assertEquals(r.invocationCount, 0); |
1036 |
> |
assertEquals(0, r.invocationCount); |
1037 |
|
checkCompletedNormally(f, v1); |
1038 |
|
} |
1039 |
|
} |
1053 |
|
|
1054 |
|
checkCompletedWithWrappedCFException(h, ex); |
1055 |
|
checkCompletedWithWrappedCFException(g, ex); |
1056 |
< |
assertEquals(r.invocationCount, 0); |
1056 |
> |
assertEquals(0, r.invocationCount); |
1057 |
|
checkCompletedNormally(f, v1); |
1058 |
|
} |
1059 |
|
} |
1073 |
|
|
1074 |
|
checkCompletedWithWrappedCFException(h, ex); |
1075 |
|
checkCompletedWithWrappedCFException(f, ex); |
1076 |
< |
assertEquals(r.invocationCount, 0); |
1076 |
> |
assertEquals(0, r.invocationCount); |
1077 |
|
checkCompletedNormally(g, v1); |
1078 |
|
} |
1079 |
|
} |
1140 |
|
|
1141 |
|
checkCompletedWithWrappedCancellationException(h); |
1142 |
|
checkCancelled(f); |
1143 |
< |
assertEquals(r.invocationCount, 0); |
1143 |
> |
assertEquals(0, r.invocationCount); |
1144 |
|
checkCompletedNormally(g, v1); |
1145 |
|
} |
1146 |
|
} |
1161 |
|
|
1162 |
|
checkCompletedWithWrappedCancellationException(h); |
1163 |
|
checkCancelled(g); |
1164 |
< |
assertEquals(r.invocationCount, 0); |
1164 |
> |
assertEquals(0, r.invocationCount); |
1165 |
|
checkCompletedNormally(f, v1); |
1166 |
|
} |
1167 |
|
} |
1181 |
|
|
1182 |
|
checkCompletedWithWrappedCancellationException(h); |
1183 |
|
checkCancelled(g); |
1184 |
< |
assertEquals(r.invocationCount, 0); |
1184 |
> |
assertEquals(0, r.invocationCount); |
1185 |
|
checkCompletedNormally(f, v1); |
1186 |
|
} |
1187 |
|
} |
1201 |
|
|
1202 |
|
checkCompletedWithWrappedCancellationException(h); |
1203 |
|
checkCancelled(f); |
1204 |
< |
assertEquals(r.invocationCount, 0); |
1204 |
> |
assertEquals(0, r.invocationCount); |
1205 |
|
checkCompletedNormally(g, v1); |
1206 |
|
} |
1207 |
|
} |
1222 |
|
|
1223 |
|
f.complete(v1); |
1224 |
|
checkIncomplete(h); |
1225 |
< |
assertFalse(r.ran()); |
1225 |
> |
assertEquals(0, r.invocationCount); |
1226 |
|
g.complete(v2); |
1227 |
|
|
1228 |
|
checkCompletedNormally(h, null); |
1244 |
|
|
1245 |
|
g.complete(v2); |
1246 |
|
checkIncomplete(h); |
1247 |
< |
assertFalse(r.ran()); |
1247 |
> |
assertEquals(0, r.invocationCount); |
1248 |
|
f.complete(v1); |
1249 |
|
|
1250 |
|
checkCompletedNormally(h, null); |
1314 |
|
|
1315 |
|
checkCompletedWithWrappedCFException(h, ex); |
1316 |
|
checkCompletedWithWrappedCFException(f, ex); |
1317 |
< |
assertEquals(r.invocationCount, 0); |
1317 |
> |
assertEquals(0, r.invocationCount); |
1318 |
|
checkCompletedNormally(g, v1); |
1319 |
|
} |
1320 |
|
} |
1335 |
|
|
1336 |
|
checkCompletedWithWrappedCFException(h, ex); |
1337 |
|
checkCompletedWithWrappedCFException(g, ex); |
1338 |
< |
assertEquals(r.invocationCount, 0); |
1338 |
> |
assertEquals(0, r.invocationCount); |
1339 |
|
checkCompletedNormally(f, v1); |
1340 |
|
} |
1341 |
|
} |
1355 |
|
|
1356 |
|
checkCompletedWithWrappedCFException(h, ex); |
1357 |
|
checkCompletedWithWrappedCFException(g, ex); |
1358 |
< |
assertEquals(r.invocationCount, 0); |
1358 |
> |
assertEquals(0, r.invocationCount); |
1359 |
|
checkCompletedNormally(f, v1); |
1360 |
|
} |
1361 |
|
} |
1375 |
|
|
1376 |
|
checkCompletedWithWrappedCFException(h, ex); |
1377 |
|
checkCompletedWithWrappedCFException(f, ex); |
1378 |
< |
assertFalse(r.ran()); |
1378 |
> |
assertEquals(0, r.invocationCount); |
1379 |
|
checkCompletedNormally(g, v1); |
1380 |
|
} |
1381 |
|
} |
1442 |
|
|
1443 |
|
checkCompletedWithWrappedCancellationException(h); |
1444 |
|
checkCancelled(f); |
1445 |
< |
assertEquals(r.invocationCount, 0); |
1445 |
> |
assertEquals(0, r.invocationCount); |
1446 |
|
checkCompletedNormally(g, v1); |
1447 |
|
} |
1448 |
|
} |
1463 |
|
|
1464 |
|
checkCompletedWithWrappedCancellationException(h); |
1465 |
|
checkCancelled(g); |
1466 |
< |
assertEquals(r.invocationCount, 0); |
1466 |
> |
assertEquals(0, r.invocationCount); |
1467 |
|
checkCompletedNormally(f, v1); |
1468 |
|
} |
1469 |
|
} |
1483 |
|
|
1484 |
|
checkCompletedWithWrappedCancellationException(h); |
1485 |
|
checkCancelled(g); |
1486 |
< |
assertEquals(r.invocationCount, 0); |
1486 |
> |
assertEquals(0, r.invocationCount); |
1487 |
|
checkCompletedNormally(f, v1); |
1488 |
|
} |
1489 |
|
} |
1503 |
|
|
1504 |
|
checkCompletedWithWrappedCancellationException(h); |
1505 |
|
checkCancelled(f); |
1506 |
< |
assertEquals(r.invocationCount, 0); |
1506 |
> |
assertEquals(0, r.invocationCount); |
1507 |
|
checkCompletedNormally(g, v1); |
1508 |
|
} |
1509 |
|
} |
1524 |
|
|
1525 |
|
f.complete(v1); |
1526 |
|
checkIncomplete(h); |
1527 |
< |
assertFalse(r.ran); |
1527 |
> |
assertEquals(0, r.invocationCount); |
1528 |
|
g.complete(v2); |
1529 |
|
|
1530 |
|
checkCompletedNormally(h, null); |
1531 |
< |
assertEquals(r.invocationCount, 1); |
1531 |
> |
assertEquals(1, r.invocationCount); |
1532 |
|
checkCompletedNormally(f, v1); |
1533 |
|
checkCompletedNormally(g, v2); |
1534 |
|
} |
1546 |
|
|
1547 |
|
g.complete(v2); |
1548 |
|
checkIncomplete(h); |
1549 |
< |
assertFalse(r.ran); |
1549 |
> |
assertEquals(0, r.invocationCount); |
1550 |
|
f.complete(v1); |
1551 |
|
|
1552 |
|
checkCompletedNormally(h, null); |
1553 |
< |
assertEquals(r.invocationCount, 1); |
1553 |
> |
assertEquals(1, r.invocationCount); |
1554 |
|
checkCompletedNormally(f, v1); |
1555 |
|
checkCompletedNormally(g, v2); |
1556 |
|
} |
1570 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1571 |
|
|
1572 |
|
checkCompletedNormally(h, null); |
1573 |
< |
assertTrue(r.ran); |
1573 |
> |
assertEquals(1, r.invocationCount); |
1574 |
|
checkCompletedNormally(f, v1); |
1575 |
|
checkCompletedNormally(g, v2); |
1576 |
|
} |
1590 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1591 |
|
|
1592 |
|
checkCompletedNormally(h, null); |
1593 |
< |
assertEquals(r.invocationCount, 1); |
1593 |
> |
assertEquals(1, r.invocationCount); |
1594 |
|
checkCompletedNormally(f, v1); |
1595 |
|
checkCompletedNormally(g, v2); |
1596 |
|
} |
1616 |
|
|
1617 |
|
checkCompletedWithWrappedCFException(h, ex); |
1618 |
|
checkCompletedWithWrappedCFException(f, ex); |
1619 |
< |
assertEquals(r.invocationCount, 0); |
1619 |
> |
assertEquals(0, r.invocationCount); |
1620 |
|
checkCompletedNormally(g, v1); |
1621 |
|
} |
1622 |
|
} |
1637 |
|
|
1638 |
|
checkCompletedWithWrappedCFException(h, ex); |
1639 |
|
checkCompletedWithWrappedCFException(g, ex); |
1640 |
< |
assertEquals(r.invocationCount, 0); |
1640 |
> |
assertEquals(0, r.invocationCount); |
1641 |
|
checkCompletedNormally(f, v1); |
1642 |
|
} |
1643 |
|
} |
1657 |
|
|
1658 |
|
checkCompletedWithWrappedCFException(h, ex); |
1659 |
|
checkCompletedWithWrappedCFException(g, ex); |
1660 |
< |
assertEquals(r.invocationCount, 0); |
1660 |
> |
assertEquals(0, r.invocationCount); |
1661 |
|
checkCompletedNormally(f, v1); |
1662 |
|
} |
1663 |
|
} |
1677 |
|
|
1678 |
|
checkCompletedWithWrappedCFException(h, ex); |
1679 |
|
checkCompletedWithWrappedCFException(f, ex); |
1680 |
< |
assertEquals(r.invocationCount, 0); |
1680 |
> |
assertEquals(0, r.invocationCount); |
1681 |
|
checkCompletedNormally(g, v1); |
1682 |
|
} |
1683 |
|
} |
1744 |
|
|
1745 |
|
checkCompletedWithWrappedCancellationException(h); |
1746 |
|
checkCancelled(f); |
1747 |
< |
assertEquals(r.invocationCount, 0); |
1747 |
> |
assertEquals(0, r.invocationCount); |
1748 |
|
checkCompletedNormally(g, v1); |
1749 |
|
} |
1750 |
|
} |
1765 |
|
|
1766 |
|
checkCompletedWithWrappedCancellationException(h); |
1767 |
|
checkCancelled(g); |
1768 |
< |
assertEquals(r.invocationCount, 0); |
1768 |
> |
assertEquals(0, r.invocationCount); |
1769 |
|
checkCompletedNormally(f, v1); |
1770 |
|
} |
1771 |
|
} |
1785 |
|
|
1786 |
|
checkCompletedWithWrappedCancellationException(h); |
1787 |
|
checkCancelled(g); |
1788 |
< |
assertEquals(r.invocationCount, 0); |
1788 |
> |
assertEquals(0, r.invocationCount); |
1789 |
|
checkCompletedNormally(f, v1); |
1790 |
|
} |
1791 |
|
} |
1805 |
|
|
1806 |
|
checkCompletedWithWrappedCancellationException(h); |
1807 |
|
checkCancelled(f); |
1808 |
< |
assertEquals(r.invocationCount, 0); |
1808 |
> |
assertEquals(0, r.invocationCount); |
1809 |
|
checkCompletedNormally(g, v1); |
1810 |
|
} |
1811 |
|
} |
1872 |
|
// unspecified behavior |
1873 |
|
assertTrue(Objects.equals(h.join(), inc(v1)) || |
1874 |
|
Objects.equals(h.join(), inc(v2))); |
1875 |
< |
assertEquals(r.invocationCount, 1); |
1875 |
> |
assertEquals(1, r.invocationCount); |
1876 |
|
} |
1877 |
|
} |
1878 |
|
|
1894 |
|
checkCompletedWithWrappedCFException(h, ex); |
1895 |
|
g.complete(v1); |
1896 |
|
|
1897 |
< |
assertEquals(r.invocationCount, 0); |
1897 |
> |
assertEquals(0, r.invocationCount); |
1898 |
|
checkCompletedNormally(g, v1); |
1899 |
|
checkCompletedWithWrappedCFException(f, ex); |
1900 |
|
checkCompletedWithWrappedCFException(h, ex); |
1915 |
|
checkCompletedWithWrappedCFException(h, ex); |
1916 |
|
f.complete(v1); |
1917 |
|
|
1918 |
< |
assertEquals(r.invocationCount, 0); |
1918 |
> |
assertEquals(0, r.invocationCount); |
1919 |
|
checkCompletedNormally(f, v1); |
1920 |
|
checkCompletedWithWrappedCFException(g, ex); |
1921 |
|
checkCompletedWithWrappedCFException(h, ex); |
1939 |
|
Integer v; |
1940 |
|
try { |
1941 |
|
assertEquals(h.join(), inc(v1)); |
1942 |
< |
assertEquals(r.invocationCount, 1); |
1942 |
> |
assertEquals(1, r.invocationCount); |
1943 |
|
} catch (CompletionException ok) { |
1944 |
|
checkCompletedWithWrappedCFException(h, ex); |
1945 |
< |
assertEquals(r.invocationCount, 0); |
1945 |
> |
assertEquals(0, r.invocationCount); |
1946 |
|
} |
1947 |
|
|
1948 |
|
checkCompletedWithWrappedCFException(g, ex); |
1967 |
|
Integer v; |
1968 |
|
try { |
1969 |
|
assertEquals(h.join(), inc(v1)); |
1970 |
< |
assertEquals(r.invocationCount, 1); |
1970 |
> |
assertEquals(1, r.invocationCount); |
1971 |
|
} catch (CompletionException ok) { |
1972 |
|
checkCompletedWithWrappedCFException(h, ex); |
1973 |
< |
assertEquals(r.invocationCount, 0); |
1973 |
> |
assertEquals(0, r.invocationCount); |
1974 |
|
} |
1975 |
|
|
1976 |
|
checkCompletedWithWrappedCFException(f, ex); |
2035 |
|
g.complete(v1); |
2036 |
|
|
2037 |
|
checkCancelled(f); |
2038 |
< |
assertEquals(r.invocationCount, 0); |
2038 |
> |
assertEquals(0, r.invocationCount); |
2039 |
|
checkCompletedNormally(g, v1); |
2040 |
|
checkCompletedWithWrappedCancellationException(h); |
2041 |
|
} |
2056 |
|
f.complete(v1); |
2057 |
|
|
2058 |
|
checkCancelled(g); |
2059 |
< |
assertEquals(r.invocationCount, 0); |
2059 |
> |
assertEquals(0, r.invocationCount); |
2060 |
|
checkCompletedNormally(f, v1); |
2061 |
|
checkCompletedWithWrappedCancellationException(h); |
2062 |
|
} |
2079 |
|
Integer v; |
2080 |
|
try { |
2081 |
|
assertEquals(h.join(), inc(v1)); |
2082 |
< |
assertEquals(r.invocationCount, 1); |
2082 |
> |
assertEquals(1, r.invocationCount); |
2083 |
|
} catch (CompletionException ok) { |
2084 |
|
checkCompletedWithWrappedCancellationException(h); |
2085 |
< |
assertEquals(r.invocationCount, 0); |
2085 |
> |
assertEquals(0, r.invocationCount); |
2086 |
|
} |
2087 |
|
|
2088 |
|
checkCancelled(g); |
2107 |
|
Integer v; |
2108 |
|
try { |
2109 |
|
assertEquals(h.join(), inc(v1)); |
2110 |
< |
assertEquals(r.invocationCount, 1); |
2110 |
> |
assertEquals(1, r.invocationCount); |
2111 |
|
} catch (CompletionException ok) { |
2112 |
|
checkCompletedWithWrappedCancellationException(h); |
2113 |
< |
assertEquals(r.invocationCount, 0); |
2113 |
> |
assertEquals(0, r.invocationCount); |
2114 |
|
} |
2115 |
|
|
2116 |
|
checkCancelled(f); |
2204 |
|
checkCompletedWithWrappedCFException(h, ex); |
2205 |
|
g.complete(v1); |
2206 |
|
|
2207 |
< |
assertEquals(r.invocationCount, 0); |
2207 |
> |
assertEquals(0, r.invocationCount); |
2208 |
|
checkCompletedNormally(g, v1); |
2209 |
|
checkCompletedWithWrappedCFException(f, ex); |
2210 |
|
checkCompletedWithWrappedCFException(h, ex); |
2225 |
|
checkCompletedWithWrappedCFException(h, ex); |
2226 |
|
f.complete(v1); |
2227 |
|
|
2228 |
< |
assertEquals(r.invocationCount, 0); |
2228 |
> |
assertEquals(0, r.invocationCount); |
2229 |
|
checkCompletedNormally(f, v1); |
2230 |
|
checkCompletedWithWrappedCFException(g, ex); |
2231 |
|
checkCompletedWithWrappedCFException(h, ex); |
2249 |
|
Integer v; |
2250 |
|
try { |
2251 |
|
assertEquals(h.join(), null); |
2252 |
< |
assertEquals(r.invocationCount, 1); |
2252 |
> |
assertEquals(1, r.invocationCount); |
2253 |
|
assertEquals(inc(v1), r.value); |
2254 |
|
} catch (CompletionException ok) { |
2255 |
|
checkCompletedWithWrappedCFException(h, ex); |
2256 |
< |
assertEquals(r.invocationCount, 0); |
2256 |
> |
assertEquals(0, r.invocationCount); |
2257 |
|
} |
2258 |
|
|
2259 |
|
checkCompletedWithWrappedCFException(g, ex); |
2278 |
|
Integer v; |
2279 |
|
try { |
2280 |
|
assertEquals(h.join(), null); |
2281 |
< |
assertEquals(r.invocationCount, 1); |
2281 |
> |
assertEquals(1, r.invocationCount); |
2282 |
|
assertEquals(inc(v1), r.value); |
2283 |
|
} catch (CompletionException ok) { |
2284 |
|
checkCompletedWithWrappedCFException(h, ex); |
2285 |
< |
assertEquals(r.invocationCount, 0); |
2285 |
> |
assertEquals(0, r.invocationCount); |
2286 |
|
} |
2287 |
|
|
2288 |
|
checkCompletedWithWrappedCFException(f, ex); |
2347 |
|
g.complete(v1); |
2348 |
|
|
2349 |
|
checkCancelled(f); |
2350 |
< |
assertEquals(r.invocationCount, 0); |
2350 |
> |
assertEquals(0, r.invocationCount); |
2351 |
|
checkCompletedNormally(g, v1); |
2352 |
|
checkCompletedWithWrappedCancellationException(h); |
2353 |
|
} |
2368 |
|
f.complete(v1); |
2369 |
|
|
2370 |
|
checkCancelled(g); |
2371 |
< |
assertEquals(r.invocationCount, 0); |
2371 |
> |
assertEquals(0, r.invocationCount); |
2372 |
|
checkCompletedNormally(f, v1); |
2373 |
|
checkCompletedWithWrappedCancellationException(h); |
2374 |
|
} |
2391 |
|
Integer v; |
2392 |
|
try { |
2393 |
|
assertEquals(h.join(), null); |
2394 |
< |
assertEquals(r.invocationCount, 1); |
2394 |
> |
assertEquals(1, r.invocationCount); |
2395 |
|
assertEquals(inc(v1), r.value); |
2396 |
|
} catch (CompletionException ok) { |
2397 |
|
checkCompletedWithWrappedCancellationException(h); |
2398 |
< |
assertEquals(r.invocationCount, 0); |
2398 |
> |
assertEquals(0, r.invocationCount); |
2399 |
|
} |
2400 |
|
|
2401 |
|
checkCancelled(g); |
2420 |
|
Integer v; |
2421 |
|
try { |
2422 |
|
assertEquals(h.join(), null); |
2423 |
< |
assertEquals(r.invocationCount, 1); |
2423 |
> |
assertEquals(1, r.invocationCount); |
2424 |
|
assertEquals(inc(v1), r.value); |
2425 |
|
} catch (CompletionException ok) { |
2426 |
|
checkCompletedWithWrappedCancellationException(h); |
2427 |
< |
assertEquals(r.invocationCount, 0); |
2427 |
> |
assertEquals(0, r.invocationCount); |
2428 |
|
} |
2429 |
|
|
2430 |
|
checkCancelled(f); |
2448 |
|
|
2449 |
|
f.complete(v1); |
2450 |
|
checkCompletedNormally(h, null); |
2451 |
< |
assertEquals(r.invocationCount, 1); |
2451 |
> |
assertEquals(1, r.invocationCount); |
2452 |
|
g.complete(v2); |
2453 |
|
|
2454 |
|
checkCompletedNormally(f, v1); |
2455 |
|
checkCompletedNormally(g, v2); |
2456 |
|
checkCompletedNormally(h, null); |
2457 |
< |
assertEquals(r.invocationCount, 1); |
2457 |
> |
assertEquals(1, r.invocationCount); |
2458 |
|
} |
2459 |
|
} |
2460 |
|
|
2470 |
|
|
2471 |
|
g.complete(v2); |
2472 |
|
checkCompletedNormally(h, null); |
2473 |
< |
assertEquals(r.invocationCount, 1); |
2473 |
> |
assertEquals(1, r.invocationCount); |
2474 |
|
f.complete(v1); |
2475 |
|
|
2476 |
|
checkCompletedNormally(f, v1); |
2477 |
|
checkCompletedNormally(g, v2); |
2478 |
|
checkCompletedNormally(h, null); |
2479 |
< |
assertEquals(r.invocationCount, 1); |
2479 |
> |
assertEquals(1, r.invocationCount); |
2480 |
|
} |
2481 |
|
} |
2482 |
|
public void testRunAfterEither_normalCompletion3() { |
2495 |
|
checkCompletedNormally(h, null); |
2496 |
|
checkCompletedNormally(f, v1); |
2497 |
|
checkCompletedNormally(g, v2); |
2498 |
< |
assertEquals(r.invocationCount, 1); |
2498 |
> |
assertEquals(1, r.invocationCount); |
2499 |
|
} |
2500 |
|
} |
2501 |
|
|
2517 |
|
checkCompletedWithWrappedCFException(h, ex); |
2518 |
|
g.complete(v1); |
2519 |
|
|
2520 |
< |
assertEquals(r.invocationCount, 0); |
2520 |
> |
assertEquals(0, r.invocationCount); |
2521 |
|
checkCompletedNormally(g, v1); |
2522 |
|
checkCompletedWithWrappedCFException(f, ex); |
2523 |
|
checkCompletedWithWrappedCFException(h, ex); |
2538 |
|
checkCompletedWithWrappedCFException(h, ex); |
2539 |
|
f.complete(v1); |
2540 |
|
|
2541 |
< |
assertEquals(r.invocationCount, 0); |
2541 |
> |
assertEquals(0, r.invocationCount); |
2542 |
|
checkCompletedNormally(f, v1); |
2543 |
|
checkCompletedWithWrappedCFException(g, ex); |
2544 |
|
checkCompletedWithWrappedCFException(h, ex); |
2562 |
|
Integer v; |
2563 |
|
try { |
2564 |
|
assertEquals(h.join(), null); |
2565 |
< |
assertEquals(r.invocationCount, 1); |
2565 |
> |
assertEquals(1, r.invocationCount); |
2566 |
|
} catch (CompletionException ok) { |
2567 |
|
checkCompletedWithWrappedCFException(h, ex); |
2568 |
< |
assertEquals(r.invocationCount, 0); |
2568 |
> |
assertEquals(0, r.invocationCount); |
2569 |
|
} |
2570 |
|
|
2571 |
|
checkCompletedWithWrappedCFException(g, ex); |
2590 |
|
Integer v; |
2591 |
|
try { |
2592 |
|
assertEquals(h.join(), null); |
2593 |
< |
assertEquals(r.invocationCount, 1); |
2593 |
> |
assertEquals(1, r.invocationCount); |
2594 |
|
} catch (CompletionException ok) { |
2595 |
|
checkCompletedWithWrappedCFException(h, ex); |
2596 |
< |
assertEquals(r.invocationCount, 0); |
2596 |
> |
assertEquals(0, r.invocationCount); |
2597 |
|
} |
2598 |
|
|
2599 |
|
checkCompletedWithWrappedCFException(f, ex); |
2658 |
|
g.complete(v1); |
2659 |
|
|
2660 |
|
checkCancelled(f); |
2661 |
< |
assertEquals(r.invocationCount, 0); |
2661 |
> |
assertEquals(0, r.invocationCount); |
2662 |
|
checkCompletedNormally(g, v1); |
2663 |
|
checkCompletedWithWrappedCancellationException(h); |
2664 |
|
} |
2679 |
|
f.complete(v1); |
2680 |
|
|
2681 |
|
checkCancelled(g); |
2682 |
< |
assertEquals(r.invocationCount, 0); |
2682 |
> |
assertEquals(0, r.invocationCount); |
2683 |
|
checkCompletedNormally(f, v1); |
2684 |
|
checkCompletedWithWrappedCancellationException(h); |
2685 |
|
} |
2702 |
|
Integer v; |
2703 |
|
try { |
2704 |
|
assertEquals(h.join(), null); |
2705 |
< |
assertEquals(r.invocationCount, 1); |
2705 |
> |
assertEquals(1, r.invocationCount); |
2706 |
|
} catch (CompletionException ok) { |
2707 |
|
checkCompletedWithWrappedCancellationException(h); |
2708 |
< |
assertEquals(r.invocationCount, 0); |
2708 |
> |
assertEquals(0, r.invocationCount); |
2709 |
|
} |
2710 |
|
|
2711 |
|
checkCancelled(g); |
2730 |
|
Integer v; |
2731 |
|
try { |
2732 |
|
assertEquals(h.join(), null); |
2733 |
< |
assertEquals(r.invocationCount, 1); |
2733 |
> |
assertEquals(1, r.invocationCount); |
2734 |
|
} catch (CompletionException ok) { |
2735 |
|
checkCompletedWithWrappedCancellationException(h); |
2736 |
< |
assertEquals(r.invocationCount, 0); |
2736 |
> |
assertEquals(0, r.invocationCount); |
2737 |
|
} |
2738 |
|
|
2739 |
|
checkCancelled(f); |
2744 |
|
/** |
2745 |
|
* thenCompose result completes normally after normal completion of source |
2746 |
|
*/ |
2747 |
< |
public void testThenCompose() { |
2748 |
< |
CompletableFuture<Integer> f, g; |
2749 |
< |
CompletableFutureInc r; |
2747 |
> |
public void testThenCompose_normalCompletion1() { |
2748 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2749 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2750 |
|
|
2751 |
< |
f = new CompletableFuture<>(); |
2752 |
< |
g = f.thenCompose(r = new CompletableFutureInc()); |
2753 |
< |
f.complete(one); |
2754 |
< |
checkCompletedNormally(g, two); |
2755 |
< |
assertTrue(r.ran); |
2751 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2752 |
> |
final CompletableFutureInc r = new CompletableFutureInc(); |
2753 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2754 |
> |
f.complete(v1); |
2755 |
> |
checkCompletedNormally(g, inc(v1)); |
2756 |
> |
checkCompletedNormally(f, v1); |
2757 |
> |
assertEquals(1, r.invocationCount); |
2758 |
> |
} |
2759 |
> |
} |
2760 |
|
|
2761 |
< |
f = new CompletableFuture<>(); |
2762 |
< |
f.complete(one); |
2763 |
< |
g = f.thenCompose(r = new CompletableFutureInc()); |
2764 |
< |
checkCompletedNormally(g, two); |
2765 |
< |
assertTrue(r.ran); |
2761 |
> |
public void testThenCompose_normalCompletion2() { |
2762 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2763 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2764 |
> |
|
2765 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2766 |
> |
final CompletableFutureInc r = new CompletableFutureInc(); |
2767 |
> |
f.complete(v1); |
2768 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2769 |
> |
checkCompletedNormally(g, inc(v1)); |
2770 |
> |
checkCompletedNormally(f, v1); |
2771 |
> |
assertEquals(1, r.invocationCount); |
2772 |
> |
} |
2773 |
|
} |
2774 |
|
|
2775 |
|
/** |
2776 |
|
* thenCompose result completes exceptionally after exceptional |
2777 |
|
* completion of source |
2778 |
|
*/ |
2779 |
< |
public void testThenCompose2() { |
2780 |
< |
CompletableFuture<Integer> f, g; |
2756 |
< |
CompletableFutureInc r; |
2779 |
> |
public void testThenCompose_exceptionalCompletion1() { |
2780 |
> |
for (ExecutionMode m : ExecutionMode.values()) { |
2781 |
|
|
2782 |
< |
f = new CompletableFuture<>(); |
2783 |
< |
g = f.thenCompose(r = new CompletableFutureInc()); |
2784 |
< |
f.completeExceptionally(new CFException()); |
2785 |
< |
checkCompletedWithWrappedCFException(g); |
2782 |
> |
final CFException ex = new CFException(); |
2783 |
> |
final CompletableFutureInc r = new CompletableFutureInc(); |
2784 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2785 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2786 |
> |
f.completeExceptionally(ex); |
2787 |
> |
checkCompletedWithWrappedCFException(g, ex); |
2788 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2789 |
> |
} |
2790 |
> |
} |
2791 |
|
|
2792 |
< |
f = new CompletableFuture<>(); |
2793 |
< |
f.completeExceptionally(new CFException()); |
2794 |
< |
g = f.thenCompose(r = new CompletableFutureInc()); |
2795 |
< |
checkCompletedWithWrappedCFException(g); |
2792 |
> |
public void testThenCompose_exceptionalCompletion2() { |
2793 |
> |
for (ExecutionMode m : ExecutionMode.values()) { |
2794 |
> |
|
2795 |
> |
final CFException ex = new CFException(); |
2796 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2797 |
> |
f.completeExceptionally(ex); |
2798 |
> |
final CompletableFutureInc r = new CompletableFutureInc(); |
2799 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2800 |
> |
checkCompletedWithWrappedCFException(g, ex); |
2801 |
> |
checkCompletedWithWrappedCFException(f, ex); |
2802 |
> |
} |
2803 |
|
} |
2804 |
|
|
2805 |
|
/** |
2806 |
|
* thenCompose result completes exceptionally if action does |
2807 |
|
*/ |
2808 |
< |
public void testThenCompose3() { |
2809 |
< |
CompletableFuture<Integer> f, g; |
2810 |
< |
FailingCompletableFutureFunction r; |
2808 |
> |
public void testThenCompose_actionFailed1() { |
2809 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2810 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2811 |
|
|
2812 |
< |
f = new CompletableFuture<>(); |
2813 |
< |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
2814 |
< |
f.complete(one); |
2812 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2813 |
> |
final FailingCompletableFutureFunction r |
2814 |
> |
= new FailingCompletableFutureFunction(); |
2815 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2816 |
> |
f.complete(v1); |
2817 |
|
checkCompletedWithWrappedCFException(g); |
2818 |
+ |
checkCompletedNormally(f, v1); |
2819 |
+ |
} |
2820 |
+ |
} |
2821 |
|
|
2822 |
< |
f = new CompletableFuture<>(); |
2823 |
< |
f.complete(one); |
2824 |
< |
g = f.thenCompose(r = new FailingCompletableFutureFunction()); |
2822 |
> |
public void testThenCompose_actionFailed2() { |
2823 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2824 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
2825 |
> |
|
2826 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2827 |
> |
f.complete(v1); |
2828 |
> |
final FailingCompletableFutureFunction r |
2829 |
> |
= new FailingCompletableFutureFunction(); |
2830 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2831 |
|
checkCompletedWithWrappedCFException(g); |
2832 |
+ |
checkCompletedNormally(f, v1); |
2833 |
+ |
} |
2834 |
|
} |
2835 |
|
|
2836 |
|
/** |
2837 |
|
* thenCompose result completes exceptionally if source cancelled |
2838 |
|
*/ |
2839 |
< |
public void testThenCompose4() { |
2840 |
< |
CompletableFuture<Integer> f, g; |
2841 |
< |
CompletableFutureInc r; |
2839 |
> |
public void testThenCompose_sourceCancelled1() { |
2840 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2841 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
2842 |
|
|
2843 |
< |
f = new CompletableFuture<>(); |
2844 |
< |
g = f.thenCompose(r = new CompletableFutureInc()); |
2845 |
< |
assertTrue(f.cancel(true)); |
2843 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2844 |
> |
final CompletableFutureInc r = new CompletableFutureInc(); |
2845 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2846 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2847 |
|
checkCompletedWithWrappedCancellationException(g); |
2848 |
+ |
checkCancelled(f); |
2849 |
+ |
} |
2850 |
+ |
} |
2851 |
|
|
2852 |
< |
f = new CompletableFuture<>(); |
2853 |
< |
assertTrue(f.cancel(true)); |
2854 |
< |
g = f.thenCompose(r = new CompletableFutureInc()); |
2852 |
> |
public void testThenCompose_sourceCancelled2() { |
2853 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2854 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
2855 |
> |
|
2856 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2857 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2858 |
> |
final CompletableFutureInc r = new CompletableFutureInc(); |
2859 |
> |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2860 |
|
checkCompletedWithWrappedCancellationException(g); |
2861 |
+ |
checkCancelled(f); |
2862 |
+ |
} |
2863 |
|
} |
2864 |
|
|
2865 |
|
// asyncs |
3009 |
|
checkCompletedWithWrappedCancellationException(g); |
3010 |
|
} |
3011 |
|
|
2952 |
– |
/** |
2953 |
– |
* thenComposeAsync result completes normally after normal |
2954 |
– |
* completion of source |
2955 |
– |
*/ |
2956 |
– |
public void testThenComposeAsync() { |
2957 |
– |
CompletableFuture<Integer> f, g; |
2958 |
– |
CompletableFutureInc r; |
2959 |
– |
|
2960 |
– |
f = new CompletableFuture<>(); |
2961 |
– |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2962 |
– |
f.complete(one); |
2963 |
– |
checkCompletedNormally(g, two); |
2964 |
– |
|
2965 |
– |
f = new CompletableFuture<>(); |
2966 |
– |
f.complete(one); |
2967 |
– |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2968 |
– |
checkCompletedNormally(g, two); |
2969 |
– |
} |
2970 |
– |
|
2971 |
– |
/** |
2972 |
– |
* thenComposeAsync result completes exceptionally after |
2973 |
– |
* exceptional completion of source |
2974 |
– |
*/ |
2975 |
– |
public void testThenComposeAsync2() { |
2976 |
– |
CompletableFuture<Integer> f, g; |
2977 |
– |
CompletableFutureInc r; |
2978 |
– |
|
2979 |
– |
f = new CompletableFuture<>(); |
2980 |
– |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2981 |
– |
f.completeExceptionally(new CFException()); |
2982 |
– |
checkCompletedWithWrappedCFException(g); |
2983 |
– |
assertFalse(r.ran); |
2984 |
– |
|
2985 |
– |
f = new CompletableFuture<>(); |
2986 |
– |
f.completeExceptionally(new CFException()); |
2987 |
– |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
2988 |
– |
checkCompletedWithWrappedCFException(g); |
2989 |
– |
assertFalse(r.ran); |
2990 |
– |
} |
2991 |
– |
|
2992 |
– |
/** |
2993 |
– |
* thenComposeAsync result completes exceptionally if action does |
2994 |
– |
*/ |
2995 |
– |
public void testThenComposeAsync3() { |
2996 |
– |
CompletableFuture<Integer> f, g; |
2997 |
– |
FailingCompletableFutureFunction r; |
2998 |
– |
|
2999 |
– |
f = new CompletableFuture<>(); |
3000 |
– |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
3001 |
– |
f.complete(one); |
3002 |
– |
checkCompletedWithWrappedCFException(g); |
3003 |
– |
|
3004 |
– |
f = new CompletableFuture<>(); |
3005 |
– |
f.complete(one); |
3006 |
– |
g = f.thenComposeAsync(r = new FailingCompletableFutureFunction()); |
3007 |
– |
checkCompletedWithWrappedCFException(g); |
3008 |
– |
} |
3009 |
– |
|
3010 |
– |
/** |
3011 |
– |
* thenComposeAsync result completes exceptionally if source cancelled |
3012 |
– |
*/ |
3013 |
– |
public void testThenComposeAsync4() { |
3014 |
– |
CompletableFuture<Integer> f, g; |
3015 |
– |
CompletableFutureInc r; |
3016 |
– |
|
3017 |
– |
f = new CompletableFuture<>(); |
3018 |
– |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
3019 |
– |
assertTrue(f.cancel(true)); |
3020 |
– |
checkCompletedWithWrappedCancellationException(g); |
3021 |
– |
|
3022 |
– |
f = new CompletableFuture<>(); |
3023 |
– |
assertTrue(f.cancel(true)); |
3024 |
– |
g = f.thenComposeAsync(r = new CompletableFutureInc()); |
3025 |
– |
checkCompletedWithWrappedCancellationException(g); |
3026 |
– |
} |
3027 |
– |
|
3012 |
|
// async with explicit executors |
3013 |
|
|
3014 |
|
/** |
3156 |
|
checkCompletedWithWrappedCancellationException(g); |
3157 |
|
} |
3158 |
|
|
3175 |
– |
/** |
3176 |
– |
* thenComposeAsync result completes normally after normal |
3177 |
– |
* completion of source |
3178 |
– |
*/ |
3179 |
– |
public void testThenComposeAsyncE() { |
3180 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3181 |
– |
CompletableFutureInc r = new CompletableFutureInc(); |
3182 |
– |
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3183 |
– |
f.complete(one); |
3184 |
– |
checkCompletedNormally(g, two); |
3185 |
– |
} |
3186 |
– |
|
3187 |
– |
/** |
3188 |
– |
* thenComposeAsync result completes exceptionally after |
3189 |
– |
* exceptional completion of source |
3190 |
– |
*/ |
3191 |
– |
public void testThenComposeAsync2E() { |
3192 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3193 |
– |
CompletableFutureInc r = new CompletableFutureInc(); |
3194 |
– |
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3195 |
– |
f.completeExceptionally(new CFException()); |
3196 |
– |
checkCompletedWithWrappedCFException(g); |
3197 |
– |
} |
3198 |
– |
|
3199 |
– |
/** |
3200 |
– |
* thenComposeAsync result completes exceptionally if action does |
3201 |
– |
*/ |
3202 |
– |
public void testThenComposeAsync3E() { |
3203 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3204 |
– |
FailingCompletableFutureFunction r = new FailingCompletableFutureFunction(); |
3205 |
– |
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3206 |
– |
f.complete(one); |
3207 |
– |
checkCompletedWithWrappedCFException(g); |
3208 |
– |
} |
3209 |
– |
|
3210 |
– |
/** |
3211 |
– |
* thenComposeAsync result completes exceptionally if source cancelled |
3212 |
– |
*/ |
3213 |
– |
public void testThenComposeAsync4E() { |
3214 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3215 |
– |
CompletableFutureInc r = new CompletableFutureInc(); |
3216 |
– |
CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor()); |
3217 |
– |
assertTrue(f.cancel(true)); |
3218 |
– |
checkCompletedWithWrappedCancellationException(g); |
3219 |
– |
} |
3220 |
– |
|
3159 |
|
// other static methods |
3160 |
|
|
3161 |
|
/** |
3355 |
|
* source result. |
3356 |
|
*/ |
3357 |
|
public void testWhenComplete_normalCompletion1() { |
3358 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
3359 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3360 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
3361 |
|
|
3362 |
|
final AtomicInteger a = new AtomicInteger(); |
3363 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3364 |
+ |
if (!createIncomplete) f.complete(v1); |
3365 |
|
final CompletableFuture<Integer> g = |
3366 |
|
m.whenComplete(f, |
3367 |
|
(Integer x, Throwable t) -> { |
3369 |
|
threadAssertNull(t); |
3370 |
|
a.getAndIncrement(); |
3371 |
|
}); |
3372 |
< |
f.complete(v1); |
3372 |
> |
if (createIncomplete) f.complete(v1); |
3373 |
|
checkCompletedNormally(f, v1); |
3374 |
|
checkCompletedNormally(g, v1); |
3375 |
|
assertEquals(a.get(), 1); |
3381 |
|
* source result. |
3382 |
|
*/ |
3383 |
|
public void testWhenComplete_exceptionalCompletion() { |
3384 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
3385 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3386 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
3387 |
|
|
3388 |
|
final AtomicInteger a = new AtomicInteger(); |
3389 |
|
final CFException ex = new CFException(); |
3390 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3391 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
3392 |
|
final CompletableFuture<Integer> g = m.whenComplete |
3393 |
|
(f, |
3394 |
|
(Integer x, Throwable t) -> { |
3396 |
|
threadAssertSame(t, ex); |
3397 |
|
a.getAndIncrement(); |
3398 |
|
}); |
3399 |
< |
f.completeExceptionally(ex); |
3399 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
3400 |
|
checkCompletedWithWrappedCFException(f, ex); |
3401 |
|
checkCompletedWithWrappedCFException(g, ex); |
3402 |
|
assertEquals(a.get(), 1); |
3408 |
|
* a normal completion, it completes exceptionally |
3409 |
|
*/ |
3410 |
|
public void testWhenComplete_actionFailed() { |
3411 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
3412 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3413 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
3414 |
|
|
3415 |
|
final CFException ex = new CFException(); |
3416 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3417 |
+ |
if (!createIncomplete) f.complete(v1); |
3418 |
|
final CompletableFuture<Integer> g = m.whenComplete |
3419 |
|
(f, |
3420 |
|
(Integer x, Throwable t) -> { |
3422 |
|
threadAssertNull(t); |
3423 |
|
throw ex; |
3424 |
|
}); |
3425 |
< |
f.complete(v1); |
3425 |
> |
if (createIncomplete) f.complete(v1); |
3426 |
|
checkCompletedNormally(f, v1); |
3427 |
|
checkCompletedWithWrappedCFException(g, ex); |
3428 |
|
} |
3434 |
|
* exception takes precedence. |
3435 |
|
*/ |
3436 |
|
public void testWhenComplete_actionFailedSourceFailed() { |
3437 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
3438 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3439 |
|
for (Integer v1 : new Integer[] { 1, null }) { |
3440 |
|
|
3441 |
|
final CFException ex1 = new CFException(); |
3442 |
|
final CFException ex2 = new CFException(); |
3443 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3444 |
+ |
|
3445 |
+ |
if (!createIncomplete) f.completeExceptionally(ex1); |
3446 |
|
final CompletableFuture<Integer> g = m.whenComplete |
3447 |
|
(f, |
3448 |
|
(Integer x, Throwable t) -> { |
3450 |
|
threadAssertNull(x); |
3451 |
|
throw ex2; |
3452 |
|
}); |
3453 |
< |
f.completeExceptionally(ex1); |
3453 |
> |
if (createIncomplete) f.completeExceptionally(ex1); |
3454 |
> |
|
3455 |
|
checkCompletedWithWrappedCFException(f, ex1); |
3456 |
|
checkCompletedWithWrappedCFException(g, ex1); |
3457 |
|
} |
3467 |
|
|
3468 |
|
f = new CompletableFuture<>(); |
3469 |
|
g = f.handleAsync(r = new IntegerHandler()); |
3470 |
< |
assertFalse(r.ran); |
3470 |
> |
assertEquals(0, r.invocationCount); |
3471 |
|
f.completeExceptionally(new CFException()); |
3472 |
|
checkCompletedWithWrappedCFException(f); |
3473 |
|
checkCompletedNormally(g, three); |
3474 |
< |
assertTrue(r.ran); |
3474 |
> |
assertEquals(1, r.invocationCount); |
3475 |
|
|
3476 |
|
f = new CompletableFuture<>(); |
3477 |
|
g = f.handleAsync(r = new IntegerHandler()); |
3478 |
< |
assertFalse(r.ran); |
3478 |
> |
assertEquals(0, r.invocationCount); |
3479 |
|
f.completeExceptionally(new CFException()); |
3480 |
|
checkCompletedWithWrappedCFException(f); |
3481 |
|
checkCompletedNormally(g, three); |
3482 |
< |
assertTrue(r.ran); |
3482 |
> |
assertEquals(1, r.invocationCount); |
3483 |
|
|
3484 |
|
f = new CompletableFuture<>(); |
3485 |
|
g = f.handleAsync(r = new IntegerHandler()); |
3486 |
< |
assertFalse(r.ran); |
3486 |
> |
assertEquals(0, r.invocationCount); |
3487 |
|
f.complete(one); |
3488 |
|
checkCompletedNormally(f, one); |
3489 |
|
checkCompletedNormally(g, two); |
3490 |
< |
assertTrue(r.ran); |
3490 |
> |
assertEquals(1, r.invocationCount); |
3491 |
|
|
3492 |
|
f = new CompletableFuture<>(); |
3493 |
|
g = f.handleAsync(r = new IntegerHandler()); |
3494 |
< |
assertFalse(r.ran); |
3494 |
> |
assertEquals(0, r.invocationCount); |
3495 |
|
f.complete(one); |
3496 |
|
checkCompletedNormally(f, one); |
3497 |
|
checkCompletedNormally(g, two); |
3498 |
< |
assertTrue(r.ran); |
3498 |
> |
assertEquals(1, r.invocationCount); |
3499 |
|
} |
3500 |
|
|
3501 |
|
/** |
3510 |
|
|
3511 |
|
f = new CompletableFuture<>(); |
3512 |
|
g = f.handleAsync(r = new IntegerHandler(), exec); |
3513 |
< |
assertFalse(r.ran); |
3513 |
> |
assertEquals(0, r.invocationCount); |
3514 |
|
f.completeExceptionally(new CFException()); |
3515 |
|
checkCompletedWithWrappedCFException(f); |
3516 |
|
checkCompletedNormally(g, three); |
3517 |
< |
assertTrue(r.ran); |
3517 |
> |
assertEquals(1, r.invocationCount); |
3518 |
|
|
3519 |
|
f = new CompletableFuture<>(); |
3520 |
|
g = f.handleAsync(r = new IntegerHandler(), exec); |
3521 |
< |
assertFalse(r.ran); |
3521 |
> |
assertEquals(0, r.invocationCount); |
3522 |
|
f.completeExceptionally(new CFException()); |
3523 |
|
checkCompletedWithWrappedCFException(f); |
3524 |
|
checkCompletedNormally(g, three); |
3525 |
< |
assertTrue(r.ran); |
3525 |
> |
assertEquals(1, r.invocationCount); |
3526 |
|
|
3527 |
|
f = new CompletableFuture<>(); |
3528 |
|
g = f.handleAsync(r = new IntegerHandler(), exec); |
3529 |
< |
assertFalse(r.ran); |
3529 |
> |
assertEquals(0, r.invocationCount); |
3530 |
|
f.complete(one); |
3531 |
|
checkCompletedNormally(f, one); |
3532 |
|
checkCompletedNormally(g, two); |
3533 |
< |
assertTrue(r.ran); |
3533 |
> |
assertEquals(1, r.invocationCount); |
3534 |
|
|
3535 |
|
f = new CompletableFuture<>(); |
3536 |
|
g = f.handleAsync(r = new IntegerHandler(), exec); |
3537 |
< |
assertFalse(r.ran); |
3537 |
> |
assertEquals(0, r.invocationCount); |
3538 |
|
f.complete(one); |
3539 |
|
checkCompletedNormally(f, one); |
3540 |
|
checkCompletedNormally(g, two); |
3541 |
< |
assertTrue(r.ran); |
3541 |
> |
assertEquals(1, r.invocationCount); |
3542 |
|
} |
3543 |
|
|
3544 |
|
} |