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.49 by jsr166, Mon Jun 2 19:20:51 2014 UTC vs.
Revision 1.55 by jsr166, Mon Jun 2 21:41:37 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 375 | Line 375 | public class CompletableFutureTest exten
375          }
376      }
377      static final class Noop implements Runnable {
378 +        final ExecutionMode m;
379          int invocationCount = 0;
380 +        Noop(ExecutionMode m) { this.m = m; }
381          public void run() {
382 +            m.checkExecutionMode();
383              invocationCount++;
384          }
385      }
# Line 416 | Line 419 | public class CompletableFutureTest exten
419              throw new CFException();
420          }
421      }
422 <    static final class FailingNoop implements Runnable {
422 >    static final class FailingRunnable implements Runnable {
423          int invocationCount = 0;
424          public void run() {
425              invocationCount++;
# Line 909 | Line 912 | public class CompletableFutureTest exten
912       * runAsync completes after running Runnable
913       */
914      public void testRunAsync() {
915 <        Noop r = new Noop();
915 >        Noop r = new Noop(ExecutionMode.ASYNC);
916          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
917          assertNull(f.join());
918          assertEquals(1, r.invocationCount);
# Line 920 | Line 923 | public class CompletableFutureTest exten
923       * runAsync with executor completes after running Runnable
924       */
925      public void testRunAsync2() {
926 <        Noop r = new Noop();
926 >        Noop r = new Noop(ExecutionMode.EXECUTOR);
927          ThreadExecutor exec = new ThreadExecutor();
928          CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
929          assertNull(f.join());
# Line 933 | Line 936 | public class CompletableFutureTest exten
936       * failing runAsync completes exceptionally after running Runnable
937       */
938      public void testRunAsync3() {
939 <        FailingNoop r = new FailingNoop();
939 >        FailingRunnable r = new FailingRunnable();
940          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
941          checkCompletedWithWrappedCFException(f);
942          assertEquals(1, r.invocationCount);
# Line 980 | Line 983 | public class CompletableFutureTest exten
983          for (Integer v1 : new Integer[] { 1, null })
984      {
985          final CompletableFuture<Integer> f = new CompletableFuture<>();
986 <        final Noop r = new Noop();
986 >        final Noop r = new Noop(m);
987          if (!createIncomplete) f.complete(v1);
988          final CompletableFuture<Void> g = m.thenRun(f, r);
989 <        if (createIncomplete) f.complete(v1);
989 >        if (createIncomplete) {
990 >            checkIncomplete(g);
991 >            f.complete(v1);
992 >        }
993  
994          checkCompletedNormally(g, null);
995          checkCompletedNormally(f, v1);
# Line 1000 | Line 1006 | public class CompletableFutureTest exten
1006      {
1007          final CFException ex = new CFException();
1008          final CompletableFuture<Integer> f = new CompletableFuture<>();
1009 <        final Noop r = new Noop();
1009 >        final Noop r = new Noop(m);
1010          if (!createIncomplete) f.completeExceptionally(ex);
1011          final CompletableFuture<Void> g = m.thenRun(f, r);
1012 <        if (createIncomplete) f.completeExceptionally(ex);
1012 >        if (createIncomplete) {
1013 >            checkIncomplete(g);
1014 >            f.completeExceptionally(ex);
1015 >        }
1016  
1017          checkCompletedWithWrappedCFException(g, ex);
1018          checkCompletedWithWrappedCFException(f, ex);
# Line 1019 | Line 1028 | public class CompletableFutureTest exten
1028          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1029      {
1030          final CompletableFuture<Integer> f = new CompletableFuture<>();
1031 <        final Noop r = new Noop();
1031 >        final Noop r = new Noop(m);
1032          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1033          final CompletableFuture<Void> g = f.thenRun(r);
1034 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1034 >        if (createIncomplete) {
1035 >            checkIncomplete(g);
1036 >            assertTrue(f.cancel(mayInterruptIfRunning));
1037 >        }
1038  
1039          checkCompletedWithWrappedCancellationException(g);
1040          checkCancelled(f);
# Line 1038 | Line 1050 | public class CompletableFutureTest exten
1050          for (Integer v1 : new Integer[] { 1, null })
1051      {
1052          final CompletableFuture<Integer> f = new CompletableFuture<>();
1053 <        final FailingNoop r = new FailingNoop();
1053 >        final FailingRunnable r = new FailingRunnable();
1054          if (!createIncomplete) f.complete(v1);
1055          final CompletableFuture<Void> g = f.thenRun(r);
1056 <        if (createIncomplete) f.complete(v1);
1056 >        if (createIncomplete) {
1057 >            checkIncomplete(g);
1058 >            f.complete(v1);
1059 >        }
1060  
1061          checkCompletedWithWrappedCFException(g);
1062          checkCompletedNormally(f, v1);
# Line 1082 | Line 1097 | public class CompletableFutureTest exten
1097          final IncFunction r = new IncFunction();
1098          if (!createIncomplete) f.completeExceptionally(ex);
1099          final CompletableFuture<Integer> g = m.thenApply(f, r);
1100 <        if (createIncomplete) f.completeExceptionally(ex);
1100 >        if (createIncomplete) {
1101 >            checkIncomplete(g);
1102 >            f.completeExceptionally(ex);
1103 >        }
1104  
1105          checkCompletedWithWrappedCFException(g, ex);
1106          checkCompletedWithWrappedCFException(f, ex);
# Line 1101 | Line 1119 | public class CompletableFutureTest exten
1119          final IncFunction r = new IncFunction();
1120          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1121          final CompletableFuture<Integer> g = f.thenApply(r);
1122 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1122 >        if (createIncomplete) {
1123 >            checkIncomplete(g);
1124 >            assertTrue(f.cancel(mayInterruptIfRunning));
1125 >        }
1126  
1127          checkCompletedWithWrappedCancellationException(g);
1128          checkCancelled(f);
# Line 1120 | Line 1141 | public class CompletableFutureTest exten
1141          final FailingFunction r = new FailingFunction();
1142          if (!createIncomplete) f.complete(v1);
1143          final CompletableFuture<Integer> g = f.thenApply(r);
1144 <        if (createIncomplete) f.complete(v1);
1144 >        if (createIncomplete) {
1145 >            checkIncomplete(g);
1146 >            f.complete(v1);
1147 >        }
1148  
1149          checkCompletedWithWrappedCFException(g);
1150          checkCompletedNormally(f, v1);
# Line 1129 | Line 1153 | public class CompletableFutureTest exten
1153      /**
1154       * thenAccept result completes normally after normal completion of source
1155       */
1156 <    public void testThenAccept() {
1157 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1158 <        IncAction r = new IncAction();
1159 <        CompletableFuture<Void> g = f.thenAccept(r);
1160 <        f.complete(one);
1156 >    public void testThenAccept_normalCompletion() {
1157 >        for (ExecutionMode m : ExecutionMode.values())
1158 >        for (boolean createIncomplete : new boolean[] { true, false })
1159 >        for (Integer v1 : new Integer[] { 1, null })
1160 >    {
1161 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1162 >        final IncAction r = new IncAction();
1163 >        if (!createIncomplete) f.complete(v1);
1164 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1165 >        if (createIncomplete) {
1166 >            checkIncomplete(g);
1167 >            f.complete(v1);
1168 >        }
1169 >
1170          checkCompletedNormally(g, null);
1171 <        assertEquals(r.value, (Integer) 2);
1172 <    }
1171 >        checkCompletedNormally(f, v1);
1172 >        assertEquals(1, r.invocationCount);
1173 >        assertEquals(inc(v1), r.value);
1174 >    }}
1175  
1176      /**
1177       * thenAccept result completes exceptionally after exceptional
1178       * completion of source
1179       */
1180 <    public void testThenAccept2() {
1181 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1182 <        IncAction r = new IncAction();
1183 <        CompletableFuture<Void> g = f.thenAccept(r);
1184 <        f.completeExceptionally(new CFException());
1185 <        checkCompletedWithWrappedCFException(g);
1186 <    }
1180 >    public void testThenAccept_exceptionalCompletion() {
1181 >        for (ExecutionMode m : ExecutionMode.values())
1182 >        for (boolean createIncomplete : new boolean[] { true, false })
1183 >    {
1184 >        final CFException ex = new CFException();
1185 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1186 >        final IncAction r = new IncAction();
1187 >        if (!createIncomplete) f.completeExceptionally(ex);
1188 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1189 >        if (createIncomplete) {
1190 >            checkIncomplete(g);
1191 >            f.completeExceptionally(ex);
1192 >        }
1193 >
1194 >        checkCompletedWithWrappedCFException(g, ex);
1195 >        checkCompletedWithWrappedCFException(f, ex);
1196 >        assertEquals(0, r.invocationCount);
1197 >    }}
1198  
1199      /**
1200       * thenAccept result completes exceptionally if action does
1201       */
1202 <    public void testThenAccept3() {
1203 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1204 <        FailingConsumer r = new FailingConsumer();
1205 <        CompletableFuture<Void> g = f.thenAccept(r);
1206 <        f.complete(one);
1202 >    public void testThenAccept_actionFailed() {
1203 >        for (ExecutionMode m : ExecutionMode.values())
1204 >        for (boolean createIncomplete : new boolean[] { true, false })
1205 >        for (Integer v1 : new Integer[] { 1, null })
1206 >    {
1207 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1208 >        final FailingConsumer r = new FailingConsumer();
1209 >        if (!createIncomplete) f.complete(v1);
1210 >        final CompletableFuture<Void> g = f.thenAccept(r);
1211 >        if (createIncomplete) {
1212 >            checkIncomplete(g);
1213 >            f.complete(v1);
1214 >        }
1215 >
1216          checkCompletedWithWrappedCFException(g);
1217 <        assertEquals(1, r.invocationCount);
1218 <    }
1217 >        checkCompletedNormally(f, v1);
1218 >    }}
1219  
1220      /**
1221       * thenAccept result completes exceptionally if source cancelled
1222       */
1223 <    public void testThenAccept4() {
1224 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1225 <        IncAction r = new IncAction();
1226 <        CompletableFuture<Void> g = f.thenAccept(r);
1227 <        assertTrue(f.cancel(true));
1223 >    public void testThenAccept_sourceCancelled() {
1224 >        for (ExecutionMode m : ExecutionMode.values())
1225 >        for (boolean createIncomplete : new boolean[] { true, false })
1226 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1227 >    {
1228 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1229 >        final IncAction r = new IncAction();
1230 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1231 >        final CompletableFuture<Void> g = f.thenAccept(r);
1232 >        if (createIncomplete) {
1233 >            checkIncomplete(g);
1234 >            assertTrue(f.cancel(mayInterruptIfRunning));
1235 >        }
1236 >
1237          checkCompletedWithWrappedCancellationException(g);
1238 <    }
1238 >        checkCancelled(f);
1239 >        assertEquals(0, r.invocationCount);
1240 >    }}
1241  
1242      /**
1243       * thenCombine result completes normally after normal completion
1244       * of sources
1245       */
1246 <    public void testThenCombine_normalCompletion1() {
1246 >    public void testThenCombine_normalCompletion() {
1247 >        for (ExecutionMode m : ExecutionMode.values())
1248          for (boolean createIncomplete : new boolean[] { true, false })
1249          for (boolean fFirst : new boolean[] { true, false })
1183        for (ExecutionMode m : ExecutionMode.values())
1250          for (Integer v1 : new Integer[] { 1, null })
1251          for (Integer v2 : new Integer[] { 2, null })
1252      {
1253          final CompletableFuture<Integer> f = new CompletableFuture<>();
1254          final CompletableFuture<Integer> g = new CompletableFuture<>();
1255          final SubtractFunction r = new SubtractFunction();
1190        CompletableFuture<Integer> h = null;
1191        if (createIncomplete) h = m.thenCombine(f, g, r);
1256  
1257 <        if (fFirst)
1258 <            f.complete(v1);
1259 <        else
1260 <            g.complete(v2);
1261 <        if (createIncomplete) checkIncomplete(h);
1262 <        assertEquals(0, r.invocationCount);
1263 <        if (!fFirst)
1264 <            f.complete(v1);
1265 <        else
1202 <            g.complete(v2);
1203 <        if (!createIncomplete) h = m.thenCombine(f, g, r);
1257 >        if (fFirst) f.complete(v1); else g.complete(v2);
1258 >        if (!createIncomplete)
1259 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1260 >        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1261 >        if (createIncomplete) {
1262 >            checkIncomplete(h);
1263 >            assertEquals(0, r.invocationCount);
1264 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1265 >        }
1266  
1267          checkCompletedNormally(h, subtract(v1, v2));
1268          checkCompletedNormally(f, v1);
# Line 1212 | Line 1274 | public class CompletableFutureTest exten
1274       * thenCombine result completes exceptionally after exceptional
1275       * completion of either source
1276       */
1277 <    public void testThenCombine_exceptionalCompletion1() {
1216 <        for (ExecutionMode m : ExecutionMode.values())
1217 <        for (Integer v1 : new Integer[] { 1, null })
1218 <    {
1219 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1220 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1221 <        final SubtractFunction r = new SubtractFunction();
1222 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1223 <        final CFException ex = new CFException();
1224 <
1225 <        f.completeExceptionally(ex);
1226 <        checkIncomplete(h);
1227 <        g.complete(v1);
1228 <
1229 <        checkCompletedWithWrappedCFException(h, ex);
1230 <        checkCompletedWithWrappedCFException(f, ex);
1231 <        assertEquals(0, r.invocationCount);
1232 <        checkCompletedNormally(g, v1);
1233 <    }}
1234 <
1235 <    public void testThenCombine_exceptionalCompletion2() {
1236 <        for (ExecutionMode m : ExecutionMode.values())
1237 <        for (Integer v1 : new Integer[] { 1, null })
1238 <    {
1239 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1240 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1241 <        final SubtractFunction r = new SubtractFunction();
1242 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1243 <        final CFException ex = new CFException();
1244 <
1245 <        g.completeExceptionally(ex);
1246 <        checkIncomplete(h);
1247 <        f.complete(v1);
1248 <
1249 <        checkCompletedWithWrappedCFException(h, ex);
1250 <        checkCompletedWithWrappedCFException(g, ex);
1251 <        assertEquals(0, r.invocationCount);
1252 <        checkCompletedNormally(f, v1);
1253 <    }}
1254 <
1255 <    public void testThenCombine_exceptionalCompletion3() {
1277 >    public void testThenCombine_exceptionalCompletion() {
1278          for (ExecutionMode m : ExecutionMode.values())
1279 +        for (boolean createIncomplete : new boolean[] { true, false })
1280 +        for (boolean fFirst : new boolean[] { true, false })
1281          for (Integer v1 : new Integer[] { 1, null })
1282      {
1283          final CompletableFuture<Integer> f = new CompletableFuture<>();
1284          final CompletableFuture<Integer> g = new CompletableFuture<>();
1261        final SubtractFunction r = new SubtractFunction();
1285          final CFException ex = new CFException();
1263
1264        g.completeExceptionally(ex);
1265        f.complete(v1);
1266        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1267
1268        checkCompletedWithWrappedCFException(h, ex);
1269        checkCompletedWithWrappedCFException(g, ex);
1270        assertEquals(0, r.invocationCount);
1271        checkCompletedNormally(f, v1);
1272    }}
1273
1274    public void testThenCombine_exceptionalCompletion4() {
1275        for (ExecutionMode m : ExecutionMode.values())
1276        for (Integer v1 : new Integer[] { 1, null })
1277    {
1278        final CompletableFuture<Integer> f = new CompletableFuture<>();
1279        final CompletableFuture<Integer> g = new CompletableFuture<>();
1286          final SubtractFunction r = new SubtractFunction();
1281        final CFException ex = new CFException();
1287  
1288 <        f.completeExceptionally(ex);
1289 <        g.complete(v1);
1288 >        (fFirst ? f : g).complete(v1);
1289 >        if (!createIncomplete)
1290 >            (!fFirst ? f : g).completeExceptionally(ex);
1291          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1292 +        if (createIncomplete) {
1293 +            checkIncomplete(h);
1294 +            (!fFirst ? f : g).completeExceptionally(ex);
1295 +        }
1296  
1297          checkCompletedWithWrappedCFException(h, ex);
1288        checkCompletedWithWrappedCFException(f, ex);
1298          assertEquals(0, r.invocationCount);
1299 <        checkCompletedNormally(g, v1);
1299 >        checkCompletedNormally(fFirst ? f : g, v1);
1300 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1301      }}
1302  
1303      /**
1304       * thenCombine result completes exceptionally if action does
1305       */
1306 <    public void testThenCombine_actionFailed1() {
1297 <        for (ExecutionMode m : ExecutionMode.values())
1298 <        for (Integer v1 : new Integer[] { 1, null })
1299 <        for (Integer v2 : new Integer[] { 2, null })
1300 <    {
1301 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1302 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1303 <        final FailingBiFunction r = new FailingBiFunction();
1304 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1305 <
1306 <        f.complete(v1);
1307 <        checkIncomplete(h);
1308 <        g.complete(v2);
1309 <
1310 <        checkCompletedWithWrappedCFException(h);
1311 <        checkCompletedNormally(f, v1);
1312 <        checkCompletedNormally(g, v2);
1313 <    }}
1314 <
1315 <    public void testThenCombine_actionFailed2() {
1306 >    public void testThenCombine_actionFailed() {
1307          for (ExecutionMode m : ExecutionMode.values())
1308 +        for (boolean fFirst : new boolean[] { true, false })
1309          for (Integer v1 : new Integer[] { 1, null })
1310          for (Integer v2 : new Integer[] { 2, null })
1311      {
# Line 1322 | Line 1314 | public class CompletableFutureTest exten
1314          final FailingBiFunction r = new FailingBiFunction();
1315          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1316  
1317 <        g.complete(v2);
1318 <        checkIncomplete(h);
1319 <        f.complete(v1);
1317 >        if (fFirst) {
1318 >            f.complete(v1);
1319 >            g.complete(v2);
1320 >        } else {
1321 >            g.complete(v2);
1322 >            f.complete(v1);
1323 >        }
1324  
1325          checkCompletedWithWrappedCFException(h);
1326          checkCompletedNormally(f, v1);
# Line 1334 | Line 1330 | public class CompletableFutureTest exten
1330      /**
1331       * thenCombine result completes exceptionally if either source cancelled
1332       */
1333 <    public void testThenCombine_sourceCancelled1() {
1338 <        for (ExecutionMode m : ExecutionMode.values())
1339 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1340 <        for (Integer v1 : new Integer[] { 1, null })
1341 <    {
1342 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1343 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1344 <        final SubtractFunction r = new SubtractFunction();
1345 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1346 <
1347 <        assertTrue(f.cancel(mayInterruptIfRunning));
1348 <        checkIncomplete(h);
1349 <        g.complete(v1);
1350 <
1351 <        checkCompletedWithWrappedCancellationException(h);
1352 <        checkCancelled(f);
1353 <        assertEquals(0, r.invocationCount);
1354 <        checkCompletedNormally(g, v1);
1355 <    }}
1356 <
1357 <    public void testThenCombine_sourceCancelled2() {
1358 <        for (ExecutionMode m : ExecutionMode.values())
1359 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1360 <        for (Integer v1 : new Integer[] { 1, null })
1361 <    {
1362 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1363 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1364 <        final SubtractFunction r = new SubtractFunction();
1365 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1366 <
1367 <        assertTrue(g.cancel(mayInterruptIfRunning));
1368 <        checkIncomplete(h);
1369 <        f.complete(v1);
1370 <
1371 <        checkCompletedWithWrappedCancellationException(h);
1372 <        checkCancelled(g);
1373 <        assertEquals(0, r.invocationCount);
1374 <        checkCompletedNormally(f, v1);
1375 <    }}
1376 <
1377 <    public void testThenCombine_sourceCancelled3() {
1333 >    public void testThenCombine_sourceCancelled() {
1334          for (ExecutionMode m : ExecutionMode.values())
1335          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1336 +        for (boolean createIncomplete : new boolean[] { true, false })
1337 +        for (boolean fFirst : new boolean[] { true, false })
1338          for (Integer v1 : new Integer[] { 1, null })
1339      {
1340          final CompletableFuture<Integer> f = new CompletableFuture<>();
1341          final CompletableFuture<Integer> g = new CompletableFuture<>();
1342          final SubtractFunction r = new SubtractFunction();
1343  
1344 <        assertTrue(g.cancel(mayInterruptIfRunning));
1345 <        f.complete(v1);
1346 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1389 <
1390 <        checkCompletedWithWrappedCancellationException(h);
1391 <        checkCancelled(g);
1392 <        assertEquals(0, r.invocationCount);
1393 <        checkCompletedNormally(f, v1);
1394 <    }}
1395 <
1396 <    public void testThenCombine_sourceCancelled4() {
1397 <        for (ExecutionMode m : ExecutionMode.values())
1398 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1399 <        for (Integer v1 : new Integer[] { 1, null })
1400 <    {
1401 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1402 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1403 <        final SubtractFunction r = new SubtractFunction();
1404 <
1405 <        assertTrue(f.cancel(mayInterruptIfRunning));
1406 <        g.complete(v1);
1344 >        (fFirst ? f : g).complete(v1);
1345 >        if (!createIncomplete)
1346 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1347          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1348 +        if (createIncomplete) {
1349 +            checkIncomplete(h);
1350 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1351 +        }
1352  
1353          checkCompletedWithWrappedCancellationException(h);
1354 <        checkCancelled(f);
1354 >        checkCancelled(!fFirst ? f : g);
1355          assertEquals(0, r.invocationCount);
1356 <        checkCompletedNormally(g, v1);
1356 >        checkCompletedNormally(fFirst ? f : g, v1);
1357      }}
1358  
1359      /**
1360       * thenAcceptBoth result completes normally after normal
1361       * completion of sources
1362       */
1363 <    public void testThenAcceptBoth_normalCompletion1() {
1420 <        for (ExecutionMode m : ExecutionMode.values())
1421 <        for (Integer v1 : new Integer[] { 1, null })
1422 <        for (Integer v2 : new Integer[] { 2, null })
1423 <    {
1424 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1425 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1426 <        final SubtractAction r = new SubtractAction();
1427 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1428 <
1429 <        f.complete(v1);
1430 <        checkIncomplete(h);
1431 <        assertEquals(0, r.invocationCount);
1432 <        g.complete(v2);
1433 <
1434 <        checkCompletedNormally(h, null);
1435 <        assertEquals(subtract(v1, v2), r.value);
1436 <        checkCompletedNormally(f, v1);
1437 <        checkCompletedNormally(g, v2);
1438 <    }}
1439 <
1440 <    public void testThenAcceptBoth_normalCompletion2() {
1441 <        for (ExecutionMode m : ExecutionMode.values())
1442 <        for (Integer v1 : new Integer[] { 1, null })
1443 <        for (Integer v2 : new Integer[] { 2, null })
1444 <    {
1445 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1446 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1447 <        final SubtractAction r = new SubtractAction();
1448 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1449 <
1450 <        g.complete(v2);
1451 <        checkIncomplete(h);
1452 <        assertEquals(0, r.invocationCount);
1453 <        f.complete(v1);
1454 <
1455 <        checkCompletedNormally(h, null);
1456 <        assertEquals(subtract(v1, v2), r.value);
1457 <        checkCompletedNormally(f, v1);
1458 <        checkCompletedNormally(g, v2);
1459 <    }}
1460 <
1461 <    public void testThenAcceptBoth_normalCompletion3() {
1462 <        for (ExecutionMode m : ExecutionMode.values())
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 SubtractAction r = new SubtractAction();
1469 <
1470 <        g.complete(v2);
1471 <        f.complete(v1);
1472 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1473 <
1474 <        checkCompletedNormally(h, null);
1475 <        assertEquals(subtract(v1, v2), r.value);
1476 <        checkCompletedNormally(f, v1);
1477 <        checkCompletedNormally(g, v2);
1478 <    }}
1479 <
1480 <    public void testThenAcceptBoth_normalCompletion4() {
1363 >    public void testThenAcceptBoth_normalCompletion() {
1364          for (ExecutionMode m : ExecutionMode.values())
1365 +        for (boolean createIncomplete : new boolean[] { true, false })
1366 +        for (boolean fFirst : new boolean[] { true, false })
1367          for (Integer v1 : new Integer[] { 1, null })
1368          for (Integer v2 : new Integer[] { 2, null })
1369      {
# Line 1486 | Line 1371 | public class CompletableFutureTest exten
1371          final CompletableFuture<Integer> g = new CompletableFuture<>();
1372          final SubtractAction r = new SubtractAction();
1373  
1374 <        f.complete(v1);
1375 <        g.complete(v2);
1374 >        if (fFirst) f.complete(v1); else g.complete(v2);
1375 >        if (!createIncomplete)
1376 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1377          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1378 +        if (createIncomplete) {
1379 +            checkIncomplete(h);
1380 +            assertEquals(0, r.invocationCount);
1381 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1382 +        }
1383  
1384          checkCompletedNormally(h, null);
1385          assertEquals(subtract(v1, v2), r.value);
# Line 1500 | Line 1391 | public class CompletableFutureTest exten
1391       * thenAcceptBoth result completes exceptionally after exceptional
1392       * completion of either source
1393       */
1394 <    public void testThenAcceptBoth_exceptionalCompletion1() {
1504 <        for (ExecutionMode m : ExecutionMode.values())
1505 <        for (Integer v1 : new Integer[] { 1, null })
1506 <    {
1507 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1508 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1509 <        final SubtractAction r = new SubtractAction();
1510 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1511 <        final CFException ex = new CFException();
1512 <
1513 <        f.completeExceptionally(ex);
1514 <        checkIncomplete(h);
1515 <        g.complete(v1);
1516 <
1517 <        checkCompletedWithWrappedCFException(h, ex);
1518 <        checkCompletedWithWrappedCFException(f, ex);
1519 <        assertEquals(0, r.invocationCount);
1520 <        checkCompletedNormally(g, v1);
1521 <    }}
1522 <
1523 <    public void testThenAcceptBoth_exceptionalCompletion2() {
1524 <        for (ExecutionMode m : ExecutionMode.values())
1525 <        for (Integer v1 : new Integer[] { 1, null })
1526 <    {
1527 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1528 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1529 <        final SubtractAction r = new SubtractAction();
1530 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1531 <        final CFException ex = new CFException();
1532 <
1533 <        g.completeExceptionally(ex);
1534 <        checkIncomplete(h);
1535 <        f.complete(v1);
1536 <
1537 <        checkCompletedWithWrappedCFException(h, ex);
1538 <        checkCompletedWithWrappedCFException(g, ex);
1539 <        assertEquals(0, r.invocationCount);
1540 <        checkCompletedNormally(f, v1);
1541 <    }}
1542 <
1543 <    public void testThenAcceptBoth_exceptionalCompletion3() {
1394 >    public void testThenAcceptBoth_exceptionalCompletion() {
1395          for (ExecutionMode m : ExecutionMode.values())
1396 +        for (boolean createIncomplete : new boolean[] { true, false })
1397 +        for (boolean fFirst : new boolean[] { true, false })
1398          for (Integer v1 : new Integer[] { 1, null })
1399      {
1400          final CompletableFuture<Integer> f = new CompletableFuture<>();
1401          final CompletableFuture<Integer> g = new CompletableFuture<>();
1549        final SubtractAction r = new SubtractAction();
1402          final CFException ex = new CFException();
1551
1552        g.completeExceptionally(ex);
1553        f.complete(v1);
1554        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1555
1556        checkCompletedWithWrappedCFException(h, ex);
1557        checkCompletedWithWrappedCFException(g, ex);
1558        assertEquals(0, r.invocationCount);
1559        checkCompletedNormally(f, v1);
1560    }}
1561
1562    public void testThenAcceptBoth_exceptionalCompletion4() {
1563        for (ExecutionMode m : ExecutionMode.values())
1564        for (Integer v1 : new Integer[] { 1, null })
1565    {
1566        final CompletableFuture<Integer> f = new CompletableFuture<>();
1567        final CompletableFuture<Integer> g = new CompletableFuture<>();
1403          final SubtractAction r = new SubtractAction();
1569        final CFException ex = new CFException();
1404  
1405 <        f.completeExceptionally(ex);
1406 <        g.complete(v1);
1405 >        (fFirst ? f : g).complete(v1);
1406 >        if (!createIncomplete)
1407 >            (!fFirst ? f : g).completeExceptionally(ex);
1408          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1409 +        if (createIncomplete) {
1410 +            checkIncomplete(h);
1411 +            (!fFirst ? f : g).completeExceptionally(ex);
1412 +        }
1413  
1414          checkCompletedWithWrappedCFException(h, ex);
1576        checkCompletedWithWrappedCFException(f, ex);
1415          assertEquals(0, r.invocationCount);
1416 <        checkCompletedNormally(g, v1);
1416 >        checkCompletedNormally(fFirst ? f : g, v1);
1417 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1418      }}
1419  
1420      /**
1421       * thenAcceptBoth result completes exceptionally if action does
1422       */
1423 <    public void testThenAcceptBoth_actionFailed1() {
1585 <        for (ExecutionMode m : ExecutionMode.values())
1586 <        for (Integer v1 : new Integer[] { 1, null })
1587 <        for (Integer v2 : new Integer[] { 2, null })
1588 <    {
1589 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1590 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1591 <        final FailingBiConsumer r = new FailingBiConsumer();
1592 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1593 <
1594 <        f.complete(v1);
1595 <        checkIncomplete(h);
1596 <        g.complete(v2);
1597 <
1598 <        checkCompletedWithWrappedCFException(h);
1599 <        checkCompletedNormally(f, v1);
1600 <        checkCompletedNormally(g, v2);
1601 <    }}
1602 <
1603 <    public void testThenAcceptBoth_actionFailed2() {
1423 >    public void testThenAcceptBoth_actionFailed() {
1424          for (ExecutionMode m : ExecutionMode.values())
1425 +        for (boolean fFirst : new boolean[] { true, false })
1426          for (Integer v1 : new Integer[] { 1, null })
1427          for (Integer v2 : new Integer[] { 2, null })
1428      {
# Line 1610 | Line 1431 | public class CompletableFutureTest exten
1431          final FailingBiConsumer r = new FailingBiConsumer();
1432          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1433  
1434 <        g.complete(v2);
1435 <        checkIncomplete(h);
1436 <        f.complete(v1);
1434 >        if (fFirst) {
1435 >            f.complete(v1);
1436 >            g.complete(v2);
1437 >        } else {
1438 >            g.complete(v2);
1439 >            f.complete(v1);
1440 >        }
1441  
1442          checkCompletedWithWrappedCFException(h);
1443          checkCompletedNormally(f, v1);
# Line 1622 | Line 1447 | public class CompletableFutureTest exten
1447      /**
1448       * thenAcceptBoth result completes exceptionally if either source cancelled
1449       */
1450 <    public void testThenAcceptBoth_sourceCancelled1() {
1626 <        for (ExecutionMode m : ExecutionMode.values())
1627 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1628 <        for (Integer v1 : new Integer[] { 1, null })
1629 <    {
1630 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1631 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1632 <        final SubtractAction r = new SubtractAction();
1633 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1634 <
1635 <        assertTrue(f.cancel(mayInterruptIfRunning));
1636 <        checkIncomplete(h);
1637 <        g.complete(v1);
1638 <
1639 <        checkCompletedWithWrappedCancellationException(h);
1640 <        checkCancelled(f);
1641 <        assertEquals(0, r.invocationCount);
1642 <        checkCompletedNormally(g, v1);
1643 <    }}
1644 <
1645 <    public void testThenAcceptBoth_sourceCancelled2() {
1646 <        for (ExecutionMode m : ExecutionMode.values())
1647 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1648 <        for (Integer v1 : new Integer[] { 1, null })
1649 <    {
1650 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1651 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1652 <        final SubtractAction r = new SubtractAction();
1653 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1654 <
1655 <        assertTrue(g.cancel(mayInterruptIfRunning));
1656 <        checkIncomplete(h);
1657 <        f.complete(v1);
1658 <
1659 <        checkCompletedWithWrappedCancellationException(h);
1660 <        checkCancelled(g);
1661 <        assertEquals(0, r.invocationCount);
1662 <        checkCompletedNormally(f, v1);
1663 <    }}
1664 <
1665 <    public void testThenAcceptBoth_sourceCancelled3() {
1666 <        for (ExecutionMode m : ExecutionMode.values())
1667 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1668 <        for (Integer v1 : new Integer[] { 1, null })
1669 <    {
1670 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1671 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1672 <        final SubtractAction r = new SubtractAction();
1673 <
1674 <        assertTrue(g.cancel(mayInterruptIfRunning));
1675 <        f.complete(v1);
1676 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1677 <
1678 <        checkCompletedWithWrappedCancellationException(h);
1679 <        checkCancelled(g);
1680 <        assertEquals(0, r.invocationCount);
1681 <        checkCompletedNormally(f, v1);
1682 <    }}
1683 <
1684 <    public void testThenAcceptBoth_sourceCancelled4() {
1450 >    public void testThenAcceptBoth_sourceCancelled() {
1451          for (ExecutionMode m : ExecutionMode.values())
1452          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1453 +        for (boolean createIncomplete : new boolean[] { true, false })
1454 +        for (boolean fFirst : new boolean[] { true, false })
1455          for (Integer v1 : new Integer[] { 1, null })
1456      {
1457          final CompletableFuture<Integer> f = new CompletableFuture<>();
1458          final CompletableFuture<Integer> g = new CompletableFuture<>();
1459          final SubtractAction r = new SubtractAction();
1460  
1461 <        assertTrue(f.cancel(mayInterruptIfRunning));
1462 <        g.complete(v1);
1461 >        (fFirst ? f : g).complete(v1);
1462 >        if (!createIncomplete)
1463 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1464          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1465 +        if (createIncomplete) {
1466 +            checkIncomplete(h);
1467 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1468 +        }
1469  
1470          checkCompletedWithWrappedCancellationException(h);
1471 <        checkCancelled(f);
1471 >        checkCancelled(!fFirst ? f : g);
1472          assertEquals(0, r.invocationCount);
1473 <        checkCompletedNormally(g, v1);
1473 >        checkCompletedNormally(fFirst ? f : g, v1);
1474      }}
1475  
1476      /**
1477       * runAfterBoth result completes normally after normal
1478       * completion of sources
1479       */
1480 <    public void testRunAfterBoth_normalCompletion1() {
1708 <        for (ExecutionMode m : ExecutionMode.values())
1709 <        for (Integer v1 : new Integer[] { 1, null })
1710 <        for (Integer v2 : new Integer[] { 2, null })
1711 <    {
1712 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1713 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1714 <        final Noop r = new Noop();
1715 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1716 <
1717 <        f.complete(v1);
1718 <        checkIncomplete(h);
1719 <        assertEquals(0, r.invocationCount);
1720 <        g.complete(v2);
1721 <
1722 <        checkCompletedNormally(h, null);
1723 <        assertEquals(1, r.invocationCount);
1724 <        checkCompletedNormally(f, v1);
1725 <        checkCompletedNormally(g, v2);
1726 <    }}
1727 <
1728 <    public void testRunAfterBoth_normalCompletion2() {
1729 <        for (ExecutionMode m : ExecutionMode.values())
1730 <        for (Integer v1 : new Integer[] { 1, null })
1731 <        for (Integer v2 : new Integer[] { 2, null })
1732 <    {
1733 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1734 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1735 <        final Noop r = new Noop();
1736 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1737 <
1738 <        g.complete(v2);
1739 <        checkIncomplete(h);
1740 <        assertEquals(0, r.invocationCount);
1741 <        f.complete(v1);
1742 <
1743 <        checkCompletedNormally(h, null);
1744 <        assertEquals(1, r.invocationCount);
1745 <        checkCompletedNormally(f, v1);
1746 <        checkCompletedNormally(g, v2);
1747 <    }}
1748 <
1749 <    public void testRunAfterBoth_normalCompletion3() {
1750 <        for (ExecutionMode m : ExecutionMode.values())
1751 <        for (Integer v1 : new Integer[] { 1, null })
1752 <        for (Integer v2 : new Integer[] { 2, null })
1753 <    {
1754 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1755 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1756 <        final Noop r = new Noop();
1757 <
1758 <        g.complete(v2);
1759 <        f.complete(v1);
1760 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1761 <
1762 <        checkCompletedNormally(h, null);
1763 <        assertEquals(1, r.invocationCount);
1764 <        checkCompletedNormally(f, v1);
1765 <        checkCompletedNormally(g, v2);
1766 <    }}
1767 <
1768 <    public void testRunAfterBoth_normalCompletion4() {
1480 >    public void testRunAfterBoth_normalCompletion() {
1481          for (ExecutionMode m : ExecutionMode.values())
1482 +        for (boolean createIncomplete : new boolean[] { true, false })
1483 +        for (boolean fFirst : new boolean[] { true, false })
1484          for (Integer v1 : new Integer[] { 1, null })
1485          for (Integer v2 : new Integer[] { 2, null })
1486      {
1487          final CompletableFuture<Integer> f = new CompletableFuture<>();
1488          final CompletableFuture<Integer> g = new CompletableFuture<>();
1489 <        final Noop r = new Noop();
1489 >        final Noop r = new Noop(m);
1490  
1491 <        f.complete(v1);
1492 <        g.complete(v2);
1491 >        if (fFirst) f.complete(v1); else g.complete(v2);
1492 >        if (!createIncomplete)
1493 >            if (!fFirst) f.complete(v1); else g.complete(v2);
1494          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1495 +        if (createIncomplete) {
1496 +            checkIncomplete(h);
1497 +            assertEquals(0, r.invocationCount);
1498 +            if (!fFirst) f.complete(v1); else g.complete(v2);
1499 +        }
1500  
1501          checkCompletedNormally(h, null);
1502          assertEquals(1, r.invocationCount);
# Line 1788 | Line 1508 | public class CompletableFutureTest exten
1508       * runAfterBoth result completes exceptionally after exceptional
1509       * completion of either source
1510       */
1511 <    public void testRunAfterBoth_exceptionalCompletion1() {
1792 <        for (ExecutionMode m : ExecutionMode.values())
1793 <        for (Integer v1 : new Integer[] { 1, null })
1794 <    {
1795 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1796 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1797 <        final Noop r = new Noop();
1798 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1799 <        final CFException ex = new CFException();
1800 <
1801 <        f.completeExceptionally(ex);
1802 <        checkIncomplete(h);
1803 <        g.complete(v1);
1804 <
1805 <        checkCompletedWithWrappedCFException(h, ex);
1806 <        checkCompletedWithWrappedCFException(f, ex);
1807 <        assertEquals(0, r.invocationCount);
1808 <        checkCompletedNormally(g, v1);
1809 <    }}
1810 <
1811 <    public void testRunAfterBoth_exceptionalCompletion2() {
1812 <        for (ExecutionMode m : ExecutionMode.values())
1813 <        for (Integer v1 : new Integer[] { 1, null })
1814 <    {
1815 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1816 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1817 <        final Noop r = new Noop();
1818 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1819 <        final CFException ex = new CFException();
1820 <
1821 <        g.completeExceptionally(ex);
1822 <        checkIncomplete(h);
1823 <        f.complete(v1);
1824 <
1825 <        checkCompletedWithWrappedCFException(h, ex);
1826 <        checkCompletedWithWrappedCFException(g, ex);
1827 <        assertEquals(0, r.invocationCount);
1828 <        checkCompletedNormally(f, v1);
1829 <    }}
1830 <
1831 <    public void testRunAfterBoth_exceptionalCompletion3() {
1832 <        for (ExecutionMode m : ExecutionMode.values())
1833 <        for (Integer v1 : new Integer[] { 1, null })
1834 <    {
1835 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1836 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1837 <        final Noop r = new Noop();
1838 <        final CFException ex = new CFException();
1839 <
1840 <        g.completeExceptionally(ex);
1841 <        f.complete(v1);
1842 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1843 <
1844 <        checkCompletedWithWrappedCFException(h, ex);
1845 <        checkCompletedWithWrappedCFException(g, ex);
1846 <        assertEquals(0, r.invocationCount);
1847 <        checkCompletedNormally(f, v1);
1848 <    }}
1849 <
1850 <    public void testRunAfterBoth_exceptionalCompletion4() {
1511 >    public void testRunAfterBoth_exceptionalCompletion() {
1512          for (ExecutionMode m : ExecutionMode.values())
1513 +        for (boolean createIncomplete : new boolean[] { true, false })
1514 +        for (boolean fFirst : new boolean[] { true, false })
1515          for (Integer v1 : new Integer[] { 1, null })
1516      {
1517          final CompletableFuture<Integer> f = new CompletableFuture<>();
1518          final CompletableFuture<Integer> g = new CompletableFuture<>();
1856        final Noop r = new Noop();
1519          final CFException ex = new CFException();
1520 +        final Noop r = new Noop(m);
1521  
1522 <        f.completeExceptionally(ex);
1523 <        g.complete(v1);
1522 >        (fFirst ? f : g).complete(v1);
1523 >        if (!createIncomplete)
1524 >            (!fFirst ? f : g).completeExceptionally(ex);
1525          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1526 +        if (createIncomplete) {
1527 +            checkIncomplete(h);
1528 +            (!fFirst ? f : g).completeExceptionally(ex);
1529 +        }
1530  
1531          checkCompletedWithWrappedCFException(h, ex);
1864        checkCompletedWithWrappedCFException(f, ex);
1532          assertEquals(0, r.invocationCount);
1533 <        checkCompletedNormally(g, v1);
1533 >        checkCompletedNormally(fFirst ? f : g, v1);
1534 >        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1535      }}
1536  
1537      /**
1538       * runAfterBoth result completes exceptionally if action does
1539       */
1540 <    public void testRunAfterBoth_actionFailed1() {
1873 <        for (ExecutionMode m : ExecutionMode.values())
1874 <        for (Integer v1 : new Integer[] { 1, null })
1875 <        for (Integer v2 : new Integer[] { 2, null })
1876 <    {
1877 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1878 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1879 <        final FailingNoop r = new FailingNoop();
1880 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1881 <
1882 <        f.complete(v1);
1883 <        checkIncomplete(h);
1884 <        g.complete(v2);
1885 <
1886 <        checkCompletedWithWrappedCFException(h);
1887 <        checkCompletedNormally(f, v1);
1888 <        checkCompletedNormally(g, v2);
1889 <    }}
1890 <
1891 <    public void testRunAfterBoth_actionFailed2() {
1540 >    public void testRunAfterBoth_actionFailed() {
1541          for (ExecutionMode m : ExecutionMode.values())
1542 +        for (boolean fFirst : new boolean[] { true, false })
1543          for (Integer v1 : new Integer[] { 1, null })
1544          for (Integer v2 : new Integer[] { 2, null })
1545      {
1546          final CompletableFuture<Integer> f = new CompletableFuture<>();
1547          final CompletableFuture<Integer> g = new CompletableFuture<>();
1548 <        final FailingNoop r = new FailingNoop();
1899 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1548 >        final FailingRunnable r = new FailingRunnable();
1549  
1550 <        g.complete(v2);
1551 <        checkIncomplete(h);
1552 <        f.complete(v1);
1550 >        CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r);
1551 >        if (fFirst) {
1552 >            f.complete(v1);
1553 >            g.complete(v2);
1554 >        } else {
1555 >            g.complete(v2);
1556 >            f.complete(v1);
1557 >        }
1558 >        CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r);
1559  
1560 <        checkCompletedWithWrappedCFException(h);
1560 >        checkCompletedWithWrappedCFException(h1);
1561 >        checkCompletedWithWrappedCFException(h2);
1562          checkCompletedNormally(f, v1);
1563          checkCompletedNormally(g, v2);
1564      }}
# Line 1910 | Line 1566 | public class CompletableFutureTest exten
1566      /**
1567       * runAfterBoth result completes exceptionally if either source cancelled
1568       */
1569 <    public void testRunAfterBoth_sourceCancelled1() {
1914 <        for (ExecutionMode m : ExecutionMode.values())
1915 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1916 <        for (Integer v1 : new Integer[] { 1, null })
1917 <    {
1918 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1919 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1920 <        final Noop r = new Noop();
1921 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1922 <
1923 <        assertTrue(f.cancel(mayInterruptIfRunning));
1924 <        checkIncomplete(h);
1925 <        g.complete(v1);
1926 <
1927 <        checkCompletedWithWrappedCancellationException(h);
1928 <        checkCancelled(f);
1929 <        assertEquals(0, r.invocationCount);
1930 <        checkCompletedNormally(g, v1);
1931 <    }}
1932 <
1933 <    public void testRunAfterBoth_sourceCancelled2() {
1934 <        for (ExecutionMode m : ExecutionMode.values())
1935 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1936 <        for (Integer v1 : new Integer[] { 1, null })
1937 <    {
1938 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1939 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1940 <        final Noop r = new Noop();
1941 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1942 <
1943 <        assertTrue(g.cancel(mayInterruptIfRunning));
1944 <        checkIncomplete(h);
1945 <        f.complete(v1);
1946 <
1947 <        checkCompletedWithWrappedCancellationException(h);
1948 <        checkCancelled(g);
1949 <        assertEquals(0, r.invocationCount);
1950 <        checkCompletedNormally(f, v1);
1951 <    }}
1952 <
1953 <    public void testRunAfterBoth_sourceCancelled3() {
1569 >    public void testRunAfterBoth_sourceCancelled() {
1570          for (ExecutionMode m : ExecutionMode.values())
1571          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1572 +        for (boolean createIncomplete : new boolean[] { true, false })
1573 +        for (boolean fFirst : new boolean[] { true, false })
1574          for (Integer v1 : new Integer[] { 1, null })
1575      {
1576          final CompletableFuture<Integer> f = new CompletableFuture<>();
1577          final CompletableFuture<Integer> g = new CompletableFuture<>();
1578 <        final Noop r = new Noop();
1961 <
1962 <        assertTrue(g.cancel(mayInterruptIfRunning));
1963 <        f.complete(v1);
1964 <        final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1965 <
1966 <        checkCompletedWithWrappedCancellationException(h);
1967 <        checkCancelled(g);
1968 <        assertEquals(0, r.invocationCount);
1969 <        checkCompletedNormally(f, v1);
1970 <    }}
1578 >        final Noop r = new Noop(m);
1579  
1972    public void testRunAfterBoth_sourceCancelled4() {
1973        for (ExecutionMode m : ExecutionMode.values())
1974        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1975        for (Integer v1 : new Integer[] { 1, null })
1976    {
1977        final CompletableFuture<Integer> f = new CompletableFuture<>();
1978        final CompletableFuture<Integer> g = new CompletableFuture<>();
1979        final Noop r = new Noop();
1580  
1581 <        assertTrue(f.cancel(mayInterruptIfRunning));
1582 <        g.complete(v1);
1581 >        (fFirst ? f : g).complete(v1);
1582 >        if (!createIncomplete)
1583 >            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1584          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1585 +        if (createIncomplete) {
1586 +            checkIncomplete(h);
1587 +            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1588 +        }
1589  
1590          checkCompletedWithWrappedCancellationException(h);
1591 <        checkCancelled(f);
1591 >        checkCancelled(!fFirst ? f : g);
1592          assertEquals(0, r.invocationCount);
1593 <        checkCompletedNormally(g, v1);
1593 >        checkCompletedNormally(fFirst ? f : g, v1);
1594      }}
1595  
1596      /**
1597       * applyToEither result completes normally after normal completion
1598       * of either source
1599       */
1600 <    public void testApplyToEither_normalCompletion1() {
1600 >    public void testApplyToEither_normalCompletion() {
1601          for (ExecutionMode m : ExecutionMode.values())
1602 +        for (boolean createIncomplete : new boolean[] { true, false })
1603 +        for (boolean fFirst : new boolean[] { true, false })
1604          for (Integer v1 : new Integer[] { 1, null })
1605          for (Integer v2 : new Integer[] { 2, null })
1606      {
1607          final CompletableFuture<Integer> f = new CompletableFuture<>();
1608          final CompletableFuture<Integer> g = new CompletableFuture<>();
1609          final IncFunction r = new IncFunction();
2003        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1610  
1611 <        f.complete(v1);
1612 <        checkCompletedNormally(h, inc(v1));
1613 <        g.complete(v2);
1611 >        if (!createIncomplete)
1612 >            if (fFirst) f.complete(v1); else g.complete(v2);
1613 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1614 >        if (createIncomplete) {
1615 >            checkIncomplete(h);
1616 >            assertEquals(0, r.invocationCount);
1617 >            if (fFirst) f.complete(v1); else g.complete(v2);
1618 >        }
1619 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1620 >        if (!fFirst) f.complete(v1); else g.complete(v2);
1621  
1622          checkCompletedNormally(f, v1);
1623          checkCompletedNormally(g, v2);
1624 <        checkCompletedNormally(h, inc(v1));
1624 >        checkCompletedNormally(h, inc(fFirst ? v1 : v2));
1625      }}
1626  
1627 <    public void testApplyToEither_normalCompletion2() {
1627 >    public void testApplyToEither_normalCompletionBothAvailable() {
1628          for (ExecutionMode m : ExecutionMode.values())
1629 +        for (boolean fFirst : new boolean[] { true, false })
1630          for (Integer v1 : new Integer[] { 1, null })
1631          for (Integer v2 : new Integer[] { 2, null })
1632      {
1633          final CompletableFuture<Integer> f = new CompletableFuture<>();
1634          final CompletableFuture<Integer> g = new CompletableFuture<>();
1635          final IncFunction r = new IncFunction();
2022        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1636  
1637 <        g.complete(v2);
1638 <        checkCompletedNormally(h, inc(v2));
1639 <        f.complete(v1);
1640 <
1641 <        checkCompletedNormally(f, v1);
1642 <        checkCompletedNormally(g, v2);
1643 <        checkCompletedNormally(h, inc(v2));
2031 <        }}
2032 <
2033 <    public void testApplyToEither_normalCompletion3() {
2034 <        for (ExecutionMode m : ExecutionMode.values())
2035 <        for (Integer v1 : new Integer[] { 1, null })
2036 <        for (Integer v2 : new Integer[] { 2, null })
2037 <    {
2038 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2039 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2040 <        final IncFunction r = new IncFunction();
1637 >        if (fFirst) {
1638 >            f.complete(v1);
1639 >            g.complete(v2);
1640 >        } else {
1641 >            g.complete(v2);
1642 >            f.complete(v1);
1643 >        }
1644  
2042        f.complete(v1);
2043        g.complete(v2);
1645          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1646  
1647          checkCompletedNormally(f, v1);
# Line 2058 | Line 1659 | public class CompletableFutureTest exten
1659       */
1660      public void testApplyToEither_exceptionalCompletion1() {
1661          for (ExecutionMode m : ExecutionMode.values())
1662 +        for (boolean createIncomplete : new boolean[] { true, false })
1663 +        for (boolean fFirst : new boolean[] { true, false })
1664          for (Integer v1 : new Integer[] { 1, null })
1665      {
1666          final CompletableFuture<Integer> f = new CompletableFuture<>();
1667          final CompletableFuture<Integer> g = new CompletableFuture<>();
2065        final IncFunction r = new IncFunction();
2066        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1668          final CFException ex = new CFException();
2068
2069        f.completeExceptionally(ex);
2070        checkCompletedWithWrappedCFException(h, ex);
2071        g.complete(v1);
2072
2073        assertEquals(0, r.invocationCount);
2074        checkCompletedNormally(g, v1);
2075        checkCompletedWithWrappedCFException(f, ex);
2076        checkCompletedWithWrappedCFException(h, ex);
2077    }}
2078
2079    public void testApplyToEither_exceptionalCompletion2() {
2080        for (ExecutionMode m : ExecutionMode.values())
2081        for (Integer v1 : new Integer[] { 1, null })
2082    {
2083        final CompletableFuture<Integer> f = new CompletableFuture<>();
2084        final CompletableFuture<Integer> g = new CompletableFuture<>();
1669          final IncFunction r = new IncFunction();
1670 +
1671 +        if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex);
1672          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1673 <        final CFException ex = new CFException();
1673 >        if (createIncomplete) {
1674 >            checkIncomplete(h);
1675 >            assertEquals(0, r.invocationCount);
1676 >            (fFirst ? f : g).completeExceptionally(ex);
1677 >        }
1678  
2089        g.completeExceptionally(ex);
1679          checkCompletedWithWrappedCFException(h, ex);
1680 <        f.complete(v1);
1680 >        (!fFirst ? f : g).complete(v1);
1681  
1682          assertEquals(0, r.invocationCount);
1683 <        checkCompletedNormally(f, v1);
1684 <        checkCompletedWithWrappedCFException(g, ex);
1683 >        checkCompletedNormally(!fFirst ? f : g, v1);
1684 >        checkCompletedWithWrappedCFException(fFirst ? f : g, ex);
1685          checkCompletedWithWrappedCFException(h, ex);
1686      }}
1687  
1688 <    public void testApplyToEither_exceptionalCompletion3() {
1688 >    public void testApplyToEither_exceptionalCompletion2() {
1689          for (ExecutionMode m : ExecutionMode.values())
1690 +        for (boolean reverseArgs : new boolean[] { true, false })
1691 +        for (boolean fFirst : new boolean[] { true, false })
1692          for (Integer v1 : new Integer[] { 1, null })
1693      {
1694          final CompletableFuture<Integer> f = new CompletableFuture<>();
1695          final CompletableFuture<Integer> g = new CompletableFuture<>();
1696 <        final IncFunction r = new IncFunction();
1696 >        final IncFunction r1 = new IncFunction();
1697 >        final IncFunction r2 = new IncFunction();
1698          final CFException ex = new CFException();
1699 <
1700 <        g.completeExceptionally(ex);
1701 <        f.complete(v1);
1702 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1699 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1700 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1701 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1702 >        if (fFirst) {
1703 >            f.complete(v1);
1704 >            g.completeExceptionally(ex);
1705 >        } else {
1706 >            g.completeExceptionally(ex);
1707 >            f.complete(v1);
1708 >        }
1709 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1710  
1711          // unspecified behavior
2113        Integer v;
1712          try {
1713 <            assertEquals(inc(v1), h.join());
1714 <            assertEquals(1, r.invocationCount);
1713 >            assertEquals(inc(v1), h1.join());
1714 >            assertEquals(1, r1.invocationCount);
1715          } catch (CompletionException ok) {
1716 <            checkCompletedWithWrappedCFException(h, ex);
1717 <            assertEquals(0, r.invocationCount);
1716 >            checkCompletedWithWrappedCFException(h1, ex);
1717 >            assertEquals(0, r1.invocationCount);
1718          }
1719  
2122        checkCompletedWithWrappedCFException(g, ex);
2123        checkCompletedNormally(f, v1);
2124    }}
2125
2126    public void testApplyToEither_exceptionalCompletion4() {
2127        for (ExecutionMode m : ExecutionMode.values())
2128        for (Integer v1 : new Integer[] { 1, null })
2129    {
2130        final CompletableFuture<Integer> f = new CompletableFuture<>();
2131        final CompletableFuture<Integer> g = new CompletableFuture<>();
2132        final IncFunction r = new IncFunction();
2133        final CFException ex = new CFException();
2134
2135        f.completeExceptionally(ex);
2136        g.complete(v1);
2137        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2138
2139        // unspecified behavior
2140        Integer v;
1720          try {
1721 <            assertEquals(inc(v1), h.join());
1722 <            assertEquals(1, r.invocationCount);
1721 >            assertEquals(inc(v1), h2.join());
1722 >            assertEquals(1, r2.invocationCount);
1723          } catch (CompletionException ok) {
1724 <            checkCompletedWithWrappedCFException(h, ex);
1725 <            assertEquals(0, r.invocationCount);
1724 >            checkCompletedWithWrappedCFException(h2, ex);
1725 >            assertEquals(0, r2.invocationCount);
1726          }
1727  
1728 <        checkCompletedWithWrappedCFException(f, ex);
1729 <        checkCompletedNormally(g, v1);
1728 >        checkCompletedWithWrappedCFException(g, ex);
1729 >        checkCompletedNormally(f, v1);
1730      }}
1731  
1732      /**
# Line 2193 | Line 1772 | public class CompletableFutureTest exten
1772      public void testApplyToEither_sourceCancelled1() {
1773          for (ExecutionMode m : ExecutionMode.values())
1774          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1775 +        for (boolean createIncomplete : new boolean[] { true, false })
1776 +        for (boolean fFirst : new boolean[] { true, false })
1777          for (Integer v1 : new Integer[] { 1, null })
1778      {
1779          final CompletableFuture<Integer> f = new CompletableFuture<>();
1780          final CompletableFuture<Integer> g = new CompletableFuture<>();
1781          final IncFunction r = new IncFunction();
2201        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2202
2203        assertTrue(f.cancel(mayInterruptIfRunning));
2204        checkCompletedWithWrappedCancellationException(h);
2205        g.complete(v1);
2206
2207        checkCancelled(f);
2208        assertEquals(0, r.invocationCount);
2209        checkCompletedNormally(g, v1);
2210        checkCompletedWithWrappedCancellationException(h);
2211    }}
1782  
1783 <    public void testApplyToEither_sourceCancelled2() {
2214 <        for (ExecutionMode m : ExecutionMode.values())
2215 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2216 <        for (Integer v1 : new Integer[] { 1, null })
2217 <    {
2218 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2219 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
2220 <        final IncFunction r = new IncFunction();
1783 >        if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1784          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1785 +        if (createIncomplete) {
1786 +            checkIncomplete(h);
1787 +            assertEquals(0, r.invocationCount);
1788 +            assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1789 +        }
1790  
2223        assertTrue(g.cancel(mayInterruptIfRunning));
1791          checkCompletedWithWrappedCancellationException(h);
1792 <        f.complete(v1);
1792 >        (!fFirst ? f : g).complete(v1);
1793  
2227        checkCancelled(g);
1794          assertEquals(0, r.invocationCount);
1795 <        checkCompletedNormally(f, v1);
1795 >        checkCompletedNormally(!fFirst ? f : g, v1);
1796 >        checkCancelled(fFirst ? f : g);
1797          checkCompletedWithWrappedCancellationException(h);
1798      }}
1799  
1800 <    public void testApplyToEither_sourceCancelled3() {
1800 >    public void testApplyToEither_sourceCancelled2() {
1801          for (ExecutionMode m : ExecutionMode.values())
1802          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1803 +        for (boolean reverseArgs : new boolean[] { true, false })
1804 +        for (boolean fFirst : new boolean[] { true, false })
1805          for (Integer v1 : new Integer[] { 1, null })
1806      {
1807          final CompletableFuture<Integer> f = new CompletableFuture<>();
1808          final CompletableFuture<Integer> g = new CompletableFuture<>();
1809 <        final IncFunction r = new IncFunction();
1809 >        final IncFunction r1 = new IncFunction();
1810 >        final IncFunction r2 = new IncFunction();
1811 >        final CFException ex = new CFException();
1812 >        final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1813 >        final CompletableFuture<Integer> k = (reverseArgs ? f : g);
1814  
1815 <        assertTrue(g.cancel(mayInterruptIfRunning));
1816 <        f.complete(v1);
1817 <        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1815 >        final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1);
1816 >        if (fFirst) {
1817 >            f.complete(v1);
1818 >            assertTrue(g.cancel(mayInterruptIfRunning));
1819 >        } else {
1820 >            assertTrue(g.cancel(mayInterruptIfRunning));
1821 >            f.complete(v1);
1822 >        }
1823 >        final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2);
1824  
1825          // unspecified behavior
2247        Integer v;
1826          try {
1827 <            assertEquals(inc(v1), h.join());
1828 <            assertEquals(1, r.invocationCount);
1827 >            assertEquals(inc(v1), h1.join());
1828 >            assertEquals(1, r1.invocationCount);
1829          } catch (CompletionException ok) {
1830 <            checkCompletedWithWrappedCancellationException(h);
1831 <            assertEquals(0, r.invocationCount);
1830 >            checkCompletedWithWrappedCancellationException(h1);
1831 >            assertEquals(0, r1.invocationCount);
1832          }
1833  
2256        checkCancelled(g);
2257        checkCompletedNormally(f, v1);
2258    }}
2259
2260    public void testApplyToEither_sourceCancelled4() {
2261        for (ExecutionMode m : ExecutionMode.values())
2262        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2263        for (Integer v1 : new Integer[] { 1, null })
2264    {
2265        final CompletableFuture<Integer> f = new CompletableFuture<>();
2266        final CompletableFuture<Integer> g = new CompletableFuture<>();
2267        final IncFunction r = new IncFunction();
2268
2269        assertTrue(f.cancel(mayInterruptIfRunning));
2270        g.complete(v1);
2271        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2272
2273        // unspecified behavior
2274        Integer v;
1834          try {
1835 <            assertEquals(inc(v1), h.join());
1836 <            assertEquals(1, r.invocationCount);
1835 >            assertEquals(inc(v1), h2.join());
1836 >            assertEquals(1, r2.invocationCount);
1837          } catch (CompletionException ok) {
1838 <            checkCompletedWithWrappedCancellationException(h);
1839 <            assertEquals(0, r.invocationCount);
1838 >            checkCompletedWithWrappedCancellationException(h2);
1839 >            assertEquals(0, r2.invocationCount);
1840          }
1841  
1842 <        checkCancelled(f);
1843 <        checkCompletedNormally(g, v1);
1842 >        checkCancelled(g);
1843 >        checkCompletedNormally(f, v1);
1844      }}
1845  
1846      /**
# Line 2597 | Line 2156 | public class CompletableFutureTest exten
2156      {
2157          final CompletableFuture<Integer> f = new CompletableFuture<>();
2158          final CompletableFuture<Integer> g = new CompletableFuture<>();
2159 <        final Noop r = new Noop();
2159 >        final Noop r = new Noop(m);
2160          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2161  
2162          f.complete(v1);
# Line 2618 | Line 2177 | public class CompletableFutureTest exten
2177      {
2178          final CompletableFuture<Integer> f = new CompletableFuture<>();
2179          final CompletableFuture<Integer> g = new CompletableFuture<>();
2180 <        final Noop r = new Noop();
2180 >        final Noop r = new Noop(m);
2181          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2182  
2183          g.complete(v2);
# Line 2639 | Line 2198 | public class CompletableFutureTest exten
2198      {
2199          final CompletableFuture<Integer> f = new CompletableFuture<>();
2200          final CompletableFuture<Integer> g = new CompletableFuture<>();
2201 <        final Noop r = new Noop();
2201 >        final Noop r = new Noop(m);
2202  
2203          f.complete(v1);
2204          g.complete(v2);
# Line 2661 | Line 2220 | public class CompletableFutureTest exten
2220      {
2221          final CompletableFuture<Integer> f = new CompletableFuture<>();
2222          final CompletableFuture<Integer> g = new CompletableFuture<>();
2223 <        final Noop r = new Noop();
2223 >        final Noop r = new Noop(m);
2224          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2225          final CFException ex = new CFException();
2226  
# Line 2681 | Line 2240 | public class CompletableFutureTest exten
2240      {
2241          final CompletableFuture<Integer> f = new CompletableFuture<>();
2242          final CompletableFuture<Integer> g = new CompletableFuture<>();
2243 <        final Noop r = new Noop();
2243 >        final Noop r = new Noop(m);
2244          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2245          final CFException ex = new CFException();
2246  
# Line 2701 | Line 2260 | public class CompletableFutureTest exten
2260      {
2261          final CompletableFuture<Integer> f = new CompletableFuture<>();
2262          final CompletableFuture<Integer> g = new CompletableFuture<>();
2263 <        final Noop r = new Noop();
2263 >        final Noop r = new Noop(m);
2264          final CFException ex = new CFException();
2265  
2266          g.completeExceptionally(ex);
# Line 2728 | Line 2287 | public class CompletableFutureTest exten
2287      {
2288          final CompletableFuture<Integer> f = new CompletableFuture<>();
2289          final CompletableFuture<Integer> g = new CompletableFuture<>();
2290 <        final Noop r = new Noop();
2290 >        final Noop r = new Noop(m);
2291          final CFException ex = new CFException();
2292  
2293          f.completeExceptionally(ex);
# Line 2759 | Line 2318 | public class CompletableFutureTest exten
2318      {
2319          final CompletableFuture<Integer> f = new CompletableFuture<>();
2320          final CompletableFuture<Integer> g = new CompletableFuture<>();
2321 <        final FailingNoop r = new FailingNoop();
2321 >        final FailingRunnable r = new FailingRunnable();
2322          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2323  
2324          f.complete(v1);
# Line 2776 | Line 2335 | public class CompletableFutureTest exten
2335      {
2336          final CompletableFuture<Integer> f = new CompletableFuture<>();
2337          final CompletableFuture<Integer> g = new CompletableFuture<>();
2338 <        final FailingNoop r = new FailingNoop();
2338 >        final FailingRunnable r = new FailingRunnable();
2339          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2340  
2341          g.complete(v2);
# Line 2796 | Line 2355 | public class CompletableFutureTest exten
2355      {
2356          final CompletableFuture<Integer> f = new CompletableFuture<>();
2357          final CompletableFuture<Integer> g = new CompletableFuture<>();
2358 <        final Noop r = new Noop();
2358 >        final Noop r = new Noop(m);
2359          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2360  
2361          assertTrue(f.cancel(mayInterruptIfRunning));
# Line 2816 | Line 2375 | public class CompletableFutureTest exten
2375      {
2376          final CompletableFuture<Integer> f = new CompletableFuture<>();
2377          final CompletableFuture<Integer> g = new CompletableFuture<>();
2378 <        final Noop r = new Noop();
2378 >        final Noop r = new Noop(m);
2379          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2380  
2381          assertTrue(g.cancel(mayInterruptIfRunning));
# Line 2836 | Line 2395 | public class CompletableFutureTest exten
2395      {
2396          final CompletableFuture<Integer> f = new CompletableFuture<>();
2397          final CompletableFuture<Integer> g = new CompletableFuture<>();
2398 <        final Noop r = new Noop();
2398 >        final Noop r = new Noop(m);
2399  
2400          assertTrue(g.cancel(mayInterruptIfRunning));
2401          f.complete(v1);
# Line 2863 | Line 2422 | public class CompletableFutureTest exten
2422      {
2423          final CompletableFuture<Integer> f = new CompletableFuture<>();
2424          final CompletableFuture<Integer> g = new CompletableFuture<>();
2425 <        final Noop r = new Noop();
2425 >        final Noop r = new Noop(m);
2426  
2427          assertTrue(f.cancel(mayInterruptIfRunning));
2428          g.complete(v1);
# Line 2953 | Line 2512 | public class CompletableFutureTest exten
2512          final CompletableFutureInc r = new CompletableFutureInc();
2513          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2514          final CompletableFuture<Integer> g = f.thenCompose(r);
2515 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2515 >        if (createIncomplete) {
2516 >            checkIncomplete(g);
2517 >            assertTrue(f.cancel(mayInterruptIfRunning));
2518 >        }
2519  
2520          checkCompletedWithWrappedCancellationException(g);
2521          checkCancelled(f);
2522      }}
2523  
2962    // asyncs
2963
2964    /**
2965     * thenAcceptAsync result completes normally after normal
2966     * completion of source
2967     */
2968    public void testThenAcceptAsync() {
2969        CompletableFuture<Integer> f = new CompletableFuture<>();
2970        IncAction r = new IncAction();
2971        CompletableFuture<Void> g = f.thenAcceptAsync(r);
2972        f.complete(one);
2973        checkCompletedNormally(g, null);
2974        assertEquals(r.value, (Integer) 2);
2975    }
2976
2977    /**
2978     * thenAcceptAsync result completes exceptionally after exceptional
2979     * completion of source
2980     */
2981    public void testThenAcceptAsync2() {
2982        CompletableFuture<Integer> f = new CompletableFuture<>();
2983        IncAction r = new IncAction();
2984        CompletableFuture<Void> g = f.thenAcceptAsync(r);
2985        f.completeExceptionally(new CFException());
2986        checkCompletedWithWrappedCFException(g);
2987    }
2988
2989    /**
2990     * thenAcceptAsync result completes exceptionally if action does
2991     */
2992    public void testThenAcceptAsync3() {
2993        CompletableFuture<Integer> f = new CompletableFuture<>();
2994        FailingConsumer r = new FailingConsumer();
2995        CompletableFuture<Void> g = f.thenAcceptAsync(r);
2996        f.complete(null);
2997        checkCompletedWithWrappedCFException(g);
2998    }
2999
3000    /**
3001     * thenAcceptAsync result completes exceptionally if source cancelled
3002     */
3003    public void testThenAcceptAsync4() {
3004        CompletableFuture<Integer> f = new CompletableFuture<>();
3005        IncAction r = new IncAction();
3006        CompletableFuture<Void> g = f.thenAcceptAsync(r);
3007        assertTrue(f.cancel(true));
3008        checkCompletedWithWrappedCancellationException(g);
3009    }
3010
3011    // async with explicit executors
3012
3013    /**
3014     * thenAcceptAsync result completes normally after normal
3015     * completion of source
3016     */
3017    public void testThenAcceptAsyncE() {
3018        CompletableFuture<Integer> f = new CompletableFuture<>();
3019        IncAction r = new IncAction();
3020        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3021        f.complete(one);
3022        checkCompletedNormally(g, null);
3023        assertEquals(r.value, (Integer) 2);
3024    }
3025
3026    /**
3027     * thenAcceptAsync result completes exceptionally after exceptional
3028     * completion of source
3029     */
3030    public void testThenAcceptAsync2E() {
3031        CompletableFuture<Integer> f = new CompletableFuture<>();
3032        IncAction r = new IncAction();
3033        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3034        f.completeExceptionally(new CFException());
3035        checkCompletedWithWrappedCFException(g);
3036    }
3037
3038    /**
3039     * thenAcceptAsync result completes exceptionally if action does
3040     */
3041    public void testThenAcceptAsync3E() {
3042        CompletableFuture<Integer> f = new CompletableFuture<>();
3043        FailingConsumer r = new FailingConsumer();
3044        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3045        f.complete(null);
3046        checkCompletedWithWrappedCFException(g);
3047    }
3048
3049    /**
3050     * thenAcceptAsync result completes exceptionally if source cancelled
3051     */
3052    public void testThenAcceptAsync4E() {
3053        CompletableFuture<Integer> f = new CompletableFuture<>();
3054        IncAction r = new IncAction();
3055        CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
3056        assertTrue(f.cancel(true));
3057        checkCompletedWithWrappedCancellationException(g);
3058    }
3059
2524      // other static methods
2525  
2526      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines