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.7 by jsr166, Fri Mar 22 16:29:42 2013 UTC vs.
Revision 1.34 by jsr166, Sun Jun 1 21:17:05 2014 UTC

# Line 53 | Line 53 | public class CompletableFutureTest exten
53          catch (Throwable fail) { threadUnexpectedException(fail); }
54      }
55  
56 <    void checkCompletedNormally(CompletableFuture<?> f, Object value) {
56 >    <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
57 >        try {
58 >            assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS));
59 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
60          try {
61              assertEquals(value, f.join());
62          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 63 | Line 66 | public class CompletableFutureTest exten
66          try {
67              assertEquals(value, f.get());
68          } catch (Throwable fail) { threadUnexpectedException(fail); }
66        try {
67            assertEquals(value, f.get(0L, SECONDS));
68        } catch (Throwable fail) { threadUnexpectedException(fail); }
69          assertTrue(f.isDone());
70          assertFalse(f.isCancelled());
71 +        assertFalse(f.isCompletedExceptionally());
72          assertTrue(f.toString().contains("[Completed normally]"));
73      }
74  
75      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
76          try {
77 +            f.get(LONG_DELAY_MS, MILLISECONDS);
78 +            shouldThrow();
79 +        } catch (ExecutionException success) {
80 +            assertTrue(success.getCause() instanceof CFException);
81 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
82 +        try {
83              f.join();
84              shouldThrow();
85 <        } catch (Throwable ex) {
86 <            assertTrue(ex instanceof CompletionException &&
80 <                       ((CompletionException)ex).getCause() instanceof CFException);
85 >        } catch (CompletionException success) {
86 >            assertTrue(success.getCause() instanceof CFException);
87          }
88          try {
89              f.getNow(null);
90              shouldThrow();
91 <        } catch (Throwable ex) {
92 <            assertTrue(ex instanceof CompletionException &&
87 <                       ((CompletionException)ex).getCause() instanceof CFException);
91 >        } catch (CompletionException success) {
92 >            assertTrue(success.getCause() instanceof CFException);
93          }
94          try {
95              f.get();
96              shouldThrow();
97 <        } catch (Throwable ex) {
98 <            assertTrue(ex instanceof ExecutionException &&
99 <                       ((ExecutionException)ex).getCause() instanceof CFException);
97 >        } catch (ExecutionException success) {
98 >            assertTrue(success.getCause() instanceof CFException);
99 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
100 >        assertTrue(f.isDone());
101 >        assertFalse(f.isCancelled());
102 >        assertTrue(f.toString().contains("[Completed exceptionally]"));
103 >    }
104 >
105 >    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
106 >                                              CFException ex) {
107 >        try {
108 >            f.get(LONG_DELAY_MS, MILLISECONDS);
109 >            shouldThrow();
110 >        } catch (ExecutionException success) {
111 >            assertSame(ex, success.getCause());
112 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
113 >        try {
114 >            f.join();
115 >            shouldThrow();
116 >        } catch (CompletionException success) {
117 >            assertSame(ex, success.getCause());
118          }
119          try {
120 <            f.get(0L, SECONDS);
120 >            f.getNow(null);
121              shouldThrow();
122 <        } catch (Throwable ex) {
123 <            assertTrue(ex instanceof ExecutionException &&
101 <                       ((ExecutionException)ex).getCause() instanceof CFException);
122 >        } catch (CompletionException success) {
123 >            assertSame(ex, success.getCause());
124          }
125 +        try {
126 +            f.get();
127 +            shouldThrow();
128 +        } catch (ExecutionException success) {
129 +            assertSame(ex, success.getCause());
130 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
131          assertTrue(f.isDone());
132          assertFalse(f.isCancelled());
133 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
134      }
135  
136      void checkCancelled(CompletableFuture<?> f) {
137          try {
138 +            f.get(LONG_DELAY_MS, MILLISECONDS);
139 +            shouldThrow();
140 +        } catch (CancellationException success) {
141 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
142 +        try {
143              f.join();
144              shouldThrow();
145 <        } catch (Throwable ex) {
112 <            assertTrue(ex instanceof CancellationException);
113 <        }
145 >        } catch (CancellationException success) {}
146          try {
147              f.getNow(null);
148              shouldThrow();
149 <        } catch (Throwable ex) {
118 <            assertTrue(ex instanceof CancellationException);
119 <        }
149 >        } catch (CancellationException success) {}
150          try {
151              f.get();
152              shouldThrow();
153 <        } catch (Throwable ex) {
154 <            assertTrue(ex instanceof CancellationException);
125 <        }
126 <        try {
127 <            f.get(0L, SECONDS);
128 <            shouldThrow();
129 <        } catch (Throwable ex) {
130 <            assertTrue(ex instanceof CancellationException);
131 <        }
153 >        } catch (CancellationException success) {
154 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
155          assertTrue(f.isDone());
156 +        assertTrue(f.isCompletedExceptionally());
157          assertTrue(f.isCancelled());
158 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
159      }
160  
161      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
162          try {
163 +            f.get(LONG_DELAY_MS, MILLISECONDS);
164 +            shouldThrow();
165 +        } catch (ExecutionException success) {
166 +            assertTrue(success.getCause() instanceof CancellationException);
167 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
168 +        try {
169              f.join();
170              shouldThrow();
171 <        } catch (Throwable ex) {
172 <            assertTrue(ex instanceof CompletionException &&
142 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
171 >        } catch (CompletionException success) {
172 >            assertTrue(success.getCause() instanceof CancellationException);
173          }
174          try {
175              f.getNow(null);
176              shouldThrow();
177 <        } catch (Throwable ex) {
178 <            assertTrue(ex instanceof CompletionException &&
149 <                       ((CompletionException)ex).getCause() instanceof CancellationException);
177 >        } catch (CompletionException success) {
178 >            assertTrue(success.getCause() instanceof CancellationException);
179          }
180          try {
181              f.get();
182              shouldThrow();
183 <        } catch (Throwable ex) {
184 <            assertTrue(ex instanceof ExecutionException &&
185 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
157 <        }
158 <        try {
159 <            f.get(0L, SECONDS);
160 <            shouldThrow();
161 <        } catch (Throwable ex) {
162 <            assertTrue(ex instanceof ExecutionException &&
163 <                       ((ExecutionException)ex).getCause() instanceof CancellationException);
164 <        }
183 >        } catch (ExecutionException success) {
184 >            assertTrue(success.getCause() instanceof CancellationException);
185 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
186          assertTrue(f.isDone());
187          assertFalse(f.isCancelled());
188 +        assertTrue(f.isCompletedExceptionally());
189 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
190      }
191  
192      /**
# Line 171 | Line 194 | public class CompletableFutureTest exten
194       * by methods isDone, isCancelled, and getNow
195       */
196      public void testConstructor() {
197 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
197 >        CompletableFuture<Integer> f = new CompletableFuture<>();
198          checkIncomplete(f);
199      }
200  
# Line 180 | Line 203 | public class CompletableFutureTest exten
203       * isCancelled, join, get, and getNow
204       */
205      public void testComplete() {
206 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
206 >        CompletableFuture<Integer> f = new CompletableFuture<>();
207          checkIncomplete(f);
208          f.complete(one);
209          checkCompletedNormally(f, one);
# Line 191 | Line 214 | public class CompletableFutureTest exten
214       * methods isDone, isCancelled, join, get, and getNow
215       */
216      public void testCompleteExceptionally() {
217 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
217 >        CompletableFuture<Integer> f = new CompletableFuture<>();
218          checkIncomplete(f);
219          f.completeExceptionally(new CFException());
220          checkCompletedWithWrappedCFException(f);
# Line 202 | Line 225 | public class CompletableFutureTest exten
225       * methods isDone, isCancelled, join, get, and getNow
226       */
227      public void testCancel() {
228 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
228 >        CompletableFuture<Integer> f = new CompletableFuture<>();
229          checkIncomplete(f);
230          assertTrue(f.cancel(true));
231          checkCancelled(f);
# Line 212 | Line 235 | public class CompletableFutureTest exten
235       * obtrudeValue forces completion with given value
236       */
237      public void testObtrudeValue() {
238 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
238 >        CompletableFuture<Integer> f = new CompletableFuture<>();
239          checkIncomplete(f);
240          f.complete(one);
241          checkCompletedNormally(f, one);
# Line 220 | Line 243 | public class CompletableFutureTest exten
243          checkCompletedNormally(f, three);
244          f.obtrudeValue(two);
245          checkCompletedNormally(f, two);
246 <        f = new CompletableFuture<Integer>();
246 >        f = new CompletableFuture<>();
247          f.obtrudeValue(three);
248          checkCompletedNormally(f, three);
249 <        f = new CompletableFuture<Integer>();
249 >        f = new CompletableFuture<>();
250          f.completeExceptionally(new CFException());
251          f.obtrudeValue(four);
252          checkCompletedNormally(f, four);
# Line 233 | Line 256 | public class CompletableFutureTest exten
256       * obtrudeException forces completion with given exception
257       */
258      public void testObtrudeException() {
259 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
259 >        CompletableFuture<Integer> f = new CompletableFuture<>();
260          checkIncomplete(f);
261          f.complete(one);
262          checkCompletedNormally(f, one);
263          f.obtrudeException(new CFException());
264          checkCompletedWithWrappedCFException(f);
265 <        f = new CompletableFuture<Integer>();
265 >        f = new CompletableFuture<>();
266          f.obtrudeException(new CFException());
267          checkCompletedWithWrappedCFException(f);
268 <        f = new CompletableFuture<Integer>();
268 >        f = new CompletableFuture<>();
269          f.completeExceptionally(new CFException());
270          f.obtrudeValue(four);
271          checkCompletedNormally(f, four);
# Line 254 | Line 277 | public class CompletableFutureTest exten
277       * getNumberOfDependents returns number of dependent tasks
278       */
279      public void testGetNumberOfDependents() {
280 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
280 >        CompletableFuture<Integer> f = new CompletableFuture<>();
281          assertEquals(f.getNumberOfDependents(), 0);
282          CompletableFuture g = f.thenRun(new Noop());
283          assertEquals(f.getNumberOfDependents(), 1);
# Line 267 | Line 290 | public class CompletableFutureTest exten
290          assertEquals(g.getNumberOfDependents(), 0);
291      }
292  
270
293      /**
294       * toString indicates current completion state
295       */
# Line 285 | Line 307 | public class CompletableFutureTest exten
307          assertTrue(f.toString().contains("[Completed exceptionally]"));
308      }
309  
310 +    /**
311 +     * completedFuture returns a completed CompletableFuture with given value
312 +     */
313 +    public void testCompletedFuture() {
314 +        CompletableFuture<String> f = CompletableFuture.completedFuture("test");
315 +        checkCompletedNormally(f, "test");
316 +    }
317 +
318 +    // Choose non-commutative actions for better coverage
319 +
320      static final Supplier<Integer> supplyOne =
321          () -> Integer.valueOf(1);
322      static final Function<Integer, Integer> inc =
323          (Integer x) -> Integer.valueOf(x.intValue() + 1);
324 <    static final BiFunction<Integer, Integer, Integer> add =
325 <        (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue());
324 >    static final BiFunction<Integer, Integer, Integer> subtract =
325 >        (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue());
326      static final class IncAction implements Consumer<Integer> {
327          int value;
328          public void accept(Integer x) { value = x.intValue() + 1; }
329      }
330 <    static final class AddAction implements BiConsumer<Integer, Integer> {
330 >    static final class SubtractAction implements BiConsumer<Integer, Integer> {
331          int value;
332          public void accept(Integer x, Integer y) {
333 <            value = x.intValue() + y.intValue();
333 >            value = x.intValue() - y.intValue();
334          }
335      }
336      static final class Noop implements Runnable {
# Line 331 | Line 363 | public class CompletableFutureTest exten
363          public void run() { ran = true; throw new CFException(); }
364      }
365  
366 <    static final class CompletableFutureInc implements Function<Integer, CompletableFuture<Integer>> {
366 >    static final class CompletableFutureInc
367 >        implements Function<Integer, CompletableFuture<Integer>> {
368 >        boolean ran;
369          public CompletableFuture<Integer> apply(Integer x) {
370 <            CompletableFuture<Integer> f = new CompletableFuture<Integer>();
370 >            ran = true;
371 >            CompletableFuture<Integer> f = new CompletableFuture<>();
372              f.complete(Integer.valueOf(x.intValue() + 1));
373              return f;
374          }
375      }
376  
377 <    static final class FailingCompletableFutureFunction implements Function<Integer, CompletableFuture<Integer>> {
377 >    static final class FailingCompletableFutureFunction
378 >        implements Function<Integer, CompletableFuture<Integer>> {
379          boolean ran;
380          public CompletableFuture<Integer> apply(Integer x) {
381              ran = true; throw new CFException();
# Line 348 | Line 384 | public class CompletableFutureTest exten
384  
385      // Used for explicit executor tests
386      static final class ThreadExecutor implements Executor {
387 +        AtomicInteger count = new AtomicInteger(0);
388 +
389          public void execute(Runnable r) {
390 +            count.getAndIncrement();
391              new Thread(r).start();
392          }
393      }
# Line 358 | Line 397 | public class CompletableFutureTest exten
397      }
398  
399      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
400 +        boolean ran;
401          public Integer apply(Integer x, Throwable t) {
402 +            ran = true;
403              return (t == null) ? two : three;
404          }
405      }
406  
366
407      /**
408       * exceptionally action completes with function value on source
409 <     * exception;  otherwise with source value
409 >     * exception; otherwise with source value
410       */
411      public void testExceptionally() {
412 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
412 >        CompletableFuture<Integer> f = new CompletableFuture<>();
413          ExceptionToInteger r = new ExceptionToInteger();
414          CompletableFuture<Integer> g = f.exceptionally(r);
415          f.completeExceptionally(new CFException());
416          checkCompletedNormally(g, three);
417  
418 <        f = new CompletableFuture<Integer>();
418 >        f = new CompletableFuture<>();
419          r = new ExceptionToInteger();
420          g = f.exceptionally(r);
421          f.complete(one);
# Line 387 | Line 427 | public class CompletableFutureTest exten
427       * normal or exceptional completion of source
428       */
429      public void testHandle() {
430 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
431 <        IntegerHandler r = new IntegerHandler();
432 <        CompletableFuture<Integer> g = f.handle(r);
430 >        CompletableFuture<Integer> f, g;
431 >        IntegerHandler r;
432 >
433 >        f = new CompletableFuture<>();
434          f.completeExceptionally(new CFException());
435 +        g = f.handle(r = new IntegerHandler());
436 +        assertTrue(r.ran);
437          checkCompletedNormally(g, three);
438  
439 <        f = new CompletableFuture<Integer>();
440 <        r = new IntegerHandler();
441 <        g = f.handle(r);
439 >        f = new CompletableFuture<>();
440 >        g = f.handle(r = new IntegerHandler());
441 >        assertFalse(r.ran);
442 >        f.completeExceptionally(new CFException());
443 >        checkCompletedNormally(g, three);
444 >        assertTrue(r.ran);
445 >
446 >        f = new CompletableFuture<>();
447          f.complete(one);
448 +        g = f.handle(r = new IntegerHandler());
449 +        assertTrue(r.ran);
450 +        checkCompletedNormally(g, two);
451 +
452 +        f = new CompletableFuture<>();
453 +        g = f.handle(r = new IntegerHandler());
454 +        assertFalse(r.ran);
455 +        f.complete(one);
456 +        assertTrue(r.ran);
457          checkCompletedNormally(g, two);
458      }
459  
# Line 408 | Line 465 | public class CompletableFutureTest exten
465          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
466          assertNull(f.join());
467          assertTrue(r.ran);
468 +        checkCompletedNormally(f, null);
469      }
470  
471      /**
# Line 415 | Line 473 | public class CompletableFutureTest exten
473       */
474      public void testRunAsync2() {
475          Noop r = new Noop();
476 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor());
476 >        ThreadExecutor exec = new ThreadExecutor();
477 >        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
478          assertNull(f.join());
479          assertTrue(r.ran);
480 +        checkCompletedNormally(f, null);
481 +        assertEquals(1, exec.count.get());
482      }
483  
484      /**
# Line 434 | Line 495 | public class CompletableFutureTest exten
495       * supplyAsync completes with result of supplier
496       */
497      public void testSupplyAsync() {
498 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne);
498 >        CompletableFuture<Integer> f;
499 >        f = CompletableFuture.supplyAsync(supplyOne);
500          assertEquals(f.join(), one);
501 +        checkCompletedNormally(f, one);
502      }
503  
504      /**
505       * supplyAsync with executor completes with result of supplier
506       */
507      public void testSupplyAsync2() {
508 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
508 >        CompletableFuture<Integer> f;
509 >        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
510          assertEquals(f.join(), one);
511 +        checkCompletedNormally(f, one);
512      }
513  
514      /**
# Line 462 | Line 527 | public class CompletableFutureTest exten
527       * thenRun result completes normally after normal completion of source
528       */
529      public void testThenRun() {
530 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
531 <        Noop r = new Noop();
532 <        CompletableFuture<Void> g = f.thenRun(r);
530 >        CompletableFuture<Integer> f;
531 >        CompletableFuture<Void> g;
532 >        Noop r;
533 >
534 >        f = new CompletableFuture<>();
535 >        g = f.thenRun(r = new Noop());
536          f.complete(null);
537          checkCompletedNormally(g, null);
538 <        // reordered version
539 <        f = new CompletableFuture<Integer>();
538 >        assertTrue(r.ran);
539 >
540 >        f = new CompletableFuture<>();
541          f.complete(null);
542 <        r = new Noop();
474 <        g = f.thenRun(r);
542 >        g = f.thenRun(r = new Noop());
543          checkCompletedNormally(g, null);
544 +        assertTrue(r.ran);
545      }
546  
547      /**
# Line 480 | Line 549 | public class CompletableFutureTest exten
549       * completion of source
550       */
551      public void testThenRun2() {
552 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
553 <        Noop r = new Noop();
554 <        CompletableFuture<Void> g = f.thenRun(r);
552 >        CompletableFuture<Integer> f;
553 >        CompletableFuture<Void> g;
554 >        Noop r;
555 >
556 >        f = new CompletableFuture<>();
557 >        g = f.thenRun(r = new Noop());
558 >        f.completeExceptionally(new CFException());
559 >        checkCompletedWithWrappedCFException(g);
560 >        assertFalse(r.ran);
561 >
562 >        f = new CompletableFuture<>();
563          f.completeExceptionally(new CFException());
564 +        g = f.thenRun(r = new Noop());
565          checkCompletedWithWrappedCFException(g);
566 +        assertFalse(r.ran);
567      }
568  
569      /**
570       * thenRun result completes exceptionally if action does
571       */
572      public void testThenRun3() {
573 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
574 <        FailingNoop r = new FailingNoop();
575 <        CompletableFuture<Void> g = f.thenRun(r);
573 >        CompletableFuture<Integer> f;
574 >        CompletableFuture<Void> g;
575 >        FailingNoop r;
576 >
577 >        f = new CompletableFuture<>();
578 >        g = f.thenRun(r = new FailingNoop());
579          f.complete(null);
580          checkCompletedWithWrappedCFException(g);
581 +
582 +        f = new CompletableFuture<>();
583 +        f.complete(null);
584 +        g = f.thenRun(r = new FailingNoop());
585 +        checkCompletedWithWrappedCFException(g);
586      }
587  
588      /**
589       * thenRun result completes exceptionally if source cancelled
590       */
591      public void testThenRun4() {
592 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
593 <        Noop r = new Noop();
594 <        CompletableFuture<Void> g = f.thenRun(r);
592 >        CompletableFuture<Integer> f;
593 >        CompletableFuture<Void> g;
594 >        Noop r;
595 >
596 >        f = new CompletableFuture<>();
597 >        g = f.thenRun(r = new Noop());
598          assertTrue(f.cancel(true));
599          checkCompletedWithWrappedCancellationException(g);
600 +
601 +        f = new CompletableFuture<>();
602 +        assertTrue(f.cancel(true));
603 +        g = f.thenRun(r = new Noop());
604 +        checkCompletedWithWrappedCancellationException(g);
605      }
606  
607      /**
608       * thenApply result completes normally after normal completion of source
609       */
610      public void testThenApply() {
611 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
611 >        CompletableFuture<Integer> f = new CompletableFuture<>();
612          CompletableFuture<Integer> g = f.thenApply(inc);
613          f.complete(one);
614          checkCompletedNormally(g, two);
# Line 524 | Line 619 | public class CompletableFutureTest exten
619       * completion of source
620       */
621      public void testThenApply2() {
622 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
622 >        CompletableFuture<Integer> f = new CompletableFuture<>();
623          CompletableFuture<Integer> g = f.thenApply(inc);
624          f.completeExceptionally(new CFException());
625          checkCompletedWithWrappedCFException(g);
# Line 534 | Line 629 | public class CompletableFutureTest exten
629       * thenApply result completes exceptionally if action does
630       */
631      public void testThenApply3() {
632 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
632 >        CompletableFuture<Integer> f = new CompletableFuture<>();
633          CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
634          f.complete(one);
635          checkCompletedWithWrappedCFException(g);
# Line 544 | Line 639 | public class CompletableFutureTest exten
639       * thenApply result completes exceptionally if source cancelled
640       */
641      public void testThenApply4() {
642 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
642 >        CompletableFuture<Integer> f = new CompletableFuture<>();
643          CompletableFuture<Integer> g = f.thenApply(inc);
644          assertTrue(f.cancel(true));
645          checkCompletedWithWrappedCancellationException(g);
# Line 554 | Line 649 | public class CompletableFutureTest exten
649       * thenAccept result completes normally after normal completion of source
650       */
651      public void testThenAccept() {
652 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
652 >        CompletableFuture<Integer> f = new CompletableFuture<>();
653          IncAction r = new IncAction();
654          CompletableFuture<Void> g = f.thenAccept(r);
655          f.complete(one);
# Line 567 | Line 662 | public class CompletableFutureTest exten
662       * completion of source
663       */
664      public void testThenAccept2() {
665 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
665 >        CompletableFuture<Integer> f = new CompletableFuture<>();
666          IncAction r = new IncAction();
667          CompletableFuture<Void> g = f.thenAccept(r);
668          f.completeExceptionally(new CFException());
# Line 578 | Line 673 | public class CompletableFutureTest exten
673       * thenAccept result completes exceptionally if action does
674       */
675      public void testThenAccept3() {
676 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
676 >        CompletableFuture<Integer> f = new CompletableFuture<>();
677          FailingConsumer r = new FailingConsumer();
678          CompletableFuture<Void> g = f.thenAccept(r);
679          f.complete(one);
# Line 590 | Line 685 | public class CompletableFutureTest exten
685       * thenAccept result completes exceptionally if source cancelled
686       */
687      public void testThenAccept4() {
688 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
688 >        CompletableFuture<Integer> f = new CompletableFuture<>();
689          IncAction r = new IncAction();
690          CompletableFuture<Void> g = f.thenAccept(r);
691          assertTrue(f.cancel(true));
692          checkCompletedWithWrappedCancellationException(g);
693      }
694  
600
695      /**
696 <     * thenCombine result completes normally after normal completion of sources
696 >     * thenCombine result completes normally after normal completion
697 >     * of sources
698       */
699      public void testThenCombine() {
700 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
606 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
607 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
608 <        f.complete(one);
609 <        checkIncomplete(g);
610 <        f2.complete(two);
611 <        checkCompletedNormally(g, three);
700 >        CompletableFuture<Integer> f, g, h;
701  
702 <        f = new CompletableFuture<Integer>();
703 <        f.complete(one);
704 <        f2 = new CompletableFuture<Integer>();
705 <        g = f.thenCombine(f2, add);
706 <        checkIncomplete(g);
707 <        f2.complete(two);
708 <        checkCompletedNormally(g, three);
702 >        f = new CompletableFuture<>();
703 >        g = new CompletableFuture<>();
704 >        h = f.thenCombine(g, subtract);
705 >        f.complete(3);
706 >        checkIncomplete(h);
707 >        g.complete(1);
708 >        checkCompletedNormally(h, 2);
709 >
710 >        f = new CompletableFuture<>();
711 >        g = new CompletableFuture<>();
712 >        h = f.thenCombine(g, subtract);
713 >        g.complete(1);
714 >        checkIncomplete(h);
715 >        f.complete(3);
716 >        checkCompletedNormally(h, 2);
717 >
718 >        f = new CompletableFuture<>();
719 >        g = new CompletableFuture<>();
720 >        g.complete(1);
721 >        f.complete(3);
722 >        h = f.thenCombine(g, subtract);
723 >        checkCompletedNormally(h, 2);
724      }
725  
726      /**
# Line 624 | Line 728 | public class CompletableFutureTest exten
728       * completion of either source
729       */
730      public void testThenCombine2() {
731 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
628 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
629 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
630 <        f.completeExceptionally(new CFException());
631 <        f2.complete(two);
632 <        checkCompletedWithWrappedCFException(g);
731 >        CompletableFuture<Integer> f, g, h;
732  
733 <        f = new CompletableFuture<Integer>();
734 <        f.complete(one);
735 <        f2 = new CompletableFuture<Integer>();
736 <        g = f.thenCombine(f2, add);
737 <        f2.completeExceptionally(new CFException());
738 <        checkCompletedWithWrappedCFException(g);
733 >        f = new CompletableFuture<>();
734 >        g = new CompletableFuture<>();
735 >        h = f.thenCombine(g, subtract);
736 >        f.completeExceptionally(new CFException());
737 >        checkIncomplete(h);
738 >        g.complete(1);
739 >        checkCompletedWithWrappedCFException(h);
740 >
741 >        f = new CompletableFuture<>();
742 >        g = new CompletableFuture<>();
743 >        h = f.thenCombine(g, subtract);
744 >        g.completeExceptionally(new CFException());
745 >        checkIncomplete(h);
746 >        f.complete(3);
747 >        checkCompletedWithWrappedCFException(h);
748 >
749 >        f = new CompletableFuture<>();
750 >        g = new CompletableFuture<>();
751 >        f.complete(3);
752 >        g.completeExceptionally(new CFException());
753 >        h = f.thenCombine(g, subtract);
754 >        checkCompletedWithWrappedCFException(h);
755 >
756 >        f = new CompletableFuture<>();
757 >        g = new CompletableFuture<>();
758 >        f.completeExceptionally(new CFException());
759 >        g.complete(3);
760 >        h = f.thenCombine(g, subtract);
761 >        checkCompletedWithWrappedCFException(h);
762      }
763  
764      /**
765       * thenCombine result completes exceptionally if action does
766       */
767      public void testThenCombine3() {
768 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
769 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
768 >        CompletableFuture<Integer> f = new CompletableFuture<>();
769 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
770          FailingBiFunction r = new FailingBiFunction();
771          CompletableFuture<Integer> g = f.thenCombine(f2, r);
772          f.complete(one);
773          checkIncomplete(g);
774 +        assertFalse(r.ran);
775          f2.complete(two);
776          checkCompletedWithWrappedCFException(g);
777 +        assertTrue(r.ran);
778      }
779  
780      /**
781       * thenCombine result completes exceptionally if either source cancelled
782       */
783      public void testThenCombine4() {
784 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
785 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
786 <        CompletableFuture<Integer> g = f.thenCombine(f2, add);
787 <        assertTrue(f.cancel(true));
788 <        f2.complete(two);
789 <        checkCompletedWithWrappedCancellationException(g);
790 <        f = new CompletableFuture<Integer>();
791 <        f2 = new CompletableFuture<Integer>();
792 <        g = f.thenCombine(f2, add);
793 <        f.complete(one);
794 <        assertTrue(f2.cancel(true));
795 <        checkCompletedWithWrappedCancellationException(g);
784 >        CompletableFuture<Integer> f, g, h;
785 >
786 >        f = new CompletableFuture<>();
787 >        g = new CompletableFuture<>();
788 >        h = f.thenCombine(g, subtract);
789 >        assertTrue(f.cancel(true));
790 >        checkIncomplete(h);
791 >        g.complete(1);
792 >        checkCompletedWithWrappedCancellationException(h);
793 >
794 >        f = new CompletableFuture<>();
795 >        g = new CompletableFuture<>();
796 >        h = f.thenCombine(g, subtract);
797 >        assertTrue(g.cancel(true));
798 >        checkIncomplete(h);
799 >        f.complete(3);
800 >        checkCompletedWithWrappedCancellationException(h);
801 >
802 >        f = new CompletableFuture<>();
803 >        g = new CompletableFuture<>();
804 >        assertTrue(f.cancel(true));
805 >        assertTrue(g.cancel(true));
806 >        h = f.thenCombine(g, subtract);
807 >        checkCompletedWithWrappedCancellationException(h);
808      }
809  
810      /**
# Line 676 | Line 812 | public class CompletableFutureTest exten
812       * completion of sources
813       */
814      public void testThenAcceptBoth() {
815 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
816 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
817 <        AddAction r = new AddAction();
818 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
819 <        f.complete(one);
820 <        checkIncomplete(g);
821 <        f2.complete(two);
822 <        checkCompletedNormally(g, null);
823 <        assertEquals(r.value, 3);
815 >        CompletableFuture<Integer> f, g;
816 >        CompletableFuture<Void> h;
817 >        SubtractAction r;
818 >
819 >        f = new CompletableFuture<>();
820 >        g = new CompletableFuture<>();
821 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
822 >        f.complete(3);
823 >        checkIncomplete(h);
824 >        g.complete(1);
825 >        checkCompletedNormally(h, null);
826 >        assertEquals(r.value, 2);
827  
828 <        r = new AddAction();
829 <        f = new CompletableFuture<Integer>();
830 <        f.complete(one);
831 <        f2 = new CompletableFuture<Integer>();
832 <        g = f.thenAcceptBoth(f2, r);
833 <        checkIncomplete(g);
834 <        f2.complete(two);
835 <        checkCompletedNormally(g, null);
836 <        assertEquals(r.value, 3);
828 >        f = new CompletableFuture<>();
829 >        g = new CompletableFuture<>();
830 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
831 >        g.complete(1);
832 >        checkIncomplete(h);
833 >        f.complete(3);
834 >        checkCompletedNormally(h, null);
835 >        assertEquals(r.value, 2);
836 >
837 >        f = new CompletableFuture<>();
838 >        g = new CompletableFuture<>();
839 >        g.complete(1);
840 >        f.complete(3);
841 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
842 >        checkCompletedNormally(h, null);
843 >        assertEquals(r.value, 2);
844      }
845  
846      /**
# Line 702 | Line 848 | public class CompletableFutureTest exten
848       * completion of either source
849       */
850      public void testThenAcceptBoth2() {
851 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
852 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
853 <        AddAction r = new AddAction();
854 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
855 <        f.completeExceptionally(new CFException());
856 <        f2.complete(two);
857 <        checkCompletedWithWrappedCFException(g);
858 <
859 <        r = new AddAction();
860 <        f = new CompletableFuture<Integer>();
861 <        f.complete(one);
862 <        f2 = new CompletableFuture<Integer>();
863 <        g = f.thenAcceptBoth(f2, r);
864 <        f2.completeExceptionally(new CFException());
865 <        checkCompletedWithWrappedCFException(g);
851 >        CompletableFuture<Integer> f, g;
852 >        CompletableFuture<Void> h;
853 >        SubtractAction r;
854 >
855 >        f = new CompletableFuture<>();
856 >        g = new CompletableFuture<>();
857 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
858 >        f.completeExceptionally(new CFException());
859 >        checkIncomplete(h);
860 >        g.complete(1);
861 >        checkCompletedWithWrappedCFException(h);
862 >
863 >        f = new CompletableFuture<>();
864 >        g = new CompletableFuture<>();
865 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
866 >        g.completeExceptionally(new CFException());
867 >        checkIncomplete(h);
868 >        f.complete(3);
869 >        checkCompletedWithWrappedCFException(h);
870 >
871 >        f = new CompletableFuture<>();
872 >        g = new CompletableFuture<>();
873 >        f.complete(3);
874 >        g.completeExceptionally(new CFException());
875 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
876 >        checkCompletedWithWrappedCFException(h);
877 >
878 >        f = new CompletableFuture<>();
879 >        g = new CompletableFuture<>();
880 >        f.completeExceptionally(new CFException());
881 >        g.complete(3);
882 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
883 >        checkCompletedWithWrappedCFException(h);
884      }
885  
886      /**
887       * thenAcceptBoth result completes exceptionally if action does
888       */
889      public void testThenAcceptBoth3() {
890 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
891 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
892 <        FailingBiConsumer r = new FailingBiConsumer();
893 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
894 <        f.complete(one);
895 <        checkIncomplete(g);
896 <        f2.complete(two);
897 <        checkCompletedWithWrappedCFException(g);
890 >        CompletableFuture<Integer> f, g;
891 >        CompletableFuture<Void> h;
892 >        FailingBiConsumer r;
893 >
894 >        f = new CompletableFuture<>();
895 >        g = new CompletableFuture<>();
896 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
897 >        f.complete(3);
898 >        checkIncomplete(h);
899 >        g.complete(1);
900 >        checkCompletedWithWrappedCFException(h);
901 >
902 >        f = new CompletableFuture<>();
903 >        g = new CompletableFuture<>();
904 >        f.complete(3);
905 >        g.complete(1);
906 >        h = f.thenAcceptBoth(g, r = new FailingBiConsumer());
907 >        checkCompletedWithWrappedCFException(h);
908      }
909  
910      /**
911       * thenAcceptBoth result completes exceptionally if either source cancelled
912       */
913      public void testThenAcceptBoth4() {
914 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
915 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
916 <        AddAction r = new AddAction();
917 <        CompletableFuture<Void> g = f.thenAcceptBoth(f2, r);
918 <        assertTrue(f.cancel(true));
919 <        f2.complete(two);
920 <        checkCompletedWithWrappedCancellationException(g);
921 <        f = new CompletableFuture<Integer>();
922 <        f2 = new CompletableFuture<Integer>();
923 <        r = new AddAction();
924 <        g = f.thenAcceptBoth(f2, r);
925 <        f.complete(one);
926 <        assertTrue(f2.cancel(true));
927 <        checkCompletedWithWrappedCancellationException(g);
914 >        CompletableFuture<Integer> f, g;
915 >        CompletableFuture<Void> h;
916 >        SubtractAction r;
917 >
918 >        f = new CompletableFuture<>();
919 >        g = new CompletableFuture<>();
920 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
921 >        assertTrue(f.cancel(true));
922 >        checkIncomplete(h);
923 >        g.complete(1);
924 >        checkCompletedWithWrappedCancellationException(h);
925 >
926 >        f = new CompletableFuture<>();
927 >        g = new CompletableFuture<>();
928 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
929 >        assertTrue(g.cancel(true));
930 >        checkIncomplete(h);
931 >        f.complete(3);
932 >        checkCompletedWithWrappedCancellationException(h);
933 >
934 >        f = new CompletableFuture<>();
935 >        g = new CompletableFuture<>();
936 >        f.complete(3);
937 >        assertTrue(g.cancel(true));
938 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
939 >        checkCompletedWithWrappedCancellationException(h);
940 >
941 >        f = new CompletableFuture<>();
942 >        g = new CompletableFuture<>();
943 >        assertTrue(f.cancel(true));
944 >        g.complete(3);
945 >        h = f.thenAcceptBoth(g, r = new SubtractAction());
946 >        checkCompletedWithWrappedCancellationException(h);
947 >    }
948 >
949 >    /**
950 >     * Permits the testing of parallel code for the 3 different
951 >     * execution modes without repeating all the testing code.
952 >     */
953 >    enum ExecutionMode {
954 >        DEFAULT {
955 >            public <T,U> CompletableFuture<Void> runAfterBoth
956 >                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
957 >                return f.runAfterBoth(g, r);
958 >            }
959 >        },
960 >
961 >        DEFAULT_ASYNC {
962 >            public <T,U> CompletableFuture<Void> runAfterBoth
963 >                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
964 >                return f.runAfterBothAsync(g, r);
965 >            }
966 >        },
967 >
968 >        EXECUTOR {
969 >            public <T,U> CompletableFuture<Void> runAfterBoth
970 >                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
971 >                return f.runAfterBothAsync(g, r, new ThreadExecutor());
972 >            }
973 >        };
974 >
975 >        public abstract <T,U> CompletableFuture<Void> runAfterBoth
976 >            (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r);
977      }
978  
979      /**
980       * runAfterBoth result completes normally after normal
981       * completion of sources
982       */
983 <    public void testRunAfterBoth() {
984 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
985 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
986 <        Noop r = new Noop();
987 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
988 <        f.complete(one);
989 <        checkIncomplete(g);
990 <        f2.complete(two);
991 <        checkCompletedNormally(g, null);
983 >    public void testRunAfterBoth_normalCompletion1() {
984 >        for (ExecutionMode m : ExecutionMode.values())
985 >        for (Integer v1 : new Integer[] { 1, null })
986 >        for (Integer v2 : new Integer[] { 2, null }) {
987 >
988 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
989 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
990 >        final Noop r = new Noop();
991 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
992 >
993 >        f.complete(v1);
994 >        checkIncomplete(h);
995 >        assertFalse(r.ran);
996 >        g.complete(v2);
997 >
998 >        checkCompletedNormally(h, null);
999          assertTrue(r.ran);
1000 +        checkCompletedNormally(f, v1);
1001 +        checkCompletedNormally(g, v2);
1002 +        }
1003 +    }
1004  
1005 <        r = new Noop();
1006 <        f = new CompletableFuture<Integer>();
1007 <        f.complete(one);
1008 <        f2 = new CompletableFuture<Integer>();
1009 <        g = f.runAfterBoth(f2, r);
1010 <        checkIncomplete(g);
1011 <        f2.complete(two);
1012 <        checkCompletedNormally(g, null);
1005 >    public void testRunAfterBoth_normalCompletion2() {
1006 >        for (ExecutionMode m : ExecutionMode.values())
1007 >        for (Integer v1 : new Integer[] { 1, null })
1008 >        for (Integer v2 : new Integer[] { 2, null }) {
1009 >
1010 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1011 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1012 >        final Noop r = new Noop();
1013 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1014 >
1015 >        g.complete(v2);
1016 >        checkIncomplete(h);
1017 >        assertFalse(r.ran);
1018 >        f.complete(v1);
1019 >
1020 >        checkCompletedNormally(h, null);
1021 >        assertTrue(r.ran);
1022 >        checkCompletedNormally(f, v1);
1023 >        checkCompletedNormally(g, v2);
1024 >        }
1025 >    }
1026 >
1027 >    public void testRunAfterBoth_normalCompletion3() {
1028 >        for (ExecutionMode m : ExecutionMode.values())
1029 >        for (Integer v1 : new Integer[] { 1, null })
1030 >        for (Integer v2 : new Integer[] { 2, null }) {
1031 >
1032 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1033 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1034 >        final Noop r = new Noop();
1035 >
1036 >        g.complete(v2);
1037 >        f.complete(v1);
1038 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1039 >
1040 >        checkCompletedNormally(h, null);
1041          assertTrue(r.ran);
1042 +        checkCompletedNormally(f, v1);
1043 +        checkCompletedNormally(g, v2);
1044 +        }
1045 +    }
1046 +
1047 +    public void testRunAfterBoth_normalCompletion4() {
1048 +        for (ExecutionMode m : ExecutionMode.values())
1049 +        for (Integer v1 : new Integer[] { 1, null })
1050 +        for (Integer v2 : new Integer[] { 2, null }) {
1051 +
1052 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1053 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1054 +        final Noop r = new Noop();
1055 +
1056 +        f.complete(v1);
1057 +        g.complete(v2);
1058 +        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1059 +
1060 +        checkCompletedNormally(h, null);
1061 +        assertTrue(r.ran);
1062 +        checkCompletedNormally(f, v1);
1063 +        checkCompletedNormally(g, v2);
1064 +        }
1065      }
1066  
1067      /**
1068       * runAfterBoth result completes exceptionally after exceptional
1069       * completion of either source
1070       */
1071 <    public void testRunAfterBoth2() {
1072 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1073 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
789 <        Noop r = new Noop();
790 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
791 <        f.completeExceptionally(new CFException());
792 <        f2.complete(two);
793 <        checkCompletedWithWrappedCFException(g);
1071 >    public void testRunAfterBoth_exceptionalCompletion1() {
1072 >        for (ExecutionMode m : ExecutionMode.values())
1073 >        for (Integer v1 : new Integer[] { 1, null }) {
1074  
1075 <        r = new Noop();
1076 <        f = new CompletableFuture<Integer>();
1077 <        f.complete(one);
1078 <        f2 = new CompletableFuture<Integer>();
1079 <        g = f.runAfterBoth(f2, r);
1080 <        f2.completeExceptionally(new CFException());
1081 <        checkCompletedWithWrappedCFException(g);
1075 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1076 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1077 >        final Noop r = new Noop();
1078 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1079 >        final CFException ex = new CFException();
1080 >
1081 >        f.completeExceptionally(ex);
1082 >        checkIncomplete(h);
1083 >        g.complete(v1);
1084 >
1085 >        checkCompletedWithWrappedCFException(h, ex);
1086 >        checkCompletedWithWrappedCFException(f, ex);
1087 >        assertFalse(r.ran);
1088 >        checkCompletedNormally(g, v1);
1089 >        }
1090 >    }
1091 >
1092 >    public void testRunAfterBoth_exceptionalCompletion2() {
1093 >        for (ExecutionMode m : ExecutionMode.values())
1094 >        for (Integer v1 : new Integer[] { 1, null }) {
1095 >
1096 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1097 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1098 >        final Noop r = new Noop();
1099 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1100 >        final CFException ex = new CFException();
1101 >
1102 >        g.completeExceptionally(ex);
1103 >        checkIncomplete(h);
1104 >        f.complete(v1);
1105 >
1106 >        checkCompletedWithWrappedCFException(h, ex);
1107 >        checkCompletedWithWrappedCFException(g, ex);
1108 >        assertFalse(r.ran);
1109 >        checkCompletedNormally(f, v1);
1110 >        }
1111 >    }
1112 >
1113 >    public void testRunAfterBoth_exceptionalCompletion3() {
1114 >        for (ExecutionMode m : ExecutionMode.values())
1115 >        for (Integer v1 : new Integer[] { 1, null }) {
1116 >
1117 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1118 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1119 >        final Noop r = new Noop();
1120 >        final CFException ex = new CFException();
1121 >
1122 >        g.completeExceptionally(ex);
1123 >        f.complete(v1);
1124 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1125 >
1126 >        checkCompletedWithWrappedCFException(h, ex);
1127 >        checkCompletedWithWrappedCFException(g, ex);
1128 >        assertFalse(r.ran);
1129 >        checkCompletedNormally(f, v1);
1130 >        }
1131 >    }
1132 >
1133 >    public void testRunAfterBoth_exceptionalCompletion4() {
1134 >        for (ExecutionMode m : ExecutionMode.values())
1135 >        for (Integer v1 : new Integer[] { 1, null }) {
1136 >
1137 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1138 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1139 >        final Noop r = new Noop();
1140 >        final CFException ex = new CFException();
1141 >
1142 >        f.completeExceptionally(ex);
1143 >        g.complete(v1);
1144 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1145 >
1146 >        checkCompletedWithWrappedCFException(h, ex);
1147 >        checkCompletedWithWrappedCFException(f, ex);
1148 >        assertFalse(r.ran);
1149 >        checkCompletedNormally(g, v1);
1150 >        }
1151      }
1152  
1153      /**
1154       * runAfterBoth result completes exceptionally if action does
1155       */
1156 <    public void testRunAfterBoth3() {
1157 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1158 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1159 <        FailingNoop r = new FailingNoop();
1160 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1161 <        f.complete(one);
1162 <        checkIncomplete(g);
1163 <        f2.complete(two);
1164 <        checkCompletedWithWrappedCFException(g);
1156 >    public void testRunAfterBoth_actionFailed1() {
1157 >        for (ExecutionMode m : ExecutionMode.values())
1158 >        for (Integer v1 : new Integer[] { 1, null })
1159 >        for (Integer v2 : new Integer[] { 2, null }) {
1160 >
1161 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1162 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1163 >        final FailingNoop r = new FailingNoop();
1164 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1165 >
1166 >        f.complete(v1);
1167 >        checkIncomplete(h);
1168 >        g.complete(v2);
1169 >
1170 >        checkCompletedWithWrappedCFException(h);
1171 >        checkCompletedNormally(f, v1);
1172 >        checkCompletedNormally(g, v2);
1173 >        }
1174 >    }
1175 >
1176 >    public void testRunAfterBoth_actionFailed2() {
1177 >        for (ExecutionMode m : ExecutionMode.values())
1178 >        for (Integer v1 : new Integer[] { 1, null })
1179 >        for (Integer v2 : new Integer[] { 2, null }) {
1180 >
1181 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1182 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1183 >        final FailingNoop r = new FailingNoop();
1184 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1185 >
1186 >        g.complete(v2);
1187 >        checkIncomplete(h);
1188 >        f.complete(v1);
1189 >
1190 >        checkCompletedWithWrappedCFException(h);
1191 >        checkCompletedNormally(f, v1);
1192 >        checkCompletedNormally(g, v2);
1193 >        }
1194      }
1195  
1196      /**
1197       * runAfterBoth result completes exceptionally if either source cancelled
1198       */
1199 <    public void testRunAfterBoth4() {
1200 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1201 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1202 <        Noop r = new Noop();
1203 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1204 <        assertTrue(f.cancel(true));
1205 <        f2.complete(two);
1206 <        checkCompletedWithWrappedCancellationException(g);
1207 <        f = new CompletableFuture<Integer>();
1208 <        f2 = new CompletableFuture<Integer>();
1209 <        r = new Noop();
1210 <        g = f.runAfterBoth(f2, r);
1211 <        f.complete(one);
1212 <        assertTrue(f2.cancel(true));
1213 <        checkCompletedWithWrappedCancellationException(g);
1199 >    public void testRunAfterBoth_sourceCancelled1() {
1200 >        for (ExecutionMode m : ExecutionMode.values())
1201 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1202 >        for (Integer v1 : new Integer[] { 1, null }) {
1203 >
1204 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1205 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1206 >        final Noop r = new Noop();
1207 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1208 >
1209 >        assertTrue(f.cancel(mayInterruptIfRunning));
1210 >        checkIncomplete(h);
1211 >        g.complete(v1);
1212 >
1213 >        checkCompletedWithWrappedCancellationException(h);
1214 >        checkCancelled(f);
1215 >        assertFalse(r.ran);
1216 >        checkCompletedNormally(g, v1);
1217 >        }
1218 >    }
1219 >
1220 >    public void testRunAfterBoth_sourceCancelled2() {
1221 >        for (ExecutionMode m : ExecutionMode.values())
1222 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1223 >        for (Integer v1 : new Integer[] { 1, null }) {
1224 >
1225 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1226 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1227 >        final Noop r = new Noop();
1228 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1229 >
1230 >        assertTrue(g.cancel(mayInterruptIfRunning));
1231 >        checkIncomplete(h);
1232 >        f.complete(v1);
1233 >
1234 >        checkCompletedWithWrappedCancellationException(h);
1235 >        checkCancelled(g);
1236 >        assertFalse(r.ran);
1237 >        checkCompletedNormally(f, v1);
1238 >        }
1239 >    }
1240 >
1241 >    public void testRunAfterBoth_sourceCancelled3() {
1242 >        for (ExecutionMode m : ExecutionMode.values())
1243 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1244 >        for (Integer v1 : new Integer[] { 1, null }) {
1245 >
1246 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1247 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1248 >        final Noop r = new Noop();
1249 >
1250 >        assertTrue(g.cancel(mayInterruptIfRunning));
1251 >        f.complete(v1);
1252 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1253 >
1254 >        checkCompletedWithWrappedCancellationException(h);
1255 >        checkCancelled(g);
1256 >        assertFalse(r.ran);
1257 >        checkCompletedNormally(f, v1);
1258 >        }
1259 >    }
1260 >
1261 >    public void testRunAfterBoth_sourceCancelled4() {
1262 >        for (ExecutionMode m : ExecutionMode.values())
1263 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1264 >        for (Integer v1 : new Integer[] { 1, null }) {
1265 >
1266 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1267 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1268 >        final Noop r = new Noop();
1269 >
1270 >        assertTrue(f.cancel(mayInterruptIfRunning));
1271 >        g.complete(v1);
1272 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1273 >
1274 >        checkCompletedWithWrappedCancellationException(h);
1275 >        checkCancelled(f);
1276 >        assertFalse(r.ran);
1277 >        checkCompletedNormally(g, v1);
1278 >        }
1279      }
1280  
1281      /**
# Line 840 | Line 1283 | public class CompletableFutureTest exten
1283       * of either source
1284       */
1285      public void testApplyToEither() {
1286 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1287 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1286 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1287 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1288          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1289          f.complete(one);
1290          checkCompletedNormally(g, two);
1291          f2.complete(one);
1292          checkCompletedNormally(g, two);
1293  
1294 <        f = new CompletableFuture<Integer>();
1294 >        f = new CompletableFuture<>();
1295          f.complete(one);
1296 <        f2 = new CompletableFuture<Integer>();
1296 >        f2 = new CompletableFuture<>();
1297          g = f.applyToEither(f2, inc);
1298          checkCompletedNormally(g, two);
1299      }
# Line 860 | Line 1303 | public class CompletableFutureTest exten
1303       * completion of either source
1304       */
1305      public void testApplyToEither2() {
1306 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1307 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1306 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1307 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1308          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1309          f.completeExceptionally(new CFException());
1310          f2.complete(one);
1311          checkCompletedWithWrappedCFException(g);
1312  
1313 <        f = new CompletableFuture<Integer>();
1314 <        f2 = new CompletableFuture<Integer>();
1313 >        f = new CompletableFuture<>();
1314 >        f2 = new CompletableFuture<>();
1315          f2.completeExceptionally(new CFException());
1316          g = f.applyToEither(f2, inc);
1317          checkCompletedWithWrappedCFException(g);
# Line 878 | Line 1321 | public class CompletableFutureTest exten
1321       * applyToEither result completes exceptionally if action does
1322       */
1323      public void testApplyToEither3() {
1324 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1325 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1324 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1325 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1326          FailingFunction r = new FailingFunction();
1327          CompletableFuture<Integer> g = f.applyToEither(f2, r);
1328          f2.complete(two);
# Line 890 | Line 1333 | public class CompletableFutureTest exten
1333       * applyToEither result completes exceptionally if either source cancelled
1334       */
1335      public void testApplyToEither4() {
1336 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1337 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1336 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1337 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1338          CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1339          assertTrue(f.cancel(true));
1340          checkCompletedWithWrappedCancellationException(g);
1341 <        f = new CompletableFuture<Integer>();
1342 <        f2 = new CompletableFuture<Integer>();
1341 >        f = new CompletableFuture<>();
1342 >        f2 = new CompletableFuture<>();
1343          assertTrue(f2.cancel(true));
1344          checkCompletedWithWrappedCancellationException(g);
1345      }
# Line 906 | Line 1349 | public class CompletableFutureTest exten
1349       * of either source
1350       */
1351      public void testAcceptEither() {
1352 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1353 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1352 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1353 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1354          IncAction r = new IncAction();
1355          CompletableFuture<Void> g = f.acceptEither(f2, r);
1356          f.complete(one);
# Line 917 | Line 1360 | public class CompletableFutureTest exten
1360          assertEquals(r.value, 2);
1361  
1362          r = new IncAction();
1363 <        f = new CompletableFuture<Integer>();
1363 >        f = new CompletableFuture<>();
1364          f.complete(one);
1365 <        f2 = new CompletableFuture<Integer>();
1365 >        f2 = new CompletableFuture<>();
1366          g = f.acceptEither(f2, r);
1367          checkCompletedNormally(g, null);
1368          assertEquals(r.value, 2);
# Line 930 | Line 1373 | public class CompletableFutureTest exten
1373       * completion of either source
1374       */
1375      public void testAcceptEither2() {
1376 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1377 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1376 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1377 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1378          IncAction r = new IncAction();
1379          CompletableFuture<Void> g = f.acceptEither(f2, r);
1380          f.completeExceptionally(new CFException());
# Line 939 | Line 1382 | public class CompletableFutureTest exten
1382          checkCompletedWithWrappedCFException(g);
1383  
1384          r = new IncAction();
1385 <        f = new CompletableFuture<Integer>();
1386 <        f2 = new CompletableFuture<Integer>();
1385 >        f = new CompletableFuture<>();
1386 >        f2 = new CompletableFuture<>();
1387          f2.completeExceptionally(new CFException());
1388          g = f.acceptEither(f2, r);
1389          checkCompletedWithWrappedCFException(g);
# Line 950 | Line 1393 | public class CompletableFutureTest exten
1393       * acceptEither result completes exceptionally if action does
1394       */
1395      public void testAcceptEither3() {
1396 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1397 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1396 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1397 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1398          FailingConsumer r = new FailingConsumer();
1399          CompletableFuture<Void> g = f.acceptEither(f2, r);
1400          f2.complete(two);
# Line 962 | Line 1405 | public class CompletableFutureTest exten
1405       * acceptEither result completes exceptionally if either source cancelled
1406       */
1407      public void testAcceptEither4() {
1408 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1409 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1408 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1409 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1410          IncAction r = new IncAction();
1411          CompletableFuture<Void> g = f.acceptEither(f2, r);
1412          assertTrue(f.cancel(true));
1413          checkCompletedWithWrappedCancellationException(g);
1414 <        f = new CompletableFuture<Integer>();
1415 <        f2 = new CompletableFuture<Integer>();
1414 >        f = new CompletableFuture<>();
1415 >        f2 = new CompletableFuture<>();
1416          assertTrue(f2.cancel(true));
1417          checkCompletedWithWrappedCancellationException(g);
1418      }
1419  
977
1420      /**
1421       * runAfterEither result completes normally after normal completion
1422       * of either source
1423       */
1424      public void testRunAfterEither() {
1425 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1426 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1425 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1426 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1427          Noop r = new Noop();
1428          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1429          f.complete(one);
# Line 991 | Line 1433 | public class CompletableFutureTest exten
1433          assertTrue(r.ran);
1434  
1435          r = new Noop();
1436 <        f = new CompletableFuture<Integer>();
1436 >        f = new CompletableFuture<>();
1437          f.complete(one);
1438 <        f2 = new CompletableFuture<Integer>();
1438 >        f2 = new CompletableFuture<>();
1439          g = f.runAfterEither(f2, r);
1440          checkCompletedNormally(g, null);
1441          assertTrue(r.ran);
# Line 1004 | Line 1446 | public class CompletableFutureTest exten
1446       * completion of either source
1447       */
1448      public void testRunAfterEither2() {
1449 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1450 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1449 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1450 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1451          Noop r = new Noop();
1452          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1453          f.completeExceptionally(new CFException());
# Line 1013 | Line 1455 | public class CompletableFutureTest exten
1455          checkCompletedWithWrappedCFException(g);
1456  
1457          r = new Noop();
1458 <        f = new CompletableFuture<Integer>();
1459 <        f2 = new CompletableFuture<Integer>();
1458 >        f = new CompletableFuture<>();
1459 >        f2 = new CompletableFuture<>();
1460          f2.completeExceptionally(new CFException());
1461          g = f.runAfterEither(f2, r);
1462          checkCompletedWithWrappedCFException(g);
# Line 1024 | Line 1466 | public class CompletableFutureTest exten
1466       * runAfterEither result completes exceptionally if action does
1467       */
1468      public void testRunAfterEither3() {
1469 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1470 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1469 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1470 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1471          FailingNoop r = new FailingNoop();
1472          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1473          f2.complete(two);
# Line 1036 | Line 1478 | public class CompletableFutureTest exten
1478       * runAfterEither result completes exceptionally if either source cancelled
1479       */
1480      public void testRunAfterEither4() {
1481 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1482 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1481 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1482 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1483          Noop r = new Noop();
1484          CompletableFuture<Void> g = f.runAfterEither(f2, r);
1485          assertTrue(f.cancel(true));
1486          checkCompletedWithWrappedCancellationException(g);
1487 <        f = new CompletableFuture<Integer>();
1488 <        f2 = new CompletableFuture<Integer>();
1487 >        f = new CompletableFuture<>();
1488 >        f2 = new CompletableFuture<>();
1489          assertTrue(f2.cancel(true));
1490          checkCompletedWithWrappedCancellationException(g);
1491      }
# Line 1052 | Line 1494 | public class CompletableFutureTest exten
1494       * thenCompose result completes normally after normal completion of source
1495       */
1496      public void testThenCompose() {
1497 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1498 <        CompletableFutureInc r = new CompletableFutureInc();
1499 <        CompletableFuture<Integer> g = f.thenCompose(r);
1497 >        CompletableFuture<Integer> f, g;
1498 >        CompletableFutureInc r;
1499 >
1500 >        f = new CompletableFuture<>();
1501 >        g = f.thenCompose(r = new CompletableFutureInc());
1502          f.complete(one);
1503          checkCompletedNormally(g, two);
1504 +        assertTrue(r.ran);
1505 +
1506 +        f = new CompletableFuture<>();
1507 +        f.complete(one);
1508 +        g = f.thenCompose(r = new CompletableFutureInc());
1509 +        checkCompletedNormally(g, two);
1510 +        assertTrue(r.ran);
1511      }
1512  
1513      /**
# Line 1064 | Line 1515 | public class CompletableFutureTest exten
1515       * completion of source
1516       */
1517      public void testThenCompose2() {
1518 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1519 <        CompletableFutureInc r = new CompletableFutureInc();
1520 <        CompletableFuture<Integer> g = f.thenCompose(r);
1518 >        CompletableFuture<Integer> f, g;
1519 >        CompletableFutureInc r;
1520 >
1521 >        f = new CompletableFuture<>();
1522 >        g = f.thenCompose(r = new CompletableFutureInc());
1523          f.completeExceptionally(new CFException());
1524          checkCompletedWithWrappedCFException(g);
1525 +
1526 +        f = new CompletableFuture<>();
1527 +        f.completeExceptionally(new CFException());
1528 +        g = f.thenCompose(r = new CompletableFutureInc());
1529 +        checkCompletedWithWrappedCFException(g);
1530      }
1531  
1532      /**
1533       * thenCompose result completes exceptionally if action does
1534       */
1535      public void testThenCompose3() {
1536 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1537 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
1538 <        CompletableFuture<Integer> g = f.thenCompose(r);
1536 >        CompletableFuture<Integer> f, g;
1537 >        FailingCompletableFutureFunction r;
1538 >
1539 >        f = new CompletableFuture<>();
1540 >        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1541          f.complete(one);
1542          checkCompletedWithWrappedCFException(g);
1543 +
1544 +        f = new CompletableFuture<>();
1545 +        f.complete(one);
1546 +        g = f.thenCompose(r = new FailingCompletableFutureFunction());
1547 +        checkCompletedWithWrappedCFException(g);
1548      }
1549  
1550      /**
1551       * thenCompose result completes exceptionally if source cancelled
1552       */
1553      public void testThenCompose4() {
1554 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1555 <        CompletableFutureInc r = new CompletableFutureInc();
1556 <        CompletableFuture<Integer> g = f.thenCompose(r);
1554 >        CompletableFuture<Integer> f, g;
1555 >        CompletableFutureInc r;
1556 >
1557 >        f = new CompletableFuture<>();
1558 >        g = f.thenCompose(r = new CompletableFutureInc());
1559          assertTrue(f.cancel(true));
1560          checkCompletedWithWrappedCancellationException(g);
1094    }
1561  
1562 +        f = new CompletableFuture<>();
1563 +        assertTrue(f.cancel(true));
1564 +        g = f.thenCompose(r = new CompletableFutureInc());
1565 +        checkCompletedWithWrappedCancellationException(g);
1566 +    }
1567  
1568      // asyncs
1569  
# Line 1100 | Line 1571 | public class CompletableFutureTest exten
1571       * thenRunAsync result completes normally after normal completion of source
1572       */
1573      public void testThenRunAsync() {
1574 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1574 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1575          Noop r = new Noop();
1576          CompletableFuture<Void> g = f.thenRunAsync(r);
1577          f.complete(null);
1578          checkCompletedNormally(g, null);
1579  
1580          // reordered version
1581 <        f = new CompletableFuture<Integer>();
1581 >        f = new CompletableFuture<>();
1582          f.complete(null);
1583          r = new Noop();
1584          g = f.thenRunAsync(r);
# Line 1119 | Line 1590 | public class CompletableFutureTest exten
1590       * completion of source
1591       */
1592      public void testThenRunAsync2() {
1593 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1593 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1594          Noop r = new Noop();
1595          CompletableFuture<Void> g = f.thenRunAsync(r);
1596          f.completeExceptionally(new CFException());
1597          try {
1598              g.join();
1599              shouldThrow();
1600 <        } catch (Exception ok) {
1130 <        }
1600 >        } catch (CompletionException success) {}
1601          checkCompletedWithWrappedCFException(g);
1602      }
1603  
# Line 1135 | Line 1605 | public class CompletableFutureTest exten
1605       * thenRunAsync result completes exceptionally if action does
1606       */
1607      public void testThenRunAsync3() {
1608 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1608 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1609          FailingNoop r = new FailingNoop();
1610          CompletableFuture<Void> g = f.thenRunAsync(r);
1611          f.complete(null);
# Line 1146 | Line 1616 | public class CompletableFutureTest exten
1616       * thenRunAsync result completes exceptionally if source cancelled
1617       */
1618      public void testThenRunAsync4() {
1619 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1619 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1620          Noop r = new Noop();
1621          CompletableFuture<Void> g = f.thenRunAsync(r);
1622          assertTrue(f.cancel(true));
# Line 1157 | Line 1627 | public class CompletableFutureTest exten
1627       * thenApplyAsync result completes normally after normal completion of source
1628       */
1629      public void testThenApplyAsync() {
1630 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1630 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1631          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1632          f.complete(one);
1633          checkCompletedNormally(g, two);
# Line 1168 | Line 1638 | public class CompletableFutureTest exten
1638       * completion of source
1639       */
1640      public void testThenApplyAsync2() {
1641 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1641 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1642          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1643          f.completeExceptionally(new CFException());
1644          checkCompletedWithWrappedCFException(g);
# Line 1178 | Line 1648 | public class CompletableFutureTest exten
1648       * thenApplyAsync result completes exceptionally if action does
1649       */
1650      public void testThenApplyAsync3() {
1651 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1651 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1652          FailingFunction r = new FailingFunction();
1653          CompletableFuture<Integer> g = f.thenApplyAsync(r);
1654          f.complete(null);
# Line 1189 | Line 1659 | public class CompletableFutureTest exten
1659       * thenApplyAsync result completes exceptionally if source cancelled
1660       */
1661      public void testThenApplyAsync4() {
1662 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1662 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1663          CompletableFuture<Integer> g = f.thenApplyAsync(inc);
1664          assertTrue(f.cancel(true));
1665          checkCompletedWithWrappedCancellationException(g);
# Line 1200 | Line 1670 | public class CompletableFutureTest exten
1670       * completion of source
1671       */
1672      public void testThenAcceptAsync() {
1673 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1673 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1674          IncAction r = new IncAction();
1675          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1676          f.complete(one);
# Line 1213 | Line 1683 | public class CompletableFutureTest exten
1683       * completion of source
1684       */
1685      public void testThenAcceptAsync2() {
1686 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1686 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1687          IncAction r = new IncAction();
1688          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1689          f.completeExceptionally(new CFException());
# Line 1224 | Line 1694 | public class CompletableFutureTest exten
1694       * thenAcceptAsync result completes exceptionally if action does
1695       */
1696      public void testThenAcceptAsync3() {
1697 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1697 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1698          FailingConsumer r = new FailingConsumer();
1699          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1700          f.complete(null);
# Line 1235 | Line 1705 | public class CompletableFutureTest exten
1705       * thenAcceptAsync result completes exceptionally if source cancelled
1706       */
1707      public void testThenAcceptAsync4() {
1708 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1708 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1709          IncAction r = new IncAction();
1710          CompletableFuture<Void> g = f.thenAcceptAsync(r);
1711          assertTrue(f.cancel(true));
1712          checkCompletedWithWrappedCancellationException(g);
1713      }
1714 +
1715      /**
1716       * thenCombineAsync result completes normally after normal
1717       * completion of sources
1718       */
1719      public void testThenCombineAsync() {
1720 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1721 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1722 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1723 <        f.complete(one);
1724 <        checkIncomplete(g);
1725 <        f2.complete(two);
1726 <        checkCompletedNormally(g, three);
1720 >        CompletableFuture<Integer> f, g, h;
1721 >
1722 >        f = new CompletableFuture<>();
1723 >        g = new CompletableFuture<>();
1724 >        h = f.thenCombineAsync(g, subtract);
1725 >        f.complete(3);
1726 >        checkIncomplete(h);
1727 >        g.complete(1);
1728 >        checkCompletedNormally(h, 2);
1729 >
1730 >        f = new CompletableFuture<>();
1731 >        g = new CompletableFuture<>();
1732 >        h = f.thenCombineAsync(g, subtract);
1733 >        g.complete(1);
1734 >        checkIncomplete(h);
1735 >        f.complete(3);
1736 >        checkCompletedNormally(h, 2);
1737 >
1738 >        f = new CompletableFuture<>();
1739 >        g = new CompletableFuture<>();
1740 >        g.complete(1);
1741 >        f.complete(3);
1742 >        h = f.thenCombineAsync(g, subtract);
1743 >        checkCompletedNormally(h, 2);
1744      }
1745  
1746      /**
1747       * thenCombineAsync result completes exceptionally after exceptional
1748 <     * completion of source
1748 >     * completion of either source
1749       */
1750      public void testThenCombineAsync2() {
1751 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1264 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1265 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1266 <        f.completeExceptionally(new CFException());
1267 <        f2.complete(two);
1268 <        checkCompletedWithWrappedCFException(g);
1751 >        CompletableFuture<Integer> f, g, h;
1752  
1753 <        f = new CompletableFuture<Integer>();
1754 <        f2 = new CompletableFuture<Integer>();
1755 <        g = f.thenCombineAsync(f2, add);
1756 <        f.complete(one);
1757 <        f2.completeExceptionally(new CFException());
1758 <        checkCompletedWithWrappedCFException(g);
1753 >        f = new CompletableFuture<>();
1754 >        g = new CompletableFuture<>();
1755 >        h = f.thenCombineAsync(g, subtract);
1756 >        f.completeExceptionally(new CFException());
1757 >        checkIncomplete(h);
1758 >        g.complete(1);
1759 >        checkCompletedWithWrappedCFException(h);
1760 >
1761 >        f = new CompletableFuture<>();
1762 >        g = new CompletableFuture<>();
1763 >        h = f.thenCombineAsync(g, subtract);
1764 >        g.completeExceptionally(new CFException());
1765 >        checkIncomplete(h);
1766 >        f.complete(3);
1767 >        checkCompletedWithWrappedCFException(h);
1768 >
1769 >        f = new CompletableFuture<>();
1770 >        g = new CompletableFuture<>();
1771 >        g.completeExceptionally(new CFException());
1772 >        f.complete(3);
1773 >        h = f.thenCombineAsync(g, subtract);
1774 >        checkCompletedWithWrappedCFException(h);
1775      }
1776  
1777      /**
1778       * thenCombineAsync result completes exceptionally if action does
1779       */
1780      public void testThenCombineAsync3() {
1781 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1782 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1781 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1782 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1783          FailingBiFunction r = new FailingBiFunction();
1784          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r);
1785          f.complete(one);
1786          checkIncomplete(g);
1787 +        assertFalse(r.ran);
1788          f2.complete(two);
1789          checkCompletedWithWrappedCFException(g);
1790 +        assertTrue(r.ran);
1791      }
1792  
1793      /**
1794       * thenCombineAsync result completes exceptionally if either source cancelled
1795       */
1796      public void testThenCombineAsync4() {
1797 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1297 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1298 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add);
1299 <        assertTrue(f.cancel(true));
1300 <        f2.complete(two);
1301 <        checkCompletedWithWrappedCancellationException(g);
1797 >        CompletableFuture<Integer> f, g, h;
1798  
1799 <        f = new CompletableFuture<Integer>();
1800 <        f2 = new CompletableFuture<Integer>();
1801 <        g = f.thenCombineAsync(f2, add);
1802 <        f.complete(one);
1803 <        assertTrue(f2.cancel(true));
1804 <        checkCompletedWithWrappedCancellationException(g);
1799 >        f = new CompletableFuture<>();
1800 >        g = new CompletableFuture<>();
1801 >        h = f.thenCombineAsync(g, subtract);
1802 >        assertTrue(f.cancel(true));
1803 >        checkIncomplete(h);
1804 >        g.complete(1);
1805 >        checkCompletedWithWrappedCancellationException(h);
1806 >
1807 >        f = new CompletableFuture<>();
1808 >        g = new CompletableFuture<>();
1809 >        h = f.thenCombineAsync(g, subtract);
1810 >        assertTrue(g.cancel(true));
1811 >        checkIncomplete(h);
1812 >        f.complete(3);
1813 >        checkCompletedWithWrappedCancellationException(h);
1814 >
1815 >        f = new CompletableFuture<>();
1816 >        g = new CompletableFuture<>();
1817 >        g.complete(3);
1818 >        assertTrue(f.cancel(true));
1819 >        h = f.thenCombineAsync(g, subtract);
1820 >        checkCompletedWithWrappedCancellationException(h);
1821 >
1822 >        f = new CompletableFuture<>();
1823 >        g = new CompletableFuture<>();
1824 >        f.complete(3);
1825 >        assertTrue(g.cancel(true));
1826 >        h = f.thenCombineAsync(g, subtract);
1827 >        checkCompletedWithWrappedCancellationException(h);
1828      }
1829  
1830      /**
# Line 1313 | Line 1832 | public class CompletableFutureTest exten
1832       * completion of sources
1833       */
1834      public void testThenAcceptBothAsync() {
1835 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1836 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1837 <        AddAction r = new AddAction();
1838 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1839 <        f.complete(one);
1840 <        checkIncomplete(g);
1841 <        f2.complete(two);
1842 <        checkCompletedNormally(g, null);
1843 <        assertEquals(r.value, 3);
1835 >        CompletableFuture<Integer> f, g;
1836 >        CompletableFuture<Void> h;
1837 >        SubtractAction r;
1838 >
1839 >        f = new CompletableFuture<>();
1840 >        g = new CompletableFuture<>();
1841 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1842 >        f.complete(3);
1843 >        checkIncomplete(h);
1844 >        g.complete(1);
1845 >        checkCompletedNormally(h, null);
1846 >        assertEquals(r.value, 2);
1847 >
1848 >        f = new CompletableFuture<>();
1849 >        g = new CompletableFuture<>();
1850 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1851 >        g.complete(1);
1852 >        checkIncomplete(h);
1853 >        f.complete(3);
1854 >        checkCompletedNormally(h, null);
1855 >        assertEquals(r.value, 2);
1856 >
1857 >        f = new CompletableFuture<>();
1858 >        g = new CompletableFuture<>();
1859 >        g.complete(1);
1860 >        f.complete(3);
1861 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1862 >        checkCompletedNormally(h, null);
1863 >        assertEquals(r.value, 2);
1864      }
1865  
1866      /**
# Line 1329 | Line 1868 | public class CompletableFutureTest exten
1868       * completion of source
1869       */
1870      public void testThenAcceptBothAsync2() {
1871 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1872 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1873 <        AddAction r = new AddAction();
1874 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1875 <        f.completeExceptionally(new CFException());
1876 <        f2.complete(two);
1877 <        checkCompletedWithWrappedCFException(g);
1878 <
1879 <        r = new AddAction();
1880 <        f = new CompletableFuture<Integer>();
1881 <        f2 = new CompletableFuture<Integer>();
1882 <        g = f.thenAcceptBothAsync(f2, r);
1883 <        f.complete(one);
1884 <        f2.completeExceptionally(new CFException());
1885 <        checkCompletedWithWrappedCFException(g);
1871 >        CompletableFuture<Integer> f, g;
1872 >        CompletableFuture<Void> h;
1873 >        SubtractAction r;
1874 >
1875 >        f = new CompletableFuture<>();
1876 >        g = new CompletableFuture<>();
1877 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1878 >        f.completeExceptionally(new CFException());
1879 >        checkIncomplete(h);
1880 >        g.complete(1);
1881 >        checkCompletedWithWrappedCFException(h);
1882 >
1883 >        f = new CompletableFuture<>();
1884 >        g = new CompletableFuture<>();
1885 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1886 >        g.completeExceptionally(new CFException());
1887 >        checkIncomplete(h);
1888 >        f.complete(3);
1889 >        checkCompletedWithWrappedCFException(h);
1890 >
1891 >        f = new CompletableFuture<>();
1892 >        g = new CompletableFuture<>();
1893 >        f.complete(3);
1894 >        g.completeExceptionally(new CFException());
1895 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1896 >        checkCompletedWithWrappedCFException(h);
1897 >
1898 >        f = new CompletableFuture<>();
1899 >        g = new CompletableFuture<>();
1900 >        f.completeExceptionally(new CFException());
1901 >        g.complete(3);
1902 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1903 >        checkCompletedWithWrappedCFException(h);
1904      }
1905  
1906      /**
1907       * thenAcceptBothAsync result completes exceptionally if action does
1908       */
1909      public void testThenAcceptBothAsync3() {
1910 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1911 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1912 <        FailingBiConsumer r = new FailingBiConsumer();
1913 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1914 <        f.complete(one);
1915 <        checkIncomplete(g);
1916 <        f2.complete(two);
1917 <        checkCompletedWithWrappedCFException(g);
1910 >        CompletableFuture<Integer> f, g;
1911 >        CompletableFuture<Void> h;
1912 >        FailingBiConsumer r;
1913 >
1914 >        f = new CompletableFuture<>();
1915 >        g = new CompletableFuture<>();
1916 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1917 >        f.complete(3);
1918 >        checkIncomplete(h);
1919 >        g.complete(1);
1920 >        checkCompletedWithWrappedCFException(h);
1921 >
1922 >        f = new CompletableFuture<>();
1923 >        g = new CompletableFuture<>();
1924 >        f.complete(3);
1925 >        g.complete(1);
1926 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer());
1927 >        checkCompletedWithWrappedCFException(h);
1928      }
1929  
1930      /**
1931       * thenAcceptBothAsync result completes exceptionally if either source cancelled
1932       */
1933      public void testThenAcceptBothAsync4() {
1934 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1935 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1936 <        AddAction r = new AddAction();
1937 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r);
1938 <        assertTrue(f.cancel(true));
1939 <        f2.complete(two);
1940 <        checkCompletedWithWrappedCancellationException(g);
1941 <
1942 <        r = new AddAction();
1943 <        f = new CompletableFuture<Integer>();
1944 <        f2 = new CompletableFuture<Integer>();
1945 <        g = f.thenAcceptBothAsync(f2, r);
1946 <        f.complete(one);
1947 <        assertTrue(f2.cancel(true));
1948 <        checkCompletedWithWrappedCancellationException(g);
1949 <    }
1950 <
1951 <    /**
1952 <     * runAfterBothAsync result completes normally after normal
1953 <     * completion of sources
1954 <     */
1955 <    public void testRunAfterBothAsync() {
1956 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1957 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1958 <        Noop r = new Noop();
1959 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1960 <        f.complete(one);
1961 <        checkIncomplete(g);
1962 <        f2.complete(two);
1963 <        checkCompletedNormally(g, null);
1964 <        assertTrue(r.ran);
1965 <    }
1966 <
1400 <    /**
1401 <     * runAfterBothAsync result completes exceptionally after exceptional
1402 <     * completion of source
1403 <     */
1404 <    public void testRunAfterBothAsync2() {
1405 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1406 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1407 <        Noop r = new Noop();
1408 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1409 <        f.completeExceptionally(new CFException());
1410 <        f2.complete(two);
1411 <        checkCompletedWithWrappedCFException(g);
1412 <
1413 <        r = new Noop();
1414 <        f = new CompletableFuture<Integer>();
1415 <        f2 = new CompletableFuture<Integer>();
1416 <        g = f.runAfterBothAsync(f2, r);
1417 <        f.complete(one);
1418 <        f2.completeExceptionally(new CFException());
1419 <        checkCompletedWithWrappedCFException(g);
1420 <    }
1421 <
1422 <    /**
1423 <     * runAfterBothAsync result completes exceptionally if action does
1424 <     */
1425 <    public void testRunAfterBothAsync3() {
1426 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1427 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1428 <        FailingNoop r = new FailingNoop();
1429 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1430 <        f.complete(one);
1431 <        checkIncomplete(g);
1432 <        f2.complete(two);
1433 <        checkCompletedWithWrappedCFException(g);
1434 <    }
1435 <
1436 <    /**
1437 <     * runAfterBothAsync result completes exceptionally if either source cancelled
1438 <     */
1439 <    public void testRunAfterBothAsync4() {
1440 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1441 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1442 <        Noop r = new Noop();
1443 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1444 <        assertTrue(f.cancel(true));
1445 <        f2.complete(two);
1446 <        checkCompletedWithWrappedCancellationException(g);
1447 <
1448 <        r = new Noop();
1449 <        f = new CompletableFuture<Integer>();
1450 <        f2 = new CompletableFuture<Integer>();
1451 <        g = f.runAfterBothAsync(f2, r);
1452 <        f.complete(one);
1453 <        assertTrue(f2.cancel(true));
1454 <        checkCompletedWithWrappedCancellationException(g);
1934 >        CompletableFuture<Integer> f, g;
1935 >        CompletableFuture<Void> h;
1936 >        SubtractAction r;
1937 >
1938 >        f = new CompletableFuture<>();
1939 >        g = new CompletableFuture<>();
1940 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1941 >        assertTrue(f.cancel(true));
1942 >        checkIncomplete(h);
1943 >        g.complete(1);
1944 >        checkCompletedWithWrappedCancellationException(h);
1945 >
1946 >        f = new CompletableFuture<>();
1947 >        g = new CompletableFuture<>();
1948 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1949 >        assertTrue(g.cancel(true));
1950 >        checkIncomplete(h);
1951 >        f.complete(3);
1952 >        checkCompletedWithWrappedCancellationException(h);
1953 >
1954 >        f = new CompletableFuture<>();
1955 >        g = new CompletableFuture<>();
1956 >        f.complete(3);
1957 >        assertTrue(g.cancel(true));
1958 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1959 >        checkCompletedWithWrappedCancellationException(h);
1960 >
1961 >        f = new CompletableFuture<>();
1962 >        g = new CompletableFuture<>();
1963 >        assertTrue(f.cancel(true));
1964 >        g.complete(3);
1965 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction());
1966 >        checkCompletedWithWrappedCancellationException(h);
1967      }
1968  
1969      /**
# Line 1459 | Line 1971 | public class CompletableFutureTest exten
1971       * completion of sources
1972       */
1973      public void testApplyToEitherAsync() {
1974 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1975 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1974 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1975 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1976          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1977          f.complete(one);
1978          checkCompletedNormally(g, two);
1979  
1980 <        f = new CompletableFuture<Integer>();
1980 >        f = new CompletableFuture<>();
1981          f.complete(one);
1982 <        f2 = new CompletableFuture<Integer>();
1982 >        f2 = new CompletableFuture<>();
1983          g = f.applyToEitherAsync(f2, inc);
1984          checkCompletedNormally(g, two);
1985      }
# Line 1477 | Line 1989 | public class CompletableFutureTest exten
1989       * completion of source
1990       */
1991      public void testApplyToEitherAsync2() {
1992 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
1993 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1992 >        CompletableFuture<Integer> f = new CompletableFuture<>();
1993 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1994          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
1995          f.completeExceptionally(new CFException());
1996          checkCompletedWithWrappedCFException(g);
1997  
1998 <        f = new CompletableFuture<Integer>();
1999 <        f2 = new CompletableFuture<Integer>();
1998 >        f = new CompletableFuture<>();
1999 >        f2 = new CompletableFuture<>();
2000          f2.completeExceptionally(new CFException());
2001          g = f.applyToEitherAsync(f2, inc);
2002          f.complete(one);
# Line 1495 | Line 2007 | public class CompletableFutureTest exten
2007       * applyToEitherAsync result completes exceptionally if action does
2008       */
2009      public void testApplyToEitherAsync3() {
2010 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2011 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2010 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2011 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2012          FailingFunction r = new FailingFunction();
2013          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
2014          f.complete(one);
# Line 1507 | Line 2019 | public class CompletableFutureTest exten
2019       * applyToEitherAsync result completes exceptionally if either source cancelled
2020       */
2021      public void testApplyToEitherAsync4() {
2022 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2023 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2022 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2023 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2024          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2025          assertTrue(f.cancel(true));
2026          checkCompletedWithWrappedCancellationException(g);
2027  
2028 <        f = new CompletableFuture<Integer>();
2029 <        f2 = new CompletableFuture<Integer>();
2028 >        f = new CompletableFuture<>();
2029 >        f2 = new CompletableFuture<>();
2030          assertTrue(f2.cancel(true));
2031          g = f.applyToEitherAsync(f2, inc);
2032          checkCompletedWithWrappedCancellationException(g);
# Line 1525 | Line 2037 | public class CompletableFutureTest exten
2037       * completion of sources
2038       */
2039      public void testAcceptEitherAsync() {
2040 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2041 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2040 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2041 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2042          IncAction r = new IncAction();
2043          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2044          f.complete(one);
# Line 1534 | Line 2046 | public class CompletableFutureTest exten
2046          assertEquals(r.value, 2);
2047  
2048          r = new IncAction();
2049 <        f = new CompletableFuture<Integer>();
2049 >        f = new CompletableFuture<>();
2050          f.complete(one);
2051 <        f2 = new CompletableFuture<Integer>();
2051 >        f2 = new CompletableFuture<>();
2052          g = f.acceptEitherAsync(f2, r);
2053          checkCompletedNormally(g, null);
2054          assertEquals(r.value, 2);
# Line 1547 | Line 2059 | public class CompletableFutureTest exten
2059       * completion of source
2060       */
2061      public void testAcceptEitherAsync2() {
2062 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2063 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2062 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2063 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2064          IncAction r = new IncAction();
2065          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2066          f.completeExceptionally(new CFException());
2067          checkCompletedWithWrappedCFException(g);
2068  
2069          r = new IncAction();
2070 <        f = new CompletableFuture<Integer>();
2071 <        f2 = new CompletableFuture<Integer>();
2070 >        f = new CompletableFuture<>();
2071 >        f2 = new CompletableFuture<>();
2072          f2.completeExceptionally(new CFException());
2073          g = f.acceptEitherAsync(f2, r);
2074          f.complete(one);
# Line 1567 | Line 2079 | public class CompletableFutureTest exten
2079       * acceptEitherAsync result completes exceptionally if action does
2080       */
2081      public void testAcceptEitherAsync3() {
2082 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2083 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2082 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2083 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2084          FailingConsumer r = new FailingConsumer();
2085          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2086          f.complete(one);
# Line 1580 | Line 2092 | public class CompletableFutureTest exten
2092       * source cancelled
2093       */
2094      public void testAcceptEitherAsync4() {
2095 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2096 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2095 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2096 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2097          IncAction r = new IncAction();
2098          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2099          assertTrue(f.cancel(true));
2100          checkCompletedWithWrappedCancellationException(g);
2101  
2102          r = new IncAction();
2103 <        f = new CompletableFuture<Integer>();
2104 <        f2 = new CompletableFuture<Integer>();
2103 >        f = new CompletableFuture<>();
2104 >        f2 = new CompletableFuture<>();
2105          assertTrue(f2.cancel(true));
2106          g = f.acceptEitherAsync(f2, r);
2107          checkCompletedWithWrappedCancellationException(g);
# Line 1600 | Line 2112 | public class CompletableFutureTest exten
2112       * completion of sources
2113       */
2114      public void testRunAfterEitherAsync() {
2115 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2116 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2115 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2116 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2117          Noop r = new Noop();
2118          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2119          f.complete(one);
# Line 1609 | Line 2121 | public class CompletableFutureTest exten
2121          assertTrue(r.ran);
2122  
2123          r = new Noop();
2124 <        f = new CompletableFuture<Integer>();
2124 >        f = new CompletableFuture<>();
2125          f.complete(one);
2126 <        f2 = new CompletableFuture<Integer>();
2126 >        f2 = new CompletableFuture<>();
2127          g = f.runAfterEitherAsync(f2, r);
2128          checkCompletedNormally(g, null);
2129          assertTrue(r.ran);
# Line 1622 | Line 2134 | public class CompletableFutureTest exten
2134       * completion of source
2135       */
2136      public void testRunAfterEitherAsync2() {
2137 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2138 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2137 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2138 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2139          Noop r = new Noop();
2140          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2141          f.completeExceptionally(new CFException());
2142          checkCompletedWithWrappedCFException(g);
2143  
2144          r = new Noop();
2145 <        f = new CompletableFuture<Integer>();
2146 <        f2 = new CompletableFuture<Integer>();
2145 >        f = new CompletableFuture<>();
2146 >        f2 = new CompletableFuture<>();
2147          f2.completeExceptionally(new CFException());
2148          g = f.runAfterEitherAsync(f2, r);
2149          f.complete(one);
# Line 1642 | Line 2154 | public class CompletableFutureTest exten
2154       * runAfterEitherAsync result completes exceptionally if action does
2155       */
2156      public void testRunAfterEitherAsync3() {
2157 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2158 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2157 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2158 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2159          FailingNoop r = new FailingNoop();
2160          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2161          f.complete(one);
# Line 1655 | Line 2167 | public class CompletableFutureTest exten
2167       * source cancelled
2168       */
2169      public void testRunAfterEitherAsync4() {
2170 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2171 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2170 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2171 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2172          Noop r = new Noop();
2173          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2174          assertTrue(f.cancel(true));
2175          checkCompletedWithWrappedCancellationException(g);
2176  
2177          r = new Noop();
2178 <        f = new CompletableFuture<Integer>();
2179 <        f2 = new CompletableFuture<Integer>();
2178 >        f = new CompletableFuture<>();
2179 >        f2 = new CompletableFuture<>();
2180          assertTrue(f2.cancel(true));
2181          g = f.runAfterEitherAsync(f2, r);
2182          checkCompletedWithWrappedCancellationException(g);
# Line 1675 | Line 2187 | public class CompletableFutureTest exten
2187       * completion of source
2188       */
2189      public void testThenComposeAsync() {
2190 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2191 <        CompletableFutureInc r = new CompletableFutureInc();
2192 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2190 >        CompletableFuture<Integer> f, g;
2191 >        CompletableFutureInc r;
2192 >
2193 >        f = new CompletableFuture<>();
2194 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2195          f.complete(one);
2196          checkCompletedNormally(g, two);
2197 +
2198 +        f = new CompletableFuture<>();
2199 +        f.complete(one);
2200 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2201 +        checkCompletedNormally(g, two);
2202      }
2203  
2204      /**
# Line 1687 | Line 2206 | public class CompletableFutureTest exten
2206       * exceptional completion of source
2207       */
2208      public void testThenComposeAsync2() {
2209 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2210 <        CompletableFutureInc r = new CompletableFutureInc();
2211 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2209 >        CompletableFuture<Integer> f, g;
2210 >        CompletableFutureInc r;
2211 >
2212 >        f = new CompletableFuture<>();
2213 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2214          f.completeExceptionally(new CFException());
2215          checkCompletedWithWrappedCFException(g);
2216 +        assertFalse(r.ran);
2217 +
2218 +        f = new CompletableFuture<>();
2219 +        f.completeExceptionally(new CFException());
2220 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2221 +        checkCompletedWithWrappedCFException(g);
2222 +        assertFalse(r.ran);
2223      }
2224  
2225      /**
2226       * thenComposeAsync result completes exceptionally if action does
2227       */
2228      public void testThenComposeAsync3() {
2229 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2230 <        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2231 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2229 >        CompletableFuture<Integer> f, g;
2230 >        FailingCompletableFutureFunction r;
2231 >
2232 >        f = new CompletableFuture<>();
2233 >        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2234          f.complete(one);
2235          checkCompletedWithWrappedCFException(g);
2236 +
2237 +        f = new CompletableFuture<>();
2238 +        f.complete(one);
2239 +        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2240 +        checkCompletedWithWrappedCFException(g);
2241      }
2242  
2243      /**
2244       * thenComposeAsync result completes exceptionally if source cancelled
2245       */
2246      public void testThenComposeAsync4() {
2247 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2248 <        CompletableFutureInc r = new CompletableFutureInc();
2249 <        CompletableFuture<Integer> g = f.thenComposeAsync(r);
2247 >        CompletableFuture<Integer> f, g;
2248 >        CompletableFutureInc r;
2249 >
2250 >        f = new CompletableFuture<>();
2251 >        g = f.thenComposeAsync(r = new CompletableFutureInc());
2252          assertTrue(f.cancel(true));
2253          checkCompletedWithWrappedCancellationException(g);
1717    }
2254  
2255 +        f = new CompletableFuture<>();
2256 +        assertTrue(f.cancel(true));
2257 +        g = f.thenComposeAsync(r = new CompletableFutureInc());
2258 +        checkCompletedWithWrappedCancellationException(g);
2259 +    }
2260  
2261      // async with explicit executors
2262  
# Line 1723 | Line 2264 | public class CompletableFutureTest exten
2264       * thenRunAsync result completes normally after normal completion of source
2265       */
2266      public void testThenRunAsyncE() {
2267 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2267 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2268          Noop r = new Noop();
2269          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2270          f.complete(null);
2271          checkCompletedNormally(g, null);
2272  
2273          // reordered version
2274 <        f = new CompletableFuture<Integer>();
2274 >        f = new CompletableFuture<>();
2275          f.complete(null);
2276          r = new Noop();
2277          g = f.thenRunAsync(r, new ThreadExecutor());
# Line 1742 | Line 2283 | public class CompletableFutureTest exten
2283       * completion of source
2284       */
2285      public void testThenRunAsync2E() {
2286 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2286 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2287          Noop r = new Noop();
2288          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2289          f.completeExceptionally(new CFException());
2290          try {
2291              g.join();
2292              shouldThrow();
2293 <        } catch (Exception ok) {
1753 <        }
2293 >        } catch (CompletionException success) {}
2294          checkCompletedWithWrappedCFException(g);
2295      }
2296  
# Line 1758 | Line 2298 | public class CompletableFutureTest exten
2298       * thenRunAsync result completes exceptionally if action does
2299       */
2300      public void testThenRunAsync3E() {
2301 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2301 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2302          FailingNoop r = new FailingNoop();
2303          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2304          f.complete(null);
# Line 1769 | Line 2309 | public class CompletableFutureTest exten
2309       * thenRunAsync result completes exceptionally if source cancelled
2310       */
2311      public void testThenRunAsync4E() {
2312 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2312 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2313          Noop r = new Noop();
2314          CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
2315          assertTrue(f.cancel(true));
# Line 1780 | Line 2320 | public class CompletableFutureTest exten
2320       * thenApplyAsync result completes normally after normal completion of source
2321       */
2322      public void testThenApplyAsyncE() {
2323 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2323 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2324          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2325          f.complete(one);
2326          checkCompletedNormally(g, two);
# Line 1791 | Line 2331 | public class CompletableFutureTest exten
2331       * completion of source
2332       */
2333      public void testThenApplyAsync2E() {
2334 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2334 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2335          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2336          f.completeExceptionally(new CFException());
2337          checkCompletedWithWrappedCFException(g);
# Line 1801 | Line 2341 | public class CompletableFutureTest exten
2341       * thenApplyAsync result completes exceptionally if action does
2342       */
2343      public void testThenApplyAsync3E() {
2344 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2344 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2345          FailingFunction r = new FailingFunction();
2346          CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
2347          f.complete(null);
# Line 1812 | Line 2352 | public class CompletableFutureTest exten
2352       * thenApplyAsync result completes exceptionally if source cancelled
2353       */
2354      public void testThenApplyAsync4E() {
2355 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2355 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2356          CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
2357          assertTrue(f.cancel(true));
2358          checkCompletedWithWrappedCancellationException(g);
# Line 1823 | Line 2363 | public class CompletableFutureTest exten
2363       * completion of source
2364       */
2365      public void testThenAcceptAsyncE() {
2366 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2366 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2367          IncAction r = new IncAction();
2368          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2369          f.complete(one);
# Line 1836 | Line 2376 | public class CompletableFutureTest exten
2376       * completion of source
2377       */
2378      public void testThenAcceptAsync2E() {
2379 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2379 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2380          IncAction r = new IncAction();
2381          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2382          f.completeExceptionally(new CFException());
# Line 1847 | Line 2387 | public class CompletableFutureTest exten
2387       * thenAcceptAsync result completes exceptionally if action does
2388       */
2389      public void testThenAcceptAsync3E() {
2390 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2390 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2391          FailingConsumer r = new FailingConsumer();
2392          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2393          f.complete(null);
# Line 1858 | Line 2398 | public class CompletableFutureTest exten
2398       * thenAcceptAsync result completes exceptionally if source cancelled
2399       */
2400      public void testThenAcceptAsync4E() {
2401 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2401 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2402          IncAction r = new IncAction();
2403          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2404          assertTrue(f.cancel(true));
2405          checkCompletedWithWrappedCancellationException(g);
2406      }
2407 +
2408      /**
2409       * thenCombineAsync result completes normally after normal
2410       * completion of sources
2411       */
2412      public void testThenCombineAsyncE() {
2413 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2414 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2415 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2416 <        f.complete(one);
2417 <        checkIncomplete(g);
2418 <        f2.complete(two);
2419 <        checkCompletedNormally(g, three);
2413 >        CompletableFuture<Integer> f, g, h;
2414 >        ThreadExecutor e = new ThreadExecutor();
2415 >        int count = 0;
2416 >
2417 >        f = new CompletableFuture<>();
2418 >        g = new CompletableFuture<>();
2419 >        h = f.thenCombineAsync(g, subtract, e);
2420 >        f.complete(3);
2421 >        checkIncomplete(h);
2422 >        g.complete(1);
2423 >        checkCompletedNormally(h, 2);
2424 >        assertEquals(++count, e.count.get());
2425 >
2426 >        f = new CompletableFuture<>();
2427 >        g = new CompletableFuture<>();
2428 >        h = f.thenCombineAsync(g, subtract, e);
2429 >        g.complete(1);
2430 >        checkIncomplete(h);
2431 >        f.complete(3);
2432 >        checkCompletedNormally(h, 2);
2433 >        assertEquals(++count, e.count.get());
2434 >
2435 >        f = new CompletableFuture<>();
2436 >        g = new CompletableFuture<>();
2437 >        g.complete(1);
2438 >        f.complete(3);
2439 >        h = f.thenCombineAsync(g, subtract, e);
2440 >        checkCompletedNormally(h, 2);
2441 >        assertEquals(++count, e.count.get());
2442      }
2443  
2444      /**
2445       * thenCombineAsync result completes exceptionally after exceptional
2446 <     * completion of source
2446 >     * completion of either source
2447       */
2448      public void testThenCombineAsync2E() {
2449 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2450 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2451 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2452 <        f.completeExceptionally(new CFException());
2453 <        f2.complete(two);
2454 <        checkCompletedWithWrappedCFException(g);
2449 >        CompletableFuture<Integer> f, g, h;
2450 >        ThreadExecutor e = new ThreadExecutor();
2451 >        int count = 0;
2452 >
2453 >        f = new CompletableFuture<>();
2454 >        g = new CompletableFuture<>();
2455 >        h = f.thenCombineAsync(g, subtract, e);
2456 >        f.completeExceptionally(new CFException());
2457 >        checkIncomplete(h);
2458 >        g.complete(1);
2459 >        checkCompletedWithWrappedCFException(h);
2460 >
2461 >        f = new CompletableFuture<>();
2462 >        g = new CompletableFuture<>();
2463 >        h = f.thenCombineAsync(g, subtract, e);
2464 >        g.completeExceptionally(new CFException());
2465 >        checkIncomplete(h);
2466 >        f.complete(3);
2467 >        checkCompletedWithWrappedCFException(h);
2468 >
2469 >        f = new CompletableFuture<>();
2470 >        g = new CompletableFuture<>();
2471 >        g.completeExceptionally(new CFException());
2472 >        h = f.thenCombineAsync(g, subtract, e);
2473 >        checkIncomplete(h);
2474 >        f.complete(3);
2475 >        checkCompletedWithWrappedCFException(h);
2476  
2477 <        f = new CompletableFuture<Integer>();
1894 <        f2 = new CompletableFuture<Integer>();
1895 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1896 <        f.complete(one);
1897 <        f2.completeExceptionally(new CFException());
1898 <        checkCompletedWithWrappedCFException(g);
2477 >        assertEquals(0, e.count.get());
2478      }
2479  
2480      /**
2481       * thenCombineAsync result completes exceptionally if action does
2482       */
2483      public void testThenCombineAsync3E() {
2484 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2485 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2484 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2485 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2486          FailingBiFunction r = new FailingBiFunction();
2487          CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor());
2488          f.complete(one);
2489          checkIncomplete(g);
2490 +        assertFalse(r.ran);
2491          f2.complete(two);
2492          checkCompletedWithWrappedCFException(g);
2493 +        assertTrue(r.ran);
2494      }
2495  
2496      /**
2497       * thenCombineAsync result completes exceptionally if either source cancelled
2498       */
2499      public void testThenCombineAsync4E() {
2500 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2501 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
1921 <        CompletableFuture<Integer> g = f.thenCombineAsync(f2, add, new ThreadExecutor());
1922 <        assertTrue(f.cancel(true));
1923 <        f2.complete(two);
1924 <        checkCompletedWithWrappedCancellationException(g);
2500 >        CompletableFuture<Integer> f, g, h;
2501 >        ThreadExecutor e = new ThreadExecutor();
2502  
2503 <        f = new CompletableFuture<Integer>();
2504 <        f2 = new CompletableFuture<Integer>();
2505 <        g = f.thenCombineAsync(f2, add, new ThreadExecutor());
2506 <        f.complete(one);
2507 <        assertTrue(f2.cancel(true));
2508 <        checkCompletedWithWrappedCancellationException(g);
2503 >        f = new CompletableFuture<>();
2504 >        g = new CompletableFuture<>();
2505 >        h = f.thenCombineAsync(g, subtract, e);
2506 >        assertTrue(f.cancel(true));
2507 >        checkIncomplete(h);
2508 >        g.complete(1);
2509 >        checkCompletedWithWrappedCancellationException(h);
2510 >
2511 >        f = new CompletableFuture<>();
2512 >        g = new CompletableFuture<>();
2513 >        h = f.thenCombineAsync(g, subtract, e);
2514 >        assertTrue(g.cancel(true));
2515 >        checkIncomplete(h);
2516 >        f.complete(3);
2517 >        checkCompletedWithWrappedCancellationException(h);
2518 >
2519 >        f = new CompletableFuture<>();
2520 >        g = new CompletableFuture<>();
2521 >        assertTrue(g.cancel(true));
2522 >        h = f.thenCombineAsync(g, subtract, e);
2523 >        checkIncomplete(h);
2524 >        f.complete(3);
2525 >        checkCompletedWithWrappedCancellationException(h);
2526 >
2527 >        f = new CompletableFuture<>();
2528 >        g = new CompletableFuture<>();
2529 >        assertTrue(f.cancel(true));
2530 >        assertTrue(g.cancel(true));
2531 >        h = f.thenCombineAsync(g, subtract, e);
2532 >        checkCompletedWithWrappedCancellationException(h);
2533 >
2534 >        assertEquals(0, e.count.get());
2535      }
2536  
2537      /**
# Line 1936 | Line 2539 | public class CompletableFutureTest exten
2539       * completion of sources
2540       */
2541      public void testThenAcceptBothAsyncE() {
2542 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2543 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2544 <        AddAction r = new AddAction();
2545 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2546 <        f.complete(one);
2547 <        checkIncomplete(g);
2548 <        f2.complete(two);
2549 <        checkCompletedNormally(g, null);
2550 <        assertEquals(r.value, 3);
2542 >        CompletableFuture<Integer> f, g;
2543 >        CompletableFuture<Void> h;
2544 >        SubtractAction r;
2545 >        ThreadExecutor e = new ThreadExecutor();
2546 >
2547 >        f = new CompletableFuture<>();
2548 >        g = new CompletableFuture<>();
2549 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2550 >        f.complete(3);
2551 >        checkIncomplete(h);
2552 >        g.complete(1);
2553 >        checkCompletedNormally(h, null);
2554 >        assertEquals(r.value, 2);
2555 >
2556 >        f = new CompletableFuture<>();
2557 >        g = new CompletableFuture<>();
2558 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2559 >        g.complete(1);
2560 >        checkIncomplete(h);
2561 >        f.complete(3);
2562 >        checkCompletedNormally(h, null);
2563 >        assertEquals(r.value, 2);
2564 >
2565 >        f = new CompletableFuture<>();
2566 >        g = new CompletableFuture<>();
2567 >        g.complete(1);
2568 >        f.complete(3);
2569 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2570 >        checkCompletedNormally(h, null);
2571 >        assertEquals(r.value, 2);
2572 >
2573 >        assertEquals(3, e.count.get());
2574      }
2575  
2576      /**
# Line 1952 | Line 2578 | public class CompletableFutureTest exten
2578       * completion of source
2579       */
2580      public void testThenAcceptBothAsync2E() {
2581 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2582 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2583 <        AddAction r = new AddAction();
2584 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2585 <        f.completeExceptionally(new CFException());
2586 <        f2.complete(two);
2587 <        checkCompletedWithWrappedCFException(g);
2581 >        CompletableFuture<Integer> f, g;
2582 >        CompletableFuture<Void> h;
2583 >        SubtractAction r;
2584 >        ThreadExecutor e = new ThreadExecutor();
2585 >
2586 >        f = new CompletableFuture<>();
2587 >        g = new CompletableFuture<>();
2588 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2589 >        f.completeExceptionally(new CFException());
2590 >        checkIncomplete(h);
2591 >        g.complete(1);
2592 >        checkCompletedWithWrappedCFException(h);
2593 >
2594 >        f = new CompletableFuture<>();
2595 >        g = new CompletableFuture<>();
2596 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2597 >        g.completeExceptionally(new CFException());
2598 >        checkIncomplete(h);
2599 >        f.complete(3);
2600 >        checkCompletedWithWrappedCFException(h);
2601 >
2602 >        f = new CompletableFuture<>();
2603 >        g = new CompletableFuture<>();
2604 >        f.complete(3);
2605 >        g.completeExceptionally(new CFException());
2606 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2607 >        checkCompletedWithWrappedCFException(h);
2608 >
2609 >        f = new CompletableFuture<>();
2610 >        g = new CompletableFuture<>();
2611 >        f.completeExceptionally(new CFException());
2612 >        g.complete(3);
2613 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2614 >        checkCompletedWithWrappedCFException(h);
2615  
2616 <        r = new AddAction();
1964 <        f = new CompletableFuture<Integer>();
1965 <        f2 = new CompletableFuture<Integer>();
1966 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
1967 <        f.complete(one);
1968 <        f2.completeExceptionally(new CFException());
1969 <        checkCompletedWithWrappedCFException(g);
2616 >        assertEquals(0, e.count.get());
2617      }
2618  
2619      /**
2620       * thenAcceptBothAsync result completes exceptionally if action does
2621       */
2622      public void testThenAcceptBothAsync3E() {
2623 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2624 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2625 <        FailingBiConsumer r = new FailingBiConsumer();
2626 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2627 <        f.complete(one);
2628 <        checkIncomplete(g);
2629 <        f2.complete(two);
2630 <        checkCompletedWithWrappedCFException(g);
2623 >        CompletableFuture<Integer> f, g;
2624 >        CompletableFuture<Void> h;
2625 >        FailingBiConsumer r;
2626 >        ThreadExecutor e = new ThreadExecutor();
2627 >
2628 >        f = new CompletableFuture<>();
2629 >        g = new CompletableFuture<>();
2630 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2631 >        f.complete(3);
2632 >        checkIncomplete(h);
2633 >        g.complete(1);
2634 >        checkCompletedWithWrappedCFException(h);
2635 >
2636 >        f = new CompletableFuture<>();
2637 >        g = new CompletableFuture<>();
2638 >        f.complete(3);
2639 >        g.complete(1);
2640 >        h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e);
2641 >        checkCompletedWithWrappedCFException(h);
2642 >
2643 >        assertEquals(2, e.count.get());
2644      }
2645  
2646      /**
2647       * thenAcceptBothAsync result completes exceptionally if either source cancelled
2648       */
2649      public void testThenAcceptBothAsync4E() {
2650 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2651 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2652 <        AddAction r = new AddAction();
2653 <        CompletableFuture<Void> g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2654 <        assertTrue(f.cancel(true));
2655 <        f2.complete(two);
2656 <        checkCompletedWithWrappedCancellationException(g);
2650 >        CompletableFuture<Integer> f, g;
2651 >        CompletableFuture<Void> h;
2652 >        SubtractAction r;
2653 >        ThreadExecutor e = new ThreadExecutor();
2654 >
2655 >        f = new CompletableFuture<>();
2656 >        g = new CompletableFuture<>();
2657 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2658 >        assertTrue(f.cancel(true));
2659 >        checkIncomplete(h);
2660 >        g.complete(1);
2661 >        checkCompletedWithWrappedCancellationException(h);
2662 >
2663 >        f = new CompletableFuture<>();
2664 >        g = new CompletableFuture<>();
2665 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2666 >        assertTrue(g.cancel(true));
2667 >        checkIncomplete(h);
2668 >        f.complete(3);
2669 >        checkCompletedWithWrappedCancellationException(h);
2670 >
2671 >        f = new CompletableFuture<>();
2672 >        g = new CompletableFuture<>();
2673 >        f.complete(3);
2674 >        assertTrue(g.cancel(true));
2675 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2676 >        checkCompletedWithWrappedCancellationException(h);
2677 >
2678 >        f = new CompletableFuture<>();
2679 >        g = new CompletableFuture<>();
2680 >        assertTrue(f.cancel(true));
2681 >        g.complete(3);
2682 >        h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e);
2683 >        checkCompletedWithWrappedCancellationException(h);
2684  
2685 <        r = new AddAction();
1999 <        f = new CompletableFuture<Integer>();
2000 <        f2 = new CompletableFuture<Integer>();
2001 <        g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor());
2002 <        f.complete(one);
2003 <        assertTrue(f2.cancel(true));
2004 <        checkCompletedWithWrappedCancellationException(g);
2005 <    }
2006 <
2007 <    /**
2008 <     * runAfterBothAsync result completes normally after normal
2009 <     * completion of sources
2010 <     */
2011 <    public void testRunAfterBothAsyncE() {
2012 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2013 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2014 <        Noop r = new Noop();
2015 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2016 <        f.complete(one);
2017 <        checkIncomplete(g);
2018 <        f2.complete(two);
2019 <        checkCompletedNormally(g, null);
2020 <        assertTrue(r.ran);
2021 <    }
2022 <
2023 <    /**
2024 <     * runAfterBothAsync result completes exceptionally after exceptional
2025 <     * completion of source
2026 <     */
2027 <    public void testRunAfterBothAsync2E() {
2028 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2029 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2030 <        Noop r = new Noop();
2031 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2032 <        f.completeExceptionally(new CFException());
2033 <        f2.complete(two);
2034 <        checkCompletedWithWrappedCFException(g);
2035 <
2036 <        r = new Noop();
2037 <        f = new CompletableFuture<Integer>();
2038 <        f2 = new CompletableFuture<Integer>();
2039 <        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2040 <        f.complete(one);
2041 <        f2.completeExceptionally(new CFException());
2042 <        checkCompletedWithWrappedCFException(g);
2043 <    }
2044 <
2045 <    /**
2046 <     * runAfterBothAsync result completes exceptionally if action does
2047 <     */
2048 <    public void testRunAfterBothAsync3E() {
2049 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2050 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2051 <        FailingNoop r = new FailingNoop();
2052 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2053 <        f.complete(one);
2054 <        checkIncomplete(g);
2055 <        f2.complete(two);
2056 <        checkCompletedWithWrappedCFException(g);
2057 <    }
2058 <
2059 <    /**
2060 <     * runAfterBothAsync result completes exceptionally if either source cancelled
2061 <     */
2062 <    public void testRunAfterBothAsync4E() {
2063 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2064 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2065 <        Noop r = new Noop();
2066 <        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2067 <        assertTrue(f.cancel(true));
2068 <        f2.complete(two);
2069 <        checkCompletedWithWrappedCancellationException(g);
2070 <
2071 <        r = new Noop();
2072 <        f = new CompletableFuture<Integer>();
2073 <        f2 = new CompletableFuture<Integer>();
2074 <        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2075 <        f.complete(one);
2076 <        assertTrue(f2.cancel(true));
2077 <        checkCompletedWithWrappedCancellationException(g);
2685 >        assertEquals(0, e.count.get());
2686      }
2687  
2688      /**
# Line 2082 | Line 2690 | public class CompletableFutureTest exten
2690       * completion of sources
2691       */
2692      public void testApplyToEitherAsyncE() {
2693 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2694 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2693 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2694 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2695          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2696          f.complete(one);
2697          checkCompletedNormally(g, two);
2698  
2699 <        f = new CompletableFuture<Integer>();
2699 >        f = new CompletableFuture<>();
2700          f.complete(one);
2701 <        f2 = new CompletableFuture<Integer>();
2701 >        f2 = new CompletableFuture<>();
2702          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2703          checkCompletedNormally(g, two);
2704      }
# Line 2100 | Line 2708 | public class CompletableFutureTest exten
2708       * completion of source
2709       */
2710      public void testApplyToEitherAsync2E() {
2711 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2712 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2711 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2712 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2713          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2714          f.completeExceptionally(new CFException());
2715          checkCompletedWithWrappedCFException(g);
2716  
2717 <        f = new CompletableFuture<Integer>();
2718 <        f2 = new CompletableFuture<Integer>();
2717 >        f = new CompletableFuture<>();
2718 >        f2 = new CompletableFuture<>();
2719          f2.completeExceptionally(new CFException());
2720          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2721          f.complete(one);
# Line 2118 | Line 2726 | public class CompletableFutureTest exten
2726       * applyToEitherAsync result completes exceptionally if action does
2727       */
2728      public void testApplyToEitherAsync3E() {
2729 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2730 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2729 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2730 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2731          FailingFunction r = new FailingFunction();
2732          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2733          f.complete(one);
# Line 2130 | Line 2738 | public class CompletableFutureTest exten
2738       * applyToEitherAsync result completes exceptionally if either source cancelled
2739       */
2740      public void testApplyToEitherAsync4E() {
2741 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2742 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2741 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2742 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2743          CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2744          assertTrue(f.cancel(true));
2745          checkCompletedWithWrappedCancellationException(g);
2746  
2747 <        f = new CompletableFuture<Integer>();
2748 <        f2 = new CompletableFuture<Integer>();
2747 >        f = new CompletableFuture<>();
2748 >        f2 = new CompletableFuture<>();
2749          assertTrue(f2.cancel(true));
2750          g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2751          checkCompletedWithWrappedCancellationException(g);
# Line 2148 | Line 2756 | public class CompletableFutureTest exten
2756       * completion of sources
2757       */
2758      public void testAcceptEitherAsyncE() {
2759 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2760 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2759 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2760 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2761          IncAction r = new IncAction();
2762          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2763          f.complete(one);
# Line 2157 | Line 2765 | public class CompletableFutureTest exten
2765          assertEquals(r.value, 2);
2766  
2767          r = new IncAction();
2768 <        f = new CompletableFuture<Integer>();
2768 >        f = new CompletableFuture<>();
2769          f.complete(one);
2770 <        f2 = new CompletableFuture<Integer>();
2770 >        f2 = new CompletableFuture<>();
2771          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2772          checkCompletedNormally(g, null);
2773          assertEquals(r.value, 2);
# Line 2170 | Line 2778 | public class CompletableFutureTest exten
2778       * completion of source
2779       */
2780      public void testAcceptEitherAsync2E() {
2781 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2782 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2781 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2782 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2783          IncAction r = new IncAction();
2784          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2785          f.completeExceptionally(new CFException());
2786          checkCompletedWithWrappedCFException(g);
2787  
2788          r = new IncAction();
2789 <        f = new CompletableFuture<Integer>();
2790 <        f2 = new CompletableFuture<Integer>();
2789 >        f = new CompletableFuture<>();
2790 >        f2 = new CompletableFuture<>();
2791          f2.completeExceptionally(new CFException());
2792          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2793          f.complete(one);
# Line 2190 | Line 2798 | public class CompletableFutureTest exten
2798       * acceptEitherAsync result completes exceptionally if action does
2799       */
2800      public void testAcceptEitherAsync3E() {
2801 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2802 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2801 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2802 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2803          FailingConsumer r = new FailingConsumer();
2804          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2805          f.complete(one);
# Line 2203 | Line 2811 | public class CompletableFutureTest exten
2811       * source cancelled
2812       */
2813      public void testAcceptEitherAsync4E() {
2814 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2815 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2814 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2815 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2816          IncAction r = new IncAction();
2817          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2818          assertTrue(f.cancel(true));
2819          checkCompletedWithWrappedCancellationException(g);
2820  
2821          r = new IncAction();
2822 <        f = new CompletableFuture<Integer>();
2823 <        f2 = new CompletableFuture<Integer>();
2822 >        f = new CompletableFuture<>();
2823 >        f2 = new CompletableFuture<>();
2824          assertTrue(f2.cancel(true));
2825          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2826          checkCompletedWithWrappedCancellationException(g);
# Line 2223 | Line 2831 | public class CompletableFutureTest exten
2831       * completion of sources
2832       */
2833      public void testRunAfterEitherAsyncE() {
2834 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2835 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2834 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2835 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2836          Noop r = new Noop();
2837          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2838          f.complete(one);
# Line 2232 | Line 2840 | public class CompletableFutureTest exten
2840          assertTrue(r.ran);
2841  
2842          r = new Noop();
2843 <        f = new CompletableFuture<Integer>();
2843 >        f = new CompletableFuture<>();
2844          f.complete(one);
2845 <        f2 = new CompletableFuture<Integer>();
2845 >        f2 = new CompletableFuture<>();
2846          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2847          checkCompletedNormally(g, null);
2848          assertTrue(r.ran);
# Line 2245 | Line 2853 | public class CompletableFutureTest exten
2853       * completion of source
2854       */
2855      public void testRunAfterEitherAsync2E() {
2856 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2857 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2856 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2857 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2858          Noop r = new Noop();
2859          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2860          f.completeExceptionally(new CFException());
2861          checkCompletedWithWrappedCFException(g);
2862  
2863          r = new Noop();
2864 <        f = new CompletableFuture<Integer>();
2865 <        f2 = new CompletableFuture<Integer>();
2864 >        f = new CompletableFuture<>();
2865 >        f2 = new CompletableFuture<>();
2866          f2.completeExceptionally(new CFException());
2867          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2868          f.complete(one);
# Line 2265 | Line 2873 | public class CompletableFutureTest exten
2873       * runAfterEitherAsync result completes exceptionally if action does
2874       */
2875      public void testRunAfterEitherAsync3E() {
2876 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2877 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2876 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2877 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2878          FailingNoop r = new FailingNoop();
2879          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2880          f.complete(one);
# Line 2278 | Line 2886 | public class CompletableFutureTest exten
2886       * source cancelled
2887       */
2888      public void testRunAfterEitherAsync4E() {
2889 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2890 <        CompletableFuture<Integer> f2 = new CompletableFuture<Integer>();
2889 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2890 >        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2891          Noop r = new Noop();
2892          CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2893          assertTrue(f.cancel(true));
2894          checkCompletedWithWrappedCancellationException(g);
2895  
2896          r = new Noop();
2897 <        f = new CompletableFuture<Integer>();
2898 <        f2 = new CompletableFuture<Integer>();
2897 >        f = new CompletableFuture<>();
2898 >        f2 = new CompletableFuture<>();
2899          assertTrue(f2.cancel(true));
2900          g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2901          checkCompletedWithWrappedCancellationException(g);
# Line 2298 | Line 2906 | public class CompletableFutureTest exten
2906       * completion of source
2907       */
2908      public void testThenComposeAsyncE() {
2909 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2909 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2910          CompletableFutureInc r = new CompletableFutureInc();
2911          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2912          f.complete(one);
# Line 2310 | Line 2918 | public class CompletableFutureTest exten
2918       * exceptional completion of source
2919       */
2920      public void testThenComposeAsync2E() {
2921 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2921 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2922          CompletableFutureInc r = new CompletableFutureInc();
2923          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2924          f.completeExceptionally(new CFException());
# Line 2321 | Line 2929 | public class CompletableFutureTest exten
2929       * thenComposeAsync result completes exceptionally if action does
2930       */
2931      public void testThenComposeAsync3E() {
2932 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2932 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2933          FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
2934          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2935          f.complete(one);
# Line 2332 | Line 2940 | public class CompletableFutureTest exten
2940       * thenComposeAsync result completes exceptionally if source cancelled
2941       */
2942      public void testThenComposeAsync4E() {
2943 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
2943 >        CompletableFuture<Integer> f = new CompletableFuture<>();
2944          CompletableFutureInc r = new CompletableFutureInc();
2945          CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
2946          assertTrue(f.cancel(true));
# Line 2346 | Line 2954 | public class CompletableFutureTest exten
2954       * with the value null
2955       */
2956      public void testAllOf_empty() throws Exception {
2957 <        CompletableFuture<?> f = CompletableFuture.allOf();
2957 >        CompletableFuture<Void> f = CompletableFuture.allOf();
2958          checkCompletedNormally(f, null);
2959      }
2960  
2961      /**
2962 <     * allOf returns a future completed when all components complete
2962 >     * allOf returns a future completed normally with the value null
2963 >     * when all components complete normally
2964       */
2965 <    public void testAllOf() throws Exception {
2965 >    public void testAllOf_normal() throws Exception {
2966          for (int k = 1; k < 20; ++k) {
2967 <            CompletableFuture[] fs = new CompletableFuture[k];
2967 >            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2968              for (int i = 0; i < k; ++i)
2969 <                fs[i] = new CompletableFuture<Integer>();
2970 <            CompletableFuture<?> f = CompletableFuture.allOf(fs);
2969 >                fs[i] = new CompletableFuture<>();
2970 >            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2971              for (int i = 0; i < k; ++i) {
2972                  checkIncomplete(f);
2973 +                checkIncomplete(CompletableFuture.allOf(fs));
2974                  fs[i].complete(one);
2975              }
2976 <            assertTrue(f.isDone());
2977 <            assertFalse(f.isCancelled());
2976 >            checkCompletedNormally(f, null);
2977 >            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2978          }
2979      }
2980  
# Line 2372 | Line 2982 | public class CompletableFutureTest exten
2982       * anyOf(no component futures) returns an incomplete future
2983       */
2984      public void testAnyOf_empty() throws Exception {
2985 <        CompletableFuture<?> f = CompletableFuture.anyOf();
2985 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
2986          checkIncomplete(f);
2987      }
2988  
2989      /**
2990 <     * allOf returns a future completed when any components complete
2990 >     * anyOf returns a future completed normally with a value when
2991 >     * a component future does
2992       */
2993 <    public void testAnyOf() throws Exception {
2994 <        for (int k = 1; k < 20; ++k) {
2993 >    public void testAnyOf_normal() throws Exception {
2994 >        for (int k = 0; k < 10; ++k) {
2995              CompletableFuture[] fs = new CompletableFuture[k];
2996              for (int i = 0; i < k; ++i)
2997 <                fs[i] = new CompletableFuture<Integer>();
2998 <            CompletableFuture<?> f = CompletableFuture.anyOf(fs);
2997 >                fs[i] = new CompletableFuture<>();
2998 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2999              checkIncomplete(f);
3000              for (int i = 0; i < k; ++i) {
3001                  fs[i].complete(one);
3002 <                assertTrue(f.isDone());
3002 >                checkCompletedNormally(f, one);
3003 >                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
3004 >            }
3005 >        }
3006 >    }
3007 >
3008 >    /**
3009 >     * anyOf result completes exceptionally when any component does.
3010 >     */
3011 >    public void testAnyOf_exceptional() throws Exception {
3012 >        for (int k = 0; k < 10; ++k) {
3013 >            CompletableFuture[] fs = new CompletableFuture[k];
3014 >            for (int i = 0; i < k; ++i)
3015 >                fs[i] = new CompletableFuture<>();
3016 >            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
3017 >            checkIncomplete(f);
3018 >            for (int i = 0; i < k; ++i) {
3019 >                fs[i].completeExceptionally(new CFException());
3020 >                checkCompletedWithWrappedCFException(f);
3021 >                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
3022              }
3023          }
3024      }
# Line 2397 | Line 3027 | public class CompletableFutureTest exten
3027       * Completion methods throw NullPointerException with null arguments
3028       */
3029      public void testNPE() {
3030 <        CompletableFuture<Integer> f = new CompletableFuture<Integer>();
3031 <        CompletableFuture<Integer> g = new CompletableFuture<Integer>();
3032 <        CompletableFuture h;
3033 <        try { h = f.thenApply(null); } catch (NullPointerException ok) {}
3034 <        try { h = f.thenAccept(null); } catch (NullPointerException ok) {}
3035 <        try { h = f.thenRun(null); } catch (NullPointerException ok) {}
3036 <        try { h = f.thenCombine(g, null); } catch (NullPointerException ok) {}
3037 <        try { h = f.thenCombine(null, null); } catch (NullPointerException ok) {}
3038 <        try { h = f.applyToEither(g, null); } catch (NullPointerException ok) {}
3039 <        try { h = f.applyToEither(null, null); } catch (NullPointerException ok) {}
3040 <        try { h = f.thenAcceptBoth(g, null); } catch (NullPointerException ok) {}
3041 <        try { h = f.thenAcceptBoth(null, null); } catch (NullPointerException ok) {}
3042 <        try { h = f.runAfterEither(g, null); } catch (NullPointerException ok) {}
3043 <        try { h = f.runAfterEither(null, null); } catch (NullPointerException ok) {}
3044 <        try { h = f.runAfterBoth(g, null); } catch (NullPointerException ok) {}
3045 <        try { h = f.runAfterBoth(null, null); } catch (NullPointerException ok) {}
3046 <        try { h = f.exceptionally(null); } catch (NullPointerException ok) {}
3047 <        try { h = f.handle(null); } catch (NullPointerException ok) {}
3048 <        try { h = f.thenCompose(null); } catch (NullPointerException ok) {}
3049 <
3050 <        try { h = f.thenApplyAsync(null); } catch (NullPointerException ok) {}
3051 <        try { h = f.thenAcceptAsync(null); } catch (NullPointerException ok) {}
3052 <        try { h = f.thenRunAsync(null); } catch (NullPointerException ok) {}
3053 <        try { h = f.thenCombineAsync(g, null); } catch (NullPointerException ok) {}
3054 <        try { h = f.thenCombineAsync(null, null); } catch (NullPointerException ok) {}
3055 <        try { h = f.applyToEitherAsync(g, null); } catch (NullPointerException ok) {}
3056 <        try { h = f.applyToEitherAsync(null, null); } catch (NullPointerException ok) {}
3057 <        try { h = f.thenAcceptBothAsync(g, null); } catch (NullPointerException ok) {}
3058 <        try { h = f.thenAcceptBothAsync(null, null); } catch (NullPointerException ok) {}
3059 <        try { h = f.runAfterEitherAsync(g, null); } catch (NullPointerException ok) {}
3060 <        try { h = f.runAfterEitherAsync(null, null); } catch (NullPointerException ok) {}
3061 <        try { h = f.runAfterBothAsync(g, null); } catch (NullPointerException ok) {}
3062 <        try { h = f.runAfterBothAsync(null, null); } catch (NullPointerException ok) {}
3030 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3031 >        CompletableFuture<Integer> g = new CompletableFuture<>();
3032 >        CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null;
3033 >        CompletableFuture<?> h;
3034 >        ThreadExecutor exec = new ThreadExecutor();
3035 >
3036 >        Runnable[] throwingActions = {
3037 >            () -> CompletableFuture.supplyAsync(null),
3038 >            () -> CompletableFuture.supplyAsync(null, exec),
3039 >            () -> CompletableFuture.supplyAsync(supplyOne, null),
3040 >
3041 >            () -> CompletableFuture.runAsync(null),
3042 >            () -> CompletableFuture.runAsync(null, exec),
3043 >            () -> CompletableFuture.runAsync(() -> {}, null),
3044 >
3045 >            () -> f.completeExceptionally(null),
3046 >
3047 >            () -> f.thenApply(null),
3048 >            () -> f.thenApplyAsync(null),
3049 >            () -> f.thenApplyAsync((x) -> x, null),
3050 >            () -> f.thenApplyAsync(null, exec),
3051 >
3052 >            () -> f.thenAccept(null),
3053 >            () -> f.thenAcceptAsync(null),
3054 >            () -> f.thenAcceptAsync((x) -> {} , null),
3055 >            () -> f.thenAcceptAsync(null, exec),
3056 >
3057 >            () -> f.thenRun(null),
3058 >            () -> f.thenRunAsync(null),
3059 >            () -> f.thenRunAsync(() -> {} , null),
3060 >            () -> f.thenRunAsync(null, exec),
3061 >
3062 >            () -> f.thenCombine(g, null),
3063 >            () -> f.thenCombineAsync(g, null),
3064 >            () -> f.thenCombineAsync(g, null, exec),
3065 >            () -> f.thenCombine(nullFuture, (x, y) -> x),
3066 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x),
3067 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec),
3068 >            () -> f.thenCombineAsync(g, (x, y) -> x, null),
3069 >
3070 >            () -> f.thenAcceptBoth(g, null),
3071 >            () -> f.thenAcceptBothAsync(g, null),
3072 >            () -> f.thenAcceptBothAsync(g, null, exec),
3073 >            () -> f.thenAcceptBoth(nullFuture, (x, y) -> {}),
3074 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}),
3075 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec),
3076 >            () -> f.thenAcceptBothAsync(g, (x, y) -> {}, null),
3077 >
3078 >            () -> f.runAfterBoth(g, null),
3079 >            () -> f.runAfterBothAsync(g, null),
3080 >            () -> f.runAfterBothAsync(g, null, exec),
3081 >            () -> f.runAfterBoth(nullFuture, () -> {}),
3082 >            () -> f.runAfterBothAsync(nullFuture, () -> {}),
3083 >            () -> f.runAfterBothAsync(nullFuture, () -> {}, exec),
3084 >            () -> f.runAfterBothAsync(g, () -> {}, null),
3085 >
3086 >            () -> f.applyToEither(g, null),
3087 >            () -> f.applyToEitherAsync(g, null),
3088 >            () -> f.applyToEitherAsync(g, null, exec),
3089 >            () -> f.applyToEither(nullFuture, (x) -> x),
3090 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3091 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3092 >            () -> f.applyToEitherAsync(g, (x) -> x, null),
3093 >
3094 >            () -> f.acceptEither(g, null),
3095 >            () -> f.acceptEitherAsync(g, null),
3096 >            () -> f.acceptEitherAsync(g, null, exec),
3097 >            () -> f.acceptEither(nullFuture, (x) -> {}),
3098 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3099 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3100 >            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3101 >
3102 >            () -> f.runAfterEither(g, null),
3103 >            () -> f.runAfterEitherAsync(g, null),
3104 >            () -> f.runAfterEitherAsync(g, null, exec),
3105 >            () -> f.runAfterEither(nullFuture, () -> {}),
3106 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}),
3107 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}, exec),
3108 >            () -> f.runAfterEitherAsync(g, () -> {}, null),
3109 >
3110 >            () -> f.thenCompose(null),
3111 >            () -> f.thenComposeAsync(null),
3112 >            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
3113 >            () -> f.thenComposeAsync(null, exec),
3114 >
3115 >            () -> f.exceptionally(null),
3116 >
3117 >            () -> f.handle(null),
3118 >
3119 >            () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3120 >            () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3121 >            () -> CompletableFuture.allOf(f, null),
3122 >            () -> CompletableFuture.allOf(null, f),
3123 >
3124 >            () -> CompletableFuture.anyOf((CompletableFuture<?>)null),
3125 >            () -> CompletableFuture.anyOf((CompletableFuture<?>[])null),
3126 >            () -> CompletableFuture.anyOf(f, null),
3127 >            () -> CompletableFuture.anyOf(null, f),
3128 >
3129 >            () -> f.obtrudeException(null),
3130 >        };
3131 >
3132 >        assertThrows(NullPointerException.class, throwingActions);
3133 >        assertEquals(0, exec.count.get());
3134 >    }
3135 >
3136 >    /**
3137 >     * toCompletableFuture returns this CompletableFuture.
3138 >     */
3139 >    public void testToCompletableFuture() {
3140 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3141 >        assertSame(f, f.toCompletableFuture());
3142 >    }
3143 >
3144 >    /**
3145 >     * whenComplete action executes on normal completion, propagating
3146 >     * source result.
3147 >     */
3148 >    public void testWhenComplete1() {
3149 >        final AtomicInteger a = new AtomicInteger();
3150 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3151 >        CompletableFuture<Integer> g =
3152 >            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3153 >        f.complete(three);
3154 >        checkCompletedNormally(f, three);
3155 >        checkCompletedNormally(g, three);
3156 >        assertEquals(a.get(), 1);
3157 >    }
3158 >
3159 >    /**
3160 >     * whenComplete action executes on exceptional completion, propagating
3161 >     * source result.
3162 >     */
3163 >    public void testWhenComplete2() {
3164 >        final AtomicInteger a = new AtomicInteger();
3165 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3166 >        CompletableFuture<Integer> g =
3167 >            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3168 >        f.completeExceptionally(new CFException());
3169 >        assertTrue(f.isCompletedExceptionally());
3170 >        assertTrue(g.isCompletedExceptionally());
3171 >        assertEquals(a.get(), 1);
3172 >    }
3173 >
3174 >    /**
3175 >     * If a whenComplete action throws an exception when triggered by
3176 >     * a normal completion, it completes exceptionally
3177 >     */
3178 >    public void testWhenComplete3() {
3179 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3180 >        CompletableFuture<Integer> g =
3181 >            f.whenComplete((Integer x, Throwable t) ->
3182 >                           { throw new CFException(); } );
3183 >        f.complete(three);
3184 >        checkCompletedNormally(f, three);
3185 >        assertTrue(g.isCompletedExceptionally());
3186 >        checkCompletedWithWrappedCFException(g);
3187 >    }
3188 >
3189 >    /**
3190 >     * whenCompleteAsync action executes on normal completion, propagating
3191 >     * source result.
3192 >     */
3193 >    public void testWhenCompleteAsync1() {
3194 >        final AtomicInteger a = new AtomicInteger();
3195 >        CompletableFuture<Integer> f = new CompletableFuture<>();
3196 >        CompletableFuture<Integer> g =
3197 >            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3198 >        f.complete(three);
3199 >        checkCompletedNormally(f, three);
3200 >        checkCompletedNormally(g, three);
3201 >        assertEquals(a.get(), 1);
3202 >    }
3203  
3204 +    /**
3205 +     * whenCompleteAsync action executes on exceptional completion, propagating
3206 +     * source result.
3207 +     */
3208 +    public void testWhenCompleteAsync2() {
3209 +        final AtomicInteger a = new AtomicInteger();
3210 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3211 +        CompletableFuture<Integer> g =
3212 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3213 +        f.completeExceptionally(new CFException());
3214 +        checkCompletedWithWrappedCFException(f);
3215 +        checkCompletedWithWrappedCFException(g);
3216 +    }
3217 +
3218 +    /**
3219 +     * If a whenCompleteAsync action throws an exception when
3220 +     * triggered by a normal completion, it completes exceptionally
3221 +     */
3222 +    public void testWhenCompleteAsync3() {
3223 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3224 +        CompletableFuture<Integer> g =
3225 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3226 +                           { throw new CFException(); } );
3227 +        f.complete(three);
3228 +        checkCompletedNormally(f, three);
3229 +        checkCompletedWithWrappedCFException(g);
3230 +    }
3231 +
3232 +    /**
3233 +     * whenCompleteAsync action executes on normal completion, propagating
3234 +     * source result.
3235 +     */
3236 +    public void testWhenCompleteAsync1e() {
3237 +        final AtomicInteger a = new AtomicInteger();
3238 +        ThreadExecutor exec = new ThreadExecutor();
3239 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3240 +        CompletableFuture<Integer> g =
3241 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3242 +                                exec);
3243 +        f.complete(three);
3244 +        checkCompletedNormally(f, three);
3245 +        checkCompletedNormally(g, three);
3246 +        assertEquals(a.get(), 1);
3247 +    }
3248 +
3249 +    /**
3250 +     * whenCompleteAsync action executes on exceptional completion, propagating
3251 +     * source result.
3252 +     */
3253 +    public void testWhenCompleteAsync2e() {
3254 +        final AtomicInteger a = new AtomicInteger();
3255 +        ThreadExecutor exec = new ThreadExecutor();
3256 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3257 +        CompletableFuture<Integer> g =
3258 +            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3259 +                                exec);
3260 +        f.completeExceptionally(new CFException());
3261 +        checkCompletedWithWrappedCFException(f);
3262 +        checkCompletedWithWrappedCFException(g);
3263 +    }
3264 +
3265 +    /**
3266 +     * If a whenCompleteAsync action throws an exception when triggered
3267 +     * by a normal completion, it completes exceptionally
3268 +     */
3269 +    public void testWhenCompleteAsync3e() {
3270 +        ThreadExecutor exec = new ThreadExecutor();
3271 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3272 +        CompletableFuture<Integer> g =
3273 +            f.whenCompleteAsync((Integer x, Throwable t) ->
3274 +                                { throw new CFException(); },
3275 +                                exec);
3276 +        f.complete(three);
3277 +        checkCompletedNormally(f, three);
3278 +        checkCompletedWithWrappedCFException(g);
3279 +    }
3280 +
3281 +    /**
3282 +     * handleAsync action completes normally with function value on
3283 +     * either normal or exceptional completion of source
3284 +     */
3285 +    public void testHandleAsync() {
3286 +        CompletableFuture<Integer> f, g;
3287 +        IntegerHandler r;
3288 +
3289 +        f = new CompletableFuture<>();
3290 +        g = f.handleAsync(r = new IntegerHandler());
3291 +        assertFalse(r.ran);
3292 +        f.completeExceptionally(new CFException());
3293 +        checkCompletedWithWrappedCFException(f);
3294 +        checkCompletedNormally(g, three);
3295 +        assertTrue(r.ran);
3296 +
3297 +        f = new CompletableFuture<>();
3298 +        g = f.handleAsync(r = new IntegerHandler());
3299 +        assertFalse(r.ran);
3300 +        f.completeExceptionally(new CFException());
3301 +        checkCompletedWithWrappedCFException(f);
3302 +        checkCompletedNormally(g, three);
3303 +        assertTrue(r.ran);
3304 +
3305 +        f = new CompletableFuture<>();
3306 +        g = f.handleAsync(r = new IntegerHandler());
3307 +        assertFalse(r.ran);
3308 +        f.complete(one);
3309 +        checkCompletedNormally(f, one);
3310 +        checkCompletedNormally(g, two);
3311 +        assertTrue(r.ran);
3312 +
3313 +        f = new CompletableFuture<>();
3314 +        g = f.handleAsync(r = new IntegerHandler());
3315 +        assertFalse(r.ran);
3316 +        f.complete(one);
3317 +        checkCompletedNormally(f, one);
3318 +        checkCompletedNormally(g, two);
3319 +        assertTrue(r.ran);
3320      }
3321  
3322 +    /**
3323 +     * handleAsync action with Executor completes normally with
3324 +     * function value on either normal or exceptional completion of
3325 +     * source
3326 +     */
3327 +    public void testHandleAsync2() {
3328 +        CompletableFuture<Integer> f, g;
3329 +        ThreadExecutor exec = new ThreadExecutor();
3330 +        IntegerHandler r;
3331 +
3332 +        f = new CompletableFuture<>();
3333 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3334 +        assertFalse(r.ran);
3335 +        f.completeExceptionally(new CFException());
3336 +        checkCompletedWithWrappedCFException(f);
3337 +        checkCompletedNormally(g, three);
3338 +        assertTrue(r.ran);
3339 +
3340 +        f = new CompletableFuture<>();
3341 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3342 +        assertFalse(r.ran);
3343 +        f.completeExceptionally(new CFException());
3344 +        checkCompletedWithWrappedCFException(f);
3345 +        checkCompletedNormally(g, three);
3346 +        assertTrue(r.ran);
3347 +
3348 +        f = new CompletableFuture<>();
3349 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3350 +        assertFalse(r.ran);
3351 +        f.complete(one);
3352 +        checkCompletedNormally(f, one);
3353 +        checkCompletedNormally(g, two);
3354 +        assertTrue(r.ran);
3355 +
3356 +        f = new CompletableFuture<>();
3357 +        g = f.handleAsync(r = new IntegerHandler(), exec);
3358 +        assertFalse(r.ran);
3359 +        f.complete(one);
3360 +        checkCompletedNormally(f, one);
3361 +        checkCompletedNormally(g, two);
3362 +        assertTrue(r.ran);
3363 +    }
3364  
3365   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines