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.71 by jsr166, Fri Jun 6 20:01:16 2014 UTC vs.
Revision 1.72 by jsr166, Fri Jun 6 21:10:34 2014 UTC

# Line 105 | Line 105 | public class CompletableFutureTest exten
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();
# Line 131 | Line 131 | public class CompletableFutureTest exten
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);
# Line 218 | Line 239 | public class CompletableFutureTest exten
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      /**
# Line 261 | Line 283 | public class CompletableFutureTest exten
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
# Line 852 | Line 887 | public class CompletableFutureTest exten
887              });
888          if (createIncomplete) f.completeExceptionally(ex1);
889  
890 <        checkCompletedWithWrappedCFException(g, ex2);
890 >        checkCompletedWithWrappedException(g, ex2);
891          assertEquals(1, a.get());
892      }}
893  
# Line 909 | Line 944 | public class CompletableFutureTest exten
944          if (createIncomplete) f.completeExceptionally(ex);
945  
946          checkCompletedNormally(g, v1);
947 <        checkCompletedWithWrappedCFException(f, ex);
947 >        checkCompletedExceptionally(f, ex);
948          assertEquals(1, a.get());
949      }}
950  
# Line 965 | Line 1000 | public class CompletableFutureTest exten
1000              });
1001          if (createIncomplete) f.completeExceptionally(ex1);
1002  
1003 <        checkCompletedWithWrappedCFException(g, ex2);
1004 <        checkCompletedWithWrappedCFException(f, ex1);
1003 >        checkCompletedWithWrappedException(g, ex2);
1004 >        checkCompletedExceptionally(f, ex1);
1005          assertEquals(1, a.get());
1006      }}
1007  
# Line 990 | Line 1025 | public class CompletableFutureTest exten
1025              });
1026          if (createIncomplete) f.complete(v1);
1027  
1028 <        checkCompletedWithWrappedCFException(g, ex);
1028 >        checkCompletedWithWrappedException(g, ex);
1029          checkCompletedNormally(f, v1);
1030          assertEquals(1, a.get());
1031      }}
# Line 1104 | Line 1139 | public class CompletableFutureTest exten
1139              f.completeExceptionally(ex);
1140          }
1141  
1142 <        checkCompletedWithWrappedCFException(g, ex);
1143 <        checkCompletedWithWrappedCFException(f, ex);
1142 >        checkCompletedWithWrappedException(g, ex);
1143 >        checkCompletedExceptionally(f, ex);
1144          r.assertNotInvoked();
1145      }}
1146  
# Line 1192 | Line 1227 | public class CompletableFutureTest exten
1227              f.completeExceptionally(ex);
1228          }
1229  
1230 <        checkCompletedWithWrappedCFException(g, ex);
1231 <        checkCompletedWithWrappedCFException(f, ex);
1230 >        checkCompletedWithWrappedException(g, ex);
1231 >        checkCompletedExceptionally(f, ex);
1232          r.assertNotInvoked();
1233      }}
1234  
# Line 1280 | Line 1315 | public class CompletableFutureTest exten
1315              f.completeExceptionally(ex);
1316          }
1317  
1318 <        checkCompletedWithWrappedCFException(g, ex);
1319 <        checkCompletedWithWrappedCFException(f, ex);
1318 >        checkCompletedWithWrappedException(g, ex);
1319 >        checkCompletedExceptionally(f, ex);
1320          r.assertNotInvoked();
1321      }}
1322  
# Line 1383 | Line 1418 | public class CompletableFutureTest exten
1418              (!fFirst ? f : g).completeExceptionally(ex);
1419          }
1420  
1421 <        checkCompletedWithWrappedCFException(h, ex);
1421 >        checkCompletedWithWrappedException(h, ex);
1422          r.assertNotInvoked();
1423          checkCompletedNormally(fFirst ? f : g, v1);
1424 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1424 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1425      }}
1426  
1427      /**
# Line 1500 | Line 1535 | public class CompletableFutureTest exten
1535              (!fFirst ? f : g).completeExceptionally(ex);
1536          }
1537  
1538 <        checkCompletedWithWrappedCFException(h, ex);
1538 >        checkCompletedWithWrappedException(h, ex);
1539          r.assertNotInvoked();
1540          checkCompletedNormally(fFirst ? f : g, v1);
1541 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1541 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1542      }}
1543  
1544      /**
# Line 1617 | Line 1652 | public class CompletableFutureTest exten
1652              (!fFirst ? f : g).completeExceptionally(ex);
1653          }
1654  
1655 <        checkCompletedWithWrappedCFException(h, ex);
1655 >        checkCompletedWithWrappedException(h, ex);
1656          r.assertNotInvoked();
1657          checkCompletedNormally(fFirst ? f : g, v1);
1658 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1658 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1659      }}
1660  
1661      /**
# Line 1752 | Line 1787 | public class CompletableFutureTest exten
1787          rs[0].assertNotInvoked();
1788          rs[1].assertNotInvoked();
1789          f.completeExceptionally(ex);
1790 <        checkCompletedWithWrappedCFException(h0, ex);
1791 <        checkCompletedWithWrappedCFException(h1, ex);
1790 >        checkCompletedWithWrappedException(h0, ex);
1791 >        checkCompletedWithWrappedException(h1, ex);
1792          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
1793          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
1794 <        checkCompletedWithWrappedCFException(h2, ex);
1795 <        checkCompletedWithWrappedCFException(h3, ex);
1794 >        checkCompletedWithWrappedException(h2, ex);
1795 >        checkCompletedWithWrappedException(h3, ex);
1796          g.complete(v1);
1797  
1798          // unspecified behavior - both source completions available
# Line 1767 | Line 1802 | public class CompletableFutureTest exten
1802              assertEquals(inc(v1), h4.join());
1803              rs[4].assertValue(inc(v1));
1804          } catch (CompletionException ok) {
1805 <            checkCompletedWithWrappedCFException(h4, ex);
1805 >            checkCompletedWithWrappedException(h4, ex);
1806              rs[4].assertNotInvoked();
1807          }
1808          try {
1809              assertEquals(inc(v1), h5.join());
1810              rs[5].assertValue(inc(v1));
1811          } catch (CompletionException ok) {
1812 <            checkCompletedWithWrappedCFException(h5, ex);
1812 >            checkCompletedWithWrappedException(h5, ex);
1813              rs[5].assertNotInvoked();
1814          }
1815  
1816 <        checkCompletedWithWrappedCFException(f, ex);
1816 >        checkCompletedExceptionally(f, ex);
1817          checkCompletedNormally(g, v1);
1818 <        checkCompletedWithWrappedCFException(h0, ex);
1819 <        checkCompletedWithWrappedCFException(h1, ex);
1820 <        checkCompletedWithWrappedCFException(h2, ex);
1821 <        checkCompletedWithWrappedCFException(h3, ex);
1822 <        checkCompletedWithWrappedCFException(h4, ex);
1818 >        checkCompletedWithWrappedException(h0, ex);
1819 >        checkCompletedWithWrappedException(h1, ex);
1820 >        checkCompletedWithWrappedException(h2, ex);
1821 >        checkCompletedWithWrappedException(h3, ex);
1822 >        checkCompletedWithWrappedException(h4, ex);
1823          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
1824      }}
1825  
# Line 1816 | Line 1851 | public class CompletableFutureTest exten
1851              assertEquals(inc(v1), h0.join());
1852              rs[0].assertValue(inc(v1));
1853          } catch (CompletionException ok) {
1854 <            checkCompletedWithWrappedCFException(h0, ex);
1854 >            checkCompletedWithWrappedException(h0, ex);
1855              rs[0].assertNotInvoked();
1856          }
1857          try {
1858              assertEquals(inc(v1), h1.join());
1859              rs[1].assertValue(inc(v1));
1860          } catch (CompletionException ok) {
1861 <            checkCompletedWithWrappedCFException(h1, ex);
1861 >            checkCompletedWithWrappedException(h1, ex);
1862              rs[1].assertNotInvoked();
1863          }
1864          try {
1865              assertEquals(inc(v1), h2.join());
1866              rs[2].assertValue(inc(v1));
1867          } catch (CompletionException ok) {
1868 <            checkCompletedWithWrappedCFException(h2, ex);
1868 >            checkCompletedWithWrappedException(h2, ex);
1869              rs[2].assertNotInvoked();
1870          }
1871          try {
1872              assertEquals(inc(v1), h3.join());
1873              rs[3].assertValue(inc(v1));
1874          } catch (CompletionException ok) {
1875 <            checkCompletedWithWrappedCFException(h3, ex);
1875 >            checkCompletedWithWrappedException(h3, ex);
1876              rs[3].assertNotInvoked();
1877          }
1878  
1879          checkCompletedNormally(f, v1);
1880 <        checkCompletedWithWrappedCFException(g, ex);
1880 >        checkCompletedExceptionally(g, ex);
1881      }}
1882  
1883      /**
# Line 2071 | Line 2106 | public class CompletableFutureTest exten
2106          rs[0].assertNotInvoked();
2107          rs[1].assertNotInvoked();
2108          f.completeExceptionally(ex);
2109 <        checkCompletedWithWrappedCFException(h0, ex);
2110 <        checkCompletedWithWrappedCFException(h1, ex);
2109 >        checkCompletedWithWrappedException(h0, ex);
2110 >        checkCompletedWithWrappedException(h1, ex);
2111          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2112          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2113 <        checkCompletedWithWrappedCFException(h2, ex);
2114 <        checkCompletedWithWrappedCFException(h3, ex);
2113 >        checkCompletedWithWrappedException(h2, ex);
2114 >        checkCompletedWithWrappedException(h3, ex);
2115  
2116          g.complete(v1);
2117  
# Line 2087 | Line 2122 | public class CompletableFutureTest exten
2122              assertNull(h4.join());
2123              rs[4].assertValue(v1);
2124          } catch (CompletionException ok) {
2125 <            checkCompletedWithWrappedCFException(h4, ex);
2125 >            checkCompletedWithWrappedException(h4, ex);
2126              rs[4].assertNotInvoked();
2127          }
2128          try {
2129              assertNull(h5.join());
2130              rs[5].assertValue(v1);
2131          } catch (CompletionException ok) {
2132 <            checkCompletedWithWrappedCFException(h5, ex);
2132 >            checkCompletedWithWrappedException(h5, ex);
2133              rs[5].assertNotInvoked();
2134          }
2135  
2136 <        checkCompletedWithWrappedCFException(f, ex);
2136 >        checkCompletedExceptionally(f, ex);
2137          checkCompletedNormally(g, v1);
2138 <        checkCompletedWithWrappedCFException(h0, ex);
2139 <        checkCompletedWithWrappedCFException(h1, ex);
2140 <        checkCompletedWithWrappedCFException(h2, ex);
2141 <        checkCompletedWithWrappedCFException(h3, ex);
2142 <        checkCompletedWithWrappedCFException(h4, ex);
2138 >        checkCompletedWithWrappedException(h0, ex);
2139 >        checkCompletedWithWrappedException(h1, ex);
2140 >        checkCompletedWithWrappedException(h2, ex);
2141 >        checkCompletedWithWrappedException(h3, ex);
2142 >        checkCompletedWithWrappedException(h4, ex);
2143          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2144      }}
2145  
# Line 2136 | Line 2171 | public class CompletableFutureTest exten
2171              assertEquals(null, h0.join());
2172              rs[0].assertValue(v1);
2173          } catch (CompletionException ok) {
2174 <            checkCompletedWithWrappedCFException(h0, ex);
2174 >            checkCompletedWithWrappedException(h0, ex);
2175              rs[0].assertNotInvoked();
2176          }
2177          try {
2178              assertEquals(null, h1.join());
2179              rs[1].assertValue(v1);
2180          } catch (CompletionException ok) {
2181 <            checkCompletedWithWrappedCFException(h1, ex);
2181 >            checkCompletedWithWrappedException(h1, ex);
2182              rs[1].assertNotInvoked();
2183          }
2184          try {
2185              assertEquals(null, h2.join());
2186              rs[2].assertValue(v1);
2187          } catch (CompletionException ok) {
2188 <            checkCompletedWithWrappedCFException(h2, ex);
2188 >            checkCompletedWithWrappedException(h2, ex);
2189              rs[2].assertNotInvoked();
2190          }
2191          try {
2192              assertEquals(null, h3.join());
2193              rs[3].assertValue(v1);
2194          } catch (CompletionException ok) {
2195 <            checkCompletedWithWrappedCFException(h3, ex);
2195 >            checkCompletedWithWrappedException(h3, ex);
2196              rs[3].assertNotInvoked();
2197          }
2198  
2199          checkCompletedNormally(f, v1);
2200 <        checkCompletedWithWrappedCFException(g, ex);
2200 >        checkCompletedExceptionally(g, ex);
2201      }}
2202  
2203      /**
# Line 2331 | Line 2366 | public class CompletableFutureTest exten
2366          rs[0].assertNotInvoked();
2367          rs[1].assertNotInvoked();
2368          f.completeExceptionally(ex);
2369 <        checkCompletedWithWrappedCFException(h0, ex);
2370 <        checkCompletedWithWrappedCFException(h1, ex);
2369 >        checkCompletedWithWrappedException(h0, ex);
2370 >        checkCompletedWithWrappedException(h1, ex);
2371          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2372          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2373 <        checkCompletedWithWrappedCFException(h2, ex);
2374 <        checkCompletedWithWrappedCFException(h3, ex);
2373 >        checkCompletedWithWrappedException(h2, ex);
2374 >        checkCompletedWithWrappedException(h3, ex);
2375  
2376          g.complete(v1);
2377  
# Line 2347 | Line 2382 | public class CompletableFutureTest exten
2382              assertNull(h4.join());
2383              rs[4].assertInvoked();
2384          } catch (CompletionException ok) {
2385 <            checkCompletedWithWrappedCFException(h4, ex);
2385 >            checkCompletedWithWrappedException(h4, ex);
2386              rs[4].assertNotInvoked();
2387          }
2388          try {
2389              assertNull(h5.join());
2390              rs[5].assertInvoked();
2391          } catch (CompletionException ok) {
2392 <            checkCompletedWithWrappedCFException(h5, ex);
2392 >            checkCompletedWithWrappedException(h5, ex);
2393              rs[5].assertNotInvoked();
2394          }
2395  
2396 <        checkCompletedWithWrappedCFException(f, ex);
2396 >        checkCompletedExceptionally(f, ex);
2397          checkCompletedNormally(g, v1);
2398 <        checkCompletedWithWrappedCFException(h0, ex);
2399 <        checkCompletedWithWrappedCFException(h1, ex);
2400 <        checkCompletedWithWrappedCFException(h2, ex);
2401 <        checkCompletedWithWrappedCFException(h3, ex);
2402 <        checkCompletedWithWrappedCFException(h4, ex);
2398 >        checkCompletedWithWrappedException(h0, ex);
2399 >        checkCompletedWithWrappedException(h1, ex);
2400 >        checkCompletedWithWrappedException(h2, ex);
2401 >        checkCompletedWithWrappedException(h3, ex);
2402 >        checkCompletedWithWrappedException(h4, ex);
2403          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2404      }}
2405  
# Line 2396 | Line 2431 | public class CompletableFutureTest exten
2431              assertEquals(null, h0.join());
2432              rs[0].assertInvoked();
2433          } catch (CompletionException ok) {
2434 <            checkCompletedWithWrappedCFException(h0, ex);
2434 >            checkCompletedWithWrappedException(h0, ex);
2435              rs[0].assertNotInvoked();
2436          }
2437          try {
2438              assertEquals(null, h1.join());
2439              rs[1].assertInvoked();
2440          } catch (CompletionException ok) {
2441 <            checkCompletedWithWrappedCFException(h1, ex);
2441 >            checkCompletedWithWrappedException(h1, ex);
2442              rs[1].assertNotInvoked();
2443          }
2444          try {
2445              assertEquals(null, h2.join());
2446              rs[2].assertInvoked();
2447          } catch (CompletionException ok) {
2448 <            checkCompletedWithWrappedCFException(h2, ex);
2448 >            checkCompletedWithWrappedException(h2, ex);
2449              rs[2].assertNotInvoked();
2450          }
2451          try {
2452              assertEquals(null, h3.join());
2453              rs[3].assertInvoked();
2454          } catch (CompletionException ok) {
2455 <            checkCompletedWithWrappedCFException(h3, ex);
2455 >            checkCompletedWithWrappedException(h3, ex);
2456              rs[3].assertNotInvoked();
2457          }
2458  
2459          checkCompletedNormally(f, v1);
2460 <        checkCompletedWithWrappedCFException(g, ex);
2460 >        checkCompletedExceptionally(g, ex);
2461      }}
2462  
2463      /**
# Line 2549 | Line 2584 | public class CompletableFutureTest exten
2584          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2585          if (createIncomplete) f.completeExceptionally(ex);
2586  
2587 <        checkCompletedWithWrappedCFException(g, ex);
2588 <        checkCompletedWithWrappedCFException(f, ex);
2587 >        checkCompletedWithWrappedException(g, ex);
2588 >        checkCompletedExceptionally(f, ex);
2589          r.assertNotInvoked();
2590      }}
2591  
# Line 2855 | Line 2890 | public class CompletableFutureTest exten
2890                  a.getAndIncrement();
2891              });
2892          if (createIncomplete) f.completeExceptionally(ex);
2893 <        checkCompletedWithWrappedCFException(f, ex);
2894 <        checkCompletedWithWrappedCFException(g, ex);
2893 >        checkCompletedExceptionally(f, ex);
2894 >        checkCompletedWithWrappedException(g, ex);
2895          assertEquals(1, a.get());
2896      }}
2897  
# Line 2911 | Line 2946 | public class CompletableFutureTest exten
2946              });
2947          if (createIncomplete) f.complete(v1);
2948          checkCompletedNormally(f, v1);
2949 <        checkCompletedWithWrappedCFException(g, ex);
2949 >        checkCompletedWithWrappedException(g, ex);
2950          assertEquals(1, a.get());
2951      }}
2952  
# Line 2942 | Line 2977 | public class CompletableFutureTest exten
2977              });
2978          if (createIncomplete) f.completeExceptionally(ex1);
2979  
2980 <        checkCompletedWithWrappedCFException(f, ex1);
2981 <        checkCompletedWithWrappedCFException(g, ex1);
2980 >        checkCompletedExceptionally(f, ex1);
2981 >        checkCompletedWithWrappedException(g, ex1);
2982          assertEquals(1, a.get());
2983      }}
2984  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines