ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.64 by jsr166, Fri Jun 6 17:08:48 2014 UTC vs.
Revision 1.65 by jsr166, Fri Jun 6 17:41:02 2014 UTC

# Line 2095 | Line 2095 | public class CompletableFutureTest exten
2095       * runAfterEither result completes normally after normal completion
2096       * of either source
2097       */
2098 <    public void testRunAfterEither_normalCompletion1() {
2098 >    public void testRunAfterEither_normalCompletion() {
2099          for (ExecutionMode m : ExecutionMode.values())
2100          for (Integer v1 : new Integer[] { 1, null })
2101          for (Integer v2 : new Integer[] { 2, null })
2102      {
2103          final CompletableFuture<Integer> f = new CompletableFuture<>();
2104          final CompletableFuture<Integer> g = new CompletableFuture<>();
2105 <        final Noop r = new Noop(m);
2106 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2105 >        final Noop[] rs = new Noop[6];
2106 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2107  
2108 <        f.complete(v1);
2109 <        checkCompletedNormally(h, null);
2110 <        r.assertInvoked();
2111 <        g.complete(v2);
2112 <
2113 <        checkCompletedNormally(f, v1);
2114 <        checkCompletedNormally(g, v2);
2115 <        checkCompletedNormally(h, null);
2116 <        r.assertInvoked();
2117 <    }}
2118 <
2119 <    public void testRunAfterEither_normalCompletion2() {
2120 <        for (ExecutionMode m : ExecutionMode.values())
2121 <        for (Integer v1 : new Integer[] { 1, null })
2122 <        for (Integer v2 : new Integer[] { 2, null })
2123 <    {
2124 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2125 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2126 <        final Noop r = new Noop(m);
2127 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2108 >        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2109 >        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2110 >        checkIncomplete(h0);
2111 >        checkIncomplete(h1);
2112 >        rs[0].assertNotInvoked();
2113 >        rs[1].assertNotInvoked();
2114 >        f.complete(v1);
2115 >        checkCompletedNormally(h0, null);
2116 >        checkCompletedNormally(h1, null);
2117 >        rs[0].assertInvoked();
2118 >        rs[1].assertInvoked();
2119 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2120 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2121 >        checkCompletedNormally(h2, null);
2122 >        checkCompletedNormally(h3, null);
2123 >        rs[2].assertInvoked();
2124 >        rs[3].assertInvoked();
2125  
2126          g.complete(v2);
2130        checkCompletedNormally(h, null);
2131        r.assertInvoked();
2132        f.complete(v1);
2133
2134        checkCompletedNormally(f, v1);
2135        checkCompletedNormally(g, v2);
2136        checkCompletedNormally(h, null);
2137        r.assertInvoked();
2138        }}
2139
2140    public void testRunAfterEither_normalCompletion3() {
2141        for (ExecutionMode m : ExecutionMode.values())
2142        for (Integer v1 : new Integer[] { 1, null })
2143        for (Integer v2 : new Integer[] { 2, null })
2144    {
2145        final CompletableFuture<Integer> f = new CompletableFuture<>();
2146        final CompletableFuture<Integer> g = new CompletableFuture<>();
2147        final Noop r = new Noop(m);
2127  
2128 <        f.complete(v1);
2129 <        g.complete(v2);
2151 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2128 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2129 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2130  
2153        checkCompletedNormally(h, null);
2131          checkCompletedNormally(f, v1);
2132          checkCompletedNormally(g, v2);
2133 <        r.assertInvoked();
2133 >        checkCompletedNormally(h0, null);
2134 >        checkCompletedNormally(h1, null);
2135 >        checkCompletedNormally(h2, null);
2136 >        checkCompletedNormally(h3, null);
2137 >        checkCompletedNormally(h4, null);
2138 >        checkCompletedNormally(h5, null);
2139 >        for (int i = 0; i < 6; i++) rs[i].assertInvoked();
2140      }}
2141  
2142      /**
2143       * runAfterEither result completes exceptionally after exceptional
2144       * completion of either source
2145       */
2146 <    public void testRunAfterEither_exceptionalCompletion1() {
2146 >    public void testRunAfterEither_exceptionalCompletion() {
2147          for (ExecutionMode m : ExecutionMode.values())
2148          for (Integer v1 : new Integer[] { 1, null })
2149      {
2150          final CompletableFuture<Integer> f = new CompletableFuture<>();
2151          final CompletableFuture<Integer> g = new CompletableFuture<>();
2169        final Noop r = new Noop(m);
2170        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2152          final CFException ex = new CFException();
2153 +        final Noop[] rs = new Noop[6];
2154 +        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2155  
2156 +        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2157 +        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2158 +        checkIncomplete(h0);
2159 +        checkIncomplete(h1);
2160 +        rs[0].assertNotInvoked();
2161 +        rs[1].assertNotInvoked();
2162          f.completeExceptionally(ex);
2163 <        checkCompletedWithWrappedCFException(h, ex);
2164 <        g.complete(v1);
2165 <
2166 <        r.assertNotInvoked();
2167 <        checkCompletedNormally(g, v1);
2168 <        checkCompletedWithWrappedCFException(f, ex);
2180 <        checkCompletedWithWrappedCFException(h, ex);
2181 <    }}
2182 <
2183 <    public void testRunAfterEither_exceptionalCompletion2() {
2184 <        for (ExecutionMode m : ExecutionMode.values())
2185 <        for (Integer v1 : new Integer[] { 1, null })
2186 <    {
2187 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2188 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2189 <        final Noop r = new Noop(m);
2190 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2191 <        final CFException ex = new CFException();
2192 <
2193 <        g.completeExceptionally(ex);
2194 <        checkCompletedWithWrappedCFException(h, ex);
2195 <        f.complete(v1);
2196 <
2197 <        r.assertNotInvoked();
2198 <        checkCompletedNormally(f, v1);
2199 <        checkCompletedWithWrappedCFException(g, ex);
2200 <        checkCompletedWithWrappedCFException(h, ex);
2201 <    }}
2202 <
2203 <    public void testRunAfterEither_exceptionalCompletion3() {
2204 <        for (ExecutionMode m : ExecutionMode.values())
2205 <        for (Integer v1 : new Integer[] { 1, null })
2206 <    {
2207 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2208 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2209 <        final Noop r = new Noop(m);
2210 <        final CFException ex = new CFException();
2163 >        checkCompletedWithWrappedCFException(h0, ex);
2164 >        checkCompletedWithWrappedCFException(h1, ex);
2165 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2166 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2167 >        checkCompletedWithWrappedCFException(h2, ex);
2168 >        checkCompletedWithWrappedCFException(h3, ex);
2169  
2170 <        g.completeExceptionally(ex);
2213 <        f.complete(v1);
2214 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2170 >        g.complete(v1);
2171  
2172 <        // unspecified behavior
2173 <        Integer v;
2172 >        // unspecified behavior - both source completions available
2173 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2174 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2175          try {
2176 <            assertNull(h.join());
2177 <            r.assertInvoked();
2176 >            assertNull(h4.join());
2177 >            rs[4].assertInvoked();
2178          } catch (CompletionException ok) {
2179 <            checkCompletedWithWrappedCFException(h, ex);
2180 <            r.assertNotInvoked();
2179 >            checkCompletedWithWrappedCFException(h4, ex);
2180 >            rs[4].assertNotInvoked();
2181          }
2225
2226        checkCompletedWithWrappedCFException(g, ex);
2227        checkCompletedNormally(f, v1);
2228    }}
2229
2230    public void testRunAfterEither_exceptionalCompletion4() {
2231        for (ExecutionMode m : ExecutionMode.values())
2232        for (Integer v1 : new Integer[] { 1, null })
2233    {
2234        final CompletableFuture<Integer> f = new CompletableFuture<>();
2235        final CompletableFuture<Integer> g = new CompletableFuture<>();
2236        final Noop r = new Noop(m);
2237        final CFException ex = new CFException();
2238
2239        f.completeExceptionally(ex);
2240        g.complete(v1);
2241        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2242
2243        // unspecified behavior
2244        Integer v;
2182          try {
2183 <            assertNull(h.join());
2184 <            r.assertInvoked();
2183 >            assertNull(h5.join());
2184 >            rs[5].assertInvoked();
2185          } catch (CompletionException ok) {
2186 <            checkCompletedWithWrappedCFException(h, ex);
2187 <            r.assertNotInvoked();
2186 >            checkCompletedWithWrappedCFException(h5, ex);
2187 >            rs[5].assertNotInvoked();
2188          }
2189  
2190          checkCompletedWithWrappedCFException(f, ex);
2191          checkCompletedNormally(g, v1);
2192 <    }}
2193 <
2194 <    /**
2195 <     * runAfterEither result completes exceptionally if action does
2196 <     */
2197 <    public void testRunAfterEither_actionFailed1() {
2261 <        for (ExecutionMode m : ExecutionMode.values())
2262 <        for (Integer v1 : new Integer[] { 1, null })
2263 <        for (Integer v2 : new Integer[] { 2, null })
2264 <    {
2265 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2266 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2267 <        final FailingRunnable r = new FailingRunnable(m);
2268 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2269 <
2270 <        f.complete(v1);
2271 <        checkCompletedWithWrappedCFException(h);
2272 <        g.complete(v2);
2273 <        checkCompletedNormally(f, v1);
2274 <        checkCompletedNormally(g, v2);
2275 <    }}
2276 <
2277 <    public void testRunAfterEither_actionFailed2() {
2278 <        for (ExecutionMode m : ExecutionMode.values())
2279 <        for (Integer v1 : new Integer[] { 1, null })
2280 <        for (Integer v2 : new Integer[] { 2, null })
2281 <    {
2282 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2283 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2284 <        final FailingRunnable r = new FailingRunnable(m);
2285 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2286 <
2287 <        g.complete(v2);
2288 <        checkCompletedWithWrappedCFException(h);
2289 <        f.complete(v1);
2290 <        checkCompletedNormally(f, v1);
2291 <        checkCompletedNormally(g, v2);
2192 >        checkCompletedWithWrappedCFException(h0, ex);
2193 >        checkCompletedWithWrappedCFException(h1, ex);
2194 >        checkCompletedWithWrappedCFException(h2, ex);
2195 >        checkCompletedWithWrappedCFException(h3, ex);
2196 >        checkCompletedWithWrappedCFException(h4, ex);
2197 >        for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2198      }}
2199  
2200      /**
2201       * runAfterEither result completes exceptionally if either source cancelled
2202       */
2203 <    public void testRunAfterEither_sourceCancelled1() {
2203 >    public void testRunAfterEither_sourceCancelled() {
2204          for (ExecutionMode m : ExecutionMode.values())
2205          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2206          for (Integer v1 : new Integer[] { 1, null })
2207      {
2208          final CompletableFuture<Integer> f = new CompletableFuture<>();
2209          final CompletableFuture<Integer> g = new CompletableFuture<>();
2210 <        final Noop r = new Noop(m);
2211 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2306 <
2307 <        assertTrue(f.cancel(mayInterruptIfRunning));
2308 <        checkCompletedWithWrappedCancellationException(h);
2309 <        g.complete(v1);
2310 <
2311 <        checkCancelled(f);
2312 <        r.assertNotInvoked();
2313 <        checkCompletedNormally(g, v1);
2314 <        checkCompletedWithWrappedCancellationException(h);
2315 <    }}
2210 >        final Noop[] rs = new Noop[6];
2211 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
2212  
2213 <    public void testRunAfterEither_sourceCancelled2() {
2214 <        for (ExecutionMode m : ExecutionMode.values())
2215 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2216 <        for (Integer v1 : new Integer[] { 1, null })
2217 <    {
2218 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2219 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2220 <        final Noop r = new Noop(m);
2221 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2213 >        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2214 >        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2215 >        checkIncomplete(h0);
2216 >        checkIncomplete(h1);
2217 >        rs[0].assertNotInvoked();
2218 >        rs[1].assertNotInvoked();
2219 >        f.cancel(mayInterruptIfRunning);
2220 >        checkCompletedWithWrappedCancellationException(h0);
2221 >        checkCompletedWithWrappedCancellationException(h1);
2222 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2223 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2224 >        checkCompletedWithWrappedCancellationException(h2);
2225 >        checkCompletedWithWrappedCancellationException(h3);
2226  
2227 <        assertTrue(g.cancel(mayInterruptIfRunning));
2328 <        checkCompletedWithWrappedCancellationException(h);
2329 <        f.complete(v1);
2330 <
2331 <        checkCancelled(g);
2332 <        r.assertNotInvoked();
2333 <        checkCompletedNormally(f, v1);
2334 <        checkCompletedWithWrappedCancellationException(h);
2335 <    }}
2336 <
2337 <    public void testRunAfterEither_sourceCancelled3() {
2338 <        for (ExecutionMode m : ExecutionMode.values())
2339 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2340 <        for (Integer v1 : new Integer[] { 1, null })
2341 <    {
2342 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2343 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2344 <        final Noop r = new Noop(m);
2345 <
2346 <        assertTrue(g.cancel(mayInterruptIfRunning));
2347 <        f.complete(v1);
2348 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2227 >        g.complete(v1);
2228  
2229 <        // unspecified behavior
2230 <        Integer v;
2229 >        // unspecified behavior - both source completions available
2230 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2231 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2232          try {
2233 <            assertNull(h.join());
2234 <            r.assertInvoked();
2233 >            assertNull(h4.join());
2234 >            rs[4].assertInvoked();
2235          } catch (CompletionException ok) {
2236 <            checkCompletedWithWrappedCancellationException(h);
2237 <            r.assertNotInvoked();
2236 >            checkCompletedWithWrappedCancellationException(h4);
2237 >            rs[4].assertNotInvoked();
2238 >        }
2239 >        try {
2240 >            assertNull(h5.join());
2241 >            rs[5].assertInvoked();
2242 >        } catch (CompletionException ok) {
2243 >            checkCompletedWithWrappedCancellationException(h5);
2244 >            rs[5].assertNotInvoked();
2245          }
2246  
2247 <        checkCancelled(g);
2248 <        checkCompletedNormally(f, v1);
2247 >        checkCancelled(f);
2248 >        checkCompletedNormally(g, v1);
2249 >        checkCompletedWithWrappedCancellationException(h0);
2250 >        checkCompletedWithWrappedCancellationException(h1);
2251 >        checkCompletedWithWrappedCancellationException(h2);
2252 >        checkCompletedWithWrappedCancellationException(h3);
2253 >        for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2254      }}
2255  
2256 <    public void testRunAfterEither_sourceCancelled4() {
2256 >    /**
2257 >     * runAfterEither result completes exceptionally if action does
2258 >     */
2259 >    public void testRunAfterEither_actionFailed() {
2260          for (ExecutionMode m : ExecutionMode.values())
2366        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2261          for (Integer v1 : new Integer[] { 1, null })
2262 +        for (Integer v2 : new Integer[] { 2, null })
2263      {
2264          final CompletableFuture<Integer> f = new CompletableFuture<>();
2265          final CompletableFuture<Integer> g = new CompletableFuture<>();
2266 <        final Noop r = new Noop(m);
2267 <
2373 <        assertTrue(f.cancel(mayInterruptIfRunning));
2374 <        g.complete(v1);
2375 <        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2266 >        final FailingRunnable[] rs = new FailingRunnable[6];
2267 >        for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m);
2268  
2269 <        // unspecified behavior
2270 <        Integer v;
2271 <        try {
2272 <            assertNull(h.join());
2273 <            r.assertInvoked();
2274 <        } catch (CompletionException ok) {
2275 <            checkCompletedWithWrappedCancellationException(h);
2276 <            r.assertNotInvoked();
2277 <        }
2269 >        final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2270 >        final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2271 >        f.complete(v1);
2272 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2273 >        final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2274 >        checkCompletedWithWrappedCFException(h0);
2275 >        checkCompletedWithWrappedCFException(h1);
2276 >        checkCompletedWithWrappedCFException(h2);
2277 >        checkCompletedWithWrappedCFException(h3);
2278 >        for (int i = 0; i < 4; i++) rs[i].assertInvoked();
2279 >        g.complete(v2);
2280 >        final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2281 >        final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2282 >        checkCompletedWithWrappedCFException(h4);
2283 >        checkCompletedWithWrappedCFException(h5);
2284  
2285 <        checkCancelled(f);
2286 <        checkCompletedNormally(g, v1);
2285 >        checkCompletedNormally(f, v1);
2286 >        checkCompletedNormally(g, v2);
2287 >        for (int i = 0; i < 6; i++) rs[i].assertInvoked();
2288      }}
2289  
2290      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines