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.19 by jsr166, Sun Apr 7 15:04:14 2013 UTC

# Line 53 | Line 53 | public class CompletableFutureTest exten
53          catch (Throwable fail) { threadUnexpectedException(fail); }
54      }
55  
56 <    void checkCompletedNormally(CompletableFuture<?> f, Object value) {
56 >    <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
57          try {
58              assertEquals(value, f.join());
59          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 75 | Line 75 | public class CompletableFutureTest exten
75          try {
76              f.join();
77              shouldThrow();
78 <        } catch (Throwable ex) {
79 <            assertTrue(ex instanceof CompletionException &&
80 <                       ((CompletionException)ex).getCause() instanceof CFException);
78 >        } catch (CompletionException success) {
79 >            assertTrue(success.getCause() instanceof CFException);
80          }
81          try {
82              f.getNow(null);
83              shouldThrow();
84 <        } catch (Throwable ex) {
85 <            assertTrue(ex instanceof CompletionException &&
87 <                       ((CompletionException)ex).getCause() instanceof CFException);
84 >        } catch (CompletionException success) {
85 >            assertTrue(success.getCause() instanceof CFException);
86          }
87          try {
88              f.get();
89              shouldThrow();
90 <        } catch (Throwable ex) {
91 <            assertTrue(ex instanceof ExecutionException &&
92 <                       ((ExecutionException)ex).getCause() instanceof CFException);
95 <        }
90 >        } catch (ExecutionException success) {
91 >            assertTrue(success.getCause() instanceof CFException);
92 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
93          try {
94              f.get(0L, SECONDS);
95              shouldThrow();
96 <        } catch (Throwable ex) {
97 <            assertTrue(ex instanceof ExecutionException &&
98 <                       ((ExecutionException)ex).getCause() instanceof CFException);
102 <        }
96 >        } catch (ExecutionException success) {
97 >            assertTrue(success.getCause() instanceof CFException);
98 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
99          assertTrue(f.isDone());
100          assertFalse(f.isCancelled());
101 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
102      }
103  
104      void checkCancelled(CompletableFuture<?> f) {
105          try {
106              f.join();
107              shouldThrow();
108 <        } catch (Throwable ex) {
112 <            assertTrue(ex instanceof CancellationException);
113 <        }
108 >        } catch (CancellationException success) {}
109          try {
110              f.getNow(null);
111              shouldThrow();
112 <        } catch (Throwable ex) {
118 <            assertTrue(ex instanceof CancellationException);
119 <        }
112 >        } catch (CancellationException success) {}
113          try {
114              f.get();
115              shouldThrow();
116 <        } catch (Throwable ex) {
117 <            assertTrue(ex instanceof CancellationException);
125 <        }
116 >        } catch (CancellationException success) {
117 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
118          try {
119              f.get(0L, SECONDS);
120              shouldThrow();
121 <        } catch (Throwable ex) {
122 <            assertTrue(ex instanceof CancellationException);
131 <        }
121 >        } catch (CancellationException success) {
122 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
123          assertTrue(f.isDone());
124          assertTrue(f.isCancelled());
125 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
126      }
127  
128      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
129          try {
130              f.join();
131              shouldThrow();
132 <        } catch (Throwable ex) {
133 <            assertTrue(ex instanceof CompletionException &&
142 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
132 >        } catch (CompletionException success) {
133 >            assertTrue(success.getCause() instanceof CancellationException);
134          }
135          try {
136              f.getNow(null);
137              shouldThrow();
138 <        } catch (Throwable ex) {
139 <            assertTrue(ex instanceof CompletionException &&
149 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
138 >        } catch (CompletionException success) {
139 >            assertTrue(success.getCause() instanceof CancellationException);
140          }
141          try {
142              f.get();
143              shouldThrow();
144 <        } catch (Throwable ex) {
145 <            assertTrue(ex instanceof ExecutionException &&
146 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
157 <        }
144 >        } catch (ExecutionException success) {
145 >            assertTrue(success.getCause() instanceof CancellationException);
146 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
147          try {
148              f.get(0L, SECONDS);
149              shouldThrow();
150 <        } catch (Throwable ex) {
151 <            assertTrue(ex instanceof ExecutionException &&
152 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
164 <        }
150 >        } catch (ExecutionException success) {
151 >            assertTrue(success.getCause() instanceof CancellationException);
152 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
153          assertTrue(f.isDone());
154          assertFalse(f.isCancelled());
155 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
156      }
157  
158      /**
# Line 249 | Line 238 | public class CompletableFutureTest exten
238          f.obtrudeException(new CFException());
239          checkCompletedWithWrappedCFException(f);
240      }
241 <    
241 >
242      /**
243       * getNumberOfDependents returns number of dependent tasks
244       */
# Line 285 | Line 274 | public class CompletableFutureTest exten
274          assertTrue(f.toString().contains("[Completed exceptionally]"));
275      }
276  
277 <    static final Supplier<Integer> supplyOne =
277 >    /**
278 >     * completedFuture returns a completed CompletableFuture with given value
279 >     */
280 >    public void testCompletedFuture() {
281 >        CompletableFuture<String> f = CompletableFuture.completedFuture("test");
282 >        checkCompletedNormally(f, "test");
283 >    }
284 >
285 >    // Choose non-commutative actions for better coverage
286 >
287 >    static final Supplier<Integer> supplyOne =
288          () -> Integer.valueOf(1);
289 <    static final Function<Integer, Integer> inc =
289 >    static final Function<Integer, Integer> inc =
290          (Integer x) -> Integer.valueOf(x.intValue() + 1);
291 <    static final BiFunction<Integer, Integer, Integer> add =
292 <        (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
291 >    static final BiFunction<Integer, Integer, Integer> subtract =
292 >        (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue());
293      static final class IncAction implements Consumer<Integer> {
294          int value;
295          public void accept(Integer x) { value = x.intValue() + 1; }
296      }
297      static final class AddAction implements BiConsumer<Integer, Integer> {
298          int value;
299 <        public void accept(Integer x, Integer y) {
300 <            value = x.intValue() + y.intValue();
299 >        public void accept(Integer x, Integer y) {
300 >            value = x.intValue() + y.intValue();
301          }
302      }
303      static final class Noop implements Runnable {
# Line 331 | Line 330 | public class CompletableFutureTest exten
330          public void run() { ran = true; throw new CFException(); }
331      }
332  
333 <    static final class CompletableFutureInc implements Function<Integer, CompletableFuture<Integer>> {
333 >    static final class CompletableFutureInc
334 >        implements Function<Integer, CompletableFuture<Integer>> {
335          public CompletableFuture<Integer> apply(Integer x) {
336              CompletableFuture<Integer> f = new CompletableFuture<Integer>();
337              f.complete(Integer.valueOf(x.intValue() + 1));
# Line 339 | Line 339 | public class CompletableFutureTest exten
339          }
340      }
341  
342 <    static final class FailingCompletableFutureFunction implements Function<Integer, CompletableFuture<Integer>> {
342 >    static final class FailingCompletableFutureFunction
343 >        implements Function<Integer, CompletableFuture<Integer>> {
344          boolean ran;
345          public CompletableFuture<Integer> apply(Integer x) {
346              ran = true; throw new CFException();
347          }
348      }
349 <    
349 >
350      // Used for explicit executor tests
351      static final class ThreadExecutor implements Executor {
352 +        AtomicInteger count = new AtomicInteger(0);
353 +
354          public void execute(Runnable r) {
355 +            count.getAndIncrement();
356              new Thread(r).start();
357          }
358      }
# Line 358 | Line 362 | public class CompletableFutureTest exten
362      }
363  
364      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
365 <        public Integer apply(Integer x, Throwable t) {
365 >        boolean ran;
366 >        public Integer apply(Integer x, Throwable t) {
367 >            ran = true;
368              return (t == null) ? two : three;
369          }
370      }
# Line 387 | Line 393 | public class CompletableFutureTest exten
393       * normal or exceptional completion of source
394       */
395      public void testHandle() {
396 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
397 <        IntegerHandler r = new IntegerHandler();
398 <        CompletableFuture<Integer> g = f.handle(r);
396 >        CompletableFuture<Integer> f, g;
397 >        IntegerHandler r;
398 >
399 >        f = new CompletableFuture<Integer>();
400          f.completeExceptionally(new CFException());
401 +        g = f.handle(r = new IntegerHandler());
402 +        assertTrue(r.ran);
403          checkCompletedNormally(g, three);
404  
405          f = new CompletableFuture<Integer>();
406 <        r = new IntegerHandler();
407 <        g = f.handle(r);
406 >        g = f.handle(r = new IntegerHandler());
407 >        assertFalse(r.ran);
408 >        f.completeExceptionally(new CFException());
409 >        checkCompletedNormally(g, three);
410 >        assertTrue(r.ran);
411 >
412 >        f = new CompletableFuture<Integer>();
413 >        f.complete(one);
414 >        g = f.handle(r = new IntegerHandler());
415 >        assertTrue(r.ran);
416 >        checkCompletedNormally(g, two);
417 >
418 >        f = new CompletableFuture<Integer>();
419 >        g = f.handle(r = new IntegerHandler());
420 >        assertFalse(r.ran);
421          f.complete(one);
422 +        assertTrue(r.ran);
423          checkCompletedNormally(g, two);
424      }
425  
# Line 408 | Line 431 | public class CompletableFutureTest exten
431          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
432          assertNull(f.join());
433          assertTrue(r.ran);
434 +        checkCompletedNormally(f, null);
435      }
436  
437      /**
# Line 415 | Line 439 | public class CompletableFutureTest exten
439       */
440      public void testRunAsync2() {
441          Noop r = new Noop();
442 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor());
442 >        ThreadExecutor exec = new ThreadExecutor();
443 >        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
444          assertNull(f.join());
445          assertTrue(r.ran);
446 +        checkCompletedNormally(f, null);
447 +        assertEquals(1, exec.count.get());
448      }
449  
450      /**
# Line 434 | Line 461 | public class CompletableFutureTest exten
461       * supplyAsync completes with result of supplier
462       */
463      public void testSupplyAsync() {
464 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne);
464 >        CompletableFuture<Integer> f;
465 >        f = CompletableFuture.supplyAsync(supplyOne);
466          assertEquals(f.join(), one);
467 +        checkCompletedNormally(f, one);
468      }
469  
470      /**
471       * supplyAsync with executor completes with result of supplier
472       */
473      public void testSupplyAsync2() {
474 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
474 >        CompletableFuture<Integer> f;
475 >        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
476          assertEquals(f.join(), one);
477 +        checkCompletedNormally(f, one);
478      }
479  
480      /**
# Line 456 | Line 487 | public class CompletableFutureTest exten
487          assertTrue(r.ran);
488      }
489  
490 <    // seq conmpletion methods
491 <    
490 >    // seq completion methods
491 >
492      /**
493       * thenRun result completes normally after normal completion of source
494       */
# Line 599 | Line 630 | public class CompletableFutureTest exten
630  
631  
632      /**
633 <     * thenCombine result completes normally after normal completion of sources
633 >     * thenCombine result completes normally after normal completion
634 >     * of sources
635       */
636      public void testThenCombine() {
637 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
606 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
607 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
608 <        f.complete(one);
609 <        checkIncomplete(g);
610 <        f2.complete(two);
611 <        checkCompletedNormally(g, three);
637 >        CompletableFuture<Integer> f, g, h;
638  
639          f = new CompletableFuture<Integer>();
640 <        f.complete(one);
641 <        f2 = new CompletableFuture<Integer>();
642 <        g = f.thenCombine(f2, add);
643 <        checkIncomplete(g);
644 <        f2.complete(two);
645 <        checkCompletedNormally(g, three);
640 >        g = new CompletableFuture<Integer>();
641 >        h = f.thenCombine(g, subtract);
642 >        f.complete(3);
643 >        checkIncomplete(h);
644 >        g.complete(1);
645 >        checkCompletedNormally(h, 2);
646 >
647 >        f = new CompletableFuture<Integer>();
648 >        g = new CompletableFuture<Integer>();
649 >        h = f.thenCombine(g, subtract);
650 >        g.complete(1);
651 >        checkIncomplete(h);
652 >        f.complete(3);
653 >        checkCompletedNormally(h, 2);
654 >
655 >        f = new CompletableFuture<Integer>();
656 >        g = new CompletableFuture<Integer>();
657 >        g.complete(1);
658 >        f.complete(3);
659 >        h = f.thenCombine(g, subtract);
660 >        checkCompletedNormally(h, 2);
661      }
662  
663      /**
# Line 624 | Line 665 | public class CompletableFutureTest exten
665       * completion of either source
666       */
667      public void testThenCombine2() {
668 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
669 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
670 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
668 >        CompletableFuture<Integer> f, g, h;
669 >
670 >        f = new CompletableFuture<Integer>();
671 >        g = new CompletableFuture<Integer>();
672 >        h = f.thenCombine(g, subtract);
673          f.completeExceptionally(new CFException());
674 <        f2.complete(two);
675 <        checkCompletedWithWrappedCFException(g);
674 >        checkIncomplete(h);
675 >        g.complete(1);
676 >        checkCompletedWithWrappedCFException(h);
677  
678          f = new CompletableFuture<Integer>();
679 <        f.complete(one);
680 <        f2 = new CompletableFuture<Integer>();
681 <        g = f.thenCombine(f2, add);
682 <        f2.completeExceptionally(new CFException());
683 <        checkCompletedWithWrappedCFException(g);
679 >        g = new CompletableFuture<Integer>();
680 >        h = f.thenCombine(g, subtract);
681 >        g.completeExceptionally(new CFException());
682 >        checkIncomplete(h);
683 >        f.complete(3);
684 >        checkCompletedWithWrappedCFException(h);
685 >
686 >        f = new CompletableFuture<Integer>();
687 >        g = new CompletableFuture<Integer>();
688 >        f.complete(3);
689 >        g.completeExceptionally(new CFException());
690 >        h = f.thenCombine(g, subtract);
691 >        checkCompletedWithWrappedCFException(h);
692 >
693 >        f = new CompletableFuture<Integer>();
694 >        g = new CompletableFuture<Integer>();
695 >        f.completeExceptionally(new CFException());
696 >        g.complete(3);
697 >        h = f.thenCombine(g, subtract);
698 >        checkCompletedWithWrappedCFException(h);
699      }
700  
701      /**
# Line 649 | Line 708 | public class CompletableFutureTest exten
708          CompletableFuture<Integer> g = f.thenCombine(f2, r);
709          f.complete(one);
710          checkIncomplete(g);
711 +        assertFalse(r.ran);
712          f2.complete(two);
713          checkCompletedWithWrappedCFException(g);
714 +        assertTrue(r.ran);
715      }
716  
717      /**
718       * thenCombine result completes exceptionally if either source cancelled
719       */
720      public void testThenCombine4() {
721 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
722 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
723 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
721 >        CompletableFuture<Integer> f, g, h;
722 >
723 >        f = new CompletableFuture<Integer>();
724 >        g = new CompletableFuture<Integer>();
725 >        h = f.thenCombine(g, subtract);
726          assertTrue(f.cancel(true));
727 <        f2.complete(two);
728 <        checkCompletedWithWrappedCancellationException(g);
727 >        checkIncomplete(h);
728 >        g.complete(1);
729 >        checkCompletedWithWrappedCancellationException(h);
730 >
731          f = new CompletableFuture<Integer>();
732 <        f2 = new CompletableFuture<Integer>();
733 <        g = f.thenCombine(f2, add);
734 <        f.complete(one);
735 <        assertTrue(f2.cancel(true));
736 <        checkCompletedWithWrappedCancellationException(g);
732 >        g = new CompletableFuture<Integer>();
733 >        h = f.thenCombine(g, subtract);
734 >        assertTrue(g.cancel(true));
735 >        checkIncomplete(h);
736 >        f.complete(3);
737 >        checkCompletedWithWrappedCancellationException(h);
738 >
739 >        f = new CompletableFuture<Integer>();
740 >        g = new CompletableFuture<Integer>();
741 >        assertTrue(f.cancel(true));
742 >        assertTrue(g.cancel(true));
743 >        h = f.thenCombine(g, subtract);
744 >        checkCompletedWithWrappedCancellationException(h);
745      }
746  
747      /**
# Line 1126 | Line 1199 | public class CompletableFutureTest exten
1199          try {
1200              g.join();
1201              shouldThrow();
1202 <        } catch(Exception ok) {
1202 >        } catch (Exception ok) {
1203          }
1204          checkCompletedWithWrappedCFException(g);
1205      }
# Line 1141 | Line 1214 | public class CompletableFutureTest exten
1214          f.complete(null);
1215          checkCompletedWithWrappedCFException(g);
1216      }
1217 <        
1217 >
1218      /**
1219       * thenRunAsync result completes exceptionally if source cancelled
1220       */
# Line 1184 | Line 1257 | public class CompletableFutureTest exten
1257          f.complete(null);
1258          checkCompletedWithWrappedCFException(g);
1259      }
1260 <        
1260 >
1261      /**
1262       * thenApplyAsync result completes exceptionally if source cancelled
1263       */
# Line 1230 | Line 1303 | public class CompletableFutureTest exten
1303          f.complete(null);
1304          checkCompletedWithWrappedCFException(g);
1305      }
1306 <        
1306 >
1307      /**
1308       * thenAcceptAsync result completes exceptionally if source cancelled
1309       */
# Line 1241 | Line 1314 | public class CompletableFutureTest exten
1314          assertTrue(f.cancel(true));
1315          checkCompletedWithWrappedCancellationException(g);
1316      }
1317 +
1318      /**
1319       * thenCombineAsync result completes normally after normal
1320       * completion of sources
1321       */
1322      public void testThenCombineAsync() {
1323 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1324 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1325 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1326 <        f.complete(one);
1327 <        checkIncomplete(g);
1328 <        f2.complete(two);
1329 <        checkCompletedNormally(g, three);
1323 >        CompletableFuture<Integer> f, g, h;
1324 >
1325 >        f = new CompletableFuture<Integer>();
1326 >        g = new CompletableFuture<Integer>();
1327 >        h = f.thenCombineAsync(g, subtract);
1328 >        f.complete(3);
1329 >        checkIncomplete(h);
1330 >        g.complete(1);
1331 >        checkCompletedNormally(h, 2);
1332 >
1333 >        f = new CompletableFuture<Integer>();
1334 >        g = new CompletableFuture<Integer>();
1335 >        h = f.thenCombineAsync(g, subtract);
1336 >        g.complete(1);
1337 >        checkIncomplete(h);
1338 >        f.complete(3);
1339 >        checkCompletedNormally(h, 2);
1340 >
1341 >        f = new CompletableFuture<Integer>();
1342 >        g = new CompletableFuture<Integer>();
1343 >        g.complete(1);
1344 >        f.complete(3);
1345 >        h = f.thenCombineAsync(g, subtract);
1346 >        checkCompletedNormally(h, 2);
1347      }
1348  
1349      /**
1350       * thenCombineAsync result completes exceptionally after exceptional
1351 <     * completion of source
1351 >     * completion of either source
1352       */
1353      public void testThenCombineAsync2() {
1354 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1355 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1356 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1354 >        CompletableFuture<Integer> f, g, h;
1355 >
1356 >        f = new CompletableFuture<Integer>();
1357 >        g = new CompletableFuture<Integer>();
1358 >        h = f.thenCombineAsync(g, subtract);
1359          f.completeExceptionally(new CFException());
1360 <        f2.complete(two);
1361 <        checkCompletedWithWrappedCFException(g);
1360 >        checkIncomplete(h);
1361 >        g.complete(1);
1362 >        checkCompletedWithWrappedCFException(h);
1363  
1364          f = new CompletableFuture<Integer>();
1365 <        f2 = new CompletableFuture<Integer>();
1366 <        g = f.thenCombineAsync(f2, add);
1367 <        f.complete(one);
1368 <        f2.completeExceptionally(new CFException());
1369 <        checkCompletedWithWrappedCFException(g);
1365 >        g = new CompletableFuture<Integer>();
1366 >        h = f.thenCombineAsync(g, subtract);
1367 >        g.completeExceptionally(new CFException());
1368 >        checkIncomplete(h);
1369 >        f.complete(3);
1370 >        checkCompletedWithWrappedCFException(h);
1371 >
1372 >        f = new CompletableFuture<Integer>();
1373 >        g = new CompletableFuture<Integer>();
1374 >        g.completeExceptionally(new CFException());
1375 >        f.complete(3);
1376 >        h = f.thenCombineAsync(g, subtract);
1377 >        checkCompletedWithWrappedCFException(h);
1378      }
1379  
1380      /**
# Line 1285 | Line 1387 | public class CompletableFutureTest exten
1387          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
1388          f.complete(one);
1389          checkIncomplete(g);
1390 +        assertFalse(r.ran);
1391          f2.complete(two);
1392          checkCompletedWithWrappedCFException(g);
1393 +        assertTrue(r.ran);
1394      }
1395 <        
1395 >
1396      /**
1397       * thenCombineAsync result completes exceptionally if either source cancelled
1398       */
1399      public void testThenCombineAsync4() {
1400 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1401 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1402 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1400 >        CompletableFuture<Integer> f, g, h;
1401 >
1402 >        f = new CompletableFuture<Integer>();
1403 >        g = new CompletableFuture<Integer>();
1404 >        h = f.thenCombineAsync(g, subtract);
1405          assertTrue(f.cancel(true));
1406 <        f2.complete(two);
1407 <        checkCompletedWithWrappedCancellationException(g);
1408 <        
1406 >        checkIncomplete(h);
1407 >        g.complete(1);
1408 >        checkCompletedWithWrappedCancellationException(h);
1409 >
1410          f = new CompletableFuture<Integer>();
1411 <        f2 = new CompletableFuture<Integer>();
1412 <        g = f.thenCombineAsync(f2, add);
1413 <        f.complete(one);
1414 <        assertTrue(f2.cancel(true));
1415 <        checkCompletedWithWrappedCancellationException(g);
1411 >        g = new CompletableFuture<Integer>();
1412 >        h = f.thenCombineAsync(g, subtract);
1413 >        assertTrue(g.cancel(true));
1414 >        checkIncomplete(h);
1415 >        f.complete(3);
1416 >        checkCompletedWithWrappedCancellationException(h);
1417 >
1418 >        f = new CompletableFuture<Integer>();
1419 >        g = new CompletableFuture<Integer>();
1420 >        g.complete(3);
1421 >        assertTrue(f.cancel(true));
1422 >        h = f.thenCombineAsync(g, subtract);
1423 >        checkCompletedWithWrappedCancellationException(h);
1424 >
1425 >        f = new CompletableFuture<Integer>();
1426 >        g = new CompletableFuture<Integer>();
1427 >        f.complete(3);
1428 >        assertTrue(g.cancel(true));
1429 >        h = f.thenCombineAsync(g, subtract);
1430 >        checkCompletedWithWrappedCancellationException(h);
1431      }
1432  
1433      /**
# Line 1353 | Line 1475 | public class CompletableFutureTest exten
1475          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1476          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1477          FailingBiConsumer r = new FailingBiConsumer();
1478 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);      
1478 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1479          f.complete(one);
1480          checkIncomplete(g);
1481          f2.complete(two);
1482          checkCompletedWithWrappedCFException(g);
1483      }
1484 <        
1484 >
1485      /**
1486       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1487       */
# Line 1371 | Line 1493 | public class CompletableFutureTest exten
1493          assertTrue(f.cancel(true));
1494          f2.complete(two);
1495          checkCompletedWithWrappedCancellationException(g);
1496 <        
1496 >
1497          r = new AddAction();
1498          f = new CompletableFuture<Integer>();
1499          f2 = new CompletableFuture<Integer>();
# Line 1426 | Line 1548 | public class CompletableFutureTest exten
1548          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1549          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1550          FailingNoop r = new FailingNoop();
1551 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);      
1551 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1552          f.complete(one);
1553          checkIncomplete(g);
1554          f2.complete(two);
1555          checkCompletedWithWrappedCFException(g);
1556      }
1557 <        
1557 >
1558      /**
1559       * runAfterBothAsync result completes exceptionally if either source cancelled
1560       */
# Line 1444 | Line 1566 | public class CompletableFutureTest exten
1566          assertTrue(f.cancel(true));
1567          f2.complete(two);
1568          checkCompletedWithWrappedCancellationException(g);
1569 <        
1569 >
1570          r = new Noop();
1571          f = new CompletableFuture<Integer>();
1572          f2 = new CompletableFuture<Integer>();
# Line 1498 | Line 1620 | public class CompletableFutureTest exten
1620          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1621          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1622          FailingFunction r = new FailingFunction();
1623 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);      
1623 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
1624          f.complete(one);
1625          checkCompletedWithWrappedCFException(g);
1626      }
1627 <        
1627 >
1628      /**
1629       * applyToEitherAsync result completes exceptionally if either source cancelled
1630       */
# Line 1512 | Line 1634 | public class CompletableFutureTest exten
1634          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1635          assertTrue(f.cancel(true));
1636          checkCompletedWithWrappedCancellationException(g);
1637 <        
1637 >
1638          f = new CompletableFuture<Integer>();
1639          f2 = new CompletableFuture<Integer>();
1640          assertTrue(f2.cancel(true));
# Line 1570 | Line 1692 | public class CompletableFutureTest exten
1692          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1693          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1694          FailingConsumer r = new FailingConsumer();
1695 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);      
1695 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1696          f.complete(one);
1697          checkCompletedWithWrappedCFException(g);
1698      }
1699 <        
1699 >
1700      /**
1701       * acceptEitherAsync result completes exceptionally if either
1702       * source cancelled
# Line 1586 | Line 1708 | public class CompletableFutureTest exten
1708          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
1709          assertTrue(f.cancel(true));
1710          checkCompletedWithWrappedCancellationException(g);
1711 <        
1711 >
1712          r = new IncAction();
1713          f = new CompletableFuture<Integer>();
1714          f2 = new CompletableFuture<Integer>();
# Line 1645 | Line 1767 | public class CompletableFutureTest exten
1767          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1768          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1769          FailingNoop r = new FailingNoop();
1770 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);      
1770 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1771          f.complete(one);
1772          checkCompletedWithWrappedCFException(g);
1773      }
1774 <        
1774 >
1775      /**
1776       * runAfterEitherAsync result completes exceptionally if either
1777       * source cancelled
# Line 1661 | Line 1783 | public class CompletableFutureTest exten
1783          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
1784          assertTrue(f.cancel(true));
1785          checkCompletedWithWrappedCancellationException(g);
1786 <        
1786 >
1787          r = new Noop();
1788          f = new CompletableFuture<Integer>();
1789          f2 = new CompletableFuture<Integer>();
# Line 1671 | Line 1793 | public class CompletableFutureTest exten
1793      }
1794  
1795      /**
1796 <     * thenCompse result completes normally after normal completion of source
1796 >     * thenComposeAsync result completes normally after normal
1797 >     * completion of source
1798       */
1799      public void testThenComposeAsync() {
1800          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 1682 | Line 1805 | public class CompletableFutureTest exten
1805      }
1806  
1807      /**
1808 <     * thenComposeAsync result completes exceptionally after exceptional
1809 <     * completion of source
1808 >     * thenComposeAsync result completes exceptionally after
1809 >     * exceptional completion of source
1810       */
1811      public void testThenComposeAsync2() {
1812          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 1716 | Line 1839 | public class CompletableFutureTest exten
1839      }
1840  
1841  
1842 <    // aaync with explicit executors
1842 >    // async with explicit executors
1843  
1844      /**
1845       * thenRunAsync result completes normally after normal completion of source
# Line 1748 | Line 1871 | public class CompletableFutureTest exten
1871          try {
1872              g.join();
1873              shouldThrow();
1874 <        } catch(Exception ok) {
1874 >        } catch (Exception ok) {
1875          }
1876          checkCompletedWithWrappedCFException(g);
1877      }
# Line 1763 | Line 1886 | public class CompletableFutureTest exten
1886          f.complete(null);
1887          checkCompletedWithWrappedCFException(g);
1888      }
1889 <        
1889 >
1890      /**
1891       * thenRunAsync result completes exceptionally if source cancelled
1892       */
# Line 1806 | Line 1929 | public class CompletableFutureTest exten
1929          f.complete(null);
1930          checkCompletedWithWrappedCFException(g);
1931      }
1932 <        
1932 >
1933      /**
1934       * thenApplyAsync result completes exceptionally if source cancelled
1935       */
# Line 1852 | Line 1975 | public class CompletableFutureTest exten
1975          f.complete(null);
1976          checkCompletedWithWrappedCFException(g);
1977      }
1978 <        
1978 >
1979      /**
1980       * thenAcceptAsync result completes exceptionally if source cancelled
1981       */
# Line 1863 | Line 1986 | public class CompletableFutureTest exten
1986          assertTrue(f.cancel(true));
1987          checkCompletedWithWrappedCancellationException(g);
1988      }
1989 +
1990      /**
1991       * thenCombineAsync result completes normally after normal
1992       * completion of sources
1993       */
1994      public void testThenCombineAsyncE() {
1995 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1996 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1997 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1998 <        f.complete(one);
1999 <        checkIncomplete(g);
2000 <        f2.complete(two);
2001 <        checkCompletedNormally(g, three);
1995 >        CompletableFuture<Integer> f, g, h;
1996 >        ThreadExecutor e = new ThreadExecutor();
1997 >        int count = 0;
1998 >
1999 >        f = new CompletableFuture<Integer>();
2000 >        g = new CompletableFuture<Integer>();
2001 >        h = f.thenCombineAsync(g, subtract, e);
2002 >        f.complete(3);
2003 >        checkIncomplete(h);
2004 >        g.complete(1);
2005 >        checkCompletedNormally(h, 2);
2006 >        assertEquals(++count, e.count.get());
2007 >
2008 >        f = new CompletableFuture<Integer>();
2009 >        g = new CompletableFuture<Integer>();
2010 >        h = f.thenCombineAsync(g, subtract, e);
2011 >        g.complete(1);
2012 >        checkIncomplete(h);
2013 >        f.complete(3);
2014 >        checkCompletedNormally(h, 2);
2015 >        assertEquals(++count, e.count.get());
2016 >
2017 >        f = new CompletableFuture<Integer>();
2018 >        g = new CompletableFuture<Integer>();
2019 >        g.complete(1);
2020 >        f.complete(3);
2021 >        h = f.thenCombineAsync(g, subtract, e);
2022 >        checkCompletedNormally(h, 2);
2023 >        assertEquals(++count, e.count.get());
2024      }
2025  
2026      /**
2027       * thenCombineAsync result completes exceptionally after exceptional
2028 <     * completion of source
2028 >     * completion of either source
2029       */
2030      public void testThenCombineAsync2E() {
2031 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2032 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2033 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2031 >        CompletableFuture<Integer> f, g, h;
2032 >        ThreadExecutor e = new ThreadExecutor();
2033 >        int count = 0;
2034 >
2035 >        f = new CompletableFuture<Integer>();
2036 >        g = new CompletableFuture<Integer>();
2037 >        h = f.thenCombineAsync(g, subtract, e);
2038          f.completeExceptionally(new CFException());
2039 <        f2.complete(two);
2040 <        checkCompletedWithWrappedCFException(g);
2039 >        checkIncomplete(h);
2040 >        g.complete(1);
2041 >        checkCompletedWithWrappedCFException(h);
2042  
2043          f = new CompletableFuture<Integer>();
2044 <        f2 = new CompletableFuture<Integer>();
2045 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2046 <        f.complete(one);
2047 <        f2.completeExceptionally(new CFException());
2048 <        checkCompletedWithWrappedCFException(g);
2044 >        g = new CompletableFuture<Integer>();
2045 >        h = f.thenCombineAsync(g, subtract, e);
2046 >        g.completeExceptionally(new CFException());
2047 >        checkIncomplete(h);
2048 >        f.complete(3);
2049 >        checkCompletedWithWrappedCFException(h);
2050 >
2051 >        f = new CompletableFuture<Integer>();
2052 >        g = new CompletableFuture<Integer>();
2053 >        g.completeExceptionally(new CFException());
2054 >        h = f.thenCombineAsync(g, subtract, e);
2055 >        checkIncomplete(h);
2056 >        f.complete(3);
2057 >        checkCompletedWithWrappedCFException(h);
2058 >
2059 >        assertEquals(0, e.count.get());
2060      }
2061  
2062      /**
# Line 1907 | Line 2069 | public class CompletableFutureTest exten
2069          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2070          f.complete(one);
2071          checkIncomplete(g);
2072 +        assertFalse(r.ran);
2073          f2.complete(two);
2074          checkCompletedWithWrappedCFException(g);
2075 +        assertTrue(r.ran);
2076      }
2077 <        
2077 >
2078      /**
2079       * thenCombineAsync result completes exceptionally if either source cancelled
2080       */
2081      public void testThenCombineAsync4E() {
2082 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2083 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2084 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2082 >        CompletableFuture<Integer> f, g, h;
2083 >        ThreadExecutor e = new ThreadExecutor();
2084 >
2085 >        f = new CompletableFuture<Integer>();
2086 >        g = new CompletableFuture<Integer>();
2087 >        h = f.thenCombineAsync(g, subtract, e);
2088          assertTrue(f.cancel(true));
2089 <        f2.complete(two);
2090 <        checkCompletedWithWrappedCancellationException(g);
2091 <        
2089 >        checkIncomplete(h);
2090 >        g.complete(1);
2091 >        checkCompletedWithWrappedCancellationException(h);
2092 >
2093          f = new CompletableFuture<Integer>();
2094 <        f2 = new CompletableFuture<Integer>();
2095 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2096 <        f.complete(one);
2097 <        assertTrue(f2.cancel(true));
2098 <        checkCompletedWithWrappedCancellationException(g);
2094 >        g = new CompletableFuture<Integer>();
2095 >        h = f.thenCombineAsync(g, subtract, e);
2096 >        assertTrue(g.cancel(true));
2097 >        checkIncomplete(h);
2098 >        f.complete(3);
2099 >        checkCompletedWithWrappedCancellationException(h);
2100 >
2101 >        f = new CompletableFuture<Integer>();
2102 >        g = new CompletableFuture<Integer>();
2103 >        assertTrue(g.cancel(true));
2104 >        h = f.thenCombineAsync(g, subtract, e);
2105 >        checkIncomplete(h);
2106 >        f.complete(3);
2107 >        checkCompletedWithWrappedCancellationException(h);
2108 >
2109 >        f = new CompletableFuture<Integer>();
2110 >        g = new CompletableFuture<Integer>();
2111 >        assertTrue(f.cancel(true));
2112 >        assertTrue(g.cancel(true));
2113 >        h = f.thenCombineAsync(g, subtract, e);
2114 >        checkCompletedWithWrappedCancellationException(h);
2115 >
2116 >        assertEquals(0, e.count.get());
2117      }
2118  
2119      /**
# Line 1975 | Line 2161 | public class CompletableFutureTest exten
2161          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2162          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2163          FailingBiConsumer r = new FailingBiConsumer();
2164 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());      
2164 >        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2165          f.complete(one);
2166          checkIncomplete(g);
2167          f2.complete(two);
2168          checkCompletedWithWrappedCFException(g);
2169      }
2170 <        
2170 >
2171      /**
2172       * thenAcceptBothAsync result completes exceptionally if either source cancelled
2173       */
# Line 1993 | Line 2179 | public class CompletableFutureTest exten
2179          assertTrue(f.cancel(true));
2180          f2.complete(two);
2181          checkCompletedWithWrappedCancellationException(g);
2182 <        
2182 >
2183          r = new AddAction();
2184          f = new CompletableFuture<Integer>();
2185          f2 = new CompletableFuture<Integer>();
# Line 2048 | Line 2234 | public class CompletableFutureTest exten
2234          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2235          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2236          FailingNoop r = new FailingNoop();
2237 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());      
2237 >        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2238          f.complete(one);
2239          checkIncomplete(g);
2240          f2.complete(two);
2241          checkCompletedWithWrappedCFException(g);
2242      }
2243 <        
2243 >
2244      /**
2245       * runAfterBothAsync result completes exceptionally if either source cancelled
2246       */
# Line 2066 | Line 2252 | public class CompletableFutureTest exten
2252          assertTrue(f.cancel(true));
2253          f2.complete(two);
2254          checkCompletedWithWrappedCancellationException(g);
2255 <        
2255 >
2256          r = new Noop();
2257          f = new CompletableFuture<Integer>();
2258          f2 = new CompletableFuture<Integer>();
# Line 2120 | Line 2306 | public class CompletableFutureTest exten
2306          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2307          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2308          FailingFunction r = new FailingFunction();
2309 <        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());      
2309 >        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2310          f.complete(one);
2311          checkCompletedWithWrappedCFException(g);
2312      }
2313 <        
2313 >
2314      /**
2315       * applyToEitherAsync result completes exceptionally if either source cancelled
2316       */
# Line 2134 | Line 2320 | public class CompletableFutureTest exten
2320          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2321          assertTrue(f.cancel(true));
2322          checkCompletedWithWrappedCancellationException(g);
2323 <        
2323 >
2324          f = new CompletableFuture<Integer>();
2325          f2 = new CompletableFuture<Integer>();
2326          assertTrue(f2.cancel(true));
# Line 2192 | Line 2378 | public class CompletableFutureTest exten
2378          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2379          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2380          FailingConsumer r = new FailingConsumer();
2381 <        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());      
2381 >        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2382          f.complete(one);
2383          checkCompletedWithWrappedCFException(g);
2384      }
2385 <        
2385 >
2386      /**
2387       * acceptEitherAsync result completes exceptionally if either
2388       * source cancelled
# Line 2208 | Line 2394 | public class CompletableFutureTest exten
2394          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2395          assertTrue(f.cancel(true));
2396          checkCompletedWithWrappedCancellationException(g);
2397 <        
2397 >
2398          r = new IncAction();
2399          f = new CompletableFuture<Integer>();
2400          f2 = new CompletableFuture<Integer>();
# Line 2267 | Line 2453 | public class CompletableFutureTest exten
2453          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2454          CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2455          FailingNoop r = new FailingNoop();
2456 <        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());      
2456 >        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2457          f.complete(one);
2458          checkCompletedWithWrappedCFException(g);
2459      }
2460 <        
2460 >
2461      /**
2462       * runAfterEitherAsync result completes exceptionally if either
2463       * source cancelled
# Line 2283 | Line 2469 | public class CompletableFutureTest exten
2469          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2470          assertTrue(f.cancel(true));
2471          checkCompletedWithWrappedCancellationException(g);
2472 <        
2472 >
2473          r = new Noop();
2474          f = new CompletableFuture<Integer>();
2475          f2 = new CompletableFuture<Integer>();
# Line 2293 | Line 2479 | public class CompletableFutureTest exten
2479      }
2480  
2481      /**
2482 <     * thenCompse result completes normally after normal completion of source
2482 >     * thenComposeAsync result completes normally after normal
2483 >     * completion of source
2484       */
2485      public void testThenComposeAsyncE() {
2486          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 2304 | Line 2491 | public class CompletableFutureTest exten
2491      }
2492  
2493      /**
2494 <     * thenComposeAsync result completes exceptionally after exceptional
2495 <     * completion of source
2494 >     * thenComposeAsync result completes exceptionally after
2495 >     * exceptional completion of source
2496       */
2497      public void testThenComposeAsync2E() {
2498          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
# Line 2337 | Line 2524 | public class CompletableFutureTest exten
2524          checkCompletedWithWrappedCancellationException(g);
2525      }
2526  
2527 <    // other static methods    
2527 >    // other static methods
2528  
2529      /**
2530       * allOf(no component futures) returns a future completed normally
# Line 2354 | Line 2541 | public class CompletableFutureTest exten
2541      public void testAllOf() throws Exception {
2542          for (int k = 1; k < 20; ++k) {
2543              CompletableFuture[] fs = new CompletableFuture[k];
2544 <            for (int i = 0; i < k; ++i)
2544 >            for (int i = 0; i < k; ++i)
2545                  fs[i] = new CompletableFuture<Integer>();
2546 <            CompletableFuture<?> f = CompletableFuture.allOf(fs);
2546 >            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2547              for (int i = 0; i < k; ++i) {
2548                  checkIncomplete(f);
2549                  fs[i].complete(one);
2550              }
2551 <            assertTrue(f.isDone());
2365 <            assertFalse(f.isCancelled());
2551 >            checkCompletedNormally(f, null);
2552          }
2553      }
2554  
# Line 2375 | Line 2561 | public class CompletableFutureTest exten
2561      }
2562  
2563      /**
2564 <     * allOf returns a future completed when any components complete
2564 >     * anyOf returns a future completed when any components complete
2565       */
2566      public void testAnyOf() throws Exception {
2567          for (int k = 1; k < 20; ++k) {
2568              CompletableFuture[] fs = new CompletableFuture[k];
2569 <            for (int i = 0; i < k; ++i)
2569 >            for (int i = 0; i < k; ++i)
2570                  fs[i] = new CompletableFuture<Integer>();
2571 <            CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2571 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2572              checkIncomplete(f);
2573              for (int i = 0; i < k; ++i) {
2574                  fs[i].complete(one);
2575 <                assertTrue(f.isDone());
2575 >                checkCompletedNormally(f, one);
2576              }
2577          }
2578      }
# Line 2397 | Line 2583 | public class CompletableFutureTest exten
2583      public void testNPE() {
2584          CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2585          CompletableFuture<Integer> g = new CompletableFuture<Integer>();
2586 <        CompletableFuture h;
2587 <        try { h = f.thenApply(null); } catch (NullPointerException ok) {}
2588 <        try { h = f.thenAccept(null); } catch (NullPointerException ok) {}
2589 <        try { h = f.thenRun(null); } catch (NullPointerException ok) {}
2590 <        try { h = f.thenCombine(g, null); } catch (NullPointerException ok) {}
2591 <        try { h = f.thenCombine(null, null); } catch (NullPointerException ok) {}
2592 <        try { h = f.applyToEither(g, null); } catch (NullPointerException ok) {}
2593 <        try { h = f.applyToEither(null, null); } catch (NullPointerException ok) {}
2594 <        try { h = f.thenAcceptBoth(g, null); } catch (NullPointerException ok) {}
2595 <        try { h = f.thenAcceptBoth(null, null); } catch (NullPointerException ok) {}
2596 <        try { h = f.runAfterEither(g, null); } catch (NullPointerException ok) {}
2597 <        try { h = f.runAfterEither(null, null); } catch (NullPointerException ok) {}
2598 <        try { h = f.runAfterBoth(g, null); } catch (NullPointerException ok) {}
2599 <        try { h = f.runAfterBoth(null, null); } catch (NullPointerException ok) {}
2600 <        try { h = f.exceptionally(null); } catch (NullPointerException ok) {}
2601 <        try { h = f.handle(null); } catch (NullPointerException ok) {}
2602 <        try { h = f.thenCompose(null); } catch (NullPointerException ok) {}
2603 <
2604 <        try { h = f.thenApplyAsync(null); } catch (NullPointerException ok) {}
2605 <        try { h = f.thenAcceptAsync(null); } catch (NullPointerException ok) {}
2606 <        try { h = f.thenRunAsync(null); } catch (NullPointerException ok) {}
2607 <        try { h = f.thenCombineAsync(g, null); } catch (NullPointerException ok) {}
2608 <        try { h = f.thenCombineAsync(null, null); } catch (NullPointerException ok) {}
2609 <        try { h = f.applyToEitherAsync(g, null); } catch (NullPointerException ok) {}
2610 <        try { h = f.applyToEitherAsync(null, null); } catch (NullPointerException ok) {}
2611 <        try { h = f.thenAcceptBothAsync(g, null); } catch (NullPointerException ok) {}
2612 <        try { h = f.thenAcceptBothAsync(null, null); } catch (NullPointerException ok) {}
2613 <        try { h = f.runAfterEitherAsync(g, null); } catch (NullPointerException ok) {}
2614 <        try { h = f.runAfterEitherAsync(null, null); } catch (NullPointerException ok) {}
2615 <        try { h = f.runAfterBothAsync(g, null); } catch (NullPointerException ok) {}
2616 <        try { h = f.runAfterBothAsync(null, null); } catch (NullPointerException ok) {}
2586 >        CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
2587 >        CompletableFuture<?> h;
2588 >        ThreadExecutor exec = new ThreadExecutor();
2589 >
2590 >        Runnable[] throwingActions = {
2591 >            () -> { CompletableFuture.supplyAsync(null); },
2592 >            () -> { CompletableFuture.supplyAsync(null, exec); },
2593 >            () -> { CompletableFuture.supplyAsync(supplyOne, null); },
2594 >
2595 >            () -> { CompletableFuture.runAsync(null); },
2596 >            () -> { CompletableFuture.runAsync(null, exec); },
2597 >            () -> { CompletableFuture.runAsync(() -> {}, null); },
2598 >
2599 >            () -> { f.completeExceptionally(null); },
2600 >
2601 >            () -> { f.thenApply(null); },
2602 >            () -> { f.thenApplyAsync(null); },
2603 >            () -> { f.thenApplyAsync((x) -> x, null); },
2604 >            () -> { f.thenApplyAsync(null, exec); },
2605 >
2606 >            () -> { f.thenAccept(null); },
2607 >            () -> { f.thenAcceptAsync(null); },
2608 >            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
2609 >            () -> { f.thenAcceptAsync(null, exec); },
2610 >
2611 >            () -> { f.thenRun(null); },
2612 >            () -> { f.thenRunAsync(null); },
2613 >            () -> { f.thenRunAsync(() -> { ; }, null); },
2614 >            () -> { f.thenRunAsync(null, exec); },
2615 >
2616 >            () -> { f.thenCombine(g, null); },
2617 >            () -> { f.thenCombineAsync(g, null); },
2618 >            () -> { f.thenCombineAsync(g, null, exec); },
2619 >            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
2620 >            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
2621 >            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
2622 >            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
2623 >
2624 >            () -> { f.thenAcceptBoth(g, null); },
2625 >            () -> { f.thenAcceptBothAsync(g, null); },
2626 >            () -> { f.thenAcceptBothAsync(g, null, exec); },
2627 >            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
2628 >            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
2629 >            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
2630 >            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
2631 >
2632 >            () -> { f.runAfterBoth(g, null); },
2633 >            () -> { f.runAfterBothAsync(g, null); },
2634 >            () -> { f.runAfterBothAsync(g, null, exec); },
2635 >            () -> { f.runAfterBoth(nullFuture, () -> {}); },
2636 >            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
2637 >            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
2638 >            () -> { f.runAfterBothAsync(g, () -> {}, null); },
2639 >
2640 >            () -> { f.applyToEither(g, null); },
2641 >            () -> { f.applyToEitherAsync(g, null); },
2642 >            () -> { f.applyToEitherAsync(g, null, exec); },
2643 >            () -> { f.applyToEither(nullFuture, (x) -> x); },
2644 >            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
2645 >            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
2646 >            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
2647 >
2648 >            () -> { f.acceptEither(g, null); },
2649 >            () -> { f.acceptEitherAsync(g, null); },
2650 >            () -> { f.acceptEitherAsync(g, null, exec); },
2651 >            () -> { f.acceptEither(nullFuture, (x) -> {}); },
2652 >            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
2653 >            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
2654 >            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
2655 >
2656 >            () -> { f.runAfterEither(g, null); },
2657 >            () -> { f.runAfterEitherAsync(g, null); },
2658 >            () -> { f.runAfterEitherAsync(g, null, exec); },
2659 >            () -> { f.runAfterEither(nullFuture, () -> {}); },
2660 >            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
2661 >            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
2662 >            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
2663 >
2664 >            () -> { f.thenCompose(null); },
2665 >            () -> { f.thenComposeAsync(null); },
2666 >            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
2667 >            () -> { f.thenComposeAsync(null, exec); },
2668 >
2669 >            () -> { f.exceptionally(null); },
2670 >
2671 >            () -> { f.handle(null); },
2672 >
2673 >            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
2674 >            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
2675 >            () -> { CompletableFuture.allOf(f, null); },
2676 >            () -> { CompletableFuture.allOf(null, f); },
2677 >
2678 >            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
2679 >            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
2680 >            () -> { CompletableFuture.anyOf(f, null); },
2681 >            () -> { CompletableFuture.anyOf(null, f); },
2682 >        };
2683  
2684 +        assertThrows(NullPointerException.class, throwingActions);
2685 +        assertEquals(0, exec.count.get());
2686      }
2687  
2434
2688   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines