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() { |
1066 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1067 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1068 |
< |
f.complete(one); |
1069 |
< |
checkCompletedNormally(g, two); |
1070 |
< |
} |
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 }) |
1069 |
> |
{ |
1070 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
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 |
> |
} |
1078 |
> |
|
1079 |
> |
checkCompletedNormally(g, inc(v1)); |
1080 |
> |
checkCompletedNormally(f, v1); |
1081 |
> |
assertEquals(1, r.invocationCount); |
1082 |
> |
}} |
1083 |
|
|
1084 |
|
/** |
1085 |
|
* thenApply result completes exceptionally after exceptional |
1086 |
|
* completion of source |
1087 |
|
*/ |
1088 |
< |
public void testThenApply2() { |
1089 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1090 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1091 |
< |
f.completeExceptionally(new CFException()); |
1092 |
< |
checkCompletedWithWrappedCFException(g); |
1093 |
< |
} |
1088 |
> |
public void testThenApply_exceptionalCompletion() { |
1089 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1090 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1091 |
> |
{ |
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 |
< |
/** |
1103 |
< |
* thenApply result completes exceptionally if action does |
1104 |
< |
*/ |
1105 |
< |
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 |
< |
} |
1102 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1103 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1104 |
> |
assertEquals(0, r.invocationCount); |
1105 |
> |
}} |
1106 |
|
|
1107 |
|
/** |
1108 |
|
* thenApply result completes exceptionally if source cancelled |
1109 |
|
*/ |
1110 |
< |
public void testThenApply4() { |
1111 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1112 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1113 |
< |
assertTrue(f.cancel(true)); |
1114 |
< |
checkCompletedWithWrappedCancellationException(g); |
1115 |
< |
} |
1116 |
< |
|
1117 |
< |
/** |
1118 |
< |
* thenAccept result completes normally after normal completion of source |
1119 |
< |
*/ |
1120 |
< |
public void testThenAccept() { |
1121 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1122 |
< |
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 |
< |
} |
1110 |
> |
public void testThenApply_sourceCancelled() { |
1111 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
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 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 |
|
|
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)); |
1124 |
|
checkCompletedWithWrappedCancellationException(g); |
1125 |
< |
} |
1125 |
> |
checkCancelled(f); |
1126 |
> |
assertEquals(0, r.invocationCount); |
1127 |
> |
}} |
1128 |
|
|
1129 |
|
/** |
1130 |
< |
* thenCombine result completes normally after normal completion |
1140 |
< |
* of sources |
1130 |
> |
* thenApply result completes exceptionally if action does |
1131 |
|
*/ |
1132 |
< |
public void testThenCombine_normalCompletion1() { |
1143 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
1144 |
< |
for (boolean fFirst : new boolean[] { true, false }) |
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 }) |
1147 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1136 |
|
{ |
1137 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1138 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1139 |
< |
final SubtractFunction r = new SubtractFunction(); |
1140 |
< |
CompletableFuture<Integer> h = null; |
1141 |
< |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1142 |
< |
|
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) |
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 |
< |
else |
1164 |
< |
g.complete(v2); |
1165 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1144 |
> |
} |
1145 |
|
|
1146 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
1146 |
> |
checkCompletedWithWrappedCFException(g); |
1147 |
|
checkCompletedNormally(f, v1); |
1169 |
– |
checkCompletedNormally(g, v2); |
1170 |
– |
assertEquals(1, r.invocationCount); |
1148 |
|
}} |
1149 |
|
|
1150 |
|
/** |
1151 |
< |
* thenCombine result completes exceptionally after exceptional |
1175 |
< |
* completion of either source |
1151 |
> |
* thenAccept result completes normally after normal completion of source |
1152 |
|
*/ |
1153 |
< |
public void testThenCombine_exceptionalCompletion1() { |
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 CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1162 |
< |
final CFException ex = new CFException(); |
1163 |
< |
|
1164 |
< |
f.completeExceptionally(ex); |
1165 |
< |
checkIncomplete(h); |
1189 |
< |
g.complete(v1); |
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 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1173 |
> |
/** |
1174 |
> |
* thenAccept result completes exceptionally after exceptional |
1175 |
> |
* completion of source |
1176 |
> |
*/ |
1177 |
> |
public void testThenAccept_exceptionalCompletion() { |
1178 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1179 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1179 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1180 |
|
{ |
1201 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1202 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1203 |
– |
final SubtractFunction r = new SubtractFunction(); |
1204 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1181 |
|
final CFException ex = new CFException(); |
1182 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
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 |
|
|
1207 |
– |
g.completeExceptionally(ex); |
1208 |
– |
checkIncomplete(h); |
1209 |
– |
f.complete(v1); |
1210 |
– |
|
1211 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1191 |
|
checkCompletedWithWrappedCFException(g, ex); |
1192 |
+ |
checkCompletedWithWrappedCFException(f, ex); |
1193 |
|
assertEquals(0, r.invocationCount); |
1214 |
– |
checkCompletedNormally(f, v1); |
1194 |
|
}} |
1195 |
|
|
1196 |
< |
public void testThenCombine_exceptionalCompletion3() { |
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 }) |
1203 |
|
{ |
1204 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1205 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1206 |
< |
final SubtractFunction r = new SubtractFunction(); |
1207 |
< |
final CFException ex = new CFException(); |
1208 |
< |
|
1209 |
< |
g.completeExceptionally(ex); |
1210 |
< |
f.complete(v1); |
1211 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
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, ex); |
1231 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1232 |
< |
assertEquals(0, r.invocationCount); |
1213 |
> |
checkCompletedWithWrappedCFException(g); |
1214 |
|
checkCompletedNormally(f, v1); |
1215 |
|
}} |
1216 |
|
|
1217 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1217 |
> |
/** |
1218 |
> |
* thenAccept result completes exceptionally if source cancelled |
1219 |
> |
*/ |
1220 |
> |
public void testThenAccept_sourceCancelled() { |
1221 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1222 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1222 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1223 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1224 |
|
{ |
1225 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1226 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1227 |
< |
final SubtractFunction r = new SubtractFunction(); |
1228 |
< |
final CFException ex = new CFException(); |
1229 |
< |
|
1230 |
< |
f.completeExceptionally(ex); |
1231 |
< |
g.complete(v1); |
1232 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
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 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1235 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1234 |
> |
checkCompletedWithWrappedCancellationException(g); |
1235 |
> |
checkCancelled(f); |
1236 |
|
assertEquals(0, r.invocationCount); |
1252 |
– |
checkCompletedNormally(g, v1); |
1237 |
|
}} |
1238 |
|
|
1239 |
|
/** |
1240 |
< |
* thenCombine result completes exceptionally if action does |
1240 |
> |
* thenCombine result completes normally after normal completion |
1241 |
> |
* of sources |
1242 |
|
*/ |
1243 |
< |
public void testThenCombine_actionFailed1() { |
1243 |
> |
public void testThenCombine_normalCompletion() { |
1244 |
|
for (ExecutionMode m : ExecutionMode.values()) |
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 FailingBiFunction r = new FailingBiFunction(); |
1266 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1267 |
< |
|
1268 |
< |
f.complete(v1); |
1269 |
< |
checkIncomplete(h); |
1270 |
< |
g.complete(v2); |
1271 |
< |
|
1272 |
< |
checkCompletedWithWrappedCFException(h); |
1273 |
< |
checkCompletedNormally(f, v1); |
1274 |
< |
checkCompletedNormally(g, v2); |
1275 |
< |
}} |
1252 |
> |
final SubtractFunction r = new SubtractFunction(); |
1253 |
|
|
1254 |
< |
public void testThenCombine_actionFailed2() { |
1255 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1256 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1280 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1281 |
< |
{ |
1282 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1283 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1284 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
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 |
< |
g.complete(v2); |
1288 |
< |
checkIncomplete(h); |
1289 |
< |
f.complete(v1); |
1290 |
< |
|
1291 |
< |
checkCompletedWithWrappedCFException(h); |
1264 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
1265 |
|
checkCompletedNormally(f, v1); |
1266 |
|
checkCompletedNormally(g, v2); |
1267 |
+ |
assertEquals(1, r.invocationCount); |
1268 |
|
}} |
1269 |
|
|
1270 |
|
/** |
1271 |
< |
* thenCombine result completes exceptionally if either source cancelled |
1271 |
> |
* thenCombine result completes exceptionally after exceptional |
1272 |
> |
* completion of either source |
1273 |
|
*/ |
1274 |
< |
public void testThenCombine_sourceCancelled1() { |
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(); |
1307 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1284 |
|
|
1285 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1286 |
< |
checkIncomplete(h); |
1287 |
< |
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); |
1314 |
< |
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 |
< |
public void testThenCombine_sourceCancelled2() { |
1300 |
> |
/** |
1301 |
> |
* thenCombine result completes exceptionally if action does |
1302 |
> |
*/ |
1303 |
> |
public void testThenCombine_actionFailed() { |
1304 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1305 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
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 SubtractFunction r = new SubtractFunction(); |
1311 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1312 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1313 |
|
|
1314 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1315 |
< |
checkIncomplete(h); |
1316 |
< |
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 |
< |
checkCompletedWithWrappedCancellationException(h); |
1334 |
< |
checkCancelled(g); |
1335 |
< |
assertEquals(0, r.invocationCount); |
1322 |
> |
checkCompletedWithWrappedCFException(h); |
1323 |
|
checkCompletedNormally(f, v1); |
1324 |
+ |
checkCompletedNormally(g, v2); |
1325 |
|
}} |
1326 |
|
|
1327 |
< |
public void testThenCombine_sourceCancelled3() { |
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 }) |
1336 |
|
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
|
|
1341 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1342 |
< |
f.complete(v1); |
1343 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1351 |
< |
|
1352 |
< |
checkCompletedWithWrappedCancellationException(h); |
1353 |
< |
checkCancelled(g); |
1354 |
< |
assertEquals(0, r.invocationCount); |
1355 |
< |
checkCompletedNormally(f, v1); |
1356 |
< |
}} |
1357 |
< |
|
1358 |
< |
public void testThenCombine_sourceCancelled4() { |
1359 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1360 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1361 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1362 |
< |
{ |
1363 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1364 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1365 |
< |
final SubtractFunction r = new SubtractFunction(); |
1366 |
< |
|
1367 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1368 |
< |
g.complete(v1); |
1341 |
> |
(fFirst ? f : g).complete(v1); |
1342 |
> |
if (!createIncomplete) |
1343 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1344 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1345 |
+ |
if (createIncomplete) { |
1346 |
+ |
checkIncomplete(h); |
1347 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1348 |
+ |
} |
1349 |
|
|
1350 |
|
checkCompletedWithWrappedCancellationException(h); |
1351 |
< |
checkCancelled(f); |
1351 |
> |
checkCancelled(!fFirst ? f : g); |
1352 |
|
assertEquals(0, r.invocationCount); |
1353 |
< |
checkCompletedNormally(g, v1); |
1353 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1354 |
|
}} |
1355 |
|
|
1356 |
|
/** |
1817 |
|
{ |
1818 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1819 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1820 |
< |
final FailingNoop r = new FailingNoop(); |
1820 |
> |
final FailingRunnable r = new FailingRunnable(); |
1821 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1822 |
|
|
1823 |
|
f.complete(v1); |
1836 |
|
{ |
1837 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1838 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1839 |
< |
final FailingNoop r = new FailingNoop(); |
1839 |
> |
final FailingRunnable r = new FailingRunnable(); |
1840 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1841 |
|
|
1842 |
|
g.complete(v2); |
2700 |
|
{ |
2701 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2702 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2703 |
< |
final FailingNoop r = new FailingNoop(); |
2703 |
> |
final FailingRunnable r = new FailingRunnable(); |
2704 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2705 |
|
|
2706 |
|
f.complete(v1); |
2717 |
|
{ |
2718 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2719 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2720 |
< |
final FailingNoop r = new FailingNoop(); |
2720 |
> |
final FailingRunnable r = new FailingRunnable(); |
2721 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2722 |
|
|
2723 |
|
g.complete(v2); |
2894 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2895 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2896 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2897 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2897 |
> |
if (createIncomplete) { |
2898 |
> |
checkIncomplete(g); |
2899 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2900 |
> |
} |
2901 |
|
|
2902 |
|
checkCompletedWithWrappedCancellationException(g); |
2903 |
|
checkCancelled(f); |
2904 |
|
}} |
2905 |
|
|
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 |
– |
|
2906 |
|
// other static methods |
2907 |
|
|
2908 |
|
/** |