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.26 by dl, Fri Jul 5 15:47:52 2013 UTC vs.
Revision 1.34 by jsr166, Sun Jun 1 21:17:05 2014 UTC

# Line 102 | Line 102 | public class CompletableFutureTest exten
102          assertTrue(f.toString().contains("[Completed exceptionally]"));
103      }
104  
105 +    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
106 +                                              CFException ex) {
107 +        try {
108 +            f.get(LONG_DELAY_MS, MILLISECONDS);
109 +            shouldThrow();
110 +        } catch (ExecutionException success) {
111 +            assertSame(ex, success.getCause());
112 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
113 +        try {
114 +            f.join();
115 +            shouldThrow();
116 +        } catch (CompletionException success) {
117 +            assertSame(ex, success.getCause());
118 +        }
119 +        try {
120 +            f.getNow(null);
121 +            shouldThrow();
122 +        } catch (CompletionException success) {
123 +            assertSame(ex, success.getCause());
124 +        }
125 +        try {
126 +            f.get();
127 +            shouldThrow();
128 +        } catch (ExecutionException success) {
129 +            assertSame(ex, success.getCause());
130 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
131 +        assertTrue(f.isDone());
132 +        assertFalse(f.isCancelled());
133 +        assertTrue(f.toString().contains("[Completed exceptionally]"));
134 +    }
135 +
136      void checkCancelled(CompletableFuture<?> f) {
137          try {
138              f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 259 | Line 290 | public class CompletableFutureTest exten
290          assertEquals(g.getNumberOfDependents(), 0);
291      }
292  
262
293      /**
294       * toString indicates current completion state
295       */
# Line 374 | Line 404 | public class CompletableFutureTest exten
404          }
405      }
406  
377
407      /**
408       * exceptionally action completes with function value on source
409 <     * exception;  otherwise with source value
409 >     * exception; otherwise with source value
410       */
411      public void testExceptionally() {
412          CompletableFuture<Integer> f = new CompletableFuture<>();
# Line 663 | Line 692 | public class CompletableFutureTest exten
692          checkCompletedWithWrappedCancellationException(g);
693      }
694  
666
695      /**
696       * thenCombine result completes normally after normal completion
697       * of sources
# Line 919 | Line 947 | public class CompletableFutureTest exten
947      }
948  
949      /**
950 +     * Permits the testing of parallel code for the 3 different
951 +     * execution modes without repeating all the testing code.
952 +     */
953 +    enum ExecutionMode {
954 +        DEFAULT {
955 +            public <T,U> CompletableFuture<Void> runAfterBoth
956 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
957 +                return f.runAfterBoth(g, r);
958 +            }
959 +        },
960 +
961 +        DEFAULT_ASYNC {
962 +            public <T,U> CompletableFuture<Void> runAfterBoth
963 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
964 +                return f.runAfterBothAsync(g, r);
965 +            }
966 +        },
967 +
968 +        EXECUTOR {
969 +            public <T,U> CompletableFuture<Void> runAfterBoth
970 +                (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r) {
971 +                return f.runAfterBothAsync(g, r, new ThreadExecutor());
972 +            }
973 +        };
974 +
975 +        public abstract <T,U> CompletableFuture<Void> runAfterBoth
976 +            (CompletableFuture<T> f, CompletableFuture<U> g, Runnable r);
977 +    }
978 +
979 +    /**
980       * runAfterBoth result completes normally after normal
981       * completion of sources
982       */
983 <    public void testRunAfterBoth() {
984 <        CompletableFuture<Integer> f, g;
985 <        CompletableFuture<Void> h;
986 <        Noop r;
983 >    public void testRunAfterBoth_normalCompletion1() {
984 >        for (ExecutionMode m : ExecutionMode.values())
985 >        for (Integer v1 : new Integer[] { 1, null })
986 >        for (Integer v2 : new Integer[] { 2, null }) {
987 >
988 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
989 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
990 >        final Noop r = new Noop();
991 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
992  
993 <        f = new CompletableFuture<>();
931 <        g = new CompletableFuture<>();
932 <        h = f.runAfterBoth(g, r = new Noop());
933 <        f.complete(3);
993 >        f.complete(v1);
994          checkIncomplete(h);
995 <        g.complete(1);
995 >        assertFalse(r.ran);
996 >        g.complete(v2);
997 >
998          checkCompletedNormally(h, null);
999          assertTrue(r.ran);
1000 +        checkCompletedNormally(f, v1);
1001 +        checkCompletedNormally(g, v2);
1002 +        }
1003 +    }
1004  
1005 <        f = new CompletableFuture<>();
1006 <        g = new CompletableFuture<>();
1007 <        h = f.runAfterBoth(g, r = new Noop());
1008 <        g.complete(1);
1005 >    public void testRunAfterBoth_normalCompletion2() {
1006 >        for (ExecutionMode m : ExecutionMode.values())
1007 >        for (Integer v1 : new Integer[] { 1, null })
1008 >        for (Integer v2 : new Integer[] { 2, null }) {
1009 >
1010 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1011 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1012 >        final Noop r = new Noop();
1013 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1014 >
1015 >        g.complete(v2);
1016          checkIncomplete(h);
1017 <        f.complete(3);
1017 >        assertFalse(r.ran);
1018 >        f.complete(v1);
1019 >
1020          checkCompletedNormally(h, null);
1021          assertTrue(r.ran);
1022 +        checkCompletedNormally(f, v1);
1023 +        checkCompletedNormally(g, v2);
1024 +        }
1025 +    }
1026 +
1027 +    public void testRunAfterBoth_normalCompletion3() {
1028 +        for (ExecutionMode m : ExecutionMode.values())
1029 +        for (Integer v1 : new Integer[] { 1, null })
1030 +        for (Integer v2 : new Integer[] { 2, null }) {
1031 +
1032 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1033 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1034 +        final Noop r = new Noop();
1035 +
1036 +        g.complete(v2);
1037 +        f.complete(v1);
1038 +        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1039 +
1040 +        checkCompletedNormally(h, null);
1041 +        assertTrue(r.ran);
1042 +        checkCompletedNormally(f, v1);
1043 +        checkCompletedNormally(g, v2);
1044 +        }
1045 +    }
1046 +
1047 +    public void testRunAfterBoth_normalCompletion4() {
1048 +        for (ExecutionMode m : ExecutionMode.values())
1049 +        for (Integer v1 : new Integer[] { 1, null })
1050 +        for (Integer v2 : new Integer[] { 2, null }) {
1051 +
1052 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1053 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1054 +        final Noop r = new Noop();
1055 +
1056 +        f.complete(v1);
1057 +        g.complete(v2);
1058 +        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1059  
948        f = new CompletableFuture<>();
949        g = new CompletableFuture<>();
950        g.complete(1);
951        f.complete(3);
952        h = f.runAfterBoth(g, r = new Noop());
1060          checkCompletedNormally(h, null);
1061          assertTrue(r.ran);
1062 +        checkCompletedNormally(f, v1);
1063 +        checkCompletedNormally(g, v2);
1064 +        }
1065      }
1066  
1067      /**
1068       * runAfterBoth result completes exceptionally after exceptional
1069       * completion of either source
1070       */
1071 <    public void testRunAfterBoth2() {
1072 <        CompletableFuture<Integer> f, g;
1073 <        CompletableFuture<Void> h;
1074 <        Noop r;
1071 >    public void testRunAfterBoth_exceptionalCompletion1() {
1072 >        for (ExecutionMode m : ExecutionMode.values())
1073 >        for (Integer v1 : new Integer[] { 1, null }) {
1074 >
1075 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1076 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1077 >        final Noop r = new Noop();
1078 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1079 >        final CFException ex = new CFException();
1080  
1081 <        f = new CompletableFuture<>();
967 <        g = new CompletableFuture<>();
968 <        h = f.runAfterBoth(g, r = new Noop());
969 <        f.completeExceptionally(new CFException());
1081 >        f.completeExceptionally(ex);
1082          checkIncomplete(h);
1083 <        g.complete(1);
1084 <        checkCompletedWithWrappedCFException(h);
1083 >        g.complete(v1);
1084 >
1085 >        checkCompletedWithWrappedCFException(h, ex);
1086 >        checkCompletedWithWrappedCFException(f, ex);
1087          assertFalse(r.ran);
1088 +        checkCompletedNormally(g, v1);
1089 +        }
1090 +    }
1091  
1092 <        f = new CompletableFuture<>();
1093 <        g = new CompletableFuture<>();
1094 <        h = f.runAfterBoth(g, r = new Noop());
1095 <        g.completeExceptionally(new CFException());
1092 >    public void testRunAfterBoth_exceptionalCompletion2() {
1093 >        for (ExecutionMode m : ExecutionMode.values())
1094 >        for (Integer v1 : new Integer[] { 1, null }) {
1095 >
1096 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1097 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1098 >        final Noop r = new Noop();
1099 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1100 >        final CFException ex = new CFException();
1101 >
1102 >        g.completeExceptionally(ex);
1103          checkIncomplete(h);
1104 <        f.complete(3);
1105 <        checkCompletedWithWrappedCFException(h);
1104 >        f.complete(v1);
1105 >
1106 >        checkCompletedWithWrappedCFException(h, ex);
1107 >        checkCompletedWithWrappedCFException(g, ex);
1108          assertFalse(r.ran);
1109 +        checkCompletedNormally(f, v1);
1110 +        }
1111 +    }
1112  
1113 <        f = new CompletableFuture<>();
1114 <        g = new CompletableFuture<>();
1115 <        g.completeExceptionally(new CFException());
1116 <        f.complete(3);
1117 <        h = f.runAfterBoth(g, r = new Noop());
1118 <        checkCompletedWithWrappedCFException(h);
1113 >    public void testRunAfterBoth_exceptionalCompletion3() {
1114 >        for (ExecutionMode m : ExecutionMode.values())
1115 >        for (Integer v1 : new Integer[] { 1, null }) {
1116 >
1117 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1118 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1119 >        final Noop r = new Noop();
1120 >        final CFException ex = new CFException();
1121 >
1122 >        g.completeExceptionally(ex);
1123 >        f.complete(v1);
1124 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1125 >
1126 >        checkCompletedWithWrappedCFException(h, ex);
1127 >        checkCompletedWithWrappedCFException(g, ex);
1128          assertFalse(r.ran);
1129 +        checkCompletedNormally(f, v1);
1130 +        }
1131 +    }
1132  
1133 <        f = new CompletableFuture<>();
1134 <        g = new CompletableFuture<>();
1135 <        f.completeExceptionally(new CFException());
1136 <        g.complete(1);
1137 <        h = f.runAfterBoth(g, r = new Noop());
1138 <        checkCompletedWithWrappedCFException(h);
1133 >    public void testRunAfterBoth_exceptionalCompletion4() {
1134 >        for (ExecutionMode m : ExecutionMode.values())
1135 >        for (Integer v1 : new Integer[] { 1, null }) {
1136 >
1137 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1138 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1139 >        final Noop r = new Noop();
1140 >        final CFException ex = new CFException();
1141 >
1142 >        f.completeExceptionally(ex);
1143 >        g.complete(v1);
1144 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1145 >
1146 >        checkCompletedWithWrappedCFException(h, ex);
1147 >        checkCompletedWithWrappedCFException(f, ex);
1148          assertFalse(r.ran);
1149 +        checkCompletedNormally(g, v1);
1150 +        }
1151      }
1152  
1153      /**
1154       * runAfterBoth result completes exceptionally if action does
1155       */
1156 <    public void testRunAfterBoth3() {
1157 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1158 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1159 <        FailingNoop r = new FailingNoop();
1160 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1161 <        f.complete(one);
1162 <        checkIncomplete(g);
1163 <        f2.complete(two);
1164 <        checkCompletedWithWrappedCFException(g);
1156 >    public void testRunAfterBoth_actionFailed1() {
1157 >        for (ExecutionMode m : ExecutionMode.values())
1158 >        for (Integer v1 : new Integer[] { 1, null })
1159 >        for (Integer v2 : new Integer[] { 2, null }) {
1160 >
1161 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1162 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1163 >        final FailingNoop r = new FailingNoop();
1164 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1165 >
1166 >        f.complete(v1);
1167 >        checkIncomplete(h);
1168 >        g.complete(v2);
1169 >
1170 >        checkCompletedWithWrappedCFException(h);
1171 >        checkCompletedNormally(f, v1);
1172 >        checkCompletedNormally(g, v2);
1173 >        }
1174 >    }
1175 >
1176 >    public void testRunAfterBoth_actionFailed2() {
1177 >        for (ExecutionMode m : ExecutionMode.values())
1178 >        for (Integer v1 : new Integer[] { 1, null })
1179 >        for (Integer v2 : new Integer[] { 2, null }) {
1180 >
1181 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1182 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1183 >        final FailingNoop r = new FailingNoop();
1184 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1185 >
1186 >        g.complete(v2);
1187 >        checkIncomplete(h);
1188 >        f.complete(v1);
1189 >
1190 >        checkCompletedWithWrappedCFException(h);
1191 >        checkCompletedNormally(f, v1);
1192 >        checkCompletedNormally(g, v2);
1193 >        }
1194      }
1195  
1196      /**
1197       * runAfterBoth result completes exceptionally if either source cancelled
1198       */
1199 <    public void testRunAfterBoth4() {
1200 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1201 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1202 <        Noop r = new Noop();
1203 <        CompletableFuture<Void> g = f.runAfterBoth(f2, r);
1204 <        assertTrue(f.cancel(true));
1205 <        f2.complete(two);
1206 <        checkCompletedWithWrappedCancellationException(g);
1207 <        f = new CompletableFuture<>();
1208 <        f2 = new CompletableFuture<>();
1209 <        r = new Noop();
1210 <        g = f.runAfterBoth(f2, r);
1211 <        f.complete(one);
1212 <        assertTrue(f2.cancel(true));
1213 <        checkCompletedWithWrappedCancellationException(g);
1199 >    public void testRunAfterBoth_sourceCancelled1() {
1200 >        for (ExecutionMode m : ExecutionMode.values())
1201 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1202 >        for (Integer v1 : new Integer[] { 1, null }) {
1203 >
1204 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1205 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1206 >        final Noop r = new Noop();
1207 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1208 >
1209 >        assertTrue(f.cancel(mayInterruptIfRunning));
1210 >        checkIncomplete(h);
1211 >        g.complete(v1);
1212 >
1213 >        checkCompletedWithWrappedCancellationException(h);
1214 >        checkCancelled(f);
1215 >        assertFalse(r.ran);
1216 >        checkCompletedNormally(g, v1);
1217 >        }
1218 >    }
1219 >
1220 >    public void testRunAfterBoth_sourceCancelled2() {
1221 >        for (ExecutionMode m : ExecutionMode.values())
1222 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1223 >        for (Integer v1 : new Integer[] { 1, null }) {
1224 >
1225 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1226 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1227 >        final Noop r = new Noop();
1228 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1229 >
1230 >        assertTrue(g.cancel(mayInterruptIfRunning));
1231 >        checkIncomplete(h);
1232 >        f.complete(v1);
1233 >
1234 >        checkCompletedWithWrappedCancellationException(h);
1235 >        checkCancelled(g);
1236 >        assertFalse(r.ran);
1237 >        checkCompletedNormally(f, v1);
1238 >        }
1239 >    }
1240 >
1241 >    public void testRunAfterBoth_sourceCancelled3() {
1242 >        for (ExecutionMode m : ExecutionMode.values())
1243 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1244 >        for (Integer v1 : new Integer[] { 1, null }) {
1245 >
1246 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1247 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1248 >        final Noop r = new Noop();
1249 >
1250 >        assertTrue(g.cancel(mayInterruptIfRunning));
1251 >        f.complete(v1);
1252 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1253 >
1254 >        checkCompletedWithWrappedCancellationException(h);
1255 >        checkCancelled(g);
1256 >        assertFalse(r.ran);
1257 >        checkCompletedNormally(f, v1);
1258 >        }
1259 >    }
1260 >
1261 >    public void testRunAfterBoth_sourceCancelled4() {
1262 >        for (ExecutionMode m : ExecutionMode.values())
1263 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1264 >        for (Integer v1 : new Integer[] { 1, null }) {
1265 >
1266 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1267 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1268 >        final Noop r = new Noop();
1269 >
1270 >        assertTrue(f.cancel(mayInterruptIfRunning));
1271 >        g.complete(v1);
1272 >        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1273 >
1274 >        checkCompletedWithWrappedCancellationException(h);
1275 >        checkCancelled(f);
1276 >        assertFalse(r.ran);
1277 >        checkCompletedNormally(g, v1);
1278 >        }
1279      }
1280  
1281      /**
# Line 1171 | Line 1417 | public class CompletableFutureTest exten
1417          checkCompletedWithWrappedCancellationException(g);
1418      }
1419  
1174
1420      /**
1421       * runAfterEither result completes normally after normal completion
1422       * of either source
# Line 1320 | Line 1565 | public class CompletableFutureTest exten
1565          checkCompletedWithWrappedCancellationException(g);
1566      }
1567  
1323
1568      // asyncs
1569  
1570      /**
# Line 1353 | Line 1597 | public class CompletableFutureTest exten
1597          try {
1598              g.join();
1599              shouldThrow();
1600 <        } catch (Exception ok) {
1357 <        }
1600 >        } catch (CompletionException success) {}
1601          checkCompletedWithWrappedCFException(g);
1602      }
1603  
# Line 1724 | Line 1967 | public class CompletableFutureTest exten
1967      }
1968  
1969      /**
1727     * runAfterBothAsync result completes normally after normal
1728     * completion of sources
1729     */
1730    public void testRunAfterBothAsync() {
1731        CompletableFuture<Integer> f = new CompletableFuture<>();
1732        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1733        Noop r = new Noop();
1734        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1735        f.complete(one);
1736        checkIncomplete(g);
1737        f2.complete(two);
1738        checkCompletedNormally(g, null);
1739        assertTrue(r.ran);
1740    }
1741
1742    /**
1743     * runAfterBothAsync result completes exceptionally after exceptional
1744     * completion of source
1745     */
1746    public void testRunAfterBothAsync2() {
1747        CompletableFuture<Integer> f = new CompletableFuture<>();
1748        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1749        Noop r = new Noop();
1750        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1751        f.completeExceptionally(new CFException());
1752        f2.complete(two);
1753        checkCompletedWithWrappedCFException(g);
1754
1755        r = new Noop();
1756        f = new CompletableFuture<>();
1757        f2 = new CompletableFuture<>();
1758        g = f.runAfterBothAsync(f2, r);
1759        f.complete(one);
1760        f2.completeExceptionally(new CFException());
1761        checkCompletedWithWrappedCFException(g);
1762    }
1763
1764    /**
1765     * runAfterBothAsync result completes exceptionally if action does
1766     */
1767    public void testRunAfterBothAsync3() {
1768        CompletableFuture<Integer> f = new CompletableFuture<>();
1769        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1770        FailingNoop r = new FailingNoop();
1771        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1772        f.complete(one);
1773        checkIncomplete(g);
1774        f2.complete(two);
1775        checkCompletedWithWrappedCFException(g);
1776    }
1777
1778    /**
1779     * runAfterBothAsync result completes exceptionally if either source cancelled
1780     */
1781    public void testRunAfterBothAsync4() {
1782        CompletableFuture<Integer> f = new CompletableFuture<>();
1783        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1784        Noop r = new Noop();
1785        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r);
1786        assertTrue(f.cancel(true));
1787        f2.complete(two);
1788        checkCompletedWithWrappedCancellationException(g);
1789
1790        r = new Noop();
1791        f = new CompletableFuture<>();
1792        f2 = new CompletableFuture<>();
1793        g = f.runAfterBothAsync(f2, r);
1794        f.complete(one);
1795        assertTrue(f2.cancel(true));
1796        checkCompletedWithWrappedCancellationException(g);
1797    }
1798
1799    /**
1970       * applyToEitherAsync result completes normally after normal
1971       * completion of sources
1972       */
# Line 2088 | Line 2258 | public class CompletableFutureTest exten
2258          checkCompletedWithWrappedCancellationException(g);
2259      }
2260  
2091
2261      // async with explicit executors
2262  
2263      /**
# Line 2121 | Line 2290 | public class CompletableFutureTest exten
2290          try {
2291              g.join();
2292              shouldThrow();
2293 <        } catch (Exception ok) {
2125 <        }
2293 >        } catch (CompletionException success) {}
2294          checkCompletedWithWrappedCFException(g);
2295      }
2296  
# Line 2518 | Line 2686 | public class CompletableFutureTest exten
2686      }
2687  
2688      /**
2521     * runAfterBothAsync result completes normally after normal
2522     * completion of sources
2523     */
2524    public void testRunAfterBothAsyncE() {
2525        CompletableFuture<Integer> f = new CompletableFuture<>();
2526        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2527        Noop r = new Noop();
2528        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2529        f.complete(one);
2530        checkIncomplete(g);
2531        f2.complete(two);
2532        checkCompletedNormally(g, null);
2533        assertTrue(r.ran);
2534    }
2535
2536    /**
2537     * runAfterBothAsync result completes exceptionally after exceptional
2538     * completion of source
2539     */
2540    public void testRunAfterBothAsync2E() {
2541        CompletableFuture<Integer> f = new CompletableFuture<>();
2542        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2543        Noop r = new Noop();
2544        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2545        f.completeExceptionally(new CFException());
2546        f2.complete(two);
2547        checkCompletedWithWrappedCFException(g);
2548
2549        r = new Noop();
2550        f = new CompletableFuture<>();
2551        f2 = new CompletableFuture<>();
2552        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2553        f.complete(one);
2554        f2.completeExceptionally(new CFException());
2555        checkCompletedWithWrappedCFException(g);
2556    }
2557
2558    /**
2559     * runAfterBothAsync result completes exceptionally if action does
2560     */
2561    public void testRunAfterBothAsync3E() {
2562        CompletableFuture<Integer> f = new CompletableFuture<>();
2563        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2564        FailingNoop r = new FailingNoop();
2565        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2566        f.complete(one);
2567        checkIncomplete(g);
2568        f2.complete(two);
2569        checkCompletedWithWrappedCFException(g);
2570    }
2571
2572    /**
2573     * runAfterBothAsync result completes exceptionally if either source cancelled
2574     */
2575    public void testRunAfterBothAsync4E() {
2576        CompletableFuture<Integer> f = new CompletableFuture<>();
2577        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2578        Noop r = new Noop();
2579        CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2580        assertTrue(f.cancel(true));
2581        f2.complete(two);
2582        checkCompletedWithWrappedCancellationException(g);
2583
2584        r = new Noop();
2585        f = new CompletableFuture<>();
2586        f2 = new CompletableFuture<>();
2587        g = f.runAfterBothAsync(f2, r, new ThreadExecutor());
2588        f.complete(one);
2589        assertTrue(f2.cancel(true));
2590        checkCompletedWithWrappedCancellationException(g);
2591    }
2592
2593    /**
2689       * applyToEitherAsync result completes normally after normal
2690       * completion of sources
2691       */
# Line 2939 | Line 3034 | public class CompletableFutureTest exten
3034          ThreadExecutor exec = new ThreadExecutor();
3035  
3036          Runnable[] throwingActions = {
3037 <            () -> { CompletableFuture.supplyAsync(null); },
3038 <            () -> { CompletableFuture.supplyAsync(null, exec); },
3039 <            () -> { CompletableFuture.supplyAsync(supplyOne, null); },
3040 <
3041 <            () -> { CompletableFuture.runAsync(null); },
3042 <            () -> { CompletableFuture.runAsync(null, exec); },
3043 <            () -> { CompletableFuture.runAsync(() -> {}, null); },
3044 <
3045 <            () -> { f.completeExceptionally(null); },
3046 <
3047 <            () -> { f.thenApply(null); },
3048 <            () -> { f.thenApplyAsync(null); },
3049 <            () -> { f.thenApplyAsync((x) -> x, null); },
3050 <            () -> { f.thenApplyAsync(null, exec); },
3051 <
3052 <            () -> { f.thenAccept(null); },
3053 <            () -> { f.thenAcceptAsync(null); },
3054 <            () -> { f.thenAcceptAsync((x) -> { ; }, null); },
3055 <            () -> { f.thenAcceptAsync(null, exec); },
3056 <
3057 <            () -> { f.thenRun(null); },
3058 <            () -> { f.thenRunAsync(null); },
3059 <            () -> { f.thenRunAsync(() -> { ; }, null); },
3060 <            () -> { f.thenRunAsync(null, exec); },
3061 <
3062 <            () -> { f.thenCombine(g, null); },
3063 <            () -> { f.thenCombineAsync(g, null); },
3064 <            () -> { f.thenCombineAsync(g, null, exec); },
3065 <            () -> { f.thenCombine(nullFuture, (x, y) -> x); },
3066 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x); },
3067 <            () -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); },
3068 <            () -> { f.thenCombineAsync(g, (x, y) -> x, null); },
3069 <
3070 <            () -> { f.thenAcceptBoth(g, null); },
3071 <            () -> { f.thenAcceptBothAsync(g, null); },
3072 <            () -> { f.thenAcceptBothAsync(g, null, exec); },
3073 <            () -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); },
3074 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); },
3075 <            () -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); },
3076 <            () -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); },
3077 <
3078 <            () -> { f.runAfterBoth(g, null); },
3079 <            () -> { f.runAfterBothAsync(g, null); },
3080 <            () -> { f.runAfterBothAsync(g, null, exec); },
3081 <            () -> { f.runAfterBoth(nullFuture, () -> {}); },
3082 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}); },
3083 <            () -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); },
3084 <            () -> { f.runAfterBothAsync(g, () -> {}, null); },
3085 <
3086 <            () -> { f.applyToEither(g, null); },
3087 <            () -> { f.applyToEitherAsync(g, null); },
3088 <            () -> { f.applyToEitherAsync(g, null, exec); },
3089 <            () -> { f.applyToEither(nullFuture, (x) -> x); },
3090 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x); },
3091 <            () -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); },
3092 <            () -> { f.applyToEitherAsync(g, (x) -> x, null); },
3093 <
3094 <            () -> { f.acceptEither(g, null); },
3095 <            () -> { f.acceptEitherAsync(g, null); },
3096 <            () -> { f.acceptEitherAsync(g, null, exec); },
3097 <            () -> { f.acceptEither(nullFuture, (x) -> {}); },
3098 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}); },
3099 <            () -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); },
3100 <            () -> { f.acceptEitherAsync(g, (x) -> {}, null); },
3101 <
3102 <            () -> { f.runAfterEither(g, null); },
3103 <            () -> { f.runAfterEitherAsync(g, null); },
3104 <            () -> { f.runAfterEitherAsync(g, null, exec); },
3105 <            () -> { f.runAfterEither(nullFuture, () -> {}); },
3106 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}); },
3107 <            () -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); },
3108 <            () -> { f.runAfterEitherAsync(g, () -> {}, null); },
3109 <
3110 <            () -> { f.thenCompose(null); },
3111 <            () -> { f.thenComposeAsync(null); },
3112 <            () -> { f.thenComposeAsync(new CompletableFutureInc(), null); },
3113 <            () -> { f.thenComposeAsync(null, exec); },
3114 <
3115 <            () -> { f.exceptionally(null); },
3116 <
3117 <            () -> { f.handle(null); },
3118 <
3119 <            () -> { CompletableFuture.allOf((CompletableFuture<?>)null); },
3120 <            () -> { CompletableFuture.allOf((CompletableFuture<?>[])null); },
3121 <            () -> { CompletableFuture.allOf(f, null); },
3122 <            () -> { CompletableFuture.allOf(null, f); },
3123 <
3124 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>)null); },
3125 <            () -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); },
3126 <            () -> { CompletableFuture.anyOf(f, null); },
3127 <            () -> { CompletableFuture.anyOf(null, f); },
3037 >            () -> CompletableFuture.supplyAsync(null),
3038 >            () -> CompletableFuture.supplyAsync(null, exec),
3039 >            () -> CompletableFuture.supplyAsync(supplyOne, null),
3040 >
3041 >            () -> CompletableFuture.runAsync(null),
3042 >            () -> CompletableFuture.runAsync(null, exec),
3043 >            () -> CompletableFuture.runAsync(() -> {}, null),
3044 >
3045 >            () -> f.completeExceptionally(null),
3046 >
3047 >            () -> f.thenApply(null),
3048 >            () -> f.thenApplyAsync(null),
3049 >            () -> f.thenApplyAsync((x) -> x, null),
3050 >            () -> f.thenApplyAsync(null, exec),
3051 >
3052 >            () -> f.thenAccept(null),
3053 >            () -> f.thenAcceptAsync(null),
3054 >            () -> f.thenAcceptAsync((x) -> {} , null),
3055 >            () -> f.thenAcceptAsync(null, exec),
3056 >
3057 >            () -> f.thenRun(null),
3058 >            () -> f.thenRunAsync(null),
3059 >            () -> f.thenRunAsync(() -> {} , null),
3060 >            () -> f.thenRunAsync(null, exec),
3061 >
3062 >            () -> f.thenCombine(g, null),
3063 >            () -> f.thenCombineAsync(g, null),
3064 >            () -> f.thenCombineAsync(g, null, exec),
3065 >            () -> f.thenCombine(nullFuture, (x, y) -> x),
3066 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x),
3067 >            () -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec),
3068 >            () -> f.thenCombineAsync(g, (x, y) -> x, null),
3069 >
3070 >            () -> f.thenAcceptBoth(g, null),
3071 >            () -> f.thenAcceptBothAsync(g, null),
3072 >            () -> f.thenAcceptBothAsync(g, null, exec),
3073 >            () -> f.thenAcceptBoth(nullFuture, (x, y) -> {}),
3074 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}),
3075 >            () -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec),
3076 >            () -> f.thenAcceptBothAsync(g, (x, y) -> {}, null),
3077 >
3078 >            () -> f.runAfterBoth(g, null),
3079 >            () -> f.runAfterBothAsync(g, null),
3080 >            () -> f.runAfterBothAsync(g, null, exec),
3081 >            () -> f.runAfterBoth(nullFuture, () -> {}),
3082 >            () -> f.runAfterBothAsync(nullFuture, () -> {}),
3083 >            () -> f.runAfterBothAsync(nullFuture, () -> {}, exec),
3084 >            () -> f.runAfterBothAsync(g, () -> {}, null),
3085 >
3086 >            () -> f.applyToEither(g, null),
3087 >            () -> f.applyToEitherAsync(g, null),
3088 >            () -> f.applyToEitherAsync(g, null, exec),
3089 >            () -> f.applyToEither(nullFuture, (x) -> x),
3090 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x),
3091 >            () -> f.applyToEitherAsync(nullFuture, (x) -> x, exec),
3092 >            () -> f.applyToEitherAsync(g, (x) -> x, null),
3093 >
3094 >            () -> f.acceptEither(g, null),
3095 >            () -> f.acceptEitherAsync(g, null),
3096 >            () -> f.acceptEitherAsync(g, null, exec),
3097 >            () -> f.acceptEither(nullFuture, (x) -> {}),
3098 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}),
3099 >            () -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec),
3100 >            () -> f.acceptEitherAsync(g, (x) -> {}, null),
3101 >
3102 >            () -> f.runAfterEither(g, null),
3103 >            () -> f.runAfterEitherAsync(g, null),
3104 >            () -> f.runAfterEitherAsync(g, null, exec),
3105 >            () -> f.runAfterEither(nullFuture, () -> {}),
3106 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}),
3107 >            () -> f.runAfterEitherAsync(nullFuture, () -> {}, exec),
3108 >            () -> f.runAfterEitherAsync(g, () -> {}, null),
3109 >
3110 >            () -> f.thenCompose(null),
3111 >            () -> f.thenComposeAsync(null),
3112 >            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
3113 >            () -> f.thenComposeAsync(null, exec),
3114 >
3115 >            () -> f.exceptionally(null),
3116 >
3117 >            () -> f.handle(null),
3118 >
3119 >            () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3120 >            () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3121 >            () -> CompletableFuture.allOf(f, null),
3122 >            () -> CompletableFuture.allOf(null, f),
3123 >
3124 >            () -> CompletableFuture.anyOf((CompletableFuture<?>)null),
3125 >            () -> CompletableFuture.anyOf((CompletableFuture<?>[])null),
3126 >            () -> CompletableFuture.anyOf(f, null),
3127 >            () -> CompletableFuture.anyOf(null, f),
3128 >
3129 >            () -> f.obtrudeException(null),
3130          };
3131  
3132          assertThrows(NullPointerException.class, throwingActions);
# Line 3181 | Line 3278 | public class CompletableFutureTest exten
3278          checkCompletedWithWrappedCFException(g);
3279      }
3280  
3184
3281      /**
3282 <     * handleAsync action action completes normally with function
3283 <     * value on either normal or exceptional completion of source
3282 >     * handleAsync action completes normally with function value on
3283 >     * either normal or exceptional completion of source
3284       */
3285      public void testHandleAsync() {
3286          CompletableFuture<Integer> f, g;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines