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.95 by jsr166, Wed Jun 25 15:32:10 2014 UTC vs.
Revision 1.100 by jsr166, Thu Jan 15 18:34:19 2015 UTC

# Line 5 | Line 5
5   * http://creativecommons.org/publicdomain/zero/1.0/
6   */
7  
8 < import junit.framework.*;
8 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
9 > import static java.util.concurrent.TimeUnit.SECONDS;
10 >
11 > import java.util.ArrayList;
12 > import java.util.List;
13 > import java.util.Objects;
14   import java.util.concurrent.Callable;
10 import java.util.concurrent.Executor;
11 import java.util.concurrent.ExecutorService;
12 import java.util.concurrent.Executors;
15   import java.util.concurrent.CancellationException;
14 import java.util.concurrent.CountDownLatch;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Future;
16   import java.util.concurrent.CompletableFuture;
17   import java.util.concurrent.CompletionException;
18   import java.util.concurrent.CompletionStage;
19 + import java.util.concurrent.ExecutionException;
20 + import java.util.concurrent.Executor;
21   import java.util.concurrent.ForkJoinPool;
22   import java.util.concurrent.ForkJoinTask;
23   import java.util.concurrent.TimeoutException;
24   import java.util.concurrent.atomic.AtomicInteger;
24 import static java.util.concurrent.TimeUnit.MILLISECONDS;
25 import static java.util.concurrent.TimeUnit.SECONDS;
26 import java.util.*;
27 import java.util.function.Supplier;
28 import java.util.function.Consumer;
25   import java.util.function.BiConsumer;
30 import java.util.function.Function;
26   import java.util.function.BiFunction;
27 + import java.util.function.Consumer;
28 + import java.util.function.Function;
29 + import java.util.function.Supplier;
30 +
31 + import junit.framework.Test;
32 + import junit.framework.TestSuite;
33  
34   public class CompletableFutureTest extends JSR166TestCase {
35  
# Line 545 | Line 546 | public class CompletableFutureTest exten
546          }
547      }
548  
548
549      class CompletableFutureInc extends CheckedIntegerAction
550          implements Function<Integer, CompletableFuture<Integer>>
551      {
# Line 584 | Line 584 | public class CompletableFutureTest exten
584          }
585      }
586  
587 +    static final boolean defaultExecutorIsCommonPool
588 +        = ForkJoinPool.getCommonPoolParallelism() > 1;
589 +
590      /**
591       * Permits the testing of parallel code for the 3 different
592       * execution modes without copy/pasting all the test methods.
# Line 665 | Line 668 | public class CompletableFutureTest exten
668  
669          ASYNC {
670              public void checkExecutionMode() {
671 <                assertSame(ForkJoinPool.commonPool(),
672 <                           ForkJoinTask.getPool());
671 >                assertEquals(defaultExecutorIsCommonPool,
672 >                             (ForkJoinPool.commonPool() == ForkJoinTask.getPool()));
673              }
674              public CompletableFuture<Void> runAsync(Runnable a) {
675                  return CompletableFuture.runAsync(a);
# Line 2990 | Line 2993 | public class CompletableFutureTest exten
2993          checkCancelled(f);
2994      }}
2995  
2996 +    /**
2997 +     * thenCompose result completes exceptionally if the result of the action does
2998 +     */
2999 +    public void testThenCompose_actionReturnsFailingFuture() {
3000 +        for (ExecutionMode m : ExecutionMode.values())
3001 +        for (int order = 0; order < 6; order++)
3002 +        for (Integer v1 : new Integer[] { 1, null })
3003 +    {
3004 +        final CFException ex = new CFException();
3005 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
3006 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
3007 +        final CompletableFuture<Integer> h;
3008 +        // Test all permutations of orders
3009 +        switch (order) {
3010 +        case 0:
3011 +            assertTrue(f.complete(v1));
3012 +            assertTrue(g.completeExceptionally(ex));
3013 +            h = m.thenCompose(f, (x -> g));
3014 +            break;
3015 +        case 1:
3016 +            assertTrue(f.complete(v1));
3017 +            h = m.thenCompose(f, (x -> g));
3018 +            assertTrue(g.completeExceptionally(ex));
3019 +            break;
3020 +        case 2:
3021 +            assertTrue(g.completeExceptionally(ex));
3022 +            assertTrue(f.complete(v1));
3023 +            h = m.thenCompose(f, (x -> g));
3024 +            break;
3025 +        case 3:
3026 +            assertTrue(g.completeExceptionally(ex));
3027 +            h = m.thenCompose(f, (x -> g));
3028 +            assertTrue(f.complete(v1));
3029 +            break;
3030 +        case 4:
3031 +            h = m.thenCompose(f, (x -> g));
3032 +            assertTrue(f.complete(v1));
3033 +            assertTrue(g.completeExceptionally(ex));
3034 +            break;
3035 +        case 5:
3036 +            h = m.thenCompose(f, (x -> g));
3037 +            assertTrue(f.complete(v1));
3038 +            assertTrue(g.completeExceptionally(ex));
3039 +            break;
3040 +        default: throw new AssertionError();
3041 +        }
3042 +
3043 +        checkCompletedExceptionally(g, ex);
3044 +        checkCompletedWithWrappedException(h, ex);
3045 +        checkCompletedNormally(f, v1);
3046 +    }}
3047 +
3048      // other static methods
3049  
3050      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines