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.14 by jsr166, Mon Apr 1 20:06:25 2013 UTC vs.
Revision 1.35 by jsr166, Sun Jun 1 22:22:49 2014 UTC

# Line 16 | Line 16 | import java.util.concurrent.ExecutionExc
16   import java.util.concurrent.Future;
17   import java.util.concurrent.CompletableFuture;
18   import java.util.concurrent.CompletionException;
19 + import java.util.concurrent.CompletionStage;
20   import java.util.concurrent.TimeoutException;
21   import java.util.concurrent.atomic.AtomicInteger;
22   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 55 | Line 56 | public class CompletableFutureTest exten
56  
57      <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
58          try {
59 +            assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS));
60 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
61 +        try {
62              assertEquals(value, f.join());
63          } catch (Throwable fail) { threadUnexpectedException(fail); }
64          try {
# Line 63 | Line 67 | public class CompletableFutureTest exten
67          try {
68              assertEquals(value, f.get());
69          } catch (Throwable fail) { threadUnexpectedException(fail); }
66        try {
67            assertEquals(value, f.get(0L, SECONDS));
68        } catch (Throwable fail) { threadUnexpectedException(fail); }
70          assertTrue(f.isDone());
71          assertFalse(f.isCancelled());
72 +        assertFalse(f.isCompletedExceptionally());
73          assertTrue(f.toString().contains("[Completed normally]"));
74      }
75  
76      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
77          try {
78 +            f.get(LONG_DELAY_MS, MILLISECONDS);
79 +            shouldThrow();
80 +        } catch (ExecutionException success) {
81 +            assertTrue(success.getCause() instanceof CFException);
82 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
83 +        try {
84              f.join();
85              shouldThrow();
86          } catch (CompletionException success) {
# Line 90 | Line 98 | public class CompletableFutureTest exten
98          } catch (ExecutionException success) {
99              assertTrue(success.getCause() instanceof CFException);
100          } catch (Throwable fail) { threadUnexpectedException(fail); }
101 +        assertTrue(f.isDone());
102 +        assertFalse(f.isCancelled());
103 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
104 +    }
105 +
106 +    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
107 +                                              CFException ex) {
108          try {
109 <            f.get(0L, SECONDS);
109 >            f.get(LONG_DELAY_MS, MILLISECONDS);
110              shouldThrow();
111          } catch (ExecutionException success) {
112 <            assertTrue(success.getCause() instanceof CFException);
112 >            assertSame(ex, success.getCause());
113 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
114 >        try {
115 >            f.join();
116 >            shouldThrow();
117 >        } catch (CompletionException success) {
118 >            assertSame(ex, success.getCause());
119 >        }
120 >        try {
121 >            f.getNow(null);
122 >            shouldThrow();
123 >        } catch (CompletionException success) {
124 >            assertSame(ex, success.getCause());
125 >        }
126 >        try {
127 >            f.get();
128 >            shouldThrow();
129 >        } catch (ExecutionException success) {
130 >            assertSame(ex, success.getCause());
131          } catch (Throwable fail) { threadUnexpectedException(fail); }
132          assertTrue(f.isDone());
133          assertFalse(f.isCancelled());
# Line 103 | Line 136 | public class CompletableFutureTest exten
136  
137      void checkCancelled(CompletableFuture<?> f) {
138          try {
139 +            f.get(LONG_DELAY_MS, MILLISECONDS);
140 +            shouldThrow();
141 +        } catch (CancellationException success) {
142 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
143 +        try {
144              f.join();
145              shouldThrow();
146          } catch (CancellationException success) {}
# Line 115 | Line 153 | public class CompletableFutureTest exten
153              shouldThrow();
154          } catch (CancellationException success) {
155          } catch (Throwable fail) { threadUnexpectedException(fail); }
118        try {
119            f.get(0L, SECONDS);
120            shouldThrow();
121        } catch (CancellationException success) {
122        } catch (Throwable fail) { threadUnexpectedException(fail); }
156          assertTrue(f.isDone());
157 +        assertTrue(f.isCompletedExceptionally());
158          assertTrue(f.isCancelled());
159          assertTrue(f.toString().contains("[Completed exceptionally]"));
160      }
161  
162      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
163          try {
164 +            f.get(LONG_DELAY_MS, MILLISECONDS);
165 +            shouldThrow();
166 +        } catch (ExecutionException success) {
167 +            assertTrue(success.getCause() instanceof CancellationException);
168 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
169 +        try {
170              f.join();
171              shouldThrow();
172          } catch (CompletionException success) {
# Line 144 | Line 184 | public class CompletableFutureTest exten
184          } catch (ExecutionException success) {
185              assertTrue(success.getCause() instanceof CancellationException);
186          } catch (Throwable fail) { threadUnexpectedException(fail); }
147        try {
148            f.get(0L, SECONDS);
149            shouldThrow();
150        } catch (ExecutionException success) {
151            assertTrue(success.getCause() instanceof CancellationException);
152        } catch (Throwable fail) { threadUnexpectedException(fail); }
187          assertTrue(f.isDone());
188          assertFalse(f.isCancelled());
189 +        assertTrue(f.isCompletedExceptionally());
190          assertTrue(f.toString().contains("[Completed exceptionally]"));
191      }
192  
# Line 160 | Line 195 | public class CompletableFutureTest exten
195       * by methods isDone, isCancelled, and getNow
196       */
197      public void testConstructor() {
198 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
198 >        CompletableFuture<Integer> f = new CompletableFuture<>();
199          checkIncomplete(f);
200      }
201  
# Line 169 | Line 204 | public class CompletableFutureTest exten
204       * isCancelled, join, get, and getNow
205       */
206      public void testComplete() {
207 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
207 >        CompletableFuture<Integer> f = new CompletableFuture<>();
208          checkIncomplete(f);
209          f.complete(one);
210          checkCompletedNormally(f, one);
# Line 180 | Line 215 | public class CompletableFutureTest exten
215       * methods isDone, isCancelled, join, get, and getNow
216       */
217      public void testCompleteExceptionally() {
218 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
218 >        CompletableFuture<Integer> f = new CompletableFuture<>();
219          checkIncomplete(f);
220          f.completeExceptionally(new CFException());
221          checkCompletedWithWrappedCFException(f);
# Line 191 | Line 226 | public class CompletableFutureTest exten
226       * methods isDone, isCancelled, join, get, and getNow
227       */
228      public void testCancel() {
229 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
229 >        CompletableFuture<Integer> f = new CompletableFuture<>();
230          checkIncomplete(f);
231          assertTrue(f.cancel(true));
232          checkCancelled(f);
# Line 201 | Line 236 | public class CompletableFutureTest exten
236       * obtrudeValue forces completion with given value
237       */
238      public void testObtrudeValue() {
239 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
239 >        CompletableFuture<Integer> f = new CompletableFuture<>();
240          checkIncomplete(f);
241          f.complete(one);
242          checkCompletedNormally(f, one);
# Line 209 | Line 244 | public class CompletableFutureTest exten
244          checkCompletedNormally(f, three);
245          f.obtrudeValue(two);
246          checkCompletedNormally(f, two);
247 <        f = new CompletableFuture<Integer>();
247 >        f = new CompletableFuture<>();
248          f.obtrudeValue(three);
249          checkCompletedNormally(f, three);
250 <        f = new CompletableFuture<Integer>();
250 >        f = new CompletableFuture<>();
251          f.completeExceptionally(new CFException());
252          f.obtrudeValue(four);
253          checkCompletedNormally(f, four);
# Line 222 | Line 257 | public class CompletableFutureTest exten
257       * obtrudeException forces completion with given exception
258       */
259      public void testObtrudeException() {
260 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
260 >        CompletableFuture<Integer> f = new CompletableFuture<>();
261          checkIncomplete(f);
262          f.complete(one);
263          checkCompletedNormally(f, one);
264          f.obtrudeException(new CFException());
265          checkCompletedWithWrappedCFException(f);
266 <        f = new CompletableFuture<Integer>();
266 >        f = new CompletableFuture<>();
267          f.obtrudeException(new CFException());
268          checkCompletedWithWrappedCFException(f);
269 <        f = new CompletableFuture<Integer>();
269 >        f = new CompletableFuture<>();
270          f.completeExceptionally(new CFException());
271          f.obtrudeValue(four);
272          checkCompletedNormally(f, four);
# Line 243 | Line 278 | public class CompletableFutureTest exten
278       * getNumberOfDependents returns number of dependent tasks
279       */
280      public void testGetNumberOfDependents() {
281 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
281 >        CompletableFuture<Integer> f = new CompletableFuture<>();
282          assertEquals(f.getNumberOfDependents(), 0);
283          CompletableFuture g = f.thenRun(new Noop());
284          assertEquals(f.getNumberOfDependents(), 1);
# Line 256 | Line 291 | public class CompletableFutureTest exten
291          assertEquals(g.getNumberOfDependents(), 0);
292      }
293  
259
294      /**
295       * toString indicates current completion state
296       */
# Line 282 | Line 316 | public class CompletableFutureTest exten
316          checkCompletedNormally(f, "test");
317      }
318  
319 +    // Choose non-commutative actions for better coverage
320 +
321      static final Supplier<Integer> supplyOne =
322          () -> Integer.valueOf(1);
323      static final Function<Integer, Integer> inc =
324          (Integer x) -> Integer.valueOf(x.intValue() + 1);
325 <    static final BiFunction<Integer, Integer, Integer> add =
326 <        (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
325 >    static final BiFunction<Integer, Integer, Integer> subtract =
326 >        (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue());
327      static final class IncAction implements Consumer<Integer> {
328          int value;
329          public void accept(Integer x) { value = x.intValue() + 1; }
330      }
331 <    static final class AddAction implements BiConsumer<Integer, Integer> {
331 >    static final class SubtractAction implements BiConsumer<Integer, Integer> {
332 >        // Handle null values as well
333 >        public int subtract(Integer x, Integer y) {
334 >            return ((x == null) ? 42 : x.intValue())
335 >                - ((y == null) ? 99 : y.intValue());
336 >        }
337          int value;
338 +        public boolean ran() { return value != 0; }
339          public void accept(Integer x, Integer y) {
340 <            value = x.intValue() + y.intValue();
340 >            value = subtract(x, y);
341          }
342      }
343      static final class Noop implements Runnable {
# Line 328 | Line 370 | public class CompletableFutureTest exten
370          public void run() { ran = true; throw new CFException(); }
371      }
372  
373 <    static final class CompletableFutureInc implements Function<Integer, CompletableFuture<Integer>> {
373 >    static final class CompletableFutureInc
374 >        implements Function<Integer, CompletableFuture<Integer>> {
375 >        boolean ran;
376          public CompletableFuture<Integer> apply(Integer x) {
377 <            CompletableFuture<Integer> f = new CompletableFuture<Integer>();
377 >            ran = true;
378 >            CompletableFuture<Integer> f = new CompletableFuture<>();
379              f.complete(Integer.valueOf(x.intValue() + 1));
380              return f;
381          }
382      }
383  
384 <    static final class FailingCompletableFutureFunction implements Function<Integer, CompletableFuture<Integer>> {
384 >    static final class FailingCompletableFutureFunction
385 >        implements Function<Integer, CompletableFuture<Integer>> {
386          boolean ran;
387          public CompletableFuture<Integer> apply(Integer x) {
388              ran = true; throw new CFException();
# Line 345 | Line 391 | public class CompletableFutureTest exten
391  
392      // Used for explicit executor tests
393      static final class ThreadExecutor implements Executor {
394 +        AtomicInteger count = new AtomicInteger(0);
395 +
396          public void execute(Runnable r) {
397 +            count.getAndIncrement();
398              new Thread(r).start();
399          }
400      }
# Line 355 | Line 404 | public class CompletableFutureTest exten
404      }
405  
406      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
407 +        boolean ran;
408          public Integer apply(Integer x, Throwable t) {
409 +            ran = true;
410              return (t == null) ? two : three;
411          }
412      }
413  
414 +    /**
415 +     * Permits the testing of parallel code for the 3 different
416 +     * execution modes without repeating all the testing code.
417 +     */
418 +    enum ExecutionMode {
419 +        DEFAULT {
420 +            public <T,U> CompletableFuture<Void> runAfterBoth
421 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
422 +                return f.runAfterBoth(g, a);
423 +            }
424 +            public <T,U> CompletableFuture<Void> thenAcceptBoth
425 +                (CompletableFuture<T> f,
426 +                 CompletionStage<? extends U> g,
427 +                 BiConsumer<? super T,? super U> a) {
428 +                return f.thenAcceptBoth(g, a);
429 +            }
430 +        },
431 +
432 + //             /** Experimental way to do more testing */
433 + //         REVERSE_DEFAULT {
434 + //             public <T,U> CompletableFuture<Void> runAfterBoth
435 + //                 (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
436 + //                 return g.runAfterBoth(f, a);
437 + //             }
438 + //             public <T,U> CompletableFuture<Void> thenAcceptBoth
439 + //                 (CompletableFuture<T> f,
440 + //                  CompletionStage<? extends U> g,
441 + //                  BiConsumer<? super T,? super U> a) {
442 + //                 return DEFAULT.thenAcceptBoth(f, g, a);
443 + //             }
444 + //         },
445 +
446 +        DEFAULT_ASYNC {
447 +            public <T,U> CompletableFuture<Void> runAfterBoth
448 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
449 +                return f.runAfterBothAsync(g, a);
450 +            }
451 +            public <T,U> CompletableFuture<Void> thenAcceptBoth
452 +                (CompletableFuture<T> f,
453 +                 CompletionStage<? extends U> g,
454 +                 BiConsumer<? super T,? super U> a) {
455 +                return f.thenAcceptBothAsync(g, a);
456 +            }
457 +        },
458 +
459 + //         REVERSE_DEFAULT_ASYNC {
460 + //             public <T,U> CompletableFuture<Void> runAfterBoth
461 + //                 (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
462 + //                 return f.runAfterBothAsync(g, a);
463 + //             }
464 + //             public <T,U> CompletableFuture<Void> thenAcceptBoth
465 + //                 (CompletableFuture<T> f,
466 + //                  CompletionStage<? extends U> g,
467 + //                  BiConsumer<? super T,? super U> a) {
468 + //                 return DEFAULT_ASYNC.thenAcceptBoth(f, g, a);
469 + //             }
470 + //         },
471 +
472 +        EXECUTOR {
473 +            public <T,U> CompletableFuture<Void> runAfterBoth
474 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
475 +                return f.runAfterBothAsync(g, a, new ThreadExecutor());
476 +            }
477 +            public <T,U> CompletableFuture<Void> thenAcceptBoth
478 +                (CompletableFuture<T> f,
479 +                 CompletionStage<? extends U> g,
480 +                 BiConsumer<? super T,? super U> a) {
481 +                return f.thenAcceptBothAsync(g, a, new ThreadExecutor());
482 +            }
483 +        };
484 +
485 +        public abstract <T,U> CompletableFuture<Void> runAfterBoth
486 +            (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a);
487 +        public abstract <T,U> CompletableFuture<Void> thenAcceptBoth
488 +            (CompletableFuture<T> f,
489 +             CompletionStage<? extends U> g,
490 +             BiConsumer<? super T,? super U> a);
491 +    }
492  
493      /**
494       * exceptionally action completes with function value on source
495 <     * exception;  otherwise with source value
495 >     * exception; otherwise with source value
496       */
497      public void testExceptionally() {
498 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
498 >        CompletableFuture<Integer> f = new CompletableFuture<>();
499          ExceptionToInteger r = new ExceptionToInteger();
500          CompletableFuture<Integer> g = f.exceptionally(r);
501          f.completeExceptionally(new CFException());
502          checkCompletedNormally(g, three);
503  
504 <        f = new CompletableFuture<Integer>();
504 >        f = new CompletableFuture<>();
505          r = new ExceptionToInteger();
506          g = f.exceptionally(r);
507          f.complete(one);
# Line 384 | Line 513 | public class CompletableFutureTest exten
513       * normal or exceptional completion of source
514       */
515      public void testHandle() {
516 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
517 <        IntegerHandler r = new IntegerHandler();
518 <        CompletableFuture<Integer> g = f.handle(r);
516 >        CompletableFuture<Integer> f, g;
517 >        IntegerHandler r;
518 >
519 >        f = new CompletableFuture<>();
520 >        f.completeExceptionally(new CFException());
521 >        g = f.handle(r = new IntegerHandler());
522 >        assertTrue(r.ran);
523 >        checkCompletedNormally(g, three);
524 >
525 >        f = new CompletableFuture<>();
526 >        g = f.handle(r = new IntegerHandler());
527 >        assertFalse(r.ran);
528          f.completeExceptionally(new CFException());
529          checkCompletedNormally(g, three);
530 +        assertTrue(r.ran);
531 +
532 +        f = new CompletableFuture<>();
533 +        f.complete(one);
534 +        g = f.handle(r = new IntegerHandler());
535 +        assertTrue(r.ran);
536 +        checkCompletedNormally(g, two);
537  
538 <        f = new CompletableFuture<Integer>();
539 <        r = new IntegerHandler();
540 <        g = f.handle(r);
538 >        f = new CompletableFuture<>();
539 >        g = f.handle(r = new IntegerHandler());
540 >        assertFalse(r.ran);
541          f.complete(one);
542 +        assertTrue(r.ran);
543          checkCompletedNormally(g, two);
544      }
545  
# Line 413 | Line 559 | public class CompletableFutureTest exten
559       */
560      public void testRunAsync2() {
561          Noop r = new Noop();
562 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor());
562 >        ThreadExecutor exec = new ThreadExecutor();
563 >        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
564          assertNull(f.join());
565          assertTrue(r.ran);
566          checkCompletedNormally(f, null);
567 +        assertEquals(1, exec.count.get());
568      }
569  
570      /**
# Line 433 | Line 581 | public class CompletableFutureTest exten
581       * supplyAsync completes with result of supplier
582       */
583      public void testSupplyAsync() {
584 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne);
584 >        CompletableFuture<Integer> f;
585 >        f = CompletableFuture.supplyAsync(supplyOne);
586          assertEquals(f.join(), one);
587 +        checkCompletedNormally(f, one);
588      }
589  
590      /**
591       * supplyAsync with executor completes with result of supplier
592       */
593      public void testSupplyAsync2() {
594 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
594 >        CompletableFuture<Integer> f;
595 >        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
596          assertEquals(f.join(), one);
597 +        checkCompletedNormally(f, one);
598      }
599  
600      /**
# Line 461 | Line 613 | public class CompletableFutureTest exten
613       * thenRun result completes normally after normal completion of source
614       */
615      public void testThenRun() {
616 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
617 <        Noop r = new Noop();
618 <        CompletableFuture<Void> g = f.thenRun(r);
616 >        CompletableFuture<Integer> f;
617 >        CompletableFuture<Void> g;
618 >        Noop r;
619 >
620 >        f = new CompletableFuture<>();
621 >        g = f.thenRun(r = new Noop());
622          f.complete(null);
623          checkCompletedNormally(g, null);
624 <        // reordered version
625 <        f = new CompletableFuture<Integer>();
624 >        assertTrue(r.ran);
625 >
626 >        f = new CompletableFuture<>();
627          f.complete(null);
628 <        r = new Noop();
473 <        g = f.thenRun(r);
628 >        g = f.thenRun(r = new Noop());
629          checkCompletedNormally(g, null);
630 +        assertTrue(r.ran);
631      }
632  
633      /**
# Line 479 | Line 635 | public class CompletableFutureTest exten
635       * completion of source
636       */
637      public void testThenRun2() {
638 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
639 <        Noop r = new Noop();
640 <        CompletableFuture<Void> g = f.thenRun(r);
638 >        CompletableFuture<Integer> f;
639 >        CompletableFuture<Void> g;
640 >        Noop r;
641 >
642 >        f = new CompletableFuture<>();
643 >        g = f.thenRun(r = new Noop());
644 >        f.completeExceptionally(new CFException());
645 >        checkCompletedWithWrappedCFException(g);
646 >        assertFalse(r.ran);
647 >
648 >        f = new CompletableFuture<>();
649          f.completeExceptionally(new CFException());
650 +        g = f.thenRun(r = new Noop());
651          checkCompletedWithWrappedCFException(g);
652 +        assertFalse(r.ran);
653      }
654  
655      /**
656       * thenRun result completes exceptionally if action does
657       */
658      public void testThenRun3() {
659 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
660 <        FailingNoop r = new FailingNoop();
661 <        CompletableFuture<Void> g = f.thenRun(r);
659 >        CompletableFuture<Integer> f;
660 >        CompletableFuture<Void> g;
661 >        FailingNoop r;
662 >
663 >        f = new CompletableFuture<>();
664 >        g = f.thenRun(r = new FailingNoop());
665 >        f.complete(null);
666 >        checkCompletedWithWrappedCFException(g);
667 >
668 >        f = new CompletableFuture<>();
669          f.complete(null);
670 +        g = f.thenRun(r = new FailingNoop());
671          checkCompletedWithWrappedCFException(g);
672      }
673  
# Line 501 | Line 675 | public class CompletableFutureTest exten
675       * thenRun result completes exceptionally if source cancelled
676       */
677      public void testThenRun4() {
678 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
679 <        Noop r = new Noop();
680 <        CompletableFuture<Void> g = f.thenRun(r);
678 >        CompletableFuture<Integer> f;
679 >        CompletableFuture<Void> g;
680 >        Noop r;
681 >
682 >        f = new CompletableFuture<>();
683 >        g = f.thenRun(r = new Noop());
684 >        assertTrue(f.cancel(true));
685 >        checkCompletedWithWrappedCancellationException(g);
686 >
687 >        f = new CompletableFuture<>();
688          assertTrue(f.cancel(true));
689 +        g = f.thenRun(r = new Noop());
690          checkCompletedWithWrappedCancellationException(g);
691      }
692  
# Line 512 | Line 694 | public class CompletableFutureTest exten
694       * thenApply result completes normally after normal completion of source
695       */
696      public void testThenApply() {
697 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
697 >        CompletableFuture<Integer> f = new CompletableFuture<>();
698          CompletableFuture<Integer> g = f.thenApply(inc);
699          f.complete(one);
700          checkCompletedNormally(g, two);
# Line 523 | Line 705 | public class CompletableFutureTest exten
705       * completion of source
706       */
707      public void testThenApply2() {
708 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
708 >        CompletableFuture<Integer> f = new CompletableFuture<>();
709          CompletableFuture<Integer> g = f.thenApply(inc);
710          f.completeExceptionally(new CFException());
711          checkCompletedWithWrappedCFException(g);
# Line 533 | Line 715 | public class CompletableFutureTest exten
715       * thenApply result completes exceptionally if action does
716       */
717      public void testThenApply3() {
718 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
718 >        CompletableFuture<Integer> f = new CompletableFuture<>();
719          CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
720          f.complete(one);
721          checkCompletedWithWrappedCFException(g);
# Line 543 | Line 725 | public class CompletableFutureTest exten
725       * thenApply result completes exceptionally if source cancelled
726       */
727      public void testThenApply4() {
728 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
728 >        CompletableFuture<Integer> f = new CompletableFuture<>();
729          CompletableFuture<Integer> g = f.thenApply(inc);
730          assertTrue(f.cancel(true));
731          checkCompletedWithWrappedCancellationException(g);
# Line 553 | Line 735 | public class CompletableFutureTest exten
735       * thenAccept result completes normally after normal completion of source
736       */
737      public void testThenAccept() {
738 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
738 >        CompletableFuture<Integer> f = new CompletableFuture<>();
739          IncAction r = new IncAction();
740          CompletableFuture<Void> g = f.thenAccept(r);
741          f.complete(one);
# Line 566 | Line 748 | public class CompletableFutureTest exten
748       * completion of source
749       */
750      public void testThenAccept2() {
751 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
751 >        CompletableFuture<Integer> f = new CompletableFuture<>();
752          IncAction r = new IncAction();
753          CompletableFuture<Void> g = f.thenAccept(r);
754          f.completeExceptionally(new CFException());
# Line 577 | Line 759 | public class CompletableFutureTest exten
759       * thenAccept result completes exceptionally if action does
760       */
761      public void testThenAccept3() {
762 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
762 >        CompletableFuture<Integer> f = new CompletableFuture<>();
763          FailingConsumer r = new FailingConsumer();
764          CompletableFuture<Void> g = f.thenAccept(r);
765          f.complete(one);
# Line 589 | Line 771 | public class CompletableFutureTest exten
771       * thenAccept result completes exceptionally if source cancelled
772       */
773      public void testThenAccept4() {
774 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
774 >        CompletableFuture<Integer> f = new CompletableFuture<>();
775          IncAction r = new IncAction();
776          CompletableFuture<Void> g = f.thenAccept(r);
777          assertTrue(f.cancel(true));
778          checkCompletedWithWrappedCancellationException(g);
779      }
780  
599
781      /**
782 <     * thenCombine result completes normally after normal completion of sources
782 >     * thenCombine result completes normally after normal completion
783 >     * of sources
784       */
785      public void testThenCombine() {
786 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
605 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
606 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
607 <        f.complete(one);
608 <        checkIncomplete(g);
609 <        f2.complete(two);
610 <        checkCompletedNormally(g, three);
786 >        CompletableFuture<Integer> f, g, h;
787  
788 <        f = new CompletableFuture<Integer>();
789 <        f.complete(one);
790 <        f2 = new CompletableFuture<Integer>();
791 <        g = f.thenCombine(f2, add);
792 <        checkIncomplete(g);
793 <        f2.complete(two);
794 <        checkCompletedNormally(g, three);
788 >        f = new CompletableFuture<>();
789 >        g = new CompletableFuture<>();
790 >        h = f.thenCombine(g, subtract);
791 >        f.complete(3);
792 >        checkIncomplete(h);
793 >        g.complete(1);
794 >        checkCompletedNormally(h, 2);
795 >
796 >        f = new CompletableFuture<>();
797 >        g = new CompletableFuture<>();
798 >        h = f.thenCombine(g, subtract);
799 >        g.complete(1);
800 >        checkIncomplete(h);
801 >        f.complete(3);
802 >        checkCompletedNormally(h, 2);
803 >
804 >        f = new CompletableFuture<>();
805 >        g = new CompletableFuture<>();
806 >        g.complete(1);
807 >        f.complete(3);
808 >        h = f.thenCombine(g, subtract);
809 >        checkCompletedNormally(h, 2);
810      }
811  
812      /**
# Line 623 | Line 814 | public class CompletableFutureTest exten
814       * completion of either source
815       */
816      public void testThenCombine2() {
817 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
627 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
628 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
629 <        f.completeExceptionally(new CFException());
630 <        f2.complete(two);
631 <        checkCompletedWithWrappedCFException(g);
817 >        CompletableFuture<Integer> f, g, h;
818  
819 <        f = new CompletableFuture<Integer>();
820 <        f.complete(one);
821 <        f2 = new CompletableFuture<Integer>();
822 <        g = f.thenCombine(f2, add);
823 <        f2.completeExceptionally(new CFException());
824 <        checkCompletedWithWrappedCFException(g);
819 >        f = new CompletableFuture<>();
820 >        g = new CompletableFuture<>();
821 >        h = f.thenCombine(g, subtract);
822 >        f.completeExceptionally(new CFException());
823 >        checkIncomplete(h);
824 >        g.complete(1);
825 >        checkCompletedWithWrappedCFException(h);
826 >
827 >        f = new CompletableFuture<>();
828 >        g = new CompletableFuture<>();
829 >        h = f.thenCombine(g, subtract);
830 >        g.completeExceptionally(new CFException());
831 >        checkIncomplete(h);
832 >        f.complete(3);
833 >        checkCompletedWithWrappedCFException(h);
834 >
835 >        f = new CompletableFuture<>();
836 >        g = new CompletableFuture<>();
837 >        f.complete(3);
838 >        g.completeExceptionally(new CFException());
839 >        h = f.thenCombine(g, subtract);
840 >        checkCompletedWithWrappedCFException(h);
841 >
842 >        f = new CompletableFuture<>();
843 >        g = new CompletableFuture<>();
844 >        f.completeExceptionally(new CFException());
845 >        g.complete(3);
846 >        h = f.thenCombine(g, subtract);
847 >        checkCompletedWithWrappedCFException(h);
848      }
849  
850      /**
851       * thenCombine result completes exceptionally if action does
852       */
853      public void testThenCombine3() {
854 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
855 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
854 >        CompletableFuture<Integer> f = new CompletableFuture<>();
855 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
856          FailingBiFunction r = new FailingBiFunction();
857          CompletableFuture<Integer> g = f.thenCombine(f2, r);
858          f.complete(one);
859          checkIncomplete(g);
860 +        assertFalse(r.ran);
861          f2.complete(two);
862          checkCompletedWithWrappedCFException(g);
863 +        assertTrue(r.ran);
864      }
865  
866      /**
867       * thenCombine result completes exceptionally if either source cancelled
868       */
869      public void testThenCombine4() {
870 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
871 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
872 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
873 <        assertTrue(f.cancel(true));
874 <        f2.complete(two);
875 <        checkCompletedWithWrappedCancellationException(g);
876 <        f = new CompletableFuture<Integer>();
877 <        f2 = new CompletableFuture<Integer>();
878 <        g = f.thenCombine(f2, add);
879 <        f.complete(one);
880 <        assertTrue(f2.cancel(true));
881 <        checkCompletedWithWrappedCancellationException(g);
870 >        CompletableFuture<Integer> f, g, h;
871 >
872 >        f = new CompletableFuture<>();
873 >        g = new CompletableFuture<>();
874 >        h = f.thenCombine(g, subtract);
875 >        assertTrue(f.cancel(true));
876 >        checkIncomplete(h);
877 >        g.complete(1);
878 >        checkCompletedWithWrappedCancellationException(h);
879 >
880 >        f = new CompletableFuture<>();
881 >        g = new CompletableFuture<>();
882 >        h = f.thenCombine(g, subtract);
883 >        assertTrue(g.cancel(true));
884 >        checkIncomplete(h);
885 >        f.complete(3);
886 >        checkCompletedWithWrappedCancellationException(h);
887 >
888 >        f = new CompletableFuture<>();
889 >        g = new CompletableFuture<>();
890 >        assertTrue(f.cancel(true));
891 >        assertTrue(g.cancel(true));
892 >        h = f.thenCombine(g, subtract);
893 >        checkCompletedWithWrappedCancellationException(h);
894      }
895  
896      /**
897       * thenAcceptBoth result completes normally after normal
898       * completion of sources
899       */
900 <    public void testThenAcceptBoth() {
901 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
902 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
903 <        AddAction r = new AddAction();
904 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
905 <        f.complete(one);
906 <        checkIncomplete(g);
907 <        f2.complete(two);
908 <        checkCompletedNormally(g, null);
909 <        assertEquals(r.value, 3);
900 >    public void testThenAcceptBoth_normalCompletion1() {
901 >        for (ExecutionMode m : ExecutionMode.values())
902 >        for (Integer v1 : new Integer[] { 1, null })
903 >        for (Integer v2 : new Integer[] { 2, null }) {
904 >
905 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
906 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
907 >        final SubtractAction r = new SubtractAction();
908 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
909 >
910 >        f.complete(v1);
911 >        checkIncomplete(h);
912 >        assertEquals(r.value, 0);
913 >        g.complete(v2);
914 >
915 >        checkCompletedNormally(h, null);
916 >        assertEquals(r.value, r.subtract(v1, v2));
917 >        checkCompletedNormally(f, v1);
918 >        checkCompletedNormally(g, v2);
919 >        }
920 >    }
921  
922 <        r = new AddAction();
923 <        f = new CompletableFuture<Integer>();
924 <        f.complete(one);
925 <        f2 = new CompletableFuture<Integer>();
926 <        g = f.thenAcceptBoth(f2, r);
927 <        checkIncomplete(g);
928 <        f2.complete(two);
929 <        checkCompletedNormally(g, null);
930 <        assertEquals(r.value, 3);
922 >    public void testThenAcceptBoth_normalCompletion2() {
923 >        for (ExecutionMode m : ExecutionMode.values())
924 >        for (Integer v1 : new Integer[] { 1, null })
925 >        for (Integer v2 : new Integer[] { 2, null }) {
926 >
927 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
928 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
929 >        final SubtractAction r = new SubtractAction();
930 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
931 >
932 >        g.complete(v2);
933 >        checkIncomplete(h);
934 >        assertEquals(r.value, 0);
935 >        f.complete(v1);
936 >
937 >        checkCompletedNormally(h, null);
938 >        assertEquals(r.value, r.subtract(v1, v2));
939 >        checkCompletedNormally(f, v1);
940 >        checkCompletedNormally(g, v2);
941 >        }
942 >    }
943 >
944 >    public void testThenAcceptBoth_normalCompletion3() {
945 >        for (ExecutionMode m : ExecutionMode.values())
946 >        for (Integer v1 : new Integer[] { 1, null })
947 >        for (Integer v2 : new Integer[] { 2, null }) {
948 >
949 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
950 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
951 >        final SubtractAction r = new SubtractAction();
952 >
953 >        g.complete(v2);
954 >        f.complete(v1);
955 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
956 >
957 >        checkCompletedNormally(h, null);
958 >        assertEquals(r.value, r.subtract(v1, v2));
959 >        checkCompletedNormally(f, v1);
960 >        checkCompletedNormally(g, v2);
961 >        }
962 >    }
963 >
964 >    public void testThenAcceptBoth_normalCompletion4() {
965 >        for (ExecutionMode m : ExecutionMode.values())
966 >        for (Integer v1 : new Integer[] { 1, null })
967 >        for (Integer v2 : new Integer[] { 2, null }) {
968 >
969 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
970 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
971 >        final SubtractAction r = new SubtractAction();
972 >
973 >        f.complete(v1);
974 >        g.complete(v2);
975 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
976 >
977 >        checkCompletedNormally(h, null);
978 >        assertEquals(r.value, r.subtract(v1, v2));
979 >        checkCompletedNormally(f, v1);
980 >        checkCompletedNormally(g, v2);
981 >        }
982      }
983  
984      /**
985       * thenAcceptBoth result completes exceptionally after exceptional
986       * completion of either source
987       */
988 <    public void testThenAcceptBoth2() {
989 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
990 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
991 <        AddAction r = new AddAction();
992 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
993 <        f.completeExceptionally(new CFException());
994 <        f2.complete(two);
995 <        checkCompletedWithWrappedCFException(g);
988 >    public void testThenAcceptBoth_exceptionalCompletion1() {
989 >        for (ExecutionMode m : ExecutionMode.values())
990 >        for (Integer v1 : new Integer[] { 1, null }) {
991 >
992 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
993 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
994 >        final SubtractAction r = new SubtractAction();
995 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
996 >        final CFException ex = new CFException();
997 >
998 >        f.completeExceptionally(ex);
999 >        checkIncomplete(h);
1000 >        g.complete(v1);
1001 >
1002 >        checkCompletedWithWrappedCFException(h, ex);
1003 >        checkCompletedWithWrappedCFException(f, ex);
1004 >        assertFalse(r.ran());
1005 >        checkCompletedNormally(g, v1);
1006 >        }
1007 >    }
1008  
1009 <        r = new AddAction();
1010 <        f = new CompletableFuture<Integer>();
1011 <        f.complete(one);
1012 <        f2 = new CompletableFuture<Integer>();
1013 <        g = f.thenAcceptBoth(f2, r);
1014 <        f2.completeExceptionally(new CFException());
1015 <        checkCompletedWithWrappedCFException(g);
1009 >    public void testThenAcceptBoth_exceptionalCompletion2() {
1010 >        for (ExecutionMode m : ExecutionMode.values())
1011 >        for (Integer v1 : new Integer[] { 1, null }) {
1012 >
1013 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1014 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1015 >        final SubtractAction r = new SubtractAction();
1016 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1017 >        final CFException ex = new CFException();
1018 >
1019 >        g.completeExceptionally(ex);
1020 >        checkIncomplete(h);
1021 >        f.complete(v1);
1022 >
1023 >        checkCompletedWithWrappedCFException(h, ex);
1024 >        checkCompletedWithWrappedCFException(g, ex);
1025 >        assertFalse(r.ran());
1026 >        checkCompletedNormally(f, v1);
1027 >        }
1028 >    }
1029 >
1030 >    public void testThenAcceptBoth_exceptionalCompletion3() {
1031 >        for (ExecutionMode m : ExecutionMode.values())
1032 >        for (Integer v1 : new Integer[] { 1, null }) {
1033 >
1034 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1035 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1036 >        final SubtractAction r = new SubtractAction();
1037 >        final CFException ex = new CFException();
1038 >
1039 >        g.completeExceptionally(ex);
1040 >        f.complete(v1);
1041 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1042 >
1043 >        checkCompletedWithWrappedCFException(h, ex);
1044 >        checkCompletedWithWrappedCFException(g, ex);
1045 >        assertFalse(r.ran());
1046 >        checkCompletedNormally(f, v1);
1047 >        }
1048 >    }
1049 >
1050 >    public void testThenAcceptBoth_exceptionalCompletion4() {
1051 >        for (ExecutionMode m : ExecutionMode.values())
1052 >        for (Integer v1 : new Integer[] { 1, null }) {
1053 >
1054 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1055 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1056 >        final SubtractAction r = new SubtractAction();
1057 >        final CFException ex = new CFException();
1058 >
1059 >        f.completeExceptionally(ex);
1060 >        g.complete(v1);
1061 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1062 >
1063 >        checkCompletedWithWrappedCFException(h, ex);
1064 >        checkCompletedWithWrappedCFException(f, ex);
1065 >        assertFalse(r.ran());
1066 >        checkCompletedNormally(g, v1);
1067 >        }
1068      }
1069  
1070      /**
1071       * thenAcceptBoth result completes exceptionally if action does
1072       */
1073 <    public void testThenAcceptBoth3() {
1074 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1075 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1076 <        FailingBiConsumer r = new FailingBiConsumer();
1077 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
1078 <        f.complete(one);
1079 <        checkIncomplete(g);
1080 <        f2.complete(two);
1081 <        checkCompletedWithWrappedCFException(g);
1073 >    public void testThenAcceptBoth_actionFailed1() {
1074 >        for (ExecutionMode m : ExecutionMode.values())
1075 >        for (Integer v1 : new Integer[] { 1, null })
1076 >        for (Integer v2 : new Integer[] { 2, null }) {
1077 >
1078 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1079 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1080 >        final FailingBiConsumer r = new FailingBiConsumer();
1081 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1082 >
1083 >        f.complete(v1);
1084 >        checkIncomplete(h);
1085 >        g.complete(v2);
1086 >
1087 >        checkCompletedWithWrappedCFException(h);
1088 >        checkCompletedNormally(f, v1);
1089 >        checkCompletedNormally(g, v2);
1090 >        }
1091 >    }
1092 >
1093 >    public void testThenAcceptBoth_actionFailed2() {
1094 >        for (ExecutionMode m : ExecutionMode.values())
1095 >        for (Integer v1 : new Integer[] { 1, null })
1096 >        for (Integer v2 : new Integer[] { 2, null }) {
1097 >
1098 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1099 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1100 >        final FailingBiConsumer r = new FailingBiConsumer();
1101 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1102 >
1103 >        g.complete(v2);
1104 >        checkIncomplete(h);
1105 >        f.complete(v1);
1106 >
1107 >        checkCompletedWithWrappedCFException(h);
1108 >        checkCompletedNormally(f, v1);
1109 >        checkCompletedNormally(g, v2);
1110 >        }
1111      }
1112  
1113      /**
1114       * thenAcceptBoth result completes exceptionally if either source cancelled
1115       */
1116 <    public void testThenAcceptBoth4() {
1117 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1118 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1119 <        AddAction r = new AddAction();
1120 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
1121 <        assertTrue(f.cancel(true));
1122 <        f2.complete(two);
1123 <        checkCompletedWithWrappedCancellationException(g);
1124 <        f = new CompletableFuture<Integer>();
1125 <        f2 = new CompletableFuture<Integer>();
1126 <        r = new AddAction();
1127 <        g = f.thenAcceptBoth(f2, r);
1128 <        f.complete(one);
1129 <        assertTrue(f2.cancel(true));
1130 <        checkCompletedWithWrappedCancellationException(g);
1116 >    public void testThenAcceptBoth_sourceCancelled1() {
1117 >        for (ExecutionMode m : ExecutionMode.values())
1118 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1119 >        for (Integer v1 : new Integer[] { 1, null }) {
1120 >
1121 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1122 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1123 >        final SubtractAction r = new SubtractAction();
1124 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1125 >
1126 >        assertTrue(f.cancel(mayInterruptIfRunning));
1127 >        checkIncomplete(h);
1128 >        g.complete(v1);
1129 >
1130 >        checkCompletedWithWrappedCancellationException(h);
1131 >        checkCancelled(f);
1132 >        assertFalse(r.ran());
1133 >        checkCompletedNormally(g, v1);
1134 >        }
1135 >    }
1136 >
1137 >    public void testThenAcceptBoth_sourceCancelled2() {
1138 >        for (ExecutionMode m : ExecutionMode.values())
1139 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1140 >        for (Integer v1 : new Integer[] { 1, null }) {
1141 >
1142 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1143 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1144 >        final SubtractAction r = new SubtractAction();
1145 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1146 >
1147 >        assertTrue(g.cancel(mayInterruptIfRunning));
1148 >        checkIncomplete(h);
1149 >        f.complete(v1);
1150 >
1151 >        checkCompletedWithWrappedCancellationException(h);
1152 >        checkCancelled(g);
1153 >        assertFalse(r.ran());
1154 >        checkCompletedNormally(f, v1);
1155 >        }
1156 >    }
1157 >
1158 >    public void testThenAcceptBoth_sourceCancelled3() {
1159 >        for (ExecutionMode m : ExecutionMode.values())
1160 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1161 >        for (Integer v1 : new Integer[] { 1, null }) {
1162 >
1163 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1164 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1165 >        final SubtractAction r = new SubtractAction();
1166 >
1167 >        assertTrue(g.cancel(mayInterruptIfRunning));
1168 >        f.complete(v1);
1169 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1170 >
1171 >        checkCompletedWithWrappedCancellationException(h);
1172 >        checkCancelled(g);
1173 >        assertFalse(r.ran());
1174 >        checkCompletedNormally(f, v1);
1175 >        }
1176 >    }
1177 >
1178 >    public void testThenAcceptBoth_sourceCancelled4() {
1179 >        for (ExecutionMode m : ExecutionMode.values())
1180 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1181 >        for (Integer v1 : new Integer[] { 1, null }) {
1182 >
1183 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1184 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1185 >        final SubtractAction r = new SubtractAction();
1186 >
1187 >        assertTrue(f.cancel(mayInterruptIfRunning));
1188 >        g.complete(v1);
1189 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1190 >
1191 >        checkCompletedWithWrappedCancellationException(h);
1192 >        checkCancelled(f);
1193 >        assertFalse(r.ran());
1194 >        checkCompletedNormally(g, v1);
1195 >        }
1196      }
1197  
1198      /**
1199       * runAfterBoth result completes normally after normal
1200       * completion of sources
1201       */
1202 <    public void testRunAfterBoth() {
1203 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1204 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1205 <        Noop r = new Noop();
1206 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1207 <        f.complete(one);
1208 <        checkIncomplete(g);
1209 <        f2.complete(two);
1210 <        checkCompletedNormally(g, null);
1202 >    public void testRunAfterBoth_normalCompletion1() {
1203 >        for (ExecutionMode m : ExecutionMode.values())
1204 >        for (Integer v1 : new Integer[] { 1, null })
1205 >        for (Integer v2 : new Integer[] { 2, null }) {
1206 >
1207 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1208 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1209 >        final Noop r = new Noop();
1210 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1211 >
1212 >        f.complete(v1);
1213 >        checkIncomplete(h);
1214 >        assertFalse(r.ran);
1215 >        g.complete(v2);
1216 >
1217 >        checkCompletedNormally(h, null);
1218          assertTrue(r.ran);
1219 +        checkCompletedNormally(f, v1);
1220 +        checkCompletedNormally(g, v2);
1221 +        }
1222 +    }
1223  
1224 <        r = new Noop();
1225 <        f = new CompletableFuture<Integer>();
1226 <        f.complete(one);
1227 <        f2 = new CompletableFuture<Integer>();
1228 <        g = f.runAfterBoth(f2, r);
1229 <        checkIncomplete(g);
1230 <        f2.complete(two);
1231 <        checkCompletedNormally(g, null);
1224 >    public void testRunAfterBoth_normalCompletion2() {
1225 >        for (ExecutionMode m : ExecutionMode.values())
1226 >        for (Integer v1 : new Integer[] { 1, null })
1227 >        for (Integer v2 : new Integer[] { 2, null }) {
1228 >
1229 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1230 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1231 >        final Noop r = new Noop();
1232 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1233 >
1234 >        g.complete(v2);
1235 >        checkIncomplete(h);
1236 >        assertFalse(r.ran);
1237 >        f.complete(v1);
1238 >
1239 >        checkCompletedNormally(h, null);
1240 >        assertTrue(r.ran);
1241 >        checkCompletedNormally(f, v1);
1242 >        checkCompletedNormally(g, v2);
1243 >        }
1244 >    }
1245 >
1246 >    public void testRunAfterBoth_normalCompletion3() {
1247 >        for (ExecutionMode m : ExecutionMode.values())
1248 >        for (Integer v1 : new Integer[] { 1, null })
1249 >        for (Integer v2 : new Integer[] { 2, null }) {
1250 >
1251 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1252 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1253 >        final Noop r = new Noop();
1254 >
1255 >        g.complete(v2);
1256 >        f.complete(v1);
1257 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1258 >
1259 >        checkCompletedNormally(h, null);
1260 >        assertTrue(r.ran);
1261 >        checkCompletedNormally(f, v1);
1262 >        checkCompletedNormally(g, v2);
1263 >        }
1264 >    }
1265 >
1266 >    public void testRunAfterBoth_normalCompletion4() {
1267 >        for (ExecutionMode m : ExecutionMode.values())
1268 >        for (Integer v1 : new Integer[] { 1, null })
1269 >        for (Integer v2 : new Integer[] { 2, null }) {
1270 >
1271 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1272 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1273 >        final Noop r = new Noop();
1274 >
1275 >        f.complete(v1);
1276 >        g.complete(v2);
1277 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1278 >
1279 >        checkCompletedNormally(h, null);
1280          assertTrue(r.ran);
1281 +        checkCompletedNormally(f, v1);
1282 +        checkCompletedNormally(g, v2);
1283 +        }
1284      }
1285  
1286      /**
1287       * runAfterBoth result completes exceptionally after exceptional
1288       * completion of either source
1289       */
1290 <    public void testRunAfterBoth2() {
1291 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1292 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1293 <        Noop r = new Noop();
1294 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1295 <        f.completeExceptionally(new CFException());
1296 <        f2.complete(two);
1297 <        checkCompletedWithWrappedCFException(g);
1290 >    public void testRunAfterBoth_exceptionalCompletion1() {
1291 >        for (ExecutionMode m : ExecutionMode.values())
1292 >        for (Integer v1 : new Integer[] { 1, null }) {
1293 >
1294 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1295 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1296 >        final Noop r = new Noop();
1297 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1298 >        final CFException ex = new CFException();
1299 >
1300 >        f.completeExceptionally(ex);
1301 >        checkIncomplete(h);
1302 >        g.complete(v1);
1303 >
1304 >        checkCompletedWithWrappedCFException(h, ex);
1305 >        checkCompletedWithWrappedCFException(f, ex);
1306 >        assertFalse(r.ran);
1307 >        checkCompletedNormally(g, v1);
1308 >        }
1309 >    }
1310  
1311 <        r = new Noop();
1312 <        f = new CompletableFuture<Integer>();
1313 <        f.complete(one);
1314 <        f2 = new CompletableFuture<Integer>();
1315 <        g = f.runAfterBoth(f2, r);
1316 <        f2.completeExceptionally(new CFException());
1317 <        checkCompletedWithWrappedCFException(g);
1311 >    public void testRunAfterBoth_exceptionalCompletion2() {
1312 >        for (ExecutionMode m : ExecutionMode.values())
1313 >        for (Integer v1 : new Integer[] { 1, null }) {
1314 >
1315 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1316 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1317 >        final Noop r = new Noop();
1318 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1319 >        final CFException ex = new CFException();
1320 >
1321 >        g.completeExceptionally(ex);
1322 >        checkIncomplete(h);
1323 >        f.complete(v1);
1324 >
1325 >        checkCompletedWithWrappedCFException(h, ex);
1326 >        checkCompletedWithWrappedCFException(g, ex);
1327 >        assertFalse(r.ran);
1328 >        checkCompletedNormally(f, v1);
1329 >        }
1330 >    }
1331 >
1332 >    public void testRunAfterBoth_exceptionalCompletion3() {
1333 >        for (ExecutionMode m : ExecutionMode.values())
1334 >        for (Integer v1 : new Integer[] { 1, null }) {
1335 >
1336 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1337 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1338 >        final Noop r = new Noop();
1339 >        final CFException ex = new CFException();
1340 >
1341 >        g.completeExceptionally(ex);
1342 >        f.complete(v1);
1343 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1344 >
1345 >        checkCompletedWithWrappedCFException(h, ex);
1346 >        checkCompletedWithWrappedCFException(g, ex);
1347 >        assertFalse(r.ran);
1348 >        checkCompletedNormally(f, v1);
1349 >        }
1350 >    }
1351 >
1352 >    public void testRunAfterBoth_exceptionalCompletion4() {
1353 >        for (ExecutionMode m : ExecutionMode.values())
1354 >        for (Integer v1 : new Integer[] { 1, null }) {
1355 >
1356 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1357 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1358 >        final Noop r = new Noop();
1359 >        final CFException ex = new CFException();
1360 >
1361 >        f.completeExceptionally(ex);
1362 >        g.complete(v1);
1363 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1364 >
1365 >        checkCompletedWithWrappedCFException(h, ex);
1366 >        checkCompletedWithWrappedCFException(f, ex);
1367 >        assertFalse(r.ran);
1368 >        checkCompletedNormally(g, v1);
1369 >        }
1370      }
1371  
1372      /**
1373       * runAfterBoth result completes exceptionally if action does
1374       */
1375 <    public void testRunAfterBoth3() {
1376 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1377 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1378 <        FailingNoop r = new FailingNoop();
1379 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1380 <        f.complete(one);
1381 <        checkIncomplete(g);
1382 <        f2.complete(two);
1383 <        checkCompletedWithWrappedCFException(g);
1375 >    public void testRunAfterBoth_actionFailed1() {
1376 >        for (ExecutionMode m : ExecutionMode.values())
1377 >        for (Integer v1 : new Integer[] { 1, null })
1378 >        for (Integer v2 : new Integer[] { 2, null }) {
1379 >
1380 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1381 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1382 >        final FailingNoop r = new FailingNoop();
1383 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1384 >
1385 >        f.complete(v1);
1386 >        checkIncomplete(h);
1387 >        g.complete(v2);
1388 >
1389 >        checkCompletedWithWrappedCFException(h);
1390 >        checkCompletedNormally(f, v1);
1391 >        checkCompletedNormally(g, v2);
1392 >        }
1393 >    }
1394 >
1395 >    public void testRunAfterBoth_actionFailed2() {
1396 >        for (ExecutionMode m : ExecutionMode.values())
1397 >        for (Integer v1 : new Integer[] { 1, null })
1398 >        for (Integer v2 : new Integer[] { 2, null }) {
1399 >
1400 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1401 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1402 >        final FailingNoop r = new FailingNoop();
1403 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1404 >
1405 >        g.complete(v2);
1406 >        checkIncomplete(h);
1407 >        f.complete(v1);
1408 >
1409 >        checkCompletedWithWrappedCFException(h);
1410 >        checkCompletedNormally(f, v1);
1411 >        checkCompletedNormally(g, v2);
1412 >        }
1413      }
1414  
1415      /**
1416       * runAfterBoth result completes exceptionally if either source cancelled
1417       */
1418 <    public void testRunAfterBoth4() {
1419 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1420 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1421 <        Noop r = new Noop();
1422 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1423 <        assertTrue(f.cancel(true));
1424 <        f2.complete(two);
1425 <        checkCompletedWithWrappedCancellationException(g);
1426 <        f = new CompletableFuture<Integer>();
1427 <        f2 = new CompletableFuture<Integer>();
1428 <        r = new Noop();
1429 <        g = f.runAfterBoth(f2, r);
1430 <        f.complete(one);
1431 <        assertTrue(f2.cancel(true));
1432 <        checkCompletedWithWrappedCancellationException(g);
1418 >    public void testRunAfterBoth_sourceCancelled1() {
1419 >        for (ExecutionMode m : ExecutionMode.values())
1420 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1421 >        for (Integer v1 : new Integer[] { 1, null }) {
1422 >
1423 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1424 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1425 >        final Noop r = new Noop();
1426 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1427 >
1428 >        assertTrue(f.cancel(mayInterruptIfRunning));
1429 >        checkIncomplete(h);
1430 >        g.complete(v1);
1431 >
1432 >        checkCompletedWithWrappedCancellationException(h);
1433 >        checkCancelled(f);
1434 >        assertFalse(r.ran);
1435 >        checkCompletedNormally(g, v1);
1436 >        }
1437 >    }
1438 >
1439 >    public void testRunAfterBoth_sourceCancelled2() {
1440 >        for (ExecutionMode m : ExecutionMode.values())
1441 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1442 >        for (Integer v1 : new Integer[] { 1, null }) {
1443 >
1444 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1445 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1446 >        final Noop r = new Noop();
1447 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1448 >
1449 >        assertTrue(g.cancel(mayInterruptIfRunning));
1450 >        checkIncomplete(h);
1451 >        f.complete(v1);
1452 >
1453 >        checkCompletedWithWrappedCancellationException(h);
1454 >        checkCancelled(g);
1455 >        assertFalse(r.ran);
1456 >        checkCompletedNormally(f, v1);
1457 >        }
1458 >    }
1459 >
1460 >    public void testRunAfterBoth_sourceCancelled3() {
1461 >        for (ExecutionMode m : ExecutionMode.values())
1462 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1463 >        for (Integer v1 : new Integer[] { 1, null }) {
1464 >
1465 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1466 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1467 >        final Noop r = new Noop();
1468 >
1469 >        assertTrue(g.cancel(mayInterruptIfRunning));
1470 >        f.complete(v1);
1471 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1472 >
1473 >        checkCompletedWithWrappedCancellationException(h);
1474 >        checkCancelled(g);
1475 >        assertFalse(r.ran);
1476 >        checkCompletedNormally(f, v1);
1477 >        }
1478 >    }
1479 >
1480 >    public void testRunAfterBoth_sourceCancelled4() {
1481 >        for (ExecutionMode m : ExecutionMode.values())
1482 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1483 >        for (Integer v1 : new Integer[] { 1, null }) {
1484 >
1485 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1486 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1487 >        final Noop r = new Noop();
1488 >
1489 >        assertTrue(f.cancel(mayInterruptIfRunning));
1490 >        g.complete(v1);
1491 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1492 >
1493 >        checkCompletedWithWrappedCancellationException(h);
1494 >        checkCancelled(f);
1495 >        assertFalse(r.ran);
1496 >        checkCompletedNormally(g, v1);
1497 >        }
1498      }
1499  
1500      /**
# Line 839 | Line 1502 | public class CompletableFutureTest exten
1502       * of either source
1503       */
1504      public void testApplyToEither() {
1505 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1506 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1505 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1506 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1507          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1508          f.complete(one);
1509          checkCompletedNormally(g, two);
1510          f2.complete(one);
1511          checkCompletedNormally(g, two);
1512  
1513 <        f = new CompletableFuture<Integer>();
1513 >        f = new CompletableFuture<>();
1514          f.complete(one);
1515 <        f2 = new CompletableFuture<Integer>();
1515 >        f2 = new CompletableFuture<>();
1516          g = f.applyToEither(f2, inc);
1517          checkCompletedNormally(g, two);
1518      }
# Line 859 | Line 1522 | public class CompletableFutureTest exten
1522       * completion of either source
1523       */
1524      public void testApplyToEither2() {
1525 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1526 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1525 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1526 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1527          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1528          f.completeExceptionally(new CFException());
1529          f2.complete(one);
1530          checkCompletedWithWrappedCFException(g);
1531  
1532 <        f = new CompletableFuture<Integer>();
1533 <        f2 = new CompletableFuture<Integer>();
1532 >        f = new CompletableFuture<>();
1533 >        f2 = new CompletableFuture<>();
1534          f2.completeExceptionally(new CFException());
1535          g = f.applyToEither(f2, inc);
1536          checkCompletedWithWrappedCFException(g);
# Line 877 | Line 1540 | public class CompletableFutureTest exten
1540       * applyToEither result completes exceptionally if action does
1541       */
1542      public void testApplyToEither3() {
1543 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1544 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1543 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1544 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1545          FailingFunction r = new FailingFunction();
1546          CompletableFuture<Integer> g = f.applyToEither(f2, r);
1547          f2.complete(two);
# Line 889 | Line 1552 | public class CompletableFutureTest exten
1552       * applyToEither result completes exceptionally if either source cancelled
1553       */
1554      public void testApplyToEither4() {
1555 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1556 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1555 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1556 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1557          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1558          assertTrue(f.cancel(true));
1559          checkCompletedWithWrappedCancellationException(g);
1560 <        f = new CompletableFuture<Integer>();
1561 <        f2 = new CompletableFuture<Integer>();
1560 >        f = new CompletableFuture<>();
1561 >        f2 = new CompletableFuture<>();
1562          assertTrue(f2.cancel(true));
1563          checkCompletedWithWrappedCancellationException(g);
1564      }
# Line 905 | Line 1568 | public class CompletableFutureTest exten
1568       * of either source
1569       */
1570      public void testAcceptEither() {
1571 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1572 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1571 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1572 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1573          IncAction r = new IncAction();
1574          CompletableFuture<Void> g = f.acceptEither(f2, r);
1575          f.complete(one);
# Line 916 | Line 1579 | public class CompletableFutureTest exten
1579          assertEquals(r.value, 2);
1580  
1581          r = new IncAction();
1582 <        f = new CompletableFuture<Integer>();
1582 >        f = new CompletableFuture<>();
1583          f.complete(one);
1584 <        f2 = new CompletableFuture<Integer>();
1584 >        f2 = new CompletableFuture<>();
1585          g = f.acceptEither(f2, r);
1586          checkCompletedNormally(g, null);
1587          assertEquals(r.value, 2);
# Line 929 | Line 1592 | public class CompletableFutureTest exten
1592       * completion of either source
1593       */
1594      public void testAcceptEither2() {
1595 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1596 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1595 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1596 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1597          IncAction r = new IncAction();
1598          CompletableFuture<Void> g = f.acceptEither(f2, r);
1599          f.completeExceptionally(new CFException());
# Line 938 | Line 1601 | public class CompletableFutureTest exten
1601          checkCompletedWithWrappedCFException(g);
1602  
1603          r = new IncAction();
1604 <        f = new CompletableFuture<Integer>();
1605 <        f2 = new CompletableFuture<Integer>();
1604 >        f = new CompletableFuture<>();
1605 >        f2 = new CompletableFuture<>();
1606          f2.completeExceptionally(new CFException());
1607          g = f.acceptEither(f2, r);
1608          checkCompletedWithWrappedCFException(g);
# Line 949 | Line 1612 | public class CompletableFutureTest exten
1612       * acceptEither result completes exceptionally if action does
1613       */
1614      public void testAcceptEither3() {
1615 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1616 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1615 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1616 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1617          FailingConsumer r = new FailingConsumer();
1618          CompletableFuture<Void> g = f.acceptEither(f2, r);
1619          f2.complete(two);
# Line 961 | Line 1624 | public class CompletableFutureTest exten
1624       * acceptEither result completes exceptionally if either source cancelled
1625       */
1626      public void testAcceptEither4() {
1627 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1628 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1627 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1628 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1629          IncAction r = new IncAction();
1630          CompletableFuture<Void> g = f.acceptEither(f2, r);
1631          assertTrue(f.cancel(true));
1632          checkCompletedWithWrappedCancellationException(g);
1633 <        f = new CompletableFuture<Integer>();
1634 <        f2 = new CompletableFuture<Integer>();
1633 >        f = new CompletableFuture<>();
1634 >        f2 = new CompletableFuture<>();
1635          assertTrue(f2.cancel(true));
1636          checkCompletedWithWrappedCancellationException(g);
1637      }
1638  
976
1639      /**
1640       * runAfterEither result completes normally after normal completion
1641       * of either source
1642       */
1643      public void testRunAfterEither() {
1644 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1645 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1644 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1645 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1646          Noop r = new Noop();
1647          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1648          f.complete(one);
# Line 990 | Line 1652 | public class CompletableFutureTest exten
1652          assertTrue(r.ran);
1653  
1654          r = new Noop();
1655 <        f = new CompletableFuture<Integer>();
1655 >        f = new CompletableFuture<>();
1656          f.complete(one);
1657 <        f2 = new CompletableFuture<Integer>();
1657 >        f2 = new CompletableFuture<>();
1658          g = f.runAfterEither(f2, r);
1659          checkCompletedNormally(g, null);
1660          assertTrue(r.ran);
# Line 1003 | Line 1665 | public class CompletableFutureTest exten
1665       * completion of either source
1666       */
1667      public void testRunAfterEither2() {
1668 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1669 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1668 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1669 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1670          Noop r = new Noop();
1671          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1672          f.completeExceptionally(new CFException());
# Line 1012 | Line 1674 | public class CompletableFutureTest exten
1674          checkCompletedWithWrappedCFException(g);
1675  
1676          r = new Noop();
1677 <        f = new CompletableFuture<Integer>();
1678 <        f2 = new CompletableFuture<Integer>();
1677 >        f = new CompletableFuture<>();
1678 >        f2 = new CompletableFuture<>();
1679          f2.completeExceptionally(new CFException());
1680          g = f.runAfterEither(f2, r);
1681          checkCompletedWithWrappedCFException(g);
# Line 1023 | Line 1685 | public class CompletableFutureTest exten
1685       * runAfterEither result completes exceptionally if action does
1686       */
1687      public void testRunAfterEither3() {
1688 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1689 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1688 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1689 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1690          FailingNoop r = new FailingNoop();
1691          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1692          f2.complete(two);
# Line 1035 | Line 1697 | public class CompletableFutureTest exten
1697       * runAfterEither result completes exceptionally if either source cancelled
1698       */
1699      public void testRunAfterEither4() {
1700 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1701 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1700 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1701 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1702          Noop r = new Noop();
1703          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1704          assertTrue(f.cancel(true));
1705          checkCompletedWithWrappedCancellationException(g);
1706 <        f = new CompletableFuture<Integer>();
1707 <        f2 = new CompletableFuture<Integer>();
1706 >        f = new CompletableFuture<>();
1707 >        f2 = new CompletableFuture<>();
1708          assertTrue(f2.cancel(true));
1709          checkCompletedWithWrappedCancellationException(g);
1710      }
# Line 1051 | Line 1713 | public class CompletableFutureTest exten
1713       * thenCompose result completes normally after normal completion of source
1714       */
1715      public void testThenCompose() {
1716 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1717 <        CompletableFutureInc r = new CompletableFutureInc();
1718 <        CompletableFuture<Integer> g = f.thenCompose(r);
1716 >        CompletableFuture<Integer> f, g;
1717 >        CompletableFutureInc r;
1718 >
1719 >        f = new CompletableFuture<>();
1720 >        g = f.thenCompose(r = new CompletableFutureInc());
1721 >        f.complete(one);
1722 >        checkCompletedNormally(g, two);
1723 >        assertTrue(r.ran);
1724 >
1725 >        f = new CompletableFuture<>();
1726          f.complete(one);
1727 +        g = f.thenCompose(r = new CompletableFutureInc());
1728          checkCompletedNormally(g, two);
1729 +        assertTrue(r.ran);
1730      }
1731  
1732      /**
# Line 1063 | Line 1734 | public class CompletableFutureTest exten
1734       * completion of source
1735       */
1736      public void testThenCompose2() {
1737 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1738 <        CompletableFutureInc r = new CompletableFutureInc();
1739 <        CompletableFuture<Integer> g = f.thenCompose(r);
1737 >        CompletableFuture<Integer> f, g;
1738 >        CompletableFutureInc r;
1739 >
1740 >        f = new CompletableFuture<>();
1741 >        g = f.thenCompose(r = new CompletableFutureInc());
1742          f.completeExceptionally(new CFException());
1743          checkCompletedWithWrappedCFException(g);
1744 +
1745 +        f = new CompletableFuture<>();
1746 +        f.completeExceptionally(new CFException());
1747 +        g = f.thenCompose(r = new CompletableFutureInc());
1748 +        checkCompletedWithWrappedCFException(g);
1749      }
1750  
1751      /**
1752       * thenCompose result completes exceptionally if action does
1753       */
1754      public void testThenCompose3() {
1755 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1756 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
1757 <        CompletableFuture<Integer> g = f.thenCompose(r);
1755 >        CompletableFuture<Integer> f, g;
1756 >        FailingCompletableFutureFunction r;
1757 >
1758 >        f = new CompletableFuture<>();
1759 >        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1760          f.complete(one);
1761          checkCompletedWithWrappedCFException(g);
1762 +
1763 +        f = new CompletableFuture<>();
1764 +        f.complete(one);
1765 +        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1766 +        checkCompletedWithWrappedCFException(g);
1767      }
1768  
1769      /**
1770       * thenCompose result completes exceptionally if source cancelled
1771       */
1772      public void testThenCompose4() {
1773 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1774 <        CompletableFutureInc r = new CompletableFutureInc();
1775 <        CompletableFuture<Integer> g = f.thenCompose(r);
1773 >        CompletableFuture<Integer> f, g;
1774 >        CompletableFutureInc r;
1775 >
1776 >        f = new CompletableFuture<>();
1777 >        g = f.thenCompose(r = new CompletableFutureInc());
1778          assertTrue(f.cancel(true));
1779          checkCompletedWithWrappedCancellationException(g);
1093    }
1780  
1781 +        f = new CompletableFuture<>();
1782 +        assertTrue(f.cancel(true));
1783 +        g = f.thenCompose(r = new CompletableFutureInc());
1784 +        checkCompletedWithWrappedCancellationException(g);
1785 +    }
1786  
1787      // asyncs
1788  
# Line 1099 | Line 1790 | public class CompletableFutureTest exten
1790       * thenRunAsync result completes normally after normal completion of source
1791       */
1792      public void testThenRunAsync() {
1793 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1793 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1794          Noop r = new Noop();
1795          CompletableFuture<Void> g = f.thenRunAsync(r);
1796          f.complete(null);
1797          checkCompletedNormally(g, null);
1798  
1799          // reordered version
1800 <        f = new CompletableFuture<Integer>();
1800 >        f = new CompletableFuture<>();
1801          f.complete(null);
1802          r = new Noop();
1803          g = f.thenRunAsync(r);
# Line 1118 | Line 1809 | public class CompletableFutureTest exten
1809       * completion of source
1810       */
1811      public void testThenRunAsync2() {
1812 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1812 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1813          Noop r = new Noop();
1814          CompletableFuture<Void> g = f.thenRunAsync(r);
1815          f.completeExceptionally(new CFException());
1816          try {
1817              g.join();
1818              shouldThrow();
1819 <        } catch (Exception ok) {
1129 <        }
1819 >        } catch (CompletionException success) {}
1820          checkCompletedWithWrappedCFException(g);
1821      }
1822  
# Line 1134 | Line 1824 | public class CompletableFutureTest exten
1824       * thenRunAsync result completes exceptionally if action does
1825       */
1826      public void testThenRunAsync3() {
1827 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1827 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1828          FailingNoop r = new FailingNoop();
1829          CompletableFuture<Void> g = f.thenRunAsync(r);
1830          f.complete(null);
# Line 1145 | Line 1835 | public class CompletableFutureTest exten
1835       * thenRunAsync result completes exceptionally if source cancelled
1836       */
1837      public void testThenRunAsync4() {
1838 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1838 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1839          Noop r = new Noop();
1840          CompletableFuture<Void> g = f.thenRunAsync(r);
1841          assertTrue(f.cancel(true));
# Line 1156 | Line 1846 | public class CompletableFutureTest exten
1846       * thenApplyAsync result completes normally after normal completion of source
1847       */
1848      public void testThenApplyAsync() {
1849 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1849 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1850          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1851          f.complete(one);
1852          checkCompletedNormally(g, two);
# Line 1167 | Line 1857 | public class CompletableFutureTest exten
1857       * completion of source
1858       */
1859      public void testThenApplyAsync2() {
1860 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1860 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1861          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1862          f.completeExceptionally(new CFException());
1863          checkCompletedWithWrappedCFException(g);
# Line 1177 | Line 1867 | public class CompletableFutureTest exten
1867       * thenApplyAsync result completes exceptionally if action does
1868       */
1869      public void testThenApplyAsync3() {
1870 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1870 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1871          FailingFunction r = new FailingFunction();
1872          CompletableFuture<Integer> g = f.thenApplyAsync(r);
1873          f.complete(null);
# Line 1188 | Line 1878 | public class CompletableFutureTest exten
1878       * thenApplyAsync result completes exceptionally if source cancelled
1879       */
1880      public void testThenApplyAsync4() {
1881 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1881 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1882          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1883          assertTrue(f.cancel(true));
1884          checkCompletedWithWrappedCancellationException(g);
# Line 1199 | Line 1889 | public class CompletableFutureTest exten
1889       * completion of source
1890       */
1891      public void testThenAcceptAsync() {
1892 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1892 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1893          IncAction r = new IncAction();
1894          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1895          f.complete(one);
# Line 1212 | Line 1902 | public class CompletableFutureTest exten
1902       * completion of source
1903       */
1904      public void testThenAcceptAsync2() {
1905 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1905 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1906          IncAction r = new IncAction();
1907          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1908          f.completeExceptionally(new CFException());
# Line 1223 | Line 1913 | public class CompletableFutureTest exten
1913       * thenAcceptAsync result completes exceptionally if action does
1914       */
1915      public void testThenAcceptAsync3() {
1916 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1916 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1917          FailingConsumer r = new FailingConsumer();
1918          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1919          f.complete(null);
# Line 1234 | Line 1924 | public class CompletableFutureTest exten
1924       * thenAcceptAsync result completes exceptionally if source cancelled
1925       */
1926      public void testThenAcceptAsync4() {
1927 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1927 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1928          IncAction r = new IncAction();
1929          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1930          assertTrue(f.cancel(true));
1931          checkCompletedWithWrappedCancellationException(g);
1932      }
1933 +
1934      /**
1935       * thenCombineAsync result completes normally after normal
1936       * completion of sources
1937       */
1938      public void testThenCombineAsync() {
1939 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1940 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1941 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1942 <        f.complete(one);
1943 <        checkIncomplete(g);
1944 <        f2.complete(two);
1945 <        checkCompletedNormally(g, three);
1939 >        CompletableFuture<Integer> f, g, h;
1940 >
1941 >        f = new CompletableFuture<>();
1942 >        g = new CompletableFuture<>();
1943 >        h = f.thenCombineAsync(g, subtract);
1944 >        f.complete(3);
1945 >        checkIncomplete(h);
1946 >        g.complete(1);
1947 >        checkCompletedNormally(h, 2);
1948 >
1949 >        f = new CompletableFuture<>();
1950 >        g = new CompletableFuture<>();
1951 >        h = f.thenCombineAsync(g, subtract);
1952 >        g.complete(1);
1953 >        checkIncomplete(h);
1954 >        f.complete(3);
1955 >        checkCompletedNormally(h, 2);
1956 >
1957 >        f = new CompletableFuture<>();
1958 >        g = new CompletableFuture<>();
1959 >        g.complete(1);
1960 >        f.complete(3);
1961 >        h = f.thenCombineAsync(g, subtract);
1962 >        checkCompletedNormally(h, 2);
1963      }
1964  
1965      /**
1966       * thenCombineAsync result completes exceptionally after exceptional
1967 <     * completion of source
1967 >     * completion of either source
1968       */
1969      public void testThenCombineAsync2() {
1970 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1263 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1264 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1265 <        f.completeExceptionally(new CFException());
1266 <        f2.complete(two);
1267 <        checkCompletedWithWrappedCFException(g);
1970 >        CompletableFuture<Integer> f, g, h;
1971  
1972 <        f = new CompletableFuture<Integer>();
1973 <        f2 = new CompletableFuture<Integer>();
1974 <        g = f.thenCombineAsync(f2, add);
1975 <        f.complete(one);
1976 <        f2.completeExceptionally(new CFException());
1977 <        checkCompletedWithWrappedCFException(g);
1972 >        f = new CompletableFuture<>();
1973 >        g = new CompletableFuture<>();
1974 >        h = f.thenCombineAsync(g, subtract);
1975 >        f.completeExceptionally(new CFException());
1976 >        checkIncomplete(h);
1977 >        g.complete(1);
1978 >        checkCompletedWithWrappedCFException(h);
1979 >
1980 >        f = new CompletableFuture<>();
1981 >        g = new CompletableFuture<>();
1982 >        h = f.thenCombineAsync(g, subtract);
1983 >        g.completeExceptionally(new CFException());
1984 >        checkIncomplete(h);
1985 >        f.complete(3);
1986 >        checkCompletedWithWrappedCFException(h);
1987 >
1988 >        f = new CompletableFuture<>();
1989 >        g = new CompletableFuture<>();
1990 >        g.completeExceptionally(new CFException());
1991 >        f.complete(3);
1992 >        h = f.thenCombineAsync(g, subtract);
1993 >        checkCompletedWithWrappedCFException(h);
1994      }
1995  
1996      /**
1997       * thenCombineAsync result completes exceptionally if action does
1998       */
1999      public void testThenCombineAsync3() {
2000 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2001 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2000 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2001 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2002          FailingBiFunction r = new FailingBiFunction();
2003          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
2004          f.complete(one);
2005          checkIncomplete(g);
2006 +        assertFalse(r.ran);
2007          f2.complete(two);
2008          checkCompletedWithWrappedCFException(g);
2009 +        assertTrue(r.ran);
2010      }
2011  
2012      /**
2013       * thenCombineAsync result completes exceptionally if either source cancelled
2014       */
2015      public void testThenCombineAsync4() {
2016 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1296 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1297 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1298 <        assertTrue(f.cancel(true));
1299 <        f2.complete(two);
1300 <        checkCompletedWithWrappedCancellationException(g);
1301 <
1302 <        f = new CompletableFuture<Integer>();
1303 <        f2 = new CompletableFuture<Integer>();
1304 <        g = f.thenCombineAsync(f2, add);
1305 <        f.complete(one);
1306 <        assertTrue(f2.cancel(true));
1307 <        checkCompletedWithWrappedCancellationException(g);
1308 <    }
1309 <
1310 <    /**
1311 <     * thenAcceptBothAsync result completes normally after normal
1312 <     * completion of sources
1313 <     */
1314 <    public void testThenAcceptBothAsync() {
1315 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1316 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1317 <        AddAction r = new AddAction();
1318 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1319 <        f.complete(one);
1320 <        checkIncomplete(g);
1321 <        f2.complete(two);
1322 <        checkCompletedNormally(g, null);
1323 <        assertEquals(r.value, 3);
1324 <    }
1325 <
1326 <    /**
1327 <     * thenAcceptBothAsync result completes exceptionally after exceptional
1328 <     * completion of source
1329 <     */
1330 <    public void testThenAcceptBothAsync2() {
1331 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1332 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1333 <        AddAction r = new AddAction();
1334 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1335 <        f.completeExceptionally(new CFException());
1336 <        f2.complete(two);
1337 <        checkCompletedWithWrappedCFException(g);
1338 <
1339 <        r = new AddAction();
1340 <        f = new CompletableFuture<Integer>();
1341 <        f2 = new CompletableFuture<Integer>();
1342 <        g = f.thenAcceptBothAsync(f2, r);
1343 <        f.complete(one);
1344 <        f2.completeExceptionally(new CFException());
1345 <        checkCompletedWithWrappedCFException(g);
1346 <    }
1347 <
1348 <    /**
1349 <     * thenAcceptBothAsync result completes exceptionally if action does
1350 <     */
1351 <    public void testThenAcceptBothAsync3() {
1352 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1353 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1354 <        FailingBiConsumer r = new FailingBiConsumer();
1355 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1356 <        f.complete(one);
1357 <        checkIncomplete(g);
1358 <        f2.complete(two);
1359 <        checkCompletedWithWrappedCFException(g);
1360 <    }
1361 <
1362 <    /**
1363 <     * thenAcceptBothAsync result completes exceptionally if either source cancelled
1364 <     */
1365 <    public void testThenAcceptBothAsync4() {
1366 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1367 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1368 <        AddAction r = new AddAction();
1369 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1370 <        assertTrue(f.cancel(true));
1371 <        f2.complete(two);
1372 <        checkCompletedWithWrappedCancellationException(g);
1373 <
1374 <        r = new AddAction();
1375 <        f = new CompletableFuture<Integer>();
1376 <        f2 = new CompletableFuture<Integer>();
1377 <        g = f.thenAcceptBothAsync(f2, r);
1378 <        f.complete(one);
1379 <        assertTrue(f2.cancel(true));
1380 <        checkCompletedWithWrappedCancellationException(g);
1381 <    }
1382 <
1383 <    /**
1384 <     * runAfterBothAsync result completes normally after normal
1385 <     * completion of sources
1386 <     */
1387 <    public void testRunAfterBothAsync() {
1388 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1389 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1390 <        Noop r = new Noop();
1391 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1392 <        f.complete(one);
1393 <        checkIncomplete(g);
1394 <        f2.complete(two);
1395 <        checkCompletedNormally(g, null);
1396 <        assertTrue(r.ran);
1397 <    }
2016 >        CompletableFuture<Integer> f, g, h;
2017  
2018 <    /**
2019 <     * runAfterBothAsync result completes exceptionally after exceptional
2020 <     * completion of source
2021 <     */
2022 <    public void testRunAfterBothAsync2() {
2023 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2024 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2025 <        Noop r = new Noop();
2026 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
2027 <        f.completeExceptionally(new CFException());
2028 <        f2.complete(two);
2029 <        checkCompletedWithWrappedCFException(g);
2030 <
2031 <        r = new Noop();
2032 <        f = new CompletableFuture<Integer>();
2033 <        f2 = new CompletableFuture<Integer>();
2034 <        g = f.runAfterBothAsync(f2, r);
2035 <        f.complete(one);
2036 <        f2.completeExceptionally(new CFException());
2037 <        checkCompletedWithWrappedCFException(g);
2038 <    }
2039 <
2040 <    /**
2041 <     * runAfterBothAsync result completes exceptionally if action does
2042 <     */
2043 <    public void testRunAfterBothAsync3() {
2044 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2045 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2046 <        FailingNoop r = new FailingNoop();
1428 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1429 <        f.complete(one);
1430 <        checkIncomplete(g);
1431 <        f2.complete(two);
1432 <        checkCompletedWithWrappedCFException(g);
1433 <    }
1434 <
1435 <    /**
1436 <     * runAfterBothAsync result completes exceptionally if either source cancelled
1437 <     */
1438 <    public void testRunAfterBothAsync4() {
1439 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1440 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1441 <        Noop r = new Noop();
1442 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1443 <        assertTrue(f.cancel(true));
1444 <        f2.complete(two);
1445 <        checkCompletedWithWrappedCancellationException(g);
1446 <
1447 <        r = new Noop();
1448 <        f = new CompletableFuture<Integer>();
1449 <        f2 = new CompletableFuture<Integer>();
1450 <        g = f.runAfterBothAsync(f2, r);
1451 <        f.complete(one);
1452 <        assertTrue(f2.cancel(true));
1453 <        checkCompletedWithWrappedCancellationException(g);
2018 >        f = new CompletableFuture<>();
2019 >        g = new CompletableFuture<>();
2020 >        h = f.thenCombineAsync(g, subtract);
2021 >        assertTrue(f.cancel(true));
2022 >        checkIncomplete(h);
2023 >        g.complete(1);
2024 >        checkCompletedWithWrappedCancellationException(h);
2025 >
2026 >        f = new CompletableFuture<>();
2027 >        g = new CompletableFuture<>();
2028 >        h = f.thenCombineAsync(g, subtract);
2029 >        assertTrue(g.cancel(true));
2030 >        checkIncomplete(h);
2031 >        f.complete(3);
2032 >        checkCompletedWithWrappedCancellationException(h);
2033 >
2034 >        f = new CompletableFuture<>();
2035 >        g = new CompletableFuture<>();
2036 >        g.complete(3);
2037 >        assertTrue(f.cancel(true));
2038 >        h = f.thenCombineAsync(g, subtract);
2039 >        checkCompletedWithWrappedCancellationException(h);
2040 >
2041 >        f = new CompletableFuture<>();
2042 >        g = new CompletableFuture<>();
2043 >        f.complete(3);
2044 >        assertTrue(g.cancel(true));
2045 >        h = f.thenCombineAsync(g, subtract);
2046 >        checkCompletedWithWrappedCancellationException(h);
2047      }
2048  
2049      /**
# Line 1458 | Line 2051 | public class CompletableFutureTest exten
2051       * completion of sources
2052       */
2053      public void testApplyToEitherAsync() {
2054 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2055 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2054 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2055 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2056          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2057          f.complete(one);
2058          checkCompletedNormally(g, two);
2059  
2060 <        f = new CompletableFuture<Integer>();
2060 >        f = new CompletableFuture<>();
2061          f.complete(one);
2062 <        f2 = new CompletableFuture<Integer>();
2062 >        f2 = new CompletableFuture<>();
2063          g = f.applyToEitherAsync(f2, inc);
2064          checkCompletedNormally(g, two);
2065      }
# Line 1476 | Line 2069 | public class CompletableFutureTest exten
2069       * completion of source
2070       */
2071      public void testApplyToEitherAsync2() {
2072 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2073 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2072 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2073 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2074          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2075          f.completeExceptionally(new CFException());
2076          checkCompletedWithWrappedCFException(g);
2077  
2078 <        f = new CompletableFuture<Integer>();
2079 <        f2 = new CompletableFuture<Integer>();
2078 >        f = new CompletableFuture<>();
2079 >        f2 = new CompletableFuture<>();
2080          f2.completeExceptionally(new CFException());
2081          g = f.applyToEitherAsync(f2, inc);
2082          f.complete(one);
# Line 1494 | Line 2087 | public class CompletableFutureTest exten
2087       * applyToEitherAsync result completes exceptionally if action does
2088       */
2089      public void testApplyToEitherAsync3() {
2090 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2091 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2090 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2091 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2092          FailingFunction r = new FailingFunction();
2093          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
2094          f.complete(one);
# Line 1506 | Line 2099 | public class CompletableFutureTest exten
2099       * applyToEitherAsync result completes exceptionally if either source cancelled
2100       */
2101      public void testApplyToEitherAsync4() {
2102 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2103 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2102 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2103 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2104          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2105          assertTrue(f.cancel(true));
2106          checkCompletedWithWrappedCancellationException(g);
2107  
2108 <        f = new CompletableFuture<Integer>();
2109 <        f2 = new CompletableFuture<Integer>();
2108 >        f = new CompletableFuture<>();
2109 >        f2 = new CompletableFuture<>();
2110          assertTrue(f2.cancel(true));
2111          g = f.applyToEitherAsync(f2, inc);
2112          checkCompletedWithWrappedCancellationException(g);
# Line 1524 | Line 2117 | public class CompletableFutureTest exten
2117       * completion of sources
2118       */
2119      public void testAcceptEitherAsync() {
2120 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2121 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2120 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2121 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2122          IncAction r = new IncAction();
2123          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2124          f.complete(one);
# Line 1533 | Line 2126 | public class CompletableFutureTest exten
2126          assertEquals(r.value, 2);
2127  
2128          r = new IncAction();
2129 <        f = new CompletableFuture<Integer>();
2129 >        f = new CompletableFuture<>();
2130          f.complete(one);
2131 <        f2 = new CompletableFuture<Integer>();
2131 >        f2 = new CompletableFuture<>();
2132          g = f.acceptEitherAsync(f2, r);
2133          checkCompletedNormally(g, null);
2134          assertEquals(r.value, 2);
# Line 1546 | Line 2139 | public class CompletableFutureTest exten
2139       * completion of source
2140       */
2141      public void testAcceptEitherAsync2() {
2142 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2143 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2142 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2143 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2144          IncAction r = new IncAction();
2145          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2146          f.completeExceptionally(new CFException());
2147          checkCompletedWithWrappedCFException(g);
2148  
2149          r = new IncAction();
2150 <        f = new CompletableFuture<Integer>();
2151 <        f2 = new CompletableFuture<Integer>();
2150 >        f = new CompletableFuture<>();
2151 >        f2 = new CompletableFuture<>();
2152          f2.completeExceptionally(new CFException());
2153          g = f.acceptEitherAsync(f2, r);
2154          f.complete(one);
# Line 1566 | Line 2159 | public class CompletableFutureTest exten
2159       * acceptEitherAsync result completes exceptionally if action does
2160       */
2161      public void testAcceptEitherAsync3() {
2162 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2163 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2162 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2163 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2164          FailingConsumer r = new FailingConsumer();
2165          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2166          f.complete(one);
# Line 1579 | Line 2172 | public class CompletableFutureTest exten
2172       * source cancelled
2173       */
2174      public void testAcceptEitherAsync4() {
2175 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2176 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2175 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2176 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2177          IncAction r = new IncAction();
2178          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2179          assertTrue(f.cancel(true));
2180          checkCompletedWithWrappedCancellationException(g);
2181  
2182          r = new IncAction();
2183 <        f = new CompletableFuture<Integer>();
2184 <        f2 = new CompletableFuture<Integer>();
2183 >        f = new CompletableFuture<>();
2184 >        f2 = new CompletableFuture<>();
2185          assertTrue(f2.cancel(true));
2186          g = f.acceptEitherAsync(f2, r);
2187          checkCompletedWithWrappedCancellationException(g);
# Line 1599 | Line 2192 | public class CompletableFutureTest exten
2192       * completion of sources
2193       */
2194      public void testRunAfterEitherAsync() {
2195 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2196 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2195 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2196 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2197          Noop r = new Noop();
2198          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2199          f.complete(one);
# Line 1608 | Line 2201 | public class CompletableFutureTest exten
2201          assertTrue(r.ran);
2202  
2203          r = new Noop();
2204 <        f = new CompletableFuture<Integer>();
2204 >        f = new CompletableFuture<>();
2205          f.complete(one);
2206 <        f2 = new CompletableFuture<Integer>();
2206 >        f2 = new CompletableFuture<>();
2207          g = f.runAfterEitherAsync(f2, r);
2208          checkCompletedNormally(g, null);
2209          assertTrue(r.ran);
# Line 1621 | Line 2214 | public class CompletableFutureTest exten
2214       * completion of source
2215       */
2216      public void testRunAfterEitherAsync2() {
2217 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2218 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2217 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2218 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2219          Noop r = new Noop();
2220          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2221          f.completeExceptionally(new CFException());
2222          checkCompletedWithWrappedCFException(g);
2223  
2224          r = new Noop();
2225 <        f = new CompletableFuture<Integer>();
2226 <        f2 = new CompletableFuture<Integer>();
2225 >        f = new CompletableFuture<>();
2226 >        f2 = new CompletableFuture<>();
2227          f2.completeExceptionally(new CFException());
2228          g = f.runAfterEitherAsync(f2, r);
2229          f.complete(one);
# Line 1641 | Line 2234 | public class CompletableFutureTest exten
2234       * runAfterEitherAsync result completes exceptionally if action does
2235       */
2236      public void testRunAfterEitherAsync3() {
2237 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2238 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2237 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2238 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2239          FailingNoop r = new FailingNoop();
2240          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2241          f.complete(one);
# Line 1654 | Line 2247 | public class CompletableFutureTest exten
2247       * source cancelled
2248       */
2249      public void testRunAfterEitherAsync4() {
2250 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2251 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2250 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2251 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2252          Noop r = new Noop();
2253          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2254          assertTrue(f.cancel(true));
2255          checkCompletedWithWrappedCancellationException(g);
2256  
2257          r = new Noop();
2258 <        f = new CompletableFuture<Integer>();
2259 <        f2 = new CompletableFuture<Integer>();
2258 >        f = new CompletableFuture<>();
2259 >        f2 = new CompletableFuture<>();
2260          assertTrue(f2.cancel(true));
2261          g = f.runAfterEitherAsync(f2, r);
2262          checkCompletedWithWrappedCancellationException(g);
# Line 1674 | Line 2267 | public class CompletableFutureTest exten
2267       * completion of source
2268       */
2269      public void testThenComposeAsync() {
2270 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2271 <        CompletableFutureInc r = new CompletableFutureInc();
2272 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2270 >        CompletableFuture<Integer> f, g;
2271 >        CompletableFutureInc r;
2272 >
2273 >        f = new CompletableFuture<>();
2274 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2275          f.complete(one);
2276          checkCompletedNormally(g, two);
2277 +
2278 +        f = new CompletableFuture<>();
2279 +        f.complete(one);
2280 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2281 +        checkCompletedNormally(g, two);
2282      }
2283  
2284      /**
# Line 1686 | Line 2286 | public class CompletableFutureTest exten
2286       * exceptional completion of source
2287       */
2288      public void testThenComposeAsync2() {
2289 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2290 <        CompletableFutureInc r = new CompletableFutureInc();
2291 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2289 >        CompletableFuture<Integer> f, g;
2290 >        CompletableFutureInc r;
2291 >
2292 >        f = new CompletableFuture<>();
2293 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2294          f.completeExceptionally(new CFException());
2295          checkCompletedWithWrappedCFException(g);
2296 +        assertFalse(r.ran);
2297 +
2298 +        f = new CompletableFuture<>();
2299 +        f.completeExceptionally(new CFException());
2300 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2301 +        checkCompletedWithWrappedCFException(g);
2302 +        assertFalse(r.ran);
2303      }
2304  
2305      /**
2306       * thenComposeAsync result completes exceptionally if action does
2307       */
2308      public void testThenComposeAsync3() {
2309 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2310 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2311 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2309 >        CompletableFuture<Integer> f, g;
2310 >        FailingCompletableFutureFunction r;
2311 >
2312 >        f = new CompletableFuture<>();
2313 >        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2314          f.complete(one);
2315          checkCompletedWithWrappedCFException(g);
2316 +
2317 +        f = new CompletableFuture<>();
2318 +        f.complete(one);
2319 +        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2320 +        checkCompletedWithWrappedCFException(g);
2321      }
2322  
2323      /**
2324       * thenComposeAsync result completes exceptionally if source cancelled
2325       */
2326      public void testThenComposeAsync4() {
2327 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2328 <        CompletableFutureInc r = new CompletableFutureInc();
2329 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2327 >        CompletableFuture<Integer> f, g;
2328 >        CompletableFutureInc r;
2329 >
2330 >        f = new CompletableFuture<>();
2331 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2332          assertTrue(f.cancel(true));
2333          checkCompletedWithWrappedCancellationException(g);
1716    }
2334  
2335 +        f = new CompletableFuture<>();
2336 +        assertTrue(f.cancel(true));
2337 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2338 +        checkCompletedWithWrappedCancellationException(g);
2339 +    }
2340  
2341      // async with explicit executors
2342  
# Line 1722 | Line 2344 | public class CompletableFutureTest exten
2344       * thenRunAsync result completes normally after normal completion of source
2345       */
2346      public void testThenRunAsyncE() {
2347 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2347 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2348          Noop r = new Noop();
2349          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2350          f.complete(null);
2351          checkCompletedNormally(g, null);
2352  
2353          // reordered version
2354 <        f = new CompletableFuture<Integer>();
2354 >        f = new CompletableFuture<>();
2355          f.complete(null);
2356          r = new Noop();
2357          g = f.thenRunAsync(r, new ThreadExecutor());
# Line 1741 | Line 2363 | public class CompletableFutureTest exten
2363       * completion of source
2364       */
2365      public void testThenRunAsync2E() {
2366 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2366 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2367          Noop r = new Noop();
2368          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2369          f.completeExceptionally(new CFException());
2370          try {
2371              g.join();
2372              shouldThrow();
2373 <        } catch (Exception ok) {
1752 <        }
2373 >        } catch (CompletionException success) {}
2374          checkCompletedWithWrappedCFException(g);
2375      }
2376  
# Line 1757 | Line 2378 | public class CompletableFutureTest exten
2378       * thenRunAsync result completes exceptionally if action does
2379       */
2380      public void testThenRunAsync3E() {
2381 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2381 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2382          FailingNoop r = new FailingNoop();
2383          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2384          f.complete(null);
# Line 1768 | Line 2389 | public class CompletableFutureTest exten
2389       * thenRunAsync result completes exceptionally if source cancelled
2390       */
2391      public void testThenRunAsync4E() {
2392 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2392 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2393          Noop r = new Noop();
2394          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2395          assertTrue(f.cancel(true));
# Line 1779 | Line 2400 | public class CompletableFutureTest exten
2400       * thenApplyAsync result completes normally after normal completion of source
2401       */
2402      public void testThenApplyAsyncE() {
2403 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2403 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2404          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2405          f.complete(one);
2406          checkCompletedNormally(g, two);
# Line 1790 | Line 2411 | public class CompletableFutureTest exten
2411       * completion of source
2412       */
2413      public void testThenApplyAsync2E() {
2414 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2414 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2415          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2416          f.completeExceptionally(new CFException());
2417          checkCompletedWithWrappedCFException(g);
# Line 1800 | Line 2421 | public class CompletableFutureTest exten
2421       * thenApplyAsync result completes exceptionally if action does
2422       */
2423      public void testThenApplyAsync3E() {
2424 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2424 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2425          FailingFunction r = new FailingFunction();
2426          CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
2427          f.complete(null);
# Line 1811 | Line 2432 | public class CompletableFutureTest exten
2432       * thenApplyAsync result completes exceptionally if source cancelled
2433       */
2434      public void testThenApplyAsync4E() {
2435 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2435 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2436          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2437          assertTrue(f.cancel(true));
2438          checkCompletedWithWrappedCancellationException(g);
# Line 1822 | Line 2443 | public class CompletableFutureTest exten
2443       * completion of source
2444       */
2445      public void testThenAcceptAsyncE() {
2446 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2446 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2447          IncAction r = new IncAction();
2448          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2449          f.complete(one);
# Line 1835 | Line 2456 | public class CompletableFutureTest exten
2456       * completion of source
2457       */
2458      public void testThenAcceptAsync2E() {
2459 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2459 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2460          IncAction r = new IncAction();
2461          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2462          f.completeExceptionally(new CFException());
# Line 1846 | Line 2467 | public class CompletableFutureTest exten
2467       * thenAcceptAsync result completes exceptionally if action does
2468       */
2469      public void testThenAcceptAsync3E() {
2470 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2470 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2471          FailingConsumer r = new FailingConsumer();
2472          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2473          f.complete(null);
# Line 1857 | Line 2478 | public class CompletableFutureTest exten
2478       * thenAcceptAsync result completes exceptionally if source cancelled
2479       */
2480      public void testThenAcceptAsync4E() {
2481 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2481 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2482          IncAction r = new IncAction();
2483          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2484          assertTrue(f.cancel(true));
2485          checkCompletedWithWrappedCancellationException(g);
2486      }
2487 +
2488      /**
2489       * thenCombineAsync result completes normally after normal
2490       * completion of sources
2491       */
2492      public void testThenCombineAsyncE() {
2493 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2494 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2495 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2496 <        f.complete(one);
2497 <        checkIncomplete(g);
2498 <        f2.complete(two);
2499 <        checkCompletedNormally(g, three);
2493 >        CompletableFuture<Integer> f, g, h;
2494 >        ThreadExecutor e = new ThreadExecutor();
2495 >        int count = 0;
2496 >
2497 >        f = new CompletableFuture<>();
2498 >        g = new CompletableFuture<>();
2499 >        h = f.thenCombineAsync(g, subtract, e);
2500 >        f.complete(3);
2501 >        checkIncomplete(h);
2502 >        g.complete(1);
2503 >        checkCompletedNormally(h, 2);
2504 >        assertEquals(++count, e.count.get());
2505 >
2506 >        f = new CompletableFuture<>();
2507 >        g = new CompletableFuture<>();
2508 >        h = f.thenCombineAsync(g, subtract, e);
2509 >        g.complete(1);
2510 >        checkIncomplete(h);
2511 >        f.complete(3);
2512 >        checkCompletedNormally(h, 2);
2513 >        assertEquals(++count, e.count.get());
2514 >
2515 >        f = new CompletableFuture<>();
2516 >        g = new CompletableFuture<>();
2517 >        g.complete(1);
2518 >        f.complete(3);
2519 >        h = f.thenCombineAsync(g, subtract, e);
2520 >        checkCompletedNormally(h, 2);
2521 >        assertEquals(++count, e.count.get());
2522      }
2523  
2524      /**
2525       * thenCombineAsync result completes exceptionally after exceptional
2526 <     * completion of source
2526 >     * completion of either source
2527       */
2528      public void testThenCombineAsync2E() {
2529 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2530 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2531 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2532 <        f.completeExceptionally(new CFException());
2533 <        f2.complete(two);
2534 <        checkCompletedWithWrappedCFException(g);
2529 >        CompletableFuture<Integer> f, g, h;
2530 >        ThreadExecutor e = new ThreadExecutor();
2531 >        int count = 0;
2532 >
2533 >        f = new CompletableFuture<>();
2534 >        g = new CompletableFuture<>();
2535 >        h = f.thenCombineAsync(g, subtract, e);
2536 >        f.completeExceptionally(new CFException());
2537 >        checkIncomplete(h);
2538 >        g.complete(1);
2539 >        checkCompletedWithWrappedCFException(h);
2540 >
2541 >        f = new CompletableFuture<>();
2542 >        g = new CompletableFuture<>();
2543 >        h = f.thenCombineAsync(g, subtract, e);
2544 >        g.completeExceptionally(new CFException());
2545 >        checkIncomplete(h);
2546 >        f.complete(3);
2547 >        checkCompletedWithWrappedCFException(h);
2548 >
2549 >        f = new CompletableFuture<>();
2550 >        g = new CompletableFuture<>();
2551 >        g.completeExceptionally(new CFException());
2552 >        h = f.thenCombineAsync(g, subtract, e);
2553 >        checkIncomplete(h);
2554 >        f.complete(3);
2555 >        checkCompletedWithWrappedCFException(h);
2556  
2557 <        f = new CompletableFuture<Integer>();
1893 <        f2 = new CompletableFuture<Integer>();
1894 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1895 <        f.complete(one);
1896 <        f2.completeExceptionally(new CFException());
1897 <        checkCompletedWithWrappedCFException(g);
2557 >        assertEquals(0, e.count.get());
2558      }
2559  
2560      /**
2561       * thenCombineAsync result completes exceptionally if action does
2562       */
2563      public void testThenCombineAsync3E() {
2564 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2565 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2564 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2565 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2566          FailingBiFunction r = new FailingBiFunction();
2567          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2568          f.complete(one);
2569          checkIncomplete(g);
2570 +        assertFalse(r.ran);
2571          f2.complete(two);
2572          checkCompletedWithWrappedCFException(g);
2573 +        assertTrue(r.ran);
2574      }
2575  
2576      /**
2577       * thenCombineAsync result completes exceptionally if either source cancelled
2578       */
2579      public void testThenCombineAsync4E() {
2580 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2581 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1920 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1921 <        assertTrue(f.cancel(true));
1922 <        f2.complete(two);
1923 <        checkCompletedWithWrappedCancellationException(g);
1924 <
1925 <        f = new CompletableFuture<Integer>();
1926 <        f2 = new CompletableFuture<Integer>();
1927 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1928 <        f.complete(one);
1929 <        assertTrue(f2.cancel(true));
1930 <        checkCompletedWithWrappedCancellationException(g);
1931 <    }
1932 <
1933 <    /**
1934 <     * thenAcceptBothAsync result completes normally after normal
1935 <     * completion of sources
1936 <     */
1937 <    public void testThenAcceptBothAsyncE() {
1938 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1939 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1940 <        AddAction r = new AddAction();
1941 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1942 <        f.complete(one);
1943 <        checkIncomplete(g);
1944 <        f2.complete(two);
1945 <        checkCompletedNormally(g, null);
1946 <        assertEquals(r.value, 3);
1947 <    }
1948 <
1949 <    /**
1950 <     * thenAcceptBothAsync result completes exceptionally after exceptional
1951 <     * completion of source
1952 <     */
1953 <    public void testThenAcceptBothAsync2E() {
1954 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1955 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1956 <        AddAction r = new AddAction();
1957 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1958 <        f.completeExceptionally(new CFException());
1959 <        f2.complete(two);
1960 <        checkCompletedWithWrappedCFException(g);
1961 <
1962 <        r = new AddAction();
1963 <        f = new CompletableFuture<Integer>();
1964 <        f2 = new CompletableFuture<Integer>();
1965 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1966 <        f.complete(one);
1967 <        f2.completeExceptionally(new CFException());
1968 <        checkCompletedWithWrappedCFException(g);
1969 <    }
1970 <
1971 <    /**
1972 <     * thenAcceptBothAsync result completes exceptionally if action does
1973 <     */
1974 <    public void testThenAcceptBothAsync3E() {
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());
1979 <        f.complete(one);
1980 <        checkIncomplete(g);
1981 <        f2.complete(two);
1982 <        checkCompletedWithWrappedCFException(g);
1983 <    }
1984 <
1985 <    /**
1986 <     * thenAcceptBothAsync result completes exceptionally if either source cancelled
1987 <     */
1988 <    public void testThenAcceptBothAsync4E() {
1989 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1990 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1991 <        AddAction r = new AddAction();
1992 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1993 <        assertTrue(f.cancel(true));
1994 <        f2.complete(two);
1995 <        checkCompletedWithWrappedCancellationException(g);
1996 <
1997 <        r = new AddAction();
1998 <        f = new CompletableFuture<Integer>();
1999 <        f2 = new CompletableFuture<Integer>();
2000 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2001 <        f.complete(one);
2002 <        assertTrue(f2.cancel(true));
2003 <        checkCompletedWithWrappedCancellationException(g);
2004 <    }
2005 <
2006 <    /**
2007 <     * runAfterBothAsync result completes normally after normal
2008 <     * completion of sources
2009 <     */
2010 <    public void testRunAfterBothAsyncE() {
2011 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2012 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2013 <        Noop r = new Noop();
2014 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2015 <        f.complete(one);
2016 <        checkIncomplete(g);
2017 <        f2.complete(two);
2018 <        checkCompletedNormally(g, null);
2019 <        assertTrue(r.ran);
2020 <    }
2021 <
2022 <    /**
2023 <     * runAfterBothAsync result completes exceptionally after exceptional
2024 <     * completion of source
2025 <     */
2026 <    public void testRunAfterBothAsync2E() {
2027 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2028 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2029 <        Noop r = new Noop();
2030 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2031 <        f.completeExceptionally(new CFException());
2032 <        f2.complete(two);
2033 <        checkCompletedWithWrappedCFException(g);
2034 <
2035 <        r = new Noop();
2036 <        f = new CompletableFuture<Integer>();
2037 <        f2 = new CompletableFuture<Integer>();
2038 <        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2039 <        f.complete(one);
2040 <        f2.completeExceptionally(new CFException());
2041 <        checkCompletedWithWrappedCFException(g);
2042 <    }
2043 <
2044 <    /**
2045 <     * runAfterBothAsync result completes exceptionally if action does
2046 <     */
2047 <    public void testRunAfterBothAsync3E() {
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());
2052 <        f.complete(one);
2053 <        checkIncomplete(g);
2054 <        f2.complete(two);
2055 <        checkCompletedWithWrappedCFException(g);
2056 <    }
2580 >        CompletableFuture<Integer> f, g, h;
2581 >        ThreadExecutor e = new ThreadExecutor();
2582  
2583 <    /**
2584 <     * runAfterBothAsync result completes exceptionally if either source cancelled
2585 <     */
2586 <    public void testRunAfterBothAsync4E() {
2587 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2588 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2589 <        Noop r = new Noop();
2590 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2591 <        assertTrue(f.cancel(true));
2592 <        f2.complete(two);
2593 <        checkCompletedWithWrappedCancellationException(g);
2583 >        f = new CompletableFuture<>();
2584 >        g = new CompletableFuture<>();
2585 >        h = f.thenCombineAsync(g, subtract, e);
2586 >        assertTrue(f.cancel(true));
2587 >        checkIncomplete(h);
2588 >        g.complete(1);
2589 >        checkCompletedWithWrappedCancellationException(h);
2590 >
2591 >        f = new CompletableFuture<>();
2592 >        g = new CompletableFuture<>();
2593 >        h = f.thenCombineAsync(g, subtract, e);
2594 >        assertTrue(g.cancel(true));
2595 >        checkIncomplete(h);
2596 >        f.complete(3);
2597 >        checkCompletedWithWrappedCancellationException(h);
2598 >
2599 >        f = new CompletableFuture<>();
2600 >        g = new CompletableFuture<>();
2601 >        assertTrue(g.cancel(true));
2602 >        h = f.thenCombineAsync(g, subtract, e);
2603 >        checkIncomplete(h);
2604 >        f.complete(3);
2605 >        checkCompletedWithWrappedCancellationException(h);
2606 >
2607 >        f = new CompletableFuture<>();
2608 >        g = new CompletableFuture<>();
2609 >        assertTrue(f.cancel(true));
2610 >        assertTrue(g.cancel(true));
2611 >        h = f.thenCombineAsync(g, subtract, e);
2612 >        checkCompletedWithWrappedCancellationException(h);
2613  
2614 <        r = new Noop();
2071 <        f = new CompletableFuture<Integer>();
2072 <        f2 = new CompletableFuture<Integer>();
2073 <        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2074 <        f.complete(one);
2075 <        assertTrue(f2.cancel(true));
2076 <        checkCompletedWithWrappedCancellationException(g);
2614 >        assertEquals(0, e.count.get());
2615      }
2616  
2617      /**
# Line 2081 | Line 2619 | public class CompletableFutureTest exten
2619       * completion of sources
2620       */
2621      public void testApplyToEitherAsyncE() {
2622 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2623 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2622 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2623 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2624          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2625          f.complete(one);
2626          checkCompletedNormally(g, two);
2627  
2628 <        f = new CompletableFuture<Integer>();
2628 >        f = new CompletableFuture<>();
2629          f.complete(one);
2630 <        f2 = new CompletableFuture<Integer>();
2630 >        f2 = new CompletableFuture<>();
2631          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2632          checkCompletedNormally(g, two);
2633      }
# Line 2099 | Line 2637 | public class CompletableFutureTest exten
2637       * completion of source
2638       */
2639      public void testApplyToEitherAsync2E() {
2640 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2641 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2640 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2641 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2642          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2643          f.completeExceptionally(new CFException());
2644          checkCompletedWithWrappedCFException(g);
2645  
2646 <        f = new CompletableFuture<Integer>();
2647 <        f2 = new CompletableFuture<Integer>();
2646 >        f = new CompletableFuture<>();
2647 >        f2 = new CompletableFuture<>();
2648          f2.completeExceptionally(new CFException());
2649          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2650          f.complete(one);
# Line 2117 | Line 2655 | public class CompletableFutureTest exten
2655       * applyToEitherAsync result completes exceptionally if action does
2656       */
2657      public void testApplyToEitherAsync3E() {
2658 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2659 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2658 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2659 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2660          FailingFunction r = new FailingFunction();
2661          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2662          f.complete(one);
# Line 2129 | Line 2667 | public class CompletableFutureTest exten
2667       * applyToEitherAsync result completes exceptionally if either source cancelled
2668       */
2669      public void testApplyToEitherAsync4E() {
2670 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2671 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2670 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2671 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2672          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2673          assertTrue(f.cancel(true));
2674          checkCompletedWithWrappedCancellationException(g);
2675  
2676 <        f = new CompletableFuture<Integer>();
2677 <        f2 = new CompletableFuture<Integer>();
2676 >        f = new CompletableFuture<>();
2677 >        f2 = new CompletableFuture<>();
2678          assertTrue(f2.cancel(true));
2679          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2680          checkCompletedWithWrappedCancellationException(g);
# Line 2147 | Line 2685 | public class CompletableFutureTest exten
2685       * completion of sources
2686       */
2687      public void testAcceptEitherAsyncE() {
2688 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2689 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2688 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2689 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2690          IncAction r = new IncAction();
2691          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2692          f.complete(one);
# Line 2156 | Line 2694 | public class CompletableFutureTest exten
2694          assertEquals(r.value, 2);
2695  
2696          r = new IncAction();
2697 <        f = new CompletableFuture<Integer>();
2697 >        f = new CompletableFuture<>();
2698          f.complete(one);
2699 <        f2 = new CompletableFuture<Integer>();
2699 >        f2 = new CompletableFuture<>();
2700          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2701          checkCompletedNormally(g, null);
2702          assertEquals(r.value, 2);
# Line 2169 | Line 2707 | public class CompletableFutureTest exten
2707       * completion of source
2708       */
2709      public void testAcceptEitherAsync2E() {
2710 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2711 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2710 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2711 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2712          IncAction r = new IncAction();
2713          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2714          f.completeExceptionally(new CFException());
2715          checkCompletedWithWrappedCFException(g);
2716  
2717          r = new IncAction();
2718 <        f = new CompletableFuture<Integer>();
2719 <        f2 = new CompletableFuture<Integer>();
2718 >        f = new CompletableFuture<>();
2719 >        f2 = new CompletableFuture<>();
2720          f2.completeExceptionally(new CFException());
2721          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2722          f.complete(one);
# Line 2189 | Line 2727 | public class CompletableFutureTest exten
2727       * acceptEitherAsync result completes exceptionally if action does
2728       */
2729      public void testAcceptEitherAsync3E() {
2730 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2731 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2730 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2731 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2732          FailingConsumer r = new FailingConsumer();
2733          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2734          f.complete(one);
# Line 2202 | Line 2740 | public class CompletableFutureTest exten
2740       * source cancelled
2741       */
2742      public void testAcceptEitherAsync4E() {
2743 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2744 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2743 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2744 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2745          IncAction r = new IncAction();
2746          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2747          assertTrue(f.cancel(true));
2748          checkCompletedWithWrappedCancellationException(g);
2749  
2750          r = new IncAction();
2751 <        f = new CompletableFuture<Integer>();
2752 <        f2 = new CompletableFuture<Integer>();
2751 >        f = new CompletableFuture<>();
2752 >        f2 = new CompletableFuture<>();
2753          assertTrue(f2.cancel(true));
2754          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2755          checkCompletedWithWrappedCancellationException(g);
# Line 2222 | Line 2760 | public class CompletableFutureTest exten
2760       * completion of sources
2761       */
2762      public void testRunAfterEitherAsyncE() {
2763 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2764 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2763 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2764 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2765          Noop r = new Noop();
2766          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2767          f.complete(one);
# Line 2231 | Line 2769 | public class CompletableFutureTest exten
2769          assertTrue(r.ran);
2770  
2771          r = new Noop();
2772 <        f = new CompletableFuture<Integer>();
2772 >        f = new CompletableFuture<>();
2773          f.complete(one);
2774 <        f2 = new CompletableFuture<Integer>();
2774 >        f2 = new CompletableFuture<>();
2775          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2776          checkCompletedNormally(g, null);
2777          assertTrue(r.ran);
# Line 2244 | Line 2782 | public class CompletableFutureTest exten
2782       * completion of source
2783       */
2784      public void testRunAfterEitherAsync2E() {
2785 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2786 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2785 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2786 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2787          Noop r = new Noop();
2788          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2789          f.completeExceptionally(new CFException());
2790          checkCompletedWithWrappedCFException(g);
2791  
2792          r = new Noop();
2793 <        f = new CompletableFuture<Integer>();
2794 <        f2 = new CompletableFuture<Integer>();
2793 >        f = new CompletableFuture<>();
2794 >        f2 = new CompletableFuture<>();
2795          f2.completeExceptionally(new CFException());
2796          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2797          f.complete(one);
# Line 2264 | Line 2802 | public class CompletableFutureTest exten
2802       * runAfterEitherAsync result completes exceptionally if action does
2803       */
2804      public void testRunAfterEitherAsync3E() {
2805 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2806 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2805 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2806 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2807          FailingNoop r = new FailingNoop();
2808          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2809          f.complete(one);
# Line 2277 | Line 2815 | public class CompletableFutureTest exten
2815       * source cancelled
2816       */
2817      public void testRunAfterEitherAsync4E() {
2818 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2819 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2818 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2819 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2820          Noop r = new Noop();
2821          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2822          assertTrue(f.cancel(true));
2823          checkCompletedWithWrappedCancellationException(g);
2824  
2825          r = new Noop();
2826 <        f = new CompletableFuture<Integer>();
2827 <        f2 = new CompletableFuture<Integer>();
2826 >        f = new CompletableFuture<>();
2827 >        f2 = new CompletableFuture<>();
2828          assertTrue(f2.cancel(true));
2829          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2830          checkCompletedWithWrappedCancellationException(g);
# Line 2297 | Line 2835 | public class CompletableFutureTest exten
2835       * completion of source
2836       */
2837      public void testThenComposeAsyncE() {
2838 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2838 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2839          CompletableFutureInc r = new CompletableFutureInc();
2840          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2841          f.complete(one);
# Line 2309 | Line 2847 | public class CompletableFutureTest exten
2847       * exceptional completion of source
2848       */
2849      public void testThenComposeAsync2E() {
2850 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2850 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2851          CompletableFutureInc r = new CompletableFutureInc();
2852          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2853          f.completeExceptionally(new CFException());
# Line 2320 | Line 2858 | public class CompletableFutureTest exten
2858       * thenComposeAsync result completes exceptionally if action does
2859       */
2860      public void testThenComposeAsync3E() {
2861 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2861 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2862          FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2863          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2864          f.complete(one);
# Line 2331 | Line 2869 | public class CompletableFutureTest exten
2869       * thenComposeAsync result completes exceptionally if source cancelled
2870       */
2871      public void testThenComposeAsync4E() {
2872 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2872 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2873          CompletableFutureInc r = new CompletableFutureInc();
2874          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2875          assertTrue(f.cancel(true));
# Line 2345 | Line 2883 | public class CompletableFutureTest exten
2883       * with the value null
2884       */
2885      public void testAllOf_empty() throws Exception {
2886 <        CompletableFuture<?> f = CompletableFuture.allOf();
2886 >        CompletableFuture<Void> f = CompletableFuture.allOf();
2887          checkCompletedNormally(f, null);
2888      }
2889  
2890      /**
2891 <     * allOf returns a future completed when all components complete
2891 >     * allOf returns a future completed normally with the value null
2892 >     * when all components complete normally
2893       */
2894 <    public void testAllOf() throws Exception {
2894 >    public void testAllOf_normal() throws Exception {
2895          for (int k = 1; k < 20; ++k) {
2896 <            CompletableFuture[] fs = new CompletableFuture[k];
2896 >            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2897              for (int i = 0; i < k; ++i)
2898 <                fs[i] = new CompletableFuture<Integer>();
2898 >                fs[i] = new CompletableFuture<>();
2899              CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2900              for (int i = 0; i < k; ++i) {
2901                  checkIncomplete(f);
2902 +                checkIncomplete(CompletableFuture.allOf(fs));
2903                  fs[i].complete(one);
2904              }
2905              checkCompletedNormally(f, null);
2906 +            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2907          }
2908      }
2909  
# Line 2370 | Line 2911 | public class CompletableFutureTest exten
2911       * anyOf(no component futures) returns an incomplete future
2912       */
2913      public void testAnyOf_empty() throws Exception {
2914 <        CompletableFuture<?> f = CompletableFuture.anyOf();
2914 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
2915          checkIncomplete(f);
2916      }
2917  
2918      /**
2919 <     * anyOf returns a future completed when any components complete
2919 >     * anyOf returns a future completed normally with a value when
2920 >     * a component future does
2921       */
2922 <    public void testAnyOf() throws Exception {
2923 <        for (int k = 1; k < 20; ++k) {
2922 >    public void testAnyOf_normal() throws Exception {
2923 >        for (int k = 0; k < 10; ++k) {
2924              CompletableFuture[] fs = new CompletableFuture[k];
2925              for (int i = 0; i < k; ++i)
2926 <                fs[i] = new CompletableFuture<Integer>();
2926 >                fs[i] = new CompletableFuture<>();
2927              CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2928              checkIncomplete(f);
2929              for (int i = 0; i < k; ++i) {
2930                  fs[i].complete(one);
2931                  checkCompletedNormally(f, one);
2932 +                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
2933 +            }
2934 +        }
2935 +    }
2936 +
2937 +    /**
2938 +     * anyOf result completes exceptionally when any component does.
2939 +     */
2940 +    public void testAnyOf_exceptional() throws Exception {
2941 +        for (int k = 0; k < 10; ++k) {
2942 +            CompletableFuture[] fs = new CompletableFuture[k];
2943 +            for (int i = 0; i < k; ++i)
2944 +                fs[i] = new CompletableFuture<>();
2945 +            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2946 +            checkIncomplete(f);
2947 +            for (int i = 0; i < k; ++i) {
2948 +                fs[i].completeExceptionally(new CFException());
2949 +                checkCompletedWithWrappedCFException(f);
2950 +                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
2951              }
2952          }
2953      }
# Line 2395 | Line 2956 | public class CompletableFutureTest exten
2956       * Completion methods throw NullPointerException with null arguments
2957       */
2958      public void testNPE() {
2959 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2960 <        CompletableFuture<Integer> g = new CompletableFuture<Integer>();
2959 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2960 >        CompletableFuture<Integer> g = new CompletableFuture<>();
2961          CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
2962          CompletableFuture<?> h;
2963 <        Executor exec = new ThreadExecutor();
2963 >        ThreadExecutor exec = new ThreadExecutor();
2964  
2965          Runnable[] throwingActions = {
2966 <            () -> { CompletableFuture.supplyAsync(null); },
2967 <            () -> { CompletableFuture.supplyAsync(null, exec); },
2968 <            () -> { CompletableFuture.supplyAsync(() -> one, null); },
2969 <
2970 <            () -> { CompletableFuture.runAsync(null); },
2971 <            () -> { CompletableFuture.runAsync(null, exec); },
2972 <            () -> { CompletableFuture.runAsync(() -> {}, null); },
2973 <
2974 <            () -> { f.completeExceptionally(null); },
2975 <
2976 <            () -> { f.thenApply(null); },
2977 <            () -> { f.thenApplyAsync(null); },
2978 <            () -> { f.thenApplyAsync((x) -> x, null); },
2979 <            () -> { f.thenApplyAsync(null, exec); },
2980 <
2981 <            () -> { f.thenAccept(null); },
2982 <            () -> { f.thenAcceptAsync(null); },
2983 <            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
2984 <            () -> { f.thenAcceptAsync(null, exec); },
2985 <
2986 <            () -> { f.thenRun(null); },
2987 <            () -> { f.thenRunAsync(null); },
2988 <            () -> { f.thenRunAsync(() -> { ; }, null); },
2989 <            () -> { f.thenRunAsync(null, exec); },
2990 <
2991 <            () -> { f.thenCombine(g, null); },
2992 <            () -> { f.thenCombineAsync(g, null); },
2993 <            () -> { f.thenCombineAsync(g, null, exec); },
2994 <            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
2995 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
2996 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
2997 <            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
2998 <
2999 <            () -> { f.thenAcceptBoth(g, null); },
3000 <            () -> { f.thenAcceptBothAsync(g, null); },
3001 <            () -> { f.thenAcceptBothAsync(g, null, exec); },
3002 <            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
3003 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
3004 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
3005 <            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
3006 <
3007 <            () -> { f.runAfterBoth(g, null); },
3008 <            () -> { f.runAfterBothAsync(g, null); },
3009 <            () -> { f.runAfterBothAsync(g, null, exec); },
3010 <            () -> { f.runAfterBoth(nullFuture, () -> {}); },
3011 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
3012 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
3013 <            () -> { f.runAfterBothAsync(g, () -> {}, null); },
3014 <
3015 <            () -> { f.applyToEither(g, null); },
3016 <            () -> { f.applyToEitherAsync(g, null); },
3017 <            () -> { f.applyToEitherAsync(g, null, exec); },
3018 <            () -> { f.applyToEither(nullFuture, (x) -> x); },
3019 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
3020 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
3021 <            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
3022 <
3023 <            () -> { f.acceptEither(g, null); },
3024 <            () -> { f.acceptEitherAsync(g, null); },
3025 <            () -> { f.acceptEitherAsync(g, null, exec); },
3026 <            () -> { f.acceptEither(nullFuture, (x) -> {}); },
3027 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
3028 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
3029 <            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
3030 <
3031 <            () -> { f.runAfterEither(g, null); },
3032 <            () -> { f.runAfterEitherAsync(g, null); },
3033 <            () -> { f.runAfterEitherAsync(g, null, exec); },
3034 <            () -> { f.runAfterEither(nullFuture, () -> {}); },
3035 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
3036 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
3037 <            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
3038 <
3039 <            () -> { f.thenCompose(null); },
3040 <            () -> { f.thenComposeAsync(null); },
3041 <            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
3042 <            () -> { f.thenComposeAsync(null, exec); },
3043 <
3044 <            () -> { f.exceptionally(null); },
3045 <
3046 <            () -> { f.handle(null); },
3047 <
3048 <            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
3049 <            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
3050 <            () -> { CompletableFuture.allOf(f, null); },
3051 <            () -> { CompletableFuture.allOf(null, f); },
3052 <
3053 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
3054 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
3055 <            () -> { CompletableFuture.anyOf(f, null); },
3056 <            () -> { CompletableFuture.anyOf(null, f); },
3057 <
3058 <            // TODO: Crashes javac with lambda-8-2013-03-31...
2498 <            //() -> { CompletableFuture<?> x = f.thenAccept(null); },
2499 <            //() -> { CompletableFuture<Void> x = f.thenRun(null); },
2500 <            //() -> { CompletableFuture<Integer> x = f.thenApply(() -> { ; }); },
2966 >            () -> CompletableFuture.supplyAsync(null),
2967 >            () -> CompletableFuture.supplyAsync(null, exec),
2968 >            () -> CompletableFuture.supplyAsync(supplyOne, null),
2969 >
2970 >            () -> CompletableFuture.runAsync(null),
2971 >            () -> CompletableFuture.runAsync(null, exec),
2972 >            () -> CompletableFuture.runAsync(() -> {}, null),
2973 >
2974 >            () -> f.completeExceptionally(null),
2975 >
2976 >            () -> f.thenApply(null),
2977 >            () -> f.thenApplyAsync(null),
2978 >            () -> f.thenApplyAsync((x) -> x, null),
2979 >            () -> f.thenApplyAsync(null, exec),
2980 >
2981 >            () -> f.thenAccept(null),
2982 >            () -> f.thenAcceptAsync(null),
2983 >            () -> f.thenAcceptAsync((x) -> {} , null),
2984 >            () -> f.thenAcceptAsync(null, exec),
2985 >
2986 >            () -> f.thenRun(null),
2987 >            () -> f.thenRunAsync(null),
2988 >            () -> f.thenRunAsync(() -> {} , null),
2989 >            () -> f.thenRunAsync(null, exec),
2990 >
2991 >            () -> f.thenCombine(g, null),
2992 >            () -> f.thenCombineAsync(g, null),
2993 >            () -> f.thenCombineAsync(g, null, exec),
2994 >            () -> f.thenCombine(nullFuture, (x, y) -> x),
2995 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x),
2996 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec),
2997 >            () -> f.thenCombineAsync(g, (x, y) -> x, null),
2998 >
2999 >            () -> f.thenAcceptBoth(g, null),
3000 >            () -> f.thenAcceptBothAsync(g, null),
3001 >            () -> f.thenAcceptBothAsync(g, null, exec),
3002 >            () -> f.thenAcceptBoth(nullFuture, (x, y) -> {}),
3003 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}),
3004 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec),
3005 >            () -> f.thenAcceptBothAsync(g, (x, y) -> {}, null),
3006 >
3007 >            () -> f.runAfterBoth(g, null),
3008 >            () -> f.runAfterBothAsync(g, null),
3009 >            () -> f.runAfterBothAsync(g, null, exec),
3010 >            () -> f.runAfterBoth(nullFuture, () -> {}),
3011 >            () -> f.runAfterBothAsync(nullFuture, () -> {}),
3012 >            () -> f.runAfterBothAsync(nullFuture, () -> {}, exec),
3013 >            () -> f.runAfterBothAsync(g, () -> {}, null),
3014 >
3015 >            () -> f.applyToEither(g, null),
3016 >            () -> f.applyToEitherAsync(g, null),
3017 >            () -> f.applyToEitherAsync(g, null, exec),
3018 >            () -> f.applyToEither(nullFuture, (x) -> x),
3019 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3020 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3021 >            () -> f.applyToEitherAsync(g, (x) -> x, null),
3022 >
3023 >            () -> f.acceptEither(g, null),
3024 >            () -> f.acceptEitherAsync(g, null),
3025 >            () -> f.acceptEitherAsync(g, null, exec),
3026 >            () -> f.acceptEither(nullFuture, (x) -> {}),
3027 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3028 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3029 >            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3030 >
3031 >            () -> f.runAfterEither(g, null),
3032 >            () -> f.runAfterEitherAsync(g, null),
3033 >            () -> f.runAfterEitherAsync(g, null, exec),
3034 >            () -> f.runAfterEither(nullFuture, () -> {}),
3035 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}),
3036 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}, exec),
3037 >            () -> f.runAfterEitherAsync(g, () -> {}, null),
3038 >
3039 >            () -> f.thenCompose(null),
3040 >            () -> f.thenComposeAsync(null),
3041 >            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
3042 >            () -> f.thenComposeAsync(null, exec),
3043 >
3044 >            () -> f.exceptionally(null),
3045 >
3046 >            () -> f.handle(null),
3047 >
3048 >            () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3049 >            () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3050 >            () -> CompletableFuture.allOf(f, null),
3051 >            () -> CompletableFuture.allOf(null, f),
3052 >
3053 >            () -> CompletableFuture.anyOf((CompletableFuture<?>)null),
3054 >            () -> CompletableFuture.anyOf((CompletableFuture<?>[])null),
3055 >            () -> CompletableFuture.anyOf(f, null),
3056 >            () -> CompletableFuture.anyOf(null, f),
3057 >
3058 >            () -> f.obtrudeException(null),
3059          };
3060  
3061          assertThrows(NullPointerException.class, throwingActions);
3062 +        assertEquals(0, exec.count.get());
3063 +    }
3064 +
3065 +    /**
3066 +     * toCompletableFuture returns this CompletableFuture.
3067 +     */
3068 +    public void testToCompletableFuture() {
3069 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3070 +        assertSame(f, f.toCompletableFuture());
3071 +    }
3072 +
3073 +    /**
3074 +     * whenComplete action executes on normal completion, propagating
3075 +     * source result.
3076 +     */
3077 +    public void testWhenComplete1() {
3078 +        final AtomicInteger a = new AtomicInteger();
3079 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3080 +        CompletableFuture<Integer> g =
3081 +            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3082 +        f.complete(three);
3083 +        checkCompletedNormally(f, three);
3084 +        checkCompletedNormally(g, three);
3085 +        assertEquals(a.get(), 1);
3086 +    }
3087 +
3088 +    /**
3089 +     * whenComplete action executes on exceptional completion, propagating
3090 +     * source result.
3091 +     */
3092 +    public void testWhenComplete2() {
3093 +        final AtomicInteger a = new AtomicInteger();
3094 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3095 +        CompletableFuture<Integer> g =
3096 +            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3097 +        f.completeExceptionally(new CFException());
3098 +        assertTrue(f.isCompletedExceptionally());
3099 +        assertTrue(g.isCompletedExceptionally());
3100 +        assertEquals(a.get(), 1);
3101 +    }
3102 +
3103 +    /**
3104 +     * If a whenComplete action throws an exception when triggered by
3105 +     * a normal completion, it completes exceptionally
3106 +     */
3107 +    public void testWhenComplete3() {
3108 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3109 +        CompletableFuture<Integer> g =
3110 +            f.whenComplete((Integer x, Throwable t) ->
3111 +                           { throw new CFException(); } );
3112 +        f.complete(three);
3113 +        checkCompletedNormally(f, three);
3114 +        assertTrue(g.isCompletedExceptionally());
3115 +        checkCompletedWithWrappedCFException(g);
3116 +    }
3117 +
3118 +    /**
3119 +     * whenCompleteAsync action executes on normal completion, propagating
3120 +     * source result.
3121 +     */
3122 +    public void testWhenCompleteAsync1() {
3123 +        final AtomicInteger a = new AtomicInteger();
3124 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3125 +        CompletableFuture<Integer> g =
3126 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3127 +        f.complete(three);
3128 +        checkCompletedNormally(f, three);
3129 +        checkCompletedNormally(g, three);
3130 +        assertEquals(a.get(), 1);
3131 +    }
3132 +
3133 +    /**
3134 +     * whenCompleteAsync action executes on exceptional completion, propagating
3135 +     * source result.
3136 +     */
3137 +    public void testWhenCompleteAsync2() {
3138 +        final AtomicInteger a = new AtomicInteger();
3139 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3140 +        CompletableFuture<Integer> g =
3141 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3142 +        f.completeExceptionally(new CFException());
3143 +        checkCompletedWithWrappedCFException(f);
3144 +        checkCompletedWithWrappedCFException(g);
3145 +    }
3146 +
3147 +    /**
3148 +     * If a whenCompleteAsync action throws an exception when
3149 +     * triggered by a normal completion, it completes exceptionally
3150 +     */
3151 +    public void testWhenCompleteAsync3() {
3152 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3153 +        CompletableFuture<Integer> g =
3154 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3155 +                           { throw new CFException(); } );
3156 +        f.complete(three);
3157 +        checkCompletedNormally(f, three);
3158 +        checkCompletedWithWrappedCFException(g);
3159 +    }
3160 +
3161 +    /**
3162 +     * whenCompleteAsync action executes on normal completion, propagating
3163 +     * source result.
3164 +     */
3165 +    public void testWhenCompleteAsync1e() {
3166 +        final AtomicInteger a = new AtomicInteger();
3167 +        ThreadExecutor exec = new ThreadExecutor();
3168 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3169 +        CompletableFuture<Integer> g =
3170 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3171 +                                exec);
3172 +        f.complete(three);
3173 +        checkCompletedNormally(f, three);
3174 +        checkCompletedNormally(g, three);
3175 +        assertEquals(a.get(), 1);
3176 +    }
3177 +
3178 +    /**
3179 +     * whenCompleteAsync action executes on exceptional completion, propagating
3180 +     * source result.
3181 +     */
3182 +    public void testWhenCompleteAsync2e() {
3183 +        final AtomicInteger a = new AtomicInteger();
3184 +        ThreadExecutor exec = new ThreadExecutor();
3185 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3186 +        CompletableFuture<Integer> g =
3187 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3188 +                                exec);
3189 +        f.completeExceptionally(new CFException());
3190 +        checkCompletedWithWrappedCFException(f);
3191 +        checkCompletedWithWrappedCFException(g);
3192 +    }
3193 +
3194 +    /**
3195 +     * If a whenCompleteAsync action throws an exception when triggered
3196 +     * by a normal completion, it completes exceptionally
3197 +     */
3198 +    public void testWhenCompleteAsync3e() {
3199 +        ThreadExecutor exec = new ThreadExecutor();
3200 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3201 +        CompletableFuture<Integer> g =
3202 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3203 +                                { throw new CFException(); },
3204 +                                exec);
3205 +        f.complete(three);
3206 +        checkCompletedNormally(f, three);
3207 +        checkCompletedWithWrappedCFException(g);
3208 +    }
3209 +
3210 +    /**
3211 +     * handleAsync action completes normally with function value on
3212 +     * either normal or exceptional completion of source
3213 +     */
3214 +    public void testHandleAsync() {
3215 +        CompletableFuture<Integer> f, g;
3216 +        IntegerHandler r;
3217 +
3218 +        f = new CompletableFuture<>();
3219 +        g = f.handleAsync(r = new IntegerHandler());
3220 +        assertFalse(r.ran);
3221 +        f.completeExceptionally(new CFException());
3222 +        checkCompletedWithWrappedCFException(f);
3223 +        checkCompletedNormally(g, three);
3224 +        assertTrue(r.ran);
3225 +
3226 +        f = new CompletableFuture<>();
3227 +        g = f.handleAsync(r = new IntegerHandler());
3228 +        assertFalse(r.ran);
3229 +        f.completeExceptionally(new CFException());
3230 +        checkCompletedWithWrappedCFException(f);
3231 +        checkCompletedNormally(g, three);
3232 +        assertTrue(r.ran);
3233 +
3234 +        f = new CompletableFuture<>();
3235 +        g = f.handleAsync(r = new IntegerHandler());
3236 +        assertFalse(r.ran);
3237 +        f.complete(one);
3238 +        checkCompletedNormally(f, one);
3239 +        checkCompletedNormally(g, two);
3240 +        assertTrue(r.ran);
3241 +
3242 +        f = new CompletableFuture<>();
3243 +        g = f.handleAsync(r = new IntegerHandler());
3244 +        assertFalse(r.ran);
3245 +        f.complete(one);
3246 +        checkCompletedNormally(f, one);
3247 +        checkCompletedNormally(g, two);
3248 +        assertTrue(r.ran);
3249 +    }
3250 +
3251 +    /**
3252 +     * handleAsync action with Executor completes normally with
3253 +     * function value on either normal or exceptional completion of
3254 +     * source
3255 +     */
3256 +    public void testHandleAsync2() {
3257 +        CompletableFuture<Integer> f, g;
3258 +        ThreadExecutor exec = new ThreadExecutor();
3259 +        IntegerHandler r;
3260 +
3261 +        f = new CompletableFuture<>();
3262 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3263 +        assertFalse(r.ran);
3264 +        f.completeExceptionally(new CFException());
3265 +        checkCompletedWithWrappedCFException(f);
3266 +        checkCompletedNormally(g, three);
3267 +        assertTrue(r.ran);
3268 +
3269 +        f = new CompletableFuture<>();
3270 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3271 +        assertFalse(r.ran);
3272 +        f.completeExceptionally(new CFException());
3273 +        checkCompletedWithWrappedCFException(f);
3274 +        checkCompletedNormally(g, three);
3275 +        assertTrue(r.ran);
3276 +
3277 +        f = new CompletableFuture<>();
3278 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3279 +        assertFalse(r.ran);
3280 +        f.complete(one);
3281 +        checkCompletedNormally(f, one);
3282 +        checkCompletedNormally(g, two);
3283 +        assertTrue(r.ran);
3284 +
3285 +        f = new CompletableFuture<>();
3286 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3287 +        assertFalse(r.ran);
3288 +        f.complete(one);
3289 +        checkCompletedNormally(f, one);
3290 +        checkCompletedNormally(g, two);
3291 +        assertTrue(r.ran);
3292      }
3293  
3294   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines