102 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
103 |
|
} |
104 |
|
|
105 |
+ |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
106 |
+ |
CFException ex) { |
107 |
+ |
try { |
108 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
109 |
+ |
shouldThrow(); |
110 |
+ |
} catch (ExecutionException success) { |
111 |
+ |
assertSame(ex, success.getCause()); |
112 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
113 |
+ |
try { |
114 |
+ |
f.join(); |
115 |
+ |
shouldThrow(); |
116 |
+ |
} catch (CompletionException success) { |
117 |
+ |
assertSame(ex, success.getCause()); |
118 |
+ |
} |
119 |
+ |
try { |
120 |
+ |
f.getNow(null); |
121 |
+ |
shouldThrow(); |
122 |
+ |
} catch (CompletionException success) { |
123 |
+ |
assertSame(ex, success.getCause()); |
124 |
+ |
} |
125 |
+ |
try { |
126 |
+ |
f.get(); |
127 |
+ |
shouldThrow(); |
128 |
+ |
} catch (ExecutionException success) { |
129 |
+ |
assertSame(ex, success.getCause()); |
130 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
131 |
+ |
assertTrue(f.isDone()); |
132 |
+ |
assertFalse(f.isCancelled()); |
133 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
134 |
+ |
} |
135 |
+ |
|
136 |
|
void checkCancelled(CompletableFuture<?> f) { |
137 |
|
try { |
138 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
947 |
|
} |
948 |
|
|
949 |
|
/** |
950 |
+ |
* Permits the testing of parallel code for the 3 different |
951 |
+ |
* execution modes without repeating all the testing code. |
952 |
+ |
*/ |
953 |
+ |
enum ExecutionMode { |
954 |
+ |
DEFAULT { |
955 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
956 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) { |
957 |
+ |
return f.runAfterBoth(g, r); |
958 |
+ |
} |
959 |
+ |
}, |
960 |
+ |
|
961 |
+ |
DEFAULT_ASYNC { |
962 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
963 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) { |
964 |
+ |
return f.runAfterBothAsync(g, r); |
965 |
+ |
} |
966 |
+ |
}, |
967 |
+ |
|
968 |
+ |
EXECUTOR { |
969 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
970 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) { |
971 |
+ |
return f.runAfterBothAsync(g, r, new ThreadExecutor()); |
972 |
+ |
} |
973 |
+ |
}; |
974 |
+ |
|
975 |
+ |
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
976 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable r); |
977 |
+ |
} |
978 |
+ |
|
979 |
+ |
/** |
980 |
|
* runAfterBoth result completes normally after normal |
981 |
|
* completion of sources |
982 |
|
*/ |
983 |
< |
public void testRunAfterBoth() { |
984 |
< |
CompletableFuture<Integer> f, g; |
985 |
< |
CompletableFuture<Void> h; |
986 |
< |
Noop r; |
983 |
> |
public void testRunAfterBoth_normalCompletion1() { |
984 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
985 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
986 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
987 |
> |
|
988 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
989 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
990 |
> |
final Noop r = new Noop(); |
991 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
992 |
|
|
993 |
< |
f = new CompletableFuture<>(); |
928 |
< |
g = new CompletableFuture<>(); |
929 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
930 |
< |
f.complete(3); |
993 |
> |
f.complete(v1); |
994 |
|
checkIncomplete(h); |
995 |
< |
g.complete(1); |
995 |
> |
assertFalse(r.ran); |
996 |
> |
g.complete(v2); |
997 |
> |
|
998 |
|
checkCompletedNormally(h, null); |
999 |
|
assertTrue(r.ran); |
1000 |
+ |
checkCompletedNormally(f, v1); |
1001 |
+ |
checkCompletedNormally(g, v2); |
1002 |
+ |
} |
1003 |
+ |
} |
1004 |
|
|
1005 |
< |
f = new CompletableFuture<>(); |
1006 |
< |
g = new CompletableFuture<>(); |
1007 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1008 |
< |
g.complete(1); |
1005 |
> |
public void testRunAfterBoth_normalCompletion2() { |
1006 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1007 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1008 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1009 |
> |
|
1010 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1011 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1012 |
> |
final Noop r = new Noop(); |
1013 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1014 |
> |
|
1015 |
> |
g.complete(v2); |
1016 |
|
checkIncomplete(h); |
1017 |
< |
f.complete(3); |
1017 |
> |
assertFalse(r.ran); |
1018 |
> |
f.complete(v1); |
1019 |
> |
|
1020 |
|
checkCompletedNormally(h, null); |
1021 |
|
assertTrue(r.ran); |
1022 |
+ |
checkCompletedNormally(f, v1); |
1023 |
+ |
checkCompletedNormally(g, v2); |
1024 |
+ |
} |
1025 |
+ |
} |
1026 |
+ |
|
1027 |
+ |
public void testRunAfterBoth_normalCompletion3() { |
1028 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1029 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1030 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1031 |
+ |
|
1032 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1033 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1034 |
+ |
final Noop r = new Noop(); |
1035 |
+ |
|
1036 |
+ |
g.complete(v2); |
1037 |
+ |
f.complete(v1); |
1038 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1039 |
+ |
|
1040 |
+ |
checkCompletedNormally(h, null); |
1041 |
+ |
assertTrue(r.ran); |
1042 |
+ |
checkCompletedNormally(f, v1); |
1043 |
+ |
checkCompletedNormally(g, v2); |
1044 |
+ |
} |
1045 |
+ |
} |
1046 |
+ |
|
1047 |
+ |
public void testRunAfterBoth_normalCompletion4() { |
1048 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1049 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1050 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1051 |
+ |
|
1052 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1053 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1054 |
+ |
final Noop r = new Noop(); |
1055 |
+ |
|
1056 |
+ |
f.complete(v1); |
1057 |
+ |
g.complete(v2); |
1058 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1059 |
|
|
945 |
– |
f = new CompletableFuture<>(); |
946 |
– |
g = new CompletableFuture<>(); |
947 |
– |
g.complete(1); |
948 |
– |
f.complete(3); |
949 |
– |
h = f.runAfterBoth(g, r = new Noop()); |
1060 |
|
checkCompletedNormally(h, null); |
1061 |
|
assertTrue(r.ran); |
1062 |
+ |
checkCompletedNormally(f, v1); |
1063 |
+ |
checkCompletedNormally(g, v2); |
1064 |
+ |
} |
1065 |
|
} |
1066 |
|
|
1067 |
|
/** |
1068 |
|
* runAfterBoth result completes exceptionally after exceptional |
1069 |
|
* completion of either source |
1070 |
|
*/ |
1071 |
< |
public void testRunAfterBoth2() { |
1072 |
< |
CompletableFuture<Integer> f, g; |
1073 |
< |
CompletableFuture<Void> h; |
1074 |
< |
Noop r; |
1071 |
> |
public void testRunAfterBoth_exceptionalCompletion1() { |
1072 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1073 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1074 |
> |
|
1075 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1076 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1077 |
> |
final Noop r = new Noop(); |
1078 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1079 |
> |
final CFException ex = new CFException(); |
1080 |
|
|
1081 |
< |
f = new CompletableFuture<>(); |
964 |
< |
g = new CompletableFuture<>(); |
965 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
966 |
< |
f.completeExceptionally(new CFException()); |
1081 |
> |
f.completeExceptionally(ex); |
1082 |
|
checkIncomplete(h); |
1083 |
< |
g.complete(1); |
1084 |
< |
checkCompletedWithWrappedCFException(h); |
1083 |
> |
g.complete(v1); |
1084 |
> |
|
1085 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1086 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1087 |
|
assertFalse(r.ran); |
1088 |
+ |
checkCompletedNormally(g, v1); |
1089 |
+ |
} |
1090 |
+ |
} |
1091 |
|
|
1092 |
< |
f = new CompletableFuture<>(); |
1093 |
< |
g = new CompletableFuture<>(); |
1094 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1095 |
< |
g.completeExceptionally(new CFException()); |
1092 |
> |
public void testRunAfterBoth_exceptionalCompletion2() { |
1093 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1094 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1095 |
> |
|
1096 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1097 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1098 |
> |
final Noop r = new Noop(); |
1099 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1100 |
> |
final CFException ex = new CFException(); |
1101 |
> |
|
1102 |
> |
g.completeExceptionally(ex); |
1103 |
|
checkIncomplete(h); |
1104 |
< |
f.complete(3); |
1105 |
< |
checkCompletedWithWrappedCFException(h); |
1104 |
> |
f.complete(v1); |
1105 |
> |
|
1106 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1107 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1108 |
|
assertFalse(r.ran); |
1109 |
+ |
checkCompletedNormally(f, v1); |
1110 |
+ |
} |
1111 |
+ |
} |
1112 |
|
|
1113 |
< |
f = new CompletableFuture<>(); |
1114 |
< |
g = new CompletableFuture<>(); |
1115 |
< |
g.completeExceptionally(new CFException()); |
1116 |
< |
f.complete(3); |
1117 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1118 |
< |
checkCompletedWithWrappedCFException(h); |
1113 |
> |
public void testRunAfterBoth_exceptionalCompletion3() { |
1114 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1115 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1116 |
> |
|
1117 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1118 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1119 |
> |
final Noop r = new Noop(); |
1120 |
> |
final CFException ex = new CFException(); |
1121 |
> |
|
1122 |
> |
g.completeExceptionally(ex); |
1123 |
> |
f.complete(v1); |
1124 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1125 |
> |
|
1126 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1127 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1128 |
|
assertFalse(r.ran); |
1129 |
+ |
checkCompletedNormally(f, v1); |
1130 |
+ |
} |
1131 |
+ |
} |
1132 |
|
|
1133 |
< |
f = new CompletableFuture<>(); |
1134 |
< |
g = new CompletableFuture<>(); |
1135 |
< |
f.completeExceptionally(new CFException()); |
1136 |
< |
g.complete(1); |
1137 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1138 |
< |
checkCompletedWithWrappedCFException(h); |
1133 |
> |
public void testRunAfterBoth_exceptionalCompletion4() { |
1134 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1135 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1136 |
> |
|
1137 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1138 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1139 |
> |
final Noop r = new Noop(); |
1140 |
> |
final CFException ex = new CFException(); |
1141 |
> |
|
1142 |
> |
f.completeExceptionally(ex); |
1143 |
> |
g.complete(v1); |
1144 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1145 |
> |
|
1146 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1147 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1148 |
|
assertFalse(r.ran); |
1149 |
+ |
checkCompletedNormally(g, v1); |
1150 |
+ |
} |
1151 |
|
} |
1152 |
|
|
1153 |
|
/** |
1154 |
|
* runAfterBoth result completes exceptionally if action does |
1155 |
|
*/ |
1156 |
< |
public void testRunAfterBoth3() { |
1157 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1158 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1159 |
< |
FailingNoop r = new FailingNoop(); |
1160 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1161 |
< |
f.complete(one); |
1162 |
< |
checkIncomplete(g); |
1163 |
< |
f2.complete(two); |
1164 |
< |
checkCompletedWithWrappedCFException(g); |
1156 |
> |
public void testRunAfterBoth_actionFailed1() { |
1157 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1158 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1159 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1160 |
> |
|
1161 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1162 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1163 |
> |
final FailingNoop r = new FailingNoop(); |
1164 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1165 |
> |
|
1166 |
> |
f.complete(v1); |
1167 |
> |
checkIncomplete(h); |
1168 |
> |
g.complete(v2); |
1169 |
> |
|
1170 |
> |
checkCompletedWithWrappedCFException(h); |
1171 |
> |
checkCompletedNormally(f, v1); |
1172 |
> |
checkCompletedNormally(g, v2); |
1173 |
> |
} |
1174 |
> |
} |
1175 |
> |
|
1176 |
> |
public void testRunAfterBoth_actionFailed2() { |
1177 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1178 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1179 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1180 |
> |
|
1181 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1182 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1183 |
> |
final FailingNoop r = new FailingNoop(); |
1184 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1185 |
> |
|
1186 |
> |
g.complete(v2); |
1187 |
> |
checkIncomplete(h); |
1188 |
> |
f.complete(v1); |
1189 |
> |
|
1190 |
> |
checkCompletedWithWrappedCFException(h); |
1191 |
> |
checkCompletedNormally(f, v1); |
1192 |
> |
checkCompletedNormally(g, v2); |
1193 |
> |
} |
1194 |
|
} |
1195 |
|
|
1196 |
|
/** |
1197 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1198 |
|
*/ |
1199 |
< |
public void testRunAfterBoth4() { |
1200 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1201 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1202 |
< |
Noop r = new Noop(); |
1203 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1204 |
< |
assertTrue(f.cancel(true)); |
1205 |
< |
f2.complete(two); |
1206 |
< |
checkCompletedWithWrappedCancellationException(g); |
1207 |
< |
f = new CompletableFuture<>(); |
1208 |
< |
f2 = new CompletableFuture<>(); |
1209 |
< |
r = new Noop(); |
1210 |
< |
g = f.runAfterBoth(f2, r); |
1211 |
< |
f.complete(one); |
1212 |
< |
assertTrue(f2.cancel(true)); |
1213 |
< |
checkCompletedWithWrappedCancellationException(g); |
1199 |
> |
public void testRunAfterBoth_sourceCancelled1() { |
1200 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1201 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1202 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1203 |
> |
|
1204 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1205 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1206 |
> |
final Noop r = new Noop(); |
1207 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1208 |
> |
|
1209 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1210 |
> |
checkIncomplete(h); |
1211 |
> |
g.complete(v1); |
1212 |
> |
|
1213 |
> |
checkCompletedWithWrappedCancellationException(h); |
1214 |
> |
checkCancelled(f); |
1215 |
> |
assertFalse(r.ran); |
1216 |
> |
checkCompletedNormally(g, v1); |
1217 |
> |
} |
1218 |
> |
} |
1219 |
> |
|
1220 |
> |
public void testRunAfterBoth_sourceCancelled2() { |
1221 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1222 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1223 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1224 |
> |
|
1225 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1226 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1227 |
> |
final Noop r = new Noop(); |
1228 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1229 |
> |
|
1230 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1231 |
> |
checkIncomplete(h); |
1232 |
> |
f.complete(v1); |
1233 |
> |
|
1234 |
> |
checkCompletedWithWrappedCancellationException(h); |
1235 |
> |
checkCancelled(g); |
1236 |
> |
assertFalse(r.ran); |
1237 |
> |
checkCompletedNormally(f, v1); |
1238 |
> |
} |
1239 |
> |
} |
1240 |
> |
|
1241 |
> |
public void testRunAfterBoth_sourceCancelled3() { |
1242 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1243 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1244 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1245 |
> |
|
1246 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1247 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1248 |
> |
final Noop r = new Noop(); |
1249 |
> |
|
1250 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1251 |
> |
f.complete(v1); |
1252 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1253 |
> |
|
1254 |
> |
checkCompletedWithWrappedCancellationException(h); |
1255 |
> |
checkCancelled(g); |
1256 |
> |
assertFalse(r.ran); |
1257 |
> |
checkCompletedNormally(f, v1); |
1258 |
> |
} |
1259 |
> |
} |
1260 |
> |
|
1261 |
> |
public void testRunAfterBoth_sourceCancelled4() { |
1262 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1263 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1264 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1265 |
> |
|
1266 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1267 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1268 |
> |
final Noop r = new Noop(); |
1269 |
> |
|
1270 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1271 |
> |
g.complete(v1); |
1272 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1273 |
> |
|
1274 |
> |
checkCompletedWithWrappedCancellationException(h); |
1275 |
> |
checkCancelled(f); |
1276 |
> |
assertFalse(r.ran); |
1277 |
> |
checkCompletedNormally(g, v1); |
1278 |
> |
} |
1279 |
|
} |
1280 |
|
|
1281 |
|
/** |
1967 |
|
} |
1968 |
|
|
1969 |
|
/** |
1721 |
– |
* runAfterBothAsync result completes normally after normal |
1722 |
– |
* completion of sources |
1723 |
– |
*/ |
1724 |
– |
public void testRunAfterBothAsync() { |
1725 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1726 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1727 |
– |
Noop r = new Noop(); |
1728 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1729 |
– |
f.complete(one); |
1730 |
– |
checkIncomplete(g); |
1731 |
– |
f2.complete(two); |
1732 |
– |
checkCompletedNormally(g, null); |
1733 |
– |
assertTrue(r.ran); |
1734 |
– |
} |
1735 |
– |
|
1736 |
– |
/** |
1737 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
1738 |
– |
* completion of source |
1739 |
– |
*/ |
1740 |
– |
public void testRunAfterBothAsync2() { |
1741 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1742 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1743 |
– |
Noop r = new Noop(); |
1744 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1745 |
– |
f.completeExceptionally(new CFException()); |
1746 |
– |
f2.complete(two); |
1747 |
– |
checkCompletedWithWrappedCFException(g); |
1748 |
– |
|
1749 |
– |
r = new Noop(); |
1750 |
– |
f = new CompletableFuture<>(); |
1751 |
– |
f2 = new CompletableFuture<>(); |
1752 |
– |
g = f.runAfterBothAsync(f2, r); |
1753 |
– |
f.complete(one); |
1754 |
– |
f2.completeExceptionally(new CFException()); |
1755 |
– |
checkCompletedWithWrappedCFException(g); |
1756 |
– |
} |
1757 |
– |
|
1758 |
– |
/** |
1759 |
– |
* runAfterBothAsync result completes exceptionally if action does |
1760 |
– |
*/ |
1761 |
– |
public void testRunAfterBothAsync3() { |
1762 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1763 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1764 |
– |
FailingNoop r = new FailingNoop(); |
1765 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1766 |
– |
f.complete(one); |
1767 |
– |
checkIncomplete(g); |
1768 |
– |
f2.complete(two); |
1769 |
– |
checkCompletedWithWrappedCFException(g); |
1770 |
– |
} |
1771 |
– |
|
1772 |
– |
/** |
1773 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
1774 |
– |
*/ |
1775 |
– |
public void testRunAfterBothAsync4() { |
1776 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1777 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1778 |
– |
Noop r = new Noop(); |
1779 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1780 |
– |
assertTrue(f.cancel(true)); |
1781 |
– |
f2.complete(two); |
1782 |
– |
checkCompletedWithWrappedCancellationException(g); |
1783 |
– |
|
1784 |
– |
r = new Noop(); |
1785 |
– |
f = new CompletableFuture<>(); |
1786 |
– |
f2 = new CompletableFuture<>(); |
1787 |
– |
g = f.runAfterBothAsync(f2, r); |
1788 |
– |
f.complete(one); |
1789 |
– |
assertTrue(f2.cancel(true)); |
1790 |
– |
checkCompletedWithWrappedCancellationException(g); |
1791 |
– |
} |
1792 |
– |
|
1793 |
– |
/** |
1970 |
|
* applyToEitherAsync result completes normally after normal |
1971 |
|
* completion of sources |
1972 |
|
*/ |
2686 |
|
} |
2687 |
|
|
2688 |
|
/** |
2513 |
– |
* runAfterBothAsync result completes normally after normal |
2514 |
– |
* completion of sources |
2515 |
– |
*/ |
2516 |
– |
public void testRunAfterBothAsyncE() { |
2517 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2518 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2519 |
– |
Noop r = new Noop(); |
2520 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2521 |
– |
f.complete(one); |
2522 |
– |
checkIncomplete(g); |
2523 |
– |
f2.complete(two); |
2524 |
– |
checkCompletedNormally(g, null); |
2525 |
– |
assertTrue(r.ran); |
2526 |
– |
} |
2527 |
– |
|
2528 |
– |
/** |
2529 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
2530 |
– |
* completion of source |
2531 |
– |
*/ |
2532 |
– |
public void testRunAfterBothAsync2E() { |
2533 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2534 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2535 |
– |
Noop r = new Noop(); |
2536 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2537 |
– |
f.completeExceptionally(new CFException()); |
2538 |
– |
f2.complete(two); |
2539 |
– |
checkCompletedWithWrappedCFException(g); |
2540 |
– |
|
2541 |
– |
r = new Noop(); |
2542 |
– |
f = new CompletableFuture<>(); |
2543 |
– |
f2 = new CompletableFuture<>(); |
2544 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2545 |
– |
f.complete(one); |
2546 |
– |
f2.completeExceptionally(new CFException()); |
2547 |
– |
checkCompletedWithWrappedCFException(g); |
2548 |
– |
} |
2549 |
– |
|
2550 |
– |
/** |
2551 |
– |
* runAfterBothAsync result completes exceptionally if action does |
2552 |
– |
*/ |
2553 |
– |
public void testRunAfterBothAsync3E() { |
2554 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2555 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2556 |
– |
FailingNoop r = new FailingNoop(); |
2557 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2558 |
– |
f.complete(one); |
2559 |
– |
checkIncomplete(g); |
2560 |
– |
f2.complete(two); |
2561 |
– |
checkCompletedWithWrappedCFException(g); |
2562 |
– |
} |
2563 |
– |
|
2564 |
– |
/** |
2565 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
2566 |
– |
*/ |
2567 |
– |
public void testRunAfterBothAsync4E() { |
2568 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2569 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2570 |
– |
Noop r = new Noop(); |
2571 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2572 |
– |
assertTrue(f.cancel(true)); |
2573 |
– |
f2.complete(two); |
2574 |
– |
checkCompletedWithWrappedCancellationException(g); |
2575 |
– |
|
2576 |
– |
r = new Noop(); |
2577 |
– |
f = new CompletableFuture<>(); |
2578 |
– |
f2 = new CompletableFuture<>(); |
2579 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2580 |
– |
f.complete(one); |
2581 |
– |
assertTrue(f2.cancel(true)); |
2582 |
– |
checkCompletedWithWrappedCancellationException(g); |
2583 |
– |
} |
2584 |
– |
|
2585 |
– |
/** |
2689 |
|
* applyToEitherAsync result completes normally after normal |
2690 |
|
* completion of sources |
2691 |
|
*/ |
3034 |
|
ThreadExecutor exec = new ThreadExecutor(); |
3035 |
|
|
3036 |
|
Runnable[] throwingActions = { |
3037 |
< |
() -> { CompletableFuture.supplyAsync(null); }, |
3038 |
< |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
3039 |
< |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
3040 |
< |
|
3041 |
< |
() -> { CompletableFuture.runAsync(null); }, |
3042 |
< |
() -> { CompletableFuture.runAsync(null, exec); }, |
3043 |
< |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
3044 |
< |
|
3045 |
< |
() -> { f.completeExceptionally(null); }, |
3046 |
< |
|
3047 |
< |
() -> { f.thenApply(null); }, |
3048 |
< |
() -> { f.thenApplyAsync(null); }, |
3049 |
< |
() -> { f.thenApplyAsync((x) -> x, null); }, |
3050 |
< |
() -> { f.thenApplyAsync(null, exec); }, |
3051 |
< |
|
3052 |
< |
() -> { f.thenAccept(null); }, |
3053 |
< |
() -> { f.thenAcceptAsync(null); }, |
3054 |
< |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
3055 |
< |
() -> { f.thenAcceptAsync(null, exec); }, |
3056 |
< |
|
3057 |
< |
() -> { f.thenRun(null); }, |
3058 |
< |
() -> { f.thenRunAsync(null); }, |
3059 |
< |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
3060 |
< |
() -> { f.thenRunAsync(null, exec); }, |
3061 |
< |
|
3062 |
< |
() -> { f.thenCombine(g, null); }, |
3063 |
< |
() -> { f.thenCombineAsync(g, null); }, |
3064 |
< |
() -> { f.thenCombineAsync(g, null, exec); }, |
3065 |
< |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
3066 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
3067 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
3068 |
< |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
3069 |
< |
|
3070 |
< |
() -> { f.thenAcceptBoth(g, null); }, |
3071 |
< |
() -> { f.thenAcceptBothAsync(g, null); }, |
3072 |
< |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
3073 |
< |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
3074 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
3075 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
3076 |
< |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
3077 |
< |
|
3078 |
< |
() -> { f.runAfterBoth(g, null); }, |
3079 |
< |
() -> { f.runAfterBothAsync(g, null); }, |
3080 |
< |
() -> { f.runAfterBothAsync(g, null, exec); }, |
3081 |
< |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
3082 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
3083 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
3084 |
< |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
3085 |
< |
|
3086 |
< |
() -> { f.applyToEither(g, null); }, |
3087 |
< |
() -> { f.applyToEitherAsync(g, null); }, |
3088 |
< |
() -> { f.applyToEitherAsync(g, null, exec); }, |
3089 |
< |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
3090 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
3091 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
3092 |
< |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
3093 |
< |
|
3094 |
< |
() -> { f.acceptEither(g, null); }, |
3095 |
< |
() -> { f.acceptEitherAsync(g, null); }, |
3096 |
< |
() -> { f.acceptEitherAsync(g, null, exec); }, |
3097 |
< |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
3098 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
3099 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
3100 |
< |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
3101 |
< |
|
3102 |
< |
() -> { f.runAfterEither(g, null); }, |
3103 |
< |
() -> { f.runAfterEitherAsync(g, null); }, |
3104 |
< |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
3105 |
< |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
3106 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
3107 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
3108 |
< |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
3109 |
< |
|
3110 |
< |
() -> { f.thenCompose(null); }, |
3111 |
< |
() -> { f.thenComposeAsync(null); }, |
3112 |
< |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
3113 |
< |
() -> { f.thenComposeAsync(null, exec); }, |
3114 |
< |
|
3115 |
< |
() -> { f.exceptionally(null); }, |
3116 |
< |
|
3117 |
< |
() -> { f.handle(null); }, |
3118 |
< |
|
3119 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
3120 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
3121 |
< |
() -> { CompletableFuture.allOf(f, null); }, |
3122 |
< |
() -> { CompletableFuture.allOf(null, f); }, |
3123 |
< |
|
3124 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
3125 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
3126 |
< |
() -> { CompletableFuture.anyOf(f, null); }, |
3127 |
< |
() -> { CompletableFuture.anyOf(null, f); }, |
3037 |
> |
() -> CompletableFuture.supplyAsync(null), |
3038 |
> |
() -> CompletableFuture.supplyAsync(null, exec), |
3039 |
> |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
3040 |
> |
|
3041 |
> |
() -> CompletableFuture.runAsync(null), |
3042 |
> |
() -> CompletableFuture.runAsync(null, exec), |
3043 |
> |
() -> CompletableFuture.runAsync(() -> {}, null), |
3044 |
> |
|
3045 |
> |
() -> f.completeExceptionally(null), |
3046 |
> |
|
3047 |
> |
() -> f.thenApply(null), |
3048 |
> |
() -> f.thenApplyAsync(null), |
3049 |
> |
() -> f.thenApplyAsync((x) -> x, null), |
3050 |
> |
() -> f.thenApplyAsync(null, exec), |
3051 |
> |
|
3052 |
> |
() -> f.thenAccept(null), |
3053 |
> |
() -> f.thenAcceptAsync(null), |
3054 |
> |
() -> f.thenAcceptAsync((x) -> {} , null), |
3055 |
> |
() -> f.thenAcceptAsync(null, exec), |
3056 |
> |
|
3057 |
> |
() -> f.thenRun(null), |
3058 |
> |
() -> f.thenRunAsync(null), |
3059 |
> |
() -> f.thenRunAsync(() -> {} , null), |
3060 |
> |
() -> f.thenRunAsync(null, exec), |
3061 |
> |
|
3062 |
> |
() -> f.thenCombine(g, null), |
3063 |
> |
() -> f.thenCombineAsync(g, null), |
3064 |
> |
() -> f.thenCombineAsync(g, null, exec), |
3065 |
> |
() -> f.thenCombine(nullFuture, (x, y) -> x), |
3066 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x), |
3067 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec), |
3068 |
> |
() -> f.thenCombineAsync(g, (x, y) -> x, null), |
3069 |
> |
|
3070 |
> |
() -> f.thenAcceptBoth(g, null), |
3071 |
> |
() -> f.thenAcceptBothAsync(g, null), |
3072 |
> |
() -> f.thenAcceptBothAsync(g, null, exec), |
3073 |
> |
() -> f.thenAcceptBoth(nullFuture, (x, y) -> {}), |
3074 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}), |
3075 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec), |
3076 |
> |
() -> f.thenAcceptBothAsync(g, (x, y) -> {}, null), |
3077 |
> |
|
3078 |
> |
() -> f.runAfterBoth(g, null), |
3079 |
> |
() -> f.runAfterBothAsync(g, null), |
3080 |
> |
() -> f.runAfterBothAsync(g, null, exec), |
3081 |
> |
() -> f.runAfterBoth(nullFuture, () -> {}), |
3082 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}), |
3083 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}, exec), |
3084 |
> |
() -> f.runAfterBothAsync(g, () -> {}, null), |
3085 |
> |
|
3086 |
> |
() -> f.applyToEither(g, null), |
3087 |
> |
() -> f.applyToEitherAsync(g, null), |
3088 |
> |
() -> f.applyToEitherAsync(g, null, exec), |
3089 |
> |
() -> f.applyToEither(nullFuture, (x) -> x), |
3090 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
3091 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
3092 |
> |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
3093 |
> |
|
3094 |
> |
() -> f.acceptEither(g, null), |
3095 |
> |
() -> f.acceptEitherAsync(g, null), |
3096 |
> |
() -> f.acceptEitherAsync(g, null, exec), |
3097 |
> |
() -> f.acceptEither(nullFuture, (x) -> {}), |
3098 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
3099 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
3100 |
> |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
3101 |
> |
|
3102 |
> |
() -> f.runAfterEither(g, null), |
3103 |
> |
() -> f.runAfterEitherAsync(g, null), |
3104 |
> |
() -> f.runAfterEitherAsync(g, null, exec), |
3105 |
> |
() -> f.runAfterEither(nullFuture, () -> {}), |
3106 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}), |
3107 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}, exec), |
3108 |
> |
() -> f.runAfterEitherAsync(g, () -> {}, null), |
3109 |
> |
|
3110 |
> |
() -> f.thenCompose(null), |
3111 |
> |
() -> f.thenComposeAsync(null), |
3112 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
3113 |
> |
() -> f.thenComposeAsync(null, exec), |
3114 |
> |
|
3115 |
> |
() -> f.exceptionally(null), |
3116 |
> |
|
3117 |
> |
() -> f.handle(null), |
3118 |
> |
|
3119 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>)null), |
3120 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>[])null), |
3121 |
> |
() -> CompletableFuture.allOf(f, null), |
3122 |
> |
() -> CompletableFuture.allOf(null, f), |
3123 |
> |
|
3124 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>)null), |
3125 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>[])null), |
3126 |
> |
() -> CompletableFuture.anyOf(f, null), |
3127 |
> |
() -> CompletableFuture.anyOf(null, f), |
3128 |
> |
|
3129 |
> |
() -> f.obtrudeException(null), |
3130 |
|
}; |
3131 |
|
|
3132 |
|
assertThrows(NullPointerException.class, throwingActions); |