284 |
|
public void testGetNumberOfDependents() { |
285 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
286 |
|
assertEquals(0, f.getNumberOfDependents()); |
287 |
< |
CompletableFuture g = f.thenRun(new Noop()); |
287 |
> |
CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
288 |
|
assertEquals(1, f.getNumberOfDependents()); |
289 |
|
assertEquals(0, g.getNumberOfDependents()); |
290 |
< |
CompletableFuture h = f.thenRun(new Noop()); |
290 |
> |
CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
291 |
|
assertEquals(2, f.getNumberOfDependents()); |
292 |
|
f.complete(1); |
293 |
|
checkCompletedNormally(g, null); |
349 |
|
} |
350 |
|
} |
351 |
|
static final class IncFunction implements Function<Integer,Integer> { |
352 |
+ |
final ExecutionMode m; |
353 |
|
int invocationCount = 0; |
354 |
|
Integer value; |
355 |
+ |
IncFunction(ExecutionMode m) { this.m = m; } |
356 |
|
public Integer apply(Integer x) { |
357 |
+ |
m.checkExecutionMode(); |
358 |
|
invocationCount++; |
359 |
|
return value = inc(x); |
360 |
|
} |
361 |
|
} |
362 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
363 |
+ |
final ExecutionMode m; |
364 |
|
int invocationCount = 0; |
365 |
|
Integer value; |
366 |
|
// Check this action was invoked exactly once when result is computed. |
367 |
+ |
SubtractAction(ExecutionMode m) { this.m = m; } |
368 |
|
public void accept(Integer x, Integer y) { |
369 |
+ |
m.checkExecutionMode(); |
370 |
|
invocationCount++; |
371 |
|
value = subtract(x, y); |
372 |
|
} |
373 |
|
} |
374 |
|
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
375 |
+ |
final ExecutionMode m; |
376 |
|
int invocationCount = 0; |
377 |
|
Integer value; |
378 |
|
// Check this action was invoked exactly once when result is computed. |
379 |
+ |
SubtractFunction(ExecutionMode m) { this.m = m; } |
380 |
|
public Integer apply(Integer x, Integer y) { |
381 |
+ |
m.checkExecutionMode(); |
382 |
|
invocationCount++; |
383 |
|
return value = subtract(x, y); |
384 |
|
} |
385 |
|
} |
386 |
|
static final class Noop implements Runnable { |
387 |
+ |
final ExecutionMode m; |
388 |
|
int invocationCount = 0; |
389 |
+ |
Noop(ExecutionMode m) { this.m = m; } |
390 |
|
public void run() { |
391 |
+ |
m.checkExecutionMode(); |
392 |
|
invocationCount++; |
393 |
|
} |
394 |
|
} |
395 |
|
|
396 |
|
static final class FailingSupplier implements Supplier<Integer> { |
397 |
+ |
final ExecutionMode m; |
398 |
|
int invocationCount = 0; |
399 |
+ |
FailingSupplier(ExecutionMode m) { this.m = m; } |
400 |
|
public Integer get() { |
401 |
+ |
m.checkExecutionMode(); |
402 |
|
invocationCount++; |
403 |
|
throw new CFException(); |
404 |
|
} |
405 |
|
} |
406 |
|
static final class FailingConsumer implements Consumer<Integer> { |
407 |
+ |
final ExecutionMode m; |
408 |
|
int invocationCount = 0; |
409 |
+ |
FailingConsumer(ExecutionMode m) { this.m = m; } |
410 |
|
public void accept(Integer x) { |
411 |
+ |
m.checkExecutionMode(); |
412 |
|
invocationCount++; |
413 |
|
throw new CFException(); |
414 |
|
} |
415 |
|
} |
416 |
|
static final class FailingBiConsumer implements BiConsumer<Integer, Integer> { |
417 |
+ |
final ExecutionMode m; |
418 |
|
int invocationCount = 0; |
419 |
+ |
FailingBiConsumer(ExecutionMode m) { this.m = m; } |
420 |
|
public void accept(Integer x, Integer y) { |
421 |
+ |
m.checkExecutionMode(); |
422 |
|
invocationCount++; |
423 |
|
throw new CFException(); |
424 |
|
} |
425 |
|
} |
426 |
|
static final class FailingFunction implements Function<Integer, Integer> { |
427 |
+ |
final ExecutionMode m; |
428 |
|
int invocationCount = 0; |
429 |
+ |
FailingFunction(ExecutionMode m) { this.m = m; } |
430 |
|
public Integer apply(Integer x) { |
431 |
+ |
m.checkExecutionMode(); |
432 |
|
invocationCount++; |
433 |
|
throw new CFException(); |
434 |
|
} |
435 |
|
} |
436 |
|
static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> { |
437 |
+ |
final ExecutionMode m; |
438 |
|
int invocationCount = 0; |
439 |
+ |
FailingBiFunction(ExecutionMode m) { this.m = m; } |
440 |
|
public Integer apply(Integer x, Integer y) { |
441 |
+ |
m.checkExecutionMode(); |
442 |
|
invocationCount++; |
443 |
|
throw new CFException(); |
444 |
|
} |
445 |
|
} |
446 |
|
static final class FailingRunnable implements Runnable { |
447 |
+ |
final ExecutionMode m; |
448 |
|
int invocationCount = 0; |
449 |
+ |
FailingRunnable(ExecutionMode m) { this.m = m; } |
450 |
|
public void run() { |
451 |
+ |
m.checkExecutionMode(); |
452 |
|
invocationCount++; |
453 |
|
throw new CFException(); |
454 |
|
} |
456 |
|
|
457 |
|
static final class CompletableFutureInc |
458 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
459 |
+ |
final ExecutionMode m; |
460 |
|
int invocationCount = 0; |
461 |
+ |
CompletableFutureInc(ExecutionMode m) { this.m = m; } |
462 |
|
public CompletableFuture<Integer> apply(Integer x) { |
463 |
+ |
m.checkExecutionMode(); |
464 |
|
invocationCount++; |
465 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
466 |
|
f.complete(inc(x)); |
470 |
|
|
471 |
|
static final class FailingCompletableFutureFunction |
472 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
473 |
+ |
final ExecutionMode m; |
474 |
|
int invocationCount = 0; |
475 |
+ |
FailingCompletableFutureFunction(ExecutionMode m) { this.m = m; } |
476 |
|
public CompletableFuture<Integer> apply(Integer x) { |
477 |
+ |
m.checkExecutionMode(); |
478 |
|
invocationCount++; |
479 |
|
throw new CFException(); |
480 |
|
} |
482 |
|
|
483 |
|
// Used for explicit executor tests |
484 |
|
static final class ThreadExecutor implements Executor { |
485 |
< |
AtomicInteger count = new AtomicInteger(0); |
485 |
> |
final AtomicInteger count = new AtomicInteger(0); |
486 |
> |
static final ThreadGroup tg = new ThreadGroup("ThreadExecutor"); |
487 |
> |
static boolean startedCurrentThread() { |
488 |
> |
return Thread.currentThread().getThreadGroup() == tg; |
489 |
> |
} |
490 |
|
|
491 |
|
public void execute(Runnable r) { |
492 |
|
count.getAndIncrement(); |
493 |
< |
new Thread(r).start(); |
493 |
> |
new Thread(tg, r).start(); |
494 |
|
} |
495 |
|
} |
496 |
|
|
636 |
|
|
637 |
|
EXECUTOR { |
638 |
|
public void checkExecutionMode() { |
639 |
< |
//TODO |
639 |
> |
assertTrue(ThreadExecutor.startedCurrentThread()); |
640 |
|
} |
641 |
|
public <T> CompletableFuture<Void> thenRun |
642 |
|
(CompletableFuture<T> f, Runnable a) { |
949 |
|
* runAsync completes after running Runnable |
950 |
|
*/ |
951 |
|
public void testRunAsync() { |
952 |
< |
Noop r = new Noop(); |
952 |
> |
Noop r = new Noop(ExecutionMode.ASYNC); |
953 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
954 |
|
assertNull(f.join()); |
955 |
|
assertEquals(1, r.invocationCount); |
960 |
|
* runAsync with executor completes after running Runnable |
961 |
|
*/ |
962 |
|
public void testRunAsync2() { |
963 |
< |
Noop r = new Noop(); |
963 |
> |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
964 |
|
ThreadExecutor exec = new ThreadExecutor(); |
965 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
966 |
|
assertNull(f.join()); |
973 |
|
* failing runAsync completes exceptionally after running Runnable |
974 |
|
*/ |
975 |
|
public void testRunAsync3() { |
976 |
< |
FailingRunnable r = new FailingRunnable(); |
976 |
> |
FailingRunnable r = new FailingRunnable(ExecutionMode.ASYNC); |
977 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
978 |
|
checkCompletedWithWrappedCFException(f); |
979 |
|
assertEquals(1, r.invocationCount); |
1003 |
|
* Failing supplyAsync completes exceptionally |
1004 |
|
*/ |
1005 |
|
public void testSupplyAsync3() { |
1006 |
< |
FailingSupplier r = new FailingSupplier(); |
1006 |
> |
FailingSupplier r = new FailingSupplier(ExecutionMode.ASYNC); |
1007 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r); |
1008 |
|
checkCompletedWithWrappedCFException(f); |
1009 |
|
assertEquals(1, r.invocationCount); |
1020 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1021 |
|
{ |
1022 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1023 |
< |
final Noop r = new Noop(); |
1023 |
> |
final Noop r = new Noop(m); |
1024 |
|
if (!createIncomplete) f.complete(v1); |
1025 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1026 |
< |
if (createIncomplete) f.complete(v1); |
1026 |
> |
if (createIncomplete) { |
1027 |
> |
checkIncomplete(g); |
1028 |
> |
f.complete(v1); |
1029 |
> |
} |
1030 |
|
|
1031 |
|
checkCompletedNormally(g, null); |
1032 |
|
checkCompletedNormally(f, v1); |
1043 |
|
{ |
1044 |
|
final CFException ex = new CFException(); |
1045 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1046 |
< |
final Noop r = new Noop(); |
1046 |
> |
final Noop r = new Noop(m); |
1047 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1048 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1049 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1049 |
> |
if (createIncomplete) { |
1050 |
> |
checkIncomplete(g); |
1051 |
> |
f.completeExceptionally(ex); |
1052 |
> |
} |
1053 |
|
|
1054 |
|
checkCompletedWithWrappedCFException(g, ex); |
1055 |
|
checkCompletedWithWrappedCFException(f, ex); |
1065 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1066 |
|
{ |
1067 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1068 |
< |
final Noop r = new Noop(); |
1068 |
> |
final Noop r = new Noop(m); |
1069 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1070 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1071 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1070 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1071 |
> |
if (createIncomplete) { |
1072 |
> |
checkIncomplete(g); |
1073 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1074 |
> |
} |
1075 |
|
|
1076 |
|
checkCompletedWithWrappedCancellationException(g); |
1077 |
|
checkCancelled(f); |
1087 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1088 |
|
{ |
1089 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1090 |
< |
final FailingRunnable r = new FailingRunnable(); |
1090 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1091 |
|
if (!createIncomplete) f.complete(v1); |
1092 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1093 |
< |
if (createIncomplete) f.complete(v1); |
1092 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1093 |
> |
if (createIncomplete) { |
1094 |
> |
checkIncomplete(g); |
1095 |
> |
f.complete(v1); |
1096 |
> |
} |
1097 |
|
|
1098 |
|
checkCompletedWithWrappedCFException(g); |
1099 |
|
checkCompletedNormally(f, v1); |
1108 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1109 |
|
{ |
1110 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1111 |
< |
final IncFunction r = new IncFunction(); |
1111 |
> |
final IncFunction r = new IncFunction(m); |
1112 |
|
if (!createIncomplete) f.complete(v1); |
1113 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1114 |
|
if (createIncomplete) { |
1131 |
|
{ |
1132 |
|
final CFException ex = new CFException(); |
1133 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1134 |
< |
final IncFunction r = new IncFunction(); |
1134 |
> |
final IncFunction r = new IncFunction(m); |
1135 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1136 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1137 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1137 |
> |
if (createIncomplete) { |
1138 |
> |
checkIncomplete(g); |
1139 |
> |
f.completeExceptionally(ex); |
1140 |
> |
} |
1141 |
|
|
1142 |
|
checkCompletedWithWrappedCFException(g, ex); |
1143 |
|
checkCompletedWithWrappedCFException(f, ex); |
1153 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1154 |
|
{ |
1155 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1156 |
< |
final IncFunction r = new IncFunction(); |
1156 |
> |
final IncFunction r = new IncFunction(m); |
1157 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1158 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1159 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1158 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1159 |
> |
if (createIncomplete) { |
1160 |
> |
checkIncomplete(g); |
1161 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1162 |
> |
} |
1163 |
|
|
1164 |
|
checkCompletedWithWrappedCancellationException(g); |
1165 |
|
checkCancelled(f); |
1175 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1176 |
|
{ |
1177 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1178 |
< |
final FailingFunction r = new FailingFunction(); |
1178 |
> |
final FailingFunction r = new FailingFunction(m); |
1179 |
|
if (!createIncomplete) f.complete(v1); |
1180 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1181 |
< |
if (createIncomplete) f.complete(v1); |
1180 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1181 |
> |
if (createIncomplete) { |
1182 |
> |
checkIncomplete(g); |
1183 |
> |
f.complete(v1); |
1184 |
> |
} |
1185 |
|
|
1186 |
|
checkCompletedWithWrappedCFException(g); |
1187 |
|
checkCompletedNormally(f, v1); |
1199 |
|
final IncAction r = new IncAction(); |
1200 |
|
if (!createIncomplete) f.complete(v1); |
1201 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1202 |
< |
if (createIncomplete) f.complete(v1); |
1202 |
> |
if (createIncomplete) { |
1203 |
> |
checkIncomplete(g); |
1204 |
> |
f.complete(v1); |
1205 |
> |
} |
1206 |
|
|
1207 |
|
checkCompletedNormally(g, null); |
1208 |
|
checkCompletedNormally(f, v1); |
1223 |
|
final IncAction r = new IncAction(); |
1224 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1225 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1226 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1226 |
> |
if (createIncomplete) { |
1227 |
> |
checkIncomplete(g); |
1228 |
> |
f.completeExceptionally(ex); |
1229 |
> |
} |
1230 |
|
|
1231 |
|
checkCompletedWithWrappedCFException(g, ex); |
1232 |
|
checkCompletedWithWrappedCFException(f, ex); |
1242 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1243 |
|
{ |
1244 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1245 |
< |
final FailingConsumer r = new FailingConsumer(); |
1245 |
> |
final FailingConsumer r = new FailingConsumer(m); |
1246 |
|
if (!createIncomplete) f.complete(v1); |
1247 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1248 |
< |
if (createIncomplete) f.complete(v1); |
1247 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1248 |
> |
if (createIncomplete) { |
1249 |
> |
checkIncomplete(g); |
1250 |
> |
f.complete(v1); |
1251 |
> |
} |
1252 |
|
|
1253 |
|
checkCompletedWithWrappedCFException(g); |
1254 |
|
checkCompletedNormally(f, v1); |
1265 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1266 |
|
final IncAction r = new IncAction(); |
1267 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1268 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1268 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1269 |
|
if (createIncomplete) { |
1270 |
|
checkIncomplete(g); |
1271 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1280 |
|
* thenCombine result completes normally after normal completion |
1281 |
|
* of sources |
1282 |
|
*/ |
1283 |
< |
public void testThenCombine_normalCompletion1() { |
1283 |
> |
public void testThenCombine_normalCompletion() { |
1284 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1285 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
1286 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1216 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1287 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1288 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1289 |
|
{ |
1290 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1291 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1292 |
< |
final SubtractFunction r = new SubtractFunction(); |
1223 |
< |
CompletableFuture<Integer> h = null; |
1224 |
< |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1292 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1293 |
|
|
1294 |
< |
if (fFirst) |
1295 |
< |
f.complete(v1); |
1296 |
< |
else |
1297 |
< |
g.complete(v2); |
1298 |
< |
if (createIncomplete) checkIncomplete(h); |
1299 |
< |
assertEquals(0, r.invocationCount); |
1300 |
< |
if (!fFirst) |
1301 |
< |
f.complete(v1); |
1302 |
< |
else |
1235 |
< |
g.complete(v2); |
1236 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1294 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1295 |
> |
if (!createIncomplete) |
1296 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1297 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1298 |
> |
if (createIncomplete) { |
1299 |
> |
checkIncomplete(h); |
1300 |
> |
assertEquals(0, r.invocationCount); |
1301 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1302 |
> |
} |
1303 |
|
|
1304 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1305 |
|
checkCompletedNormally(f, v1); |
1311 |
|
* thenCombine result completes exceptionally after exceptional |
1312 |
|
* completion of either source |
1313 |
|
*/ |
1314 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1249 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1250 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1251 |
< |
{ |
1252 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1253 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1254 |
< |
final SubtractFunction r = new SubtractFunction(); |
1255 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1256 |
< |
final CFException ex = new CFException(); |
1257 |
< |
|
1258 |
< |
f.completeExceptionally(ex); |
1259 |
< |
checkIncomplete(h); |
1260 |
< |
g.complete(v1); |
1261 |
< |
|
1262 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1263 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1264 |
< |
assertEquals(0, r.invocationCount); |
1265 |
< |
checkCompletedNormally(g, v1); |
1266 |
< |
}} |
1267 |
< |
|
1268 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1269 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1270 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1271 |
< |
{ |
1272 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1273 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1274 |
< |
final SubtractFunction r = new SubtractFunction(); |
1275 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1276 |
< |
final CFException ex = new CFException(); |
1277 |
< |
|
1278 |
< |
g.completeExceptionally(ex); |
1279 |
< |
checkIncomplete(h); |
1280 |
< |
f.complete(v1); |
1281 |
< |
|
1282 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1283 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1284 |
< |
assertEquals(0, r.invocationCount); |
1285 |
< |
checkCompletedNormally(f, v1); |
1286 |
< |
}} |
1287 |
< |
|
1288 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1289 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1290 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1291 |
< |
{ |
1292 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1293 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1294 |
< |
final SubtractFunction r = new SubtractFunction(); |
1295 |
< |
final CFException ex = new CFException(); |
1296 |
< |
|
1297 |
< |
g.completeExceptionally(ex); |
1298 |
< |
f.complete(v1); |
1299 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1300 |
< |
|
1301 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1302 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1303 |
< |
assertEquals(0, r.invocationCount); |
1304 |
< |
checkCompletedNormally(f, v1); |
1305 |
< |
}} |
1306 |
< |
|
1307 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1314 |
> |
public void testThenCombine_exceptionalCompletion() { |
1315 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1317 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1318 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1319 |
|
{ |
1320 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1321 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1313 |
– |
final SubtractFunction r = new SubtractFunction(); |
1322 |
|
final CFException ex = new CFException(); |
1323 |
+ |
final SubtractFunction r = new SubtractFunction(m); |
1324 |
|
|
1325 |
< |
f.completeExceptionally(ex); |
1326 |
< |
g.complete(v1); |
1325 |
> |
(fFirst ? f : g).complete(v1); |
1326 |
> |
if (!createIncomplete) |
1327 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1328 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1329 |
+ |
if (createIncomplete) { |
1330 |
+ |
checkIncomplete(h); |
1331 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1332 |
+ |
} |
1333 |
|
|
1334 |
|
checkCompletedWithWrappedCFException(h, ex); |
1321 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1335 |
|
assertEquals(0, r.invocationCount); |
1336 |
< |
checkCompletedNormally(g, v1); |
1336 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1337 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1338 |
|
}} |
1339 |
|
|
1340 |
|
/** |
1341 |
|
* thenCombine result completes exceptionally if action does |
1342 |
|
*/ |
1343 |
< |
public void testThenCombine_actionFailed1() { |
1330 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1331 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1332 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1333 |
< |
{ |
1334 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1335 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1336 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1337 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1338 |
< |
|
1339 |
< |
f.complete(v1); |
1340 |
< |
checkIncomplete(h); |
1341 |
< |
g.complete(v2); |
1342 |
< |
|
1343 |
< |
checkCompletedWithWrappedCFException(h); |
1344 |
< |
checkCompletedNormally(f, v1); |
1345 |
< |
checkCompletedNormally(g, v2); |
1346 |
< |
}} |
1347 |
< |
|
1348 |
< |
public void testThenCombine_actionFailed2() { |
1343 |
> |
public void testThenCombine_actionFailed() { |
1344 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1345 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1346 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1347 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1348 |
|
{ |
1349 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1350 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1351 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1351 |
> |
final FailingBiFunction r = new FailingBiFunction(m); |
1352 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1353 |
|
|
1354 |
< |
g.complete(v2); |
1355 |
< |
checkIncomplete(h); |
1356 |
< |
f.complete(v1); |
1354 |
> |
if (fFirst) { |
1355 |
> |
f.complete(v1); |
1356 |
> |
g.complete(v2); |
1357 |
> |
} else { |
1358 |
> |
g.complete(v2); |
1359 |
> |
f.complete(v1); |
1360 |
> |
} |
1361 |
|
|
1362 |
|
checkCompletedWithWrappedCFException(h); |
1363 |
|
checkCompletedNormally(f, v1); |
1367 |
|
/** |
1368 |
|
* thenCombine result completes exceptionally if either source cancelled |
1369 |
|
*/ |
1370 |
< |
public void testThenCombine_sourceCancelled1() { |
1371 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1372 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1373 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1374 |
< |
{ |
1375 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1376 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1377 |
< |
final SubtractFunction r = new SubtractFunction(); |
1378 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1379 |
< |
|
1380 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1381 |
< |
checkIncomplete(h); |
1382 |
< |
g.complete(v1); |
1383 |
< |
|
1384 |
< |
checkCompletedWithWrappedCancellationException(h); |
1385 |
< |
checkCancelled(f); |
1386 |
< |
assertEquals(0, r.invocationCount); |
1387 |
< |
checkCompletedNormally(g, v1); |
1388 |
< |
}} |
1389 |
< |
|
1390 |
< |
public void testThenCombine_sourceCancelled2() { |
1391 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1392 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1393 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1394 |
< |
{ |
1395 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1396 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1397 |
< |
final SubtractFunction r = new SubtractFunction(); |
1398 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1399 |
< |
|
1400 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1401 |
< |
checkIncomplete(h); |
1402 |
< |
f.complete(v1); |
1403 |
< |
|
1404 |
< |
checkCompletedWithWrappedCancellationException(h); |
1405 |
< |
checkCancelled(g); |
1406 |
< |
assertEquals(0, r.invocationCount); |
1407 |
< |
checkCompletedNormally(f, v1); |
1408 |
< |
}} |
1409 |
< |
|
1410 |
< |
public void testThenCombine_sourceCancelled3() { |
1411 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1412 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1413 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1414 |
< |
{ |
1415 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1416 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1417 |
< |
final SubtractFunction r = new SubtractFunction(); |
1418 |
< |
|
1419 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1420 |
< |
f.complete(v1); |
1421 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1422 |
< |
|
1423 |
< |
checkCompletedWithWrappedCancellationException(h); |
1424 |
< |
checkCancelled(g); |
1425 |
< |
assertEquals(0, r.invocationCount); |
1426 |
< |
checkCompletedNormally(f, v1); |
1427 |
< |
}} |
1428 |
< |
|
1429 |
< |
public void testThenCombine_sourceCancelled4() { |
1370 |
> |
public void testThenCombine_sourceCancelled() { |
1371 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1372 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1373 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1374 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1375 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1376 |
|
{ |
1377 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1378 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1379 |
< |
final SubtractFunction r = new SubtractFunction(); |
1379 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1380 |
|
|
1381 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1382 |
< |
g.complete(v1); |
1381 |
> |
(fFirst ? f : g).complete(v1); |
1382 |
> |
if (!createIncomplete) |
1383 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1384 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1385 |
+ |
if (createIncomplete) { |
1386 |
+ |
checkIncomplete(h); |
1387 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1388 |
+ |
} |
1389 |
|
|
1390 |
|
checkCompletedWithWrappedCancellationException(h); |
1391 |
< |
checkCancelled(f); |
1391 |
> |
checkCancelled(!fFirst ? f : g); |
1392 |
|
assertEquals(0, r.invocationCount); |
1393 |
< |
checkCompletedNormally(g, v1); |
1393 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1394 |
|
}} |
1395 |
|
|
1396 |
|
/** |
1397 |
|
* thenAcceptBoth result completes normally after normal |
1398 |
|
* completion of sources |
1399 |
|
*/ |
1400 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1453 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1454 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1455 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1456 |
< |
{ |
1457 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1458 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1459 |
< |
final SubtractAction r = new SubtractAction(); |
1460 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1461 |
< |
|
1462 |
< |
f.complete(v1); |
1463 |
< |
checkIncomplete(h); |
1464 |
< |
assertEquals(0, r.invocationCount); |
1465 |
< |
g.complete(v2); |
1466 |
< |
|
1467 |
< |
checkCompletedNormally(h, null); |
1468 |
< |
assertEquals(subtract(v1, v2), r.value); |
1469 |
< |
checkCompletedNormally(f, v1); |
1470 |
< |
checkCompletedNormally(g, v2); |
1471 |
< |
}} |
1472 |
< |
|
1473 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1474 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1475 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1476 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1477 |
< |
{ |
1478 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1479 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1480 |
< |
final SubtractAction r = new SubtractAction(); |
1481 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1482 |
< |
|
1483 |
< |
g.complete(v2); |
1484 |
< |
checkIncomplete(h); |
1485 |
< |
assertEquals(0, r.invocationCount); |
1486 |
< |
f.complete(v1); |
1487 |
< |
|
1488 |
< |
checkCompletedNormally(h, null); |
1489 |
< |
assertEquals(subtract(v1, v2), r.value); |
1490 |
< |
checkCompletedNormally(f, v1); |
1491 |
< |
checkCompletedNormally(g, v2); |
1492 |
< |
}} |
1493 |
< |
|
1494 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1495 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1496 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1497 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1498 |
< |
{ |
1499 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1500 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1501 |
< |
final SubtractAction r = new SubtractAction(); |
1502 |
< |
|
1503 |
< |
g.complete(v2); |
1504 |
< |
f.complete(v1); |
1505 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1506 |
< |
|
1507 |
< |
checkCompletedNormally(h, null); |
1508 |
< |
assertEquals(subtract(v1, v2), r.value); |
1509 |
< |
checkCompletedNormally(f, v1); |
1510 |
< |
checkCompletedNormally(g, v2); |
1511 |
< |
}} |
1512 |
< |
|
1513 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1400 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1401 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1402 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1403 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1404 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1405 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1406 |
|
{ |
1407 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1408 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1409 |
< |
final SubtractAction r = new SubtractAction(); |
1409 |
> |
final SubtractAction r = new SubtractAction(m); |
1410 |
|
|
1411 |
< |
f.complete(v1); |
1412 |
< |
g.complete(v2); |
1411 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1412 |
> |
if (!createIncomplete) |
1413 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1414 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1415 |
+ |
if (createIncomplete) { |
1416 |
+ |
checkIncomplete(h); |
1417 |
+ |
assertEquals(0, r.invocationCount); |
1418 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1419 |
+ |
} |
1420 |
|
|
1421 |
|
checkCompletedNormally(h, null); |
1422 |
|
assertEquals(subtract(v1, v2), r.value); |
1428 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1429 |
|
* completion of either source |
1430 |
|
*/ |
1431 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1537 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1538 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1539 |
< |
{ |
1540 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1541 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1542 |
< |
final SubtractAction r = new SubtractAction(); |
1543 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1544 |
< |
final CFException ex = new CFException(); |
1545 |
< |
|
1546 |
< |
f.completeExceptionally(ex); |
1547 |
< |
checkIncomplete(h); |
1548 |
< |
g.complete(v1); |
1549 |
< |
|
1550 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1551 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1552 |
< |
assertEquals(0, r.invocationCount); |
1553 |
< |
checkCompletedNormally(g, v1); |
1554 |
< |
}} |
1555 |
< |
|
1556 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1557 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1558 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1559 |
< |
{ |
1560 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1561 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1562 |
< |
final SubtractAction r = new SubtractAction(); |
1563 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1564 |
< |
final CFException ex = new CFException(); |
1565 |
< |
|
1566 |
< |
g.completeExceptionally(ex); |
1567 |
< |
checkIncomplete(h); |
1568 |
< |
f.complete(v1); |
1569 |
< |
|
1570 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1571 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1572 |
< |
assertEquals(0, r.invocationCount); |
1573 |
< |
checkCompletedNormally(f, v1); |
1574 |
< |
}} |
1575 |
< |
|
1576 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1577 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1578 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1579 |
< |
{ |
1580 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1581 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1582 |
< |
final SubtractAction r = new SubtractAction(); |
1583 |
< |
final CFException ex = new CFException(); |
1584 |
< |
|
1585 |
< |
g.completeExceptionally(ex); |
1586 |
< |
f.complete(v1); |
1587 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1588 |
< |
|
1589 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1590 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1591 |
< |
assertEquals(0, r.invocationCount); |
1592 |
< |
checkCompletedNormally(f, v1); |
1593 |
< |
}} |
1594 |
< |
|
1595 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1431 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1432 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1433 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1434 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1435 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1436 |
|
{ |
1437 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1438 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1601 |
– |
final SubtractAction r = new SubtractAction(); |
1439 |
|
final CFException ex = new CFException(); |
1440 |
+ |
final SubtractAction r = new SubtractAction(m); |
1441 |
|
|
1442 |
< |
f.completeExceptionally(ex); |
1443 |
< |
g.complete(v1); |
1442 |
> |
(fFirst ? f : g).complete(v1); |
1443 |
> |
if (!createIncomplete) |
1444 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1445 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1446 |
+ |
if (createIncomplete) { |
1447 |
+ |
checkIncomplete(h); |
1448 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1449 |
+ |
} |
1450 |
|
|
1451 |
|
checkCompletedWithWrappedCFException(h, ex); |
1609 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1452 |
|
assertEquals(0, r.invocationCount); |
1453 |
< |
checkCompletedNormally(g, v1); |
1453 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1454 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1455 |
|
}} |
1456 |
|
|
1457 |
|
/** |
1458 |
|
* thenAcceptBoth result completes exceptionally if action does |
1459 |
|
*/ |
1460 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1618 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1619 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1620 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1621 |
< |
{ |
1622 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1623 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1624 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1625 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1626 |
< |
|
1627 |
< |
f.complete(v1); |
1628 |
< |
checkIncomplete(h); |
1629 |
< |
g.complete(v2); |
1630 |
< |
|
1631 |
< |
checkCompletedWithWrappedCFException(h); |
1632 |
< |
checkCompletedNormally(f, v1); |
1633 |
< |
checkCompletedNormally(g, v2); |
1634 |
< |
}} |
1635 |
< |
|
1636 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1460 |
> |
public void testThenAcceptBoth_actionFailed() { |
1461 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1462 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1463 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1464 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1465 |
|
{ |
1466 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1467 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1468 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1468 |
> |
final FailingBiConsumer r = new FailingBiConsumer(m); |
1469 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1470 |
|
|
1471 |
< |
g.complete(v2); |
1472 |
< |
checkIncomplete(h); |
1473 |
< |
f.complete(v1); |
1471 |
> |
if (fFirst) { |
1472 |
> |
f.complete(v1); |
1473 |
> |
g.complete(v2); |
1474 |
> |
} else { |
1475 |
> |
g.complete(v2); |
1476 |
> |
f.complete(v1); |
1477 |
> |
} |
1478 |
|
|
1479 |
|
checkCompletedWithWrappedCFException(h); |
1480 |
|
checkCompletedNormally(f, v1); |
1484 |
|
/** |
1485 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1486 |
|
*/ |
1487 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1659 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1660 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1661 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1662 |
< |
{ |
1663 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1664 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1665 |
< |
final SubtractAction r = new SubtractAction(); |
1666 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1667 |
< |
|
1668 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1669 |
< |
checkIncomplete(h); |
1670 |
< |
g.complete(v1); |
1671 |
< |
|
1672 |
< |
checkCompletedWithWrappedCancellationException(h); |
1673 |
< |
checkCancelled(f); |
1674 |
< |
assertEquals(0, r.invocationCount); |
1675 |
< |
checkCompletedNormally(g, v1); |
1676 |
< |
}} |
1677 |
< |
|
1678 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1679 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1680 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1681 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1682 |
< |
{ |
1683 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1684 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1685 |
< |
final SubtractAction r = new SubtractAction(); |
1686 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1687 |
< |
|
1688 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1689 |
< |
checkIncomplete(h); |
1690 |
< |
f.complete(v1); |
1691 |
< |
|
1692 |
< |
checkCompletedWithWrappedCancellationException(h); |
1693 |
< |
checkCancelled(g); |
1694 |
< |
assertEquals(0, r.invocationCount); |
1695 |
< |
checkCompletedNormally(f, v1); |
1696 |
< |
}} |
1697 |
< |
|
1698 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1699 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1700 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1701 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1702 |
< |
{ |
1703 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1704 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1705 |
< |
final SubtractAction r = new SubtractAction(); |
1706 |
< |
|
1707 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1708 |
< |
f.complete(v1); |
1709 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1710 |
< |
|
1711 |
< |
checkCompletedWithWrappedCancellationException(h); |
1712 |
< |
checkCancelled(g); |
1713 |
< |
assertEquals(0, r.invocationCount); |
1714 |
< |
checkCompletedNormally(f, v1); |
1715 |
< |
}} |
1716 |
< |
|
1717 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1487 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1488 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1489 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1490 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1491 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1492 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1493 |
|
{ |
1494 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1495 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1496 |
< |
final SubtractAction r = new SubtractAction(); |
1496 |
> |
final SubtractAction r = new SubtractAction(m); |
1497 |
|
|
1498 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1499 |
< |
g.complete(v1); |
1498 |
> |
(fFirst ? f : g).complete(v1); |
1499 |
> |
if (!createIncomplete) |
1500 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1501 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1502 |
+ |
if (createIncomplete) { |
1503 |
+ |
checkIncomplete(h); |
1504 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1505 |
+ |
} |
1506 |
|
|
1507 |
|
checkCompletedWithWrappedCancellationException(h); |
1508 |
< |
checkCancelled(f); |
1508 |
> |
checkCancelled(!fFirst ? f : g); |
1509 |
|
assertEquals(0, r.invocationCount); |
1510 |
< |
checkCompletedNormally(g, v1); |
1510 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1511 |
|
}} |
1512 |
|
|
1513 |
|
/** |
1514 |
|
* runAfterBoth result completes normally after normal |
1515 |
|
* completion of sources |
1516 |
|
*/ |
1517 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1741 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1742 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1743 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1744 |
< |
{ |
1745 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1746 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1747 |
< |
final Noop r = new Noop(); |
1748 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1749 |
< |
|
1750 |
< |
f.complete(v1); |
1751 |
< |
checkIncomplete(h); |
1752 |
< |
assertEquals(0, r.invocationCount); |
1753 |
< |
g.complete(v2); |
1754 |
< |
|
1755 |
< |
checkCompletedNormally(h, null); |
1756 |
< |
assertEquals(1, r.invocationCount); |
1757 |
< |
checkCompletedNormally(f, v1); |
1758 |
< |
checkCompletedNormally(g, v2); |
1759 |
< |
}} |
1760 |
< |
|
1761 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1762 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1763 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1764 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1765 |
< |
{ |
1766 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1767 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1768 |
< |
final Noop r = new Noop(); |
1769 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1770 |
< |
|
1771 |
< |
g.complete(v2); |
1772 |
< |
checkIncomplete(h); |
1773 |
< |
assertEquals(0, r.invocationCount); |
1774 |
< |
f.complete(v1); |
1775 |
< |
|
1776 |
< |
checkCompletedNormally(h, null); |
1777 |
< |
assertEquals(1, r.invocationCount); |
1778 |
< |
checkCompletedNormally(f, v1); |
1779 |
< |
checkCompletedNormally(g, v2); |
1780 |
< |
}} |
1781 |
< |
|
1782 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1783 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1784 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1785 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1786 |
< |
{ |
1787 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1788 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1789 |
< |
final Noop r = new Noop(); |
1790 |
< |
|
1791 |
< |
g.complete(v2); |
1792 |
< |
f.complete(v1); |
1793 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1794 |
< |
|
1795 |
< |
checkCompletedNormally(h, null); |
1796 |
< |
assertEquals(1, r.invocationCount); |
1797 |
< |
checkCompletedNormally(f, v1); |
1798 |
< |
checkCompletedNormally(g, v2); |
1799 |
< |
}} |
1800 |
< |
|
1801 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1517 |
> |
public void testRunAfterBoth_normalCompletion() { |
1518 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1519 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1520 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1521 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1522 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1523 |
|
{ |
1524 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1525 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1526 |
< |
final Noop r = new Noop(); |
1526 |
> |
final Noop r = new Noop(m); |
1527 |
|
|
1528 |
< |
f.complete(v1); |
1529 |
< |
g.complete(v2); |
1528 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1529 |
> |
if (!createIncomplete) |
1530 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1531 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1532 |
+ |
if (createIncomplete) { |
1533 |
+ |
checkIncomplete(h); |
1534 |
+ |
assertEquals(0, r.invocationCount); |
1535 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1536 |
+ |
} |
1537 |
|
|
1538 |
|
checkCompletedNormally(h, null); |
1539 |
|
assertEquals(1, r.invocationCount); |
1545 |
|
* runAfterBoth result completes exceptionally after exceptional |
1546 |
|
* completion of either source |
1547 |
|
*/ |
1548 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1825 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1826 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1827 |
< |
{ |
1828 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1829 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1830 |
< |
final Noop r = new Noop(); |
1831 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1832 |
< |
final CFException ex = new CFException(); |
1833 |
< |
|
1834 |
< |
f.completeExceptionally(ex); |
1835 |
< |
checkIncomplete(h); |
1836 |
< |
g.complete(v1); |
1837 |
< |
|
1838 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1839 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1840 |
< |
assertEquals(0, r.invocationCount); |
1841 |
< |
checkCompletedNormally(g, v1); |
1842 |
< |
}} |
1843 |
< |
|
1844 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1845 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1846 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1847 |
< |
{ |
1848 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1849 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1850 |
< |
final Noop r = new Noop(); |
1851 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1852 |
< |
final CFException ex = new CFException(); |
1853 |
< |
|
1854 |
< |
g.completeExceptionally(ex); |
1855 |
< |
checkIncomplete(h); |
1856 |
< |
f.complete(v1); |
1857 |
< |
|
1858 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1859 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1860 |
< |
assertEquals(0, r.invocationCount); |
1861 |
< |
checkCompletedNormally(f, v1); |
1862 |
< |
}} |
1863 |
< |
|
1864 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1865 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1866 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1867 |
< |
{ |
1868 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1869 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1870 |
< |
final Noop r = new Noop(); |
1871 |
< |
final CFException ex = new CFException(); |
1872 |
< |
|
1873 |
< |
g.completeExceptionally(ex); |
1874 |
< |
f.complete(v1); |
1875 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1876 |
< |
|
1877 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1878 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1879 |
< |
assertEquals(0, r.invocationCount); |
1880 |
< |
checkCompletedNormally(f, v1); |
1881 |
< |
}} |
1882 |
< |
|
1883 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1548 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1549 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1550 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1551 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1552 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1553 |
|
{ |
1554 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1555 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1889 |
– |
final Noop r = new Noop(); |
1556 |
|
final CFException ex = new CFException(); |
1557 |
+ |
final Noop r = new Noop(m); |
1558 |
|
|
1559 |
< |
f.completeExceptionally(ex); |
1560 |
< |
g.complete(v1); |
1559 |
> |
(fFirst ? f : g).complete(v1); |
1560 |
> |
if (!createIncomplete) |
1561 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1562 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1563 |
+ |
if (createIncomplete) { |
1564 |
+ |
checkIncomplete(h); |
1565 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1566 |
+ |
} |
1567 |
|
|
1568 |
|
checkCompletedWithWrappedCFException(h, ex); |
1897 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1569 |
|
assertEquals(0, r.invocationCount); |
1570 |
< |
checkCompletedNormally(g, v1); |
1570 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1571 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1572 |
|
}} |
1573 |
|
|
1574 |
|
/** |
1575 |
|
* runAfterBoth result completes exceptionally if action does |
1576 |
|
*/ |
1577 |
< |
public void testRunAfterBoth_actionFailed1() { |
1906 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1907 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1908 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1909 |
< |
{ |
1910 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1911 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1912 |
< |
final FailingRunnable r = new FailingRunnable(); |
1913 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1914 |
< |
|
1915 |
< |
f.complete(v1); |
1916 |
< |
checkIncomplete(h); |
1917 |
< |
g.complete(v2); |
1918 |
< |
|
1919 |
< |
checkCompletedWithWrappedCFException(h); |
1920 |
< |
checkCompletedNormally(f, v1); |
1921 |
< |
checkCompletedNormally(g, v2); |
1922 |
< |
}} |
1923 |
< |
|
1924 |
< |
public void testRunAfterBoth_actionFailed2() { |
1577 |
> |
public void testRunAfterBoth_actionFailed() { |
1578 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1579 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1580 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1581 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1582 |
|
{ |
1583 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1584 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1585 |
< |
final FailingRunnable r = new FailingRunnable(); |
1932 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1586 |
|
|
1587 |
< |
g.complete(v2); |
1588 |
< |
checkIncomplete(h); |
1589 |
< |
f.complete(v1); |
1587 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1588 |
> |
if (fFirst) { |
1589 |
> |
f.complete(v1); |
1590 |
> |
g.complete(v2); |
1591 |
> |
} else { |
1592 |
> |
g.complete(v2); |
1593 |
> |
f.complete(v1); |
1594 |
> |
} |
1595 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1596 |
|
|
1597 |
< |
checkCompletedWithWrappedCFException(h); |
1597 |
> |
checkCompletedWithWrappedCFException(h1); |
1598 |
> |
checkCompletedWithWrappedCFException(h2); |
1599 |
|
checkCompletedNormally(f, v1); |
1600 |
|
checkCompletedNormally(g, v2); |
1601 |
|
}} |
1603 |
|
/** |
1604 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1605 |
|
*/ |
1606 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1947 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1948 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1949 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1950 |
< |
{ |
1951 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1952 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1953 |
< |
final Noop r = new Noop(); |
1954 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1955 |
< |
|
1956 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1957 |
< |
checkIncomplete(h); |
1958 |
< |
g.complete(v1); |
1959 |
< |
|
1960 |
< |
checkCompletedWithWrappedCancellationException(h); |
1961 |
< |
checkCancelled(f); |
1962 |
< |
assertEquals(0, r.invocationCount); |
1963 |
< |
checkCompletedNormally(g, v1); |
1964 |
< |
}} |
1965 |
< |
|
1966 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1967 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1968 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1969 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1970 |
< |
{ |
1971 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1972 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1973 |
< |
final Noop r = new Noop(); |
1974 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1975 |
< |
|
1976 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1977 |
< |
checkIncomplete(h); |
1978 |
< |
f.complete(v1); |
1979 |
< |
|
1980 |
< |
checkCompletedWithWrappedCancellationException(h); |
1981 |
< |
checkCancelled(g); |
1982 |
< |
assertEquals(0, r.invocationCount); |
1983 |
< |
checkCompletedNormally(f, v1); |
1984 |
< |
}} |
1985 |
< |
|
1986 |
< |
public void testRunAfterBoth_sourceCancelled3() { |
1606 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1607 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1608 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1609 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1610 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1611 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1612 |
|
{ |
1613 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1614 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1615 |
< |
final Noop r = new Noop(); |
1994 |
< |
|
1995 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1996 |
< |
f.complete(v1); |
1997 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1998 |
< |
|
1999 |
< |
checkCompletedWithWrappedCancellationException(h); |
2000 |
< |
checkCancelled(g); |
2001 |
< |
assertEquals(0, r.invocationCount); |
2002 |
< |
checkCompletedNormally(f, v1); |
2003 |
< |
}} |
1615 |
> |
final Noop r = new Noop(m); |
1616 |
|
|
2005 |
– |
public void testRunAfterBoth_sourceCancelled4() { |
2006 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2007 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2008 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2009 |
– |
{ |
2010 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2011 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2012 |
– |
final Noop r = new Noop(); |
1617 |
|
|
1618 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1619 |
< |
g.complete(v1); |
1618 |
> |
(fFirst ? f : g).complete(v1); |
1619 |
> |
if (!createIncomplete) |
1620 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1621 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1622 |
+ |
if (createIncomplete) { |
1623 |
+ |
checkIncomplete(h); |
1624 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1625 |
+ |
} |
1626 |
|
|
1627 |
|
checkCompletedWithWrappedCancellationException(h); |
1628 |
< |
checkCancelled(f); |
1628 |
> |
checkCancelled(!fFirst ? f : g); |
1629 |
|
assertEquals(0, r.invocationCount); |
1630 |
< |
checkCompletedNormally(g, v1); |
1630 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1631 |
|
}} |
1632 |
|
|
1633 |
|
/** |
1634 |
|
* applyToEither result completes normally after normal completion |
1635 |
|
* of either source |
1636 |
|
*/ |
1637 |
< |
public void testApplyToEither_normalCompletion1() { |
1637 |
> |
public void testApplyToEither_normalCompletion() { |
1638 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1639 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1640 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1641 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1642 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1643 |
|
{ |
1644 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1645 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1646 |
< |
final IncFunction r = new IncFunction(); |
2036 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1646 |
> |
final IncFunction r = new IncFunction(m); |
1647 |
|
|
1648 |
< |
f.complete(v1); |
1649 |
< |
checkCompletedNormally(h, inc(v1)); |
1650 |
< |
g.complete(v2); |
1648 |
> |
if (!createIncomplete) |
1649 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1650 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1651 |
> |
if (createIncomplete) { |
1652 |
> |
checkIncomplete(h); |
1653 |
> |
assertEquals(0, r.invocationCount); |
1654 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1655 |
> |
} |
1656 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1657 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1658 |
|
|
1659 |
|
checkCompletedNormally(f, v1); |
1660 |
|
checkCompletedNormally(g, v2); |
1661 |
< |
checkCompletedNormally(h, inc(v1)); |
1661 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1662 |
|
}} |
1663 |
|
|
1664 |
< |
public void testApplyToEither_normalCompletion2() { |
1664 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1665 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1666 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1667 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1668 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1669 |
|
{ |
1670 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1671 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1672 |
< |
final IncFunction r = new IncFunction(); |
2055 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2056 |
< |
|
2057 |
< |
g.complete(v2); |
2058 |
< |
checkCompletedNormally(h, inc(v2)); |
2059 |
< |
f.complete(v1); |
2060 |
< |
|
2061 |
< |
checkCompletedNormally(f, v1); |
2062 |
< |
checkCompletedNormally(g, v2); |
2063 |
< |
checkCompletedNormally(h, inc(v2)); |
2064 |
< |
}} |
1672 |
> |
final IncFunction r = new IncFunction(m); |
1673 |
|
|
1674 |
< |
public void testApplyToEither_normalCompletion3() { |
1675 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1676 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1677 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1678 |
< |
{ |
1679 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1680 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2073 |
< |
final IncFunction r = new IncFunction(); |
1674 |
> |
if (fFirst) { |
1675 |
> |
f.complete(v1); |
1676 |
> |
g.complete(v2); |
1677 |
> |
} else { |
1678 |
> |
g.complete(v2); |
1679 |
> |
f.complete(v1); |
1680 |
> |
} |
1681 |
|
|
2075 |
– |
f.complete(v1); |
2076 |
– |
g.complete(v2); |
1682 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1683 |
|
|
1684 |
|
checkCompletedNormally(f, v1); |
1696 |
|
*/ |
1697 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1698 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1699 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1700 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1701 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1702 |
|
{ |
1703 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1704 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2098 |
– |
final IncFunction r = new IncFunction(); |
2099 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1705 |
|
final CFException ex = new CFException(); |
1706 |
+ |
final IncFunction r = new IncFunction(m); |
1707 |
|
|
1708 |
< |
f.completeExceptionally(ex); |
2103 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2104 |
< |
g.complete(v1); |
2105 |
< |
|
2106 |
< |
assertEquals(0, r.invocationCount); |
2107 |
< |
checkCompletedNormally(g, v1); |
2108 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2109 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2110 |
< |
}} |
2111 |
< |
|
2112 |
< |
public void testApplyToEither_exceptionalCompletion2() { |
2113 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2114 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2115 |
< |
{ |
2116 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2117 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2118 |
< |
final IncFunction r = new IncFunction(); |
1708 |
> |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1709 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1710 |
< |
final CFException ex = new CFException(); |
1710 |
> |
if (createIncomplete) { |
1711 |
> |
checkIncomplete(h); |
1712 |
> |
assertEquals(0, r.invocationCount); |
1713 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1714 |
> |
} |
1715 |
|
|
2122 |
– |
g.completeExceptionally(ex); |
1716 |
|
checkCompletedWithWrappedCFException(h, ex); |
1717 |
< |
f.complete(v1); |
1717 |
> |
(!fFirst ? f : g).complete(v1); |
1718 |
|
|
1719 |
|
assertEquals(0, r.invocationCount); |
1720 |
< |
checkCompletedNormally(f, v1); |
1721 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1720 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1721 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1722 |
|
checkCompletedWithWrappedCFException(h, ex); |
1723 |
|
}} |
1724 |
|
|
1725 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1725 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1726 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1727 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1728 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1729 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1730 |
|
{ |
1731 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1732 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1733 |
< |
final IncFunction r = new IncFunction(); |
1733 |
> |
final IncFunction r1 = new IncFunction(m); |
1734 |
> |
final IncFunction r2 = new IncFunction(m); |
1735 |
|
final CFException ex = new CFException(); |
1736 |
< |
|
1737 |
< |
g.completeExceptionally(ex); |
1738 |
< |
f.complete(v1); |
1739 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1736 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1737 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1738 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1739 |
> |
if (fFirst) { |
1740 |
> |
f.complete(v1); |
1741 |
> |
g.completeExceptionally(ex); |
1742 |
> |
} else { |
1743 |
> |
g.completeExceptionally(ex); |
1744 |
> |
f.complete(v1); |
1745 |
> |
} |
1746 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1747 |
|
|
1748 |
|
// unspecified behavior |
2146 |
– |
Integer v; |
1749 |
|
try { |
1750 |
< |
assertEquals(inc(v1), h.join()); |
1751 |
< |
assertEquals(1, r.invocationCount); |
1750 |
> |
assertEquals(inc(v1), h1.join()); |
1751 |
> |
assertEquals(1, r1.invocationCount); |
1752 |
|
} catch (CompletionException ok) { |
1753 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1754 |
< |
assertEquals(0, r.invocationCount); |
1753 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1754 |
> |
assertEquals(0, r1.invocationCount); |
1755 |
|
} |
1756 |
|
|
2155 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2156 |
– |
checkCompletedNormally(f, v1); |
2157 |
– |
}} |
2158 |
– |
|
2159 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2160 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2161 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2162 |
– |
{ |
2163 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2164 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2165 |
– |
final IncFunction r = new IncFunction(); |
2166 |
– |
final CFException ex = new CFException(); |
2167 |
– |
|
2168 |
– |
f.completeExceptionally(ex); |
2169 |
– |
g.complete(v1); |
2170 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2171 |
– |
|
2172 |
– |
// unspecified behavior |
2173 |
– |
Integer v; |
1757 |
|
try { |
1758 |
< |
assertEquals(inc(v1), h.join()); |
1759 |
< |
assertEquals(1, r.invocationCount); |
1758 |
> |
assertEquals(inc(v1), h2.join()); |
1759 |
> |
assertEquals(1, r2.invocationCount); |
1760 |
|
} catch (CompletionException ok) { |
1761 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1762 |
< |
assertEquals(0, r.invocationCount); |
1761 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1762 |
> |
assertEquals(0, r2.invocationCount); |
1763 |
|
} |
1764 |
|
|
1765 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1766 |
< |
checkCompletedNormally(g, v1); |
1765 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1766 |
> |
checkCompletedNormally(f, v1); |
1767 |
|
}} |
1768 |
|
|
1769 |
|
/** |
1776 |
|
{ |
1777 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1778 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1779 |
< |
final FailingFunction r = new FailingFunction(); |
1779 |
> |
final FailingFunction r = new FailingFunction(m); |
1780 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1781 |
|
|
1782 |
|
f.complete(v1); |
1793 |
|
{ |
1794 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1795 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1796 |
< |
final FailingFunction r = new FailingFunction(); |
1796 |
> |
final FailingFunction r = new FailingFunction(m); |
1797 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1798 |
|
|
1799 |
|
g.complete(v2); |
1809 |
|
public void testApplyToEither_sourceCancelled1() { |
1810 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1811 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1812 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1813 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1814 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1815 |
|
{ |
1816 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1817 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1818 |
< |
final IncFunction r = new IncFunction(); |
2234 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2235 |
< |
|
2236 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2237 |
< |
checkCompletedWithWrappedCancellationException(h); |
2238 |
< |
g.complete(v1); |
2239 |
< |
|
2240 |
< |
checkCancelled(f); |
2241 |
< |
assertEquals(0, r.invocationCount); |
2242 |
< |
checkCompletedNormally(g, v1); |
2243 |
< |
checkCompletedWithWrappedCancellationException(h); |
2244 |
< |
}} |
1818 |
> |
final IncFunction r = new IncFunction(m); |
1819 |
|
|
1820 |
< |
public void testApplyToEither_sourceCancelled2() { |
2247 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2248 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2249 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2250 |
< |
{ |
2251 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2252 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2253 |
< |
final IncFunction r = new IncFunction(); |
1820 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1821 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1822 |
+ |
if (createIncomplete) { |
1823 |
+ |
checkIncomplete(h); |
1824 |
+ |
assertEquals(0, r.invocationCount); |
1825 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1826 |
+ |
} |
1827 |
|
|
2256 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1828 |
|
checkCompletedWithWrappedCancellationException(h); |
1829 |
< |
f.complete(v1); |
1829 |
> |
(!fFirst ? f : g).complete(v1); |
1830 |
|
|
2260 |
– |
checkCancelled(g); |
1831 |
|
assertEquals(0, r.invocationCount); |
1832 |
< |
checkCompletedNormally(f, v1); |
1832 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1833 |
> |
checkCancelled(fFirst ? f : g); |
1834 |
|
checkCompletedWithWrappedCancellationException(h); |
1835 |
|
}} |
1836 |
|
|
1837 |
< |
public void testApplyToEither_sourceCancelled3() { |
1837 |
> |
public void testApplyToEither_sourceCancelled2() { |
1838 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1839 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1840 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1841 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1842 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1843 |
|
{ |
1844 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1845 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1846 |
< |
final IncFunction r = new IncFunction(); |
1846 |
> |
final IncFunction r1 = new IncFunction(m); |
1847 |
> |
final IncFunction r2 = new IncFunction(m); |
1848 |
> |
final CFException ex = new CFException(); |
1849 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1850 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1851 |
|
|
1852 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1853 |
< |
f.complete(v1); |
1854 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1852 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1853 |
> |
if (fFirst) { |
1854 |
> |
f.complete(v1); |
1855 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1856 |
> |
} else { |
1857 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1858 |
> |
f.complete(v1); |
1859 |
> |
} |
1860 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1861 |
|
|
1862 |
|
// unspecified behavior |
2280 |
– |
Integer v; |
1863 |
|
try { |
1864 |
< |
assertEquals(inc(v1), h.join()); |
1865 |
< |
assertEquals(1, r.invocationCount); |
1864 |
> |
assertEquals(inc(v1), h1.join()); |
1865 |
> |
assertEquals(1, r1.invocationCount); |
1866 |
|
} catch (CompletionException ok) { |
1867 |
< |
checkCompletedWithWrappedCancellationException(h); |
1868 |
< |
assertEquals(0, r.invocationCount); |
1867 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1868 |
> |
assertEquals(0, r1.invocationCount); |
1869 |
|
} |
1870 |
|
|
2289 |
– |
checkCancelled(g); |
2290 |
– |
checkCompletedNormally(f, v1); |
2291 |
– |
}} |
2292 |
– |
|
2293 |
– |
public void testApplyToEither_sourceCancelled4() { |
2294 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2295 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2296 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2297 |
– |
{ |
2298 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2299 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2300 |
– |
final IncFunction r = new IncFunction(); |
2301 |
– |
|
2302 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2303 |
– |
g.complete(v1); |
2304 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2305 |
– |
|
2306 |
– |
// unspecified behavior |
2307 |
– |
Integer v; |
1871 |
|
try { |
1872 |
< |
assertEquals(inc(v1), h.join()); |
1873 |
< |
assertEquals(1, r.invocationCount); |
1872 |
> |
assertEquals(inc(v1), h2.join()); |
1873 |
> |
assertEquals(1, r2.invocationCount); |
1874 |
|
} catch (CompletionException ok) { |
1875 |
< |
checkCompletedWithWrappedCancellationException(h); |
1876 |
< |
assertEquals(0, r.invocationCount); |
1875 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1876 |
> |
assertEquals(0, r2.invocationCount); |
1877 |
|
} |
1878 |
|
|
1879 |
< |
checkCancelled(f); |
1880 |
< |
checkCompletedNormally(g, v1); |
1879 |
> |
checkCancelled(g); |
1880 |
> |
checkCompletedNormally(f, v1); |
1881 |
|
}} |
1882 |
|
|
1883 |
|
/** |
2056 |
|
{ |
2057 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2058 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2059 |
< |
final FailingConsumer r = new FailingConsumer(); |
2059 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2060 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2061 |
|
|
2062 |
|
f.complete(v1); |
2073 |
|
{ |
2074 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2075 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2076 |
< |
final FailingConsumer r = new FailingConsumer(); |
2076 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2077 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2078 |
|
|
2079 |
|
g.complete(v2); |
2193 |
|
{ |
2194 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2195 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2196 |
< |
final Noop r = new Noop(); |
2196 |
> |
final Noop r = new Noop(m); |
2197 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2198 |
|
|
2199 |
|
f.complete(v1); |
2214 |
|
{ |
2215 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2216 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2217 |
< |
final Noop r = new Noop(); |
2217 |
> |
final Noop r = new Noop(m); |
2218 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2219 |
|
|
2220 |
|
g.complete(v2); |
2235 |
|
{ |
2236 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2237 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2238 |
< |
final Noop r = new Noop(); |
2238 |
> |
final Noop r = new Noop(m); |
2239 |
|
|
2240 |
|
f.complete(v1); |
2241 |
|
g.complete(v2); |
2257 |
|
{ |
2258 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2259 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2260 |
< |
final Noop r = new Noop(); |
2260 |
> |
final Noop r = new Noop(m); |
2261 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2262 |
|
final CFException ex = new CFException(); |
2263 |
|
|
2277 |
|
{ |
2278 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2279 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2280 |
< |
final Noop r = new Noop(); |
2280 |
> |
final Noop r = new Noop(m); |
2281 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2282 |
|
final CFException ex = new CFException(); |
2283 |
|
|
2297 |
|
{ |
2298 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2299 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2300 |
< |
final Noop r = new Noop(); |
2300 |
> |
final Noop r = new Noop(m); |
2301 |
|
final CFException ex = new CFException(); |
2302 |
|
|
2303 |
|
g.completeExceptionally(ex); |
2324 |
|
{ |
2325 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2326 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2327 |
< |
final Noop r = new Noop(); |
2327 |
> |
final Noop r = new Noop(m); |
2328 |
|
final CFException ex = new CFException(); |
2329 |
|
|
2330 |
|
f.completeExceptionally(ex); |
2355 |
|
{ |
2356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2357 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2358 |
< |
final FailingRunnable r = new FailingRunnable(); |
2358 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2359 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2360 |
|
|
2361 |
|
f.complete(v1); |
2372 |
|
{ |
2373 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2374 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2375 |
< |
final FailingRunnable r = new FailingRunnable(); |
2375 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2376 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2377 |
|
|
2378 |
|
g.complete(v2); |
2392 |
|
{ |
2393 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2394 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2395 |
< |
final Noop r = new Noop(); |
2395 |
> |
final Noop r = new Noop(m); |
2396 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2397 |
|
|
2398 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2412 |
|
{ |
2413 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2414 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2415 |
< |
final Noop r = new Noop(); |
2415 |
> |
final Noop r = new Noop(m); |
2416 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2417 |
|
|
2418 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2432 |
|
{ |
2433 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2434 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2435 |
< |
final Noop r = new Noop(); |
2435 |
> |
final Noop r = new Noop(m); |
2436 |
|
|
2437 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2438 |
|
f.complete(v1); |
2459 |
|
{ |
2460 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2461 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2462 |
< |
final Noop r = new Noop(); |
2462 |
> |
final Noop r = new Noop(m); |
2463 |
|
|
2464 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2465 |
|
g.complete(v1); |
2488 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2489 |
|
{ |
2490 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2491 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2491 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2492 |
|
if (!createIncomplete) f.complete(v1); |
2493 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2493 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2494 |
|
if (createIncomplete) f.complete(v1); |
2495 |
|
|
2496 |
|
checkCompletedNormally(g, inc(v1)); |
2507 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2508 |
|
{ |
2509 |
|
final CFException ex = new CFException(); |
2510 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2510 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2511 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2512 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
2513 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2513 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2514 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2515 |
|
|
2516 |
|
checkCompletedWithWrappedCFException(g, ex); |
2528 |
|
{ |
2529 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2530 |
|
final FailingCompletableFutureFunction r |
2531 |
< |
= new FailingCompletableFutureFunction(); |
2531 |
> |
= new FailingCompletableFutureFunction(m); |
2532 |
|
if (!createIncomplete) f.complete(v1); |
2533 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2533 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2534 |
|
if (createIncomplete) f.complete(v1); |
2535 |
|
|
2536 |
|
checkCompletedWithWrappedCFException(g); |
2546 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2547 |
|
{ |
2548 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2549 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2549 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2550 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2551 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2551 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2552 |
|
if (createIncomplete) { |
2553 |
|
checkIncomplete(g); |
2554 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2720 |
|
|
2721 |
|
() -> f.thenCompose(null), |
2722 |
|
() -> f.thenComposeAsync(null), |
2723 |
< |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
2723 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null), |
2724 |
|
() -> f.thenComposeAsync(null, exec), |
2725 |
|
|
2726 |
|
() -> f.exceptionally(null), |