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.91 by jsr166, Tue Jun 17 20:34:18 2014 UTC vs.
Revision 1.92 by jsr166, Tue Jun 17 20:50:01 2014 UTC

# Line 1491 | Line 1491 | public class CompletableFutureTest exten
1491       */
1492      public void testThenAccept_normalCompletion() {
1493          for (ExecutionMode m : ExecutionMode.values())
1494        for (boolean createIncomplete : new boolean[] { true, false })
1494          for (Integer v1 : new Integer[] { 1, null })
1495      {
1496          final CompletableFuture<Integer> f = new CompletableFuture<>();
1497 <        final NoopConsumer r = new NoopConsumer(m);
1498 <        if (!createIncomplete) assertTrue(f.complete(v1));
1500 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1501 <        if (createIncomplete) {
1502 <            checkIncomplete(g);
1503 <            assertTrue(f.complete(v1));
1504 <        }
1497 >        final NoopConsumer[] rs = new NoopConsumer[4];
1498 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
1499  
1500 <        checkCompletedNormally(g, null);
1501 <        r.assertValue(v1);
1500 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1501 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1502 >        checkIncomplete(h0);
1503 >        checkIncomplete(h1);
1504 >        assertTrue(f.complete(v1));
1505 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1506 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1507 >
1508 >        checkCompletedNormally(h0, null);
1509 >        checkCompletedNormally(h1, null);
1510 >        checkCompletedNormally(h2, null);
1511 >        checkCompletedNormally(h3, null);
1512          checkCompletedNormally(f, v1);
1513 +        for (NoopConsumer r : rs) r.assertValue(v1);
1514      }}
1515  
1516      /**
# Line 1514 | Line 1519 | public class CompletableFutureTest exten
1519       */
1520      public void testThenAccept_exceptionalCompletion() {
1521          for (ExecutionMode m : ExecutionMode.values())
1517        for (boolean createIncomplete : new boolean[] { true, false })
1522      {
1523          final CFException ex = new CFException();
1524          final CompletableFuture<Integer> f = new CompletableFuture<>();
1525 <        final NoopConsumer r = new NoopConsumer(m);
1526 <        if (!createIncomplete) f.completeExceptionally(ex);
1523 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1524 <        if (createIncomplete) {
1525 <            checkIncomplete(g);
1526 <            f.completeExceptionally(ex);
1527 <        }
1525 >        final NoopConsumer[] rs = new NoopConsumer[4];
1526 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
1527  
1528 <        checkCompletedWithWrappedException(g, ex);
1528 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1529 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1530 >        assertTrue(f.completeExceptionally(ex));
1531 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1532 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1533 >
1534 >        checkCompletedWithWrappedException(h0, ex);
1535 >        checkCompletedWithWrappedException(h1, ex);
1536 >        checkCompletedWithWrappedException(h2, ex);
1537 >        checkCompletedWithWrappedException(h3, ex);
1538          checkCompletedExceptionally(f, ex);
1539 <        r.assertNotInvoked();
1539 >        for (NoopConsumer r : rs) r.assertNotInvoked();
1540      }}
1541  
1542      /**
# Line 1536 | Line 1544 | public class CompletableFutureTest exten
1544       */
1545      public void testThenAccept_sourceCancelled() {
1546          for (ExecutionMode m : ExecutionMode.values())
1539        for (boolean createIncomplete : new boolean[] { true, false })
1547          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1548      {
1549          final CompletableFuture<Integer> f = new CompletableFuture<>();
1550 <        final NoopConsumer r = new NoopConsumer(m);
1551 <        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1545 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1546 <        if (createIncomplete) {
1547 <            checkIncomplete(g);
1548 <            assertTrue(f.cancel(mayInterruptIfRunning));
1549 <        }
1550 >        final NoopConsumer[] rs = new NoopConsumer[4];
1551 >        for (int i = 0; i < rs.length; i++) rs[i] = new NoopConsumer(m);
1552  
1553 <        checkCompletedWithWrappedCancellationException(g);
1553 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1554 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1555 >        assertTrue(f.cancel(mayInterruptIfRunning));
1556 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1557 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1558 >
1559 >        checkCompletedWithWrappedCancellationException(h0);
1560 >        checkCompletedWithWrappedCancellationException(h1);
1561 >        checkCompletedWithWrappedCancellationException(h2);
1562 >        checkCompletedWithWrappedCancellationException(h3);
1563          checkCancelled(f);
1564 <        r.assertNotInvoked();
1564 >        for (NoopConsumer r : rs) r.assertNotInvoked();
1565      }}
1566  
1567      /**
# Line 1558 | Line 1569 | public class CompletableFutureTest exten
1569       */
1570      public void testThenAccept_actionFailed() {
1571          for (ExecutionMode m : ExecutionMode.values())
1561        for (boolean createIncomplete : new boolean[] { true, false })
1572          for (Integer v1 : new Integer[] { 1, null })
1573      {
1574          final CompletableFuture<Integer> f = new CompletableFuture<>();
1575 <        final FailingConsumer r = new FailingConsumer(m);
1576 <        if (!createIncomplete) f.complete(v1);
1567 <        final CompletableFuture<Void> g = m.thenAccept(f, r);
1568 <        if (createIncomplete) {
1569 <            checkIncomplete(g);
1570 <            f.complete(v1);
1571 <        }
1575 >        final FailingConsumer[] rs = new FailingConsumer[4];
1576 >        for (int i = 0; i < rs.length; i++) rs[i] = new FailingConsumer(m);
1577  
1578 <        checkCompletedWithWrappedCFException(g);
1578 >        final CompletableFuture<Void> h0 = m.thenAccept(f, rs[0]);
1579 >        final CompletableFuture<Void> h1 = m.acceptEither(f, f, rs[1]);
1580 >        assertTrue(f.complete(v1));
1581 >        final CompletableFuture<Void> h2 = m.thenAccept(f, rs[2]);
1582 >        final CompletableFuture<Void> h3 = m.acceptEither(f, f, rs[3]);
1583 >
1584 >        checkCompletedWithWrappedCFException(h0);
1585 >        checkCompletedWithWrappedCFException(h1);
1586 >        checkCompletedWithWrappedCFException(h2);
1587 >        checkCompletedWithWrappedCFException(h3);
1588          checkCompletedNormally(f, v1);
1589      }}
1590  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines