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 |
|
*/ |