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.72 by jsr166, Fri Jun 6 21:10:34 2014 UTC vs.
Revision 1.79 by jsr166, Mon Jun 16 17:08:15 2014 UTC

# Line 131 | Line 131 | public class CompletableFutureTest exten
131          } catch (ExecutionException success) {
132              assertSame(ex, success.getCause());
133          } catch (Throwable fail) { threadUnexpectedException(fail); }
134 <                                                            
134 >
135          assertTrue(f.isDone());
136          assertFalse(f.isCancelled());
137          assertTrue(f.toString().contains("[Completed exceptionally]"));
# 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());
358 >        assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
359          assertTrue(f.toString().contains("[Completed exceptionally]"));
360 +
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 521 | 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 829 | 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);
861          assertEquals(0, a.get());
862      }}
863  
846
864      /**
865       * exceptionally action completes with function value on source
866       * exception
# Line 892 | Line 909 | public class CompletableFutureTest exten
909      }}
910  
911      /**
912 +     * whenComplete action executes on normal completion, propagating
913 +     * source result.
914 +     */
915 +    public void testWhenComplete_normalCompletion1() {
916 +        for (ExecutionMode m : ExecutionMode.values())
917 +        for (boolean createIncomplete : new boolean[] { true, false })
918 +        for (Integer v1 : new Integer[] { 1, null })
919 +    {
920 +        final AtomicInteger a = new AtomicInteger(0);
921 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
922 +        if (!createIncomplete) assertTrue(f.complete(v1));
923 +        final CompletableFuture<Integer> g = m.whenComplete
924 +            (f,
925 +             (Integer x, Throwable t) -> {
926 +                m.checkExecutionMode();
927 +                threadAssertSame(x, v1);
928 +                threadAssertNull(t);
929 +                a.getAndIncrement();
930 +            });
931 +        if (createIncomplete) assertTrue(f.complete(v1));
932 +
933 +        checkCompletedNormally(g, v1);
934 +        checkCompletedNormally(f, v1);
935 +        assertEquals(1, a.get());
936 +    }}
937 +
938 +    /**
939 +     * whenComplete action executes on exceptional completion, propagating
940 +     * source result.
941 +     */
942 +    public void testWhenComplete_exceptionalCompletion() {
943 +        for (ExecutionMode m : ExecutionMode.values())
944 +        for (boolean createIncomplete : new boolean[] { true, false })
945 +        for (Integer v1 : new Integer[] { 1, null })
946 +    {
947 +        final AtomicInteger a = new AtomicInteger(0);
948 +        final CFException ex = new CFException();
949 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
950 +        if (!createIncomplete) f.completeExceptionally(ex);
951 +        final CompletableFuture<Integer> g = m.whenComplete
952 +            (f,
953 +             (Integer x, Throwable t) -> {
954 +                m.checkExecutionMode();
955 +                threadAssertNull(x);
956 +                threadAssertSame(t, ex);
957 +                a.getAndIncrement();
958 +            });
959 +        if (createIncomplete) f.completeExceptionally(ex);
960 +
961 +        checkCompletedWithWrappedException(g, ex);
962 +        checkCompletedExceptionally(f, ex);
963 +        assertEquals(1, a.get());
964 +    }}
965 +
966 +    /**
967 +     * whenComplete action executes on cancelled source, propagating
968 +     * CancellationException.
969 +     */
970 +    public void testWhenComplete_sourceCancelled() {
971 +        for (ExecutionMode m : ExecutionMode.values())
972 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
973 +        for (boolean createIncomplete : new boolean[] { true, false })
974 +    {
975 +        final AtomicInteger a = new AtomicInteger(0);
976 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
977 +        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
978 +        final CompletableFuture<Integer> g = m.whenComplete
979 +            (f,
980 +             (Integer x, Throwable t) -> {
981 +                m.checkExecutionMode();
982 +                threadAssertNull(x);
983 +                threadAssertTrue(t instanceof CancellationException);
984 +                a.getAndIncrement();
985 +            });
986 +        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
987 +
988 +        checkCompletedWithWrappedCancellationException(g);
989 +        checkCancelled(f);
990 +        assertEquals(1, a.get());
991 +    }}
992 +
993 +    /**
994 +     * If a whenComplete action throws an exception when triggered by
995 +     * a normal completion, it completes exceptionally
996 +     */
997 +    public void testWhenComplete_actionFailed() {
998 +        for (boolean createIncomplete : new boolean[] { true, false })
999 +        for (ExecutionMode m : ExecutionMode.values())
1000 +        for (Integer v1 : new Integer[] { 1, null })
1001 +    {
1002 +        final AtomicInteger a = new AtomicInteger(0);
1003 +        final CFException ex = new CFException();
1004 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1005 +        if (!createIncomplete) assertTrue(f.complete(v1));
1006 +        final CompletableFuture<Integer> g = m.whenComplete
1007 +            (f,
1008 +             (Integer x, Throwable t) -> {
1009 +                m.checkExecutionMode();
1010 +                threadAssertSame(x, v1);
1011 +                threadAssertNull(t);
1012 +                a.getAndIncrement();
1013 +                throw ex;
1014 +            });
1015 +        if (createIncomplete) assertTrue(f.complete(v1));
1016 +
1017 +        checkCompletedWithWrappedException(g, ex);
1018 +        checkCompletedNormally(f, v1);
1019 +        assertEquals(1, a.get());
1020 +    }}
1021 +
1022 +    /**
1023 +     * If a whenComplete action throws an exception when triggered by
1024 +     * a source completion that also throws an exception, the source
1025 +     * exception takes precedence.
1026 +     */
1027 +    public void testWhenComplete_actionFailedSourceFailed() {
1028 +        for (boolean createIncomplete : new boolean[] { true, false })
1029 +        for (ExecutionMode m : ExecutionMode.values())
1030 +        for (Integer v1 : new Integer[] { 1, null })
1031 +    {
1032 +        final AtomicInteger a = new AtomicInteger(0);
1033 +        final CFException ex1 = new CFException();
1034 +        final CFException ex2 = new CFException();
1035 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1036 +
1037 +        if (!createIncomplete) f.completeExceptionally(ex1);
1038 +        final CompletableFuture<Integer> g = m.whenComplete
1039 +            (f,
1040 +             (Integer x, Throwable t) -> {
1041 +                m.checkExecutionMode();
1042 +                threadAssertSame(t, ex1);
1043 +                threadAssertNull(x);
1044 +                a.getAndIncrement();
1045 +                throw ex2;
1046 +            });
1047 +        if (createIncomplete) f.completeExceptionally(ex1);
1048 +
1049 +        checkCompletedWithWrappedException(g, ex1);
1050 +        checkCompletedExceptionally(f, ex1);
1051 +        assertEquals(1, a.get());
1052 +    }}
1053 +
1054 +    /**
1055       * handle action completes normally with function value on normal
1056       * completion of source
1057       */
# Line 902 | 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 912 | 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 1013 | 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 1023 | 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 1109 | 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 1176 | 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 1197 | 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 1264 | 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 1285 | 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 1369 | Line 1529 | public class CompletableFutureTest exten
1529       */
1530      public void testThenCombine_normalCompletion() {
1531          for (ExecutionMode m : ExecutionMode.values())
1372        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);
1394        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())
1403        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 })
1433        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 1464 | 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);
1473 <        } else {
1474 <            g.complete(v2);
1475 <            f.complete(v1);
1476 <        }
1477 <
1478 <        checkCompletedWithWrappedCFException(h);
1680 >        checkCompletedWithWrappedCFException(h1);
1681 >        checkCompletedWithWrappedCFException(h2);
1682 >        checkCompletedWithWrappedCFException(h3);
1683          checkCompletedNormally(f, v1);
1684          checkCompletedNormally(g, v2);
1685      }}
# Line 1495 | 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 1526 | 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 1555 | 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 1584 | 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);
1589 <            g.complete(v2);
1590 <        } else {
1591 <            g.complete(v2);
1592 <            f.complete(v1);
1593 <        }
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 1612 | 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 1643 | 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 1672 | Line 1871 | public class CompletableFutureTest exten
1871          final CompletableFuture<Integer> g = new CompletableFuture<>();
1872          final Noop r = new Noop(m);
1873  
1874 <
1676 <        (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 1703 | 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);
1708 <            g.complete(v2);
1709 <        } else {
1710 <            g.complete(v2);
1711 <            f.complete(v1);
1712 <        }
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 1836 | 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);
1841 <            g.completeExceptionally(ex);
1842 <        } else {
1843 <            g.completeExceptionally(ex);
1844 <            f.complete(v1);
1845 <        }
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 1948 | 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);
1953 <            g.cancel(mayInterruptIfRunning);
1954 <        } else {
1955 <            g.cancel(mayInterruptIfRunning);
1956 <            f.complete(v1);
1957 <        }
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 2156 | 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);
2161 <            g.completeExceptionally(ex);
2162 <        } else {
2163 <            g.completeExceptionally(ex);
2164 <            f.complete(v1);
2165 <        }
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 2365 | 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 2373 | 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 2416 | 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);
2421 <            g.completeExceptionally(ex);
2422 <        } else {
2423 <            g.completeExceptionally(ex);
2424 <            f.complete(v1);
2425 <        }
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 2487 | 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 2531 | 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 2539 | 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 2560 | 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 2600 | 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 2841 | Line 3014 | public class CompletableFutureTest exten
3014          assertSame(f, f.toCompletableFuture());
3015      }
3016  
3017 <    /**
3018 <     * whenComplete action executes on normal completion, propagating
3019 <     * source result.
3020 <     */
3021 <    public void testWhenComplete_normalCompletion1() {
3022 <        for (ExecutionMode m : ExecutionMode.values())
3023 <        for (boolean createIncomplete : new boolean[] { true, false })
3024 <        for (Integer v1 : new Integer[] { 1, null })
3025 <    {
3026 <        final AtomicInteger a = new AtomicInteger(0);
3027 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
3028 <        if (!createIncomplete) f.complete(v1);
3029 <        final CompletableFuture<Integer> g = m.whenComplete
3030 <            (f,
3031 <             (Integer x, Throwable t) -> {
3032 <                m.checkExecutionMode();
3033 <                threadAssertSame(x, v1);
2861 <                threadAssertNull(t);
2862 <                a.getAndIncrement();
2863 <            });
2864 <        if (createIncomplete) f.complete(v1);
2865 <
2866 <        checkCompletedNormally(g, v1);
2867 <        checkCompletedNormally(f, v1);
2868 <        assertEquals(1, a.get());
2869 <    }}
2870 <
2871 <    /**
2872 <     * whenComplete action executes on exceptional completion, propagating
2873 <     * source result.
2874 <     */
2875 <    public void testWhenComplete_exceptionalCompletion() {
2876 <        for (ExecutionMode m : ExecutionMode.values())
2877 <        for (boolean createIncomplete : new boolean[] { true, false })
2878 <        for (Integer v1 : new Integer[] { 1, null })
2879 <    {
2880 <        final AtomicInteger a = new AtomicInteger(0);
2881 <        final CFException ex = new CFException();
2882 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2883 <        if (!createIncomplete) f.completeExceptionally(ex);
2884 <        final CompletableFuture<Integer> g = m.whenComplete
2885 <            (f,
2886 <             (Integer x, Throwable t) -> {
2887 <                m.checkExecutionMode();
2888 <                threadAssertNull(x);
2889 <                threadAssertSame(t, ex);
2890 <                a.getAndIncrement();
2891 <            });
2892 <        if (createIncomplete) f.completeExceptionally(ex);
2893 <        checkCompletedExceptionally(f, ex);
2894 <        checkCompletedWithWrappedException(g, ex);
2895 <        assertEquals(1, a.get());
2896 <    }}
2897 <
2898 <    /**
2899 <     * whenComplete action executes on cancelled source, propagating
2900 <     * CancellationException.
2901 <     */
2902 <    public void testWhenComplete_sourceCancelled() {
2903 <        for (ExecutionMode m : ExecutionMode.values())
2904 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2905 <        for (boolean createIncomplete : new boolean[] { true, false })
2906 <    {
2907 <        final AtomicInteger a = new AtomicInteger(0);
2908 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2909 <        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2910 <        final CompletableFuture<Integer> g = m.whenComplete
2911 <            (f,
2912 <             (Integer x, Throwable t) -> {
2913 <                m.checkExecutionMode();
2914 <                threadAssertNull(x);
2915 <                threadAssertTrue(t instanceof CancellationException);
2916 <                a.getAndIncrement();
2917 <            });
2918 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2919 <
2920 <        checkCompletedWithWrappedCancellationException(g);
2921 <        checkCancelled(f);
2922 <        assertEquals(1, a.get());
2923 <    }}
2924 <
2925 <    /**
2926 <     * If a whenComplete action throws an exception when triggered by
2927 <     * a normal completion, it completes exceptionally
2928 <     */
2929 <    public void testWhenComplete_actionFailed() {
2930 <        for (boolean createIncomplete : new boolean[] { true, false })
2931 <        for (ExecutionMode m : ExecutionMode.values())
2932 <        for (Integer v1 : new Integer[] { 1, null })
2933 <    {
2934 <        final AtomicInteger a = new AtomicInteger(0);
2935 <        final CFException ex = new CFException();
2936 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2937 <        if (!createIncomplete) f.complete(v1);
2938 <        final CompletableFuture<Integer> g = m.whenComplete
2939 <            (f,
2940 <             (Integer x, Throwable t) -> {
2941 <                m.checkExecutionMode();
2942 <                threadAssertSame(x, v1);
2943 <                threadAssertNull(t);
2944 <                a.getAndIncrement();
2945 <                throw ex;
2946 <            });
2947 <        if (createIncomplete) f.complete(v1);
2948 <        checkCompletedNormally(f, v1);
2949 <        checkCompletedWithWrappedException(g, ex);
2950 <        assertEquals(1, a.get());
2951 <    }}
2952 <
2953 <    /**
2954 <     * If a whenComplete action throws an exception when triggered by
2955 <     * a source completion that also throws an exception, the source
2956 <     * exception takes precedence.
2957 <     */
2958 <    public void testWhenComplete_actionFailedSourceFailed() {
2959 <        for (boolean createIncomplete : new boolean[] { true, false })
2960 <        for (ExecutionMode m : ExecutionMode.values())
2961 <        for (Integer v1 : new Integer[] { 1, null })
2962 <    {
2963 <        final AtomicInteger a = new AtomicInteger(0);
2964 <        final CFException ex1 = new CFException();
2965 <        final CFException ex2 = new CFException();
2966 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2967 <
2968 <        if (!createIncomplete) f.completeExceptionally(ex1);
2969 <        final CompletableFuture<Integer> g = m.whenComplete
2970 <            (f,
2971 <             (Integer x, Throwable t) -> {
2972 <                m.checkExecutionMode();
2973 <                threadAssertSame(t, ex1);
2974 <                threadAssertNull(x);
2975 <                a.getAndIncrement();
2976 <                throw ex2;
2977 <            });
2978 <        if (createIncomplete) f.completeExceptionally(ex1);
2979 <
2980 <        checkCompletedExceptionally(f, ex1);
2981 <        checkCompletedWithWrappedException(g, ex1);
2982 <        assertEquals(1, a.get());
2983 <    }}
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