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++; |
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); |
983 |
|
final Noop r = new Noop(); |
984 |
|
if (!createIncomplete) f.complete(v1); |
985 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
986 |
< |
if (createIncomplete) f.complete(v1); |
986 |
> |
if (createIncomplete) { |
987 |
> |
checkIncomplete(g); |
988 |
> |
f.complete(v1); |
989 |
> |
} |
990 |
|
|
991 |
|
checkCompletedNormally(g, null); |
992 |
|
checkCompletedNormally(f, v1); |
1006 |
|
final Noop r = new Noop(); |
1007 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1008 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1009 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1009 |
> |
if (createIncomplete) { |
1010 |
> |
checkIncomplete(g); |
1011 |
> |
f.completeExceptionally(ex); |
1012 |
> |
} |
1013 |
|
|
1014 |
|
checkCompletedWithWrappedCFException(g, ex); |
1015 |
|
checkCompletedWithWrappedCFException(f, ex); |
1028 |
|
final Noop r = new Noop(); |
1029 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1030 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1031 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1031 |
> |
if (createIncomplete) { |
1032 |
> |
checkIncomplete(g); |
1033 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1034 |
> |
} |
1035 |
|
|
1036 |
|
checkCompletedWithWrappedCancellationException(g); |
1037 |
|
checkCancelled(f); |
1047 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1048 |
|
{ |
1049 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1050 |
< |
final FailingNoop r = new FailingNoop(); |
1050 |
> |
final FailingRunnable r = new FailingRunnable(); |
1051 |
|
if (!createIncomplete) f.complete(v1); |
1052 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1053 |
< |
if (createIncomplete) f.complete(v1); |
1053 |
> |
if (createIncomplete) { |
1054 |
> |
checkIncomplete(g); |
1055 |
> |
f.complete(v1); |
1056 |
> |
} |
1057 |
|
|
1058 |
|
checkCompletedWithWrappedCFException(g); |
1059 |
|
checkCompletedNormally(f, v1); |
1062 |
|
/** |
1063 |
|
* thenApply result completes normally after normal completion of source |
1064 |
|
*/ |
1065 |
< |
public void testThenApply() { |
1054 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1055 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1056 |
< |
f.complete(one); |
1057 |
< |
checkCompletedNormally(g, two); |
1058 |
< |
} |
1059 |
< |
|
1060 |
< |
/** |
1061 |
< |
* thenApply result completes exceptionally after exceptional |
1062 |
< |
* completion of source |
1063 |
< |
*/ |
1064 |
< |
public void testThenApply2() { |
1065 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1066 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1067 |
< |
f.completeExceptionally(new CFException()); |
1068 |
< |
checkCompletedWithWrappedCFException(g); |
1069 |
< |
} |
1070 |
< |
|
1071 |
< |
/** |
1072 |
< |
* thenApply result completes exceptionally if action does |
1073 |
< |
*/ |
1074 |
< |
public void testThenApply3() { |
1075 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1076 |
< |
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
1077 |
< |
f.complete(one); |
1078 |
< |
checkCompletedWithWrappedCFException(g); |
1079 |
< |
} |
1080 |
< |
|
1081 |
< |
/** |
1082 |
< |
* thenApply result completes exceptionally if source cancelled |
1083 |
< |
*/ |
1084 |
< |
public void testThenApply4() { |
1085 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1086 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1087 |
< |
assertTrue(f.cancel(true)); |
1088 |
< |
checkCompletedWithWrappedCancellationException(g); |
1089 |
< |
} |
1090 |
< |
|
1091 |
< |
/** |
1092 |
< |
* thenAccept result completes normally after normal completion of source |
1093 |
< |
*/ |
1094 |
< |
public void testThenAccept() { |
1095 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1096 |
< |
IncAction r = new IncAction(); |
1097 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1098 |
< |
f.complete(one); |
1099 |
< |
checkCompletedNormally(g, null); |
1100 |
< |
assertEquals(r.value, (Integer) 2); |
1101 |
< |
} |
1102 |
< |
|
1103 |
< |
/** |
1104 |
< |
* thenAccept result completes exceptionally after exceptional |
1105 |
< |
* completion of source |
1106 |
< |
*/ |
1107 |
< |
public void testThenAccept2() { |
1108 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1109 |
< |
IncAction r = new IncAction(); |
1110 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1111 |
< |
f.completeExceptionally(new CFException()); |
1112 |
< |
checkCompletedWithWrappedCFException(g); |
1113 |
< |
} |
1114 |
< |
|
1115 |
< |
/** |
1116 |
< |
* thenAccept result completes exceptionally if action does |
1117 |
< |
*/ |
1118 |
< |
public void testThenAccept3() { |
1119 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1120 |
< |
FailingConsumer r = new FailingConsumer(); |
1121 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1122 |
< |
f.complete(one); |
1123 |
< |
checkCompletedWithWrappedCFException(g); |
1124 |
< |
assertEquals(1, r.invocationCount); |
1125 |
< |
} |
1126 |
< |
|
1127 |
< |
/** |
1128 |
< |
* thenAccept result completes exceptionally if source cancelled |
1129 |
< |
*/ |
1130 |
< |
public void testThenAccept4() { |
1131 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1132 |
< |
IncAction r = new IncAction(); |
1133 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1134 |
< |
assertTrue(f.cancel(true)); |
1135 |
< |
checkCompletedWithWrappedCancellationException(g); |
1136 |
< |
} |
1137 |
< |
|
1138 |
< |
/** |
1139 |
< |
* thenCombine result completes normally after normal completion |
1140 |
< |
* of sources |
1141 |
< |
*/ |
1142 |
< |
public void testThenCombine_normalCompletion1() { |
1143 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
1144 |
< |
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 }) |
1147 |
– |
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 |
< |
|
1155 |
< |
if (fFirst) |
1156 |
< |
f.complete(v1); |
1157 |
< |
else |
1158 |
< |
g.complete(v2); |
1159 |
< |
if (createIncomplete) checkIncomplete(h); |
1160 |
< |
assertEquals(0, r.invocationCount); |
1161 |
< |
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 |
1164 |
< |
g.complete(v2); |
1165 |
< |
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); |
1169 |
– |
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 |
|
{ |
1181 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1182 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1183 |
– |
final SubtractFunction r = new SubtractFunction(); |
1184 |
– |
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); |
1188 |
< |
checkIncomplete(h); |
1189 |
< |
g.complete(v1); |
1190 |
< |
|
1191 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1102 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1103 |
|
checkCompletedWithWrappedCFException(f, ex); |
1104 |
|
assertEquals(0, r.invocationCount); |
1194 |
– |
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); |
1209 |
< |
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); |
1214 |
– |
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); |
1231 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1232 |
< |
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 }) |
1261 |
< |
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 }) |
1280 |
– |
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); |
1293 |
– |
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 }) |
1302 |
– |
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); |
1316 |
– |
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 |
< |
{ |
1324 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1325 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1326 |
< |
final SubtractFunction r = new SubtractFunction(); |
1327 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1328 |
< |
|
1329 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1330 |
< |
checkIncomplete(h); |
1331 |
< |
f.complete(v1); |
1332 |
< |
|
1333 |
< |
checkCompletedWithWrappedCancellationException(h); |
1334 |
< |
checkCancelled(g); |
1335 |
< |
assertEquals(0, r.invocationCount); |
1336 |
< |
checkCompletedNormally(f, v1); |
1337 |
< |
}} |
1338 |
< |
|
1339 |
< |
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); |
1353 |
< |
checkCancelled(g); |
1354 |
< |
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); |
1372 |
< |
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 |
1379 |
< |
* completion of sources |
1301 |
> |
* thenCombine result completes exceptionally if action does |
1302 |
|
*/ |
1303 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1382 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1383 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1384 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1385 |
< |
{ |
1386 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1387 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1388 |
< |
final SubtractAction r = new SubtractAction(); |
1389 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1390 |
< |
|
1391 |
< |
f.complete(v1); |
1392 |
< |
checkIncomplete(h); |
1393 |
< |
assertEquals(0, r.invocationCount); |
1394 |
< |
g.complete(v2); |
1395 |
< |
|
1396 |
< |
checkCompletedNormally(h, null); |
1397 |
< |
assertEquals(subtract(v1, v2), r.value); |
1398 |
< |
checkCompletedNormally(f, v1); |
1399 |
< |
checkCompletedNormally(g, v2); |
1400 |
< |
}} |
1401 |
< |
|
1402 |
< |
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); |
1418 |
< |
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 }) |
1426 |
– |
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() { |
1466 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1467 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1468 |
< |
{ |
1469 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1470 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1471 |
< |
final SubtractAction r = new SubtractAction(); |
1472 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1473 |
< |
final CFException ex = new CFException(); |
1474 |
< |
|
1475 |
< |
f.completeExceptionally(ex); |
1476 |
< |
checkIncomplete(h); |
1477 |
< |
g.complete(v1); |
1478 |
< |
|
1479 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1480 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1481 |
< |
assertEquals(0, r.invocationCount); |
1482 |
< |
checkCompletedNormally(g, v1); |
1483 |
< |
}} |
1484 |
< |
|
1485 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1486 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1487 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1488 |
< |
{ |
1489 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1490 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1491 |
< |
final SubtractAction r = new SubtractAction(); |
1492 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1493 |
< |
final CFException ex = new CFException(); |
1494 |
< |
|
1495 |
< |
g.completeExceptionally(ex); |
1496 |
< |
checkIncomplete(h); |
1497 |
< |
f.complete(v1); |
1498 |
< |
|
1499 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1500 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1501 |
< |
assertEquals(0, r.invocationCount); |
1502 |
< |
checkCompletedNormally(f, v1); |
1503 |
< |
}} |
1504 |
< |
|
1505 |
< |
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<>(); |
1511 |
– |
final SubtractAction r = new SubtractAction(); |
1399 |
|
final CFException ex = new CFException(); |
1513 |
– |
|
1514 |
– |
g.completeExceptionally(ex); |
1515 |
– |
f.complete(v1); |
1516 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1517 |
– |
|
1518 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1519 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1520 |
– |
assertEquals(0, r.invocationCount); |
1521 |
– |
checkCompletedNormally(f, v1); |
1522 |
– |
}} |
1523 |
– |
|
1524 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1525 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1526 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1527 |
– |
{ |
1528 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1529 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1531 |
– |
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); |
1538 |
– |
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() { |
1547 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1548 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1549 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1550 |
< |
{ |
1551 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1552 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1553 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1554 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1555 |
< |
|
1556 |
< |
f.complete(v1); |
1557 |
< |
checkIncomplete(h); |
1558 |
< |
g.complete(v2); |
1559 |
< |
|
1560 |
< |
checkCompletedWithWrappedCFException(h); |
1561 |
< |
checkCompletedNormally(f, v1); |
1562 |
< |
checkCompletedNormally(g, v2); |
1563 |
< |
}} |
1564 |
< |
|
1565 |
< |
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() { |
1588 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1589 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1590 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1591 |
< |
{ |
1592 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1593 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1594 |
< |
final SubtractAction r = new SubtractAction(); |
1595 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1596 |
< |
|
1597 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1598 |
< |
checkIncomplete(h); |
1599 |
< |
g.complete(v1); |
1600 |
< |
|
1601 |
< |
checkCompletedWithWrappedCancellationException(h); |
1602 |
< |
checkCancelled(f); |
1603 |
< |
assertEquals(0, r.invocationCount); |
1604 |
< |
checkCompletedNormally(g, v1); |
1605 |
< |
}} |
1606 |
< |
|
1607 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1608 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1609 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1610 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1611 |
< |
{ |
1612 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1613 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1614 |
< |
final SubtractAction r = new SubtractAction(); |
1615 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1616 |
< |
|
1617 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1618 |
< |
checkIncomplete(h); |
1619 |
< |
f.complete(v1); |
1620 |
< |
|
1621 |
< |
checkCompletedWithWrappedCancellationException(h); |
1622 |
< |
checkCancelled(g); |
1623 |
< |
assertEquals(0, r.invocationCount); |
1624 |
< |
checkCompletedNormally(f, v1); |
1625 |
< |
}} |
1626 |
< |
|
1627 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1628 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1629 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1630 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1631 |
< |
{ |
1632 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1633 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1634 |
< |
final SubtractAction r = new SubtractAction(); |
1635 |
< |
|
1636 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1637 |
< |
f.complete(v1); |
1638 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1639 |
< |
|
1640 |
< |
checkCompletedWithWrappedCancellationException(h); |
1641 |
< |
checkCancelled(g); |
1642 |
< |
assertEquals(0, r.invocationCount); |
1643 |
< |
checkCompletedNormally(f, v1); |
1644 |
< |
}} |
1645 |
< |
|
1646 |
< |
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); |
2723 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2724 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2725 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2726 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2726 |
> |
if (createIncomplete) { |
2727 |
> |
checkIncomplete(g); |
2728 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2729 |
> |
} |
2730 |
|
|
2731 |
|
checkCompletedWithWrappedCancellationException(g); |
2732 |
|
checkCancelled(f); |
2733 |
|
}} |
2734 |
|
|
2924 |
– |
// asyncs |
2925 |
– |
|
2926 |
– |
/** |
2927 |
– |
* thenApplyAsync result completes normally after normal completion of source |
2928 |
– |
*/ |
2929 |
– |
public void testThenApplyAsync() { |
2930 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2931 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
2932 |
– |
f.complete(one); |
2933 |
– |
checkCompletedNormally(g, two); |
2934 |
– |
} |
2935 |
– |
|
2936 |
– |
/** |
2937 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
2938 |
– |
* completion of source |
2939 |
– |
*/ |
2940 |
– |
public void testThenApplyAsync2() { |
2941 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2942 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
2943 |
– |
f.completeExceptionally(new CFException()); |
2944 |
– |
checkCompletedWithWrappedCFException(g); |
2945 |
– |
} |
2946 |
– |
|
2947 |
– |
/** |
2948 |
– |
* thenApplyAsync result completes exceptionally if action does |
2949 |
– |
*/ |
2950 |
– |
public void testThenApplyAsync3() { |
2951 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2952 |
– |
FailingFunction r = new FailingFunction(); |
2953 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
2954 |
– |
f.complete(null); |
2955 |
– |
checkCompletedWithWrappedCFException(g); |
2956 |
– |
} |
2957 |
– |
|
2958 |
– |
/** |
2959 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
2960 |
– |
*/ |
2961 |
– |
public void testThenApplyAsync4() { |
2962 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2963 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
2964 |
– |
assertTrue(f.cancel(true)); |
2965 |
– |
checkCompletedWithWrappedCancellationException(g); |
2966 |
– |
} |
2967 |
– |
|
2968 |
– |
/** |
2969 |
– |
* thenAcceptAsync result completes normally after normal |
2970 |
– |
* completion of source |
2971 |
– |
*/ |
2972 |
– |
public void testThenAcceptAsync() { |
2973 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2974 |
– |
IncAction r = new IncAction(); |
2975 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2976 |
– |
f.complete(one); |
2977 |
– |
checkCompletedNormally(g, null); |
2978 |
– |
assertEquals(r.value, (Integer) 2); |
2979 |
– |
} |
2980 |
– |
|
2981 |
– |
/** |
2982 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
2983 |
– |
* completion of source |
2984 |
– |
*/ |
2985 |
– |
public void testThenAcceptAsync2() { |
2986 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2987 |
– |
IncAction r = new IncAction(); |
2988 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2989 |
– |
f.completeExceptionally(new CFException()); |
2990 |
– |
checkCompletedWithWrappedCFException(g); |
2991 |
– |
} |
2992 |
– |
|
2993 |
– |
/** |
2994 |
– |
* thenAcceptAsync result completes exceptionally if action does |
2995 |
– |
*/ |
2996 |
– |
public void testThenAcceptAsync3() { |
2997 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2998 |
– |
FailingConsumer r = new FailingConsumer(); |
2999 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3000 |
– |
f.complete(null); |
3001 |
– |
checkCompletedWithWrappedCFException(g); |
3002 |
– |
} |
3003 |
– |
|
3004 |
– |
/** |
3005 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3006 |
– |
*/ |
3007 |
– |
public void testThenAcceptAsync4() { |
3008 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3009 |
– |
IncAction r = new IncAction(); |
3010 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3011 |
– |
assertTrue(f.cancel(true)); |
3012 |
– |
checkCompletedWithWrappedCancellationException(g); |
3013 |
– |
} |
3014 |
– |
|
3015 |
– |
// async with explicit executors |
3016 |
– |
|
3017 |
– |
/** |
3018 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3019 |
– |
*/ |
3020 |
– |
public void testThenApplyAsyncE() { |
3021 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3022 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3023 |
– |
f.complete(one); |
3024 |
– |
checkCompletedNormally(g, two); |
3025 |
– |
} |
3026 |
– |
|
3027 |
– |
/** |
3028 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3029 |
– |
* completion of source |
3030 |
– |
*/ |
3031 |
– |
public void testThenApplyAsync2E() { |
3032 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3033 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3034 |
– |
f.completeExceptionally(new CFException()); |
3035 |
– |
checkCompletedWithWrappedCFException(g); |
3036 |
– |
} |
3037 |
– |
|
3038 |
– |
/** |
3039 |
– |
* thenApplyAsync result completes exceptionally if action does |
3040 |
– |
*/ |
3041 |
– |
public void testThenApplyAsync3E() { |
3042 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3043 |
– |
FailingFunction r = new FailingFunction(); |
3044 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
3045 |
– |
f.complete(null); |
3046 |
– |
checkCompletedWithWrappedCFException(g); |
3047 |
– |
} |
3048 |
– |
|
3049 |
– |
/** |
3050 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3051 |
– |
*/ |
3052 |
– |
public void testThenApplyAsync4E() { |
3053 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3054 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3055 |
– |
assertTrue(f.cancel(true)); |
3056 |
– |
checkCompletedWithWrappedCancellationException(g); |
3057 |
– |
} |
3058 |
– |
|
3059 |
– |
/** |
3060 |
– |
* thenAcceptAsync result completes normally after normal |
3061 |
– |
* completion of source |
3062 |
– |
*/ |
3063 |
– |
public void testThenAcceptAsyncE() { |
3064 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3065 |
– |
IncAction r = new IncAction(); |
3066 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3067 |
– |
f.complete(one); |
3068 |
– |
checkCompletedNormally(g, null); |
3069 |
– |
assertEquals(r.value, (Integer) 2); |
3070 |
– |
} |
3071 |
– |
|
3072 |
– |
/** |
3073 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3074 |
– |
* completion of source |
3075 |
– |
*/ |
3076 |
– |
public void testThenAcceptAsync2E() { |
3077 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3078 |
– |
IncAction r = new IncAction(); |
3079 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3080 |
– |
f.completeExceptionally(new CFException()); |
3081 |
– |
checkCompletedWithWrappedCFException(g); |
3082 |
– |
} |
3083 |
– |
|
3084 |
– |
/** |
3085 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3086 |
– |
*/ |
3087 |
– |
public void testThenAcceptAsync3E() { |
3088 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3089 |
– |
FailingConsumer r = new FailingConsumer(); |
3090 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3091 |
– |
f.complete(null); |
3092 |
– |
checkCompletedWithWrappedCFException(g); |
3093 |
– |
} |
3094 |
– |
|
3095 |
– |
/** |
3096 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3097 |
– |
*/ |
3098 |
– |
public void testThenAcceptAsync4E() { |
3099 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3100 |
– |
IncAction r = new IncAction(); |
3101 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3102 |
– |
assertTrue(f.cancel(true)); |
3103 |
– |
checkCompletedWithWrappedCancellationException(g); |
3104 |
– |
} |
3105 |
– |
|
2735 |
|
// other static methods |
2736 |
|
|
2737 |
|
/** |