17 |
|
import java.util.concurrent.CompletableFuture; |
18 |
|
import java.util.concurrent.CompletionException; |
19 |
|
import java.util.concurrent.CompletionStage; |
20 |
+ |
import java.util.concurrent.ForkJoinPool; |
21 |
+ |
import java.util.concurrent.ForkJoinTask; |
22 |
|
import java.util.concurrent.TimeoutException; |
23 |
|
import java.util.concurrent.atomic.AtomicInteger; |
24 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
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); |
375 |
|
} |
376 |
|
} |
377 |
|
static final class Noop implements Runnable { |
378 |
+ |
final ExecutionMode m; |
379 |
|
int invocationCount = 0; |
380 |
+ |
Noop(ExecutionMode m) { this.m = m; } |
381 |
|
public void run() { |
382 |
+ |
m.checkExecutionMode(); |
383 |
|
invocationCount++; |
384 |
|
} |
385 |
|
} |
419 |
|
throw new CFException(); |
420 |
|
} |
421 |
|
} |
422 |
< |
static final class FailingNoop implements Runnable { |
422 |
> |
static final class FailingRunnable implements Runnable { |
423 |
|
int invocationCount = 0; |
424 |
|
public void run() { |
425 |
|
invocationCount++; |
463 |
|
*/ |
464 |
|
enum ExecutionMode { |
465 |
|
DEFAULT { |
466 |
+ |
public void checkExecutionMode() { |
467 |
+ |
assertNull(ForkJoinTask.getPool()); |
468 |
+ |
} |
469 |
|
public <T> CompletableFuture<Void> thenRun |
470 |
|
(CompletableFuture<T> f, Runnable a) { |
471 |
|
return f.thenRun(a); |
529 |
|
} |
530 |
|
}, |
531 |
|
|
532 |
< |
DEFAULT_ASYNC { |
532 |
> |
ASYNC { |
533 |
> |
public void checkExecutionMode() { |
534 |
> |
assertSame(ForkJoinPool.commonPool(), |
535 |
> |
ForkJoinTask.getPool()); |
536 |
> |
} |
537 |
|
public <T> CompletableFuture<Void> thenRun |
538 |
|
(CompletableFuture<T> f, Runnable a) { |
539 |
|
return f.thenRunAsync(a); |
598 |
|
}, |
599 |
|
|
600 |
|
EXECUTOR { |
601 |
+ |
public void checkExecutionMode() { |
602 |
+ |
//TODO |
603 |
+ |
} |
604 |
|
public <T> CompletableFuture<Void> thenRun |
605 |
|
(CompletableFuture<T> f, Runnable a) { |
606 |
|
return f.thenRunAsync(a, new ThreadExecutor()); |
664 |
|
} |
665 |
|
}; |
666 |
|
|
667 |
+ |
public abstract void checkExecutionMode(); |
668 |
|
public abstract <T> CompletableFuture<Void> thenRun |
669 |
|
(CompletableFuture<T> f, Runnable a); |
670 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
912 |
|
* runAsync completes after running Runnable |
913 |
|
*/ |
914 |
|
public void testRunAsync() { |
915 |
< |
Noop r = new Noop(); |
915 |
> |
Noop r = new Noop(ExecutionMode.ASYNC); |
916 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
917 |
|
assertNull(f.join()); |
918 |
|
assertEquals(1, r.invocationCount); |
923 |
|
* runAsync with executor completes after running Runnable |
924 |
|
*/ |
925 |
|
public void testRunAsync2() { |
926 |
< |
Noop r = new Noop(); |
926 |
> |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
927 |
|
ThreadExecutor exec = new ThreadExecutor(); |
928 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
929 |
|
assertNull(f.join()); |
936 |
|
* failing runAsync completes exceptionally after running Runnable |
937 |
|
*/ |
938 |
|
public void testRunAsync3() { |
939 |
< |
FailingNoop r = new FailingNoop(); |
939 |
> |
FailingRunnable r = new FailingRunnable(); |
940 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
941 |
|
checkCompletedWithWrappedCFException(f); |
942 |
|
assertEquals(1, r.invocationCount); |
977 |
|
/** |
978 |
|
* thenRun result completes normally after normal completion of source |
979 |
|
*/ |
980 |
< |
public void testThenRun() { |
981 |
< |
CompletableFuture<Integer> f; |
982 |
< |
CompletableFuture<Void> g; |
983 |
< |
Noop r; |
984 |
< |
|
985 |
< |
f = new CompletableFuture<>(); |
986 |
< |
g = f.thenRun(r = new Noop()); |
987 |
< |
f.complete(null); |
988 |
< |
checkCompletedNormally(g, null); |
989 |
< |
assertEquals(1, r.invocationCount); |
980 |
> |
public void testThenRun_normalCompletion() { |
981 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
982 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
983 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
984 |
> |
{ |
985 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
986 |
> |
final Noop r = new Noop(m); |
987 |
> |
if (!createIncomplete) f.complete(v1); |
988 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
989 |
> |
if (createIncomplete) { |
990 |
> |
checkIncomplete(g); |
991 |
> |
f.complete(v1); |
992 |
> |
} |
993 |
|
|
975 |
– |
f = new CompletableFuture<>(); |
976 |
– |
f.complete(null); |
977 |
– |
g = f.thenRun(r = new Noop()); |
994 |
|
checkCompletedNormally(g, null); |
995 |
+ |
checkCompletedNormally(f, v1); |
996 |
|
assertEquals(1, r.invocationCount); |
997 |
< |
} |
997 |
> |
}} |
998 |
|
|
999 |
|
/** |
1000 |
|
* thenRun result completes exceptionally after exceptional |
1001 |
|
* completion of source |
1002 |
|
*/ |
1003 |
< |
public void testThenRun2() { |
1004 |
< |
CompletableFuture<Integer> f; |
1005 |
< |
CompletableFuture<Void> g; |
1006 |
< |
Noop r; |
1007 |
< |
|
1008 |
< |
f = new CompletableFuture<>(); |
1009 |
< |
g = f.thenRun(r = new Noop()); |
1010 |
< |
f.completeExceptionally(new CFException()); |
1011 |
< |
checkCompletedWithWrappedCFException(g); |
1012 |
< |
assertEquals(0, r.invocationCount); |
1003 |
> |
public void testThenRun_exceptionalCompletion() { |
1004 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1005 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1006 |
> |
{ |
1007 |
> |
final CFException ex = new CFException(); |
1008 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1009 |
> |
final Noop r = new Noop(m); |
1010 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1011 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1012 |
> |
if (createIncomplete) { |
1013 |
> |
checkIncomplete(g); |
1014 |
> |
f.completeExceptionally(ex); |
1015 |
> |
} |
1016 |
|
|
1017 |
< |
f = new CompletableFuture<>(); |
1018 |
< |
f.completeExceptionally(new CFException()); |
999 |
< |
g = f.thenRun(r = new Noop()); |
1000 |
< |
checkCompletedWithWrappedCFException(g); |
1017 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1018 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1019 |
|
assertEquals(0, r.invocationCount); |
1020 |
< |
} |
1003 |
< |
|
1004 |
< |
/** |
1005 |
< |
* thenRun result completes exceptionally if action does |
1006 |
< |
*/ |
1007 |
< |
public void testThenRun3() { |
1008 |
< |
CompletableFuture<Integer> f; |
1009 |
< |
CompletableFuture<Void> g; |
1010 |
< |
FailingNoop r; |
1011 |
< |
|
1012 |
< |
f = new CompletableFuture<>(); |
1013 |
< |
g = f.thenRun(r = new FailingNoop()); |
1014 |
< |
f.complete(null); |
1015 |
< |
checkCompletedWithWrappedCFException(g); |
1016 |
< |
|
1017 |
< |
f = new CompletableFuture<>(); |
1018 |
< |
f.complete(null); |
1019 |
< |
g = f.thenRun(r = new FailingNoop()); |
1020 |
< |
checkCompletedWithWrappedCFException(g); |
1021 |
< |
} |
1020 |
> |
}} |
1021 |
|
|
1022 |
|
/** |
1023 |
|
* thenRun result completes exceptionally if source cancelled |
1024 |
|
*/ |
1025 |
< |
public void testThenRun4() { |
1026 |
< |
CompletableFuture<Integer> f; |
1027 |
< |
CompletableFuture<Void> g; |
1028 |
< |
Noop r; |
1029 |
< |
|
1030 |
< |
f = new CompletableFuture<>(); |
1031 |
< |
g = f.thenRun(r = new Noop()); |
1032 |
< |
assertTrue(f.cancel(true)); |
1033 |
< |
checkCompletedWithWrappedCancellationException(g); |
1034 |
< |
|
1035 |
< |
f = new CompletableFuture<>(); |
1036 |
< |
assertTrue(f.cancel(true)); |
1037 |
< |
g = f.thenRun(r = new Noop()); |
1039 |
< |
checkCompletedWithWrappedCancellationException(g); |
1040 |
< |
} |
1041 |
< |
|
1042 |
< |
/** |
1043 |
< |
* thenApply result completes normally after normal completion of source |
1044 |
< |
*/ |
1045 |
< |
public void testThenApply() { |
1046 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1047 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1048 |
< |
f.complete(one); |
1049 |
< |
checkCompletedNormally(g, two); |
1050 |
< |
} |
1051 |
< |
|
1052 |
< |
/** |
1053 |
< |
* thenApply result completes exceptionally after exceptional |
1054 |
< |
* completion of source |
1055 |
< |
*/ |
1056 |
< |
public void testThenApply2() { |
1057 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1058 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1059 |
< |
f.completeExceptionally(new CFException()); |
1060 |
< |
checkCompletedWithWrappedCFException(g); |
1061 |
< |
} |
1062 |
< |
|
1063 |
< |
/** |
1064 |
< |
* thenApply result completes exceptionally if action does |
1065 |
< |
*/ |
1066 |
< |
public void testThenApply3() { |
1067 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1068 |
< |
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
1069 |
< |
f.complete(one); |
1070 |
< |
checkCompletedWithWrappedCFException(g); |
1071 |
< |
} |
1025 |
> |
public void testThenRun_sourceCancelled() { |
1026 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1027 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1028 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1029 |
> |
{ |
1030 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1031 |
> |
final Noop r = new Noop(m); |
1032 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1033 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1034 |
> |
if (createIncomplete) { |
1035 |
> |
checkIncomplete(g); |
1036 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1037 |
> |
} |
1038 |
|
|
1073 |
– |
/** |
1074 |
– |
* thenApply result completes exceptionally if source cancelled |
1075 |
– |
*/ |
1076 |
– |
public void testThenApply4() { |
1077 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1078 |
– |
CompletableFuture<Integer> g = f.thenApply(inc); |
1079 |
– |
assertTrue(f.cancel(true)); |
1039 |
|
checkCompletedWithWrappedCancellationException(g); |
1040 |
< |
} |
1041 |
< |
|
1042 |
< |
/** |
1084 |
< |
* thenAccept result completes normally after normal completion of source |
1085 |
< |
*/ |
1086 |
< |
public void testThenAccept() { |
1087 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1088 |
< |
IncAction r = new IncAction(); |
1089 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1090 |
< |
f.complete(one); |
1091 |
< |
checkCompletedNormally(g, null); |
1092 |
< |
assertEquals(r.value, (Integer) 2); |
1093 |
< |
} |
1040 |
> |
checkCancelled(f); |
1041 |
> |
assertEquals(0, r.invocationCount); |
1042 |
> |
}} |
1043 |
|
|
1044 |
|
/** |
1045 |
< |
* thenAccept result completes exceptionally after exceptional |
1097 |
< |
* completion of source |
1045 |
> |
* thenRun result completes exceptionally if action does |
1046 |
|
*/ |
1047 |
< |
public void testThenAccept2() { |
1048 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1049 |
< |
IncAction r = new IncAction(); |
1050 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1051 |
< |
f.completeExceptionally(new CFException()); |
1052 |
< |
checkCompletedWithWrappedCFException(g); |
1053 |
< |
} |
1047 |
> |
public void testThenRun_actionFailed() { |
1048 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1049 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1050 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1051 |
> |
{ |
1052 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1053 |
> |
final FailingRunnable r = new FailingRunnable(); |
1054 |
> |
if (!createIncomplete) f.complete(v1); |
1055 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1056 |
> |
if (createIncomplete) { |
1057 |
> |
checkIncomplete(g); |
1058 |
> |
f.complete(v1); |
1059 |
> |
} |
1060 |
|
|
1107 |
– |
/** |
1108 |
– |
* thenAccept result completes exceptionally if action does |
1109 |
– |
*/ |
1110 |
– |
public void testThenAccept3() { |
1111 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1112 |
– |
FailingConsumer r = new FailingConsumer(); |
1113 |
– |
CompletableFuture<Void> g = f.thenAccept(r); |
1114 |
– |
f.complete(one); |
1061 |
|
checkCompletedWithWrappedCFException(g); |
1062 |
< |
assertEquals(1, r.invocationCount); |
1063 |
< |
} |
1118 |
< |
|
1119 |
< |
/** |
1120 |
< |
* thenAccept result completes exceptionally if source cancelled |
1121 |
< |
*/ |
1122 |
< |
public void testThenAccept4() { |
1123 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1124 |
< |
IncAction r = new IncAction(); |
1125 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1126 |
< |
assertTrue(f.cancel(true)); |
1127 |
< |
checkCompletedWithWrappedCancellationException(g); |
1128 |
< |
} |
1062 |
> |
checkCompletedNormally(f, v1); |
1063 |
> |
}} |
1064 |
|
|
1065 |
|
/** |
1066 |
< |
* thenCombine result completes normally after normal completion |
1132 |
< |
* of sources |
1066 |
> |
* thenApply result completes normally after normal completion of source |
1067 |
|
*/ |
1068 |
< |
public void testThenCombine_normalCompletion1() { |
1135 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
1136 |
< |
for (boolean fFirst : new boolean[] { true, false }) |
1068 |
> |
public void testThenApply_normalCompletion() { |
1069 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1070 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1071 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1139 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1072 |
|
{ |
1073 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1074 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1075 |
< |
final SubtractFunction r = new SubtractFunction(); |
1076 |
< |
CompletableFuture<Integer> h = null; |
1077 |
< |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1078 |
< |
|
1147 |
< |
if (fFirst) |
1148 |
< |
f.complete(v1); |
1149 |
< |
else |
1150 |
< |
g.complete(v2); |
1151 |
< |
if (createIncomplete) checkIncomplete(h); |
1152 |
< |
assertEquals(0, r.invocationCount); |
1153 |
< |
if (!fFirst) |
1074 |
> |
final IncFunction r = new IncFunction(); |
1075 |
> |
if (!createIncomplete) f.complete(v1); |
1076 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1077 |
> |
if (createIncomplete) { |
1078 |
> |
checkIncomplete(g); |
1079 |
|
f.complete(v1); |
1080 |
< |
else |
1156 |
< |
g.complete(v2); |
1157 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1080 |
> |
} |
1081 |
|
|
1082 |
< |
checkCompletedNormally(h, subtract(v1, v2)); |
1082 |
> |
checkCompletedNormally(g, inc(v1)); |
1083 |
|
checkCompletedNormally(f, v1); |
1161 |
– |
checkCompletedNormally(g, v2); |
1084 |
|
assertEquals(1, r.invocationCount); |
1085 |
|
}} |
1086 |
|
|
1087 |
|
/** |
1088 |
< |
* thenCombine result completes exceptionally after exceptional |
1089 |
< |
* completion of either source |
1088 |
> |
* thenApply result completes exceptionally after exceptional |
1089 |
> |
* completion of source |
1090 |
|
*/ |
1091 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1091 |
> |
public void testThenApply_exceptionalCompletion() { |
1092 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1093 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1093 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1094 |
|
{ |
1173 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1174 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1175 |
– |
final SubtractFunction r = new SubtractFunction(); |
1176 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1095 |
|
final CFException ex = new CFException(); |
1096 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1097 |
+ |
final IncFunction r = new IncFunction(); |
1098 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
1099 |
+ |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1100 |
+ |
if (createIncomplete) { |
1101 |
+ |
checkIncomplete(g); |
1102 |
+ |
f.completeExceptionally(ex); |
1103 |
+ |
} |
1104 |
|
|
1105 |
< |
f.completeExceptionally(ex); |
1180 |
< |
checkIncomplete(h); |
1181 |
< |
g.complete(v1); |
1182 |
< |
|
1183 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1105 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1106 |
|
checkCompletedWithWrappedCFException(f, ex); |
1107 |
|
assertEquals(0, r.invocationCount); |
1186 |
– |
checkCompletedNormally(g, v1); |
1108 |
|
}} |
1109 |
|
|
1110 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1110 |
> |
/** |
1111 |
> |
* thenApply result completes exceptionally if source cancelled |
1112 |
> |
*/ |
1113 |
> |
public void testThenApply_sourceCancelled() { |
1114 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1115 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1115 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1116 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1117 |
|
{ |
1118 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1119 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1120 |
< |
final SubtractFunction r = new SubtractFunction(); |
1121 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1122 |
< |
final CFException ex = new CFException(); |
1123 |
< |
|
1124 |
< |
g.completeExceptionally(ex); |
1125 |
< |
checkIncomplete(h); |
1201 |
< |
f.complete(v1); |
1119 |
> |
final IncFunction r = new IncFunction(); |
1120 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1121 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1122 |
> |
if (createIncomplete) { |
1123 |
> |
checkIncomplete(g); |
1124 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1125 |
> |
} |
1126 |
|
|
1127 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1128 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1127 |
> |
checkCompletedWithWrappedCancellationException(g); |
1128 |
> |
checkCancelled(f); |
1129 |
|
assertEquals(0, r.invocationCount); |
1206 |
– |
checkCompletedNormally(f, v1); |
1130 |
|
}} |
1131 |
|
|
1132 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1132 |
> |
/** |
1133 |
> |
* thenApply result completes exceptionally if action does |
1134 |
> |
*/ |
1135 |
> |
public void testThenApply_actionFailed() { |
1136 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1137 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1138 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1139 |
|
{ |
1140 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1141 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1142 |
< |
final SubtractFunction r = new SubtractFunction(); |
1143 |
< |
final CFException ex = new CFException(); |
1144 |
< |
|
1145 |
< |
g.completeExceptionally(ex); |
1146 |
< |
f.complete(v1); |
1147 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1141 |
> |
final FailingFunction r = new FailingFunction(); |
1142 |
> |
if (!createIncomplete) f.complete(v1); |
1143 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1144 |
> |
if (createIncomplete) { |
1145 |
> |
checkIncomplete(g); |
1146 |
> |
f.complete(v1); |
1147 |
> |
} |
1148 |
|
|
1149 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1223 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1224 |
< |
assertEquals(0, r.invocationCount); |
1149 |
> |
checkCompletedWithWrappedCFException(g); |
1150 |
|
checkCompletedNormally(f, v1); |
1151 |
|
}} |
1152 |
|
|
1153 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1153 |
> |
/** |
1154 |
> |
* thenAccept result completes normally after normal completion of source |
1155 |
> |
*/ |
1156 |
> |
public void testThenAccept_normalCompletion() { |
1157 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1158 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1159 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1160 |
|
{ |
1161 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1162 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1163 |
< |
final SubtractFunction r = new SubtractFunction(); |
1164 |
< |
final CFException ex = new CFException(); |
1165 |
< |
|
1166 |
< |
f.completeExceptionally(ex); |
1167 |
< |
g.complete(v1); |
1168 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1162 |
> |
final IncAction r = new IncAction(); |
1163 |
> |
if (!createIncomplete) f.complete(v1); |
1164 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1165 |
> |
if (createIncomplete) { |
1166 |
> |
checkIncomplete(g); |
1167 |
> |
f.complete(v1); |
1168 |
> |
} |
1169 |
|
|
1170 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1171 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1172 |
< |
assertEquals(0, r.invocationCount); |
1173 |
< |
checkCompletedNormally(g, v1); |
1170 |
> |
checkCompletedNormally(g, null); |
1171 |
> |
checkCompletedNormally(f, v1); |
1172 |
> |
assertEquals(1, r.invocationCount); |
1173 |
> |
assertEquals(inc(v1), r.value); |
1174 |
|
}} |
1175 |
|
|
1176 |
|
/** |
1177 |
< |
* thenCombine result completes exceptionally if action does |
1177 |
> |
* thenAccept result completes exceptionally after exceptional |
1178 |
> |
* completion of source |
1179 |
|
*/ |
1180 |
< |
public void testThenCombine_actionFailed1() { |
1180 |
> |
public void testThenAccept_exceptionalCompletion() { |
1181 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1182 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1253 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1182 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1183 |
|
{ |
1184 |
+ |
final CFException ex = new CFException(); |
1185 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1186 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1187 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1188 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1189 |
< |
|
1190 |
< |
f.complete(v1); |
1191 |
< |
checkIncomplete(h); |
1192 |
< |
g.complete(v2); |
1186 |
> |
final IncAction r = new IncAction(); |
1187 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1188 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1189 |
> |
if (createIncomplete) { |
1190 |
> |
checkIncomplete(g); |
1191 |
> |
f.completeExceptionally(ex); |
1192 |
> |
} |
1193 |
|
|
1194 |
< |
checkCompletedWithWrappedCFException(h); |
1195 |
< |
checkCompletedNormally(f, v1); |
1196 |
< |
checkCompletedNormally(g, v2); |
1194 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1195 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1196 |
> |
assertEquals(0, r.invocationCount); |
1197 |
|
}} |
1198 |
|
|
1199 |
< |
public void testThenCombine_actionFailed2() { |
1199 |
> |
/** |
1200 |
> |
* thenAccept result completes exceptionally if action does |
1201 |
> |
*/ |
1202 |
> |
public void testThenAccept_actionFailed() { |
1203 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1204 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1205 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1272 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1206 |
|
{ |
1207 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1208 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1209 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1210 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1211 |
< |
|
1212 |
< |
g.complete(v2); |
1213 |
< |
checkIncomplete(h); |
1214 |
< |
f.complete(v1); |
1208 |
> |
final FailingConsumer r = new FailingConsumer(); |
1209 |
> |
if (!createIncomplete) f.complete(v1); |
1210 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1211 |
> |
if (createIncomplete) { |
1212 |
> |
checkIncomplete(g); |
1213 |
> |
f.complete(v1); |
1214 |
> |
} |
1215 |
|
|
1216 |
< |
checkCompletedWithWrappedCFException(h); |
1216 |
> |
checkCompletedWithWrappedCFException(g); |
1217 |
|
checkCompletedNormally(f, v1); |
1285 |
– |
checkCompletedNormally(g, v2); |
1218 |
|
}} |
1219 |
|
|
1220 |
|
/** |
1221 |
< |
* thenCombine result completes exceptionally if either source cancelled |
1221 |
> |
* thenAccept result completes exceptionally if source cancelled |
1222 |
|
*/ |
1223 |
< |
public void testThenCombine_sourceCancelled1() { |
1223 |
> |
public void testThenAccept_sourceCancelled() { |
1224 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1225 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1226 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1294 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1227 |
|
{ |
1228 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1229 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1230 |
< |
final SubtractFunction r = new SubtractFunction(); |
1231 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1232 |
< |
|
1233 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1234 |
< |
checkIncomplete(h); |
1235 |
< |
g.complete(v1); |
1229 |
> |
final IncAction r = new IncAction(); |
1230 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1231 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1232 |
> |
if (createIncomplete) { |
1233 |
> |
checkIncomplete(g); |
1234 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1235 |
> |
} |
1236 |
|
|
1237 |
< |
checkCompletedWithWrappedCancellationException(h); |
1237 |
> |
checkCompletedWithWrappedCancellationException(g); |
1238 |
|
checkCancelled(f); |
1239 |
|
assertEquals(0, r.invocationCount); |
1308 |
– |
checkCompletedNormally(g, v1); |
1240 |
|
}} |
1241 |
|
|
1242 |
< |
public void testThenCombine_sourceCancelled2() { |
1243 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1244 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1245 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1246 |
< |
{ |
1316 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1317 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1318 |
< |
final SubtractFunction r = new SubtractFunction(); |
1319 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1320 |
< |
|
1321 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1322 |
< |
checkIncomplete(h); |
1323 |
< |
f.complete(v1); |
1324 |
< |
|
1325 |
< |
checkCompletedWithWrappedCancellationException(h); |
1326 |
< |
checkCancelled(g); |
1327 |
< |
assertEquals(0, r.invocationCount); |
1328 |
< |
checkCompletedNormally(f, v1); |
1329 |
< |
}} |
1330 |
< |
|
1331 |
< |
public void testThenCombine_sourceCancelled3() { |
1242 |
> |
/** |
1243 |
> |
* thenCombine result completes normally after normal completion |
1244 |
> |
* of sources |
1245 |
> |
*/ |
1246 |
> |
public void testThenCombine_normalCompletion() { |
1247 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1248 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1248 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1249 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1250 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1251 |
+ |
for (Integer v2 : new Integer[] { 2, null }) |
1252 |
|
{ |
1253 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1254 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1255 |
|
final SubtractFunction r = new SubtractFunction(); |
1256 |
|
|
1257 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1258 |
< |
f.complete(v1); |
1257 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1258 |
> |
if (!createIncomplete) |
1259 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1260 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1261 |
+ |
if (createIncomplete) { |
1262 |
+ |
checkIncomplete(h); |
1263 |
+ |
assertEquals(0, r.invocationCount); |
1264 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1265 |
+ |
} |
1266 |
|
|
1267 |
< |
checkCompletedWithWrappedCancellationException(h); |
1345 |
< |
checkCancelled(g); |
1346 |
< |
assertEquals(0, r.invocationCount); |
1267 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
1268 |
|
checkCompletedNormally(f, v1); |
1269 |
+ |
checkCompletedNormally(g, v2); |
1270 |
+ |
assertEquals(1, r.invocationCount); |
1271 |
|
}} |
1272 |
|
|
1273 |
< |
public void testThenCombine_sourceCancelled4() { |
1273 |
> |
/** |
1274 |
> |
* thenCombine result completes exceptionally after exceptional |
1275 |
> |
* completion of either source |
1276 |
> |
*/ |
1277 |
> |
public void testThenCombine_exceptionalCompletion() { |
1278 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1279 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1279 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1280 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1281 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1282 |
|
{ |
1283 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1284 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1285 |
+ |
final CFException ex = new CFException(); |
1286 |
|
final SubtractFunction r = new SubtractFunction(); |
1287 |
|
|
1288 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1289 |
< |
g.complete(v1); |
1288 |
> |
(fFirst ? f : g).complete(v1); |
1289 |
> |
if (!createIncomplete) |
1290 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1291 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1292 |
+ |
if (createIncomplete) { |
1293 |
+ |
checkIncomplete(h); |
1294 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1295 |
+ |
} |
1296 |
|
|
1297 |
< |
checkCompletedWithWrappedCancellationException(h); |
1364 |
< |
checkCancelled(f); |
1297 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1298 |
|
assertEquals(0, r.invocationCount); |
1299 |
< |
checkCompletedNormally(g, v1); |
1299 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1300 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1301 |
|
}} |
1302 |
|
|
1303 |
|
/** |
1304 |
< |
* thenAcceptBoth result completes normally after normal |
1371 |
< |
* completion of sources |
1304 |
> |
* thenCombine result completes exceptionally if action does |
1305 |
|
*/ |
1306 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1374 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1375 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1376 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1377 |
< |
{ |
1378 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1379 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1380 |
< |
final SubtractAction r = new SubtractAction(); |
1381 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1382 |
< |
|
1383 |
< |
f.complete(v1); |
1384 |
< |
checkIncomplete(h); |
1385 |
< |
assertEquals(0, r.invocationCount); |
1386 |
< |
g.complete(v2); |
1387 |
< |
|
1388 |
< |
checkCompletedNormally(h, null); |
1389 |
< |
assertEquals(subtract(v1, v2), r.value); |
1390 |
< |
checkCompletedNormally(f, v1); |
1391 |
< |
checkCompletedNormally(g, v2); |
1392 |
< |
}} |
1393 |
< |
|
1394 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1306 |
> |
public void testThenCombine_actionFailed() { |
1307 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1308 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1309 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1310 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1311 |
|
{ |
1312 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1313 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1314 |
< |
final SubtractAction r = new SubtractAction(); |
1315 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1314 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1315 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1316 |
|
|
1317 |
< |
g.complete(v2); |
1318 |
< |
checkIncomplete(h); |
1319 |
< |
assertEquals(0, r.invocationCount); |
1320 |
< |
f.complete(v1); |
1317 |
> |
if (fFirst) { |
1318 |
> |
f.complete(v1); |
1319 |
> |
g.complete(v2); |
1320 |
> |
} else { |
1321 |
> |
g.complete(v2); |
1322 |
> |
f.complete(v1); |
1323 |
> |
} |
1324 |
|
|
1325 |
< |
checkCompletedNormally(h, null); |
1410 |
< |
assertEquals(subtract(v1, v2), r.value); |
1325 |
> |
checkCompletedWithWrappedCFException(h); |
1326 |
|
checkCompletedNormally(f, v1); |
1327 |
|
checkCompletedNormally(g, v2); |
1328 |
|
}} |
1329 |
|
|
1330 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1330 |
> |
/** |
1331 |
> |
* thenCombine result completes exceptionally if either source cancelled |
1332 |
> |
*/ |
1333 |
> |
public void testThenCombine_sourceCancelled() { |
1334 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1335 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1336 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1337 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1338 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1418 |
– |
for (Integer v2 : new Integer[] { 2, null }) |
1339 |
|
{ |
1340 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1341 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1342 |
< |
final SubtractAction r = new SubtractAction(); |
1342 |
> |
final SubtractFunction r = new SubtractFunction(); |
1343 |
|
|
1344 |
< |
g.complete(v2); |
1345 |
< |
f.complete(v1); |
1346 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1344 |
> |
(fFirst ? f : g).complete(v1); |
1345 |
> |
if (!createIncomplete) |
1346 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1347 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1348 |
> |
if (createIncomplete) { |
1349 |
> |
checkIncomplete(h); |
1350 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1351 |
> |
} |
1352 |
|
|
1353 |
< |
checkCompletedNormally(h, null); |
1354 |
< |
assertEquals(subtract(v1, v2), r.value); |
1355 |
< |
checkCompletedNormally(f, v1); |
1356 |
< |
checkCompletedNormally(g, v2); |
1353 |
> |
checkCompletedWithWrappedCancellationException(h); |
1354 |
> |
checkCancelled(!fFirst ? f : g); |
1355 |
> |
assertEquals(0, r.invocationCount); |
1356 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1357 |
|
}} |
1358 |
|
|
1359 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1359 |
> |
/** |
1360 |
> |
* thenAcceptBoth result completes normally after normal |
1361 |
> |
* completion of sources |
1362 |
> |
*/ |
1363 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1364 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1365 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1366 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1367 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1368 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1369 |
|
{ |
1371 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1372 |
|
final SubtractAction r = new SubtractAction(); |
1373 |
|
|
1374 |
< |
f.complete(v1); |
1375 |
< |
g.complete(v2); |
1374 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1375 |
> |
if (!createIncomplete) |
1376 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1377 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1378 |
+ |
if (createIncomplete) { |
1379 |
+ |
checkIncomplete(h); |
1380 |
+ |
assertEquals(0, r.invocationCount); |
1381 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1382 |
+ |
} |
1383 |
|
|
1384 |
|
checkCompletedNormally(h, null); |
1385 |
|
assertEquals(subtract(v1, v2), r.value); |
1391 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1392 |
|
* completion of either source |
1393 |
|
*/ |
1394 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1458 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1459 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1460 |
< |
{ |
1461 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1462 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1463 |
< |
final SubtractAction r = new SubtractAction(); |
1464 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1465 |
< |
final CFException ex = new CFException(); |
1466 |
< |
|
1467 |
< |
f.completeExceptionally(ex); |
1468 |
< |
checkIncomplete(h); |
1469 |
< |
g.complete(v1); |
1470 |
< |
|
1471 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1472 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1473 |
< |
assertEquals(0, r.invocationCount); |
1474 |
< |
checkCompletedNormally(g, v1); |
1475 |
< |
}} |
1476 |
< |
|
1477 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1478 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1479 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1480 |
< |
{ |
1481 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1482 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1483 |
< |
final SubtractAction r = new SubtractAction(); |
1484 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1485 |
< |
final CFException ex = new CFException(); |
1486 |
< |
|
1487 |
< |
g.completeExceptionally(ex); |
1488 |
< |
checkIncomplete(h); |
1489 |
< |
f.complete(v1); |
1490 |
< |
|
1491 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1492 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1493 |
< |
assertEquals(0, r.invocationCount); |
1494 |
< |
checkCompletedNormally(f, v1); |
1495 |
< |
}} |
1496 |
< |
|
1497 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1394 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1395 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1396 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1397 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1398 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1399 |
|
{ |
1400 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1401 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1503 |
– |
final SubtractAction r = new SubtractAction(); |
1402 |
|
final CFException ex = new CFException(); |
1505 |
– |
|
1506 |
– |
g.completeExceptionally(ex); |
1507 |
– |
f.complete(v1); |
1508 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1509 |
– |
|
1510 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1511 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1512 |
– |
assertEquals(0, r.invocationCount); |
1513 |
– |
checkCompletedNormally(f, v1); |
1514 |
– |
}} |
1515 |
– |
|
1516 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1517 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1518 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1519 |
– |
{ |
1520 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1521 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
|
final SubtractAction r = new SubtractAction(); |
1523 |
– |
final CFException ex = new CFException(); |
1404 |
|
|
1405 |
< |
f.completeExceptionally(ex); |
1406 |
< |
g.complete(v1); |
1405 |
> |
(fFirst ? f : g).complete(v1); |
1406 |
> |
if (!createIncomplete) |
1407 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1408 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1409 |
+ |
if (createIncomplete) { |
1410 |
+ |
checkIncomplete(h); |
1411 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1412 |
+ |
} |
1413 |
|
|
1414 |
|
checkCompletedWithWrappedCFException(h, ex); |
1530 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1415 |
|
assertEquals(0, r.invocationCount); |
1416 |
< |
checkCompletedNormally(g, v1); |
1416 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1417 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1418 |
|
}} |
1419 |
|
|
1420 |
|
/** |
1421 |
|
* thenAcceptBoth result completes exceptionally if action does |
1422 |
|
*/ |
1423 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1539 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1540 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1541 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1542 |
< |
{ |
1543 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1544 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1545 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1546 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1547 |
< |
|
1548 |
< |
f.complete(v1); |
1549 |
< |
checkIncomplete(h); |
1550 |
< |
g.complete(v2); |
1551 |
< |
|
1552 |
< |
checkCompletedWithWrappedCFException(h); |
1553 |
< |
checkCompletedNormally(f, v1); |
1554 |
< |
checkCompletedNormally(g, v2); |
1555 |
< |
}} |
1556 |
< |
|
1557 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1423 |
> |
public void testThenAcceptBoth_actionFailed() { |
1424 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1425 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1426 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1427 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1428 |
|
{ |
1431 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1432 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1433 |
|
|
1434 |
< |
g.complete(v2); |
1435 |
< |
checkIncomplete(h); |
1436 |
< |
f.complete(v1); |
1434 |
> |
if (fFirst) { |
1435 |
> |
f.complete(v1); |
1436 |
> |
g.complete(v2); |
1437 |
> |
} else { |
1438 |
> |
g.complete(v2); |
1439 |
> |
f.complete(v1); |
1440 |
> |
} |
1441 |
|
|
1442 |
|
checkCompletedWithWrappedCFException(h); |
1443 |
|
checkCompletedNormally(f, v1); |
1447 |
|
/** |
1448 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1449 |
|
*/ |
1450 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1580 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1581 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1582 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1583 |
< |
{ |
1584 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1585 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1586 |
< |
final SubtractAction r = new SubtractAction(); |
1587 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1588 |
< |
|
1589 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1590 |
< |
checkIncomplete(h); |
1591 |
< |
g.complete(v1); |
1592 |
< |
|
1593 |
< |
checkCompletedWithWrappedCancellationException(h); |
1594 |
< |
checkCancelled(f); |
1595 |
< |
assertEquals(0, r.invocationCount); |
1596 |
< |
checkCompletedNormally(g, v1); |
1597 |
< |
}} |
1598 |
< |
|
1599 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1600 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1601 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1602 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1603 |
< |
{ |
1604 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1605 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1606 |
< |
final SubtractAction r = new SubtractAction(); |
1607 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1608 |
< |
|
1609 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1610 |
< |
checkIncomplete(h); |
1611 |
< |
f.complete(v1); |
1612 |
< |
|
1613 |
< |
checkCompletedWithWrappedCancellationException(h); |
1614 |
< |
checkCancelled(g); |
1615 |
< |
assertEquals(0, r.invocationCount); |
1616 |
< |
checkCompletedNormally(f, v1); |
1617 |
< |
}} |
1618 |
< |
|
1619 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1620 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1621 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1622 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1623 |
< |
{ |
1624 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1625 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1626 |
< |
final SubtractAction r = new SubtractAction(); |
1627 |
< |
|
1628 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1629 |
< |
f.complete(v1); |
1630 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1631 |
< |
|
1632 |
< |
checkCompletedWithWrappedCancellationException(h); |
1633 |
< |
checkCancelled(g); |
1634 |
< |
assertEquals(0, r.invocationCount); |
1635 |
< |
checkCompletedNormally(f, v1); |
1636 |
< |
}} |
1637 |
< |
|
1638 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1450 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1451 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1452 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1453 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1454 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1455 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1456 |
|
{ |
1457 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1458 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1459 |
|
final SubtractAction r = new SubtractAction(); |
1460 |
|
|
1461 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1462 |
< |
g.complete(v1); |
1461 |
> |
(fFirst ? f : g).complete(v1); |
1462 |
> |
if (!createIncomplete) |
1463 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1464 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1465 |
+ |
if (createIncomplete) { |
1466 |
+ |
checkIncomplete(h); |
1467 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1468 |
+ |
} |
1469 |
|
|
1470 |
|
checkCompletedWithWrappedCancellationException(h); |
1471 |
< |
checkCancelled(f); |
1471 |
> |
checkCancelled(!fFirst ? f : g); |
1472 |
|
assertEquals(0, r.invocationCount); |
1473 |
< |
checkCompletedNormally(g, v1); |
1473 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1474 |
|
}} |
1475 |
|
|
1476 |
|
/** |
1477 |
|
* runAfterBoth result completes normally after normal |
1478 |
|
* completion of sources |
1479 |
|
*/ |
1480 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1662 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1663 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1664 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1665 |
< |
{ |
1666 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1667 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1668 |
< |
final Noop r = new Noop(); |
1669 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1670 |
< |
|
1671 |
< |
f.complete(v1); |
1672 |
< |
checkIncomplete(h); |
1673 |
< |
assertEquals(0, r.invocationCount); |
1674 |
< |
g.complete(v2); |
1675 |
< |
|
1676 |
< |
checkCompletedNormally(h, null); |
1677 |
< |
assertEquals(1, r.invocationCount); |
1678 |
< |
checkCompletedNormally(f, v1); |
1679 |
< |
checkCompletedNormally(g, v2); |
1680 |
< |
}} |
1681 |
< |
|
1682 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1683 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1684 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1685 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1686 |
< |
{ |
1687 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1688 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1689 |
< |
final Noop r = new Noop(); |
1690 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1691 |
< |
|
1692 |
< |
g.complete(v2); |
1693 |
< |
checkIncomplete(h); |
1694 |
< |
assertEquals(0, r.invocationCount); |
1695 |
< |
f.complete(v1); |
1696 |
< |
|
1697 |
< |
checkCompletedNormally(h, null); |
1698 |
< |
assertEquals(1, r.invocationCount); |
1699 |
< |
checkCompletedNormally(f, v1); |
1700 |
< |
checkCompletedNormally(g, v2); |
1701 |
< |
}} |
1702 |
< |
|
1703 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1480 |
> |
public void testRunAfterBoth_normalCompletion() { |
1481 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1482 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1483 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1484 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1485 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1486 |
|
{ |
1487 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1488 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1489 |
< |
final Noop r = new Noop(); |
1489 |
> |
final Noop r = new Noop(m); |
1490 |
|
|
1491 |
< |
g.complete(v2); |
1492 |
< |
f.complete(v1); |
1493 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1715 |
< |
|
1716 |
< |
checkCompletedNormally(h, null); |
1717 |
< |
assertEquals(1, r.invocationCount); |
1718 |
< |
checkCompletedNormally(f, v1); |
1719 |
< |
checkCompletedNormally(g, v2); |
1720 |
< |
}} |
1721 |
< |
|
1722 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1723 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1724 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1725 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1726 |
< |
{ |
1727 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1728 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1729 |
< |
final Noop r = new Noop(); |
1730 |
< |
|
1731 |
< |
f.complete(v1); |
1732 |
< |
g.complete(v2); |
1491 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1492 |
> |
if (!createIncomplete) |
1493 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1494 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1495 |
+ |
if (createIncomplete) { |
1496 |
+ |
checkIncomplete(h); |
1497 |
+ |
assertEquals(0, r.invocationCount); |
1498 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1499 |
+ |
} |
1500 |
|
|
1501 |
|
checkCompletedNormally(h, null); |
1502 |
|
assertEquals(1, r.invocationCount); |
1508 |
|
* runAfterBoth result completes exceptionally after exceptional |
1509 |
|
* completion of either source |
1510 |
|
*/ |
1511 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1746 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1747 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1748 |
< |
{ |
1749 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1750 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1751 |
< |
final Noop r = new Noop(); |
1752 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1753 |
< |
final CFException ex = new CFException(); |
1754 |
< |
|
1755 |
< |
f.completeExceptionally(ex); |
1756 |
< |
checkIncomplete(h); |
1757 |
< |
g.complete(v1); |
1758 |
< |
|
1759 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1760 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1761 |
< |
assertEquals(0, r.invocationCount); |
1762 |
< |
checkCompletedNormally(g, v1); |
1763 |
< |
}} |
1764 |
< |
|
1765 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1766 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1767 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1768 |
< |
{ |
1769 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1770 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1771 |
< |
final Noop r = new Noop(); |
1772 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1773 |
< |
final CFException ex = new CFException(); |
1774 |
< |
|
1775 |
< |
g.completeExceptionally(ex); |
1776 |
< |
checkIncomplete(h); |
1777 |
< |
f.complete(v1); |
1778 |
< |
|
1779 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1780 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1781 |
< |
assertEquals(0, r.invocationCount); |
1782 |
< |
checkCompletedNormally(f, v1); |
1783 |
< |
}} |
1784 |
< |
|
1785 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1786 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1787 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1788 |
< |
{ |
1789 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1790 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1791 |
< |
final Noop r = new Noop(); |
1792 |
< |
final CFException ex = new CFException(); |
1793 |
< |
|
1794 |
< |
g.completeExceptionally(ex); |
1795 |
< |
f.complete(v1); |
1796 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1797 |
< |
|
1798 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1799 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1800 |
< |
assertEquals(0, r.invocationCount); |
1801 |
< |
checkCompletedNormally(f, v1); |
1802 |
< |
}} |
1803 |
< |
|
1804 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1511 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1512 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1513 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1514 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1515 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1516 |
|
{ |
1517 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1518 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1810 |
– |
final Noop r = new Noop(); |
1519 |
|
final CFException ex = new CFException(); |
1520 |
+ |
final Noop r = new Noop(m); |
1521 |
|
|
1522 |
< |
f.completeExceptionally(ex); |
1523 |
< |
g.complete(v1); |
1522 |
> |
(fFirst ? f : g).complete(v1); |
1523 |
> |
if (!createIncomplete) |
1524 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1525 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1526 |
+ |
if (createIncomplete) { |
1527 |
+ |
checkIncomplete(h); |
1528 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1529 |
+ |
} |
1530 |
|
|
1531 |
|
checkCompletedWithWrappedCFException(h, ex); |
1818 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1532 |
|
assertEquals(0, r.invocationCount); |
1533 |
< |
checkCompletedNormally(g, v1); |
1533 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1534 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1535 |
|
}} |
1536 |
|
|
1537 |
|
/** |
1538 |
|
* runAfterBoth result completes exceptionally if action does |
1539 |
|
*/ |
1540 |
< |
public void testRunAfterBoth_actionFailed1() { |
1827 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1828 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1829 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1830 |
< |
{ |
1831 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1832 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1833 |
< |
final FailingNoop r = new FailingNoop(); |
1834 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1835 |
< |
|
1836 |
< |
f.complete(v1); |
1837 |
< |
checkIncomplete(h); |
1838 |
< |
g.complete(v2); |
1839 |
< |
|
1840 |
< |
checkCompletedWithWrappedCFException(h); |
1841 |
< |
checkCompletedNormally(f, v1); |
1842 |
< |
checkCompletedNormally(g, v2); |
1843 |
< |
}} |
1844 |
< |
|
1845 |
< |
public void testRunAfterBoth_actionFailed2() { |
1540 |
> |
public void testRunAfterBoth_actionFailed() { |
1541 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1542 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1543 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1544 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1545 |
|
{ |
1546 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1547 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1548 |
< |
final FailingNoop r = new FailingNoop(); |
1853 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1548 |
> |
final FailingRunnable r = new FailingRunnable(); |
1549 |
|
|
1550 |
< |
g.complete(v2); |
1551 |
< |
checkIncomplete(h); |
1552 |
< |
f.complete(v1); |
1550 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1551 |
> |
if (fFirst) { |
1552 |
> |
f.complete(v1); |
1553 |
> |
g.complete(v2); |
1554 |
> |
} else { |
1555 |
> |
g.complete(v2); |
1556 |
> |
f.complete(v1); |
1557 |
> |
} |
1558 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1559 |
|
|
1560 |
< |
checkCompletedWithWrappedCFException(h); |
1560 |
> |
checkCompletedWithWrappedCFException(h1); |
1561 |
> |
checkCompletedWithWrappedCFException(h2); |
1562 |
|
checkCompletedNormally(f, v1); |
1563 |
|
checkCompletedNormally(g, v2); |
1564 |
|
}} |
1566 |
|
/** |
1567 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1568 |
|
*/ |
1569 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1868 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1869 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1870 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1871 |
< |
{ |
1872 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1873 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1874 |
< |
final Noop r = new Noop(); |
1875 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1876 |
< |
|
1877 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1878 |
< |
checkIncomplete(h); |
1879 |
< |
g.complete(v1); |
1880 |
< |
|
1881 |
< |
checkCompletedWithWrappedCancellationException(h); |
1882 |
< |
checkCancelled(f); |
1883 |
< |
assertEquals(0, r.invocationCount); |
1884 |
< |
checkCompletedNormally(g, v1); |
1885 |
< |
}} |
1886 |
< |
|
1887 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1888 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1889 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1890 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1891 |
< |
{ |
1892 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1893 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1894 |
< |
final Noop r = new Noop(); |
1895 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1896 |
< |
|
1897 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1898 |
< |
checkIncomplete(h); |
1899 |
< |
f.complete(v1); |
1900 |
< |
|
1901 |
< |
checkCompletedWithWrappedCancellationException(h); |
1902 |
< |
checkCancelled(g); |
1903 |
< |
assertEquals(0, r.invocationCount); |
1904 |
< |
checkCompletedNormally(f, v1); |
1905 |
< |
}} |
1906 |
< |
|
1907 |
< |
public void testRunAfterBoth_sourceCancelled3() { |
1569 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1570 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1571 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1572 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1573 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1574 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1575 |
|
{ |
1576 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1577 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1578 |
< |
final Noop r = new Noop(); |
1578 |
> |
final Noop r = new Noop(m); |
1579 |
|
|
1916 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1917 |
– |
f.complete(v1); |
1918 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1580 |
|
|
1581 |
< |
checkCompletedWithWrappedCancellationException(h); |
1582 |
< |
checkCancelled(g); |
1583 |
< |
assertEquals(0, r.invocationCount); |
1923 |
< |
checkCompletedNormally(f, v1); |
1924 |
< |
}} |
1925 |
< |
|
1926 |
< |
public void testRunAfterBoth_sourceCancelled4() { |
1927 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1928 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1929 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1930 |
< |
{ |
1931 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1932 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1933 |
< |
final Noop r = new Noop(); |
1934 |
< |
|
1935 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1936 |
< |
g.complete(v1); |
1581 |
> |
(fFirst ? f : g).complete(v1); |
1582 |
> |
if (!createIncomplete) |
1583 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1584 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
+ |
if (createIncomplete) { |
1586 |
+ |
checkIncomplete(h); |
1587 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1588 |
+ |
} |
1589 |
|
|
1590 |
|
checkCompletedWithWrappedCancellationException(h); |
1591 |
< |
checkCancelled(f); |
1591 |
> |
checkCancelled(!fFirst ? f : g); |
1592 |
|
assertEquals(0, r.invocationCount); |
1593 |
< |
checkCompletedNormally(g, v1); |
1593 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1594 |
|
}} |
1595 |
|
|
1596 |
|
/** |
1597 |
|
* applyToEither result completes normally after normal completion |
1598 |
|
* of either source |
1599 |
|
*/ |
1600 |
< |
public void testApplyToEither_normalCompletion1() { |
1600 |
> |
public void testApplyToEither_normalCompletion() { |
1601 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1602 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1603 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1604 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1605 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1606 |
|
{ |
1607 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1608 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1609 |
|
final IncFunction r = new IncFunction(); |
1957 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1610 |
|
|
1611 |
< |
f.complete(v1); |
1612 |
< |
checkCompletedNormally(h, inc(v1)); |
1613 |
< |
g.complete(v2); |
1611 |
> |
if (!createIncomplete) |
1612 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1613 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1614 |
> |
if (createIncomplete) { |
1615 |
> |
checkIncomplete(h); |
1616 |
> |
assertEquals(0, r.invocationCount); |
1617 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1618 |
> |
} |
1619 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1620 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1621 |
|
|
1622 |
|
checkCompletedNormally(f, v1); |
1623 |
|
checkCompletedNormally(g, v2); |
1624 |
< |
checkCompletedNormally(h, inc(v1)); |
1624 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1625 |
|
}} |
1626 |
|
|
1627 |
< |
public void testApplyToEither_normalCompletion2() { |
1627 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1628 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1629 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1630 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1631 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1632 |
|
{ |
1633 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1634 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1635 |
|
final IncFunction r = new IncFunction(); |
1976 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1636 |
|
|
1637 |
< |
g.complete(v2); |
1638 |
< |
checkCompletedNormally(h, inc(v2)); |
1639 |
< |
f.complete(v1); |
1640 |
< |
|
1641 |
< |
checkCompletedNormally(f, v1); |
1642 |
< |
checkCompletedNormally(g, v2); |
1643 |
< |
checkCompletedNormally(h, inc(v2)); |
1985 |
< |
}} |
1986 |
< |
|
1987 |
< |
public void testApplyToEither_normalCompletion3() { |
1988 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1989 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1990 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1991 |
< |
{ |
1992 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1993 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1994 |
< |
final IncFunction r = new IncFunction(); |
1637 |
> |
if (fFirst) { |
1638 |
> |
f.complete(v1); |
1639 |
> |
g.complete(v2); |
1640 |
> |
} else { |
1641 |
> |
g.complete(v2); |
1642 |
> |
f.complete(v1); |
1643 |
> |
} |
1644 |
|
|
1996 |
– |
f.complete(v1); |
1997 |
– |
g.complete(v2); |
1645 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1646 |
|
|
1647 |
|
checkCompletedNormally(f, v1); |
1659 |
|
*/ |
1660 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1661 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1662 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1663 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1664 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1665 |
|
{ |
1666 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1667 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2019 |
– |
final IncFunction r = new IncFunction(); |
2020 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1668 |
|
final CFException ex = new CFException(); |
2022 |
– |
|
2023 |
– |
f.completeExceptionally(ex); |
2024 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2025 |
– |
g.complete(v1); |
2026 |
– |
|
2027 |
– |
assertEquals(0, r.invocationCount); |
2028 |
– |
checkCompletedNormally(g, v1); |
2029 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2030 |
– |
checkCompletedWithWrappedCFException(h, ex); |
2031 |
– |
}} |
2032 |
– |
|
2033 |
– |
public void testApplyToEither_exceptionalCompletion2() { |
2034 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2035 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2036 |
– |
{ |
2037 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2038 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1669 |
|
final IncFunction r = new IncFunction(); |
1670 |
+ |
|
1671 |
+ |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1672 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1673 |
< |
final CFException ex = new CFException(); |
1673 |
> |
if (createIncomplete) { |
1674 |
> |
checkIncomplete(h); |
1675 |
> |
assertEquals(0, r.invocationCount); |
1676 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1677 |
> |
} |
1678 |
|
|
2043 |
– |
g.completeExceptionally(ex); |
1679 |
|
checkCompletedWithWrappedCFException(h, ex); |
1680 |
< |
f.complete(v1); |
1680 |
> |
(!fFirst ? f : g).complete(v1); |
1681 |
|
|
1682 |
|
assertEquals(0, r.invocationCount); |
1683 |
< |
checkCompletedNormally(f, v1); |
1684 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1683 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1684 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1685 |
|
checkCompletedWithWrappedCFException(h, ex); |
1686 |
|
}} |
1687 |
|
|
1688 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1688 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1689 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1690 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1691 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1692 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1693 |
|
{ |
1694 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1695 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1696 |
< |
final IncFunction r = new IncFunction(); |
1696 |
> |
final IncFunction r1 = new IncFunction(); |
1697 |
> |
final IncFunction r2 = new IncFunction(); |
1698 |
|
final CFException ex = new CFException(); |
1699 |
< |
|
1700 |
< |
g.completeExceptionally(ex); |
1701 |
< |
f.complete(v1); |
1702 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1699 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1700 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1701 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1702 |
> |
if (fFirst) { |
1703 |
> |
f.complete(v1); |
1704 |
> |
g.completeExceptionally(ex); |
1705 |
> |
} else { |
1706 |
> |
g.completeExceptionally(ex); |
1707 |
> |
f.complete(v1); |
1708 |
> |
} |
1709 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1710 |
|
|
1711 |
|
// unspecified behavior |
2067 |
– |
Integer v; |
1712 |
|
try { |
1713 |
< |
assertEquals(inc(v1), h.join()); |
1714 |
< |
assertEquals(1, r.invocationCount); |
1713 |
> |
assertEquals(inc(v1), h1.join()); |
1714 |
> |
assertEquals(1, r1.invocationCount); |
1715 |
|
} catch (CompletionException ok) { |
1716 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1717 |
< |
assertEquals(0, r.invocationCount); |
1716 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1717 |
> |
assertEquals(0, r1.invocationCount); |
1718 |
|
} |
1719 |
|
|
2076 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2077 |
– |
checkCompletedNormally(f, v1); |
2078 |
– |
}} |
2079 |
– |
|
2080 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2081 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2082 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2083 |
– |
{ |
2084 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2085 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2086 |
– |
final IncFunction r = new IncFunction(); |
2087 |
– |
final CFException ex = new CFException(); |
2088 |
– |
|
2089 |
– |
f.completeExceptionally(ex); |
2090 |
– |
g.complete(v1); |
2091 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2092 |
– |
|
2093 |
– |
// unspecified behavior |
2094 |
– |
Integer v; |
1720 |
|
try { |
1721 |
< |
assertEquals(inc(v1), h.join()); |
1722 |
< |
assertEquals(1, r.invocationCount); |
1721 |
> |
assertEquals(inc(v1), h2.join()); |
1722 |
> |
assertEquals(1, r2.invocationCount); |
1723 |
|
} catch (CompletionException ok) { |
1724 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1725 |
< |
assertEquals(0, r.invocationCount); |
1724 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1725 |
> |
assertEquals(0, r2.invocationCount); |
1726 |
|
} |
1727 |
|
|
1728 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1729 |
< |
checkCompletedNormally(g, v1); |
1728 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1729 |
> |
checkCompletedNormally(f, v1); |
1730 |
|
}} |
1731 |
|
|
1732 |
|
/** |
1772 |
|
public void testApplyToEither_sourceCancelled1() { |
1773 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1774 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1775 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1776 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1777 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1778 |
|
{ |
1779 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1780 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1781 |
|
final IncFunction r = new IncFunction(); |
2155 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2156 |
– |
|
2157 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2158 |
– |
checkCompletedWithWrappedCancellationException(h); |
2159 |
– |
g.complete(v1); |
2160 |
– |
|
2161 |
– |
checkCancelled(f); |
2162 |
– |
assertEquals(0, r.invocationCount); |
2163 |
– |
checkCompletedNormally(g, v1); |
2164 |
– |
checkCompletedWithWrappedCancellationException(h); |
2165 |
– |
}} |
1782 |
|
|
1783 |
< |
public void testApplyToEither_sourceCancelled2() { |
2168 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2169 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2170 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2171 |
< |
{ |
2172 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2173 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2174 |
< |
final IncFunction r = new IncFunction(); |
1783 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1784 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1785 |
+ |
if (createIncomplete) { |
1786 |
+ |
checkIncomplete(h); |
1787 |
+ |
assertEquals(0, r.invocationCount); |
1788 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1789 |
+ |
} |
1790 |
|
|
2177 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1791 |
|
checkCompletedWithWrappedCancellationException(h); |
1792 |
< |
f.complete(v1); |
1792 |
> |
(!fFirst ? f : g).complete(v1); |
1793 |
|
|
2181 |
– |
checkCancelled(g); |
1794 |
|
assertEquals(0, r.invocationCount); |
1795 |
< |
checkCompletedNormally(f, v1); |
1795 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1796 |
> |
checkCancelled(fFirst ? f : g); |
1797 |
|
checkCompletedWithWrappedCancellationException(h); |
1798 |
|
}} |
1799 |
|
|
1800 |
< |
public void testApplyToEither_sourceCancelled3() { |
1800 |
> |
public void testApplyToEither_sourceCancelled2() { |
1801 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1802 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1803 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1804 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1805 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1806 |
|
{ |
1807 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1808 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1809 |
< |
final IncFunction r = new IncFunction(); |
1809 |
> |
final IncFunction r1 = new IncFunction(); |
1810 |
> |
final IncFunction r2 = new IncFunction(); |
1811 |
> |
final CFException ex = new CFException(); |
1812 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1813 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1814 |
|
|
1815 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1816 |
< |
f.complete(v1); |
1817 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1815 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1816 |
> |
if (fFirst) { |
1817 |
> |
f.complete(v1); |
1818 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1819 |
> |
} else { |
1820 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1821 |
> |
f.complete(v1); |
1822 |
> |
} |
1823 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1824 |
|
|
1825 |
|
// unspecified behavior |
2201 |
– |
Integer v; |
1826 |
|
try { |
1827 |
< |
assertEquals(inc(v1), h.join()); |
1828 |
< |
assertEquals(1, r.invocationCount); |
1827 |
> |
assertEquals(inc(v1), h1.join()); |
1828 |
> |
assertEquals(1, r1.invocationCount); |
1829 |
|
} catch (CompletionException ok) { |
1830 |
< |
checkCompletedWithWrappedCancellationException(h); |
1831 |
< |
assertEquals(0, r.invocationCount); |
1830 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1831 |
> |
assertEquals(0, r1.invocationCount); |
1832 |
|
} |
1833 |
|
|
2210 |
– |
checkCancelled(g); |
2211 |
– |
checkCompletedNormally(f, v1); |
2212 |
– |
}} |
2213 |
– |
|
2214 |
– |
public void testApplyToEither_sourceCancelled4() { |
2215 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2216 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2217 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2218 |
– |
{ |
2219 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2220 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2221 |
– |
final IncFunction r = new IncFunction(); |
2222 |
– |
|
2223 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2224 |
– |
g.complete(v1); |
2225 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2226 |
– |
|
2227 |
– |
// unspecified behavior |
2228 |
– |
Integer v; |
1834 |
|
try { |
1835 |
< |
assertEquals(inc(v1), h.join()); |
1836 |
< |
assertEquals(1, r.invocationCount); |
1835 |
> |
assertEquals(inc(v1), h2.join()); |
1836 |
> |
assertEquals(1, r2.invocationCount); |
1837 |
|
} catch (CompletionException ok) { |
1838 |
< |
checkCompletedWithWrappedCancellationException(h); |
1839 |
< |
assertEquals(0, r.invocationCount); |
1838 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1839 |
> |
assertEquals(0, r2.invocationCount); |
1840 |
|
} |
1841 |
|
|
1842 |
< |
checkCancelled(f); |
1843 |
< |
checkCompletedNormally(g, v1); |
1842 |
> |
checkCancelled(g); |
1843 |
> |
checkCompletedNormally(f, v1); |
1844 |
|
}} |
1845 |
|
|
1846 |
|
/** |
2156 |
|
{ |
2157 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2158 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2159 |
< |
final Noop r = new Noop(); |
2159 |
> |
final Noop r = new Noop(m); |
2160 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2161 |
|
|
2162 |
|
f.complete(v1); |
2177 |
|
{ |
2178 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2179 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2180 |
< |
final Noop r = new Noop(); |
2180 |
> |
final Noop r = new Noop(m); |
2181 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2182 |
|
|
2183 |
|
g.complete(v2); |
2198 |
|
{ |
2199 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2200 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2201 |
< |
final Noop r = new Noop(); |
2201 |
> |
final Noop r = new Noop(m); |
2202 |
|
|
2203 |
|
f.complete(v1); |
2204 |
|
g.complete(v2); |
2220 |
|
{ |
2221 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2222 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2223 |
< |
final Noop r = new Noop(); |
2223 |
> |
final Noop r = new Noop(m); |
2224 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2225 |
|
final CFException ex = new CFException(); |
2226 |
|
|
2240 |
|
{ |
2241 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2242 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2243 |
< |
final Noop r = new Noop(); |
2243 |
> |
final Noop r = new Noop(m); |
2244 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2245 |
|
final CFException ex = new CFException(); |
2246 |
|
|
2260 |
|
{ |
2261 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2262 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2263 |
< |
final Noop r = new Noop(); |
2263 |
> |
final Noop r = new Noop(m); |
2264 |
|
final CFException ex = new CFException(); |
2265 |
|
|
2266 |
|
g.completeExceptionally(ex); |
2287 |
|
{ |
2288 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2289 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2290 |
< |
final Noop r = new Noop(); |
2290 |
> |
final Noop r = new Noop(m); |
2291 |
|
final CFException ex = new CFException(); |
2292 |
|
|
2293 |
|
f.completeExceptionally(ex); |
2318 |
|
{ |
2319 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2320 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2321 |
< |
final FailingNoop r = new FailingNoop(); |
2321 |
> |
final FailingRunnable r = new FailingRunnable(); |
2322 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2323 |
|
|
2324 |
|
f.complete(v1); |
2335 |
|
{ |
2336 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2337 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2338 |
< |
final FailingNoop r = new FailingNoop(); |
2338 |
> |
final FailingRunnable r = new FailingRunnable(); |
2339 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2340 |
|
|
2341 |
|
g.complete(v2); |
2355 |
|
{ |
2356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2357 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2358 |
< |
final Noop r = new Noop(); |
2358 |
> |
final Noop r = new Noop(m); |
2359 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2360 |
|
|
2361 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2375 |
|
{ |
2376 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2377 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2378 |
< |
final Noop r = new Noop(); |
2378 |
> |
final Noop r = new Noop(m); |
2379 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2380 |
|
|
2381 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2395 |
|
{ |
2396 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2397 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2398 |
< |
final Noop r = new Noop(); |
2398 |
> |
final Noop r = new Noop(m); |
2399 |
|
|
2400 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2401 |
|
f.complete(v1); |
2422 |
|
{ |
2423 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2424 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2425 |
< |
final Noop r = new Noop(); |
2425 |
> |
final Noop r = new Noop(m); |
2426 |
|
|
2427 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2428 |
|
g.complete(v1); |
2445 |
|
/** |
2446 |
|
* thenCompose result completes normally after normal completion of source |
2447 |
|
*/ |
2448 |
< |
public void testThenCompose_normalCompletion1() { |
2448 |
> |
public void testThenCompose_normalCompletion() { |
2449 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2450 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2451 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2452 |
|
{ |
2453 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2454 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2455 |
+ |
if (!createIncomplete) f.complete(v1); |
2456 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2457 |
< |
f.complete(v1); |
2851 |
< |
checkCompletedNormally(g, inc(v1)); |
2852 |
< |
checkCompletedNormally(f, v1); |
2853 |
< |
assertEquals(1, r.invocationCount); |
2854 |
< |
}} |
2457 |
> |
if (createIncomplete) f.complete(v1); |
2458 |
|
|
2856 |
– |
public void testThenCompose_normalCompletion2() { |
2857 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2858 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2859 |
– |
{ |
2860 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2861 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2862 |
– |
f.complete(v1); |
2863 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2459 |
|
checkCompletedNormally(g, inc(v1)); |
2460 |
|
checkCompletedNormally(f, v1); |
2461 |
|
assertEquals(1, r.invocationCount); |
2465 |
|
* thenCompose result completes exceptionally after exceptional |
2466 |
|
* completion of source |
2467 |
|
*/ |
2468 |
< |
public void testThenCompose_exceptionalCompletion1() { |
2468 |
> |
public void testThenCompose_exceptionalCompletion() { |
2469 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2470 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2471 |
|
{ |
2472 |
|
final CFException ex = new CFException(); |
2473 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2474 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2475 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
2476 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2477 |
< |
f.completeExceptionally(ex); |
2881 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2882 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2883 |
< |
}} |
2477 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
2478 |
|
|
2885 |
– |
public void testThenCompose_exceptionalCompletion2() { |
2886 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2887 |
– |
{ |
2888 |
– |
final CFException ex = new CFException(); |
2889 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2890 |
– |
f.completeExceptionally(ex); |
2891 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2892 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2479 |
|
checkCompletedWithWrappedCFException(g, ex); |
2480 |
|
checkCompletedWithWrappedCFException(f, ex); |
2481 |
+ |
assertEquals(0, r.invocationCount); |
2482 |
|
}} |
2483 |
|
|
2484 |
|
/** |
2485 |
|
* thenCompose result completes exceptionally if action does |
2486 |
|
*/ |
2487 |
< |
public void testThenCompose_actionFailed1() { |
2487 |
> |
public void testThenCompose_actionFailed() { |
2488 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2489 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2490 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2491 |
|
{ |
2492 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2493 |
|
final FailingCompletableFutureFunction r |
2494 |
|
= new FailingCompletableFutureFunction(); |
2495 |
+ |
if (!createIncomplete) f.complete(v1); |
2496 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2497 |
< |
f.complete(v1); |
2909 |
< |
checkCompletedWithWrappedCFException(g); |
2910 |
< |
checkCompletedNormally(f, v1); |
2911 |
< |
}} |
2497 |
> |
if (createIncomplete) f.complete(v1); |
2498 |
|
|
2913 |
– |
public void testThenCompose_actionFailed2() { |
2914 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2915 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2916 |
– |
{ |
2917 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2918 |
– |
f.complete(v1); |
2919 |
– |
final FailingCompletableFutureFunction r |
2920 |
– |
= new FailingCompletableFutureFunction(); |
2921 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2499 |
|
checkCompletedWithWrappedCFException(g); |
2500 |
|
checkCompletedNormally(f, v1); |
2501 |
|
}} |
2503 |
|
/** |
2504 |
|
* thenCompose result completes exceptionally if source cancelled |
2505 |
|
*/ |
2506 |
< |
public void testThenCompose_sourceCancelled1() { |
2506 |
> |
public void testThenCompose_sourceCancelled() { |
2507 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2508 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2509 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2510 |
|
{ |
2511 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2512 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2513 |
+ |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2514 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2515 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2516 |
< |
checkCompletedWithWrappedCancellationException(g); |
2517 |
< |
checkCancelled(f); |
2518 |
< |
}} |
2515 |
> |
if (createIncomplete) { |
2516 |
> |
checkIncomplete(g); |
2517 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2518 |
> |
} |
2519 |
|
|
2941 |
– |
public void testThenCompose_sourceCancelled2() { |
2942 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2943 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2944 |
– |
{ |
2945 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2946 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2947 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2948 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2520 |
|
checkCompletedWithWrappedCancellationException(g); |
2521 |
|
checkCancelled(f); |
2522 |
|
}} |
2523 |
|
|
2953 |
– |
// asyncs |
2954 |
– |
|
2955 |
– |
/** |
2956 |
– |
* thenRunAsync result completes normally after normal completion of source |
2957 |
– |
*/ |
2958 |
– |
public void testThenRunAsync() { |
2959 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2960 |
– |
Noop r = new Noop(); |
2961 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2962 |
– |
f.complete(null); |
2963 |
– |
checkCompletedNormally(g, null); |
2964 |
– |
|
2965 |
– |
// reordered version |
2966 |
– |
f = new CompletableFuture<>(); |
2967 |
– |
f.complete(null); |
2968 |
– |
r = new Noop(); |
2969 |
– |
g = f.thenRunAsync(r); |
2970 |
– |
checkCompletedNormally(g, null); |
2971 |
– |
} |
2972 |
– |
|
2973 |
– |
/** |
2974 |
– |
* thenRunAsync result completes exceptionally after exceptional |
2975 |
– |
* completion of source |
2976 |
– |
*/ |
2977 |
– |
public void testThenRunAsync2() { |
2978 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2979 |
– |
Noop r = new Noop(); |
2980 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2981 |
– |
f.completeExceptionally(new CFException()); |
2982 |
– |
try { |
2983 |
– |
g.join(); |
2984 |
– |
shouldThrow(); |
2985 |
– |
} catch (CompletionException success) {} |
2986 |
– |
checkCompletedWithWrappedCFException(g); |
2987 |
– |
} |
2988 |
– |
|
2989 |
– |
/** |
2990 |
– |
* thenRunAsync result completes exceptionally if action does |
2991 |
– |
*/ |
2992 |
– |
public void testThenRunAsync3() { |
2993 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2994 |
– |
FailingNoop r = new FailingNoop(); |
2995 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2996 |
– |
f.complete(null); |
2997 |
– |
checkCompletedWithWrappedCFException(g); |
2998 |
– |
} |
2999 |
– |
|
3000 |
– |
/** |
3001 |
– |
* thenRunAsync result completes exceptionally if source cancelled |
3002 |
– |
*/ |
3003 |
– |
public void testThenRunAsync4() { |
3004 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3005 |
– |
Noop r = new Noop(); |
3006 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3007 |
– |
assertTrue(f.cancel(true)); |
3008 |
– |
checkCompletedWithWrappedCancellationException(g); |
3009 |
– |
} |
3010 |
– |
|
3011 |
– |
/** |
3012 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3013 |
– |
*/ |
3014 |
– |
public void testThenApplyAsync() { |
3015 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3016 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3017 |
– |
f.complete(one); |
3018 |
– |
checkCompletedNormally(g, two); |
3019 |
– |
} |
3020 |
– |
|
3021 |
– |
/** |
3022 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3023 |
– |
* completion of source |
3024 |
– |
*/ |
3025 |
– |
public void testThenApplyAsync2() { |
3026 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3027 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3028 |
– |
f.completeExceptionally(new CFException()); |
3029 |
– |
checkCompletedWithWrappedCFException(g); |
3030 |
– |
} |
3031 |
– |
|
3032 |
– |
/** |
3033 |
– |
* thenApplyAsync result completes exceptionally if action does |
3034 |
– |
*/ |
3035 |
– |
public void testThenApplyAsync3() { |
3036 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3037 |
– |
FailingFunction r = new FailingFunction(); |
3038 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
3039 |
– |
f.complete(null); |
3040 |
– |
checkCompletedWithWrappedCFException(g); |
3041 |
– |
} |
3042 |
– |
|
3043 |
– |
/** |
3044 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3045 |
– |
*/ |
3046 |
– |
public void testThenApplyAsync4() { |
3047 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3048 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3049 |
– |
assertTrue(f.cancel(true)); |
3050 |
– |
checkCompletedWithWrappedCancellationException(g); |
3051 |
– |
} |
3052 |
– |
|
3053 |
– |
/** |
3054 |
– |
* thenAcceptAsync result completes normally after normal |
3055 |
– |
* completion of source |
3056 |
– |
*/ |
3057 |
– |
public void testThenAcceptAsync() { |
3058 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3059 |
– |
IncAction r = new IncAction(); |
3060 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3061 |
– |
f.complete(one); |
3062 |
– |
checkCompletedNormally(g, null); |
3063 |
– |
assertEquals(r.value, (Integer) 2); |
3064 |
– |
} |
3065 |
– |
|
3066 |
– |
/** |
3067 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3068 |
– |
* completion of source |
3069 |
– |
*/ |
3070 |
– |
public void testThenAcceptAsync2() { |
3071 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3072 |
– |
IncAction r = new IncAction(); |
3073 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3074 |
– |
f.completeExceptionally(new CFException()); |
3075 |
– |
checkCompletedWithWrappedCFException(g); |
3076 |
– |
} |
3077 |
– |
|
3078 |
– |
/** |
3079 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3080 |
– |
*/ |
3081 |
– |
public void testThenAcceptAsync3() { |
3082 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3083 |
– |
FailingConsumer r = new FailingConsumer(); |
3084 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3085 |
– |
f.complete(null); |
3086 |
– |
checkCompletedWithWrappedCFException(g); |
3087 |
– |
} |
3088 |
– |
|
3089 |
– |
/** |
3090 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3091 |
– |
*/ |
3092 |
– |
public void testThenAcceptAsync4() { |
3093 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3094 |
– |
IncAction r = new IncAction(); |
3095 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3096 |
– |
assertTrue(f.cancel(true)); |
3097 |
– |
checkCompletedWithWrappedCancellationException(g); |
3098 |
– |
} |
3099 |
– |
|
3100 |
– |
// async with explicit executors |
3101 |
– |
|
3102 |
– |
/** |
3103 |
– |
* thenRunAsync result completes normally after normal completion of source |
3104 |
– |
*/ |
3105 |
– |
public void testThenRunAsyncE() { |
3106 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3107 |
– |
Noop r = new Noop(); |
3108 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3109 |
– |
f.complete(null); |
3110 |
– |
checkCompletedNormally(g, null); |
3111 |
– |
|
3112 |
– |
// reordered version |
3113 |
– |
f = new CompletableFuture<>(); |
3114 |
– |
f.complete(null); |
3115 |
– |
r = new Noop(); |
3116 |
– |
g = f.thenRunAsync(r, new ThreadExecutor()); |
3117 |
– |
checkCompletedNormally(g, null); |
3118 |
– |
} |
3119 |
– |
|
3120 |
– |
/** |
3121 |
– |
* thenRunAsync result completes exceptionally after exceptional |
3122 |
– |
* completion of source |
3123 |
– |
*/ |
3124 |
– |
public void testThenRunAsync2E() { |
3125 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3126 |
– |
Noop r = new Noop(); |
3127 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3128 |
– |
f.completeExceptionally(new CFException()); |
3129 |
– |
try { |
3130 |
– |
g.join(); |
3131 |
– |
shouldThrow(); |
3132 |
– |
} catch (CompletionException success) {} |
3133 |
– |
checkCompletedWithWrappedCFException(g); |
3134 |
– |
} |
3135 |
– |
|
3136 |
– |
/** |
3137 |
– |
* thenRunAsync result completes exceptionally if action does |
3138 |
– |
*/ |
3139 |
– |
public void testThenRunAsync3E() { |
3140 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3141 |
– |
FailingNoop r = new FailingNoop(); |
3142 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3143 |
– |
f.complete(null); |
3144 |
– |
checkCompletedWithWrappedCFException(g); |
3145 |
– |
} |
3146 |
– |
|
3147 |
– |
/** |
3148 |
– |
* thenRunAsync result completes exceptionally if source cancelled |
3149 |
– |
*/ |
3150 |
– |
public void testThenRunAsync4E() { |
3151 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3152 |
– |
Noop r = new Noop(); |
3153 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3154 |
– |
assertTrue(f.cancel(true)); |
3155 |
– |
checkCompletedWithWrappedCancellationException(g); |
3156 |
– |
} |
3157 |
– |
|
3158 |
– |
/** |
3159 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3160 |
– |
*/ |
3161 |
– |
public void testThenApplyAsyncE() { |
3162 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3163 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3164 |
– |
f.complete(one); |
3165 |
– |
checkCompletedNormally(g, two); |
3166 |
– |
} |
3167 |
– |
|
3168 |
– |
/** |
3169 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3170 |
– |
* completion of source |
3171 |
– |
*/ |
3172 |
– |
public void testThenApplyAsync2E() { |
3173 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3174 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3175 |
– |
f.completeExceptionally(new CFException()); |
3176 |
– |
checkCompletedWithWrappedCFException(g); |
3177 |
– |
} |
3178 |
– |
|
3179 |
– |
/** |
3180 |
– |
* thenApplyAsync result completes exceptionally if action does |
3181 |
– |
*/ |
3182 |
– |
public void testThenApplyAsync3E() { |
3183 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3184 |
– |
FailingFunction r = new FailingFunction(); |
3185 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
3186 |
– |
f.complete(null); |
3187 |
– |
checkCompletedWithWrappedCFException(g); |
3188 |
– |
} |
3189 |
– |
|
3190 |
– |
/** |
3191 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3192 |
– |
*/ |
3193 |
– |
public void testThenApplyAsync4E() { |
3194 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3195 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3196 |
– |
assertTrue(f.cancel(true)); |
3197 |
– |
checkCompletedWithWrappedCancellationException(g); |
3198 |
– |
} |
3199 |
– |
|
3200 |
– |
/** |
3201 |
– |
* thenAcceptAsync result completes normally after normal |
3202 |
– |
* completion of source |
3203 |
– |
*/ |
3204 |
– |
public void testThenAcceptAsyncE() { |
3205 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3206 |
– |
IncAction r = new IncAction(); |
3207 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3208 |
– |
f.complete(one); |
3209 |
– |
checkCompletedNormally(g, null); |
3210 |
– |
assertEquals(r.value, (Integer) 2); |
3211 |
– |
} |
3212 |
– |
|
3213 |
– |
/** |
3214 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3215 |
– |
* completion of source |
3216 |
– |
*/ |
3217 |
– |
public void testThenAcceptAsync2E() { |
3218 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3219 |
– |
IncAction r = new IncAction(); |
3220 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3221 |
– |
f.completeExceptionally(new CFException()); |
3222 |
– |
checkCompletedWithWrappedCFException(g); |
3223 |
– |
} |
3224 |
– |
|
3225 |
– |
/** |
3226 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3227 |
– |
*/ |
3228 |
– |
public void testThenAcceptAsync3E() { |
3229 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3230 |
– |
FailingConsumer r = new FailingConsumer(); |
3231 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3232 |
– |
f.complete(null); |
3233 |
– |
checkCompletedWithWrappedCFException(g); |
3234 |
– |
} |
3235 |
– |
|
3236 |
– |
/** |
3237 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3238 |
– |
*/ |
3239 |
– |
public void testThenAcceptAsync4E() { |
3240 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3241 |
– |
IncAction r = new IncAction(); |
3242 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3243 |
– |
assertTrue(f.cancel(true)); |
3244 |
– |
checkCompletedWithWrappedCancellationException(g); |
3245 |
– |
} |
3246 |
– |
|
2524 |
|
// other static methods |
2525 |
|
|
2526 |
|
/** |