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.87 by jsr166, Mon Jun 16 21:14:16 2014 UTC vs.
Revision 1.89 by jsr166, Mon Jun 16 21:34:49 2014 UTC

# Line 2922 | Line 2922 | public class CompletableFutureTest exten
2922       * when all components complete normally
2923       */
2924      public void testAllOf_normal() throws Exception {
2925 <        for (int k = 1; k < 20; k++) {
2925 >        for (int k = 1; k < 10; k++) {
2926              CompletableFuture<Integer>[] fs
2927                  = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2928              for (int i = 0; i < k; i++)
# Line 2939 | Line 2939 | public class CompletableFutureTest exten
2939      }
2940  
2941      public void testAllOf_backwards() throws Exception {
2942 <        for (int k = 1; k < 20; k++) {
2942 >        for (int k = 1; k < 10; k++) {
2943              CompletableFuture<Integer>[] fs
2944                  = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2945              for (int i = 0; i < k; i++)
# Line 2955 | Line 2955 | public class CompletableFutureTest exten
2955          }
2956      }
2957  
2958 +    public void testAllOf_exceptional() throws Exception {
2959 +        for (int k = 1; k < 10; k++) {
2960 +            CompletableFuture<Integer>[] fs
2961 +                = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2962 +            CFException ex = new CFException();
2963 +            for (int i = 0; i < k; i++)
2964 +                fs[i] = new CompletableFuture<>();
2965 +            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2966 +            for (int i = 0; i < k; i++) {
2967 +                checkIncomplete(f);
2968 +                checkIncomplete(CompletableFuture.allOf(fs));
2969 +                if (i != k/2) {
2970 +                    fs[i].complete(i);
2971 +                    checkCompletedNormally(fs[i], i);
2972 +                } else {
2973 +                    fs[i].completeExceptionally(ex);
2974 +                    checkCompletedExceptionally(fs[i], ex);
2975 +                }
2976 +            }
2977 +            checkCompletedWithWrappedException(f, ex);
2978 +            checkCompletedWithWrappedException(CompletableFuture.allOf(fs), ex);
2979 +        }
2980 +    }
2981 +
2982      /**
2983       * anyOf(no component futures) returns an incomplete future
2984       */
# Line 3179 | Line 3203 | public class CompletableFutureTest exten
3203          final CompletableFuture<Integer> v42 = CompletableFuture.completedFuture(42);
3204          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3205  
3206 <        List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> dependentFactories
3206 >        List<Function<CompletableFuture<Integer>, CompletableFuture<?>>> funs
3207              = new ArrayList<>();
3208  
3209 <        dependentFactories.add((y) -> m.thenRun(y, new Noop(m)));
3210 <        dependentFactories.add((y) -> m.thenAccept(y, new NoopConsumer(m)));
3211 <        dependentFactories.add((y) -> m.thenApply(y, new IncFunction(m)));
3209 >        funs.add((y) -> m.thenRun(y, new Noop(m)));
3210 >        funs.add((y) -> m.thenAccept(y, new NoopConsumer(m)));
3211 >        funs.add((y) -> m.thenApply(y, new IncFunction(m)));
3212  
3213 <        dependentFactories.add((y) -> m.runAfterEither(y, incomplete, new Noop(m)));
3214 <        dependentFactories.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m)));
3215 <        dependentFactories.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3213 >        funs.add((y) -> m.runAfterEither(y, incomplete, new Noop(m)));
3214 >        funs.add((y) -> m.acceptEither(y, incomplete, new NoopConsumer(m)));
3215 >        funs.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m)));
3216  
3217 <        dependentFactories.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3218 <        dependentFactories.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3219 <        dependentFactories.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
3217 >        funs.add((y) -> m.runAfterBoth(y, v42, new Noop(m)));
3218 >        funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m)));
3219 >        funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m)));
3220  
3221 <        dependentFactories.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {}));
3221 >        funs.add((y) -> m.whenComplete(y, (Integer x, Throwable t) -> {}));
3222  
3223 <        dependentFactories.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3223 >        funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m)));
3224  
3225 <        dependentFactories.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42}));
3226 <        dependentFactories.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete}));
3225 >        funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42}));
3226 >        funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete}));
3227  
3228          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3229 <                 dependentFactory : dependentFactories) {
3229 >                 fun : funs) {
3230              CompletableFuture<Integer> f = new CompletableFuture<>();
3231              f.completeExceptionally(ex);
3232              CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3233              checkCompletedWithWrappedException(src, ex);
3234 <            CompletableFuture<?> dep = dependentFactory.apply(src);
3234 >            CompletableFuture<?> dep = fun.apply(src);
3235              checkCompletedWithWrappedException(dep, ex);
3236              assertSame(resultOf(src), resultOf(dep));
3237          }
3238  
3239          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3240 <                 dependentFactory : dependentFactories) {
3240 >                 fun : funs) {
3241              CompletableFuture<Integer> f = new CompletableFuture<>();
3242              CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3243 <            CompletableFuture<?> dep = dependentFactory.apply(src);
3243 >            CompletableFuture<?> dep = fun.apply(src);
3244              f.completeExceptionally(ex);
3245              checkCompletedWithWrappedException(src, ex);
3246              checkCompletedWithWrappedException(dep, ex);
# Line 3225 | Line 3249 | public class CompletableFutureTest exten
3249  
3250          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3251          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3252 <                 dependentFactory : dependentFactories) {
3252 >                 fun : funs) {
3253              CompletableFuture<Integer> f = new CompletableFuture<>();
3254              f.cancel(mayInterruptIfRunning);
3255              checkCancelled(f);
3256              CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3257              checkCompletedWithWrappedCancellationException(src);
3258 <            CompletableFuture<?> dep = dependentFactory.apply(src);
3258 >            CompletableFuture<?> dep = fun.apply(src);
3259              checkCompletedWithWrappedCancellationException(dep);
3260              assertSame(resultOf(src), resultOf(dep));
3261          }
3262  
3263          for (boolean mayInterruptIfRunning : new boolean[] { true, false })
3264          for (Function<CompletableFuture<Integer>, CompletableFuture<?>>
3265 <                 dependentFactory : dependentFactories) {
3265 >                 fun : funs) {
3266              CompletableFuture<Integer> f = new CompletableFuture<>();
3267              CompletableFuture<Integer> src = m.thenApply(f, new IncFunction(m));
3268 <            CompletableFuture<?> dep = dependentFactory.apply(src);
3268 >            CompletableFuture<?> dep = fun.apply(src);
3269              f.cancel(mayInterruptIfRunning);
3270              checkCancelled(f);
3271              checkCompletedWithWrappedCancellationException(src);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines