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); |
239 |
|
*/ |
240 |
|
public void testCompleteExceptionally() { |
241 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
242 |
+ |
CFException ex = new CFException(); |
243 |
|
checkIncomplete(f); |
244 |
< |
f.completeExceptionally(new CFException()); |
245 |
< |
checkCompletedWithWrappedCFException(f); |
244 |
> |
f.completeExceptionally(ex); |
245 |
> |
checkCompletedExceptionally(f, ex); |
246 |
|
} |
247 |
|
|
248 |
|
/** |
283 |
|
* obtrudeException forces completion with given exception |
284 |
|
*/ |
285 |
|
public void testObtrudeException() { |
286 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
287 |
< |
checkIncomplete(f); |
288 |
< |
f.complete(one); |
289 |
< |
checkCompletedNormally(f, one); |
290 |
< |
f.obtrudeException(new CFException()); |
269 |
< |
checkCompletedWithWrappedCFException(f); |
286 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
287 |
> |
{ |
288 |
> |
CFException ex; |
289 |
> |
CompletableFuture<Integer> f; |
290 |
> |
|
291 |
|
f = new CompletableFuture<>(); |
292 |
< |
f.obtrudeException(new CFException()); |
293 |
< |
checkCompletedWithWrappedCFException(f); |
292 |
> |
f.complete(v1); |
293 |
> |
for (int i = 0; i < 2; i++) { |
294 |
> |
f.obtrudeException(ex = new CFException()); |
295 |
> |
checkCompletedExceptionally(f, ex); |
296 |
> |
} |
297 |
> |
|
298 |
> |
f = new CompletableFuture<>(); |
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 |
+ |
f.completeExceptionally(ex = new CFException()); |
306 |
+ |
f.obtrudeValue(v1); |
307 |
+ |
checkCompletedNormally(f, v1); |
308 |
+ |
f.obtrudeException(ex = new CFException()); |
309 |
+ |
checkCompletedExceptionally(f, ex); |
310 |
|
f.completeExceptionally(new CFException()); |
311 |
< |
f.obtrudeValue(four); |
312 |
< |
checkCompletedNormally(f, four); |
313 |
< |
f.obtrudeException(new CFException()); |
314 |
< |
checkCompletedWithWrappedCFException(f); |
279 |
< |
} |
311 |
> |
checkCompletedExceptionally(f, ex); |
312 |
> |
f.complete(v1); |
313 |
> |
checkCompletedExceptionally(f, ex); |
314 |
> |
}} |
315 |
|
|
316 |
|
/** |
317 |
|
* getNumberOfDependents returns number of dependent tasks |
345 |
|
f = new CompletableFuture<String>(); |
346 |
|
f.completeExceptionally(new IndexOutOfBoundsException()); |
347 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
348 |
+ |
|
349 |
+ |
f = new CompletableFuture<String>(); |
350 |
+ |
f.cancel(true); |
351 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
352 |
+ |
|
353 |
+ |
f = new CompletableFuture<String>(); |
354 |
+ |
f.cancel(false); |
355 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
356 |
|
} |
357 |
|
|
358 |
|
/** |
851 |
|
assertEquals(0, a.get()); |
852 |
|
}} |
853 |
|
|
811 |
– |
|
854 |
|
/** |
855 |
|
* exceptionally action completes with function value on source |
856 |
|
* exception |
894 |
|
}); |
895 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
896 |
|
|
897 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
897 |
> |
checkCompletedWithWrappedException(g, ex2); |
898 |
> |
assertEquals(1, a.get()); |
899 |
> |
}} |
900 |
> |
|
901 |
> |
/** |
902 |
> |
* whenComplete action executes on normal completion, propagating |
903 |
> |
* source result. |
904 |
> |
*/ |
905 |
> |
public void testWhenComplete_normalCompletion1() { |
906 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
907 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
908 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
909 |
> |
{ |
910 |
> |
final AtomicInteger a = new AtomicInteger(0); |
911 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
912 |
> |
if (!createIncomplete) f.complete(v1); |
913 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
914 |
> |
(f, |
915 |
> |
(Integer x, Throwable t) -> { |
916 |
> |
m.checkExecutionMode(); |
917 |
> |
threadAssertSame(x, v1); |
918 |
> |
threadAssertNull(t); |
919 |
> |
a.getAndIncrement(); |
920 |
> |
}); |
921 |
> |
if (createIncomplete) f.complete(v1); |
922 |
> |
|
923 |
> |
checkCompletedNormally(g, v1); |
924 |
> |
checkCompletedNormally(f, v1); |
925 |
> |
assertEquals(1, a.get()); |
926 |
> |
}} |
927 |
> |
|
928 |
> |
/** |
929 |
> |
* whenComplete action executes on exceptional completion, propagating |
930 |
> |
* source result. |
931 |
> |
*/ |
932 |
> |
public void testWhenComplete_exceptionalCompletion() { |
933 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
934 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
935 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
936 |
> |
{ |
937 |
> |
final AtomicInteger a = new AtomicInteger(0); |
938 |
> |
final CFException ex = new CFException(); |
939 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
940 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
941 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
942 |
> |
(f, |
943 |
> |
(Integer x, Throwable t) -> { |
944 |
> |
m.checkExecutionMode(); |
945 |
> |
threadAssertNull(x); |
946 |
> |
threadAssertSame(t, ex); |
947 |
> |
a.getAndIncrement(); |
948 |
> |
}); |
949 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
950 |
> |
|
951 |
> |
checkCompletedWithWrappedException(g, ex); |
952 |
> |
checkCompletedExceptionally(f, ex); |
953 |
> |
assertEquals(1, a.get()); |
954 |
> |
}} |
955 |
> |
|
956 |
> |
/** |
957 |
> |
* whenComplete action executes on cancelled source, propagating |
958 |
> |
* CancellationException. |
959 |
> |
*/ |
960 |
> |
public void testWhenComplete_sourceCancelled() { |
961 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
962 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
963 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
964 |
> |
{ |
965 |
> |
final AtomicInteger a = new AtomicInteger(0); |
966 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
967 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
968 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
969 |
> |
(f, |
970 |
> |
(Integer x, Throwable t) -> { |
971 |
> |
m.checkExecutionMode(); |
972 |
> |
threadAssertNull(x); |
973 |
> |
threadAssertTrue(t instanceof CancellationException); |
974 |
> |
a.getAndIncrement(); |
975 |
> |
}); |
976 |
> |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
977 |
> |
|
978 |
> |
checkCompletedWithWrappedCancellationException(g); |
979 |
> |
checkCancelled(f); |
980 |
> |
assertEquals(1, a.get()); |
981 |
> |
}} |
982 |
> |
|
983 |
> |
/** |
984 |
> |
* If a whenComplete action throws an exception when triggered by |
985 |
> |
* a normal completion, it completes exceptionally |
986 |
> |
*/ |
987 |
> |
public void testWhenComplete_actionFailed() { |
988 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
989 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
990 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
991 |
> |
{ |
992 |
> |
final AtomicInteger a = new AtomicInteger(0); |
993 |
> |
final CFException ex = new CFException(); |
994 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
995 |
> |
if (!createIncomplete) f.complete(v1); |
996 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
997 |
> |
(f, |
998 |
> |
(Integer x, Throwable t) -> { |
999 |
> |
m.checkExecutionMode(); |
1000 |
> |
threadAssertSame(x, v1); |
1001 |
> |
threadAssertNull(t); |
1002 |
> |
a.getAndIncrement(); |
1003 |
> |
throw ex; |
1004 |
> |
}); |
1005 |
> |
if (createIncomplete) f.complete(v1); |
1006 |
> |
|
1007 |
> |
checkCompletedWithWrappedException(g, ex); |
1008 |
> |
checkCompletedNormally(f, v1); |
1009 |
> |
assertEquals(1, a.get()); |
1010 |
> |
}} |
1011 |
> |
|
1012 |
> |
/** |
1013 |
> |
* If a whenComplete action throws an exception when triggered by |
1014 |
> |
* a source completion that also throws an exception, the source |
1015 |
> |
* exception takes precedence. |
1016 |
> |
*/ |
1017 |
> |
public void testWhenComplete_actionFailedSourceFailed() { |
1018 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1019 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1020 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1021 |
> |
{ |
1022 |
> |
final AtomicInteger a = new AtomicInteger(0); |
1023 |
> |
final CFException ex1 = new CFException(); |
1024 |
> |
final CFException ex2 = new CFException(); |
1025 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1026 |
> |
|
1027 |
> |
if (!createIncomplete) f.completeExceptionally(ex1); |
1028 |
> |
final CompletableFuture<Integer> g = m.whenComplete |
1029 |
> |
(f, |
1030 |
> |
(Integer x, Throwable t) -> { |
1031 |
> |
m.checkExecutionMode(); |
1032 |
> |
threadAssertSame(t, ex1); |
1033 |
> |
threadAssertNull(x); |
1034 |
> |
a.getAndIncrement(); |
1035 |
> |
throw ex2; |
1036 |
> |
}); |
1037 |
> |
if (createIncomplete) f.completeExceptionally(ex1); |
1038 |
> |
|
1039 |
> |
checkCompletedWithWrappedException(g, ex1); |
1040 |
> |
checkCompletedExceptionally(f, ex1); |
1041 |
|
assertEquals(1, a.get()); |
1042 |
|
}} |
1043 |
|
|
1094 |
|
if (createIncomplete) f.completeExceptionally(ex); |
1095 |
|
|
1096 |
|
checkCompletedNormally(g, v1); |
1097 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1097 |
> |
checkCompletedExceptionally(f, ex); |
1098 |
|
assertEquals(1, a.get()); |
1099 |
|
}} |
1100 |
|
|
1150 |
|
}); |
1151 |
|
if (createIncomplete) f.completeExceptionally(ex1); |
1152 |
|
|
1153 |
< |
checkCompletedWithWrappedCFException(g, ex2); |
1154 |
< |
checkCompletedWithWrappedCFException(f, ex1); |
1153 |
> |
checkCompletedWithWrappedException(g, ex2); |
1154 |
> |
checkCompletedExceptionally(f, ex1); |
1155 |
|
assertEquals(1, a.get()); |
1156 |
|
}} |
1157 |
|
|
1175 |
|
}); |
1176 |
|
if (createIncomplete) f.complete(v1); |
1177 |
|
|
1178 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1178 |
> |
checkCompletedWithWrappedException(g, ex); |
1179 |
|
checkCompletedNormally(f, v1); |
1180 |
|
assertEquals(1, a.get()); |
1181 |
|
}} |
1289 |
|
f.completeExceptionally(ex); |
1290 |
|
} |
1291 |
|
|
1292 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1293 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1292 |
> |
checkCompletedWithWrappedException(g, ex); |
1293 |
> |
checkCompletedExceptionally(f, ex); |
1294 |
|
r.assertNotInvoked(); |
1295 |
|
}} |
1296 |
|
|
1356 |
|
|
1357 |
|
checkCompletedNormally(g, inc(v1)); |
1358 |
|
checkCompletedNormally(f, v1); |
1359 |
< |
r.assertInvoked(); |
1359 |
> |
r.assertValue(inc(v1)); |
1360 |
|
}} |
1361 |
|
|
1362 |
|
/** |
1377 |
|
f.completeExceptionally(ex); |
1378 |
|
} |
1379 |
|
|
1380 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1381 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1380 |
> |
checkCompletedWithWrappedException(g, ex); |
1381 |
> |
checkCompletedExceptionally(f, ex); |
1382 |
|
r.assertNotInvoked(); |
1383 |
|
}} |
1384 |
|
|
1465 |
|
f.completeExceptionally(ex); |
1466 |
|
} |
1467 |
|
|
1468 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1469 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1468 |
> |
checkCompletedWithWrappedException(g, ex); |
1469 |
> |
checkCompletedExceptionally(f, ex); |
1470 |
|
r.assertNotInvoked(); |
1471 |
|
}} |
1472 |
|
|
1541 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1542 |
|
checkCompletedNormally(f, v1); |
1543 |
|
checkCompletedNormally(g, v2); |
1544 |
< |
r.assertInvoked(); |
1544 |
> |
r.assertValue(subtract(v1, v2)); |
1545 |
|
}} |
1546 |
|
|
1547 |
|
/** |
1568 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1569 |
|
} |
1570 |
|
|
1571 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1571 |
> |
checkCompletedWithWrappedException(h, ex); |
1572 |
|
r.assertNotInvoked(); |
1573 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1574 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1574 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1575 |
|
}} |
1576 |
|
|
1577 |
|
/** |
1685 |
|
(!fFirst ? f : g).completeExceptionally(ex); |
1686 |
|
} |
1687 |
|
|
1688 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1688 |
> |
checkCompletedWithWrappedException(h, ex); |
1689 |
|
r.assertNotInvoked(); |
1690 |
|
checkCompletedNormally(fFirst ? f : g, v1); |
1691 |
< |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1691 |
> |
checkCompletedExceptionally(!fFirst ? f : g, ex); |
1692 |
|
}} |
1693 |
|
|
1694 |
|
/** |
1802 |
|
(!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 |
|
|
1640 |
– |
|
1825 |
|
(fFirst ? f : g).complete(v1); |
1826 |
|
if (!createIncomplete) |
1827 |
|
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1936 |
|
rs[0].assertNotInvoked(); |
1937 |
|
rs[1].assertNotInvoked(); |
1938 |
|
f.completeExceptionally(ex); |
1939 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1940 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1939 |
> |
checkCompletedWithWrappedException(h0, ex); |
1940 |
> |
checkCompletedWithWrappedException(h1, ex); |
1941 |
|
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1942 |
|
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1943 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1944 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1943 |
> |
checkCompletedWithWrappedException(h2, ex); |
1944 |
> |
checkCompletedWithWrappedException(h3, ex); |
1945 |
|
g.complete(v1); |
1946 |
|
|
1947 |
|
// unspecified behavior - both source completions available |
1951 |
|
assertEquals(inc(v1), h4.join()); |
1952 |
|
rs[4].assertValue(inc(v1)); |
1953 |
|
} catch (CompletionException ok) { |
1954 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1954 |
> |
checkCompletedWithWrappedException(h4, ex); |
1955 |
|
rs[4].assertNotInvoked(); |
1956 |
|
} |
1957 |
|
try { |
1958 |
|
assertEquals(inc(v1), h5.join()); |
1959 |
|
rs[5].assertValue(inc(v1)); |
1960 |
|
} catch (CompletionException ok) { |
1961 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
1961 |
> |
checkCompletedWithWrappedException(h5, ex); |
1962 |
|
rs[5].assertNotInvoked(); |
1963 |
|
} |
1964 |
|
|
1965 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1965 |
> |
checkCompletedExceptionally(f, ex); |
1966 |
|
checkCompletedNormally(g, v1); |
1967 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
1968 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
1969 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
1970 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
1971 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
1967 |
> |
checkCompletedWithWrappedException(h0, ex); |
1968 |
> |
checkCompletedWithWrappedException(h1, ex); |
1969 |
> |
checkCompletedWithWrappedException(h2, ex); |
1970 |
> |
checkCompletedWithWrappedException(h3, ex); |
1971 |
> |
checkCompletedWithWrappedException(h4, ex); |
1972 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1973 |
|
}} |
1974 |
|
|
2000 |
|
assertEquals(inc(v1), h0.join()); |
2001 |
|
rs[0].assertValue(inc(v1)); |
2002 |
|
} catch (CompletionException ok) { |
2003 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2003 |
> |
checkCompletedWithWrappedException(h0, ex); |
2004 |
|
rs[0].assertNotInvoked(); |
2005 |
|
} |
2006 |
|
try { |
2007 |
|
assertEquals(inc(v1), h1.join()); |
2008 |
|
rs[1].assertValue(inc(v1)); |
2009 |
|
} catch (CompletionException ok) { |
2010 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2010 |
> |
checkCompletedWithWrappedException(h1, ex); |
2011 |
|
rs[1].assertNotInvoked(); |
2012 |
|
} |
2013 |
|
try { |
2014 |
|
assertEquals(inc(v1), h2.join()); |
2015 |
|
rs[2].assertValue(inc(v1)); |
2016 |
|
} catch (CompletionException ok) { |
2017 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2017 |
> |
checkCompletedWithWrappedException(h2, ex); |
2018 |
|
rs[2].assertNotInvoked(); |
2019 |
|
} |
2020 |
|
try { |
2021 |
|
assertEquals(inc(v1), h3.join()); |
2022 |
|
rs[3].assertValue(inc(v1)); |
2023 |
|
} catch (CompletionException ok) { |
2024 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2024 |
> |
checkCompletedWithWrappedException(h3, ex); |
2025 |
|
rs[3].assertNotInvoked(); |
2026 |
|
} |
2027 |
|
|
2028 |
|
checkCompletedNormally(f, v1); |
2029 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2029 |
> |
checkCompletedExceptionally(g, ex); |
2030 |
|
}} |
2031 |
|
|
2032 |
|
/** |
2084 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2085 |
|
}} |
2086 |
|
|
2087 |
+ |
public void testApplyToEither_sourceCancelled2() { |
2088 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2089 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2090 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2091 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2092 |
+ |
{ |
2093 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2094 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2095 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
2096 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
2097 |
+ |
|
2098 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
2099 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
2100 |
+ |
if (fFirst) { |
2101 |
+ |
f.complete(v1); |
2102 |
+ |
g.cancel(mayInterruptIfRunning); |
2103 |
+ |
} else { |
2104 |
+ |
g.cancel(mayInterruptIfRunning); |
2105 |
+ |
f.complete(v1); |
2106 |
+ |
} |
2107 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
2108 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
2109 |
+ |
|
2110 |
+ |
// unspecified behavior - both source completions available |
2111 |
+ |
try { |
2112 |
+ |
assertEquals(inc(v1), h0.join()); |
2113 |
+ |
rs[0].assertValue(inc(v1)); |
2114 |
+ |
} catch (CompletionException ok) { |
2115 |
+ |
checkCompletedWithWrappedCancellationException(h0); |
2116 |
+ |
rs[0].assertNotInvoked(); |
2117 |
+ |
} |
2118 |
+ |
try { |
2119 |
+ |
assertEquals(inc(v1), h1.join()); |
2120 |
+ |
rs[1].assertValue(inc(v1)); |
2121 |
+ |
} catch (CompletionException ok) { |
2122 |
+ |
checkCompletedWithWrappedCancellationException(h1); |
2123 |
+ |
rs[1].assertNotInvoked(); |
2124 |
+ |
} |
2125 |
+ |
try { |
2126 |
+ |
assertEquals(inc(v1), h2.join()); |
2127 |
+ |
rs[2].assertValue(inc(v1)); |
2128 |
+ |
} catch (CompletionException ok) { |
2129 |
+ |
checkCompletedWithWrappedCancellationException(h2); |
2130 |
+ |
rs[2].assertNotInvoked(); |
2131 |
+ |
} |
2132 |
+ |
try { |
2133 |
+ |
assertEquals(inc(v1), h3.join()); |
2134 |
+ |
rs[3].assertValue(inc(v1)); |
2135 |
+ |
} catch (CompletionException ok) { |
2136 |
+ |
checkCompletedWithWrappedCancellationException(h3); |
2137 |
+ |
rs[3].assertNotInvoked(); |
2138 |
+ |
} |
2139 |
+ |
|
2140 |
+ |
checkCompletedNormally(f, v1); |
2141 |
+ |
checkCancelled(g); |
2142 |
+ |
}} |
2143 |
+ |
|
2144 |
|
/** |
2145 |
|
* applyToEither result completes exceptionally if action does |
2146 |
|
*/ |
2255 |
|
rs[0].assertNotInvoked(); |
2256 |
|
rs[1].assertNotInvoked(); |
2257 |
|
f.completeExceptionally(ex); |
2258 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2259 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2258 |
> |
checkCompletedWithWrappedException(h0, ex); |
2259 |
> |
checkCompletedWithWrappedException(h1, ex); |
2260 |
|
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2261 |
|
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2262 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2263 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2262 |
> |
checkCompletedWithWrappedException(h2, ex); |
2263 |
> |
checkCompletedWithWrappedException(h3, ex); |
2264 |
|
|
2265 |
|
g.complete(v1); |
2266 |
|
|
2271 |
|
assertNull(h4.join()); |
2272 |
|
rs[4].assertValue(v1); |
2273 |
|
} catch (CompletionException ok) { |
2274 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2274 |
> |
checkCompletedWithWrappedException(h4, ex); |
2275 |
|
rs[4].assertNotInvoked(); |
2276 |
|
} |
2277 |
|
try { |
2278 |
|
assertNull(h5.join()); |
2279 |
|
rs[5].assertValue(v1); |
2280 |
|
} catch (CompletionException ok) { |
2281 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
2281 |
> |
checkCompletedWithWrappedException(h5, ex); |
2282 |
|
rs[5].assertNotInvoked(); |
2283 |
|
} |
2284 |
|
|
2285 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2285 |
> |
checkCompletedExceptionally(f, ex); |
2286 |
|
checkCompletedNormally(g, v1); |
2287 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2288 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2289 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2290 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2291 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2287 |
> |
checkCompletedWithWrappedException(h0, ex); |
2288 |
> |
checkCompletedWithWrappedException(h1, ex); |
2289 |
> |
checkCompletedWithWrappedException(h2, ex); |
2290 |
> |
checkCompletedWithWrappedException(h3, ex); |
2291 |
> |
checkCompletedWithWrappedException(h4, ex); |
2292 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2293 |
|
}} |
2294 |
|
|
2295 |
+ |
public void testAcceptEither_exceptionalCompletion2() { |
2296 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2297 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2298 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2299 |
+ |
{ |
2300 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2301 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2302 |
+ |
final CFException ex = new CFException(); |
2303 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2304 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2305 |
+ |
|
2306 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2307 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2308 |
+ |
if (fFirst) { |
2309 |
+ |
f.complete(v1); |
2310 |
+ |
g.completeExceptionally(ex); |
2311 |
+ |
} else { |
2312 |
+ |
g.completeExceptionally(ex); |
2313 |
+ |
f.complete(v1); |
2314 |
+ |
} |
2315 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2316 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2317 |
+ |
|
2318 |
+ |
// unspecified behavior - both source completions available |
2319 |
+ |
try { |
2320 |
+ |
assertEquals(null, h0.join()); |
2321 |
+ |
rs[0].assertValue(v1); |
2322 |
+ |
} catch (CompletionException ok) { |
2323 |
+ |
checkCompletedWithWrappedException(h0, ex); |
2324 |
+ |
rs[0].assertNotInvoked(); |
2325 |
+ |
} |
2326 |
+ |
try { |
2327 |
+ |
assertEquals(null, h1.join()); |
2328 |
+ |
rs[1].assertValue(v1); |
2329 |
+ |
} catch (CompletionException ok) { |
2330 |
+ |
checkCompletedWithWrappedException(h1, ex); |
2331 |
+ |
rs[1].assertNotInvoked(); |
2332 |
+ |
} |
2333 |
+ |
try { |
2334 |
+ |
assertEquals(null, h2.join()); |
2335 |
+ |
rs[2].assertValue(v1); |
2336 |
+ |
} catch (CompletionException ok) { |
2337 |
+ |
checkCompletedWithWrappedException(h2, ex); |
2338 |
+ |
rs[2].assertNotInvoked(); |
2339 |
+ |
} |
2340 |
+ |
try { |
2341 |
+ |
assertEquals(null, h3.join()); |
2342 |
+ |
rs[3].assertValue(v1); |
2343 |
+ |
} catch (CompletionException ok) { |
2344 |
+ |
checkCompletedWithWrappedException(h3, ex); |
2345 |
+ |
rs[3].assertNotInvoked(); |
2346 |
+ |
} |
2347 |
+ |
|
2348 |
+ |
checkCompletedNormally(f, v1); |
2349 |
+ |
checkCompletedExceptionally(g, ex); |
2350 |
+ |
}} |
2351 |
+ |
|
2352 |
|
/** |
2353 |
|
* acceptEither result completes exceptionally if either source cancelled |
2354 |
|
*/ |
2515 |
|
rs[0].assertNotInvoked(); |
2516 |
|
rs[1].assertNotInvoked(); |
2517 |
|
f.completeExceptionally(ex); |
2518 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2519 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2518 |
> |
checkCompletedWithWrappedException(h0, ex); |
2519 |
> |
checkCompletedWithWrappedException(h1, ex); |
2520 |
|
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2521 |
|
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2522 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2523 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2522 |
> |
checkCompletedWithWrappedException(h2, ex); |
2523 |
> |
checkCompletedWithWrappedException(h3, ex); |
2524 |
|
|
2525 |
|
g.complete(v1); |
2526 |
|
|
2531 |
|
assertNull(h4.join()); |
2532 |
|
rs[4].assertInvoked(); |
2533 |
|
} catch (CompletionException ok) { |
2534 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2534 |
> |
checkCompletedWithWrappedException(h4, ex); |
2535 |
|
rs[4].assertNotInvoked(); |
2536 |
|
} |
2537 |
|
try { |
2538 |
|
assertNull(h5.join()); |
2539 |
|
rs[5].assertInvoked(); |
2540 |
|
} catch (CompletionException ok) { |
2541 |
< |
checkCompletedWithWrappedCFException(h5, ex); |
2541 |
> |
checkCompletedWithWrappedException(h5, ex); |
2542 |
|
rs[5].assertNotInvoked(); |
2543 |
|
} |
2544 |
|
|
2545 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2545 |
> |
checkCompletedExceptionally(f, ex); |
2546 |
|
checkCompletedNormally(g, v1); |
2547 |
< |
checkCompletedWithWrappedCFException(h0, ex); |
2548 |
< |
checkCompletedWithWrappedCFException(h1, ex); |
2549 |
< |
checkCompletedWithWrappedCFException(h2, ex); |
2550 |
< |
checkCompletedWithWrappedCFException(h3, ex); |
2551 |
< |
checkCompletedWithWrappedCFException(h4, ex); |
2547 |
> |
checkCompletedWithWrappedException(h0, ex); |
2548 |
> |
checkCompletedWithWrappedException(h1, ex); |
2549 |
> |
checkCompletedWithWrappedException(h2, ex); |
2550 |
> |
checkCompletedWithWrappedException(h3, ex); |
2551 |
> |
checkCompletedWithWrappedException(h4, ex); |
2552 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2553 |
|
}} |
2554 |
|
|
2555 |
+ |
public void testRunAfterEither_exceptionalCompletion2() { |
2556 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2557 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2558 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2559 |
+ |
{ |
2560 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2561 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2562 |
+ |
final CFException ex = new CFException(); |
2563 |
+ |
final Noop[] rs = new Noop[6]; |
2564 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2565 |
+ |
|
2566 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2567 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2568 |
+ |
if (fFirst) { |
2569 |
+ |
f.complete(v1); |
2570 |
+ |
g.completeExceptionally(ex); |
2571 |
+ |
} else { |
2572 |
+ |
g.completeExceptionally(ex); |
2573 |
+ |
f.complete(v1); |
2574 |
+ |
} |
2575 |
+ |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2576 |
+ |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2577 |
+ |
|
2578 |
+ |
// unspecified behavior - both source completions available |
2579 |
+ |
try { |
2580 |
+ |
assertEquals(null, h0.join()); |
2581 |
+ |
rs[0].assertInvoked(); |
2582 |
+ |
} catch (CompletionException ok) { |
2583 |
+ |
checkCompletedWithWrappedException(h0, ex); |
2584 |
+ |
rs[0].assertNotInvoked(); |
2585 |
+ |
} |
2586 |
+ |
try { |
2587 |
+ |
assertEquals(null, h1.join()); |
2588 |
+ |
rs[1].assertInvoked(); |
2589 |
+ |
} catch (CompletionException ok) { |
2590 |
+ |
checkCompletedWithWrappedException(h1, ex); |
2591 |
+ |
rs[1].assertNotInvoked(); |
2592 |
+ |
} |
2593 |
+ |
try { |
2594 |
+ |
assertEquals(null, h2.join()); |
2595 |
+ |
rs[2].assertInvoked(); |
2596 |
+ |
} catch (CompletionException ok) { |
2597 |
+ |
checkCompletedWithWrappedException(h2, ex); |
2598 |
+ |
rs[2].assertNotInvoked(); |
2599 |
+ |
} |
2600 |
+ |
try { |
2601 |
+ |
assertEquals(null, h3.join()); |
2602 |
+ |
rs[3].assertInvoked(); |
2603 |
+ |
} catch (CompletionException ok) { |
2604 |
+ |
checkCompletedWithWrappedException(h3, ex); |
2605 |
+ |
rs[3].assertNotInvoked(); |
2606 |
+ |
} |
2607 |
+ |
|
2608 |
+ |
checkCompletedNormally(f, v1); |
2609 |
+ |
checkCompletedExceptionally(g, ex); |
2610 |
+ |
}} |
2611 |
+ |
|
2612 |
|
/** |
2613 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2614 |
|
*/ |
2715 |
|
|
2716 |
|
checkCompletedNormally(g, inc(v1)); |
2717 |
|
checkCompletedNormally(f, v1); |
2718 |
< |
r.assertInvoked(); |
2718 |
> |
r.assertValue(v1); |
2719 |
|
}} |
2720 |
|
|
2721 |
|
/** |
2733 |
|
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2734 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2735 |
|
|
2736 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2737 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2736 |
> |
checkCompletedWithWrappedException(g, ex); |
2737 |
> |
checkCompletedExceptionally(f, ex); |
2738 |
|
r.assertNotInvoked(); |
2739 |
|
}} |
2740 |
|
|
2990 |
|
assertSame(f, f.toCompletableFuture()); |
2991 |
|
} |
2992 |
|
|
2638 |
– |
/** |
2639 |
– |
* whenComplete action executes on normal completion, propagating |
2640 |
– |
* source result. |
2641 |
– |
*/ |
2642 |
– |
public void testWhenComplete_normalCompletion1() { |
2643 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2644 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
2645 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2646 |
– |
{ |
2647 |
– |
final AtomicInteger a = new AtomicInteger(0); |
2648 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2649 |
– |
if (!createIncomplete) f.complete(v1); |
2650 |
– |
final CompletableFuture<Integer> g = m.whenComplete |
2651 |
– |
(f, |
2652 |
– |
(Integer x, Throwable t) -> { |
2653 |
– |
threadAssertSame(x, v1); |
2654 |
– |
threadAssertNull(t); |
2655 |
– |
a.getAndIncrement(); |
2656 |
– |
}); |
2657 |
– |
if (createIncomplete) f.complete(v1); |
2658 |
– |
|
2659 |
– |
checkCompletedNormally(g, v1); |
2660 |
– |
checkCompletedNormally(f, v1); |
2661 |
– |
assertEquals(1, a.get()); |
2662 |
– |
}} |
2663 |
– |
|
2664 |
– |
/** |
2665 |
– |
* whenComplete action executes on exceptional completion, propagating |
2666 |
– |
* source result. |
2667 |
– |
*/ |
2668 |
– |
public void testWhenComplete_exceptionalCompletion() { |
2669 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2670 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
2671 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2672 |
– |
{ |
2673 |
– |
final AtomicInteger a = new AtomicInteger(0); |
2674 |
– |
final CFException ex = new CFException(); |
2675 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2676 |
– |
if (!createIncomplete) f.completeExceptionally(ex); |
2677 |
– |
final CompletableFuture<Integer> g = m.whenComplete |
2678 |
– |
(f, |
2679 |
– |
(Integer x, Throwable t) -> { |
2680 |
– |
threadAssertNull(x); |
2681 |
– |
threadAssertSame(t, ex); |
2682 |
– |
a.getAndIncrement(); |
2683 |
– |
}); |
2684 |
– |
if (createIncomplete) f.completeExceptionally(ex); |
2685 |
– |
checkCompletedWithWrappedCFException(f, ex); |
2686 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2687 |
– |
assertEquals(1, a.get()); |
2688 |
– |
}} |
2689 |
– |
|
2690 |
– |
/** |
2691 |
– |
* whenComplete action executes on cancelled source, propagating |
2692 |
– |
* CancellationException. |
2693 |
– |
*/ |
2694 |
– |
public void testWhenComplete_sourceCancelled() { |
2695 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2696 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2697 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
2698 |
– |
{ |
2699 |
– |
final AtomicInteger a = new AtomicInteger(0); |
2700 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2701 |
– |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2702 |
– |
final CompletableFuture<Integer> g = m.whenComplete |
2703 |
– |
(f, |
2704 |
– |
(Integer x, Throwable t) -> { |
2705 |
– |
threadAssertNull(x); |
2706 |
– |
threadAssertTrue(t instanceof CancellationException); |
2707 |
– |
a.getAndIncrement(); |
2708 |
– |
}); |
2709 |
– |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2710 |
– |
|
2711 |
– |
//try { g.join(); } catch (Throwable t) { throw new Error(t); } |
2712 |
– |
checkCompletedWithWrappedCancellationException(g); |
2713 |
– |
checkCancelled(f); |
2714 |
– |
assertEquals(1, a.get()); |
2715 |
– |
}} |
2716 |
– |
|
2717 |
– |
/** |
2718 |
– |
* If a whenComplete action throws an exception when triggered by |
2719 |
– |
* a normal completion, it completes exceptionally |
2720 |
– |
*/ |
2721 |
– |
public void testWhenComplete_actionFailed() { |
2722 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
2723 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2724 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2725 |
– |
{ |
2726 |
– |
final AtomicInteger a = new AtomicInteger(0); |
2727 |
– |
final CFException ex = new CFException(); |
2728 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2729 |
– |
if (!createIncomplete) f.complete(v1); |
2730 |
– |
final CompletableFuture<Integer> g = m.whenComplete |
2731 |
– |
(f, |
2732 |
– |
(Integer x, Throwable t) -> { |
2733 |
– |
threadAssertSame(x, v1); |
2734 |
– |
threadAssertNull(t); |
2735 |
– |
a.getAndIncrement(); |
2736 |
– |
throw ex; |
2737 |
– |
}); |
2738 |
– |
if (createIncomplete) f.complete(v1); |
2739 |
– |
checkCompletedNormally(f, v1); |
2740 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2741 |
– |
assertEquals(1, a.get()); |
2742 |
– |
}} |
2743 |
– |
|
2744 |
– |
/** |
2745 |
– |
* If a whenComplete action throws an exception when triggered by |
2746 |
– |
* a source completion that also throws an exception, the source |
2747 |
– |
* exception takes precedence. |
2748 |
– |
*/ |
2749 |
– |
public void testWhenComplete_actionFailedSourceFailed() { |
2750 |
– |
for (boolean createIncomplete : new boolean[] { true, false }) |
2751 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2752 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2753 |
– |
{ |
2754 |
– |
final AtomicInteger a = new AtomicInteger(0); |
2755 |
– |
final CFException ex1 = new CFException(); |
2756 |
– |
final CFException ex2 = new CFException(); |
2757 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2758 |
– |
|
2759 |
– |
if (!createIncomplete) f.completeExceptionally(ex1); |
2760 |
– |
final CompletableFuture<Integer> g = m.whenComplete |
2761 |
– |
(f, |
2762 |
– |
(Integer x, Throwable t) -> { |
2763 |
– |
threadAssertSame(t, ex1); |
2764 |
– |
threadAssertNull(x); |
2765 |
– |
a.getAndIncrement(); |
2766 |
– |
throw ex2; |
2767 |
– |
}); |
2768 |
– |
if (createIncomplete) f.completeExceptionally(ex1); |
2769 |
– |
|
2770 |
– |
checkCompletedWithWrappedCFException(f, ex1); |
2771 |
– |
checkCompletedWithWrappedCFException(g, ex1); |
2772 |
– |
assertEquals(1, a.get()); |
2773 |
– |
}} |
2774 |
– |
|
2993 |
|
} |