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.6 by jsr166, Fri Mar 22 16:10:19 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 457 | Line 457 | public class CompletableFutureTest exten
457      }
458  
459      // seq conmpletion methods
460 <    
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 1748 | Line 1748 | public class CompletableFutureTest exten
1748          try {
1749              g.join();
1750              shouldThrow();
1751 <        } catch(Exception ok) {
1751 >        } catch (Exception ok) {
1752          }
1753          checkCompletedWithWrappedCFException(g);
1754      }
# Line 1763 | Line 1763 | public class CompletableFutureTest exten
1763          f.complete(null);
1764          checkCompletedWithWrappedCFException(g);
1765      }
1766 <        
1766 >
1767      /**
1768       * thenRunAsync result completes exceptionally if source cancelled
1769       */
# Line 1806 | Line 1806 | public class CompletableFutureTest exten
1806          f.complete(null);
1807          checkCompletedWithWrappedCFException(g);
1808      }
1809 <        
1809 >
1810      /**
1811       * thenApplyAsync result completes exceptionally if source cancelled
1812       */
# Line 1852 | Line 1852 | public class CompletableFutureTest exten
1852          f.complete(null);
1853          checkCompletedWithWrappedCFException(g);
1854      }
1855 <        
1855 >
1856      /**
1857       * thenAcceptAsync result completes exceptionally if source cancelled
1858       */
# Line 1910 | Line 1910 | public class CompletableFutureTest exten
1910          f2.complete(two);
1911          checkCompletedWithWrappedCFException(g);
1912      }
1913 <        
1913 >
1914      /**
1915       * thenCombineAsync result completes exceptionally if either source cancelled
1916       */
# Line 1921 | Line 1921 | public class CompletableFutureTest exten
1921          assertTrue(f.cancel(true));
1922          f2.complete(two);
1923          checkCompletedWithWrappedCancellationException(g);
1924 <        
1924 >
1925          f = new CompletableFuture<Integer>();
1926          f2 = new CompletableFuture<Integer>();
1927          g = f.thenCombineAsync(f2, add, new ThreadExecutor());
# Line 1975 | Line 1975 | public class CompletableFutureTest exten
1975          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1976          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1977          FailingBiConsumer r = new FailingBiConsumer();
1978 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());      
1978 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1979          f.complete(one);
1980          checkIncomplete(g);
1981          f2.complete(two);
1982          checkCompletedWithWrappedCFException(g);
1983      }
1984 <        
1984 >
1985      /**
1986       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1987       */
# Line 1993 | Line 1993 | public class CompletableFutureTest exten
1993          assertTrue(f.cancel(true));
1994          f2.complete(two);
1995          checkCompletedWithWrappedCancellationException(g);
1996 <        
1996 >
1997          r = new AddAction();
1998          f = new CompletableFuture<Integer>();
1999          f2 = new CompletableFuture<Integer>();
# Line 2048 | Line 2048 | public class CompletableFutureTest exten
2048          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2049          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2050          FailingNoop r = new FailingNoop();
2051 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());      
2051 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2052          f.complete(one);
2053          checkIncomplete(g);
2054          f2.complete(two);
2055          checkCompletedWithWrappedCFException(g);
2056      }
2057 <        
2057 >
2058      /**
2059       * runAfterBothAsync result completes exceptionally if either source cancelled
2060       */
# Line 2066 | Line 2066 | public class CompletableFutureTest exten
2066          assertTrue(f.cancel(true));
2067          f2.complete(two);
2068          checkCompletedWithWrappedCancellationException(g);
2069 <        
2069 >
2070          r = new Noop();
2071          f = new CompletableFuture<Integer>();
2072          f2 = new CompletableFuture<Integer>();
# Line 2120 | Line 2120 | public class CompletableFutureTest exten
2120          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2121          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2122          FailingFunction r = new FailingFunction();
2123 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());      
2123 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2124          f.complete(one);
2125          checkCompletedWithWrappedCFException(g);
2126      }
2127 <        
2127 >
2128      /**
2129       * applyToEitherAsync result completes exceptionally if either source cancelled
2130       */
# Line 2134 | Line 2134 | public class CompletableFutureTest exten
2134          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2135          assertTrue(f.cancel(true));
2136          checkCompletedWithWrappedCancellationException(g);
2137 <        
2137 >
2138          f = new CompletableFuture<Integer>();
2139          f2 = new CompletableFuture<Integer>();
2140          assertTrue(f2.cancel(true));
# Line 2192 | Line 2192 | public class CompletableFutureTest exten
2192          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2193          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2194          FailingConsumer r = new FailingConsumer();
2195 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());      
2195 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2196          f.complete(one);
2197          checkCompletedWithWrappedCFException(g);
2198      }
2199 <        
2199 >
2200      /**
2201       * acceptEitherAsync result completes exceptionally if either
2202       * source cancelled
# Line 2208 | Line 2208 | public class CompletableFutureTest exten
2208          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2209          assertTrue(f.cancel(true));
2210          checkCompletedWithWrappedCancellationException(g);
2211 <        
2211 >
2212          r = new IncAction();
2213          f = new CompletableFuture<Integer>();
2214          f2 = new CompletableFuture<Integer>();
# Line 2267 | Line 2267 | public class CompletableFutureTest exten
2267          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2268          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2269          FailingNoop r = new FailingNoop();
2270 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());      
2270 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2271          f.complete(one);
2272          checkCompletedWithWrappedCFException(g);
2273      }
2274 <        
2274 >
2275      /**
2276       * runAfterEitherAsync result completes exceptionally if either
2277       * source cancelled
# Line 2283 | Line 2283 | public class CompletableFutureTest exten
2283          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2284          assertTrue(f.cancel(true));
2285          checkCompletedWithWrappedCancellationException(g);
2286 <        
2286 >
2287          r = new Noop();
2288          f = new CompletableFuture<Integer>();
2289          f2 = new CompletableFuture<Integer>();
# Line 2337 | Line 2337 | public class CompletableFutureTest exten
2337          checkCompletedWithWrappedCancellationException(g);
2338      }
2339  
2340 <    // other static methods    
2340 >    // other static methods
2341  
2342      /**
2343       * allOf(no component futures) returns a future completed normally
# Line 2354 | Line 2354 | public class CompletableFutureTest exten
2354      public void testAllOf() throws Exception {
2355          for (int k = 1; k < 20; ++k) {
2356              CompletableFuture[] fs = new CompletableFuture[k];
2357 <            for (int i = 0; i < k; ++i)
2357 >            for (int i = 0; i < k; ++i)
2358                  fs[i] = new CompletableFuture<Integer>();
2359              CompletableFuture<?> f = CompletableFuture.allOf(fs);
2360              for (int i = 0; i < k; ++i) {
# Line 2380 | Line 2380 | public class CompletableFutureTest exten
2380      public void testAnyOf() throws Exception {
2381          for (int k = 1; k < 20; ++k) {
2382              CompletableFuture[] fs = new CompletableFuture[k];
2383 <            for (int i = 0; i < k; ++i)
2383 >            for (int i = 0; i < k; ++i)
2384                  fs[i] = new CompletableFuture<Integer>();
2385              CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2386              checkIncomplete(f);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines