416 |
|
throw new CFException(); |
417 |
|
} |
418 |
|
} |
419 |
< |
static final class FailingNoop implements Runnable { |
419 |
> |
static final class FailingRunnable implements Runnable { |
420 |
|
int invocationCount = 0; |
421 |
|
public void run() { |
422 |
|
invocationCount++; |
933 |
|
* failing runAsync completes exceptionally after running Runnable |
934 |
|
*/ |
935 |
|
public void testRunAsync3() { |
936 |
< |
FailingNoop r = new FailingNoop(); |
936 |
> |
FailingRunnable r = new FailingRunnable(); |
937 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
938 |
|
checkCompletedWithWrappedCFException(f); |
939 |
|
assertEquals(1, r.invocationCount); |
1038 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1039 |
|
{ |
1040 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1041 |
< |
final FailingNoop r = new FailingNoop(); |
1041 |
> |
final FailingRunnable r = new FailingRunnable(); |
1042 |
|
if (!createIncomplete) f.complete(v1); |
1043 |
|
final CompletableFuture<Void> g = f.thenRun(r); |
1044 |
|
if (createIncomplete) f.complete(v1); |
1129 |
|
/** |
1130 |
|
* thenAccept result completes normally after normal completion of source |
1131 |
|
*/ |
1132 |
< |
public void testThenAccept() { |
1133 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1134 |
< |
IncAction r = new IncAction(); |
1135 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1136 |
< |
f.complete(one); |
1132 |
> |
public void testThenAccept_normalCompletion() { |
1133 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1134 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1135 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1136 |
> |
{ |
1137 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1138 |
> |
final IncAction r = new IncAction(); |
1139 |
> |
if (!createIncomplete) f.complete(v1); |
1140 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1141 |
> |
if (createIncomplete) f.complete(v1); |
1142 |
> |
|
1143 |
|
checkCompletedNormally(g, null); |
1144 |
< |
assertEquals(r.value, (Integer) 2); |
1145 |
< |
} |
1144 |
> |
checkCompletedNormally(f, v1); |
1145 |
> |
assertEquals(1, r.invocationCount); |
1146 |
> |
assertEquals(inc(v1), r.value); |
1147 |
> |
}} |
1148 |
|
|
1149 |
|
/** |
1150 |
|
* thenAccept result completes exceptionally after exceptional |
1151 |
|
* completion of source |
1152 |
|
*/ |
1153 |
< |
public void testThenAccept2() { |
1154 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1155 |
< |
IncAction r = new IncAction(); |
1156 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1157 |
< |
f.completeExceptionally(new CFException()); |
1158 |
< |
checkCompletedWithWrappedCFException(g); |
1159 |
< |
} |
1153 |
> |
public void testThenAccept_exceptionalCompletion() { |
1154 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1155 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1156 |
> |
{ |
1157 |
> |
final CFException ex = new CFException(); |
1158 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1159 |
> |
final IncAction r = new IncAction(); |
1160 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1161 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1162 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
1163 |
> |
|
1164 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1165 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1166 |
> |
assertEquals(0, r.invocationCount); |
1167 |
> |
}} |
1168 |
|
|
1169 |
|
/** |
1170 |
|
* thenAccept result completes exceptionally if action does |
1171 |
|
*/ |
1172 |
< |
public void testThenAccept3() { |
1173 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1174 |
< |
FailingConsumer r = new FailingConsumer(); |
1175 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1176 |
< |
f.complete(one); |
1172 |
> |
public void testThenAccept_actionFailed() { |
1173 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1174 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1175 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1176 |
> |
{ |
1177 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1178 |
> |
final FailingConsumer r = new FailingConsumer(); |
1179 |
> |
if (!createIncomplete) f.complete(v1); |
1180 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1181 |
> |
if (createIncomplete) f.complete(v1); |
1182 |
> |
|
1183 |
|
checkCompletedWithWrappedCFException(g); |
1184 |
< |
assertEquals(1, r.invocationCount); |
1185 |
< |
} |
1184 |
> |
checkCompletedNormally(f, v1); |
1185 |
> |
}} |
1186 |
|
|
1187 |
|
/** |
1188 |
|
* thenAccept result completes exceptionally if source cancelled |
1189 |
|
*/ |
1190 |
< |
public void testThenAccept4() { |
1191 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1192 |
< |
IncAction r = new IncAction(); |
1193 |
< |
CompletableFuture<Void> g = f.thenAccept(r); |
1194 |
< |
assertTrue(f.cancel(true)); |
1190 |
> |
public void testThenAccept_sourceCancelled() { |
1191 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1192 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1193 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1194 |
> |
{ |
1195 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1196 |
> |
final IncAction r = new IncAction(); |
1197 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1198 |
> |
final CompletableFuture<Void> g = f.thenAccept(r); |
1199 |
> |
if (createIncomplete) { |
1200 |
> |
checkIncomplete(g); |
1201 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1202 |
> |
} |
1203 |
> |
|
1204 |
|
checkCompletedWithWrappedCancellationException(g); |
1205 |
< |
} |
1205 |
> |
checkCancelled(f); |
1206 |
> |
assertEquals(0, r.invocationCount); |
1207 |
> |
}} |
1208 |
|
|
1209 |
|
/** |
1210 |
|
* thenCombine result completes normally after normal completion |
1909 |
|
{ |
1910 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1911 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1912 |
< |
final FailingNoop r = new FailingNoop(); |
1912 |
> |
final FailingRunnable r = new FailingRunnable(); |
1913 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1914 |
|
|
1915 |
|
f.complete(v1); |
1928 |
|
{ |
1929 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1930 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1931 |
< |
final FailingNoop r = new FailingNoop(); |
1931 |
> |
final FailingRunnable r = new FailingRunnable(); |
1932 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1933 |
|
|
1934 |
|
g.complete(v2); |
2792 |
|
{ |
2793 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2794 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2795 |
< |
final FailingNoop r = new FailingNoop(); |
2795 |
> |
final FailingRunnable r = new FailingRunnable(); |
2796 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2797 |
|
|
2798 |
|
f.complete(v1); |
2809 |
|
{ |
2810 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2811 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2812 |
< |
final FailingNoop r = new FailingNoop(); |
2812 |
> |
final FailingRunnable r = new FailingRunnable(); |
2813 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2814 |
|
|
2815 |
|
g.complete(v2); |
2986 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2987 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2988 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2989 |
< |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2989 |
> |
if (createIncomplete) { |
2990 |
> |
checkIncomplete(g); |
2991 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2992 |
> |
} |
2993 |
|
|
2994 |
|
checkCompletedWithWrappedCancellationException(g); |
2995 |
|
checkCancelled(f); |
2996 |
|
}} |
2997 |
|
|
2962 |
– |
// asyncs |
2963 |
– |
|
2964 |
– |
/** |
2965 |
– |
* thenAcceptAsync result completes normally after normal |
2966 |
– |
* completion of source |
2967 |
– |
*/ |
2968 |
– |
public void testThenAcceptAsync() { |
2969 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2970 |
– |
IncAction r = new IncAction(); |
2971 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2972 |
– |
f.complete(one); |
2973 |
– |
checkCompletedNormally(g, null); |
2974 |
– |
assertEquals(r.value, (Integer) 2); |
2975 |
– |
} |
2976 |
– |
|
2977 |
– |
/** |
2978 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
2979 |
– |
* completion of source |
2980 |
– |
*/ |
2981 |
– |
public void testThenAcceptAsync2() { |
2982 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2983 |
– |
IncAction r = new IncAction(); |
2984 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2985 |
– |
f.completeExceptionally(new CFException()); |
2986 |
– |
checkCompletedWithWrappedCFException(g); |
2987 |
– |
} |
2988 |
– |
|
2989 |
– |
/** |
2990 |
– |
* thenAcceptAsync result completes exceptionally if action does |
2991 |
– |
*/ |
2992 |
– |
public void testThenAcceptAsync3() { |
2993 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2994 |
– |
FailingConsumer r = new FailingConsumer(); |
2995 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
2996 |
– |
f.complete(null); |
2997 |
– |
checkCompletedWithWrappedCFException(g); |
2998 |
– |
} |
2999 |
– |
|
3000 |
– |
/** |
3001 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3002 |
– |
*/ |
3003 |
– |
public void testThenAcceptAsync4() { |
3004 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3005 |
– |
IncAction r = new IncAction(); |
3006 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r); |
3007 |
– |
assertTrue(f.cancel(true)); |
3008 |
– |
checkCompletedWithWrappedCancellationException(g); |
3009 |
– |
} |
3010 |
– |
|
3011 |
– |
// async with explicit executors |
3012 |
– |
|
3013 |
– |
/** |
3014 |
– |
* thenAcceptAsync result completes normally after normal |
3015 |
– |
* completion of source |
3016 |
– |
*/ |
3017 |
– |
public void testThenAcceptAsyncE() { |
3018 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3019 |
– |
IncAction r = new IncAction(); |
3020 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3021 |
– |
f.complete(one); |
3022 |
– |
checkCompletedNormally(g, null); |
3023 |
– |
assertEquals(r.value, (Integer) 2); |
3024 |
– |
} |
3025 |
– |
|
3026 |
– |
/** |
3027 |
– |
* thenAcceptAsync result completes exceptionally after exceptional |
3028 |
– |
* completion of source |
3029 |
– |
*/ |
3030 |
– |
public void testThenAcceptAsync2E() { |
3031 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3032 |
– |
IncAction r = new IncAction(); |
3033 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3034 |
– |
f.completeExceptionally(new CFException()); |
3035 |
– |
checkCompletedWithWrappedCFException(g); |
3036 |
– |
} |
3037 |
– |
|
3038 |
– |
/** |
3039 |
– |
* thenAcceptAsync result completes exceptionally if action does |
3040 |
– |
*/ |
3041 |
– |
public void testThenAcceptAsync3E() { |
3042 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3043 |
– |
FailingConsumer r = new FailingConsumer(); |
3044 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3045 |
– |
f.complete(null); |
3046 |
– |
checkCompletedWithWrappedCFException(g); |
3047 |
– |
} |
3048 |
– |
|
3049 |
– |
/** |
3050 |
– |
* thenAcceptAsync result completes exceptionally if source cancelled |
3051 |
– |
*/ |
3052 |
– |
public void testThenAcceptAsync4E() { |
3053 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3054 |
– |
IncAction r = new IncAction(); |
3055 |
– |
CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor()); |
3056 |
– |
assertTrue(f.cancel(true)); |
3057 |
– |
checkCompletedWithWrappedCancellationException(g); |
3058 |
– |
} |
3059 |
– |
|
2998 |
|
// other static methods |
2999 |
|
|
3000 |
|
/** |