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.56 by jsr166, Mon Jun 2 22:20:32 2014 UTC vs.
Revision 1.57 by jsr166, Mon Jun 2 22:48:50 2014 UTC

# Line 503 | Line 503 | public class CompletableFutureTest exten
503              public void checkExecutionMode() {
504                  assertNull(ForkJoinTask.getPool());
505              }
506 +            public CompletableFuture<Void> runAsync(Runnable a) {
507 +                throw new UnsupportedOperationException();
508 +            }
509              public <T> CompletableFuture<Void> thenRun
510                  (CompletableFuture<T> f, Runnable a) {
511                  return f.thenRun(a);
# Line 571 | Line 574 | public class CompletableFutureTest exten
574                  assertSame(ForkJoinPool.commonPool(),
575                             ForkJoinTask.getPool());
576              }
577 +            public CompletableFuture<Void> runAsync(Runnable a) {
578 +                return CompletableFuture.runAsync(a);
579 +            }
580              public <T> CompletableFuture<Void> thenRun
581                  (CompletableFuture<T> f, Runnable a) {
582                  return f.thenRunAsync(a);
# Line 638 | Line 644 | public class CompletableFutureTest exten
644              public void checkExecutionMode() {
645                  assertTrue(ThreadExecutor.startedCurrentThread());
646              }
647 +            public CompletableFuture<Void> runAsync(Runnable a) {
648 +                return CompletableFuture.runAsync(a, new ThreadExecutor());
649 +            }
650              public <T> CompletableFuture<Void> thenRun
651                  (CompletableFuture<T> f, Runnable a) {
652                  return f.thenRunAsync(a, new ThreadExecutor());
# Line 702 | Line 711 | public class CompletableFutureTest exten
711          };
712  
713          public abstract void checkExecutionMode();
714 +        public abstract CompletableFuture<Void> runAsync(Runnable a);
715          public abstract <T> CompletableFuture<Void> thenRun
716              (CompletableFuture<T> f, Runnable a);
717          public abstract <T> CompletableFuture<Void> thenAccept
# Line 780 | Line 790 | public class CompletableFutureTest exten
790          if (!createIncomplete) f.completeExceptionally(ex);
791          final CompletableFuture<Integer> g = f.exceptionally
792              ((Throwable t) -> {
793 +                ExecutionMode.DEFAULT.checkExecutionMode();
794                  threadAssertSame(t, ex);
795                  a.getAndIncrement();
796                  return v1;
# Line 801 | Line 812 | public class CompletableFutureTest exten
812          if (!createIncomplete) f.completeExceptionally(ex1);
813          final CompletableFuture<Integer> g = f.exceptionally
814              ((Throwable t) -> {
815 +                ExecutionMode.DEFAULT.checkExecutionMode();
816                  threadAssertSame(t, ex1);
817                  a.getAndIncrement();
818                  throw ex2;
# Line 826 | Line 838 | public class CompletableFutureTest exten
838          final CompletableFuture<Integer> g = m.handle
839              (f,
840               (Integer x, Throwable t) -> {
841 +                m.checkExecutionMode();
842                  threadAssertSame(x, v1);
843                  threadAssertNull(t);
844                  a.getAndIncrement();
# Line 854 | Line 867 | public class CompletableFutureTest exten
867          final CompletableFuture<Integer> g = m.handle
868              (f,
869               (Integer x, Throwable t) -> {
870 +                m.checkExecutionMode();
871                  threadAssertNull(x);
872                  threadAssertSame(t, ex);
873                  a.getAndIncrement();
# Line 882 | Line 896 | public class CompletableFutureTest exten
896          final CompletableFuture<Integer> g = m.handle
897              (f,
898               (Integer x, Throwable t) -> {
899 +                m.checkExecutionMode();
900                  threadAssertNull(x);
901                  threadAssertTrue(t instanceof CancellationException);
902                  a.getAndIncrement();
# Line 909 | Line 924 | public class CompletableFutureTest exten
924          final CompletableFuture<Integer> g = m.handle
925              (f,
926               (Integer x, Throwable t) -> {
927 +                m.checkExecutionMode();
928                  threadAssertNull(x);
929                  threadAssertSame(ex1, t);
930                  a.getAndIncrement();
# Line 933 | Line 949 | public class CompletableFutureTest exten
949          final CompletableFuture<Integer> g = m.handle
950              (f,
951               (Integer x, Throwable t) -> {
952 +                m.checkExecutionMode();
953                  threadAssertSame(x, v1);
954                  threadAssertNull(t);
955                  a.getAndIncrement();
# Line 948 | Line 965 | public class CompletableFutureTest exten
965      /**
966       * runAsync completes after running Runnable
967       */
968 <    public void testRunAsync() {
969 <        Noop r = new Noop(ExecutionMode.ASYNC);
970 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r);
968 >    public void testRunAsync_normalCompletion() {
969 >        ExecutionMode[] executionModes = {
970 >            ExecutionMode.ASYNC,
971 >            ExecutionMode.EXECUTOR,
972 >        };
973 >        for (ExecutionMode m : executionModes)
974 >    {
975 >        final Noop r = new Noop(m);
976 >        final CompletableFuture<Void> f = m.runAsync(r);
977          assertNull(f.join());
955        assertEquals(1, r.invocationCount);
978          checkCompletedNormally(f, null);
957    }
958
959    /**
960     * runAsync with executor completes after running Runnable
961     */
962    public void testRunAsync2() {
963        Noop r = new Noop(ExecutionMode.EXECUTOR);
964        ThreadExecutor exec = new ThreadExecutor();
965        CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec);
966        assertNull(f.join());
979          assertEquals(1, r.invocationCount);
980 <        checkCompletedNormally(f, null);
969 <        assertEquals(1, exec.count.get());
970 <    }
980 >    }}
981  
982      /**
983       * failing runAsync completes exceptionally after running Runnable
984       */
985 <    public void testRunAsync3() {
986 <        FailingRunnable r = new FailingRunnable(ExecutionMode.ASYNC);
987 <        CompletableFuture<Void> f = CompletableFuture.runAsync(r);
985 >    public void testRunAsync_exceptionalCompletion() {
986 >        ExecutionMode[] executionModes = {
987 >            ExecutionMode.ASYNC,
988 >            ExecutionMode.EXECUTOR,
989 >        };
990 >        for (ExecutionMode m : executionModes)
991 >    {
992 >        final FailingRunnable r = new FailingRunnable(m);
993 >        final CompletableFuture<Void> f = m.runAsync(r);
994          checkCompletedWithWrappedCFException(f);
995          assertEquals(1, r.invocationCount);
996 <    }
996 >    }}
997  
998      /**
999       * supplyAsync completes with result of supplier

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines