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; |
416 |
|
throw new CFException(); |
417 |
|
} |
418 |
|
} |
419 |
< |
static final class FailingNoop implements Runnable { |
419 |
> |
static final class FailingRunnable implements Runnable { |
420 |
|
int invocationCount = 0; |
421 |
|
public void run() { |
422 |
|
invocationCount++; |
460 |
|
*/ |
461 |
|
enum ExecutionMode { |
462 |
|
DEFAULT { |
463 |
+ |
public void checkExecutionMode() { |
464 |
+ |
assertNull(ForkJoinTask.getPool()); |
465 |
+ |
} |
466 |
|
public <T> CompletableFuture<Void> thenRun |
467 |
|
(CompletableFuture<T> f, Runnable a) { |
468 |
|
return f.thenRun(a); |
526 |
|
} |
527 |
|
}, |
528 |
|
|
529 |
< |
DEFAULT_ASYNC { |
529 |
> |
ASYNC { |
530 |
> |
public void checkExecutionMode() { |
531 |
> |
assertSame(ForkJoinPool.commonPool(), |
532 |
> |
ForkJoinTask.getPool()); |
533 |
> |
} |
534 |
|
public <T> CompletableFuture<Void> thenRun |
535 |
|
(CompletableFuture<T> f, Runnable a) { |
536 |
|
return f.thenRunAsync(a); |
595 |
|
}, |
596 |
|
|
597 |
|
EXECUTOR { |
598 |
+ |
public void checkExecutionMode() { |
599 |
+ |
//TODO |
600 |
+ |
} |
601 |
|
public <T> CompletableFuture<Void> thenRun |
602 |
|
(CompletableFuture<T> f, Runnable a) { |
603 |
|
return f.thenRunAsync(a, new ThreadExecutor()); |
661 |
|
} |
662 |
|
}; |
663 |
|
|
664 |
+ |
public abstract void checkExecutionMode(); |
665 |
|
public abstract <T> CompletableFuture<Void> thenRun |
666 |
|
(CompletableFuture<T> f, Runnable a); |
667 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
933 |
|
* failing runAsync completes exceptionally after running Runnable |
934 |
|
*/ |
935 |
|
public void testRunAsync3() { |
936 |
< |
FailingNoop r = new FailingNoop(); |
936 |
> |
FailingRunnable r = new FailingRunnable(); |
937 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
938 |
|
checkCompletedWithWrappedCFException(f); |
939 |
|
assertEquals(1, r.invocationCount); |
974 |
|
/** |
975 |
|
* thenRun result completes normally after normal completion of source |
976 |
|
*/ |
977 |
< |
public void testThenRun() { |
978 |
< |
CompletableFuture<Integer> f; |
979 |
< |
CompletableFuture<Void> g; |
980 |
< |
Noop r; |
981 |
< |
|
982 |
< |
f = new CompletableFuture<>(); |
983 |
< |
g = f.thenRun(r = new Noop()); |
984 |
< |
f.complete(null); |
985 |
< |
checkCompletedNormally(g, null); |
986 |
< |
assertEquals(1, r.invocationCount); |
977 |
> |
public void testThenRun_normalCompletion() { |
978 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
979 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
980 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
981 |
> |
{ |
982 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
983 |
> |
final Noop r = new Noop(); |
984 |
> |
if (!createIncomplete) f.complete(v1); |
985 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
986 |
> |
if (createIncomplete) { |
987 |
> |
checkIncomplete(g); |
988 |
> |
f.complete(v1); |
989 |
> |
} |
990 |
|
|
975 |
– |
f = new CompletableFuture<>(); |
976 |
– |
f.complete(null); |
977 |
– |
g = f.thenRun(r = new Noop()); |
991 |
|
checkCompletedNormally(g, null); |
992 |
+ |
checkCompletedNormally(f, v1); |
993 |
|
assertEquals(1, r.invocationCount); |
994 |
< |
} |
994 |
> |
}} |
995 |
|
|
996 |
|
/** |
997 |
|
* thenRun result completes exceptionally after exceptional |
998 |
|
* completion of source |
999 |
|
*/ |
1000 |
< |
public void testThenRun2() { |
1001 |
< |
CompletableFuture<Integer> f; |
1002 |
< |
CompletableFuture<Void> g; |
1003 |
< |
Noop r; |
1004 |
< |
|
1005 |
< |
f = new CompletableFuture<>(); |
1006 |
< |
g = f.thenRun(r = new Noop()); |
1007 |
< |
f.completeExceptionally(new CFException()); |
1008 |
< |
checkCompletedWithWrappedCFException(g); |
1009 |
< |
assertEquals(0, r.invocationCount); |
1000 |
> |
public void testThenRun_exceptionalCompletion() { |
1001 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1002 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1003 |
> |
{ |
1004 |
> |
final CFException ex = new CFException(); |
1005 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1006 |
> |
final Noop r = new Noop(); |
1007 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1008 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1009 |
> |
if (createIncomplete) { |
1010 |
> |
checkIncomplete(g); |
1011 |
> |
f.completeExceptionally(ex); |
1012 |
> |
} |
1013 |
|
|
1014 |
< |
f = new CompletableFuture<>(); |
1015 |
< |
f.completeExceptionally(new CFException()); |
999 |
< |
g = f.thenRun(r = new Noop()); |
1000 |
< |
checkCompletedWithWrappedCFException(g); |
1014 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1015 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1016 |
|
assertEquals(0, r.invocationCount); |
1017 |
< |
} |
1017 |
> |
}} |
1018 |
|
|
1019 |
|
/** |
1020 |
< |
* thenRun result completes exceptionally if action does |
1020 |
> |
* thenRun result completes exceptionally if source cancelled |
1021 |
|
*/ |
1022 |
< |
public void testThenRun3() { |
1023 |
< |
CompletableFuture<Integer> f; |
1024 |
< |
CompletableFuture<Void> g; |
1025 |
< |
FailingNoop r; |
1026 |
< |
|
1027 |
< |
f = new CompletableFuture<>(); |
1028 |
< |
g = f.thenRun(r = new FailingNoop()); |
1029 |
< |
f.complete(null); |
1030 |
< |
checkCompletedWithWrappedCFException(g); |
1022 |
> |
public void testThenRun_sourceCancelled() { |
1023 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1024 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1025 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1026 |
> |
{ |
1027 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1028 |
> |
final Noop r = new Noop(); |
1029 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1030 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1031 |
> |
if (createIncomplete) { |
1032 |
> |
checkIncomplete(g); |
1033 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1034 |
> |
} |
1035 |
|
|
1036 |
< |
f = new CompletableFuture<>(); |
1037 |
< |
f.complete(null); |
1038 |
< |
g = f.thenRun(r = new FailingNoop()); |
1039 |
< |
checkCompletedWithWrappedCFException(g); |
1021 |
< |
} |
1036 |
> |
checkCompletedWithWrappedCancellationException(g); |
1037 |
> |
checkCancelled(f); |
1038 |
> |
assertEquals(0, r.invocationCount); |
1039 |
> |
}} |
1040 |
|
|
1041 |
|
/** |
1042 |
< |
* thenRun result completes exceptionally if source cancelled |
1042 |
> |
* thenRun result completes exceptionally if action does |
1043 |
|
*/ |
1044 |
< |
public void testThenRun4() { |
1045 |
< |
CompletableFuture<Integer> f; |
1046 |
< |
CompletableFuture<Void> g; |
1047 |
< |
Noop r; |
1048 |
< |
|
1049 |
< |
f = new CompletableFuture<>(); |
1050 |
< |
g = f.thenRun(r = new Noop()); |
1051 |
< |
assertTrue(f.cancel(true)); |
1052 |
< |
checkCompletedWithWrappedCancellationException(g); |
1044 |
> |
public void testThenRun_actionFailed() { |
1045 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1046 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1047 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1048 |
> |
{ |
1049 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1050 |
> |
final FailingRunnable r = new FailingRunnable(); |
1051 |
> |
if (!createIncomplete) f.complete(v1); |
1052 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1053 |
> |
if (createIncomplete) { |
1054 |
> |
checkIncomplete(g); |
1055 |
> |
f.complete(v1); |
1056 |
> |
} |
1057 |
|
|
1058 |
< |
f = new CompletableFuture<>(); |
1059 |
< |
assertTrue(f.cancel(true)); |
1060 |
< |
g = f.thenRun(r = new Noop()); |
1039 |
< |
checkCompletedWithWrappedCancellationException(g); |
1040 |
< |
} |
1058 |
> |
checkCompletedWithWrappedCFException(g); |
1059 |
> |
checkCompletedNormally(f, v1); |
1060 |
> |
}} |
1061 |
|
|
1062 |
|
/** |
1063 |
|
* thenApply result completes normally after normal completion of source |
1064 |
|
*/ |
1065 |
< |
public void testThenApply() { |
1066 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1067 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1068 |
< |
f.complete(one); |
1069 |
< |
checkCompletedNormally(g, two); |
1070 |
< |
} |
1065 |
> |
public void testThenApply_normalCompletion() { |
1066 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1067 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1068 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1069 |
> |
{ |
1070 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1071 |
> |
final IncFunction r = new IncFunction(); |
1072 |
> |
if (!createIncomplete) f.complete(v1); |
1073 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1074 |
> |
if (createIncomplete) { |
1075 |
> |
checkIncomplete(g); |
1076 |
> |
f.complete(v1); |
1077 |
> |
} |
1078 |
> |
|
1079 |
> |
checkCompletedNormally(g, inc(v1)); |
1080 |
> |
checkCompletedNormally(f, v1); |
1081 |
> |
assertEquals(1, r.invocationCount); |
1082 |
> |
}} |
1083 |
|
|
1084 |
|
/** |
1085 |
|
* thenApply result completes exceptionally after exceptional |
1086 |
|
* completion of source |
1087 |
|
*/ |
1088 |
< |
public void testThenApply2() { |
1089 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1090 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1091 |
< |
f.completeExceptionally(new CFException()); |
1092 |
< |
checkCompletedWithWrappedCFException(g); |
1093 |
< |
} |
1088 |
> |
public void testThenApply_exceptionalCompletion() { |
1089 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1090 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1091 |
> |
{ |
1092 |
> |
final CFException ex = new CFException(); |
1093 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1094 |
> |
final IncFunction r = new IncFunction(); |
1095 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1096 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1097 |
> |
if (createIncomplete) { |
1098 |
> |
checkIncomplete(g); |
1099 |
> |
f.completeExceptionally(ex); |
1100 |
> |
} |
1101 |
|
|
1102 |
< |
/** |
1103 |
< |
* thenApply result completes exceptionally if action does |
1104 |
< |
*/ |
1105 |
< |
public void testThenApply3() { |
1067 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1068 |
< |
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
1069 |
< |
f.complete(one); |
1070 |
< |
checkCompletedWithWrappedCFException(g); |
1071 |
< |
} |
1102 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1103 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1104 |
> |
assertEquals(0, r.invocationCount); |
1105 |
> |
}} |
1106 |
|
|
1107 |
|
/** |
1108 |
|
* thenApply result completes exceptionally if source cancelled |
1109 |
|
*/ |
1110 |
< |
public void testThenApply4() { |
1111 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1112 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1113 |
< |
assertTrue(f.cancel(true)); |
1110 |
> |
public void testThenApply_sourceCancelled() { |
1111 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1112 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1113 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1114 |
> |
{ |
1115 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1116 |
> |
final IncFunction r = new IncFunction(); |
1117 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1118 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1119 |
> |
if (createIncomplete) { |
1120 |
> |
checkIncomplete(g); |
1121 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1122 |
> |
} |
1123 |
> |
|
1124 |
|
checkCompletedWithWrappedCancellationException(g); |
1125 |
< |
} |
1125 |
> |
checkCancelled(f); |
1126 |
> |
assertEquals(0, r.invocationCount); |
1127 |
> |
}} |
1128 |
> |
|
1129 |
> |
/** |
1130 |
> |
* thenApply result completes exceptionally if action does |
1131 |
> |
*/ |
1132 |
> |
public void testThenApply_actionFailed() { |
1133 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1134 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1135 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1136 |
> |
{ |
1137 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1138 |
> |
final FailingFunction r = new FailingFunction(); |
1139 |
> |
if (!createIncomplete) f.complete(v1); |
1140 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1141 |
> |
if (createIncomplete) { |
1142 |
> |
checkIncomplete(g); |
1143 |
> |
f.complete(v1); |
1144 |
> |
} |
1145 |
> |
|
1146 |
> |
checkCompletedWithWrappedCFException(g); |
1147 |
> |
checkCompletedNormally(f, v1); |
1148 |
> |
}} |
1149 |
|
|
1150 |
|
/** |
1151 |
|
* thenAccept result completes normally after normal completion of source |
1152 |
|
*/ |
1153 |
< |
public void testThenAccept() { |
1154 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1155 |
< |
IncAction r = new IncAction(); |
1156 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1157 |
< |
f.complete(one); |
1153 |
> |
public void testThenAccept_normalCompletion() { |
1154 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1155 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1156 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1157 |
> |
{ |
1158 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1159 |
> |
final IncAction r = new IncAction(); |
1160 |
> |
if (!createIncomplete) f.complete(v1); |
1161 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1162 |
> |
if (createIncomplete) { |
1163 |
> |
checkIncomplete(g); |
1164 |
> |
f.complete(v1); |
1165 |
> |
} |
1166 |
> |
|
1167 |
|
checkCompletedNormally(g, null); |
1168 |
< |
assertEquals(r.value, (Integer) 2); |
1169 |
< |
} |
1168 |
> |
checkCompletedNormally(f, v1); |
1169 |
> |
assertEquals(1, r.invocationCount); |
1170 |
> |
assertEquals(inc(v1), r.value); |
1171 |
> |
}} |
1172 |
|
|
1173 |
|
/** |
1174 |
|
* thenAccept result completes exceptionally after exceptional |
1175 |
|
* completion of source |
1176 |
|
*/ |
1177 |
< |
public void testThenAccept2() { |
1178 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1179 |
< |
IncAction r = new IncAction(); |
1180 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1181 |
< |
f.completeExceptionally(new CFException()); |
1182 |
< |
checkCompletedWithWrappedCFException(g); |
1183 |
< |
} |
1177 |
> |
public void testThenAccept_exceptionalCompletion() { |
1178 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1179 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1180 |
> |
{ |
1181 |
> |
final CFException ex = new CFException(); |
1182 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1183 |
> |
final IncAction r = new IncAction(); |
1184 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1185 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1186 |
> |
if (createIncomplete) { |
1187 |
> |
checkIncomplete(g); |
1188 |
> |
f.completeExceptionally(ex); |
1189 |
> |
} |
1190 |
> |
|
1191 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1192 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1193 |
> |
assertEquals(0, r.invocationCount); |
1194 |
> |
}} |
1195 |
|
|
1196 |
|
/** |
1197 |
|
* thenAccept result completes exceptionally if action does |
1198 |
|
*/ |
1199 |
< |
public void testThenAccept3() { |
1200 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1201 |
< |
FailingConsumer r = new FailingConsumer(); |
1202 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1203 |
< |
f.complete(one); |
1199 |
> |
public void testThenAccept_actionFailed() { |
1200 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1201 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1202 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1203 |
> |
{ |
1204 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1205 |
> |
final FailingConsumer r = new FailingConsumer(); |
1206 |
> |
if (!createIncomplete) f.complete(v1); |
1207 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1208 |
> |
if (createIncomplete) { |
1209 |
> |
checkIncomplete(g); |
1210 |
> |
f.complete(v1); |
1211 |
> |
} |
1212 |
> |
|
1213 |
|
checkCompletedWithWrappedCFException(g); |
1214 |
< |
assertEquals(1, r.invocationCount); |
1215 |
< |
} |
1214 |
> |
checkCompletedNormally(f, v1); |
1215 |
> |
}} |
1216 |
|
|
1217 |
|
/** |
1218 |
|
* thenAccept result completes exceptionally if source cancelled |
1219 |
|
*/ |
1220 |
< |
public void testThenAccept4() { |
1221 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1222 |
< |
IncAction r = new IncAction(); |
1223 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1224 |
< |
assertTrue(f.cancel(true)); |
1220 |
> |
public void testThenAccept_sourceCancelled() { |
1221 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1222 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1223 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1224 |
> |
{ |
1225 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1226 |
> |
final IncAction r = new IncAction(); |
1227 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1228 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1229 |
> |
if (createIncomplete) { |
1230 |
> |
checkIncomplete(g); |
1231 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1232 |
> |
} |
1233 |
> |
|
1234 |
|
checkCompletedWithWrappedCancellationException(g); |
1235 |
< |
} |
1235 |
> |
checkCancelled(f); |
1236 |
> |
assertEquals(0, r.invocationCount); |
1237 |
> |
}} |
1238 |
|
|
1239 |
|
/** |
1240 |
|
* thenCombine result completes normally after normal completion |
1241 |
|
* of sources |
1242 |
|
*/ |
1243 |
< |
public void testThenCombine_normalCompletion1() { |
1243 |
> |
public void testThenCombine_normalCompletion() { |
1244 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1245 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
1246 |
|
for (boolean fFirst : new boolean[] { true, false }) |
1137 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1247 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1248 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1249 |
< |
|
1248 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1249 |
> |
{ |
1250 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1251 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1252 |
|
final SubtractFunction r = new SubtractFunction(); |
1144 |
– |
CompletableFuture<Integer> h = null; |
1145 |
– |
if (createIncomplete) h = m.thenCombine(f, g, r); |
1253 |
|
|
1254 |
< |
if (fFirst) |
1255 |
< |
f.complete(v1); |
1256 |
< |
else |
1257 |
< |
g.complete(v2); |
1258 |
< |
if (createIncomplete) checkIncomplete(h); |
1259 |
< |
assertEquals(0, r.invocationCount); |
1260 |
< |
if (!fFirst) |
1261 |
< |
f.complete(v1); |
1262 |
< |
else |
1156 |
< |
g.complete(v2); |
1157 |
< |
if (!createIncomplete) h = m.thenCombine(f, g, r); |
1254 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1255 |
> |
if (!createIncomplete) |
1256 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1257 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1258 |
> |
if (createIncomplete) { |
1259 |
> |
checkIncomplete(h); |
1260 |
> |
assertEquals(0, r.invocationCount); |
1261 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1262 |
> |
} |
1263 |
|
|
1264 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1265 |
|
checkCompletedNormally(f, v1); |
1266 |
|
checkCompletedNormally(g, v2); |
1267 |
|
assertEquals(1, r.invocationCount); |
1268 |
< |
} |
1164 |
< |
} |
1268 |
> |
}} |
1269 |
|
|
1270 |
|
/** |
1271 |
|
* thenCombine result completes exceptionally after exceptional |
1272 |
|
* completion of either source |
1273 |
|
*/ |
1274 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1274 |
> |
public void testThenCombine_exceptionalCompletion() { |
1275 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1277 |
< |
|
1276 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1277 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1278 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1279 |
> |
{ |
1280 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1281 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1176 |
– |
final SubtractFunction r = new SubtractFunction(); |
1177 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1282 |
|
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<>(); |
1283 |
|
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); |
1284 |
|
|
1285 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1286 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1287 |
< |
assertEquals(0, r.invocationCount); |
1208 |
< |
checkCompletedNormally(f, v1); |
1209 |
< |
} |
1210 |
< |
} |
1211 |
< |
|
1212 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1213 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1214 |
< |
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); |
1285 |
> |
(fFirst ? f : g).complete(v1); |
1286 |
> |
if (!createIncomplete) |
1287 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1288 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1289 |
< |
|
1290 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1291 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1227 |
< |
assertEquals(0, r.invocationCount); |
1228 |
< |
checkCompletedNormally(f, v1); |
1289 |
> |
if (createIncomplete) { |
1290 |
> |
checkIncomplete(h); |
1291 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1292 |
|
} |
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); |
1293 |
|
|
1294 |
|
checkCompletedWithWrappedCFException(h, ex); |
1246 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1295 |
|
assertEquals(0, r.invocationCount); |
1296 |
< |
checkCompletedNormally(g, v1); |
1297 |
< |
} |
1298 |
< |
} |
1296 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1297 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1298 |
> |
}} |
1299 |
|
|
1300 |
|
/** |
1301 |
|
* thenCombine result completes exceptionally if action does |
1302 |
|
*/ |
1303 |
< |
public void testThenCombine_actionFailed1() { |
1303 |
> |
public void testThenCombine_actionFailed() { |
1304 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1305 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1306 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1307 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1308 |
< |
|
1307 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1308 |
> |
{ |
1309 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1310 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1311 |
|
final FailingBiFunction r = new FailingBiFunction(); |
1312 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1313 |
|
|
1314 |
< |
f.complete(v1); |
1315 |
< |
checkIncomplete(h); |
1316 |
< |
g.complete(v2); |
1317 |
< |
|
1318 |
< |
checkCompletedWithWrappedCFException(h); |
1319 |
< |
checkCompletedNormally(f, v1); |
1271 |
< |
checkCompletedNormally(g, v2); |
1314 |
> |
if (fFirst) { |
1315 |
> |
f.complete(v1); |
1316 |
> |
g.complete(v2); |
1317 |
> |
} else { |
1318 |
> |
g.complete(v2); |
1319 |
> |
f.complete(v1); |
1320 |
|
} |
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); |
1321 |
|
|
1322 |
|
checkCompletedWithWrappedCFException(h); |
1323 |
|
checkCompletedNormally(f, v1); |
1324 |
|
checkCompletedNormally(g, v2); |
1325 |
< |
} |
1293 |
< |
} |
1325 |
> |
}} |
1326 |
|
|
1327 |
|
/** |
1328 |
|
* thenCombine result completes exceptionally if either source cancelled |
1329 |
|
*/ |
1330 |
< |
public void testThenCombine_sourceCancelled1() { |
1330 |
> |
public void testThenCombine_sourceCancelled() { |
1331 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1332 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1333 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1334 |
< |
|
1335 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1336 |
< |
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() { |
1341 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1342 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1343 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1344 |
< |
|
1333 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1334 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1335 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1336 |
> |
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
|
final SubtractFunction r = new SubtractFunction(); |
1340 |
|
|
1341 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1342 |
< |
f.complete(v1); |
1341 |
> |
(fFirst ? f : g).complete(v1); |
1342 |
> |
if (!createIncomplete) |
1343 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1344 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1345 |
< |
|
1346 |
< |
checkCompletedWithWrappedCancellationException(h); |
1347 |
< |
checkCancelled(g); |
1355 |
< |
assertEquals(0, r.invocationCount); |
1356 |
< |
checkCompletedNormally(f, v1); |
1345 |
> |
if (createIncomplete) { |
1346 |
> |
checkIncomplete(h); |
1347 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1348 |
|
} |
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); |
1349 |
|
|
1350 |
|
checkCompletedWithWrappedCancellationException(h); |
1351 |
< |
checkCancelled(f); |
1351 |
> |
checkCancelled(!fFirst ? f : g); |
1352 |
|
assertEquals(0, r.invocationCount); |
1353 |
< |
checkCompletedNormally(g, v1); |
1354 |
< |
} |
1378 |
< |
} |
1353 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1354 |
> |
}} |
1355 |
|
|
1356 |
|
/** |
1357 |
|
* thenAcceptBoth result completes normally after normal |
1358 |
|
* completion of sources |
1359 |
|
*/ |
1360 |
< |
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() { |
1360 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1361 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1362 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1363 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1364 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1365 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1366 |
< |
|
1365 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1366 |
> |
{ |
1367 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1368 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1369 |
|
final SubtractAction r = new SubtractAction(); |
1370 |
|
|
1371 |
< |
g.complete(v2); |
1372 |
< |
f.complete(v1); |
1371 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1372 |
> |
if (!createIncomplete) |
1373 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1374 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1375 |
< |
|
1376 |
< |
checkCompletedNormally(h, null); |
1377 |
< |
assertEquals(subtract(v1, v2), r.value); |
1378 |
< |
checkCompletedNormally(f, v1); |
1444 |
< |
checkCompletedNormally(g, v2); |
1375 |
> |
if (createIncomplete) { |
1376 |
> |
checkIncomplete(h); |
1377 |
> |
assertEquals(0, r.invocationCount); |
1378 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1379 |
|
} |
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); |
1380 |
|
|
1381 |
|
checkCompletedNormally(h, null); |
1382 |
|
assertEquals(subtract(v1, v2), r.value); |
1383 |
|
checkCompletedNormally(f, v1); |
1384 |
|
checkCompletedNormally(g, v2); |
1385 |
< |
} |
1466 |
< |
} |
1385 |
> |
}} |
1386 |
|
|
1387 |
|
/** |
1388 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1389 |
|
* completion of either source |
1390 |
|
*/ |
1391 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1391 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1392 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1393 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1394 |
< |
|
1395 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1396 |
< |
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 |
< |
|
1393 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1394 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1395 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1396 |
> |
{ |
1397 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1398 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1499 |
– |
final SubtractAction r = new SubtractAction(); |
1500 |
– |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1399 |
|
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<>(); |
1400 |
|
final SubtractAction r = new SubtractAction(); |
1521 |
– |
final CFException ex = new CFException(); |
1401 |
|
|
1402 |
< |
g.completeExceptionally(ex); |
1403 |
< |
f.complete(v1); |
1402 |
> |
(fFirst ? f : g).complete(v1); |
1403 |
> |
if (!createIncomplete) |
1404 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1405 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1406 |
< |
|
1407 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1408 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1529 |
< |
assertEquals(0, r.invocationCount); |
1530 |
< |
checkCompletedNormally(f, v1); |
1406 |
> |
if (createIncomplete) { |
1407 |
> |
checkIncomplete(h); |
1408 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1409 |
|
} |
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); |
1410 |
|
|
1411 |
|
checkCompletedWithWrappedCFException(h, ex); |
1548 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1412 |
|
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1414 |
< |
} |
1415 |
< |
} |
1413 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1414 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1415 |
> |
}} |
1416 |
|
|
1417 |
|
/** |
1418 |
|
* thenAcceptBoth result completes exceptionally if action does |
1419 |
|
*/ |
1420 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1420 |
> |
public void testThenAcceptBoth_actionFailed() { |
1421 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1422 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1423 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1424 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1425 |
< |
|
1424 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1425 |
> |
{ |
1426 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1427 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1428 |
|
final FailingBiConsumer r = new FailingBiConsumer(); |
1429 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1430 |
|
|
1431 |
< |
f.complete(v1); |
1432 |
< |
checkIncomplete(h); |
1433 |
< |
g.complete(v2); |
1434 |
< |
|
1435 |
< |
checkCompletedWithWrappedCFException(h); |
1436 |
< |
checkCompletedNormally(f, v1); |
1573 |
< |
checkCompletedNormally(g, v2); |
1431 |
> |
if (fFirst) { |
1432 |
> |
f.complete(v1); |
1433 |
> |
g.complete(v2); |
1434 |
> |
} else { |
1435 |
> |
g.complete(v2); |
1436 |
> |
f.complete(v1); |
1437 |
|
} |
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); |
1438 |
|
|
1439 |
|
checkCompletedWithWrappedCFException(h); |
1440 |
|
checkCompletedNormally(f, v1); |
1441 |
|
checkCompletedNormally(g, v2); |
1442 |
< |
} |
1595 |
< |
} |
1442 |
> |
}} |
1443 |
|
|
1444 |
|
/** |
1445 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1446 |
|
*/ |
1447 |
< |
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() { |
1622 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1623 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1624 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1625 |
< |
|
1626 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1627 |
< |
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() { |
1447 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1448 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1449 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1450 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1451 |
< |
|
1450 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1451 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1452 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1453 |
> |
{ |
1454 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1455 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1456 |
|
final SubtractAction r = new SubtractAction(); |
1457 |
|
|
1458 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1459 |
< |
f.complete(v1); |
1458 |
> |
(fFirst ? f : g).complete(v1); |
1459 |
> |
if (!createIncomplete) |
1460 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1461 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1462 |
< |
|
1463 |
< |
checkCompletedWithWrappedCancellationException(h); |
1464 |
< |
checkCancelled(g); |
1657 |
< |
assertEquals(0, r.invocationCount); |
1658 |
< |
checkCompletedNormally(f, v1); |
1462 |
> |
if (createIncomplete) { |
1463 |
> |
checkIncomplete(h); |
1464 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1465 |
|
} |
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); |
1466 |
|
|
1467 |
|
checkCompletedWithWrappedCancellationException(h); |
1468 |
< |
checkCancelled(f); |
1468 |
> |
checkCancelled(!fFirst ? f : g); |
1469 |
|
assertEquals(0, r.invocationCount); |
1470 |
< |
checkCompletedNormally(g, v1); |
1471 |
< |
} |
1680 |
< |
} |
1470 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1471 |
> |
}} |
1472 |
|
|
1473 |
|
/** |
1474 |
|
* runAfterBoth result completes normally after normal |
1475 |
|
* completion of sources |
1476 |
|
*/ |
1477 |
< |
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() { |
1477 |
> |
public void testRunAfterBoth_normalCompletion() { |
1478 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1479 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1480 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1481 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1482 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1483 |
< |
|
1482 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1483 |
> |
{ |
1484 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1485 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1486 |
|
final Noop r = new Noop(); |
1487 |
|
|
1488 |
< |
g.complete(v2); |
1489 |
< |
f.complete(v1); |
1488 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1489 |
> |
if (!createIncomplete) |
1490 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1491 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1492 |
< |
|
1493 |
< |
checkCompletedNormally(h, null); |
1494 |
< |
assertEquals(1, r.invocationCount); |
1495 |
< |
checkCompletedNormally(f, v1); |
1746 |
< |
checkCompletedNormally(g, v2); |
1492 |
> |
if (createIncomplete) { |
1493 |
> |
checkIncomplete(h); |
1494 |
> |
assertEquals(0, r.invocationCount); |
1495 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1496 |
|
} |
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); |
1497 |
|
|
1498 |
|
checkCompletedNormally(h, null); |
1499 |
|
assertEquals(1, r.invocationCount); |
1500 |
|
checkCompletedNormally(f, v1); |
1501 |
|
checkCompletedNormally(g, v2); |
1502 |
< |
} |
1768 |
< |
} |
1502 |
> |
}} |
1503 |
|
|
1504 |
|
/** |
1505 |
|
* runAfterBoth result completes exceptionally after exceptional |
1506 |
|
* completion of either source |
1507 |
|
*/ |
1508 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1508 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1509 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1510 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1511 |
< |
|
1512 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1513 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1780 |
< |
final Noop r = new Noop(); |
1781 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1782 |
< |
final CFException ex = new CFException(); |
1783 |
< |
|
1784 |
< |
f.completeExceptionally(ex); |
1785 |
< |
checkIncomplete(h); |
1786 |
< |
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 |
< |
|
1510 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1511 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1512 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1513 |
> |
{ |
1514 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1515 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1801 |
– |
final Noop r = new Noop(); |
1802 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1516 |
|
final CFException ex = new CFException(); |
1804 |
– |
|
1805 |
– |
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); |
1813 |
– |
} |
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<>(); |
1517 |
|
final Noop r = new Noop(); |
1823 |
– |
final CFException ex = new CFException(); |
1518 |
|
|
1519 |
< |
g.completeExceptionally(ex); |
1520 |
< |
f.complete(v1); |
1519 |
> |
(fFirst ? f : g).complete(v1); |
1520 |
> |
if (!createIncomplete) |
1521 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1522 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1523 |
< |
|
1524 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1525 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1831 |
< |
assertEquals(0, r.invocationCount); |
1832 |
< |
checkCompletedNormally(f, v1); |
1523 |
> |
if (createIncomplete) { |
1524 |
> |
checkIncomplete(h); |
1525 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1526 |
|
} |
1834 |
– |
} |
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); |
1527 |
|
|
1528 |
|
checkCompletedWithWrappedCFException(h, ex); |
1850 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1529 |
|
assertEquals(0, r.invocationCount); |
1530 |
< |
checkCompletedNormally(g, v1); |
1531 |
< |
} |
1532 |
< |
} |
1530 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1531 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1532 |
> |
}} |
1533 |
|
|
1534 |
|
/** |
1535 |
|
* runAfterBoth result completes exceptionally if action does |
1536 |
|
*/ |
1537 |
< |
public void testRunAfterBoth_actionFailed1() { |
1537 |
> |
public void testRunAfterBoth_actionFailed() { |
1538 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1539 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1540 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1541 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1542 |
< |
|
1541 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1542 |
> |
{ |
1543 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1544 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1545 |
< |
final FailingNoop r = new FailingNoop(); |
1867 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1545 |
> |
final FailingRunnable r = new FailingRunnable(); |
1546 |
|
|
1547 |
< |
f.complete(v1); |
1548 |
< |
checkIncomplete(h); |
1549 |
< |
g.complete(v2); |
1550 |
< |
|
1551 |
< |
checkCompletedWithWrappedCFException(h); |
1552 |
< |
checkCompletedNormally(f, v1); |
1553 |
< |
checkCompletedNormally(g, v2); |
1547 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1548 |
> |
if (fFirst) { |
1549 |
> |
f.complete(v1); |
1550 |
> |
g.complete(v2); |
1551 |
> |
} else { |
1552 |
> |
g.complete(v2); |
1553 |
> |
f.complete(v1); |
1554 |
|
} |
1555 |
< |
} |
1555 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1556 |
|
|
1557 |
< |
public void testRunAfterBoth_actionFailed2() { |
1558 |
< |
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); |
1557 |
> |
checkCompletedWithWrappedCFException(h1); |
1558 |
> |
checkCompletedWithWrappedCFException(h2); |
1559 |
|
checkCompletedNormally(f, v1); |
1560 |
|
checkCompletedNormally(g, v2); |
1561 |
< |
} |
1897 |
< |
} |
1561 |
> |
}} |
1562 |
|
|
1563 |
|
/** |
1564 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1565 |
|
*/ |
1566 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1903 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1904 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1905 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1906 |
< |
|
1907 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1908 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1909 |
< |
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); |
1915 |
< |
|
1916 |
< |
checkCompletedWithWrappedCancellationException(h); |
1917 |
< |
checkCancelled(f); |
1918 |
< |
assertEquals(0, r.invocationCount); |
1919 |
< |
checkCompletedNormally(g, v1); |
1920 |
< |
} |
1921 |
< |
} |
1922 |
< |
|
1923 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1566 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1567 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1568 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1569 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1570 |
< |
|
1569 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1570 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1571 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1572 |
> |
{ |
1573 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1574 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1575 |
|
final Noop r = new Noop(); |
1931 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1932 |
– |
|
1933 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1934 |
– |
checkIncomplete(h); |
1935 |
– |
f.complete(v1); |
1936 |
– |
|
1937 |
– |
checkCompletedWithWrappedCancellationException(h); |
1938 |
– |
checkCancelled(g); |
1939 |
– |
assertEquals(0, r.invocationCount); |
1940 |
– |
checkCompletedNormally(f, v1); |
1941 |
– |
} |
1942 |
– |
} |
1576 |
|
|
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 }) { |
1577 |
|
|
1578 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1579 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1580 |
< |
final Noop r = new Noop(); |
1952 |
< |
|
1953 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1954 |
< |
f.complete(v1); |
1578 |
> |
(fFirst ? f : g).complete(v1); |
1579 |
> |
if (!createIncomplete) |
1580 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1581 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1582 |
< |
|
1583 |
< |
checkCompletedWithWrappedCancellationException(h); |
1584 |
< |
checkCancelled(g); |
1959 |
< |
assertEquals(0, r.invocationCount); |
1960 |
< |
checkCompletedNormally(f, v1); |
1582 |
> |
if (createIncomplete) { |
1583 |
> |
checkIncomplete(h); |
1584 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1585 |
|
} |
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); |
1586 |
|
|
1587 |
|
checkCompletedWithWrappedCancellationException(h); |
1588 |
< |
checkCancelled(f); |
1588 |
> |
checkCancelled(!fFirst ? f : g); |
1589 |
|
assertEquals(0, r.invocationCount); |
1590 |
< |
checkCompletedNormally(g, v1); |
1591 |
< |
} |
1982 |
< |
} |
1590 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1591 |
> |
}} |
1592 |
|
|
1593 |
|
/** |
1594 |
|
* applyToEither result completes normally after normal completion |
1595 |
|
* of either source |
1596 |
|
*/ |
1597 |
< |
public void testApplyToEither_normalCompletion1() { |
1597 |
> |
public void testApplyToEither_normalCompletion() { |
1598 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1599 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1600 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1601 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1602 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1603 |
< |
|
1602 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1603 |
> |
{ |
1604 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1605 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1606 |
|
final IncFunction r = new IncFunction(); |
1996 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1607 |
|
|
1608 |
< |
f.complete(v1); |
1609 |
< |
checkCompletedNormally(h, inc(v1)); |
1610 |
< |
g.complete(v2); |
1608 |
> |
if (!createIncomplete) |
1609 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1610 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1611 |
> |
if (createIncomplete) { |
1612 |
> |
checkIncomplete(h); |
1613 |
> |
assertEquals(0, r.invocationCount); |
1614 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1615 |
> |
} |
1616 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1617 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1618 |
|
|
1619 |
|
checkCompletedNormally(f, v1); |
1620 |
|
checkCompletedNormally(g, v2); |
1621 |
< |
checkCompletedNormally(h, inc(v1)); |
1622 |
< |
} |
2006 |
< |
} |
1621 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1622 |
> |
}} |
1623 |
|
|
1624 |
< |
public void testApplyToEither_normalCompletion2() { |
1624 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1625 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1626 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1627 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1628 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1629 |
< |
|
1628 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1629 |
> |
{ |
1630 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1631 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1632 |
|
final IncFunction r = new IncFunction(); |
2016 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2017 |
– |
|
2018 |
– |
g.complete(v2); |
2019 |
– |
checkCompletedNormally(h, inc(v2)); |
2020 |
– |
f.complete(v1); |
1633 |
|
|
1634 |
< |
checkCompletedNormally(f, v1); |
1635 |
< |
checkCompletedNormally(g, v2); |
1636 |
< |
checkCompletedNormally(h, inc(v2)); |
1634 |
> |
if (fFirst) { |
1635 |
> |
f.complete(v1); |
1636 |
> |
g.complete(v2); |
1637 |
> |
} else { |
1638 |
> |
g.complete(v2); |
1639 |
> |
f.complete(v1); |
1640 |
|
} |
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(); |
1641 |
|
|
2036 |
– |
f.complete(v1); |
2037 |
– |
g.complete(v2); |
1642 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1643 |
|
|
1644 |
|
checkCompletedNormally(f, v1); |
1648 |
|
assertTrue(Objects.equals(h.join(), inc(v1)) || |
1649 |
|
Objects.equals(h.join(), inc(v2))); |
1650 |
|
assertEquals(1, r.invocationCount); |
1651 |
< |
} |
2048 |
< |
} |
1651 |
> |
}} |
1652 |
|
|
1653 |
|
/** |
1654 |
|
* applyToEither result completes exceptionally after exceptional |
1656 |
|
*/ |
1657 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1658 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1659 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1660 |
< |
|
1659 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1660 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1661 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1662 |
> |
{ |
1663 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1664 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1665 |
+ |
final CFException ex = new CFException(); |
1666 |
|
final IncFunction r = new IncFunction(); |
1667 |
+ |
|
1668 |
+ |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1669 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1670 |
< |
final CFException ex = new CFException(); |
1670 |
> |
if (createIncomplete) { |
1671 |
> |
checkIncomplete(h); |
1672 |
> |
assertEquals(0, r.invocationCount); |
1673 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1674 |
> |
} |
1675 |
|
|
2064 |
– |
f.completeExceptionally(ex); |
1676 |
|
checkCompletedWithWrappedCFException(h, ex); |
1677 |
< |
g.complete(v1); |
1677 |
> |
(!fFirst ? f : g).complete(v1); |
1678 |
|
|
1679 |
|
assertEquals(0, r.invocationCount); |
1680 |
< |
checkCompletedNormally(g, v1); |
1681 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1680 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1681 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1682 |
|
checkCompletedWithWrappedCFException(h, ex); |
1683 |
< |
} |
2073 |
< |
} |
1683 |
> |
}} |
1684 |
|
|
1685 |
|
public void testApplyToEither_exceptionalCompletion2() { |
1686 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1687 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1688 |
< |
|
1687 |
> |
for (boolean reverseArgs : new boolean[] { true, false }) |
1688 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1689 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1690 |
> |
{ |
1691 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1692 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1693 |
< |
final IncFunction r = new IncFunction(); |
1694 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1693 |
> |
final IncFunction r1 = new IncFunction(); |
1694 |
> |
final IncFunction r2 = new IncFunction(); |
1695 |
|
final CFException ex = new CFException(); |
1696 |
< |
|
1697 |
< |
g.completeExceptionally(ex); |
1698 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1699 |
< |
f.complete(v1); |
1700 |
< |
|
1701 |
< |
assertEquals(0, r.invocationCount); |
1702 |
< |
checkCompletedNormally(f, v1); |
1703 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1704 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1696 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1697 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1698 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1699 |
> |
if (fFirst) { |
1700 |
> |
f.complete(v1); |
1701 |
> |
g.completeExceptionally(ex); |
1702 |
> |
} else { |
1703 |
> |
g.completeExceptionally(ex); |
1704 |
> |
f.complete(v1); |
1705 |
|
} |
1706 |
< |
} |
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); |
1706 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1707 |
|
|
1708 |
|
// unspecified behavior |
2110 |
– |
Integer v; |
1709 |
|
try { |
1710 |
< |
assertEquals(inc(v1), h.join()); |
1711 |
< |
assertEquals(1, r.invocationCount); |
1710 |
> |
assertEquals(inc(v1), h1.join()); |
1711 |
> |
assertEquals(1, r1.invocationCount); |
1712 |
|
} catch (CompletionException ok) { |
1713 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1714 |
< |
assertEquals(0, r.invocationCount); |
1713 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1714 |
> |
assertEquals(0, r1.invocationCount); |
1715 |
|
} |
1716 |
|
|
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; |
1717 |
|
try { |
1718 |
< |
assertEquals(inc(v1), h.join()); |
1719 |
< |
assertEquals(1, r.invocationCount); |
1718 |
> |
assertEquals(inc(v1), h2.join()); |
1719 |
> |
assertEquals(1, r2.invocationCount); |
1720 |
|
} catch (CompletionException ok) { |
1721 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1722 |
< |
assertEquals(0, r.invocationCount); |
1721 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1722 |
> |
assertEquals(0, r2.invocationCount); |
1723 |
|
} |
1724 |
|
|
1725 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1726 |
< |
checkCompletedNormally(g, v1); |
1727 |
< |
} |
2150 |
< |
} |
1725 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1726 |
> |
checkCompletedNormally(f, v1); |
1727 |
> |
}} |
1728 |
|
|
1729 |
|
/** |
1730 |
|
* applyToEither result completes exceptionally if action does |
1732 |
|
public void testApplyToEither_actionFailed1() { |
1733 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1734 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1735 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1736 |
< |
|
1735 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1736 |
> |
{ |
1737 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1738 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1739 |
|
final FailingFunction r = new FailingFunction(); |
1744 |
|
g.complete(v2); |
1745 |
|
checkCompletedNormally(f, v1); |
1746 |
|
checkCompletedNormally(g, v2); |
1747 |
< |
} |
2171 |
< |
} |
1747 |
> |
}} |
1748 |
|
|
1749 |
|
public void testApplyToEither_actionFailed2() { |
1750 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1751 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1752 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1753 |
< |
|
1752 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1753 |
> |
{ |
1754 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1755 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1756 |
|
final FailingFunction r = new FailingFunction(); |
1761 |
|
f.complete(v1); |
1762 |
|
checkCompletedNormally(f, v1); |
1763 |
|
checkCompletedNormally(g, v2); |
1764 |
< |
} |
2189 |
< |
} |
1764 |
> |
}} |
1765 |
|
|
1766 |
|
/** |
1767 |
|
* applyToEither result completes exceptionally if either source cancelled |
1769 |
|
public void testApplyToEither_sourceCancelled1() { |
1770 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1771 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1772 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1773 |
< |
|
1772 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1773 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1774 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1775 |
> |
{ |
1776 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1777 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1778 |
|
final IncFunction r = new IncFunction(); |
1779 |
+ |
|
1780 |
+ |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1781 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1782 |
+ |
if (createIncomplete) { |
1783 |
+ |
checkIncomplete(h); |
1784 |
+ |
assertEquals(0, r.invocationCount); |
1785 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1786 |
+ |
} |
1787 |
|
|
2204 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1788 |
|
checkCompletedWithWrappedCancellationException(h); |
1789 |
< |
g.complete(v1); |
1789 |
> |
(!fFirst ? f : g).complete(v1); |
1790 |
|
|
2208 |
– |
checkCancelled(f); |
1791 |
|
assertEquals(0, r.invocationCount); |
1792 |
< |
checkCompletedNormally(g, v1); |
1792 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1793 |
> |
checkCancelled(fFirst ? f : g); |
1794 |
|
checkCompletedWithWrappedCancellationException(h); |
1795 |
< |
} |
2213 |
< |
} |
1795 |
> |
}} |
1796 |
|
|
1797 |
|
public void testApplyToEither_sourceCancelled2() { |
1798 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1799 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1800 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1801 |
< |
|
1800 |
> |
for (boolean reverseArgs : new boolean[] { true, false }) |
1801 |
> |
for (boolean fFirst : new boolean[] { true, false }) |
1802 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1803 |
> |
{ |
1804 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1805 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1806 |
< |
final IncFunction r = new IncFunction(); |
1807 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1808 |
< |
|
1809 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1810 |
< |
checkCompletedWithWrappedCancellationException(h); |
2227 |
< |
f.complete(v1); |
1806 |
> |
final IncFunction r1 = new IncFunction(); |
1807 |
> |
final IncFunction r2 = new IncFunction(); |
1808 |
> |
final CFException ex = new CFException(); |
1809 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1810 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1811 |
|
|
1812 |
< |
checkCancelled(g); |
1813 |
< |
assertEquals(0, r.invocationCount); |
1814 |
< |
checkCompletedNormally(f, v1); |
1815 |
< |
checkCompletedWithWrappedCancellationException(h); |
1812 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1813 |
> |
if (fFirst) { |
1814 |
> |
f.complete(v1); |
1815 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1816 |
> |
} else { |
1817 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1818 |
> |
f.complete(v1); |
1819 |
|
} |
1820 |
< |
} |
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); |
1820 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1821 |
|
|
1822 |
|
// unspecified behavior |
2250 |
– |
Integer v; |
1823 |
|
try { |
1824 |
< |
assertEquals(inc(v1), h.join()); |
1825 |
< |
assertEquals(1, r.invocationCount); |
1824 |
> |
assertEquals(inc(v1), h1.join()); |
1825 |
> |
assertEquals(1, r1.invocationCount); |
1826 |
|
} catch (CompletionException ok) { |
1827 |
< |
checkCompletedWithWrappedCancellationException(h); |
1828 |
< |
assertEquals(0, r.invocationCount); |
2257 |
< |
} |
2258 |
< |
|
2259 |
< |
checkCancelled(g); |
2260 |
< |
checkCompletedNormally(f, v1); |
1827 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1828 |
> |
assertEquals(0, r1.invocationCount); |
1829 |
|
} |
2262 |
– |
} |
1830 |
|
|
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; |
1831 |
|
try { |
1832 |
< |
assertEquals(inc(v1), h.join()); |
1833 |
< |
assertEquals(1, r.invocationCount); |
1832 |
> |
assertEquals(inc(v1), h2.join()); |
1833 |
> |
assertEquals(1, r2.invocationCount); |
1834 |
|
} catch (CompletionException ok) { |
1835 |
< |
checkCompletedWithWrappedCancellationException(h); |
1836 |
< |
assertEquals(0, r.invocationCount); |
1835 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1836 |
> |
assertEquals(0, r2.invocationCount); |
1837 |
|
} |
1838 |
|
|
1839 |
< |
checkCancelled(f); |
1840 |
< |
checkCompletedNormally(g, v1); |
1841 |
< |
} |
2290 |
< |
} |
1839 |
> |
checkCancelled(g); |
1840 |
> |
checkCompletedNormally(f, v1); |
1841 |
> |
}} |
1842 |
|
|
1843 |
|
/** |
1844 |
|
* acceptEither result completes normally after normal completion |
1847 |
|
public void testAcceptEither_normalCompletion1() { |
1848 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1849 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1850 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1851 |
< |
|
1850 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1851 |
> |
{ |
1852 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1853 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1854 |
|
final IncAction r = new IncAction(); |
1862 |
|
checkCompletedNormally(f, v1); |
1863 |
|
checkCompletedNormally(g, v2); |
1864 |
|
checkCompletedNormally(h, null); |
1865 |
< |
} |
2315 |
< |
} |
1865 |
> |
}} |
1866 |
|
|
1867 |
|
public void testAcceptEither_normalCompletion2() { |
1868 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1869 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1870 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1871 |
< |
|
1870 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1871 |
> |
{ |
1872 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1873 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1874 |
|
final IncAction r = new IncAction(); |
1882 |
|
checkCompletedNormally(f, v1); |
1883 |
|
checkCompletedNormally(g, v2); |
1884 |
|
checkCompletedNormally(h, null); |
1885 |
< |
} |
1886 |
< |
} |
1885 |
> |
}} |
1886 |
> |
|
1887 |
|
public void testAcceptEither_normalCompletion3() { |
1888 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1889 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1890 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1891 |
< |
|
1890 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1891 |
> |
{ |
1892 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1893 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1894 |
|
final IncAction r = new IncAction(); |
1904 |
|
// unspecified behavior |
1905 |
|
assertTrue(Objects.equals(r.value, inc(v1)) || |
1906 |
|
Objects.equals(r.value, inc(v2))); |
1907 |
< |
} |
2358 |
< |
} |
1907 |
> |
}} |
1908 |
|
|
1909 |
|
/** |
1910 |
|
* acceptEither result completes exceptionally after exceptional |
1912 |
|
*/ |
1913 |
|
public void testAcceptEither_exceptionalCompletion1() { |
1914 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1915 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1916 |
< |
|
1915 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1916 |
> |
{ |
1917 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1918 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1919 |
|
final IncAction r = new IncAction(); |
1928 |
|
checkCompletedNormally(g, v1); |
1929 |
|
checkCompletedWithWrappedCFException(f, ex); |
1930 |
|
checkCompletedWithWrappedCFException(h, ex); |
1931 |
< |
} |
2383 |
< |
} |
1931 |
> |
}} |
1932 |
|
|
1933 |
|
public void testAcceptEither_exceptionalCompletion2() { |
1934 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1935 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1936 |
< |
|
1935 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1936 |
> |
{ |
1937 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1938 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1939 |
|
final IncAction r = new IncAction(); |
1948 |
|
checkCompletedNormally(f, v1); |
1949 |
|
checkCompletedWithWrappedCFException(g, ex); |
1950 |
|
checkCompletedWithWrappedCFException(h, ex); |
1951 |
< |
} |
2404 |
< |
} |
1951 |
> |
}} |
1952 |
|
|
1953 |
|
public void testAcceptEither_exceptionalCompletion3() { |
1954 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1955 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1956 |
< |
|
1955 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1956 |
> |
{ |
1957 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1958 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1959 |
|
final IncAction r = new IncAction(); |
1976 |
|
|
1977 |
|
checkCompletedWithWrappedCFException(g, ex); |
1978 |
|
checkCompletedNormally(f, v1); |
1979 |
< |
} |
2433 |
< |
} |
1979 |
> |
}} |
1980 |
|
|
1981 |
|
public void testAcceptEither_exceptionalCompletion4() { |
1982 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1983 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1984 |
< |
|
1983 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1984 |
> |
{ |
1985 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1986 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1987 |
|
final IncAction r = new IncAction(); |
2004 |
|
|
2005 |
|
checkCompletedWithWrappedCFException(f, ex); |
2006 |
|
checkCompletedNormally(g, v1); |
2007 |
< |
} |
2462 |
< |
} |
2007 |
> |
}} |
2008 |
|
|
2009 |
|
/** |
2010 |
|
* acceptEither result completes exceptionally if action does |
2012 |
|
public void testAcceptEither_actionFailed1() { |
2013 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2014 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2015 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2016 |
< |
|
2015 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2016 |
> |
{ |
2017 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2018 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2019 |
|
final FailingConsumer r = new FailingConsumer(); |
2024 |
|
g.complete(v2); |
2025 |
|
checkCompletedNormally(f, v1); |
2026 |
|
checkCompletedNormally(g, v2); |
2027 |
< |
} |
2483 |
< |
} |
2027 |
> |
}} |
2028 |
|
|
2029 |
|
public void testAcceptEither_actionFailed2() { |
2030 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2031 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2032 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2033 |
< |
|
2032 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2033 |
> |
{ |
2034 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2035 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2036 |
|
final FailingConsumer r = new FailingConsumer(); |
2041 |
|
f.complete(v1); |
2042 |
|
checkCompletedNormally(f, v1); |
2043 |
|
checkCompletedNormally(g, v2); |
2044 |
< |
} |
2501 |
< |
} |
2044 |
> |
}} |
2045 |
|
|
2046 |
|
/** |
2047 |
|
* acceptEither result completes exceptionally if either source cancelled |
2049 |
|
public void testAcceptEither_sourceCancelled1() { |
2050 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2051 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2052 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2053 |
< |
|
2052 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2053 |
> |
{ |
2054 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2055 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2056 |
|
final IncAction r = new IncAction(); |
2064 |
|
assertEquals(0, r.invocationCount); |
2065 |
|
checkCompletedNormally(g, v1); |
2066 |
|
checkCompletedWithWrappedCancellationException(h); |
2067 |
< |
} |
2525 |
< |
} |
2067 |
> |
}} |
2068 |
|
|
2069 |
|
public void testAcceptEither_sourceCancelled2() { |
2070 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2071 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2072 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2073 |
< |
|
2072 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2073 |
> |
{ |
2074 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2075 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2076 |
|
final IncAction r = new IncAction(); |
2084 |
|
assertEquals(0, r.invocationCount); |
2085 |
|
checkCompletedNormally(f, v1); |
2086 |
|
checkCompletedWithWrappedCancellationException(h); |
2087 |
< |
} |
2546 |
< |
} |
2087 |
> |
}} |
2088 |
|
|
2089 |
|
public void testAcceptEither_sourceCancelled3() { |
2090 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2091 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2092 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2093 |
< |
|
2092 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2093 |
> |
{ |
2094 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2095 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2096 |
|
final IncAction r = new IncAction(); |
2112 |
|
|
2113 |
|
checkCancelled(g); |
2114 |
|
checkCompletedNormally(f, v1); |
2115 |
< |
} |
2575 |
< |
} |
2115 |
> |
}} |
2116 |
|
|
2117 |
|
public void testAcceptEither_sourceCancelled4() { |
2118 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2119 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2120 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2121 |
< |
|
2120 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2121 |
> |
{ |
2122 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2123 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
|
final IncAction r = new IncAction(); |
2140 |
|
|
2141 |
|
checkCancelled(f); |
2142 |
|
checkCompletedNormally(g, v1); |
2143 |
< |
} |
2604 |
< |
} |
2143 |
> |
}} |
2144 |
|
|
2145 |
|
/** |
2146 |
|
* runAfterEither result completes normally after normal completion |
2149 |
|
public void testRunAfterEither_normalCompletion1() { |
2150 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2151 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2152 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2153 |
< |
|
2152 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2153 |
> |
{ |
2154 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2155 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2156 |
|
final Noop r = new Noop(); |
2165 |
|
checkCompletedNormally(g, v2); |
2166 |
|
checkCompletedNormally(h, null); |
2167 |
|
assertEquals(1, r.invocationCount); |
2168 |
< |
} |
2630 |
< |
} |
2168 |
> |
}} |
2169 |
|
|
2170 |
|
public void testRunAfterEither_normalCompletion2() { |
2171 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2172 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2173 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2174 |
< |
|
2173 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2174 |
> |
{ |
2175 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2176 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2177 |
|
final Noop r = new Noop(); |
2186 |
|
checkCompletedNormally(g, v2); |
2187 |
|
checkCompletedNormally(h, null); |
2188 |
|
assertEquals(1, r.invocationCount); |
2189 |
< |
} |
2190 |
< |
} |
2189 |
> |
}} |
2190 |
> |
|
2191 |
|
public void testRunAfterEither_normalCompletion3() { |
2192 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2193 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2194 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2195 |
< |
|
2194 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2195 |
> |
{ |
2196 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2197 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2198 |
|
final Noop r = new Noop(); |
2205 |
|
checkCompletedNormally(f, v1); |
2206 |
|
checkCompletedNormally(g, v2); |
2207 |
|
assertEquals(1, r.invocationCount); |
2208 |
< |
} |
2671 |
< |
} |
2208 |
> |
}} |
2209 |
|
|
2210 |
|
/** |
2211 |
|
* runAfterEither result completes exceptionally after exceptional |
2213 |
|
*/ |
2214 |
|
public void testRunAfterEither_exceptionalCompletion1() { |
2215 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2216 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2217 |
< |
|
2216 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2217 |
> |
{ |
2218 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2219 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2220 |
|
final Noop r = new Noop(); |
2229 |
|
checkCompletedNormally(g, v1); |
2230 |
|
checkCompletedWithWrappedCFException(f, ex); |
2231 |
|
checkCompletedWithWrappedCFException(h, ex); |
2232 |
< |
} |
2696 |
< |
} |
2232 |
> |
}} |
2233 |
|
|
2234 |
|
public void testRunAfterEither_exceptionalCompletion2() { |
2235 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2236 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2237 |
< |
|
2236 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2237 |
> |
{ |
2238 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2239 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2240 |
|
final Noop r = new Noop(); |
2249 |
|
checkCompletedNormally(f, v1); |
2250 |
|
checkCompletedWithWrappedCFException(g, ex); |
2251 |
|
checkCompletedWithWrappedCFException(h, ex); |
2252 |
< |
} |
2717 |
< |
} |
2252 |
> |
}} |
2253 |
|
|
2254 |
|
public void testRunAfterEither_exceptionalCompletion3() { |
2255 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2256 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2257 |
< |
|
2256 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2257 |
> |
{ |
2258 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2259 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2260 |
|
final Noop r = new Noop(); |
2276 |
|
|
2277 |
|
checkCompletedWithWrappedCFException(g, ex); |
2278 |
|
checkCompletedNormally(f, v1); |
2279 |
< |
} |
2745 |
< |
} |
2279 |
> |
}} |
2280 |
|
|
2281 |
|
public void testRunAfterEither_exceptionalCompletion4() { |
2282 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2283 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2284 |
< |
|
2283 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2284 |
> |
{ |
2285 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2286 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2287 |
|
final Noop r = new Noop(); |
2303 |
|
|
2304 |
|
checkCompletedWithWrappedCFException(f, ex); |
2305 |
|
checkCompletedNormally(g, v1); |
2306 |
< |
} |
2773 |
< |
} |
2306 |
> |
}} |
2307 |
|
|
2308 |
|
/** |
2309 |
|
* runAfterEither result completes exceptionally if action does |
2311 |
|
public void testRunAfterEither_actionFailed1() { |
2312 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2313 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2314 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2315 |
< |
|
2314 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2315 |
> |
{ |
2316 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2317 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2318 |
< |
final FailingNoop r = new FailingNoop(); |
2318 |
> |
final FailingRunnable r = new FailingRunnable(); |
2319 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2320 |
|
|
2321 |
|
f.complete(v1); |
2323 |
|
g.complete(v2); |
2324 |
|
checkCompletedNormally(f, v1); |
2325 |
|
checkCompletedNormally(g, v2); |
2326 |
< |
} |
2794 |
< |
} |
2326 |
> |
}} |
2327 |
|
|
2328 |
|
public void testRunAfterEither_actionFailed2() { |
2329 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2330 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2331 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2332 |
< |
|
2331 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2332 |
> |
{ |
2333 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2334 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2335 |
< |
final FailingNoop r = new FailingNoop(); |
2335 |
> |
final FailingRunnable r = new FailingRunnable(); |
2336 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2337 |
|
|
2338 |
|
g.complete(v2); |
2340 |
|
f.complete(v1); |
2341 |
|
checkCompletedNormally(f, v1); |
2342 |
|
checkCompletedNormally(g, v2); |
2343 |
< |
} |
2812 |
< |
} |
2343 |
> |
}} |
2344 |
|
|
2345 |
|
/** |
2346 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2348 |
|
public void testRunAfterEither_sourceCancelled1() { |
2349 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2350 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2351 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2352 |
< |
|
2351 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2352 |
> |
{ |
2353 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2354 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2355 |
|
final Noop r = new Noop(); |
2363 |
|
assertEquals(0, r.invocationCount); |
2364 |
|
checkCompletedNormally(g, v1); |
2365 |
|
checkCompletedWithWrappedCancellationException(h); |
2366 |
< |
} |
2836 |
< |
} |
2366 |
> |
}} |
2367 |
|
|
2368 |
|
public void testRunAfterEither_sourceCancelled2() { |
2369 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2370 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2371 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2372 |
< |
|
2371 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2372 |
> |
{ |
2373 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2374 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2375 |
|
final Noop r = new Noop(); |
2383 |
|
assertEquals(0, r.invocationCount); |
2384 |
|
checkCompletedNormally(f, v1); |
2385 |
|
checkCompletedWithWrappedCancellationException(h); |
2386 |
< |
} |
2857 |
< |
} |
2386 |
> |
}} |
2387 |
|
|
2388 |
|
public void testRunAfterEither_sourceCancelled3() { |
2389 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2390 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2391 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2392 |
< |
|
2391 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2392 |
> |
{ |
2393 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2394 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2395 |
|
final Noop r = new Noop(); |
2410 |
|
|
2411 |
|
checkCancelled(g); |
2412 |
|
checkCompletedNormally(f, v1); |
2413 |
< |
} |
2885 |
< |
} |
2413 |
> |
}} |
2414 |
|
|
2415 |
|
public void testRunAfterEither_sourceCancelled4() { |
2416 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2417 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2418 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2419 |
< |
|
2418 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2419 |
> |
{ |
2420 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2421 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2422 |
|
final Noop r = new Noop(); |
2437 |
|
|
2438 |
|
checkCancelled(f); |
2439 |
|
checkCompletedNormally(g, v1); |
2440 |
< |
} |
2913 |
< |
} |
2440 |
> |
}} |
2441 |
|
|
2442 |
|
/** |
2443 |
|
* thenCompose result completes normally after normal completion of source |
2444 |
|
*/ |
2445 |
< |
public void testThenCompose_normalCompletion1() { |
2445 |
> |
public void testThenCompose_normalCompletion() { |
2446 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2447 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2448 |
< |
|
2447 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2448 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2449 |
> |
{ |
2450 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2451 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2452 |
+ |
if (!createIncomplete) f.complete(v1); |
2453 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2454 |
< |
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 }) { |
2454 |
> |
if (createIncomplete) f.complete(v1); |
2455 |
|
|
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); |
2456 |
|
checkCompletedNormally(g, inc(v1)); |
2457 |
|
checkCompletedNormally(f, v1); |
2458 |
|
assertEquals(1, r.invocationCount); |
2459 |
< |
} |
2944 |
< |
} |
2459 |
> |
}} |
2460 |
|
|
2461 |
|
/** |
2462 |
|
* thenCompose result completes exceptionally after exceptional |
2463 |
|
* completion of source |
2464 |
|
*/ |
2465 |
< |
public void testThenCompose_exceptionalCompletion1() { |
2466 |
< |
for (ExecutionMode m : ExecutionMode.values()) { |
2467 |
< |
|
2465 |
> |
public void testThenCompose_exceptionalCompletion() { |
2466 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2467 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2468 |
> |
{ |
2469 |
|
final CFException ex = new CFException(); |
2470 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2471 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2472 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
2473 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2474 |
< |
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()) { |
2474 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
2475 |
|
|
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); |
2476 |
|
checkCompletedWithWrappedCFException(g, ex); |
2477 |
|
checkCompletedWithWrappedCFException(f, ex); |
2478 |
< |
} |
2479 |
< |
} |
2478 |
> |
assertEquals(0, r.invocationCount); |
2479 |
> |
}} |
2480 |
|
|
2481 |
|
/** |
2482 |
|
* thenCompose result completes exceptionally if action does |
2483 |
|
*/ |
2484 |
< |
public void testThenCompose_actionFailed1() { |
2484 |
> |
public void testThenCompose_actionFailed() { |
2485 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2486 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2487 |
< |
|
2486 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2487 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2488 |
> |
{ |
2489 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2490 |
|
final FailingCompletableFutureFunction r |
2491 |
|
= new FailingCompletableFutureFunction(); |
2492 |
+ |
if (!createIncomplete) f.complete(v1); |
2493 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2494 |
< |
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 }) { |
2494 |
> |
if (createIncomplete) f.complete(v1); |
2495 |
|
|
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); |
2496 |
|
checkCompletedWithWrappedCFException(g); |
2497 |
|
checkCompletedNormally(f, v1); |
2498 |
< |
} |
3005 |
< |
} |
2498 |
> |
}} |
2499 |
|
|
2500 |
|
/** |
2501 |
|
* thenCompose result completes exceptionally if source cancelled |
2502 |
|
*/ |
2503 |
< |
public void testThenCompose_sourceCancelled1() { |
2503 |
> |
public void testThenCompose_sourceCancelled() { |
2504 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2505 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
2506 |
< |
|
2505 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2506 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2507 |
> |
{ |
2508 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2509 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2510 |
+ |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2511 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2512 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2513 |
< |
checkCompletedWithWrappedCancellationException(g); |
2514 |
< |
checkCancelled(f); |
2512 |
> |
if (createIncomplete) { |
2513 |
> |
checkIncomplete(g); |
2514 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2515 |
|
} |
3021 |
– |
} |
2516 |
|
|
3023 |
– |
public void testThenCompose_sourceCancelled2() { |
3024 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
3025 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
3026 |
– |
|
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); |
2517 |
|
checkCompletedWithWrappedCancellationException(g); |
2518 |
|
checkCancelled(f); |
2519 |
< |
} |
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 |
< |
} |
2519 |
> |
}} |
2520 |
|
|
2521 |
|
// other static methods |
2522 |
|
|
2798 |
|
public void testWhenComplete_actionFailed() { |
2799 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2800 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2801 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2802 |
< |
|
2801 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2802 |
> |
{ |
2803 |
|
final AtomicInteger a = new AtomicInteger(0); |
2804 |
|
final CFException ex = new CFException(); |
2805 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2816 |
|
checkCompletedNormally(f, v1); |
2817 |
|
checkCompletedWithWrappedCFException(g, ex); |
2818 |
|
assertEquals(1, a.get()); |
2819 |
< |
} |
3629 |
< |
} |
2819 |
> |
}} |
2820 |
|
|
2821 |
|
/** |
2822 |
|
* If a whenComplete action throws an exception when triggered by |
2826 |
|
public void testWhenComplete_actionFailedSourceFailed() { |
2827 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2828 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2829 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2830 |
< |
|
2829 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2830 |
> |
{ |
2831 |
|
final AtomicInteger a = new AtomicInteger(0); |
2832 |
|
final CFException ex1 = new CFException(); |
2833 |
|
final CFException ex2 = new CFException(); |
2847 |
|
checkCompletedWithWrappedCFException(f, ex1); |
2848 |
|
checkCompletedWithWrappedCFException(g, ex1); |
2849 |
|
assertEquals(1, a.get()); |
2850 |
< |
} |
3661 |
< |
} |
2850 |
> |
}} |
2851 |
|
|
2852 |
|
} |