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.55 by jsr166, Mon Jun 2 21:41:37 2014 UTC vs.
Revision 1.58 by jsr166, Mon Jun 2 23:10:08 2014 UTC

# Line 334 | Line 334 | public class CompletableFutureTest exten
334          return (x == null) ? null : x + 1;
335      }
336  
337 <    static final Supplier<Integer> supplyOne =
338 <        () -> Integer.valueOf(1);
339 <    static final Function<Integer, Integer> inc =
340 <        (Integer x) -> Integer.valueOf(x.intValue() + 1);
341 <    static final BiFunction<Integer, Integer, Integer> subtract =
342 <        (Integer x, Integer y) -> subtract(x, y);
337 >    static final class IntegerSupplier implements Supplier<Integer> {
338 >        final ExecutionMode m;
339 >        int invocationCount = 0;
340 >        final Integer value;
341 >        IntegerSupplier(ExecutionMode m, Integer value) {
342 >            this.m = m;
343 >            this.value = value;
344 >        }
345 >        public Integer get() {
346 >            m.checkExecutionMode();
347 >            invocationCount++;
348 >            return value;
349 >        }
350 >    }
351 >        
352      static final class IncAction implements Consumer<Integer> {
353          int invocationCount = 0;
354          Integer value;
# Line 349 | Line 358 | public class CompletableFutureTest exten
358          }
359      }
360      static final class IncFunction implements Function<Integer,Integer> {
361 +        final ExecutionMode m;
362          int invocationCount = 0;
363          Integer value;
364 +        IncFunction(ExecutionMode m) { this.m = m; }
365          public Integer apply(Integer x) {
366 +            m.checkExecutionMode();
367              invocationCount++;
368              return value = inc(x);
369          }
370      }
371      static final class SubtractAction implements BiConsumer<Integer, Integer> {
372 +        final ExecutionMode m;
373          int invocationCount = 0;
374          Integer value;
375          // Check this action was invoked exactly once when result is computed.
376 +        SubtractAction(ExecutionMode m) { this.m = m; }
377          public void accept(Integer x, Integer y) {
378 +            m.checkExecutionMode();
379              invocationCount++;
380              value = subtract(x, y);
381          }
382      }
383      static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> {
384 +        final ExecutionMode m;
385          int invocationCount = 0;
386          Integer value;
387          // Check this action was invoked exactly once when result is computed.
388 +        SubtractFunction(ExecutionMode m) { this.m = m; }
389          public Integer apply(Integer x, Integer y) {
390 +            m.checkExecutionMode();
391              invocationCount++;
392              return value = subtract(x, y);
393          }
# Line 385 | Line 403 | public class CompletableFutureTest exten
403      }
404  
405      static final class FailingSupplier implements Supplier<Integer> {
406 +        final ExecutionMode m;
407          int invocationCount = 0;
408 +        FailingSupplier(ExecutionMode m) { this.m = m; }
409          public Integer get() {
410 +            m.checkExecutionMode();
411              invocationCount++;
412              throw new CFException();
413          }
414      }
415      static final class FailingConsumer implements Consumer<Integer> {
416 +        final ExecutionMode m;
417          int invocationCount = 0;
418 +        FailingConsumer(ExecutionMode m) { this.m = m; }
419          public void accept(Integer x) {
420 +            m.checkExecutionMode();
421              invocationCount++;
422              throw new CFException();
423          }
424      }
425      static final class FailingBiConsumer implements BiConsumer<Integer, Integer> {
426 +        final ExecutionMode m;
427          int invocationCount = 0;
428 +        FailingBiConsumer(ExecutionMode m) { this.m = m; }
429          public void accept(Integer x, Integer y) {
430 +            m.checkExecutionMode();
431              invocationCount++;
432              throw new CFException();
433          }
434      }
435      static final class FailingFunction implements Function<Integer, Integer> {
436 +        final ExecutionMode m;
437          int invocationCount = 0;
438 +        FailingFunction(ExecutionMode m) { this.m = m; }
439          public Integer apply(Integer x) {
440 +            m.checkExecutionMode();
441              invocationCount++;
442              throw new CFException();
443          }
444      }
445      static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> {
446 +        final ExecutionMode m;
447          int invocationCount = 0;
448 +        FailingBiFunction(ExecutionMode m) { this.m = m; }
449          public Integer apply(Integer x, Integer y) {
450 +            m.checkExecutionMode();
451              invocationCount++;
452              throw new CFException();
453          }
454      }
455      static final class FailingRunnable implements Runnable {
456 +        final ExecutionMode m;
457          int invocationCount = 0;
458 +        FailingRunnable(ExecutionMode m) { this.m = m; }
459          public void run() {
460 +            m.checkExecutionMode();
461              invocationCount++;
462              throw new CFException();
463          }
# Line 429 | Line 465 | public class CompletableFutureTest exten
465  
466      static final class CompletableFutureInc
467          implements Function<Integer, CompletableFuture<Integer>> {
468 +        final ExecutionMode m;
469          int invocationCount = 0;
470 +        CompletableFutureInc(ExecutionMode m) { this.m = m; }
471          public CompletableFuture<Integer> apply(Integer x) {
472 +            m.checkExecutionMode();
473              invocationCount++;
474              CompletableFuture<Integer> f = new CompletableFuture<>();
475              f.complete(inc(x));
# Line 440 | Line 479 | public class CompletableFutureTest exten
479  
480      static final class FailingCompletableFutureFunction
481          implements Function<Integer, CompletableFuture<Integer>> {
482 +        final ExecutionMode m;
483          int invocationCount = 0;
484 +        FailingCompletableFutureFunction(ExecutionMode m) { this.m = m; }
485          public CompletableFuture<Integer> apply(Integer x) {
486 +            m.checkExecutionMode();
487              invocationCount++;
488              throw new CFException();
489          }
# Line 449 | Line 491 | public class CompletableFutureTest exten
491  
492      // Used for explicit executor tests
493      static final class ThreadExecutor implements Executor {
494 <        AtomicInteger count = new AtomicInteger(0);
494 >        final AtomicInteger count = new AtomicInteger(0);
495 >        static final ThreadGroup tg = new ThreadGroup("ThreadExecutor");
496 >        static boolean startedCurrentThread() {
497 >            return Thread.currentThread().getThreadGroup() == tg;
498 >        }
499  
500          public void execute(Runnable r) {
501              count.getAndIncrement();
502 <            new Thread(r).start();
502 >            new Thread(tg, r).start();
503          }
504      }
505  
# Line 466 | Line 512 | public class CompletableFutureTest exten
512              public void checkExecutionMode() {
513                  assertNull(ForkJoinTask.getPool());
514              }
515 +            public CompletableFuture<Void> runAsync(Runnable a) {
516 +                throw new UnsupportedOperationException();
517 +            }
518 +            public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) {
519 +                throw new UnsupportedOperationException();
520 +            }
521              public <T> CompletableFuture<Void> thenRun
522                  (CompletableFuture<T> f, Runnable a) {
523                  return f.thenRun(a);
# Line 534 | Line 586 | public class CompletableFutureTest exten
586                  assertSame(ForkJoinPool.commonPool(),
587                             ForkJoinTask.getPool());
588              }
589 +            public CompletableFuture<Void> runAsync(Runnable a) {
590 +                return CompletableFuture.runAsync(a);
591 +            }
592 +            public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) {
593 +                return CompletableFuture.supplyAsync(a);
594 +            }
595              public <T> CompletableFuture<Void> thenRun
596                  (CompletableFuture<T> f, Runnable a) {
597                  return f.thenRunAsync(a);
# Line 599 | Line 657 | public class CompletableFutureTest exten
657  
658          EXECUTOR {
659              public void checkExecutionMode() {
660 <                //TODO
660 >                assertTrue(ThreadExecutor.startedCurrentThread());
661 >            }
662 >            public CompletableFuture<Void> runAsync(Runnable a) {
663 >                return CompletableFuture.runAsync(a, new ThreadExecutor());
664 >            }
665 >            public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) {
666 >                return CompletableFuture.supplyAsync(a, new ThreadExecutor());
667              }
668              public <T> CompletableFuture<Void> thenRun
669                  (CompletableFuture<T> f, Runnable a) {
# Line 665 | Line 729 | public class CompletableFutureTest exten
729          };
730  
731          public abstract void checkExecutionMode();
732 +        public abstract CompletableFuture<Void> runAsync(Runnable a);
733 +        public abstract <U> CompletableFuture<U> supplyAsync(Supplier<U> a);
734          public abstract <T> CompletableFuture<Void> thenRun
735              (CompletableFuture<T> f, Runnable a);
736          public abstract <T> CompletableFuture<Void> thenAccept
# Line 743 | Line 809 | public class CompletableFutureTest exten
809          if (!createIncomplete) f.completeExceptionally(ex);
810          final CompletableFuture<Integer> g = f.exceptionally
811              ((Throwable t) -> {
812 +                ExecutionMode.DEFAULT.checkExecutionMode();
813                  threadAssertSame(t, ex);
814                  a.getAndIncrement();
815                  return v1;
# Line 764 | Line 831 | public class CompletableFutureTest exten
831          if (!createIncomplete) f.completeExceptionally(ex1);
832          final CompletableFuture<Integer> g = f.exceptionally
833              ((Throwable t) -> {
834 +                ExecutionMode.DEFAULT.checkExecutionMode();
835                  threadAssertSame(t, ex1);
836                  a.getAndIncrement();
837                  throw ex2;
# Line 789 | Line 857 | public class CompletableFutureTest exten
857          final CompletableFuture<Integer> g = m.handle
858              (f,
859               (Integer x, Throwable t) -> {
860 +                m.checkExecutionMode();
861                  threadAssertSame(x, v1);
862                  threadAssertNull(t);
863                  a.getAndIncrement();
# Line 817 | Line 886 | public class CompletableFutureTest exten
886          final CompletableFuture<Integer> g = m.handle
887              (f,
888               (Integer x, Throwable t) -> {
889 +                m.checkExecutionMode();
890                  threadAssertNull(x);
891                  threadAssertSame(t, ex);
892                  a.getAndIncrement();
# Line 845 | Line 915 | public class CompletableFutureTest exten
915          final CompletableFuture<Integer> g = m.handle
916              (f,
917               (Integer x, Throwable t) -> {
918 +                m.checkExecutionMode();
919                  threadAssertNull(x);
920                  threadAssertTrue(t instanceof CancellationException);
921                  a.getAndIncrement();
# Line 872 | Line 943 | public class CompletableFutureTest exten
943          final CompletableFuture<Integer> g = m.handle
944              (f,
945               (Integer x, Throwable t) -> {
946 +                m.checkExecutionMode();
947                  threadAssertNull(x);
948                  threadAssertSame(ex1, t);
949                  a.getAndIncrement();
# Line 896 | Line 968 | public class CompletableFutureTest exten
968          final CompletableFuture<Integer> g = m.handle
969              (f,
970               (Integer x, Throwable t) -> {
971 +                m.checkExecutionMode();
972                  threadAssertSame(x, v1);
973                  threadAssertNull(t);
974                  a.getAndIncrement();
# Line 911 | Line 984 | public class CompletableFutureTest exten
984      /**
985       * runAsync completes after running Runnable
986       */
987 <    public void testRunAsync() {
988 <        Noop r = new Noop(ExecutionMode.ASYNC);
989 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r);
987 >    public void testRunAsync_normalCompletion() {
988 >        ExecutionMode[] executionModes = {
989 >            ExecutionMode.ASYNC,
990 >            ExecutionMode.EXECUTOR,
991 >        };
992 >        for (ExecutionMode m : executionModes)
993 >    {
994 >        final Noop r = new Noop(m);
995 >        final CompletableFuture<Void> f = m.runAsync(r);
996          assertNull(f.join());
918        assertEquals(1, r.invocationCount);
997          checkCompletedNormally(f, null);
920    }
921
922    /**
923     * runAsync with executor completes after running Runnable
924     */
925    public void testRunAsync2() {
926        Noop r = new Noop(ExecutionMode.EXECUTOR);
927        ThreadExecutor exec = new ThreadExecutor();
928        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
929        assertNull(f.join());
998          assertEquals(1, r.invocationCount);
999 <        checkCompletedNormally(f, null);
932 <        assertEquals(1, exec.count.get());
933 <    }
999 >    }}
1000  
1001      /**
1002       * failing runAsync completes exceptionally after running Runnable
1003       */
1004 <    public void testRunAsync3() {
1005 <        FailingRunnable r = new FailingRunnable();
1006 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r);
1004 >    public void testRunAsync_exceptionalCompletion() {
1005 >        ExecutionMode[] executionModes = {
1006 >            ExecutionMode.ASYNC,
1007 >            ExecutionMode.EXECUTOR,
1008 >        };
1009 >        for (ExecutionMode m : executionModes)
1010 >    {
1011 >        final FailingRunnable r = new FailingRunnable(m);
1012 >        final CompletableFuture<Void> f = m.runAsync(r);
1013          checkCompletedWithWrappedCFException(f);
1014          assertEquals(1, r.invocationCount);
1015 <    }
1015 >    }}
1016  
1017      /**
1018       * supplyAsync completes with result of supplier
1019       */
1020 <    public void testSupplyAsync() {
1021 <        CompletableFuture<Integer> f;
1022 <        f = CompletableFuture.supplyAsync(supplyOne);
1023 <        assertEquals(f.join(), one);
1024 <        checkCompletedNormally(f, one);
1025 <    }
1026 <
1027 <    /**
1028 <     * supplyAsync with executor completes with result of supplier
1029 <     */
1030 <    public void testSupplyAsync2() {
1031 <        CompletableFuture<Integer> f;
1032 <        f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor());
1033 <        assertEquals(f.join(), one);
962 <        checkCompletedNormally(f, one);
963 <    }
1020 >    public void testSupplyAsync_normalCompletion() {
1021 >        ExecutionMode[] executionModes = {
1022 >            ExecutionMode.ASYNC,
1023 >            ExecutionMode.EXECUTOR,
1024 >        };
1025 >        for (ExecutionMode m : executionModes)
1026 >        for (Integer v1 : new Integer[] { 1, null })
1027 >    {
1028 >        final IntegerSupplier r = new IntegerSupplier(m, v1);
1029 >        final CompletableFuture<Integer> f = m.supplyAsync(r);
1030 >        assertSame(v1, f.join());
1031 >        checkCompletedNormally(f, v1);
1032 >        assertEquals(1, r.invocationCount);
1033 >    }}
1034  
1035      /**
1036       * Failing supplyAsync completes exceptionally
1037       */
1038 <    public void testSupplyAsync3() {
1039 <        FailingSupplier r = new FailingSupplier();
1040 <        CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r);
1038 >    public void testSupplyAsync_exceptionalCompletion() {
1039 >        ExecutionMode[] executionModes = {
1040 >            ExecutionMode.ASYNC,
1041 >            ExecutionMode.EXECUTOR,
1042 >        };
1043 >        for (ExecutionMode m : executionModes)
1044 >    {
1045 >        FailingSupplier r = new FailingSupplier(m);
1046 >        CompletableFuture<Integer> f = m.supplyAsync(r);
1047          checkCompletedWithWrappedCFException(f);
1048          assertEquals(1, r.invocationCount);
1049 <    }
1049 >    }}
1050  
1051      // seq completion methods
1052  
# Line 1030 | Line 1106 | public class CompletableFutureTest exten
1106          final CompletableFuture<Integer> f = new CompletableFuture<>();
1107          final Noop r = new Noop(m);
1108          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1109 <        final CompletableFuture<Void> g = f.thenRun(r);
1109 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1110          if (createIncomplete) {
1111              checkIncomplete(g);
1112              assertTrue(f.cancel(mayInterruptIfRunning));
# Line 1050 | Line 1126 | public class CompletableFutureTest exten
1126          for (Integer v1 : new Integer[] { 1, null })
1127      {
1128          final CompletableFuture<Integer> f = new CompletableFuture<>();
1129 <        final FailingRunnable r = new FailingRunnable();
1129 >        final FailingRunnable r = new FailingRunnable(m);
1130          if (!createIncomplete) f.complete(v1);
1131 <        final CompletableFuture<Void> g = f.thenRun(r);
1131 >        final CompletableFuture<Void> g = m.thenRun(f, r);
1132          if (createIncomplete) {
1133              checkIncomplete(g);
1134              f.complete(v1);
# Line 1071 | Line 1147 | public class CompletableFutureTest exten
1147          for (Integer v1 : new Integer[] { 1, null })
1148      {
1149          final CompletableFuture<Integer> f = new CompletableFuture<>();
1150 <        final IncFunction r = new IncFunction();
1150 >        final IncFunction r = new IncFunction(m);
1151          if (!createIncomplete) f.complete(v1);
1152          final CompletableFuture<Integer> g = m.thenApply(f, r);
1153          if (createIncomplete) {
# Line 1094 | Line 1170 | public class CompletableFutureTest exten
1170      {
1171          final CFException ex = new CFException();
1172          final CompletableFuture<Integer> f = new CompletableFuture<>();
1173 <        final IncFunction r = new IncFunction();
1173 >        final IncFunction r = new IncFunction(m);
1174          if (!createIncomplete) f.completeExceptionally(ex);
1175          final CompletableFuture<Integer> g = m.thenApply(f, r);
1176          if (createIncomplete) {
# Line 1116 | Line 1192 | public class CompletableFutureTest exten
1192          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1193      {
1194          final CompletableFuture<Integer> f = new CompletableFuture<>();
1195 <        final IncFunction r = new IncFunction();
1195 >        final IncFunction r = new IncFunction(m);
1196          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1197 <        final CompletableFuture<Integer> g = f.thenApply(r);
1197 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1198          if (createIncomplete) {
1199              checkIncomplete(g);
1200              assertTrue(f.cancel(mayInterruptIfRunning));
# Line 1138 | Line 1214 | public class CompletableFutureTest exten
1214          for (Integer v1 : new Integer[] { 1, null })
1215      {
1216          final CompletableFuture<Integer> f = new CompletableFuture<>();
1217 <        final FailingFunction r = new FailingFunction();
1217 >        final FailingFunction r = new FailingFunction(m);
1218          if (!createIncomplete) f.complete(v1);
1219 <        final CompletableFuture<Integer> g = f.thenApply(r);
1219 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1220          if (createIncomplete) {
1221              checkIncomplete(g);
1222              f.complete(v1);
# Line 1205 | Line 1281 | public class CompletableFutureTest exten
1281          for (Integer v1 : new Integer[] { 1, null })
1282      {
1283          final CompletableFuture<Integer> f = new CompletableFuture<>();
1284 <        final FailingConsumer r = new FailingConsumer();
1284 >        final FailingConsumer r = new FailingConsumer(m);
1285          if (!createIncomplete) f.complete(v1);
1286 <        final CompletableFuture<Void> g = f.thenAccept(r);
1286 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1287          if (createIncomplete) {
1288              checkIncomplete(g);
1289              f.complete(v1);
# Line 1228 | Line 1304 | public class CompletableFutureTest exten
1304          final CompletableFuture<Integer> f = new CompletableFuture<>();
1305          final IncAction r = new IncAction();
1306          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1307 <        final CompletableFuture<Void> g = f.thenAccept(r);
1307 >        final CompletableFuture<Void> g = m.thenAccept(f, r);
1308          if (createIncomplete) {
1309              checkIncomplete(g);
1310              assertTrue(f.cancel(mayInterruptIfRunning));
# Line 1252 | Line 1328 | public class CompletableFutureTest exten
1328      {
1329          final CompletableFuture<Integer> f = new CompletableFuture<>();
1330          final CompletableFuture<Integer> g = new CompletableFuture<>();
1331 <        final SubtractFunction r = new SubtractFunction();
1331 >        final SubtractFunction r = new SubtractFunction(m);
1332  
1333          if (fFirst) f.complete(v1); else g.complete(v2);
1334          if (!createIncomplete)
# Line 1283 | Line 1359 | public class CompletableFutureTest exten
1359          final CompletableFuture<Integer> f = new CompletableFuture<>();
1360          final CompletableFuture<Integer> g = new CompletableFuture<>();
1361          final CFException ex = new CFException();
1362 <        final SubtractFunction r = new SubtractFunction();
1362 >        final SubtractFunction r = new SubtractFunction(m);
1363  
1364          (fFirst ? f : g).complete(v1);
1365          if (!createIncomplete)
# Line 1311 | Line 1387 | public class CompletableFutureTest exten
1387      {
1388          final CompletableFuture<Integer> f = new CompletableFuture<>();
1389          final CompletableFuture<Integer> g = new CompletableFuture<>();
1390 <        final FailingBiFunction r = new FailingBiFunction();
1390 >        final FailingBiFunction r = new FailingBiFunction(m);
1391          final CompletableFuture<Integer> h = m.thenCombine(f, g, r);
1392  
1393          if (fFirst) {
# Line 1339 | Line 1415 | public class CompletableFutureTest exten
1415      {
1416          final CompletableFuture<Integer> f = new CompletableFuture<>();
1417          final CompletableFuture<Integer> g = new CompletableFuture<>();
1418 <        final SubtractFunction r = new SubtractFunction();
1418 >        final SubtractFunction r = new SubtractFunction(m);
1419  
1420          (fFirst ? f : g).complete(v1);
1421          if (!createIncomplete)
# Line 1369 | Line 1445 | public class CompletableFutureTest exten
1445      {
1446          final CompletableFuture<Integer> f = new CompletableFuture<>();
1447          final CompletableFuture<Integer> g = new CompletableFuture<>();
1448 <        final SubtractAction r = new SubtractAction();
1448 >        final SubtractAction r = new SubtractAction(m);
1449  
1450          if (fFirst) f.complete(v1); else g.complete(v2);
1451          if (!createIncomplete)
# Line 1400 | Line 1476 | public class CompletableFutureTest exten
1476          final CompletableFuture<Integer> f = new CompletableFuture<>();
1477          final CompletableFuture<Integer> g = new CompletableFuture<>();
1478          final CFException ex = new CFException();
1479 <        final SubtractAction r = new SubtractAction();
1479 >        final SubtractAction r = new SubtractAction(m);
1480  
1481          (fFirst ? f : g).complete(v1);
1482          if (!createIncomplete)
# Line 1428 | Line 1504 | public class CompletableFutureTest exten
1504      {
1505          final CompletableFuture<Integer> f = new CompletableFuture<>();
1506          final CompletableFuture<Integer> g = new CompletableFuture<>();
1507 <        final FailingBiConsumer r = new FailingBiConsumer();
1507 >        final FailingBiConsumer r = new FailingBiConsumer(m);
1508          final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r);
1509  
1510          if (fFirst) {
# Line 1456 | Line 1532 | public class CompletableFutureTest exten
1532      {
1533          final CompletableFuture<Integer> f = new CompletableFuture<>();
1534          final CompletableFuture<Integer> g = new CompletableFuture<>();
1535 <        final SubtractAction r = new SubtractAction();
1535 >        final SubtractAction r = new SubtractAction(m);
1536  
1537          (fFirst ? f : g).complete(v1);
1538          if (!createIncomplete)
# Line 1545 | Line 1621 | public class CompletableFutureTest exten
1621      {
1622          final CompletableFuture<Integer> f = new CompletableFuture<>();
1623          final CompletableFuture<Integer> g = new CompletableFuture<>();
1624 <        final FailingRunnable r = new FailingRunnable();
1624 >        final FailingRunnable r = new FailingRunnable(m);
1625  
1626          CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r);
1627          if (fFirst) {
# Line 1606 | Line 1682 | public class CompletableFutureTest exten
1682      {
1683          final CompletableFuture<Integer> f = new CompletableFuture<>();
1684          final CompletableFuture<Integer> g = new CompletableFuture<>();
1685 <        final IncFunction r = new IncFunction();
1685 >        final IncFunction r = new IncFunction(m);
1686  
1687          if (!createIncomplete)
1688              if (fFirst) f.complete(v1); else g.complete(v2);
# Line 1632 | Line 1708 | public class CompletableFutureTest exten
1708      {
1709          final CompletableFuture<Integer> f = new CompletableFuture<>();
1710          final CompletableFuture<Integer> g = new CompletableFuture<>();
1711 <        final IncFunction r = new IncFunction();
1711 >        final IncFunction r = new IncFunction(m);
1712  
1713          if (fFirst) {
1714              f.complete(v1);
# Line 1666 | Line 1742 | public class CompletableFutureTest exten
1742          final CompletableFuture<Integer> f = new CompletableFuture<>();
1743          final CompletableFuture<Integer> g = new CompletableFuture<>();
1744          final CFException ex = new CFException();
1745 <        final IncFunction r = new IncFunction();
1745 >        final IncFunction r = new IncFunction(m);
1746  
1747          if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex);
1748          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
# Line 1693 | Line 1769 | public class CompletableFutureTest exten
1769      {
1770          final CompletableFuture<Integer> f = new CompletableFuture<>();
1771          final CompletableFuture<Integer> g = new CompletableFuture<>();
1772 <        final IncFunction r1 = new IncFunction();
1773 <        final IncFunction r2 = new IncFunction();
1772 >        final IncFunction r1 = new IncFunction(m);
1773 >        final IncFunction r2 = new IncFunction(m);
1774          final CFException ex = new CFException();
1775          final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1776          final CompletableFuture<Integer> k = (reverseArgs ? f : g);
# Line 1739 | Line 1815 | public class CompletableFutureTest exten
1815      {
1816          final CompletableFuture<Integer> f = new CompletableFuture<>();
1817          final CompletableFuture<Integer> g = new CompletableFuture<>();
1818 <        final FailingFunction r = new FailingFunction();
1818 >        final FailingFunction r = new FailingFunction(m);
1819          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1820  
1821          f.complete(v1);
# Line 1756 | Line 1832 | public class CompletableFutureTest exten
1832      {
1833          final CompletableFuture<Integer> f = new CompletableFuture<>();
1834          final CompletableFuture<Integer> g = new CompletableFuture<>();
1835 <        final FailingFunction r = new FailingFunction();
1835 >        final FailingFunction r = new FailingFunction(m);
1836          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1837  
1838          g.complete(v2);
# Line 1778 | Line 1854 | public class CompletableFutureTest exten
1854      {
1855          final CompletableFuture<Integer> f = new CompletableFuture<>();
1856          final CompletableFuture<Integer> g = new CompletableFuture<>();
1857 <        final IncFunction r = new IncFunction();
1857 >        final IncFunction r = new IncFunction(m);
1858  
1859          if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning));
1860          final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
# Line 1806 | Line 1882 | public class CompletableFutureTest exten
1882      {
1883          final CompletableFuture<Integer> f = new CompletableFuture<>();
1884          final CompletableFuture<Integer> g = new CompletableFuture<>();
1885 <        final IncFunction r1 = new IncFunction();
1886 <        final IncFunction r2 = new IncFunction();
1885 >        final IncFunction r1 = new IncFunction(m);
1886 >        final IncFunction r2 = new IncFunction(m);
1887          final CFException ex = new CFException();
1888          final CompletableFuture<Integer> j = (reverseArgs ? g : f);
1889          final CompletableFuture<Integer> k = (reverseArgs ? f : g);
# Line 2019 | Line 2095 | public class CompletableFutureTest exten
2095      {
2096          final CompletableFuture<Integer> f = new CompletableFuture<>();
2097          final CompletableFuture<Integer> g = new CompletableFuture<>();
2098 <        final FailingConsumer r = new FailingConsumer();
2098 >        final FailingConsumer r = new FailingConsumer(m);
2099          final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2100  
2101          f.complete(v1);
# Line 2036 | Line 2112 | public class CompletableFutureTest exten
2112      {
2113          final CompletableFuture<Integer> f = new CompletableFuture<>();
2114          final CompletableFuture<Integer> g = new CompletableFuture<>();
2115 <        final FailingConsumer r = new FailingConsumer();
2115 >        final FailingConsumer r = new FailingConsumer(m);
2116          final CompletableFuture<Void> h = m.acceptEither(f, g, r);
2117  
2118          g.complete(v2);
# Line 2318 | Line 2394 | public class CompletableFutureTest exten
2394      {
2395          final CompletableFuture<Integer> f = new CompletableFuture<>();
2396          final CompletableFuture<Integer> g = new CompletableFuture<>();
2397 <        final FailingRunnable r = new FailingRunnable();
2397 >        final FailingRunnable r = new FailingRunnable(m);
2398          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2399  
2400          f.complete(v1);
# Line 2335 | Line 2411 | public class CompletableFutureTest exten
2411      {
2412          final CompletableFuture<Integer> f = new CompletableFuture<>();
2413          final CompletableFuture<Integer> g = new CompletableFuture<>();
2414 <        final FailingRunnable r = new FailingRunnable();
2414 >        final FailingRunnable r = new FailingRunnable(m);
2415          final CompletableFuture<Void> h = m.runAfterEither(f, g, r);
2416  
2417          g.complete(v2);
# Line 2451 | Line 2527 | public class CompletableFutureTest exten
2527          for (Integer v1 : new Integer[] { 1, null })
2528      {
2529          final CompletableFuture<Integer> f = new CompletableFuture<>();
2530 <        final CompletableFutureInc r = new CompletableFutureInc();
2530 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2531          if (!createIncomplete) f.complete(v1);
2532 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2532 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2533          if (createIncomplete) f.complete(v1);
2534  
2535          checkCompletedNormally(g, inc(v1));
# Line 2470 | Line 2546 | public class CompletableFutureTest exten
2546          for (boolean createIncomplete : new boolean[] { true, false })
2547      {
2548          final CFException ex = new CFException();
2549 <        final CompletableFutureInc r = new CompletableFutureInc();
2549 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2550          final CompletableFuture<Integer> f = new CompletableFuture<>();
2551          if (!createIncomplete) f.completeExceptionally(ex);
2552 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2552 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2553          if (createIncomplete) f.completeExceptionally(ex);
2554  
2555          checkCompletedWithWrappedCFException(g, ex);
# Line 2491 | Line 2567 | public class CompletableFutureTest exten
2567      {
2568          final CompletableFuture<Integer> f = new CompletableFuture<>();
2569          final FailingCompletableFutureFunction r
2570 <            = new FailingCompletableFutureFunction();
2570 >            = new FailingCompletableFutureFunction(m);
2571          if (!createIncomplete) f.complete(v1);
2572 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2572 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2573          if (createIncomplete) f.complete(v1);
2574  
2575          checkCompletedWithWrappedCFException(g);
# Line 2509 | Line 2585 | public class CompletableFutureTest exten
2585          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2586      {
2587          final CompletableFuture<Integer> f = new CompletableFuture<>();
2588 <        final CompletableFutureInc r = new CompletableFutureInc();
2588 >        final CompletableFutureInc r = new CompletableFutureInc(m);
2589          if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
2590 <        final CompletableFuture<Integer> g = f.thenCompose(r);
2590 >        final CompletableFuture<Integer> g = m.thenCompose(f, r);
2591          if (createIncomplete) {
2592              checkIncomplete(g);
2593              assertTrue(f.cancel(mayInterruptIfRunning));
# Line 2610 | Line 2686 | public class CompletableFutureTest exten
2686          Runnable[] throwingActions = {
2687              () -> CompletableFuture.supplyAsync(null),
2688              () -> CompletableFuture.supplyAsync(null, exec),
2689 <            () -> CompletableFuture.supplyAsync(supplyOne, null),
2689 >            () -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.DEFAULT, 42), null),
2690  
2691              () -> CompletableFuture.runAsync(null),
2692              () -> CompletableFuture.runAsync(null, exec),
# Line 2683 | Line 2759 | public class CompletableFutureTest exten
2759  
2760              () -> f.thenCompose(null),
2761              () -> f.thenComposeAsync(null),
2762 <            () -> f.thenComposeAsync(new CompletableFutureInc(), null),
2762 >            () -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null),
2763              () -> f.thenComposeAsync(null, exec),
2764  
2765              () -> f.exceptionally(null),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines