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.85 by jsr166, Mon Jun 16 20:44:14 2014 UTC

# Line 3118 | Line 3118 | public class CompletableFutureTest exten
3118          assertSame(f, f.toCompletableFuture());
3119      }
3120  
3121 < //     public void testRunAfterEither_resultDeterminedAtTimeOfCreation() {
3122 < //         for (ExecutionMode m : ExecutionMode.values())
3123 < //         for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3124 < //         for (Integer v1 : new Integer[] { 1, null })
3125 < //     {
3126 < //         final CompletableFuture<Integer> f = new CompletableFuture<>();
3127 < //         final CompletableFuture<Integer> g = new CompletableFuture<>();
3128 < //         final Noop[] rs = new Noop[2];
3129 < //         for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m);
3130 < //         f.complete(v1);
3131 < //         final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]);
3132 < //         final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]);
3133 < //         assertTrue(g.cancel(mayInterruptIfRunning));
3134 < //         checkCompletedNormally(h0, null);
3135 < //         checkCompletedNormally(h1, null);
3136 < //         for (Noop r : rs) r.assertInvoked();
3137 < //     }}
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 >        dependentFactories.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42}));
3160 >        dependentFactories.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete}));
3161 >
3162 >        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3163 >                 dependentFactory : dependentFactories) {
3164 >            CompletableFuture<Integer> f = new CompletableFuture<>();
3165 >            f.completeExceptionally(ex);
3166 >            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3167 >            checkCompletedWithWrappedException(src, ex);
3168 >            CompletableFuture<?> dep = dependentFactory.apply(src);
3169 >            checkCompletedWithWrappedException(dep, ex);
3170 >            assertSame(resultOf(src), resultOf(dep));
3171 >        }
3172 >
3173 >        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3174 >                 dependentFactory : dependentFactories) {
3175 >            CompletableFuture<Integer> f = new CompletableFuture<>();
3176 >            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3177 >            CompletableFuture<?> dep = dependentFactory.apply(src);
3178 >            f.completeExceptionally(ex);
3179 >            checkCompletedWithWrappedException(src, ex);
3180 >            checkCompletedWithWrappedException(dep, ex);
3181 >            assertSame(resultOf(src), resultOf(dep));
3182 >        }
3183 >
3184 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3185 >        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3186 >                 dependentFactory : dependentFactories) {
3187 >            CompletableFuture<Integer> f = new CompletableFuture<>();
3188 >            f.cancel(mayInterruptIfRunning);
3189 >            checkCancelled(f);
3190 >            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3191 >            checkCompletedWithWrappedCancellationException(src);
3192 >            CompletableFuture<?> dep = dependentFactory.apply(src);
3193 >            checkCompletedWithWrappedCancellationException(dep);
3194 >            assertSame(resultOf(src), resultOf(dep));
3195 >        }
3196 >
3197 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3198 >        for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3199 >                 dependentFactory : dependentFactories) {
3200 >            CompletableFuture<Integer> f = new CompletableFuture<>();
3201 >            CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3202 >            CompletableFuture<?> dep = dependentFactory.apply(src);
3203 >            f.cancel(mayInterruptIfRunning);
3204 >            checkCancelled(f);
3205 >            checkCompletedWithWrappedCancellationException(src);
3206 >            checkCompletedWithWrappedCancellationException(dep);
3207 >            assertSame(resultOf(src), resultOf(dep));
3208 >        }
3209 >    }}
3210  
3211   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines