ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.47 by jsr166, Mon Jun 2 18:21:34 2014 UTC vs.
Revision 1.52 by jsr166, Mon Jun 2 20:10:04 2014 UTC

# Line 17 | Line 17 | import java.util.concurrent.Future;
17   import java.util.concurrent.CompletableFuture;
18   import java.util.concurrent.CompletionException;
19   import java.util.concurrent.CompletionStage;
20 + import java.util.concurrent.ForkJoinPool;
21 + import java.util.concurrent.ForkJoinTask;
22   import java.util.concurrent.TimeoutException;
23   import java.util.concurrent.atomic.AtomicInteger;
24   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 414 | Line 416 | public class CompletableFutureTest exten
416              throw new CFException();
417          }
418      }
419 <    static final class FailingNoop implements Runnable {
419 >    static final class FailingRunnable implements Runnable {
420          int invocationCount = 0;
421          public void run() {
422              invocationCount++;
# Line 458 | Line 460 | public class CompletableFutureTest exten
460       */
461      enum ExecutionMode {
462          DEFAULT {
463 +            public void checkExecutionMode() {
464 +                assertNull(ForkJoinTask.getPool());
465 +            }
466              public <T> CompletableFuture<Void> thenRun
467                  (CompletableFuture<T> f, Runnable a) {
468                  return f.thenRun(a);
# Line 521 | Line 526 | public class CompletableFutureTest exten
526              }
527          },
528  
529 <        DEFAULT_ASYNC {
529 >        ASYNC {
530 >            public void checkExecutionMode() {
531 >                assertSame(ForkJoinPool.commonPool(),
532 >                           ForkJoinTask.getPool());
533 >            }
534              public <T> CompletableFuture<Void> thenRun
535                  (CompletableFuture<T> f, Runnable a) {
536                  return f.thenRunAsync(a);
# Line 586 | Line 595 | public class CompletableFutureTest exten
595          },
596  
597          EXECUTOR {
598 +            public void checkExecutionMode() {
599 +                //TODO
600 +            }
601              public <T> CompletableFuture<Void> thenRun
602                  (CompletableFuture<T> f, Runnable a) {
603                  return f.thenRunAsync(a, new ThreadExecutor());
# Line 649 | Line 661 | public class CompletableFutureTest exten
661              }
662          };
663  
664 +        public abstract void checkExecutionMode();
665          public abstract <T> CompletableFuture<Void> thenRun
666              (CompletableFuture<T> f, Runnable a);
667          public abstract <T> CompletableFuture<Void> thenAccept
# Line 920 | Line 933 | public class CompletableFutureTest exten
933       * failing runAsync completes exceptionally after running Runnable
934       */
935      public void testRunAsync3() {
936 <        FailingNoop r = new FailingNoop();
936 >        FailingRunnable r = new FailingRunnable();
937          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
938          checkCompletedWithWrappedCFException(f);
939          assertEquals(1, r.invocationCount);
# Line 961 | Line 974 | public class CompletableFutureTest exten
974      /**
975       * thenRun result completes normally after normal completion of source
976       */
977 <    public void testThenRun() {
978 <        CompletableFuture<Integer> f;
979 <        CompletableFuture<Void> g;
980 <        Noop r;
981 <
982 <        f = new CompletableFuture<>();
983 <        g = f.thenRun(r = new Noop());
984 <        f.complete(null);
985 <        checkCompletedNormally(g, null);
986 <        assertEquals(1, r.invocationCount);
977 >    public void testThenRun_normalCompletion() {
978 >        for (ExecutionMode m : ExecutionMode.values())
979 >        for (boolean createIncomplete : new boolean[] { true, false })
980 >        for (Integer v1 : new Integer[] { 1, null })
981 >    {
982 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
983 >        final Noop r = new Noop();
984 >        if (!createIncomplete) f.complete(v1);
985 >        final CompletableFuture<Void> g = m.thenRun(f, r);
986 >        if (createIncomplete) {
987 >            checkIncomplete(g);
988 >            f.complete(v1);
989 >        }
990  
975        f = new CompletableFuture<>();
976        f.complete(null);
977        g = f.thenRun(r = new Noop());
991          checkCompletedNormally(g, null);
992 +        checkCompletedNormally(f, v1);
993          assertEquals(1, r.invocationCount);
994 <    }
994 >    }}
995  
996      /**
997       * thenRun result completes exceptionally after exceptional
998       * completion of source
999       */
1000 <    public void testThenRun2() {
1001 <        CompletableFuture<Integer> f;
1002 <        CompletableFuture<Void> g;
1003 <        Noop r;
1004 <
1005 <        f = new CompletableFuture<>();
1006 <        g = f.thenRun(r = new Noop());
1007 <        f.completeExceptionally(new CFException());
1008 <        checkCompletedWithWrappedCFException(g);
1009 <        assertEquals(0, r.invocationCount);
1000 >    public void testThenRun_exceptionalCompletion() {
1001 >        for (ExecutionMode m : ExecutionMode.values())
1002 >        for (boolean createIncomplete : new boolean[] { true, false })
1003 >    {
1004 >        final CFException ex = new CFException();
1005 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1006 >        final Noop r = new Noop();
1007 >        if (!createIncomplete) f.completeExceptionally(ex);
1008 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1009 >        if (createIncomplete) {
1010 >            checkIncomplete(g);
1011 >            f.completeExceptionally(ex);
1012 >        }
1013  
1014 <        f = new CompletableFuture<>();
1015 <        f.completeExceptionally(new CFException());
999 <        g = f.thenRun(r = new Noop());
1000 <        checkCompletedWithWrappedCFException(g);
1014 >        checkCompletedWithWrappedCFException(g, ex);
1015 >        checkCompletedWithWrappedCFException(f, ex);
1016          assertEquals(0, r.invocationCount);
1017 <    }
1003 <
1004 <    /**
1005 <     * thenRun result completes exceptionally if action does
1006 <     */
1007 <    public void testThenRun3() {
1008 <        CompletableFuture<Integer> f;
1009 <        CompletableFuture<Void> g;
1010 <        FailingNoop r;
1011 <
1012 <        f = new CompletableFuture<>();
1013 <        g = f.thenRun(r = new FailingNoop());
1014 <        f.complete(null);
1015 <        checkCompletedWithWrappedCFException(g);
1016 <
1017 <        f = new CompletableFuture<>();
1018 <        f.complete(null);
1019 <        g = f.thenRun(r = new FailingNoop());
1020 <        checkCompletedWithWrappedCFException(g);
1021 <    }
1017 >    }}
1018  
1019      /**
1020       * thenRun result completes exceptionally if source cancelled
1021       */
1022 <    public void testThenRun4() {
1023 <        CompletableFuture<Integer> f;
1024 <        CompletableFuture<Void> g;
1025 <        Noop r;
1026 <
1027 <        f = new CompletableFuture<>();
1028 <        g = f.thenRun(r = new Noop());
1029 <        assertTrue(f.cancel(true));
1030 <        checkCompletedWithWrappedCancellationException(g);
1031 <
1032 <        f = new CompletableFuture<>();
1033 <        assertTrue(f.cancel(true));
1034 <        g = f.thenRun(r = new Noop());
1039 <        checkCompletedWithWrappedCancellationException(g);
1040 <    }
1041 <
1042 <    /**
1043 <     * thenApply result completes normally after normal completion of source
1044 <     */
1045 <    public void testThenApply() {
1046 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1047 <        CompletableFuture<Integer> g = f.thenApply(inc);
1048 <        f.complete(one);
1049 <        checkCompletedNormally(g, two);
1050 <    }
1051 <
1052 <    /**
1053 <     * thenApply result completes exceptionally after exceptional
1054 <     * completion of source
1055 <     */
1056 <    public void testThenApply2() {
1057 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1058 <        CompletableFuture<Integer> g = f.thenApply(inc);
1059 <        f.completeExceptionally(new CFException());
1060 <        checkCompletedWithWrappedCFException(g);
1061 <    }
1062 <
1063 <    /**
1064 <     * thenApply result completes exceptionally if action does
1065 <     */
1066 <    public void testThenApply3() {
1067 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1068 <        CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
1069 <        f.complete(one);
1070 <        checkCompletedWithWrappedCFException(g);
1071 <    }
1022 >    public void testThenRun_sourceCancelled() {
1023 >        for (ExecutionMode m : ExecutionMode.values())
1024 >        for (boolean createIncomplete : new boolean[] { true, false })
1025 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1026 >    {
1027 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1028 >        final Noop r = new Noop();
1029 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1030 >        final CompletableFuture<Void> g = f.thenRun(r);
1031 >        if (createIncomplete) {
1032 >            checkIncomplete(g);
1033 >            assertTrue(f.cancel(mayInterruptIfRunning));
1034 >        }
1035  
1073    /**
1074     * thenApply result completes exceptionally if source cancelled
1075     */
1076    public void testThenApply4() {
1077        CompletableFuture<Integer> f = new CompletableFuture<>();
1078        CompletableFuture<Integer> g = f.thenApply(inc);
1079        assertTrue(f.cancel(true));
1036          checkCompletedWithWrappedCancellationException(g);
1037 <    }
1038 <
1039 <    /**
1084 <     * thenAccept result completes normally after normal completion of source
1085 <     */
1086 <    public void testThenAccept() {
1087 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1088 <        IncAction r = new IncAction();
1089 <        CompletableFuture<Void> g = f.thenAccept(r);
1090 <        f.complete(one);
1091 <        checkCompletedNormally(g, null);
1092 <        assertEquals(r.value, (Integer) 2);
1093 <    }
1037 >        checkCancelled(f);
1038 >        assertEquals(0, r.invocationCount);
1039 >    }}
1040  
1041      /**
1042 <     * thenAccept result completes exceptionally after exceptional
1097 <     * completion of source
1042 >     * thenRun result completes exceptionally if action does
1043       */
1044 <    public void testThenAccept2() {
1045 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1046 <        IncAction r = new IncAction();
1047 <        CompletableFuture<Void> g = f.thenAccept(r);
1048 <        f.completeExceptionally(new CFException());
1049 <        checkCompletedWithWrappedCFException(g);
1050 <    }
1044 >    public void testThenRun_actionFailed() {
1045 >        for (ExecutionMode m : ExecutionMode.values())
1046 >        for (boolean createIncomplete : new boolean[] { true, false })
1047 >        for (Integer v1 : new Integer[] { 1, null })
1048 >    {
1049 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1050 >        final FailingRunnable r = new FailingRunnable();
1051 >        if (!createIncomplete) f.complete(v1);
1052 >        final CompletableFuture<Void> g = f.thenRun(r);
1053 >        if (createIncomplete) {
1054 >            checkIncomplete(g);
1055 >            f.complete(v1);
1056 >        }
1057  
1107    /**
1108     * thenAccept result completes exceptionally if action does
1109     */
1110    public void testThenAccept3() {
1111        CompletableFuture<Integer> f = new CompletableFuture<>();
1112        FailingConsumer r = new FailingConsumer();
1113        CompletableFuture<Void> g = f.thenAccept(r);
1114        f.complete(one);
1058          checkCompletedWithWrappedCFException(g);
1059 <        assertEquals(1, r.invocationCount);
1060 <    }
1118 <
1119 <    /**
1120 <     * thenAccept result completes exceptionally if source cancelled
1121 <     */
1122 <    public void testThenAccept4() {
1123 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1124 <        IncAction r = new IncAction();
1125 <        CompletableFuture<Void> g = f.thenAccept(r);
1126 <        assertTrue(f.cancel(true));
1127 <        checkCompletedWithWrappedCancellationException(g);
1128 <    }
1059 >        checkCompletedNormally(f, v1);
1060 >    }}
1061  
1062      /**
1063 <     * thenCombine result completes normally after normal completion
1132 <     * of sources
1063 >     * thenApply result completes normally after normal completion of source
1064       */
1065 <    public void testThenCombine_normalCompletion1() {
1135 <        for (boolean createIncomplete : new boolean[] { true, false })
1136 <        for (boolean fFirst : new boolean[] { true, false })
1065 >    public void testThenApply_normalCompletion() {
1066          for (ExecutionMode m : ExecutionMode.values())
1067 +        for (boolean createIncomplete : new boolean[] { true, false })
1068          for (Integer v1 : new Integer[] { 1, null })
1139        for (Integer v2 : new Integer[] { 2, null })
1069      {
1070          final CompletableFuture<Integer> f = new CompletableFuture<>();
1071 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1072 <        final SubtractFunction r = new SubtractFunction();
1073 <        CompletableFuture<Integer> h = null;
1074 <        if (createIncomplete) h = m.thenCombine(f, g, r);
1075 <
1147 <        if (fFirst)
1148 <            f.complete(v1);
1149 <        else
1150 <            g.complete(v2);
1151 <        if (createIncomplete) checkIncomplete(h);
1152 <        assertEquals(0, r.invocationCount);
1153 <        if (!fFirst)
1071 >        final IncFunction r = new IncFunction();
1072 >        if (!createIncomplete) f.complete(v1);
1073 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1074 >        if (createIncomplete) {
1075 >            checkIncomplete(g);
1076              f.complete(v1);
1077 <        else
1156 <            g.complete(v2);
1157 <        if (!createIncomplete) h = m.thenCombine(f, g, r);
1077 >        }
1078  
1079 <        checkCompletedNormally(h, subtract(v1, v2));
1079 >        checkCompletedNormally(g, inc(v1));
1080          checkCompletedNormally(f, v1);
1161        checkCompletedNormally(g, v2);
1081          assertEquals(1, r.invocationCount);
1082      }}
1083  
1084      /**
1085 <     * thenCombine result completes exceptionally after exceptional
1086 <     * completion of either source
1085 >     * thenApply result completes exceptionally after exceptional
1086 >     * completion of source
1087       */
1088 <    public void testThenCombine_exceptionalCompletion1() {
1088 >    public void testThenApply_exceptionalCompletion() {
1089          for (ExecutionMode m : ExecutionMode.values())
1090 <        for (Integer v1 : new Integer[] { 1, null })
1090 >        for (boolean createIncomplete : new boolean[] { true, false })
1091      {
1173        final CompletableFuture<Integer> f = new CompletableFuture<>();
1174        final CompletableFuture<Integer> g = new CompletableFuture<>();
1175        final SubtractFunction r = new SubtractFunction();
1176        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1092          final CFException ex = new CFException();
1093 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1094 +        final IncFunction r = new IncFunction();
1095 +        if (!createIncomplete) f.completeExceptionally(ex);
1096 +        final CompletableFuture<Integer> g = m.thenApply(f, r);
1097 +        if (createIncomplete) {
1098 +            checkIncomplete(g);
1099 +            f.completeExceptionally(ex);
1100 +        }
1101  
1102 <        f.completeExceptionally(ex);
1180 <        checkIncomplete(h);
1181 <        g.complete(v1);
1182 <
1183 <        checkCompletedWithWrappedCFException(h, ex);
1102 >        checkCompletedWithWrappedCFException(g, ex);
1103          checkCompletedWithWrappedCFException(f, ex);
1104          assertEquals(0, r.invocationCount);
1186        checkCompletedNormally(g, v1);
1105      }}
1106  
1107 <    public void testThenCombine_exceptionalCompletion2() {
1107 >    /**
1108 >     * thenApply result completes exceptionally if source cancelled
1109 >     */
1110 >    public void testThenApply_sourceCancelled() {
1111          for (ExecutionMode m : ExecutionMode.values())
1112 <        for (Integer v1 : new Integer[] { 1, null })
1112 >        for (boolean createIncomplete : new boolean[] { true, false })
1113 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1114      {
1115          final CompletableFuture<Integer> f = new CompletableFuture<>();
1116 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1117 <        final SubtractFunction r = new SubtractFunction();
1118 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1119 <        final CFException ex = new CFException();
1120 <
1121 <        g.completeExceptionally(ex);
1122 <        checkIncomplete(h);
1201 <        f.complete(v1);
1116 >        final IncFunction r = new IncFunction();
1117 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1118 >        final CompletableFuture<Integer> g = f.thenApply(r);
1119 >        if (createIncomplete) {
1120 >            checkIncomplete(g);
1121 >            assertTrue(f.cancel(mayInterruptIfRunning));
1122 >        }
1123  
1124 <        checkCompletedWithWrappedCFException(h, ex);
1125 <        checkCompletedWithWrappedCFException(g, ex);
1124 >        checkCompletedWithWrappedCancellationException(g);
1125 >        checkCancelled(f);
1126          assertEquals(0, r.invocationCount);
1206        checkCompletedNormally(f, v1);
1127      }}
1128  
1129 <    public void testThenCombine_exceptionalCompletion3() {
1129 >    /**
1130 >     * thenApply result completes exceptionally if action does
1131 >     */
1132 >    public void testThenApply_actionFailed() {
1133          for (ExecutionMode m : ExecutionMode.values())
1134 +        for (boolean createIncomplete : new boolean[] { true, false })
1135          for (Integer v1 : new Integer[] { 1, null })
1136      {
1137          final CompletableFuture<Integer> f = new CompletableFuture<>();
1138 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1139 <        final SubtractFunction r = new SubtractFunction();
1140 <        final CFException ex = new CFException();
1141 <
1142 <        g.completeExceptionally(ex);
1143 <        f.complete(v1);
1144 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1138 >        final FailingFunction r = new FailingFunction();
1139 >        if (!createIncomplete) f.complete(v1);
1140 >        final CompletableFuture<Integer> g = f.thenApply(r);
1141 >        if (createIncomplete) {
1142 >            checkIncomplete(g);
1143 >            f.complete(v1);
1144 >        }
1145  
1146 <        checkCompletedWithWrappedCFException(h, ex);
1223 <        checkCompletedWithWrappedCFException(g, ex);
1224 <        assertEquals(0, r.invocationCount);
1146 >        checkCompletedWithWrappedCFException(g);
1147          checkCompletedNormally(f, v1);
1148      }}
1149  
1150 <    public void testThenCombine_exceptionalCompletion4() {
1150 >    /**
1151 >     * thenAccept result completes normally after normal completion of source
1152 >     */
1153 >    public void testThenAccept_normalCompletion() {
1154          for (ExecutionMode m : ExecutionMode.values())
1155 +        for (boolean createIncomplete : new boolean[] { true, false })
1156          for (Integer v1 : new Integer[] { 1, null })
1157      {
1158          final CompletableFuture<Integer> f = new CompletableFuture<>();
1159 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1160 <        final SubtractFunction r = new SubtractFunction();
1161 <        final CFException ex = new CFException();
1159 >        final IncAction r = new IncAction();
1160 >        if (!createIncomplete) f.complete(v1);
1161 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1162 >        if (createIncomplete) {
1163 >            checkIncomplete(g);
1164 >            f.complete(v1);
1165 >        }
1166  
1167 <        f.completeExceptionally(ex);
1168 <        g.complete(v1);
1169 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1167 >        checkCompletedNormally(g, null);
1168 >        checkCompletedNormally(f, v1);
1169 >        assertEquals(1, r.invocationCount);
1170 >        assertEquals(inc(v1), r.value);
1171 >    }}
1172  
1173 <        checkCompletedWithWrappedCFException(h, ex);
1173 >    /**
1174 >     * thenAccept result completes exceptionally after exceptional
1175 >     * completion of source
1176 >     */
1177 >    public void testThenAccept_exceptionalCompletion() {
1178 >        for (ExecutionMode m : ExecutionMode.values())
1179 >        for (boolean createIncomplete : new boolean[] { true, false })
1180 >    {
1181 >        final CFException ex = new CFException();
1182 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1183 >        final IncAction r = new IncAction();
1184 >        if (!createIncomplete) f.completeExceptionally(ex);
1185 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1186 >        if (createIncomplete) {
1187 >            checkIncomplete(g);
1188 >            f.completeExceptionally(ex);
1189 >        }
1190 >
1191 >        checkCompletedWithWrappedCFException(g, ex);
1192          checkCompletedWithWrappedCFException(f, ex);
1193          assertEquals(0, r.invocationCount);
1244        checkCompletedNormally(g, v1);
1194      }}
1195  
1196      /**
1197 <     * thenCombine result completes exceptionally if action does
1197 >     * thenAccept result completes exceptionally if action does
1198       */
1199 <    public void testThenCombine_actionFailed1() {
1199 >    public void testThenAccept_actionFailed() {
1200          for (ExecutionMode m : ExecutionMode.values())
1201 +        for (boolean createIncomplete : new boolean[] { true, false })
1202          for (Integer v1 : new Integer[] { 1, null })
1253        for (Integer v2 : new Integer[] { 2, null })
1203      {
1204          final CompletableFuture<Integer> f = new CompletableFuture<>();
1205 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1206 <        final FailingBiFunction r = new FailingBiFunction();
1207 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1208 <
1209 <        f.complete(v1);
1210 <        checkIncomplete(h);
1211 <        g.complete(v2);
1205 >        final FailingConsumer r = new FailingConsumer();
1206 >        if (!createIncomplete) f.complete(v1);
1207 >        final CompletableFuture<Void> g = f.thenAccept(r);
1208 >        if (createIncomplete) {
1209 >            checkIncomplete(g);
1210 >            f.complete(v1);
1211 >        }
1212  
1213 <        checkCompletedWithWrappedCFException(h);
1213 >        checkCompletedWithWrappedCFException(g);
1214          checkCompletedNormally(f, v1);
1266        checkCompletedNormally(g, v2);
1215      }}
1216  
1217 <    public void testThenCombine_actionFailed2() {
1217 >    /**
1218 >     * thenAccept result completes exceptionally if source cancelled
1219 >     */
1220 >    public void testThenAccept_sourceCancelled() {
1221          for (ExecutionMode m : ExecutionMode.values())
1222 <        for (Integer v1 : new Integer[] { 1, null })
1223 <        for (Integer v2 : new Integer[] { 2, null })
1222 >        for (boolean createIncomplete : new boolean[] { true, false })
1223 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1224      {
1225          final CompletableFuture<Integer> f = new CompletableFuture<>();
1226 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1227 <        final FailingBiFunction r = new FailingBiFunction();
1228 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1229 <
1230 <        g.complete(v2);
1231 <        checkIncomplete(h);
1232 <        f.complete(v1);
1226 >        final IncAction r = new IncAction();
1227 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1228 >        final CompletableFuture<Void> g = f.thenAccept(r);
1229 >        if (createIncomplete) {
1230 >            checkIncomplete(g);
1231 >            assertTrue(f.cancel(mayInterruptIfRunning));
1232 >        }
1233  
1234 <        checkCompletedWithWrappedCFException(h);
1235 <        checkCompletedNormally(f, v1);
1236 <        checkCompletedNormally(g, v2);
1234 >        checkCompletedWithWrappedCancellationException(g);
1235 >        checkCancelled(f);
1236 >        assertEquals(0, r.invocationCount);
1237      }}
1238  
1239      /**
1240 <     * thenCombine result completes exceptionally if either source cancelled
1240 >     * thenCombine result completes normally after normal completion
1241 >     * of sources
1242       */
1243 <    public void testThenCombine_sourceCancelled1() {
1243 >    public void testThenCombine_normalCompletion() {
1244          for (ExecutionMode m : ExecutionMode.values())
1245 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1245 >        for (boolean createIncomplete : new boolean[] { true, false })
1246 >        for (boolean fFirst : new boolean[] { true, false })
1247          for (Integer v1 : new Integer[] { 1, null })
1248 +        for (Integer v2 : new Integer[] { 2, null })
1249      {
1250          final CompletableFuture<Integer> f = new CompletableFuture<>();
1251          final CompletableFuture<Integer> g = new CompletableFuture<>();
1252          final SubtractFunction r = new SubtractFunction();
1299        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1253  
1254 <        assertTrue(f.cancel(mayInterruptIfRunning));
1255 <        checkIncomplete(h);
1256 <        g.complete(v1);
1254 >        if (fFirst) f.complete(v1); else g.complete(v2);
1255 >        if (!createIncomplete)
1256 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1257 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1258 >        if (createIncomplete) {
1259 >            checkIncomplete(h);
1260 >            assertEquals(0, r.invocationCount);
1261 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1262 >        }
1263  
1264 <        checkCompletedWithWrappedCancellationException(h);
1265 <        checkCancelled(f);
1266 <        assertEquals(0, r.invocationCount);
1267 <        checkCompletedNormally(g, v1);
1264 >        checkCompletedNormally(h, subtract(v1, v2));
1265 >        checkCompletedNormally(f, v1);
1266 >        checkCompletedNormally(g, v2);
1267 >        assertEquals(1, r.invocationCount);
1268      }}
1269  
1270 <    public void testThenCombine_sourceCancelled2() {
1270 >    /**
1271 >     * thenCombine result completes exceptionally after exceptional
1272 >     * completion of either source
1273 >     */
1274 >    public void testThenCombine_exceptionalCompletion() {
1275          for (ExecutionMode m : ExecutionMode.values())
1276 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1276 >        for (boolean createIncomplete : new boolean[] { true, false })
1277 >        for (boolean fFirst : new boolean[] { true, false })
1278          for (Integer v1 : new Integer[] { 1, null })
1279      {
1280          final CompletableFuture<Integer> f = new CompletableFuture<>();
1281          final CompletableFuture<Integer> g = new CompletableFuture<>();
1282 +        final CFException ex = new CFException();
1283          final SubtractFunction r = new SubtractFunction();
1319        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1284  
1285 <        assertTrue(g.cancel(mayInterruptIfRunning));
1286 <        checkIncomplete(h);
1287 <        f.complete(v1);
1285 >        (fFirst ? f : g).complete(v1);
1286 >        if (!createIncomplete)
1287 >            (!fFirst ? f : g).completeExceptionally(ex);
1288 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1289 >        if (createIncomplete) {
1290 >            checkIncomplete(h);
1291 >            (!fFirst ? f : g).completeExceptionally(ex);
1292 >        }
1293  
1294 <        checkCompletedWithWrappedCancellationException(h);
1326 <        checkCancelled(g);
1294 >        checkCompletedWithWrappedCFException(h, ex);
1295          assertEquals(0, r.invocationCount);
1296 <        checkCompletedNormally(f, v1);
1296 >        checkCompletedNormally(fFirst ? f : g, v1);
1297 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1298      }}
1299  
1300 <    public void testThenCombine_sourceCancelled3() {
1300 >    /**
1301 >     * thenCombine result completes exceptionally if action does
1302 >     */
1303 >    public void testThenCombine_actionFailed() {
1304          for (ExecutionMode m : ExecutionMode.values())
1305 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1305 >        for (boolean fFirst : new boolean[] { true, false })
1306          for (Integer v1 : new Integer[] { 1, null })
1307 +        for (Integer v2 : new Integer[] { 2, null })
1308      {
1309          final CompletableFuture<Integer> f = new CompletableFuture<>();
1310          final CompletableFuture<Integer> g = new CompletableFuture<>();
1311 <        final SubtractFunction r = new SubtractFunction();
1339 <
1340 <        assertTrue(g.cancel(mayInterruptIfRunning));
1341 <        f.complete(v1);
1311 >        final FailingBiFunction r = new FailingBiFunction();
1312          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1313  
1314 <        checkCompletedWithWrappedCancellationException(h);
1315 <        checkCancelled(g);
1316 <        assertEquals(0, r.invocationCount);
1314 >        if (fFirst) {
1315 >            f.complete(v1);
1316 >            g.complete(v2);
1317 >        } else {
1318 >            g.complete(v2);
1319 >            f.complete(v1);
1320 >        }
1321 >
1322 >        checkCompletedWithWrappedCFException(h);
1323          checkCompletedNormally(f, v1);
1324 +        checkCompletedNormally(g, v2);
1325      }}
1326  
1327 <    public void testThenCombine_sourceCancelled4() {
1327 >    /**
1328 >     * thenCombine result completes exceptionally if either source cancelled
1329 >     */
1330 >    public void testThenCombine_sourceCancelled() {
1331          for (ExecutionMode m : ExecutionMode.values())
1332          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1333 +        for (boolean createIncomplete : new boolean[] { true, false })
1334 +        for (boolean fFirst : new boolean[] { true, false })
1335          for (Integer v1 : new Integer[] { 1, null })
1336      {
1337          final CompletableFuture<Integer> f = new CompletableFuture<>();
1338          final CompletableFuture<Integer> g = new CompletableFuture<>();
1339          final SubtractFunction r = new SubtractFunction();
1340  
1341 <        assertTrue(f.cancel(mayInterruptIfRunning));
1342 <        g.complete(v1);
1341 >        (fFirst ? f : g).complete(v1);
1342 >        if (!createIncomplete)
1343 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1344          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1345 +        if (createIncomplete) {
1346 +            checkIncomplete(h);
1347 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1348 +        }
1349  
1350          checkCompletedWithWrappedCancellationException(h);
1351 <        checkCancelled(f);
1351 >        checkCancelled(!fFirst ? f : g);
1352          assertEquals(0, r.invocationCount);
1353 <        checkCompletedNormally(g, v1);
1353 >        checkCompletedNormally(fFirst ? f : g, v1);
1354      }}
1355  
1356      /**
# Line 1830 | Line 1817 | public class CompletableFutureTest exten
1817      {
1818          final CompletableFuture<Integer> f = new CompletableFuture<>();
1819          final CompletableFuture<Integer> g = new CompletableFuture<>();
1820 <        final FailingNoop r = new FailingNoop();
1820 >        final FailingRunnable r = new FailingRunnable();
1821          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1822  
1823          f.complete(v1);
# Line 1849 | Line 1836 | public class CompletableFutureTest exten
1836      {
1837          final CompletableFuture<Integer> f = new CompletableFuture<>();
1838          final CompletableFuture<Integer> g = new CompletableFuture<>();
1839 <        final FailingNoop r = new FailingNoop();
1839 >        final FailingRunnable r = new FailingRunnable();
1840          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1841  
1842          g.complete(v2);
# Line 2713 | Line 2700 | public class CompletableFutureTest exten
2700      {
2701          final CompletableFuture<Integer> f = new CompletableFuture<>();
2702          final CompletableFuture<Integer> g = new CompletableFuture<>();
2703 <        final FailingNoop r = new FailingNoop();
2703 >        final FailingRunnable r = new FailingRunnable();
2704          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2705  
2706          f.complete(v1);
# Line 2730 | Line 2717 | public class CompletableFutureTest exten
2717      {
2718          final CompletableFuture<Integer> f = new CompletableFuture<>();
2719          final CompletableFuture<Integer> g = new CompletableFuture<>();
2720 <        final FailingNoop r = new FailingNoop();
2720 >        final FailingRunnable r = new FailingRunnable();
2721          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2722  
2723          g.complete(v2);
# Line 2840 | Line 2827 | public class CompletableFutureTest exten
2827      /**
2828       * thenCompose result completes normally after normal completion of source
2829       */
2830 <    public void testThenCompose_normalCompletion1() {
2830 >    public void testThenCompose_normalCompletion() {
2831          for (ExecutionMode m : ExecutionMode.values())
2832 +        for (boolean createIncomplete : new boolean[] { true, false })
2833          for (Integer v1 : new Integer[] { 1, null })
2834      {
2835          final CompletableFuture<Integer> f = new CompletableFuture<>();
2836          final CompletableFutureInc r = new CompletableFutureInc();
2837 +        if (!createIncomplete) f.complete(v1);
2838          final CompletableFuture<Integer> g = f.thenCompose(r);
2839 <        f.complete(v1);
2851 <        checkCompletedNormally(g, inc(v1));
2852 <        checkCompletedNormally(f, v1);
2853 <        assertEquals(1, r.invocationCount);
2854 <    }}
2839 >        if (createIncomplete) f.complete(v1);
2840  
2856    public void testThenCompose_normalCompletion2() {
2857        for (ExecutionMode m : ExecutionMode.values())
2858        for (Integer v1 : new Integer[] { 1, null })
2859    {
2860        final CompletableFuture<Integer> f = new CompletableFuture<>();
2861        final CompletableFutureInc r = new CompletableFutureInc();
2862        f.complete(v1);
2863        final CompletableFuture<Integer> g = f.thenCompose(r);
2841          checkCompletedNormally(g, inc(v1));
2842          checkCompletedNormally(f, v1);
2843          assertEquals(1, r.invocationCount);
# Line 2870 | Line 2847 | public class CompletableFutureTest exten
2847       * thenCompose result completes exceptionally after exceptional
2848       * completion of source
2849       */
2850 <    public void testThenCompose_exceptionalCompletion1() {
2850 >    public void testThenCompose_exceptionalCompletion() {
2851          for (ExecutionMode m : ExecutionMode.values())
2852 +        for (boolean createIncomplete : new boolean[] { true, false })
2853      {
2854          final CFException ex = new CFException();
2855          final CompletableFutureInc r = new CompletableFutureInc();
2856          final CompletableFuture<Integer> f = new CompletableFuture<>();
2857 +        if (!createIncomplete) f.completeExceptionally(ex);
2858          final CompletableFuture<Integer> g = f.thenCompose(r);
2859 <        f.completeExceptionally(ex);
2881 <        checkCompletedWithWrappedCFException(g, ex);
2882 <        checkCompletedWithWrappedCFException(f, ex);
2883 <    }}
2859 >        if (createIncomplete) f.completeExceptionally(ex);
2860  
2885    public void testThenCompose_exceptionalCompletion2() {
2886        for (ExecutionMode m : ExecutionMode.values())
2887    {
2888        final CFException ex = new CFException();
2889        final CompletableFuture<Integer> f = new CompletableFuture<>();
2890        f.completeExceptionally(ex);
2891        final CompletableFutureInc r = new CompletableFutureInc();
2892        final CompletableFuture<Integer> g = f.thenCompose(r);
2861          checkCompletedWithWrappedCFException(g, ex);
2862          checkCompletedWithWrappedCFException(f, ex);
2863 +        assertEquals(0, r.invocationCount);
2864      }}
2865  
2866      /**
2867       * thenCompose result completes exceptionally if action does
2868       */
2869 <    public void testThenCompose_actionFailed1() {
2869 >    public void testThenCompose_actionFailed() {
2870          for (ExecutionMode m : ExecutionMode.values())
2871 +        for (boolean createIncomplete : new boolean[] { true, false })
2872          for (Integer v1 : new Integer[] { 1, null })
2873      {
2874          final CompletableFuture<Integer> f = new CompletableFuture<>();
2875          final FailingCompletableFutureFunction r
2876              = new FailingCompletableFutureFunction();
2877 +        if (!createIncomplete) f.complete(v1);
2878          final CompletableFuture<Integer> g = f.thenCompose(r);
2879 <        f.complete(v1);
2909 <        checkCompletedWithWrappedCFException(g);
2910 <        checkCompletedNormally(f, v1);
2911 <    }}
2879 >        if (createIncomplete) f.complete(v1);
2880  
2913    public void testThenCompose_actionFailed2() {
2914        for (ExecutionMode m : ExecutionMode.values())
2915        for (Integer v1 : new Integer[] { 1, null })
2916    {
2917        final CompletableFuture<Integer> f = new CompletableFuture<>();
2918        f.complete(v1);
2919        final FailingCompletableFutureFunction r
2920            = new FailingCompletableFutureFunction();
2921        final CompletableFuture<Integer> g = f.thenCompose(r);
2881          checkCompletedWithWrappedCFException(g);
2882          checkCompletedNormally(f, v1);
2883      }}
# Line 2926 | Line 2885 | public class CompletableFutureTest exten
2885      /**
2886       * thenCompose result completes exceptionally if source cancelled
2887       */
2888 <    public void testThenCompose_sourceCancelled1() {
2888 >    public void testThenCompose_sourceCancelled() {
2889          for (ExecutionMode m : ExecutionMode.values())
2890 +        for (boolean createIncomplete : new boolean[] { true, false })
2891          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2892      {
2893          final CompletableFuture<Integer> f = new CompletableFuture<>();
2894          final CompletableFutureInc r = new CompletableFutureInc();
2895 +        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2896          final CompletableFuture<Integer> g = f.thenCompose(r);
2897 <        assertTrue(f.cancel(mayInterruptIfRunning));
2898 <        checkCompletedWithWrappedCancellationException(g);
2899 <        checkCancelled(f);
2900 <    }}
2897 >        if (createIncomplete) {
2898 >            checkIncomplete(g);
2899 >            assertTrue(f.cancel(mayInterruptIfRunning));
2900 >        }
2901  
2941    public void testThenCompose_sourceCancelled2() {
2942        for (ExecutionMode m : ExecutionMode.values())
2943        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2944    {
2945        final CompletableFuture<Integer> f = new CompletableFuture<>();
2946        assertTrue(f.cancel(mayInterruptIfRunning));
2947        final CompletableFutureInc r = new CompletableFutureInc();
2948        final CompletableFuture<Integer> g = f.thenCompose(r);
2902          checkCompletedWithWrappedCancellationException(g);
2903          checkCancelled(f);
2904      }}
2905  
2953    // asyncs
2954
2955    /**
2956     * thenRunAsync result completes normally after normal completion of source
2957     */
2958    public void testThenRunAsync() {
2959        CompletableFuture<Integer> f = new CompletableFuture<>();
2960        Noop r = new Noop();
2961        CompletableFuture<Void> g = f.thenRunAsync(r);
2962        f.complete(null);
2963        checkCompletedNormally(g, null);
2964
2965        // reordered version
2966        f = new CompletableFuture<>();
2967        f.complete(null);
2968        r = new Noop();
2969        g = f.thenRunAsync(r);
2970        checkCompletedNormally(g, null);
2971    }
2972
2973    /**
2974     * thenRunAsync result completes exceptionally after exceptional
2975     * completion of source
2976     */
2977    public void testThenRunAsync2() {
2978        CompletableFuture<Integer> f = new CompletableFuture<>();
2979        Noop r = new Noop();
2980        CompletableFuture<Void> g = f.thenRunAsync(r);
2981        f.completeExceptionally(new CFException());
2982        try {
2983            g.join();
2984            shouldThrow();
2985        } catch (CompletionException success) {}
2986        checkCompletedWithWrappedCFException(g);
2987    }
2988
2989    /**
2990     * thenRunAsync result completes exceptionally if action does
2991     */
2992    public void testThenRunAsync3() {
2993        CompletableFuture<Integer> f = new CompletableFuture<>();
2994        FailingNoop r = new FailingNoop();
2995        CompletableFuture<Void> g = f.thenRunAsync(r);
2996        f.complete(null);
2997        checkCompletedWithWrappedCFException(g);
2998    }
2999
3000    /**
3001     * thenRunAsync result completes exceptionally if source cancelled
3002     */
3003    public void testThenRunAsync4() {
3004        CompletableFuture<Integer> f = new CompletableFuture<>();
3005        Noop r = new Noop();
3006        CompletableFuture<Void> g = f.thenRunAsync(r);
3007        assertTrue(f.cancel(true));
3008        checkCompletedWithWrappedCancellationException(g);
3009    }
3010
3011    /**
3012     * thenApplyAsync result completes normally after normal completion of source
3013     */
3014    public void testThenApplyAsync() {
3015        CompletableFuture<Integer> f = new CompletableFuture<>();
3016        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
3017        f.complete(one);
3018        checkCompletedNormally(g, two);
3019    }
3020
3021    /**
3022     * thenApplyAsync result completes exceptionally after exceptional
3023     * completion of source
3024     */
3025    public void testThenApplyAsync2() {
3026        CompletableFuture<Integer> f = new CompletableFuture<>();
3027        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
3028        f.completeExceptionally(new CFException());
3029        checkCompletedWithWrappedCFException(g);
3030    }
3031
3032    /**
3033     * thenApplyAsync result completes exceptionally if action does
3034     */
3035    public void testThenApplyAsync3() {
3036        CompletableFuture<Integer> f = new CompletableFuture<>();
3037        FailingFunction r = new FailingFunction();
3038        CompletableFuture<Integer> g = f.thenApplyAsync(r);
3039        f.complete(null);
3040        checkCompletedWithWrappedCFException(g);
3041    }
3042
3043    /**
3044     * thenApplyAsync result completes exceptionally if source cancelled
3045     */
3046    public void testThenApplyAsync4() {
3047        CompletableFuture<Integer> f = new CompletableFuture<>();
3048        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
3049        assertTrue(f.cancel(true));
3050        checkCompletedWithWrappedCancellationException(g);
3051    }
3052
3053    /**
3054     * thenAcceptAsync result completes normally after normal
3055     * completion of source
3056     */
3057    public void testThenAcceptAsync() {
3058        CompletableFuture<Integer> f = new CompletableFuture<>();
3059        IncAction r = new IncAction();
3060        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3061        f.complete(one);
3062        checkCompletedNormally(g, null);
3063        assertEquals(r.value, (Integer) 2);
3064    }
3065
3066    /**
3067     * thenAcceptAsync result completes exceptionally after exceptional
3068     * completion of source
3069     */
3070    public void testThenAcceptAsync2() {
3071        CompletableFuture<Integer> f = new CompletableFuture<>();
3072        IncAction r = new IncAction();
3073        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3074        f.completeExceptionally(new CFException());
3075        checkCompletedWithWrappedCFException(g);
3076    }
3077
3078    /**
3079     * thenAcceptAsync result completes exceptionally if action does
3080     */
3081    public void testThenAcceptAsync3() {
3082        CompletableFuture<Integer> f = new CompletableFuture<>();
3083        FailingConsumer r = new FailingConsumer();
3084        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3085        f.complete(null);
3086        checkCompletedWithWrappedCFException(g);
3087    }
3088
3089    /**
3090     * thenAcceptAsync result completes exceptionally if source cancelled
3091     */
3092    public void testThenAcceptAsync4() {
3093        CompletableFuture<Integer> f = new CompletableFuture<>();
3094        IncAction r = new IncAction();
3095        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3096        assertTrue(f.cancel(true));
3097        checkCompletedWithWrappedCancellationException(g);
3098    }
3099
3100    // async with explicit executors
3101
3102    /**
3103     * thenRunAsync result completes normally after normal completion of source
3104     */
3105    public void testThenRunAsyncE() {
3106        CompletableFuture<Integer> f = new CompletableFuture<>();
3107        Noop r = new Noop();
3108        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3109        f.complete(null);
3110        checkCompletedNormally(g, null);
3111
3112        // reordered version
3113        f = new CompletableFuture<>();
3114        f.complete(null);
3115        r = new Noop();
3116        g = f.thenRunAsync(r, new ThreadExecutor());
3117        checkCompletedNormally(g, null);
3118    }
3119
3120    /**
3121     * thenRunAsync result completes exceptionally after exceptional
3122     * completion of source
3123     */
3124    public void testThenRunAsync2E() {
3125        CompletableFuture<Integer> f = new CompletableFuture<>();
3126        Noop r = new Noop();
3127        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3128        f.completeExceptionally(new CFException());
3129        try {
3130            g.join();
3131            shouldThrow();
3132        } catch (CompletionException success) {}
3133        checkCompletedWithWrappedCFException(g);
3134    }
3135
3136    /**
3137     * thenRunAsync result completes exceptionally if action does
3138     */
3139    public void testThenRunAsync3E() {
3140        CompletableFuture<Integer> f = new CompletableFuture<>();
3141        FailingNoop r = new FailingNoop();
3142        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3143        f.complete(null);
3144        checkCompletedWithWrappedCFException(g);
3145    }
3146
3147    /**
3148     * thenRunAsync result completes exceptionally if source cancelled
3149     */
3150    public void testThenRunAsync4E() {
3151        CompletableFuture<Integer> f = new CompletableFuture<>();
3152        Noop r = new Noop();
3153        CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor());
3154        assertTrue(f.cancel(true));
3155        checkCompletedWithWrappedCancellationException(g);
3156    }
3157
3158    /**
3159     * thenApplyAsync result completes normally after normal completion of source
3160     */
3161    public void testThenApplyAsyncE() {
3162        CompletableFuture<Integer> f = new CompletableFuture<>();
3163        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3164        f.complete(one);
3165        checkCompletedNormally(g, two);
3166    }
3167
3168    /**
3169     * thenApplyAsync result completes exceptionally after exceptional
3170     * completion of source
3171     */
3172    public void testThenApplyAsync2E() {
3173        CompletableFuture<Integer> f = new CompletableFuture<>();
3174        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3175        f.completeExceptionally(new CFException());
3176        checkCompletedWithWrappedCFException(g);
3177    }
3178
3179    /**
3180     * thenApplyAsync result completes exceptionally if action does
3181     */
3182    public void testThenApplyAsync3E() {
3183        CompletableFuture<Integer> f = new CompletableFuture<>();
3184        FailingFunction r = new FailingFunction();
3185        CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
3186        f.complete(null);
3187        checkCompletedWithWrappedCFException(g);
3188    }
3189
3190    /**
3191     * thenApplyAsync result completes exceptionally if source cancelled
3192     */
3193    public void testThenApplyAsync4E() {
3194        CompletableFuture<Integer> f = new CompletableFuture<>();
3195        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3196        assertTrue(f.cancel(true));
3197        checkCompletedWithWrappedCancellationException(g);
3198    }
3199
3200    /**
3201     * thenAcceptAsync result completes normally after normal
3202     * completion of source
3203     */
3204    public void testThenAcceptAsyncE() {
3205        CompletableFuture<Integer> f = new CompletableFuture<>();
3206        IncAction r = new IncAction();
3207        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3208        f.complete(one);
3209        checkCompletedNormally(g, null);
3210        assertEquals(r.value, (Integer) 2);
3211    }
3212
3213    /**
3214     * thenAcceptAsync result completes exceptionally after exceptional
3215     * completion of source
3216     */
3217    public void testThenAcceptAsync2E() {
3218        CompletableFuture<Integer> f = new CompletableFuture<>();
3219        IncAction r = new IncAction();
3220        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3221        f.completeExceptionally(new CFException());
3222        checkCompletedWithWrappedCFException(g);
3223    }
3224
3225    /**
3226     * thenAcceptAsync result completes exceptionally if action does
3227     */
3228    public void testThenAcceptAsync3E() {
3229        CompletableFuture<Integer> f = new CompletableFuture<>();
3230        FailingConsumer r = new FailingConsumer();
3231        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3232        f.complete(null);
3233        checkCompletedWithWrappedCFException(g);
3234    }
3235
3236    /**
3237     * thenAcceptAsync result completes exceptionally if source cancelled
3238     */
3239    public void testThenAcceptAsync4E() {
3240        CompletableFuture<Integer> f = new CompletableFuture<>();
3241        IncAction r = new IncAction();
3242        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3243        assertTrue(f.cancel(true));
3244        checkCompletedWithWrappedCancellationException(g);
3245    }
3246
2906      // other static methods
2907  
2908      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines