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 |
< |
} |
1020 |
> |
}} |
1021 |
|
|
1022 |
|
/** |
1023 |
< |
* thenRun result completes exceptionally if action does |
1023 |
> |
* thenRun result completes exceptionally if source cancelled |
1024 |
|
*/ |
1025 |
< |
public void testThenRun3() { |
1026 |
< |
CompletableFuture<Integer> f; |
1027 |
< |
CompletableFuture<Void> g; |
1028 |
< |
FailingNoop r; |
1029 |
< |
|
1030 |
< |
f = new CompletableFuture<>(); |
1031 |
< |
g = f.thenRun(r = new FailingNoop()); |
1032 |
< |
f.complete(null); |
1033 |
< |
checkCompletedWithWrappedCFException(g); |
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 |
|
|
1039 |
< |
f = new CompletableFuture<>(); |
1040 |
< |
f.complete(null); |
1041 |
< |
g = f.thenRun(r = new FailingNoop()); |
1042 |
< |
checkCompletedWithWrappedCFException(g); |
1021 |
< |
} |
1039 |
> |
checkCompletedWithWrappedCancellationException(g); |
1040 |
> |
checkCancelled(f); |
1041 |
> |
assertEquals(0, r.invocationCount); |
1042 |
> |
}} |
1043 |
|
|
1044 |
|
/** |
1045 |
< |
* thenRun result completes exceptionally if source cancelled |
1045 |
> |
* thenRun result completes exceptionally if action does |
1046 |
|
*/ |
1047 |
< |
public void testThenRun4() { |
1048 |
< |
CompletableFuture<Integer> f; |
1049 |
< |
CompletableFuture<Void> g; |
1050 |
< |
Noop r; |
1051 |
< |
|
1052 |
< |
f = new CompletableFuture<>(); |
1053 |
< |
g = f.thenRun(r = new Noop()); |
1054 |
< |
assertTrue(f.cancel(true)); |
1055 |
< |
checkCompletedWithWrappedCancellationException(g); |
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 |
|
|
1061 |
< |
f = new CompletableFuture<>(); |
1062 |
< |
assertTrue(f.cancel(true)); |
1063 |
< |
g = f.thenRun(r = new Noop()); |
1039 |
< |
checkCompletedWithWrappedCancellationException(g); |
1040 |
< |
} |
1061 |
> |
checkCompletedWithWrappedCFException(g); |
1062 |
> |
checkCompletedNormally(f, v1); |
1063 |
> |
}} |
1064 |
|
|
1065 |
|
/** |
1066 |
|
* thenApply result completes normally after normal completion of source |
1067 |
|
*/ |
1068 |
< |
public void testThenApply() { |
1069 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1070 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1071 |
< |
f.complete(one); |
1072 |
< |
checkCompletedNormally(g, two); |
1073 |
< |
} |
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 }) |
1072 |
> |
{ |
1073 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
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 |
> |
} |
1081 |
> |
|
1082 |
> |
checkCompletedNormally(g, inc(v1)); |
1083 |
> |
checkCompletedNormally(f, v1); |
1084 |
> |
assertEquals(1, r.invocationCount); |
1085 |
> |
}} |
1086 |
|
|
1087 |
|
/** |
1088 |
|
* thenApply result completes exceptionally after exceptional |
1089 |
|
* completion of source |
1090 |
|
*/ |
1091 |
< |
public void testThenApply2() { |
1092 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1093 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1094 |
< |
f.completeExceptionally(new CFException()); |
1095 |
< |
checkCompletedWithWrappedCFException(g); |
1096 |
< |
} |
1091 |
> |
public void testThenApply_exceptionalCompletion() { |
1092 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1093 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1094 |
> |
{ |
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 |
< |
/** |
1106 |
< |
* thenApply result completes exceptionally if action does |
1107 |
< |
*/ |
1108 |
< |
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 |
< |
} |
1105 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1106 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1107 |
> |
assertEquals(0, r.invocationCount); |
1108 |
> |
}} |
1109 |
|
|
1110 |
|
/** |
1111 |
|
* thenApply result completes exceptionally if source cancelled |
1112 |
|
*/ |
1113 |
< |
public void testThenApply4() { |
1114 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1115 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1116 |
< |
assertTrue(f.cancel(true)); |
1113 |
> |
public void testThenApply_sourceCancelled() { |
1114 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
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 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 |
|
checkCompletedWithWrappedCancellationException(g); |
1128 |
< |
} |
1128 |
> |
checkCancelled(f); |
1129 |
> |
assertEquals(0, r.invocationCount); |
1130 |
> |
}} |
1131 |
> |
|
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 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(g); |
1150 |
> |
checkCompletedNormally(f, v1); |
1151 |
> |
}} |
1152 |
|
|
1153 |
|
/** |
1154 |
|
* thenAccept result completes normally after normal completion of source |
1155 |
|
*/ |
1156 |
< |
public void testThenAccept() { |
1157 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1158 |
< |
IncAction r = new IncAction(); |
1159 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1160 |
< |
f.complete(one); |
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 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 |
|
checkCompletedNormally(g, null); |
1171 |
< |
assertEquals(r.value, (Integer) 2); |
1172 |
< |
} |
1171 |
> |
checkCompletedNormally(f, v1); |
1172 |
> |
assertEquals(1, r.invocationCount); |
1173 |
> |
assertEquals(inc(v1), r.value); |
1174 |
> |
}} |
1175 |
|
|
1176 |
|
/** |
1177 |
|
* thenAccept result completes exceptionally after exceptional |
1178 |
|
* completion of source |
1179 |
|
*/ |
1180 |
< |
public void testThenAccept2() { |
1181 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1182 |
< |
IncAction r = new IncAction(); |
1183 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1184 |
< |
f.completeExceptionally(new CFException()); |
1185 |
< |
checkCompletedWithWrappedCFException(g); |
1186 |
< |
} |
1180 |
> |
public void testThenAccept_exceptionalCompletion() { |
1181 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1182 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1183 |
> |
{ |
1184 |
> |
final CFException ex = new CFException(); |
1185 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
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(g, ex); |
1195 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1196 |
> |
assertEquals(0, r.invocationCount); |
1197 |
> |
}} |
1198 |
|
|
1199 |
|
/** |
1200 |
|
* thenAccept result completes exceptionally if action does |
1201 |
|
*/ |
1202 |
< |
public void testThenAccept3() { |
1203 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1204 |
< |
FailingConsumer r = new FailingConsumer(); |
1205 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1206 |
< |
f.complete(one); |
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 }) |
1206 |
> |
{ |
1207 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
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(g); |
1217 |
< |
assertEquals(1, r.invocationCount); |
1218 |
< |
} |
1217 |
> |
checkCompletedNormally(f, v1); |
1218 |
> |
}} |
1219 |
|
|
1220 |
|
/** |
1221 |
|
* thenAccept result completes exceptionally if source cancelled |
1222 |
|
*/ |
1223 |
< |
public void testThenAccept4() { |
1224 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1225 |
< |
IncAction r = new IncAction(); |
1226 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1227 |
< |
assertTrue(f.cancel(true)); |
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 }) |
1227 |
> |
{ |
1228 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
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(g); |
1238 |
< |
} |
1238 |
> |
checkCancelled(f); |
1239 |
> |
assertEquals(0, r.invocationCount); |
1240 |
> |
}} |
1241 |
|
|
1242 |
|
/** |
1243 |
|
* thenCombine result completes normally after normal completion |
1244 |
|
* of sources |
1245 |
|
*/ |
1246 |
< |
public void testThenCombine_normalCompletion1() { |
1246 |
> |
public void testThenCombine_normalCompletion() { |
1247 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1248 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
1249 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1137 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1250 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1251 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1252 |
< |
|
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(); |
1144 |
– |
CompletableFuture<Integer> h = null; |
1145 |
– |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1256 |
|
|
1257 |
< |
if (fFirst) |
1258 |
< |
f.complete(v1); |
1259 |
< |
else |
1260 |
< |
g.complete(v2); |
1261 |
< |
if (createIncomplete) checkIncomplete(h); |
1262 |
< |
assertEquals(0, r.invocationCount); |
1263 |
< |
if (!fFirst) |
1264 |
< |
f.complete(v1); |
1265 |
< |
else |
1156 |
< |
g.complete(v2); |
1157 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
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 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1268 |
|
checkCompletedNormally(f, v1); |
1269 |
|
checkCompletedNormally(g, v2); |
1270 |
|
assertEquals(1, r.invocationCount); |
1271 |
< |
} |
1164 |
< |
} |
1271 |
> |
}} |
1272 |
|
|
1273 |
|
/** |
1274 |
|
* thenCombine result completes exceptionally after exceptional |
1275 |
|
* completion of either source |
1276 |
|
*/ |
1277 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1277 |
> |
public void testThenCombine_exceptionalCompletion() { |
1278 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1279 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1280 |
< |
|
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<>(); |
1176 |
– |
final SubtractFunction r = new SubtractFunction(); |
1177 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1285 |
|
final CFException ex = new CFException(); |
1179 |
– |
|
1180 |
– |
f.completeExceptionally(ex); |
1181 |
– |
checkIncomplete(h); |
1182 |
– |
g.complete(v1); |
1183 |
– |
|
1184 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1185 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1186 |
– |
assertEquals(0, r.invocationCount); |
1187 |
– |
checkCompletedNormally(g, v1); |
1188 |
– |
} |
1189 |
– |
} |
1190 |
– |
|
1191 |
– |
public void testThenCombine_exceptionalCompletion2() { |
1192 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1193 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1194 |
– |
|
1195 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1196 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1286 |
|
final SubtractFunction r = new SubtractFunction(); |
1198 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1199 |
– |
final CFException ex = new CFException(); |
1200 |
– |
|
1201 |
– |
g.completeExceptionally(ex); |
1202 |
– |
checkIncomplete(h); |
1203 |
– |
f.complete(v1); |
1204 |
– |
|
1205 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1206 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1207 |
– |
assertEquals(0, r.invocationCount); |
1208 |
– |
checkCompletedNormally(f, v1); |
1209 |
– |
} |
1210 |
– |
} |
1287 |
|
|
1288 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1289 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1290 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1215 |
< |
|
1216 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1217 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1218 |
< |
final SubtractFunction r = new SubtractFunction(); |
1219 |
< |
final CFException ex = new CFException(); |
1220 |
< |
|
1221 |
< |
g.completeExceptionally(ex); |
1222 |
< |
f.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 |
< |
|
1293 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1294 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1227 |
< |
assertEquals(0, r.invocationCount); |
1228 |
< |
checkCompletedNormally(f, v1); |
1292 |
> |
if (createIncomplete) { |
1293 |
> |
checkIncomplete(h); |
1294 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1295 |
|
} |
1230 |
– |
} |
1231 |
– |
|
1232 |
– |
public void testThenCombine_exceptionalCompletion4() { |
1233 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1234 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1235 |
– |
|
1236 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1237 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1238 |
– |
final SubtractFunction r = new SubtractFunction(); |
1239 |
– |
final CFException ex = new CFException(); |
1240 |
– |
|
1241 |
– |
f.completeExceptionally(ex); |
1242 |
– |
g.complete(v1); |
1243 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1296 |
|
|
1297 |
|
checkCompletedWithWrappedCFException(h, ex); |
1246 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1298 |
|
assertEquals(0, r.invocationCount); |
1299 |
< |
checkCompletedNormally(g, v1); |
1300 |
< |
} |
1301 |
< |
} |
1299 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1300 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1301 |
> |
}} |
1302 |
|
|
1303 |
|
/** |
1304 |
|
* thenCombine result completes exceptionally if action does |
1305 |
|
*/ |
1306 |
< |
public void testThenCombine_actionFailed1() { |
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 |
< |
|
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 FailingBiFunction r = new FailingBiFunction(); |
1315 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1316 |
|
|
1317 |
< |
f.complete(v1); |
1318 |
< |
checkIncomplete(h); |
1319 |
< |
g.complete(v2); |
1320 |
< |
|
1321 |
< |
checkCompletedWithWrappedCFException(h); |
1322 |
< |
checkCompletedNormally(f, v1); |
1271 |
< |
checkCompletedNormally(g, v2); |
1317 |
> |
if (fFirst) { |
1318 |
> |
f.complete(v1); |
1319 |
> |
g.complete(v2); |
1320 |
> |
} else { |
1321 |
> |
g.complete(v2); |
1322 |
> |
f.complete(v1); |
1323 |
|
} |
1273 |
– |
} |
1274 |
– |
|
1275 |
– |
public void testThenCombine_actionFailed2() { |
1276 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1277 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1278 |
– |
for (Integer v2 : new Integer[] { 2, null }) { |
1279 |
– |
|
1280 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1281 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1282 |
– |
final FailingBiFunction r = new FailingBiFunction(); |
1283 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1284 |
– |
|
1285 |
– |
g.complete(v2); |
1286 |
– |
checkIncomplete(h); |
1287 |
– |
f.complete(v1); |
1324 |
|
|
1325 |
|
checkCompletedWithWrappedCFException(h); |
1326 |
|
checkCompletedNormally(f, v1); |
1327 |
|
checkCompletedNormally(g, v2); |
1328 |
< |
} |
1293 |
< |
} |
1328 |
> |
}} |
1329 |
|
|
1330 |
|
/** |
1331 |
|
* thenCombine result completes exceptionally if either source cancelled |
1332 |
|
*/ |
1333 |
< |
public void testThenCombine_sourceCancelled1() { |
1299 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1300 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1301 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1302 |
< |
|
1303 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1304 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1305 |
< |
final SubtractFunction r = new SubtractFunction(); |
1306 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1307 |
< |
|
1308 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1309 |
< |
checkIncomplete(h); |
1310 |
< |
g.complete(v1); |
1311 |
< |
|
1312 |
< |
checkCompletedWithWrappedCancellationException(h); |
1313 |
< |
checkCancelled(f); |
1314 |
< |
assertEquals(0, r.invocationCount); |
1315 |
< |
checkCompletedNormally(g, v1); |
1316 |
< |
} |
1317 |
< |
} |
1318 |
< |
|
1319 |
< |
public void testThenCombine_sourceCancelled2() { |
1320 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1321 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1322 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1323 |
< |
|
1324 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1325 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1326 |
< |
final SubtractFunction r = new SubtractFunction(); |
1327 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1328 |
< |
|
1329 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1330 |
< |
checkIncomplete(h); |
1331 |
< |
f.complete(v1); |
1332 |
< |
|
1333 |
< |
checkCompletedWithWrappedCancellationException(h); |
1334 |
< |
checkCancelled(g); |
1335 |
< |
assertEquals(0, r.invocationCount); |
1336 |
< |
checkCompletedNormally(f, v1); |
1337 |
< |
} |
1338 |
< |
} |
1339 |
< |
|
1340 |
< |
public void testThenCombine_sourceCancelled3() { |
1333 |
> |
public void testThenCombine_sourceCancelled() { |
1334 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1335 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1336 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1337 |
< |
|
1336 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1337 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1338 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1339 |
> |
{ |
1340 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1341 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1342 |
|
final SubtractFunction r = new SubtractFunction(); |
1343 |
|
|
1344 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1345 |
< |
f.complete(v1); |
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 |
< |
|
1349 |
< |
checkCompletedWithWrappedCancellationException(h); |
1350 |
< |
checkCancelled(g); |
1355 |
< |
assertEquals(0, r.invocationCount); |
1356 |
< |
checkCompletedNormally(f, v1); |
1348 |
> |
if (createIncomplete) { |
1349 |
> |
checkIncomplete(h); |
1350 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1351 |
|
} |
1358 |
– |
} |
1359 |
– |
|
1360 |
– |
public void testThenCombine_sourceCancelled4() { |
1361 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1362 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1363 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1364 |
– |
|
1365 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1366 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1367 |
– |
final SubtractFunction r = new SubtractFunction(); |
1368 |
– |
|
1369 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1370 |
– |
g.complete(v1); |
1371 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1352 |
|
|
1353 |
|
checkCompletedWithWrappedCancellationException(h); |
1354 |
< |
checkCancelled(f); |
1354 |
> |
checkCancelled(!fFirst ? f : g); |
1355 |
|
assertEquals(0, r.invocationCount); |
1356 |
< |
checkCompletedNormally(g, v1); |
1357 |
< |
} |
1378 |
< |
} |
1356 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1357 |
> |
}} |
1358 |
|
|
1359 |
|
/** |
1360 |
|
* thenAcceptBoth result completes normally after normal |
1361 |
|
* completion of sources |
1362 |
|
*/ |
1363 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1385 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1386 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1387 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1388 |
< |
|
1389 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1390 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1391 |
< |
final SubtractAction r = new SubtractAction(); |
1392 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1393 |
< |
|
1394 |
< |
f.complete(v1); |
1395 |
< |
checkIncomplete(h); |
1396 |
< |
assertEquals(0, r.invocationCount); |
1397 |
< |
g.complete(v2); |
1398 |
< |
|
1399 |
< |
checkCompletedNormally(h, null); |
1400 |
< |
assertEquals(subtract(v1, v2), r.value); |
1401 |
< |
checkCompletedNormally(f, v1); |
1402 |
< |
checkCompletedNormally(g, v2); |
1403 |
< |
} |
1404 |
< |
} |
1405 |
< |
|
1406 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1407 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1408 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1409 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1410 |
< |
|
1411 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1412 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1413 |
< |
final SubtractAction r = new SubtractAction(); |
1414 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1415 |
< |
|
1416 |
< |
g.complete(v2); |
1417 |
< |
checkIncomplete(h); |
1418 |
< |
assertEquals(0, r.invocationCount); |
1419 |
< |
f.complete(v1); |
1420 |
< |
|
1421 |
< |
checkCompletedNormally(h, null); |
1422 |
< |
assertEquals(subtract(v1, v2), r.value); |
1423 |
< |
checkCompletedNormally(f, v1); |
1424 |
< |
checkCompletedNormally(g, v2); |
1425 |
< |
} |
1426 |
< |
} |
1427 |
< |
|
1428 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
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 |
< |
|
1368 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1369 |
> |
{ |
1370 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1371 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1372 |
|
final SubtractAction r = new SubtractAction(); |
1373 |
|
|
1374 |
< |
g.complete(v2); |
1375 |
< |
f.complete(v1); |
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 |
< |
|
1379 |
< |
checkCompletedNormally(h, null); |
1380 |
< |
assertEquals(subtract(v1, v2), r.value); |
1381 |
< |
checkCompletedNormally(f, v1); |
1444 |
< |
checkCompletedNormally(g, v2); |
1378 |
> |
if (createIncomplete) { |
1379 |
> |
checkIncomplete(h); |
1380 |
> |
assertEquals(0, r.invocationCount); |
1381 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1382 |
|
} |
1446 |
– |
} |
1447 |
– |
|
1448 |
– |
public void testThenAcceptBoth_normalCompletion4() { |
1449 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1450 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1451 |
– |
for (Integer v2 : new Integer[] { 2, null }) { |
1452 |
– |
|
1453 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1454 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1455 |
– |
final SubtractAction r = new SubtractAction(); |
1456 |
– |
|
1457 |
– |
f.complete(v1); |
1458 |
– |
g.complete(v2); |
1459 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1383 |
|
|
1384 |
|
checkCompletedNormally(h, null); |
1385 |
|
assertEquals(subtract(v1, v2), r.value); |
1386 |
|
checkCompletedNormally(f, v1); |
1387 |
|
checkCompletedNormally(g, v2); |
1388 |
< |
} |
1466 |
< |
} |
1388 |
> |
}} |
1389 |
|
|
1390 |
|
/** |
1391 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1392 |
|
* completion of either source |
1393 |
|
*/ |
1394 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1394 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1395 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1396 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1397 |
< |
|
1398 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1399 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1478 |
< |
final SubtractAction r = new SubtractAction(); |
1479 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1480 |
< |
final CFException ex = new CFException(); |
1481 |
< |
|
1482 |
< |
f.completeExceptionally(ex); |
1483 |
< |
checkIncomplete(h); |
1484 |
< |
g.complete(v1); |
1485 |
< |
|
1486 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1487 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1488 |
< |
assertEquals(0, r.invocationCount); |
1489 |
< |
checkCompletedNormally(g, v1); |
1490 |
< |
} |
1491 |
< |
} |
1492 |
< |
|
1493 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1494 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1495 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1496 |
< |
|
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<>(); |
1499 |
– |
final SubtractAction r = new SubtractAction(); |
1500 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1402 |
|
final CFException ex = new CFException(); |
1502 |
– |
|
1503 |
– |
g.completeExceptionally(ex); |
1504 |
– |
checkIncomplete(h); |
1505 |
– |
f.complete(v1); |
1506 |
– |
|
1507 |
– |
checkCompletedWithWrappedCFException(h, ex); |
1508 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1509 |
– |
assertEquals(0, r.invocationCount); |
1510 |
– |
checkCompletedNormally(f, v1); |
1511 |
– |
} |
1512 |
– |
} |
1513 |
– |
|
1514 |
– |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1515 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1516 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1517 |
– |
|
1518 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1519 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
|
final SubtractAction r = new SubtractAction(); |
1521 |
– |
final CFException ex = new CFException(); |
1404 |
|
|
1405 |
< |
g.completeExceptionally(ex); |
1406 |
< |
f.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 |
< |
|
1410 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1411 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1529 |
< |
assertEquals(0, r.invocationCount); |
1530 |
< |
checkCompletedNormally(f, v1); |
1409 |
> |
if (createIncomplete) { |
1410 |
> |
checkIncomplete(h); |
1411 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1412 |
|
} |
1532 |
– |
} |
1533 |
– |
|
1534 |
– |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1535 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1536 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1537 |
– |
|
1538 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1539 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1540 |
– |
final SubtractAction r = new SubtractAction(); |
1541 |
– |
final CFException ex = new CFException(); |
1542 |
– |
|
1543 |
– |
f.completeExceptionally(ex); |
1544 |
– |
g.complete(v1); |
1545 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1413 |
|
|
1414 |
|
checkCompletedWithWrappedCFException(h, ex); |
1548 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1415 |
|
assertEquals(0, r.invocationCount); |
1416 |
< |
checkCompletedNormally(g, v1); |
1417 |
< |
} |
1418 |
< |
} |
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() { |
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 |
< |
|
1427 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1428 |
> |
{ |
1429 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1430 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1431 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1432 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1433 |
|
|
1434 |
< |
f.complete(v1); |
1435 |
< |
checkIncomplete(h); |
1436 |
< |
g.complete(v2); |
1437 |
< |
|
1438 |
< |
checkCompletedWithWrappedCFException(h); |
1439 |
< |
checkCompletedNormally(f, v1); |
1573 |
< |
checkCompletedNormally(g, v2); |
1434 |
> |
if (fFirst) { |
1435 |
> |
f.complete(v1); |
1436 |
> |
g.complete(v2); |
1437 |
> |
} else { |
1438 |
> |
g.complete(v2); |
1439 |
> |
f.complete(v1); |
1440 |
|
} |
1575 |
– |
} |
1576 |
– |
|
1577 |
– |
public void testThenAcceptBoth_actionFailed2() { |
1578 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1579 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1580 |
– |
for (Integer v2 : new Integer[] { 2, null }) { |
1581 |
– |
|
1582 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1583 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1584 |
– |
final FailingBiConsumer r = new FailingBiConsumer(); |
1585 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1586 |
– |
|
1587 |
– |
g.complete(v2); |
1588 |
– |
checkIncomplete(h); |
1589 |
– |
f.complete(v1); |
1441 |
|
|
1442 |
|
checkCompletedWithWrappedCFException(h); |
1443 |
|
checkCompletedNormally(f, v1); |
1444 |
|
checkCompletedNormally(g, v2); |
1445 |
< |
} |
1595 |
< |
} |
1445 |
> |
}} |
1446 |
|
|
1447 |
|
/** |
1448 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1449 |
|
*/ |
1450 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1601 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1602 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1603 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1604 |
< |
|
1605 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1606 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1607 |
< |
final SubtractAction r = new SubtractAction(); |
1608 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1609 |
< |
|
1610 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1611 |
< |
checkIncomplete(h); |
1612 |
< |
g.complete(v1); |
1613 |
< |
|
1614 |
< |
checkCompletedWithWrappedCancellationException(h); |
1615 |
< |
checkCancelled(f); |
1616 |
< |
assertEquals(0, r.invocationCount); |
1617 |
< |
checkCompletedNormally(g, v1); |
1618 |
< |
} |
1619 |
< |
} |
1620 |
< |
|
1621 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1450 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1451 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1452 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1453 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1454 |
< |
|
1455 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1456 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1628 |
< |
final SubtractAction r = new SubtractAction(); |
1629 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1630 |
< |
|
1631 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1632 |
< |
checkIncomplete(h); |
1633 |
< |
f.complete(v1); |
1634 |
< |
|
1635 |
< |
checkCompletedWithWrappedCancellationException(h); |
1636 |
< |
checkCancelled(g); |
1637 |
< |
assertEquals(0, r.invocationCount); |
1638 |
< |
checkCompletedNormally(f, v1); |
1639 |
< |
} |
1640 |
< |
} |
1641 |
< |
|
1642 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1643 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1644 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1645 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1646 |
< |
|
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(g.cancel(mayInterruptIfRunning)); |
1462 |
< |
f.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 |
< |
|
1466 |
< |
checkCompletedWithWrappedCancellationException(h); |
1467 |
< |
checkCancelled(g); |
1657 |
< |
assertEquals(0, r.invocationCount); |
1658 |
< |
checkCompletedNormally(f, v1); |
1465 |
> |
if (createIncomplete) { |
1466 |
> |
checkIncomplete(h); |
1467 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1468 |
|
} |
1660 |
– |
} |
1661 |
– |
|
1662 |
– |
public void testThenAcceptBoth_sourceCancelled4() { |
1663 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1664 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1665 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1666 |
– |
|
1667 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1668 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1669 |
– |
final SubtractAction r = new SubtractAction(); |
1670 |
– |
|
1671 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1672 |
– |
g.complete(v1); |
1673 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1469 |
|
|
1470 |
|
checkCompletedWithWrappedCancellationException(h); |
1471 |
< |
checkCancelled(f); |
1471 |
> |
checkCancelled(!fFirst ? f : g); |
1472 |
|
assertEquals(0, r.invocationCount); |
1473 |
< |
checkCompletedNormally(g, v1); |
1474 |
< |
} |
1680 |
< |
} |
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() { |
1687 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1688 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1689 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1690 |
< |
|
1691 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1692 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1693 |
< |
final Noop r = new Noop(); |
1694 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1695 |
< |
|
1696 |
< |
f.complete(v1); |
1697 |
< |
checkIncomplete(h); |
1698 |
< |
assertEquals(0, r.invocationCount); |
1699 |
< |
g.complete(v2); |
1700 |
< |
|
1701 |
< |
checkCompletedNormally(h, null); |
1702 |
< |
assertEquals(1, r.invocationCount); |
1703 |
< |
checkCompletedNormally(f, v1); |
1704 |
< |
checkCompletedNormally(g, v2); |
1705 |
< |
} |
1706 |
< |
} |
1707 |
< |
|
1708 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1709 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1710 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1711 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1712 |
< |
|
1713 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1714 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1715 |
< |
final Noop r = new Noop(); |
1716 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1717 |
< |
|
1718 |
< |
g.complete(v2); |
1719 |
< |
checkIncomplete(h); |
1720 |
< |
assertEquals(0, r.invocationCount); |
1721 |
< |
f.complete(v1); |
1722 |
< |
|
1723 |
< |
checkCompletedNormally(h, null); |
1724 |
< |
assertEquals(1, r.invocationCount); |
1725 |
< |
checkCompletedNormally(f, v1); |
1726 |
< |
checkCompletedNormally(g, v2); |
1727 |
< |
} |
1728 |
< |
} |
1729 |
< |
|
1730 |
< |
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 |
< |
|
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); |
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 |
< |
|
1496 |
< |
checkCompletedNormally(h, null); |
1497 |
< |
assertEquals(1, r.invocationCount); |
1498 |
< |
checkCompletedNormally(f, v1); |
1746 |
< |
checkCompletedNormally(g, v2); |
1495 |
> |
if (createIncomplete) { |
1496 |
> |
checkIncomplete(h); |
1497 |
> |
assertEquals(0, r.invocationCount); |
1498 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1499 |
|
} |
1748 |
– |
} |
1749 |
– |
|
1750 |
– |
public void testRunAfterBoth_normalCompletion4() { |
1751 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1752 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1753 |
– |
for (Integer v2 : new Integer[] { 2, null }) { |
1754 |
– |
|
1755 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1756 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1757 |
– |
final Noop r = new Noop(); |
1758 |
– |
|
1759 |
– |
f.complete(v1); |
1760 |
– |
g.complete(v2); |
1761 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1500 |
|
|
1501 |
|
checkCompletedNormally(h, null); |
1502 |
|
assertEquals(1, r.invocationCount); |
1503 |
|
checkCompletedNormally(f, v1); |
1504 |
|
checkCompletedNormally(g, v2); |
1505 |
< |
} |
1768 |
< |
} |
1505 |
> |
}} |
1506 |
|
|
1507 |
|
/** |
1508 |
|
* runAfterBoth result completes exceptionally after exceptional |
1509 |
|
* completion of either source |
1510 |
|
*/ |
1511 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1511 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1512 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1513 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1514 |
< |
|
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<>(); |
1780 |
– |
final Noop r = new Noop(); |
1781 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1519 |
|
final CFException ex = new CFException(); |
1520 |
+ |
final Noop r = new Noop(m); |
1521 |
|
|
1522 |
< |
f.completeExceptionally(ex); |
1523 |
< |
checkIncomplete(h); |
1524 |
< |
g.complete(v1); |
1787 |
< |
|
1788 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1789 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1790 |
< |
assertEquals(0, r.invocationCount); |
1791 |
< |
checkCompletedNormally(g, v1); |
1792 |
< |
} |
1793 |
< |
} |
1794 |
< |
|
1795 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1796 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1797 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1798 |
< |
|
1799 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1800 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1801 |
< |
final Noop r = new Noop(); |
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 |
< |
final CFException ex = new CFException(); |
1527 |
< |
|
1528 |
< |
g.completeExceptionally(ex); |
1806 |
< |
checkIncomplete(h); |
1807 |
< |
f.complete(v1); |
1808 |
< |
|
1809 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1810 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1811 |
< |
assertEquals(0, r.invocationCount); |
1812 |
< |
checkCompletedNormally(f, v1); |
1526 |
> |
if (createIncomplete) { |
1527 |
> |
checkIncomplete(h); |
1528 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1529 |
|
} |
1814 |
– |
} |
1815 |
– |
|
1816 |
– |
public void testRunAfterBoth_exceptionalCompletion3() { |
1817 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1818 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1819 |
– |
|
1820 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1821 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1822 |
– |
final Noop r = new Noop(); |
1823 |
– |
final CFException ex = new CFException(); |
1824 |
– |
|
1825 |
– |
g.completeExceptionally(ex); |
1826 |
– |
f.complete(v1); |
1827 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1530 |
|
|
1531 |
|
checkCompletedWithWrappedCFException(h, ex); |
1830 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1532 |
|
assertEquals(0, r.invocationCount); |
1533 |
< |
checkCompletedNormally(f, v1); |
1534 |
< |
} |
1535 |
< |
} |
1835 |
< |
|
1836 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1837 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1838 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1839 |
< |
|
1840 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1841 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1842 |
< |
final Noop r = new Noop(); |
1843 |
< |
final CFException ex = new CFException(); |
1844 |
< |
|
1845 |
< |
f.completeExceptionally(ex); |
1846 |
< |
g.complete(v1); |
1847 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1848 |
< |
|
1849 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1850 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1851 |
< |
assertEquals(0, r.invocationCount); |
1852 |
< |
checkCompletedNormally(g, v1); |
1853 |
< |
} |
1854 |
< |
} |
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() { |
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 |
< |
|
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(); |
1867 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1548 |
> |
final FailingRunnable r = new FailingRunnable(); |
1549 |
|
|
1550 |
< |
f.complete(v1); |
1551 |
< |
checkIncomplete(h); |
1552 |
< |
g.complete(v2); |
1553 |
< |
|
1554 |
< |
checkCompletedWithWrappedCFException(h); |
1555 |
< |
checkCompletedNormally(f, v1); |
1556 |
< |
checkCompletedNormally(g, v2); |
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 |
< |
} |
1558 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1559 |
|
|
1560 |
< |
public void testRunAfterBoth_actionFailed2() { |
1561 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1881 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1882 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1883 |
< |
|
1884 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1885 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1886 |
< |
final FailingNoop r = new FailingNoop(); |
1887 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1888 |
< |
|
1889 |
< |
g.complete(v2); |
1890 |
< |
checkIncomplete(h); |
1891 |
< |
f.complete(v1); |
1892 |
< |
|
1893 |
< |
checkCompletedWithWrappedCFException(h); |
1560 |
> |
checkCompletedWithWrappedCFException(h1); |
1561 |
> |
checkCompletedWithWrappedCFException(h2); |
1562 |
|
checkCompletedNormally(f, v1); |
1563 |
|
checkCompletedNormally(g, v2); |
1564 |
< |
} |
1897 |
< |
} |
1564 |
> |
}} |
1565 |
|
|
1566 |
|
/** |
1567 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1568 |
|
*/ |
1569 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1569 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1570 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1571 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1572 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1573 |
< |
|
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(); |
1910 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1911 |
< |
|
1912 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1913 |
< |
checkIncomplete(h); |
1914 |
< |
g.complete(v1); |
1578 |
> |
final Noop r = new Noop(m); |
1579 |
|
|
1916 |
– |
checkCompletedWithWrappedCancellationException(h); |
1917 |
– |
checkCancelled(f); |
1918 |
– |
assertEquals(0, r.invocationCount); |
1919 |
– |
checkCompletedNormally(g, v1); |
1920 |
– |
} |
1921 |
– |
} |
1580 |
|
|
1581 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1582 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1583 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1926 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1927 |
< |
|
1928 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1929 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1930 |
< |
final Noop r = new Noop(); |
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 |
< |
|
1586 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1587 |
< |
checkIncomplete(h); |
1935 |
< |
f.complete(v1); |
1936 |
< |
|
1937 |
< |
checkCompletedWithWrappedCancellationException(h); |
1938 |
< |
checkCancelled(g); |
1939 |
< |
assertEquals(0, r.invocationCount); |
1940 |
< |
checkCompletedNormally(f, v1); |
1585 |
> |
if (createIncomplete) { |
1586 |
> |
checkIncomplete(h); |
1587 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1588 |
|
} |
1942 |
– |
} |
1943 |
– |
|
1944 |
– |
public void testRunAfterBoth_sourceCancelled3() { |
1945 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1946 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1947 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
1948 |
– |
|
1949 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1950 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1951 |
– |
final Noop r = new Noop(); |
1952 |
– |
|
1953 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1954 |
– |
f.complete(v1); |
1955 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1589 |
|
|
1590 |
|
checkCompletedWithWrappedCancellationException(h); |
1591 |
< |
checkCancelled(g); |
1591 |
> |
checkCancelled(!fFirst ? f : g); |
1592 |
|
assertEquals(0, r.invocationCount); |
1593 |
< |
checkCompletedNormally(f, v1); |
1594 |
< |
} |
1962 |
< |
} |
1963 |
< |
|
1964 |
< |
public void testRunAfterBoth_sourceCancelled4() { |
1965 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1966 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1967 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1968 |
< |
|
1969 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1970 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1971 |
< |
final Noop r = new Noop(); |
1972 |
< |
|
1973 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1974 |
< |
g.complete(v1); |
1975 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1976 |
< |
|
1977 |
< |
checkCompletedWithWrappedCancellationException(h); |
1978 |
< |
checkCancelled(f); |
1979 |
< |
assertEquals(0, r.invocationCount); |
1980 |
< |
checkCompletedNormally(g, v1); |
1981 |
< |
} |
1982 |
< |
} |
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 |
< |
|
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(); |
1996 |
– |
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)); |
1625 |
< |
} |
2006 |
< |
} |
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 |
< |
|
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(); |
2016 |
– |
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); |
2024 |
< |
checkCompletedNormally(h, inc(v2)); |
1637 |
> |
if (fFirst) { |
1638 |
> |
f.complete(v1); |
1639 |
> |
g.complete(v2); |
1640 |
> |
} else { |
1641 |
> |
g.complete(v2); |
1642 |
> |
f.complete(v1); |
1643 |
|
} |
2026 |
– |
} |
2027 |
– |
public void testApplyToEither_normalCompletion3() { |
2028 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2029 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2030 |
– |
for (Integer v2 : new Integer[] { 2, null }) { |
2031 |
– |
|
2032 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2033 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2034 |
– |
final IncFunction r = new IncFunction(); |
1644 |
|
|
2036 |
– |
f.complete(v1); |
2037 |
– |
g.complete(v2); |
1645 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1646 |
|
|
1647 |
|
checkCompletedNormally(f, v1); |
1651 |
|
assertTrue(Objects.equals(h.join(), inc(v1)) || |
1652 |
|
Objects.equals(h.join(), inc(v2))); |
1653 |
|
assertEquals(1, r.invocationCount); |
1654 |
< |
} |
2048 |
< |
} |
1654 |
> |
}} |
1655 |
|
|
1656 |
|
/** |
1657 |
|
* applyToEither result completes exceptionally after exceptional |
1659 |
|
*/ |
1660 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1661 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1662 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1663 |
< |
|
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<>(); |
1668 |
+ |
final CFException ex = new CFException(); |
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 |
|
|
2064 |
– |
f.completeExceptionally(ex); |
1679 |
|
checkCompletedWithWrappedCFException(h, ex); |
1680 |
< |
g.complete(v1); |
1680 |
> |
(!fFirst ? f : g).complete(v1); |
1681 |
|
|
1682 |
|
assertEquals(0, r.invocationCount); |
1683 |
< |
checkCompletedNormally(g, v1); |
1684 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1683 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1684 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1685 |
|
checkCompletedWithWrappedCFException(h, ex); |
1686 |
< |
} |
2073 |
< |
} |
1686 |
> |
}} |
1687 |
|
|
1688 |
|
public void testApplyToEither_exceptionalCompletion2() { |
1689 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1690 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1691 |
< |
|
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(); |
1697 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1696 |
> |
final IncFunction r1 = new IncFunction(); |
1697 |
> |
final IncFunction r2 = new IncFunction(); |
1698 |
|
final CFException ex = new CFException(); |
1699 |
< |
|
1700 |
< |
g.completeExceptionally(ex); |
1701 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1702 |
< |
f.complete(v1); |
1703 |
< |
|
1704 |
< |
assertEquals(0, r.invocationCount); |
1705 |
< |
checkCompletedNormally(f, v1); |
1706 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1707 |
< |
checkCompletedWithWrappedCFException(h, ex); |
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 |
< |
} |
2095 |
< |
|
2096 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
2097 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2098 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2099 |
< |
|
2100 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2101 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2102 |
< |
final IncFunction r = new IncFunction(); |
2103 |
< |
final CFException ex = new CFException(); |
2104 |
< |
|
2105 |
< |
g.completeExceptionally(ex); |
2106 |
< |
f.complete(v1); |
2107 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1709 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1710 |
|
|
1711 |
|
// unspecified behavior |
2110 |
– |
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 |
|
|
2119 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2120 |
– |
checkCompletedNormally(f, v1); |
2121 |
– |
} |
2122 |
– |
} |
2123 |
– |
|
2124 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2125 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2126 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
2127 |
– |
|
2128 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2129 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2130 |
– |
final IncFunction r = new IncFunction(); |
2131 |
– |
final CFException ex = new CFException(); |
2132 |
– |
|
2133 |
– |
f.completeExceptionally(ex); |
2134 |
– |
g.complete(v1); |
2135 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2136 |
– |
|
2137 |
– |
// unspecified behavior |
2138 |
– |
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); |
1730 |
< |
} |
2150 |
< |
} |
1728 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1729 |
> |
checkCompletedNormally(f, v1); |
1730 |
> |
}} |
1731 |
|
|
1732 |
|
/** |
1733 |
|
* applyToEither result completes exceptionally if action does |
1735 |
|
public void testApplyToEither_actionFailed1() { |
1736 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1737 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1738 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1739 |
< |
|
1738 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1739 |
> |
{ |
1740 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1741 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1742 |
|
final FailingFunction r = new FailingFunction(); |
1747 |
|
g.complete(v2); |
1748 |
|
checkCompletedNormally(f, v1); |
1749 |
|
checkCompletedNormally(g, v2); |
1750 |
< |
} |
2171 |
< |
} |
1750 |
> |
}} |
1751 |
|
|
1752 |
|
public void testApplyToEither_actionFailed2() { |
1753 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1754 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1755 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1756 |
< |
|
1755 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1756 |
> |
{ |
1757 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1758 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1759 |
|
final FailingFunction r = new FailingFunction(); |
1764 |
|
f.complete(v1); |
1765 |
|
checkCompletedNormally(f, v1); |
1766 |
|
checkCompletedNormally(g, v2); |
1767 |
< |
} |
2189 |
< |
} |
1767 |
> |
}} |
1768 |
|
|
1769 |
|
/** |
1770 |
|
* applyToEither result completes exceptionally if either source cancelled |
1772 |
|
public void testApplyToEither_sourceCancelled1() { |
1773 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1774 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1775 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1776 |
< |
|
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(); |
1782 |
+ |
|
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 |
|
|
2204 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1791 |
|
checkCompletedWithWrappedCancellationException(h); |
1792 |
< |
g.complete(v1); |
1792 |
> |
(!fFirst ? f : g).complete(v1); |
1793 |
|
|
2208 |
– |
checkCancelled(f); |
1794 |
|
assertEquals(0, r.invocationCount); |
1795 |
< |
checkCompletedNormally(g, v1); |
1795 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1796 |
> |
checkCancelled(fFirst ? f : g); |
1797 |
|
checkCompletedWithWrappedCancellationException(h); |
1798 |
< |
} |
2213 |
< |
} |
1798 |
> |
}} |
1799 |
|
|
1800 |
|
public void testApplyToEither_sourceCancelled2() { |
1801 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1802 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1803 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1804 |
< |
|
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(); |
1810 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1811 |
< |
|
1812 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1813 |
< |
checkCompletedWithWrappedCancellationException(h); |
2227 |
< |
f.complete(v1); |
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 |
< |
checkCancelled(g); |
1816 |
< |
assertEquals(0, r.invocationCount); |
1817 |
< |
checkCompletedNormally(f, v1); |
1818 |
< |
checkCompletedWithWrappedCancellationException(h); |
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 |
< |
} |
2235 |
< |
|
2236 |
< |
public void testApplyToEither_sourceCancelled3() { |
2237 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2238 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2239 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2240 |
< |
|
2241 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2242 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2243 |
< |
final IncFunction r = new IncFunction(); |
2244 |
< |
|
2245 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2246 |
< |
f.complete(v1); |
2247 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1823 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1824 |
|
|
1825 |
|
// unspecified behavior |
2250 |
– |
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 |
|
|
2259 |
– |
checkCancelled(g); |
2260 |
– |
checkCompletedNormally(f, v1); |
2261 |
– |
} |
2262 |
– |
} |
2263 |
– |
|
2264 |
– |
public void testApplyToEither_sourceCancelled4() { |
2265 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2266 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2267 |
– |
for (Integer v1 : new Integer[] { 1, null }) { |
2268 |
– |
|
2269 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2270 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2271 |
– |
final IncFunction r = new IncFunction(); |
2272 |
– |
|
2273 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2274 |
– |
g.complete(v1); |
2275 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2276 |
– |
|
2277 |
– |
// unspecified behavior |
2278 |
– |
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); |
1844 |
< |
} |
2290 |
< |
} |
1842 |
> |
checkCancelled(g); |
1843 |
> |
checkCompletedNormally(f, v1); |
1844 |
> |
}} |
1845 |
|
|
1846 |
|
/** |
1847 |
|
* acceptEither result completes normally after normal completion |
1850 |
|
public void testAcceptEither_normalCompletion1() { |
1851 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1852 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1853 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1854 |
< |
|
1853 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1854 |
> |
{ |
1855 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1856 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1857 |
|
final IncAction r = new IncAction(); |
1865 |
|
checkCompletedNormally(f, v1); |
1866 |
|
checkCompletedNormally(g, v2); |
1867 |
|
checkCompletedNormally(h, null); |
1868 |
< |
} |
2315 |
< |
} |
1868 |
> |
}} |
1869 |
|
|
1870 |
|
public void testAcceptEither_normalCompletion2() { |
1871 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1872 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1873 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1874 |
< |
|
1873 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1874 |
> |
{ |
1875 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1876 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1877 |
|
final IncAction r = new IncAction(); |
1885 |
|
checkCompletedNormally(f, v1); |
1886 |
|
checkCompletedNormally(g, v2); |
1887 |
|
checkCompletedNormally(h, null); |
1888 |
< |
} |
1889 |
< |
} |
1888 |
> |
}} |
1889 |
> |
|
1890 |
|
public void testAcceptEither_normalCompletion3() { |
1891 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1892 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1893 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1894 |
< |
|
1893 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1894 |
> |
{ |
1895 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1896 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1897 |
|
final IncAction r = new IncAction(); |
1907 |
|
// unspecified behavior |
1908 |
|
assertTrue(Objects.equals(r.value, inc(v1)) || |
1909 |
|
Objects.equals(r.value, inc(v2))); |
1910 |
< |
} |
2358 |
< |
} |
1910 |
> |
}} |
1911 |
|
|
1912 |
|
/** |
1913 |
|
* acceptEither result completes exceptionally after exceptional |
1915 |
|
*/ |
1916 |
|
public void testAcceptEither_exceptionalCompletion1() { |
1917 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1918 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1919 |
< |
|
1918 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1919 |
> |
{ |
1920 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1921 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1922 |
|
final IncAction r = new IncAction(); |
1931 |
|
checkCompletedNormally(g, v1); |
1932 |
|
checkCompletedWithWrappedCFException(f, ex); |
1933 |
|
checkCompletedWithWrappedCFException(h, ex); |
1934 |
< |
} |
2383 |
< |
} |
1934 |
> |
}} |
1935 |
|
|
1936 |
|
public void testAcceptEither_exceptionalCompletion2() { |
1937 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1938 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1939 |
< |
|
1938 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1939 |
> |
{ |
1940 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1941 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1942 |
|
final IncAction r = new IncAction(); |
1951 |
|
checkCompletedNormally(f, v1); |
1952 |
|
checkCompletedWithWrappedCFException(g, ex); |
1953 |
|
checkCompletedWithWrappedCFException(h, ex); |
1954 |
< |
} |
2404 |
< |
} |
1954 |
> |
}} |
1955 |
|
|
1956 |
|
public void testAcceptEither_exceptionalCompletion3() { |
1957 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1958 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1959 |
< |
|
1958 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1959 |
> |
{ |
1960 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1961 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1962 |
|
final IncAction r = new IncAction(); |
1979 |
|
|
1980 |
|
checkCompletedWithWrappedCFException(g, ex); |
1981 |
|
checkCompletedNormally(f, v1); |
1982 |
< |
} |
2433 |
< |
} |
1982 |
> |
}} |
1983 |
|
|
1984 |
|
public void testAcceptEither_exceptionalCompletion4() { |
1985 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1986 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1987 |
< |
|
1986 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1987 |
> |
{ |
1988 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1989 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1990 |
|
final IncAction r = new IncAction(); |
2007 |
|
|
2008 |
|
checkCompletedWithWrappedCFException(f, ex); |
2009 |
|
checkCompletedNormally(g, v1); |
2010 |
< |
} |
2462 |
< |
} |
2010 |
> |
}} |
2011 |
|
|
2012 |
|
/** |
2013 |
|
* acceptEither result completes exceptionally if action does |
2015 |
|
public void testAcceptEither_actionFailed1() { |
2016 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2017 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2018 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2019 |
< |
|
2018 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2019 |
> |
{ |
2020 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2021 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2022 |
|
final FailingConsumer r = new FailingConsumer(); |
2027 |
|
g.complete(v2); |
2028 |
|
checkCompletedNormally(f, v1); |
2029 |
|
checkCompletedNormally(g, v2); |
2030 |
< |
} |
2483 |
< |
} |
2030 |
> |
}} |
2031 |
|
|
2032 |
|
public void testAcceptEither_actionFailed2() { |
2033 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2034 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2035 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2036 |
< |
|
2035 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2036 |
> |
{ |
2037 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2038 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2039 |
|
final FailingConsumer r = new FailingConsumer(); |
2044 |
|
f.complete(v1); |
2045 |
|
checkCompletedNormally(f, v1); |
2046 |
|
checkCompletedNormally(g, v2); |
2047 |
< |
} |
2501 |
< |
} |
2047 |
> |
}} |
2048 |
|
|
2049 |
|
/** |
2050 |
|
* acceptEither result completes exceptionally if either source cancelled |
2052 |
|
public void testAcceptEither_sourceCancelled1() { |
2053 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2054 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2055 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2056 |
< |
|
2055 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2056 |
> |
{ |
2057 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2058 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2059 |
|
final IncAction r = new IncAction(); |
2067 |
|
assertEquals(0, r.invocationCount); |
2068 |
|
checkCompletedNormally(g, v1); |
2069 |
|
checkCompletedWithWrappedCancellationException(h); |
2070 |
< |
} |
2525 |
< |
} |
2070 |
> |
}} |
2071 |
|
|
2072 |
|
public void testAcceptEither_sourceCancelled2() { |
2073 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2074 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2075 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2076 |
< |
|
2075 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2076 |
> |
{ |
2077 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2078 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2079 |
|
final IncAction r = new IncAction(); |
2087 |
|
assertEquals(0, r.invocationCount); |
2088 |
|
checkCompletedNormally(f, v1); |
2089 |
|
checkCompletedWithWrappedCancellationException(h); |
2090 |
< |
} |
2546 |
< |
} |
2090 |
> |
}} |
2091 |
|
|
2092 |
|
public void testAcceptEither_sourceCancelled3() { |
2093 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2094 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2095 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2096 |
< |
|
2095 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2096 |
> |
{ |
2097 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2098 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2099 |
|
final IncAction r = new IncAction(); |
2115 |
|
|
2116 |
|
checkCancelled(g); |
2117 |
|
checkCompletedNormally(f, v1); |
2118 |
< |
} |
2575 |
< |
} |
2118 |
> |
}} |
2119 |
|
|
2120 |
|
public void testAcceptEither_sourceCancelled4() { |
2121 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2122 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2123 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2124 |
< |
|
2123 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2124 |
> |
{ |
2125 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2126 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2127 |
|
final IncAction r = new IncAction(); |
2143 |
|
|
2144 |
|
checkCancelled(f); |
2145 |
|
checkCompletedNormally(g, v1); |
2146 |
< |
} |
2604 |
< |
} |
2146 |
> |
}} |
2147 |
|
|
2148 |
|
/** |
2149 |
|
* runAfterEither result completes normally after normal completion |
2152 |
|
public void testRunAfterEither_normalCompletion1() { |
2153 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2154 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2155 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2156 |
< |
|
2155 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
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); |
2168 |
|
checkCompletedNormally(g, v2); |
2169 |
|
checkCompletedNormally(h, null); |
2170 |
|
assertEquals(1, r.invocationCount); |
2171 |
< |
} |
2630 |
< |
} |
2171 |
> |
}} |
2172 |
|
|
2173 |
|
public void testRunAfterEither_normalCompletion2() { |
2174 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2175 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2176 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2177 |
< |
|
2176 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
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); |
2189 |
|
checkCompletedNormally(g, v2); |
2190 |
|
checkCompletedNormally(h, null); |
2191 |
|
assertEquals(1, r.invocationCount); |
2192 |
< |
} |
2193 |
< |
} |
2192 |
> |
}} |
2193 |
> |
|
2194 |
|
public void testRunAfterEither_normalCompletion3() { |
2195 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2196 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2197 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2198 |
< |
|
2197 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
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); |
2208 |
|
checkCompletedNormally(f, v1); |
2209 |
|
checkCompletedNormally(g, v2); |
2210 |
|
assertEquals(1, r.invocationCount); |
2211 |
< |
} |
2671 |
< |
} |
2211 |
> |
}} |
2212 |
|
|
2213 |
|
/** |
2214 |
|
* runAfterEither result completes exceptionally after exceptional |
2216 |
|
*/ |
2217 |
|
public void testRunAfterEither_exceptionalCompletion1() { |
2218 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2219 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2220 |
< |
|
2219 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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 |
|
|
2232 |
|
checkCompletedNormally(g, v1); |
2233 |
|
checkCompletedWithWrappedCFException(f, ex); |
2234 |
|
checkCompletedWithWrappedCFException(h, ex); |
2235 |
< |
} |
2696 |
< |
} |
2235 |
> |
}} |
2236 |
|
|
2237 |
|
public void testRunAfterEither_exceptionalCompletion2() { |
2238 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2239 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2240 |
< |
|
2239 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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 |
|
|
2252 |
|
checkCompletedNormally(f, v1); |
2253 |
|
checkCompletedWithWrappedCFException(g, ex); |
2254 |
|
checkCompletedWithWrappedCFException(h, ex); |
2255 |
< |
} |
2717 |
< |
} |
2255 |
> |
}} |
2256 |
|
|
2257 |
|
public void testRunAfterEither_exceptionalCompletion3() { |
2258 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2259 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2260 |
< |
|
2259 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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); |
2279 |
|
|
2280 |
|
checkCompletedWithWrappedCFException(g, ex); |
2281 |
|
checkCompletedNormally(f, v1); |
2282 |
< |
} |
2745 |
< |
} |
2282 |
> |
}} |
2283 |
|
|
2284 |
|
public void testRunAfterEither_exceptionalCompletion4() { |
2285 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2286 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2287 |
< |
|
2286 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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); |
2306 |
|
|
2307 |
|
checkCompletedWithWrappedCFException(f, ex); |
2308 |
|
checkCompletedNormally(g, v1); |
2309 |
< |
} |
2773 |
< |
} |
2309 |
> |
}} |
2310 |
|
|
2311 |
|
/** |
2312 |
|
* runAfterEither result completes exceptionally if action does |
2314 |
|
public void testRunAfterEither_actionFailed1() { |
2315 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2316 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2317 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2318 |
< |
|
2317 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
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); |
2326 |
|
g.complete(v2); |
2327 |
|
checkCompletedNormally(f, v1); |
2328 |
|
checkCompletedNormally(g, v2); |
2329 |
< |
} |
2794 |
< |
} |
2329 |
> |
}} |
2330 |
|
|
2331 |
|
public void testRunAfterEither_actionFailed2() { |
2332 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2333 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2334 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2335 |
< |
|
2334 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
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); |
2343 |
|
f.complete(v1); |
2344 |
|
checkCompletedNormally(f, v1); |
2345 |
|
checkCompletedNormally(g, v2); |
2346 |
< |
} |
2812 |
< |
} |
2346 |
> |
}} |
2347 |
|
|
2348 |
|
/** |
2349 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2351 |
|
public void testRunAfterEither_sourceCancelled1() { |
2352 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2353 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2354 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2355 |
< |
|
2354 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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)); |
2366 |
|
assertEquals(0, r.invocationCount); |
2367 |
|
checkCompletedNormally(g, v1); |
2368 |
|
checkCompletedWithWrappedCancellationException(h); |
2369 |
< |
} |
2836 |
< |
} |
2369 |
> |
}} |
2370 |
|
|
2371 |
|
public void testRunAfterEither_sourceCancelled2() { |
2372 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2373 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2374 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2375 |
< |
|
2374 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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)); |
2386 |
|
assertEquals(0, r.invocationCount); |
2387 |
|
checkCompletedNormally(f, v1); |
2388 |
|
checkCompletedWithWrappedCancellationException(h); |
2389 |
< |
} |
2857 |
< |
} |
2389 |
> |
}} |
2390 |
|
|
2391 |
|
public void testRunAfterEither_sourceCancelled3() { |
2392 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2393 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2394 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2395 |
< |
|
2394 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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); |
2413 |
|
|
2414 |
|
checkCancelled(g); |
2415 |
|
checkCompletedNormally(f, v1); |
2416 |
< |
} |
2885 |
< |
} |
2416 |
> |
}} |
2417 |
|
|
2418 |
|
public void testRunAfterEither_sourceCancelled4() { |
2419 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2420 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2421 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2422 |
< |
|
2421 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
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); |
2440 |
|
|
2441 |
|
checkCancelled(f); |
2442 |
|
checkCompletedNormally(g, v1); |
2443 |
< |
} |
2913 |
< |
} |
2443 |
> |
}} |
2444 |
|
|
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 (Integer v1 : new Integer[] { 1, null }) { |
2451 |
< |
|
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); |
2926 |
< |
checkCompletedNormally(g, inc(v1)); |
2927 |
< |
checkCompletedNormally(f, v1); |
2928 |
< |
assertEquals(1, r.invocationCount); |
2929 |
< |
} |
2930 |
< |
} |
2931 |
< |
|
2932 |
< |
public void testThenCompose_normalCompletion2() { |
2933 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2934 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2457 |
> |
if (createIncomplete) f.complete(v1); |
2458 |
|
|
2936 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2937 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2938 |
– |
f.complete(v1); |
2939 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2459 |
|
checkCompletedNormally(g, inc(v1)); |
2460 |
|
checkCompletedNormally(f, v1); |
2461 |
|
assertEquals(1, r.invocationCount); |
2462 |
< |
} |
2944 |
< |
} |
2462 |
> |
}} |
2463 |
|
|
2464 |
|
/** |
2465 |
|
* thenCompose result completes exceptionally after exceptional |
2466 |
|
* completion of source |
2467 |
|
*/ |
2468 |
< |
public void testThenCompose_exceptionalCompletion1() { |
2469 |
< |
for (ExecutionMode m : ExecutionMode.values()) { |
2470 |
< |
|
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); |
2958 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2959 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2960 |
< |
} |
2961 |
< |
} |
2962 |
< |
|
2963 |
< |
public void testThenCompose_exceptionalCompletion2() { |
2964 |
< |
for (ExecutionMode m : ExecutionMode.values()) { |
2477 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
2478 |
|
|
2966 |
– |
final CFException ex = new CFException(); |
2967 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2968 |
– |
f.completeExceptionally(ex); |
2969 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2970 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2479 |
|
checkCompletedWithWrappedCFException(g, ex); |
2480 |
|
checkCompletedWithWrappedCFException(f, ex); |
2481 |
< |
} |
2482 |
< |
} |
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 (Integer v1 : new Integer[] { 1, null }) { |
2490 |
< |
|
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); |
2988 |
< |
checkCompletedWithWrappedCFException(g); |
2989 |
< |
checkCompletedNormally(f, v1); |
2990 |
< |
} |
2991 |
< |
} |
2992 |
< |
|
2993 |
< |
public void testThenCompose_actionFailed2() { |
2994 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2995 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2497 |
> |
if (createIncomplete) f.complete(v1); |
2498 |
|
|
2997 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2998 |
– |
f.complete(v1); |
2999 |
– |
final FailingCompletableFutureFunction r |
3000 |
– |
= new FailingCompletableFutureFunction(); |
3001 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2499 |
|
checkCompletedWithWrappedCFException(g); |
2500 |
|
checkCompletedNormally(f, v1); |
2501 |
< |
} |
3005 |
< |
} |
2501 |
> |
}} |
2502 |
|
|
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 mayInterruptIfRunning : new boolean[] { true, false }) { |
2509 |
< |
|
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); |
2515 |
> |
if (createIncomplete) { |
2516 |
> |
checkIncomplete(g); |
2517 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2518 |
|
} |
3021 |
– |
} |
3022 |
– |
|
3023 |
– |
public void testThenCompose_sourceCancelled2() { |
3024 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
3025 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
2519 |
|
|
3027 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3028 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
3029 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
3030 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2520 |
|
checkCompletedWithWrappedCancellationException(g); |
2521 |
|
checkCancelled(f); |
2522 |
< |
} |
3034 |
< |
} |
3035 |
< |
|
3036 |
< |
// asyncs |
3037 |
< |
|
3038 |
< |
/** |
3039 |
< |
* thenRunAsync result completes normally after normal completion of source |
3040 |
< |
*/ |
3041 |
< |
public void testThenRunAsync() { |
3042 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3043 |
< |
Noop r = new Noop(); |
3044 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3045 |
< |
f.complete(null); |
3046 |
< |
checkCompletedNormally(g, null); |
3047 |
< |
|
3048 |
< |
// reordered version |
3049 |
< |
f = new CompletableFuture<>(); |
3050 |
< |
f.complete(null); |
3051 |
< |
r = new Noop(); |
3052 |
< |
g = f.thenRunAsync(r); |
3053 |
< |
checkCompletedNormally(g, null); |
3054 |
< |
} |
3055 |
< |
|
3056 |
< |
/** |
3057 |
< |
* thenRunAsync result completes exceptionally after exceptional |
3058 |
< |
* completion of source |
3059 |
< |
*/ |
3060 |
< |
public void testThenRunAsync2() { |
3061 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3062 |
< |
Noop r = new Noop(); |
3063 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3064 |
< |
f.completeExceptionally(new CFException()); |
3065 |
< |
try { |
3066 |
< |
g.join(); |
3067 |
< |
shouldThrow(); |
3068 |
< |
} catch (CompletionException success) {} |
3069 |
< |
checkCompletedWithWrappedCFException(g); |
3070 |
< |
} |
3071 |
< |
|
3072 |
< |
/** |
3073 |
< |
* thenRunAsync result completes exceptionally if action does |
3074 |
< |
*/ |
3075 |
< |
public void testThenRunAsync3() { |
3076 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3077 |
< |
FailingNoop r = new FailingNoop(); |
3078 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3079 |
< |
f.complete(null); |
3080 |
< |
checkCompletedWithWrappedCFException(g); |
3081 |
< |
} |
3082 |
< |
|
3083 |
< |
/** |
3084 |
< |
* thenRunAsync result completes exceptionally if source cancelled |
3085 |
< |
*/ |
3086 |
< |
public void testThenRunAsync4() { |
3087 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3088 |
< |
Noop r = new Noop(); |
3089 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3090 |
< |
assertTrue(f.cancel(true)); |
3091 |
< |
checkCompletedWithWrappedCancellationException(g); |
3092 |
< |
} |
3093 |
< |
|
3094 |
< |
/** |
3095 |
< |
* thenApplyAsync result completes normally after normal completion of source |
3096 |
< |
*/ |
3097 |
< |
public void testThenApplyAsync() { |
3098 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3099 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3100 |
< |
f.complete(one); |
3101 |
< |
checkCompletedNormally(g, two); |
3102 |
< |
} |
3103 |
< |
|
3104 |
< |
/** |
3105 |
< |
* thenApplyAsync result completes exceptionally after exceptional |
3106 |
< |
* completion of source |
3107 |
< |
*/ |
3108 |
< |
public void testThenApplyAsync2() { |
3109 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3110 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3111 |
< |
f.completeExceptionally(new CFException()); |
3112 |
< |
checkCompletedWithWrappedCFException(g); |
3113 |
< |
} |
3114 |
< |
|
3115 |
< |
/** |
3116 |
< |
* thenApplyAsync result completes exceptionally if action does |
3117 |
< |
*/ |
3118 |
< |
public void testThenApplyAsync3() { |
3119 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3120 |
< |
FailingFunction r = new FailingFunction(); |
3121 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
3122 |
< |
f.complete(null); |
3123 |
< |
checkCompletedWithWrappedCFException(g); |
3124 |
< |
} |
3125 |
< |
|
3126 |
< |
/** |
3127 |
< |
* thenApplyAsync result completes exceptionally if source cancelled |
3128 |
< |
*/ |
3129 |
< |
public void testThenApplyAsync4() { |
3130 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3131 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3132 |
< |
assertTrue(f.cancel(true)); |
3133 |
< |
checkCompletedWithWrappedCancellationException(g); |
3134 |
< |
} |
3135 |
< |
|
3136 |
< |
/** |
3137 |
< |
* thenAcceptAsync result completes normally after normal |
3138 |
< |
* completion of source |
3139 |
< |
*/ |
3140 |
< |
public void testThenAcceptAsync() { |
3141 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3142 |
< |
IncAction r = new IncAction(); |
3143 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3144 |
< |
f.complete(one); |
3145 |
< |
checkCompletedNormally(g, null); |
3146 |
< |
assertEquals(r.value, (Integer) 2); |
3147 |
< |
} |
3148 |
< |
|
3149 |
< |
/** |
3150 |
< |
* thenAcceptAsync result completes exceptionally after exceptional |
3151 |
< |
* completion of source |
3152 |
< |
*/ |
3153 |
< |
public void testThenAcceptAsync2() { |
3154 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3155 |
< |
IncAction r = new IncAction(); |
3156 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3157 |
< |
f.completeExceptionally(new CFException()); |
3158 |
< |
checkCompletedWithWrappedCFException(g); |
3159 |
< |
} |
3160 |
< |
|
3161 |
< |
/** |
3162 |
< |
* thenAcceptAsync result completes exceptionally if action does |
3163 |
< |
*/ |
3164 |
< |
public void testThenAcceptAsync3() { |
3165 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3166 |
< |
FailingConsumer r = new FailingConsumer(); |
3167 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3168 |
< |
f.complete(null); |
3169 |
< |
checkCompletedWithWrappedCFException(g); |
3170 |
< |
} |
3171 |
< |
|
3172 |
< |
/** |
3173 |
< |
* thenAcceptAsync result completes exceptionally if source cancelled |
3174 |
< |
*/ |
3175 |
< |
public void testThenAcceptAsync4() { |
3176 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3177 |
< |
IncAction r = new IncAction(); |
3178 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3179 |
< |
assertTrue(f.cancel(true)); |
3180 |
< |
checkCompletedWithWrappedCancellationException(g); |
3181 |
< |
} |
3182 |
< |
|
3183 |
< |
// async with explicit executors |
3184 |
< |
|
3185 |
< |
/** |
3186 |
< |
* thenRunAsync result completes normally after normal completion of source |
3187 |
< |
*/ |
3188 |
< |
public void testThenRunAsyncE() { |
3189 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3190 |
< |
Noop r = new Noop(); |
3191 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3192 |
< |
f.complete(null); |
3193 |
< |
checkCompletedNormally(g, null); |
3194 |
< |
|
3195 |
< |
// reordered version |
3196 |
< |
f = new CompletableFuture<>(); |
3197 |
< |
f.complete(null); |
3198 |
< |
r = new Noop(); |
3199 |
< |
g = f.thenRunAsync(r, new ThreadExecutor()); |
3200 |
< |
checkCompletedNormally(g, null); |
3201 |
< |
} |
3202 |
< |
|
3203 |
< |
/** |
3204 |
< |
* thenRunAsync result completes exceptionally after exceptional |
3205 |
< |
* completion of source |
3206 |
< |
*/ |
3207 |
< |
public void testThenRunAsync2E() { |
3208 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3209 |
< |
Noop r = new Noop(); |
3210 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3211 |
< |
f.completeExceptionally(new CFException()); |
3212 |
< |
try { |
3213 |
< |
g.join(); |
3214 |
< |
shouldThrow(); |
3215 |
< |
} catch (CompletionException success) {} |
3216 |
< |
checkCompletedWithWrappedCFException(g); |
3217 |
< |
} |
3218 |
< |
|
3219 |
< |
/** |
3220 |
< |
* thenRunAsync result completes exceptionally if action does |
3221 |
< |
*/ |
3222 |
< |
public void testThenRunAsync3E() { |
3223 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3224 |
< |
FailingNoop r = new FailingNoop(); |
3225 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3226 |
< |
f.complete(null); |
3227 |
< |
checkCompletedWithWrappedCFException(g); |
3228 |
< |
} |
3229 |
< |
|
3230 |
< |
/** |
3231 |
< |
* thenRunAsync result completes exceptionally if source cancelled |
3232 |
< |
*/ |
3233 |
< |
public void testThenRunAsync4E() { |
3234 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3235 |
< |
Noop r = new Noop(); |
3236 |
< |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3237 |
< |
assertTrue(f.cancel(true)); |
3238 |
< |
checkCompletedWithWrappedCancellationException(g); |
3239 |
< |
} |
3240 |
< |
|
3241 |
< |
/** |
3242 |
< |
* thenApplyAsync result completes normally after normal completion of source |
3243 |
< |
*/ |
3244 |
< |
public void testThenApplyAsyncE() { |
3245 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3246 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3247 |
< |
f.complete(one); |
3248 |
< |
checkCompletedNormally(g, two); |
3249 |
< |
} |
3250 |
< |
|
3251 |
< |
/** |
3252 |
< |
* thenApplyAsync result completes exceptionally after exceptional |
3253 |
< |
* completion of source |
3254 |
< |
*/ |
3255 |
< |
public void testThenApplyAsync2E() { |
3256 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3257 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3258 |
< |
f.completeExceptionally(new CFException()); |
3259 |
< |
checkCompletedWithWrappedCFException(g); |
3260 |
< |
} |
3261 |
< |
|
3262 |
< |
/** |
3263 |
< |
* thenApplyAsync result completes exceptionally if action does |
3264 |
< |
*/ |
3265 |
< |
public void testThenApplyAsync3E() { |
3266 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3267 |
< |
FailingFunction r = new FailingFunction(); |
3268 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
3269 |
< |
f.complete(null); |
3270 |
< |
checkCompletedWithWrappedCFException(g); |
3271 |
< |
} |
3272 |
< |
|
3273 |
< |
/** |
3274 |
< |
* thenApplyAsync result completes exceptionally if source cancelled |
3275 |
< |
*/ |
3276 |
< |
public void testThenApplyAsync4E() { |
3277 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3278 |
< |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3279 |
< |
assertTrue(f.cancel(true)); |
3280 |
< |
checkCompletedWithWrappedCancellationException(g); |
3281 |
< |
} |
3282 |
< |
|
3283 |
< |
/** |
3284 |
< |
* thenAcceptAsync result completes normally after normal |
3285 |
< |
* completion of source |
3286 |
< |
*/ |
3287 |
< |
public void testThenAcceptAsyncE() { |
3288 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3289 |
< |
IncAction r = new IncAction(); |
3290 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3291 |
< |
f.complete(one); |
3292 |
< |
checkCompletedNormally(g, null); |
3293 |
< |
assertEquals(r.value, (Integer) 2); |
3294 |
< |
} |
3295 |
< |
|
3296 |
< |
/** |
3297 |
< |
* thenAcceptAsync result completes exceptionally after exceptional |
3298 |
< |
* completion of source |
3299 |
< |
*/ |
3300 |
< |
public void testThenAcceptAsync2E() { |
3301 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3302 |
< |
IncAction r = new IncAction(); |
3303 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3304 |
< |
f.completeExceptionally(new CFException()); |
3305 |
< |
checkCompletedWithWrappedCFException(g); |
3306 |
< |
} |
3307 |
< |
|
3308 |
< |
/** |
3309 |
< |
* thenAcceptAsync result completes exceptionally if action does |
3310 |
< |
*/ |
3311 |
< |
public void testThenAcceptAsync3E() { |
3312 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3313 |
< |
FailingConsumer r = new FailingConsumer(); |
3314 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3315 |
< |
f.complete(null); |
3316 |
< |
checkCompletedWithWrappedCFException(g); |
3317 |
< |
} |
3318 |
< |
|
3319 |
< |
/** |
3320 |
< |
* thenAcceptAsync result completes exceptionally if source cancelled |
3321 |
< |
*/ |
3322 |
< |
public void testThenAcceptAsync4E() { |
3323 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3324 |
< |
IncAction r = new IncAction(); |
3325 |
< |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3326 |
< |
assertTrue(f.cancel(true)); |
3327 |
< |
checkCompletedWithWrappedCancellationException(g); |
3328 |
< |
} |
2522 |
> |
}} |
2523 |
|
|
2524 |
|
// other static methods |
2525 |
|
|
2801 |
|
public void testWhenComplete_actionFailed() { |
2802 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2803 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2804 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2805 |
< |
|
2804 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2805 |
> |
{ |
2806 |
|
final AtomicInteger a = new AtomicInteger(0); |
2807 |
|
final CFException ex = new CFException(); |
2808 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2819 |
|
checkCompletedNormally(f, v1); |
2820 |
|
checkCompletedWithWrappedCFException(g, ex); |
2821 |
|
assertEquals(1, a.get()); |
2822 |
< |
} |
3629 |
< |
} |
2822 |
> |
}} |
2823 |
|
|
2824 |
|
/** |
2825 |
|
* If a whenComplete action throws an exception when triggered by |
2829 |
|
public void testWhenComplete_actionFailedSourceFailed() { |
2830 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2831 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2832 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2833 |
< |
|
2832 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2833 |
> |
{ |
2834 |
|
final AtomicInteger a = new AtomicInteger(0); |
2835 |
|
final CFException ex1 = new CFException(); |
2836 |
|
final CFException ex2 = new CFException(); |
2850 |
|
checkCompletedWithWrappedCFException(f, ex1); |
2851 |
|
checkCompletedWithWrappedCFException(g, ex1); |
2852 |
|
assertEquals(1, a.get()); |
2853 |
< |
} |
3661 |
< |
} |
2853 |
> |
}} |
2854 |
|
|
2855 |
|
} |