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.39 by jsr166, Mon Jun 2 00:46:52 2014 UTC vs.
Revision 1.45 by jsr166, Mon Jun 2 06:07:34 2014 UTC

# Line 339 | Line 339 | public class CompletableFutureTest exten
339      static final class IncAction implements Consumer<Integer> {
340          int invocationCount = 0;
341          Integer value;
342        public boolean ran() { return invocationCount == 1; }
342          public void accept(Integer x) {
343              invocationCount++;
344              value = inc(x);
# Line 348 | Line 347 | public class CompletableFutureTest exten
347      static final class IncFunction implements Function<Integer,Integer> {
348          int invocationCount = 0;
349          Integer value;
351        public boolean ran() { return invocationCount == 1; }
350          public Integer apply(Integer x) {
351              invocationCount++;
352              return value = inc(x);
# Line 358 | Line 356 | public class CompletableFutureTest exten
356          int invocationCount = 0;
357          Integer value;
358          // Check this action was invoked exactly once when result is computed.
361        public boolean ran() { return invocationCount == 1; }
359          public void accept(Integer x, Integer y) {
360              invocationCount++;
361              value = subtract(x, y);
# Line 368 | Line 365 | public class CompletableFutureTest exten
365          int invocationCount = 0;
366          Integer value;
367          // Check this action was invoked exactly once when result is computed.
371        public boolean ran() { return invocationCount == 1; }
368          public Integer apply(Integer x, Integer y) {
369              invocationCount++;
370              return value = subtract(x, y);
371          }
372      }
373      static final class Noop implements Runnable {
374 <        boolean ran;
375 <        public void run() { ran = true; }
374 >        int invocationCount = 0;
375 >        public void run() {
376 >            invocationCount++;
377 >        }
378      }
379  
380      static final class FailingSupplier implements Supplier<Integer> {
381 <        boolean ran;
382 <        public Integer get() { ran = true; throw new CFException(); }
381 >        int invocationCount = 0;
382 >        public Integer get() {
383 >            invocationCount++;
384 >            throw new CFException();
385 >        }
386      }
387      static final class FailingConsumer implements Consumer<Integer> {
388 <        boolean ran;
389 <        public void accept(Integer x) { ran = true; throw new CFException(); }
388 >        int invocationCount = 0;
389 >        public void accept(Integer x) {
390 >            invocationCount++;
391 >            throw new CFException();
392 >        }
393      }
394      static final class FailingBiConsumer implements BiConsumer<Integer, Integer> {
395 <        boolean ran;
396 <        public void accept(Integer x, Integer y) { ran = true; throw new CFException(); }
395 >        int invocationCount = 0;
396 >        public void accept(Integer x, Integer y) {
397 >            invocationCount++;
398 >            throw new CFException();
399 >        }
400      }
401      static final class FailingFunction implements Function<Integer, Integer> {
402 <        boolean ran;
403 <        public Integer apply(Integer x) { ran = true; throw new CFException(); }
402 >        int invocationCount = 0;
403 >        public Integer apply(Integer x) {
404 >            invocationCount++;
405 >            throw new CFException();
406 >        }
407      }
408      static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> {
409 <        boolean ran;
410 <        public Integer apply(Integer x, Integer y) { ran = true; throw new CFException(); }
409 >        int invocationCount = 0;
410 >        public Integer apply(Integer x, Integer y) {
411 >            invocationCount++;
412 >            throw new CFException();
413 >        }
414      }
415      static final class FailingNoop implements Runnable {
416 <        boolean ran;
417 <        public void run() { ran = true; throw new CFException(); }
416 >        int invocationCount = 0;
417 >        public void run() {
418 >            invocationCount++;
419 >            throw new CFException();
420 >        }
421      }
422  
423      static final class CompletableFutureInc
424          implements Function<Integer, CompletableFuture<Integer>> {
425 <        boolean ran;
425 >        int invocationCount = 0;
426          public CompletableFuture<Integer> apply(Integer x) {
427 <            ran = true;
427 >            invocationCount++;
428              CompletableFuture<Integer> f = new CompletableFuture<>();
429 <            f.complete(Integer.valueOf(x.intValue() + 1));
429 >            f.complete(inc(x));
430              return f;
431          }
432      }
433  
434      static final class FailingCompletableFutureFunction
435          implements Function<Integer, CompletableFuture<Integer>> {
436 <        boolean ran;
436 >        int invocationCount = 0;
437          public CompletableFuture<Integer> apply(Integer x) {
438 <            ran = true; throw new CFException();
438 >            invocationCount++;
439 >            throw new CFException();
440          }
441      }
442  
# Line 438 | Line 455 | public class CompletableFutureTest exten
455      }
456  
457      static final class IntegerHandler implements BiFunction<Integer, Throwable, Integer> {
458 <        boolean ran;
458 >        int invocationCount = 0;
459          public Integer apply(Integer x, Throwable t) {
460 <            ran = true;
460 >            invocationCount++;
461              return (t == null) ? two : three;
462          }
463      }
# Line 497 | Line 514 | public class CompletableFutureTest exten
514              }
515          },
516  
500 //             /** Experimental way to do more testing */
501 //         REVERSE_DEFAULT {
502 //             public <T,U> CompletableFuture<Void> runAfterBoth
503 //                 (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
504 //                 return g.runAfterBoth(f, a);
505 //             }
506 //             public <T,U> CompletableFuture<Void> thenAcceptBoth
507 //                 (CompletableFuture<T> f,
508 //                  CompletionStage<? extends U> g,
509 //                  BiConsumer<? super T,? super U> a) {
510 //                 return DEFAULT.thenAcceptBoth(f, g, a);
511 //             }
512 //         },
513
517          DEFAULT_ASYNC {
518              public <T,U> CompletableFuture<Void> runAfterBoth
519                  (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
# Line 558 | Line 561 | public class CompletableFutureTest exten
561              }
562          },
563  
561 //         REVERSE_DEFAULT_ASYNC {
562 //             public <T,U> CompletableFuture<Void> runAfterBoth
563 //                 (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
564 //                 return f.runAfterBothAsync(g, a);
565 //             }
566 //             public <T,U> CompletableFuture<Void> thenAcceptBoth
567 //                 (CompletableFuture<T> f,
568 //                  CompletionStage<? extends U> g,
569 //                  BiConsumer<? super T,? super U> a) {
570 //                 return DEFAULT_ASYNC.thenAcceptBoth(f, g, a);
571 //             }
572 //         },
573
564          EXECUTOR {
565              public <T,U> CompletableFuture<Void> runAfterBoth
566                  (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) {
# Line 679 | Line 669 | public class CompletableFutureTest exten
669          f = new CompletableFuture<>();
670          f.completeExceptionally(new CFException());
671          g = f.handle(r = new IntegerHandler());
672 <        assertTrue(r.ran);
672 >        assertEquals(1, r.invocationCount);
673 >        assertEquals(1, r.invocationCount);
674          checkCompletedNormally(g, three);
675  
676          f = new CompletableFuture<>();
677          g = f.handle(r = new IntegerHandler());
678 <        assertFalse(r.ran);
678 >        assertEquals(0, r.invocationCount);
679          f.completeExceptionally(new CFException());
680          checkCompletedNormally(g, three);
681 <        assertTrue(r.ran);
681 >        assertEquals(1, r.invocationCount);
682  
683          f = new CompletableFuture<>();
684          f.complete(one);
685          g = f.handle(r = new IntegerHandler());
686 <        assertTrue(r.ran);
686 >        assertEquals(1, r.invocationCount);
687          checkCompletedNormally(g, two);
688  
689          f = new CompletableFuture<>();
690          g = f.handle(r = new IntegerHandler());
691 <        assertFalse(r.ran);
691 >        assertEquals(0, r.invocationCount);
692          f.complete(one);
693 <        assertTrue(r.ran);
693 >        assertEquals(1, r.invocationCount);
694          checkCompletedNormally(g, two);
695      }
696  
# Line 710 | Line 701 | public class CompletableFutureTest exten
701          Noop r = new Noop();
702          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
703          assertNull(f.join());
704 <        assertTrue(r.ran);
704 >        assertEquals(1, r.invocationCount);
705          checkCompletedNormally(f, null);
706      }
707  
# Line 722 | Line 713 | public class CompletableFutureTest exten
713          ThreadExecutor exec = new ThreadExecutor();
714          CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
715          assertNull(f.join());
716 <        assertTrue(r.ran);
716 >        assertEquals(1, r.invocationCount);
717          checkCompletedNormally(f, null);
718          assertEquals(1, exec.count.get());
719      }
# Line 734 | Line 725 | public class CompletableFutureTest exten
725          FailingNoop r = new FailingNoop();
726          CompletableFuture<Void> f = CompletableFuture.runAsync(r);
727          checkCompletedWithWrappedCFException(f);
728 <        assertTrue(r.ran);
728 >        assertEquals(1, r.invocationCount);
729      }
730  
731      /**
# Line 764 | Line 755 | public class CompletableFutureTest exten
755          FailingSupplier r = new FailingSupplier();
756          CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r);
757          checkCompletedWithWrappedCFException(f);
758 <        assertTrue(r.ran);
758 >        assertEquals(1, r.invocationCount);
759      }
760  
761      // seq completion methods
# Line 781 | Line 772 | public class CompletableFutureTest exten
772          g = f.thenRun(r = new Noop());
773          f.complete(null);
774          checkCompletedNormally(g, null);
775 <        assertTrue(r.ran);
775 >        assertEquals(1, r.invocationCount);
776  
777          f = new CompletableFuture<>();
778          f.complete(null);
779          g = f.thenRun(r = new Noop());
780          checkCompletedNormally(g, null);
781 <        assertTrue(r.ran);
781 >        assertEquals(1, r.invocationCount);
782      }
783  
784      /**
# Line 803 | Line 794 | public class CompletableFutureTest exten
794          g = f.thenRun(r = new Noop());
795          f.completeExceptionally(new CFException());
796          checkCompletedWithWrappedCFException(g);
797 <        assertFalse(r.ran);
797 >        assertEquals(0, r.invocationCount);
798  
799          f = new CompletableFuture<>();
800          f.completeExceptionally(new CFException());
801          g = f.thenRun(r = new Noop());
802          checkCompletedWithWrappedCFException(g);
803 <        assertFalse(r.ran);
803 >        assertEquals(0, r.invocationCount);
804      }
805  
806      /**
# Line 924 | Line 915 | public class CompletableFutureTest exten
915          CompletableFuture<Void> g = f.thenAccept(r);
916          f.complete(one);
917          checkCompletedWithWrappedCFException(g);
918 <        assertTrue(r.ran);
918 >        assertEquals(1, r.invocationCount);
919      }
920  
921      /**
# Line 943 | Line 934 | public class CompletableFutureTest exten
934       * of sources
935       */
936      public void testThenCombine_normalCompletion1() {
937 +        for (boolean createIncomplete : new boolean[] { true, false })
938 +        for (boolean fFirst : new boolean[] { true, false })
939          for (ExecutionMode m : ExecutionMode.values())
940          for (Integer v1 : new Integer[] { 1, null })
941          for (Integer v2 : new Integer[] { 2, null }) {
# Line 950 | Line 943 | public class CompletableFutureTest exten
943          final CompletableFuture<Integer> f = new CompletableFuture<>();
944          final CompletableFuture<Integer> g = new CompletableFuture<>();
945          final SubtractFunction r = new SubtractFunction();
946 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
947 <
955 <        f.complete(v1);
956 <        checkIncomplete(h);
957 <        assertFalse(r.ran());
958 <        g.complete(v2);
959 <
960 <        checkCompletedNormally(h, subtract(v1, v2));
961 <        checkCompletedNormally(f, v1);
962 <        checkCompletedNormally(g, v2);
963 <        }
964 <    }
965 <
966 <    public void testThenCombine_normalCompletion2() {
967 <        for (ExecutionMode m : ExecutionMode.values())
968 <        for (Integer v1 : new Integer[] { 1, null })
969 <        for (Integer v2 : new Integer[] { 2, null }) {
970 <
971 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
972 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
973 <        final SubtractFunction r = new SubtractFunction();
974 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
975 <
976 <        g.complete(v2);
977 <        checkIncomplete(h);
978 <        assertFalse(r.ran());
979 <        f.complete(v1);
980 <
981 <        checkCompletedNormally(h, subtract(v1, v2));
982 <        checkCompletedNormally(f, v1);
983 <        checkCompletedNormally(g, v2);
984 <        }
985 <    }
986 <
987 <    public void testThenCombine_normalCompletion3() {
988 <        for (ExecutionMode m : ExecutionMode.values())
989 <        for (Integer v1 : new Integer[] { 1, null })
990 <        for (Integer v2 : new Integer[] { 2, null }) {
991 <
992 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
993 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
994 <        final SubtractFunction r = new SubtractFunction();
946 >        CompletableFuture<Integer> h = null;
947 >        if (createIncomplete) h = m.thenCombine(f, g, r);
948  
949 <        g.complete(v2);
950 <        f.complete(v1);
951 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
952 <
953 <        checkCompletedNormally(h, subtract(v1, v2));
954 <        checkCompletedNormally(f, v1);
955 <        checkCompletedNormally(g, v2);
956 <        }
957 <    }
958 <
959 <    public void testThenCombine_normalCompletion4() {
1007 <        for (ExecutionMode m : ExecutionMode.values())
1008 <        for (Integer v1 : new Integer[] { 1, null })
1009 <        for (Integer v2 : new Integer[] { 2, null }) {
1010 <
1011 <        final CompletableFuture<Integer> f = new CompletableFuture<>();
1012 <        final CompletableFuture<Integer> g = new CompletableFuture<>();
1013 <        final SubtractFunction r = new SubtractFunction();
1014 <
1015 <        f.complete(v1);
1016 <        g.complete(v2);
1017 <        final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
949 >        if (fFirst)
950 >            f.complete(v1);
951 >        else
952 >            g.complete(v2);
953 >        if (createIncomplete) checkIncomplete(h);
954 >        assertEquals(0, r.invocationCount);
955 >        if (!fFirst)
956 >            f.complete(v1);
957 >        else
958 >            g.complete(v2);
959 >        if (!createIncomplete) h = m.thenCombine(f, g, r);
960  
961          checkCompletedNormally(h, subtract(v1, v2));
962          checkCompletedNormally(f, v1);
963          checkCompletedNormally(g, v2);
964 +        assertEquals(1, r.invocationCount);
965          }
966      }
967  
# Line 1042 | Line 985 | public class CompletableFutureTest exten
985  
986          checkCompletedWithWrappedCFException(h, ex);
987          checkCompletedWithWrappedCFException(f, ex);
988 <        assertFalse(r.ran());
988 >        assertEquals(0, r.invocationCount);
989          checkCompletedNormally(g, v1);
990          }
991      }
# Line 1063 | Line 1006 | public class CompletableFutureTest exten
1006  
1007          checkCompletedWithWrappedCFException(h, ex);
1008          checkCompletedWithWrappedCFException(g, ex);
1009 <        assertFalse(r.ran());
1009 >        assertEquals(0, r.invocationCount);
1010          checkCompletedNormally(f, v1);
1011          }
1012      }
# Line 1083 | Line 1026 | public class CompletableFutureTest exten
1026  
1027          checkCompletedWithWrappedCFException(h, ex);
1028          checkCompletedWithWrappedCFException(g, ex);
1029 <        assertFalse(r.ran());
1029 >        assertEquals(0, r.invocationCount);
1030          checkCompletedNormally(f, v1);
1031          }
1032      }
# Line 1103 | Line 1046 | public class CompletableFutureTest exten
1046  
1047          checkCompletedWithWrappedCFException(h, ex);
1048          checkCompletedWithWrappedCFException(f, ex);
1049 <        assertFalse(r.ran());
1049 >        assertEquals(0, r.invocationCount);
1050          checkCompletedNormally(g, v1);
1051          }
1052      }
# Line 1170 | Line 1113 | public class CompletableFutureTest exten
1113  
1114          checkCompletedWithWrappedCancellationException(h);
1115          checkCancelled(f);
1116 <        assertFalse(r.ran());
1116 >        assertEquals(0, r.invocationCount);
1117          checkCompletedNormally(g, v1);
1118          }
1119      }
# Line 1191 | Line 1134 | public class CompletableFutureTest exten
1134  
1135          checkCompletedWithWrappedCancellationException(h);
1136          checkCancelled(g);
1137 <        assertFalse(r.ran());
1137 >        assertEquals(0, r.invocationCount);
1138          checkCompletedNormally(f, v1);
1139          }
1140      }
# Line 1211 | Line 1154 | public class CompletableFutureTest exten
1154  
1155          checkCompletedWithWrappedCancellationException(h);
1156          checkCancelled(g);
1157 <        assertFalse(r.ran());
1157 >        assertEquals(0, r.invocationCount);
1158          checkCompletedNormally(f, v1);
1159          }
1160      }
# Line 1231 | Line 1174 | public class CompletableFutureTest exten
1174  
1175          checkCompletedWithWrappedCancellationException(h);
1176          checkCancelled(f);
1177 <        assertFalse(r.ran());
1177 >        assertEquals(0, r.invocationCount);
1178          checkCompletedNormally(g, v1);
1179          }
1180      }
# Line 1252 | Line 1195 | public class CompletableFutureTest exten
1195  
1196          f.complete(v1);
1197          checkIncomplete(h);
1198 <        assertFalse(r.ran());
1198 >        assertEquals(0, r.invocationCount);
1199          g.complete(v2);
1200  
1201          checkCompletedNormally(h, null);
# Line 1274 | Line 1217 | public class CompletableFutureTest exten
1217  
1218          g.complete(v2);
1219          checkIncomplete(h);
1220 <        assertFalse(r.ran());
1220 >        assertEquals(0, r.invocationCount);
1221          f.complete(v1);
1222  
1223          checkCompletedNormally(h, null);
# Line 1344 | Line 1287 | public class CompletableFutureTest exten
1287  
1288          checkCompletedWithWrappedCFException(h, ex);
1289          checkCompletedWithWrappedCFException(f, ex);
1290 <        assertFalse(r.ran());
1290 >        assertEquals(0, r.invocationCount);
1291          checkCompletedNormally(g, v1);
1292          }
1293      }
# Line 1365 | Line 1308 | public class CompletableFutureTest exten
1308  
1309          checkCompletedWithWrappedCFException(h, ex);
1310          checkCompletedWithWrappedCFException(g, ex);
1311 <        assertFalse(r.ran());
1311 >        assertEquals(0, r.invocationCount);
1312          checkCompletedNormally(f, v1);
1313          }
1314      }
# Line 1385 | Line 1328 | public class CompletableFutureTest exten
1328  
1329          checkCompletedWithWrappedCFException(h, ex);
1330          checkCompletedWithWrappedCFException(g, ex);
1331 <        assertFalse(r.ran());
1331 >        assertEquals(0, r.invocationCount);
1332          checkCompletedNormally(f, v1);
1333          }
1334      }
# Line 1405 | Line 1348 | public class CompletableFutureTest exten
1348  
1349          checkCompletedWithWrappedCFException(h, ex);
1350          checkCompletedWithWrappedCFException(f, ex);
1351 <        assertFalse(r.ran());
1351 >        assertEquals(0, r.invocationCount);
1352          checkCompletedNormally(g, v1);
1353          }
1354      }
# Line 1472 | Line 1415 | public class CompletableFutureTest exten
1415  
1416          checkCompletedWithWrappedCancellationException(h);
1417          checkCancelled(f);
1418 <        assertFalse(r.ran());
1418 >        assertEquals(0, r.invocationCount);
1419          checkCompletedNormally(g, v1);
1420          }
1421      }
# Line 1493 | Line 1436 | public class CompletableFutureTest exten
1436  
1437          checkCompletedWithWrappedCancellationException(h);
1438          checkCancelled(g);
1439 <        assertFalse(r.ran());
1439 >        assertEquals(0, r.invocationCount);
1440          checkCompletedNormally(f, v1);
1441          }
1442      }
# Line 1513 | Line 1456 | public class CompletableFutureTest exten
1456  
1457          checkCompletedWithWrappedCancellationException(h);
1458          checkCancelled(g);
1459 <        assertFalse(r.ran());
1459 >        assertEquals(0, r.invocationCount);
1460          checkCompletedNormally(f, v1);
1461          }
1462      }
# Line 1533 | Line 1476 | public class CompletableFutureTest exten
1476  
1477          checkCompletedWithWrappedCancellationException(h);
1478          checkCancelled(f);
1479 <        assertFalse(r.ran());
1479 >        assertEquals(0, r.invocationCount);
1480          checkCompletedNormally(g, v1);
1481          }
1482      }
# Line 1554 | Line 1497 | public class CompletableFutureTest exten
1497  
1498          f.complete(v1);
1499          checkIncomplete(h);
1500 <        assertFalse(r.ran);
1500 >        assertEquals(0, r.invocationCount);
1501          g.complete(v2);
1502  
1503          checkCompletedNormally(h, null);
1504 <        assertTrue(r.ran);
1504 >        assertEquals(1, r.invocationCount);
1505          checkCompletedNormally(f, v1);
1506          checkCompletedNormally(g, v2);
1507          }
# Line 1576 | Line 1519 | public class CompletableFutureTest exten
1519  
1520          g.complete(v2);
1521          checkIncomplete(h);
1522 <        assertFalse(r.ran);
1522 >        assertEquals(0, r.invocationCount);
1523          f.complete(v1);
1524  
1525          checkCompletedNormally(h, null);
1526 <        assertTrue(r.ran);
1526 >        assertEquals(1, r.invocationCount);
1527          checkCompletedNormally(f, v1);
1528          checkCompletedNormally(g, v2);
1529          }
# Line 1600 | Line 1543 | public class CompletableFutureTest exten
1543          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1544  
1545          checkCompletedNormally(h, null);
1546 <        assertTrue(r.ran);
1546 >        assertEquals(1, r.invocationCount);
1547          checkCompletedNormally(f, v1);
1548          checkCompletedNormally(g, v2);
1549          }
# Line 1620 | Line 1563 | public class CompletableFutureTest exten
1563          final CompletableFuture<Void> h = m.runAfterBoth(f, g, r);
1564  
1565          checkCompletedNormally(h, null);
1566 <        assertTrue(r.ran);
1566 >        assertEquals(1, r.invocationCount);
1567          checkCompletedNormally(f, v1);
1568          checkCompletedNormally(g, v2);
1569          }
# Line 1646 | Line 1589 | public class CompletableFutureTest exten
1589  
1590          checkCompletedWithWrappedCFException(h, ex);
1591          checkCompletedWithWrappedCFException(f, ex);
1592 <        assertFalse(r.ran);
1592 >        assertEquals(0, r.invocationCount);
1593          checkCompletedNormally(g, v1);
1594          }
1595      }
# Line 1667 | Line 1610 | public class CompletableFutureTest exten
1610  
1611          checkCompletedWithWrappedCFException(h, ex);
1612          checkCompletedWithWrappedCFException(g, ex);
1613 <        assertFalse(r.ran);
1613 >        assertEquals(0, r.invocationCount);
1614          checkCompletedNormally(f, v1);
1615          }
1616      }
# Line 1687 | Line 1630 | public class CompletableFutureTest exten
1630  
1631          checkCompletedWithWrappedCFException(h, ex);
1632          checkCompletedWithWrappedCFException(g, ex);
1633 <        assertFalse(r.ran);
1633 >        assertEquals(0, r.invocationCount);
1634          checkCompletedNormally(f, v1);
1635          }
1636      }
# Line 1707 | Line 1650 | public class CompletableFutureTest exten
1650  
1651          checkCompletedWithWrappedCFException(h, ex);
1652          checkCompletedWithWrappedCFException(f, ex);
1653 <        assertFalse(r.ran);
1653 >        assertEquals(0, r.invocationCount);
1654          checkCompletedNormally(g, v1);
1655          }
1656      }
# Line 1774 | Line 1717 | public class CompletableFutureTest exten
1717  
1718          checkCompletedWithWrappedCancellationException(h);
1719          checkCancelled(f);
1720 <        assertFalse(r.ran);
1720 >        assertEquals(0, r.invocationCount);
1721          checkCompletedNormally(g, v1);
1722          }
1723      }
# Line 1795 | Line 1738 | public class CompletableFutureTest exten
1738  
1739          checkCompletedWithWrappedCancellationException(h);
1740          checkCancelled(g);
1741 <        assertFalse(r.ran);
1741 >        assertEquals(0, r.invocationCount);
1742          checkCompletedNormally(f, v1);
1743          }
1744      }
# Line 1815 | Line 1758 | public class CompletableFutureTest exten
1758  
1759          checkCompletedWithWrappedCancellationException(h);
1760          checkCancelled(g);
1761 <        assertFalse(r.ran);
1761 >        assertEquals(0, r.invocationCount);
1762          checkCompletedNormally(f, v1);
1763          }
1764      }
# Line 1835 | Line 1778 | public class CompletableFutureTest exten
1778  
1779          checkCompletedWithWrappedCancellationException(h);
1780          checkCancelled(f);
1781 <        assertFalse(r.ran);
1781 >        assertEquals(0, r.invocationCount);
1782          checkCompletedNormally(g, v1);
1783          }
1784      }
# Line 1902 | Line 1845 | public class CompletableFutureTest exten
1845          // unspecified behavior
1846          assertTrue(Objects.equals(h.join(), inc(v1)) ||
1847                     Objects.equals(h.join(), inc(v2)));
1848 +        assertEquals(1, r.invocationCount);
1849          }
1850      }
1851  
# Line 1923 | Line 1867 | public class CompletableFutureTest exten
1867          checkCompletedWithWrappedCFException(h, ex);
1868          g.complete(v1);
1869  
1870 <        assertFalse(r.ran());
1870 >        assertEquals(0, r.invocationCount);
1871          checkCompletedNormally(g, v1);
1872          checkCompletedWithWrappedCFException(f, ex);
1873          checkCompletedWithWrappedCFException(h, ex);
# Line 1944 | Line 1888 | public class CompletableFutureTest exten
1888          checkCompletedWithWrappedCFException(h, ex);
1889          f.complete(v1);
1890  
1891 <        assertFalse(r.ran());
1891 >        assertEquals(0, r.invocationCount);
1892          checkCompletedNormally(f, v1);
1893          checkCompletedWithWrappedCFException(g, ex);
1894          checkCompletedWithWrappedCFException(h, ex);
# Line 1968 | Line 1912 | public class CompletableFutureTest exten
1912          Integer v;
1913          try {
1914              assertEquals(h.join(), inc(v1));
1915 <            assertTrue(r.ran());
1915 >            assertEquals(1, r.invocationCount);
1916          } catch (CompletionException ok) {
1917              checkCompletedWithWrappedCFException(h, ex);
1918 <            assertFalse(r.ran());
1918 >            assertEquals(0, r.invocationCount);
1919          }
1920  
1921          checkCompletedWithWrappedCFException(g, ex);
# Line 1996 | Line 1940 | public class CompletableFutureTest exten
1940          Integer v;
1941          try {
1942              assertEquals(h.join(), inc(v1));
1943 <            assertTrue(r.ran());
1943 >            assertEquals(1, r.invocationCount);
1944          } catch (CompletionException ok) {
1945              checkCompletedWithWrappedCFException(h, ex);
1946 <            assertFalse(r.ran());
1946 >            assertEquals(0, r.invocationCount);
1947          }
1948  
1949          checkCompletedWithWrappedCFException(f, ex);
2006        assertFalse(r.ran());
1950          checkCompletedNormally(g, v1);
1951          }
1952      }
# Line 2065 | Line 2008 | public class CompletableFutureTest exten
2008          g.complete(v1);
2009  
2010          checkCancelled(f);
2011 <        assertFalse(r.ran());
2011 >        assertEquals(0, r.invocationCount);
2012          checkCompletedNormally(g, v1);
2013          checkCompletedWithWrappedCancellationException(h);
2014          }
# Line 2086 | Line 2029 | public class CompletableFutureTest exten
2029          f.complete(v1);
2030  
2031          checkCancelled(g);
2032 <        assertFalse(r.ran());
2032 >        assertEquals(0, r.invocationCount);
2033          checkCompletedNormally(f, v1);
2034          checkCompletedWithWrappedCancellationException(h);
2035          }
# Line 2109 | Line 2052 | public class CompletableFutureTest exten
2052          Integer v;
2053          try {
2054              assertEquals(h.join(), inc(v1));
2055 <            assertTrue(r.ran());
2055 >            assertEquals(1, r.invocationCount);
2056          } catch (CompletionException ok) {
2057              checkCompletedWithWrappedCancellationException(h);
2058 <            assertFalse(r.ran());
2058 >            assertEquals(0, r.invocationCount);
2059          }
2060  
2061          checkCancelled(g);
# Line 2137 | Line 2080 | public class CompletableFutureTest exten
2080          Integer v;
2081          try {
2082              assertEquals(h.join(), inc(v1));
2083 <            assertTrue(r.ran());
2083 >            assertEquals(1, r.invocationCount);
2084          } catch (CompletionException ok) {
2085              checkCompletedWithWrappedCancellationException(h);
2086 <            assertFalse(r.ran());
2086 >            assertEquals(0, r.invocationCount);
2087          }
2088  
2089          checkCancelled(f);
# Line 2152 | Line 2095 | public class CompletableFutureTest exten
2095       * acceptEither result completes normally after normal completion
2096       * of either source
2097       */
2098 <    public void testAcceptEither() {
2099 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2100 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2101 <        IncAction r = new IncAction();
2159 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2160 <        f.complete(one);
2161 <        checkCompletedNormally(g, null);
2162 <        f2.complete(one);
2163 <        checkCompletedNormally(g, null);
2164 <        assertEquals(r.value, (Integer) 2);
2098 >    public void testAcceptEither_normalCompletion1() {
2099 >        for (ExecutionMode m : ExecutionMode.values())
2100 >        for (Integer v1 : new Integer[] { 1, null })
2101 >        for (Integer v2 : new Integer[] { 2, null }) {
2102  
2103 <        r = new IncAction();
2104 <        f = new CompletableFuture<>();
2105 <        f.complete(one);
2106 <        f2 = new CompletableFuture<>();
2107 <        g = f.acceptEither(f2, r);
2108 <        checkCompletedNormally(g, null);
2109 <        assertEquals(r.value, (Integer) 2);
2103 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2104 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2105 >        final IncAction r = new IncAction();
2106 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2107 >
2108 >        f.complete(v1);
2109 >        checkCompletedNormally(h, null);
2110 >        assertEquals(r.value, inc(v1));
2111 >        g.complete(v2);
2112 >
2113 >        checkCompletedNormally(f, v1);
2114 >        checkCompletedNormally(g, v2);
2115 >        checkCompletedNormally(h, null);
2116 >        }
2117 >    }
2118 >
2119 >    public void testAcceptEither_normalCompletion2() {
2120 >        for (ExecutionMode m : ExecutionMode.values())
2121 >        for (Integer v1 : new Integer[] { 1, null })
2122 >        for (Integer v2 : new Integer[] { 2, null }) {
2123 >
2124 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2125 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2126 >        final IncAction r = new IncAction();
2127 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2128 >
2129 >        g.complete(v2);
2130 >        checkCompletedNormally(h, null);
2131 >        assertEquals(r.value, inc(v2));
2132 >        f.complete(v1);
2133 >
2134 >        checkCompletedNormally(f, v1);
2135 >        checkCompletedNormally(g, v2);
2136 >        checkCompletedNormally(h, null);
2137 >        }
2138 >    }
2139 >    public void testAcceptEither_normalCompletion3() {
2140 >        for (ExecutionMode m : ExecutionMode.values())
2141 >        for (Integer v1 : new Integer[] { 1, null })
2142 >        for (Integer v2 : new Integer[] { 2, null }) {
2143 >
2144 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2145 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2146 >        final IncAction r = new IncAction();
2147 >
2148 >        f.complete(v1);
2149 >        g.complete(v2);
2150 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2151 >
2152 >        checkCompletedNormally(h, null);
2153 >        checkCompletedNormally(f, v1);
2154 >        checkCompletedNormally(g, v2);
2155 >
2156 >        // unspecified behavior
2157 >        assertTrue(Objects.equals(r.value, inc(v1)) ||
2158 >                   Objects.equals(r.value, inc(v2)));
2159 >        }
2160      }
2161  
2162      /**
2163       * acceptEither result completes exceptionally after exceptional
2164       * completion of either source
2165       */
2166 <    public void testAcceptEither2() {
2167 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2168 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2182 <        IncAction r = new IncAction();
2183 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2184 <        f.completeExceptionally(new CFException());
2185 <        f2.complete(one);
2186 <        checkCompletedWithWrappedCFException(g);
2166 >    public void testAcceptEither_exceptionalCompletion1() {
2167 >        for (ExecutionMode m : ExecutionMode.values())
2168 >        for (Integer v1 : new Integer[] { 1, null }) {
2169  
2170 <        r = new IncAction();
2171 <        f = new CompletableFuture<>();
2172 <        f2 = new CompletableFuture<>();
2173 <        f2.completeExceptionally(new CFException());
2174 <        g = f.acceptEither(f2, r);
2175 <        checkCompletedWithWrappedCFException(g);
2170 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2171 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2172 >        final IncAction r = new IncAction();
2173 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2174 >        final CFException ex = new CFException();
2175 >
2176 >        f.completeExceptionally(ex);
2177 >        checkCompletedWithWrappedCFException(h, ex);
2178 >        g.complete(v1);
2179 >
2180 >        assertEquals(0, r.invocationCount);
2181 >        checkCompletedNormally(g, v1);
2182 >        checkCompletedWithWrappedCFException(f, ex);
2183 >        checkCompletedWithWrappedCFException(h, ex);
2184 >        }
2185 >    }
2186 >
2187 >    public void testAcceptEither_exceptionalCompletion2() {
2188 >        for (ExecutionMode m : ExecutionMode.values())
2189 >        for (Integer v1 : new Integer[] { 1, null }) {
2190 >
2191 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2192 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2193 >        final IncAction r = new IncAction();
2194 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2195 >        final CFException ex = new CFException();
2196 >
2197 >        g.completeExceptionally(ex);
2198 >        checkCompletedWithWrappedCFException(h, ex);
2199 >        f.complete(v1);
2200 >
2201 >        assertEquals(0, r.invocationCount);
2202 >        checkCompletedNormally(f, v1);
2203 >        checkCompletedWithWrappedCFException(g, ex);
2204 >        checkCompletedWithWrappedCFException(h, ex);
2205 >        }
2206 >    }
2207 >
2208 >    public void testAcceptEither_exceptionalCompletion3() {
2209 >        for (ExecutionMode m : ExecutionMode.values())
2210 >        for (Integer v1 : new Integer[] { 1, null }) {
2211 >
2212 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2213 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2214 >        final IncAction r = new IncAction();
2215 >        final CFException ex = new CFException();
2216 >
2217 >        g.completeExceptionally(ex);
2218 >        f.complete(v1);
2219 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2220 >
2221 >        // unspecified behavior
2222 >        Integer v;
2223 >        try {
2224 >            assertEquals(h.join(), null);
2225 >            assertEquals(1, r.invocationCount);
2226 >            assertEquals(inc(v1), r.value);
2227 >        } catch (CompletionException ok) {
2228 >            checkCompletedWithWrappedCFException(h, ex);
2229 >            assertEquals(0, r.invocationCount);
2230 >        }
2231 >
2232 >        checkCompletedWithWrappedCFException(g, ex);
2233 >        checkCompletedNormally(f, v1);
2234 >        }
2235 >    }
2236 >
2237 >    public void testAcceptEither_exceptionalCompletion4() {
2238 >        for (ExecutionMode m : ExecutionMode.values())
2239 >        for (Integer v1 : new Integer[] { 1, null }) {
2240 >
2241 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2242 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2243 >        final IncAction r = new IncAction();
2244 >        final CFException ex = new CFException();
2245 >
2246 >        f.completeExceptionally(ex);
2247 >        g.complete(v1);
2248 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2249 >
2250 >        // unspecified behavior
2251 >        Integer v;
2252 >        try {
2253 >            assertEquals(h.join(), null);
2254 >            assertEquals(1, r.invocationCount);
2255 >            assertEquals(inc(v1), r.value);
2256 >        } catch (CompletionException ok) {
2257 >            checkCompletedWithWrappedCFException(h, ex);
2258 >            assertEquals(0, r.invocationCount);
2259 >        }
2260 >
2261 >        checkCompletedWithWrappedCFException(f, ex);
2262 >        checkCompletedNormally(g, v1);
2263 >        }
2264      }
2265  
2266      /**
2267       * acceptEither result completes exceptionally if action does
2268       */
2269 <    public void testAcceptEither3() {
2270 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2271 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2272 <        FailingConsumer r = new FailingConsumer();
2273 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2274 <        f2.complete(two);
2275 <        checkCompletedWithWrappedCFException(g);
2269 >    public void testAcceptEither_actionFailed1() {
2270 >        for (ExecutionMode m : ExecutionMode.values())
2271 >        for (Integer v1 : new Integer[] { 1, null })
2272 >        for (Integer v2 : new Integer[] { 2, null }) {
2273 >
2274 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2275 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2276 >        final FailingConsumer r = new FailingConsumer();
2277 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2278 >
2279 >        f.complete(v1);
2280 >        checkCompletedWithWrappedCFException(h);
2281 >        g.complete(v2);
2282 >        checkCompletedNormally(f, v1);
2283 >        checkCompletedNormally(g, v2);
2284 >        }
2285 >    }
2286 >
2287 >    public void testAcceptEither_actionFailed2() {
2288 >        for (ExecutionMode m : ExecutionMode.values())
2289 >        for (Integer v1 : new Integer[] { 1, null })
2290 >        for (Integer v2 : new Integer[] { 2, null }) {
2291 >
2292 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2293 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2294 >        final FailingConsumer r = new FailingConsumer();
2295 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2296 >
2297 >        g.complete(v2);
2298 >        checkCompletedWithWrappedCFException(h);
2299 >        f.complete(v1);
2300 >        checkCompletedNormally(f, v1);
2301 >        checkCompletedNormally(g, v2);
2302 >        }
2303      }
2304  
2305      /**
2306       * acceptEither result completes exceptionally if either source cancelled
2307       */
2308 <    public void testAcceptEither4() {
2309 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2310 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2311 <        IncAction r = new IncAction();
2312 <        CompletableFuture<Void> g = f.acceptEither(f2, r);
2313 <        assertTrue(f.cancel(true));
2314 <        checkCompletedWithWrappedCancellationException(g);
2315 <        f = new CompletableFuture<>();
2316 <        f2 = new CompletableFuture<>();
2317 <        assertTrue(f2.cancel(true));
2318 <        checkCompletedWithWrappedCancellationException(g);
2308 >    public void testAcceptEither_sourceCancelled1() {
2309 >        for (ExecutionMode m : ExecutionMode.values())
2310 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2311 >        for (Integer v1 : new Integer[] { 1, null }) {
2312 >
2313 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2314 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2315 >        final IncAction r = new IncAction();
2316 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2317 >
2318 >        assertTrue(f.cancel(mayInterruptIfRunning));
2319 >        checkCompletedWithWrappedCancellationException(h);
2320 >        g.complete(v1);
2321 >
2322 >        checkCancelled(f);
2323 >        assertEquals(0, r.invocationCount);
2324 >        checkCompletedNormally(g, v1);
2325 >        checkCompletedWithWrappedCancellationException(h);
2326 >        }
2327 >    }
2328 >
2329 >    public void testAcceptEither_sourceCancelled2() {
2330 >        for (ExecutionMode m : ExecutionMode.values())
2331 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2332 >        for (Integer v1 : new Integer[] { 1, null }) {
2333 >
2334 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2335 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2336 >        final IncAction r = new IncAction();
2337 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2338 >
2339 >        assertTrue(g.cancel(mayInterruptIfRunning));
2340 >        checkCompletedWithWrappedCancellationException(h);
2341 >        f.complete(v1);
2342 >
2343 >        checkCancelled(g);
2344 >        assertEquals(0, r.invocationCount);
2345 >        checkCompletedNormally(f, v1);
2346 >        checkCompletedWithWrappedCancellationException(h);
2347 >        }
2348 >    }
2349 >
2350 >    public void testAcceptEither_sourceCancelled3() {
2351 >        for (ExecutionMode m : ExecutionMode.values())
2352 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2353 >        for (Integer v1 : new Integer[] { 1, null }) {
2354 >
2355 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2356 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2357 >        final IncAction r = new IncAction();
2358 >
2359 >        assertTrue(g.cancel(mayInterruptIfRunning));
2360 >        f.complete(v1);
2361 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2362 >
2363 >        // unspecified behavior
2364 >        Integer v;
2365 >        try {
2366 >            assertEquals(h.join(), null);
2367 >            assertEquals(1, r.invocationCount);
2368 >            assertEquals(inc(v1), r.value);
2369 >        } catch (CompletionException ok) {
2370 >            checkCompletedWithWrappedCancellationException(h);
2371 >            assertEquals(0, r.invocationCount);
2372 >        }
2373 >
2374 >        checkCancelled(g);
2375 >        checkCompletedNormally(f, v1);
2376 >        }
2377 >    }
2378 >
2379 >    public void testAcceptEither_sourceCancelled4() {
2380 >        for (ExecutionMode m : ExecutionMode.values())
2381 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2382 >        for (Integer v1 : new Integer[] { 1, null }) {
2383 >
2384 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2385 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2386 >        final IncAction r = new IncAction();
2387 >
2388 >        assertTrue(f.cancel(mayInterruptIfRunning));
2389 >        g.complete(v1);
2390 >        final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2391 >
2392 >        // unspecified behavior
2393 >        Integer v;
2394 >        try {
2395 >            assertEquals(h.join(), null);
2396 >            assertEquals(1, r.invocationCount);
2397 >            assertEquals(inc(v1), r.value);
2398 >        } catch (CompletionException ok) {
2399 >            checkCompletedWithWrappedCancellationException(h);
2400 >            assertEquals(0, r.invocationCount);
2401 >        }
2402 >
2403 >        checkCancelled(f);
2404 >        checkCompletedNormally(g, v1);
2405 >        }
2406      }
2407  
2408      /**
2409       * runAfterEither result completes normally after normal completion
2410       * of either source
2411       */
2412 <    public void testRunAfterEither() {
2413 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2414 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2415 <        Noop r = new Noop();
2232 <        CompletableFuture<Void> g = f.runAfterEither(f2, r);
2233 <        f.complete(one);
2234 <        checkCompletedNormally(g, null);
2235 <        f2.complete(one);
2236 <        checkCompletedNormally(g, null);
2237 <        assertTrue(r.ran);
2412 >    public void testRunAfterEither_normalCompletion1() {
2413 >        for (ExecutionMode m : ExecutionMode.values())
2414 >        for (Integer v1 : new Integer[] { 1, null })
2415 >        for (Integer v2 : new Integer[] { 2, null }) {
2416  
2417 <        r = new Noop();
2418 <        f = new CompletableFuture<>();
2419 <        f.complete(one);
2420 <        f2 = new CompletableFuture<>();
2421 <        g = f.runAfterEither(f2, r);
2422 <        checkCompletedNormally(g, null);
2423 <        assertTrue(r.ran);
2417 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2418 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2419 >        final Noop r = new Noop();
2420 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2421 >
2422 >        f.complete(v1);
2423 >        checkCompletedNormally(h, null);
2424 >        assertEquals(1, r.invocationCount);
2425 >        g.complete(v2);
2426 >
2427 >        checkCompletedNormally(f, v1);
2428 >        checkCompletedNormally(g, v2);
2429 >        checkCompletedNormally(h, null);
2430 >        assertEquals(1, r.invocationCount);
2431 >        }
2432 >    }
2433 >
2434 >    public void testRunAfterEither_normalCompletion2() {
2435 >        for (ExecutionMode m : ExecutionMode.values())
2436 >        for (Integer v1 : new Integer[] { 1, null })
2437 >        for (Integer v2 : new Integer[] { 2, null }) {
2438 >
2439 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2440 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2441 >        final Noop r = new Noop();
2442 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2443 >
2444 >        g.complete(v2);
2445 >        checkCompletedNormally(h, null);
2446 >        assertEquals(1, r.invocationCount);
2447 >        f.complete(v1);
2448 >
2449 >        checkCompletedNormally(f, v1);
2450 >        checkCompletedNormally(g, v2);
2451 >        checkCompletedNormally(h, null);
2452 >        assertEquals(1, r.invocationCount);
2453 >        }
2454 >    }
2455 >    public void testRunAfterEither_normalCompletion3() {
2456 >        for (ExecutionMode m : ExecutionMode.values())
2457 >        for (Integer v1 : new Integer[] { 1, null })
2458 >        for (Integer v2 : new Integer[] { 2, null }) {
2459 >
2460 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2461 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2462 >        final Noop r = new Noop();
2463 >
2464 >        f.complete(v1);
2465 >        g.complete(v2);
2466 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2467 >
2468 >        checkCompletedNormally(h, null);
2469 >        checkCompletedNormally(f, v1);
2470 >        checkCompletedNormally(g, v2);
2471 >        assertEquals(1, r.invocationCount);
2472 >        }
2473      }
2474  
2475      /**
2476       * runAfterEither result completes exceptionally after exceptional
2477       * completion of either source
2478       */
2479 <    public void testRunAfterEither2() {
2480 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2481 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2255 <        Noop r = new Noop();
2256 <        CompletableFuture<Void> g = f.runAfterEither(f2, r);
2257 <        f.completeExceptionally(new CFException());
2258 <        f2.complete(one);
2259 <        checkCompletedWithWrappedCFException(g);
2479 >    public void testRunAfterEither_exceptionalCompletion1() {
2480 >        for (ExecutionMode m : ExecutionMode.values())
2481 >        for (Integer v1 : new Integer[] { 1, null }) {
2482  
2483 <        r = new Noop();
2484 <        f = new CompletableFuture<>();
2485 <        f2 = new CompletableFuture<>();
2486 <        f2.completeExceptionally(new CFException());
2487 <        g = f.runAfterEither(f2, r);
2488 <        checkCompletedWithWrappedCFException(g);
2483 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2484 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2485 >        final Noop r = new Noop();
2486 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2487 >        final CFException ex = new CFException();
2488 >
2489 >        f.completeExceptionally(ex);
2490 >        checkCompletedWithWrappedCFException(h, ex);
2491 >        g.complete(v1);
2492 >
2493 >        assertEquals(0, r.invocationCount);
2494 >        checkCompletedNormally(g, v1);
2495 >        checkCompletedWithWrappedCFException(f, ex);
2496 >        checkCompletedWithWrappedCFException(h, ex);
2497 >        }
2498 >    }
2499 >
2500 >    public void testRunAfterEither_exceptionalCompletion2() {
2501 >        for (ExecutionMode m : ExecutionMode.values())
2502 >        for (Integer v1 : new Integer[] { 1, null }) {
2503 >
2504 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2505 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2506 >        final Noop r = new Noop();
2507 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2508 >        final CFException ex = new CFException();
2509 >
2510 >        g.completeExceptionally(ex);
2511 >        checkCompletedWithWrappedCFException(h, ex);
2512 >        f.complete(v1);
2513 >
2514 >        assertEquals(0, r.invocationCount);
2515 >        checkCompletedNormally(f, v1);
2516 >        checkCompletedWithWrappedCFException(g, ex);
2517 >        checkCompletedWithWrappedCFException(h, ex);
2518 >        }
2519 >    }
2520 >
2521 >    public void testRunAfterEither_exceptionalCompletion3() {
2522 >        for (ExecutionMode m : ExecutionMode.values())
2523 >        for (Integer v1 : new Integer[] { 1, null }) {
2524 >
2525 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2526 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2527 >        final Noop r = new Noop();
2528 >        final CFException ex = new CFException();
2529 >
2530 >        g.completeExceptionally(ex);
2531 >        f.complete(v1);
2532 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2533 >
2534 >        // unspecified behavior
2535 >        Integer v;
2536 >        try {
2537 >            assertEquals(h.join(), null);
2538 >            assertEquals(1, r.invocationCount);
2539 >        } catch (CompletionException ok) {
2540 >            checkCompletedWithWrappedCFException(h, ex);
2541 >            assertEquals(0, r.invocationCount);
2542 >        }
2543 >
2544 >        checkCompletedWithWrappedCFException(g, ex);
2545 >        checkCompletedNormally(f, v1);
2546 >        }
2547 >    }
2548 >
2549 >    public void testRunAfterEither_exceptionalCompletion4() {
2550 >        for (ExecutionMode m : ExecutionMode.values())
2551 >        for (Integer v1 : new Integer[] { 1, null }) {
2552 >
2553 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2554 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2555 >        final Noop r = new Noop();
2556 >        final CFException ex = new CFException();
2557 >
2558 >        f.completeExceptionally(ex);
2559 >        g.complete(v1);
2560 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2561 >
2562 >        // unspecified behavior
2563 >        Integer v;
2564 >        try {
2565 >            assertEquals(h.join(), null);
2566 >            assertEquals(1, r.invocationCount);
2567 >        } catch (CompletionException ok) {
2568 >            checkCompletedWithWrappedCFException(h, ex);
2569 >            assertEquals(0, r.invocationCount);
2570 >        }
2571 >
2572 >        checkCompletedWithWrappedCFException(f, ex);
2573 >        checkCompletedNormally(g, v1);
2574 >        }
2575      }
2576  
2577      /**
2578       * runAfterEither result completes exceptionally if action does
2579       */
2580 <    public void testRunAfterEither3() {
2581 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2582 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2583 <        FailingNoop r = new FailingNoop();
2584 <        CompletableFuture<Void> g = f.runAfterEither(f2, r);
2585 <        f2.complete(two);
2586 <        checkCompletedWithWrappedCFException(g);
2580 >    public void testRunAfterEither_actionFailed1() {
2581 >        for (ExecutionMode m : ExecutionMode.values())
2582 >        for (Integer v1 : new Integer[] { 1, null })
2583 >        for (Integer v2 : new Integer[] { 2, null }) {
2584 >
2585 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2586 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2587 >        final FailingNoop r = new FailingNoop();
2588 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2589 >
2590 >        f.complete(v1);
2591 >        checkCompletedWithWrappedCFException(h);
2592 >        g.complete(v2);
2593 >        checkCompletedNormally(f, v1);
2594 >        checkCompletedNormally(g, v2);
2595 >        }
2596 >    }
2597 >
2598 >    public void testRunAfterEither_actionFailed2() {
2599 >        for (ExecutionMode m : ExecutionMode.values())
2600 >        for (Integer v1 : new Integer[] { 1, null })
2601 >        for (Integer v2 : new Integer[] { 2, null }) {
2602 >
2603 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2604 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2605 >        final FailingNoop r = new FailingNoop();
2606 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2607 >
2608 >        g.complete(v2);
2609 >        checkCompletedWithWrappedCFException(h);
2610 >        f.complete(v1);
2611 >        checkCompletedNormally(f, v1);
2612 >        checkCompletedNormally(g, v2);
2613 >        }
2614      }
2615  
2616      /**
2617       * runAfterEither result completes exceptionally if either source cancelled
2618       */
2619 <    public void testRunAfterEither4() {
2620 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2621 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2622 <        Noop r = new Noop();
2623 <        CompletableFuture<Void> g = f.runAfterEither(f2, r);
2624 <        assertTrue(f.cancel(true));
2625 <        checkCompletedWithWrappedCancellationException(g);
2626 <        f = new CompletableFuture<>();
2627 <        f2 = new CompletableFuture<>();
2628 <        assertTrue(f2.cancel(true));
2629 <        checkCompletedWithWrappedCancellationException(g);
2619 >    public void testRunAfterEither_sourceCancelled1() {
2620 >        for (ExecutionMode m : ExecutionMode.values())
2621 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2622 >        for (Integer v1 : new Integer[] { 1, null }) {
2623 >
2624 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2625 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2626 >        final Noop r = new Noop();
2627 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2628 >
2629 >        assertTrue(f.cancel(mayInterruptIfRunning));
2630 >        checkCompletedWithWrappedCancellationException(h);
2631 >        g.complete(v1);
2632 >
2633 >        checkCancelled(f);
2634 >        assertEquals(0, r.invocationCount);
2635 >        checkCompletedNormally(g, v1);
2636 >        checkCompletedWithWrappedCancellationException(h);
2637 >        }
2638 >    }
2639 >
2640 >    public void testRunAfterEither_sourceCancelled2() {
2641 >        for (ExecutionMode m : ExecutionMode.values())
2642 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2643 >        for (Integer v1 : new Integer[] { 1, null }) {
2644 >
2645 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2646 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2647 >        final Noop r = new Noop();
2648 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2649 >
2650 >        assertTrue(g.cancel(mayInterruptIfRunning));
2651 >        checkCompletedWithWrappedCancellationException(h);
2652 >        f.complete(v1);
2653 >
2654 >        checkCancelled(g);
2655 >        assertEquals(0, r.invocationCount);
2656 >        checkCompletedNormally(f, v1);
2657 >        checkCompletedWithWrappedCancellationException(h);
2658 >        }
2659 >    }
2660 >
2661 >    public void testRunAfterEither_sourceCancelled3() {
2662 >        for (ExecutionMode m : ExecutionMode.values())
2663 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2664 >        for (Integer v1 : new Integer[] { 1, null }) {
2665 >
2666 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2667 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2668 >        final Noop r = new Noop();
2669 >
2670 >        assertTrue(g.cancel(mayInterruptIfRunning));
2671 >        f.complete(v1);
2672 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2673 >
2674 >        // unspecified behavior
2675 >        Integer v;
2676 >        try {
2677 >            assertEquals(h.join(), null);
2678 >            assertEquals(1, r.invocationCount);
2679 >        } catch (CompletionException ok) {
2680 >            checkCompletedWithWrappedCancellationException(h);
2681 >            assertEquals(0, r.invocationCount);
2682 >        }
2683 >
2684 >        checkCancelled(g);
2685 >        checkCompletedNormally(f, v1);
2686 >        }
2687 >    }
2688 >
2689 >    public void testRunAfterEither_sourceCancelled4() {
2690 >        for (ExecutionMode m : ExecutionMode.values())
2691 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2692 >        for (Integer v1 : new Integer[] { 1, null }) {
2693 >
2694 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2695 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2696 >        final Noop r = new Noop();
2697 >
2698 >        assertTrue(f.cancel(mayInterruptIfRunning));
2699 >        g.complete(v1);
2700 >        final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2701 >
2702 >        // unspecified behavior
2703 >        Integer v;
2704 >        try {
2705 >            assertEquals(h.join(), null);
2706 >            assertEquals(1, r.invocationCount);
2707 >        } catch (CompletionException ok) {
2708 >            checkCompletedWithWrappedCancellationException(h);
2709 >            assertEquals(0, r.invocationCount);
2710 >        }
2711 >
2712 >        checkCancelled(f);
2713 >        checkCompletedNormally(g, v1);
2714 >        }
2715      }
2716  
2717      /**
2718       * thenCompose result completes normally after normal completion of source
2719       */
2720 <    public void testThenCompose() {
2721 <        CompletableFuture<Integer> f, g;
2722 <        CompletableFutureInc r;
2720 >    public void testThenCompose_normalCompletion1() {
2721 >        for (ExecutionMode m : ExecutionMode.values())
2722 >        for (Integer v1 : new Integer[] { 1, null }) {
2723  
2724 <        f = new CompletableFuture<>();
2725 <        g = f.thenCompose(r = new CompletableFutureInc());
2726 <        f.complete(one);
2727 <        checkCompletedNormally(g, two);
2728 <        assertTrue(r.ran);
2724 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2725 >        final CompletableFutureInc r = new CompletableFutureInc();
2726 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2727 >        f.complete(v1);
2728 >        checkCompletedNormally(g, inc(v1));
2729 >        checkCompletedNormally(f, v1);
2730 >        assertEquals(1, r.invocationCount);
2731 >        }
2732 >    }
2733  
2734 <        f = new CompletableFuture<>();
2735 <        f.complete(one);
2736 <        g = f.thenCompose(r = new CompletableFutureInc());
2737 <        checkCompletedNormally(g, two);
2738 <        assertTrue(r.ran);
2734 >    public void testThenCompose_normalCompletion2() {
2735 >        for (ExecutionMode m : ExecutionMode.values())
2736 >        for (Integer v1 : new Integer[] { 1, null }) {
2737 >
2738 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2739 >        final CompletableFutureInc r = new CompletableFutureInc();
2740 >        f.complete(v1);
2741 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2742 >        checkCompletedNormally(g, inc(v1));
2743 >        checkCompletedNormally(f, v1);
2744 >        assertEquals(1, r.invocationCount);
2745 >        }
2746      }
2747  
2748      /**
2749       * thenCompose result completes exceptionally after exceptional
2750       * completion of source
2751       */
2752 <    public void testThenCompose2() {
2753 <        CompletableFuture<Integer> f, g;
2323 <        CompletableFutureInc r;
2752 >    public void testThenCompose_exceptionalCompletion1() {
2753 >        for (ExecutionMode m : ExecutionMode.values()) {
2754  
2755 <        f = new CompletableFuture<>();
2756 <        g = f.thenCompose(r = new CompletableFutureInc());
2757 <        f.completeExceptionally(new CFException());
2758 <        checkCompletedWithWrappedCFException(g);
2755 >        final CFException ex = new CFException();
2756 >        final CompletableFutureInc r = new CompletableFutureInc();
2757 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2758 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2759 >        f.completeExceptionally(ex);
2760 >        checkCompletedWithWrappedCFException(g, ex);
2761 >        checkCompletedWithWrappedCFException(f, ex);
2762 >        }
2763 >    }
2764  
2765 <        f = new CompletableFuture<>();
2766 <        f.completeExceptionally(new CFException());
2767 <        g = f.thenCompose(r = new CompletableFutureInc());
2768 <        checkCompletedWithWrappedCFException(g);
2765 >    public void testThenCompose_exceptionalCompletion2() {
2766 >        for (ExecutionMode m : ExecutionMode.values()) {
2767 >
2768 >        final CFException ex = new CFException();
2769 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2770 >        f.completeExceptionally(ex);
2771 >        final CompletableFutureInc r = new CompletableFutureInc();
2772 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2773 >        checkCompletedWithWrappedCFException(g, ex);
2774 >        checkCompletedWithWrappedCFException(f, ex);
2775 >        }
2776      }
2777  
2778      /**
2779       * thenCompose result completes exceptionally if action does
2780       */
2781 <    public void testThenCompose3() {
2782 <        CompletableFuture<Integer> f, g;
2783 <        FailingCompletableFutureFunction r;
2781 >    public void testThenCompose_actionFailed1() {
2782 >        for (ExecutionMode m : ExecutionMode.values())
2783 >        for (Integer v1 : new Integer[] { 1, null }) {
2784  
2785 <        f = new CompletableFuture<>();
2786 <        g = f.thenCompose(r = new FailingCompletableFutureFunction());
2787 <        f.complete(one);
2785 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2786 >        final FailingCompletableFutureFunction r
2787 >            = new FailingCompletableFutureFunction();
2788 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2789 >        f.complete(v1);
2790          checkCompletedWithWrappedCFException(g);
2791 +        checkCompletedNormally(f, v1);
2792 +        }
2793 +    }
2794  
2795 <        f = new CompletableFuture<>();
2796 <        f.complete(one);
2797 <        g = f.thenCompose(r = new FailingCompletableFutureFunction());
2795 >    public void testThenCompose_actionFailed2() {
2796 >        for (ExecutionMode m : ExecutionMode.values())
2797 >        for (Integer v1 : new Integer[] { 1, null }) {
2798 >
2799 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2800 >        f.complete(v1);
2801 >        final FailingCompletableFutureFunction r
2802 >            = new FailingCompletableFutureFunction();
2803 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2804          checkCompletedWithWrappedCFException(g);
2805 +        checkCompletedNormally(f, v1);
2806 +        }
2807      }
2808  
2809      /**
2810       * thenCompose result completes exceptionally if source cancelled
2811       */
2812 <    public void testThenCompose4() {
2813 <        CompletableFuture<Integer> f, g;
2814 <        CompletableFutureInc r;
2812 >    public void testThenCompose_sourceCancelled1() {
2813 >        for (ExecutionMode m : ExecutionMode.values())
2814 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
2815  
2816 <        f = new CompletableFuture<>();
2817 <        g = f.thenCompose(r = new CompletableFutureInc());
2818 <        assertTrue(f.cancel(true));
2816 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2817 >        final CompletableFutureInc r = new CompletableFutureInc();
2818 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2819 >        assertTrue(f.cancel(mayInterruptIfRunning));
2820          checkCompletedWithWrappedCancellationException(g);
2821 +        checkCancelled(f);
2822 +        }
2823 +    }
2824  
2825 <        f = new CompletableFuture<>();
2826 <        assertTrue(f.cancel(true));
2827 <        g = f.thenCompose(r = new CompletableFutureInc());
2825 >    public void testThenCompose_sourceCancelled2() {
2826 >        for (ExecutionMode m : ExecutionMode.values())
2827 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
2828 >
2829 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2830 >        assertTrue(f.cancel(mayInterruptIfRunning));
2831 >        final CompletableFutureInc r = new CompletableFutureInc();
2832 >        final CompletableFuture<Integer> g = f.thenCompose(r);
2833          checkCompletedWithWrappedCancellationException(g);
2834 +        checkCancelled(f);
2835 +        }
2836      }
2837  
2838      // asyncs
# Line 2516 | Line 2982 | public class CompletableFutureTest exten
2982          checkCompletedWithWrappedCancellationException(g);
2983      }
2984  
2519    /**
2520     * acceptEitherAsync result completes normally after normal
2521     * completion of sources
2522     */
2523    public void testAcceptEitherAsync() {
2524        CompletableFuture<Integer> f = new CompletableFuture<>();
2525        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2526        IncAction r = new IncAction();
2527        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2528        f.complete(one);
2529        checkCompletedNormally(g, null);
2530        assertEquals(r.value, (Integer) 2);
2531
2532        r = new IncAction();
2533        f = new CompletableFuture<>();
2534        f.complete(one);
2535        f2 = new CompletableFuture<>();
2536        g = f.acceptEitherAsync(f2, r);
2537        checkCompletedNormally(g, null);
2538        assertEquals(r.value, (Integer) 2);
2539    }
2540
2541    /**
2542     * acceptEitherAsync result completes exceptionally after exceptional
2543     * completion of source
2544     */
2545    public void testAcceptEitherAsync2() {
2546        CompletableFuture<Integer> f = new CompletableFuture<>();
2547        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2548        IncAction r = new IncAction();
2549        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2550        f.completeExceptionally(new CFException());
2551        checkCompletedWithWrappedCFException(g);
2552
2553        r = new IncAction();
2554        f = new CompletableFuture<>();
2555        f2 = new CompletableFuture<>();
2556        f2.completeExceptionally(new CFException());
2557        g = f.acceptEitherAsync(f2, r);
2558        f.complete(one);
2559        checkCompletedWithWrappedCFException(g);
2560    }
2561
2562    /**
2563     * acceptEitherAsync result completes exceptionally if action does
2564     */
2565    public void testAcceptEitherAsync3() {
2566        CompletableFuture<Integer> f = new CompletableFuture<>();
2567        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2568        FailingConsumer r = new FailingConsumer();
2569        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2570        f.complete(one);
2571        checkCompletedWithWrappedCFException(g);
2572    }
2573
2574    /**
2575     * acceptEitherAsync result completes exceptionally if either
2576     * source cancelled
2577     */
2578    public void testAcceptEitherAsync4() {
2579        CompletableFuture<Integer> f = new CompletableFuture<>();
2580        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2581        IncAction r = new IncAction();
2582        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2583        assertTrue(f.cancel(true));
2584        checkCompletedWithWrappedCancellationException(g);
2585
2586        r = new IncAction();
2587        f = new CompletableFuture<>();
2588        f2 = new CompletableFuture<>();
2589        assertTrue(f2.cancel(true));
2590        g = f.acceptEitherAsync(f2, r);
2591        checkCompletedWithWrappedCancellationException(g);
2592    }
2593
2594    /**
2595     * runAfterEitherAsync result completes normally after normal
2596     * completion of sources
2597     */
2598    public void testRunAfterEitherAsync() {
2599        CompletableFuture<Integer> f = new CompletableFuture<>();
2600        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2601        Noop r = new Noop();
2602        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2603        f.complete(one);
2604        checkCompletedNormally(g, null);
2605        assertTrue(r.ran);
2606
2607        r = new Noop();
2608        f = new CompletableFuture<>();
2609        f.complete(one);
2610        f2 = new CompletableFuture<>();
2611        g = f.runAfterEitherAsync(f2, r);
2612        checkCompletedNormally(g, null);
2613        assertTrue(r.ran);
2614    }
2615
2616    /**
2617     * runAfterEitherAsync result completes exceptionally after exceptional
2618     * completion of source
2619     */
2620    public void testRunAfterEitherAsync2() {
2621        CompletableFuture<Integer> f = new CompletableFuture<>();
2622        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2623        Noop r = new Noop();
2624        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2625        f.completeExceptionally(new CFException());
2626        checkCompletedWithWrappedCFException(g);
2627
2628        r = new Noop();
2629        f = new CompletableFuture<>();
2630        f2 = new CompletableFuture<>();
2631        f2.completeExceptionally(new CFException());
2632        g = f.runAfterEitherAsync(f2, r);
2633        f.complete(one);
2634        checkCompletedWithWrappedCFException(g);
2635    }
2636
2637    /**
2638     * runAfterEitherAsync result completes exceptionally if action does
2639     */
2640    public void testRunAfterEitherAsync3() {
2641        CompletableFuture<Integer> f = new CompletableFuture<>();
2642        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2643        FailingNoop r = new FailingNoop();
2644        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2645        f.complete(one);
2646        checkCompletedWithWrappedCFException(g);
2647    }
2648
2649    /**
2650     * runAfterEitherAsync result completes exceptionally if either
2651     * source cancelled
2652     */
2653    public void testRunAfterEitherAsync4() {
2654        CompletableFuture<Integer> f = new CompletableFuture<>();
2655        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2656        Noop r = new Noop();
2657        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r);
2658        assertTrue(f.cancel(true));
2659        checkCompletedWithWrappedCancellationException(g);
2660
2661        r = new Noop();
2662        f = new CompletableFuture<>();
2663        f2 = new CompletableFuture<>();
2664        assertTrue(f2.cancel(true));
2665        g = f.runAfterEitherAsync(f2, r);
2666        checkCompletedWithWrappedCancellationException(g);
2667    }
2668
2669    /**
2670     * thenComposeAsync result completes normally after normal
2671     * completion of source
2672     */
2673    public void testThenComposeAsync() {
2674        CompletableFuture<Integer> f, g;
2675        CompletableFutureInc r;
2676
2677        f = new CompletableFuture<>();
2678        g = f.thenComposeAsync(r = new CompletableFutureInc());
2679        f.complete(one);
2680        checkCompletedNormally(g, two);
2681
2682        f = new CompletableFuture<>();
2683        f.complete(one);
2684        g = f.thenComposeAsync(r = new CompletableFutureInc());
2685        checkCompletedNormally(g, two);
2686    }
2687
2688    /**
2689     * thenComposeAsync result completes exceptionally after
2690     * exceptional completion of source
2691     */
2692    public void testThenComposeAsync2() {
2693        CompletableFuture<Integer> f, g;
2694        CompletableFutureInc r;
2695
2696        f = new CompletableFuture<>();
2697        g = f.thenComposeAsync(r = new CompletableFutureInc());
2698        f.completeExceptionally(new CFException());
2699        checkCompletedWithWrappedCFException(g);
2700        assertFalse(r.ran);
2701
2702        f = new CompletableFuture<>();
2703        f.completeExceptionally(new CFException());
2704        g = f.thenComposeAsync(r = new CompletableFutureInc());
2705        checkCompletedWithWrappedCFException(g);
2706        assertFalse(r.ran);
2707    }
2708
2709    /**
2710     * thenComposeAsync result completes exceptionally if action does
2711     */
2712    public void testThenComposeAsync3() {
2713        CompletableFuture<Integer> f, g;
2714        FailingCompletableFutureFunction r;
2715
2716        f = new CompletableFuture<>();
2717        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2718        f.complete(one);
2719        checkCompletedWithWrappedCFException(g);
2720
2721        f = new CompletableFuture<>();
2722        f.complete(one);
2723        g = f.thenComposeAsync(r = new FailingCompletableFutureFunction());
2724        checkCompletedWithWrappedCFException(g);
2725    }
2726
2727    /**
2728     * thenComposeAsync result completes exceptionally if source cancelled
2729     */
2730    public void testThenComposeAsync4() {
2731        CompletableFuture<Integer> f, g;
2732        CompletableFutureInc r;
2733
2734        f = new CompletableFuture<>();
2735        g = f.thenComposeAsync(r = new CompletableFutureInc());
2736        assertTrue(f.cancel(true));
2737        checkCompletedWithWrappedCancellationException(g);
2738
2739        f = new CompletableFuture<>();
2740        assertTrue(f.cancel(true));
2741        g = f.thenComposeAsync(r = new CompletableFutureInc());
2742        checkCompletedWithWrappedCancellationException(g);
2743    }
2744
2985      // async with explicit executors
2986  
2987      /**
# Line 2889 | Line 3129 | public class CompletableFutureTest exten
3129          checkCompletedWithWrappedCancellationException(g);
3130      }
3131  
2892    /**
2893     * acceptEitherAsync result completes normally after normal
2894     * completion of sources
2895     */
2896    public void testAcceptEitherAsyncE() {
2897        CompletableFuture<Integer> f = new CompletableFuture<>();
2898        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2899        IncAction r = new IncAction();
2900        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2901        f.complete(one);
2902        checkCompletedNormally(g, null);
2903        assertEquals(r.value, (Integer) 2);
2904
2905        r = new IncAction();
2906        f = new CompletableFuture<>();
2907        f.complete(one);
2908        f2 = new CompletableFuture<>();
2909        g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2910        checkCompletedNormally(g, null);
2911        assertEquals(r.value, (Integer) 2);
2912    }
2913
2914    /**
2915     * acceptEitherAsync result completes exceptionally after exceptional
2916     * completion of source
2917     */
2918    public void testAcceptEitherAsync2E() {
2919        CompletableFuture<Integer> f = new CompletableFuture<>();
2920        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2921        IncAction r = new IncAction();
2922        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2923        f.completeExceptionally(new CFException());
2924        checkCompletedWithWrappedCFException(g);
2925
2926        r = new IncAction();
2927        f = new CompletableFuture<>();
2928        f2 = new CompletableFuture<>();
2929        f2.completeExceptionally(new CFException());
2930        g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2931        f.complete(one);
2932        checkCompletedWithWrappedCFException(g);
2933    }
2934
2935    /**
2936     * acceptEitherAsync result completes exceptionally if action does
2937     */
2938    public void testAcceptEitherAsync3E() {
2939        CompletableFuture<Integer> f = new CompletableFuture<>();
2940        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2941        FailingConsumer r = new FailingConsumer();
2942        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2943        f.complete(one);
2944        checkCompletedWithWrappedCFException(g);
2945    }
2946
2947    /**
2948     * acceptEitherAsync result completes exceptionally if either
2949     * source cancelled
2950     */
2951    public void testAcceptEitherAsync4E() {
2952        CompletableFuture<Integer> f = new CompletableFuture<>();
2953        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2954        IncAction r = new IncAction();
2955        CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2956        assertTrue(f.cancel(true));
2957        checkCompletedWithWrappedCancellationException(g);
2958
2959        r = new IncAction();
2960        f = new CompletableFuture<>();
2961        f2 = new CompletableFuture<>();
2962        assertTrue(f2.cancel(true));
2963        g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2964        checkCompletedWithWrappedCancellationException(g);
2965    }
2966
2967    /**
2968     * runAfterEitherAsync result completes normally after normal
2969     * completion of sources
2970     */
2971    public void testRunAfterEitherAsyncE() {
2972        CompletableFuture<Integer> f = new CompletableFuture<>();
2973        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2974        Noop r = new Noop();
2975        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2976        f.complete(one);
2977        checkCompletedNormally(g, null);
2978        assertTrue(r.ran);
2979
2980        r = new Noop();
2981        f = new CompletableFuture<>();
2982        f.complete(one);
2983        f2 = new CompletableFuture<>();
2984        g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2985        checkCompletedNormally(g, null);
2986        assertTrue(r.ran);
2987    }
2988
2989    /**
2990     * runAfterEitherAsync result completes exceptionally after exceptional
2991     * completion of source
2992     */
2993    public void testRunAfterEitherAsync2E() {
2994        CompletableFuture<Integer> f = new CompletableFuture<>();
2995        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2996        Noop r = new Noop();
2997        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
2998        f.completeExceptionally(new CFException());
2999        checkCompletedWithWrappedCFException(g);
3000
3001        r = new Noop();
3002        f = new CompletableFuture<>();
3003        f2 = new CompletableFuture<>();
3004        f2.completeExceptionally(new CFException());
3005        g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
3006        f.complete(one);
3007        checkCompletedWithWrappedCFException(g);
3008    }
3009
3010    /**
3011     * runAfterEitherAsync result completes exceptionally if action does
3012     */
3013    public void testRunAfterEitherAsync3E() {
3014        CompletableFuture<Integer> f = new CompletableFuture<>();
3015        CompletableFuture<Integer> f2 = new CompletableFuture<>();
3016        FailingNoop r = new FailingNoop();
3017        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
3018        f.complete(one);
3019        checkCompletedWithWrappedCFException(g);
3020    }
3021
3022    /**
3023     * runAfterEitherAsync result completes exceptionally if either
3024     * source cancelled
3025     */
3026    public void testRunAfterEitherAsync4E() {
3027        CompletableFuture<Integer> f = new CompletableFuture<>();
3028        CompletableFuture<Integer> f2 = new CompletableFuture<>();
3029        Noop r = new Noop();
3030        CompletableFuture<Void> g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
3031        assertTrue(f.cancel(true));
3032        checkCompletedWithWrappedCancellationException(g);
3033
3034        r = new Noop();
3035        f = new CompletableFuture<>();
3036        f2 = new CompletableFuture<>();
3037        assertTrue(f2.cancel(true));
3038        g = f.runAfterEitherAsync(f2, r, new ThreadExecutor());
3039        checkCompletedWithWrappedCancellationException(g);
3040    }
3041
3042    /**
3043     * thenComposeAsync result completes normally after normal
3044     * completion of source
3045     */
3046    public void testThenComposeAsyncE() {
3047        CompletableFuture<Integer> f = new CompletableFuture<>();
3048        CompletableFutureInc r = new CompletableFutureInc();
3049        CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3050        f.complete(one);
3051        checkCompletedNormally(g, two);
3052    }
3053
3054    /**
3055     * thenComposeAsync result completes exceptionally after
3056     * exceptional completion of source
3057     */
3058    public void testThenComposeAsync2E() {
3059        CompletableFuture<Integer> f = new CompletableFuture<>();
3060        CompletableFutureInc r = new CompletableFutureInc();
3061        CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3062        f.completeExceptionally(new CFException());
3063        checkCompletedWithWrappedCFException(g);
3064    }
3065
3066    /**
3067     * thenComposeAsync result completes exceptionally if action does
3068     */
3069    public void testThenComposeAsync3E() {
3070        CompletableFuture<Integer> f = new CompletableFuture<>();
3071        FailingCompletableFutureFunction r = new FailingCompletableFutureFunction();
3072        CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3073        f.complete(one);
3074        checkCompletedWithWrappedCFException(g);
3075    }
3076
3077    /**
3078     * thenComposeAsync result completes exceptionally if source cancelled
3079     */
3080    public void testThenComposeAsync4E() {
3081        CompletableFuture<Integer> f = new CompletableFuture<>();
3082        CompletableFutureInc r = new CompletableFutureInc();
3083        CompletableFuture<Integer> g = f.thenComposeAsync(r, new ThreadExecutor());
3084        assertTrue(f.cancel(true));
3085        checkCompletedWithWrappedCancellationException(g);
3086    }
3087
3132      // other static methods
3133  
3134      /**
# Line 3283 | Line 3327 | public class CompletableFutureTest exten
3327       * whenComplete action executes on normal completion, propagating
3328       * source result.
3329       */
3330 <    public void testWhenComplete1() {
3330 >    public void testWhenComplete_normalCompletion1() {
3331 >        for (boolean createIncomplete : new boolean[] { true, false })
3332 >        for (ExecutionMode m : ExecutionMode.values())
3333 >        for (Integer v1 : new Integer[] { 1, null }) {
3334 >
3335          final AtomicInteger a = new AtomicInteger();
3336 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3337 <        CompletableFuture<Integer> g =
3338 <            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3339 <        f.complete(three);
3340 <        checkCompletedNormally(f, three);
3341 <        checkCompletedNormally(g, three);
3336 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
3337 >        if (!createIncomplete) f.complete(v1);
3338 >        final CompletableFuture<Integer> g =
3339 >            m.whenComplete(f,
3340 >                           (Integer x, Throwable t) -> {
3341 >                               threadAssertSame(x, v1);
3342 >                               threadAssertNull(t);
3343 >                               a.getAndIncrement();
3344 >                           });
3345 >        if (createIncomplete) f.complete(v1);
3346 >        checkCompletedNormally(f, v1);
3347 >        checkCompletedNormally(g, v1);
3348          assertEquals(a.get(), 1);
3349 +        }
3350      }
3351  
3352      /**
3353       * whenComplete action executes on exceptional completion, propagating
3354       * source result.
3355       */
3356 <    public void testWhenComplete2() {
3356 >    public void testWhenComplete_exceptionalCompletion() {
3357 >        for (boolean createIncomplete : new boolean[] { true, false })
3358 >        for (ExecutionMode m : ExecutionMode.values())
3359 >        for (Integer v1 : new Integer[] { 1, null }) {
3360 >
3361          final AtomicInteger a = new AtomicInteger();
3362 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3363 <        CompletableFuture<Integer> g =
3364 <            f.whenComplete((Integer x, Throwable t) -> a.getAndIncrement());
3365 <        f.completeExceptionally(new CFException());
3366 <        assertTrue(f.isCompletedExceptionally());
3367 <        assertTrue(g.isCompletedExceptionally());
3362 >        final CFException ex = new CFException();
3363 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
3364 >        if (!createIncomplete) f.completeExceptionally(ex);
3365 >        final CompletableFuture<Integer> g = m.whenComplete
3366 >            (f,
3367 >             (Integer x, Throwable t) -> {
3368 >                threadAssertNull(x);
3369 >                threadAssertSame(t, ex);
3370 >                a.getAndIncrement();
3371 >            });
3372 >        if (createIncomplete) f.completeExceptionally(ex);
3373 >        checkCompletedWithWrappedCFException(f, ex);
3374 >        checkCompletedWithWrappedCFException(g, ex);
3375          assertEquals(a.get(), 1);
3376 +        }
3377      }
3378  
3379      /**
3380       * If a whenComplete action throws an exception when triggered by
3381       * a normal completion, it completes exceptionally
3382       */
3383 <    public void testWhenComplete3() {
3384 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3385 <        CompletableFuture<Integer> g =
3386 <            f.whenComplete((Integer x, Throwable t) ->
3320 <                           { throw new CFException(); } );
3321 <        f.complete(three);
3322 <        checkCompletedNormally(f, three);
3323 <        assertTrue(g.isCompletedExceptionally());
3324 <        checkCompletedWithWrappedCFException(g);
3325 <    }
3326 <
3327 <    /**
3328 <     * whenCompleteAsync action executes on normal completion, propagating
3329 <     * source result.
3330 <     */
3331 <    public void testWhenCompleteAsync1() {
3332 <        final AtomicInteger a = new AtomicInteger();
3333 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3334 <        CompletableFuture<Integer> g =
3335 <            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3336 <        f.complete(three);
3337 <        checkCompletedNormally(f, three);
3338 <        checkCompletedNormally(g, three);
3339 <        assertEquals(a.get(), 1);
3340 <    }
3383 >    public void testWhenComplete_actionFailed() {
3384 >        for (boolean createIncomplete : new boolean[] { true, false })
3385 >        for (ExecutionMode m : ExecutionMode.values())
3386 >        for (Integer v1 : new Integer[] { 1, null }) {
3387  
3388 <    /**
3389 <     * whenCompleteAsync action executes on exceptional completion, propagating
3390 <     * source result.
3391 <     */
3392 <    public void testWhenCompleteAsync2() {
3393 <        final AtomicInteger a = new AtomicInteger();
3394 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3395 <        CompletableFuture<Integer> g =
3396 <            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement());
3397 <        f.completeExceptionally(new CFException());
3398 <        checkCompletedWithWrappedCFException(f);
3399 <        checkCompletedWithWrappedCFException(g);
3388 >        final CFException ex = new CFException();
3389 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
3390 >        if (!createIncomplete) f.complete(v1);
3391 >        final CompletableFuture<Integer> g = m.whenComplete
3392 >            (f,
3393 >             (Integer x, Throwable t) -> {
3394 >                threadAssertSame(x, v1);
3395 >                threadAssertNull(t);
3396 >                throw ex;
3397 >            });
3398 >        if (createIncomplete) f.complete(v1);
3399 >        checkCompletedNormally(f, v1);
3400 >        checkCompletedWithWrappedCFException(g, ex);
3401 >        }
3402      }
3403  
3404      /**
3405 <     * If a whenCompleteAsync action throws an exception when
3406 <     * triggered by a normal completion, it completes exceptionally
3405 >     * If a whenComplete action throws an exception when triggered by
3406 >     * a source completion that also throws an exception, the source
3407 >     * exception takes precedence.
3408       */
3409 <    public void testWhenCompleteAsync3() {
3410 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3411 <        CompletableFuture<Integer> g =
3412 <            f.whenCompleteAsync((Integer x, Throwable t) ->
3364 <                           { throw new CFException(); } );
3365 <        f.complete(three);
3366 <        checkCompletedNormally(f, three);
3367 <        checkCompletedWithWrappedCFException(g);
3368 <    }
3409 >    public void testWhenComplete_actionFailedSourceFailed() {
3410 >        for (boolean createIncomplete : new boolean[] { true, false })
3411 >        for (ExecutionMode m : ExecutionMode.values())
3412 >        for (Integer v1 : new Integer[] { 1, null }) {
3413  
3414 <    /**
3415 <     * whenCompleteAsync action executes on normal completion, propagating
3416 <     * source result.
3373 <     */
3374 <    public void testWhenCompleteAsync1e() {
3375 <        final AtomicInteger a = new AtomicInteger();
3376 <        ThreadExecutor exec = new ThreadExecutor();
3377 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3378 <        CompletableFuture<Integer> g =
3379 <            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3380 <                                exec);
3381 <        f.complete(three);
3382 <        checkCompletedNormally(f, three);
3383 <        checkCompletedNormally(g, three);
3384 <        assertEquals(a.get(), 1);
3385 <    }
3414 >        final CFException ex1 = new CFException();
3415 >        final CFException ex2 = new CFException();
3416 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
3417  
3418 <    /**
3419 <     * whenCompleteAsync action executes on exceptional completion, propagating
3420 <     * source result.
3421 <     */
3422 <    public void testWhenCompleteAsync2e() {
3423 <        final AtomicInteger a = new AtomicInteger();
3424 <        ThreadExecutor exec = new ThreadExecutor();
3425 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3426 <        CompletableFuture<Integer> g =
3396 <            f.whenCompleteAsync((Integer x, Throwable t) -> a.getAndIncrement(),
3397 <                                exec);
3398 <        f.completeExceptionally(new CFException());
3399 <        checkCompletedWithWrappedCFException(f);
3400 <        checkCompletedWithWrappedCFException(g);
3401 <    }
3418 >        if (!createIncomplete) f.completeExceptionally(ex1);
3419 >        final CompletableFuture<Integer> g = m.whenComplete
3420 >            (f,
3421 >             (Integer x, Throwable t) -> {
3422 >                threadAssertSame(t, ex1);
3423 >                threadAssertNull(x);
3424 >                throw ex2;
3425 >            });
3426 >        if (createIncomplete) f.completeExceptionally(ex1);
3427  
3428 <    /**
3429 <     * If a whenCompleteAsync action throws an exception when triggered
3430 <     * by a normal completion, it completes exceptionally
3406 <     */
3407 <    public void testWhenCompleteAsync3e() {
3408 <        ThreadExecutor exec = new ThreadExecutor();
3409 <        CompletableFuture<Integer> f = new CompletableFuture<>();
3410 <        CompletableFuture<Integer> g =
3411 <            f.whenCompleteAsync((Integer x, Throwable t) ->
3412 <                                { throw new CFException(); },
3413 <                                exec);
3414 <        f.complete(three);
3415 <        checkCompletedNormally(f, three);
3416 <        checkCompletedWithWrappedCFException(g);
3428 >        checkCompletedWithWrappedCFException(f, ex1);
3429 >        checkCompletedWithWrappedCFException(g, ex1);
3430 >        }
3431      }
3432  
3433      /**
# Line 3426 | Line 3440 | public class CompletableFutureTest exten
3440  
3441          f = new CompletableFuture<>();
3442          g = f.handleAsync(r = new IntegerHandler());
3443 <        assertFalse(r.ran);
3443 >        assertEquals(0, r.invocationCount);
3444          f.completeExceptionally(new CFException());
3445          checkCompletedWithWrappedCFException(f);
3446          checkCompletedNormally(g, three);
3447 <        assertTrue(r.ran);
3447 >        assertEquals(1, r.invocationCount);
3448  
3449          f = new CompletableFuture<>();
3450          g = f.handleAsync(r = new IntegerHandler());
3451 <        assertFalse(r.ran);
3451 >        assertEquals(0, r.invocationCount);
3452          f.completeExceptionally(new CFException());
3453          checkCompletedWithWrappedCFException(f);
3454          checkCompletedNormally(g, three);
3455 <        assertTrue(r.ran);
3455 >        assertEquals(1, r.invocationCount);
3456  
3457          f = new CompletableFuture<>();
3458          g = f.handleAsync(r = new IntegerHandler());
3459 <        assertFalse(r.ran);
3459 >        assertEquals(0, r.invocationCount);
3460          f.complete(one);
3461          checkCompletedNormally(f, one);
3462          checkCompletedNormally(g, two);
3463 <        assertTrue(r.ran);
3463 >        assertEquals(1, r.invocationCount);
3464  
3465          f = new CompletableFuture<>();
3466          g = f.handleAsync(r = new IntegerHandler());
3467 <        assertFalse(r.ran);
3467 >        assertEquals(0, r.invocationCount);
3468          f.complete(one);
3469          checkCompletedNormally(f, one);
3470          checkCompletedNormally(g, two);
3471 <        assertTrue(r.ran);
3471 >        assertEquals(1, r.invocationCount);
3472      }
3473  
3474      /**
# Line 3469 | Line 3483 | public class CompletableFutureTest exten
3483  
3484          f = new CompletableFuture<>();
3485          g = f.handleAsync(r = new IntegerHandler(), exec);
3486 <        assertFalse(r.ran);
3486 >        assertEquals(0, r.invocationCount);
3487          f.completeExceptionally(new CFException());
3488          checkCompletedWithWrappedCFException(f);
3489          checkCompletedNormally(g, three);
3490 <        assertTrue(r.ran);
3490 >        assertEquals(1, r.invocationCount);
3491  
3492          f = new CompletableFuture<>();
3493          g = f.handleAsync(r = new IntegerHandler(), exec);
3494 <        assertFalse(r.ran);
3494 >        assertEquals(0, r.invocationCount);
3495          f.completeExceptionally(new CFException());
3496          checkCompletedWithWrappedCFException(f);
3497          checkCompletedNormally(g, three);
3498 <        assertTrue(r.ran);
3498 >        assertEquals(1, r.invocationCount);
3499  
3500          f = new CompletableFuture<>();
3501          g = f.handleAsync(r = new IntegerHandler(), exec);
3502 <        assertFalse(r.ran);
3502 >        assertEquals(0, r.invocationCount);
3503          f.complete(one);
3504          checkCompletedNormally(f, one);
3505          checkCompletedNormally(g, two);
3506 <        assertTrue(r.ran);
3506 >        assertEquals(1, r.invocationCount);
3507  
3508          f = new CompletableFuture<>();
3509          g = f.handleAsync(r = new IntegerHandler(), exec);
3510 <        assertFalse(r.ran);
3510 >        assertEquals(0, r.invocationCount);
3511          f.complete(one);
3512          checkCompletedNormally(f, one);
3513          checkCompletedNormally(g, two);
3514 <        assertTrue(r.ran);
3514 >        assertEquals(1, r.invocationCount);
3515      }
3516  
3517   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines