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.81 by jsr166, Mon Jun 16 17:41:26 2014 UTC vs.
Revision 1.83 by jsr166, Mon Jun 16 20:16:32 2014 UTC

# Line 3118 | Line 3118 | public class CompletableFutureTest exten
3118          assertSame(f, f.toCompletableFuture());
3119      }
3120  
3121 +    //--- tests of implementation details; not part of official tck ---
3122 +
3123 +    Object resultOf(CompletableFuture<?> f) {
3124 +        try {
3125 +            java.lang.reflect.Field resultField
3126 +                = CompletableFuture.class.getDeclaredField("result");
3127 +            resultField.setAccessible(true);
3128 +            return resultField.get(f);
3129 +        } catch (Throwable t) { throw new AssertionError(t); }
3130 +    }
3131 +
3132 +    public void testExceptionPropagationReusesResultObject() {
3133 +        if (!testImplementationDetails) return;
3134 +        for (ExecutionMode m : ExecutionMode.values())
3135 +    {
3136 +        final CFException ex = new CFException();
3137 +        final CompletableFuture<Integer> v42 = CompletableFuture.completedFuture(42);
3138 +        final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3139 +
3140 +        List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> dependentFactories
3141 +            = new ArrayList<>();
3142 +
3143 +        dependentFactories.add((y) -> m.thenRun(y, new Noop(m)));
3144 +        dependentFactories.add((y) -> m.thenAccept(y, new NoopConsumer(m)));
3145 +        dependentFactories.add((y) -> m.thenApply(y, new IncFunction(m)));
3146 +
3147 +        dependentFactories.add((y) -> m.runAfterEither(y, incomplete, new Noop(m)));
3148 +        dependentFactories.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m)));
3149 +        dependentFactories.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3150 +
3151 +        dependentFactories.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3152 +        dependentFactories.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3153 +        dependentFactories.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
3154 +
3155 +        dependentFactories.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {}));
3156 +
3157 +        dependentFactories.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3158 +
3159 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3160 +                 dependentFactory : dependentFactories) {
3161 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3162 +            f.completeExceptionally(ex);
3163 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3164 +            checkCompletedWithWrappedException(src, ex);
3165 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3166 +            checkCompletedWithWrappedException(dep, ex);
3167 +            assertSame(resultOf(src), resultOf(dep));
3168 +        }
3169 +
3170 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3171 +                 dependentFactory : dependentFactories) {
3172 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3173 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3174 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3175 +            f.completeExceptionally(ex);
3176 +            checkCompletedWithWrappedException(src, ex);
3177 +            checkCompletedWithWrappedException(dep, ex);
3178 +            assertSame(resultOf(src), resultOf(dep));
3179 +        }
3180 +
3181 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3182 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3183 +                 dependentFactory : dependentFactories) {
3184 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3185 +            f.cancel(mayInterruptIfRunning);
3186 +            checkCancelled(f);
3187 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3188 +            checkCompletedWithWrappedCancellationException(src);
3189 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3190 +            checkCompletedWithWrappedCancellationException(dep);
3191 +            assertSame(resultOf(src), resultOf(dep));
3192 +        }
3193 +
3194 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3195 +        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3196 +                 dependentFactory : dependentFactories) {
3197 +            CompletableFuture<Integer> f = new CompletableFuture<>();
3198 +            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3199 +            CompletableFuture<?> dep = dependentFactory.apply(src);
3200 +            f.cancel(mayInterruptIfRunning);
3201 +            checkCancelled(f);
3202 +            checkCompletedWithWrappedCancellationException(src);
3203 +            checkCompletedWithWrappedCancellationException(dep);
3204 +            assertSame(resultOf(src), resultOf(dep));
3205 +        }
3206 +    }}
3207 +
3208   //     public void testRunAfterEither_resultDeterminedAtTimeOfCreation() {
3209   //         for (ExecutionMode m : ExecutionMode.values())
3210   //         for (boolean mayInterruptIfRunning : new boolean[] { true, false })

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines