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.48 by jsr166, Mon Jun 2 19:07:14 2014 UTC vs.
Revision 1.49 by jsr166, Mon Jun 2 19:20:51 2014 UTC

# Line 1050 | Line 1050 | public class CompletableFutureTest exten
1050      /**
1051       * thenApply result completes normally after normal completion of source
1052       */
1053 <    public void testThenApply() {
1054 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1055 <        CompletableFuture<Integer> g = f.thenApply(inc);
1056 <        f.complete(one);
1057 <        checkCompletedNormally(g, two);
1058 <    }
1053 >    public void testThenApply_normalCompletion() {
1054 >        for (ExecutionMode m : ExecutionMode.values())
1055 >        for (boolean createIncomplete : new boolean[] { true, false })
1056 >        for (Integer v1 : new Integer[] { 1, null })
1057 >    {
1058 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1059 >        final IncFunction r = new IncFunction();
1060 >        if (!createIncomplete) f.complete(v1);
1061 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1062 >        if (createIncomplete) {
1063 >            checkIncomplete(g);
1064 >            f.complete(v1);
1065 >        }
1066 >
1067 >        checkCompletedNormally(g, inc(v1));
1068 >        checkCompletedNormally(f, v1);
1069 >        assertEquals(1, r.invocationCount);
1070 >    }}
1071  
1072      /**
1073       * thenApply result completes exceptionally after exceptional
1074       * completion of source
1075       */
1076 <    public void testThenApply2() {
1077 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1078 <        CompletableFuture<Integer> g = f.thenApply(inc);
1079 <        f.completeExceptionally(new CFException());
1080 <        checkCompletedWithWrappedCFException(g);
1081 <    }
1076 >    public void testThenApply_exceptionalCompletion() {
1077 >        for (ExecutionMode m : ExecutionMode.values())
1078 >        for (boolean createIncomplete : new boolean[] { true, false })
1079 >    {
1080 >        final CFException ex = new CFException();
1081 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1082 >        final IncFunction r = new IncFunction();
1083 >        if (!createIncomplete) f.completeExceptionally(ex);
1084 >        final CompletableFuture<Integer> g = m.thenApply(f, r);
1085 >        if (createIncomplete) f.completeExceptionally(ex);
1086  
1087 <    /**
1088 <     * thenApply result completes exceptionally if action does
1089 <     */
1090 <    public void testThenApply3() {
1075 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1076 <        CompletableFuture<Integer> g = f.thenApply(new FailingFunction());
1077 <        f.complete(one);
1078 <        checkCompletedWithWrappedCFException(g);
1079 <    }
1087 >        checkCompletedWithWrappedCFException(g, ex);
1088 >        checkCompletedWithWrappedCFException(f, ex);
1089 >        assertEquals(0, r.invocationCount);
1090 >    }}
1091  
1092      /**
1093       * thenApply result completes exceptionally if source cancelled
1094       */
1095 <    public void testThenApply4() {
1096 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1097 <        CompletableFuture<Integer> g = f.thenApply(inc);
1098 <        assertTrue(f.cancel(true));
1095 >    public void testThenApply_sourceCancelled() {
1096 >        for (ExecutionMode m : ExecutionMode.values())
1097 >        for (boolean createIncomplete : new boolean[] { true, false })
1098 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1099 >    {
1100 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1101 >        final IncFunction r = new IncFunction();
1102 >        if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1103 >        final CompletableFuture<Integer> g = f.thenApply(r);
1104 >        if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning));
1105 >
1106          checkCompletedWithWrappedCancellationException(g);
1107 <    }
1107 >        checkCancelled(f);
1108 >        assertEquals(0, r.invocationCount);
1109 >    }}
1110 >
1111 >    /**
1112 >     * thenApply result completes exceptionally if action does
1113 >     */
1114 >    public void testThenApply_actionFailed() {
1115 >        for (ExecutionMode m : ExecutionMode.values())
1116 >        for (boolean createIncomplete : new boolean[] { true, false })
1117 >        for (Integer v1 : new Integer[] { 1, null })
1118 >    {
1119 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1120 >        final FailingFunction r = new FailingFunction();
1121 >        if (!createIncomplete) f.complete(v1);
1122 >        final CompletableFuture<Integer> g = f.thenApply(r);
1123 >        if (createIncomplete) f.complete(v1);
1124 >
1125 >        checkCompletedWithWrappedCFException(g);
1126 >        checkCompletedNormally(f, v1);
1127 >    }}
1128  
1129      /**
1130       * thenAccept result completes normally after normal completion of source
# Line 2924 | Line 2962 | public class CompletableFutureTest exten
2962      // asyncs
2963  
2964      /**
2927     * thenApplyAsync result completes normally after normal completion of source
2928     */
2929    public void testThenApplyAsync() {
2930        CompletableFuture<Integer> f = new CompletableFuture<>();
2931        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
2932        f.complete(one);
2933        checkCompletedNormally(g, two);
2934    }
2935
2936    /**
2937     * thenApplyAsync result completes exceptionally after exceptional
2938     * completion of source
2939     */
2940    public void testThenApplyAsync2() {
2941        CompletableFuture<Integer> f = new CompletableFuture<>();
2942        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
2943        f.completeExceptionally(new CFException());
2944        checkCompletedWithWrappedCFException(g);
2945    }
2946
2947    /**
2948     * thenApplyAsync result completes exceptionally if action does
2949     */
2950    public void testThenApplyAsync3() {
2951        CompletableFuture<Integer> f = new CompletableFuture<>();
2952        FailingFunction r = new FailingFunction();
2953        CompletableFuture<Integer> g = f.thenApplyAsync(r);
2954        f.complete(null);
2955        checkCompletedWithWrappedCFException(g);
2956    }
2957
2958    /**
2959     * thenApplyAsync result completes exceptionally if source cancelled
2960     */
2961    public void testThenApplyAsync4() {
2962        CompletableFuture<Integer> f = new CompletableFuture<>();
2963        CompletableFuture<Integer> g = f.thenApplyAsync(inc);
2964        assertTrue(f.cancel(true));
2965        checkCompletedWithWrappedCancellationException(g);
2966    }
2967
2968    /**
2965       * thenAcceptAsync result completes normally after normal
2966       * completion of source
2967       */
# Line 3015 | Line 3011 | public class CompletableFutureTest exten
3011      // async with explicit executors
3012  
3013      /**
3018     * thenApplyAsync result completes normally after normal completion of source
3019     */
3020    public void testThenApplyAsyncE() {
3021        CompletableFuture<Integer> f = new CompletableFuture<>();
3022        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3023        f.complete(one);
3024        checkCompletedNormally(g, two);
3025    }
3026
3027    /**
3028     * thenApplyAsync result completes exceptionally after exceptional
3029     * completion of source
3030     */
3031    public void testThenApplyAsync2E() {
3032        CompletableFuture<Integer> f = new CompletableFuture<>();
3033        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3034        f.completeExceptionally(new CFException());
3035        checkCompletedWithWrappedCFException(g);
3036    }
3037
3038    /**
3039     * thenApplyAsync result completes exceptionally if action does
3040     */
3041    public void testThenApplyAsync3E() {
3042        CompletableFuture<Integer> f = new CompletableFuture<>();
3043        FailingFunction r = new FailingFunction();
3044        CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor());
3045        f.complete(null);
3046        checkCompletedWithWrappedCFException(g);
3047    }
3048
3049    /**
3050     * thenApplyAsync result completes exceptionally if source cancelled
3051     */
3052    public void testThenApplyAsync4E() {
3053        CompletableFuture<Integer> f = new CompletableFuture<>();
3054        CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor());
3055        assertTrue(f.cancel(true));
3056        checkCompletedWithWrappedCancellationException(g);
3057    }
3058
3059    /**
3014       * thenAcceptAsync result completes normally after normal
3015       * completion of source
3016       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines