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.48 by jsr166, Mon Jun 2 19:07:14 2014 UTC vs.
Revision 1.56 by jsr166, Mon Jun 2 22:20:32 2014 UTC

# Line 284 | 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 349 | 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      static final class SubtractAction implements BiConsumer<Integer, Integer> {
363 +        final ExecutionMode m;
364          int invocationCount = 0;
365          Integer value;
366          // Check this action was invoked exactly once when result is computed.
367 +        SubtractAction(ExecutionMode m) { this.m = m; }
368          public void accept(Integer x, Integer y) {
369 +            m.checkExecutionMode();
370              invocationCount++;
371              value = subtract(x, y);
372          }
373      }
374      static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> {
375 +        final ExecutionMode m;
376          int invocationCount = 0;
377          Integer value;
378          // Check this action was invoked exactly once when result is computed.
379 +        SubtractFunction(ExecutionMode m) { this.m = m; }
380          public Integer apply(Integer x, Integer y) {
381 +            m.checkExecutionMode();
382              invocationCount++;
383              return value = subtract(x, y);
384          }
385      }
386      static final class Noop implements Runnable {
387 +        final ExecutionMode m;
388          int invocationCount = 0;
389 +        Noop(ExecutionMode m) { this.m = m; }
390          public void run() {
391 +            m.checkExecutionMode();
392              invocationCount++;
393          }
394      }
395  
396      static final class FailingSupplier implements Supplier<Integer> {
397 +        final ExecutionMode m;
398          int invocationCount = 0;
399 +        FailingSupplier(ExecutionMode m) { this.m = m; }
400          public Integer get() {
401 +            m.checkExecutionMode();
402              invocationCount++;
403              throw new CFException();
404          }
405      }
406      static final class FailingConsumer implements Consumer<Integer> {
407 +        final ExecutionMode m;
408          int invocationCount = 0;
409 +        FailingConsumer(ExecutionMode m) { this.m = m; }
410          public void accept(Integer x) {
411 +            m.checkExecutionMode();
412              invocationCount++;
413              throw new CFException();
414          }
415      }
416      static final class FailingBiConsumer implements BiConsumer<Integer, Integer> {
417 +        final ExecutionMode m;
418          int invocationCount = 0;
419 +        FailingBiConsumer(ExecutionMode m) { this.m = m; }
420          public void accept(Integer x, Integer y) {
421 +            m.checkExecutionMode();
422              invocationCount++;
423              throw new CFException();
424          }
425      }
426      static final class FailingFunction implements Function<Integer, Integer> {
427 +        final ExecutionMode m;
428          int invocationCount = 0;
429 +        FailingFunction(ExecutionMode m) { this.m = m; }
430          public Integer apply(Integer x) {
431 +            m.checkExecutionMode();
432              invocationCount++;
433              throw new CFException();
434          }
435      }
436      static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> {
437 +        final ExecutionMode m;
438          int invocationCount = 0;
439 +        FailingBiFunction(ExecutionMode m) { this.m = m; }
440          public Integer apply(Integer x, Integer y) {
441 +            m.checkExecutionMode();
442              invocationCount++;
443              throw new CFException();
444          }
445      }
446 <    static final class FailingNoop implements Runnable {
446 >    static final class FailingRunnable implements Runnable {
447 >        final ExecutionMode m;
448          int invocationCount = 0;
449 +        FailingRunnable(ExecutionMode m) { this.m = m; }
450          public void run() {
451 +            m.checkExecutionMode();
452              invocationCount++;
453              throw new CFException();
454          }
# Line 426 | Line 456 | public class CompletableFutureTest exten
456  
457      static final class CompletableFutureInc
458          implements Function<Integer, CompletableFuture<Integer>> {
459 +        final ExecutionMode m;
460          int invocationCount = 0;
461 +        CompletableFutureInc(ExecutionMode m) { this.m = m; }
462          public CompletableFuture<Integer> apply(Integer x) {
463 +            m.checkExecutionMode();
464              invocationCount++;
465              CompletableFuture<Integer> f = new CompletableFuture<>();
466              f.complete(inc(x));
# Line 437 | Line 470 | public class CompletableFutureTest exten
470  
471      static final class FailingCompletableFutureFunction
472          implements Function<Integer, CompletableFuture<Integer>> {
473 +        final ExecutionMode m;
474          int invocationCount = 0;
475 +        FailingCompletableFutureFunction(ExecutionMode m) { this.m = m; }
476          public CompletableFuture<Integer> apply(Integer x) {
477 +            m.checkExecutionMode();
478              invocationCount++;
479              throw new CFException();
480          }
# Line 446 | Line 482 | public class CompletableFutureTest exten
482  
483      // Used for explicit executor tests
484      static final class ThreadExecutor implements Executor {
485 <        AtomicInteger count = new AtomicInteger(0);
485 >        final AtomicInteger count = new AtomicInteger(0);
486 >        static final ThreadGroup tg = new ThreadGroup("ThreadExecutor");
487 >        static boolean startedCurrentThread() {
488 >            return Thread.currentThread().getThreadGroup() == tg;
489 >        }
490  
491          public void execute(Runnable r) {
492              count.getAndIncrement();
493 <            new Thread(r).start();
493 >            new Thread(tg, r).start();
494          }
495      }
496  
# Line 596 | Line 636 | public class CompletableFutureTest exten
636  
637          EXECUTOR {
638              public void checkExecutionMode() {
639 <                //TODO
639 >                assertTrue(ThreadExecutor.startedCurrentThread());
640              }
641              public <T> CompletableFuture<Void> thenRun
642                  (CompletableFuture<T> f, Runnable a) {
# Line 909 | Line 949 | public class CompletableFutureTest exten
949       * runAsync completes after running Runnable
950       */
951      public void testRunAsync() {
952 <        Noop r = new Noop();
952 >        Noop r = new Noop(ExecutionMode.ASYNC);
953          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
954          assertNull(f.join());
955          assertEquals(1, r.invocationCount);
# Line 920 | Line 960 | public class CompletableFutureTest exten
960       * runAsync with executor completes after running Runnable
961       */
962      public void testRunAsync2() {
963 <        Noop r = new Noop();
963 >        Noop r = new Noop(ExecutionMode.EXECUTOR);
964          ThreadExecutor exec = new ThreadExecutor();
965          CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
966          assertNull(f.join());
# Line 933 | Line 973 | public class CompletableFutureTest exten
973       * failing runAsync completes exceptionally after running Runnable
974       */
975      public void testRunAsync3() {
976 <        FailingNoop r = new FailingNoop();
976 >        FailingRunnable r = new FailingRunnable(ExecutionMode.ASYNC);
977          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
978          checkCompletedWithWrappedCFException(f);
979          assertEquals(1, r.invocationCount);
# Line 963 | Line 1003 | public class CompletableFutureTest exten
1003       * Failing supplyAsync completes exceptionally
1004       */
1005      public void testSupplyAsync3() {
1006 <        FailingSupplier r = new FailingSupplier();
1006 >        FailingSupplier r = new FailingSupplier(ExecutionMode.ASYNC);
1007          CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r);
1008          checkCompletedWithWrappedCFException(f);
1009          assertEquals(1, r.invocationCount);
# Line 980 | Line 1020 | public class CompletableFutureTest exten
1020          for (Integer v1 : new Integer[] { 1, null })
1021      {
1022          final CompletableFuture<Integer> f = new CompletableFuture<>();
1023 <        final Noop r = new Noop();
1023 >        final Noop r = new Noop(m);
1024          if (!createIncomplete) f.complete(v1);
1025          final CompletableFuture<Void> g = m.thenRun(f, r);
1026 <        if (createIncomplete) f.complete(v1);
1026 >        if (createIncomplete) {
1027 >            checkIncomplete(g);
1028 >            f.complete(v1);
1029 >        }
1030  
1031          checkCompletedNormally(g, null);
1032          checkCompletedNormally(f, v1);
# Line 1000 | Line 1043 | public class CompletableFutureTest exten
1043      {
1044          final CFException ex = new CFException();
1045          final CompletableFuture<Integer> f = new CompletableFuture<>();
1046 <        final Noop r = new Noop();
1046 >        final Noop r = new Noop(m);
1047          if (!createIncomplete) f.completeExceptionally(ex);
1048          final CompletableFuture<Void> g = m.thenRun(f, r);
1049 <        if (createIncomplete) f.completeExceptionally(ex);
1049 >        if (createIncomplete) {
1050 >            checkIncomplete(g);
1051 >            f.completeExceptionally(ex);
1052 >        }
1053  
1054          checkCompletedWithWrappedCFException(g, ex);
1055          checkCompletedWithWrappedCFException(f, ex);
# Line 1019 | Line 1065 | public class CompletableFutureTest exten
1065          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1066      {
1067          final CompletableFuture<Integer> f = new CompletableFuture<>();
1068 <        final Noop r = new Noop();
1068 >        final Noop r = new Noop(m);
1069          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1070 <        final CompletableFuture<Void> g = f.thenRun(r);
1071 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1070 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1071 >        if (createIncomplete) {
1072 >            checkIncomplete(g);
1073 >            assertTrue(f.cancel(mayInterruptIfRunning));
1074 >        }
1075  
1076          checkCompletedWithWrappedCancellationException(g);
1077          checkCancelled(f);
# Line 1038 | Line 1087 | public class CompletableFutureTest exten
1087          for (Integer v1 : new Integer[] { 1, null })
1088      {
1089          final CompletableFuture<Integer> f = new CompletableFuture<>();
1090 <        final FailingNoop r = new FailingNoop();
1090 >        final FailingRunnable r = new FailingRunnable(m);
1091          if (!createIncomplete) f.complete(v1);
1092 <        final CompletableFuture<Void> g = f.thenRun(r);
1093 <        if (createIncomplete) f.complete(v1);
1092 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1093 >        if (createIncomplete) {
1094 >            checkIncomplete(g);
1095 >            f.complete(v1);
1096 >        }
1097  
1098          checkCompletedWithWrappedCFException(g);
1099          checkCompletedNormally(f, v1);
# Line 1050 | Line 1102 | public class CompletableFutureTest exten
1102      /**
1103       * thenApply result completes normally after normal completion of source
1104       */
1105 <    public void testThenApply() {
1054 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1055 <        CompletableFuture<Integer> g = f.thenApply(inc);
1056 <        f.complete(one);
1057 <        checkCompletedNormally(g, two);
1058 <    }
1059 <
1060 <    /**
1061 <     * thenApply result completes exceptionally after exceptional
1062 <     * completion of source
1063 <     */
1064 <    public void testThenApply2() {
1065 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1066 <        CompletableFuture<Integer> g = f.thenApply(inc);
1067 <        f.completeExceptionally(new CFException());
1068 <        checkCompletedWithWrappedCFException(g);
1069 <    }
1070 <
1071 <    /**
1072 <     * thenApply result completes exceptionally if action does
1073 <     */
1074 <    public void testThenApply3() {
1075 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1076 <        CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
1077 <        f.complete(one);
1078 <        checkCompletedWithWrappedCFException(g);
1079 <    }
1080 <
1081 <    /**
1082 <     * thenApply result completes exceptionally if source cancelled
1083 <     */
1084 <    public void testThenApply4() {
1085 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1086 <        CompletableFuture<Integer> g = f.thenApply(inc);
1087 <        assertTrue(f.cancel(true));
1088 <        checkCompletedWithWrappedCancellationException(g);
1089 <    }
1090 <
1091 <    /**
1092 <     * thenAccept result completes normally after normal completion of source
1093 <     */
1094 <    public void testThenAccept() {
1095 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1096 <        IncAction r = new IncAction();
1097 <        CompletableFuture<Void> g = f.thenAccept(r);
1098 <        f.complete(one);
1099 <        checkCompletedNormally(g, null);
1100 <        assertEquals(r.value, (Integer) 2);
1101 <    }
1102 <
1103 <    /**
1104 <     * thenAccept result completes exceptionally after exceptional
1105 <     * completion of source
1106 <     */
1107 <    public void testThenAccept2() {
1108 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1109 <        IncAction r = new IncAction();
1110 <        CompletableFuture<Void> g = f.thenAccept(r);
1111 <        f.completeExceptionally(new CFException());
1112 <        checkCompletedWithWrappedCFException(g);
1113 <    }
1114 <
1115 <    /**
1116 <     * thenAccept result completes exceptionally if action does
1117 <     */
1118 <    public void testThenAccept3() {
1119 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1120 <        FailingConsumer r = new FailingConsumer();
1121 <        CompletableFuture<Void> g = f.thenAccept(r);
1122 <        f.complete(one);
1123 <        checkCompletedWithWrappedCFException(g);
1124 <        assertEquals(1, r.invocationCount);
1125 <    }
1126 <
1127 <    /**
1128 <     * thenAccept result completes exceptionally if source cancelled
1129 <     */
1130 <    public void testThenAccept4() {
1131 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1132 <        IncAction r = new IncAction();
1133 <        CompletableFuture<Void> g = f.thenAccept(r);
1134 <        assertTrue(f.cancel(true));
1135 <        checkCompletedWithWrappedCancellationException(g);
1136 <    }
1137 <
1138 <    /**
1139 <     * thenCombine result completes normally after normal completion
1140 <     * of sources
1141 <     */
1142 <    public void testThenCombine_normalCompletion1() {
1143 <        for (boolean createIncomplete : new boolean[] { true, false })
1144 <        for (boolean fFirst : new boolean[] { true, false })
1105 >    public void testThenApply_normalCompletion() {
1106          for (ExecutionMode m : ExecutionMode.values())
1107 +        for (boolean createIncomplete : new boolean[] { true, false })
1108          for (Integer v1 : new Integer[] { 1, null })
1147        for (Integer v2 : new Integer[] { 2, null })
1109      {
1110          final CompletableFuture<Integer> f = new CompletableFuture<>();
1111 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1112 <        final SubtractFunction r = new SubtractFunction();
1113 <        CompletableFuture<Integer> h = null;
1114 <        if (createIncomplete) h = m.thenCombine(f, g, r);
1115 <
1155 <        if (fFirst)
1156 <            f.complete(v1);
1157 <        else
1158 <            g.complete(v2);
1159 <        if (createIncomplete) checkIncomplete(h);
1160 <        assertEquals(0, r.invocationCount);
1161 <        if (!fFirst)
1111 >        final IncFunction r = new IncFunction(m);
1112 >        if (!createIncomplete) f.complete(v1);
1113 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1114 >        if (createIncomplete) {
1115 >            checkIncomplete(g);
1116              f.complete(v1);
1117 <        else
1164 <            g.complete(v2);
1165 <        if (!createIncomplete) h = m.thenCombine(f, g, r);
1117 >        }
1118  
1119 <        checkCompletedNormally(h, subtract(v1, v2));
1119 >        checkCompletedNormally(g, inc(v1));
1120          checkCompletedNormally(f, v1);
1169        checkCompletedNormally(g, v2);
1121          assertEquals(1, r.invocationCount);
1122      }}
1123  
1124      /**
1125 <     * thenCombine result completes exceptionally after exceptional
1126 <     * completion of either source
1125 >     * thenApply result completes exceptionally after exceptional
1126 >     * completion of source
1127       */
1128 <    public void testThenCombine_exceptionalCompletion1() {
1128 >    public void testThenApply_exceptionalCompletion() {
1129          for (ExecutionMode m : ExecutionMode.values())
1130 <        for (Integer v1 : new Integer[] { 1, null })
1130 >        for (boolean createIncomplete : new boolean[] { true, false })
1131      {
1181        final CompletableFuture<Integer> f = new CompletableFuture<>();
1182        final CompletableFuture<Integer> g = new CompletableFuture<>();
1183        final SubtractFunction r = new SubtractFunction();
1184        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1132          final CFException ex = new CFException();
1133 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1134 +        final IncFunction r = new IncFunction(m);
1135 +        if (!createIncomplete) f.completeExceptionally(ex);
1136 +        final CompletableFuture<Integer> g = m.thenApply(f, r);
1137 +        if (createIncomplete) {
1138 +            checkIncomplete(g);
1139 +            f.completeExceptionally(ex);
1140 +        }
1141  
1142 <        f.completeExceptionally(ex);
1188 <        checkIncomplete(h);
1189 <        g.complete(v1);
1190 <
1191 <        checkCompletedWithWrappedCFException(h, ex);
1142 >        checkCompletedWithWrappedCFException(g, ex);
1143          checkCompletedWithWrappedCFException(f, ex);
1144          assertEquals(0, r.invocationCount);
1194        checkCompletedNormally(g, v1);
1145      }}
1146  
1147 <    public void testThenCombine_exceptionalCompletion2() {
1147 >    /**
1148 >     * thenApply result completes exceptionally if source cancelled
1149 >     */
1150 >    public void testThenApply_sourceCancelled() {
1151          for (ExecutionMode m : ExecutionMode.values())
1152 <        for (Integer v1 : new Integer[] { 1, null })
1152 >        for (boolean createIncomplete : new boolean[] { true, false })
1153 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1154      {
1155          final CompletableFuture<Integer> f = new CompletableFuture<>();
1156 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1157 <        final SubtractFunction r = new SubtractFunction();
1158 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1159 <        final CFException ex = new CFException();
1160 <
1161 <        g.completeExceptionally(ex);
1162 <        checkIncomplete(h);
1209 <        f.complete(v1);
1156 >        final IncFunction r = new IncFunction(m);
1157 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1158 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1159 >        if (createIncomplete) {
1160 >            checkIncomplete(g);
1161 >            assertTrue(f.cancel(mayInterruptIfRunning));
1162 >        }
1163  
1164 <        checkCompletedWithWrappedCFException(h, ex);
1165 <        checkCompletedWithWrappedCFException(g, ex);
1164 >        checkCompletedWithWrappedCancellationException(g);
1165 >        checkCancelled(f);
1166          assertEquals(0, r.invocationCount);
1214        checkCompletedNormally(f, v1);
1167      }}
1168  
1169 <    public void testThenCombine_exceptionalCompletion3() {
1169 >    /**
1170 >     * thenApply result completes exceptionally if action does
1171 >     */
1172 >    public void testThenApply_actionFailed() {
1173          for (ExecutionMode m : ExecutionMode.values())
1174 +        for (boolean createIncomplete : new boolean[] { true, false })
1175          for (Integer v1 : new Integer[] { 1, null })
1176      {
1177          final CompletableFuture<Integer> f = new CompletableFuture<>();
1178 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1179 <        final SubtractFunction r = new SubtractFunction();
1180 <        final CFException ex = new CFException();
1181 <
1182 <        g.completeExceptionally(ex);
1183 <        f.complete(v1);
1184 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1178 >        final FailingFunction r = new FailingFunction(m);
1179 >        if (!createIncomplete) f.complete(v1);
1180 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1181 >        if (createIncomplete) {
1182 >            checkIncomplete(g);
1183 >            f.complete(v1);
1184 >        }
1185  
1186 <        checkCompletedWithWrappedCFException(h, ex);
1231 <        checkCompletedWithWrappedCFException(g, ex);
1232 <        assertEquals(0, r.invocationCount);
1186 >        checkCompletedWithWrappedCFException(g);
1187          checkCompletedNormally(f, v1);
1188      }}
1189  
1190 <    public void testThenCombine_exceptionalCompletion4() {
1190 >    /**
1191 >     * thenAccept result completes normally after normal completion of source
1192 >     */
1193 >    public void testThenAccept_normalCompletion() {
1194          for (ExecutionMode m : ExecutionMode.values())
1195 +        for (boolean createIncomplete : new boolean[] { true, false })
1196          for (Integer v1 : new Integer[] { 1, null })
1197      {
1198          final CompletableFuture<Integer> f = new CompletableFuture<>();
1199 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1200 <        final SubtractFunction r = new SubtractFunction();
1201 <        final CFException ex = new CFException();
1202 <
1203 <        f.completeExceptionally(ex);
1204 <        g.complete(v1);
1205 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1199 >        final IncAction r = new IncAction();
1200 >        if (!createIncomplete) f.complete(v1);
1201 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1202 >        if (createIncomplete) {
1203 >            checkIncomplete(g);
1204 >            f.complete(v1);
1205 >        }
1206  
1207 <        checkCompletedWithWrappedCFException(h, ex);
1208 <        checkCompletedWithWrappedCFException(f, ex);
1209 <        assertEquals(0, r.invocationCount);
1210 <        checkCompletedNormally(g, v1);
1207 >        checkCompletedNormally(g, null);
1208 >        checkCompletedNormally(f, v1);
1209 >        assertEquals(1, r.invocationCount);
1210 >        assertEquals(inc(v1), r.value);
1211      }}
1212  
1213      /**
1214 <     * thenCombine result completes exceptionally if action does
1214 >     * thenAccept result completes exceptionally after exceptional
1215 >     * completion of source
1216       */
1217 <    public void testThenCombine_actionFailed1() {
1217 >    public void testThenAccept_exceptionalCompletion() {
1218          for (ExecutionMode m : ExecutionMode.values())
1219 <        for (Integer v1 : new Integer[] { 1, null })
1261 <        for (Integer v2 : new Integer[] { 2, null })
1219 >        for (boolean createIncomplete : new boolean[] { true, false })
1220      {
1221 +        final CFException ex = new CFException();
1222          final CompletableFuture<Integer> f = new CompletableFuture<>();
1223 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1224 <        final FailingBiFunction r = new FailingBiFunction();
1225 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1226 <
1227 <        f.complete(v1);
1228 <        checkIncomplete(h);
1229 <        g.complete(v2);
1223 >        final IncAction r = new IncAction();
1224 >        if (!createIncomplete) f.completeExceptionally(ex);
1225 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1226 >        if (createIncomplete) {
1227 >            checkIncomplete(g);
1228 >            f.completeExceptionally(ex);
1229 >        }
1230  
1231 <        checkCompletedWithWrappedCFException(h);
1232 <        checkCompletedNormally(f, v1);
1233 <        checkCompletedNormally(g, v2);
1231 >        checkCompletedWithWrappedCFException(g, ex);
1232 >        checkCompletedWithWrappedCFException(f, ex);
1233 >        assertEquals(0, r.invocationCount);
1234      }}
1235  
1236 <    public void testThenCombine_actionFailed2() {
1236 >    /**
1237 >     * thenAccept result completes exceptionally if action does
1238 >     */
1239 >    public void testThenAccept_actionFailed() {
1240          for (ExecutionMode m : ExecutionMode.values())
1241 +        for (boolean createIncomplete : new boolean[] { true, false })
1242          for (Integer v1 : new Integer[] { 1, null })
1280        for (Integer v2 : new Integer[] { 2, null })
1243      {
1244          final CompletableFuture<Integer> f = new CompletableFuture<>();
1245 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1246 <        final FailingBiFunction r = new FailingBiFunction();
1247 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1248 <
1249 <        g.complete(v2);
1250 <        checkIncomplete(h);
1251 <        f.complete(v1);
1245 >        final FailingConsumer r = new FailingConsumer(m);
1246 >        if (!createIncomplete) f.complete(v1);
1247 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1248 >        if (createIncomplete) {
1249 >            checkIncomplete(g);
1250 >            f.complete(v1);
1251 >        }
1252  
1253 <        checkCompletedWithWrappedCFException(h);
1253 >        checkCompletedWithWrappedCFException(g);
1254          checkCompletedNormally(f, v1);
1293        checkCompletedNormally(g, v2);
1255      }}
1256  
1257      /**
1258 <     * thenCombine result completes exceptionally if either source cancelled
1258 >     * thenAccept result completes exceptionally if source cancelled
1259       */
1260 <    public void testThenCombine_sourceCancelled1() {
1260 >    public void testThenAccept_sourceCancelled() {
1261          for (ExecutionMode m : ExecutionMode.values())
1262 +        for (boolean createIncomplete : new boolean[] { true, false })
1263          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1302        for (Integer v1 : new Integer[] { 1, null })
1264      {
1265          final CompletableFuture<Integer> f = new CompletableFuture<>();
1266 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1267 <        final SubtractFunction r = new SubtractFunction();
1268 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1269 <
1270 <        assertTrue(f.cancel(mayInterruptIfRunning));
1271 <        checkIncomplete(h);
1272 <        g.complete(v1);
1266 >        final IncAction r = new IncAction();
1267 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1268 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1269 >        if (createIncomplete) {
1270 >            checkIncomplete(g);
1271 >            assertTrue(f.cancel(mayInterruptIfRunning));
1272 >        }
1273  
1274 <        checkCompletedWithWrappedCancellationException(h);
1274 >        checkCompletedWithWrappedCancellationException(g);
1275          checkCancelled(f);
1276          assertEquals(0, r.invocationCount);
1316        checkCompletedNormally(g, v1);
1317    }}
1318
1319    public void testThenCombine_sourceCancelled2() {
1320        for (ExecutionMode m : ExecutionMode.values())
1321        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1322        for (Integer v1 : new Integer[] { 1, null })
1323    {
1324        final CompletableFuture<Integer> f = new CompletableFuture<>();
1325        final CompletableFuture<Integer> g = new CompletableFuture<>();
1326        final SubtractFunction r = new SubtractFunction();
1327        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1328
1329        assertTrue(g.cancel(mayInterruptIfRunning));
1330        checkIncomplete(h);
1331        f.complete(v1);
1332
1333        checkCompletedWithWrappedCancellationException(h);
1334        checkCancelled(g);
1335        assertEquals(0, r.invocationCount);
1336        checkCompletedNormally(f, v1);
1277      }}
1278  
1279 <    public void testThenCombine_sourceCancelled3() {
1279 >    /**
1280 >     * thenCombine result completes normally after normal completion
1281 >     * of sources
1282 >     */
1283 >    public void testThenCombine_normalCompletion() {
1284          for (ExecutionMode m : ExecutionMode.values())
1285 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1285 >        for (boolean createIncomplete : new boolean[] { true, false })
1286 >        for (boolean fFirst : new boolean[] { true, false })
1287          for (Integer v1 : new Integer[] { 1, null })
1288 +        for (Integer v2 : new Integer[] { 2, null })
1289      {
1290          final CompletableFuture<Integer> f = new CompletableFuture<>();
1291          final CompletableFuture<Integer> g = new CompletableFuture<>();
1292 <        final SubtractFunction r = new SubtractFunction();
1292 >        final SubtractFunction r = new SubtractFunction(m);
1293  
1294 <        assertTrue(g.cancel(mayInterruptIfRunning));
1295 <        f.complete(v1);
1294 >        if (fFirst) f.complete(v1); else g.complete(v2);
1295 >        if (!createIncomplete)
1296 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1297          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1298 +        if (createIncomplete) {
1299 +            checkIncomplete(h);
1300 +            assertEquals(0, r.invocationCount);
1301 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1302 +        }
1303  
1304 <        checkCompletedWithWrappedCancellationException(h);
1353 <        checkCancelled(g);
1354 <        assertEquals(0, r.invocationCount);
1304 >        checkCompletedNormally(h, subtract(v1, v2));
1305          checkCompletedNormally(f, v1);
1306 +        checkCompletedNormally(g, v2);
1307 +        assertEquals(1, r.invocationCount);
1308      }}
1309  
1310 <    public void testThenCombine_sourceCancelled4() {
1310 >    /**
1311 >     * thenCombine result completes exceptionally after exceptional
1312 >     * completion of either source
1313 >     */
1314 >    public void testThenCombine_exceptionalCompletion() {
1315          for (ExecutionMode m : ExecutionMode.values())
1316 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1316 >        for (boolean createIncomplete : new boolean[] { true, false })
1317 >        for (boolean fFirst : new boolean[] { true, false })
1318          for (Integer v1 : new Integer[] { 1, null })
1319      {
1320          final CompletableFuture<Integer> f = new CompletableFuture<>();
1321          final CompletableFuture<Integer> g = new CompletableFuture<>();
1322 <        final SubtractFunction r = new SubtractFunction();
1322 >        final CFException ex = new CFException();
1323 >        final SubtractFunction r = new SubtractFunction(m);
1324  
1325 <        assertTrue(f.cancel(mayInterruptIfRunning));
1326 <        g.complete(v1);
1325 >        (fFirst ? f : g).complete(v1);
1326 >        if (!createIncomplete)
1327 >            (!fFirst ? f : g).completeExceptionally(ex);
1328          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1329 +        if (createIncomplete) {
1330 +            checkIncomplete(h);
1331 +            (!fFirst ? f : g).completeExceptionally(ex);
1332 +        }
1333  
1334 <        checkCompletedWithWrappedCancellationException(h);
1372 <        checkCancelled(f);
1334 >        checkCompletedWithWrappedCFException(h, ex);
1335          assertEquals(0, r.invocationCount);
1336 <        checkCompletedNormally(g, v1);
1336 >        checkCompletedNormally(fFirst ? f : g, v1);
1337 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1338      }}
1339  
1340      /**
1341 <     * thenAcceptBoth result completes normally after normal
1379 <     * completion of sources
1341 >     * thenCombine result completes exceptionally if action does
1342       */
1343 <    public void testThenAcceptBoth_normalCompletion1() {
1382 <        for (ExecutionMode m : ExecutionMode.values())
1383 <        for (Integer v1 : new Integer[] { 1, null })
1384 <        for (Integer v2 : new Integer[] { 2, null })
1385 <    {
1386 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1387 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1388 <        final SubtractAction r = new SubtractAction();
1389 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1390 <
1391 <        f.complete(v1);
1392 <        checkIncomplete(h);
1393 <        assertEquals(0, r.invocationCount);
1394 <        g.complete(v2);
1395 <
1396 <        checkCompletedNormally(h, null);
1397 <        assertEquals(subtract(v1, v2), r.value);
1398 <        checkCompletedNormally(f, v1);
1399 <        checkCompletedNormally(g, v2);
1400 <    }}
1401 <
1402 <    public void testThenAcceptBoth_normalCompletion2() {
1343 >    public void testThenCombine_actionFailed() {
1344          for (ExecutionMode m : ExecutionMode.values())
1345 +        for (boolean fFirst : new boolean[] { true, false })
1346          for (Integer v1 : new Integer[] { 1, null })
1347          for (Integer v2 : new Integer[] { 2, null })
1348      {
1349          final CompletableFuture<Integer> f = new CompletableFuture<>();
1350          final CompletableFuture<Integer> g = new CompletableFuture<>();
1351 <        final SubtractAction r = new SubtractAction();
1352 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1351 >        final FailingBiFunction r = new FailingBiFunction(m);
1352 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1353  
1354 <        g.complete(v2);
1355 <        checkIncomplete(h);
1356 <        assertEquals(0, r.invocationCount);
1357 <        f.complete(v1);
1354 >        if (fFirst) {
1355 >            f.complete(v1);
1356 >            g.complete(v2);
1357 >        } else {
1358 >            g.complete(v2);
1359 >            f.complete(v1);
1360 >        }
1361  
1362 <        checkCompletedNormally(h, null);
1418 <        assertEquals(subtract(v1, v2), r.value);
1362 >        checkCompletedWithWrappedCFException(h);
1363          checkCompletedNormally(f, v1);
1364          checkCompletedNormally(g, v2);
1365      }}
1366  
1367 <    public void testThenAcceptBoth_normalCompletion3() {
1367 >    /**
1368 >     * thenCombine result completes exceptionally if either source cancelled
1369 >     */
1370 >    public void testThenCombine_sourceCancelled() {
1371          for (ExecutionMode m : ExecutionMode.values())
1372 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1373 +        for (boolean createIncomplete : new boolean[] { true, false })
1374 +        for (boolean fFirst : new boolean[] { true, false })
1375          for (Integer v1 : new Integer[] { 1, null })
1426        for (Integer v2 : new Integer[] { 2, null })
1376      {
1377          final CompletableFuture<Integer> f = new CompletableFuture<>();
1378          final CompletableFuture<Integer> g = new CompletableFuture<>();
1379 <        final SubtractAction r = new SubtractAction();
1379 >        final SubtractFunction r = new SubtractFunction(m);
1380  
1381 <        g.complete(v2);
1382 <        f.complete(v1);
1383 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1381 >        (fFirst ? f : g).complete(v1);
1382 >        if (!createIncomplete)
1383 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1384 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1385 >        if (createIncomplete) {
1386 >            checkIncomplete(h);
1387 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1388 >        }
1389  
1390 <        checkCompletedNormally(h, null);
1391 <        assertEquals(subtract(v1, v2), r.value);
1392 <        checkCompletedNormally(f, v1);
1393 <        checkCompletedNormally(g, v2);
1390 >        checkCompletedWithWrappedCancellationException(h);
1391 >        checkCancelled(!fFirst ? f : g);
1392 >        assertEquals(0, r.invocationCount);
1393 >        checkCompletedNormally(fFirst ? f : g, v1);
1394      }}
1395  
1396 <    public void testThenAcceptBoth_normalCompletion4() {
1396 >    /**
1397 >     * thenAcceptBoth result completes normally after normal
1398 >     * completion of sources
1399 >     */
1400 >    public void testThenAcceptBoth_normalCompletion() {
1401          for (ExecutionMode m : ExecutionMode.values())
1402 +        for (boolean createIncomplete : new boolean[] { true, false })
1403 +        for (boolean fFirst : new boolean[] { true, false })
1404          for (Integer v1 : new Integer[] { 1, null })
1405          for (Integer v2 : new Integer[] { 2, null })
1406      {
1407          final CompletableFuture<Integer> f = new CompletableFuture<>();
1408          final CompletableFuture<Integer> g = new CompletableFuture<>();
1409 <        final SubtractAction r = new SubtractAction();
1409 >        final SubtractAction r = new SubtractAction(m);
1410  
1411 <        f.complete(v1);
1412 <        g.complete(v2);
1411 >        if (fFirst) f.complete(v1); else g.complete(v2);
1412 >        if (!createIncomplete)
1413 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1414          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1415 +        if (createIncomplete) {
1416 +            checkIncomplete(h);
1417 +            assertEquals(0, r.invocationCount);
1418 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1419 +        }
1420  
1421          checkCompletedNormally(h, null);
1422          assertEquals(subtract(v1, v2), r.value);
# Line 1462 | Line 1428 | public class CompletableFutureTest exten
1428       * thenAcceptBoth result completes exceptionally after exceptional
1429       * completion of either source
1430       */
1431 <    public void testThenAcceptBoth_exceptionalCompletion1() {
1466 <        for (ExecutionMode m : ExecutionMode.values())
1467 <        for (Integer v1 : new Integer[] { 1, null })
1468 <    {
1469 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1470 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1471 <        final SubtractAction r = new SubtractAction();
1472 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1473 <        final CFException ex = new CFException();
1474 <
1475 <        f.completeExceptionally(ex);
1476 <        checkIncomplete(h);
1477 <        g.complete(v1);
1478 <
1479 <        checkCompletedWithWrappedCFException(h, ex);
1480 <        checkCompletedWithWrappedCFException(f, ex);
1481 <        assertEquals(0, r.invocationCount);
1482 <        checkCompletedNormally(g, v1);
1483 <    }}
1484 <
1485 <    public void testThenAcceptBoth_exceptionalCompletion2() {
1486 <        for (ExecutionMode m : ExecutionMode.values())
1487 <        for (Integer v1 : new Integer[] { 1, null })
1488 <    {
1489 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1490 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1491 <        final SubtractAction r = new SubtractAction();
1492 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1493 <        final CFException ex = new CFException();
1494 <
1495 <        g.completeExceptionally(ex);
1496 <        checkIncomplete(h);
1497 <        f.complete(v1);
1498 <
1499 <        checkCompletedWithWrappedCFException(h, ex);
1500 <        checkCompletedWithWrappedCFException(g, ex);
1501 <        assertEquals(0, r.invocationCount);
1502 <        checkCompletedNormally(f, v1);
1503 <    }}
1504 <
1505 <    public void testThenAcceptBoth_exceptionalCompletion3() {
1506 <        for (ExecutionMode m : ExecutionMode.values())
1507 <        for (Integer v1 : new Integer[] { 1, null })
1508 <    {
1509 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1510 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1511 <        final SubtractAction r = new SubtractAction();
1512 <        final CFException ex = new CFException();
1513 <
1514 <        g.completeExceptionally(ex);
1515 <        f.complete(v1);
1516 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1517 <
1518 <        checkCompletedWithWrappedCFException(h, ex);
1519 <        checkCompletedWithWrappedCFException(g, ex);
1520 <        assertEquals(0, r.invocationCount);
1521 <        checkCompletedNormally(f, v1);
1522 <    }}
1523 <
1524 <    public void testThenAcceptBoth_exceptionalCompletion4() {
1431 >    public void testThenAcceptBoth_exceptionalCompletion() {
1432          for (ExecutionMode m : ExecutionMode.values())
1433 +        for (boolean createIncomplete : new boolean[] { true, false })
1434 +        for (boolean fFirst : new boolean[] { true, false })
1435          for (Integer v1 : new Integer[] { 1, null })
1436      {
1437          final CompletableFuture<Integer> f = new CompletableFuture<>();
1438          final CompletableFuture<Integer> g = new CompletableFuture<>();
1530        final SubtractAction r = new SubtractAction();
1439          final CFException ex = new CFException();
1440 +        final SubtractAction r = new SubtractAction(m);
1441  
1442 <        f.completeExceptionally(ex);
1443 <        g.complete(v1);
1442 >        (fFirst ? f : g).complete(v1);
1443 >        if (!createIncomplete)
1444 >            (!fFirst ? f : g).completeExceptionally(ex);
1445          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1446 +        if (createIncomplete) {
1447 +            checkIncomplete(h);
1448 +            (!fFirst ? f : g).completeExceptionally(ex);
1449 +        }
1450  
1451          checkCompletedWithWrappedCFException(h, ex);
1538        checkCompletedWithWrappedCFException(f, ex);
1452          assertEquals(0, r.invocationCount);
1453 <        checkCompletedNormally(g, v1);
1453 >        checkCompletedNormally(fFirst ? f : g, v1);
1454 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1455      }}
1456  
1457      /**
1458       * thenAcceptBoth result completes exceptionally if action does
1459       */
1460 <    public void testThenAcceptBoth_actionFailed1() {
1547 <        for (ExecutionMode m : ExecutionMode.values())
1548 <        for (Integer v1 : new Integer[] { 1, null })
1549 <        for (Integer v2 : new Integer[] { 2, null })
1550 <    {
1551 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1552 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1553 <        final FailingBiConsumer r = new FailingBiConsumer();
1554 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1555 <
1556 <        f.complete(v1);
1557 <        checkIncomplete(h);
1558 <        g.complete(v2);
1559 <
1560 <        checkCompletedWithWrappedCFException(h);
1561 <        checkCompletedNormally(f, v1);
1562 <        checkCompletedNormally(g, v2);
1563 <    }}
1564 <
1565 <    public void testThenAcceptBoth_actionFailed2() {
1460 >    public void testThenAcceptBoth_actionFailed() {
1461          for (ExecutionMode m : ExecutionMode.values())
1462 +        for (boolean fFirst : new boolean[] { true, false })
1463          for (Integer v1 : new Integer[] { 1, null })
1464          for (Integer v2 : new Integer[] { 2, null })
1465      {
1466          final CompletableFuture<Integer> f = new CompletableFuture<>();
1467          final CompletableFuture<Integer> g = new CompletableFuture<>();
1468 <        final FailingBiConsumer r = new FailingBiConsumer();
1468 >        final FailingBiConsumer r = new FailingBiConsumer(m);
1469          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1470  
1471 <        g.complete(v2);
1472 <        checkIncomplete(h);
1473 <        f.complete(v1);
1471 >        if (fFirst) {
1472 >            f.complete(v1);
1473 >            g.complete(v2);
1474 >        } else {
1475 >            g.complete(v2);
1476 >            f.complete(v1);
1477 >        }
1478  
1479          checkCompletedWithWrappedCFException(h);
1480          checkCompletedNormally(f, v1);
# Line 1584 | Line 1484 | public class CompletableFutureTest exten
1484      /**
1485       * thenAcceptBoth result completes exceptionally if either source cancelled
1486       */
1487 <    public void testThenAcceptBoth_sourceCancelled1() {
1588 <        for (ExecutionMode m : ExecutionMode.values())
1589 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1590 <        for (Integer v1 : new Integer[] { 1, null })
1591 <    {
1592 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1593 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1594 <        final SubtractAction r = new SubtractAction();
1595 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1596 <
1597 <        assertTrue(f.cancel(mayInterruptIfRunning));
1598 <        checkIncomplete(h);
1599 <        g.complete(v1);
1600 <
1601 <        checkCompletedWithWrappedCancellationException(h);
1602 <        checkCancelled(f);
1603 <        assertEquals(0, r.invocationCount);
1604 <        checkCompletedNormally(g, v1);
1605 <    }}
1606 <
1607 <    public void testThenAcceptBoth_sourceCancelled2() {
1608 <        for (ExecutionMode m : ExecutionMode.values())
1609 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1610 <        for (Integer v1 : new Integer[] { 1, null })
1611 <    {
1612 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1613 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1614 <        final SubtractAction r = new SubtractAction();
1615 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1616 <
1617 <        assertTrue(g.cancel(mayInterruptIfRunning));
1618 <        checkIncomplete(h);
1619 <        f.complete(v1);
1620 <
1621 <        checkCompletedWithWrappedCancellationException(h);
1622 <        checkCancelled(g);
1623 <        assertEquals(0, r.invocationCount);
1624 <        checkCompletedNormally(f, v1);
1625 <    }}
1626 <
1627 <    public void testThenAcceptBoth_sourceCancelled3() {
1628 <        for (ExecutionMode m : ExecutionMode.values())
1629 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1630 <        for (Integer v1 : new Integer[] { 1, null })
1631 <    {
1632 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1633 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1634 <        final SubtractAction r = new SubtractAction();
1635 <
1636 <        assertTrue(g.cancel(mayInterruptIfRunning));
1637 <        f.complete(v1);
1638 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1639 <
1640 <        checkCompletedWithWrappedCancellationException(h);
1641 <        checkCancelled(g);
1642 <        assertEquals(0, r.invocationCount);
1643 <        checkCompletedNormally(f, v1);
1644 <    }}
1645 <
1646 <    public void testThenAcceptBoth_sourceCancelled4() {
1487 >    public void testThenAcceptBoth_sourceCancelled() {
1488          for (ExecutionMode m : ExecutionMode.values())
1489          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1490 +        for (boolean createIncomplete : new boolean[] { true, false })
1491 +        for (boolean fFirst : new boolean[] { true, false })
1492          for (Integer v1 : new Integer[] { 1, null })
1493      {
1494          final CompletableFuture<Integer> f = new CompletableFuture<>();
1495          final CompletableFuture<Integer> g = new CompletableFuture<>();
1496 <        final SubtractAction r = new SubtractAction();
1496 >        final SubtractAction r = new SubtractAction(m);
1497  
1498 <        assertTrue(f.cancel(mayInterruptIfRunning));
1499 <        g.complete(v1);
1498 >        (fFirst ? f : g).complete(v1);
1499 >        if (!createIncomplete)
1500 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1501          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1502 +        if (createIncomplete) {
1503 +            checkIncomplete(h);
1504 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1505 +        }
1506  
1507          checkCompletedWithWrappedCancellationException(h);
1508 <        checkCancelled(f);
1508 >        checkCancelled(!fFirst ? f : g);
1509          assertEquals(0, r.invocationCount);
1510 <        checkCompletedNormally(g, v1);
1510 >        checkCompletedNormally(fFirst ? f : g, v1);
1511      }}
1512  
1513      /**
1514       * runAfterBoth result completes normally after normal
1515       * completion of sources
1516       */
1517 <    public void testRunAfterBoth_normalCompletion1() {
1670 <        for (ExecutionMode m : ExecutionMode.values())
1671 <        for (Integer v1 : new Integer[] { 1, null })
1672 <        for (Integer v2 : new Integer[] { 2, null })
1673 <    {
1674 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1675 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1676 <        final Noop r = new Noop();
1677 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1678 <
1679 <        f.complete(v1);
1680 <        checkIncomplete(h);
1681 <        assertEquals(0, r.invocationCount);
1682 <        g.complete(v2);
1683 <
1684 <        checkCompletedNormally(h, null);
1685 <        assertEquals(1, r.invocationCount);
1686 <        checkCompletedNormally(f, v1);
1687 <        checkCompletedNormally(g, v2);
1688 <    }}
1689 <
1690 <    public void testRunAfterBoth_normalCompletion2() {
1691 <        for (ExecutionMode m : ExecutionMode.values())
1692 <        for (Integer v1 : new Integer[] { 1, null })
1693 <        for (Integer v2 : new Integer[] { 2, null })
1694 <    {
1695 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1696 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1697 <        final Noop r = new Noop();
1698 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1699 <
1700 <        g.complete(v2);
1701 <        checkIncomplete(h);
1702 <        assertEquals(0, r.invocationCount);
1703 <        f.complete(v1);
1704 <
1705 <        checkCompletedNormally(h, null);
1706 <        assertEquals(1, r.invocationCount);
1707 <        checkCompletedNormally(f, v1);
1708 <        checkCompletedNormally(g, v2);
1709 <    }}
1710 <
1711 <    public void testRunAfterBoth_normalCompletion3() {
1712 <        for (ExecutionMode m : ExecutionMode.values())
1713 <        for (Integer v1 : new Integer[] { 1, null })
1714 <        for (Integer v2 : new Integer[] { 2, null })
1715 <    {
1716 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1717 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1718 <        final Noop r = new Noop();
1719 <
1720 <        g.complete(v2);
1721 <        f.complete(v1);
1722 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1723 <
1724 <        checkCompletedNormally(h, null);
1725 <        assertEquals(1, r.invocationCount);
1726 <        checkCompletedNormally(f, v1);
1727 <        checkCompletedNormally(g, v2);
1728 <    }}
1729 <
1730 <    public void testRunAfterBoth_normalCompletion4() {
1517 >    public void testRunAfterBoth_normalCompletion() {
1518          for (ExecutionMode m : ExecutionMode.values())
1519 +        for (boolean createIncomplete : new boolean[] { true, false })
1520 +        for (boolean fFirst : new boolean[] { true, false })
1521          for (Integer v1 : new Integer[] { 1, null })
1522          for (Integer v2 : new Integer[] { 2, null })
1523      {
1524          final CompletableFuture<Integer> f = new CompletableFuture<>();
1525          final CompletableFuture<Integer> g = new CompletableFuture<>();
1526 <        final Noop r = new Noop();
1526 >        final Noop r = new Noop(m);
1527  
1528 <        f.complete(v1);
1529 <        g.complete(v2);
1528 >        if (fFirst) f.complete(v1); else g.complete(v2);
1529 >        if (!createIncomplete)
1530 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1531          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1532 +        if (createIncomplete) {
1533 +            checkIncomplete(h);
1534 +            assertEquals(0, r.invocationCount);
1535 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1536 +        }
1537  
1538          checkCompletedNormally(h, null);
1539          assertEquals(1, r.invocationCount);
# Line 1750 | Line 1545 | public class CompletableFutureTest exten
1545       * runAfterBoth result completes exceptionally after exceptional
1546       * completion of either source
1547       */
1548 <    public void testRunAfterBoth_exceptionalCompletion1() {
1754 <        for (ExecutionMode m : ExecutionMode.values())
1755 <        for (Integer v1 : new Integer[] { 1, null })
1756 <    {
1757 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1758 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1759 <        final Noop r = new Noop();
1760 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1761 <        final CFException ex = new CFException();
1762 <
1763 <        f.completeExceptionally(ex);
1764 <        checkIncomplete(h);
1765 <        g.complete(v1);
1766 <
1767 <        checkCompletedWithWrappedCFException(h, ex);
1768 <        checkCompletedWithWrappedCFException(f, ex);
1769 <        assertEquals(0, r.invocationCount);
1770 <        checkCompletedNormally(g, v1);
1771 <    }}
1772 <
1773 <    public void testRunAfterBoth_exceptionalCompletion2() {
1774 <        for (ExecutionMode m : ExecutionMode.values())
1775 <        for (Integer v1 : new Integer[] { 1, null })
1776 <    {
1777 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1778 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1779 <        final Noop r = new Noop();
1780 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1781 <        final CFException ex = new CFException();
1782 <
1783 <        g.completeExceptionally(ex);
1784 <        checkIncomplete(h);
1785 <        f.complete(v1);
1786 <
1787 <        checkCompletedWithWrappedCFException(h, ex);
1788 <        checkCompletedWithWrappedCFException(g, ex);
1789 <        assertEquals(0, r.invocationCount);
1790 <        checkCompletedNormally(f, v1);
1791 <    }}
1792 <
1793 <    public void testRunAfterBoth_exceptionalCompletion3() {
1794 <        for (ExecutionMode m : ExecutionMode.values())
1795 <        for (Integer v1 : new Integer[] { 1, null })
1796 <    {
1797 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1798 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1799 <        final Noop r = new Noop();
1800 <        final CFException ex = new CFException();
1801 <
1802 <        g.completeExceptionally(ex);
1803 <        f.complete(v1);
1804 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1805 <
1806 <        checkCompletedWithWrappedCFException(h, ex);
1807 <        checkCompletedWithWrappedCFException(g, ex);
1808 <        assertEquals(0, r.invocationCount);
1809 <        checkCompletedNormally(f, v1);
1810 <    }}
1811 <
1812 <    public void testRunAfterBoth_exceptionalCompletion4() {
1548 >    public void testRunAfterBoth_exceptionalCompletion() {
1549          for (ExecutionMode m : ExecutionMode.values())
1550 +        for (boolean createIncomplete : new boolean[] { true, false })
1551 +        for (boolean fFirst : new boolean[] { true, false })
1552          for (Integer v1 : new Integer[] { 1, null })
1553      {
1554          final CompletableFuture<Integer> f = new CompletableFuture<>();
1555          final CompletableFuture<Integer> g = new CompletableFuture<>();
1818        final Noop r = new Noop();
1556          final CFException ex = new CFException();
1557 +        final Noop r = new Noop(m);
1558  
1559 <        f.completeExceptionally(ex);
1560 <        g.complete(v1);
1559 >        (fFirst ? f : g).complete(v1);
1560 >        if (!createIncomplete)
1561 >            (!fFirst ? f : g).completeExceptionally(ex);
1562          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1563 +        if (createIncomplete) {
1564 +            checkIncomplete(h);
1565 +            (!fFirst ? f : g).completeExceptionally(ex);
1566 +        }
1567  
1568          checkCompletedWithWrappedCFException(h, ex);
1826        checkCompletedWithWrappedCFException(f, ex);
1569          assertEquals(0, r.invocationCount);
1570 <        checkCompletedNormally(g, v1);
1570 >        checkCompletedNormally(fFirst ? f : g, v1);
1571 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1572      }}
1573  
1574      /**
1575       * runAfterBoth result completes exceptionally if action does
1576       */
1577 <    public void testRunAfterBoth_actionFailed1() {
1835 <        for (ExecutionMode m : ExecutionMode.values())
1836 <        for (Integer v1 : new Integer[] { 1, null })
1837 <        for (Integer v2 : new Integer[] { 2, null })
1838 <    {
1839 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1840 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1841 <        final FailingNoop r = new FailingNoop();
1842 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1843 <
1844 <        f.complete(v1);
1845 <        checkIncomplete(h);
1846 <        g.complete(v2);
1847 <
1848 <        checkCompletedWithWrappedCFException(h);
1849 <        checkCompletedNormally(f, v1);
1850 <        checkCompletedNormally(g, v2);
1851 <    }}
1852 <
1853 <    public void testRunAfterBoth_actionFailed2() {
1577 >    public void testRunAfterBoth_actionFailed() {
1578          for (ExecutionMode m : ExecutionMode.values())
1579 +        for (boolean fFirst : new boolean[] { true, false })
1580          for (Integer v1 : new Integer[] { 1, null })
1581          for (Integer v2 : new Integer[] { 2, null })
1582      {
1583          final CompletableFuture<Integer> f = new CompletableFuture<>();
1584          final CompletableFuture<Integer> g = new CompletableFuture<>();
1585 <        final FailingNoop r = new FailingNoop();
1861 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1585 >        final FailingRunnable r = new FailingRunnable(m);
1586  
1587 <        g.complete(v2);
1588 <        checkIncomplete(h);
1589 <        f.complete(v1);
1587 >        CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r);
1588 >        if (fFirst) {
1589 >            f.complete(v1);
1590 >            g.complete(v2);
1591 >        } else {
1592 >            g.complete(v2);
1593 >            f.complete(v1);
1594 >        }
1595 >        CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r);
1596  
1597 <        checkCompletedWithWrappedCFException(h);
1597 >        checkCompletedWithWrappedCFException(h1);
1598 >        checkCompletedWithWrappedCFException(h2);
1599          checkCompletedNormally(f, v1);
1600          checkCompletedNormally(g, v2);
1601      }}
# Line 1872 | Line 1603 | public class CompletableFutureTest exten
1603      /**
1604       * runAfterBoth result completes exceptionally if either source cancelled
1605       */
1606 <    public void testRunAfterBoth_sourceCancelled1() {
1876 <        for (ExecutionMode m : ExecutionMode.values())
1877 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1878 <        for (Integer v1 : new Integer[] { 1, null })
1879 <    {
1880 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1881 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1882 <        final Noop r = new Noop();
1883 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1884 <
1885 <        assertTrue(f.cancel(mayInterruptIfRunning));
1886 <        checkIncomplete(h);
1887 <        g.complete(v1);
1888 <
1889 <        checkCompletedWithWrappedCancellationException(h);
1890 <        checkCancelled(f);
1891 <        assertEquals(0, r.invocationCount);
1892 <        checkCompletedNormally(g, v1);
1893 <    }}
1894 <
1895 <    public void testRunAfterBoth_sourceCancelled2() {
1896 <        for (ExecutionMode m : ExecutionMode.values())
1897 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1898 <        for (Integer v1 : new Integer[] { 1, null })
1899 <    {
1900 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1901 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1902 <        final Noop r = new Noop();
1903 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1904 <
1905 <        assertTrue(g.cancel(mayInterruptIfRunning));
1906 <        checkIncomplete(h);
1907 <        f.complete(v1);
1908 <
1909 <        checkCompletedWithWrappedCancellationException(h);
1910 <        checkCancelled(g);
1911 <        assertEquals(0, r.invocationCount);
1912 <        checkCompletedNormally(f, v1);
1913 <    }}
1914 <
1915 <    public void testRunAfterBoth_sourceCancelled3() {
1606 >    public void testRunAfterBoth_sourceCancelled() {
1607          for (ExecutionMode m : ExecutionMode.values())
1608          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1609 +        for (boolean createIncomplete : new boolean[] { true, false })
1610 +        for (boolean fFirst : new boolean[] { true, false })
1611          for (Integer v1 : new Integer[] { 1, null })
1612      {
1613          final CompletableFuture<Integer> f = new CompletableFuture<>();
1614          final CompletableFuture<Integer> g = new CompletableFuture<>();
1615 <        final Noop r = new Noop();
1615 >        final Noop r = new Noop(m);
1616  
1924        assertTrue(g.cancel(mayInterruptIfRunning));
1925        f.complete(v1);
1926        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1617  
1618 <        checkCompletedWithWrappedCancellationException(h);
1619 <        checkCancelled(g);
1620 <        assertEquals(0, r.invocationCount);
1931 <        checkCompletedNormally(f, v1);
1932 <    }}
1933 <
1934 <    public void testRunAfterBoth_sourceCancelled4() {
1935 <        for (ExecutionMode m : ExecutionMode.values())
1936 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1937 <        for (Integer v1 : new Integer[] { 1, null })
1938 <    {
1939 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1940 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1941 <        final Noop r = new Noop();
1942 <
1943 <        assertTrue(f.cancel(mayInterruptIfRunning));
1944 <        g.complete(v1);
1618 >        (fFirst ? f : g).complete(v1);
1619 >        if (!createIncomplete)
1620 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1621          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1622 +        if (createIncomplete) {
1623 +            checkIncomplete(h);
1624 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1625 +        }
1626  
1627          checkCompletedWithWrappedCancellationException(h);
1628 <        checkCancelled(f);
1628 >        checkCancelled(!fFirst ? f : g);
1629          assertEquals(0, r.invocationCount);
1630 <        checkCompletedNormally(g, v1);
1630 >        checkCompletedNormally(fFirst ? f : g, v1);
1631      }}
1632  
1633      /**
1634       * applyToEither result completes normally after normal completion
1635       * of either source
1636       */
1637 <    public void testApplyToEither_normalCompletion1() {
1637 >    public void testApplyToEither_normalCompletion() {
1638          for (ExecutionMode m : ExecutionMode.values())
1639 +        for (boolean createIncomplete : new boolean[] { true, false })
1640 +        for (boolean fFirst : new boolean[] { true, false })
1641          for (Integer v1 : new Integer[] { 1, null })
1642          for (Integer v2 : new Integer[] { 2, null })
1643      {
1644          final CompletableFuture<Integer> f = new CompletableFuture<>();
1645          final CompletableFuture<Integer> g = new CompletableFuture<>();
1646 <        final IncFunction r = new IncFunction();
1965 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1646 >        final IncFunction r = new IncFunction(m);
1647  
1648 <        f.complete(v1);
1649 <        checkCompletedNormally(h, inc(v1));
1650 <        g.complete(v2);
1648 >        if (!createIncomplete)
1649 >            if (fFirst) f.complete(v1); else g.complete(v2);
1650 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1651 >        if (createIncomplete) {
1652 >            checkIncomplete(h);
1653 >            assertEquals(0, r.invocationCount);
1654 >            if (fFirst) f.complete(v1); else g.complete(v2);
1655 >        }
1656 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1657 >        if (!fFirst) f.complete(v1); else g.complete(v2);
1658  
1659          checkCompletedNormally(f, v1);
1660          checkCompletedNormally(g, v2);
1661 <        checkCompletedNormally(h, inc(v1));
1661 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1662      }}
1663  
1664 <    public void testApplyToEither_normalCompletion2() {
1664 >    public void testApplyToEither_normalCompletionBothAvailable() {
1665          for (ExecutionMode m : ExecutionMode.values())
1666 +        for (boolean fFirst : new boolean[] { true, false })
1667          for (Integer v1 : new Integer[] { 1, null })
1668          for (Integer v2 : new Integer[] { 2, null })
1669      {
1670          final CompletableFuture<Integer> f = new CompletableFuture<>();
1671          final CompletableFuture<Integer> g = new CompletableFuture<>();
1672 <        final IncFunction r = new IncFunction();
1984 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1672 >        final IncFunction r = new IncFunction(m);
1673  
1674 <        g.complete(v2);
1675 <        checkCompletedNormally(h, inc(v2));
1676 <        f.complete(v1);
1677 <
1678 <        checkCompletedNormally(f, v1);
1679 <        checkCompletedNormally(g, v2);
1680 <        checkCompletedNormally(h, inc(v2));
1993 <        }}
1994 <
1995 <    public void testApplyToEither_normalCompletion3() {
1996 <        for (ExecutionMode m : ExecutionMode.values())
1997 <        for (Integer v1 : new Integer[] { 1, null })
1998 <        for (Integer v2 : new Integer[] { 2, null })
1999 <    {
2000 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2001 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2002 <        final IncFunction r = new IncFunction();
1674 >        if (fFirst) {
1675 >            f.complete(v1);
1676 >            g.complete(v2);
1677 >        } else {
1678 >            g.complete(v2);
1679 >            f.complete(v1);
1680 >        }
1681  
2004        f.complete(v1);
2005        g.complete(v2);
1682          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1683  
1684          checkCompletedNormally(f, v1);
# Line 2020 | Line 1696 | public class CompletableFutureTest exten
1696       */
1697      public void testApplyToEither_exceptionalCompletion1() {
1698          for (ExecutionMode m : ExecutionMode.values())
1699 +        for (boolean createIncomplete : new boolean[] { true, false })
1700 +        for (boolean fFirst : new boolean[] { true, false })
1701          for (Integer v1 : new Integer[] { 1, null })
1702      {
1703          final CompletableFuture<Integer> f = new CompletableFuture<>();
1704          final CompletableFuture<Integer> g = new CompletableFuture<>();
2027        final IncFunction r = new IncFunction();
2028        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1705          final CFException ex = new CFException();
1706 +        final IncFunction r = new IncFunction(m);
1707  
1708 <        f.completeExceptionally(ex);
2032 <        checkCompletedWithWrappedCFException(h, ex);
2033 <        g.complete(v1);
2034 <
2035 <        assertEquals(0, r.invocationCount);
2036 <        checkCompletedNormally(g, v1);
2037 <        checkCompletedWithWrappedCFException(f, ex);
2038 <        checkCompletedWithWrappedCFException(h, ex);
2039 <    }}
2040 <
2041 <    public void testApplyToEither_exceptionalCompletion2() {
2042 <        for (ExecutionMode m : ExecutionMode.values())
2043 <        for (Integer v1 : new Integer[] { 1, null })
2044 <    {
2045 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2046 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2047 <        final IncFunction r = new IncFunction();
1708 >        if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex);
1709          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1710 <        final CFException ex = new CFException();
1710 >        if (createIncomplete) {
1711 >            checkIncomplete(h);
1712 >            assertEquals(0, r.invocationCount);
1713 >            (fFirst ? f : g).completeExceptionally(ex);
1714 >        }
1715  
2051        g.completeExceptionally(ex);
1716          checkCompletedWithWrappedCFException(h, ex);
1717 <        f.complete(v1);
1717 >        (!fFirst ? f : g).complete(v1);
1718  
1719          assertEquals(0, r.invocationCount);
1720 <        checkCompletedNormally(f, v1);
1721 <        checkCompletedWithWrappedCFException(g, ex);
1720 >        checkCompletedNormally(!fFirst ? f : g, v1);
1721 >        checkCompletedWithWrappedCFException(fFirst ? f : g, ex);
1722          checkCompletedWithWrappedCFException(h, ex);
1723      }}
1724  
1725 <    public void testApplyToEither_exceptionalCompletion3() {
1725 >    public void testApplyToEither_exceptionalCompletion2() {
1726          for (ExecutionMode m : ExecutionMode.values())
1727 +        for (boolean reverseArgs : new boolean[] { true, false })
1728 +        for (boolean fFirst : new boolean[] { true, false })
1729          for (Integer v1 : new Integer[] { 1, null })
1730      {
1731          final CompletableFuture<Integer> f = new CompletableFuture<>();
1732          final CompletableFuture<Integer> g = new CompletableFuture<>();
1733 <        final IncFunction r = new IncFunction();
1733 >        final IncFunction r1 = new IncFunction(m);
1734 >        final IncFunction r2 = new IncFunction(m);
1735          final CFException ex = new CFException();
1736 <
1737 <        g.completeExceptionally(ex);
1738 <        f.complete(v1);
1739 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1736 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1737 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1738 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1739 >        if (fFirst) {
1740 >            f.complete(v1);
1741 >            g.completeExceptionally(ex);
1742 >        } else {
1743 >            g.completeExceptionally(ex);
1744 >            f.complete(v1);
1745 >        }
1746 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1747  
1748          // unspecified behavior
2075        Integer v;
1749          try {
1750 <            assertEquals(inc(v1), h.join());
1751 <            assertEquals(1, r.invocationCount);
1750 >            assertEquals(inc(v1), h1.join());
1751 >            assertEquals(1, r1.invocationCount);
1752          } catch (CompletionException ok) {
1753 <            checkCompletedWithWrappedCFException(h, ex);
1754 <            assertEquals(0, r.invocationCount);
1753 >            checkCompletedWithWrappedCFException(h1, ex);
1754 >            assertEquals(0, r1.invocationCount);
1755          }
1756  
2084        checkCompletedWithWrappedCFException(g, ex);
2085        checkCompletedNormally(f, v1);
2086    }}
2087
2088    public void testApplyToEither_exceptionalCompletion4() {
2089        for (ExecutionMode m : ExecutionMode.values())
2090        for (Integer v1 : new Integer[] { 1, null })
2091    {
2092        final CompletableFuture<Integer> f = new CompletableFuture<>();
2093        final CompletableFuture<Integer> g = new CompletableFuture<>();
2094        final IncFunction r = new IncFunction();
2095        final CFException ex = new CFException();
2096
2097        f.completeExceptionally(ex);
2098        g.complete(v1);
2099        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2100
2101        // unspecified behavior
2102        Integer v;
1757          try {
1758 <            assertEquals(inc(v1), h.join());
1759 <            assertEquals(1, r.invocationCount);
1758 >            assertEquals(inc(v1), h2.join());
1759 >            assertEquals(1, r2.invocationCount);
1760          } catch (CompletionException ok) {
1761 <            checkCompletedWithWrappedCFException(h, ex);
1762 <            assertEquals(0, r.invocationCount);
1761 >            checkCompletedWithWrappedCFException(h2, ex);
1762 >            assertEquals(0, r2.invocationCount);
1763          }
1764  
1765 <        checkCompletedWithWrappedCFException(f, ex);
1766 <        checkCompletedNormally(g, v1);
1765 >        checkCompletedWithWrappedCFException(g, ex);
1766 >        checkCompletedNormally(f, v1);
1767      }}
1768  
1769      /**
# Line 2122 | Line 1776 | public class CompletableFutureTest exten
1776      {
1777          final CompletableFuture<Integer> f = new CompletableFuture<>();
1778          final CompletableFuture<Integer> g = new CompletableFuture<>();
1779 <        final FailingFunction r = new FailingFunction();
1779 >        final FailingFunction r = new FailingFunction(m);
1780          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1781  
1782          f.complete(v1);
# Line 2139 | Line 1793 | public class CompletableFutureTest exten
1793      {
1794          final CompletableFuture<Integer> f = new CompletableFuture<>();
1795          final CompletableFuture<Integer> g = new CompletableFuture<>();
1796 <        final FailingFunction r = new FailingFunction();
1796 >        final FailingFunction r = new FailingFunction(m);
1797          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1798  
1799          g.complete(v2);
# Line 2155 | Line 1809 | public class CompletableFutureTest exten
1809      public void testApplyToEither_sourceCancelled1() {
1810          for (ExecutionMode m : ExecutionMode.values())
1811          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1812 +        for (boolean createIncomplete : new boolean[] { true, false })
1813 +        for (boolean fFirst : new boolean[] { true, false })
1814          for (Integer v1 : new Integer[] { 1, null })
1815      {
1816          final CompletableFuture<Integer> f = new CompletableFuture<>();
1817          final CompletableFuture<Integer> g = new CompletableFuture<>();
1818 <        final IncFunction r = new IncFunction();
2163 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1818 >        final IncFunction r = new IncFunction(m);
1819  
1820 <        assertTrue(f.cancel(mayInterruptIfRunning));
2166 <        checkCompletedWithWrappedCancellationException(h);
2167 <        g.complete(v1);
2168 <
2169 <        checkCancelled(f);
2170 <        assertEquals(0, r.invocationCount);
2171 <        checkCompletedNormally(g, v1);
2172 <        checkCompletedWithWrappedCancellationException(h);
2173 <    }}
2174 <
2175 <    public void testApplyToEither_sourceCancelled2() {
2176 <        for (ExecutionMode m : ExecutionMode.values())
2177 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2178 <        for (Integer v1 : new Integer[] { 1, null })
2179 <    {
2180 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2181 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2182 <        final IncFunction r = new IncFunction();
1820 >        if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1821          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1822 +        if (createIncomplete) {
1823 +            checkIncomplete(h);
1824 +            assertEquals(0, r.invocationCount);
1825 +            assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1826 +        }
1827  
2185        assertTrue(g.cancel(mayInterruptIfRunning));
1828          checkCompletedWithWrappedCancellationException(h);
1829 <        f.complete(v1);
1829 >        (!fFirst ? f : g).complete(v1);
1830  
2189        checkCancelled(g);
1831          assertEquals(0, r.invocationCount);
1832 <        checkCompletedNormally(f, v1);
1832 >        checkCompletedNormally(!fFirst ? f : g, v1);
1833 >        checkCancelled(fFirst ? f : g);
1834          checkCompletedWithWrappedCancellationException(h);
1835      }}
1836  
1837 <    public void testApplyToEither_sourceCancelled3() {
1837 >    public void testApplyToEither_sourceCancelled2() {
1838          for (ExecutionMode m : ExecutionMode.values())
1839          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1840 +        for (boolean reverseArgs : new boolean[] { true, false })
1841 +        for (boolean fFirst : new boolean[] { true, false })
1842          for (Integer v1 : new Integer[] { 1, null })
1843      {
1844          final CompletableFuture<Integer> f = new CompletableFuture<>();
1845          final CompletableFuture<Integer> g = new CompletableFuture<>();
1846 <        final IncFunction r = new IncFunction();
1846 >        final IncFunction r1 = new IncFunction(m);
1847 >        final IncFunction r2 = new IncFunction(m);
1848 >        final CFException ex = new CFException();
1849 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1850 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1851  
1852 <        assertTrue(g.cancel(mayInterruptIfRunning));
1853 <        f.complete(v1);
1854 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1852 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1853 >        if (fFirst) {
1854 >            f.complete(v1);
1855 >            assertTrue(g.cancel(mayInterruptIfRunning));
1856 >        } else {
1857 >            assertTrue(g.cancel(mayInterruptIfRunning));
1858 >            f.complete(v1);
1859 >        }
1860 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1861  
1862          // unspecified behavior
2209        Integer v;
1863          try {
1864 <            assertEquals(inc(v1), h.join());
1865 <            assertEquals(1, r.invocationCount);
1864 >            assertEquals(inc(v1), h1.join());
1865 >            assertEquals(1, r1.invocationCount);
1866          } catch (CompletionException ok) {
1867 <            checkCompletedWithWrappedCancellationException(h);
1868 <            assertEquals(0, r.invocationCount);
1867 >            checkCompletedWithWrappedCancellationException(h1);
1868 >            assertEquals(0, r1.invocationCount);
1869          }
1870  
2218        checkCancelled(g);
2219        checkCompletedNormally(f, v1);
2220    }}
2221
2222    public void testApplyToEither_sourceCancelled4() {
2223        for (ExecutionMode m : ExecutionMode.values())
2224        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2225        for (Integer v1 : new Integer[] { 1, null })
2226    {
2227        final CompletableFuture<Integer> f = new CompletableFuture<>();
2228        final CompletableFuture<Integer> g = new CompletableFuture<>();
2229        final IncFunction r = new IncFunction();
2230
2231        assertTrue(f.cancel(mayInterruptIfRunning));
2232        g.complete(v1);
2233        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2234
2235        // unspecified behavior
2236        Integer v;
1871          try {
1872 <            assertEquals(inc(v1), h.join());
1873 <            assertEquals(1, r.invocationCount);
1872 >            assertEquals(inc(v1), h2.join());
1873 >            assertEquals(1, r2.invocationCount);
1874          } catch (CompletionException ok) {
1875 <            checkCompletedWithWrappedCancellationException(h);
1876 <            assertEquals(0, r.invocationCount);
1875 >            checkCompletedWithWrappedCancellationException(h2);
1876 >            assertEquals(0, r2.invocationCount);
1877          }
1878  
1879 <        checkCancelled(f);
1880 <        checkCompletedNormally(g, v1);
1879 >        checkCancelled(g);
1880 >        checkCompletedNormally(f, v1);
1881      }}
1882  
1883      /**
# Line 2422 | Line 2056 | public class CompletableFutureTest exten
2056      {
2057          final CompletableFuture<Integer> f = new CompletableFuture<>();
2058          final CompletableFuture<Integer> g = new CompletableFuture<>();
2059 <        final FailingConsumer r = new FailingConsumer();
2059 >        final FailingConsumer r = new FailingConsumer(m);
2060          final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2061  
2062          f.complete(v1);
# Line 2439 | Line 2073 | public class CompletableFutureTest exten
2073      {
2074          final CompletableFuture<Integer> f = new CompletableFuture<>();
2075          final CompletableFuture<Integer> g = new CompletableFuture<>();
2076 <        final FailingConsumer r = new FailingConsumer();
2076 >        final FailingConsumer r = new FailingConsumer(m);
2077          final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2078  
2079          g.complete(v2);
# Line 2559 | Line 2193 | public class CompletableFutureTest exten
2193      {
2194          final CompletableFuture<Integer> f = new CompletableFuture<>();
2195          final CompletableFuture<Integer> g = new CompletableFuture<>();
2196 <        final Noop r = new Noop();
2196 >        final Noop r = new Noop(m);
2197          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2198  
2199          f.complete(v1);
# Line 2580 | Line 2214 | public class CompletableFutureTest exten
2214      {
2215          final CompletableFuture<Integer> f = new CompletableFuture<>();
2216          final CompletableFuture<Integer> g = new CompletableFuture<>();
2217 <        final Noop r = new Noop();
2217 >        final Noop r = new Noop(m);
2218          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2219  
2220          g.complete(v2);
# Line 2601 | Line 2235 | public class CompletableFutureTest exten
2235      {
2236          final CompletableFuture<Integer> f = new CompletableFuture<>();
2237          final CompletableFuture<Integer> g = new CompletableFuture<>();
2238 <        final Noop r = new Noop();
2238 >        final Noop r = new Noop(m);
2239  
2240          f.complete(v1);
2241          g.complete(v2);
# Line 2623 | Line 2257 | public class CompletableFutureTest exten
2257      {
2258          final CompletableFuture<Integer> f = new CompletableFuture<>();
2259          final CompletableFuture<Integer> g = new CompletableFuture<>();
2260 <        final Noop r = new Noop();
2260 >        final Noop r = new Noop(m);
2261          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2262          final CFException ex = new CFException();
2263  
# Line 2643 | Line 2277 | public class CompletableFutureTest exten
2277      {
2278          final CompletableFuture<Integer> f = new CompletableFuture<>();
2279          final CompletableFuture<Integer> g = new CompletableFuture<>();
2280 <        final Noop r = new Noop();
2280 >        final Noop r = new Noop(m);
2281          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2282          final CFException ex = new CFException();
2283  
# Line 2663 | Line 2297 | public class CompletableFutureTest exten
2297      {
2298          final CompletableFuture<Integer> f = new CompletableFuture<>();
2299          final CompletableFuture<Integer> g = new CompletableFuture<>();
2300 <        final Noop r = new Noop();
2300 >        final Noop r = new Noop(m);
2301          final CFException ex = new CFException();
2302  
2303          g.completeExceptionally(ex);
# Line 2690 | Line 2324 | public class CompletableFutureTest exten
2324      {
2325          final CompletableFuture<Integer> f = new CompletableFuture<>();
2326          final CompletableFuture<Integer> g = new CompletableFuture<>();
2327 <        final Noop r = new Noop();
2327 >        final Noop r = new Noop(m);
2328          final CFException ex = new CFException();
2329  
2330          f.completeExceptionally(ex);
# Line 2721 | Line 2355 | public class CompletableFutureTest exten
2355      {
2356          final CompletableFuture<Integer> f = new CompletableFuture<>();
2357          final CompletableFuture<Integer> g = new CompletableFuture<>();
2358 <        final FailingNoop r = new FailingNoop();
2358 >        final FailingRunnable r = new FailingRunnable(m);
2359          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2360  
2361          f.complete(v1);
# Line 2738 | Line 2372 | public class CompletableFutureTest exten
2372      {
2373          final CompletableFuture<Integer> f = new CompletableFuture<>();
2374          final CompletableFuture<Integer> g = new CompletableFuture<>();
2375 <        final FailingNoop r = new FailingNoop();
2375 >        final FailingRunnable r = new FailingRunnable(m);
2376          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2377  
2378          g.complete(v2);
# Line 2758 | Line 2392 | public class CompletableFutureTest exten
2392      {
2393          final CompletableFuture<Integer> f = new CompletableFuture<>();
2394          final CompletableFuture<Integer> g = new CompletableFuture<>();
2395 <        final Noop r = new Noop();
2395 >        final Noop r = new Noop(m);
2396          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2397  
2398          assertTrue(f.cancel(mayInterruptIfRunning));
# Line 2778 | Line 2412 | public class CompletableFutureTest exten
2412      {
2413          final CompletableFuture<Integer> f = new CompletableFuture<>();
2414          final CompletableFuture<Integer> g = new CompletableFuture<>();
2415 <        final Noop r = new Noop();
2415 >        final Noop r = new Noop(m);
2416          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2417  
2418          assertTrue(g.cancel(mayInterruptIfRunning));
# Line 2798 | Line 2432 | public class CompletableFutureTest exten
2432      {
2433          final CompletableFuture<Integer> f = new CompletableFuture<>();
2434          final CompletableFuture<Integer> g = new CompletableFuture<>();
2435 <        final Noop r = new Noop();
2435 >        final Noop r = new Noop(m);
2436  
2437          assertTrue(g.cancel(mayInterruptIfRunning));
2438          f.complete(v1);
# Line 2825 | Line 2459 | public class CompletableFutureTest exten
2459      {
2460          final CompletableFuture<Integer> f = new CompletableFuture<>();
2461          final CompletableFuture<Integer> g = new CompletableFuture<>();
2462 <        final Noop r = new Noop();
2462 >        final Noop r = new Noop(m);
2463  
2464          assertTrue(f.cancel(mayInterruptIfRunning));
2465          g.complete(v1);
# Line 2854 | Line 2488 | public class CompletableFutureTest exten
2488          for (Integer v1 : new Integer[] { 1, null })
2489      {
2490          final CompletableFuture<Integer> f = new CompletableFuture<>();
2491 <        final CompletableFutureInc r = new CompletableFutureInc();
2491 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2492          if (!createIncomplete) f.complete(v1);
2493 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2493 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2494          if (createIncomplete) f.complete(v1);
2495  
2496          checkCompletedNormally(g, inc(v1));
# Line 2873 | Line 2507 | public class CompletableFutureTest exten
2507          for (boolean createIncomplete : new boolean[] { true, false })
2508      {
2509          final CFException ex = new CFException();
2510 <        final CompletableFutureInc r = new CompletableFutureInc();
2510 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2511          final CompletableFuture<Integer> f = new CompletableFuture<>();
2512          if (!createIncomplete) f.completeExceptionally(ex);
2513 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2513 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2514          if (createIncomplete) f.completeExceptionally(ex);
2515  
2516          checkCompletedWithWrappedCFException(g, ex);
# Line 2894 | Line 2528 | public class CompletableFutureTest exten
2528      {
2529          final CompletableFuture<Integer> f = new CompletableFuture<>();
2530          final FailingCompletableFutureFunction r
2531 <            = new FailingCompletableFutureFunction();
2531 >            = new FailingCompletableFutureFunction(m);
2532          if (!createIncomplete) f.complete(v1);
2533 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2533 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2534          if (createIncomplete) f.complete(v1);
2535  
2536          checkCompletedWithWrappedCFException(g);
# Line 2912 | Line 2546 | public class CompletableFutureTest exten
2546          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2547      {
2548          final CompletableFuture<Integer> f = new CompletableFuture<>();
2549 <        final CompletableFutureInc r = new CompletableFutureInc();
2549 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2550          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2551 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2552 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2551 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2552 >        if (createIncomplete) {
2553 >            checkIncomplete(g);
2554 >            assertTrue(f.cancel(mayInterruptIfRunning));
2555 >        }
2556  
2557          checkCompletedWithWrappedCancellationException(g);
2558          checkCancelled(f);
2559      }}
2560  
2924    // asyncs
2925
2926    /**
2927     * thenApplyAsync result completes normally after normal completion of source
2928     */
2929    public void testThenApplyAsync() {
2930        CompletableFuture<Integer> f = new CompletableFuture<>();
2931        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
2932        f.complete(one);
2933        checkCompletedNormally(g, two);
2934    }
2935
2936    /**
2937     * thenApplyAsync result completes exceptionally after exceptional
2938     * completion of source
2939     */
2940    public void testThenApplyAsync2() {
2941        CompletableFuture<Integer> f = new CompletableFuture<>();
2942        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
2943        f.completeExceptionally(new CFException());
2944        checkCompletedWithWrappedCFException(g);
2945    }
2946
2947    /**
2948     * thenApplyAsync result completes exceptionally if action does
2949     */
2950    public void testThenApplyAsync3() {
2951        CompletableFuture<Integer> f = new CompletableFuture<>();
2952        FailingFunction r = new FailingFunction();
2953        CompletableFuture<Integer> g = f.thenApplyAsync(r);
2954        f.complete(null);
2955        checkCompletedWithWrappedCFException(g);
2956    }
2957
2958    /**
2959     * thenApplyAsync result completes exceptionally if source cancelled
2960     */
2961    public void testThenApplyAsync4() {
2962        CompletableFuture<Integer> f = new CompletableFuture<>();
2963        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
2964        assertTrue(f.cancel(true));
2965        checkCompletedWithWrappedCancellationException(g);
2966    }
2967
2968    /**
2969     * thenAcceptAsync result completes normally after normal
2970     * completion of source
2971     */
2972    public void testThenAcceptAsync() {
2973        CompletableFuture<Integer> f = new CompletableFuture<>();
2974        IncAction r = new IncAction();
2975        CompletableFuture<Void> g = f.thenAcceptAsync(r);
2976        f.complete(one);
2977        checkCompletedNormally(g, null);
2978        assertEquals(r.value, (Integer) 2);
2979    }
2980
2981    /**
2982     * thenAcceptAsync result completes exceptionally after exceptional
2983     * completion of source
2984     */
2985    public void testThenAcceptAsync2() {
2986        CompletableFuture<Integer> f = new CompletableFuture<>();
2987        IncAction r = new IncAction();
2988        CompletableFuture<Void> g = f.thenAcceptAsync(r);
2989        f.completeExceptionally(new CFException());
2990        checkCompletedWithWrappedCFException(g);
2991    }
2992
2993    /**
2994     * thenAcceptAsync result completes exceptionally if action does
2995     */
2996    public void testThenAcceptAsync3() {
2997        CompletableFuture<Integer> f = new CompletableFuture<>();
2998        FailingConsumer r = new FailingConsumer();
2999        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3000        f.complete(null);
3001        checkCompletedWithWrappedCFException(g);
3002    }
3003
3004    /**
3005     * thenAcceptAsync result completes exceptionally if source cancelled
3006     */
3007    public void testThenAcceptAsync4() {
3008        CompletableFuture<Integer> f = new CompletableFuture<>();
3009        IncAction r = new IncAction();
3010        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3011        assertTrue(f.cancel(true));
3012        checkCompletedWithWrappedCancellationException(g);
3013    }
3014
3015    // async with explicit executors
3016
3017    /**
3018     * thenApplyAsync result completes normally after normal completion of source
3019     */
3020    public void testThenApplyAsyncE() {
3021        CompletableFuture<Integer> f = new CompletableFuture<>();
3022        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3023        f.complete(one);
3024        checkCompletedNormally(g, two);
3025    }
3026
3027    /**
3028     * thenApplyAsync result completes exceptionally after exceptional
3029     * completion of source
3030     */
3031    public void testThenApplyAsync2E() {
3032        CompletableFuture<Integer> f = new CompletableFuture<>();
3033        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3034        f.completeExceptionally(new CFException());
3035        checkCompletedWithWrappedCFException(g);
3036    }
3037
3038    /**
3039     * thenApplyAsync result completes exceptionally if action does
3040     */
3041    public void testThenApplyAsync3E() {
3042        CompletableFuture<Integer> f = new CompletableFuture<>();
3043        FailingFunction r = new FailingFunction();
3044        CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
3045        f.complete(null);
3046        checkCompletedWithWrappedCFException(g);
3047    }
3048
3049    /**
3050     * thenApplyAsync result completes exceptionally if source cancelled
3051     */
3052    public void testThenApplyAsync4E() {
3053        CompletableFuture<Integer> f = new CompletableFuture<>();
3054        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3055        assertTrue(f.cancel(true));
3056        checkCompletedWithWrappedCancellationException(g);
3057    }
3058
3059    /**
3060     * thenAcceptAsync result completes normally after normal
3061     * completion of source
3062     */
3063    public void testThenAcceptAsyncE() {
3064        CompletableFuture<Integer> f = new CompletableFuture<>();
3065        IncAction r = new IncAction();
3066        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3067        f.complete(one);
3068        checkCompletedNormally(g, null);
3069        assertEquals(r.value, (Integer) 2);
3070    }
3071
3072    /**
3073     * thenAcceptAsync result completes exceptionally after exceptional
3074     * completion of source
3075     */
3076    public void testThenAcceptAsync2E() {
3077        CompletableFuture<Integer> f = new CompletableFuture<>();
3078        IncAction r = new IncAction();
3079        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3080        f.completeExceptionally(new CFException());
3081        checkCompletedWithWrappedCFException(g);
3082    }
3083
3084    /**
3085     * thenAcceptAsync result completes exceptionally if action does
3086     */
3087    public void testThenAcceptAsync3E() {
3088        CompletableFuture<Integer> f = new CompletableFuture<>();
3089        FailingConsumer r = new FailingConsumer();
3090        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3091        f.complete(null);
3092        checkCompletedWithWrappedCFException(g);
3093    }
3094
3095    /**
3096     * thenAcceptAsync result completes exceptionally if source cancelled
3097     */
3098    public void testThenAcceptAsync4E() {
3099        CompletableFuture<Integer> f = new CompletableFuture<>();
3100        IncAction r = new IncAction();
3101        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3102        assertTrue(f.cancel(true));
3103        checkCompletedWithWrappedCancellationException(g);
3104    }
3105
2561      // other static methods
2562  
2563      /**
# Line 3265 | Line 2720 | public class CompletableFutureTest exten
2720  
2721              () -> f.thenCompose(null),
2722              () -> f.thenComposeAsync(null),
2723 <            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
2723 >            () -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null),
2724              () -> f.thenComposeAsync(null, exec),
2725  
2726              () -> f.exceptionally(null),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines