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.47 by jsr166, Mon Jun 2 18:21:34 2014 UTC vs.
Revision 1.61 by jsr166, Wed Jun 4 04:34:49 2014 UTC

# Line 17 | Line 17 | import java.util.concurrent.Future;
17   import java.util.concurrent.CompletableFuture;
18   import java.util.concurrent.CompletionException;
19   import java.util.concurrent.CompletionStage;
20 + import java.util.concurrent.ForkJoinPool;
21 + import java.util.concurrent.ForkJoinTask;
22   import java.util.concurrent.TimeoutException;
23   import java.util.concurrent.atomic.AtomicInteger;
24   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 282 | Line 284 | public class CompletableFutureTest exten
284      public void testGetNumberOfDependents() {
285          CompletableFuture<Integer> f = new CompletableFuture<>();
286          assertEquals(0, f.getNumberOfDependents());
287 <        CompletableFuture g = f.thenRun(new Noop());
287 >        CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT));
288          assertEquals(1, f.getNumberOfDependents());
289          assertEquals(0, g.getNumberOfDependents());
290 <        CompletableFuture h = f.thenRun(new Noop());
290 >        CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT));
291          assertEquals(2, f.getNumberOfDependents());
292          f.complete(1);
293          checkCompletedNormally(g, null);
# Line 318 | Line 320 | public class CompletableFutureTest exten
320          checkCompletedNormally(f, "test");
321      }
322  
323 <    // Choose non-commutative actions for better coverage
324 <
325 <    // A non-commutative function that handles and produces null values as well.
326 <    static Integer subtract(Integer x, Integer y) {
327 <        return (x == null && y == null) ? null :
328 <            ((x == null) ? 42 : x.intValue())
329 <            - ((y == null) ? 99 : y.intValue());
323 >    static final class IntegerSupplier implements Supplier<Integer> {
324 >        final ExecutionMode m;
325 >        int invocationCount = 0;
326 >        final Integer value;
327 >        IntegerSupplier(ExecutionMode m, Integer value) {
328 >            this.m = m;
329 >            this.value = value;
330 >        }
331 >        public Integer get() {
332 >            m.checkExecutionMode();
333 >            invocationCount++;
334 >            return value;
335 >        }
336      }
337  
338      // A function that handles and produces null values as well.
# Line 332 | Line 340 | public class CompletableFutureTest exten
340          return (x == null) ? null : x + 1;
341      }
342  
335    static final Supplier<Integer> supplyOne =
336        () -> Integer.valueOf(1);
337    static final Function<Integer, Integer> inc =
338        (Integer x) -> Integer.valueOf(x.intValue() + 1);
339    static final BiFunction<Integer, Integer, Integer> subtract =
340        (Integer x, Integer y) -> subtract(x, y);
343      static final class IncAction implements Consumer<Integer> {
344          int invocationCount = 0;
345          Integer value;
# Line 347 | Line 349 | public class CompletableFutureTest exten
349          }
350      }
351      static final class IncFunction implements Function<Integer,Integer> {
352 +        final ExecutionMode m;
353          int invocationCount = 0;
354          Integer value;
355 +        IncFunction(ExecutionMode m) { this.m = m; }
356          public Integer apply(Integer x) {
357 +            m.checkExecutionMode();
358              invocationCount++;
359              return value = inc(x);
360          }
361      }
362 +
363 +    // Choose non-commutative actions for better coverage
364 +    // A non-commutative function that handles and produces null values as well.
365 +    static Integer subtract(Integer x, Integer y) {
366 +        return (x == null && y == null) ? null :
367 +            ((x == null) ? 42 : x.intValue())
368 +            - ((y == null) ? 99 : y.intValue());
369 +    }
370 +
371      static final class SubtractAction implements BiConsumer<Integer, Integer> {
372 +        final ExecutionMode m;
373          int invocationCount = 0;
374          Integer value;
375          // Check this action was invoked exactly once when result is computed.
376 +        SubtractAction(ExecutionMode m) { this.m = m; }
377          public void accept(Integer x, Integer y) {
378 +            m.checkExecutionMode();
379              invocationCount++;
380              value = subtract(x, y);
381          }
382      }
383      static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> {
384 +        final ExecutionMode m;
385          int invocationCount = 0;
386          Integer value;
387          // Check this action was invoked exactly once when result is computed.
388 +        SubtractFunction(ExecutionMode m) { this.m = m; }
389          public Integer apply(Integer x, Integer y) {
390 +            m.checkExecutionMode();
391              invocationCount++;
392              return value = subtract(x, y);
393          }
394      }
395 +
396      static final class Noop implements Runnable {
397 +        final ExecutionMode m;
398          int invocationCount = 0;
399 +        Noop(ExecutionMode m) { this.m = m; }
400          public void run() {
401 +            m.checkExecutionMode();
402              invocationCount++;
403          }
404      }
405  
406      static final class FailingSupplier implements Supplier<Integer> {
407 +        final ExecutionMode m;
408          int invocationCount = 0;
409 +        FailingSupplier(ExecutionMode m) { this.m = m; }
410          public Integer get() {
411 +            m.checkExecutionMode();
412              invocationCount++;
413              throw new CFException();
414          }
415      }
416      static final class FailingConsumer implements Consumer<Integer> {
417 +        final ExecutionMode m;
418          int invocationCount = 0;
419 +        FailingConsumer(ExecutionMode m) { this.m = m; }
420          public void accept(Integer x) {
421 +            m.checkExecutionMode();
422              invocationCount++;
423              throw new CFException();
424          }
425      }
426      static final class FailingBiConsumer implements BiConsumer<Integer, Integer> {
427 +        final ExecutionMode m;
428          int invocationCount = 0;
429 +        FailingBiConsumer(ExecutionMode m) { this.m = m; }
430          public void accept(Integer x, Integer y) {
431 +            m.checkExecutionMode();
432              invocationCount++;
433              throw new CFException();
434          }
435      }
436      static final class FailingFunction implements Function<Integer, Integer> {
437 +        final ExecutionMode m;
438          int invocationCount = 0;
439 +        FailingFunction(ExecutionMode m) { this.m = m; }
440          public Integer apply(Integer x) {
441 +            m.checkExecutionMode();
442              invocationCount++;
443              throw new CFException();
444          }
445      }
446      static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> {
447 +        final ExecutionMode m;
448          int invocationCount = 0;
449 +        FailingBiFunction(ExecutionMode m) { this.m = m; }
450          public Integer apply(Integer x, Integer y) {
451 +            m.checkExecutionMode();
452              invocationCount++;
453              throw new CFException();
454          }
455      }
456 <    static final class FailingNoop implements Runnable {
456 >    static final class FailingRunnable implements Runnable {
457 >        final ExecutionMode m;
458          int invocationCount = 0;
459 +        FailingRunnable(ExecutionMode m) { this.m = m; }
460          public void run() {
461 +            m.checkExecutionMode();
462              invocationCount++;
463              throw new CFException();
464          }
# Line 424 | Line 466 | public class CompletableFutureTest exten
466  
467      static final class CompletableFutureInc
468          implements Function<Integer, CompletableFuture<Integer>> {
469 +        final ExecutionMode m;
470          int invocationCount = 0;
471 +        CompletableFutureInc(ExecutionMode m) { this.m = m; }
472          public CompletableFuture<Integer> apply(Integer x) {
473 +            m.checkExecutionMode();
474              invocationCount++;
475              CompletableFuture<Integer> f = new CompletableFuture<>();
476              f.complete(inc(x));
# Line 435 | Line 480 | public class CompletableFutureTest exten
480  
481      static final class FailingCompletableFutureFunction
482          implements Function<Integer, CompletableFuture<Integer>> {
483 +        final ExecutionMode m;
484          int invocationCount = 0;
485 +        FailingCompletableFutureFunction(ExecutionMode m) { this.m = m; }
486          public CompletableFuture<Integer> apply(Integer x) {
487 +            m.checkExecutionMode();
488              invocationCount++;
489              throw new CFException();
490          }
# Line 444 | Line 492 | public class CompletableFutureTest exten
492  
493      // Used for explicit executor tests
494      static final class ThreadExecutor implements Executor {
495 <        AtomicInteger count = new AtomicInteger(0);
495 >        final AtomicInteger count = new AtomicInteger(0);
496 >        static final ThreadGroup tg = new ThreadGroup("ThreadExecutor");
497 >        static boolean startedCurrentThread() {
498 >            return Thread.currentThread().getThreadGroup() == tg;
499 >        }
500  
501          public void execute(Runnable r) {
502              count.getAndIncrement();
503 <            new Thread(r).start();
503 >            new Thread(tg, r).start();
504          }
505      }
506  
507      /**
508       * Permits the testing of parallel code for the 3 different
509 <     * execution modes without repeating all the testing code.
509 >     * execution modes without copy/pasting all the test methods.
510       */
511      enum ExecutionMode {
512          DEFAULT {
513 +            public void checkExecutionMode() {
514 +                assertFalse(ThreadExecutor.startedCurrentThread());
515 +                assertNull(ForkJoinTask.getPool());
516 +            }
517 +            public CompletableFuture<Void> runAsync(Runnable a) {
518 +                throw new UnsupportedOperationException();
519 +            }
520 +            public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) {
521 +                throw new UnsupportedOperationException();
522 +            }
523              public <T> CompletableFuture<Void> thenRun
524                  (CompletableFuture<T> f, Runnable a) {
525                  return f.thenRun(a);
# Line 521 | Line 583 | public class CompletableFutureTest exten
583              }
584          },
585  
586 <        DEFAULT_ASYNC {
586 >        ASYNC {
587 >            public void checkExecutionMode() {
588 >                assertSame(ForkJoinPool.commonPool(),
589 >                           ForkJoinTask.getPool());
590 >            }
591 >            public CompletableFuture<Void> runAsync(Runnable a) {
592 >                return CompletableFuture.runAsync(a);
593 >            }
594 >            public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) {
595 >                return CompletableFuture.supplyAsync(a);
596 >            }
597              public <T> CompletableFuture<Void> thenRun
598                  (CompletableFuture<T> f, Runnable a) {
599                  return f.thenRunAsync(a);
# Line 586 | Line 658 | public class CompletableFutureTest exten
658          },
659  
660          EXECUTOR {
661 +            public void checkExecutionMode() {
662 +                assertTrue(ThreadExecutor.startedCurrentThread());
663 +            }
664 +            public CompletableFuture<Void> runAsync(Runnable a) {
665 +                return CompletableFuture.runAsync(a, new ThreadExecutor());
666 +            }
667 +            public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) {
668 +                return CompletableFuture.supplyAsync(a, new ThreadExecutor());
669 +            }
670              public <T> CompletableFuture<Void> thenRun
671                  (CompletableFuture<T> f, Runnable a) {
672                  return f.thenRunAsync(a, new ThreadExecutor());
# Line 649 | Line 730 | public class CompletableFutureTest exten
730              }
731          };
732  
733 +        public abstract void checkExecutionMode();
734 +        public abstract CompletableFuture<Void> runAsync(Runnable a);
735 +        public abstract <U> CompletableFuture<U> supplyAsync(Supplier<U> a);
736          public abstract <T> CompletableFuture<Void> thenRun
737              (CompletableFuture<T> f, Runnable a);
738          public abstract <T> CompletableFuture<Void> thenAccept
# Line 727 | Line 811 | public class CompletableFutureTest exten
811          if (!createIncomplete) f.completeExceptionally(ex);
812          final CompletableFuture<Integer> g = f.exceptionally
813              ((Throwable t) -> {
814 +                ExecutionMode.DEFAULT.checkExecutionMode();
815                  threadAssertSame(t, ex);
816                  a.getAndIncrement();
817                  return v1;
# Line 748 | Line 833 | public class CompletableFutureTest exten
833          if (!createIncomplete) f.completeExceptionally(ex1);
834          final CompletableFuture<Integer> g = f.exceptionally
835              ((Throwable t) -> {
836 +                ExecutionMode.DEFAULT.checkExecutionMode();
837                  threadAssertSame(t, ex1);
838                  a.getAndIncrement();
839                  throw ex2;
# Line 773 | Line 859 | public class CompletableFutureTest exten
859          final CompletableFuture<Integer> g = m.handle
860              (f,
861               (Integer x, Throwable t) -> {
862 +                m.checkExecutionMode();
863                  threadAssertSame(x, v1);
864                  threadAssertNull(t);
865                  a.getAndIncrement();
# Line 801 | Line 888 | public class CompletableFutureTest exten
888          final CompletableFuture<Integer> g = m.handle
889              (f,
890               (Integer x, Throwable t) -> {
891 +                m.checkExecutionMode();
892                  threadAssertNull(x);
893                  threadAssertSame(t, ex);
894                  a.getAndIncrement();
# Line 829 | Line 917 | public class CompletableFutureTest exten
917          final CompletableFuture<Integer> g = m.handle
918              (f,
919               (Integer x, Throwable t) -> {
920 +                m.checkExecutionMode();
921                  threadAssertNull(x);
922                  threadAssertTrue(t instanceof CancellationException);
923                  a.getAndIncrement();
# Line 856 | Line 945 | public class CompletableFutureTest exten
945          final CompletableFuture<Integer> g = m.handle
946              (f,
947               (Integer x, Throwable t) -> {
948 +                m.checkExecutionMode();
949                  threadAssertNull(x);
950                  threadAssertSame(ex1, t);
951                  a.getAndIncrement();
# Line 880 | Line 970 | public class CompletableFutureTest exten
970          final CompletableFuture<Integer> g = m.handle
971              (f,
972               (Integer x, Throwable t) -> {
973 +                m.checkExecutionMode();
974                  threadAssertSame(x, v1);
975                  threadAssertNull(t);
976                  a.getAndIncrement();
# Line 895 | Line 986 | public class CompletableFutureTest exten
986      /**
987       * runAsync completes after running Runnable
988       */
989 <    public void testRunAsync() {
990 <        Noop r = new Noop();
991 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r);
989 >    public void testRunAsync_normalCompletion() {
990 >        ExecutionMode[] executionModes = {
991 >            ExecutionMode.ASYNC,
992 >            ExecutionMode.EXECUTOR,
993 >        };
994 >        for (ExecutionMode m : executionModes)
995 >    {
996 >        final Noop r = new Noop(m);
997 >        final CompletableFuture<Void> f = m.runAsync(r);
998          assertNull(f.join());
902        assertEquals(1, r.invocationCount);
999          checkCompletedNormally(f, null);
904    }
905
906    /**
907     * runAsync with executor completes after running Runnable
908     */
909    public void testRunAsync2() {
910        Noop r = new Noop();
911        ThreadExecutor exec = new ThreadExecutor();
912        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
913        assertNull(f.join());
1000          assertEquals(1, r.invocationCount);
1001 <        checkCompletedNormally(f, null);
916 <        assertEquals(1, exec.count.get());
917 <    }
1001 >    }}
1002  
1003      /**
1004       * failing runAsync completes exceptionally after running Runnable
1005       */
1006 <    public void testRunAsync3() {
1007 <        FailingNoop r = new FailingNoop();
1008 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r);
1006 >    public void testRunAsync_exceptionalCompletion() {
1007 >        ExecutionMode[] executionModes = {
1008 >            ExecutionMode.ASYNC,
1009 >            ExecutionMode.EXECUTOR,
1010 >        };
1011 >        for (ExecutionMode m : executionModes)
1012 >    {
1013 >        final FailingRunnable r = new FailingRunnable(m);
1014 >        final CompletableFuture<Void> f = m.runAsync(r);
1015          checkCompletedWithWrappedCFException(f);
1016          assertEquals(1, r.invocationCount);
1017 <    }
1017 >    }}
1018  
1019      /**
1020       * supplyAsync completes with result of supplier
1021       */
1022 <    public void testSupplyAsync() {
1023 <        CompletableFuture<Integer> f;
1024 <        f = CompletableFuture.supplyAsync(supplyOne);
1025 <        assertEquals(f.join(), one);
1026 <        checkCompletedNormally(f, one);
1027 <    }
1028 <
1029 <    /**
1030 <     * supplyAsync with executor completes with result of supplier
1031 <     */
1032 <    public void testSupplyAsync2() {
1033 <        CompletableFuture<Integer> f;
1034 <        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
1035 <        assertEquals(f.join(), one);
946 <        checkCompletedNormally(f, one);
947 <    }
1022 >    public void testSupplyAsync_normalCompletion() {
1023 >        ExecutionMode[] executionModes = {
1024 >            ExecutionMode.ASYNC,
1025 >            ExecutionMode.EXECUTOR,
1026 >        };
1027 >        for (ExecutionMode m : executionModes)
1028 >        for (Integer v1 : new Integer[] { 1, null })
1029 >    {
1030 >        final IntegerSupplier r = new IntegerSupplier(m, v1);
1031 >        final CompletableFuture<Integer> f = m.supplyAsync(r);
1032 >        assertSame(v1, f.join());
1033 >        checkCompletedNormally(f, v1);
1034 >        assertEquals(1, r.invocationCount);
1035 >    }}
1036  
1037      /**
1038       * Failing supplyAsync completes exceptionally
1039       */
1040 <    public void testSupplyAsync3() {
1041 <        FailingSupplier r = new FailingSupplier();
1042 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r);
1040 >    public void testSupplyAsync_exceptionalCompletion() {
1041 >        ExecutionMode[] executionModes = {
1042 >            ExecutionMode.ASYNC,
1043 >            ExecutionMode.EXECUTOR,
1044 >        };
1045 >        for (ExecutionMode m : executionModes)
1046 >    {
1047 >        FailingSupplier r = new FailingSupplier(m);
1048 >        CompletableFuture<Integer> f = m.supplyAsync(r);
1049          checkCompletedWithWrappedCFException(f);
1050          assertEquals(1, r.invocationCount);
1051 <    }
1051 >    }}
1052  
1053      // seq completion methods
1054  
1055      /**
1056       * thenRun result completes normally after normal completion of source
1057       */
1058 <    public void testThenRun() {
965 <        CompletableFuture<Integer> f;
966 <        CompletableFuture<Void> g;
967 <        Noop r;
968 <
969 <        f = new CompletableFuture<>();
970 <        g = f.thenRun(r = new Noop());
971 <        f.complete(null);
972 <        checkCompletedNormally(g, null);
973 <        assertEquals(1, r.invocationCount);
974 <
975 <        f = new CompletableFuture<>();
976 <        f.complete(null);
977 <        g = f.thenRun(r = new Noop());
978 <        checkCompletedNormally(g, null);
979 <        assertEquals(1, r.invocationCount);
980 <    }
981 <
982 <    /**
983 <     * thenRun result completes exceptionally after exceptional
984 <     * completion of source
985 <     */
986 <    public void testThenRun2() {
987 <        CompletableFuture<Integer> f;
988 <        CompletableFuture<Void> g;
989 <        Noop r;
990 <
991 <        f = new CompletableFuture<>();
992 <        g = f.thenRun(r = new Noop());
993 <        f.completeExceptionally(new CFException());
994 <        checkCompletedWithWrappedCFException(g);
995 <        assertEquals(0, r.invocationCount);
996 <
997 <        f = new CompletableFuture<>();
998 <        f.completeExceptionally(new CFException());
999 <        g = f.thenRun(r = new Noop());
1000 <        checkCompletedWithWrappedCFException(g);
1001 <        assertEquals(0, r.invocationCount);
1002 <    }
1003 <
1004 <    /**
1005 <     * thenRun result completes exceptionally if action does
1006 <     */
1007 <    public void testThenRun3() {
1008 <        CompletableFuture<Integer> f;
1009 <        CompletableFuture<Void> g;
1010 <        FailingNoop r;
1011 <
1012 <        f = new CompletableFuture<>();
1013 <        g = f.thenRun(r = new FailingNoop());
1014 <        f.complete(null);
1015 <        checkCompletedWithWrappedCFException(g);
1016 <
1017 <        f = new CompletableFuture<>();
1018 <        f.complete(null);
1019 <        g = f.thenRun(r = new FailingNoop());
1020 <        checkCompletedWithWrappedCFException(g);
1021 <    }
1022 <
1023 <    /**
1024 <     * thenRun result completes exceptionally if source cancelled
1025 <     */
1026 <    public void testThenRun4() {
1027 <        CompletableFuture<Integer> f;
1028 <        CompletableFuture<Void> g;
1029 <        Noop r;
1030 <
1031 <        f = new CompletableFuture<>();
1032 <        g = f.thenRun(r = new Noop());
1033 <        assertTrue(f.cancel(true));
1034 <        checkCompletedWithWrappedCancellationException(g);
1035 <
1036 <        f = new CompletableFuture<>();
1037 <        assertTrue(f.cancel(true));
1038 <        g = f.thenRun(r = new Noop());
1039 <        checkCompletedWithWrappedCancellationException(g);
1040 <    }
1041 <
1042 <    /**
1043 <     * thenApply result completes normally after normal completion of source
1044 <     */
1045 <    public void testThenApply() {
1046 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1047 <        CompletableFuture<Integer> g = f.thenApply(inc);
1048 <        f.complete(one);
1049 <        checkCompletedNormally(g, two);
1050 <    }
1051 <
1052 <    /**
1053 <     * thenApply result completes exceptionally after exceptional
1054 <     * completion of source
1055 <     */
1056 <    public void testThenApply2() {
1057 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1058 <        CompletableFuture<Integer> g = f.thenApply(inc);
1059 <        f.completeExceptionally(new CFException());
1060 <        checkCompletedWithWrappedCFException(g);
1061 <    }
1062 <
1063 <    /**
1064 <     * thenApply result completes exceptionally if action does
1065 <     */
1066 <    public void testThenApply3() {
1067 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1068 <        CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
1069 <        f.complete(one);
1070 <        checkCompletedWithWrappedCFException(g);
1071 <    }
1072 <
1073 <    /**
1074 <     * thenApply result completes exceptionally if source cancelled
1075 <     */
1076 <    public void testThenApply4() {
1077 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1078 <        CompletableFuture<Integer> g = f.thenApply(inc);
1079 <        assertTrue(f.cancel(true));
1080 <        checkCompletedWithWrappedCancellationException(g);
1081 <    }
1082 <
1083 <    /**
1084 <     * thenAccept result completes normally after normal completion of source
1085 <     */
1086 <    public void testThenAccept() {
1087 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1088 <        IncAction r = new IncAction();
1089 <        CompletableFuture<Void> g = f.thenAccept(r);
1090 <        f.complete(one);
1091 <        checkCompletedNormally(g, null);
1092 <        assertEquals(r.value, (Integer) 2);
1093 <    }
1094 <
1095 <    /**
1096 <     * thenAccept result completes exceptionally after exceptional
1097 <     * completion of source
1098 <     */
1099 <    public void testThenAccept2() {
1100 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1101 <        IncAction r = new IncAction();
1102 <        CompletableFuture<Void> g = f.thenAccept(r);
1103 <        f.completeExceptionally(new CFException());
1104 <        checkCompletedWithWrappedCFException(g);
1105 <    }
1106 <
1107 <    /**
1108 <     * thenAccept result completes exceptionally if action does
1109 <     */
1110 <    public void testThenAccept3() {
1111 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1112 <        FailingConsumer r = new FailingConsumer();
1113 <        CompletableFuture<Void> g = f.thenAccept(r);
1114 <        f.complete(one);
1115 <        checkCompletedWithWrappedCFException(g);
1116 <        assertEquals(1, r.invocationCount);
1117 <    }
1118 <
1119 <    /**
1120 <     * thenAccept result completes exceptionally if source cancelled
1121 <     */
1122 <    public void testThenAccept4() {
1123 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1124 <        IncAction r = new IncAction();
1125 <        CompletableFuture<Void> g = f.thenAccept(r);
1126 <        assertTrue(f.cancel(true));
1127 <        checkCompletedWithWrappedCancellationException(g);
1128 <    }
1129 <
1130 <    /**
1131 <     * thenCombine result completes normally after normal completion
1132 <     * of sources
1133 <     */
1134 <    public void testThenCombine_normalCompletion1() {
1135 <        for (boolean createIncomplete : new boolean[] { true, false })
1136 <        for (boolean fFirst : new boolean[] { true, false })
1058 >    public void testThenRun_normalCompletion() {
1059          for (ExecutionMode m : ExecutionMode.values())
1060 +        for (boolean createIncomplete : new boolean[] { true, false })
1061          for (Integer v1 : new Integer[] { 1, null })
1139        for (Integer v2 : new Integer[] { 2, null })
1062      {
1063          final CompletableFuture<Integer> f = new CompletableFuture<>();
1064 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1065 <        final SubtractFunction r = new SubtractFunction();
1066 <        CompletableFuture<Integer> h = null;
1067 <        if (createIncomplete) h = m.thenCombine(f, g, r);
1068 <
1147 <        if (fFirst)
1148 <            f.complete(v1);
1149 <        else
1150 <            g.complete(v2);
1151 <        if (createIncomplete) checkIncomplete(h);
1152 <        assertEquals(0, r.invocationCount);
1153 <        if (!fFirst)
1064 >        final Noop r = new Noop(m);
1065 >        if (!createIncomplete) f.complete(v1);
1066 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1067 >        if (createIncomplete) {
1068 >            checkIncomplete(g);
1069              f.complete(v1);
1070 <        else
1156 <            g.complete(v2);
1157 <        if (!createIncomplete) h = m.thenCombine(f, g, r);
1070 >        }
1071  
1072 <        checkCompletedNormally(h, subtract(v1, v2));
1072 >        checkCompletedNormally(g, null);
1073          checkCompletedNormally(f, v1);
1161        checkCompletedNormally(g, v2);
1074          assertEquals(1, r.invocationCount);
1075      }}
1076  
1077      /**
1078 <     * thenCombine result completes exceptionally after exceptional
1079 <     * completion of either source
1078 >     * thenRun result completes exceptionally after exceptional
1079 >     * completion of source
1080       */
1081 <    public void testThenCombine_exceptionalCompletion1() {
1081 >    public void testThenRun_exceptionalCompletion() {
1082          for (ExecutionMode m : ExecutionMode.values())
1083 <        for (Integer v1 : new Integer[] { 1, null })
1083 >        for (boolean createIncomplete : new boolean[] { true, false })
1084      {
1173        final CompletableFuture<Integer> f = new CompletableFuture<>();
1174        final CompletableFuture<Integer> g = new CompletableFuture<>();
1175        final SubtractFunction r = new SubtractFunction();
1176        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1085          final CFException ex = new CFException();
1178
1179        f.completeExceptionally(ex);
1180        checkIncomplete(h);
1181        g.complete(v1);
1182
1183        checkCompletedWithWrappedCFException(h, ex);
1184        checkCompletedWithWrappedCFException(f, ex);
1185        assertEquals(0, r.invocationCount);
1186        checkCompletedNormally(g, v1);
1187    }}
1188
1189    public void testThenCombine_exceptionalCompletion2() {
1190        for (ExecutionMode m : ExecutionMode.values())
1191        for (Integer v1 : new Integer[] { 1, null })
1192    {
1086          final CompletableFuture<Integer> f = new CompletableFuture<>();
1087 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1088 <        final SubtractFunction r = new SubtractFunction();
1089 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1090 <        final CFException ex = new CFException();
1091 <
1092 <        g.completeExceptionally(ex);
1093 <        checkIncomplete(h);
1201 <        f.complete(v1);
1202 <
1203 <        checkCompletedWithWrappedCFException(h, ex);
1204 <        checkCompletedWithWrappedCFException(g, ex);
1205 <        assertEquals(0, r.invocationCount);
1206 <        checkCompletedNormally(f, v1);
1207 <    }}
1208 <
1209 <    public void testThenCombine_exceptionalCompletion3() {
1210 <        for (ExecutionMode m : ExecutionMode.values())
1211 <        for (Integer v1 : new Integer[] { 1, null })
1212 <    {
1213 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1214 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1215 <        final SubtractFunction r = new SubtractFunction();
1216 <        final CFException ex = new CFException();
1217 <
1218 <        g.completeExceptionally(ex);
1219 <        f.complete(v1);
1220 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1087 >        final Noop r = new Noop(m);
1088 >        if (!createIncomplete) f.completeExceptionally(ex);
1089 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1090 >        if (createIncomplete) {
1091 >            checkIncomplete(g);
1092 >            f.completeExceptionally(ex);
1093 >        }
1094  
1222        checkCompletedWithWrappedCFException(h, ex);
1095          checkCompletedWithWrappedCFException(g, ex);
1096 +        checkCompletedWithWrappedCFException(f, ex);
1097          assertEquals(0, r.invocationCount);
1225        checkCompletedNormally(f, v1);
1098      }}
1099  
1100 <    public void testThenCombine_exceptionalCompletion4() {
1100 >    /**
1101 >     * thenRun result completes exceptionally if source cancelled
1102 >     */
1103 >    public void testThenRun_sourceCancelled() {
1104          for (ExecutionMode m : ExecutionMode.values())
1105 <        for (Integer v1 : new Integer[] { 1, null })
1105 >        for (boolean createIncomplete : new boolean[] { true, false })
1106 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1107      {
1108          final CompletableFuture<Integer> f = new CompletableFuture<>();
1109 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1110 <        final SubtractFunction r = new SubtractFunction();
1111 <        final CFException ex = new CFException();
1112 <
1113 <        f.completeExceptionally(ex);
1114 <        g.complete(v1);
1115 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1109 >        final Noop r = new Noop(m);
1110 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1111 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1112 >        if (createIncomplete) {
1113 >            checkIncomplete(g);
1114 >            assertTrue(f.cancel(mayInterruptIfRunning));
1115 >        }
1116  
1117 <        checkCompletedWithWrappedCFException(h, ex);
1118 <        checkCompletedWithWrappedCFException(f, ex);
1117 >        checkCompletedWithWrappedCancellationException(g);
1118 >        checkCancelled(f);
1119          assertEquals(0, r.invocationCount);
1244        checkCompletedNormally(g, v1);
1120      }}
1121  
1122      /**
1123 <     * thenCombine result completes exceptionally if action does
1123 >     * thenRun result completes exceptionally if action does
1124       */
1125 <    public void testThenCombine_actionFailed1() {
1125 >    public void testThenRun_actionFailed() {
1126          for (ExecutionMode m : ExecutionMode.values())
1127 +        for (boolean createIncomplete : new boolean[] { true, false })
1128          for (Integer v1 : new Integer[] { 1, null })
1253        for (Integer v2 : new Integer[] { 2, null })
1129      {
1130          final CompletableFuture<Integer> f = new CompletableFuture<>();
1131 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1132 <        final FailingBiFunction r = new FailingBiFunction();
1133 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1134 <
1135 <        f.complete(v1);
1136 <        checkIncomplete(h);
1137 <        g.complete(v2);
1131 >        final FailingRunnable r = new FailingRunnable(m);
1132 >        if (!createIncomplete) f.complete(v1);
1133 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1134 >        if (createIncomplete) {
1135 >            checkIncomplete(g);
1136 >            f.complete(v1);
1137 >        }
1138  
1139 <        checkCompletedWithWrappedCFException(h);
1139 >        checkCompletedWithWrappedCFException(g);
1140          checkCompletedNormally(f, v1);
1266        checkCompletedNormally(g, v2);
1141      }}
1142  
1143 <    public void testThenCombine_actionFailed2() {
1143 >    /**
1144 >     * thenApply result completes normally after normal completion of source
1145 >     */
1146 >    public void testThenApply_normalCompletion() {
1147          for (ExecutionMode m : ExecutionMode.values())
1148 +        for (boolean createIncomplete : new boolean[] { true, false })
1149          for (Integer v1 : new Integer[] { 1, null })
1272        for (Integer v2 : new Integer[] { 2, null })
1150      {
1151          final CompletableFuture<Integer> f = new CompletableFuture<>();
1152 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1153 <        final FailingBiFunction r = new FailingBiFunction();
1154 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1155 <
1156 <        g.complete(v2);
1157 <        checkIncomplete(h);
1158 <        f.complete(v1);
1152 >        final IncFunction r = new IncFunction(m);
1153 >        if (!createIncomplete) f.complete(v1);
1154 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1155 >        if (createIncomplete) {
1156 >            checkIncomplete(g);
1157 >            f.complete(v1);
1158 >        }
1159  
1160 <        checkCompletedWithWrappedCFException(h);
1160 >        checkCompletedNormally(g, inc(v1));
1161          checkCompletedNormally(f, v1);
1162 <        checkCompletedNormally(g, v2);
1162 >        assertEquals(1, r.invocationCount);
1163      }}
1164  
1165      /**
1166 <     * thenCombine result completes exceptionally if either source cancelled
1166 >     * thenApply result completes exceptionally after exceptional
1167 >     * completion of source
1168       */
1169 <    public void testThenCombine_sourceCancelled1() {
1169 >    public void testThenApply_exceptionalCompletion() {
1170          for (ExecutionMode m : ExecutionMode.values())
1171 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1294 <        for (Integer v1 : new Integer[] { 1, null })
1171 >        for (boolean createIncomplete : new boolean[] { true, false })
1172      {
1173 +        final CFException ex = new CFException();
1174          final CompletableFuture<Integer> f = new CompletableFuture<>();
1175 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1176 <        final SubtractFunction r = new SubtractFunction();
1177 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1178 <
1179 <        assertTrue(f.cancel(mayInterruptIfRunning));
1180 <        checkIncomplete(h);
1181 <        g.complete(v1);
1175 >        final IncFunction r = new IncFunction(m);
1176 >        if (!createIncomplete) f.completeExceptionally(ex);
1177 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1178 >        if (createIncomplete) {
1179 >            checkIncomplete(g);
1180 >            f.completeExceptionally(ex);
1181 >        }
1182  
1183 <        checkCompletedWithWrappedCancellationException(h);
1184 <        checkCancelled(f);
1183 >        checkCompletedWithWrappedCFException(g, ex);
1184 >        checkCompletedWithWrappedCFException(f, ex);
1185          assertEquals(0, r.invocationCount);
1308        checkCompletedNormally(g, v1);
1186      }}
1187  
1188 <    public void testThenCombine_sourceCancelled2() {
1188 >    /**
1189 >     * thenApply result completes exceptionally if source cancelled
1190 >     */
1191 >    public void testThenApply_sourceCancelled() {
1192          for (ExecutionMode m : ExecutionMode.values())
1193 +        for (boolean createIncomplete : new boolean[] { true, false })
1194          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1314        for (Integer v1 : new Integer[] { 1, null })
1195      {
1196          final CompletableFuture<Integer> f = new CompletableFuture<>();
1197 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1198 <        final SubtractFunction r = new SubtractFunction();
1199 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1200 <
1201 <        assertTrue(g.cancel(mayInterruptIfRunning));
1202 <        checkIncomplete(h);
1203 <        f.complete(v1);
1197 >        final IncFunction r = new IncFunction(m);
1198 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1199 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1200 >        if (createIncomplete) {
1201 >            checkIncomplete(g);
1202 >            assertTrue(f.cancel(mayInterruptIfRunning));
1203 >        }
1204  
1205 <        checkCompletedWithWrappedCancellationException(h);
1206 <        checkCancelled(g);
1205 >        checkCompletedWithWrappedCancellationException(g);
1206 >        checkCancelled(f);
1207          assertEquals(0, r.invocationCount);
1328        checkCompletedNormally(f, v1);
1208      }}
1209  
1210 <    public void testThenCombine_sourceCancelled3() {
1210 >    /**
1211 >     * thenApply result completes exceptionally if action does
1212 >     */
1213 >    public void testThenApply_actionFailed() {
1214          for (ExecutionMode m : ExecutionMode.values())
1215 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1215 >        for (boolean createIncomplete : new boolean[] { true, false })
1216          for (Integer v1 : new Integer[] { 1, null })
1217      {
1218          final CompletableFuture<Integer> f = new CompletableFuture<>();
1219 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1220 <        final SubtractFunction r = new SubtractFunction();
1221 <
1222 <        assertTrue(g.cancel(mayInterruptIfRunning));
1223 <        f.complete(v1);
1224 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1219 >        final FailingFunction r = new FailingFunction(m);
1220 >        if (!createIncomplete) f.complete(v1);
1221 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1222 >        if (createIncomplete) {
1223 >            checkIncomplete(g);
1224 >            f.complete(v1);
1225 >        }
1226  
1227 <        checkCompletedWithWrappedCancellationException(h);
1345 <        checkCancelled(g);
1346 <        assertEquals(0, r.invocationCount);
1227 >        checkCompletedWithWrappedCFException(g);
1228          checkCompletedNormally(f, v1);
1229      }}
1230  
1231 <    public void testThenCombine_sourceCancelled4() {
1231 >    /**
1232 >     * thenAccept result completes normally after normal completion of source
1233 >     */
1234 >    public void testThenAccept_normalCompletion() {
1235          for (ExecutionMode m : ExecutionMode.values())
1236 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1236 >        for (boolean createIncomplete : new boolean[] { true, false })
1237          for (Integer v1 : new Integer[] { 1, null })
1238      {
1239          final CompletableFuture<Integer> f = new CompletableFuture<>();
1240 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1241 <        final SubtractFunction r = new SubtractFunction();
1242 <
1243 <        assertTrue(f.cancel(mayInterruptIfRunning));
1244 <        g.complete(v1);
1245 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1240 >        final IncAction r = new IncAction();
1241 >        if (!createIncomplete) f.complete(v1);
1242 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1243 >        if (createIncomplete) {
1244 >            checkIncomplete(g);
1245 >            f.complete(v1);
1246 >        }
1247  
1248 <        checkCompletedWithWrappedCancellationException(h);
1249 <        checkCancelled(f);
1250 <        assertEquals(0, r.invocationCount);
1251 <        checkCompletedNormally(g, v1);
1248 >        checkCompletedNormally(g, null);
1249 >        checkCompletedNormally(f, v1);
1250 >        assertEquals(1, r.invocationCount);
1251 >        assertEquals(inc(v1), r.value);
1252      }}
1253  
1254      /**
1255 <     * thenAcceptBoth result completes normally after normal
1256 <     * completion of sources
1255 >     * thenAccept result completes exceptionally after exceptional
1256 >     * completion of source
1257       */
1258 <    public void testThenAcceptBoth_normalCompletion1() {
1258 >    public void testThenAccept_exceptionalCompletion() {
1259          for (ExecutionMode m : ExecutionMode.values())
1260 <        for (Integer v1 : new Integer[] { 1, null })
1376 <        for (Integer v2 : new Integer[] { 2, null })
1260 >        for (boolean createIncomplete : new boolean[] { true, false })
1261      {
1262 +        final CFException ex = new CFException();
1263          final CompletableFuture<Integer> f = new CompletableFuture<>();
1264 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1265 <        final SubtractAction r = new SubtractAction();
1266 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1264 >        final IncAction r = new IncAction();
1265 >        if (!createIncomplete) f.completeExceptionally(ex);
1266 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1267 >        if (createIncomplete) {
1268 >            checkIncomplete(g);
1269 >            f.completeExceptionally(ex);
1270 >        }
1271  
1272 <        f.complete(v1);
1273 <        checkIncomplete(h);
1272 >        checkCompletedWithWrappedCFException(g, ex);
1273 >        checkCompletedWithWrappedCFException(f, ex);
1274          assertEquals(0, r.invocationCount);
1386        g.complete(v2);
1387
1388        checkCompletedNormally(h, null);
1389        assertEquals(subtract(v1, v2), r.value);
1390        checkCompletedNormally(f, v1);
1391        checkCompletedNormally(g, v2);
1275      }}
1276  
1277 <    public void testThenAcceptBoth_normalCompletion2() {
1277 >    /**
1278 >     * thenAccept result completes exceptionally if source cancelled
1279 >     */
1280 >    public void testThenAccept_sourceCancelled() {
1281          for (ExecutionMode m : ExecutionMode.values())
1282 <        for (Integer v1 : new Integer[] { 1, null })
1283 <        for (Integer v2 : new Integer[] { 2, null })
1282 >        for (boolean createIncomplete : new boolean[] { true, false })
1283 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1284      {
1285          final CompletableFuture<Integer> f = new CompletableFuture<>();
1286 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1287 <        final SubtractAction r = new SubtractAction();
1288 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1286 >        final IncAction r = new IncAction();
1287 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1288 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1289 >        if (createIncomplete) {
1290 >            checkIncomplete(g);
1291 >            assertTrue(f.cancel(mayInterruptIfRunning));
1292 >        }
1293  
1294 <        g.complete(v2);
1295 <        checkIncomplete(h);
1294 >        checkCompletedWithWrappedCancellationException(g);
1295 >        checkCancelled(f);
1296          assertEquals(0, r.invocationCount);
1407        f.complete(v1);
1408
1409        checkCompletedNormally(h, null);
1410        assertEquals(subtract(v1, v2), r.value);
1411        checkCompletedNormally(f, v1);
1412        checkCompletedNormally(g, v2);
1297      }}
1298  
1299 <    public void testThenAcceptBoth_normalCompletion3() {
1299 >    /**
1300 >     * thenAccept result completes exceptionally if action does
1301 >     */
1302 >    public void testThenAccept_actionFailed() {
1303          for (ExecutionMode m : ExecutionMode.values())
1304 +        for (boolean createIncomplete : new boolean[] { true, false })
1305          for (Integer v1 : new Integer[] { 1, null })
1418        for (Integer v2 : new Integer[] { 2, null })
1306      {
1307          final CompletableFuture<Integer> f = new CompletableFuture<>();
1308 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1309 <        final SubtractAction r = new SubtractAction();
1310 <
1311 <        g.complete(v2);
1312 <        f.complete(v1);
1313 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1308 >        final FailingConsumer r = new FailingConsumer(m);
1309 >        if (!createIncomplete) f.complete(v1);
1310 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1311 >        if (createIncomplete) {
1312 >            checkIncomplete(g);
1313 >            f.complete(v1);
1314 >        }
1315  
1316 <        checkCompletedNormally(h, null);
1429 <        assertEquals(subtract(v1, v2), r.value);
1316 >        checkCompletedWithWrappedCFException(g);
1317          checkCompletedNormally(f, v1);
1431        checkCompletedNormally(g, v2);
1318      }}
1319  
1320 <    public void testThenAcceptBoth_normalCompletion4() {
1320 >    /**
1321 >     * thenCombine result completes normally after normal completion
1322 >     * of sources
1323 >     */
1324 >    public void testThenCombine_normalCompletion() {
1325          for (ExecutionMode m : ExecutionMode.values())
1326 +        for (boolean createIncomplete : new boolean[] { true, false })
1327 +        for (boolean fFirst : new boolean[] { true, false })
1328          for (Integer v1 : new Integer[] { 1, null })
1329          for (Integer v2 : new Integer[] { 2, null })
1330      {
1331          final CompletableFuture<Integer> f = new CompletableFuture<>();
1332          final CompletableFuture<Integer> g = new CompletableFuture<>();
1333 <        final SubtractAction r = new SubtractAction();
1333 >        final SubtractFunction r = new SubtractFunction(m);
1334  
1335 <        f.complete(v1);
1336 <        g.complete(v2);
1337 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1335 >        if (fFirst) f.complete(v1); else g.complete(v2);
1336 >        if (!createIncomplete)
1337 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1338 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1339 >        if (createIncomplete) {
1340 >            checkIncomplete(h);
1341 >            assertEquals(0, r.invocationCount);
1342 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1343 >        }
1344  
1345 <        checkCompletedNormally(h, null);
1448 <        assertEquals(subtract(v1, v2), r.value);
1345 >        checkCompletedNormally(h, subtract(v1, v2));
1346          checkCompletedNormally(f, v1);
1347          checkCompletedNormally(g, v2);
1348 +        assertEquals(1, r.invocationCount);
1349      }}
1350  
1351      /**
1352 <     * thenAcceptBoth result completes exceptionally after exceptional
1352 >     * thenCombine result completes exceptionally after exceptional
1353       * completion of either source
1354       */
1355 <    public void testThenAcceptBoth_exceptionalCompletion1() {
1458 <        for (ExecutionMode m : ExecutionMode.values())
1459 <        for (Integer v1 : new Integer[] { 1, null })
1460 <    {
1461 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1462 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1463 <        final SubtractAction r = new SubtractAction();
1464 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1465 <        final CFException ex = new CFException();
1466 <
1467 <        f.completeExceptionally(ex);
1468 <        checkIncomplete(h);
1469 <        g.complete(v1);
1470 <
1471 <        checkCompletedWithWrappedCFException(h, ex);
1472 <        checkCompletedWithWrappedCFException(f, ex);
1473 <        assertEquals(0, r.invocationCount);
1474 <        checkCompletedNormally(g, v1);
1475 <    }}
1476 <
1477 <    public void testThenAcceptBoth_exceptionalCompletion2() {
1478 <        for (ExecutionMode m : ExecutionMode.values())
1479 <        for (Integer v1 : new Integer[] { 1, null })
1480 <    {
1481 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1482 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1483 <        final SubtractAction r = new SubtractAction();
1484 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1485 <        final CFException ex = new CFException();
1486 <
1487 <        g.completeExceptionally(ex);
1488 <        checkIncomplete(h);
1489 <        f.complete(v1);
1490 <
1491 <        checkCompletedWithWrappedCFException(h, ex);
1492 <        checkCompletedWithWrappedCFException(g, ex);
1493 <        assertEquals(0, r.invocationCount);
1494 <        checkCompletedNormally(f, v1);
1495 <    }}
1496 <
1497 <    public void testThenAcceptBoth_exceptionalCompletion3() {
1355 >    public void testThenCombine_exceptionalCompletion() {
1356          for (ExecutionMode m : ExecutionMode.values())
1357 +        for (boolean createIncomplete : new boolean[] { true, false })
1358 +        for (boolean fFirst : new boolean[] { true, false })
1359          for (Integer v1 : new Integer[] { 1, null })
1360      {
1361          final CompletableFuture<Integer> f = new CompletableFuture<>();
1362          final CompletableFuture<Integer> g = new CompletableFuture<>();
1503        final SubtractAction r = new SubtractAction();
1363          final CFException ex = new CFException();
1364 +        final SubtractFunction r = new SubtractFunction(m);
1365  
1366 <        g.completeExceptionally(ex);
1367 <        f.complete(v1);
1368 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1366 >        (fFirst ? f : g).complete(v1);
1367 >        if (!createIncomplete)
1368 >            (!fFirst ? f : g).completeExceptionally(ex);
1369 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1370 >        if (createIncomplete) {
1371 >            checkIncomplete(h);
1372 >            (!fFirst ? f : g).completeExceptionally(ex);
1373 >        }
1374  
1375          checkCompletedWithWrappedCFException(h, ex);
1511        checkCompletedWithWrappedCFException(g, ex);
1376          assertEquals(0, r.invocationCount);
1377 <        checkCompletedNormally(f, v1);
1377 >        checkCompletedNormally(fFirst ? f : g, v1);
1378 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1379      }}
1380  
1381 <    public void testThenAcceptBoth_exceptionalCompletion4() {
1381 >    /**
1382 >     * thenCombine result completes exceptionally if either source cancelled
1383 >     */
1384 >    public void testThenCombine_sourceCancelled() {
1385          for (ExecutionMode m : ExecutionMode.values())
1386 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1387 +        for (boolean createIncomplete : new boolean[] { true, false })
1388 +        for (boolean fFirst : new boolean[] { true, false })
1389          for (Integer v1 : new Integer[] { 1, null })
1390      {
1391          final CompletableFuture<Integer> f = new CompletableFuture<>();
1392          final CompletableFuture<Integer> g = new CompletableFuture<>();
1393 <        final SubtractAction r = new SubtractAction();
1523 <        final CFException ex = new CFException();
1393 >        final SubtractFunction r = new SubtractFunction(m);
1394  
1395 <        f.completeExceptionally(ex);
1396 <        g.complete(v1);
1397 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1395 >        (fFirst ? f : g).complete(v1);
1396 >        if (!createIncomplete)
1397 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1398 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1399 >        if (createIncomplete) {
1400 >            checkIncomplete(h);
1401 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1402 >        }
1403  
1404 <        checkCompletedWithWrappedCFException(h, ex);
1405 <        checkCompletedWithWrappedCFException(f, ex);
1404 >        checkCompletedWithWrappedCancellationException(h);
1405 >        checkCancelled(!fFirst ? f : g);
1406          assertEquals(0, r.invocationCount);
1407 <        checkCompletedNormally(g, v1);
1407 >        checkCompletedNormally(fFirst ? f : g, v1);
1408      }}
1409  
1410      /**
1411 <     * thenAcceptBoth result completes exceptionally if action does
1411 >     * thenCombine result completes exceptionally if action does
1412       */
1413 <    public void testThenAcceptBoth_actionFailed1() {
1413 >    public void testThenCombine_actionFailed() {
1414          for (ExecutionMode m : ExecutionMode.values())
1415 +        for (boolean fFirst : new boolean[] { true, false })
1416          for (Integer v1 : new Integer[] { 1, null })
1417          for (Integer v2 : new Integer[] { 2, null })
1418      {
1419          final CompletableFuture<Integer> f = new CompletableFuture<>();
1420          final CompletableFuture<Integer> g = new CompletableFuture<>();
1421 <        final FailingBiConsumer r = new FailingBiConsumer();
1422 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1421 >        final FailingBiFunction r = new FailingBiFunction(m);
1422 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1423  
1424 <        f.complete(v1);
1425 <        checkIncomplete(h);
1426 <        g.complete(v2);
1424 >        if (fFirst) {
1425 >            f.complete(v1);
1426 >            g.complete(v2);
1427 >        } else {
1428 >            g.complete(v2);
1429 >            f.complete(v1);
1430 >        }
1431  
1432          checkCompletedWithWrappedCFException(h);
1433          checkCompletedNormally(f, v1);
1434          checkCompletedNormally(g, v2);
1435      }}
1436  
1437 <    public void testThenAcceptBoth_actionFailed2() {
1437 >    /**
1438 >     * thenAcceptBoth result completes normally after normal
1439 >     * completion of sources
1440 >     */
1441 >    public void testThenAcceptBoth_normalCompletion() {
1442          for (ExecutionMode m : ExecutionMode.values())
1443 +        for (boolean createIncomplete : new boolean[] { true, false })
1444 +        for (boolean fFirst : new boolean[] { true, false })
1445          for (Integer v1 : new Integer[] { 1, null })
1446          for (Integer v2 : new Integer[] { 2, null })
1447      {
1448          final CompletableFuture<Integer> f = new CompletableFuture<>();
1449          final CompletableFuture<Integer> g = new CompletableFuture<>();
1450 <        final FailingBiConsumer r = new FailingBiConsumer();
1565 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1450 >        final SubtractAction r = new SubtractAction(m);
1451  
1452 <        g.complete(v2);
1453 <        checkIncomplete(h);
1454 <        f.complete(v1);
1452 >        if (fFirst) f.complete(v1); else g.complete(v2);
1453 >        if (!createIncomplete)
1454 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1455 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1456 >        if (createIncomplete) {
1457 >            checkIncomplete(h);
1458 >            assertEquals(0, r.invocationCount);
1459 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1460 >        }
1461  
1462 <        checkCompletedWithWrappedCFException(h);
1462 >        checkCompletedNormally(h, null);
1463 >        assertEquals(subtract(v1, v2), r.value);
1464          checkCompletedNormally(f, v1);
1465          checkCompletedNormally(g, v2);
1466      }}
1467  
1468      /**
1469 <     * thenAcceptBoth result completes exceptionally if either source cancelled
1469 >     * thenAcceptBoth result completes exceptionally after exceptional
1470 >     * completion of either source
1471       */
1472 <    public void testThenAcceptBoth_sourceCancelled1() {
1580 <        for (ExecutionMode m : ExecutionMode.values())
1581 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1582 <        for (Integer v1 : new Integer[] { 1, null })
1583 <    {
1584 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1585 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1586 <        final SubtractAction r = new SubtractAction();
1587 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1588 <
1589 <        assertTrue(f.cancel(mayInterruptIfRunning));
1590 <        checkIncomplete(h);
1591 <        g.complete(v1);
1592 <
1593 <        checkCompletedWithWrappedCancellationException(h);
1594 <        checkCancelled(f);
1595 <        assertEquals(0, r.invocationCount);
1596 <        checkCompletedNormally(g, v1);
1597 <    }}
1598 <
1599 <    public void testThenAcceptBoth_sourceCancelled2() {
1472 >    public void testThenAcceptBoth_exceptionalCompletion() {
1473          for (ExecutionMode m : ExecutionMode.values())
1474 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1475 <        for (Integer v1 : new Integer[] { 1, null })
1603 <    {
1604 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1605 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1606 <        final SubtractAction r = new SubtractAction();
1607 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1608 <
1609 <        assertTrue(g.cancel(mayInterruptIfRunning));
1610 <        checkIncomplete(h);
1611 <        f.complete(v1);
1612 <
1613 <        checkCompletedWithWrappedCancellationException(h);
1614 <        checkCancelled(g);
1615 <        assertEquals(0, r.invocationCount);
1616 <        checkCompletedNormally(f, v1);
1617 <    }}
1618 <
1619 <    public void testThenAcceptBoth_sourceCancelled3() {
1620 <        for (ExecutionMode m : ExecutionMode.values())
1621 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1474 >        for (boolean createIncomplete : new boolean[] { true, false })
1475 >        for (boolean fFirst : new boolean[] { true, false })
1476          for (Integer v1 : new Integer[] { 1, null })
1477      {
1478          final CompletableFuture<Integer> f = new CompletableFuture<>();
1479          final CompletableFuture<Integer> g = new CompletableFuture<>();
1480 <        final SubtractAction r = new SubtractAction();
1480 >        final CFException ex = new CFException();
1481 >        final SubtractAction r = new SubtractAction(m);
1482  
1483 <        assertTrue(g.cancel(mayInterruptIfRunning));
1484 <        f.complete(v1);
1483 >        (fFirst ? f : g).complete(v1);
1484 >        if (!createIncomplete)
1485 >            (!fFirst ? f : g).completeExceptionally(ex);
1486          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1487 +        if (createIncomplete) {
1488 +            checkIncomplete(h);
1489 +            (!fFirst ? f : g).completeExceptionally(ex);
1490 +        }
1491  
1492 <        checkCompletedWithWrappedCancellationException(h);
1633 <        checkCancelled(g);
1492 >        checkCompletedWithWrappedCFException(h, ex);
1493          assertEquals(0, r.invocationCount);
1494 <        checkCompletedNormally(f, v1);
1494 >        checkCompletedNormally(fFirst ? f : g, v1);
1495 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1496      }}
1497  
1498 <    public void testThenAcceptBoth_sourceCancelled4() {
1498 >    /**
1499 >     * thenAcceptBoth result completes exceptionally if either source cancelled
1500 >     */
1501 >    public void testThenAcceptBoth_sourceCancelled() {
1502          for (ExecutionMode m : ExecutionMode.values())
1503          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1504 +        for (boolean createIncomplete : new boolean[] { true, false })
1505 +        for (boolean fFirst : new boolean[] { true, false })
1506          for (Integer v1 : new Integer[] { 1, null })
1507      {
1508          final CompletableFuture<Integer> f = new CompletableFuture<>();
1509          final CompletableFuture<Integer> g = new CompletableFuture<>();
1510 <        final SubtractAction r = new SubtractAction();
1510 >        final SubtractAction r = new SubtractAction(m);
1511  
1512 <        assertTrue(f.cancel(mayInterruptIfRunning));
1513 <        g.complete(v1);
1512 >        (fFirst ? f : g).complete(v1);
1513 >        if (!createIncomplete)
1514 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1515          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1516 +        if (createIncomplete) {
1517 +            checkIncomplete(h);
1518 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1519 +        }
1520  
1521          checkCompletedWithWrappedCancellationException(h);
1522 <        checkCancelled(f);
1522 >        checkCancelled(!fFirst ? f : g);
1523          assertEquals(0, r.invocationCount);
1524 <        checkCompletedNormally(g, v1);
1524 >        checkCompletedNormally(fFirst ? f : g, v1);
1525      }}
1526  
1527      /**
1528 <     * runAfterBoth result completes normally after normal
1659 <     * completion of sources
1528 >     * thenAcceptBoth result completes exceptionally if action does
1529       */
1530 <    public void testRunAfterBoth_normalCompletion1() {
1662 <        for (ExecutionMode m : ExecutionMode.values())
1663 <        for (Integer v1 : new Integer[] { 1, null })
1664 <        for (Integer v2 : new Integer[] { 2, null })
1665 <    {
1666 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1667 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1668 <        final Noop r = new Noop();
1669 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1670 <
1671 <        f.complete(v1);
1672 <        checkIncomplete(h);
1673 <        assertEquals(0, r.invocationCount);
1674 <        g.complete(v2);
1675 <
1676 <        checkCompletedNormally(h, null);
1677 <        assertEquals(1, r.invocationCount);
1678 <        checkCompletedNormally(f, v1);
1679 <        checkCompletedNormally(g, v2);
1680 <    }}
1681 <
1682 <    public void testRunAfterBoth_normalCompletion2() {
1683 <        for (ExecutionMode m : ExecutionMode.values())
1684 <        for (Integer v1 : new Integer[] { 1, null })
1685 <        for (Integer v2 : new Integer[] { 2, null })
1686 <    {
1687 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1688 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1689 <        final Noop r = new Noop();
1690 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1691 <
1692 <        g.complete(v2);
1693 <        checkIncomplete(h);
1694 <        assertEquals(0, r.invocationCount);
1695 <        f.complete(v1);
1696 <
1697 <        checkCompletedNormally(h, null);
1698 <        assertEquals(1, r.invocationCount);
1699 <        checkCompletedNormally(f, v1);
1700 <        checkCompletedNormally(g, v2);
1701 <    }}
1702 <
1703 <    public void testRunAfterBoth_normalCompletion3() {
1530 >    public void testThenAcceptBoth_actionFailed() {
1531          for (ExecutionMode m : ExecutionMode.values())
1532 +        for (boolean fFirst : new boolean[] { true, false })
1533          for (Integer v1 : new Integer[] { 1, null })
1534          for (Integer v2 : new Integer[] { 2, null })
1535      {
1536          final CompletableFuture<Integer> f = new CompletableFuture<>();
1537          final CompletableFuture<Integer> g = new CompletableFuture<>();
1538 <        final Noop r = new Noop();
1538 >        final FailingBiConsumer r = new FailingBiConsumer(m);
1539 >        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1540  
1541 <        g.complete(v2);
1542 <        f.complete(v1);
1543 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1541 >        if (fFirst) {
1542 >            f.complete(v1);
1543 >            g.complete(v2);
1544 >        } else {
1545 >            g.complete(v2);
1546 >            f.complete(v1);
1547 >        }
1548  
1549 <        checkCompletedNormally(h, null);
1717 <        assertEquals(1, r.invocationCount);
1549 >        checkCompletedWithWrappedCFException(h);
1550          checkCompletedNormally(f, v1);
1551          checkCompletedNormally(g, v2);
1552      }}
1553  
1554 <    public void testRunAfterBoth_normalCompletion4() {
1554 >    /**
1555 >     * runAfterBoth result completes normally after normal
1556 >     * completion of sources
1557 >     */
1558 >    public void testRunAfterBoth_normalCompletion() {
1559          for (ExecutionMode m : ExecutionMode.values())
1560 +        for (boolean createIncomplete : new boolean[] { true, false })
1561 +        for (boolean fFirst : new boolean[] { true, false })
1562          for (Integer v1 : new Integer[] { 1, null })
1563          for (Integer v2 : new Integer[] { 2, null })
1564      {
1565          final CompletableFuture<Integer> f = new CompletableFuture<>();
1566          final CompletableFuture<Integer> g = new CompletableFuture<>();
1567 <        final Noop r = new Noop();
1567 >        final Noop r = new Noop(m);
1568  
1569 <        f.complete(v1);
1570 <        g.complete(v2);
1569 >        if (fFirst) f.complete(v1); else g.complete(v2);
1570 >        if (!createIncomplete)
1571 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1572          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1573 +        if (createIncomplete) {
1574 +            checkIncomplete(h);
1575 +            assertEquals(0, r.invocationCount);
1576 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1577 +        }
1578  
1579          checkCompletedNormally(h, null);
1580          assertEquals(1, r.invocationCount);
# Line 1742 | Line 1586 | public class CompletableFutureTest exten
1586       * runAfterBoth result completes exceptionally after exceptional
1587       * completion of either source
1588       */
1589 <    public void testRunAfterBoth_exceptionalCompletion1() {
1746 <        for (ExecutionMode m : ExecutionMode.values())
1747 <        for (Integer v1 : new Integer[] { 1, null })
1748 <    {
1749 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1750 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1751 <        final Noop r = new Noop();
1752 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1753 <        final CFException ex = new CFException();
1754 <
1755 <        f.completeExceptionally(ex);
1756 <        checkIncomplete(h);
1757 <        g.complete(v1);
1758 <
1759 <        checkCompletedWithWrappedCFException(h, ex);
1760 <        checkCompletedWithWrappedCFException(f, ex);
1761 <        assertEquals(0, r.invocationCount);
1762 <        checkCompletedNormally(g, v1);
1763 <    }}
1764 <
1765 <    public void testRunAfterBoth_exceptionalCompletion2() {
1766 <        for (ExecutionMode m : ExecutionMode.values())
1767 <        for (Integer v1 : new Integer[] { 1, null })
1768 <    {
1769 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1770 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1771 <        final Noop r = new Noop();
1772 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1773 <        final CFException ex = new CFException();
1774 <
1775 <        g.completeExceptionally(ex);
1776 <        checkIncomplete(h);
1777 <        f.complete(v1);
1778 <
1779 <        checkCompletedWithWrappedCFException(h, ex);
1780 <        checkCompletedWithWrappedCFException(g, ex);
1781 <        assertEquals(0, r.invocationCount);
1782 <        checkCompletedNormally(f, v1);
1783 <    }}
1784 <
1785 <    public void testRunAfterBoth_exceptionalCompletion3() {
1786 <        for (ExecutionMode m : ExecutionMode.values())
1787 <        for (Integer v1 : new Integer[] { 1, null })
1788 <    {
1789 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1790 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1791 <        final Noop r = new Noop();
1792 <        final CFException ex = new CFException();
1793 <
1794 <        g.completeExceptionally(ex);
1795 <        f.complete(v1);
1796 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1797 <
1798 <        checkCompletedWithWrappedCFException(h, ex);
1799 <        checkCompletedWithWrappedCFException(g, ex);
1800 <        assertEquals(0, r.invocationCount);
1801 <        checkCompletedNormally(f, v1);
1802 <    }}
1803 <
1804 <    public void testRunAfterBoth_exceptionalCompletion4() {
1589 >    public void testRunAfterBoth_exceptionalCompletion() {
1590          for (ExecutionMode m : ExecutionMode.values())
1591 +        for (boolean createIncomplete : new boolean[] { true, false })
1592 +        for (boolean fFirst : new boolean[] { true, false })
1593          for (Integer v1 : new Integer[] { 1, null })
1594      {
1595          final CompletableFuture<Integer> f = new CompletableFuture<>();
1596          final CompletableFuture<Integer> g = new CompletableFuture<>();
1810        final Noop r = new Noop();
1597          final CFException ex = new CFException();
1598 +        final Noop r = new Noop(m);
1599  
1600 <        f.completeExceptionally(ex);
1601 <        g.complete(v1);
1600 >        (fFirst ? f : g).complete(v1);
1601 >        if (!createIncomplete)
1602 >            (!fFirst ? f : g).completeExceptionally(ex);
1603          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1604 +        if (createIncomplete) {
1605 +            checkIncomplete(h);
1606 +            (!fFirst ? f : g).completeExceptionally(ex);
1607 +        }
1608  
1609          checkCompletedWithWrappedCFException(h, ex);
1818        checkCompletedWithWrappedCFException(f, ex);
1610          assertEquals(0, r.invocationCount);
1611 <        checkCompletedNormally(g, v1);
1612 <    }}
1822 <
1823 <    /**
1824 <     * runAfterBoth result completes exceptionally if action does
1825 <     */
1826 <    public void testRunAfterBoth_actionFailed1() {
1827 <        for (ExecutionMode m : ExecutionMode.values())
1828 <        for (Integer v1 : new Integer[] { 1, null })
1829 <        for (Integer v2 : new Integer[] { 2, null })
1830 <    {
1831 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1832 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1833 <        final FailingNoop r = new FailingNoop();
1834 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1835 <
1836 <        f.complete(v1);
1837 <        checkIncomplete(h);
1838 <        g.complete(v2);
1839 <
1840 <        checkCompletedWithWrappedCFException(h);
1841 <        checkCompletedNormally(f, v1);
1842 <        checkCompletedNormally(g, v2);
1843 <    }}
1844 <
1845 <    public void testRunAfterBoth_actionFailed2() {
1846 <        for (ExecutionMode m : ExecutionMode.values())
1847 <        for (Integer v1 : new Integer[] { 1, null })
1848 <        for (Integer v2 : new Integer[] { 2, null })
1849 <    {
1850 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1851 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1852 <        final FailingNoop r = new FailingNoop();
1853 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1854 <
1855 <        g.complete(v2);
1856 <        checkIncomplete(h);
1857 <        f.complete(v1);
1858 <
1859 <        checkCompletedWithWrappedCFException(h);
1860 <        checkCompletedNormally(f, v1);
1861 <        checkCompletedNormally(g, v2);
1611 >        checkCompletedNormally(fFirst ? f : g, v1);
1612 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1613      }}
1614  
1615      /**
1616       * runAfterBoth result completes exceptionally if either source cancelled
1617       */
1618 <    public void testRunAfterBoth_sourceCancelled1() {
1618 >    public void testRunAfterBoth_sourceCancelled() {
1619          for (ExecutionMode m : ExecutionMode.values())
1620          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1621 +        for (boolean createIncomplete : new boolean[] { true, false })
1622 +        for (boolean fFirst : new boolean[] { true, false })
1623          for (Integer v1 : new Integer[] { 1, null })
1624      {
1625          final CompletableFuture<Integer> f = new CompletableFuture<>();
1626          final CompletableFuture<Integer> g = new CompletableFuture<>();
1627 <        final Noop r = new Noop();
1875 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1627 >        final Noop r = new Noop(m);
1628  
1877        assertTrue(f.cancel(mayInterruptIfRunning));
1878        checkIncomplete(h);
1879        g.complete(v1);
1880
1881        checkCompletedWithWrappedCancellationException(h);
1882        checkCancelled(f);
1883        assertEquals(0, r.invocationCount);
1884        checkCompletedNormally(g, v1);
1885    }}
1629  
1630 <    public void testRunAfterBoth_sourceCancelled2() {
1631 <        for (ExecutionMode m : ExecutionMode.values())
1632 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1890 <        for (Integer v1 : new Integer[] { 1, null })
1891 <    {
1892 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1893 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1894 <        final Noop r = new Noop();
1630 >        (fFirst ? f : g).complete(v1);
1631 >        if (!createIncomplete)
1632 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1633          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1634 <
1635 <        assertTrue(g.cancel(mayInterruptIfRunning));
1636 <        checkIncomplete(h);
1637 <        f.complete(v1);
1634 >        if (createIncomplete) {
1635 >            checkIncomplete(h);
1636 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1637 >        }
1638  
1639          checkCompletedWithWrappedCancellationException(h);
1640 <        checkCancelled(g);
1640 >        checkCancelled(!fFirst ? f : g);
1641          assertEquals(0, r.invocationCount);
1642 <        checkCompletedNormally(f, v1);
1642 >        checkCompletedNormally(fFirst ? f : g, v1);
1643      }}
1644  
1645 <    public void testRunAfterBoth_sourceCancelled3() {
1645 >    /**
1646 >     * runAfterBoth result completes exceptionally if action does
1647 >     */
1648 >    public void testRunAfterBoth_actionFailed() {
1649          for (ExecutionMode m : ExecutionMode.values())
1650 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1650 >        for (boolean fFirst : new boolean[] { true, false })
1651          for (Integer v1 : new Integer[] { 1, null })
1652 +        for (Integer v2 : new Integer[] { 2, null })
1653      {
1654          final CompletableFuture<Integer> f = new CompletableFuture<>();
1655          final CompletableFuture<Integer> g = new CompletableFuture<>();
1656 <        final Noop r = new Noop();
1656 >        final FailingRunnable r = new FailingRunnable(m);
1657  
1658 <        assertTrue(g.cancel(mayInterruptIfRunning));
1659 <        f.complete(v1);
1660 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1658 >        CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r);
1659 >        if (fFirst) {
1660 >            f.complete(v1);
1661 >            g.complete(v2);
1662 >        } else {
1663 >            g.complete(v2);
1664 >            f.complete(v1);
1665 >        }
1666 >        CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r);
1667  
1668 <        checkCompletedWithWrappedCancellationException(h);
1669 <        checkCancelled(g);
1922 <        assertEquals(0, r.invocationCount);
1668 >        checkCompletedWithWrappedCFException(h1);
1669 >        checkCompletedWithWrappedCFException(h2);
1670          checkCompletedNormally(f, v1);
1671 <    }}
1925 <
1926 <    public void testRunAfterBoth_sourceCancelled4() {
1927 <        for (ExecutionMode m : ExecutionMode.values())
1928 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1929 <        for (Integer v1 : new Integer[] { 1, null })
1930 <    {
1931 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1932 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1933 <        final Noop r = new Noop();
1934 <
1935 <        assertTrue(f.cancel(mayInterruptIfRunning));
1936 <        g.complete(v1);
1937 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1938 <
1939 <        checkCompletedWithWrappedCancellationException(h);
1940 <        checkCancelled(f);
1941 <        assertEquals(0, r.invocationCount);
1942 <        checkCompletedNormally(g, v1);
1671 >        checkCompletedNormally(g, v2);
1672      }}
1673  
1674      /**
1675       * applyToEither result completes normally after normal completion
1676       * of either source
1677       */
1678 <    public void testApplyToEither_normalCompletion1() {
1678 >    public void testApplyToEither_normalCompletion() {
1679          for (ExecutionMode m : ExecutionMode.values())
1680 +        for (boolean createIncomplete : new boolean[] { true, false })
1681 +        for (boolean fFirst : new boolean[] { true, false })
1682          for (Integer v1 : new Integer[] { 1, null })
1683          for (Integer v2 : new Integer[] { 2, null })
1684      {
1685          final CompletableFuture<Integer> f = new CompletableFuture<>();
1686          final CompletableFuture<Integer> g = new CompletableFuture<>();
1687 <        final IncFunction r = new IncFunction();
1957 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1687 >        final IncFunction r = new IncFunction(m);
1688  
1689 <        f.complete(v1);
1690 <        checkCompletedNormally(h, inc(v1));
1691 <        g.complete(v2);
1689 >        if (!createIncomplete)
1690 >            if (fFirst) f.complete(v1); else g.complete(v2);
1691 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1692 >        if (createIncomplete) {
1693 >            checkIncomplete(h);
1694 >            assertEquals(0, r.invocationCount);
1695 >            if (fFirst) f.complete(v1); else g.complete(v2);
1696 >        }
1697 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1698 >        if (!fFirst) f.complete(v1); else g.complete(v2);
1699  
1700          checkCompletedNormally(f, v1);
1701          checkCompletedNormally(g, v2);
1702 <        checkCompletedNormally(h, inc(v1));
1702 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1703      }}
1704  
1705 <    public void testApplyToEither_normalCompletion2() {
1705 >    public void testApplyToEither_normalCompletionBothAvailable() {
1706          for (ExecutionMode m : ExecutionMode.values())
1707 +        for (boolean fFirst : new boolean[] { true, false })
1708          for (Integer v1 : new Integer[] { 1, null })
1709          for (Integer v2 : new Integer[] { 2, null })
1710      {
1711          final CompletableFuture<Integer> f = new CompletableFuture<>();
1712          final CompletableFuture<Integer> g = new CompletableFuture<>();
1713 <        final IncFunction r = new IncFunction();
1976 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1713 >        final IncFunction r = new IncFunction(m);
1714  
1715 <        g.complete(v2);
1716 <        checkCompletedNormally(h, inc(v2));
1717 <        f.complete(v1);
1718 <
1719 <        checkCompletedNormally(f, v1);
1720 <        checkCompletedNormally(g, v2);
1721 <        checkCompletedNormally(h, inc(v2));
1985 <        }}
1986 <
1987 <    public void testApplyToEither_normalCompletion3() {
1988 <        for (ExecutionMode m : ExecutionMode.values())
1989 <        for (Integer v1 : new Integer[] { 1, null })
1990 <        for (Integer v2 : new Integer[] { 2, null })
1991 <    {
1992 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1993 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1994 <        final IncFunction r = new IncFunction();
1715 >        if (fFirst) {
1716 >            f.complete(v1);
1717 >            g.complete(v2);
1718 >        } else {
1719 >            g.complete(v2);
1720 >            f.complete(v1);
1721 >        }
1722  
1996        f.complete(v1);
1997        g.complete(v2);
1723          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1724  
1725          checkCompletedNormally(f, v1);
# Line 2012 | Line 1737 | public class CompletableFutureTest exten
1737       */
1738      public void testApplyToEither_exceptionalCompletion1() {
1739          for (ExecutionMode m : ExecutionMode.values())
1740 +        for (boolean createIncomplete : new boolean[] { true, false })
1741 +        for (boolean fFirst : new boolean[] { true, false })
1742          for (Integer v1 : new Integer[] { 1, null })
1743      {
1744          final CompletableFuture<Integer> f = new CompletableFuture<>();
1745          final CompletableFuture<Integer> g = new CompletableFuture<>();
2019        final IncFunction r = new IncFunction();
2020        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1746          final CFException ex = new CFException();
1747 +        final IncFunction r = new IncFunction(m);
1748  
1749 <        f.completeExceptionally(ex);
2024 <        checkCompletedWithWrappedCFException(h, ex);
2025 <        g.complete(v1);
2026 <
2027 <        assertEquals(0, r.invocationCount);
2028 <        checkCompletedNormally(g, v1);
2029 <        checkCompletedWithWrappedCFException(f, ex);
2030 <        checkCompletedWithWrappedCFException(h, ex);
2031 <    }}
2032 <
2033 <    public void testApplyToEither_exceptionalCompletion2() {
2034 <        for (ExecutionMode m : ExecutionMode.values())
2035 <        for (Integer v1 : new Integer[] { 1, null })
2036 <    {
2037 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2038 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2039 <        final IncFunction r = new IncFunction();
1749 >        if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex);
1750          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1751 <        final CFException ex = new CFException();
1751 >        if (createIncomplete) {
1752 >            checkIncomplete(h);
1753 >            assertEquals(0, r.invocationCount);
1754 >            (fFirst ? f : g).completeExceptionally(ex);
1755 >        }
1756  
2043        g.completeExceptionally(ex);
1757          checkCompletedWithWrappedCFException(h, ex);
1758 <        f.complete(v1);
1758 >        (!fFirst ? f : g).complete(v1);
1759  
1760          assertEquals(0, r.invocationCount);
1761 <        checkCompletedNormally(f, v1);
1762 <        checkCompletedWithWrappedCFException(g, ex);
1761 >        checkCompletedNormally(!fFirst ? f : g, v1);
1762 >        checkCompletedWithWrappedCFException(fFirst ? f : g, ex);
1763          checkCompletedWithWrappedCFException(h, ex);
1764      }}
1765  
1766 <    public void testApplyToEither_exceptionalCompletion3() {
1766 >    public void testApplyToEither_exceptionalCompletion2() {
1767          for (ExecutionMode m : ExecutionMode.values())
1768 +        for (boolean reverseArgs : new boolean[] { true, false })
1769 +        for (boolean fFirst : new boolean[] { true, false })
1770          for (Integer v1 : new Integer[] { 1, null })
1771      {
1772          final CompletableFuture<Integer> f = new CompletableFuture<>();
1773          final CompletableFuture<Integer> g = new CompletableFuture<>();
1774 <        final IncFunction r = new IncFunction();
1774 >        final IncFunction r1 = new IncFunction(m);
1775 >        final IncFunction r2 = new IncFunction(m);
1776          final CFException ex = new CFException();
1777 <
1778 <        g.completeExceptionally(ex);
1779 <        f.complete(v1);
1780 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1777 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1778 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1779 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1780 >        if (fFirst) {
1781 >            f.complete(v1);
1782 >            g.completeExceptionally(ex);
1783 >        } else {
1784 >            g.completeExceptionally(ex);
1785 >            f.complete(v1);
1786 >        }
1787 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1788  
1789          // unspecified behavior
2067        Integer v;
1790          try {
1791 <            assertEquals(inc(v1), h.join());
1792 <            assertEquals(1, r.invocationCount);
1791 >            assertEquals(inc(v1), h1.join());
1792 >            assertEquals(1, r1.invocationCount);
1793          } catch (CompletionException ok) {
1794 <            checkCompletedWithWrappedCFException(h, ex);
1795 <            assertEquals(0, r.invocationCount);
1794 >            checkCompletedWithWrappedCFException(h1, ex);
1795 >            assertEquals(0, r1.invocationCount);
1796          }
1797  
2076        checkCompletedWithWrappedCFException(g, ex);
2077        checkCompletedNormally(f, v1);
2078    }}
2079
2080    public void testApplyToEither_exceptionalCompletion4() {
2081        for (ExecutionMode m : ExecutionMode.values())
2082        for (Integer v1 : new Integer[] { 1, null })
2083    {
2084        final CompletableFuture<Integer> f = new CompletableFuture<>();
2085        final CompletableFuture<Integer> g = new CompletableFuture<>();
2086        final IncFunction r = new IncFunction();
2087        final CFException ex = new CFException();
2088
2089        f.completeExceptionally(ex);
2090        g.complete(v1);
2091        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2092
2093        // unspecified behavior
2094        Integer v;
1798          try {
1799 <            assertEquals(inc(v1), h.join());
1800 <            assertEquals(1, r.invocationCount);
1799 >            assertEquals(inc(v1), h2.join());
1800 >            assertEquals(1, r2.invocationCount);
1801          } catch (CompletionException ok) {
1802 <            checkCompletedWithWrappedCFException(h, ex);
1803 <            assertEquals(0, r.invocationCount);
1802 >            checkCompletedWithWrappedCFException(h2, ex);
1803 >            assertEquals(0, r2.invocationCount);
1804          }
1805  
1806 <        checkCompletedWithWrappedCFException(f, ex);
1807 <        checkCompletedNormally(g, v1);
1806 >        checkCompletedWithWrappedCFException(g, ex);
1807 >        checkCompletedNormally(f, v1);
1808      }}
1809  
1810      /**
# Line 2114 | Line 1817 | public class CompletableFutureTest exten
1817      {
1818          final CompletableFuture<Integer> f = new CompletableFuture<>();
1819          final CompletableFuture<Integer> g = new CompletableFuture<>();
1820 <        final FailingFunction r = new FailingFunction();
1820 >        final FailingFunction r = new FailingFunction(m);
1821          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1822  
1823          f.complete(v1);
# Line 2131 | Line 1834 | public class CompletableFutureTest exten
1834      {
1835          final CompletableFuture<Integer> f = new CompletableFuture<>();
1836          final CompletableFuture<Integer> g = new CompletableFuture<>();
1837 <        final FailingFunction r = new FailingFunction();
1837 >        final FailingFunction r = new FailingFunction(m);
1838          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1839  
1840          g.complete(v2);
# Line 2147 | Line 1850 | public class CompletableFutureTest exten
1850      public void testApplyToEither_sourceCancelled1() {
1851          for (ExecutionMode m : ExecutionMode.values())
1852          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1853 +        for (boolean createIncomplete : new boolean[] { true, false })
1854 +        for (boolean fFirst : new boolean[] { true, false })
1855          for (Integer v1 : new Integer[] { 1, null })
1856      {
1857          final CompletableFuture<Integer> f = new CompletableFuture<>();
1858          final CompletableFuture<Integer> g = new CompletableFuture<>();
1859 <        final IncFunction r = new IncFunction();
2155 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1859 >        final IncFunction r = new IncFunction(m);
1860  
1861 <        assertTrue(f.cancel(mayInterruptIfRunning));
2158 <        checkCompletedWithWrappedCancellationException(h);
2159 <        g.complete(v1);
2160 <
2161 <        checkCancelled(f);
2162 <        assertEquals(0, r.invocationCount);
2163 <        checkCompletedNormally(g, v1);
2164 <        checkCompletedWithWrappedCancellationException(h);
2165 <    }}
2166 <
2167 <    public void testApplyToEither_sourceCancelled2() {
2168 <        for (ExecutionMode m : ExecutionMode.values())
2169 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2170 <        for (Integer v1 : new Integer[] { 1, null })
2171 <    {
2172 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2173 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2174 <        final IncFunction r = new IncFunction();
1861 >        if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1862          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1863 +        if (createIncomplete) {
1864 +            checkIncomplete(h);
1865 +            assertEquals(0, r.invocationCount);
1866 +            assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1867 +        }
1868  
2177        assertTrue(g.cancel(mayInterruptIfRunning));
1869          checkCompletedWithWrappedCancellationException(h);
1870 <        f.complete(v1);
1870 >        (!fFirst ? f : g).complete(v1);
1871  
2181        checkCancelled(g);
1872          assertEquals(0, r.invocationCount);
1873 <        checkCompletedNormally(f, v1);
1873 >        checkCompletedNormally(!fFirst ? f : g, v1);
1874 >        checkCancelled(fFirst ? f : g);
1875          checkCompletedWithWrappedCancellationException(h);
1876      }}
1877  
1878 <    public void testApplyToEither_sourceCancelled3() {
1878 >    public void testApplyToEither_sourceCancelled2() {
1879          for (ExecutionMode m : ExecutionMode.values())
1880          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1881 +        for (boolean reverseArgs : new boolean[] { true, false })
1882 +        for (boolean fFirst : new boolean[] { true, false })
1883          for (Integer v1 : new Integer[] { 1, null })
1884      {
1885          final CompletableFuture<Integer> f = new CompletableFuture<>();
1886          final CompletableFuture<Integer> g = new CompletableFuture<>();
1887 <        final IncFunction r = new IncFunction();
1887 >        final IncFunction r1 = new IncFunction(m);
1888 >        final IncFunction r2 = new IncFunction(m);
1889 >        final CFException ex = new CFException();
1890 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1891 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1892  
1893 <        assertTrue(g.cancel(mayInterruptIfRunning));
1894 <        f.complete(v1);
1895 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1893 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1894 >        if (fFirst) {
1895 >            f.complete(v1);
1896 >            assertTrue(g.cancel(mayInterruptIfRunning));
1897 >        } else {
1898 >            assertTrue(g.cancel(mayInterruptIfRunning));
1899 >            f.complete(v1);
1900 >        }
1901 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1902  
1903          // unspecified behavior
2201        Integer v;
1904          try {
1905 <            assertEquals(inc(v1), h.join());
1906 <            assertEquals(1, r.invocationCount);
1905 >            assertEquals(inc(v1), h1.join());
1906 >            assertEquals(1, r1.invocationCount);
1907          } catch (CompletionException ok) {
1908 <            checkCompletedWithWrappedCancellationException(h);
1909 <            assertEquals(0, r.invocationCount);
1908 >            checkCompletedWithWrappedCancellationException(h1);
1909 >            assertEquals(0, r1.invocationCount);
1910          }
1911  
2210        checkCancelled(g);
2211        checkCompletedNormally(f, v1);
2212    }}
2213
2214    public void testApplyToEither_sourceCancelled4() {
2215        for (ExecutionMode m : ExecutionMode.values())
2216        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2217        for (Integer v1 : new Integer[] { 1, null })
2218    {
2219        final CompletableFuture<Integer> f = new CompletableFuture<>();
2220        final CompletableFuture<Integer> g = new CompletableFuture<>();
2221        final IncFunction r = new IncFunction();
2222
2223        assertTrue(f.cancel(mayInterruptIfRunning));
2224        g.complete(v1);
2225        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2226
2227        // unspecified behavior
2228        Integer v;
1912          try {
1913 <            assertEquals(inc(v1), h.join());
1914 <            assertEquals(1, r.invocationCount);
1913 >            assertEquals(inc(v1), h2.join());
1914 >            assertEquals(1, r2.invocationCount);
1915          } catch (CompletionException ok) {
1916 <            checkCompletedWithWrappedCancellationException(h);
1917 <            assertEquals(0, r.invocationCount);
1916 >            checkCompletedWithWrappedCancellationException(h2);
1917 >            assertEquals(0, r2.invocationCount);
1918          }
1919  
1920 <        checkCancelled(f);
1921 <        checkCompletedNormally(g, v1);
1920 >        checkCancelled(g);
1921 >        checkCompletedNormally(f, v1);
1922      }}
1923  
1924      /**
# Line 2414 | Line 2097 | public class CompletableFutureTest exten
2097      {
2098          final CompletableFuture<Integer> f = new CompletableFuture<>();
2099          final CompletableFuture<Integer> g = new CompletableFuture<>();
2100 <        final FailingConsumer r = new FailingConsumer();
2100 >        final FailingConsumer r = new FailingConsumer(m);
2101          final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2102  
2103          f.complete(v1);
# Line 2431 | Line 2114 | public class CompletableFutureTest exten
2114      {
2115          final CompletableFuture<Integer> f = new CompletableFuture<>();
2116          final CompletableFuture<Integer> g = new CompletableFuture<>();
2117 <        final FailingConsumer r = new FailingConsumer();
2117 >        final FailingConsumer r = new FailingConsumer(m);
2118          final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2119  
2120          g.complete(v2);
# Line 2551 | Line 2234 | public class CompletableFutureTest exten
2234      {
2235          final CompletableFuture<Integer> f = new CompletableFuture<>();
2236          final CompletableFuture<Integer> g = new CompletableFuture<>();
2237 <        final Noop r = new Noop();
2237 >        final Noop r = new Noop(m);
2238          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2239  
2240          f.complete(v1);
# Line 2572 | Line 2255 | public class CompletableFutureTest exten
2255      {
2256          final CompletableFuture<Integer> f = new CompletableFuture<>();
2257          final CompletableFuture<Integer> g = new CompletableFuture<>();
2258 <        final Noop r = new Noop();
2258 >        final Noop r = new Noop(m);
2259          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2260  
2261          g.complete(v2);
# Line 2593 | Line 2276 | public class CompletableFutureTest exten
2276      {
2277          final CompletableFuture<Integer> f = new CompletableFuture<>();
2278          final CompletableFuture<Integer> g = new CompletableFuture<>();
2279 <        final Noop r = new Noop();
2279 >        final Noop r = new Noop(m);
2280  
2281          f.complete(v1);
2282          g.complete(v2);
# Line 2615 | Line 2298 | public class CompletableFutureTest exten
2298      {
2299          final CompletableFuture<Integer> f = new CompletableFuture<>();
2300          final CompletableFuture<Integer> g = new CompletableFuture<>();
2301 <        final Noop r = new Noop();
2301 >        final Noop r = new Noop(m);
2302          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2303          final CFException ex = new CFException();
2304  
# Line 2635 | Line 2318 | public class CompletableFutureTest exten
2318      {
2319          final CompletableFuture<Integer> f = new CompletableFuture<>();
2320          final CompletableFuture<Integer> g = new CompletableFuture<>();
2321 <        final Noop r = new Noop();
2321 >        final Noop r = new Noop(m);
2322          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2323          final CFException ex = new CFException();
2324  
# Line 2655 | Line 2338 | public class CompletableFutureTest exten
2338      {
2339          final CompletableFuture<Integer> f = new CompletableFuture<>();
2340          final CompletableFuture<Integer> g = new CompletableFuture<>();
2341 <        final Noop r = new Noop();
2341 >        final Noop r = new Noop(m);
2342          final CFException ex = new CFException();
2343  
2344          g.completeExceptionally(ex);
# Line 2682 | Line 2365 | public class CompletableFutureTest exten
2365      {
2366          final CompletableFuture<Integer> f = new CompletableFuture<>();
2367          final CompletableFuture<Integer> g = new CompletableFuture<>();
2368 <        final Noop r = new Noop();
2368 >        final Noop r = new Noop(m);
2369          final CFException ex = new CFException();
2370  
2371          f.completeExceptionally(ex);
# Line 2713 | Line 2396 | public class CompletableFutureTest exten
2396      {
2397          final CompletableFuture<Integer> f = new CompletableFuture<>();
2398          final CompletableFuture<Integer> g = new CompletableFuture<>();
2399 <        final FailingNoop r = new FailingNoop();
2399 >        final FailingRunnable r = new FailingRunnable(m);
2400          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2401  
2402          f.complete(v1);
# Line 2730 | Line 2413 | public class CompletableFutureTest exten
2413      {
2414          final CompletableFuture<Integer> f = new CompletableFuture<>();
2415          final CompletableFuture<Integer> g = new CompletableFuture<>();
2416 <        final FailingNoop r = new FailingNoop();
2416 >        final FailingRunnable r = new FailingRunnable(m);
2417          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2418  
2419          g.complete(v2);
# Line 2750 | Line 2433 | public class CompletableFutureTest exten
2433      {
2434          final CompletableFuture<Integer> f = new CompletableFuture<>();
2435          final CompletableFuture<Integer> g = new CompletableFuture<>();
2436 <        final Noop r = new Noop();
2436 >        final Noop r = new Noop(m);
2437          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2438  
2439          assertTrue(f.cancel(mayInterruptIfRunning));
# Line 2770 | Line 2453 | public class CompletableFutureTest exten
2453      {
2454          final CompletableFuture<Integer> f = new CompletableFuture<>();
2455          final CompletableFuture<Integer> g = new CompletableFuture<>();
2456 <        final Noop r = new Noop();
2456 >        final Noop r = new Noop(m);
2457          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2458  
2459          assertTrue(g.cancel(mayInterruptIfRunning));
# Line 2790 | Line 2473 | public class CompletableFutureTest exten
2473      {
2474          final CompletableFuture<Integer> f = new CompletableFuture<>();
2475          final CompletableFuture<Integer> g = new CompletableFuture<>();
2476 <        final Noop r = new Noop();
2476 >        final Noop r = new Noop(m);
2477  
2478          assertTrue(g.cancel(mayInterruptIfRunning));
2479          f.complete(v1);
# Line 2817 | Line 2500 | public class CompletableFutureTest exten
2500      {
2501          final CompletableFuture<Integer> f = new CompletableFuture<>();
2502          final CompletableFuture<Integer> g = new CompletableFuture<>();
2503 <        final Noop r = new Noop();
2503 >        final Noop r = new Noop(m);
2504  
2505          assertTrue(f.cancel(mayInterruptIfRunning));
2506          g.complete(v1);
# Line 2840 | Line 2523 | public class CompletableFutureTest exten
2523      /**
2524       * thenCompose result completes normally after normal completion of source
2525       */
2526 <    public void testThenCompose_normalCompletion1() {
2526 >    public void testThenCompose_normalCompletion() {
2527          for (ExecutionMode m : ExecutionMode.values())
2528 +        for (boolean createIncomplete : new boolean[] { true, false })
2529          for (Integer v1 : new Integer[] { 1, null })
2530      {
2531          final CompletableFuture<Integer> f = new CompletableFuture<>();
2532 <        final CompletableFutureInc r = new CompletableFutureInc();
2533 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2534 <        f.complete(v1);
2535 <        checkCompletedNormally(g, inc(v1));
2852 <        checkCompletedNormally(f, v1);
2853 <        assertEquals(1, r.invocationCount);
2854 <    }}
2532 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2533 >        if (!createIncomplete) f.complete(v1);
2534 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2535 >        if (createIncomplete) f.complete(v1);
2536  
2856    public void testThenCompose_normalCompletion2() {
2857        for (ExecutionMode m : ExecutionMode.values())
2858        for (Integer v1 : new Integer[] { 1, null })
2859    {
2860        final CompletableFuture<Integer> f = new CompletableFuture<>();
2861        final CompletableFutureInc r = new CompletableFutureInc();
2862        f.complete(v1);
2863        final CompletableFuture<Integer> g = f.thenCompose(r);
2537          checkCompletedNormally(g, inc(v1));
2538          checkCompletedNormally(f, v1);
2539          assertEquals(1, r.invocationCount);
# Line 2870 | Line 2543 | public class CompletableFutureTest exten
2543       * thenCompose result completes exceptionally after exceptional
2544       * completion of source
2545       */
2546 <    public void testThenCompose_exceptionalCompletion1() {
2546 >    public void testThenCompose_exceptionalCompletion() {
2547          for (ExecutionMode m : ExecutionMode.values())
2548 +        for (boolean createIncomplete : new boolean[] { true, false })
2549      {
2550          final CFException ex = new CFException();
2551 <        final CompletableFutureInc r = new CompletableFutureInc();
2551 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2552          final CompletableFuture<Integer> f = new CompletableFuture<>();
2553 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2554 <        f.completeExceptionally(ex);
2555 <        checkCompletedWithWrappedCFException(g, ex);
2882 <        checkCompletedWithWrappedCFException(f, ex);
2883 <    }}
2553 >        if (!createIncomplete) f.completeExceptionally(ex);
2554 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2555 >        if (createIncomplete) f.completeExceptionally(ex);
2556  
2885    public void testThenCompose_exceptionalCompletion2() {
2886        for (ExecutionMode m : ExecutionMode.values())
2887    {
2888        final CFException ex = new CFException();
2889        final CompletableFuture<Integer> f = new CompletableFuture<>();
2890        f.completeExceptionally(ex);
2891        final CompletableFutureInc r = new CompletableFutureInc();
2892        final CompletableFuture<Integer> g = f.thenCompose(r);
2557          checkCompletedWithWrappedCFException(g, ex);
2558          checkCompletedWithWrappedCFException(f, ex);
2559 +        assertEquals(0, r.invocationCount);
2560      }}
2561  
2562      /**
2563       * thenCompose result completes exceptionally if action does
2564       */
2565 <    public void testThenCompose_actionFailed1() {
2565 >    public void testThenCompose_actionFailed() {
2566          for (ExecutionMode m : ExecutionMode.values())
2567 +        for (boolean createIncomplete : new boolean[] { true, false })
2568          for (Integer v1 : new Integer[] { 1, null })
2569      {
2570          final CompletableFuture<Integer> f = new CompletableFuture<>();
2571          final FailingCompletableFutureFunction r
2572 <            = new FailingCompletableFutureFunction();
2573 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2574 <        f.complete(v1);
2575 <        checkCompletedWithWrappedCFException(g);
2910 <        checkCompletedNormally(f, v1);
2911 <    }}
2572 >            = new FailingCompletableFutureFunction(m);
2573 >        if (!createIncomplete) f.complete(v1);
2574 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2575 >        if (createIncomplete) f.complete(v1);
2576  
2913    public void testThenCompose_actionFailed2() {
2914        for (ExecutionMode m : ExecutionMode.values())
2915        for (Integer v1 : new Integer[] { 1, null })
2916    {
2917        final CompletableFuture<Integer> f = new CompletableFuture<>();
2918        f.complete(v1);
2919        final FailingCompletableFutureFunction r
2920            = new FailingCompletableFutureFunction();
2921        final CompletableFuture<Integer> g = f.thenCompose(r);
2577          checkCompletedWithWrappedCFException(g);
2578          checkCompletedNormally(f, v1);
2579      }}
# Line 2926 | Line 2581 | public class CompletableFutureTest exten
2581      /**
2582       * thenCompose result completes exceptionally if source cancelled
2583       */
2584 <    public void testThenCompose_sourceCancelled1() {
2584 >    public void testThenCompose_sourceCancelled() {
2585          for (ExecutionMode m : ExecutionMode.values())
2586 +        for (boolean createIncomplete : new boolean[] { true, false })
2587          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2588      {
2589          final CompletableFuture<Integer> f = new CompletableFuture<>();
2590 <        final CompletableFutureInc r = new CompletableFutureInc();
2591 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2592 <        assertTrue(f.cancel(mayInterruptIfRunning));
2593 <        checkCompletedWithWrappedCancellationException(g);
2594 <        checkCancelled(f);
2595 <    }}
2590 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2591 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2592 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2593 >        if (createIncomplete) {
2594 >            checkIncomplete(g);
2595 >            assertTrue(f.cancel(mayInterruptIfRunning));
2596 >        }
2597  
2941    public void testThenCompose_sourceCancelled2() {
2942        for (ExecutionMode m : ExecutionMode.values())
2943        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2944    {
2945        final CompletableFuture<Integer> f = new CompletableFuture<>();
2946        assertTrue(f.cancel(mayInterruptIfRunning));
2947        final CompletableFutureInc r = new CompletableFutureInc();
2948        final CompletableFuture<Integer> g = f.thenCompose(r);
2598          checkCompletedWithWrappedCancellationException(g);
2599          checkCancelled(f);
2600      }}
2601  
2953    // asyncs
2954
2955    /**
2956     * thenRunAsync result completes normally after normal completion of source
2957     */
2958    public void testThenRunAsync() {
2959        CompletableFuture<Integer> f = new CompletableFuture<>();
2960        Noop r = new Noop();
2961        CompletableFuture<Void> g = f.thenRunAsync(r);
2962        f.complete(null);
2963        checkCompletedNormally(g, null);
2964
2965        // reordered version
2966        f = new CompletableFuture<>();
2967        f.complete(null);
2968        r = new Noop();
2969        g = f.thenRunAsync(r);
2970        checkCompletedNormally(g, null);
2971    }
2972
2973    /**
2974     * thenRunAsync result completes exceptionally after exceptional
2975     * completion of source
2976     */
2977    public void testThenRunAsync2() {
2978        CompletableFuture<Integer> f = new CompletableFuture<>();
2979        Noop r = new Noop();
2980        CompletableFuture<Void> g = f.thenRunAsync(r);
2981        f.completeExceptionally(new CFException());
2982        try {
2983            g.join();
2984            shouldThrow();
2985        } catch (CompletionException success) {}
2986        checkCompletedWithWrappedCFException(g);
2987    }
2988
2989    /**
2990     * thenRunAsync result completes exceptionally if action does
2991     */
2992    public void testThenRunAsync3() {
2993        CompletableFuture<Integer> f = new CompletableFuture<>();
2994        FailingNoop r = new FailingNoop();
2995        CompletableFuture<Void> g = f.thenRunAsync(r);
2996        f.complete(null);
2997        checkCompletedWithWrappedCFException(g);
2998    }
2999
3000    /**
3001     * thenRunAsync result completes exceptionally if source cancelled
3002     */
3003    public void testThenRunAsync4() {
3004        CompletableFuture<Integer> f = new CompletableFuture<>();
3005        Noop r = new Noop();
3006        CompletableFuture<Void> g = f.thenRunAsync(r);
3007        assertTrue(f.cancel(true));
3008        checkCompletedWithWrappedCancellationException(g);
3009    }
3010
3011    /**
3012     * thenApplyAsync result completes normally after normal completion of source
3013     */
3014    public void testThenApplyAsync() {
3015        CompletableFuture<Integer> f = new CompletableFuture<>();
3016        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
3017        f.complete(one);
3018        checkCompletedNormally(g, two);
3019    }
3020
3021    /**
3022     * thenApplyAsync result completes exceptionally after exceptional
3023     * completion of source
3024     */
3025    public void testThenApplyAsync2() {
3026        CompletableFuture<Integer> f = new CompletableFuture<>();
3027        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
3028        f.completeExceptionally(new CFException());
3029        checkCompletedWithWrappedCFException(g);
3030    }
3031
3032    /**
3033     * thenApplyAsync result completes exceptionally if action does
3034     */
3035    public void testThenApplyAsync3() {
3036        CompletableFuture<Integer> f = new CompletableFuture<>();
3037        FailingFunction r = new FailingFunction();
3038        CompletableFuture<Integer> g = f.thenApplyAsync(r);
3039        f.complete(null);
3040        checkCompletedWithWrappedCFException(g);
3041    }
3042
3043    /**
3044     * thenApplyAsync result completes exceptionally if source cancelled
3045     */
3046    public void testThenApplyAsync4() {
3047        CompletableFuture<Integer> f = new CompletableFuture<>();
3048        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
3049        assertTrue(f.cancel(true));
3050        checkCompletedWithWrappedCancellationException(g);
3051    }
3052
3053    /**
3054     * thenAcceptAsync result completes normally after normal
3055     * completion of source
3056     */
3057    public void testThenAcceptAsync() {
3058        CompletableFuture<Integer> f = new CompletableFuture<>();
3059        IncAction r = new IncAction();
3060        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3061        f.complete(one);
3062        checkCompletedNormally(g, null);
3063        assertEquals(r.value, (Integer) 2);
3064    }
3065
3066    /**
3067     * thenAcceptAsync result completes exceptionally after exceptional
3068     * completion of source
3069     */
3070    public void testThenAcceptAsync2() {
3071        CompletableFuture<Integer> f = new CompletableFuture<>();
3072        IncAction r = new IncAction();
3073        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3074        f.completeExceptionally(new CFException());
3075        checkCompletedWithWrappedCFException(g);
3076    }
3077
3078    /**
3079     * thenAcceptAsync result completes exceptionally if action does
3080     */
3081    public void testThenAcceptAsync3() {
3082        CompletableFuture<Integer> f = new CompletableFuture<>();
3083        FailingConsumer r = new FailingConsumer();
3084        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3085        f.complete(null);
3086        checkCompletedWithWrappedCFException(g);
3087    }
3088
3089    /**
3090     * thenAcceptAsync result completes exceptionally if source cancelled
3091     */
3092    public void testThenAcceptAsync4() {
3093        CompletableFuture<Integer> f = new CompletableFuture<>();
3094        IncAction r = new IncAction();
3095        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3096        assertTrue(f.cancel(true));
3097        checkCompletedWithWrappedCancellationException(g);
3098    }
3099
3100    // async with explicit executors
3101
3102    /**
3103     * thenRunAsync result completes normally after normal completion of source
3104     */
3105    public void testThenRunAsyncE() {
3106        CompletableFuture<Integer> f = new CompletableFuture<>();
3107        Noop r = new Noop();
3108        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3109        f.complete(null);
3110        checkCompletedNormally(g, null);
3111
3112        // reordered version
3113        f = new CompletableFuture<>();
3114        f.complete(null);
3115        r = new Noop();
3116        g = f.thenRunAsync(r, new ThreadExecutor());
3117        checkCompletedNormally(g, null);
3118    }
3119
3120    /**
3121     * thenRunAsync result completes exceptionally after exceptional
3122     * completion of source
3123     */
3124    public void testThenRunAsync2E() {
3125        CompletableFuture<Integer> f = new CompletableFuture<>();
3126        Noop r = new Noop();
3127        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3128        f.completeExceptionally(new CFException());
3129        try {
3130            g.join();
3131            shouldThrow();
3132        } catch (CompletionException success) {}
3133        checkCompletedWithWrappedCFException(g);
3134    }
3135
3136    /**
3137     * thenRunAsync result completes exceptionally if action does
3138     */
3139    public void testThenRunAsync3E() {
3140        CompletableFuture<Integer> f = new CompletableFuture<>();
3141        FailingNoop r = new FailingNoop();
3142        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3143        f.complete(null);
3144        checkCompletedWithWrappedCFException(g);
3145    }
3146
3147    /**
3148     * thenRunAsync result completes exceptionally if source cancelled
3149     */
3150    public void testThenRunAsync4E() {
3151        CompletableFuture<Integer> f = new CompletableFuture<>();
3152        Noop r = new Noop();
3153        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3154        assertTrue(f.cancel(true));
3155        checkCompletedWithWrappedCancellationException(g);
3156    }
3157
3158    /**
3159     * thenApplyAsync result completes normally after normal completion of source
3160     */
3161    public void testThenApplyAsyncE() {
3162        CompletableFuture<Integer> f = new CompletableFuture<>();
3163        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3164        f.complete(one);
3165        checkCompletedNormally(g, two);
3166    }
3167
3168    /**
3169     * thenApplyAsync result completes exceptionally after exceptional
3170     * completion of source
3171     */
3172    public void testThenApplyAsync2E() {
3173        CompletableFuture<Integer> f = new CompletableFuture<>();
3174        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3175        f.completeExceptionally(new CFException());
3176        checkCompletedWithWrappedCFException(g);
3177    }
3178
3179    /**
3180     * thenApplyAsync result completes exceptionally if action does
3181     */
3182    public void testThenApplyAsync3E() {
3183        CompletableFuture<Integer> f = new CompletableFuture<>();
3184        FailingFunction r = new FailingFunction();
3185        CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
3186        f.complete(null);
3187        checkCompletedWithWrappedCFException(g);
3188    }
3189
3190    /**
3191     * thenApplyAsync result completes exceptionally if source cancelled
3192     */
3193    public void testThenApplyAsync4E() {
3194        CompletableFuture<Integer> f = new CompletableFuture<>();
3195        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3196        assertTrue(f.cancel(true));
3197        checkCompletedWithWrappedCancellationException(g);
3198    }
3199
3200    /**
3201     * thenAcceptAsync result completes normally after normal
3202     * completion of source
3203     */
3204    public void testThenAcceptAsyncE() {
3205        CompletableFuture<Integer> f = new CompletableFuture<>();
3206        IncAction r = new IncAction();
3207        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3208        f.complete(one);
3209        checkCompletedNormally(g, null);
3210        assertEquals(r.value, (Integer) 2);
3211    }
3212
3213    /**
3214     * thenAcceptAsync result completes exceptionally after exceptional
3215     * completion of source
3216     */
3217    public void testThenAcceptAsync2E() {
3218        CompletableFuture<Integer> f = new CompletableFuture<>();
3219        IncAction r = new IncAction();
3220        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3221        f.completeExceptionally(new CFException());
3222        checkCompletedWithWrappedCFException(g);
3223    }
3224
3225    /**
3226     * thenAcceptAsync result completes exceptionally if action does
3227     */
3228    public void testThenAcceptAsync3E() {
3229        CompletableFuture<Integer> f = new CompletableFuture<>();
3230        FailingConsumer r = new FailingConsumer();
3231        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3232        f.complete(null);
3233        checkCompletedWithWrappedCFException(g);
3234    }
3235
3236    /**
3237     * thenAcceptAsync result completes exceptionally if source cancelled
3238     */
3239    public void testThenAcceptAsync4E() {
3240        CompletableFuture<Integer> f = new CompletableFuture<>();
3241        IncAction r = new IncAction();
3242        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3243        assertTrue(f.cancel(true));
3244        checkCompletedWithWrappedCancellationException(g);
3245    }
3246
2602      // other static methods
2603  
2604      /**
# Line 3261 | Line 2616 | public class CompletableFutureTest exten
2616       */
2617      public void testAllOf_normal() throws Exception {
2618          for (int k = 1; k < 20; ++k) {
2619 <            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2619 >            CompletableFuture<Integer>[] fs
2620 >                = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2621              for (int i = 0; i < k; ++i)
2622                  fs[i] = new CompletableFuture<>();
2623              CompletableFuture<Void> f = CompletableFuture.allOf(fs);
# Line 3275 | Line 2631 | public class CompletableFutureTest exten
2631          }
2632      }
2633  
2634 +    public void testAllOf_backwards() throws Exception {
2635 +        for (int k = 1; k < 20; ++k) {
2636 +            CompletableFuture<Integer>[] fs
2637 +                = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2638 +            for (int i = 0; i < k; ++i)
2639 +                fs[i] = new CompletableFuture<>();
2640 +            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2641 +            for (int i = k - 1; i >= 0; i--) {
2642 +                checkIncomplete(f);
2643 +                checkIncomplete(CompletableFuture.allOf(fs));
2644 +                fs[i].complete(one);
2645 +            }
2646 +            checkCompletedNormally(f, null);
2647 +            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2648 +        }
2649 +    }
2650 +
2651      /**
2652       * anyOf(no component futures) returns an incomplete future
2653       */
# Line 3333 | Line 2706 | public class CompletableFutureTest exten
2706          Runnable[] throwingActions = {
2707              () -> CompletableFuture.supplyAsync(null),
2708              () -> CompletableFuture.supplyAsync(null, exec),
2709 <            () -> CompletableFuture.supplyAsync(supplyOne, null),
2709 >            () -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.DEFAULT, 42), null),
2710  
2711              () -> CompletableFuture.runAsync(null),
2712              () -> CompletableFuture.runAsync(null, exec),
# Line 3406 | Line 2779 | public class CompletableFutureTest exten
2779  
2780              () -> f.thenCompose(null),
2781              () -> f.thenComposeAsync(null),
2782 <            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
2782 >            () -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null),
2783              () -> f.thenComposeAsync(null, exec),
2784  
2785              () -> f.exceptionally(null),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines