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.162 by jsr166, Sun Jul 3 15:27:28 2016 UTC vs.
Revision 1.176 by jsr166, Wed Sep 21 18:21:56 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 362 | Line 361 | public class CompletableFutureTest exten
361          checkCompletedNormally(f, "test");
362      }
363  
364 <    abstract class CheckedAction {
364 >    abstract static class CheckedAction {
365          int invocationCount = 0;
366          final ExecutionMode m;
367          CheckedAction(ExecutionMode m) { this.m = m; }
# Line 374 | Line 373 | public class CompletableFutureTest exten
373          void assertInvoked() { assertEquals(1, invocationCount); }
374      }
375  
376 <    abstract class CheckedIntegerAction extends CheckedAction {
376 >    abstract static class CheckedIntegerAction extends CheckedAction {
377          Integer value;
378          CheckedIntegerAction(ExecutionMode m) { super(m); }
379          void assertValue(Integer expected) {
# Line 383 | Line 382 | public class CompletableFutureTest exten
382          }
383      }
384  
385 <    class IntegerSupplier extends CheckedAction
385 >    static class IntegerSupplier extends CheckedAction
386          implements Supplier<Integer>
387      {
388          final Integer value;
# Line 402 | Line 401 | public class CompletableFutureTest exten
401          return (x == null) ? null : x + 1;
402      }
403  
404 <    class NoopConsumer extends CheckedIntegerAction
404 >    static class NoopConsumer extends CheckedIntegerAction
405          implements Consumer<Integer>
406      {
407          NoopConsumer(ExecutionMode m) { super(m); }
# Line 412 | Line 411 | public class CompletableFutureTest exten
411          }
412      }
413  
414 <    class IncFunction extends CheckedIntegerAction
414 >    static class IncFunction extends CheckedIntegerAction
415          implements Function<Integer,Integer>
416      {
417          IncFunction(ExecutionMode m) { super(m); }
# Line 430 | Line 429 | public class CompletableFutureTest exten
429              - ((y == null) ? 99 : y.intValue());
430      }
431  
432 <    class SubtractAction extends CheckedIntegerAction
432 >    static class SubtractAction extends CheckedIntegerAction
433          implements BiConsumer<Integer, Integer>
434      {
435          SubtractAction(ExecutionMode m) { super(m); }
# Line 440 | Line 439 | public class CompletableFutureTest exten
439          }
440      }
441  
442 <    class SubtractFunction extends CheckedIntegerAction
442 >    static class SubtractFunction extends CheckedIntegerAction
443          implements BiFunction<Integer, Integer, Integer>
444      {
445          SubtractFunction(ExecutionMode m) { super(m); }
# Line 450 | Line 449 | public class CompletableFutureTest exten
449          }
450      }
451  
452 <    class Noop extends CheckedAction implements Runnable {
452 >    static class Noop extends CheckedAction implements Runnable {
453          Noop(ExecutionMode m) { super(m); }
454          public void run() {
455              invoked();
456          }
457      }
458  
459 <    class FailingSupplier extends CheckedAction
459 >    static class FailingSupplier extends CheckedAction
460          implements Supplier<Integer>
461      {
462          final CFException ex;
# Line 468 | Line 467 | public class CompletableFutureTest exten
467          }
468      }
469  
470 <    class FailingConsumer extends CheckedIntegerAction
470 >    static class FailingConsumer extends CheckedIntegerAction
471          implements Consumer<Integer>
472      {
473          final CFException ex;
# Line 480 | Line 479 | public class CompletableFutureTest exten
479          }
480      }
481  
482 <    class FailingBiConsumer extends CheckedIntegerAction
482 >    static class FailingBiConsumer extends CheckedIntegerAction
483          implements BiConsumer<Integer, Integer>
484      {
485          final CFException ex;
# Line 492 | Line 491 | public class CompletableFutureTest exten
491          }
492      }
493  
494 <    class FailingFunction extends CheckedIntegerAction
494 >    static class FailingFunction extends CheckedIntegerAction
495          implements Function<Integer, Integer>
496      {
497          final CFException ex;
# Line 504 | Line 503 | public class CompletableFutureTest exten
503          }
504      }
505  
506 <    class FailingBiFunction extends CheckedIntegerAction
506 >    static class FailingBiFunction extends CheckedIntegerAction
507          implements BiFunction<Integer, Integer, Integer>
508      {
509          final CFException ex;
# Line 516 | Line 515 | public class CompletableFutureTest exten
515          }
516      }
517  
518 <    class FailingRunnable extends CheckedAction implements Runnable {
518 >    static class FailingRunnable extends CheckedAction implements Runnable {
519          final CFException ex;
520          FailingRunnable(ExecutionMode m) { super(m); ex = new CFException(); }
521          public void run() {
# Line 525 | Line 524 | public class CompletableFutureTest exten
524          }
525      }
526  
527 <    class CompletableFutureInc extends CheckedIntegerAction
527 >    static class CompletableFutureInc extends CheckedIntegerAction
528          implements Function<Integer, CompletableFuture<Integer>>
529      {
530          CompletableFutureInc(ExecutionMode m) { super(m); }
# Line 538 | Line 537 | public class CompletableFutureTest exten
537          }
538      }
539  
540 <    class FailingCompletableFutureFunction extends CheckedIntegerAction
540 >    static class FailingCompletableFutureFunction extends CheckedIntegerAction
541          implements Function<Integer, CompletableFuture<Integer>>
542      {
543          final CFException ex;
# Line 3578 | Line 3577 | public class CompletableFutureTest exten
3577       * copy returns a CompletableFuture that is completed normally,
3578       * with the same value, when source is.
3579       */
3580 <    public void testCopy() {
3580 >    public void testCopy_normalCompletion() {
3581 >        for (boolean createIncomplete : new boolean[] { true, false })
3582 >        for (Integer v1 : new Integer[] { 1, null })
3583 >    {
3584          CompletableFuture<Integer> f = new CompletableFuture<>();
3585 +        if (!createIncomplete) assertTrue(f.complete(v1));
3586          CompletableFuture<Integer> g = f.copy();
3587 <        checkIncomplete(f);
3588 <        checkIncomplete(g);
3589 <        f.complete(1);
3590 <        checkCompletedNormally(f, 1);
3591 <        checkCompletedNormally(g, 1);
3592 <    }
3587 >        if (createIncomplete) {
3588 >            checkIncomplete(f);
3589 >            checkIncomplete(g);
3590 >            assertTrue(f.complete(v1));
3591 >        }
3592 >        checkCompletedNormally(f, v1);
3593 >        checkCompletedNormally(g, v1);
3594 >    }}
3595  
3596      /**
3597       * copy returns a CompletableFuture that is completed exceptionally
3598       * when source is.
3599       */
3600 <    public void testCopy2() {
3600 >    public void testCopy_exceptionalCompletion() {
3601 >        for (boolean createIncomplete : new boolean[] { true, false })
3602 >    {
3603 >        CFException ex = new CFException();
3604          CompletableFuture<Integer> f = new CompletableFuture<>();
3605 +        if (!createIncomplete) f.completeExceptionally(ex);
3606          CompletableFuture<Integer> g = f.copy();
3607 <        checkIncomplete(f);
3608 <        checkIncomplete(g);
3609 <        CFException ex = new CFException();
3610 <        f.completeExceptionally(ex);
3607 >        if (createIncomplete) {
3608 >            checkIncomplete(f);
3609 >            checkIncomplete(g);
3610 >            f.completeExceptionally(ex);
3611 >        }
3612          checkCompletedExceptionally(f, ex);
3613          checkCompletedWithWrappedException(g, ex);
3614 +    }}
3615 +
3616 +    /**
3617 +     * Completion of a copy does not complete its source.
3618 +     */
3619 +    public void testCopy_oneWayPropagation() {
3620 +        CompletableFuture<Integer> f = new CompletableFuture<>();
3621 +        assertTrue(f.copy().complete(1));
3622 +        assertTrue(f.copy().complete(null));
3623 +        assertTrue(f.copy().cancel(true));
3624 +        assertTrue(f.copy().cancel(false));
3625 +        assertTrue(f.copy().completeExceptionally(new CFException()));
3626 +        checkIncomplete(f);
3627      }
3628  
3629      /**
# Line 3852 | Line 3875 | public class CompletableFutureTest exten
3875          final CompletableFuture<Integer> v42 = CompletableFuture.completedFuture(42);
3876          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3877  
3878 +        final Runnable noopRunnable = new Noop(m);
3879 +        final Consumer<Integer> noopConsumer = new NoopConsumer(m);
3880 +        final Function<Integer, Integer> incFunction = new IncFunction(m);
3881 +
3882          List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> funs
3883              = new ArrayList<>();
3884  
3885 <        funs.add((y) -> m.thenRun(y, new Noop(m)));
3886 <        funs.add((y) -> m.thenAccept(y, new NoopConsumer(m)));
3887 <        funs.add((y) -> m.thenApply(y, new IncFunction(m)));
3888 <
3889 <        funs.add((y) -> m.runAfterEither(y, incomplete, new Noop(m)));
3890 <        funs.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m)));
3891 <        funs.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3885 >        funs.add((y) -> m.thenRun(y, noopRunnable));
3886 >        funs.add((y) -> m.thenAccept(y, noopConsumer));
3887 >        funs.add((y) -> m.thenApply(y, incFunction));
3888 >
3889 >        funs.add((y) -> m.runAfterEither(y, incomplete, noopRunnable));
3890 >        funs.add((y) -> m.acceptEither(y, incomplete, noopConsumer));
3891 >        funs.add((y) -> m.applyToEither(y, incomplete, incFunction));
3892  
3893 <        funs.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3894 <        funs.add((y) -> m.runAfterBoth(v42, y, new Noop(m)));
3893 >        funs.add((y) -> m.runAfterBoth(y, v42, noopRunnable));
3894 >        funs.add((y) -> m.runAfterBoth(v42, y, noopRunnable));
3895          funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3896          funs.add((y) -> m.thenAcceptBoth(v42, y, new SubtractAction(m)));
3897          funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
# Line 3874 | Line 3901 | public class CompletableFutureTest exten
3901  
3902          funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3903  
3904 <        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y}));
3905 <        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42}));
3906 <        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {v42, y}));
3907 <        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y}));
3908 <        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete}));
3909 <        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {incomplete, y}));
3904 >        funs.add((y) -> CompletableFuture.allOf(y));
3905 >        funs.add((y) -> CompletableFuture.allOf(y, v42));
3906 >        funs.add((y) -> CompletableFuture.allOf(v42, y));
3907 >        funs.add((y) -> CompletableFuture.anyOf(y));
3908 >        funs.add((y) -> CompletableFuture.anyOf(y, incomplete));
3909 >        funs.add((y) -> CompletableFuture.anyOf(incomplete, y));
3910  
3911          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3912                   fun : funs) {
3913              CompletableFuture<Integer> f = new CompletableFuture<>();
3914              f.completeExceptionally(ex);
3915 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3915 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3916              checkCompletedWithWrappedException(src, ex);
3917              CompletableFuture<?> dep = fun.apply(src);
3918              checkCompletedWithWrappedException(dep, ex);
# Line 3895 | Line 3922 | public class CompletableFutureTest exten
3922          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3923                   fun : funs) {
3924              CompletableFuture<Integer> f = new CompletableFuture<>();
3925 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3925 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3926              CompletableFuture<?> dep = fun.apply(src);
3927              f.completeExceptionally(ex);
3928              checkCompletedWithWrappedException(src, ex);
# Line 3909 | Line 3936 | public class CompletableFutureTest exten
3936              CompletableFuture<Integer> f = new CompletableFuture<>();
3937              f.cancel(mayInterruptIfRunning);
3938              checkCancelled(f);
3939 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3939 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3940              checkCompletedWithWrappedCancellationException(src);
3941              CompletableFuture<?> dep = fun.apply(src);
3942              checkCompletedWithWrappedCancellationException(dep);
# Line 3920 | Line 3947 | public class CompletableFutureTest exten
3947          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3948                   fun : funs) {
3949              CompletableFuture<Integer> f = new CompletableFuture<>();
3950 <            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3950 >            CompletableFuture<Integer> src = m.thenApply(f, incFunction);
3951              CompletableFuture<?> dep = fun.apply(src);
3952              f.cancel(mayInterruptIfRunning);
3953              checkCancelled(f);
# Line 3931 | Line 3958 | public class CompletableFutureTest exten
3958      }}
3959  
3960      /**
3961 <     * Minimal completion stages throw UOE for all non-CompletionStage methods
3961 >     * Minimal completion stages throw UOE for most non-CompletionStage methods
3962       */
3963      public void testMinimalCompletionStage_minimality() {
3964          if (!testImplementationDetails) return;
# Line 3960 | Line 3987 | public class CompletableFutureTest exten
3987              .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method)))
3988              .collect(Collectors.toList());
3989  
3990 <        CompletionStage<Integer> minimalStage =
3990 >        List<CompletionStage<Integer>> stages = new ArrayList<>();
3991 >        CompletionStage<Integer> min =
3992              new CompletableFuture<Integer>().minimalCompletionStage();
3993 +        stages.add(min);
3994 +        stages.add(min.thenApply(x -> x));
3995 +        stages.add(CompletableFuture.completedStage(1));
3996 +        stages.add(CompletableFuture.failedStage(new CFException()));
3997  
3998          List<Method> bugs = new ArrayList<>();
3999          for (Method method : allMethods) {
# Line 3977 | Line 4009 | public class CompletableFutureTest exten
4009                  else if (parameterTypes[i] == long.class)
4010                      args[i] = 0L;
4011              }
4012 <            try {
4013 <                method.invoke(minimalStage, args);
4014 <                bugs.add(method);
3983 <            }
3984 <            catch (java.lang.reflect.InvocationTargetException expected) {
3985 <                if (! (expected.getCause() instanceof UnsupportedOperationException)) {
4012 >            for (CompletionStage<Integer> stage : stages) {
4013 >                try {
4014 >                    method.invoke(stage, args);
4015                      bugs.add(method);
3987                    // expected.getCause().printStackTrace();
4016                  }
4017 +                catch (java.lang.reflect.InvocationTargetException expected) {
4018 +                    if (! (expected.getCause() instanceof UnsupportedOperationException)) {
4019 +                        bugs.add(method);
4020 +                        // expected.getCause().printStackTrace();
4021 +                    }
4022 +                }
4023 +                catch (ReflectiveOperationException bad) { throw new Error(bad); }
4024              }
3990            catch (ReflectiveOperationException bad) { throw new Error(bad); }
4025          }
4026          if (!bugs.isEmpty())
4027 <            throw new Error("Methods did not throw UOE: " + bugs.toString());
4027 >            throw new Error("Methods did not throw UOE: " + bugs);
4028 >    }
4029 >
4030 >    /**
4031 >     * minimalStage.toCompletableFuture() returns a CompletableFuture that
4032 >     * is completed normally, with the same value, when source is.
4033 >     */
4034 >    public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() {
4035 >        for (boolean createIncomplete : new boolean[] { true, false })
4036 >        for (Integer v1 : new Integer[] { 1, null })
4037 >    {
4038 >        CompletableFuture<Integer> f = new CompletableFuture<>();
4039 >        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4040 >        if (!createIncomplete) assertTrue(f.complete(v1));
4041 >        CompletableFuture<Integer> g = minimal.toCompletableFuture();
4042 >        if (createIncomplete) {
4043 >            checkIncomplete(f);
4044 >            checkIncomplete(g);
4045 >            assertTrue(f.complete(v1));
4046 >        }
4047 >        checkCompletedNormally(f, v1);
4048 >        checkCompletedNormally(g, v1);
4049 >    }}
4050 >
4051 >    /**
4052 >     * minimalStage.toCompletableFuture() gives mutable CompletableFuture
4053 >     */
4054 >    public void testMinimalCompletionStage_toCompletableFuture_mutable() {
4055 >        for (Integer v1 : new Integer[] { 1, null })
4056 >    {
4057 >        CompletableFuture<Integer> f = new CompletableFuture<>();
4058 >        CompletionStage minimal = f.minimalCompletionStage();
4059 >        CompletableFuture<Integer> g = minimal.toCompletableFuture();
4060 >        g.complete(v1);
4061 >        checkCompletedNormally(g, v1);
4062 >        checkIncomplete(f);
4063 >        checkIncomplete(minimal.toCompletableFuture());
4064 >    }}
4065 >
4066 >    /**
4067 >     * minimalStage.toCompletableFuture().join() awaits completion
4068 >     */
4069 >    public void testMinimalCompletionStage_toCompletableFuture_join() throws Exception {
4070 >        for (boolean createIncomplete : new boolean[] { true, false })
4071 >        for (Integer v1 : new Integer[] { 1, null })
4072 >    {
4073 >        CompletableFuture<Integer> f = new CompletableFuture<>();
4074 >        if (!createIncomplete) assertTrue(f.complete(v1));
4075 >        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4076 >        if (createIncomplete) assertTrue(f.complete(v1));
4077 >        assertEquals(v1, minimal.toCompletableFuture().join());
4078 >        assertEquals(v1, minimal.toCompletableFuture().get());
4079 >        checkCompletedNormally(minimal.toCompletableFuture(), v1);
4080 >    }}
4081 >
4082 >    /**
4083 >     * Completion of a toCompletableFuture copy of a minimal stage
4084 >     * does not complete its source.
4085 >     */
4086 >    public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() {
4087 >        CompletableFuture<Integer> f = new CompletableFuture<>();
4088 >        CompletionStage<Integer> g = f.minimalCompletionStage();
4089 >        assertTrue(g.toCompletableFuture().complete(1));
4090 >        assertTrue(g.toCompletableFuture().complete(null));
4091 >        assertTrue(g.toCompletableFuture().cancel(true));
4092 >        assertTrue(g.toCompletableFuture().cancel(false));
4093 >        assertTrue(g.toCompletableFuture().completeExceptionally(new CFException()));
4094 >        checkIncomplete(g.toCompletableFuture());
4095 >        f.complete(1);
4096 >        checkCompletedNormally(g.toCompletableFuture(), 1);
4097 >    }
4098 >
4099 >    /** Demo utility method for external reliable toCompletableFuture */
4100 >    static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) {
4101 >        CompletableFuture<T> f = new CompletableFuture<>();
4102 >        stage.handle((T t, Throwable ex) -> {
4103 >                         if (ex != null) f.completeExceptionally(ex);
4104 >                         else f.complete(t);
4105 >                         return null;
4106 >                     });
4107 >        return f;
4108 >    }
4109 >
4110 >    /** Demo utility method to join a CompletionStage */
4111 >    static <T> T join(CompletionStage<T> stage) {
4112 >        return toCompletableFuture(stage).join();
4113      }
4114  
4115 +    /**
4116 +     * Joining a minimal stage "by hand" works
4117 +     */
4118 +    public void testMinimalCompletionStage_join_by_hand() {
4119 +        for (boolean createIncomplete : new boolean[] { true, false })
4120 +        for (Integer v1 : new Integer[] { 1, null })
4121 +    {
4122 +        CompletableFuture<Integer> f = new CompletableFuture<>();
4123 +        CompletionStage<Integer> minimal = f.minimalCompletionStage();
4124 +        CompletableFuture<Integer> g = new CompletableFuture<>();
4125 +        if (!createIncomplete) assertTrue(f.complete(v1));
4126 +        minimal.thenAccept((x) -> g.complete(x));
4127 +        if (createIncomplete) assertTrue(f.complete(v1));
4128 +        g.join();
4129 +        checkCompletedNormally(g, v1);
4130 +        checkCompletedNormally(f, v1);
4131 +        assertEquals(v1, join(minimal));
4132 +    }}
4133 +
4134      static class Monad {
4135          static class ZeroException extends RuntimeException {
4136              public ZeroException() { super("monadic zero"); }
# Line 4139 | Line 4277 | public class CompletableFutureTest exten
4277                                   Monad.plus(godot, Monad.unit(5L)));
4278      }
4279  
4280 +    /** Test long recursive chains of CompletableFutures with cascading completions */
4281 +    public void testRecursiveChains() throws Throwable {
4282 +        for (ExecutionMode m : ExecutionMode.values())
4283 +        for (boolean addDeadEnds : new boolean[] { true, false })
4284 +    {
4285 +        final int val = 42;
4286 +        final int n = expensiveTests ? 1_000 : 2;
4287 +        CompletableFuture<Integer> head = new CompletableFuture<>();
4288 +        CompletableFuture<Integer> tail = head;
4289 +        for (int i = 0; i < n; i++) {
4290 +            if (addDeadEnds) m.thenApply(tail, v -> v + 1);
4291 +            tail = m.thenApply(tail, v -> v + 1);
4292 +            if (addDeadEnds) m.applyToEither(tail, tail, v -> v + 1);
4293 +            tail = m.applyToEither(tail, tail, v -> v + 1);
4294 +            if (addDeadEnds) m.thenCombine(tail, tail, (v, w) -> v + 1);
4295 +            tail = m.thenCombine(tail, tail, (v, w) -> v + 1);
4296 +        }
4297 +        head.complete(val);
4298 +        assertEquals(val + 3 * n, (int) tail.join());
4299 +    }}
4300 +
4301      /**
4302       * A single CompletableFuture with many dependents.
4303       * A demo of scalability - runtime is O(n).
# Line 4213 | Line 4372 | public class CompletableFutureTest exten
4372          }
4373      }
4374  
4375 <    /*
4376 <     * Tests below currently fail in stress mode due to memory retention.
4377 <     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck
4375 >    /**
4376 >     * Reproduction recipe for:
4377 >     * 8160402: Garbage retention with CompletableFuture.anyOf
4378 >     * 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
4379       */
4220
4221    /** Checks for garbage retention with anyOf. */
4380      public void testAnyOfGarbageRetention() throws Throwable {
4381          for (Integer v : new Integer[] { 1, null })
4382      {
# Line 4232 | Line 4390 | public class CompletableFutureTest exten
4390              checkCompletedNormally(CompletableFuture.anyOf(fs), v);
4391      }}
4392  
4393 <    /** Checks for garbage retention with allOf. */
4393 >    /**
4394 >     * Checks for garbage retention with allOf.
4395 >     *
4396 >     * As of 2016-07, fails with OOME:
4397 >     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testCancelledAllOfGarbageRetention tck
4398 >     */
4399      public void testCancelledAllOfGarbageRetention() throws Throwable {
4400          final int n = expensiveTests ? 100_000 : 10;
4401          CompletableFuture<Integer>[] fs
# Line 4243 | Line 4406 | public class CompletableFutureTest exten
4406              assertTrue(CompletableFuture.allOf(fs).cancel(false));
4407      }
4408  
4409 +    /**
4410 +     * Checks for garbage retention when a dependent future is
4411 +     * cancelled and garbage-collected.
4412 +     * 8161600: Garbage retention when source CompletableFutures are never completed
4413 +     *
4414 +     * As of 2016-07, fails with OOME:
4415 +     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testCancelledGarbageRetention tck
4416 +     */
4417 +    public void testCancelledGarbageRetention() throws Throwable {
4418 +        final int n = expensiveTests ? 100_000 : 10;
4419 +        CompletableFuture<Integer> neverCompleted = new CompletableFuture<>();
4420 +        for (int i = 0; i < n; i++)
4421 +            assertTrue(neverCompleted.thenRun(() -> {}).cancel(true));
4422 +    }
4423 +
4424   //     static <U> U join(CompletionStage<U> stage) {
4425   //         CompletableFuture<U> f = new CompletableFuture<>();
4426   //         stage.whenComplete((v, ex) -> {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines