3133 |
|
if (!testImplementationDetails) return; |
3134 |
|
for (ExecutionMode m : ExecutionMode.values()) |
3135 |
|
{ |
3136 |
< |
final CompletableFuture<Void> f = new CompletableFuture<>(); |
3137 |
< |
CFException ex = new CFException(); |
3138 |
< |
f.completeExceptionally(ex); |
3139 |
< |
final CompletableFuture<Void> g = f.thenRun(new Noop(m)); |
3140 |
< |
checkCompletedWithWrappedException(g, ex); |
3141 |
< |
final CompletableFuture<Void> h = g.thenRun(new Noop(m)); |
3142 |
< |
checkCompletedWithWrappedException(h, ex); |
3143 |
< |
assertSame(resultOf(g), resultOf(h)); |
3144 |
< |
}} |
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 |
< |
// public void testRunAfterEither_resultDeterminedAtTimeOfCreation() { |
3158 |
< |
// for (ExecutionMode m : ExecutionMode.values()) |
3159 |
< |
// for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
3160 |
< |
// for (Integer v1 : new Integer[] { 1, null }) |
3161 |
< |
// { |
3162 |
< |
// final CompletableFuture<Integer> f = new CompletableFuture<>(); |
3163 |
< |
// final CompletableFuture<Integer> g = new CompletableFuture<>(); |
3164 |
< |
// final Noop[] rs = new Noop[2]; |
3165 |
< |
// for (int i = 0; i < rs.length; i++) rs[i] = new Noop(m); |
3166 |
< |
// f.complete(v1); |
3167 |
< |
// final CompletableFuture<Void> h0 = m.runAfterEither(f, g, rs[0]); |
3168 |
< |
// final CompletableFuture<Void> h1 = m.runAfterEither(g, f, rs[1]); |
3169 |
< |
// assertTrue(g.cancel(mayInterruptIfRunning)); |
3170 |
< |
// checkCompletedNormally(h0, null); |
3171 |
< |
// checkCompletedNormally(h1, null); |
3172 |
< |
// for (Noop r : rs) r.assertInvoked(); |
3173 |
< |
// }} |
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 |
|
} |