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

# Line 4139 | Line 4139 | public class CompletableFutureTest exten
4139                                   Monad.plus(godot, Monad.unit(5L)));
4140      }
4141  
4142 +    /** Test long recursive chains of CompletableFutures with cascading completions */
4143 +    public void testRecursiveChains() throws Throwable {
4144 +        for (ExecutionMode m : ExecutionMode.values())
4145 +        for (boolean addDeadEnds : new boolean[] { true, false })
4146 +    {
4147 +        final int val = 42;
4148 +        final int n = expensiveTests ? 1_000 : 2;
4149 +        CompletableFuture<Integer> head = new CompletableFuture<>();
4150 +        CompletableFuture<Integer> tail = head;
4151 +        for (int i = 0; i < n; i++) {
4152 +            if (addDeadEnds) m.thenApply(tail, v -> v + 1);
4153 +            tail = m.thenApply(tail, v -> v + 1);
4154 +            if (addDeadEnds) m.applyToEither(tail, tail, v -> v + 1);
4155 +            tail = m.applyToEither(tail, tail, v -> v + 1);
4156 +            if (addDeadEnds) m.thenCombine(tail, tail, (v, w) -> v + 1);
4157 +            tail = m.thenCombine(tail, tail, (v, w) -> v + 1);
4158 +        }
4159 +        head.complete(val);
4160 +        assertEquals(val + 3 * n, (int) tail.join());
4161 +    }}
4162 +
4163      /**
4164       * A single CompletableFuture with many dependents.
4165       * A demo of scalability - runtime is O(n).

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines