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.89 by jsr166, Mon Jun 16 21:34:49 2014 UTC vs.
Revision 1.95 by jsr166, Wed Jun 25 15:32:10 2014 UTC

# Line 57 | Line 57 | public class CompletableFutureTest exten
57      }
58  
59      <T> void checkCompletedNormally(CompletableFuture<T> f, T value) {
60 <        try {
61 <            assertEquals(value, f.get(LONG_DELAY_MS, MILLISECONDS));
62 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
60 >        checkTimedGet(f, value);
61 >
62          try {
63              assertEquals(value, f.join());
64          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 76 | Line 75 | public class CompletableFutureTest exten
75      }
76  
77      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
78 +        long startTime = System.nanoTime();
79 +        long timeoutMillis = LONG_DELAY_MS;
80          try {
81 <            f.get(LONG_DELAY_MS, MILLISECONDS);
81 >            f.get(timeoutMillis, MILLISECONDS);
82              shouldThrow();
83          } catch (ExecutionException success) {
84              assertTrue(success.getCause() instanceof CFException);
85          } catch (Throwable fail) { threadUnexpectedException(fail); }
86 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
87 +
88          try {
89              f.join();
90              shouldThrow();
# Line 107 | Line 110 | public class CompletableFutureTest exten
110  
111      <U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f,
112                                                        Throwable ex) {
113 +        long startTime = System.nanoTime();
114 +        long timeoutMillis = LONG_DELAY_MS;
115          try {
116 <            f.get(LONG_DELAY_MS, MILLISECONDS);
116 >            f.get(timeoutMillis, MILLISECONDS);
117              shouldThrow();
118          } catch (ExecutionException success) {
119              assertSame(ex, success.getCause());
120          } catch (Throwable fail) { threadUnexpectedException(fail); }
121 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
122 +
123          try {
124              f.join();
125              shouldThrow();
# Line 158 | Line 165 | public class CompletableFutureTest exten
165      }
166  
167      void checkCancelled(CompletableFuture<?> f) {
168 +        long startTime = System.nanoTime();
169 +        long timeoutMillis = LONG_DELAY_MS;
170          try {
171 <            f.get(LONG_DELAY_MS, MILLISECONDS);
171 >            f.get(timeoutMillis, MILLISECONDS);
172              shouldThrow();
173          } catch (CancellationException success) {
174          } catch (Throwable fail) { threadUnexpectedException(fail); }
175 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
176 +
177          try {
178              f.join();
179              shouldThrow();
# Line 183 | Line 194 | public class CompletableFutureTest exten
194      }
195  
196      void checkCompletedWithWrappedCancellationException(CompletableFuture<?> f) {
197 +        long startTime = System.nanoTime();
198 +        long timeoutMillis = LONG_DELAY_MS;
199          try {
200 <            f.get(LONG_DELAY_MS, MILLISECONDS);
200 >            f.get(timeoutMillis, MILLISECONDS);
201              shouldThrow();
202          } catch (ExecutionException success) {
203              assertTrue(success.getCause() instanceof CancellationException);
204          } catch (Throwable fail) { threadUnexpectedException(fail); }
205 +        assertTrue(millisElapsedSince(startTime) < timeoutMillis/2);
206 +
207          try {
208              f.join();
209              shouldThrow();
# Line 574 | Line 589 | public class CompletableFutureTest exten
589       * execution modes without copy/pasting all the test methods.
590       */
591      enum ExecutionMode {
592 <        DEFAULT {
592 >        SYNC {
593              public void checkExecutionMode() {
594                  assertFalse(ThreadExecutor.startedCurrentThread());
595                  assertNull(ForkJoinTask.getPool());
# Line 875 | Line 890 | public class CompletableFutureTest exten
890          if (!createIncomplete) f.completeExceptionally(ex);
891          final CompletableFuture<Integer> g = f.exceptionally
892              ((Throwable t) -> {
893 <                ExecutionMode.DEFAULT.checkExecutionMode();
893 >                ExecutionMode.SYNC.checkExecutionMode();
894                  threadAssertSame(t, ex);
895                  a.getAndIncrement();
896                  return v1;
# Line 897 | Line 912 | public class CompletableFutureTest exten
912          if (!createIncomplete) f.completeExceptionally(ex1);
913          final CompletableFuture<Integer> g = f.exceptionally
914              ((Throwable t) -> {
915 <                ExecutionMode.DEFAULT.checkExecutionMode();
915 >                ExecutionMode.SYNC.checkExecutionMode();
916                  threadAssertSame(t, ex1);
917                  a.getAndIncrement();
918                  throw ex2;
# Line 1264 | Line 1279 | public class CompletableFutureTest exten
1279       */
1280      public void testThenRun_normalCompletion() {
1281          for (ExecutionMode m : ExecutionMode.values())
1267        for (boolean createIncomplete : new boolean[] { true, false })
1282          for (Integer v1 : new Integer[] { 1, null })
1283      {
1284          final CompletableFuture<Integer> f = new CompletableFuture<>();
1285 <        final Noop r = new Noop(m);
1286 <        if (!createIncomplete) assertTrue(f.complete(v1));
1273 <        final CompletableFuture<Void> g = m.thenRun(f, r);
1274 <        if (createIncomplete) {
1275 <            checkIncomplete(g);
1276 <            assertTrue(f.complete(v1));
1277 <        }
1285 >        final Noop[] rs = new Noop[6];
1286 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
1287  
1288 <        checkCompletedNormally(g, null);
1288 >        final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]);
1289 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]);
1290 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]);
1291 >        checkIncomplete(h0);
1292 >        checkIncomplete(h1);
1293 >        checkIncomplete(h2);
1294 >        assertTrue(f.complete(v1));
1295 >        final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]);
1296 >        final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]);
1297 >        final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]);
1298 >
1299 >        checkCompletedNormally(h0, null);
1300 >        checkCompletedNormally(h1, null);
1301 >        checkCompletedNormally(h2, null);
1302 >        checkCompletedNormally(h3, null);
1303 >        checkCompletedNormally(h4, null);
1304 >        checkCompletedNormally(h5, null);
1305          checkCompletedNormally(f, v1);
1306 <        r.assertInvoked();
1306 >        for (Noop r : rs) r.assertInvoked();
1307      }}
1308  
1309      /**
# Line 1287 | Line 1312 | public class CompletableFutureTest exten
1312       */
1313      public void testThenRun_exceptionalCompletion() {
1314          for (ExecutionMode m : ExecutionMode.values())
1290        for (boolean createIncomplete : new boolean[] { true, false })
1315      {
1316          final CFException ex = new CFException();
1317          final CompletableFuture<Integer> f = new CompletableFuture<>();
1318 <        final Noop r = new Noop(m);
1319 <        if (!createIncomplete) f.completeExceptionally(ex);
1296 <        final CompletableFuture<Void> g = m.thenRun(f, r);
1297 <        if (createIncomplete) {
1298 <            checkIncomplete(g);
1299 <            f.completeExceptionally(ex);
1300 <        }
1318 >        final Noop[] rs = new Noop[6];
1319 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
1320  
1321 <        checkCompletedWithWrappedException(g, ex);
1321 >        final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]);
1322 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]);
1323 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]);
1324 >        checkIncomplete(h0);
1325 >        checkIncomplete(h1);
1326 >        checkIncomplete(h2);
1327 >        assertTrue(f.completeExceptionally(ex));
1328 >        final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]);
1329 >        final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]);
1330 >        final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]);
1331 >
1332 >        checkCompletedWithWrappedException(h0, ex);
1333 >        checkCompletedWithWrappedException(h1, ex);
1334 >        checkCompletedWithWrappedException(h2, ex);
1335 >        checkCompletedWithWrappedException(h3, ex);
1336 >        checkCompletedWithWrappedException(h4, ex);
1337 >        checkCompletedWithWrappedException(h5, ex);
1338          checkCompletedExceptionally(f, ex);
1339 <        r.assertNotInvoked();
1339 >        for (Noop r : rs) r.assertNotInvoked();
1340      }}
1341  
1342      /**
# Line 1309 | Line 1344 | public class CompletableFutureTest exten
1344       */
1345      public void testThenRun_sourceCancelled() {
1346          for (ExecutionMode m : ExecutionMode.values())
1312        for (boolean createIncomplete : new boolean[] { true, false })
1347          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1348      {
1349          final CompletableFuture<Integer> f = new CompletableFuture<>();
1350 <        final Noop r = new Noop(m);
1351 <        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1318 <        final CompletableFuture<Void> g = m.thenRun(f, r);
1319 <        if (createIncomplete) {
1320 <            checkIncomplete(g);
1321 <            assertTrue(f.cancel(mayInterruptIfRunning));
1322 <        }
1350 >        final Noop[] rs = new Noop[6];
1351 >        for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
1352  
1353 <        checkCompletedWithWrappedCancellationException(g);
1353 >        final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]);
1354 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]);
1355 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]);
1356 >        checkIncomplete(h0);
1357 >        checkIncomplete(h1);
1358 >        checkIncomplete(h2);
1359 >        assertTrue(f.cancel(mayInterruptIfRunning));
1360 >        final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]);
1361 >        final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]);
1362 >        final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]);
1363 >
1364 >        checkCompletedWithWrappedCancellationException(h0);
1365 >        checkCompletedWithWrappedCancellationException(h1);
1366 >        checkCompletedWithWrappedCancellationException(h2);
1367 >        checkCompletedWithWrappedCancellationException(h3);
1368 >        checkCompletedWithWrappedCancellationException(h4);
1369 >        checkCompletedWithWrappedCancellationException(h5);
1370          checkCancelled(f);
1371 <        r.assertNotInvoked();
1371 >        for (Noop r : rs) r.assertNotInvoked();
1372      }}
1373  
1374      /**
# Line 1331 | Line 1376 | public class CompletableFutureTest exten
1376       */
1377      public void testThenRun_actionFailed() {
1378          for (ExecutionMode m : ExecutionMode.values())
1334        for (boolean createIncomplete : new boolean[] { true, false })
1379          for (Integer v1 : new Integer[] { 1, null })
1380      {
1381          final CompletableFuture<Integer> f = new CompletableFuture<>();
1382 <        final FailingRunnable r = new FailingRunnable(m);
1383 <        if (!createIncomplete) assertTrue(f.complete(v1));
1340 <        final CompletableFuture<Void> g = m.thenRun(f, r);
1341 <        if (createIncomplete) {
1342 <            checkIncomplete(g);
1343 <            assertTrue(f.complete(v1));
1344 <        }
1382 >        final FailingRunnable[] rs = new FailingRunnable[6];
1383 >        for (int i = 0; i < rs.length; i++) rs[i] = new FailingRunnable(m);
1384  
1385 <        checkCompletedWithWrappedCFException(g);
1385 >        final CompletableFuture<Void> h0 = m.thenRun(f, rs[0]);
1386 >        final CompletableFuture<Void> h1 = m.runAfterBoth(f, f, rs[1]);
1387 >        final CompletableFuture<Void> h2 = m.runAfterEither(f, f, rs[2]);
1388 >        assertTrue(f.complete(v1));
1389 >        final CompletableFuture<Void> h3 = m.thenRun(f, rs[3]);
1390 >        final CompletableFuture<Void> h4 = m.runAfterBoth(f, f, rs[4]);
1391 >        final CompletableFuture<Void> h5 = m.runAfterEither(f, f, rs[5]);
1392 >
1393 >        checkCompletedWithWrappedCFException(h0);
1394 >        checkCompletedWithWrappedCFException(h1);
1395 >        checkCompletedWithWrappedCFException(h2);
1396 >        checkCompletedWithWrappedCFException(h3);
1397 >        checkCompletedWithWrappedCFException(h4);
1398 >        checkCompletedWithWrappedCFException(h5);
1399          checkCompletedNormally(f, v1);
1400      }}
1401  
# Line 1352 | Line 1404 | public class CompletableFutureTest exten
1404       */
1405      public void testThenApply_normalCompletion() {
1406          for (ExecutionMode m : ExecutionMode.values())
1355        for (boolean createIncomplete : new boolean[] { true, false })
1407          for (Integer v1 : new Integer[] { 1, null })
1408      {
1409          final CompletableFuture<Integer> f = new CompletableFuture<>();
1410 <        final IncFunction r = new IncFunction(m);
1411 <        if (!createIncomplete) assertTrue(f.complete(v1));
1361 <        final CompletableFuture<Integer> g = m.thenApply(f, r);
1362 <        if (createIncomplete) {
1363 <            checkIncomplete(g);
1364 <            assertTrue(f.complete(v1));
1365 <        }
1410 >        final IncFunction[] rs = new IncFunction[4];
1411 >        for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m);
1412  
1413 <        checkCompletedNormally(g, inc(v1));
1413 >        final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]);
1414 >        final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]);
1415 >        checkIncomplete(h0);
1416 >        checkIncomplete(h1);
1417 >        assertTrue(f.complete(v1));
1418 >        final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]);
1419 >        final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]);
1420 >
1421 >        checkCompletedNormally(h0, inc(v1));
1422 >        checkCompletedNormally(h1, inc(v1));
1423 >        checkCompletedNormally(h2, inc(v1));
1424 >        checkCompletedNormally(h3, inc(v1));
1425          checkCompletedNormally(f, v1);
1426 <        r.assertValue(inc(v1));
1426 >        for (IncFunction r : rs) r.assertValue(inc(v1));
1427      }}
1428  
1429      /**
# Line 1375 | Line 1432 | public class CompletableFutureTest exten
1432       */
1433      public void testThenApply_exceptionalCompletion() {
1434          for (ExecutionMode m : ExecutionMode.values())
1378        for (boolean createIncomplete : new boolean[] { true, false })
1435      {
1436          final CFException ex = new CFException();
1437          final CompletableFuture<Integer> f = new CompletableFuture<>();
1438 <        final IncFunction r = new IncFunction(m);
1439 <        if (!createIncomplete) f.completeExceptionally(ex);
1384 <        final CompletableFuture<Integer> g = m.thenApply(f, r);
1385 <        if (createIncomplete) {
1386 <            checkIncomplete(g);
1387 <            f.completeExceptionally(ex);
1388 <        }
1438 >        final IncFunction[] rs = new IncFunction[4];
1439 >        for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m);
1440  
1441 <        checkCompletedWithWrappedException(g, ex);
1441 >        final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]);
1442 >        final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]);
1443 >        assertTrue(f.completeExceptionally(ex));
1444 >        final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]);
1445 >        final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]);
1446 >
1447 >        checkCompletedWithWrappedException(h0, ex);
1448 >        checkCompletedWithWrappedException(h1, ex);
1449 >        checkCompletedWithWrappedException(h2, ex);
1450 >        checkCompletedWithWrappedException(h3, ex);
1451          checkCompletedExceptionally(f, ex);
1452 <        r.assertNotInvoked();
1452 >        for (IncFunction r : rs) r.assertNotInvoked();
1453      }}
1454  
1455      /**
# Line 1397 | Line 1457 | public class CompletableFutureTest exten
1457       */
1458      public void testThenApply_sourceCancelled() {
1459          for (ExecutionMode m : ExecutionMode.values())
1400        for (boolean createIncomplete : new boolean[] { true, false })
1460          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1461      {
1462          final CompletableFuture<Integer> f = new CompletableFuture<>();
1463 <        final IncFunction r = new IncFunction(m);
1464 <        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1406 <        final CompletableFuture<Integer> g = m.thenApply(f, r);
1407 <        if (createIncomplete) {
1408 <            checkIncomplete(g);
1409 <            assertTrue(f.cancel(mayInterruptIfRunning));
1410 <        }
1463 >        final IncFunction[] rs = new IncFunction[4];
1464 >        for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m);
1465  
1466 <        checkCompletedWithWrappedCancellationException(g);
1466 >        final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]);
1467 >        final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]);
1468 >        assertTrue(f.cancel(mayInterruptIfRunning));
1469 >        final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]);
1470 >        final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]);
1471 >
1472 >        checkCompletedWithWrappedCancellationException(h0);
1473 >        checkCompletedWithWrappedCancellationException(h1);
1474 >        checkCompletedWithWrappedCancellationException(h2);
1475 >        checkCompletedWithWrappedCancellationException(h3);
1476          checkCancelled(f);
1477 <        r.assertNotInvoked();
1477 >        for (IncFunction r : rs) r.assertNotInvoked();
1478      }}
1479  
1480      /**
# Line 1419 | Line 1482 | public class CompletableFutureTest exten
1482       */
1483      public void testThenApply_actionFailed() {
1484          for (ExecutionMode m : ExecutionMode.values())
1422        for (boolean createIncomplete : new boolean[] { true, false })
1485          for (Integer v1 : new Integer[] { 1, null })
1486      {
1487          final CompletableFuture<Integer> f = new CompletableFuture<>();
1488 <        final FailingFunction r = new FailingFunction(m);
1489 <        if (!createIncomplete) assertTrue(f.complete(v1));
1428 <        final CompletableFuture<Integer> g = m.thenApply(f, r);
1429 <        if (createIncomplete) {
1430 <            checkIncomplete(g);
1431 <            assertTrue(f.complete(v1));
1432 <        }
1488 >        final FailingFunction[] rs = new FailingFunction[4];
1489 >        for (int i = 0; i < rs.length; i++) rs[i] = new FailingFunction(m);
1490  
1491 <        checkCompletedWithWrappedCFException(g);
1491 >        final CompletableFuture<Integer> h0 = m.thenApply(f, rs[0]);
1492 >        final CompletableFuture<Integer> h1 = m.applyToEither(f, f, rs[1]);
1493 >        assertTrue(f.complete(v1));
1494 >        final CompletableFuture<Integer> h2 = m.thenApply(f, rs[2]);
1495 >        final CompletableFuture<Integer> h3 = m.applyToEither(f, f, rs[3]);
1496 >
1497 >        checkCompletedWithWrappedCFException(h0);
1498 >        checkCompletedWithWrappedCFException(h1);
1499 >        checkCompletedWithWrappedCFException(h2);
1500 >        checkCompletedWithWrappedCFException(h3);
1501          checkCompletedNormally(f, v1);
1502      }}
1503  
# Line 1440 | Line 1506 | public class CompletableFutureTest exten
1506       */
1507      public void testThenAccept_normalCompletion() {
1508          for (ExecutionMode m : ExecutionMode.values())
1443        for (boolean createIncomplete : new boolean[] { true, false })
1509          for (Integer v1 : new Integer[] { 1, null })
1510      {
1511          final CompletableFuture<Integer> f = new CompletableFuture<>();
1512 <        final NoopConsumer r = new NoopConsumer(m);
1513 <        if (!createIncomplete) assertTrue(f.complete(v1));
1449 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1450 <        if (createIncomplete) {
1451 <            checkIncomplete(g);
1452 <            assertTrue(f.complete(v1));
1453 <        }
1512 >        final NoopConsumer[] rs = new NoopConsumer[4];
1513 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
1514  
1515 <        checkCompletedNormally(g, null);
1516 <        r.assertValue(v1);
1515 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1516 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1517 >        checkIncomplete(h0);
1518 >        checkIncomplete(h1);
1519 >        assertTrue(f.complete(v1));
1520 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1521 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1522 >
1523 >        checkCompletedNormally(h0, null);
1524 >        checkCompletedNormally(h1, null);
1525 >        checkCompletedNormally(h2, null);
1526 >        checkCompletedNormally(h3, null);
1527          checkCompletedNormally(f, v1);
1528 +        for (NoopConsumer r : rs) r.assertValue(v1);
1529      }}
1530  
1531      /**
# Line 1463 | Line 1534 | public class CompletableFutureTest exten
1534       */
1535      public void testThenAccept_exceptionalCompletion() {
1536          for (ExecutionMode m : ExecutionMode.values())
1466        for (boolean createIncomplete : new boolean[] { true, false })
1537      {
1538          final CFException ex = new CFException();
1539          final CompletableFuture<Integer> f = new CompletableFuture<>();
1540 <        final NoopConsumer r = new NoopConsumer(m);
1541 <        if (!createIncomplete) f.completeExceptionally(ex);
1472 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1473 <        if (createIncomplete) {
1474 <            checkIncomplete(g);
1475 <            f.completeExceptionally(ex);
1476 <        }
1540 >        final NoopConsumer[] rs = new NoopConsumer[4];
1541 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
1542  
1543 <        checkCompletedWithWrappedException(g, ex);
1543 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1544 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1545 >        assertTrue(f.completeExceptionally(ex));
1546 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1547 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1548 >
1549 >        checkCompletedWithWrappedException(h0, ex);
1550 >        checkCompletedWithWrappedException(h1, ex);
1551 >        checkCompletedWithWrappedException(h2, ex);
1552 >        checkCompletedWithWrappedException(h3, ex);
1553          checkCompletedExceptionally(f, ex);
1554 <        r.assertNotInvoked();
1554 >        for (NoopConsumer r : rs) r.assertNotInvoked();
1555      }}
1556  
1557      /**
# Line 1485 | Line 1559 | public class CompletableFutureTest exten
1559       */
1560      public void testThenAccept_sourceCancelled() {
1561          for (ExecutionMode m : ExecutionMode.values())
1488        for (boolean createIncomplete : new boolean[] { true, false })
1562          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1563      {
1564          final CompletableFuture<Integer> f = new CompletableFuture<>();
1565 <        final NoopConsumer r = new NoopConsumer(m);
1566 <        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1494 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1495 <        if (createIncomplete) {
1496 <            checkIncomplete(g);
1497 <            assertTrue(f.cancel(mayInterruptIfRunning));
1498 <        }
1565 >        final NoopConsumer[] rs = new NoopConsumer[4];
1566 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
1567  
1568 <        checkCompletedWithWrappedCancellationException(g);
1568 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1569 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1570 >        assertTrue(f.cancel(mayInterruptIfRunning));
1571 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1572 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1573 >
1574 >        checkCompletedWithWrappedCancellationException(h0);
1575 >        checkCompletedWithWrappedCancellationException(h1);
1576 >        checkCompletedWithWrappedCancellationException(h2);
1577 >        checkCompletedWithWrappedCancellationException(h3);
1578          checkCancelled(f);
1579 <        r.assertNotInvoked();
1579 >        for (NoopConsumer r : rs) r.assertNotInvoked();
1580      }}
1581  
1582      /**
# Line 1507 | Line 1584 | public class CompletableFutureTest exten
1584       */
1585      public void testThenAccept_actionFailed() {
1586          for (ExecutionMode m : ExecutionMode.values())
1510        for (boolean createIncomplete : new boolean[] { true, false })
1587          for (Integer v1 : new Integer[] { 1, null })
1588      {
1589          final CompletableFuture<Integer> f = new CompletableFuture<>();
1590 <        final FailingConsumer r = new FailingConsumer(m);
1591 <        if (!createIncomplete) f.complete(v1);
1516 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1517 <        if (createIncomplete) {
1518 <            checkIncomplete(g);
1519 <            f.complete(v1);
1520 <        }
1590 >        final FailingConsumer[] rs = new FailingConsumer[4];
1591 >        for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m);
1592  
1593 <        checkCompletedWithWrappedCFException(g);
1593 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1594 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1595 >        assertTrue(f.complete(v1));
1596 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1597 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1598 >
1599 >        checkCompletedWithWrappedCFException(h0);
1600 >        checkCompletedWithWrappedCFException(h1);
1601 >        checkCompletedWithWrappedCFException(h2);
1602 >        checkCompletedWithWrappedCFException(h3);
1603          checkCompletedNormally(f, v1);
1604      }}
1605  
# Line 1535 | Line 1615 | public class CompletableFutureTest exten
1615      {
1616          final CompletableFuture<Integer> f = new CompletableFuture<>();
1617          final CompletableFuture<Integer> g = new CompletableFuture<>();
1618 <        final SubtractFunction r1 = new SubtractFunction(m);
1619 <        final SubtractFunction r2 = new SubtractFunction(m);
1540 <        final SubtractFunction r3 = new SubtractFunction(m);
1618 >        final SubtractFunction[] rs = new SubtractFunction[6];
1619 >        for (int i = 0; i < rs.length; i++) rs[i] = new SubtractFunction(m);
1620  
1621          final CompletableFuture<Integer> fst =  fFirst ? f : g;
1622          final CompletableFuture<Integer> snd = !fFirst ? f : g;
1623          final Integer w1 =  fFirst ? v1 : v2;
1624          final Integer w2 = !fFirst ? v1 : v2;
1625  
1626 <        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1626 >        final CompletableFuture<Integer> h0 = m.thenCombine(f, g, rs[0]);
1627 >        final CompletableFuture<Integer> h1 = m.thenCombine(fst, fst, rs[1]);
1628          assertTrue(fst.complete(w1));
1629 <        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1630 <        checkIncomplete(h1);
1631 <        checkIncomplete(h2);
1632 <        r1.assertNotInvoked();
1633 <        r2.assertNotInvoked();
1629 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, rs[2]);
1630 >        final CompletableFuture<Integer> h3 = m.thenCombine(fst, fst, rs[3]);
1631 >        checkIncomplete(h0); rs[0].assertNotInvoked();
1632 >        checkIncomplete(h2); rs[2].assertNotInvoked();
1633 >        checkCompletedNormally(h1, subtract(w1, w1));
1634 >        checkCompletedNormally(h3, subtract(w1, w1));
1635 >        rs[1].assertValue(subtract(w1, w1));
1636 >        rs[3].assertValue(subtract(w1, w1));
1637          assertTrue(snd.complete(w2));
1638 <        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1638 >        final CompletableFuture<Integer> h4 = m.thenCombine(f, g, rs[4]);
1639  
1640 <        checkCompletedNormally(h1, subtract(v1, v2));
1640 >        checkCompletedNormally(h0, subtract(v1, v2));
1641          checkCompletedNormally(h2, subtract(v1, v2));
1642 <        checkCompletedNormally(h3, subtract(v1, v2));
1643 <        r1.assertValue(subtract(v1, v2));
1644 <        r2.assertValue(subtract(v1, v2));
1645 <        r3.assertValue(subtract(v1, v2));
1642 >        checkCompletedNormally(h4, subtract(v1, v2));
1643 >        rs[0].assertValue(subtract(v1, v2));
1644 >        rs[2].assertValue(subtract(v1, v2));
1645 >        rs[4].assertValue(subtract(v1, v2));
1646 >
1647          checkCompletedNormally(f, v1);
1648          checkCompletedNormally(g, v2);
1649      }}
# Line 3079 | Line 3163 | public class CompletableFutureTest exten
3163          Runnable[] throwingActions = {
3164              () -> CompletableFuture.supplyAsync(null),
3165              () -> CompletableFuture.supplyAsync(null, exec),
3166 <            () -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.DEFAULT, 42), null),
3166 >            () -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.SYNC, 42), null),
3167  
3168              () -> CompletableFuture.runAsync(null),
3169              () -> CompletableFuture.runAsync(null, exec),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines