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 |
|
|
503 |
|
public void checkExecutionMode() { |
504 |
|
assertNull(ForkJoinTask.getPool()); |
505 |
|
} |
506 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
507 |
+ |
throw new UnsupportedOperationException(); |
508 |
+ |
} |
509 |
|
public <T> CompletableFuture<Void> thenRun |
510 |
|
(CompletableFuture<T> f, Runnable a) { |
511 |
|
return f.thenRun(a); |
574 |
|
assertSame(ForkJoinPool.commonPool(), |
575 |
|
ForkJoinTask.getPool()); |
576 |
|
} |
577 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
578 |
+ |
return CompletableFuture.runAsync(a); |
579 |
+ |
} |
580 |
|
public <T> CompletableFuture<Void> thenRun |
581 |
|
(CompletableFuture<T> f, Runnable a) { |
582 |
|
return f.thenRunAsync(a); |
642 |
|
|
643 |
|
EXECUTOR { |
644 |
|
public void checkExecutionMode() { |
645 |
< |
//TODO |
645 |
> |
assertTrue(ThreadExecutor.startedCurrentThread()); |
646 |
> |
} |
647 |
> |
public CompletableFuture<Void> runAsync(Runnable a) { |
648 |
> |
return CompletableFuture.runAsync(a, new ThreadExecutor()); |
649 |
|
} |
650 |
|
public <T> CompletableFuture<Void> thenRun |
651 |
|
(CompletableFuture<T> f, Runnable a) { |
711 |
|
}; |
712 |
|
|
713 |
|
public abstract void checkExecutionMode(); |
714 |
+ |
public abstract CompletableFuture<Void> runAsync(Runnable a); |
715 |
|
public abstract <T> CompletableFuture<Void> thenRun |
716 |
|
(CompletableFuture<T> f, Runnable a); |
717 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
790 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
791 |
|
final CompletableFuture<Integer> g = f.exceptionally |
792 |
|
((Throwable t) -> { |
793 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
794 |
|
threadAssertSame(t, ex); |
795 |
|
a.getAndIncrement(); |
796 |
|
return v1; |
812 |
|
if (!createIncomplete) f.completeExceptionally(ex1); |
813 |
|
final CompletableFuture<Integer> g = f.exceptionally |
814 |
|
((Throwable t) -> { |
815 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
816 |
|
threadAssertSame(t, ex1); |
817 |
|
a.getAndIncrement(); |
818 |
|
throw ex2; |
838 |
|
final CompletableFuture<Integer> g = m.handle |
839 |
|
(f, |
840 |
|
(Integer x, Throwable t) -> { |
841 |
+ |
m.checkExecutionMode(); |
842 |
|
threadAssertSame(x, v1); |
843 |
|
threadAssertNull(t); |
844 |
|
a.getAndIncrement(); |
867 |
|
final CompletableFuture<Integer> g = m.handle |
868 |
|
(f, |
869 |
|
(Integer x, Throwable t) -> { |
870 |
+ |
m.checkExecutionMode(); |
871 |
|
threadAssertNull(x); |
872 |
|
threadAssertSame(t, ex); |
873 |
|
a.getAndIncrement(); |
896 |
|
final CompletableFuture<Integer> g = m.handle |
897 |
|
(f, |
898 |
|
(Integer x, Throwable t) -> { |
899 |
+ |
m.checkExecutionMode(); |
900 |
|
threadAssertNull(x); |
901 |
|
threadAssertTrue(t instanceof CancellationException); |
902 |
|
a.getAndIncrement(); |
924 |
|
final CompletableFuture<Integer> g = m.handle |
925 |
|
(f, |
926 |
|
(Integer x, Throwable t) -> { |
927 |
+ |
m.checkExecutionMode(); |
928 |
|
threadAssertNull(x); |
929 |
|
threadAssertSame(ex1, t); |
930 |
|
a.getAndIncrement(); |
949 |
|
final CompletableFuture<Integer> g = m.handle |
950 |
|
(f, |
951 |
|
(Integer x, Throwable t) -> { |
952 |
+ |
m.checkExecutionMode(); |
953 |
|
threadAssertSame(x, v1); |
954 |
|
threadAssertNull(t); |
955 |
|
a.getAndIncrement(); |
965 |
|
/** |
966 |
|
* runAsync completes after running Runnable |
967 |
|
*/ |
968 |
< |
public void testRunAsync() { |
969 |
< |
Noop r = new Noop(); |
970 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
968 |
> |
public void testRunAsync_normalCompletion() { |
969 |
> |
ExecutionMode[] executionModes = { |
970 |
> |
ExecutionMode.ASYNC, |
971 |
> |
ExecutionMode.EXECUTOR, |
972 |
> |
}; |
973 |
> |
for (ExecutionMode m : executionModes) |
974 |
> |
{ |
975 |
> |
final Noop r = new Noop(m); |
976 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
977 |
|
assertNull(f.join()); |
915 |
– |
assertEquals(1, r.invocationCount); |
978 |
|
checkCompletedNormally(f, null); |
917 |
– |
} |
918 |
– |
|
919 |
– |
/** |
920 |
– |
* runAsync with executor completes after running Runnable |
921 |
– |
*/ |
922 |
– |
public void testRunAsync2() { |
923 |
– |
Noop r = new Noop(); |
924 |
– |
ThreadExecutor exec = new ThreadExecutor(); |
925 |
– |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
926 |
– |
assertNull(f.join()); |
979 |
|
assertEquals(1, r.invocationCount); |
980 |
< |
checkCompletedNormally(f, null); |
929 |
< |
assertEquals(1, exec.count.get()); |
930 |
< |
} |
980 |
> |
}} |
981 |
|
|
982 |
|
/** |
983 |
|
* failing runAsync completes exceptionally after running Runnable |
984 |
|
*/ |
985 |
< |
public void testRunAsync3() { |
986 |
< |
FailingRunnable r = new FailingRunnable(); |
987 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
985 |
> |
public void testRunAsync_exceptionalCompletion() { |
986 |
> |
ExecutionMode[] executionModes = { |
987 |
> |
ExecutionMode.ASYNC, |
988 |
> |
ExecutionMode.EXECUTOR, |
989 |
> |
}; |
990 |
> |
for (ExecutionMode m : executionModes) |
991 |
> |
{ |
992 |
> |
final FailingRunnable r = new FailingRunnable(m); |
993 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
994 |
|
checkCompletedWithWrappedCFException(f); |
995 |
|
assertEquals(1, r.invocationCount); |
996 |
< |
} |
996 |
> |
}} |
997 |
|
|
998 |
|
/** |
999 |
|
* supplyAsync completes with result of supplier |
1019 |
|
* Failing supplyAsync completes exceptionally |
1020 |
|
*/ |
1021 |
|
public void testSupplyAsync3() { |
1022 |
< |
FailingSupplier r = new FailingSupplier(); |
1022 |
> |
FailingSupplier r = new FailingSupplier(ExecutionMode.ASYNC); |
1023 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r); |
1024 |
|
checkCompletedWithWrappedCFException(f); |
1025 |
|
assertEquals(1, r.invocationCount); |
1036 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1037 |
|
{ |
1038 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1039 |
< |
final Noop r = new Noop(); |
1039 |
> |
final Noop r = new Noop(m); |
1040 |
|
if (!createIncomplete) f.complete(v1); |
1041 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1042 |
< |
if (createIncomplete) f.complete(v1); |
1042 |
> |
if (createIncomplete) { |
1043 |
> |
checkIncomplete(g); |
1044 |
> |
f.complete(v1); |
1045 |
> |
} |
1046 |
|
|
1047 |
|
checkCompletedNormally(g, null); |
1048 |
|
checkCompletedNormally(f, v1); |
1059 |
|
{ |
1060 |
|
final CFException ex = new CFException(); |
1061 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1062 |
< |
final Noop r = new Noop(); |
1062 |
> |
final Noop r = new Noop(m); |
1063 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1064 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1065 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1065 |
> |
if (createIncomplete) { |
1066 |
> |
checkIncomplete(g); |
1067 |
> |
f.completeExceptionally(ex); |
1068 |
> |
} |
1069 |
|
|
1070 |
|
checkCompletedWithWrappedCFException(g, ex); |
1071 |
|
checkCompletedWithWrappedCFException(f, ex); |
1081 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1082 |
|
{ |
1083 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1084 |
< |
final Noop r = new Noop(); |
1084 |
> |
final Noop r = new Noop(m); |
1085 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1086 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1087 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1086 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1087 |
> |
if (createIncomplete) { |
1088 |
> |
checkIncomplete(g); |
1089 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1090 |
> |
} |
1091 |
|
|
1092 |
|
checkCompletedWithWrappedCancellationException(g); |
1093 |
|
checkCancelled(f); |
1103 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1104 |
|
{ |
1105 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1106 |
< |
final FailingRunnable r = new FailingRunnable(); |
1106 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1107 |
|
if (!createIncomplete) f.complete(v1); |
1108 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1109 |
< |
if (createIncomplete) f.complete(v1); |
1108 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1109 |
> |
if (createIncomplete) { |
1110 |
> |
checkIncomplete(g); |
1111 |
> |
f.complete(v1); |
1112 |
> |
} |
1113 |
|
|
1114 |
|
checkCompletedWithWrappedCFException(g); |
1115 |
|
checkCompletedNormally(f, v1); |
1124 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1125 |
|
{ |
1126 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1127 |
< |
final IncFunction r = new IncFunction(); |
1127 |
> |
final IncFunction r = new IncFunction(m); |
1128 |
|
if (!createIncomplete) f.complete(v1); |
1129 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1130 |
|
if (createIncomplete) { |
1147 |
|
{ |
1148 |
|
final CFException ex = new CFException(); |
1149 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1150 |
< |
final IncFunction r = new IncFunction(); |
1150 |
> |
final IncFunction r = new IncFunction(m); |
1151 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1152 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1153 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1153 |
> |
if (createIncomplete) { |
1154 |
> |
checkIncomplete(g); |
1155 |
> |
f.completeExceptionally(ex); |
1156 |
> |
} |
1157 |
|
|
1158 |
|
checkCompletedWithWrappedCFException(g, ex); |
1159 |
|
checkCompletedWithWrappedCFException(f, ex); |
1169 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1170 |
|
{ |
1171 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1172 |
< |
final IncFunction r = new IncFunction(); |
1172 |
> |
final IncFunction r = new IncFunction(m); |
1173 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1174 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1175 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1174 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1175 |
> |
if (createIncomplete) { |
1176 |
> |
checkIncomplete(g); |
1177 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1178 |
> |
} |
1179 |
|
|
1180 |
|
checkCompletedWithWrappedCancellationException(g); |
1181 |
|
checkCancelled(f); |
1191 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1192 |
|
{ |
1193 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1194 |
< |
final FailingFunction r = new FailingFunction(); |
1194 |
> |
final FailingFunction r = new FailingFunction(m); |
1195 |
|
if (!createIncomplete) f.complete(v1); |
1196 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1197 |
< |
if (createIncomplete) f.complete(v1); |
1196 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1197 |
> |
if (createIncomplete) { |
1198 |
> |
checkIncomplete(g); |
1199 |
> |
f.complete(v1); |
1200 |
> |
} |
1201 |
|
|
1202 |
|
checkCompletedWithWrappedCFException(g); |
1203 |
|
checkCompletedNormally(f, v1); |
1215 |
|
final IncAction r = new IncAction(); |
1216 |
|
if (!createIncomplete) f.complete(v1); |
1217 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1218 |
< |
if (createIncomplete) f.complete(v1); |
1218 |
> |
if (createIncomplete) { |
1219 |
> |
checkIncomplete(g); |
1220 |
> |
f.complete(v1); |
1221 |
> |
} |
1222 |
|
|
1223 |
|
checkCompletedNormally(g, null); |
1224 |
|
checkCompletedNormally(f, v1); |
1239 |
|
final IncAction r = new IncAction(); |
1240 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1241 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1242 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
1242 |
> |
if (createIncomplete) { |
1243 |
> |
checkIncomplete(g); |
1244 |
> |
f.completeExceptionally(ex); |
1245 |
> |
} |
1246 |
|
|
1247 |
|
checkCompletedWithWrappedCFException(g, ex); |
1248 |
|
checkCompletedWithWrappedCFException(f, ex); |
1258 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1259 |
|
{ |
1260 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1261 |
< |
final FailingConsumer r = new FailingConsumer(); |
1261 |
> |
final FailingConsumer r = new FailingConsumer(m); |
1262 |
|
if (!createIncomplete) f.complete(v1); |
1263 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1264 |
< |
if (createIncomplete) f.complete(v1); |
1263 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1264 |
> |
if (createIncomplete) { |
1265 |
> |
checkIncomplete(g); |
1266 |
> |
f.complete(v1); |
1267 |
> |
} |
1268 |
|
|
1269 |
|
checkCompletedWithWrappedCFException(g); |
1270 |
|
checkCompletedNormally(f, v1); |
1281 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1282 |
|
final IncAction r = new IncAction(); |
1283 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1284 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1284 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1285 |
|
if (createIncomplete) { |
1286 |
|
checkIncomplete(g); |
1287 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1296 |
|
* thenCombine result completes normally after normal completion |
1297 |
|
* of sources |
1298 |
|
*/ |
1299 |
< |
public void testThenCombine_normalCompletion1() { |
1299 |
> |
public void testThenCombine_normalCompletion() { |
1300 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1301 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
1302 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1216 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1303 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1304 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1305 |
|
{ |
1306 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1307 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1308 |
< |
final SubtractFunction r = new SubtractFunction(); |
1223 |
< |
CompletableFuture<Integer> h = null; |
1224 |
< |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1308 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1309 |
|
|
1310 |
< |
if (fFirst) |
1311 |
< |
f.complete(v1); |
1312 |
< |
else |
1313 |
< |
g.complete(v2); |
1314 |
< |
if (createIncomplete) checkIncomplete(h); |
1315 |
< |
assertEquals(0, r.invocationCount); |
1316 |
< |
if (!fFirst) |
1317 |
< |
f.complete(v1); |
1318 |
< |
else |
1235 |
< |
g.complete(v2); |
1236 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1310 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1311 |
> |
if (!createIncomplete) |
1312 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1313 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1314 |
> |
if (createIncomplete) { |
1315 |
> |
checkIncomplete(h); |
1316 |
> |
assertEquals(0, r.invocationCount); |
1317 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1318 |
> |
} |
1319 |
|
|
1320 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1321 |
|
checkCompletedNormally(f, v1); |
1327 |
|
* thenCombine result completes exceptionally after exceptional |
1328 |
|
* completion of either source |
1329 |
|
*/ |
1330 |
< |
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() { |
1330 |
> |
public void testThenCombine_exceptionalCompletion() { |
1331 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1332 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1333 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1334 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1335 |
|
{ |
1336 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1337 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1313 |
– |
final SubtractFunction r = new SubtractFunction(); |
1338 |
|
final CFException ex = new CFException(); |
1339 |
+ |
final SubtractFunction r = new SubtractFunction(m); |
1340 |
|
|
1341 |
< |
f.completeExceptionally(ex); |
1342 |
< |
g.complete(v1); |
1341 |
> |
(fFirst ? f : g).complete(v1); |
1342 |
> |
if (!createIncomplete) |
1343 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1344 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1345 |
+ |
if (createIncomplete) { |
1346 |
+ |
checkIncomplete(h); |
1347 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1348 |
+ |
} |
1349 |
|
|
1350 |
|
checkCompletedWithWrappedCFException(h, ex); |
1321 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1351 |
|
assertEquals(0, r.invocationCount); |
1352 |
< |
checkCompletedNormally(g, v1); |
1352 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1353 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1354 |
|
}} |
1355 |
|
|
1356 |
|
/** |
1357 |
|
* thenCombine result completes exceptionally if action does |
1358 |
|
*/ |
1359 |
< |
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() { |
1359 |
> |
public void testThenCombine_actionFailed() { |
1360 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1361 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1362 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1363 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1364 |
|
{ |
1365 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1366 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1367 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1367 |
> |
final FailingBiFunction r = new FailingBiFunction(m); |
1368 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1369 |
|
|
1370 |
< |
g.complete(v2); |
1371 |
< |
checkIncomplete(h); |
1372 |
< |
f.complete(v1); |
1370 |
> |
if (fFirst) { |
1371 |
> |
f.complete(v1); |
1372 |
> |
g.complete(v2); |
1373 |
> |
} else { |
1374 |
> |
g.complete(v2); |
1375 |
> |
f.complete(v1); |
1376 |
> |
} |
1377 |
|
|
1378 |
|
checkCompletedWithWrappedCFException(h); |
1379 |
|
checkCompletedNormally(f, v1); |
1383 |
|
/** |
1384 |
|
* thenCombine result completes exceptionally if either source cancelled |
1385 |
|
*/ |
1386 |
< |
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() { |
1386 |
> |
public void testThenCombine_sourceCancelled() { |
1387 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1388 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1389 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1390 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1391 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1392 |
|
{ |
1393 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1394 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1395 |
< |
final SubtractFunction r = new SubtractFunction(); |
1395 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1396 |
|
|
1397 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1398 |
< |
g.complete(v1); |
1397 |
> |
(fFirst ? f : g).complete(v1); |
1398 |
> |
if (!createIncomplete) |
1399 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1400 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1401 |
+ |
if (createIncomplete) { |
1402 |
+ |
checkIncomplete(h); |
1403 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1404 |
+ |
} |
1405 |
|
|
1406 |
|
checkCompletedWithWrappedCancellationException(h); |
1407 |
< |
checkCancelled(f); |
1407 |
> |
checkCancelled(!fFirst ? f : g); |
1408 |
|
assertEquals(0, r.invocationCount); |
1409 |
< |
checkCompletedNormally(g, v1); |
1409 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1410 |
|
}} |
1411 |
|
|
1412 |
|
/** |
1413 |
|
* thenAcceptBoth result completes normally after normal |
1414 |
|
* completion of sources |
1415 |
|
*/ |
1416 |
< |
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() { |
1416 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1417 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1418 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1419 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1420 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1421 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1422 |
|
{ |
1423 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1424 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1425 |
< |
final SubtractAction r = new SubtractAction(); |
1425 |
> |
final SubtractAction r = new SubtractAction(m); |
1426 |
|
|
1427 |
< |
f.complete(v1); |
1428 |
< |
g.complete(v2); |
1427 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1428 |
> |
if (!createIncomplete) |
1429 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1430 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1431 |
+ |
if (createIncomplete) { |
1432 |
+ |
checkIncomplete(h); |
1433 |
+ |
assertEquals(0, r.invocationCount); |
1434 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1435 |
+ |
} |
1436 |
|
|
1437 |
|
checkCompletedNormally(h, null); |
1438 |
|
assertEquals(subtract(v1, v2), r.value); |
1444 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1445 |
|
* completion of either source |
1446 |
|
*/ |
1447 |
< |
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() { |
1447 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1448 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1449 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1450 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1451 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1452 |
|
{ |
1453 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1454 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1601 |
– |
final SubtractAction r = new SubtractAction(); |
1455 |
|
final CFException ex = new CFException(); |
1456 |
+ |
final SubtractAction r = new SubtractAction(m); |
1457 |
|
|
1458 |
< |
f.completeExceptionally(ex); |
1459 |
< |
g.complete(v1); |
1458 |
> |
(fFirst ? f : g).complete(v1); |
1459 |
> |
if (!createIncomplete) |
1460 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1461 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1462 |
+ |
if (createIncomplete) { |
1463 |
+ |
checkIncomplete(h); |
1464 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1465 |
+ |
} |
1466 |
|
|
1467 |
|
checkCompletedWithWrappedCFException(h, ex); |
1609 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1468 |
|
assertEquals(0, r.invocationCount); |
1469 |
< |
checkCompletedNormally(g, v1); |
1469 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1470 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1471 |
|
}} |
1472 |
|
|
1473 |
|
/** |
1474 |
|
* thenAcceptBoth result completes exceptionally if action does |
1475 |
|
*/ |
1476 |
< |
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() { |
1476 |
> |
public void testThenAcceptBoth_actionFailed() { |
1477 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1478 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1479 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1480 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1481 |
|
{ |
1482 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1483 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1484 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1484 |
> |
final FailingBiConsumer r = new FailingBiConsumer(m); |
1485 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1486 |
|
|
1487 |
< |
g.complete(v2); |
1488 |
< |
checkIncomplete(h); |
1489 |
< |
f.complete(v1); |
1487 |
> |
if (fFirst) { |
1488 |
> |
f.complete(v1); |
1489 |
> |
g.complete(v2); |
1490 |
> |
} else { |
1491 |
> |
g.complete(v2); |
1492 |
> |
f.complete(v1); |
1493 |
> |
} |
1494 |
|
|
1495 |
|
checkCompletedWithWrappedCFException(h); |
1496 |
|
checkCompletedNormally(f, v1); |
1500 |
|
/** |
1501 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1502 |
|
*/ |
1503 |
< |
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() { |
1503 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1504 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1505 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1506 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1507 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1508 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1509 |
|
{ |
1510 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1511 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1512 |
< |
final SubtractAction r = new SubtractAction(); |
1512 |
> |
final SubtractAction r = new SubtractAction(m); |
1513 |
|
|
1514 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1515 |
< |
g.complete(v1); |
1514 |
> |
(fFirst ? f : g).complete(v1); |
1515 |
> |
if (!createIncomplete) |
1516 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1517 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1518 |
+ |
if (createIncomplete) { |
1519 |
+ |
checkIncomplete(h); |
1520 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1521 |
+ |
} |
1522 |
|
|
1523 |
|
checkCompletedWithWrappedCancellationException(h); |
1524 |
< |
checkCancelled(f); |
1524 |
> |
checkCancelled(!fFirst ? f : g); |
1525 |
|
assertEquals(0, r.invocationCount); |
1526 |
< |
checkCompletedNormally(g, v1); |
1526 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1527 |
|
}} |
1528 |
|
|
1529 |
|
/** |
1530 |
|
* runAfterBoth result completes normally after normal |
1531 |
|
* completion of sources |
1532 |
|
*/ |
1533 |
< |
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() { |
1533 |
> |
public void testRunAfterBoth_normalCompletion() { |
1534 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1535 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1536 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1537 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1538 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1539 |
|
{ |
1540 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1541 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1542 |
< |
final Noop r = new Noop(); |
1542 |
> |
final Noop r = new Noop(m); |
1543 |
|
|
1544 |
< |
f.complete(v1); |
1545 |
< |
g.complete(v2); |
1544 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1545 |
> |
if (!createIncomplete) |
1546 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1547 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1548 |
+ |
if (createIncomplete) { |
1549 |
+ |
checkIncomplete(h); |
1550 |
+ |
assertEquals(0, r.invocationCount); |
1551 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1552 |
+ |
} |
1553 |
|
|
1554 |
|
checkCompletedNormally(h, null); |
1555 |
|
assertEquals(1, r.invocationCount); |
1561 |
|
* runAfterBoth result completes exceptionally after exceptional |
1562 |
|
* completion of either source |
1563 |
|
*/ |
1564 |
< |
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() { |
1564 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1565 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1566 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1567 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1568 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1569 |
|
{ |
1570 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1571 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1889 |
– |
final Noop r = new Noop(); |
1572 |
|
final CFException ex = new CFException(); |
1573 |
+ |
final Noop r = new Noop(m); |
1574 |
|
|
1575 |
< |
f.completeExceptionally(ex); |
1576 |
< |
g.complete(v1); |
1575 |
> |
(fFirst ? f : g).complete(v1); |
1576 |
> |
if (!createIncomplete) |
1577 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1578 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1579 |
+ |
if (createIncomplete) { |
1580 |
+ |
checkIncomplete(h); |
1581 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1582 |
+ |
} |
1583 |
|
|
1584 |
|
checkCompletedWithWrappedCFException(h, ex); |
1897 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1585 |
|
assertEquals(0, r.invocationCount); |
1586 |
< |
checkCompletedNormally(g, v1); |
1586 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1587 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1588 |
|
}} |
1589 |
|
|
1590 |
|
/** |
1591 |
|
* runAfterBoth result completes exceptionally if action does |
1592 |
|
*/ |
1593 |
< |
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() { |
1593 |
> |
public void testRunAfterBoth_actionFailed() { |
1594 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1595 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1596 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1597 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1598 |
|
{ |
1599 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1600 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1601 |
< |
final FailingRunnable r = new FailingRunnable(); |
1932 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1601 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1602 |
|
|
1603 |
< |
g.complete(v2); |
1604 |
< |
checkIncomplete(h); |
1605 |
< |
f.complete(v1); |
1603 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1604 |
> |
if (fFirst) { |
1605 |
> |
f.complete(v1); |
1606 |
> |
g.complete(v2); |
1607 |
> |
} else { |
1608 |
> |
g.complete(v2); |
1609 |
> |
f.complete(v1); |
1610 |
> |
} |
1611 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1612 |
|
|
1613 |
< |
checkCompletedWithWrappedCFException(h); |
1613 |
> |
checkCompletedWithWrappedCFException(h1); |
1614 |
> |
checkCompletedWithWrappedCFException(h2); |
1615 |
|
checkCompletedNormally(f, v1); |
1616 |
|
checkCompletedNormally(g, v2); |
1617 |
|
}} |
1619 |
|
/** |
1620 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1621 |
|
*/ |
1622 |
< |
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() { |
1622 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1623 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1624 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1625 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1626 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1627 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1628 |
|
{ |
1629 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1630 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1631 |
< |
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 |
< |
}} |
1631 |
> |
final Noop r = new Noop(m); |
1632 |
|
|
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(); |
1633 |
|
|
1634 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1635 |
< |
g.complete(v1); |
1634 |
> |
(fFirst ? f : g).complete(v1); |
1635 |
> |
if (!createIncomplete) |
1636 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1637 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1638 |
+ |
if (createIncomplete) { |
1639 |
+ |
checkIncomplete(h); |
1640 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1641 |
+ |
} |
1642 |
|
|
1643 |
|
checkCompletedWithWrappedCancellationException(h); |
1644 |
< |
checkCancelled(f); |
1644 |
> |
checkCancelled(!fFirst ? f : g); |
1645 |
|
assertEquals(0, r.invocationCount); |
1646 |
< |
checkCompletedNormally(g, v1); |
1646 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1647 |
|
}} |
1648 |
|
|
1649 |
|
/** |
1650 |
|
* applyToEither result completes normally after normal completion |
1651 |
|
* of either source |
1652 |
|
*/ |
1653 |
< |
public void testApplyToEither_normalCompletion1() { |
1653 |
> |
public void testApplyToEither_normalCompletion() { |
1654 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1655 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1656 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1657 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1658 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1659 |
|
{ |
1660 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1661 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1662 |
< |
final IncFunction r = new IncFunction(); |
2036 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1662 |
> |
final IncFunction r = new IncFunction(m); |
1663 |
|
|
1664 |
< |
f.complete(v1); |
1665 |
< |
checkCompletedNormally(h, inc(v1)); |
1666 |
< |
g.complete(v2); |
1664 |
> |
if (!createIncomplete) |
1665 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1666 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1667 |
> |
if (createIncomplete) { |
1668 |
> |
checkIncomplete(h); |
1669 |
> |
assertEquals(0, r.invocationCount); |
1670 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1671 |
> |
} |
1672 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1673 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1674 |
|
|
1675 |
|
checkCompletedNormally(f, v1); |
1676 |
|
checkCompletedNormally(g, v2); |
1677 |
< |
checkCompletedNormally(h, inc(v1)); |
1677 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1678 |
|
}} |
1679 |
|
|
1680 |
< |
public void testApplyToEither_normalCompletion2() { |
1680 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1681 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1682 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1683 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1684 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1685 |
|
{ |
1686 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1687 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1688 |
< |
final IncFunction r = new IncFunction(); |
2055 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1688 |
> |
final IncFunction r = new IncFunction(m); |
1689 |
|
|
1690 |
< |
g.complete(v2); |
1691 |
< |
checkCompletedNormally(h, inc(v2)); |
1692 |
< |
f.complete(v1); |
1693 |
< |
|
1694 |
< |
checkCompletedNormally(f, v1); |
1695 |
< |
checkCompletedNormally(g, v2); |
1696 |
< |
checkCompletedNormally(h, inc(v2)); |
2064 |
< |
}} |
2065 |
< |
|
2066 |
< |
public void testApplyToEither_normalCompletion3() { |
2067 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2068 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2069 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2070 |
< |
{ |
2071 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2072 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2073 |
< |
final IncFunction r = new IncFunction(); |
1690 |
> |
if (fFirst) { |
1691 |
> |
f.complete(v1); |
1692 |
> |
g.complete(v2); |
1693 |
> |
} else { |
1694 |
> |
g.complete(v2); |
1695 |
> |
f.complete(v1); |
1696 |
> |
} |
1697 |
|
|
2075 |
– |
f.complete(v1); |
2076 |
– |
g.complete(v2); |
1698 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1699 |
|
|
1700 |
|
checkCompletedNormally(f, v1); |
1712 |
|
*/ |
1713 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1714 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1715 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1716 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1717 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1718 |
|
{ |
1719 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1720 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2098 |
– |
final IncFunction r = new IncFunction(); |
2099 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1721 |
|
final CFException ex = new CFException(); |
1722 |
+ |
final IncFunction r = new IncFunction(m); |
1723 |
|
|
1724 |
< |
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(); |
1724 |
> |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1725 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1726 |
< |
final CFException ex = new CFException(); |
1726 |
> |
if (createIncomplete) { |
1727 |
> |
checkIncomplete(h); |
1728 |
> |
assertEquals(0, r.invocationCount); |
1729 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1730 |
> |
} |
1731 |
|
|
2122 |
– |
g.completeExceptionally(ex); |
1732 |
|
checkCompletedWithWrappedCFException(h, ex); |
1733 |
< |
f.complete(v1); |
1733 |
> |
(!fFirst ? f : g).complete(v1); |
1734 |
|
|
1735 |
|
assertEquals(0, r.invocationCount); |
1736 |
< |
checkCompletedNormally(f, v1); |
1737 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1736 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1737 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1738 |
|
checkCompletedWithWrappedCFException(h, ex); |
1739 |
|
}} |
1740 |
|
|
1741 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1741 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1742 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1743 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1744 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1745 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1746 |
|
{ |
1747 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1748 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1749 |
< |
final IncFunction r = new IncFunction(); |
1749 |
> |
final IncFunction r1 = new IncFunction(m); |
1750 |
> |
final IncFunction r2 = new IncFunction(m); |
1751 |
|
final CFException ex = new CFException(); |
1752 |
< |
|
1753 |
< |
g.completeExceptionally(ex); |
1754 |
< |
f.complete(v1); |
1755 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1752 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1753 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1754 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1755 |
> |
if (fFirst) { |
1756 |
> |
f.complete(v1); |
1757 |
> |
g.completeExceptionally(ex); |
1758 |
> |
} else { |
1759 |
> |
g.completeExceptionally(ex); |
1760 |
> |
f.complete(v1); |
1761 |
> |
} |
1762 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1763 |
|
|
1764 |
|
// unspecified behavior |
2146 |
– |
Integer v; |
1765 |
|
try { |
1766 |
< |
assertEquals(inc(v1), h.join()); |
1767 |
< |
assertEquals(1, r.invocationCount); |
1766 |
> |
assertEquals(inc(v1), h1.join()); |
1767 |
> |
assertEquals(1, r1.invocationCount); |
1768 |
|
} catch (CompletionException ok) { |
1769 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1770 |
< |
assertEquals(0, r.invocationCount); |
1769 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1770 |
> |
assertEquals(0, r1.invocationCount); |
1771 |
|
} |
1772 |
|
|
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; |
1773 |
|
try { |
1774 |
< |
assertEquals(inc(v1), h.join()); |
1775 |
< |
assertEquals(1, r.invocationCount); |
1774 |
> |
assertEquals(inc(v1), h2.join()); |
1775 |
> |
assertEquals(1, r2.invocationCount); |
1776 |
|
} catch (CompletionException ok) { |
1777 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1778 |
< |
assertEquals(0, r.invocationCount); |
1777 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1778 |
> |
assertEquals(0, r2.invocationCount); |
1779 |
|
} |
1780 |
|
|
1781 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1782 |
< |
checkCompletedNormally(g, v1); |
1781 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1782 |
> |
checkCompletedNormally(f, v1); |
1783 |
|
}} |
1784 |
|
|
1785 |
|
/** |
1792 |
|
{ |
1793 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1794 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1795 |
< |
final FailingFunction r = new FailingFunction(); |
1795 |
> |
final FailingFunction r = new FailingFunction(m); |
1796 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1797 |
|
|
1798 |
|
f.complete(v1); |
1809 |
|
{ |
1810 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1811 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1812 |
< |
final FailingFunction r = new FailingFunction(); |
1812 |
> |
final FailingFunction r = new FailingFunction(m); |
1813 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1814 |
|
|
1815 |
|
g.complete(v2); |
1825 |
|
public void testApplyToEither_sourceCancelled1() { |
1826 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1827 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1828 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1829 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1830 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1831 |
|
{ |
1832 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1833 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1834 |
< |
final IncFunction r = new IncFunction(); |
2234 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1834 |
> |
final IncFunction r = new IncFunction(m); |
1835 |
|
|
1836 |
< |
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 |
< |
}} |
2245 |
< |
|
2246 |
< |
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(); |
1836 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1837 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1838 |
+ |
if (createIncomplete) { |
1839 |
+ |
checkIncomplete(h); |
1840 |
+ |
assertEquals(0, r.invocationCount); |
1841 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1842 |
+ |
} |
1843 |
|
|
2256 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1844 |
|
checkCompletedWithWrappedCancellationException(h); |
1845 |
< |
f.complete(v1); |
1845 |
> |
(!fFirst ? f : g).complete(v1); |
1846 |
|
|
2260 |
– |
checkCancelled(g); |
1847 |
|
assertEquals(0, r.invocationCount); |
1848 |
< |
checkCompletedNormally(f, v1); |
1848 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1849 |
> |
checkCancelled(fFirst ? f : g); |
1850 |
|
checkCompletedWithWrappedCancellationException(h); |
1851 |
|
}} |
1852 |
|
|
1853 |
< |
public void testApplyToEither_sourceCancelled3() { |
1853 |
> |
public void testApplyToEither_sourceCancelled2() { |
1854 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1855 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1856 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1857 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1858 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1859 |
|
{ |
1860 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1861 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1862 |
< |
final IncFunction r = new IncFunction(); |
1862 |
> |
final IncFunction r1 = new IncFunction(m); |
1863 |
> |
final IncFunction r2 = new IncFunction(m); |
1864 |
> |
final CFException ex = new CFException(); |
1865 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1866 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1867 |
|
|
1868 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1869 |
< |
f.complete(v1); |
1870 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1868 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1869 |
> |
if (fFirst) { |
1870 |
> |
f.complete(v1); |
1871 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1872 |
> |
} else { |
1873 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1874 |
> |
f.complete(v1); |
1875 |
> |
} |
1876 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1877 |
|
|
1878 |
|
// unspecified behavior |
2280 |
– |
Integer v; |
1879 |
|
try { |
1880 |
< |
assertEquals(inc(v1), h.join()); |
1881 |
< |
assertEquals(1, r.invocationCount); |
1880 |
> |
assertEquals(inc(v1), h1.join()); |
1881 |
> |
assertEquals(1, r1.invocationCount); |
1882 |
|
} catch (CompletionException ok) { |
1883 |
< |
checkCompletedWithWrappedCancellationException(h); |
1884 |
< |
assertEquals(0, r.invocationCount); |
1883 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1884 |
> |
assertEquals(0, r1.invocationCount); |
1885 |
|
} |
1886 |
|
|
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; |
1887 |
|
try { |
1888 |
< |
assertEquals(inc(v1), h.join()); |
1889 |
< |
assertEquals(1, r.invocationCount); |
1888 |
> |
assertEquals(inc(v1), h2.join()); |
1889 |
> |
assertEquals(1, r2.invocationCount); |
1890 |
|
} catch (CompletionException ok) { |
1891 |
< |
checkCompletedWithWrappedCancellationException(h); |
1892 |
< |
assertEquals(0, r.invocationCount); |
1891 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1892 |
> |
assertEquals(0, r2.invocationCount); |
1893 |
|
} |
1894 |
|
|
1895 |
< |
checkCancelled(f); |
1896 |
< |
checkCompletedNormally(g, v1); |
1895 |
> |
checkCancelled(g); |
1896 |
> |
checkCompletedNormally(f, v1); |
1897 |
|
}} |
1898 |
|
|
1899 |
|
/** |
2072 |
|
{ |
2073 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2074 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2075 |
< |
final FailingConsumer r = new FailingConsumer(); |
2075 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2076 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2077 |
|
|
2078 |
|
f.complete(v1); |
2089 |
|
{ |
2090 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2091 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2092 |
< |
final FailingConsumer r = new FailingConsumer(); |
2092 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2093 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2094 |
|
|
2095 |
|
g.complete(v2); |
2209 |
|
{ |
2210 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2211 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2212 |
< |
final Noop r = new Noop(); |
2212 |
> |
final Noop r = new Noop(m); |
2213 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2214 |
|
|
2215 |
|
f.complete(v1); |
2230 |
|
{ |
2231 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2232 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2233 |
< |
final Noop r = new Noop(); |
2233 |
> |
final Noop r = new Noop(m); |
2234 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2235 |
|
|
2236 |
|
g.complete(v2); |
2251 |
|
{ |
2252 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2253 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2254 |
< |
final Noop r = new Noop(); |
2254 |
> |
final Noop r = new Noop(m); |
2255 |
|
|
2256 |
|
f.complete(v1); |
2257 |
|
g.complete(v2); |
2273 |
|
{ |
2274 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2275 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2276 |
< |
final Noop r = new Noop(); |
2276 |
> |
final Noop r = new Noop(m); |
2277 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2278 |
|
final CFException ex = new CFException(); |
2279 |
|
|
2293 |
|
{ |
2294 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2295 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2296 |
< |
final Noop r = new Noop(); |
2296 |
> |
final Noop r = new Noop(m); |
2297 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2298 |
|
final CFException ex = new CFException(); |
2299 |
|
|
2313 |
|
{ |
2314 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2315 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2316 |
< |
final Noop r = new Noop(); |
2316 |
> |
final Noop r = new Noop(m); |
2317 |
|
final CFException ex = new CFException(); |
2318 |
|
|
2319 |
|
g.completeExceptionally(ex); |
2340 |
|
{ |
2341 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2342 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2343 |
< |
final Noop r = new Noop(); |
2343 |
> |
final Noop r = new Noop(m); |
2344 |
|
final CFException ex = new CFException(); |
2345 |
|
|
2346 |
|
f.completeExceptionally(ex); |
2371 |
|
{ |
2372 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2373 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2374 |
< |
final FailingRunnable r = new FailingRunnable(); |
2374 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2375 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2376 |
|
|
2377 |
|
f.complete(v1); |
2388 |
|
{ |
2389 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2390 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2391 |
< |
final FailingRunnable r = new FailingRunnable(); |
2391 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2392 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2393 |
|
|
2394 |
|
g.complete(v2); |
2408 |
|
{ |
2409 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2410 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2411 |
< |
final Noop r = new Noop(); |
2411 |
> |
final Noop r = new Noop(m); |
2412 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2413 |
|
|
2414 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2428 |
|
{ |
2429 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2430 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2431 |
< |
final Noop r = new Noop(); |
2431 |
> |
final Noop r = new Noop(m); |
2432 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2433 |
|
|
2434 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2448 |
|
{ |
2449 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2450 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2451 |
< |
final Noop r = new Noop(); |
2451 |
> |
final Noop r = new Noop(m); |
2452 |
|
|
2453 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2454 |
|
f.complete(v1); |
2475 |
|
{ |
2476 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2477 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2478 |
< |
final Noop r = new Noop(); |
2478 |
> |
final Noop r = new Noop(m); |
2479 |
|
|
2480 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2481 |
|
g.complete(v1); |
2504 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2505 |
|
{ |
2506 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2507 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2507 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2508 |
|
if (!createIncomplete) f.complete(v1); |
2509 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2509 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2510 |
|
if (createIncomplete) f.complete(v1); |
2511 |
|
|
2512 |
|
checkCompletedNormally(g, inc(v1)); |
2523 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2524 |
|
{ |
2525 |
|
final CFException ex = new CFException(); |
2526 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2526 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2527 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2528 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
2529 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2529 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2530 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2531 |
|
|
2532 |
|
checkCompletedWithWrappedCFException(g, ex); |
2544 |
|
{ |
2545 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2546 |
|
final FailingCompletableFutureFunction r |
2547 |
< |
= new FailingCompletableFutureFunction(); |
2547 |
> |
= new FailingCompletableFutureFunction(m); |
2548 |
|
if (!createIncomplete) f.complete(v1); |
2549 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2549 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2550 |
|
if (createIncomplete) f.complete(v1); |
2551 |
|
|
2552 |
|
checkCompletedWithWrappedCFException(g); |
2562 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2563 |
|
{ |
2564 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2565 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2565 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2566 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2567 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2567 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2568 |
|
if (createIncomplete) { |
2569 |
|
checkIncomplete(g); |
2570 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2736 |
|
|
2737 |
|
() -> f.thenCompose(null), |
2738 |
|
() -> f.thenComposeAsync(null), |
2739 |
< |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
2739 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null), |
2740 |
|
() -> f.thenComposeAsync(null, exec), |
2741 |
|
|
2742 |
|
() -> f.exceptionally(null), |