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(); |
1284 |
|
|
1285 |
< |
g.completeExceptionally(ex); |
1286 |
< |
checkIncomplete(h); |
1287 |
< |
f.complete(v1); |
1204 |
< |
|
1205 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1206 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1207 |
< |
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 |
< |
|
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(); |
1306 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1340 |
|
|
1341 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1342 |
< |
checkIncomplete(h); |
1343 |
< |
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(); |
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 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1347 |
< |
checkIncomplete(h); |
1331 |
< |
f.complete(v1); |
1332 |
< |
|
1333 |
< |
checkCompletedWithWrappedCancellationException(h); |
1334 |
< |
checkCancelled(g); |
1335 |
< |
assertEquals(0, r.invocationCount); |
1336 |
< |
checkCompletedNormally(f, v1); |
1345 |
> |
if (createIncomplete) { |
1346 |
> |
checkIncomplete(h); |
1347 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1348 |
|
} |
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 |
– |
|
1345 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1346 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1347 |
– |
final SubtractFunction r = new SubtractFunction(); |
1348 |
– |
|
1349 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1350 |
– |
f.complete(v1); |
1351 |
– |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1349 |
|
|
1350 |
|
checkCompletedWithWrappedCancellationException(h); |
1351 |
< |
checkCancelled(g); |
1355 |
< |
assertEquals(0, r.invocationCount); |
1356 |
< |
checkCompletedNormally(f, v1); |
1357 |
< |
} |
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); |
1372 |
< |
|
1373 |
< |
checkCompletedWithWrappedCancellationException(h); |
1374 |
< |
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() { |
1473 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1474 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1475 |
< |
|
1476 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1477 |
< |
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() { |
1391 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1392 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1393 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1394 |
< |
|
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() { |
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 |
< |
|
1452 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1453 |
< |
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() { |
1643 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1644 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1645 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1646 |
< |
|
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 |
1477 |
|
public void testRunAfterBoth_normalCompletion1() { |
1478 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1479 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1480 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1481 |
< |
|
1480 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1481 |
> |
{ |
1482 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1483 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1484 |
|
final Noop r = new Noop(); |
1493 |
|
assertEquals(1, r.invocationCount); |
1494 |
|
checkCompletedNormally(f, v1); |
1495 |
|
checkCompletedNormally(g, v2); |
1496 |
< |
} |
1706 |
< |
} |
1496 |
> |
}} |
1497 |
|
|
1498 |
|
public void testRunAfterBoth_normalCompletion2() { |
1499 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1500 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1501 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1502 |
< |
|
1501 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1502 |
> |
{ |
1503 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1504 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1505 |
|
final Noop r = new Noop(); |
1514 |
|
assertEquals(1, r.invocationCount); |
1515 |
|
checkCompletedNormally(f, v1); |
1516 |
|
checkCompletedNormally(g, v2); |
1517 |
< |
} |
1728 |
< |
} |
1517 |
> |
}} |
1518 |
|
|
1519 |
|
public void testRunAfterBoth_normalCompletion3() { |
1520 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1521 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1522 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1523 |
< |
|
1522 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1523 |
> |
{ |
1524 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1525 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1526 |
|
final Noop r = new Noop(); |
1533 |
|
assertEquals(1, r.invocationCount); |
1534 |
|
checkCompletedNormally(f, v1); |
1535 |
|
checkCompletedNormally(g, v2); |
1536 |
< |
} |
1748 |
< |
} |
1536 |
> |
}} |
1537 |
|
|
1538 |
|
public void testRunAfterBoth_normalCompletion4() { |
1539 |
|
for (ExecutionMode m : ExecutionMode.values()) |
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 Noop r = new Noop(); |
1552 |
|
assertEquals(1, r.invocationCount); |
1553 |
|
checkCompletedNormally(f, v1); |
1554 |
|
checkCompletedNormally(g, v2); |
1555 |
< |
} |
1768 |
< |
} |
1555 |
> |
}} |
1556 |
|
|
1557 |
|
/** |
1558 |
|
* runAfterBoth result completes exceptionally after exceptional |
1560 |
|
*/ |
1561 |
|
public void testRunAfterBoth_exceptionalCompletion1() { |
1562 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1563 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1564 |
< |
|
1563 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1564 |
> |
{ |
1565 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1566 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1567 |
|
final Noop r = new Noop(); |
1576 |
|
checkCompletedWithWrappedCFException(f, ex); |
1577 |
|
assertEquals(0, r.invocationCount); |
1578 |
|
checkCompletedNormally(g, v1); |
1579 |
< |
} |
1793 |
< |
} |
1579 |
> |
}} |
1580 |
|
|
1581 |
|
public void testRunAfterBoth_exceptionalCompletion2() { |
1582 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1583 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1584 |
< |
|
1583 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1584 |
> |
{ |
1585 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1586 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1587 |
|
final Noop r = new Noop(); |
1596 |
|
checkCompletedWithWrappedCFException(g, ex); |
1597 |
|
assertEquals(0, r.invocationCount); |
1598 |
|
checkCompletedNormally(f, v1); |
1599 |
< |
} |
1814 |
< |
} |
1599 |
> |
}} |
1600 |
|
|
1601 |
|
public void testRunAfterBoth_exceptionalCompletion3() { |
1602 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1603 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1604 |
< |
|
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 Noop r = new Noop(); |
1615 |
|
checkCompletedWithWrappedCFException(g, ex); |
1616 |
|
assertEquals(0, r.invocationCount); |
1617 |
|
checkCompletedNormally(f, v1); |
1618 |
< |
} |
1834 |
< |
} |
1618 |
> |
}} |
1619 |
|
|
1620 |
|
public void testRunAfterBoth_exceptionalCompletion4() { |
1621 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1622 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1623 |
< |
|
1622 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1623 |
> |
{ |
1624 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1625 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1626 |
|
final Noop r = new Noop(); |
1634 |
|
checkCompletedWithWrappedCFException(f, ex); |
1635 |
|
assertEquals(0, r.invocationCount); |
1636 |
|
checkCompletedNormally(g, v1); |
1637 |
< |
} |
1854 |
< |
} |
1637 |
> |
}} |
1638 |
|
|
1639 |
|
/** |
1640 |
|
* runAfterBoth result completes exceptionally if action does |
1642 |
|
public void testRunAfterBoth_actionFailed1() { |
1643 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1644 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1645 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1646 |
< |
|
1645 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1646 |
> |
{ |
1647 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1648 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1649 |
< |
final FailingNoop r = new FailingNoop(); |
1649 |
> |
final FailingRunnable r = new FailingRunnable(); |
1650 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1651 |
|
|
1652 |
|
f.complete(v1); |
1656 |
|
checkCompletedWithWrappedCFException(h); |
1657 |
|
checkCompletedNormally(f, v1); |
1658 |
|
checkCompletedNormally(g, v2); |
1659 |
< |
} |
1877 |
< |
} |
1659 |
> |
}} |
1660 |
|
|
1661 |
|
public void testRunAfterBoth_actionFailed2() { |
1662 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1663 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1664 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1665 |
< |
|
1664 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1665 |
> |
{ |
1666 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1667 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1668 |
< |
final FailingNoop r = new FailingNoop(); |
1668 |
> |
final FailingRunnable r = new FailingRunnable(); |
1669 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1670 |
|
|
1671 |
|
g.complete(v2); |
1675 |
|
checkCompletedWithWrappedCFException(h); |
1676 |
|
checkCompletedNormally(f, v1); |
1677 |
|
checkCompletedNormally(g, v2); |
1678 |
< |
} |
1897 |
< |
} |
1678 |
> |
}} |
1679 |
|
|
1680 |
|
/** |
1681 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1683 |
|
public void testRunAfterBoth_sourceCancelled1() { |
1684 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1685 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1686 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1687 |
< |
|
1686 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1687 |
> |
{ |
1688 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1689 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1690 |
|
final Noop r = new Noop(); |
1698 |
|
checkCancelled(f); |
1699 |
|
assertEquals(0, r.invocationCount); |
1700 |
|
checkCompletedNormally(g, v1); |
1701 |
< |
} |
1921 |
< |
} |
1701 |
> |
}} |
1702 |
|
|
1703 |
|
public void testRunAfterBoth_sourceCancelled2() { |
1704 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1705 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1706 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1707 |
< |
|
1706 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1707 |
> |
{ |
1708 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1709 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1710 |
|
final Noop r = new Noop(); |
1718 |
|
checkCancelled(g); |
1719 |
|
assertEquals(0, r.invocationCount); |
1720 |
|
checkCompletedNormally(f, v1); |
1721 |
< |
} |
1942 |
< |
} |
1721 |
> |
}} |
1722 |
|
|
1723 |
|
public void testRunAfterBoth_sourceCancelled3() { |
1724 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1725 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1726 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1727 |
< |
|
1726 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1727 |
> |
{ |
1728 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1729 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1730 |
|
final Noop r = new Noop(); |
1737 |
|
checkCancelled(g); |
1738 |
|
assertEquals(0, r.invocationCount); |
1739 |
|
checkCompletedNormally(f, v1); |
1740 |
< |
} |
1962 |
< |
} |
1740 |
> |
}} |
1741 |
|
|
1742 |
|
public void testRunAfterBoth_sourceCancelled4() { |
1743 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1744 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1745 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1746 |
< |
|
1745 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1746 |
> |
{ |
1747 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1748 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1749 |
|
final Noop r = new Noop(); |
1756 |
|
checkCancelled(f); |
1757 |
|
assertEquals(0, r.invocationCount); |
1758 |
|
checkCompletedNormally(g, v1); |
1759 |
< |
} |
1982 |
< |
} |
1759 |
> |
}} |
1760 |
|
|
1761 |
|
/** |
1762 |
|
* applyToEither result completes normally after normal completion |
1765 |
|
public void testApplyToEither_normalCompletion1() { |
1766 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1767 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1768 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1769 |
< |
|
1768 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1769 |
> |
{ |
1770 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1771 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1772 |
|
final IncFunction r = new IncFunction(); |
1779 |
|
checkCompletedNormally(f, v1); |
1780 |
|
checkCompletedNormally(g, v2); |
1781 |
|
checkCompletedNormally(h, inc(v1)); |
1782 |
< |
} |
2006 |
< |
} |
1782 |
> |
}} |
1783 |
|
|
1784 |
|
public void testApplyToEither_normalCompletion2() { |
1785 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1786 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1787 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1788 |
< |
|
1787 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1788 |
> |
{ |
1789 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1790 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1791 |
|
final IncFunction r = new IncFunction(); |
1798 |
|
checkCompletedNormally(f, v1); |
1799 |
|
checkCompletedNormally(g, v2); |
1800 |
|
checkCompletedNormally(h, inc(v2)); |
1801 |
< |
} |
1802 |
< |
} |
1801 |
> |
}} |
1802 |
> |
|
1803 |
|
public void testApplyToEither_normalCompletion3() { |
1804 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1805 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1806 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1807 |
< |
|
1806 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1807 |
> |
{ |
1808 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1809 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1810 |
|
final IncFunction r = new IncFunction(); |
1820 |
|
assertTrue(Objects.equals(h.join(), inc(v1)) || |
1821 |
|
Objects.equals(h.join(), inc(v2))); |
1822 |
|
assertEquals(1, r.invocationCount); |
1823 |
< |
} |
2048 |
< |
} |
1823 |
> |
}} |
1824 |
|
|
1825 |
|
/** |
1826 |
|
* applyToEither result completes exceptionally after exceptional |
1828 |
|
*/ |
1829 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1830 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1831 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1832 |
< |
|
1831 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1832 |
> |
{ |
1833 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1834 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1835 |
|
final IncFunction r = new IncFunction(); |
1844 |
|
checkCompletedNormally(g, v1); |
1845 |
|
checkCompletedWithWrappedCFException(f, ex); |
1846 |
|
checkCompletedWithWrappedCFException(h, ex); |
1847 |
< |
} |
2073 |
< |
} |
1847 |
> |
}} |
1848 |
|
|
1849 |
|
public void testApplyToEither_exceptionalCompletion2() { |
1850 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1851 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1852 |
< |
|
1851 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1852 |
> |
{ |
1853 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1854 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1855 |
|
final IncFunction r = new IncFunction(); |
1864 |
|
checkCompletedNormally(f, v1); |
1865 |
|
checkCompletedWithWrappedCFException(g, ex); |
1866 |
|
checkCompletedWithWrappedCFException(h, ex); |
1867 |
< |
} |
2094 |
< |
} |
1867 |
> |
}} |
1868 |
|
|
1869 |
|
public void testApplyToEither_exceptionalCompletion3() { |
1870 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1871 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1872 |
< |
|
1871 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1872 |
> |
{ |
1873 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1874 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1875 |
|
final IncFunction r = new IncFunction(); |
1891 |
|
|
1892 |
|
checkCompletedWithWrappedCFException(g, ex); |
1893 |
|
checkCompletedNormally(f, v1); |
1894 |
< |
} |
2122 |
< |
} |
1894 |
> |
}} |
1895 |
|
|
1896 |
|
public void testApplyToEither_exceptionalCompletion4() { |
1897 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1898 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1899 |
< |
|
1898 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1899 |
> |
{ |
1900 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1901 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1902 |
|
final IncFunction r = new IncFunction(); |
1918 |
|
|
1919 |
|
checkCompletedWithWrappedCFException(f, ex); |
1920 |
|
checkCompletedNormally(g, v1); |
1921 |
< |
} |
2150 |
< |
} |
1921 |
> |
}} |
1922 |
|
|
1923 |
|
/** |
1924 |
|
* applyToEither result completes exceptionally if action does |
1926 |
|
public void testApplyToEither_actionFailed1() { |
1927 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1928 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1929 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1930 |
< |
|
1929 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1930 |
> |
{ |
1931 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1932 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1933 |
|
final FailingFunction r = new FailingFunction(); |
1938 |
|
g.complete(v2); |
1939 |
|
checkCompletedNormally(f, v1); |
1940 |
|
checkCompletedNormally(g, v2); |
1941 |
< |
} |
2171 |
< |
} |
1941 |
> |
}} |
1942 |
|
|
1943 |
|
public void testApplyToEither_actionFailed2() { |
1944 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1945 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1946 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
1947 |
< |
|
1946 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
1947 |
> |
{ |
1948 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1949 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1950 |
|
final FailingFunction r = new FailingFunction(); |
1955 |
|
f.complete(v1); |
1956 |
|
checkCompletedNormally(f, v1); |
1957 |
|
checkCompletedNormally(g, v2); |
1958 |
< |
} |
2189 |
< |
} |
1958 |
> |
}} |
1959 |
|
|
1960 |
|
/** |
1961 |
|
* applyToEither result completes exceptionally if either source cancelled |
1963 |
|
public void testApplyToEither_sourceCancelled1() { |
1964 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1965 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1966 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1967 |
< |
|
1966 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1967 |
> |
{ |
1968 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1969 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1970 |
|
final IncFunction r = new IncFunction(); |
1978 |
|
assertEquals(0, r.invocationCount); |
1979 |
|
checkCompletedNormally(g, v1); |
1980 |
|
checkCompletedWithWrappedCancellationException(h); |
1981 |
< |
} |
2213 |
< |
} |
1981 |
> |
}} |
1982 |
|
|
1983 |
|
public void testApplyToEither_sourceCancelled2() { |
1984 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1985 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1986 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
1987 |
< |
|
1986 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1987 |
> |
{ |
1988 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1989 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1990 |
|
final IncFunction r = new IncFunction(); |
1998 |
|
assertEquals(0, r.invocationCount); |
1999 |
|
checkCompletedNormally(f, v1); |
2000 |
|
checkCompletedWithWrappedCancellationException(h); |
2001 |
< |
} |
2234 |
< |
} |
2001 |
> |
}} |
2002 |
|
|
2003 |
|
public void testApplyToEither_sourceCancelled3() { |
2004 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2005 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2006 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2007 |
< |
|
2006 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2007 |
> |
{ |
2008 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2009 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2010 |
|
final IncFunction r = new IncFunction(); |
2025 |
|
|
2026 |
|
checkCancelled(g); |
2027 |
|
checkCompletedNormally(f, v1); |
2028 |
< |
} |
2262 |
< |
} |
2028 |
> |
}} |
2029 |
|
|
2030 |
|
public void testApplyToEither_sourceCancelled4() { |
2031 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2032 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2033 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2034 |
< |
|
2033 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2034 |
> |
{ |
2035 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2036 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2037 |
|
final IncFunction r = new IncFunction(); |
2052 |
|
|
2053 |
|
checkCancelled(f); |
2054 |
|
checkCompletedNormally(g, v1); |
2055 |
< |
} |
2290 |
< |
} |
2055 |
> |
}} |
2056 |
|
|
2057 |
|
/** |
2058 |
|
* acceptEither result completes normally after normal completion |
2061 |
|
public void testAcceptEither_normalCompletion1() { |
2062 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2063 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2064 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2065 |
< |
|
2064 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2065 |
> |
{ |
2066 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2067 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2068 |
|
final IncAction r = new IncAction(); |
2076 |
|
checkCompletedNormally(f, v1); |
2077 |
|
checkCompletedNormally(g, v2); |
2078 |
|
checkCompletedNormally(h, null); |
2079 |
< |
} |
2315 |
< |
} |
2079 |
> |
}} |
2080 |
|
|
2081 |
|
public void testAcceptEither_normalCompletion2() { |
2082 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2083 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2084 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2085 |
< |
|
2084 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2085 |
> |
{ |
2086 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2087 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2088 |
|
final IncAction r = new IncAction(); |
2096 |
|
checkCompletedNormally(f, v1); |
2097 |
|
checkCompletedNormally(g, v2); |
2098 |
|
checkCompletedNormally(h, null); |
2099 |
< |
} |
2100 |
< |
} |
2099 |
> |
}} |
2100 |
> |
|
2101 |
|
public void testAcceptEither_normalCompletion3() { |
2102 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2103 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2104 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2105 |
< |
|
2104 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2105 |
> |
{ |
2106 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2107 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2108 |
|
final IncAction r = new IncAction(); |
2118 |
|
// unspecified behavior |
2119 |
|
assertTrue(Objects.equals(r.value, inc(v1)) || |
2120 |
|
Objects.equals(r.value, inc(v2))); |
2121 |
< |
} |
2358 |
< |
} |
2121 |
> |
}} |
2122 |
|
|
2123 |
|
/** |
2124 |
|
* acceptEither result completes exceptionally after exceptional |
2126 |
|
*/ |
2127 |
|
public void testAcceptEither_exceptionalCompletion1() { |
2128 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2129 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2130 |
< |
|
2129 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2130 |
> |
{ |
2131 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2132 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2133 |
|
final IncAction r = new IncAction(); |
2142 |
|
checkCompletedNormally(g, v1); |
2143 |
|
checkCompletedWithWrappedCFException(f, ex); |
2144 |
|
checkCompletedWithWrappedCFException(h, ex); |
2145 |
< |
} |
2383 |
< |
} |
2145 |
> |
}} |
2146 |
|
|
2147 |
|
public void testAcceptEither_exceptionalCompletion2() { |
2148 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2149 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2150 |
< |
|
2149 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2150 |
> |
{ |
2151 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2152 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2153 |
|
final IncAction r = new IncAction(); |
2162 |
|
checkCompletedNormally(f, v1); |
2163 |
|
checkCompletedWithWrappedCFException(g, ex); |
2164 |
|
checkCompletedWithWrappedCFException(h, ex); |
2165 |
< |
} |
2404 |
< |
} |
2165 |
> |
}} |
2166 |
|
|
2167 |
|
public void testAcceptEither_exceptionalCompletion3() { |
2168 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2169 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2170 |
< |
|
2169 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2170 |
> |
{ |
2171 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2172 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2173 |
|
final IncAction r = new IncAction(); |
2190 |
|
|
2191 |
|
checkCompletedWithWrappedCFException(g, ex); |
2192 |
|
checkCompletedNormally(f, v1); |
2193 |
< |
} |
2433 |
< |
} |
2193 |
> |
}} |
2194 |
|
|
2195 |
|
public void testAcceptEither_exceptionalCompletion4() { |
2196 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2197 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2198 |
< |
|
2197 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2198 |
> |
{ |
2199 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2200 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2201 |
|
final IncAction r = new IncAction(); |
2218 |
|
|
2219 |
|
checkCompletedWithWrappedCFException(f, ex); |
2220 |
|
checkCompletedNormally(g, v1); |
2221 |
< |
} |
2462 |
< |
} |
2221 |
> |
}} |
2222 |
|
|
2223 |
|
/** |
2224 |
|
* acceptEither result completes exceptionally if action does |
2226 |
|
public void testAcceptEither_actionFailed1() { |
2227 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2228 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2229 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2230 |
< |
|
2229 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2230 |
> |
{ |
2231 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2232 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2233 |
|
final FailingConsumer r = new FailingConsumer(); |
2238 |
|
g.complete(v2); |
2239 |
|
checkCompletedNormally(f, v1); |
2240 |
|
checkCompletedNormally(g, v2); |
2241 |
< |
} |
2483 |
< |
} |
2241 |
> |
}} |
2242 |
|
|
2243 |
|
public void testAcceptEither_actionFailed2() { |
2244 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2245 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2246 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2247 |
< |
|
2246 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2247 |
> |
{ |
2248 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2249 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2250 |
|
final FailingConsumer r = new FailingConsumer(); |
2255 |
|
f.complete(v1); |
2256 |
|
checkCompletedNormally(f, v1); |
2257 |
|
checkCompletedNormally(g, v2); |
2258 |
< |
} |
2501 |
< |
} |
2258 |
> |
}} |
2259 |
|
|
2260 |
|
/** |
2261 |
|
* acceptEither result completes exceptionally if either source cancelled |
2263 |
|
public void testAcceptEither_sourceCancelled1() { |
2264 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2265 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2266 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2267 |
< |
|
2266 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2267 |
> |
{ |
2268 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2269 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2270 |
|
final IncAction r = new IncAction(); |
2278 |
|
assertEquals(0, r.invocationCount); |
2279 |
|
checkCompletedNormally(g, v1); |
2280 |
|
checkCompletedWithWrappedCancellationException(h); |
2281 |
< |
} |
2525 |
< |
} |
2281 |
> |
}} |
2282 |
|
|
2283 |
|
public void testAcceptEither_sourceCancelled2() { |
2284 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2285 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2286 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2287 |
< |
|
2286 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2287 |
> |
{ |
2288 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2289 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2290 |
|
final IncAction r = new IncAction(); |
2298 |
|
assertEquals(0, r.invocationCount); |
2299 |
|
checkCompletedNormally(f, v1); |
2300 |
|
checkCompletedWithWrappedCancellationException(h); |
2301 |
< |
} |
2546 |
< |
} |
2301 |
> |
}} |
2302 |
|
|
2303 |
|
public void testAcceptEither_sourceCancelled3() { |
2304 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2305 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2306 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2307 |
< |
|
2306 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2307 |
> |
{ |
2308 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2309 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2310 |
|
final IncAction r = new IncAction(); |
2326 |
|
|
2327 |
|
checkCancelled(g); |
2328 |
|
checkCompletedNormally(f, v1); |
2329 |
< |
} |
2575 |
< |
} |
2329 |
> |
}} |
2330 |
|
|
2331 |
|
public void testAcceptEither_sourceCancelled4() { |
2332 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2333 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2334 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2335 |
< |
|
2334 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2335 |
> |
{ |
2336 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2337 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2338 |
|
final IncAction r = new IncAction(); |
2354 |
|
|
2355 |
|
checkCancelled(f); |
2356 |
|
checkCompletedNormally(g, v1); |
2357 |
< |
} |
2604 |
< |
} |
2357 |
> |
}} |
2358 |
|
|
2359 |
|
/** |
2360 |
|
* runAfterEither result completes normally after normal completion |
2363 |
|
public void testRunAfterEither_normalCompletion1() { |
2364 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2365 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2366 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2367 |
< |
|
2366 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2367 |
> |
{ |
2368 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2369 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2370 |
|
final Noop r = new Noop(); |
2379 |
|
checkCompletedNormally(g, v2); |
2380 |
|
checkCompletedNormally(h, null); |
2381 |
|
assertEquals(1, r.invocationCount); |
2382 |
< |
} |
2630 |
< |
} |
2382 |
> |
}} |
2383 |
|
|
2384 |
|
public void testRunAfterEither_normalCompletion2() { |
2385 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2386 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2387 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2388 |
< |
|
2387 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2388 |
> |
{ |
2389 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2390 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2391 |
|
final Noop r = new Noop(); |
2400 |
|
checkCompletedNormally(g, v2); |
2401 |
|
checkCompletedNormally(h, null); |
2402 |
|
assertEquals(1, r.invocationCount); |
2403 |
< |
} |
2404 |
< |
} |
2403 |
> |
}} |
2404 |
> |
|
2405 |
|
public void testRunAfterEither_normalCompletion3() { |
2406 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2407 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2408 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2409 |
< |
|
2408 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2409 |
> |
{ |
2410 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2411 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2412 |
|
final Noop r = new Noop(); |
2419 |
|
checkCompletedNormally(f, v1); |
2420 |
|
checkCompletedNormally(g, v2); |
2421 |
|
assertEquals(1, r.invocationCount); |
2422 |
< |
} |
2671 |
< |
} |
2422 |
> |
}} |
2423 |
|
|
2424 |
|
/** |
2425 |
|
* runAfterEither result completes exceptionally after exceptional |
2427 |
|
*/ |
2428 |
|
public void testRunAfterEither_exceptionalCompletion1() { |
2429 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2430 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2431 |
< |
|
2430 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2431 |
> |
{ |
2432 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2433 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2434 |
|
final Noop r = new Noop(); |
2443 |
|
checkCompletedNormally(g, v1); |
2444 |
|
checkCompletedWithWrappedCFException(f, ex); |
2445 |
|
checkCompletedWithWrappedCFException(h, ex); |
2446 |
< |
} |
2696 |
< |
} |
2446 |
> |
}} |
2447 |
|
|
2448 |
|
public void testRunAfterEither_exceptionalCompletion2() { |
2449 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2450 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2451 |
< |
|
2450 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2451 |
> |
{ |
2452 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2453 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2454 |
|
final Noop r = new Noop(); |
2463 |
|
checkCompletedNormally(f, v1); |
2464 |
|
checkCompletedWithWrappedCFException(g, ex); |
2465 |
|
checkCompletedWithWrappedCFException(h, ex); |
2466 |
< |
} |
2717 |
< |
} |
2466 |
> |
}} |
2467 |
|
|
2468 |
|
public void testRunAfterEither_exceptionalCompletion3() { |
2469 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2470 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2471 |
< |
|
2470 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2471 |
> |
{ |
2472 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2473 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2474 |
|
final Noop r = new Noop(); |
2490 |
|
|
2491 |
|
checkCompletedWithWrappedCFException(g, ex); |
2492 |
|
checkCompletedNormally(f, v1); |
2493 |
< |
} |
2745 |
< |
} |
2493 |
> |
}} |
2494 |
|
|
2495 |
|
public void testRunAfterEither_exceptionalCompletion4() { |
2496 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2497 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2498 |
< |
|
2497 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2498 |
> |
{ |
2499 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2500 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2501 |
|
final Noop r = new Noop(); |
2517 |
|
|
2518 |
|
checkCompletedWithWrappedCFException(f, ex); |
2519 |
|
checkCompletedNormally(g, v1); |
2520 |
< |
} |
2773 |
< |
} |
2520 |
> |
}} |
2521 |
|
|
2522 |
|
/** |
2523 |
|
* runAfterEither result completes exceptionally if action does |
2525 |
|
public void testRunAfterEither_actionFailed1() { |
2526 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2527 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2528 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2529 |
< |
|
2528 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2529 |
> |
{ |
2530 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2531 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2532 |
< |
final FailingNoop r = new FailingNoop(); |
2532 |
> |
final FailingRunnable r = new FailingRunnable(); |
2533 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2534 |
|
|
2535 |
|
f.complete(v1); |
2537 |
|
g.complete(v2); |
2538 |
|
checkCompletedNormally(f, v1); |
2539 |
|
checkCompletedNormally(g, v2); |
2540 |
< |
} |
2794 |
< |
} |
2540 |
> |
}} |
2541 |
|
|
2542 |
|
public void testRunAfterEither_actionFailed2() { |
2543 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2544 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2545 |
< |
for (Integer v2 : new Integer[] { 2, null }) { |
2546 |
< |
|
2545 |
> |
for (Integer v2 : new Integer[] { 2, null }) |
2546 |
> |
{ |
2547 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2548 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2549 |
< |
final FailingNoop r = new FailingNoop(); |
2549 |
> |
final FailingRunnable r = new FailingRunnable(); |
2550 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2551 |
|
|
2552 |
|
g.complete(v2); |
2554 |
|
f.complete(v1); |
2555 |
|
checkCompletedNormally(f, v1); |
2556 |
|
checkCompletedNormally(g, v2); |
2557 |
< |
} |
2812 |
< |
} |
2557 |
> |
}} |
2558 |
|
|
2559 |
|
/** |
2560 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2562 |
|
public void testRunAfterEither_sourceCancelled1() { |
2563 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2564 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2565 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2566 |
< |
|
2565 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2566 |
> |
{ |
2567 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2568 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2569 |
|
final Noop r = new Noop(); |
2577 |
|
assertEquals(0, r.invocationCount); |
2578 |
|
checkCompletedNormally(g, v1); |
2579 |
|
checkCompletedWithWrappedCancellationException(h); |
2580 |
< |
} |
2836 |
< |
} |
2580 |
> |
}} |
2581 |
|
|
2582 |
|
public void testRunAfterEither_sourceCancelled2() { |
2583 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2584 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2585 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2586 |
< |
|
2585 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2586 |
> |
{ |
2587 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2588 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2589 |
|
final Noop r = new Noop(); |
2597 |
|
assertEquals(0, r.invocationCount); |
2598 |
|
checkCompletedNormally(f, v1); |
2599 |
|
checkCompletedWithWrappedCancellationException(h); |
2600 |
< |
} |
2857 |
< |
} |
2600 |
> |
}} |
2601 |
|
|
2602 |
|
public void testRunAfterEither_sourceCancelled3() { |
2603 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2604 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2605 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2606 |
< |
|
2605 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2606 |
> |
{ |
2607 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2608 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2609 |
|
final Noop r = new Noop(); |
2624 |
|
|
2625 |
|
checkCancelled(g); |
2626 |
|
checkCompletedNormally(f, v1); |
2627 |
< |
} |
2885 |
< |
} |
2627 |
> |
}} |
2628 |
|
|
2629 |
|
public void testRunAfterEither_sourceCancelled4() { |
2630 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2631 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2632 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2633 |
< |
|
2632 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2633 |
> |
{ |
2634 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2635 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2636 |
|
final Noop r = new Noop(); |
2651 |
|
|
2652 |
|
checkCancelled(f); |
2653 |
|
checkCompletedNormally(g, v1); |
2654 |
< |
} |
2913 |
< |
} |
2654 |
> |
}} |
2655 |
|
|
2656 |
|
/** |
2657 |
|
* thenCompose result completes normally after normal completion of source |
2658 |
|
*/ |
2659 |
< |
public void testThenCompose_normalCompletion1() { |
2659 |
> |
public void testThenCompose_normalCompletion() { |
2660 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2661 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2662 |
< |
|
2661 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2662 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2663 |
> |
{ |
2664 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2665 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2666 |
+ |
if (!createIncomplete) f.complete(v1); |
2667 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2668 |
< |
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 }) { |
2668 |
> |
if (createIncomplete) f.complete(v1); |
2669 |
|
|
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); |
2670 |
|
checkCompletedNormally(g, inc(v1)); |
2671 |
|
checkCompletedNormally(f, v1); |
2672 |
|
assertEquals(1, r.invocationCount); |
2673 |
< |
} |
2944 |
< |
} |
2673 |
> |
}} |
2674 |
|
|
2675 |
|
/** |
2676 |
|
* thenCompose result completes exceptionally after exceptional |
2677 |
|
* completion of source |
2678 |
|
*/ |
2679 |
< |
public void testThenCompose_exceptionalCompletion1() { |
2680 |
< |
for (ExecutionMode m : ExecutionMode.values()) { |
2681 |
< |
|
2679 |
> |
public void testThenCompose_exceptionalCompletion() { |
2680 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
2681 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2682 |
> |
{ |
2683 |
|
final CFException ex = new CFException(); |
2684 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2685 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2686 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
2687 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2688 |
< |
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()) { |
2688 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
2689 |
|
|
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); |
2690 |
|
checkCompletedWithWrappedCFException(g, ex); |
2691 |
|
checkCompletedWithWrappedCFException(f, ex); |
2692 |
< |
} |
2693 |
< |
} |
2692 |
> |
assertEquals(0, r.invocationCount); |
2693 |
> |
}} |
2694 |
|
|
2695 |
|
/** |
2696 |
|
* thenCompose result completes exceptionally if action does |
2697 |
|
*/ |
2698 |
< |
public void testThenCompose_actionFailed1() { |
2698 |
> |
public void testThenCompose_actionFailed() { |
2699 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2700 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
2701 |
< |
|
2700 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2701 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
2702 |
> |
{ |
2703 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2704 |
|
final FailingCompletableFutureFunction r |
2705 |
|
= new FailingCompletableFutureFunction(); |
2706 |
+ |
if (!createIncomplete) f.complete(v1); |
2707 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2708 |
< |
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 }) { |
2708 |
> |
if (createIncomplete) f.complete(v1); |
2709 |
|
|
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); |
2710 |
|
checkCompletedWithWrappedCFException(g); |
2711 |
|
checkCompletedNormally(f, v1); |
2712 |
< |
} |
3005 |
< |
} |
2712 |
> |
}} |
2713 |
|
|
2714 |
|
/** |
2715 |
|
* thenCompose result completes exceptionally if source cancelled |
2716 |
|
*/ |
2717 |
< |
public void testThenCompose_sourceCancelled1() { |
2717 |
> |
public void testThenCompose_sourceCancelled() { |
2718 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2719 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
2720 |
< |
|
2719 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
2720 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2721 |
> |
{ |
2722 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2723 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2724 |
+ |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2725 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2726 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2727 |
< |
checkCompletedWithWrappedCancellationException(g); |
2728 |
< |
checkCancelled(f); |
2726 |
> |
if (createIncomplete) { |
2727 |
> |
checkIncomplete(g); |
2728 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2729 |
|
} |
3021 |
– |
} |
3022 |
– |
|
3023 |
– |
public void testThenCompose_sourceCancelled2() { |
3024 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
3025 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
2730 |
|
|
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); |
2731 |
|
checkCompletedWithWrappedCancellationException(g); |
2732 |
|
checkCancelled(f); |
2733 |
< |
} |
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 |
< |
} |
2733 |
> |
}} |
2734 |
|
|
2735 |
|
// other static methods |
2736 |
|
|
3012 |
|
public void testWhenComplete_actionFailed() { |
3013 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
3014 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3015 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
3016 |
< |
|
3015 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
3016 |
> |
{ |
3017 |
|
final AtomicInteger a = new AtomicInteger(0); |
3018 |
|
final CFException ex = new CFException(); |
3019 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3030 |
|
checkCompletedNormally(f, v1); |
3031 |
|
checkCompletedWithWrappedCFException(g, ex); |
3032 |
|
assertEquals(1, a.get()); |
3033 |
< |
} |
3629 |
< |
} |
3033 |
> |
}} |
3034 |
|
|
3035 |
|
/** |
3036 |
|
* If a whenComplete action throws an exception when triggered by |
3040 |
|
public void testWhenComplete_actionFailedSourceFailed() { |
3041 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
3042 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3043 |
< |
for (Integer v1 : new Integer[] { 1, null }) { |
3044 |
< |
|
3043 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
3044 |
> |
{ |
3045 |
|
final AtomicInteger a = new AtomicInteger(0); |
3046 |
|
final CFException ex1 = new CFException(); |
3047 |
|
final CFException ex2 = new CFException(); |
3061 |
|
checkCompletedWithWrappedCFException(f, ex1); |
3062 |
|
checkCompletedWithWrappedCFException(g, ex1); |
3063 |
|
assertEquals(1, a.get()); |
3064 |
< |
} |
3661 |
< |
} |
3064 |
> |
}} |
3065 |
|
|
3066 |
|
} |