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.70 by jsr166, Fri Jun 6 19:48:38 2014 UTC vs.
Revision 1.80 by jsr166, Mon Jun 16 17:29:03 2014 UTC

# Line 105 | Line 105 | public class CompletableFutureTest exten
105          assertTrue(f.toString().contains("[Completed exceptionally]"));
106      }
107  
108 <    void checkCompletedWithWrappedCFException(CompletableFuture<?> f,
109 <                                              CFException ex) {
108 >    <U> void checkCompletedExceptionallyWithRootCause(CompletableFuture<U> f,
109 >                                                      Throwable ex) {
110          try {
111              f.get(LONG_DELAY_MS, MILLISECONDS);
112              shouldThrow();
# Line 131 | Line 131 | public class CompletableFutureTest exten
131          } catch (ExecutionException success) {
132              assertSame(ex, success.getCause());
133          } catch (Throwable fail) { threadUnexpectedException(fail); }
134 +
135          assertTrue(f.isDone());
136          assertFalse(f.isCancelled());
137          assertTrue(f.toString().contains("[Completed exceptionally]"));
138      }
139  
140 +    <U> void checkCompletedWithWrappedException(CompletableFuture<U> f,
141 +                                                Throwable ex) {
142 +        checkCompletedExceptionallyWithRootCause(f, ex);
143 +        try {
144 +            CompletableFuture<Throwable> spy = f.handle
145 +                ((U u, Throwable t) -> t);
146 +            assertTrue(spy.join() instanceof CompletionException);
147 +            assertSame(ex, spy.join().getCause());
148 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
149 +    }
150 +
151 +    <U> void checkCompletedExceptionally(CompletableFuture<U> f, Throwable ex) {
152 +        checkCompletedExceptionallyWithRootCause(f, ex);
153 +        try {
154 +            CompletableFuture<Throwable> spy = f.handle
155 +                ((U u, Throwable t) -> t);
156 +            assertSame(ex, spy.join());
157 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
158 +    }
159 +
160      void checkCancelled(CompletableFuture<?> f) {
161          try {
162              f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 206 | 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 218 | Line 242 | public class CompletableFutureTest exten
242       */
243      public void testCompleteExceptionally() {
244          CompletableFuture<Integer> f = new CompletableFuture<>();
245 +        CFException ex = new CFException();
246          checkIncomplete(f);
247 <        f.completeExceptionally(new CFException());
248 <        checkCompletedWithWrappedCFException(f);
247 >        f.completeExceptionally(ex);
248 >        checkCompletedExceptionally(f, ex);
249      }
250  
251      /**
# Line 228 | 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 240 | 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 261 | Line 289 | public class CompletableFutureTest exten
289       * obtrudeException forces completion with given exception
290       */
291      public void testObtrudeException() {
292 <        CompletableFuture<Integer> f = new CompletableFuture<>();
293 <        checkIncomplete(f);
294 <        f.complete(one);
295 <        checkCompletedNormally(f, one);
296 <        f.obtrudeException(new CFException());
269 <        checkCompletedWithWrappedCFException(f);
292 >        for (Integer v1 : new Integer[] { 1, null })
293 >    {
294 >        CFException ex;
295 >        CompletableFuture<Integer> f;
296 >
297          f = new CompletableFuture<>();
298 <        f.obtrudeException(new CFException());
299 <        checkCompletedWithWrappedCFException(f);
298 >        assertTrue(f.complete(v1));
299 >        for (int i = 0; i < 2; i++) {
300 >            f.obtrudeException(ex = new CFException());
301 >            checkCompletedExceptionally(f, ex);
302 >        }
303 >
304 >        f = new CompletableFuture<>();
305 >        for (int i = 0; i < 2; i++) {
306 >            f.obtrudeException(ex = new CFException());
307 >            checkCompletedExceptionally(f, ex);
308 >        }
309 >
310          f = new CompletableFuture<>();
311 +        f.completeExceptionally(ex = new CFException());
312 +        f.obtrudeValue(v1);
313 +        checkCompletedNormally(f, v1);
314 +        f.obtrudeException(ex = new CFException());
315 +        checkCompletedExceptionally(f, ex);
316          f.completeExceptionally(new CFException());
317 <        f.obtrudeValue(four);
318 <        checkCompletedNormally(f, four);
319 <        f.obtrudeException(new CFException());
320 <        checkCompletedWithWrappedCFException(f);
279 <    }
317 >        checkCompletedExceptionally(f, ex);
318 >        assertFalse(f.complete(v1));
319 >        checkCompletedExceptionally(f, ex);
320 >    }}
321  
322      /**
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 304 | 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 486 | 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 794 | 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  
811
864      /**
865       * exceptionally action completes with function value on source
866       * exception
# Line 852 | Line 904 | public class CompletableFutureTest exten
904              });
905          if (createIncomplete) f.completeExceptionally(ex1);
906  
907 <        checkCompletedWithWrappedCFException(g, ex2);
907 >        checkCompletedWithWrappedException(g, ex2);
908 >        assertEquals(1, a.get());
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  
# Line 867 | 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 877 | 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 909 | Line 1104 | public class CompletableFutureTest exten
1104          if (createIncomplete) f.completeExceptionally(ex);
1105  
1106          checkCompletedNormally(g, v1);
1107 <        checkCompletedWithWrappedCFException(f, ex);
1107 >        checkCompletedExceptionally(f, ex);
1108          assertEquals(1, a.get());
1109      }}
1110  
# Line 965 | Line 1160 | public class CompletableFutureTest exten
1160              });
1161          if (createIncomplete) f.completeExceptionally(ex1);
1162  
1163 <        checkCompletedWithWrappedCFException(g, ex2);
1164 <        checkCompletedWithWrappedCFException(f, ex1);
1163 >        checkCompletedWithWrappedException(g, ex2);
1164 >        checkCompletedExceptionally(f, ex1);
1165          assertEquals(1, a.get());
1166      }}
1167  
# Line 978 | 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 988 | 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 <        checkCompletedWithWrappedCFException(g, ex);
1188 >        checkCompletedWithWrappedException(g, ex);
1189          checkCompletedNormally(f, v1);
1190          assertEquals(1, a.get());
1191      }}
# Line 1074 | 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 1104 | Line 1299 | public class CompletableFutureTest exten
1299              f.completeExceptionally(ex);
1300          }
1301  
1302 <        checkCompletedWithWrappedCFException(g, ex);
1303 <        checkCompletedWithWrappedCFException(f, ex);
1302 >        checkCompletedWithWrappedException(g, ex);
1303 >        checkCompletedExceptionally(f, ex);
1304          r.assertNotInvoked();
1305      }}
1306  
# Line 1141 | 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 1162 | 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 1192 | Line 1387 | public class CompletableFutureTest exten
1387              f.completeExceptionally(ex);
1388          }
1389  
1390 <        checkCompletedWithWrappedCFException(g, ex);
1391 <        checkCompletedWithWrappedCFException(f, ex);
1390 >        checkCompletedWithWrappedException(g, ex);
1391 >        checkCompletedExceptionally(f, ex);
1392          r.assertNotInvoked();
1393      }}
1394  
# Line 1229 | 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 1250 | 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 1280 | Line 1475 | public class CompletableFutureTest exten
1475              f.completeExceptionally(ex);
1476          }
1477  
1478 <        checkCompletedWithWrappedCFException(g, ex);
1479 <        checkCompletedWithWrappedCFException(f, ex);
1478 >        checkCompletedWithWrappedException(g, ex);
1479 >        checkCompletedExceptionally(f, ex);
1480          r.assertNotInvoked();
1481      }}
1482  
# Line 1334 | Line 1529 | public class CompletableFutureTest exten
1529       */
1530      public void testThenCombine_normalCompletion() {
1531          for (ExecutionMode m : ExecutionMode.values())
1337        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);
1359        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())
1368        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 <        }
1590 <
1591 <        checkCompletedWithWrappedCFException(h, ex);
1592 <        r.assertNotInvoked();
1593 <        checkCompletedNormally(fFirst ? f : g, v1);
1594 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
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(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 })
1398        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 1429 | 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);
1438 <        } else {
1439 <            g.complete(v2);
1440 <            f.complete(v1);
1441 <        }
1442 <
1443 <        checkCompletedWithWrappedCFException(h);
1680 >        checkCompletedWithWrappedCFException(h1);
1681 >        checkCompletedWithWrappedCFException(h2);
1682 >        checkCompletedWithWrappedCFException(h3);
1683          checkCompletedNormally(f, v1);
1684          checkCompletedNormally(g, v2);
1685      }}
# Line 1451 | Line 1690 | public class CompletableFutureTest exten
1690       */
1691      public void testThenAcceptBoth_normalCompletion() {
1692          for (ExecutionMode m : ExecutionMode.values())
1454        for (boolean createIncomplete : new boolean[] { true, false })
1693          for (boolean fFirst : new boolean[] { true, false })
1694          for (Integer v1 : new Integer[] { 1, null })
1695          for (Integer v2 : new Integer[] { 2, null })
1696      {
1697          final CompletableFuture<Integer> f = new CompletableFuture<>();
1698          final CompletableFuture<Integer> g = new CompletableFuture<>();
1699 <        final SubtractAction r = new SubtractAction(m);
1700 <
1701 <        if (fFirst) f.complete(v1); else g.complete(v2);
1702 <        if (!createIncomplete)
1703 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1704 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1705 <        if (createIncomplete) {
1706 <            checkIncomplete(h);
1707 <            r.assertNotInvoked();
1708 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1709 <        }
1699 >        final SubtractAction r1 = new SubtractAction(m);
1700 >        final SubtractAction r2 = new SubtractAction(m);
1701 >        final SubtractAction r3 = new SubtractAction(m);
1702 >
1703 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1704 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1705 >        final Integer w1 =  fFirst ? v1 : v2;
1706 >        final Integer w2 = !fFirst ? v1 : v2;
1707 >
1708 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1709 >        assertTrue(fst.complete(w1));
1710 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1711 >        checkIncomplete(h1);
1712 >        checkIncomplete(h2);
1713 >        r1.assertNotInvoked();
1714 >        r2.assertNotInvoked();
1715 >        assertTrue(snd.complete(w2));
1716 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1717  
1718 <        checkCompletedNormally(h, null);
1719 <        r.assertValue(subtract(v1, v2));
1718 >        checkCompletedNormally(h1, null);
1719 >        checkCompletedNormally(h2, null);
1720 >        checkCompletedNormally(h3, null);
1721 >        r1.assertValue(subtract(v1, v2));
1722 >        r2.assertValue(subtract(v1, v2));
1723 >        r3.assertValue(subtract(v1, v2));
1724          checkCompletedNormally(f, v1);
1725          checkCompletedNormally(g, v2);
1726      }}
# Line 1480 | Line 1729 | public class CompletableFutureTest exten
1729       * thenAcceptBoth result completes exceptionally after exceptional
1730       * completion of either source
1731       */
1732 <    public void testThenAcceptBoth_exceptionalCompletion() {
1732 >    public void testThenAcceptBoth_exceptionalCompletion() throws Throwable {
1733          for (ExecutionMode m : ExecutionMode.values())
1485        for (boolean createIncomplete : new boolean[] { true, false })
1734          for (boolean fFirst : new boolean[] { true, false })
1735 +        for (boolean failFirst : new boolean[] { true, false })
1736          for (Integer v1 : new Integer[] { 1, null })
1737      {
1738          final CompletableFuture<Integer> f = new CompletableFuture<>();
1739          final CompletableFuture<Integer> g = new CompletableFuture<>();
1740          final CFException ex = new CFException();
1741 <        final SubtractAction r = new SubtractAction(m);
1742 <
1743 <        (fFirst ? f : g).complete(v1);
1744 <        if (!createIncomplete)
1745 <            (!fFirst ? f : g).completeExceptionally(ex);
1746 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1747 <        if (createIncomplete) {
1748 <            checkIncomplete(h);
1749 <            (!fFirst ? f : g).completeExceptionally(ex);
1750 <        }
1751 <
1752 <        checkCompletedWithWrappedCFException(h, ex);
1753 <        r.assertNotInvoked();
1754 <        checkCompletedNormally(fFirst ? f : g, v1);
1755 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1741 >        final SubtractAction r1 = new SubtractAction(m);
1742 >        final SubtractAction r2 = new SubtractAction(m);
1743 >        final SubtractAction r3 = new SubtractAction(m);
1744 >
1745 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1746 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1747 >        final Callable<Boolean> complete1 = failFirst ?
1748 >            () -> fst.completeExceptionally(ex) :
1749 >            () -> fst.complete(v1);
1750 >        final Callable<Boolean> complete2 = failFirst ?
1751 >            () -> snd.complete(v1) :
1752 >            () -> snd.completeExceptionally(ex);
1753 >
1754 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1755 >        assertTrue(complete1.call());
1756 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1757 >        checkIncomplete(h1);
1758 >        checkIncomplete(h2);
1759 >        assertTrue(complete2.call());
1760 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1761 >
1762 >        checkCompletedWithWrappedException(h1, ex);
1763 >        checkCompletedWithWrappedException(h2, ex);
1764 >        checkCompletedWithWrappedException(h3, ex);
1765 >        r1.assertNotInvoked();
1766 >        r2.assertNotInvoked();
1767 >        r3.assertNotInvoked();
1768 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1769 >        checkCompletedExceptionally(failFirst ? fst : snd, ex);
1770      }}
1771  
1772      /**
1773       * thenAcceptBoth result completes exceptionally if either source cancelled
1774       */
1775 <    public void testThenAcceptBoth_sourceCancelled() {
1775 >    public void testThenAcceptBoth_sourceCancelled() throws Throwable {
1776          for (ExecutionMode m : ExecutionMode.values())
1777          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1515        for (boolean createIncomplete : new boolean[] { true, false })
1778          for (boolean fFirst : new boolean[] { true, false })
1779 +        for (boolean failFirst : new boolean[] { true, false })
1780          for (Integer v1 : new Integer[] { 1, null })
1781      {
1782          final CompletableFuture<Integer> f = new CompletableFuture<>();
1783          final CompletableFuture<Integer> g = new CompletableFuture<>();
1784 <        final SubtractAction r = new SubtractAction(m);
1784 >        final SubtractAction r1 = new SubtractAction(m);
1785 >        final SubtractAction r2 = new SubtractAction(m);
1786 >        final SubtractAction r3 = new SubtractAction(m);
1787  
1788 <        (fFirst ? f : g).complete(v1);
1789 <        if (!createIncomplete)
1790 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1791 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1792 <        if (createIncomplete) {
1793 <            checkIncomplete(h);
1794 <            assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1795 <        }
1788 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1789 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1790 >        final Callable<Boolean> complete1 = failFirst ?
1791 >            () -> fst.cancel(mayInterruptIfRunning) :
1792 >            () -> fst.complete(v1);
1793 >        final Callable<Boolean> complete2 = failFirst ?
1794 >            () -> snd.complete(v1) :
1795 >            () -> snd.cancel(mayInterruptIfRunning);
1796  
1797 <        checkCompletedWithWrappedCancellationException(h);
1798 <        checkCancelled(!fFirst ? f : g);
1799 <        r.assertNotInvoked();
1800 <        checkCompletedNormally(fFirst ? f : g, v1);
1797 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1798 >        assertTrue(complete1.call());
1799 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1800 >        checkIncomplete(h1);
1801 >        checkIncomplete(h2);
1802 >        assertTrue(complete2.call());
1803 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1804 >
1805 >        checkCompletedWithWrappedCancellationException(h1);
1806 >        checkCompletedWithWrappedCancellationException(h2);
1807 >        checkCompletedWithWrappedCancellationException(h3);
1808 >        r1.assertNotInvoked();
1809 >        r2.assertNotInvoked();
1810 >        r3.assertNotInvoked();
1811 >        checkCompletedNormally(failFirst ? snd : fst, v1);
1812 >        checkCancelled(failFirst ? fst : snd);
1813      }}
1814  
1815      /**
# Line 1546 | Line 1823 | public class CompletableFutureTest exten
1823      {
1824          final CompletableFuture<Integer> f = new CompletableFuture<>();
1825          final CompletableFuture<Integer> g = new CompletableFuture<>();
1826 <        final FailingBiConsumer r = new FailingBiConsumer(m);
1827 <        final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1828 <
1829 <        if (fFirst) {
1830 <            f.complete(v1);
1831 <            g.complete(v2);
1832 <        } else {
1833 <            g.complete(v2);
1834 <            f.complete(v1);
1835 <        }
1826 >        final FailingBiConsumer r1 = new FailingBiConsumer(m);
1827 >        final FailingBiConsumer r2 = new FailingBiConsumer(m);
1828 >        final FailingBiConsumer r3 = new FailingBiConsumer(m);
1829 >
1830 >        final CompletableFuture<Integer> fst =  fFirst ? f : g;
1831 >        final CompletableFuture<Integer> snd = !fFirst ? f : g;
1832 >        final Integer w1 =  fFirst ? v1 : v2;
1833 >        final Integer w2 = !fFirst ? v1 : v2;
1834 >
1835 >        final CompletableFuture<Void> h1 = m.thenAcceptBoth(f, g, r1);
1836 >        assertTrue(fst.complete(w1));
1837 >        final CompletableFuture<Void> h2 = m.thenAcceptBoth(f, g, r2);
1838 >        assertTrue(snd.complete(w2));
1839 >        final CompletableFuture<Void> h3 = m.thenAcceptBoth(f, g, r3);
1840  
1841 <        checkCompletedWithWrappedCFException(h);
1841 >        checkCompletedWithWrappedCFException(h1);
1842 >        checkCompletedWithWrappedCFException(h2);
1843 >        checkCompletedWithWrappedCFException(h3);
1844          checkCompletedNormally(f, v1);
1845          checkCompletedNormally(g, v2);
1846      }}
# Line 1577 | Line 1860 | public class CompletableFutureTest exten
1860          final CompletableFuture<Integer> g = new CompletableFuture<>();
1861          final Noop r = new Noop(m);
1862  
1863 <        if (fFirst) f.complete(v1); else g.complete(v2);
1863 >        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1864          if (!createIncomplete)
1865 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1865 >            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1866          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1867          if (createIncomplete) {
1868              checkIncomplete(h);
1869              r.assertNotInvoked();
1870 <            if (!fFirst) f.complete(v1); else g.complete(v2);
1870 >            assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1871          }
1872  
1873          checkCompletedNormally(h, null);
# Line 1608 | Line 1891 | public class CompletableFutureTest exten
1891          final CFException ex = new CFException();
1892          final Noop r = new Noop(m);
1893  
1894 <        (fFirst ? f : g).complete(v1);
1894 >        assertTrue((fFirst ? f : g).complete(v1));
1895          if (!createIncomplete)
1896 <            (!fFirst ? f : g).completeExceptionally(ex);
1896 >            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1897          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1898          if (createIncomplete) {
1899              checkIncomplete(h);
1900 <            (!fFirst ? f : g).completeExceptionally(ex);
1900 >            assertTrue((!fFirst ? f : g).completeExceptionally(ex));
1901          }
1902  
1903 <        checkCompletedWithWrappedCFException(h, ex);
1903 >        checkCompletedWithWrappedException(h, ex);
1904          r.assertNotInvoked();
1905          checkCompletedNormally(fFirst ? f : g, v1);
1906 <        checkCompletedWithWrappedCFException(!fFirst ? f : g, ex);
1906 >        checkCompletedExceptionally(!fFirst ? f : g, ex);
1907      }}
1908  
1909      /**
# Line 1637 | Line 1920 | public class CompletableFutureTest exten
1920          final CompletableFuture<Integer> g = new CompletableFuture<>();
1921          final Noop r = new Noop(m);
1922  
1923 <
1641 <        (fFirst ? f : g).complete(v1);
1923 >        assertTrue((fFirst ? f : g).complete(v1));
1924          if (!createIncomplete)
1925              assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning));
1926          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
# Line 1668 | Line 1950 | public class CompletableFutureTest exten
1950          final FailingRunnable r2 = new FailingRunnable(m);
1951  
1952          CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r1);
1953 <        if (fFirst) {
1954 <            f.complete(v1);
1673 <            g.complete(v2);
1674 <        } else {
1675 <            g.complete(v2);
1676 <            f.complete(v1);
1677 <        }
1953 >        assertTrue(fFirst ? f.complete(v1) : g.complete(v2));
1954 >        assertTrue(!fFirst ? f.complete(v1) : g.complete(v2));
1955          CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r2);
1956  
1957          checkCompletedWithWrappedCFException(h1);
# Line 1752 | Line 2029 | public class CompletableFutureTest exten
2029          rs[0].assertNotInvoked();
2030          rs[1].assertNotInvoked();
2031          f.completeExceptionally(ex);
2032 <        checkCompletedWithWrappedCFException(h0, ex);
2033 <        checkCompletedWithWrappedCFException(h1, ex);
2032 >        checkCompletedWithWrappedException(h0, ex);
2033 >        checkCompletedWithWrappedException(h1, ex);
2034          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
2035          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
2036 <        checkCompletedWithWrappedCFException(h2, ex);
2037 <        checkCompletedWithWrappedCFException(h3, ex);
2036 >        checkCompletedWithWrappedException(h2, ex);
2037 >        checkCompletedWithWrappedException(h3, ex);
2038          g.complete(v1);
2039  
2040          // unspecified behavior - both source completions available
# Line 1767 | Line 2044 | public class CompletableFutureTest exten
2044              assertEquals(inc(v1), h4.join());
2045              rs[4].assertValue(inc(v1));
2046          } catch (CompletionException ok) {
2047 <            checkCompletedWithWrappedCFException(h4, ex);
2047 >            checkCompletedWithWrappedException(h4, ex);
2048              rs[4].assertNotInvoked();
2049          }
2050          try {
2051              assertEquals(inc(v1), h5.join());
2052              rs[5].assertValue(inc(v1));
2053          } catch (CompletionException ok) {
2054 <            checkCompletedWithWrappedCFException(h5, ex);
2054 >            checkCompletedWithWrappedException(h5, ex);
2055              rs[5].assertNotInvoked();
2056          }
2057  
2058 <        checkCompletedWithWrappedCFException(f, ex);
2058 >        checkCompletedExceptionally(f, ex);
2059          checkCompletedNormally(g, v1);
2060 <        checkCompletedWithWrappedCFException(h0, ex);
2061 <        checkCompletedWithWrappedCFException(h1, ex);
2062 <        checkCompletedWithWrappedCFException(h2, ex);
2063 <        checkCompletedWithWrappedCFException(h3, ex);
2064 <        checkCompletedWithWrappedCFException(h4, ex);
2060 >        checkCompletedWithWrappedException(h0, ex);
2061 >        checkCompletedWithWrappedException(h1, ex);
2062 >        checkCompletedWithWrappedException(h2, ex);
2063 >        checkCompletedWithWrappedException(h3, ex);
2064 >        checkCompletedWithWrappedException(h4, ex);
2065          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2066      }}
2067  
# Line 1801 | Line 2078 | public class CompletableFutureTest exten
2078  
2079          final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
2080          final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
2081 <        if (fFirst) {
2082 <            f.complete(v1);
1806 <            g.completeExceptionally(ex);
1807 <        } else {
1808 <            g.completeExceptionally(ex);
1809 <            f.complete(v1);
1810 <        }
2081 >        assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2082 >        assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2083          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
2084          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
2085  
# Line 1816 | Line 2088 | public class CompletableFutureTest exten
2088              assertEquals(inc(v1), h0.join());
2089              rs[0].assertValue(inc(v1));
2090          } catch (CompletionException ok) {
2091 <            checkCompletedWithWrappedCFException(h0, ex);
2091 >            checkCompletedWithWrappedException(h0, ex);
2092              rs[0].assertNotInvoked();
2093          }
2094          try {
2095              assertEquals(inc(v1), h1.join());
2096              rs[1].assertValue(inc(v1));
2097          } catch (CompletionException ok) {
2098 <            checkCompletedWithWrappedCFException(h1, ex);
2098 >            checkCompletedWithWrappedException(h1, ex);
2099              rs[1].assertNotInvoked();
2100          }
2101          try {
2102              assertEquals(inc(v1), h2.join());
2103              rs[2].assertValue(inc(v1));
2104          } catch (CompletionException ok) {
2105 <            checkCompletedWithWrappedCFException(h2, ex);
2105 >            checkCompletedWithWrappedException(h2, ex);
2106              rs[2].assertNotInvoked();
2107          }
2108          try {
2109              assertEquals(inc(v1), h3.join());
2110              rs[3].assertValue(inc(v1));
2111          } catch (CompletionException ok) {
2112 <            checkCompletedWithWrappedCFException(h3, ex);
2112 >            checkCompletedWithWrappedException(h3, ex);
2113              rs[3].assertNotInvoked();
2114          }
2115  
2116          checkCompletedNormally(f, v1);
2117 <        checkCompletedWithWrappedCFException(g, ex);
2117 >        checkCompletedExceptionally(g, ex);
2118      }}
2119  
2120      /**
# Line 1913 | Line 2185 | public class CompletableFutureTest exten
2185  
2186          final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
2187          final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
2188 <        if (fFirst) {
2189 <            f.complete(v1);
1918 <            g.cancel(mayInterruptIfRunning);
1919 <        } else {
1920 <            g.cancel(mayInterruptIfRunning);
1921 <            f.complete(v1);
1922 <        }
2188 >        assertTrue(fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning));
2189 >        assertTrue(!fFirst ? f.complete(v1) : g.cancel(mayInterruptIfRunning));
2190          final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
2191          final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
2192  
# Line 2071 | Line 2338 | public class CompletableFutureTest exten
2338          rs[0].assertNotInvoked();
2339          rs[1].assertNotInvoked();
2340          f.completeExceptionally(ex);
2341 <        checkCompletedWithWrappedCFException(h0, ex);
2342 <        checkCompletedWithWrappedCFException(h1, ex);
2341 >        checkCompletedWithWrappedException(h0, ex);
2342 >        checkCompletedWithWrappedException(h1, ex);
2343          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2344          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2345 <        checkCompletedWithWrappedCFException(h2, ex);
2346 <        checkCompletedWithWrappedCFException(h3, ex);
2345 >        checkCompletedWithWrappedException(h2, ex);
2346 >        checkCompletedWithWrappedException(h3, ex);
2347  
2348          g.complete(v1);
2349  
# Line 2087 | Line 2354 | public class CompletableFutureTest exten
2354              assertNull(h4.join());
2355              rs[4].assertValue(v1);
2356          } catch (CompletionException ok) {
2357 <            checkCompletedWithWrappedCFException(h4, ex);
2357 >            checkCompletedWithWrappedException(h4, ex);
2358              rs[4].assertNotInvoked();
2359          }
2360          try {
2361              assertNull(h5.join());
2362              rs[5].assertValue(v1);
2363          } catch (CompletionException ok) {
2364 <            checkCompletedWithWrappedCFException(h5, ex);
2364 >            checkCompletedWithWrappedException(h5, ex);
2365              rs[5].assertNotInvoked();
2366          }
2367  
2368 <        checkCompletedWithWrappedCFException(f, ex);
2368 >        checkCompletedExceptionally(f, ex);
2369          checkCompletedNormally(g, v1);
2370 <        checkCompletedWithWrappedCFException(h0, ex);
2371 <        checkCompletedWithWrappedCFException(h1, ex);
2372 <        checkCompletedWithWrappedCFException(h2, ex);
2373 <        checkCompletedWithWrappedCFException(h3, ex);
2374 <        checkCompletedWithWrappedCFException(h4, ex);
2370 >        checkCompletedWithWrappedException(h0, ex);
2371 >        checkCompletedWithWrappedException(h1, ex);
2372 >        checkCompletedWithWrappedException(h2, ex);
2373 >        checkCompletedWithWrappedException(h3, ex);
2374 >        checkCompletedWithWrappedException(h4, ex);
2375          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2376      }}
2377  
# Line 2121 | Line 2388 | public class CompletableFutureTest exten
2388  
2389          final CompletableFuture<Void> h0 = m.acceptEither(f, g, rs[0]);
2390          final CompletableFuture<Void> h1 = m.acceptEither(g, f, rs[1]);
2391 <        if (fFirst) {
2392 <            f.complete(v1);
2126 <            g.completeExceptionally(ex);
2127 <        } else {
2128 <            g.completeExceptionally(ex);
2129 <            f.complete(v1);
2130 <        }
2391 >        assertTrue(fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2392 >        assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2393          final CompletableFuture<Void> h2 = m.acceptEither(f, g, rs[2]);
2394          final CompletableFuture<Void> h3 = m.acceptEither(g, f, rs[3]);
2395  
# Line 2136 | Line 2398 | public class CompletableFutureTest exten
2398              assertEquals(null, h0.join());
2399              rs[0].assertValue(v1);
2400          } catch (CompletionException ok) {
2401 <            checkCompletedWithWrappedCFException(h0, ex);
2401 >            checkCompletedWithWrappedException(h0, ex);
2402              rs[0].assertNotInvoked();
2403          }
2404          try {
2405              assertEquals(null, h1.join());
2406              rs[1].assertValue(v1);
2407          } catch (CompletionException ok) {
2408 <            checkCompletedWithWrappedCFException(h1, ex);
2408 >            checkCompletedWithWrappedException(h1, ex);
2409              rs[1].assertNotInvoked();
2410          }
2411          try {
2412              assertEquals(null, h2.join());
2413              rs[2].assertValue(v1);
2414          } catch (CompletionException ok) {
2415 <            checkCompletedWithWrappedCFException(h2, ex);
2415 >            checkCompletedWithWrappedException(h2, ex);
2416              rs[2].assertNotInvoked();
2417          }
2418          try {
2419              assertEquals(null, h3.join());
2420              rs[3].assertValue(v1);
2421          } catch (CompletionException ok) {
2422 <            checkCompletedWithWrappedCFException(h3, ex);
2422 >            checkCompletedWithWrappedException(h3, ex);
2423              rs[3].assertNotInvoked();
2424          }
2425  
2426          checkCompletedNormally(f, v1);
2427 <        checkCompletedWithWrappedCFException(g, ex);
2427 >        checkCompletedExceptionally(g, ex);
2428      }}
2429  
2430      /**
# Line 2330 | Line 2592 | public class CompletableFutureTest exten
2592          checkIncomplete(h1);
2593          rs[0].assertNotInvoked();
2594          rs[1].assertNotInvoked();
2595 <        f.completeExceptionally(ex);
2596 <        checkCompletedWithWrappedCFException(h0, ex);
2597 <        checkCompletedWithWrappedCFException(h1, ex);
2595 >        assertTrue(f.completeExceptionally(ex));
2596 >        checkCompletedWithWrappedException(h0, ex);
2597 >        checkCompletedWithWrappedException(h1, ex);
2598          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2599          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2600 <        checkCompletedWithWrappedCFException(h2, ex);
2601 <        checkCompletedWithWrappedCFException(h3, ex);
2600 >        checkCompletedWithWrappedException(h2, ex);
2601 >        checkCompletedWithWrappedException(h3, ex);
2602  
2603 <        g.complete(v1);
2603 >        assertTrue(g.complete(v1));
2604  
2605          // unspecified behavior - both source completions available
2606          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
# Line 2347 | Line 2609 | public class CompletableFutureTest exten
2609              assertNull(h4.join());
2610              rs[4].assertInvoked();
2611          } catch (CompletionException ok) {
2612 <            checkCompletedWithWrappedCFException(h4, ex);
2612 >            checkCompletedWithWrappedException(h4, ex);
2613              rs[4].assertNotInvoked();
2614          }
2615          try {
2616              assertNull(h5.join());
2617              rs[5].assertInvoked();
2618          } catch (CompletionException ok) {
2619 <            checkCompletedWithWrappedCFException(h5, ex);
2619 >            checkCompletedWithWrappedException(h5, ex);
2620              rs[5].assertNotInvoked();
2621          }
2622  
2623 <        checkCompletedWithWrappedCFException(f, ex);
2623 >        checkCompletedExceptionally(f, ex);
2624          checkCompletedNormally(g, v1);
2625 <        checkCompletedWithWrappedCFException(h0, ex);
2626 <        checkCompletedWithWrappedCFException(h1, ex);
2627 <        checkCompletedWithWrappedCFException(h2, ex);
2628 <        checkCompletedWithWrappedCFException(h3, ex);
2629 <        checkCompletedWithWrappedCFException(h4, ex);
2625 >        checkCompletedWithWrappedException(h0, ex);
2626 >        checkCompletedWithWrappedException(h1, ex);
2627 >        checkCompletedWithWrappedException(h2, ex);
2628 >        checkCompletedWithWrappedException(h3, ex);
2629 >        checkCompletedWithWrappedException(h4, ex);
2630          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
2631      }}
2632  
# Line 2381 | Line 2643 | public class CompletableFutureTest exten
2643  
2644          final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2645          final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2646 <        if (fFirst) {
2647 <            f.complete(v1);
2386 <            g.completeExceptionally(ex);
2387 <        } else {
2388 <            g.completeExceptionally(ex);
2389 <            f.complete(v1);
2390 <        }
2646 >        assertTrue( fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2647 >        assertTrue(!fFirst ? f.complete(v1) : g.completeExceptionally(ex));
2648          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2649          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2650  
# Line 2396 | Line 2653 | public class CompletableFutureTest exten
2653              assertEquals(null, h0.join());
2654              rs[0].assertInvoked();
2655          } catch (CompletionException ok) {
2656 <            checkCompletedWithWrappedCFException(h0, ex);
2656 >            checkCompletedWithWrappedException(h0, ex);
2657              rs[0].assertNotInvoked();
2658          }
2659          try {
2660              assertEquals(null, h1.join());
2661              rs[1].assertInvoked();
2662          } catch (CompletionException ok) {
2663 <            checkCompletedWithWrappedCFException(h1, ex);
2663 >            checkCompletedWithWrappedException(h1, ex);
2664              rs[1].assertNotInvoked();
2665          }
2666          try {
2667              assertEquals(null, h2.join());
2668              rs[2].assertInvoked();
2669          } catch (CompletionException ok) {
2670 <            checkCompletedWithWrappedCFException(h2, ex);
2670 >            checkCompletedWithWrappedException(h2, ex);
2671              rs[2].assertNotInvoked();
2672          }
2673          try {
2674              assertEquals(null, h3.join());
2675              rs[3].assertInvoked();
2676          } catch (CompletionException ok) {
2677 <            checkCompletedWithWrappedCFException(h3, ex);
2677 >            checkCompletedWithWrappedException(h3, ex);
2678              rs[3].assertNotInvoked();
2679          }
2680  
2681          checkCompletedNormally(f, v1);
2682 <        checkCompletedWithWrappedCFException(g, ex);
2682 >        checkCompletedExceptionally(g, ex);
2683      }}
2684  
2685      /**
# Line 2452 | Line 2709 | public class CompletableFutureTest exten
2709          checkCompletedWithWrappedCancellationException(h2);
2710          checkCompletedWithWrappedCancellationException(h3);
2711  
2712 <        g.complete(v1);
2712 >        assertTrue(g.complete(v1));
2713  
2714          // unspecified behavior - both source completions available
2715          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
# Line 2496 | Line 2753 | public class CompletableFutureTest exten
2753  
2754          final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
2755          final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
2756 <        f.complete(v1);
2756 >        assertTrue(f.complete(v1));
2757          final CompletableFuture<Void> h2 = m.runAfterEither(f, g, rs[2]);
2758          final CompletableFuture<Void> h3 = m.runAfterEither(g, f, rs[3]);
2759          checkCompletedWithWrappedCFException(h0);
# Line 2504 | Line 2761 | public class CompletableFutureTest exten
2761          checkCompletedWithWrappedCFException(h2);
2762          checkCompletedWithWrappedCFException(h3);
2763          for (int i = 0; i < 4; i++) rs[i].assertInvoked();
2764 <        g.complete(v2);
2764 >        assertTrue(g.complete(v2));
2765          final CompletableFuture<Void> h4 = m.runAfterEither(f, g, rs[4]);
2766          final CompletableFuture<Void> h5 = m.runAfterEither(g, f, rs[5]);
2767          checkCompletedWithWrappedCFException(h4);
# Line 2525 | Line 2782 | public class CompletableFutureTest exten
2782      {
2783          final CompletableFuture<Integer> f = new CompletableFuture<>();
2784          final CompletableFutureInc r = new CompletableFutureInc(m);
2785 <        if (!createIncomplete) f.complete(v1);
2785 >        if (!createIncomplete) assertTrue(f.complete(v1));
2786          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2787 <        if (createIncomplete) f.complete(v1);
2787 >        if (createIncomplete) assertTrue(f.complete(v1));
2788  
2789          checkCompletedNormally(g, inc(v1));
2790          checkCompletedNormally(f, v1);
# Line 2549 | Line 2806 | public class CompletableFutureTest exten
2806          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2807          if (createIncomplete) f.completeExceptionally(ex);
2808  
2809 <        checkCompletedWithWrappedCFException(g, ex);
2810 <        checkCompletedWithWrappedCFException(f, ex);
2809 >        checkCompletedWithWrappedException(g, ex);
2810 >        checkCompletedExceptionally(f, ex);
2811          r.assertNotInvoked();
2812      }}
2813  
# Line 2565 | Line 2822 | public class CompletableFutureTest exten
2822          final CompletableFuture<Integer> f = new CompletableFuture<>();
2823          final FailingCompletableFutureFunction r
2824              = new FailingCompletableFutureFunction(m);
2825 <        if (!createIncomplete) f.complete(v1);
2825 >        if (!createIncomplete) assertTrue(f.complete(v1));
2826          final CompletableFuture<Integer> g = m.thenCompose(f, r);
2827 <        if (createIncomplete) f.complete(v1);
2827 >        if (createIncomplete) assertTrue(f.complete(v1));
2828  
2829          checkCompletedWithWrappedCFException(g);
2830          checkCompletedNormally(f, v1);
# Line 2806 | Line 3063 | public class CompletableFutureTest exten
3063          assertSame(f, f.toCompletableFuture());
3064      }
3065  
3066 <    /**
3067 <     * whenComplete action executes on normal completion, propagating
3068 <     * source result.
3069 <     */
3070 <    public void testWhenComplete_normalCompletion1() {
3071 <        for (ExecutionMode m : ExecutionMode.values())
3072 <        for (boolean createIncomplete : new boolean[] { true, false })
3073 <        for (Integer v1 : new Integer[] { 1, null })
3074 <    {
3075 <        final AtomicInteger a = new AtomicInteger(0);
3076 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
3077 <        if (!createIncomplete) f.complete(v1);
3078 <        final CompletableFuture<Integer> g = m.whenComplete
3079 <            (f,
3080 <             (Integer x, Throwable t) -> {
3081 <                threadAssertSame(x, v1);
3082 <                threadAssertNull(t);
2826 <                a.getAndIncrement();
2827 <            });
2828 <        if (createIncomplete) f.complete(v1);
2829 <
2830 <        checkCompletedNormally(g, v1);
2831 <        checkCompletedNormally(f, v1);
2832 <        assertEquals(1, a.get());
2833 <    }}
2834 <
2835 <    /**
2836 <     * whenComplete action executes on exceptional completion, propagating
2837 <     * source result.
2838 <     */
2839 <    public void testWhenComplete_exceptionalCompletion() {
2840 <        for (ExecutionMode m : ExecutionMode.values())
2841 <        for (boolean createIncomplete : new boolean[] { true, false })
2842 <        for (Integer v1 : new Integer[] { 1, null })
2843 <    {
2844 <        final AtomicInteger a = new AtomicInteger(0);
2845 <        final CFException ex = new CFException();
2846 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2847 <        if (!createIncomplete) f.completeExceptionally(ex);
2848 <        final CompletableFuture<Integer> g = m.whenComplete
2849 <            (f,
2850 <             (Integer x, Throwable t) -> {
2851 <                threadAssertNull(x);
2852 <                threadAssertSame(t, ex);
2853 <                a.getAndIncrement();
2854 <            });
2855 <        if (createIncomplete) f.completeExceptionally(ex);
2856 <        checkCompletedWithWrappedCFException(f, ex);
2857 <        checkCompletedWithWrappedCFException(g, ex);
2858 <        assertEquals(1, a.get());
2859 <    }}
2860 <
2861 <    /**
2862 <     * whenComplete action executes on cancelled source, propagating
2863 <     * CancellationException.
2864 <     */
2865 <    public void testWhenComplete_sourceCancelled() {
2866 <        for (ExecutionMode m : ExecutionMode.values())
2867 <        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2868 <        for (boolean createIncomplete : new boolean[] { true, false })
2869 <    {
2870 <        final AtomicInteger a = new AtomicInteger(0);
2871 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2872 <        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2873 <        final CompletableFuture<Integer> g = m.whenComplete
2874 <            (f,
2875 <             (Integer x, Throwable t) -> {
2876 <                threadAssertNull(x);
2877 <                threadAssertTrue(t instanceof CancellationException);
2878 <                a.getAndIncrement();
2879 <            });
2880 <        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2881 <
2882 <        //try { g.join(); } catch (Throwable t) { throw new Error(t); }
2883 <        checkCompletedWithWrappedCancellationException(g);
2884 <        checkCancelled(f);
2885 <        assertEquals(1, a.get());
2886 <    }}
2887 <
2888 <    /**
2889 <     * If a whenComplete action throws an exception when triggered by
2890 <     * a normal completion, it completes exceptionally
2891 <     */
2892 <    public void testWhenComplete_actionFailed() {
2893 <        for (boolean createIncomplete : new boolean[] { true, false })
2894 <        for (ExecutionMode m : ExecutionMode.values())
2895 <        for (Integer v1 : new Integer[] { 1, null })
2896 <    {
2897 <        final AtomicInteger a = new AtomicInteger(0);
2898 <        final CFException ex = new CFException();
2899 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2900 <        if (!createIncomplete) f.complete(v1);
2901 <        final CompletableFuture<Integer> g = m.whenComplete
2902 <            (f,
2903 <             (Integer x, Throwable t) -> {
2904 <                threadAssertSame(x, v1);
2905 <                threadAssertNull(t);
2906 <                a.getAndIncrement();
2907 <                throw ex;
2908 <            });
2909 <        if (createIncomplete) f.complete(v1);
2910 <        checkCompletedNormally(f, v1);
2911 <        checkCompletedWithWrappedCFException(g, ex);
2912 <        assertEquals(1, a.get());
2913 <    }}
2914 <
2915 <    /**
2916 <     * If a whenComplete action throws an exception when triggered by
2917 <     * a source completion that also throws an exception, the source
2918 <     * exception takes precedence.
2919 <     */
2920 <    public void testWhenComplete_actionFailedSourceFailed() {
2921 <        for (boolean createIncomplete : new boolean[] { true, false })
2922 <        for (ExecutionMode m : ExecutionMode.values())
2923 <        for (Integer v1 : new Integer[] { 1, null })
2924 <    {
2925 <        final AtomicInteger a = new AtomicInteger(0);
2926 <        final CFException ex1 = new CFException();
2927 <        final CFException ex2 = new CFException();
2928 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
2929 <
2930 <        if (!createIncomplete) f.completeExceptionally(ex1);
2931 <        final CompletableFuture<Integer> g = m.whenComplete
2932 <            (f,
2933 <             (Integer x, Throwable t) -> {
2934 <                threadAssertSame(t, ex1);
2935 <                threadAssertNull(x);
2936 <                a.getAndIncrement();
2937 <                throw ex2;
2938 <            });
2939 <        if (createIncomplete) f.completeExceptionally(ex1);
2940 <
2941 <        checkCompletedWithWrappedCFException(f, ex1);
2942 <        checkCompletedWithWrappedCFException(g, ex1);
2943 <        assertEquals(1, a.get());
2944 <    }}
3066 > //     public void testRunAfterEither_resultDeterminedAtTimeOfCreation() {
3067 > //         for (ExecutionMode m : ExecutionMode.values())
3068 > //         for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3069 > //         for (Integer v1 : new Integer[] { 1, null })
3070 > //     {
3071 > //         final CompletableFuture<Integer> f = new CompletableFuture<>();
3072 > //         final CompletableFuture<Integer> g = new CompletableFuture<>();
3073 > //         final Noop[] rs = new Noop[2];
3074 > //         for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
3075 > //         f.complete(v1);
3076 > //         final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
3077 > //         final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
3078 > //         assertTrue(g.cancel(mayInterruptIfRunning));
3079 > //         checkCompletedNormally(h0, null);
3080 > //         checkCompletedNormally(h1, null);
3081 > //         for (Noop r : rs) r.assertInvoked();
3082 > //     }}
3083  
3084   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines