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.163 by jsr166, Sun Jul 3 18:33:17 2016 UTC vs.
Revision 1.167 by jsr166, Sun Jul 17 17:49:23 2016 UTC

# Line 3852 | Line 3852 | public class CompletableFutureTest exten
3852          final CompletableFuture<Integer> v42 = CompletableFuture.completedFuture(42);
3853          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3854  
3855 +        final Runnable noopRunnable = new Noop(m);
3856 +        final Consumer<Integer> noopConsumer = new NoopConsumer(m);
3857 +        final Function<Integer, Integer> incFunction = new IncFunction(m);
3858 +
3859          List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> funs
3860              = new ArrayList<>();
3861  
3862 <        funs.add((y) -> m.thenRun(y, new Noop(m)));
3863 <        funs.add((y) -> m.thenAccept(y, new NoopConsumer(m)));
3864 <        funs.add((y) -> m.thenApply(y, new IncFunction(m)));
3865 <
3866 <        funs.add((y) -> m.runAfterEither(y, incomplete, new Noop(m)));
3867 <        funs.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m)));
3868 <        funs.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3862 >        funs.add((y) -> m.thenRun(y, noopRunnable));
3863 >        funs.add((y) -> m.thenAccept(y, noopConsumer));
3864 >        funs.add((y) -> m.thenApply(y, incFunction));
3865 >
3866 >        funs.add((y) -> m.runAfterEither(y, incomplete, noopRunnable));
3867 >        funs.add((y) -> m.acceptEither(y, incomplete, noopConsumer));
3868 >        funs.add((y) -> m.applyToEither(y, incomplete, incFunction));
3869  
3870 <        funs.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3871 <        funs.add((y) -> m.runAfterBoth(v42, y, new Noop(m)));
3870 >        funs.add((y) -> m.runAfterBoth(y, v42, noopRunnable));
3871 >        funs.add((y) -> m.runAfterBoth(v42, y, noopRunnable));
3872          funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3873          funs.add((y) -> m.thenAcceptBoth(v42, y, new SubtractAction(m)));
3874          funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
# Line 3874 | Line 3878 | public class CompletableFutureTest exten
3878  
3879          funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3880  
3881 <        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y}));
3882 <        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42}));
3883 <        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {v42, y}));
3884 <        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y}));
3885 <        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete}));
3886 <        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {incomplete, y}));
3881 >        funs.add((y) -> CompletableFuture.allOf(y));
3882 >        funs.add((y) -> CompletableFuture.allOf(y, v42));
3883 >        funs.add((y) -> CompletableFuture.allOf(v42, y));
3884 >        funs.add((y) -> CompletableFuture.anyOf(y));
3885 >        funs.add((y) -> CompletableFuture.anyOf(y, incomplete));
3886 >        funs.add((y) -> CompletableFuture.anyOf(incomplete, y));
3887  
3888          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3889                   fun : funs) {
3890              CompletableFuture<Integer> f = new CompletableFuture<>();
3891              f.completeExceptionally(ex);
3892 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3892 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3893              checkCompletedWithWrappedException(src, ex);
3894              CompletableFuture<?> dep = fun.apply(src);
3895              checkCompletedWithWrappedException(dep, ex);
# Line 3895 | Line 3899 | public class CompletableFutureTest exten
3899          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3900                   fun : funs) {
3901              CompletableFuture<Integer> f = new CompletableFuture<>();
3902 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3902 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3903              CompletableFuture<?> dep = fun.apply(src);
3904              f.completeExceptionally(ex);
3905              checkCompletedWithWrappedException(src, ex);
# Line 3909 | Line 3913 | public class CompletableFutureTest exten
3913              CompletableFuture<Integer> f = new CompletableFuture<>();
3914              f.cancel(mayInterruptIfRunning);
3915              checkCancelled(f);
3916 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3916 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3917              checkCompletedWithWrappedCancellationException(src);
3918              CompletableFuture<?> dep = fun.apply(src);
3919              checkCompletedWithWrappedCancellationException(dep);
# Line 3920 | Line 3924 | public class CompletableFutureTest exten
3924          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3925                   fun : funs) {
3926              CompletableFuture<Integer> f = new CompletableFuture<>();
3927 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3927 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3928              CompletableFuture<?> dep = fun.apply(src);
3929              f.cancel(mayInterruptIfRunning);
3930              checkCancelled(f);
# Line 3931 | Line 3935 | public class CompletableFutureTest exten
3935      }}
3936  
3937      /**
3938 <     * Minimal completion stages throw UOE for all non-CompletionStage methods
3938 >     * Minimal completion stages throw UOE for most non-CompletionStage methods
3939       */
3940      public void testMinimalCompletionStage_minimality() {
3941          if (!testImplementationDetails) return;
# Line 3960 | Line 3964 | public class CompletableFutureTest exten
3964              .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method)))
3965              .collect(Collectors.toList());
3966  
3967 <        CompletionStage<Integer> minimalStage =
3968 <            new CompletableFuture<Integer>().minimalCompletionStage();
3967 >        List<CompletionStage<Integer>> stages = new ArrayList<>();
3968 >        stages.add(new CompletableFuture<Integer>().minimalCompletionStage());
3969 >        stages.add(CompletableFuture.completedStage(1));
3970 >        stages.add(CompletableFuture.failedStage(new CFException()));
3971  
3972          List<Method> bugs = new ArrayList<>();
3973          for (Method method : allMethods) {
# Line 3977 | Line 3983 | public class CompletableFutureTest exten
3983                  else if (parameterTypes[i] == long.class)
3984                      args[i] = 0L;
3985              }
3986 <            try {
3987 <                method.invoke(minimalStage, args);
3988 <                bugs.add(method);
3983 <            }
3984 <            catch (java.lang.reflect.InvocationTargetException expected) {
3985 <                if (! (expected.getCause() instanceof UnsupportedOperationException)) {
3986 >            for (CompletionStage<Integer> stage : stages) {
3987 >                try {
3988 >                    method.invoke(stage, args);
3989                      bugs.add(method);
3987                    // expected.getCause().printStackTrace();
3990                  }
3991 +                catch (java.lang.reflect.InvocationTargetException expected) {
3992 +                    if (! (expected.getCause() instanceof UnsupportedOperationException)) {
3993 +                        bugs.add(method);
3994 +                        // expected.getCause().printStackTrace();
3995 +                    }
3996 +                }
3997 +                catch (ReflectiveOperationException bad) { throw new Error(bad); }
3998              }
3990            catch (ReflectiveOperationException bad) { throw new Error(bad); }
3999          }
4000          if (!bugs.isEmpty())
4001 <            throw new Error("Methods did not throw UOE: " + bugs.toString());
4001 >            throw new Error("Methods did not throw UOE: " + bugs);
4002      }
4003  
4004      static class Monad {
# Line 4234 | Line 4242 | public class CompletableFutureTest exten
4242          }
4243      }
4244  
4245 <    /*
4246 <     * Tests below currently fail in stress mode due to memory retention.
4247 <     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck
4245 >    /**
4246 >     * Checks for garbage retention with anyOf.
4247 >     * Following used to fail with OOME:
4248 >     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testAnyOfGarbageRetention tck
4249       */
4241
4242    /** Checks for garbage retention with anyOf. */
4250      public void testAnyOfGarbageRetention() throws Throwable {
4251          for (Integer v : new Integer[] { 1, null })
4252      {
# Line 4253 | Line 4260 | public class CompletableFutureTest exten
4260              checkCompletedNormally(CompletableFuture.anyOf(fs), v);
4261      }}
4262  
4263 <    /** Checks for garbage retention with allOf. */
4263 >    /**
4264 >     * Checks for garbage retention with allOf.
4265 >     *
4266 >     * As of 2016-07, fails with OOME:
4267 >     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testCancelledAllOfGarbageRetention tck
4268 >     */
4269      public void testCancelledAllOfGarbageRetention() throws Throwable {
4270          final int n = expensiveTests ? 100_000 : 10;
4271          CompletableFuture<Integer>[] fs

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines