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.164 by jsr166, Sun Jul 3 18:58:15 2016 UTC vs.
Revision 1.171 by jsr166, Wed Aug 24 22:22:39 2016 UTC

# Line 32 | Line 32 | import java.util.concurrent.ForkJoinPool
32   import java.util.concurrent.ForkJoinTask;
33   import java.util.concurrent.RejectedExecutionException;
34   import java.util.concurrent.TimeoutException;
35 import java.util.concurrent.TimeUnit;
35   import java.util.concurrent.atomic.AtomicInteger;
36   import java.util.concurrent.atomic.AtomicReference;
37   import java.util.function.BiConsumer;
# Line 3935 | Line 3934 | public class CompletableFutureTest exten
3934      }}
3935  
3936      /**
3937 <     * Minimal completion stages throw UOE for all non-CompletionStage methods
3937 >     * Minimal completion stages throw UOE for most non-CompletionStage methods
3938       */
3939      public void testMinimalCompletionStage_minimality() {
3940          if (!testImplementationDetails) return;
# Line 3964 | Line 3963 | public class CompletableFutureTest exten
3963              .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method)))
3964              .collect(Collectors.toList());
3965  
3966 <        CompletionStage<Integer> minimalStage =
3967 <            new CompletableFuture<Integer>().minimalCompletionStage();
3966 >        List<CompletionStage<Integer>> stages = new ArrayList<>();
3967 >        stages.add(new CompletableFuture<Integer>().minimalCompletionStage());
3968 >        stages.add(CompletableFuture.completedStage(1));
3969 >        stages.add(CompletableFuture.failedStage(new CFException()));
3970  
3971          List<Method> bugs = new ArrayList<>();
3972          for (Method method : allMethods) {
# Line 3981 | Line 3982 | public class CompletableFutureTest exten
3982                  else if (parameterTypes[i] == long.class)
3983                      args[i] = 0L;
3984              }
3985 <            try {
3986 <                method.invoke(minimalStage, args);
3987 <                bugs.add(method);
3987 <            }
3988 <            catch (java.lang.reflect.InvocationTargetException expected) {
3989 <                if (! (expected.getCause() instanceof UnsupportedOperationException)) {
3985 >            for (CompletionStage<Integer> stage : stages) {
3986 >                try {
3987 >                    method.invoke(stage, args);
3988                      bugs.add(method);
3991                    // expected.getCause().printStackTrace();
3989                  }
3990 +                catch (java.lang.reflect.InvocationTargetException expected) {
3991 +                    if (! (expected.getCause() instanceof UnsupportedOperationException)) {
3992 +                        bugs.add(method);
3993 +                        // expected.getCause().printStackTrace();
3994 +                    }
3995 +                }
3996 +                catch (ReflectiveOperationException bad) { throw new Error(bad); }
3997              }
3994            catch (ReflectiveOperationException bad) { throw new Error(bad); }
3998          }
3999          if (!bugs.isEmpty())
4000 <            throw new Error("Methods did not throw UOE: " + bugs.toString());
4000 >            throw new Error("Methods did not throw UOE: " + bugs);
4001      }
4002  
4003      static class Monad {
# Line 4238 | Line 4241 | public class CompletableFutureTest exten
4241          }
4242      }
4243  
4244 <    /*
4245 <     * Tests below currently fail in stress mode due to memory retention.
4246 <     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck
4244 >    /**
4245 >     * Reproduction recipe for:
4246 >     * 8160402: Garbage retention with CompletableFuture.anyOf
4247 >     * cvs update -D '2016-05-01' ./src/main/java/util/concurrent/CompletableFuture.java && ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testAnyOfGarbageRetention tck; cvs update -A
4248       */
4245
4246    /** Checks for garbage retention with anyOf. */
4249      public void testAnyOfGarbageRetention() throws Throwable {
4250          for (Integer v : new Integer[] { 1, null })
4251      {
# Line 4257 | Line 4259 | public class CompletableFutureTest exten
4259              checkCompletedNormally(CompletableFuture.anyOf(fs), v);
4260      }}
4261  
4262 <    /** Checks for garbage retention with allOf. */
4262 >    /**
4263 >     * Checks for garbage retention with allOf.
4264 >     *
4265 >     * As of 2016-07, fails with OOME:
4266 >     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testCancelledAllOfGarbageRetention tck
4267 >     */
4268      public void testCancelledAllOfGarbageRetention() throws Throwable {
4269          final int n = expensiveTests ? 100_000 : 10;
4270          CompletableFuture<Integer>[] fs
# Line 4268 | Line 4275 | public class CompletableFutureTest exten
4275              assertTrue(CompletableFuture.allOf(fs).cancel(false));
4276      }
4277  
4278 +    /**
4279 +     * Checks for garbage retention when a dependent future is
4280 +     * cancelled and garbage-collected.
4281 +     * 8161600: Garbage retention when source CompletableFutures are never completed
4282 +     *
4283 +     * As of 2016-07, fails with OOME:
4284 +     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testCancelledGarbageRetention tck
4285 +     */
4286 +    public void testCancelledGarbageRetention() throws Throwable {
4287 +        final int n = expensiveTests ? 100_000 : 10;
4288 +        CompletableFuture<Integer> neverCompleted = new CompletableFuture<>();
4289 +        for (int i = 0; i < n; i++)
4290 +            assertTrue(neverCompleted.thenRun(() -> {}).cancel(true));
4291 +    }
4292 +
4293   //     static <U> U join(CompletionStage<U> stage) {
4294   //         CompletableFuture<U> f = new CompletableFuture<>();
4295   //         stage.whenComplete((v, ex) -> {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines