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.5 by dl, Thu Mar 21 16:26:43 2013 UTC vs.
Revision 1.7 by jsr166, Fri Mar 22 16:29:42 2013 UTC

# Line 75 | Line 75 | public class CompletableFutureTest exten
75          try {
76              f.join();
77              shouldThrow();
78 <        } catch (Throwable ex) {
78 >        } catch (Throwable ex) {
79              assertTrue(ex instanceof CompletionException &&
80                         ((CompletionException)ex).getCause() instanceof CFException);
81          }
82          try {
83              f.getNow(null);
84              shouldThrow();
85 <        } catch (Throwable ex) {
85 >        } catch (Throwable ex) {
86              assertTrue(ex instanceof CompletionException &&
87                         ((CompletionException)ex).getCause() instanceof CFException);
88          }
89          try {
90              f.get();
91              shouldThrow();
92 <        } catch (Throwable ex) {
92 >        } catch (Throwable ex) {
93              assertTrue(ex instanceof ExecutionException &&
94                         ((ExecutionException)ex).getCause() instanceof CFException);
95          }
96          try {
97              f.get(0L, SECONDS);
98              shouldThrow();
99 <        } catch (Throwable ex) {
99 >        } catch (Throwable ex) {
100              assertTrue(ex instanceof ExecutionException &&
101                         ((ExecutionException)ex).getCause() instanceof CFException);
102          }
# Line 108 | Line 108 | public class CompletableFutureTest exten
108          try {
109              f.join();
110              shouldThrow();
111 <        } catch (Throwable ex) {
111 >        } catch (Throwable ex) {
112              assertTrue(ex instanceof CancellationException);
113          }
114          try {
115              f.getNow(null);
116              shouldThrow();
117 <        } catch (Throwable ex) {
117 >        } catch (Throwable ex) {
118              assertTrue(ex instanceof CancellationException);
119          }
120          try {
121              f.get();
122              shouldThrow();
123 <        } catch (Throwable ex) {
123 >        } catch (Throwable ex) {
124              assertTrue(ex instanceof CancellationException);
125          }
126          try {
127              f.get(0L, SECONDS);
128              shouldThrow();
129 <        } catch (Throwable ex) {
129 >        } catch (Throwable ex) {
130              assertTrue(ex instanceof CancellationException);
131          }
132          assertTrue(f.isDone());
# Line 137 | Line 137 | public class CompletableFutureTest exten
137          try {
138              f.join();
139              shouldThrow();
140 <        } catch (Throwable ex) {
140 >        } catch (Throwable ex) {
141              assertTrue(ex instanceof CompletionException &&
142                         ((CompletionException)ex).getCause() instanceof CancellationException);
143          }
144          try {
145              f.getNow(null);
146              shouldThrow();
147 <        } catch (Throwable ex) {
147 >        } catch (Throwable ex) {
148              assertTrue(ex instanceof CompletionException &&
149                         ((CompletionException)ex).getCause() instanceof CancellationException);
150          }
151          try {
152              f.get();
153              shouldThrow();
154 <        } catch (Throwable ex) {
154 >        } catch (Throwable ex) {
155              assertTrue(ex instanceof ExecutionException &&
156                         ((ExecutionException)ex).getCause() instanceof CancellationException);
157          }
158          try {
159              f.get(0L, SECONDS);
160              shouldThrow();
161 <        } catch (Throwable ex) {
161 >        } catch (Throwable ex) {
162              assertTrue(ex instanceof ExecutionException &&
163                         ((ExecutionException)ex).getCause() instanceof CancellationException);
164          }
# Line 249 | Line 249 | public class CompletableFutureTest exten
249          f.obtrudeException(new CFException());
250          checkCompletedWithWrappedCFException(f);
251      }
252 <    
252 >
253      /**
254       * getNumberOfDependents returns number of dependent tasks
255       */
# Line 285 | Line 285 | public class CompletableFutureTest exten
285          assertTrue(f.toString().contains("[Completed exceptionally]"));
286      }
287  
288 <    static final Supplier<Integer> supplyOne =
288 >    static final Supplier<Integer> supplyOne =
289          () -> Integer.valueOf(1);
290 <    static final Function<Integer, Integer> inc =
290 >    static final Function<Integer, Integer> inc =
291          (Integer x) -> Integer.valueOf(x.intValue() + 1);
292 <    static final BiFunction<Integer, Integer, Integer> add =
292 >    static final BiFunction<Integer, Integer, Integer> add =
293          (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
294      static final class IncAction implements Consumer<Integer> {
295          int value;
# Line 297 | Line 297 | public class CompletableFutureTest exten
297      }
298      static final class AddAction implements BiConsumer<Integer, Integer> {
299          int value;
300 <        public void accept(Integer x, Integer y) {
301 <            value = x.intValue() + y.intValue();
300 >        public void accept(Integer x, Integer y) {
301 >            value = x.intValue() + y.intValue();
302          }
303      }
304      static final class Noop implements Runnable {
# Line 345 | Line 345 | public class CompletableFutureTest exten
345              ran = true; throw new CFException();
346          }
347      }
348 <    
348 >
349      // Used for explicit executor tests
350      static final class ThreadExecutor implements Executor {
351          public void execute(Runnable r) {
# Line 358 | Line 358 | public class CompletableFutureTest exten
358      }
359  
360      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
361 <        public Integer apply(Integer x, Throwable t) {
361 >        public Integer apply(Integer x, Throwable t) {
362              return (t == null) ? two : three;
363          }
364      }
# Line 456 | Line 456 | public class CompletableFutureTest exten
456          assertTrue(r.ran);
457      }
458  
459 <    // seq conmpletion methods
460 <    
459 >    // seq completion methods
460 >
461      /**
462       * thenRun result completes normally after normal completion of source
463       */
# Line 1126 | Line 1126 | public class CompletableFutureTest exten
1126          try {
1127              g.join();
1128              shouldThrow();
1129 <        } catch(Exception ok) {
1129 >        } catch (Exception ok) {
1130          }
1131          checkCompletedWithWrappedCFException(g);
1132      }
# Line 1141 | Line 1141 | public class CompletableFutureTest exten
1141          f.complete(null);
1142          checkCompletedWithWrappedCFException(g);
1143      }
1144 <        
1144 >
1145      /**
1146       * thenRunAsync result completes exceptionally if source cancelled
1147       */
# Line 1184 | Line 1184 | public class CompletableFutureTest exten
1184          f.complete(null);
1185          checkCompletedWithWrappedCFException(g);
1186      }
1187 <        
1187 >
1188      /**
1189       * thenApplyAsync result completes exceptionally if source cancelled
1190       */
# Line 1230 | Line 1230 | public class CompletableFutureTest exten
1230          f.complete(null);
1231          checkCompletedWithWrappedCFException(g);
1232      }
1233 <        
1233 >
1234      /**
1235       * thenAcceptAsync result completes exceptionally if source cancelled
1236       */
# Line 1288 | Line 1288 | public class CompletableFutureTest exten
1288          f2.complete(two);
1289          checkCompletedWithWrappedCFException(g);
1290      }
1291 <        
1291 >
1292      /**
1293       * thenCombineAsync result completes exceptionally if either source cancelled
1294       */
# Line 1299 | Line 1299 | public class CompletableFutureTest exten
1299          assertTrue(f.cancel(true));
1300          f2.complete(two);
1301          checkCompletedWithWrappedCancellationException(g);
1302 <        
1302 >
1303          f = new CompletableFuture<Integer>();
1304          f2 = new CompletableFuture<Integer>();
1305          g = f.thenCombineAsync(f2, add);
# Line 1353 | Line 1353 | public class CompletableFutureTest exten
1353          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1354          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1355          FailingBiConsumer r = new FailingBiConsumer();
1356 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);      
1356 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1357          f.complete(one);
1358          checkIncomplete(g);
1359          f2.complete(two);
1360          checkCompletedWithWrappedCFException(g);
1361      }
1362 <        
1362 >
1363      /**
1364       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1365       */
# Line 1371 | Line 1371 | public class CompletableFutureTest exten
1371          assertTrue(f.cancel(true));
1372          f2.complete(two);
1373          checkCompletedWithWrappedCancellationException(g);
1374 <        
1374 >
1375          r = new AddAction();
1376          f = new CompletableFuture<Integer>();
1377          f2 = new CompletableFuture<Integer>();
# Line 1426 | Line 1426 | public class CompletableFutureTest exten
1426          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1427          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1428          FailingNoop r = new FailingNoop();
1429 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);      
1429 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1430          f.complete(one);
1431          checkIncomplete(g);
1432          f2.complete(two);
1433          checkCompletedWithWrappedCFException(g);
1434      }
1435 <        
1435 >
1436      /**
1437       * runAfterBothAsync result completes exceptionally if either source cancelled
1438       */
# Line 1444 | Line 1444 | public class CompletableFutureTest exten
1444          assertTrue(f.cancel(true));
1445          f2.complete(two);
1446          checkCompletedWithWrappedCancellationException(g);
1447 <        
1447 >
1448          r = new Noop();
1449          f = new CompletableFuture<Integer>();
1450          f2 = new CompletableFuture<Integer>();
# Line 1498 | Line 1498 | public class CompletableFutureTest exten
1498          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1499          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1500          FailingFunction r = new FailingFunction();
1501 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);      
1501 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
1502          f.complete(one);
1503          checkCompletedWithWrappedCFException(g);
1504      }
1505 <        
1505 >
1506      /**
1507       * applyToEitherAsync result completes exceptionally if either source cancelled
1508       */
# Line 1512 | Line 1512 | public class CompletableFutureTest exten
1512          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1513          assertTrue(f.cancel(true));
1514          checkCompletedWithWrappedCancellationException(g);
1515 <        
1515 >
1516          f = new CompletableFuture<Integer>();
1517          f2 = new CompletableFuture<Integer>();
1518          assertTrue(f2.cancel(true));
# Line 1570 | Line 1570 | public class CompletableFutureTest exten
1570          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1571          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1572          FailingConsumer r = new FailingConsumer();
1573 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);      
1573 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1574          f.complete(one);
1575          checkCompletedWithWrappedCFException(g);
1576      }
1577 <        
1577 >
1578      /**
1579       * acceptEitherAsync result completes exceptionally if either
1580       * source cancelled
# Line 1586 | Line 1586 | public class CompletableFutureTest exten
1586          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1587          assertTrue(f.cancel(true));
1588          checkCompletedWithWrappedCancellationException(g);
1589 <        
1589 >
1590          r = new IncAction();
1591          f = new CompletableFuture<Integer>();
1592          f2 = new CompletableFuture<Integer>();
# Line 1645 | Line 1645 | public class CompletableFutureTest exten
1645          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1646          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1647          FailingNoop r = new FailingNoop();
1648 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);      
1648 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1649          f.complete(one);
1650          checkCompletedWithWrappedCFException(g);
1651      }
1652 <        
1652 >
1653      /**
1654       * runAfterEitherAsync result completes exceptionally if either
1655       * source cancelled
# Line 1661 | Line 1661 | public class CompletableFutureTest exten
1661          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1662          assertTrue(f.cancel(true));
1663          checkCompletedWithWrappedCancellationException(g);
1664 <        
1664 >
1665          r = new Noop();
1666          f = new CompletableFuture<Integer>();
1667          f2 = new CompletableFuture<Integer>();
# Line 1671 | Line 1671 | public class CompletableFutureTest exten
1671      }
1672  
1673      /**
1674 <     * thenCompse result completes normally after normal completion of source
1674 >     * thenComposeAsync result completes normally after normal
1675 >     * completion of source
1676       */
1677      public void testThenComposeAsync() {
1678          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 1682 | Line 1683 | public class CompletableFutureTest exten
1683      }
1684  
1685      /**
1686 <     * thenComposeAsync result completes exceptionally after exceptional
1687 <     * completion of source
1686 >     * thenComposeAsync result completes exceptionally after
1687 >     * exceptional completion of source
1688       */
1689      public void testThenComposeAsync2() {
1690          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 1716 | Line 1717 | public class CompletableFutureTest exten
1717      }
1718  
1719  
1720 <    // aaync with explicit executors
1720 >    // async with explicit executors
1721  
1722      /**
1723       * thenRunAsync result completes normally after normal completion of source
# Line 1748 | Line 1749 | public class CompletableFutureTest exten
1749          try {
1750              g.join();
1751              shouldThrow();
1752 <        } catch(Exception ok) {
1752 >        } catch (Exception ok) {
1753          }
1754          checkCompletedWithWrappedCFException(g);
1755      }
# Line 1763 | Line 1764 | public class CompletableFutureTest exten
1764          f.complete(null);
1765          checkCompletedWithWrappedCFException(g);
1766      }
1767 <        
1767 >
1768      /**
1769       * thenRunAsync result completes exceptionally if source cancelled
1770       */
# Line 1806 | Line 1807 | public class CompletableFutureTest exten
1807          f.complete(null);
1808          checkCompletedWithWrappedCFException(g);
1809      }
1810 <        
1810 >
1811      /**
1812       * thenApplyAsync result completes exceptionally if source cancelled
1813       */
# Line 1852 | Line 1853 | public class CompletableFutureTest exten
1853          f.complete(null);
1854          checkCompletedWithWrappedCFException(g);
1855      }
1856 <        
1856 >
1857      /**
1858       * thenAcceptAsync result completes exceptionally if source cancelled
1859       */
# Line 1910 | Line 1911 | public class CompletableFutureTest exten
1911          f2.complete(two);
1912          checkCompletedWithWrappedCFException(g);
1913      }
1914 <        
1914 >
1915      /**
1916       * thenCombineAsync result completes exceptionally if either source cancelled
1917       */
# Line 1921 | Line 1922 | public class CompletableFutureTest exten
1922          assertTrue(f.cancel(true));
1923          f2.complete(two);
1924          checkCompletedWithWrappedCancellationException(g);
1925 <        
1925 >
1926          f = new CompletableFuture<Integer>();
1927          f2 = new CompletableFuture<Integer>();
1928          g = f.thenCombineAsync(f2, add, new ThreadExecutor());
# Line 1975 | Line 1976 | public class CompletableFutureTest exten
1976          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1977          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1978          FailingBiConsumer r = new FailingBiConsumer();
1979 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());      
1979 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1980          f.complete(one);
1981          checkIncomplete(g);
1982          f2.complete(two);
1983          checkCompletedWithWrappedCFException(g);
1984      }
1985 <        
1985 >
1986      /**
1987       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1988       */
# Line 1993 | Line 1994 | public class CompletableFutureTest exten
1994          assertTrue(f.cancel(true));
1995          f2.complete(two);
1996          checkCompletedWithWrappedCancellationException(g);
1997 <        
1997 >
1998          r = new AddAction();
1999          f = new CompletableFuture<Integer>();
2000          f2 = new CompletableFuture<Integer>();
# Line 2048 | Line 2049 | public class CompletableFutureTest exten
2049          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2050          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2051          FailingNoop r = new FailingNoop();
2052 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());      
2052 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2053          f.complete(one);
2054          checkIncomplete(g);
2055          f2.complete(two);
2056          checkCompletedWithWrappedCFException(g);
2057      }
2058 <        
2058 >
2059      /**
2060       * runAfterBothAsync result completes exceptionally if either source cancelled
2061       */
# Line 2066 | Line 2067 | public class CompletableFutureTest exten
2067          assertTrue(f.cancel(true));
2068          f2.complete(two);
2069          checkCompletedWithWrappedCancellationException(g);
2070 <        
2070 >
2071          r = new Noop();
2072          f = new CompletableFuture<Integer>();
2073          f2 = new CompletableFuture<Integer>();
# Line 2120 | Line 2121 | public class CompletableFutureTest exten
2121          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2122          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2123          FailingFunction r = new FailingFunction();
2124 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());      
2124 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2125          f.complete(one);
2126          checkCompletedWithWrappedCFException(g);
2127      }
2128 <        
2128 >
2129      /**
2130       * applyToEitherAsync result completes exceptionally if either source cancelled
2131       */
# Line 2134 | Line 2135 | public class CompletableFutureTest exten
2135          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2136          assertTrue(f.cancel(true));
2137          checkCompletedWithWrappedCancellationException(g);
2138 <        
2138 >
2139          f = new CompletableFuture<Integer>();
2140          f2 = new CompletableFuture<Integer>();
2141          assertTrue(f2.cancel(true));
# Line 2192 | Line 2193 | public class CompletableFutureTest exten
2193          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2194          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2195          FailingConsumer r = new FailingConsumer();
2196 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());      
2196 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2197          f.complete(one);
2198          checkCompletedWithWrappedCFException(g);
2199      }
2200 <        
2200 >
2201      /**
2202       * acceptEitherAsync result completes exceptionally if either
2203       * source cancelled
# Line 2208 | Line 2209 | public class CompletableFutureTest exten
2209          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2210          assertTrue(f.cancel(true));
2211          checkCompletedWithWrappedCancellationException(g);
2212 <        
2212 >
2213          r = new IncAction();
2214          f = new CompletableFuture<Integer>();
2215          f2 = new CompletableFuture<Integer>();
# Line 2267 | Line 2268 | public class CompletableFutureTest exten
2268          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2269          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2270          FailingNoop r = new FailingNoop();
2271 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());      
2271 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2272          f.complete(one);
2273          checkCompletedWithWrappedCFException(g);
2274      }
2275 <        
2275 >
2276      /**
2277       * runAfterEitherAsync result completes exceptionally if either
2278       * source cancelled
# Line 2283 | Line 2284 | public class CompletableFutureTest exten
2284          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2285          assertTrue(f.cancel(true));
2286          checkCompletedWithWrappedCancellationException(g);
2287 <        
2287 >
2288          r = new Noop();
2289          f = new CompletableFuture<Integer>();
2290          f2 = new CompletableFuture<Integer>();
# Line 2293 | Line 2294 | public class CompletableFutureTest exten
2294      }
2295  
2296      /**
2297 <     * thenCompse result completes normally after normal completion of source
2297 >     * thenComposeAsync result completes normally after normal
2298 >     * completion of source
2299       */
2300      public void testThenComposeAsyncE() {
2301          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 2304 | Line 2306 | public class CompletableFutureTest exten
2306      }
2307  
2308      /**
2309 <     * thenComposeAsync result completes exceptionally after exceptional
2310 <     * completion of source
2309 >     * thenComposeAsync result completes exceptionally after
2310 >     * exceptional completion of source
2311       */
2312      public void testThenComposeAsync2E() {
2313          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 2337 | Line 2339 | public class CompletableFutureTest exten
2339          checkCompletedWithWrappedCancellationException(g);
2340      }
2341  
2342 <    // other static methods    
2342 >    // other static methods
2343  
2344      /**
2345       * allOf(no component futures) returns a future completed normally
# Line 2354 | Line 2356 | public class CompletableFutureTest exten
2356      public void testAllOf() throws Exception {
2357          for (int k = 1; k < 20; ++k) {
2358              CompletableFuture[] fs = new CompletableFuture[k];
2359 <            for (int i = 0; i < k; ++i)
2359 >            for (int i = 0; i < k; ++i)
2360                  fs[i] = new CompletableFuture<Integer>();
2361              CompletableFuture<?> f = CompletableFuture.allOf(fs);
2362              for (int i = 0; i < k; ++i) {
# Line 2380 | Line 2382 | public class CompletableFutureTest exten
2382      public void testAnyOf() throws Exception {
2383          for (int k = 1; k < 20; ++k) {
2384              CompletableFuture[] fs = new CompletableFuture[k];
2385 <            for (int i = 0; i < k; ++i)
2385 >            for (int i = 0; i < k; ++i)
2386                  fs[i] = new CompletableFuture<Integer>();
2387              CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2388              checkIncomplete(f);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines