1171 |
|
|
1172 |
|
checkCompletedNormally(g, inc(v1)); |
1173 |
|
checkCompletedNormally(f, v1); |
1174 |
< |
r.assertInvoked(); |
1174 |
> |
r.assertValue(inc(v1)); |
1175 |
|
}} |
1176 |
|
|
1177 |
|
/** |
1356 |
|
checkCompletedNormally(h, subtract(v1, v2)); |
1357 |
|
checkCompletedNormally(f, v1); |
1358 |
|
checkCompletedNormally(g, v2); |
1359 |
< |
r.assertInvoked(); |
1359 |
> |
r.assertValue(subtract(v1, v2)); |
1360 |
|
}} |
1361 |
|
|
1362 |
|
/** |
2108 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2109 |
|
}} |
2110 |
|
|
2111 |
+ |
public void testAcceptEither_exceptionalCompletion2() { |
2112 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2113 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2114 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2115 |
+ |
{ |
2116 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2117 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2118 |
+ |
final CFException ex = new CFException(); |
2119 |
+ |
final NoopConsumer[] rs = new NoopConsumer[6]; |
2120 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m); |
2121 |
+ |
|
2122 |
+ |
final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]); |
2123 |
+ |
final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]); |
2124 |
+ |
if (fFirst) { |
2125 |
+ |
f.complete(v1); |
2126 |
+ |
g.completeExceptionally(ex); |
2127 |
+ |
} else { |
2128 |
+ |
g.completeExceptionally(ex); |
2129 |
+ |
f.complete(v1); |
2130 |
+ |
} |
2131 |
+ |
final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]); |
2132 |
+ |
final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]); |
2133 |
+ |
|
2134 |
+ |
// unspecified behavior - both source completions available |
2135 |
+ |
try { |
2136 |
+ |
assertEquals(null, h0.join()); |
2137 |
+ |
rs[0].assertValue(v1); |
2138 |
+ |
} catch (CompletionException ok) { |
2139 |
+ |
checkCompletedWithWrappedCFException(h0, ex); |
2140 |
+ |
rs[0].assertNotInvoked(); |
2141 |
+ |
} |
2142 |
+ |
try { |
2143 |
+ |
assertEquals(null, h1.join()); |
2144 |
+ |
rs[1].assertValue(v1); |
2145 |
+ |
} catch (CompletionException ok) { |
2146 |
+ |
checkCompletedWithWrappedCFException(h1, ex); |
2147 |
+ |
rs[1].assertNotInvoked(); |
2148 |
+ |
} |
2149 |
+ |
try { |
2150 |
+ |
assertEquals(null, h2.join()); |
2151 |
+ |
rs[2].assertValue(v1); |
2152 |
+ |
} catch (CompletionException ok) { |
2153 |
+ |
checkCompletedWithWrappedCFException(h2, ex); |
2154 |
+ |
rs[2].assertNotInvoked(); |
2155 |
+ |
} |
2156 |
+ |
try { |
2157 |
+ |
assertEquals(null, h3.join()); |
2158 |
+ |
rs[3].assertValue(v1); |
2159 |
+ |
} catch (CompletionException ok) { |
2160 |
+ |
checkCompletedWithWrappedCFException(h3, ex); |
2161 |
+ |
rs[3].assertNotInvoked(); |
2162 |
+ |
} |
2163 |
+ |
|
2164 |
+ |
checkCompletedNormally(f, v1); |
2165 |
+ |
checkCompletedWithWrappedCFException(g, ex); |
2166 |
+ |
}} |
2167 |
+ |
|
2168 |
|
/** |
2169 |
|
* acceptEither result completes exceptionally if either source cancelled |
2170 |
|
*/ |
2368 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
2369 |
|
}} |
2370 |
|
|
2371 |
+ |
public void testRunAfterEither_exceptionalCompletion2() { |
2372 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
2373 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
2374 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
2375 |
+ |
{ |
2376 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2377 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2378 |
+ |
final CFException ex = new CFException(); |
2379 |
+ |
final Noop[] rs = new Noop[6]; |
2380 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
2381 |
+ |
|
2382 |
+ |
final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
2383 |
+ |
final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
2384 |
+ |
if (fFirst) { |
2385 |
+ |
f.complete(v1); |
2386 |
+ |
g.completeExceptionally(ex); |
2387 |
+ |
} else { |
2388 |
+ |
g.completeExceptionally(ex); |
2389 |
+ |
f.complete(v1); |
2390 |
+ |
} |
2391 |
+ |
final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]); |
2392 |
+ |
final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]); |
2393 |
+ |
|
2394 |
+ |
// unspecified behavior - both source completions available |
2395 |
+ |
try { |
2396 |
+ |
assertEquals(null, h0.join()); |
2397 |
+ |
rs[0].assertInvoked(); |
2398 |
+ |
} catch (CompletionException ok) { |
2399 |
+ |
checkCompletedWithWrappedCFException(h0, ex); |
2400 |
+ |
rs[0].assertNotInvoked(); |
2401 |
+ |
} |
2402 |
+ |
try { |
2403 |
+ |
assertEquals(null, h1.join()); |
2404 |
+ |
rs[1].assertInvoked(); |
2405 |
+ |
} catch (CompletionException ok) { |
2406 |
+ |
checkCompletedWithWrappedCFException(h1, ex); |
2407 |
+ |
rs[1].assertNotInvoked(); |
2408 |
+ |
} |
2409 |
+ |
try { |
2410 |
+ |
assertEquals(null, h2.join()); |
2411 |
+ |
rs[2].assertInvoked(); |
2412 |
+ |
} catch (CompletionException ok) { |
2413 |
+ |
checkCompletedWithWrappedCFException(h2, ex); |
2414 |
+ |
rs[2].assertNotInvoked(); |
2415 |
+ |
} |
2416 |
+ |
try { |
2417 |
+ |
assertEquals(null, h3.join()); |
2418 |
+ |
rs[3].assertInvoked(); |
2419 |
+ |
} catch (CompletionException ok) { |
2420 |
+ |
checkCompletedWithWrappedCFException(h3, ex); |
2421 |
+ |
rs[3].assertNotInvoked(); |
2422 |
+ |
} |
2423 |
+ |
|
2424 |
+ |
checkCompletedNormally(f, v1); |
2425 |
+ |
checkCompletedWithWrappedCFException(g, ex); |
2426 |
+ |
}} |
2427 |
+ |
|
2428 |
|
/** |
2429 |
|
* runAfterEither result completes exceptionally if either source cancelled |
2430 |
|
*/ |
2531 |
|
|
2532 |
|
checkCompletedNormally(g, inc(v1)); |
2533 |
|
checkCompletedNormally(f, v1); |
2534 |
< |
r.assertInvoked(); |
2534 |
> |
r.assertValue(v1); |
2535 |
|
}} |
2536 |
|
|
2537 |
|
/** |
2821 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2822 |
|
(f, |
2823 |
|
(Integer x, Throwable t) -> { |
2824 |
+ |
m.checkExecutionMode(); |
2825 |
|
threadAssertSame(x, v1); |
2826 |
|
threadAssertNull(t); |
2827 |
|
a.getAndIncrement(); |
2849 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2850 |
|
(f, |
2851 |
|
(Integer x, Throwable t) -> { |
2852 |
+ |
m.checkExecutionMode(); |
2853 |
|
threadAssertNull(x); |
2854 |
|
threadAssertSame(t, ex); |
2855 |
|
a.getAndIncrement(); |
2875 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2876 |
|
(f, |
2877 |
|
(Integer x, Throwable t) -> { |
2878 |
+ |
m.checkExecutionMode(); |
2879 |
|
threadAssertNull(x); |
2880 |
|
threadAssertTrue(t instanceof CancellationException); |
2881 |
|
a.getAndIncrement(); |
2882 |
|
}); |
2883 |
|
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2884 |
|
|
2768 |
– |
//try { g.join(); } catch (Throwable t) { throw new Error(t); } |
2885 |
|
checkCompletedWithWrappedCancellationException(g); |
2886 |
|
checkCancelled(f); |
2887 |
|
assertEquals(1, a.get()); |
2903 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2904 |
|
(f, |
2905 |
|
(Integer x, Throwable t) -> { |
2906 |
+ |
m.checkExecutionMode(); |
2907 |
|
threadAssertSame(x, v1); |
2908 |
|
threadAssertNull(t); |
2909 |
|
a.getAndIncrement(); |
2934 |
|
final CompletableFuture<Integer> g = m.whenComplete |
2935 |
|
(f, |
2936 |
|
(Integer x, Throwable t) -> { |
2937 |
+ |
m.checkExecutionMode(); |
2938 |
|
threadAssertSame(t, ex1); |
2939 |
|
threadAssertNull(x); |
2940 |
|
a.getAndIncrement(); |