105 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
106 |
|
} |
107 |
|
|
108 |
< |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
109 |
< |
CFException ex) { |
108 |
> |
<U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f, |
109 |
> |
Throwable ex) { |
110 |
|
try { |
111 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
112 |
|
shouldThrow(); |
131 |
|
} catch (ExecutionException success) { |
132 |
|
assertSame(ex, success.getCause()); |
133 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
134 |
+ |
|
135 |
|
assertTrue(f.isDone()); |
136 |
|
assertFalse(f.isCancelled()); |
137 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
138 |
|
} |
139 |
|
|
140 |
+ |
<U> void checkCompletedWithWrappedException(CompletableFuture<U> f, |
141 |
+ |
Throwable ex) { |
142 |
+ |
checkCompletedExceptionallyWithRootCause(f, ex); |
143 |
+ |
try { |
144 |
+ |
CompletableFuture<Throwable> spy = f.handle |
145 |
+ |
((U u, Throwable t) -> t); |
146 |
+ |
assertTrue(spy.join() instanceof CompletionException); |
147 |
+ |
assertSame(ex, spy.join().getCause()); |
148 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
<U> void checkCompletedExceptionally(CompletableFuture<U> f, Throwable ex) { |
152 |
+ |
checkCompletedExceptionallyWithRootCause(f, ex); |
153 |
+ |
try { |
154 |
+ |
CompletableFuture<Throwable> spy = f.handle |
155 |
+ |
((U u, Throwable t) -> t); |
156 |
+ |
assertSame(ex, spy.join()); |
157 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
158 |
+ |
} |
159 |
+ |
|
160 |
|
void checkCancelled(CompletableFuture<?> f) { |
161 |
|
try { |
162 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
227 |
|
* isCancelled, join, get, and getNow |
228 |
|
*/ |
229 |
|
public void testComplete() { |
230 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
231 |
+ |
{ |
232 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
233 |
|
checkIncomplete(f); |
234 |
< |
f.complete(one); |
235 |
< |
checkCompletedNormally(f, one); |
236 |
< |
} |
234 |
> |
assertTrue(f.complete(v1)); |
235 |
> |
assertFalse(f.complete(v1)); |
236 |
> |
checkCompletedNormally(f, v1); |
237 |
> |
}} |
238 |
|
|
239 |
|
/** |
240 |
|
* completeExceptionally completes exceptionally, as indicated by |
242 |
|
*/ |
243 |
|
public void testCompleteExceptionally() { |
244 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
245 |
+ |
CFException ex = new CFException(); |
246 |
|
checkIncomplete(f); |
247 |
< |
f.completeExceptionally(new CFException()); |
248 |
< |
checkCompletedWithWrappedCFException(f); |
247 |
> |
f.completeExceptionally(ex); |
248 |
> |
checkCompletedExceptionally(f, ex); |
249 |
|
} |
250 |
|
|
251 |
|
/** |
253 |
|
* methods isDone, isCancelled, join, get, and getNow |
254 |
|
*/ |
255 |
|
public void testCancel() { |
256 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
257 |
+ |
{ |
258 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
259 |
|
checkIncomplete(f); |
260 |
|
assertTrue(f.cancel(true)); |
261 |
+ |
assertTrue(f.cancel(true)); |
262 |
|
checkCancelled(f); |
263 |
< |
} |
263 |
> |
}} |
264 |
|
|
265 |
|
/** |
266 |
|
* obtrudeValue forces completion with given value |
268 |
|
public void testObtrudeValue() { |
269 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
270 |
|
checkIncomplete(f); |
271 |
< |
f.complete(one); |
271 |
> |
assertTrue(f.complete(one)); |
272 |
|
checkCompletedNormally(f, one); |
273 |
|
f.obtrudeValue(three); |
274 |
|
checkCompletedNormally(f, three); |
289 |
|
* obtrudeException forces completion with given exception |
290 |
|
*/ |
291 |
|
public void testObtrudeException() { |
292 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
293 |
< |
checkIncomplete(f); |
294 |
< |
f.complete(one); |
295 |
< |
checkCompletedNormally(f, one); |
296 |
< |
f.obtrudeException(new CFException()); |
269 |
< |
checkCompletedWithWrappedCFException(f); |
292 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
293 |
> |
{ |
294 |
> |
CFException ex; |
295 |
> |
CompletableFuture<Integer> f; |
296 |
> |
|
297 |
|
f = new CompletableFuture<>(); |
298 |
< |
f.obtrudeException(new CFException()); |
299 |
< |
checkCompletedWithWrappedCFException(f); |
298 |
> |
assertTrue(f.complete(v1)); |
299 |
> |
for (int i = 0; i < 2; i++) { |
300 |
> |
f.obtrudeException(ex = new CFException()); |
301 |
> |
checkCompletedExceptionally(f, ex); |
302 |
> |
} |
303 |
> |
|
304 |
> |
f = new CompletableFuture<>(); |
305 |
> |
for (int i = 0; i < 2; i++) { |
306 |
> |
f.obtrudeException(ex = new CFException()); |
307 |
> |
checkCompletedExceptionally(f, ex); |
308 |
> |
} |
309 |
> |
|
310 |
|
f = new CompletableFuture<>(); |
311 |
+ |
f.completeExceptionally(ex = new CFException()); |
312 |
+ |
f.obtrudeValue(v1); |
313 |
+ |
checkCompletedNormally(f, v1); |
314 |
+ |
f.obtrudeException(ex = new CFException()); |
315 |
+ |
checkCompletedExceptionally(f, ex); |
316 |
|
f.completeExceptionally(new CFException()); |
317 |
< |
f.obtrudeValue(four); |
318 |
< |
checkCompletedNormally(f, four); |
319 |
< |
f.obtrudeException(new CFException()); |
320 |
< |
checkCompletedWithWrappedCFException(f); |
279 |
< |
} |
317 |
> |
checkCompletedExceptionally(f, ex); |
318 |
> |
assertFalse(f.complete(v1)); |
319 |
> |
checkCompletedExceptionally(f, ex); |
320 |
> |
}} |
321 |
|
|
322 |
|
/** |
323 |
|
* getNumberOfDependents returns number of dependent tasks |
324 |
|
*/ |
325 |
|
public void testGetNumberOfDependents() { |
326 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
327 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
328 |
+ |
{ |
329 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
330 |
|
assertEquals(0, f.getNumberOfDependents()); |
331 |
< |
CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
331 |
> |
final CompletableFuture<Void> g = m.thenRun(f, new Noop(m)); |
332 |
|
assertEquals(1, f.getNumberOfDependents()); |
333 |
|
assertEquals(0, g.getNumberOfDependents()); |
334 |
< |
CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
334 |
> |
final CompletableFuture<Void> h = m.thenRun(f, new Noop(m)); |
335 |
|
assertEquals(2, f.getNumberOfDependents()); |
336 |
< |
f.complete(1); |
336 |
> |
assertEquals(0, h.getNumberOfDependents()); |
337 |
> |
assertTrue(f.complete(v1)); |
338 |
|
checkCompletedNormally(g, null); |
339 |
+ |
checkCompletedNormally(h, null); |
340 |
|
assertEquals(0, f.getNumberOfDependents()); |
341 |
|
assertEquals(0, g.getNumberOfDependents()); |
342 |
< |
} |
342 |
> |
assertEquals(0, h.getNumberOfDependents()); |
343 |
> |
}} |
344 |
|
|
345 |
|
/** |
346 |
|
* toString indicates current completion state |
351 |
|
f = new CompletableFuture<String>(); |
352 |
|
assertTrue(f.toString().contains("[Not completed]")); |
353 |
|
|
354 |
< |
f.complete("foo"); |
354 |
> |
assertTrue(f.complete("foo")); |
355 |
|
assertTrue(f.toString().contains("[Completed normally]")); |
356 |
|
|
357 |
|
f = new CompletableFuture<String>(); |
358 |
< |
f.completeExceptionally(new IndexOutOfBoundsException()); |
358 |
> |
assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); |
359 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
360 |
+ |
|
361 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
362 |
+ |
f = new CompletableFuture<String>(); |
363 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
364 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
365 |
+ |
} |
366 |
|
} |
367 |
|
|
368 |
|
/** |
539 |
|
invoked(); |
540 |
|
value = x; |
541 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
542 |
< |
f.complete(inc(x)); |
542 |
> |
assertTrue(f.complete(inc(x))); |
543 |
|
return f; |
544 |
|
} |
545 |
|
} |
847 |
|
{ |
848 |
|
final AtomicInteger a = new AtomicInteger(0); |
849 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
850 |
< |
if (!createIncomplete) f.complete(v1); |
850 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
851 |
|
final CompletableFuture<Integer> g = f.exceptionally |
852 |
|
((Throwable t) -> { |
853 |
|
// Should not be called |
854 |
|
a.getAndIncrement(); |
855 |
|
throw new AssertionError(); |
856 |
|
}); |
857 |
< |
if (createIncomplete) f.complete(v1); |
857 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
858 |
|
|
859 |
|
checkCompletedNormally(g, v1); |
860 |
|
checkCompletedNormally(f, v1); |
861 |
|
assertEquals(0, a.get()); |
862 |
|
}} |
863 |
|
|
811 |
– |
|
864 |
|
/** |
865 |
|
* exceptionally action completes with function value on source |
866 |
|
* exception |
904 |
|
}); |
905 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
906 |
|
|
907 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
907 |
> |
checkCompletedWithWrappedException(g, ex2); |
908 |
> |
assertEquals(1, a.get()); |
909 |
> |
}} |
910 |
> |
|
911 |
> |
/** |
912 |
> |
* whenComplete action executes on normal completion, propagating |
913 |
> |
* source result. |
914 |
> |
*/ |
915 |
> |
public void testWhenComplete_normalCompletion1() { |
916 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
917 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
918 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
919 |
> |
{ |
920 |
> |
final AtomicInteger a = new AtomicInteger(0); |
921 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
922 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
923 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
924 |
> |
(f, |
925 |
> |
(Integer x, Throwable t) -> { |
926 |
> |
m.checkExecutionMode(); |
927 |
> |
threadAssertSame(x, v1); |
928 |
> |
threadAssertNull(t); |
929 |
> |
a.getAndIncrement(); |
930 |
> |
}); |
931 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
932 |
> |
|
933 |
> |
checkCompletedNormally(g, v1); |
934 |
> |
checkCompletedNormally(f, v1); |
935 |
> |
assertEquals(1, a.get()); |
936 |
> |
}} |
937 |
> |
|
938 |
> |
/** |
939 |
> |
* whenComplete action executes on exceptional completion, propagating |
940 |
> |
* source result. |
941 |
> |
*/ |
942 |
> |
public void testWhenComplete_exceptionalCompletion() { |
943 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
944 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
945 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
946 |
> |
{ |
947 |
> |
final AtomicInteger a = new AtomicInteger(0); |
948 |
> |
final CFException ex = new CFException(); |
949 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
950 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
951 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
952 |
> |
(f, |
953 |
> |
(Integer x, Throwable t) -> { |
954 |
> |
m.checkExecutionMode(); |
955 |
> |
threadAssertNull(x); |
956 |
> |
threadAssertSame(t, ex); |
957 |
> |
a.getAndIncrement(); |
958 |
> |
}); |
959 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
960 |
> |
|
961 |
> |
checkCompletedWithWrappedException(g, ex); |
962 |
> |
checkCompletedExceptionally(f, ex); |
963 |
> |
assertEquals(1, a.get()); |
964 |
> |
}} |
965 |
> |
|
966 |
> |
/** |
967 |
> |
* whenComplete action executes on cancelled source, propagating |
968 |
> |
* CancellationException. |
969 |
> |
*/ |
970 |
> |
public void testWhenComplete_sourceCancelled() { |
971 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
972 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
973 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
974 |
> |
{ |
975 |
> |
final AtomicInteger a = new AtomicInteger(0); |
976 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
977 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
978 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
979 |
> |
(f, |
980 |
> |
(Integer x, Throwable t) -> { |
981 |
> |
m.checkExecutionMode(); |
982 |
> |
threadAssertNull(x); |
983 |
> |
threadAssertTrue(t instanceof CancellationException); |
984 |
> |
a.getAndIncrement(); |
985 |
> |
}); |
986 |
> |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
987 |
> |
|
988 |
> |
checkCompletedWithWrappedCancellationException(g); |
989 |
> |
checkCancelled(f); |
990 |
> |
assertEquals(1, a.get()); |
991 |
> |
}} |
992 |
> |
|
993 |
> |
/** |
994 |
> |
* If a whenComplete action throws an exception when triggered by |
995 |
> |
* a normal completion, it completes exceptionally |
996 |
> |
*/ |
997 |
> |
public void testWhenComplete_actionFailed() { |
998 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
999 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1000 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1001 |
> |
{ |
1002 |
> |
final AtomicInteger a = new AtomicInteger(0); |
1003 |
> |
final CFException ex = new CFException(); |
1004 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1005 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1006 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
1007 |
> |
(f, |
1008 |
> |
(Integer x, Throwable t) -> { |
1009 |
> |
m.checkExecutionMode(); |
1010 |
> |
threadAssertSame(x, v1); |
1011 |
> |
threadAssertNull(t); |
1012 |
> |
a.getAndIncrement(); |
1013 |
> |
throw ex; |
1014 |
> |
}); |
1015 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
1016 |
> |
|
1017 |
> |
checkCompletedWithWrappedException(g, ex); |
1018 |
> |
checkCompletedNormally(f, v1); |
1019 |
> |
assertEquals(1, a.get()); |
1020 |
> |
}} |
1021 |
> |
|
1022 |
> |
/** |
1023 |
> |
* If a whenComplete action throws an exception when triggered by |
1024 |
> |
* a source completion that also throws an exception, the source |
1025 |
> |
* exception takes precedence. |
1026 |
> |
*/ |
1027 |
> |
public void testWhenComplete_actionFailedSourceFailed() { |
1028 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1029 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1030 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1031 |
> |
{ |
1032 |
> |
final AtomicInteger a = new AtomicInteger(0); |
1033 |
> |
final CFException ex1 = new CFException(); |
1034 |
> |
final CFException ex2 = new CFException(); |
1035 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1036 |
> |
|
1037 |
> |
if (!createIncomplete) f.completeExceptionally(ex1); |
1038 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
1039 |
> |
(f, |
1040 |
> |
(Integer x, Throwable t) -> { |
1041 |
> |
m.checkExecutionMode(); |
1042 |
> |
threadAssertSame(t, ex1); |
1043 |
> |
threadAssertNull(x); |
1044 |
> |
a.getAndIncrement(); |
1045 |
> |
throw ex2; |
1046 |
> |
}); |
1047 |
> |
if (createIncomplete) f.completeExceptionally(ex1); |
1048 |
> |
|
1049 |
> |
checkCompletedWithWrappedException(g, ex1); |
1050 |
> |
checkCompletedExceptionally(f, ex1); |
1051 |
|
assertEquals(1, a.get()); |
1052 |
|
}} |
1053 |
|
|
1062 |
|
{ |
1063 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1064 |
|
final AtomicInteger a = new AtomicInteger(0); |
1065 |
< |
if (!createIncomplete) f.complete(v1); |
1065 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1066 |
|
final CompletableFuture<Integer> g = m.handle |
1067 |
|
(f, |
1068 |
|
(Integer x, Throwable t) -> { |
1072 |
|
a.getAndIncrement(); |
1073 |
|
return inc(v1); |
1074 |
|
}); |
1075 |
< |
if (createIncomplete) f.complete(v1); |
1075 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
1076 |
|
|
1077 |
|
checkCompletedNormally(g, inc(v1)); |
1078 |
|
checkCompletedNormally(f, v1); |
1104 |
|
if (createIncomplete) f.completeExceptionally(ex); |
1105 |
|
|
1106 |
|
checkCompletedNormally(g, v1); |
1107 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1107 |
> |
checkCompletedExceptionally(f, ex); |
1108 |
|
assertEquals(1, a.get()); |
1109 |
|
}} |
1110 |
|
|
1160 |
|
}); |
1161 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
1162 |
|
|
1163 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
1164 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
1163 |
> |
checkCompletedWithWrappedException(g, ex2); |
1164 |
> |
checkCompletedExceptionally(f, ex1); |
1165 |
|
assertEquals(1, a.get()); |
1166 |
|
}} |
1167 |
|
|
1173 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1174 |
|
final AtomicInteger a = new AtomicInteger(0); |
1175 |
|
final CFException ex = new CFException(); |
1176 |
< |
if (!createIncomplete) f.complete(v1); |
1176 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1177 |
|
final CompletableFuture<Integer> g = m.handle |
1178 |
|
(f, |
1179 |
|
(Integer x, Throwable t) -> { |
1183 |
|
a.getAndIncrement(); |
1184 |
|
throw ex; |
1185 |
|
}); |
1186 |
< |
if (createIncomplete) f.complete(v1); |
1186 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
1187 |
|
|
1188 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1188 |
> |
checkCompletedWithWrappedException(g, ex); |
1189 |
|
checkCompletedNormally(f, v1); |
1190 |
|
assertEquals(1, a.get()); |
1191 |
|
}} |
1269 |
|
{ |
1270 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1271 |
|
final Noop r = new Noop(m); |
1272 |
< |
if (!createIncomplete) f.complete(v1); |
1272 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1273 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1274 |
|
if (createIncomplete) { |
1275 |
|
checkIncomplete(g); |
1276 |
< |
f.complete(v1); |
1276 |
> |
assertTrue(f.complete(v1)); |
1277 |
|
} |
1278 |
|
|
1279 |
|
checkCompletedNormally(g, null); |
1299 |
|
f.completeExceptionally(ex); |
1300 |
|
} |
1301 |
|
|
1302 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1303 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1302 |
> |
checkCompletedWithWrappedException(g, ex); |
1303 |
> |
checkCompletedExceptionally(f, ex); |
1304 |
|
r.assertNotInvoked(); |
1305 |
|
}} |
1306 |
|
|
1336 |
|
{ |
1337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1338 |
|
final FailingRunnable r = new FailingRunnable(m); |
1339 |
< |
if (!createIncomplete) f.complete(v1); |
1339 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1340 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1341 |
|
if (createIncomplete) { |
1342 |
|
checkIncomplete(g); |
1343 |
< |
f.complete(v1); |
1343 |
> |
assertTrue(f.complete(v1)); |
1344 |
|
} |
1345 |
|
|
1346 |
|
checkCompletedWithWrappedCFException(g); |
1357 |
|
{ |
1358 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1359 |
|
final IncFunction r = new IncFunction(m); |
1360 |
< |
if (!createIncomplete) f.complete(v1); |
1360 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1361 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1362 |
|
if (createIncomplete) { |
1363 |
|
checkIncomplete(g); |
1364 |
< |
f.complete(v1); |
1364 |
> |
assertTrue(f.complete(v1)); |
1365 |
|
} |
1366 |
|
|
1367 |
|
checkCompletedNormally(g, inc(v1)); |
1368 |
|
checkCompletedNormally(f, v1); |
1369 |
< |
r.assertInvoked(); |
1369 |
> |
r.assertValue(inc(v1)); |
1370 |
|
}} |
1371 |
|
|
1372 |
|
/** |
1387 |
|
f.completeExceptionally(ex); |
1388 |
|
} |
1389 |
|
|
1390 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1391 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1390 |
> |
checkCompletedWithWrappedException(g, ex); |
1391 |
> |
checkCompletedExceptionally(f, ex); |
1392 |
|
r.assertNotInvoked(); |
1393 |
|
}} |
1394 |
|
|
1424 |
|
{ |
1425 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1426 |
|
final FailingFunction r = new FailingFunction(m); |
1427 |
< |
if (!createIncomplete) f.complete(v1); |
1427 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1428 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1429 |
|
if (createIncomplete) { |
1430 |
|
checkIncomplete(g); |
1431 |
< |
f.complete(v1); |
1431 |
> |
assertTrue(f.complete(v1)); |
1432 |
|
} |
1433 |
|
|
1434 |
|
checkCompletedWithWrappedCFException(g); |
1445 |
|
{ |
1446 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1447 |
|
final NoopConsumer r = new NoopConsumer(m); |
1448 |
< |
if (!createIncomplete) f.complete(v1); |
1448 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
1449 |
|
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1450 |
|
if (createIncomplete) { |
1451 |
|
checkIncomplete(g); |
1452 |
< |
f.complete(v1); |
1452 |
> |
assertTrue(f.complete(v1)); |
1453 |
|
} |
1454 |
|
|
1455 |
|
checkCompletedNormally(g, null); |
1475 |
|
f.completeExceptionally(ex); |
1476 |
|
} |
1477 |
|
|
1478 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1479 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1478 |
> |
checkCompletedWithWrappedException(g, ex); |
1479 |
> |
checkCompletedExceptionally(f, ex); |
1480 |
|
r.assertNotInvoked(); |
1481 |
|
}} |
1482 |
|
|
1538 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1539 |
|
final SubtractFunction r = new SubtractFunction(m); |
1540 |
|
|
1541 |
< |
if (fFirst) f.complete(v1); else g.complete(v2); |
1541 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1542 |
|
if (!createIncomplete) |
1543 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1543 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1544 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1545 |
|
if (createIncomplete) { |
1546 |
|
checkIncomplete(h); |
1547 |
|
r.assertNotInvoked(); |
1548 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1548 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1549 |
|
} |
1550 |
|
|
1551 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1552 |
|
checkCompletedNormally(f, v1); |
1553 |
|
checkCompletedNormally(g, v2); |
1554 |
< |
r.assertInvoked(); |
1554 |
> |
r.assertValue(subtract(v1, v2)); |
1555 |
|
}} |
1556 |
|
|
1557 |
|
/** |
1569 |
|
final CFException ex = new CFException(); |
1570 |
|
final SubtractFunction r = new SubtractFunction(m); |
1571 |
|
|
1572 |
< |
(fFirst ? f : g).complete(v1); |
1572 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1573 |
|
if (!createIncomplete) |
1574 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1574 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1575 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1576 |
|
if (createIncomplete) { |
1577 |
|
checkIncomplete(h); |
1578 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1578 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1579 |
|
} |
1580 |
|
|
1581 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1581 |
> |
checkCompletedWithWrappedException(h, ex); |
1582 |
|
r.assertNotInvoked(); |
1583 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1584 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1584 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1585 |
|
}} |
1586 |
|
|
1587 |
|
/** |
1598 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1599 |
|
final SubtractFunction r = new SubtractFunction(m); |
1600 |
|
|
1601 |
< |
(fFirst ? f : g).complete(v1); |
1601 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1602 |
|
if (!createIncomplete) |
1603 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1604 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1627 |
|
final FailingBiFunction r = new FailingBiFunction(m); |
1628 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1629 |
|
|
1630 |
< |
if (fFirst) { |
1631 |
< |
f.complete(v1); |
1437 |
< |
g.complete(v2); |
1438 |
< |
} else { |
1439 |
< |
g.complete(v2); |
1440 |
< |
f.complete(v1); |
1441 |
< |
} |
1630 |
> |
assertTrue( fFirst ? f.complete(v1) : g.complete(v2)); |
1631 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1632 |
|
|
1633 |
|
checkCompletedWithWrappedCFException(h); |
1634 |
|
checkCompletedNormally(f, v1); |
1650 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1651 |
|
final SubtractAction r = new SubtractAction(m); |
1652 |
|
|
1653 |
< |
if (fFirst) f.complete(v1); else g.complete(v2); |
1653 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1654 |
|
if (!createIncomplete) |
1655 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1655 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1656 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1657 |
|
if (createIncomplete) { |
1658 |
|
checkIncomplete(h); |
1659 |
|
r.assertNotInvoked(); |
1660 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1660 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1661 |
|
} |
1662 |
|
|
1663 |
|
checkCompletedNormally(h, null); |
1681 |
|
final CFException ex = new CFException(); |
1682 |
|
final SubtractAction r = new SubtractAction(m); |
1683 |
|
|
1684 |
< |
(fFirst ? f : g).complete(v1); |
1684 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1685 |
|
if (!createIncomplete) |
1686 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1686 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1687 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1688 |
|
if (createIncomplete) { |
1689 |
|
checkIncomplete(h); |
1690 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1690 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1691 |
|
} |
1692 |
|
|
1693 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1693 |
> |
checkCompletedWithWrappedException(h, ex); |
1694 |
|
r.assertNotInvoked(); |
1695 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1696 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1696 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1697 |
|
}} |
1698 |
|
|
1699 |
|
/** |
1710 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
|
final SubtractAction r = new SubtractAction(m); |
1712 |
|
|
1713 |
< |
(fFirst ? f : g).complete(v1); |
1713 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1714 |
|
if (!createIncomplete) |
1715 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1716 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1739 |
|
final FailingBiConsumer r = new FailingBiConsumer(m); |
1740 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1741 |
|
|
1742 |
< |
if (fFirst) { |
1743 |
< |
f.complete(v1); |
1554 |
< |
g.complete(v2); |
1555 |
< |
} else { |
1556 |
< |
g.complete(v2); |
1557 |
< |
f.complete(v1); |
1558 |
< |
} |
1742 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1743 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1744 |
|
|
1745 |
|
checkCompletedWithWrappedCFException(h); |
1746 |
|
checkCompletedNormally(f, v1); |
1762 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1763 |
|
final Noop r = new Noop(m); |
1764 |
|
|
1765 |
< |
if (fFirst) f.complete(v1); else g.complete(v2); |
1765 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1766 |
|
if (!createIncomplete) |
1767 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1767 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1768 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1769 |
|
if (createIncomplete) { |
1770 |
|
checkIncomplete(h); |
1771 |
|
r.assertNotInvoked(); |
1772 |
< |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1772 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1773 |
|
} |
1774 |
|
|
1775 |
|
checkCompletedNormally(h, null); |
1793 |
|
final CFException ex = new CFException(); |
1794 |
|
final Noop r = new Noop(m); |
1795 |
|
|
1796 |
< |
(fFirst ? f : g).complete(v1); |
1796 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1797 |
|
if (!createIncomplete) |
1798 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1798 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1799 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1800 |
|
if (createIncomplete) { |
1801 |
|
checkIncomplete(h); |
1802 |
< |
(!fFirst ? f : g).completeExceptionally(ex); |
1802 |
> |
assertTrue((!fFirst ? f : g).completeExceptionally(ex)); |
1803 |
|
} |
1804 |
|
|
1805 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1805 |
> |
checkCompletedWithWrappedException(h, ex); |
1806 |
|
r.assertNotInvoked(); |
1807 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1808 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1808 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1809 |
|
}} |
1810 |
|
|
1811 |
|
/** |
1822 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1823 |
|
final Noop r = new Noop(m); |
1824 |
|
|
1825 |
< |
|
1641 |
< |
(fFirst ? f : g).complete(v1); |
1825 |
> |
assertTrue((fFirst ? f : g).complete(v1)); |
1826 |
|
if (!createIncomplete) |
1827 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1828 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1852 |
|
final FailingRunnable r2 = new FailingRunnable(m); |
1853 |
|
|
1854 |
|
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1); |
1855 |
< |
if (fFirst) { |
1856 |
< |
f.complete(v1); |
1673 |
< |
g.complete(v2); |
1674 |
< |
} else { |
1675 |
< |
g.complete(v2); |
1676 |
< |
f.complete(v1); |
1677 |
< |
} |
1855 |
> |
assertTrue(fFirst ? f.complete(v1) : g.complete(v2)); |
1856 |
> |
assertTrue(!fFirst ? f.complete(v1) : g.complete(v2)); |
1857 |
|
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2); |
1858 |
|
|
1859 |
|
checkCompletedWithWrappedCFException(h1); |
1931 |
|
rs[0].assertNotInvoked(); |
1932 |
|
rs[1].assertNotInvoked(); |
1933 |
|
f.completeExceptionally(ex); |
1934 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1935 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1934 |
> |
checkCompletedWithWrappedException(h0, ex); |
1935 |
> |
checkCompletedWithWrappedException(h1, ex); |
1936 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1937 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1938 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1939 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1938 |
> |
checkCompletedWithWrappedException(h2, ex); |
1939 |
> |
checkCompletedWithWrappedException(h3, ex); |
1940 |
|
g.complete(v1); |
1941 |
|
|
1942 |
|
// unspecified behavior - both source completions available |
1944 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1945 |
|
try { |
1946 |
|
assertEquals(inc(v1), h4.join()); |
1947 |
< |
rs[4].assertInvoked(); |
1947 |
> |
rs[4].assertValue(inc(v1)); |
1948 |
|
} catch (CompletionException ok) { |
1949 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1949 |
> |
checkCompletedWithWrappedException(h4, ex); |
1950 |
|
rs[4].assertNotInvoked(); |
1951 |
|
} |
1952 |
|
try { |
1953 |
|
assertEquals(inc(v1), h5.join()); |
1954 |
< |
rs[5].assertInvoked(); |
1954 |
> |
rs[5].assertValue(inc(v1)); |
1955 |
|
} catch (CompletionException ok) { |
1956 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
1956 |
> |
checkCompletedWithWrappedException(h5, ex); |
1957 |
|
rs[5].assertNotInvoked(); |
1958 |
|
} |
1959 |
|
|
1960 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1960 |
> |
checkCompletedExceptionally(f, ex); |
1961 |
|
checkCompletedNormally(g, v1); |
1962 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1963 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1964 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1965 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1966 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1962 |
> |
checkCompletedWithWrappedException(h0, ex); |
1963 |
> |
checkCompletedWithWrappedException(h1, ex); |
1964 |
> |
checkCompletedWithWrappedException(h2, ex); |
1965 |
> |
checkCompletedWithWrappedException(h3, ex); |
1966 |
> |
checkCompletedWithWrappedException(h4, ex); |
1967 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1968 |
|
}} |
1969 |
|
|
1970 |
+ |
public void testApplyToEither_exceptionalCompletion2() { |
1971 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1972 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1973 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1974 |
+ |
{ |
1975 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1976 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1977 |
+ |
final CFException ex = new CFException(); |
1978 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1979 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1980 |
+ |
|
1981 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1982 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1983 |
+ |
assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
1984 |
+ |
assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
1985 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1986 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1987 |
+ |
|
1988 |
+ |
// unspecified behavior - both source completions available |
1989 |
+ |
try { |
1990 |
+ |
assertEquals(inc(v1), h0.join()); |
1991 |
+ |
rs[0].assertValue(inc(v1)); |
1992 |
+ |
} catch (CompletionException ok) { |
1993 |
+ |
checkCompletedWithWrappedException(h0, ex); |
1994 |
+ |
rs[0].assertNotInvoked(); |
1995 |
+ |
} |
1996 |
+ |
try { |
1997 |
+ |
assertEquals(inc(v1), h1.join()); |
1998 |
+ |
rs[1].assertValue(inc(v1)); |
1999 |
+ |
} catch (CompletionException ok) { |
2000 |
+ |
checkCompletedWithWrappedException(h1, ex); |
2001 |
+ |
rs[1].assertNotInvoked(); |
2002 |
+ |
} |
2003 |
+ |
try { |
2004 |
+ |
assertEquals(inc(v1), h2.join()); |
2005 |
+ |
rs[2].assertValue(inc(v1)); |
2006 |
+ |
} catch (CompletionException ok) { |
2007 |
+ |
checkCompletedWithWrappedException(h2, ex); |
2008 |
+ |
rs[2].assertNotInvoked(); |
2009 |
+ |
} |
2010 |
+ |
try { |
2011 |
+ |
assertEquals(inc(v1), h3.join()); |
2012 |
+ |
rs[3].assertValue(inc(v1)); |
2013 |
+ |
} catch (CompletionException ok) { |
2014 |
+ |
checkCompletedWithWrappedException(h3, ex); |
2015 |
+ |
rs[3].assertNotInvoked(); |
2016 |
+ |
} |
2017 |
+ |
|
2018 |
+ |
checkCompletedNormally(f, v1); |
2019 |
+ |
checkCompletedExceptionally(g, ex); |
2020 |
+ |
}} |
2021 |
+ |
|
2022 |
|
/** |
2023 |
|
* applyToEither result completes exceptionally if either source cancelled |
2024 |
|
*/ |
2052 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
2053 |
|
try { |
2054 |
|
assertEquals(inc(v1), h4.join()); |
2055 |
< |
rs[4].assertInvoked(); |
2055 |
> |
rs[4].assertValue(inc(v1)); |
2056 |
|
} catch (CompletionException ok) { |
2057 |
|
checkCompletedWithWrappedCancellationException(h4); |
2058 |
|
rs[4].assertNotInvoked(); |
2059 |
|
} |
2060 |
|
try { |
2061 |
|
assertEquals(inc(v1), h5.join()); |
2062 |
< |
rs[5].assertInvoked(); |
2062 |
> |
rs[5].assertValue(inc(v1)); |
2063 |
|
} catch (CompletionException ok) { |
2064 |
|
checkCompletedWithWrappedCancellationException(h5); |
2065 |
|
rs[5].assertNotInvoked(); |
2074 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2075 |
|
}} |
2076 |
|
|
2077 |
+ |
public void testApplyToEither_sourceCancelled2() { |
2078 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2079 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2080 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2081 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2082 |
+ |
{ |
2083 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2084 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2085 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
2086 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
2087 |
+ |
|
2088 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
2089 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
2090 |
+ |
assertTrue(fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning)); |
2091 |
+ |
assertTrue(!fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning)); |
2092 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
2093 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
2094 |
+ |
|
2095 |
+ |
// unspecified behavior - both source completions available |
2096 |
+ |
try { |
2097 |
+ |
assertEquals(inc(v1), h0.join()); |
2098 |
+ |
rs[0].assertValue(inc(v1)); |
2099 |
+ |
} catch (CompletionException ok) { |
2100 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
2101 |
+ |
rs[0].assertNotInvoked(); |
2102 |
+ |
} |
2103 |
+ |
try { |
2104 |
+ |
assertEquals(inc(v1), h1.join()); |
2105 |
+ |
rs[1].assertValue(inc(v1)); |
2106 |
+ |
} catch (CompletionException ok) { |
2107 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
2108 |
+ |
rs[1].assertNotInvoked(); |
2109 |
+ |
} |
2110 |
+ |
try { |
2111 |
+ |
assertEquals(inc(v1), h2.join()); |
2112 |
+ |
rs[2].assertValue(inc(v1)); |
2113 |
+ |
} catch (CompletionException ok) { |
2114 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
2115 |
+ |
rs[2].assertNotInvoked(); |
2116 |
+ |
} |
2117 |
+ |
try { |
2118 |
+ |
assertEquals(inc(v1), h3.join()); |
2119 |
+ |
rs[3].assertValue(inc(v1)); |
2120 |
+ |
} catch (CompletionException ok) { |
2121 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
2122 |
+ |
rs[3].assertNotInvoked(); |
2123 |
+ |
} |
2124 |
+ |
|
2125 |
+ |
checkCompletedNormally(f, v1); |
2126 |
+ |
checkCancelled(g); |
2127 |
+ |
}} |
2128 |
+ |
|
2129 |
|
/** |
2130 |
|
* applyToEither result completes exceptionally if action does |
2131 |
|
*/ |
2240 |
|
rs[0].assertNotInvoked(); |
2241 |
|
rs[1].assertNotInvoked(); |
2242 |
|
f.completeExceptionally(ex); |
2243 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2244 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2243 |
> |
checkCompletedWithWrappedException(h0, ex); |
2244 |
> |
checkCompletedWithWrappedException(h1, ex); |
2245 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2246 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2247 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2248 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2247 |
> |
checkCompletedWithWrappedException(h2, ex); |
2248 |
> |
checkCompletedWithWrappedException(h3, ex); |
2249 |
|
|
2250 |
|
g.complete(v1); |
2251 |
|
|
2256 |
|
assertNull(h4.join()); |
2257 |
|
rs[4].assertValue(v1); |
2258 |
|
} catch (CompletionException ok) { |
2259 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2259 |
> |
checkCompletedWithWrappedException(h4, ex); |
2260 |
|
rs[4].assertNotInvoked(); |
2261 |
|
} |
2262 |
|
try { |
2263 |
|
assertNull(h5.join()); |
2264 |
|
rs[5].assertValue(v1); |
2265 |
|
} catch (CompletionException ok) { |
2266 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
2266 |
> |
checkCompletedWithWrappedException(h5, ex); |
2267 |
|
rs[5].assertNotInvoked(); |
2268 |
|
} |
2269 |
|
|
2270 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2270 |
> |
checkCompletedExceptionally(f, ex); |
2271 |
|
checkCompletedNormally(g, v1); |
2272 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2273 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2274 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2275 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2276 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2272 |
> |
checkCompletedWithWrappedException(h0, ex); |
2273 |
> |
checkCompletedWithWrappedException(h1, ex); |
2274 |
> |
checkCompletedWithWrappedException(h2, ex); |
2275 |
> |
checkCompletedWithWrappedException(h3, ex); |
2276 |
> |
checkCompletedWithWrappedException(h4, ex); |
2277 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2278 |
|
}} |
2279 |
|
|
2280 |
+ |
public void testAcceptEither_exceptionalCompletion2() { |
2281 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2282 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2283 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2284 |
+ |
{ |
2285 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2286 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2287 |
+ |
final CFException ex = new CFException(); |
2288 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2289 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2290 |
+ |
|
2291 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2292 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2293 |
+ |
assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2294 |
+ |
assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2295 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2296 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2297 |
+ |
|
2298 |
+ |
// unspecified behavior - both source completions available |
2299 |
+ |
try { |
2300 |
+ |
assertEquals(null, h0.join()); |
2301 |
+ |
rs[0].assertValue(v1); |
2302 |
+ |
} catch (CompletionException ok) { |
2303 |
+ |
checkCompletedWithWrappedException(h0, ex); |
2304 |
+ |
rs[0].assertNotInvoked(); |
2305 |
+ |
} |
2306 |
+ |
try { |
2307 |
+ |
assertEquals(null, h1.join()); |
2308 |
+ |
rs[1].assertValue(v1); |
2309 |
+ |
} catch (CompletionException ok) { |
2310 |
+ |
checkCompletedWithWrappedException(h1, ex); |
2311 |
+ |
rs[1].assertNotInvoked(); |
2312 |
+ |
} |
2313 |
+ |
try { |
2314 |
+ |
assertEquals(null, h2.join()); |
2315 |
+ |
rs[2].assertValue(v1); |
2316 |
+ |
} catch (CompletionException ok) { |
2317 |
+ |
checkCompletedWithWrappedException(h2, ex); |
2318 |
+ |
rs[2].assertNotInvoked(); |
2319 |
+ |
} |
2320 |
+ |
try { |
2321 |
+ |
assertEquals(null, h3.join()); |
2322 |
+ |
rs[3].assertValue(v1); |
2323 |
+ |
} catch (CompletionException ok) { |
2324 |
+ |
checkCompletedWithWrappedException(h3, ex); |
2325 |
+ |
rs[3].assertNotInvoked(); |
2326 |
+ |
} |
2327 |
+ |
|
2328 |
+ |
checkCompletedNormally(f, v1); |
2329 |
+ |
checkCompletedExceptionally(g, ex); |
2330 |
+ |
}} |
2331 |
+ |
|
2332 |
|
/** |
2333 |
|
* acceptEither result completes exceptionally if either source cancelled |
2334 |
|
*/ |
2494 |
|
checkIncomplete(h1); |
2495 |
|
rs[0].assertNotInvoked(); |
2496 |
|
rs[1].assertNotInvoked(); |
2497 |
< |
f.completeExceptionally(ex); |
2498 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2499 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2497 |
> |
assertTrue(f.completeExceptionally(ex)); |
2498 |
> |
checkCompletedWithWrappedException(h0, ex); |
2499 |
> |
checkCompletedWithWrappedException(h1, ex); |
2500 |
|
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2501 |
|
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2502 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2503 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2502 |
> |
checkCompletedWithWrappedException(h2, ex); |
2503 |
> |
checkCompletedWithWrappedException(h3, ex); |
2504 |
|
|
2505 |
< |
g.complete(v1); |
2505 |
> |
assertTrue(g.complete(v1)); |
2506 |
|
|
2507 |
|
// unspecified behavior - both source completions available |
2508 |
|
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2511 |
|
assertNull(h4.join()); |
2512 |
|
rs[4].assertInvoked(); |
2513 |
|
} catch (CompletionException ok) { |
2514 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2514 |
> |
checkCompletedWithWrappedException(h4, ex); |
2515 |
|
rs[4].assertNotInvoked(); |
2516 |
|
} |
2517 |
|
try { |
2518 |
|
assertNull(h5.join()); |
2519 |
|
rs[5].assertInvoked(); |
2520 |
|
} catch (CompletionException ok) { |
2521 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
2521 |
> |
checkCompletedWithWrappedException(h5, ex); |
2522 |
|
rs[5].assertNotInvoked(); |
2523 |
|
} |
2524 |
|
|
2525 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2525 |
> |
checkCompletedExceptionally(f, ex); |
2526 |
|
checkCompletedNormally(g, v1); |
2527 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2528 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2529 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2530 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2531 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2527 |
> |
checkCompletedWithWrappedException(h0, ex); |
2528 |
> |
checkCompletedWithWrappedException(h1, ex); |
2529 |
> |
checkCompletedWithWrappedException(h2, ex); |
2530 |
> |
checkCompletedWithWrappedException(h3, ex); |
2531 |
> |
checkCompletedWithWrappedException(h4, ex); |
2532 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2533 |
|
}} |
2534 |
|
|
2535 |
+ |
public void testRunAfterEither_exceptionalCompletion2() { |
2536 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2537 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2538 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2539 |
+ |
{ |
2540 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2541 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2542 |
+ |
final CFException ex = new CFException(); |
2543 |
+ |
final Noop[] rs = new Noop[6]; |
2544 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2545 |
+ |
|
2546 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2547 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2548 |
+ |
assertTrue( fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2549 |
+ |
assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex)); |
2550 |
+ |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2551 |
+ |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2552 |
+ |
|
2553 |
+ |
// unspecified behavior - both source completions available |
2554 |
+ |
try { |
2555 |
+ |
assertEquals(null, h0.join()); |
2556 |
+ |
rs[0].assertInvoked(); |
2557 |
+ |
} catch (CompletionException ok) { |
2558 |
+ |
checkCompletedWithWrappedException(h0, ex); |
2559 |
+ |
rs[0].assertNotInvoked(); |
2560 |
+ |
} |
2561 |
+ |
try { |
2562 |
+ |
assertEquals(null, h1.join()); |
2563 |
+ |
rs[1].assertInvoked(); |
2564 |
+ |
} catch (CompletionException ok) { |
2565 |
+ |
checkCompletedWithWrappedException(h1, ex); |
2566 |
+ |
rs[1].assertNotInvoked(); |
2567 |
+ |
} |
2568 |
+ |
try { |
2569 |
+ |
assertEquals(null, h2.join()); |
2570 |
+ |
rs[2].assertInvoked(); |
2571 |
+ |
} catch (CompletionException ok) { |
2572 |
+ |
checkCompletedWithWrappedException(h2, ex); |
2573 |
+ |
rs[2].assertNotInvoked(); |
2574 |
+ |
} |
2575 |
+ |
try { |
2576 |
+ |
assertEquals(null, h3.join()); |
2577 |
+ |
rs[3].assertInvoked(); |
2578 |
+ |
} catch (CompletionException ok) { |
2579 |
+ |
checkCompletedWithWrappedException(h3, ex); |
2580 |
+ |
rs[3].assertNotInvoked(); |
2581 |
+ |
} |
2582 |
+ |
|
2583 |
+ |
checkCompletedNormally(f, v1); |
2584 |
+ |
checkCompletedExceptionally(g, ex); |
2585 |
+ |
}} |
2586 |
+ |
|
2587 |
|
/** |
2588 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2589 |
|
*/ |
2611 |
|
checkCompletedWithWrappedCancellationException(h2); |
2612 |
|
checkCompletedWithWrappedCancellationException(h3); |
2613 |
|
|
2614 |
< |
g.complete(v1); |
2614 |
> |
assertTrue(g.complete(v1)); |
2615 |
|
|
2616 |
|
// unspecified behavior - both source completions available |
2617 |
|
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2655 |
|
|
2656 |
|
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2657 |
|
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2658 |
< |
f.complete(v1); |
2658 |
> |
assertTrue(f.complete(v1)); |
2659 |
|
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2660 |
|
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2661 |
|
checkCompletedWithWrappedCFException(h0); |
2663 |
|
checkCompletedWithWrappedCFException(h2); |
2664 |
|
checkCompletedWithWrappedCFException(h3); |
2665 |
|
for (int i = 0; i < 4; i++) rs[i].assertInvoked(); |
2666 |
< |
g.complete(v2); |
2666 |
> |
assertTrue(g.complete(v2)); |
2667 |
|
final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]); |
2668 |
|
final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]); |
2669 |
|
checkCompletedWithWrappedCFException(h4); |
2684 |
|
{ |
2685 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2686 |
|
final CompletableFutureInc r = new CompletableFutureInc(m); |
2687 |
< |
if (!createIncomplete) f.complete(v1); |
2687 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
2688 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2689 |
< |
if (createIncomplete) f.complete(v1); |
2689 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
2690 |
|
|
2691 |
|
checkCompletedNormally(g, inc(v1)); |
2692 |
|
checkCompletedNormally(f, v1); |
2693 |
< |
r.assertInvoked(); |
2693 |
> |
r.assertValue(v1); |
2694 |
|
}} |
2695 |
|
|
2696 |
|
/** |
2708 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2709 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2710 |
|
|
2711 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2712 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2711 |
> |
checkCompletedWithWrappedException(g, ex); |
2712 |
> |
checkCompletedExceptionally(f, ex); |
2713 |
|
r.assertNotInvoked(); |
2714 |
|
}} |
2715 |
|
|
2724 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2725 |
|
final FailingCompletableFutureFunction r |
2726 |
|
= new FailingCompletableFutureFunction(m); |
2727 |
< |
if (!createIncomplete) f.complete(v1); |
2727 |
> |
if (!createIncomplete) assertTrue(f.complete(v1)); |
2728 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2729 |
< |
if (createIncomplete) f.complete(v1); |
2729 |
> |
if (createIncomplete) assertTrue(f.complete(v1)); |
2730 |
|
|
2731 |
|
checkCompletedWithWrappedCFException(g); |
2732 |
|
checkCompletedNormally(f, v1); |
2965 |
|
assertSame(f, f.toCompletableFuture()); |
2966 |
|
} |
2967 |
|
|
2968 |
< |
/** |
2969 |
< |
* whenComplete action executes on normal completion, propagating |
2970 |
< |
* source result. |
2971 |
< |
*/ |
2972 |
< |
public void testWhenComplete_normalCompletion1() { |
2973 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2974 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
2975 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2976 |
< |
{ |
2977 |
< |
final AtomicInteger a = new AtomicInteger(0); |
2978 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2979 |
< |
if (!createIncomplete) f.complete(v1); |
2980 |
< |
final CompletableFuture<Integer> g = m.whenComplete |
2981 |
< |
(f, |
2982 |
< |
(Integer x, Throwable t) -> { |
2983 |
< |
threadAssertSame(x, v1); |
2984 |
< |
threadAssertNull(t); |
2598 |
< |
a.getAndIncrement(); |
2599 |
< |
}); |
2600 |
< |
if (createIncomplete) f.complete(v1); |
2601 |
< |
|
2602 |
< |
checkCompletedNormally(g, v1); |
2603 |
< |
checkCompletedNormally(f, v1); |
2604 |
< |
assertEquals(1, a.get()); |
2605 |
< |
}} |
2606 |
< |
|
2607 |
< |
/** |
2608 |
< |
* whenComplete action executes on exceptional completion, propagating |
2609 |
< |
* source result. |
2610 |
< |
*/ |
2611 |
< |
public void testWhenComplete_exceptionalCompletion() { |
2612 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2613 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
2614 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2615 |
< |
{ |
2616 |
< |
final AtomicInteger a = new AtomicInteger(0); |
2617 |
< |
final CFException ex = new CFException(); |
2618 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2619 |
< |
if (!createIncomplete) f.completeExceptionally(ex); |
2620 |
< |
final CompletableFuture<Integer> g = m.whenComplete |
2621 |
< |
(f, |
2622 |
< |
(Integer x, Throwable t) -> { |
2623 |
< |
threadAssertNull(x); |
2624 |
< |
threadAssertSame(t, ex); |
2625 |
< |
a.getAndIncrement(); |
2626 |
< |
}); |
2627 |
< |
if (createIncomplete) f.completeExceptionally(ex); |
2628 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2629 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2630 |
< |
assertEquals(1, a.get()); |
2631 |
< |
}} |
2632 |
< |
|
2633 |
< |
/** |
2634 |
< |
* whenComplete action executes on cancelled source, propagating |
2635 |
< |
* CancellationException. |
2636 |
< |
*/ |
2637 |
< |
public void testWhenComplete_sourceCancelled() { |
2638 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2639 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2640 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
2641 |
< |
{ |
2642 |
< |
final AtomicInteger a = new AtomicInteger(0); |
2643 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2644 |
< |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2645 |
< |
final CompletableFuture<Integer> g = m.whenComplete |
2646 |
< |
(f, |
2647 |
< |
(Integer x, Throwable t) -> { |
2648 |
< |
threadAssertNull(x); |
2649 |
< |
threadAssertTrue(t instanceof CancellationException); |
2650 |
< |
a.getAndIncrement(); |
2651 |
< |
}); |
2652 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2653 |
< |
|
2654 |
< |
//try { g.join(); } catch (Throwable t) { throw new Error(t); } |
2655 |
< |
checkCompletedWithWrappedCancellationException(g); |
2656 |
< |
checkCancelled(f); |
2657 |
< |
assertEquals(1, a.get()); |
2658 |
< |
}} |
2659 |
< |
|
2660 |
< |
/** |
2661 |
< |
* If a whenComplete action throws an exception when triggered by |
2662 |
< |
* a normal completion, it completes exceptionally |
2663 |
< |
*/ |
2664 |
< |
public void testWhenComplete_actionFailed() { |
2665 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
2666 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2667 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2668 |
< |
{ |
2669 |
< |
final AtomicInteger a = new AtomicInteger(0); |
2670 |
< |
final CFException ex = new CFException(); |
2671 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2672 |
< |
if (!createIncomplete) f.complete(v1); |
2673 |
< |
final CompletableFuture<Integer> g = m.whenComplete |
2674 |
< |
(f, |
2675 |
< |
(Integer x, Throwable t) -> { |
2676 |
< |
threadAssertSame(x, v1); |
2677 |
< |
threadAssertNull(t); |
2678 |
< |
a.getAndIncrement(); |
2679 |
< |
throw ex; |
2680 |
< |
}); |
2681 |
< |
if (createIncomplete) f.complete(v1); |
2682 |
< |
checkCompletedNormally(f, v1); |
2683 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2684 |
< |
assertEquals(1, a.get()); |
2685 |
< |
}} |
2686 |
< |
|
2687 |
< |
/** |
2688 |
< |
* If a whenComplete action throws an exception when triggered by |
2689 |
< |
* a source completion that also throws an exception, the source |
2690 |
< |
* exception takes precedence. |
2691 |
< |
*/ |
2692 |
< |
public void testWhenComplete_actionFailedSourceFailed() { |
2693 |
< |
for (boolean createIncomplete : new boolean[] { true, false }) |
2694 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2695 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2696 |
< |
{ |
2697 |
< |
final AtomicInteger a = new AtomicInteger(0); |
2698 |
< |
final CFException ex1 = new CFException(); |
2699 |
< |
final CFException ex2 = new CFException(); |
2700 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2701 |
< |
|
2702 |
< |
if (!createIncomplete) f.completeExceptionally(ex1); |
2703 |
< |
final CompletableFuture<Integer> g = m.whenComplete |
2704 |
< |
(f, |
2705 |
< |
(Integer x, Throwable t) -> { |
2706 |
< |
threadAssertSame(t, ex1); |
2707 |
< |
threadAssertNull(x); |
2708 |
< |
a.getAndIncrement(); |
2709 |
< |
throw ex2; |
2710 |
< |
}); |
2711 |
< |
if (createIncomplete) f.completeExceptionally(ex1); |
2712 |
< |
|
2713 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
2714 |
< |
checkCompletedWithWrappedCFException(g, ex1); |
2715 |
< |
assertEquals(1, a.get()); |
2716 |
< |
}} |
2968 |
> |
// public void testRunAfterEither_resultDeterminedAtTimeOfCreation() { |
2969 |
> |
// for (ExecutionMode m : ExecutionMode.values()) |
2970 |
> |
// for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2971 |
> |
// for (Integer v1 : new Integer[] { 1, null }) |
2972 |
> |
// { |
2973 |
> |
// final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2974 |
> |
// final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2975 |
> |
// final Noop[] rs = new Noop[2]; |
2976 |
> |
// for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2977 |
> |
// f.complete(v1); |
2978 |
> |
// final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2979 |
> |
// final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2980 |
> |
// assertTrue(g.cancel(mayInterruptIfRunning)); |
2981 |
> |
// checkCompletedNormally(h0, null); |
2982 |
> |
// checkCompletedNormally(h1, null); |
2983 |
> |
// for (Noop r : rs) r.assertInvoked(); |
2984 |
> |
// }} |
2985 |
|
|
2986 |
|
} |