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.75 by jsr166, Sat Jun 7 21:14:42 2014 UTC vs.
Revision 1.79 by jsr166, Mon Jun 16 17:08:15 2014 UTC

# Line 227 | Line 227 | public class CompletableFutureTest exten
227       * isCancelled, join, get, and getNow
228       */
229      public void testComplete() {
230 +        for (Integer v1 : new Integer[] { 1, null })
231 +    {
232          CompletableFuture<Integer> f = new CompletableFuture<>();
233          checkIncomplete(f);
234 <        f.complete(one);
235 <        checkCompletedNormally(f, one);
236 <    }
234 >        assertTrue(f.complete(v1));
235 >        assertFalse(f.complete(v1));
236 >        checkCompletedNormally(f, v1);
237 >    }}
238  
239      /**
240       * completeExceptionally completes exceptionally, as indicated by
# Line 250 | Line 253 | public class CompletableFutureTest exten
253       * methods isDone, isCancelled, join, get, and getNow
254       */
255      public void testCancel() {
256 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
257 +    {
258          CompletableFuture<Integer> f = new CompletableFuture<>();
259          checkIncomplete(f);
260          assertTrue(f.cancel(true));
261 +        assertTrue(f.cancel(true));
262          checkCancelled(f);
263 <    }
263 >    }}
264  
265      /**
266       * obtrudeValue forces completion with given value
# Line 262 | Line 268 | public class CompletableFutureTest exten
268      public void testObtrudeValue() {
269          CompletableFuture<Integer> f = new CompletableFuture<>();
270          checkIncomplete(f);
271 <        f.complete(one);
271 >        assertTrue(f.complete(one));
272          checkCompletedNormally(f, one);
273          f.obtrudeValue(three);
274          checkCompletedNormally(f, three);
# Line 289 | Line 295 | public class CompletableFutureTest exten
295          CompletableFuture<Integer> f;
296  
297          f = new CompletableFuture<>();
298 <        f.complete(v1);
298 >        assertTrue(f.complete(v1));
299          for (int i = 0; i < 2; i++) {
300              f.obtrudeException(ex = new CFException());
301              checkCompletedExceptionally(f, ex);
# Line 309 | Line 315 | public class CompletableFutureTest exten
315          checkCompletedExceptionally(f, ex);
316          f.completeExceptionally(new CFException());
317          checkCompletedExceptionally(f, ex);
318 <        f.complete(v1);
318 >        assertFalse(f.complete(v1));
319          checkCompletedExceptionally(f, ex);
320      }}
321  
# Line 317 | Line 323 | public class CompletableFutureTest exten
323       * getNumberOfDependents returns number of dependent tasks
324       */
325      public void testGetNumberOfDependents() {
326 +        for (ExecutionMode m : ExecutionMode.values())
327 +        for (Integer v1 : new Integer[] { 1, null })
328 +    {
329          CompletableFuture<Integer> f = new CompletableFuture<>();
330          assertEquals(0, f.getNumberOfDependents());
331 <        CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT));
331 >        final CompletableFuture<Void> g = m.thenRun(f, new Noop(m));
332          assertEquals(1, f.getNumberOfDependents());
333          assertEquals(0, g.getNumberOfDependents());
334 <        CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT));
334 >        final CompletableFuture<Void> h = m.thenRun(f, new Noop(m));
335          assertEquals(2, f.getNumberOfDependents());
336 <        f.complete(1);
336 >        assertEquals(0, h.getNumberOfDependents());
337 >        assertTrue(f.complete(v1));
338          checkCompletedNormally(g, null);
339 +        checkCompletedNormally(h, null);
340          assertEquals(0, f.getNumberOfDependents());
341          assertEquals(0, g.getNumberOfDependents());
342 <    }
342 >        assertEquals(0, h.getNumberOfDependents());
343 >    }}
344  
345      /**
346       * toString indicates current completion state
# Line 339 | Line 351 | public class CompletableFutureTest exten
351          f = new CompletableFuture<String>();
352          assertTrue(f.toString().contains("[Not completed]"));
353  
354 <        f.complete("foo");
354 >        assertTrue(f.complete("foo"));
355          assertTrue(f.toString().contains("[Completed normally]"));
356  
357          f = new CompletableFuture<String>();
358 <        f.completeExceptionally(new IndexOutOfBoundsException());
347 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
348 <
349 <        f = new CompletableFuture<String>();
350 <        f.cancel(true);
358 >        assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
359          assertTrue(f.toString().contains("[Completed exceptionally]"));
360  
361 <        f = new CompletableFuture<String>();
362 <        f.cancel(false);
363 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
361 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
362 >            f = new CompletableFuture<String>();
363 >            assertTrue(f.cancel(mayInterruptIfRunning));
364 >            assertTrue(f.toString().contains("[Completed exceptionally]"));
365 >        }
366      }
367  
368      /**
# Line 529 | Line 539 | public class CompletableFutureTest exten
539              invoked();
540              value = x;
541              CompletableFuture<Integer> f = new CompletableFuture<>();
542 <            f.complete(inc(x));
542 >            assertTrue(f.complete(inc(x)));
543              return f;
544          }
545      }
# Line 837 | Line 847 | public class CompletableFutureTest exten
847      {
848          final AtomicInteger a = new AtomicInteger(0);
849          final CompletableFuture<Integer> f = new CompletableFuture<>();
850 <        if (!createIncomplete) f.complete(v1);
850 >        if (!createIncomplete) assertTrue(f.complete(v1));
851          final CompletableFuture<Integer> g = f.exceptionally
852              ((Throwable t) -> {
853                  // Should not be called
854                  a.getAndIncrement();
855                  throw new AssertionError();
856              });
857 <        if (createIncomplete) f.complete(v1);
857 >        if (createIncomplete) assertTrue(f.complete(v1));
858  
859          checkCompletedNormally(g, v1);
860          checkCompletedNormally(f, v1);
# Line 909 | Line 919 | public class CompletableFutureTest exten
919      {
920          final AtomicInteger a = new AtomicInteger(0);
921          final CompletableFuture<Integer> f = new CompletableFuture<>();
922 <        if (!createIncomplete) f.complete(v1);
922 >        if (!createIncomplete) assertTrue(f.complete(v1));
923          final CompletableFuture<Integer> g = m.whenComplete
924              (f,
925               (Integer x, Throwable t) -> {
# Line 918 | Line 928 | public class CompletableFutureTest exten
928                  threadAssertNull(t);
929                  a.getAndIncrement();
930              });
931 <        if (createIncomplete) f.complete(v1);
931 >        if (createIncomplete) assertTrue(f.complete(v1));
932  
933          checkCompletedNormally(g, v1);
934          checkCompletedNormally(f, v1);
# Line 992 | Line 1002 | public class CompletableFutureTest exten
1002          final AtomicInteger a = new AtomicInteger(0);
1003          final CFException ex = new CFException();
1004          final CompletableFuture<Integer> f = new CompletableFuture<>();
1005 <        if (!createIncomplete) f.complete(v1);
1005 >        if (!createIncomplete) assertTrue(f.complete(v1));
1006          final CompletableFuture<Integer> g = m.whenComplete
1007              (f,
1008               (Integer x, Throwable t) -> {
# Line 1002 | Line 1012 | public class CompletableFutureTest exten
1012                  a.getAndIncrement();
1013                  throw ex;
1014              });
1015 <        if (createIncomplete) f.complete(v1);
1015 >        if (createIncomplete) assertTrue(f.complete(v1));
1016  
1017          checkCompletedWithWrappedException(g, ex);
1018          checkCompletedNormally(f, v1);
# Line 1052 | Line 1062 | public class CompletableFutureTest exten
1062      {
1063          final CompletableFuture<Integer> f = new CompletableFuture<>();
1064          final AtomicInteger a = new AtomicInteger(0);
1065 <        if (!createIncomplete) f.complete(v1);
1065 >        if (!createIncomplete) assertTrue(f.complete(v1));
1066          final CompletableFuture<Integer> g = m.handle
1067              (f,
1068               (Integer x, Throwable t) -> {
# Line 1062 | Line 1072 | public class CompletableFutureTest exten
1072                  a.getAndIncrement();
1073                  return inc(v1);
1074              });
1075 <        if (createIncomplete) f.complete(v1);
1075 >        if (createIncomplete) assertTrue(f.complete(v1));
1076  
1077          checkCompletedNormally(g, inc(v1));
1078          checkCompletedNormally(f, v1);
# Line 1163 | Line 1173 | public class CompletableFutureTest exten
1173          final CompletableFuture<Integer> f = new CompletableFuture<>();
1174          final AtomicInteger a = new AtomicInteger(0);
1175          final CFException ex = new CFException();
1176 <        if (!createIncomplete) f.complete(v1);
1176 >        if (!createIncomplete) assertTrue(f.complete(v1));
1177          final CompletableFuture<Integer> g = m.handle
1178              (f,
1179               (Integer x, Throwable t) -> {
# Line 1173 | Line 1183 | public class CompletableFutureTest exten
1183                  a.getAndIncrement();
1184                  throw ex;
1185              });
1186 <        if (createIncomplete) f.complete(v1);
1186 >        if (createIncomplete) assertTrue(f.complete(v1));
1187  
1188          checkCompletedWithWrappedException(g, ex);
1189          checkCompletedNormally(f, v1);
# Line 1259 | Line 1269 | public class CompletableFutureTest exten
1269      {
1270          final CompletableFuture<Integer> f = new CompletableFuture<>();
1271          final Noop r = new Noop(m);
1272 <        if (!createIncomplete) f.complete(v1);
1272 >        if (!createIncomplete) assertTrue(f.complete(v1));
1273          final CompletableFuture<Void> g = m.thenRun(f, r);
1274          if (createIncomplete) {
1275              checkIncomplete(g);
1276 <            f.complete(v1);
1276 >            assertTrue(f.complete(v1));
1277          }
1278  
1279          checkCompletedNormally(g, null);
# Line 1326 | Line 1336 | public class CompletableFutureTest exten
1336      {
1337          final CompletableFuture<Integer> f = new CompletableFuture<>();
1338          final FailingRunnable r = new FailingRunnable(m);
1339 <        if (!createIncomplete) f.complete(v1);
1339 >        if (!createIncomplete) assertTrue(f.complete(v1));
1340          final CompletableFuture<Void> g = m.thenRun(f, r);
1341          if (createIncomplete) {
1342              checkIncomplete(g);
1343 <            f.complete(v1);
1343 >            assertTrue(f.complete(v1));
1344          }
1345  
1346          checkCompletedWithWrappedCFException(g);
# Line 1347 | Line 1357 | public class CompletableFutureTest exten
1357      {
1358          final CompletableFuture<Integer> f = new CompletableFuture<>();
1359          final IncFunction r = new IncFunction(m);
1360 <        if (!createIncomplete) f.complete(v1);
1360 >        if (!createIncomplete) assertTrue(f.complete(v1));
1361          final CompletableFuture<Integer> g = m.thenApply(f, r);
1362          if (createIncomplete) {
1363              checkIncomplete(g);
1364 <            f.complete(v1);
1364 >            assertTrue(f.complete(v1));
1365          }
1366  
1367          checkCompletedNormally(g, inc(v1));
# Line 1414 | Line 1424 | public class CompletableFutureTest exten
1424      {
1425          final CompletableFuture<Integer> f = new CompletableFuture<>();
1426          final FailingFunction r = new FailingFunction(m);
1427 <        if (!createIncomplete) f.complete(v1);
1427 >        if (!createIncomplete) assertTrue(f.complete(v1));
1428          final CompletableFuture<Integer> g = m.thenApply(f, r);
1429          if (createIncomplete) {
1430              checkIncomplete(g);
1431 <            f.complete(v1);
1431 >            assertTrue(f.complete(v1));
1432          }
1433  
1434          checkCompletedWithWrappedCFException(g);
# Line 1435 | Line 1445 | public class CompletableFutureTest exten
1445      {
1446          final CompletableFuture<Integer> f = new CompletableFuture<>();
1447          final NoopConsumer r = new NoopConsumer(m);
1448 <        if (!createIncomplete) f.complete(v1);
1448 >        if (!createIncomplete) assertTrue(f.complete(v1));
1449          final CompletableFuture<Void> g = m.thenAccept(f, r);
1450          if (createIncomplete) {
1451              checkIncomplete(g);
1452 <            f.complete(v1);
1452 >            assertTrue(f.complete(v1));
1453          }
1454  
1455          checkCompletedNormally(g, null);
# Line 1519 | Line 1529 | public class CompletableFutureTest exten
1529       */
1530      public void testThenCombine_normalCompletion() {
1531          for (ExecutionMode m : ExecutionMode.values())
1522        for (boolean createIncomplete : new boolean[] { true, false })
1532          for (boolean fFirst : new boolean[] { true, false })
1533          for (Integer v1 : new Integer[] { 1, null })
1534          for (Integer v2 : new Integer[] { 2, null })
1535      {
1536          final CompletableFuture<Integer> f = new CompletableFuture<>();
1537          final CompletableFuture<Integer> g = new CompletableFuture<>();
1538 <        final SubtractFunction r = new SubtractFunction(m);
1539 <
1540 <        if (fFirst) f.complete(v1); else g.complete(v2);
1541 <        if (!createIncomplete)
1542 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1543 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1544 <        if (createIncomplete) {
1545 <            checkIncomplete(h);
1546 <            r.assertNotInvoked();
1547 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1548 <        }
1549 <
1550 <        checkCompletedNormally(h, subtract(v1, v2));
1538 >        final SubtractFunction r1 = new SubtractFunction(m);
1539 >        final SubtractFunction r2 = new SubtractFunction(m);
1540 >        final SubtractFunction r3 = new SubtractFunction(m);
1541 >
1542 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1543 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1544 >        final Integer w1 =  fFirst ? v1 : v2;
1545 >        final Integer w2 = !fFirst ? v1 : v2;
1546 >
1547 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1548 >        assertTrue(fst.complete(w1));
1549 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1550 >        checkIncomplete(h1);
1551 >        checkIncomplete(h2);
1552 >        r1.assertNotInvoked();
1553 >        r2.assertNotInvoked();
1554 >        assertTrue(snd.complete(w2));
1555 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1556 >
1557 >        checkCompletedNormally(h1, subtract(v1, v2));
1558 >        checkCompletedNormally(h2, subtract(v1, v2));
1559 >        checkCompletedNormally(h3, subtract(v1, v2));
1560 >        r1.assertValue(subtract(v1, v2));
1561 >        r2.assertValue(subtract(v1, v2));
1562 >        r3.assertValue(subtract(v1, v2));
1563          checkCompletedNormally(f, v1);
1564          checkCompletedNormally(g, v2);
1544        r.assertValue(subtract(v1, v2));
1565      }}
1566  
1567      /**
1568       * thenCombine result completes exceptionally after exceptional
1569       * completion of either source
1570       */
1571 <    public void testThenCombine_exceptionalCompletion() {
1571 >    public void testThenCombine_exceptionalCompletion() throws Throwable {
1572          for (ExecutionMode m : ExecutionMode.values())
1553        for (boolean createIncomplete : new boolean[] { true, false })
1573          for (boolean fFirst : new boolean[] { true, false })
1574 +        for (boolean failFirst : new boolean[] { true, false })
1575          for (Integer v1 : new Integer[] { 1, null })
1576      {
1577          final CompletableFuture<Integer> f = new CompletableFuture<>();
1578          final CompletableFuture<Integer> g = new CompletableFuture<>();
1579          final CFException ex = new CFException();
1580 <        final SubtractFunction r = new SubtractFunction(m);
1581 <
1582 <        (fFirst ? f : g).complete(v1);
1583 <        if (!createIncomplete)
1584 <            (!fFirst ? f : g).completeExceptionally(ex);
1585 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1586 <        if (createIncomplete) {
1587 <            checkIncomplete(h);
1588 <            (!fFirst ? f : g).completeExceptionally(ex);
1589 <        }
1580 >        final SubtractFunction r1 = new SubtractFunction(m);
1581 >        final SubtractFunction r2 = new SubtractFunction(m);
1582 >        final SubtractFunction r3 = new SubtractFunction(m);
1583 >
1584 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1585 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1586 >        final Callable<Boolean> complete1 = failFirst ?
1587 >            () -> fst.completeExceptionally(ex) :
1588 >            () -> fst.complete(v1);
1589 >        final Callable<Boolean> complete2 = failFirst ?
1590 >            () -> snd.complete(v1) :
1591 >            () -> snd.completeExceptionally(ex);
1592 >
1593 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1594 >        assertTrue(complete1.call());
1595 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1596 >        checkIncomplete(h1);
1597 >        checkIncomplete(h2);
1598 >        assertTrue(complete2.call());
1599 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1600  
1601 <        checkCompletedWithWrappedException(h, ex);
1602 <        r.assertNotInvoked();
1603 <        checkCompletedNormally(fFirst ? f : g, v1);
1604 <        checkCompletedExceptionally(!fFirst ? f : g, ex);
1601 >        checkCompletedWithWrappedException(h1, ex);
1602 >        checkCompletedWithWrappedException(h2, ex);
1603 >        checkCompletedWithWrappedException(h3, ex);
1604 >        r1.assertNotInvoked();
1605 >        r2.assertNotInvoked();
1606 >        r3.assertNotInvoked();
1607 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1608 >        checkCompletedExceptionally(failFirst ? fst : snd, ex);
1609      }}
1610  
1611      /**
1612       * thenCombine result completes exceptionally if either source cancelled
1613       */
1614 <    public void testThenCombine_sourceCancelled() {
1614 >    public void testThenCombine_sourceCancelled() throws Throwable {
1615          for (ExecutionMode m : ExecutionMode.values())
1616          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1583        for (boolean createIncomplete : new boolean[] { true, false })
1617          for (boolean fFirst : new boolean[] { true, false })
1618 +        for (boolean failFirst : new boolean[] { true, false })
1619          for (Integer v1 : new Integer[] { 1, null })
1620      {
1621          final CompletableFuture<Integer> f = new CompletableFuture<>();
1622          final CompletableFuture<Integer> g = new CompletableFuture<>();
1623 <        final SubtractFunction r = new SubtractFunction(m);
1623 >        final SubtractFunction r1 = new SubtractFunction(m);
1624 >        final SubtractFunction r2 = new SubtractFunction(m);
1625 >        final SubtractFunction r3 = new SubtractFunction(m);
1626  
1627 <        (fFirst ? f : g).complete(v1);
1628 <        if (!createIncomplete)
1629 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1630 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1631 <        if (createIncomplete) {
1632 <            checkIncomplete(h);
1633 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1634 <        }
1627 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1628 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1629 >        final Callable<Boolean> complete1 = failFirst ?
1630 >            () -> fst.cancel(mayInterruptIfRunning) :
1631 >            () -> fst.complete(v1);
1632 >        final Callable<Boolean> complete2 = failFirst ?
1633 >            () -> snd.complete(v1) :
1634 >            () -> snd.cancel(mayInterruptIfRunning);
1635  
1636 <        checkCompletedWithWrappedCancellationException(h);
1637 <        checkCancelled(!fFirst ? f : g);
1638 <        r.assertNotInvoked();
1639 <        checkCompletedNormally(fFirst ? f : g, v1);
1636 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1637 >        assertTrue(complete1.call());
1638 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1639 >        checkIncomplete(h1);
1640 >        checkIncomplete(h2);
1641 >        assertTrue(complete2.call());
1642 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1643 >
1644 >        checkCompletedWithWrappedCancellationException(h1);
1645 >        checkCompletedWithWrappedCancellationException(h2);
1646 >        checkCompletedWithWrappedCancellationException(h3);
1647 >        r1.assertNotInvoked();
1648 >        r2.assertNotInvoked();
1649 >        r3.assertNotInvoked();
1650 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1651 >        checkCancelled(failFirst ? fst : snd);
1652      }}
1653  
1654      /**
# Line 1614 | Line 1662 | public class CompletableFutureTest exten
1662      {
1663          final CompletableFuture<Integer> f = new CompletableFuture<>();
1664          final CompletableFuture<Integer> g = new CompletableFuture<>();
1665 <        final FailingBiFunction r = new FailingBiFunction(m);
1666 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1665 >        final FailingBiFunction r1 = new FailingBiFunction(m);
1666 >        final FailingBiFunction r2 = new FailingBiFunction(m);
1667 >        final FailingBiFunction r3 = new FailingBiFunction(m);
1668 >
1669 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1670 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1671 >        final Integer w1 =  fFirst ? v1 : v2;
1672 >        final Integer w2 = !fFirst ? v1 : v2;
1673 >
1674 >        final CompletableFuture<Integer> h1 = m.thenCombine(f, g, r1);
1675 >        assertTrue(fst.complete(w1));
1676 >        final CompletableFuture<Integer> h2 = m.thenCombine(f, g, r2);
1677 >        assertTrue(snd.complete(w2));
1678 >        final CompletableFuture<Integer> h3 = m.thenCombine(f, g, r3);
1679  
1680 <        if (fFirst) {
1681 <            f.complete(v1);
1682 <            g.complete(v2);
1623 <        } else {
1624 <            g.complete(v2);
1625 <            f.complete(v1);
1626 <        }
1627 <
1628 <        checkCompletedWithWrappedCFException(h);
1680 >        checkCompletedWithWrappedCFException(h1);
1681 >        checkCompletedWithWrappedCFException(h2);
1682 >        checkCompletedWithWrappedCFException(h3);
1683          checkCompletedNormally(f, v1);
1684          checkCompletedNormally(g, v2);
1685      }}
# Line 1645 | Line 1699 | public class CompletableFutureTest exten
1699          final CompletableFuture<Integer> g = new CompletableFuture<>();
1700          final SubtractAction r = new SubtractAction(m);
1701  
1702 <        if (fFirst) f.complete(v1); else g.complete(v2);
1702 >        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1703          if (!createIncomplete)
1704 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1704 >            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1705          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1706          if (createIncomplete) {
1707              checkIncomplete(h);
1708              r.assertNotInvoked();
1709 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1709 >            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1710          }
1711  
1712          checkCompletedNormally(h, null);
# Line 1676 | Line 1730 | public class CompletableFutureTest exten
1730          final CFException ex = new CFException();
1731          final SubtractAction r = new SubtractAction(m);
1732  
1733 <        (fFirst ? f : g).complete(v1);
1733 >        assertTrue((fFirst ? f : g).complete(v1));
1734          if (!createIncomplete)
1735 <            (!fFirst ? f : g).completeExceptionally(ex);
1735 >            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1736          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1737          if (createIncomplete) {
1738              checkIncomplete(h);
1739 <            (!fFirst ? f : g).completeExceptionally(ex);
1739 >            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1740          }
1741  
1742          checkCompletedWithWrappedException(h, ex);
# Line 1705 | Line 1759 | public class CompletableFutureTest exten
1759          final CompletableFuture<Integer> g = new CompletableFuture<>();
1760          final SubtractAction r = new SubtractAction(m);
1761  
1762 <        (fFirst ? f : g).complete(v1);
1762 >        assertTrue((fFirst ? f : g).complete(v1));
1763          if (!createIncomplete)
1764              assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1765          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
# Line 1734 | Line 1788 | public class CompletableFutureTest exten
1788          final FailingBiConsumer r = new FailingBiConsumer(m);
1789          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1790  
1791 <        if (fFirst) {
1792 <            f.complete(v1);
1739 <            g.complete(v2);
1740 <        } else {
1741 <            g.complete(v2);
1742 <            f.complete(v1);
1743 <        }
1791 >        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1792 >        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1793  
1794          checkCompletedWithWrappedCFException(h);
1795          checkCompletedNormally(f, v1);
# Line 1762 | Line 1811 | public class CompletableFutureTest exten
1811          final CompletableFuture<Integer> g = new CompletableFuture<>();
1812          final Noop r = new Noop(m);
1813  
1814 <        if (fFirst) f.complete(v1); else g.complete(v2);
1814 >        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1815          if (!createIncomplete)
1816 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1816 >            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1817          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1818          if (createIncomplete) {
1819              checkIncomplete(h);
1820              r.assertNotInvoked();
1821 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1821 >            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1822          }
1823  
1824          checkCompletedNormally(h, null);
# Line 1793 | Line 1842 | public class CompletableFutureTest exten
1842          final CFException ex = new CFException();
1843          final Noop r = new Noop(m);
1844  
1845 <        (fFirst ? f : g).complete(v1);
1845 >        assertTrue((fFirst ? f : g).complete(v1));
1846          if (!createIncomplete)
1847 <            (!fFirst ? f : g).completeExceptionally(ex);
1847 >            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1848          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1849          if (createIncomplete) {
1850              checkIncomplete(h);
1851 <            (!fFirst ? f : g).completeExceptionally(ex);
1851 >            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1852          }
1853  
1854          checkCompletedWithWrappedException(h, ex);
# Line 1822 | Line 1871 | public class CompletableFutureTest exten
1871          final CompletableFuture<Integer> g = new CompletableFuture<>();
1872          final Noop r = new Noop(m);
1873  
1874 <        (fFirst ? f : g).complete(v1);
1874 >        assertTrue((fFirst ? f : g).complete(v1));
1875          if (!createIncomplete)
1876              assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1877          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
# Line 1852 | Line 1901 | public class CompletableFutureTest exten
1901          final FailingRunnable r2 = new FailingRunnable(m);
1902  
1903          CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
1904 <        if (fFirst) {
1905 <            f.complete(v1);
1857 <            g.complete(v2);
1858 <        } else {
1859 <            g.complete(v2);
1860 <            f.complete(v1);
1861 <        }
1904 >        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1905 >        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1906          CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
1907  
1908          checkCompletedWithWrappedCFException(h1);
# Line 1985 | Line 2029 | public class CompletableFutureTest exten
2029  
2030          final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
2031          final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
2032 <        if (fFirst) {
2033 <            f.complete(v1);
1990 <            g.completeExceptionally(ex);
1991 <        } else {
1992 <            g.completeExceptionally(ex);
1993 <            f.complete(v1);
1994 <        }
2032 >        assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2033 >        assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2034          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
2035          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
2036  
# Line 2097 | Line 2136 | public class CompletableFutureTest exten
2136  
2137          final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
2138          final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
2139 <        if (fFirst) {
2140 <            f.complete(v1);
2102 <            g.cancel(mayInterruptIfRunning);
2103 <        } else {
2104 <            g.cancel(mayInterruptIfRunning);
2105 <            f.complete(v1);
2106 <        }
2139 >        assertTrue(fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning));
2140 >        assertTrue(!fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning));
2141          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
2142          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
2143  
# Line 2305 | Line 2339 | public class CompletableFutureTest exten
2339  
2340          final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]);
2341          final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]);
2342 <        if (fFirst) {
2343 <            f.complete(v1);
2310 <            g.completeExceptionally(ex);
2311 <        } else {
2312 <            g.completeExceptionally(ex);
2313 <            f.complete(v1);
2314 <        }
2342 >        assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2343 >        assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2344          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2345          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2346  
# Line 2514 | Line 2543 | public class CompletableFutureTest exten
2543          checkIncomplete(h1);
2544          rs[0].assertNotInvoked();
2545          rs[1].assertNotInvoked();
2546 <        f.completeExceptionally(ex);
2546 >        assertTrue(f.completeExceptionally(ex));
2547          checkCompletedWithWrappedException(h0, ex);
2548          checkCompletedWithWrappedException(h1, ex);
2549          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
# Line 2522 | Line 2551 | public class CompletableFutureTest exten
2551          checkCompletedWithWrappedException(h2, ex);
2552          checkCompletedWithWrappedException(h3, ex);
2553  
2554 <        g.complete(v1);
2554 >        assertTrue(g.complete(v1));
2555  
2556          // unspecified behavior - both source completions available
2557          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
# Line 2565 | Line 2594 | public class CompletableFutureTest exten
2594  
2595          final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2596          final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2597 <        if (fFirst) {
2598 <            f.complete(v1);
2570 <            g.completeExceptionally(ex);
2571 <        } else {
2572 <            g.completeExceptionally(ex);
2573 <            f.complete(v1);
2574 <        }
2597 >        assertTrue( fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2598 >        assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2599          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2600          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2601  
# Line 2636 | Line 2660 | public class CompletableFutureTest exten
2660          checkCompletedWithWrappedCancellationException(h2);
2661          checkCompletedWithWrappedCancellationException(h3);
2662  
2663 <        g.complete(v1);
2663 >        assertTrue(g.complete(v1));
2664  
2665          // unspecified behavior - both source completions available
2666          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
# Line 2680 | Line 2704 | public class CompletableFutureTest exten
2704  
2705          final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2706          final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2707 <        f.complete(v1);
2707 >        assertTrue(f.complete(v1));
2708          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2709          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2710          checkCompletedWithWrappedCFException(h0);
# Line 2688 | Line 2712 | public class CompletableFutureTest exten
2712          checkCompletedWithWrappedCFException(h2);
2713          checkCompletedWithWrappedCFException(h3);
2714          for (int i = 0; i < 4; i++) rs[i].assertInvoked();
2715 <        g.complete(v2);
2715 >        assertTrue(g.complete(v2));
2716          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2717          final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2718          checkCompletedWithWrappedCFException(h4);
# Line 2709 | Line 2733 | public class CompletableFutureTest exten
2733      {
2734          final CompletableFuture<Integer> f = new CompletableFuture<>();
2735          final CompletableFutureInc r = new CompletableFutureInc(m);
2736 <        if (!createIncomplete) f.complete(v1);
2736 >        if (!createIncomplete) assertTrue(f.complete(v1));
2737          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2738 <        if (createIncomplete) f.complete(v1);
2738 >        if (createIncomplete) assertTrue(f.complete(v1));
2739  
2740          checkCompletedNormally(g, inc(v1));
2741          checkCompletedNormally(f, v1);
# Line 2749 | Line 2773 | public class CompletableFutureTest exten
2773          final CompletableFuture<Integer> f = new CompletableFuture<>();
2774          final FailingCompletableFutureFunction r
2775              = new FailingCompletableFutureFunction(m);
2776 <        if (!createIncomplete) f.complete(v1);
2776 >        if (!createIncomplete) assertTrue(f.complete(v1));
2777          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2778 <        if (createIncomplete) f.complete(v1);
2778 >        if (createIncomplete) assertTrue(f.complete(v1));
2779  
2780          checkCompletedWithWrappedCFException(g);
2781          checkCompletedNormally(f, v1);
# Line 2990 | Line 3014 | public class CompletableFutureTest exten
3014          assertSame(f, f.toCompletableFuture());
3015      }
3016  
3017 + //     public void testRunAfterEither_resultDeterminedAtTimeOfCreation() {
3018 + //         for (ExecutionMode m : ExecutionMode.values())
3019 + //         for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3020 + //         for (Integer v1 : new Integer[] { 1, null })
3021 + //     {
3022 + //         final CompletableFuture<Integer> f = new CompletableFuture<>();
3023 + //         final CompletableFuture<Integer> g = new CompletableFuture<>();
3024 + //         final Noop[] rs = new Noop[2];
3025 + //         for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
3026 + //         f.complete(v1);
3027 + //         final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
3028 + //         final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
3029 + //         assertTrue(g.cancel(mayInterruptIfRunning));
3030 + //         checkCompletedNormally(h0, null);
3031 + //         checkCompletedNormally(h1, null);
3032 + //         for (Noop r : rs) r.assertInvoked();
3033 + //     }}
3034 +
3035   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines