17 |
|
import java.util.concurrent.CompletableFuture; |
18 |
|
import java.util.concurrent.CompletionException; |
19 |
|
import java.util.concurrent.CompletionStage; |
20 |
+ |
import java.util.concurrent.ForkJoinPool; |
21 |
+ |
import java.util.concurrent.ForkJoinTask; |
22 |
|
import java.util.concurrent.TimeoutException; |
23 |
|
import java.util.concurrent.atomic.AtomicInteger; |
24 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
416 |
|
throw new CFException(); |
417 |
|
} |
418 |
|
} |
419 |
< |
static final class FailingNoop implements Runnable { |
419 |
> |
static final class FailingRunnable implements Runnable { |
420 |
|
int invocationCount = 0; |
421 |
|
public void run() { |
422 |
|
invocationCount++; |
460 |
|
*/ |
461 |
|
enum ExecutionMode { |
462 |
|
DEFAULT { |
463 |
+ |
public void checkExecutionMode() { |
464 |
+ |
assertNull(ForkJoinTask.getPool()); |
465 |
+ |
} |
466 |
|
public <T> CompletableFuture<Void> thenRun |
467 |
|
(CompletableFuture<T> f, Runnable a) { |
468 |
|
return f.thenRun(a); |
526 |
|
} |
527 |
|
}, |
528 |
|
|
529 |
< |
DEFAULT_ASYNC { |
529 |
> |
ASYNC { |
530 |
> |
public void checkExecutionMode() { |
531 |
> |
assertSame(ForkJoinPool.commonPool(), |
532 |
> |
ForkJoinTask.getPool()); |
533 |
> |
} |
534 |
|
public <T> CompletableFuture<Void> thenRun |
535 |
|
(CompletableFuture<T> f, Runnable a) { |
536 |
|
return f.thenRunAsync(a); |
595 |
|
}, |
596 |
|
|
597 |
|
EXECUTOR { |
598 |
+ |
public void checkExecutionMode() { |
599 |
+ |
//TODO |
600 |
+ |
} |
601 |
|
public <T> CompletableFuture<Void> thenRun |
602 |
|
(CompletableFuture<T> f, Runnable a) { |
603 |
|
return f.thenRunAsync(a, new ThreadExecutor()); |
661 |
|
} |
662 |
|
}; |
663 |
|
|
664 |
+ |
public abstract void checkExecutionMode(); |
665 |
|
public abstract <T> CompletableFuture<Void> thenRun |
666 |
|
(CompletableFuture<T> f, Runnable a); |
667 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
933 |
|
* failing runAsync completes exceptionally after running Runnable |
934 |
|
*/ |
935 |
|
public void testRunAsync3() { |
936 |
< |
FailingNoop r = new FailingNoop(); |
936 |
> |
FailingRunnable r = new FailingRunnable(); |
937 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
938 |
|
checkCompletedWithWrappedCFException(f); |
939 |
|
assertEquals(1, r.invocationCount); |
974 |
|
/** |
975 |
|
* thenRun result completes normally after normal completion of source |
976 |
|
*/ |
977 |
< |
public void testThenRun() { |
978 |
< |
CompletableFuture<Integer> f; |
979 |
< |
CompletableFuture<Void> g; |
980 |
< |
Noop r; |
981 |
< |
|
982 |
< |
f = new CompletableFuture<>(); |
983 |
< |
g = f.thenRun(r = new Noop()); |
984 |
< |
f.complete(null); |
985 |
< |
checkCompletedNormally(g, null); |
986 |
< |
assertEquals(1, r.invocationCount); |
977 |
> |
public void testThenRun_normalCompletion() { |
978 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
979 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
980 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
981 |
> |
{ |
982 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
983 |
> |
final Noop r = new Noop(); |
984 |
> |
if (!createIncomplete) f.complete(v1); |
985 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
986 |
> |
if (createIncomplete) { |
987 |
> |
checkIncomplete(g); |
988 |
> |
f.complete(v1); |
989 |
> |
} |
990 |
|
|
975 |
– |
f = new CompletableFuture<>(); |
976 |
– |
f.complete(null); |
977 |
– |
g = f.thenRun(r = new Noop()); |
991 |
|
checkCompletedNormally(g, null); |
992 |
+ |
checkCompletedNormally(f, v1); |
993 |
|
assertEquals(1, r.invocationCount); |
994 |
< |
} |
994 |
> |
}} |
995 |
|
|
996 |
|
/** |
997 |
|
* thenRun result completes exceptionally after exceptional |
998 |
|
* completion of source |
999 |
|
*/ |
1000 |
< |
public void testThenRun2() { |
1001 |
< |
CompletableFuture<Integer> f; |
1002 |
< |
CompletableFuture<Void> g; |
1003 |
< |
Noop r; |
1004 |
< |
|
1005 |
< |
f = new CompletableFuture<>(); |
1006 |
< |
g = f.thenRun(r = new Noop()); |
1007 |
< |
f.completeExceptionally(new CFException()); |
1008 |
< |
checkCompletedWithWrappedCFException(g); |
1009 |
< |
assertEquals(0, r.invocationCount); |
1000 |
> |
public void testThenRun_exceptionalCompletion() { |
1001 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1002 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1003 |
> |
{ |
1004 |
> |
final CFException ex = new CFException(); |
1005 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1006 |
> |
final Noop r = new Noop(); |
1007 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1008 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1009 |
> |
if (createIncomplete) { |
1010 |
> |
checkIncomplete(g); |
1011 |
> |
f.completeExceptionally(ex); |
1012 |
> |
} |
1013 |
|
|
1014 |
< |
f = new CompletableFuture<>(); |
1015 |
< |
f.completeExceptionally(new CFException()); |
999 |
< |
g = f.thenRun(r = new Noop()); |
1000 |
< |
checkCompletedWithWrappedCFException(g); |
1014 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1015 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1016 |
|
assertEquals(0, r.invocationCount); |
1017 |
< |
} |
1003 |
< |
|
1004 |
< |
/** |
1005 |
< |
* thenRun result completes exceptionally if action does |
1006 |
< |
*/ |
1007 |
< |
public void testThenRun3() { |
1008 |
< |
CompletableFuture<Integer> f; |
1009 |
< |
CompletableFuture<Void> g; |
1010 |
< |
FailingNoop r; |
1011 |
< |
|
1012 |
< |
f = new CompletableFuture<>(); |
1013 |
< |
g = f.thenRun(r = new FailingNoop()); |
1014 |
< |
f.complete(null); |
1015 |
< |
checkCompletedWithWrappedCFException(g); |
1016 |
< |
|
1017 |
< |
f = new CompletableFuture<>(); |
1018 |
< |
f.complete(null); |
1019 |
< |
g = f.thenRun(r = new FailingNoop()); |
1020 |
< |
checkCompletedWithWrappedCFException(g); |
1021 |
< |
} |
1017 |
> |
}} |
1018 |
|
|
1019 |
|
/** |
1020 |
|
* thenRun result completes exceptionally if source cancelled |
1021 |
|
*/ |
1022 |
< |
public void testThenRun4() { |
1023 |
< |
CompletableFuture<Integer> f; |
1024 |
< |
CompletableFuture<Void> g; |
1025 |
< |
Noop r; |
1026 |
< |
|
1027 |
< |
f = new CompletableFuture<>(); |
1028 |
< |
g = f.thenRun(r = new Noop()); |
1029 |
< |
assertTrue(f.cancel(true)); |
1030 |
< |
checkCompletedWithWrappedCancellationException(g); |
1031 |
< |
|
1032 |
< |
f = new CompletableFuture<>(); |
1033 |
< |
assertTrue(f.cancel(true)); |
1034 |
< |
g = f.thenRun(r = new Noop()); |
1039 |
< |
checkCompletedWithWrappedCancellationException(g); |
1040 |
< |
} |
1041 |
< |
|
1042 |
< |
/** |
1043 |
< |
* thenApply result completes normally after normal completion of source |
1044 |
< |
*/ |
1045 |
< |
public void testThenApply() { |
1046 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1047 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1048 |
< |
f.complete(one); |
1049 |
< |
checkCompletedNormally(g, two); |
1050 |
< |
} |
1051 |
< |
|
1052 |
< |
/** |
1053 |
< |
* thenApply result completes exceptionally after exceptional |
1054 |
< |
* completion of source |
1055 |
< |
*/ |
1056 |
< |
public void testThenApply2() { |
1057 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1058 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1059 |
< |
f.completeExceptionally(new CFException()); |
1060 |
< |
checkCompletedWithWrappedCFException(g); |
1061 |
< |
} |
1062 |
< |
|
1063 |
< |
/** |
1064 |
< |
* thenApply result completes exceptionally if action does |
1065 |
< |
*/ |
1066 |
< |
public void testThenApply3() { |
1067 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1068 |
< |
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
1069 |
< |
f.complete(one); |
1070 |
< |
checkCompletedWithWrappedCFException(g); |
1071 |
< |
} |
1022 |
> |
public void testThenRun_sourceCancelled() { |
1023 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1024 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1025 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1026 |
> |
{ |
1027 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1028 |
> |
final Noop r = new Noop(); |
1029 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1030 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1031 |
> |
if (createIncomplete) { |
1032 |
> |
checkIncomplete(g); |
1033 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1034 |
> |
} |
1035 |
|
|
1073 |
– |
/** |
1074 |
– |
* thenApply result completes exceptionally if source cancelled |
1075 |
– |
*/ |
1076 |
– |
public void testThenApply4() { |
1077 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1078 |
– |
CompletableFuture<Integer> g = f.thenApply(inc); |
1079 |
– |
assertTrue(f.cancel(true)); |
1036 |
|
checkCompletedWithWrappedCancellationException(g); |
1037 |
< |
} |
1038 |
< |
|
1039 |
< |
/** |
1084 |
< |
* thenAccept result completes normally after normal completion of source |
1085 |
< |
*/ |
1086 |
< |
public void testThenAccept() { |
1087 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1088 |
< |
IncAction r = new IncAction(); |
1089 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1090 |
< |
f.complete(one); |
1091 |
< |
checkCompletedNormally(g, null); |
1092 |
< |
assertEquals(r.value, (Integer) 2); |
1093 |
< |
} |
1037 |
> |
checkCancelled(f); |
1038 |
> |
assertEquals(0, r.invocationCount); |
1039 |
> |
}} |
1040 |
|
|
1041 |
|
/** |
1042 |
< |
* thenAccept result completes exceptionally after exceptional |
1097 |
< |
* completion of source |
1042 |
> |
* thenRun result completes exceptionally if action does |
1043 |
|
*/ |
1044 |
< |
public void testThenAccept2() { |
1045 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1046 |
< |
IncAction r = new IncAction(); |
1047 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1048 |
< |
f.completeExceptionally(new CFException()); |
1049 |
< |
checkCompletedWithWrappedCFException(g); |
1050 |
< |
} |
1044 |
> |
public void testThenRun_actionFailed() { |
1045 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1046 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1047 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1048 |
> |
{ |
1049 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1050 |
> |
final FailingRunnable r = new FailingRunnable(); |
1051 |
> |
if (!createIncomplete) f.complete(v1); |
1052 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1053 |
> |
if (createIncomplete) { |
1054 |
> |
checkIncomplete(g); |
1055 |
> |
f.complete(v1); |
1056 |
> |
} |
1057 |
|
|
1107 |
– |
/** |
1108 |
– |
* thenAccept result completes exceptionally if action does |
1109 |
– |
*/ |
1110 |
– |
public void testThenAccept3() { |
1111 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1112 |
– |
FailingConsumer r = new FailingConsumer(); |
1113 |
– |
CompletableFuture<Void> g = f.thenAccept(r); |
1114 |
– |
f.complete(one); |
1058 |
|
checkCompletedWithWrappedCFException(g); |
1059 |
< |
assertEquals(1, r.invocationCount); |
1060 |
< |
} |
1118 |
< |
|
1119 |
< |
/** |
1120 |
< |
* thenAccept result completes exceptionally if source cancelled |
1121 |
< |
*/ |
1122 |
< |
public void testThenAccept4() { |
1123 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1124 |
< |
IncAction r = new IncAction(); |
1125 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1126 |
< |
assertTrue(f.cancel(true)); |
1127 |
< |
checkCompletedWithWrappedCancellationException(g); |
1128 |
< |
} |
1059 |
> |
checkCompletedNormally(f, v1); |
1060 |
> |
}} |
1061 |
|
|
1062 |
|
/** |
1063 |
< |
* thenCombine result completes normally after normal completion |
1132 |
< |
* of sources |
1063 |
> |
* thenApply result completes normally after normal completion of source |
1064 |
|
*/ |
1065 |
< |
public void testThenCombine_normalCompletion1() { |
1135 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
1136 |
< |
for (boolean fFirst : new boolean[] { true, false }) |
1065 |
> |
public void testThenApply_normalCompletion() { |
1066 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1067 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1068 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1139 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1069 |
|
{ |
1070 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1071 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1072 |
< |
final SubtractFunction r = new SubtractFunction(); |
1073 |
< |
CompletableFuture<Integer> h = null; |
1074 |
< |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1075 |
< |
|
1147 |
< |
if (fFirst) |
1148 |
< |
f.complete(v1); |
1149 |
< |
else |
1150 |
< |
g.complete(v2); |
1151 |
< |
if (createIncomplete) checkIncomplete(h); |
1152 |
< |
assertEquals(0, r.invocationCount); |
1153 |
< |
if (!fFirst) |
1071 |
> |
final IncFunction r = new IncFunction(); |
1072 |
> |
if (!createIncomplete) f.complete(v1); |
1073 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1074 |
> |
if (createIncomplete) { |
1075 |
> |
checkIncomplete(g); |
1076 |
|
f.complete(v1); |
1077 |
< |
else |
1156 |
< |
g.complete(v2); |
1157 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1077 |
> |
} |
1078 |
|
|
1079 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
1079 |
> |
checkCompletedNormally(g, inc(v1)); |
1080 |
|
checkCompletedNormally(f, v1); |
1161 |
– |
checkCompletedNormally(g, v2); |
1081 |
|
assertEquals(1, r.invocationCount); |
1082 |
|
}} |
1083 |
|
|
1084 |
|
/** |
1085 |
< |
* thenCombine result completes exceptionally after exceptional |
1086 |
< |
* completion of either source |
1085 |
> |
* thenApply result completes exceptionally after exceptional |
1086 |
> |
* completion of source |
1087 |
|
*/ |
1088 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1088 |
> |
public void testThenApply_exceptionalCompletion() { |
1089 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1090 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1090 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1091 |
|
{ |
1173 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1174 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1175 |
– |
final SubtractFunction r = new SubtractFunction(); |
1176 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1092 |
|
final CFException ex = new CFException(); |
1093 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1094 |
+ |
final IncFunction r = new IncFunction(); |
1095 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
1096 |
+ |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1097 |
+ |
if (createIncomplete) { |
1098 |
+ |
checkIncomplete(g); |
1099 |
+ |
f.completeExceptionally(ex); |
1100 |
+ |
} |
1101 |
|
|
1102 |
< |
f.completeExceptionally(ex); |
1180 |
< |
checkIncomplete(h); |
1181 |
< |
g.complete(v1); |
1182 |
< |
|
1183 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1102 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1103 |
|
checkCompletedWithWrappedCFException(f, ex); |
1104 |
|
assertEquals(0, r.invocationCount); |
1186 |
– |
checkCompletedNormally(g, v1); |
1105 |
|
}} |
1106 |
|
|
1107 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1107 |
> |
/** |
1108 |
> |
* thenApply result completes exceptionally if source cancelled |
1109 |
> |
*/ |
1110 |
> |
public void testThenApply_sourceCancelled() { |
1111 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1112 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1112 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1113 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1114 |
|
{ |
1115 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1116 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1117 |
< |
final SubtractFunction r = new SubtractFunction(); |
1118 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1119 |
< |
final CFException ex = new CFException(); |
1120 |
< |
|
1121 |
< |
g.completeExceptionally(ex); |
1122 |
< |
checkIncomplete(h); |
1201 |
< |
f.complete(v1); |
1116 |
> |
final IncFunction r = new IncFunction(); |
1117 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1118 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1119 |
> |
if (createIncomplete) { |
1120 |
> |
checkIncomplete(g); |
1121 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1122 |
> |
} |
1123 |
|
|
1124 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1125 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1124 |
> |
checkCompletedWithWrappedCancellationException(g); |
1125 |
> |
checkCancelled(f); |
1126 |
|
assertEquals(0, r.invocationCount); |
1206 |
– |
checkCompletedNormally(f, v1); |
1127 |
|
}} |
1128 |
|
|
1129 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1129 |
> |
/** |
1130 |
> |
* thenApply result completes exceptionally if action does |
1131 |
> |
*/ |
1132 |
> |
public void testThenApply_actionFailed() { |
1133 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1134 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1135 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1136 |
|
{ |
1137 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1138 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1139 |
< |
final SubtractFunction r = new SubtractFunction(); |
1140 |
< |
final CFException ex = new CFException(); |
1141 |
< |
|
1142 |
< |
g.completeExceptionally(ex); |
1143 |
< |
f.complete(v1); |
1144 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1138 |
> |
final FailingFunction r = new FailingFunction(); |
1139 |
> |
if (!createIncomplete) f.complete(v1); |
1140 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1141 |
> |
if (createIncomplete) { |
1142 |
> |
checkIncomplete(g); |
1143 |
> |
f.complete(v1); |
1144 |
> |
} |
1145 |
|
|
1146 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1223 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1224 |
< |
assertEquals(0, r.invocationCount); |
1146 |
> |
checkCompletedWithWrappedCFException(g); |
1147 |
|
checkCompletedNormally(f, v1); |
1148 |
|
}} |
1149 |
|
|
1150 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1150 |
> |
/** |
1151 |
> |
* thenAccept result completes normally after normal completion of source |
1152 |
> |
*/ |
1153 |
> |
public void testThenAccept_normalCompletion() { |
1154 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1155 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1156 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1157 |
|
{ |
1158 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1159 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1160 |
< |
final SubtractFunction r = new SubtractFunction(); |
1161 |
< |
final CFException ex = new CFException(); |
1162 |
< |
|
1163 |
< |
f.completeExceptionally(ex); |
1164 |
< |
g.complete(v1); |
1165 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1159 |
> |
final IncAction r = new IncAction(); |
1160 |
> |
if (!createIncomplete) f.complete(v1); |
1161 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1162 |
> |
if (createIncomplete) { |
1163 |
> |
checkIncomplete(g); |
1164 |
> |
f.complete(v1); |
1165 |
> |
} |
1166 |
|
|
1167 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1168 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1169 |
< |
assertEquals(0, r.invocationCount); |
1170 |
< |
checkCompletedNormally(g, v1); |
1167 |
> |
checkCompletedNormally(g, null); |
1168 |
> |
checkCompletedNormally(f, v1); |
1169 |
> |
assertEquals(1, r.invocationCount); |
1170 |
> |
assertEquals(inc(v1), r.value); |
1171 |
|
}} |
1172 |
|
|
1173 |
|
/** |
1174 |
< |
* thenCombine result completes exceptionally if action does |
1174 |
> |
* thenAccept result completes exceptionally after exceptional |
1175 |
> |
* completion of source |
1176 |
|
*/ |
1177 |
< |
public void testThenCombine_actionFailed1() { |
1177 |
> |
public void testThenAccept_exceptionalCompletion() { |
1178 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1179 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1253 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1179 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1180 |
|
{ |
1181 |
+ |
final CFException ex = new CFException(); |
1182 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1183 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1184 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1185 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1186 |
< |
|
1187 |
< |
f.complete(v1); |
1188 |
< |
checkIncomplete(h); |
1189 |
< |
g.complete(v2); |
1183 |
> |
final IncAction r = new IncAction(); |
1184 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1185 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1186 |
> |
if (createIncomplete) { |
1187 |
> |
checkIncomplete(g); |
1188 |
> |
f.completeExceptionally(ex); |
1189 |
> |
} |
1190 |
|
|
1191 |
< |
checkCompletedWithWrappedCFException(h); |
1192 |
< |
checkCompletedNormally(f, v1); |
1193 |
< |
checkCompletedNormally(g, v2); |
1191 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1192 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1193 |
> |
assertEquals(0, r.invocationCount); |
1194 |
|
}} |
1195 |
|
|
1196 |
< |
public void testThenCombine_actionFailed2() { |
1196 |
> |
/** |
1197 |
> |
* thenAccept result completes exceptionally if action does |
1198 |
> |
*/ |
1199 |
> |
public void testThenAccept_actionFailed() { |
1200 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1201 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1202 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1272 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1203 |
|
{ |
1204 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1205 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1206 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1207 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1208 |
< |
|
1209 |
< |
g.complete(v2); |
1210 |
< |
checkIncomplete(h); |
1211 |
< |
f.complete(v1); |
1205 |
> |
final FailingConsumer r = new FailingConsumer(); |
1206 |
> |
if (!createIncomplete) f.complete(v1); |
1207 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1208 |
> |
if (createIncomplete) { |
1209 |
> |
checkIncomplete(g); |
1210 |
> |
f.complete(v1); |
1211 |
> |
} |
1212 |
|
|
1213 |
< |
checkCompletedWithWrappedCFException(h); |
1213 |
> |
checkCompletedWithWrappedCFException(g); |
1214 |
|
checkCompletedNormally(f, v1); |
1285 |
– |
checkCompletedNormally(g, v2); |
1215 |
|
}} |
1216 |
|
|
1217 |
|
/** |
1218 |
< |
* thenCombine result completes exceptionally if either source cancelled |
1218 |
> |
* thenAccept result completes exceptionally if source cancelled |
1219 |
|
*/ |
1220 |
< |
public void testThenCombine_sourceCancelled1() { |
1220 |
> |
public void testThenAccept_sourceCancelled() { |
1221 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1222 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1223 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1294 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1224 |
|
{ |
1225 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1226 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1227 |
< |
final SubtractFunction r = new SubtractFunction(); |
1228 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1229 |
< |
|
1230 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1231 |
< |
checkIncomplete(h); |
1232 |
< |
g.complete(v1); |
1226 |
> |
final IncAction r = new IncAction(); |
1227 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1228 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1229 |
> |
if (createIncomplete) { |
1230 |
> |
checkIncomplete(g); |
1231 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1232 |
> |
} |
1233 |
|
|
1234 |
< |
checkCompletedWithWrappedCancellationException(h); |
1234 |
> |
checkCompletedWithWrappedCancellationException(g); |
1235 |
|
checkCancelled(f); |
1236 |
|
assertEquals(0, r.invocationCount); |
1308 |
– |
checkCompletedNormally(g, v1); |
1237 |
|
}} |
1238 |
|
|
1239 |
< |
public void testThenCombine_sourceCancelled2() { |
1240 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1241 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1242 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1243 |
< |
{ |
1316 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1317 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1318 |
< |
final SubtractFunction r = new SubtractFunction(); |
1319 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1320 |
< |
|
1321 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1322 |
< |
checkIncomplete(h); |
1323 |
< |
f.complete(v1); |
1324 |
< |
|
1325 |
< |
checkCompletedWithWrappedCancellationException(h); |
1326 |
< |
checkCancelled(g); |
1327 |
< |
assertEquals(0, r.invocationCount); |
1328 |
< |
checkCompletedNormally(f, v1); |
1329 |
< |
}} |
1330 |
< |
|
1331 |
< |
public void testThenCombine_sourceCancelled3() { |
1239 |
> |
/** |
1240 |
> |
* thenCombine result completes normally after normal completion |
1241 |
> |
* of sources |
1242 |
> |
*/ |
1243 |
> |
public void testThenCombine_normalCompletion() { |
1244 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1245 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1245 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1246 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1247 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1248 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
1249 |
|
{ |
1250 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1251 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1252 |
|
final SubtractFunction r = new SubtractFunction(); |
1253 |
|
|
1254 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1255 |
< |
f.complete(v1); |
1254 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1255 |
> |
if (!createIncomplete) |
1256 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1257 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1258 |
+ |
if (createIncomplete) { |
1259 |
+ |
checkIncomplete(h); |
1260 |
+ |
assertEquals(0, r.invocationCount); |
1261 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1262 |
+ |
} |
1263 |
|
|
1264 |
< |
checkCompletedWithWrappedCancellationException(h); |
1345 |
< |
checkCancelled(g); |
1346 |
< |
assertEquals(0, r.invocationCount); |
1264 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
1265 |
|
checkCompletedNormally(f, v1); |
1266 |
+ |
checkCompletedNormally(g, v2); |
1267 |
+ |
assertEquals(1, r.invocationCount); |
1268 |
|
}} |
1269 |
|
|
1270 |
< |
public void testThenCombine_sourceCancelled4() { |
1270 |
> |
/** |
1271 |
> |
* thenCombine result completes exceptionally after exceptional |
1272 |
> |
* completion of either source |
1273 |
> |
*/ |
1274 |
> |
public void testThenCombine_exceptionalCompletion() { |
1275 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
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<>(); |
1282 |
+ |
final CFException ex = new CFException(); |
1283 |
|
final SubtractFunction r = new SubtractFunction(); |
1284 |
|
|
1285 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
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 |
< |
checkCompletedWithWrappedCancellationException(h); |
1364 |
< |
checkCancelled(f); |
1294 |
> |
checkCompletedWithWrappedCFException(h, 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 |
< |
* thenAcceptBoth result completes normally after normal |
1371 |
< |
* completion of sources |
1301 |
> |
* thenCombine result completes exceptionally if action does |
1302 |
|
*/ |
1303 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1374 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1375 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1376 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1377 |
< |
{ |
1378 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1379 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1380 |
< |
final SubtractAction r = new SubtractAction(); |
1381 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1382 |
< |
|
1383 |
< |
f.complete(v1); |
1384 |
< |
checkIncomplete(h); |
1385 |
< |
assertEquals(0, r.invocationCount); |
1386 |
< |
g.complete(v2); |
1387 |
< |
|
1388 |
< |
checkCompletedNormally(h, null); |
1389 |
< |
assertEquals(subtract(v1, v2), r.value); |
1390 |
< |
checkCompletedNormally(f, v1); |
1391 |
< |
checkCompletedNormally(g, v2); |
1392 |
< |
}} |
1393 |
< |
|
1394 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
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 |
|
{ |
1309 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1310 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1311 |
< |
final SubtractAction r = new SubtractAction(); |
1312 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1311 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1312 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1313 |
|
|
1314 |
< |
g.complete(v2); |
1315 |
< |
checkIncomplete(h); |
1316 |
< |
assertEquals(0, r.invocationCount); |
1317 |
< |
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 |
< |
checkCompletedNormally(h, null); |
1410 |
< |
assertEquals(subtract(v1, v2), r.value); |
1322 |
> |
checkCompletedWithWrappedCFException(h); |
1323 |
|
checkCompletedNormally(f, v1); |
1324 |
|
checkCompletedNormally(g, v2); |
1325 |
|
}} |
1326 |
|
|
1327 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1327 |
> |
/** |
1328 |
> |
* thenCombine result completes exceptionally if either source cancelled |
1329 |
> |
*/ |
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 }) |
1418 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1336 |
|
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
< |
final SubtractAction r = new SubtractAction(); |
1339 |
> |
final SubtractFunction r = new SubtractFunction(); |
1340 |
|
|
1341 |
< |
g.complete(v2); |
1342 |
< |
f.complete(v1); |
1343 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
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 |
< |
checkCompletedNormally(h, null); |
1351 |
< |
assertEquals(subtract(v1, v2), r.value); |
1352 |
< |
checkCompletedNormally(f, v1); |
1353 |
< |
checkCompletedNormally(g, v2); |
1350 |
> |
checkCompletedWithWrappedCancellationException(h); |
1351 |
> |
checkCancelled(!fFirst ? f : g); |
1352 |
> |
assertEquals(0, r.invocationCount); |
1353 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1354 |
|
}} |
1355 |
|
|
1356 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1356 |
> |
/** |
1357 |
> |
* thenAcceptBoth result completes normally after normal |
1358 |
> |
* completion of sources |
1359 |
> |
*/ |
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 |
|
{ |
1368 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1369 |
|
final SubtractAction r = new SubtractAction(); |
1370 |
|
|
1371 |
< |
f.complete(v1); |
1372 |
< |
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() { |
1458 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1459 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1460 |
< |
{ |
1461 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1462 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1463 |
< |
final SubtractAction r = new SubtractAction(); |
1464 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1465 |
< |
final CFException ex = new CFException(); |
1466 |
< |
|
1467 |
< |
f.completeExceptionally(ex); |
1468 |
< |
checkIncomplete(h); |
1469 |
< |
g.complete(v1); |
1470 |
< |
|
1471 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1472 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1473 |
< |
assertEquals(0, r.invocationCount); |
1474 |
< |
checkCompletedNormally(g, v1); |
1475 |
< |
}} |
1476 |
< |
|
1477 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1478 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1479 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1480 |
< |
{ |
1481 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1482 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1483 |
< |
final SubtractAction r = new SubtractAction(); |
1484 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1485 |
< |
final CFException ex = new CFException(); |
1486 |
< |
|
1487 |
< |
g.completeExceptionally(ex); |
1488 |
< |
checkIncomplete(h); |
1489 |
< |
f.complete(v1); |
1490 |
< |
|
1491 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1492 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1493 |
< |
assertEquals(0, r.invocationCount); |
1494 |
< |
checkCompletedNormally(f, v1); |
1495 |
< |
}} |
1496 |
< |
|
1497 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
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<>(); |
1503 |
– |
final SubtractAction r = new SubtractAction(); |
1399 |
|
final CFException ex = new CFException(); |
1505 |
– |
|
1506 |
– |
g.completeExceptionally(ex); |
1507 |
– |
f.complete(v1); |
1508 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1509 |
– |
|
1510 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1511 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1512 |
– |
assertEquals(0, r.invocationCount); |
1513 |
– |
checkCompletedNormally(f, v1); |
1514 |
– |
}} |
1515 |
– |
|
1516 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1517 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1518 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1519 |
– |
{ |
1520 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1521 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1523 |
– |
final CFException ex = new CFException(); |
1401 |
|
|
1402 |
< |
f.completeExceptionally(ex); |
1403 |
< |
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); |
1530 |
– |
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() { |
1539 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
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 FailingBiConsumer r = new FailingBiConsumer(); |
1546 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1547 |
< |
|
1548 |
< |
f.complete(v1); |
1549 |
< |
checkIncomplete(h); |
1550 |
< |
g.complete(v2); |
1551 |
< |
|
1552 |
< |
checkCompletedWithWrappedCFException(h); |
1553 |
< |
checkCompletedNormally(f, v1); |
1554 |
< |
checkCompletedNormally(g, v2); |
1555 |
< |
}} |
1556 |
< |
|
1557 |
< |
public void testThenAcceptBoth_actionFailed2() { |
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 |
< |
g.complete(v2); |
1432 |
< |
checkIncomplete(h); |
1433 |
< |
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() { |
1580 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1581 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1582 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1583 |
< |
{ |
1584 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1585 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1586 |
< |
final SubtractAction r = new SubtractAction(); |
1587 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1588 |
< |
|
1589 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1590 |
< |
checkIncomplete(h); |
1591 |
< |
g.complete(v1); |
1592 |
< |
|
1593 |
< |
checkCompletedWithWrappedCancellationException(h); |
1594 |
< |
checkCancelled(f); |
1595 |
< |
assertEquals(0, r.invocationCount); |
1596 |
< |
checkCompletedNormally(g, v1); |
1597 |
< |
}} |
1598 |
< |
|
1599 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1600 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1601 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1602 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1603 |
< |
{ |
1604 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1605 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1606 |
< |
final SubtractAction r = new SubtractAction(); |
1607 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1608 |
< |
|
1609 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1610 |
< |
checkIncomplete(h); |
1611 |
< |
f.complete(v1); |
1612 |
< |
|
1613 |
< |
checkCompletedWithWrappedCancellationException(h); |
1614 |
< |
checkCancelled(g); |
1615 |
< |
assertEquals(0, r.invocationCount); |
1616 |
< |
checkCompletedNormally(f, v1); |
1617 |
< |
}} |
1618 |
< |
|
1619 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1620 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1621 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1622 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1623 |
< |
{ |
1624 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1625 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1626 |
< |
final SubtractAction r = new SubtractAction(); |
1627 |
< |
|
1628 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1629 |
< |
f.complete(v1); |
1630 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1631 |
< |
|
1632 |
< |
checkCompletedWithWrappedCancellationException(h); |
1633 |
< |
checkCancelled(g); |
1634 |
< |
assertEquals(0, r.invocationCount); |
1635 |
< |
checkCompletedNormally(f, v1); |
1636 |
< |
}} |
1637 |
< |
|
1638 |
< |
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 |
|
/** |
1646 |
|
{ |
1647 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1648 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1649 |
< |
final FailingNoop r = new FailingNoop(); |
1649 |
> |
final FailingRunnable r = new FailingRunnable(); |
1650 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1651 |
|
|
1652 |
|
f.complete(v1); |
1665 |
|
{ |
1666 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1667 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1668 |
< |
final FailingNoop r = new FailingNoop(); |
1668 |
> |
final FailingRunnable r = new FailingRunnable(); |
1669 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1670 |
|
|
1671 |
|
g.complete(v2); |
2529 |
|
{ |
2530 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2531 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2532 |
< |
final FailingNoop r = new FailingNoop(); |
2532 |
> |
final FailingRunnable r = new FailingRunnable(); |
2533 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2534 |
|
|
2535 |
|
f.complete(v1); |
2546 |
|
{ |
2547 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2548 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2549 |
< |
final FailingNoop r = new FailingNoop(); |
2549 |
> |
final FailingRunnable r = new FailingRunnable(); |
2550 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2551 |
|
|
2552 |
|
g.complete(v2); |
2656 |
|
/** |
2657 |
|
* thenCompose result completes normally after normal completion of source |
2658 |
|
*/ |
2659 |
< |
public void testThenCompose_normalCompletion1() { |
2659 |
> |
public void testThenCompose_normalCompletion() { |
2660 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2661 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2662 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2663 |
|
{ |
2664 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2665 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2666 |
+ |
if (!createIncomplete) f.complete(v1); |
2667 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2668 |
< |
f.complete(v1); |
2851 |
< |
checkCompletedNormally(g, inc(v1)); |
2852 |
< |
checkCompletedNormally(f, v1); |
2853 |
< |
assertEquals(1, r.invocationCount); |
2854 |
< |
}} |
2668 |
> |
if (createIncomplete) f.complete(v1); |
2669 |
|
|
2856 |
– |
public void testThenCompose_normalCompletion2() { |
2857 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2858 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2859 |
– |
{ |
2860 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2861 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2862 |
– |
f.complete(v1); |
2863 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2670 |
|
checkCompletedNormally(g, inc(v1)); |
2671 |
|
checkCompletedNormally(f, v1); |
2672 |
|
assertEquals(1, r.invocationCount); |
2676 |
|
* thenCompose result completes exceptionally after exceptional |
2677 |
|
* completion of source |
2678 |
|
*/ |
2679 |
< |
public void testThenCompose_exceptionalCompletion1() { |
2679 |
> |
public void testThenCompose_exceptionalCompletion() { |
2680 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2681 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2682 |
|
{ |
2683 |
|
final CFException ex = new CFException(); |
2684 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2685 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2686 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
2687 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2688 |
< |
f.completeExceptionally(ex); |
2881 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2882 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2883 |
< |
}} |
2688 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
2689 |
|
|
2885 |
– |
public void testThenCompose_exceptionalCompletion2() { |
2886 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2887 |
– |
{ |
2888 |
– |
final CFException ex = new CFException(); |
2889 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2890 |
– |
f.completeExceptionally(ex); |
2891 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2892 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2690 |
|
checkCompletedWithWrappedCFException(g, ex); |
2691 |
|
checkCompletedWithWrappedCFException(f, ex); |
2692 |
+ |
assertEquals(0, r.invocationCount); |
2693 |
|
}} |
2694 |
|
|
2695 |
|
/** |
2696 |
|
* thenCompose result completes exceptionally if action does |
2697 |
|
*/ |
2698 |
< |
public void testThenCompose_actionFailed1() { |
2698 |
> |
public void testThenCompose_actionFailed() { |
2699 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2700 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2701 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2702 |
|
{ |
2703 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2704 |
|
final FailingCompletableFutureFunction r |
2705 |
|
= new FailingCompletableFutureFunction(); |
2706 |
+ |
if (!createIncomplete) f.complete(v1); |
2707 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2708 |
< |
f.complete(v1); |
2909 |
< |
checkCompletedWithWrappedCFException(g); |
2910 |
< |
checkCompletedNormally(f, v1); |
2911 |
< |
}} |
2708 |
> |
if (createIncomplete) f.complete(v1); |
2709 |
|
|
2913 |
– |
public void testThenCompose_actionFailed2() { |
2914 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2915 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2916 |
– |
{ |
2917 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2918 |
– |
f.complete(v1); |
2919 |
– |
final FailingCompletableFutureFunction r |
2920 |
– |
= new FailingCompletableFutureFunction(); |
2921 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2710 |
|
checkCompletedWithWrappedCFException(g); |
2711 |
|
checkCompletedNormally(f, v1); |
2712 |
|
}} |
2714 |
|
/** |
2715 |
|
* thenCompose result completes exceptionally if source cancelled |
2716 |
|
*/ |
2717 |
< |
public void testThenCompose_sourceCancelled1() { |
2717 |
> |
public void testThenCompose_sourceCancelled() { |
2718 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2719 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2720 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2721 |
|
{ |
2722 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2723 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2724 |
+ |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2725 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2726 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2727 |
< |
checkCompletedWithWrappedCancellationException(g); |
2728 |
< |
checkCancelled(f); |
2729 |
< |
}} |
2726 |
> |
if (createIncomplete) { |
2727 |
> |
checkIncomplete(g); |
2728 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2729 |
> |
} |
2730 |
|
|
2941 |
– |
public void testThenCompose_sourceCancelled2() { |
2942 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2943 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2944 |
– |
{ |
2945 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2946 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2947 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2948 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2731 |
|
checkCompletedWithWrappedCancellationException(g); |
2732 |
|
checkCancelled(f); |
2733 |
|
}} |
2734 |
|
|
2953 |
– |
// asyncs |
2954 |
– |
|
2955 |
– |
/** |
2956 |
– |
* thenRunAsync result completes normally after normal completion of source |
2957 |
– |
*/ |
2958 |
– |
public void testThenRunAsync() { |
2959 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2960 |
– |
Noop r = new Noop(); |
2961 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2962 |
– |
f.complete(null); |
2963 |
– |
checkCompletedNormally(g, null); |
2964 |
– |
|
2965 |
– |
// reordered version |
2966 |
– |
f = new CompletableFuture<>(); |
2967 |
– |
f.complete(null); |
2968 |
– |
r = new Noop(); |
2969 |
– |
g = f.thenRunAsync(r); |
2970 |
– |
checkCompletedNormally(g, null); |
2971 |
– |
} |
2972 |
– |
|
2973 |
– |
/** |
2974 |
– |
* thenRunAsync result completes exceptionally after exceptional |
2975 |
– |
* completion of source |
2976 |
– |
*/ |
2977 |
– |
public void testThenRunAsync2() { |
2978 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2979 |
– |
Noop r = new Noop(); |
2980 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2981 |
– |
f.completeExceptionally(new CFException()); |
2982 |
– |
try { |
2983 |
– |
g.join(); |
2984 |
– |
shouldThrow(); |
2985 |
– |
} catch (CompletionException success) {} |
2986 |
– |
checkCompletedWithWrappedCFException(g); |
2987 |
– |
} |
2988 |
– |
|
2989 |
– |
/** |
2990 |
– |
* thenRunAsync result completes exceptionally if action does |
2991 |
– |
*/ |
2992 |
– |
public void testThenRunAsync3() { |
2993 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2994 |
– |
FailingNoop r = new FailingNoop(); |
2995 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2996 |
– |
f.complete(null); |
2997 |
– |
checkCompletedWithWrappedCFException(g); |
2998 |
– |
} |
2999 |
– |
|
3000 |
– |
/** |
3001 |
– |
* thenRunAsync result completes exceptionally if source cancelled |
3002 |
– |
*/ |
3003 |
– |
public void testThenRunAsync4() { |
3004 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3005 |
– |
Noop r = new Noop(); |
3006 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3007 |
– |
assertTrue(f.cancel(true)); |
3008 |
– |
checkCompletedWithWrappedCancellationException(g); |
3009 |
– |
} |
3010 |
– |
|
3011 |
– |
/** |
3012 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3013 |
– |
*/ |
3014 |
– |
public void testThenApplyAsync() { |
3015 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3016 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3017 |
– |
f.complete(one); |
3018 |
– |
checkCompletedNormally(g, two); |
3019 |
– |
} |
3020 |
– |
|
3021 |
– |
/** |
3022 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3023 |
– |
* completion of source |
3024 |
– |
*/ |
3025 |
– |
public void testThenApplyAsync2() { |
3026 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3027 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3028 |
– |
f.completeExceptionally(new CFException()); |
3029 |
– |
checkCompletedWithWrappedCFException(g); |
3030 |
– |
} |
3031 |
– |
|
3032 |
– |
/** |
3033 |
– |
* thenApplyAsync result completes exceptionally if action does |
3034 |
– |
*/ |
3035 |
– |
public void testThenApplyAsync3() { |
3036 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3037 |
– |
FailingFunction r = new FailingFunction(); |
3038 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
3039 |
– |
f.complete(null); |
3040 |
– |
checkCompletedWithWrappedCFException(g); |
3041 |
– |
} |
3042 |
– |
|
3043 |
– |
/** |
3044 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3045 |
– |
*/ |
3046 |
– |
public void testThenApplyAsync4() { |
3047 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3048 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3049 |
– |
assertTrue(f.cancel(true)); |
3050 |
– |
checkCompletedWithWrappedCancellationException(g); |
3051 |
– |
} |
3052 |
– |
|
3053 |
– |
/** |
3054 |
– |
* thenAcceptAsync result completes normally after normal |
3055 |
– |
* completion of source |
3056 |
– |
*/ |
3057 |
– |
public void testThenAcceptAsync() { |
3058 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3059 |
– |
IncAction r = new IncAction(); |
3060 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3061 |
– |
f.complete(one); |
3062 |
– |
checkCompletedNormally(g, null); |
3063 |
– |
assertEquals(r.value, (Integer) 2); |
3064 |
– |
} |
3065 |
– |
|
3066 |
– |
/** |
3067 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3068 |
– |
* completion of source |
3069 |
– |
*/ |
3070 |
– |
public void testThenAcceptAsync2() { |
3071 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3072 |
– |
IncAction r = new IncAction(); |
3073 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3074 |
– |
f.completeExceptionally(new CFException()); |
3075 |
– |
checkCompletedWithWrappedCFException(g); |
3076 |
– |
} |
3077 |
– |
|
3078 |
– |
/** |
3079 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3080 |
– |
*/ |
3081 |
– |
public void testThenAcceptAsync3() { |
3082 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3083 |
– |
FailingConsumer r = new FailingConsumer(); |
3084 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3085 |
– |
f.complete(null); |
3086 |
– |
checkCompletedWithWrappedCFException(g); |
3087 |
– |
} |
3088 |
– |
|
3089 |
– |
/** |
3090 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3091 |
– |
*/ |
3092 |
– |
public void testThenAcceptAsync4() { |
3093 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3094 |
– |
IncAction r = new IncAction(); |
3095 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3096 |
– |
assertTrue(f.cancel(true)); |
3097 |
– |
checkCompletedWithWrappedCancellationException(g); |
3098 |
– |
} |
3099 |
– |
|
3100 |
– |
// async with explicit executors |
3101 |
– |
|
3102 |
– |
/** |
3103 |
– |
* thenRunAsync result completes normally after normal completion of source |
3104 |
– |
*/ |
3105 |
– |
public void testThenRunAsyncE() { |
3106 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3107 |
– |
Noop r = new Noop(); |
3108 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3109 |
– |
f.complete(null); |
3110 |
– |
checkCompletedNormally(g, null); |
3111 |
– |
|
3112 |
– |
// reordered version |
3113 |
– |
f = new CompletableFuture<>(); |
3114 |
– |
f.complete(null); |
3115 |
– |
r = new Noop(); |
3116 |
– |
g = f.thenRunAsync(r, new ThreadExecutor()); |
3117 |
– |
checkCompletedNormally(g, null); |
3118 |
– |
} |
3119 |
– |
|
3120 |
– |
/** |
3121 |
– |
* thenRunAsync result completes exceptionally after exceptional |
3122 |
– |
* completion of source |
3123 |
– |
*/ |
3124 |
– |
public void testThenRunAsync2E() { |
3125 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3126 |
– |
Noop r = new Noop(); |
3127 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3128 |
– |
f.completeExceptionally(new CFException()); |
3129 |
– |
try { |
3130 |
– |
g.join(); |
3131 |
– |
shouldThrow(); |
3132 |
– |
} catch (CompletionException success) {} |
3133 |
– |
checkCompletedWithWrappedCFException(g); |
3134 |
– |
} |
3135 |
– |
|
3136 |
– |
/** |
3137 |
– |
* thenRunAsync result completes exceptionally if action does |
3138 |
– |
*/ |
3139 |
– |
public void testThenRunAsync3E() { |
3140 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3141 |
– |
FailingNoop r = new FailingNoop(); |
3142 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3143 |
– |
f.complete(null); |
3144 |
– |
checkCompletedWithWrappedCFException(g); |
3145 |
– |
} |
3146 |
– |
|
3147 |
– |
/** |
3148 |
– |
* thenRunAsync result completes exceptionally if source cancelled |
3149 |
– |
*/ |
3150 |
– |
public void testThenRunAsync4E() { |
3151 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3152 |
– |
Noop r = new Noop(); |
3153 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3154 |
– |
assertTrue(f.cancel(true)); |
3155 |
– |
checkCompletedWithWrappedCancellationException(g); |
3156 |
– |
} |
3157 |
– |
|
3158 |
– |
/** |
3159 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3160 |
– |
*/ |
3161 |
– |
public void testThenApplyAsyncE() { |
3162 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3163 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3164 |
– |
f.complete(one); |
3165 |
– |
checkCompletedNormally(g, two); |
3166 |
– |
} |
3167 |
– |
|
3168 |
– |
/** |
3169 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3170 |
– |
* completion of source |
3171 |
– |
*/ |
3172 |
– |
public void testThenApplyAsync2E() { |
3173 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3174 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3175 |
– |
f.completeExceptionally(new CFException()); |
3176 |
– |
checkCompletedWithWrappedCFException(g); |
3177 |
– |
} |
3178 |
– |
|
3179 |
– |
/** |
3180 |
– |
* thenApplyAsync result completes exceptionally if action does |
3181 |
– |
*/ |
3182 |
– |
public void testThenApplyAsync3E() { |
3183 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3184 |
– |
FailingFunction r = new FailingFunction(); |
3185 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
3186 |
– |
f.complete(null); |
3187 |
– |
checkCompletedWithWrappedCFException(g); |
3188 |
– |
} |
3189 |
– |
|
3190 |
– |
/** |
3191 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3192 |
– |
*/ |
3193 |
– |
public void testThenApplyAsync4E() { |
3194 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3195 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3196 |
– |
assertTrue(f.cancel(true)); |
3197 |
– |
checkCompletedWithWrappedCancellationException(g); |
3198 |
– |
} |
3199 |
– |
|
3200 |
– |
/** |
3201 |
– |
* thenAcceptAsync result completes normally after normal |
3202 |
– |
* completion of source |
3203 |
– |
*/ |
3204 |
– |
public void testThenAcceptAsyncE() { |
3205 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3206 |
– |
IncAction r = new IncAction(); |
3207 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3208 |
– |
f.complete(one); |
3209 |
– |
checkCompletedNormally(g, null); |
3210 |
– |
assertEquals(r.value, (Integer) 2); |
3211 |
– |
} |
3212 |
– |
|
3213 |
– |
/** |
3214 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3215 |
– |
* completion of source |
3216 |
– |
*/ |
3217 |
– |
public void testThenAcceptAsync2E() { |
3218 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3219 |
– |
IncAction r = new IncAction(); |
3220 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3221 |
– |
f.completeExceptionally(new CFException()); |
3222 |
– |
checkCompletedWithWrappedCFException(g); |
3223 |
– |
} |
3224 |
– |
|
3225 |
– |
/** |
3226 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3227 |
– |
*/ |
3228 |
– |
public void testThenAcceptAsync3E() { |
3229 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3230 |
– |
FailingConsumer r = new FailingConsumer(); |
3231 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3232 |
– |
f.complete(null); |
3233 |
– |
checkCompletedWithWrappedCFException(g); |
3234 |
– |
} |
3235 |
– |
|
3236 |
– |
/** |
3237 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3238 |
– |
*/ |
3239 |
– |
public void testThenAcceptAsync4E() { |
3240 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3241 |
– |
IncAction r = new IncAction(); |
3242 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3243 |
– |
assertTrue(f.cancel(true)); |
3244 |
– |
checkCompletedWithWrappedCancellationException(g); |
3245 |
– |
} |
3246 |
– |
|
2735 |
|
// other static methods |
2736 |
|
|
2737 |
|
/** |