284 |
|
public void testGetNumberOfDependents() { |
285 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
286 |
|
assertEquals(0, f.getNumberOfDependents()); |
287 |
< |
CompletableFuture g = f.thenRun(new Noop()); |
287 |
> |
CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
288 |
|
assertEquals(1, f.getNumberOfDependents()); |
289 |
|
assertEquals(0, g.getNumberOfDependents()); |
290 |
< |
CompletableFuture h = f.thenRun(new Noop()); |
290 |
> |
CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
291 |
|
assertEquals(2, f.getNumberOfDependents()); |
292 |
|
f.complete(1); |
293 |
|
checkCompletedNormally(g, null); |
349 |
|
} |
350 |
|
} |
351 |
|
static final class IncFunction implements Function<Integer,Integer> { |
352 |
+ |
final ExecutionMode m; |
353 |
|
int invocationCount = 0; |
354 |
|
Integer value; |
355 |
+ |
IncFunction(ExecutionMode m) { this.m = m; } |
356 |
|
public Integer apply(Integer x) { |
357 |
+ |
m.checkExecutionMode(); |
358 |
|
invocationCount++; |
359 |
|
return value = inc(x); |
360 |
|
} |
361 |
|
} |
362 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
363 |
+ |
final ExecutionMode m; |
364 |
|
int invocationCount = 0; |
365 |
|
Integer value; |
366 |
|
// Check this action was invoked exactly once when result is computed. |
367 |
+ |
SubtractAction(ExecutionMode m) { this.m = m; } |
368 |
|
public void accept(Integer x, Integer y) { |
369 |
+ |
m.checkExecutionMode(); |
370 |
|
invocationCount++; |
371 |
|
value = subtract(x, y); |
372 |
|
} |
373 |
|
} |
374 |
|
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
375 |
+ |
final ExecutionMode m; |
376 |
|
int invocationCount = 0; |
377 |
|
Integer value; |
378 |
|
// Check this action was invoked exactly once when result is computed. |
379 |
+ |
SubtractFunction(ExecutionMode m) { this.m = m; } |
380 |
|
public Integer apply(Integer x, Integer y) { |
381 |
+ |
m.checkExecutionMode(); |
382 |
|
invocationCount++; |
383 |
|
return value = subtract(x, y); |
384 |
|
} |
385 |
|
} |
386 |
|
static final class Noop implements Runnable { |
387 |
+ |
final ExecutionMode m; |
388 |
|
int invocationCount = 0; |
389 |
+ |
Noop(ExecutionMode m) { this.m = m; } |
390 |
|
public void run() { |
391 |
+ |
m.checkExecutionMode(); |
392 |
|
invocationCount++; |
393 |
|
} |
394 |
|
} |
395 |
|
|
396 |
|
static final class FailingSupplier implements Supplier<Integer> { |
397 |
+ |
final ExecutionMode m; |
398 |
|
int invocationCount = 0; |
399 |
+ |
FailingSupplier(ExecutionMode m) { this.m = m; } |
400 |
|
public Integer get() { |
401 |
+ |
m.checkExecutionMode(); |
402 |
|
invocationCount++; |
403 |
|
throw new CFException(); |
404 |
|
} |
405 |
|
} |
406 |
|
static final class FailingConsumer implements Consumer<Integer> { |
407 |
+ |
final ExecutionMode m; |
408 |
|
int invocationCount = 0; |
409 |
+ |
FailingConsumer(ExecutionMode m) { this.m = m; } |
410 |
|
public void accept(Integer x) { |
411 |
+ |
m.checkExecutionMode(); |
412 |
|
invocationCount++; |
413 |
|
throw new CFException(); |
414 |
|
} |
415 |
|
} |
416 |
|
static final class FailingBiConsumer implements BiConsumer<Integer, Integer> { |
417 |
+ |
final ExecutionMode m; |
418 |
|
int invocationCount = 0; |
419 |
+ |
FailingBiConsumer(ExecutionMode m) { this.m = m; } |
420 |
|
public void accept(Integer x, Integer y) { |
421 |
+ |
m.checkExecutionMode(); |
422 |
|
invocationCount++; |
423 |
|
throw new CFException(); |
424 |
|
} |
425 |
|
} |
426 |
|
static final class FailingFunction implements Function<Integer, Integer> { |
427 |
+ |
final ExecutionMode m; |
428 |
|
int invocationCount = 0; |
429 |
+ |
FailingFunction(ExecutionMode m) { this.m = m; } |
430 |
|
public Integer apply(Integer x) { |
431 |
+ |
m.checkExecutionMode(); |
432 |
|
invocationCount++; |
433 |
|
throw new CFException(); |
434 |
|
} |
435 |
|
} |
436 |
|
static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> { |
437 |
+ |
final ExecutionMode m; |
438 |
|
int invocationCount = 0; |
439 |
+ |
FailingBiFunction(ExecutionMode m) { this.m = m; } |
440 |
|
public Integer apply(Integer x, Integer y) { |
441 |
+ |
m.checkExecutionMode(); |
442 |
|
invocationCount++; |
443 |
|
throw new CFException(); |
444 |
|
} |
445 |
|
} |
446 |
|
static final class FailingRunnable implements Runnable { |
447 |
+ |
final ExecutionMode m; |
448 |
|
int invocationCount = 0; |
449 |
+ |
FailingRunnable(ExecutionMode m) { this.m = m; } |
450 |
|
public void run() { |
451 |
+ |
m.checkExecutionMode(); |
452 |
|
invocationCount++; |
453 |
|
throw new CFException(); |
454 |
|
} |
456 |
|
|
457 |
|
static final class CompletableFutureInc |
458 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
459 |
+ |
final ExecutionMode m; |
460 |
|
int invocationCount = 0; |
461 |
+ |
CompletableFutureInc(ExecutionMode m) { this.m = m; } |
462 |
|
public CompletableFuture<Integer> apply(Integer x) { |
463 |
+ |
m.checkExecutionMode(); |
464 |
|
invocationCount++; |
465 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
466 |
|
f.complete(inc(x)); |
470 |
|
|
471 |
|
static final class FailingCompletableFutureFunction |
472 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
473 |
+ |
final ExecutionMode m; |
474 |
|
int invocationCount = 0; |
475 |
+ |
FailingCompletableFutureFunction(ExecutionMode m) { this.m = m; } |
476 |
|
public CompletableFuture<Integer> apply(Integer x) { |
477 |
+ |
m.checkExecutionMode(); |
478 |
|
invocationCount++; |
479 |
|
throw new CFException(); |
480 |
|
} |
482 |
|
|
483 |
|
// Used for explicit executor tests |
484 |
|
static final class ThreadExecutor implements Executor { |
485 |
< |
AtomicInteger count = new AtomicInteger(0); |
485 |
> |
final AtomicInteger count = new AtomicInteger(0); |
486 |
> |
static final ThreadGroup tg = new ThreadGroup("ThreadExecutor"); |
487 |
> |
static boolean startedCurrentThread() { |
488 |
> |
return Thread.currentThread().getThreadGroup() == tg; |
489 |
> |
} |
490 |
|
|
491 |
|
public void execute(Runnable r) { |
492 |
|
count.getAndIncrement(); |
493 |
< |
new Thread(r).start(); |
493 |
> |
new Thread(tg, r).start(); |
494 |
|
} |
495 |
|
} |
496 |
|
|
636 |
|
|
637 |
|
EXECUTOR { |
638 |
|
public void checkExecutionMode() { |
639 |
< |
//TODO |
639 |
> |
assertTrue(ThreadExecutor.startedCurrentThread()); |
640 |
|
} |
641 |
|
public <T> CompletableFuture<Void> thenRun |
642 |
|
(CompletableFuture<T> f, Runnable a) { |
949 |
|
* runAsync completes after running Runnable |
950 |
|
*/ |
951 |
|
public void testRunAsync() { |
952 |
< |
Noop r = new Noop(); |
952 |
> |
Noop r = new Noop(ExecutionMode.ASYNC); |
953 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
954 |
|
assertNull(f.join()); |
955 |
|
assertEquals(1, r.invocationCount); |
960 |
|
* runAsync with executor completes after running Runnable |
961 |
|
*/ |
962 |
|
public void testRunAsync2() { |
963 |
< |
Noop r = new Noop(); |
963 |
> |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
964 |
|
ThreadExecutor exec = new ThreadExecutor(); |
965 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
966 |
|
assertNull(f.join()); |
973 |
|
* failing runAsync completes exceptionally after running Runnable |
974 |
|
*/ |
975 |
|
public void testRunAsync3() { |
976 |
< |
FailingRunnable r = new FailingRunnable(); |
976 |
> |
FailingRunnable r = new FailingRunnable(ExecutionMode.ASYNC); |
977 |
|
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
978 |
|
checkCompletedWithWrappedCFException(f); |
979 |
|
assertEquals(1, r.invocationCount); |
1003 |
|
* Failing supplyAsync completes exceptionally |
1004 |
|
*/ |
1005 |
|
public void testSupplyAsync3() { |
1006 |
< |
FailingSupplier r = new FailingSupplier(); |
1006 |
> |
FailingSupplier r = new FailingSupplier(ExecutionMode.ASYNC); |
1007 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r); |
1008 |
|
checkCompletedWithWrappedCFException(f); |
1009 |
|
assertEquals(1, r.invocationCount); |
1020 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1021 |
|
{ |
1022 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1023 |
< |
final Noop r = new Noop(); |
1023 |
> |
final Noop r = new Noop(m); |
1024 |
|
if (!createIncomplete) f.complete(v1); |
1025 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1026 |
|
if (createIncomplete) { |
1043 |
|
{ |
1044 |
|
final CFException ex = new CFException(); |
1045 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1046 |
< |
final Noop r = new Noop(); |
1046 |
> |
final Noop r = new Noop(m); |
1047 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1048 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1049 |
|
if (createIncomplete) { |
1065 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1066 |
|
{ |
1067 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1068 |
< |
final Noop r = new Noop(); |
1068 |
> |
final Noop r = new Noop(m); |
1069 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1070 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1070 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1071 |
|
if (createIncomplete) { |
1072 |
|
checkIncomplete(g); |
1073 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1087 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1088 |
|
{ |
1089 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1090 |
< |
final FailingRunnable r = new FailingRunnable(); |
1090 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1091 |
|
if (!createIncomplete) f.complete(v1); |
1092 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1092 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1093 |
|
if (createIncomplete) { |
1094 |
|
checkIncomplete(g); |
1095 |
|
f.complete(v1); |
1108 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1109 |
|
{ |
1110 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1111 |
< |
final IncFunction r = new IncFunction(); |
1111 |
> |
final IncFunction r = new IncFunction(m); |
1112 |
|
if (!createIncomplete) f.complete(v1); |
1113 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1114 |
|
if (createIncomplete) { |
1131 |
|
{ |
1132 |
|
final CFException ex = new CFException(); |
1133 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1134 |
< |
final IncFunction r = new IncFunction(); |
1134 |
> |
final IncFunction r = new IncFunction(m); |
1135 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1136 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1137 |
|
if (createIncomplete) { |
1153 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1154 |
|
{ |
1155 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1156 |
< |
final IncFunction r = new IncFunction(); |
1156 |
> |
final IncFunction r = new IncFunction(m); |
1157 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1158 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1158 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1159 |
|
if (createIncomplete) { |
1160 |
|
checkIncomplete(g); |
1161 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1175 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1176 |
|
{ |
1177 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1178 |
< |
final FailingFunction r = new FailingFunction(); |
1178 |
> |
final FailingFunction r = new FailingFunction(m); |
1179 |
|
if (!createIncomplete) f.complete(v1); |
1180 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1180 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1181 |
|
if (createIncomplete) { |
1182 |
|
checkIncomplete(g); |
1183 |
|
f.complete(v1); |
1242 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1243 |
|
{ |
1244 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1245 |
< |
final FailingConsumer r = new FailingConsumer(); |
1245 |
> |
final FailingConsumer r = new FailingConsumer(m); |
1246 |
|
if (!createIncomplete) f.complete(v1); |
1247 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1247 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1248 |
|
if (createIncomplete) { |
1249 |
|
checkIncomplete(g); |
1250 |
|
f.complete(v1); |
1265 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1266 |
|
final IncAction r = new IncAction(); |
1267 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1268 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1268 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1269 |
|
if (createIncomplete) { |
1270 |
|
checkIncomplete(g); |
1271 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1289 |
|
{ |
1290 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1291 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1292 |
< |
final SubtractFunction r = new SubtractFunction(); |
1292 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1293 |
|
|
1294 |
|
if (fFirst) f.complete(v1); else g.complete(v2); |
1295 |
|
if (!createIncomplete) |
1311 |
|
* thenCombine result completes exceptionally after exceptional |
1312 |
|
* completion of either source |
1313 |
|
*/ |
1314 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1275 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1277 |
< |
{ |
1278 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1279 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1280 |
< |
final SubtractFunction r = new SubtractFunction(); |
1281 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1282 |
< |
final CFException ex = new CFException(); |
1283 |
< |
|
1284 |
< |
f.completeExceptionally(ex); |
1285 |
< |
checkIncomplete(h); |
1286 |
< |
g.complete(v1); |
1287 |
< |
|
1288 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1289 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1290 |
< |
assertEquals(0, r.invocationCount); |
1291 |
< |
checkCompletedNormally(g, v1); |
1292 |
< |
}} |
1293 |
< |
|
1294 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1295 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1296 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1297 |
< |
{ |
1298 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1299 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1300 |
< |
final SubtractFunction r = new SubtractFunction(); |
1301 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1302 |
< |
final CFException ex = new CFException(); |
1303 |
< |
|
1304 |
< |
g.completeExceptionally(ex); |
1305 |
< |
checkIncomplete(h); |
1306 |
< |
f.complete(v1); |
1307 |
< |
|
1308 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1309 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1310 |
< |
assertEquals(0, r.invocationCount); |
1311 |
< |
checkCompletedNormally(f, v1); |
1312 |
< |
}} |
1313 |
< |
|
1314 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1315 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1317 |
< |
{ |
1318 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1319 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1320 |
< |
final SubtractFunction r = new SubtractFunction(); |
1321 |
< |
final CFException ex = new CFException(); |
1322 |
< |
|
1323 |
< |
g.completeExceptionally(ex); |
1324 |
< |
f.complete(v1); |
1325 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1326 |
< |
|
1327 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1328 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1329 |
< |
assertEquals(0, r.invocationCount); |
1330 |
< |
checkCompletedNormally(f, v1); |
1331 |
< |
}} |
1332 |
< |
|
1333 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1314 |
> |
public void testThenCombine_exceptionalCompletion() { |
1315 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1317 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1318 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1319 |
|
{ |
1320 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1321 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
– |
final SubtractFunction r = new SubtractFunction(); |
1322 |
|
final CFException ex = new CFException(); |
1323 |
+ |
final SubtractFunction r = new SubtractFunction(m); |
1324 |
|
|
1325 |
< |
f.completeExceptionally(ex); |
1326 |
< |
g.complete(v1); |
1325 |
> |
(fFirst ? f : g).complete(v1); |
1326 |
> |
if (!createIncomplete) |
1327 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1328 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1329 |
+ |
if (createIncomplete) { |
1330 |
+ |
checkIncomplete(h); |
1331 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1332 |
+ |
} |
1333 |
|
|
1334 |
|
checkCompletedWithWrappedCFException(h, ex); |
1347 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1335 |
|
assertEquals(0, r.invocationCount); |
1336 |
< |
checkCompletedNormally(g, v1); |
1336 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1337 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1338 |
|
}} |
1339 |
|
|
1340 |
|
/** |
1341 |
|
* thenCombine result completes exceptionally if action does |
1342 |
|
*/ |
1343 |
< |
public void testThenCombine_actionFailed1() { |
1356 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1357 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1358 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1359 |
< |
{ |
1360 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1361 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1362 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1363 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1364 |
< |
|
1365 |
< |
f.complete(v1); |
1366 |
< |
checkIncomplete(h); |
1367 |
< |
g.complete(v2); |
1368 |
< |
|
1369 |
< |
checkCompletedWithWrappedCFException(h); |
1370 |
< |
checkCompletedNormally(f, v1); |
1371 |
< |
checkCompletedNormally(g, v2); |
1372 |
< |
}} |
1373 |
< |
|
1374 |
< |
public void testThenCombine_actionFailed2() { |
1343 |
> |
public void testThenCombine_actionFailed() { |
1344 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1345 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1346 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1347 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1348 |
|
{ |
1349 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1350 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1351 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1351 |
> |
final FailingBiFunction r = new FailingBiFunction(m); |
1352 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1353 |
|
|
1354 |
< |
g.complete(v2); |
1355 |
< |
checkIncomplete(h); |
1356 |
< |
f.complete(v1); |
1354 |
> |
if (fFirst) { |
1355 |
> |
f.complete(v1); |
1356 |
> |
g.complete(v2); |
1357 |
> |
} else { |
1358 |
> |
g.complete(v2); |
1359 |
> |
f.complete(v1); |
1360 |
> |
} |
1361 |
|
|
1362 |
|
checkCompletedWithWrappedCFException(h); |
1363 |
|
checkCompletedNormally(f, v1); |
1367 |
|
/** |
1368 |
|
* thenCombine result completes exceptionally if either source cancelled |
1369 |
|
*/ |
1370 |
< |
public void testThenCombine_sourceCancelled1() { |
1397 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1398 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1399 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1400 |
< |
{ |
1401 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1402 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
< |
final SubtractFunction r = new SubtractFunction(); |
1404 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1405 |
< |
|
1406 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1407 |
< |
checkIncomplete(h); |
1408 |
< |
g.complete(v1); |
1409 |
< |
|
1410 |
< |
checkCompletedWithWrappedCancellationException(h); |
1411 |
< |
checkCancelled(f); |
1412 |
< |
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1414 |
< |
}} |
1415 |
< |
|
1416 |
< |
public void testThenCombine_sourceCancelled2() { |
1417 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1418 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1419 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1420 |
< |
{ |
1421 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1422 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1423 |
< |
final SubtractFunction r = new SubtractFunction(); |
1424 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1425 |
< |
|
1426 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1427 |
< |
checkIncomplete(h); |
1428 |
< |
f.complete(v1); |
1429 |
< |
|
1430 |
< |
checkCompletedWithWrappedCancellationException(h); |
1431 |
< |
checkCancelled(g); |
1432 |
< |
assertEquals(0, r.invocationCount); |
1433 |
< |
checkCompletedNormally(f, v1); |
1434 |
< |
}} |
1435 |
< |
|
1436 |
< |
public void testThenCombine_sourceCancelled3() { |
1437 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1438 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1439 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1440 |
< |
{ |
1441 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1442 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1443 |
< |
final SubtractFunction r = new SubtractFunction(); |
1444 |
< |
|
1445 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1446 |
< |
f.complete(v1); |
1447 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1448 |
< |
|
1449 |
< |
checkCompletedWithWrappedCancellationException(h); |
1450 |
< |
checkCancelled(g); |
1451 |
< |
assertEquals(0, r.invocationCount); |
1452 |
< |
checkCompletedNormally(f, v1); |
1453 |
< |
}} |
1454 |
< |
|
1455 |
< |
public void testThenCombine_sourceCancelled4() { |
1370 |
> |
public void testThenCombine_sourceCancelled() { |
1371 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1372 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1373 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1374 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1375 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1376 |
|
{ |
1377 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1378 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1379 |
< |
final SubtractFunction r = new SubtractFunction(); |
1379 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1380 |
|
|
1381 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1382 |
< |
g.complete(v1); |
1381 |
> |
(fFirst ? f : g).complete(v1); |
1382 |
> |
if (!createIncomplete) |
1383 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1384 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1385 |
+ |
if (createIncomplete) { |
1386 |
+ |
checkIncomplete(h); |
1387 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1388 |
+ |
} |
1389 |
|
|
1390 |
|
checkCompletedWithWrappedCancellationException(h); |
1391 |
< |
checkCancelled(f); |
1391 |
> |
checkCancelled(!fFirst ? f : g); |
1392 |
|
assertEquals(0, r.invocationCount); |
1393 |
< |
checkCompletedNormally(g, v1); |
1393 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1394 |
|
}} |
1395 |
|
|
1396 |
|
/** |
1397 |
|
* thenAcceptBoth result completes normally after normal |
1398 |
|
* completion of sources |
1399 |
|
*/ |
1400 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1479 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1480 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1481 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1482 |
< |
{ |
1483 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1484 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1485 |
< |
final SubtractAction r = new SubtractAction(); |
1486 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1487 |
< |
|
1488 |
< |
f.complete(v1); |
1489 |
< |
checkIncomplete(h); |
1490 |
< |
assertEquals(0, r.invocationCount); |
1491 |
< |
g.complete(v2); |
1492 |
< |
|
1493 |
< |
checkCompletedNormally(h, null); |
1494 |
< |
assertEquals(subtract(v1, v2), r.value); |
1495 |
< |
checkCompletedNormally(f, v1); |
1496 |
< |
checkCompletedNormally(g, v2); |
1497 |
< |
}} |
1498 |
< |
|
1499 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1500 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1501 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1502 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1503 |
< |
{ |
1504 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1505 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1506 |
< |
final SubtractAction r = new SubtractAction(); |
1507 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1508 |
< |
|
1509 |
< |
g.complete(v2); |
1510 |
< |
checkIncomplete(h); |
1511 |
< |
assertEquals(0, r.invocationCount); |
1512 |
< |
f.complete(v1); |
1513 |
< |
|
1514 |
< |
checkCompletedNormally(h, null); |
1515 |
< |
assertEquals(subtract(v1, v2), r.value); |
1516 |
< |
checkCompletedNormally(f, v1); |
1517 |
< |
checkCompletedNormally(g, v2); |
1518 |
< |
}} |
1519 |
< |
|
1520 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1521 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1522 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1523 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1524 |
< |
{ |
1525 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1526 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1527 |
< |
final SubtractAction r = new SubtractAction(); |
1528 |
< |
|
1529 |
< |
g.complete(v2); |
1530 |
< |
f.complete(v1); |
1531 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1532 |
< |
|
1533 |
< |
checkCompletedNormally(h, null); |
1534 |
< |
assertEquals(subtract(v1, v2), r.value); |
1535 |
< |
checkCompletedNormally(f, v1); |
1536 |
< |
checkCompletedNormally(g, v2); |
1537 |
< |
}} |
1538 |
< |
|
1539 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1400 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1401 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1402 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1403 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1404 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1405 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1406 |
|
{ |
1407 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1408 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1409 |
< |
final SubtractAction r = new SubtractAction(); |
1409 |
> |
final SubtractAction r = new SubtractAction(m); |
1410 |
|
|
1411 |
< |
f.complete(v1); |
1412 |
< |
g.complete(v2); |
1411 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1412 |
> |
if (!createIncomplete) |
1413 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1414 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1415 |
+ |
if (createIncomplete) { |
1416 |
+ |
checkIncomplete(h); |
1417 |
+ |
assertEquals(0, r.invocationCount); |
1418 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1419 |
+ |
} |
1420 |
|
|
1421 |
|
checkCompletedNormally(h, null); |
1422 |
|
assertEquals(subtract(v1, v2), r.value); |
1428 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1429 |
|
* completion of either source |
1430 |
|
*/ |
1431 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1563 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1564 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1565 |
< |
{ |
1566 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1567 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1568 |
< |
final SubtractAction r = new SubtractAction(); |
1569 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1570 |
< |
final CFException ex = new CFException(); |
1571 |
< |
|
1572 |
< |
f.completeExceptionally(ex); |
1573 |
< |
checkIncomplete(h); |
1574 |
< |
g.complete(v1); |
1575 |
< |
|
1576 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1577 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1578 |
< |
assertEquals(0, r.invocationCount); |
1579 |
< |
checkCompletedNormally(g, v1); |
1580 |
< |
}} |
1581 |
< |
|
1582 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1583 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1584 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1585 |
< |
{ |
1586 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1587 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1588 |
< |
final SubtractAction r = new SubtractAction(); |
1589 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1590 |
< |
final CFException ex = new CFException(); |
1591 |
< |
|
1592 |
< |
g.completeExceptionally(ex); |
1593 |
< |
checkIncomplete(h); |
1594 |
< |
f.complete(v1); |
1595 |
< |
|
1596 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1597 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1598 |
< |
assertEquals(0, r.invocationCount); |
1599 |
< |
checkCompletedNormally(f, v1); |
1600 |
< |
}} |
1601 |
< |
|
1602 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1431 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1432 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1433 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1434 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1435 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1436 |
|
{ |
1437 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1438 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1608 |
– |
final SubtractAction r = new SubtractAction(); |
1439 |
|
final CFException ex = new CFException(); |
1440 |
+ |
final SubtractAction r = new SubtractAction(m); |
1441 |
|
|
1442 |
< |
g.completeExceptionally(ex); |
1443 |
< |
f.complete(v1); |
1442 |
> |
(fFirst ? f : g).complete(v1); |
1443 |
> |
if (!createIncomplete) |
1444 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1445 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1446 |
+ |
if (createIncomplete) { |
1447 |
+ |
checkIncomplete(h); |
1448 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1449 |
+ |
} |
1450 |
|
|
1451 |
|
checkCompletedWithWrappedCFException(h, ex); |
1616 |
– |
checkCompletedWithWrappedCFException(g, ex); |
1452 |
|
assertEquals(0, r.invocationCount); |
1453 |
< |
checkCompletedNormally(f, v1); |
1454 |
< |
}} |
1620 |
< |
|
1621 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1622 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1623 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1624 |
< |
{ |
1625 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1626 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1627 |
< |
final SubtractAction r = new SubtractAction(); |
1628 |
< |
final CFException ex = new CFException(); |
1629 |
< |
|
1630 |
< |
f.completeExceptionally(ex); |
1631 |
< |
g.complete(v1); |
1632 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1633 |
< |
|
1634 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1635 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1636 |
< |
assertEquals(0, r.invocationCount); |
1637 |
< |
checkCompletedNormally(g, v1); |
1453 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1454 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1455 |
|
}} |
1456 |
|
|
1457 |
|
/** |
1458 |
|
* thenAcceptBoth result completes exceptionally if action does |
1459 |
|
*/ |
1460 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1644 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1645 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1646 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1647 |
< |
{ |
1648 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1649 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1650 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1651 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1652 |
< |
|
1653 |
< |
f.complete(v1); |
1654 |
< |
checkIncomplete(h); |
1655 |
< |
g.complete(v2); |
1656 |
< |
|
1657 |
< |
checkCompletedWithWrappedCFException(h); |
1658 |
< |
checkCompletedNormally(f, v1); |
1659 |
< |
checkCompletedNormally(g, v2); |
1660 |
< |
}} |
1661 |
< |
|
1662 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1460 |
> |
public void testThenAcceptBoth_actionFailed() { |
1461 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1462 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1463 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1464 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1465 |
|
{ |
1466 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1467 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1468 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1468 |
> |
final FailingBiConsumer r = new FailingBiConsumer(m); |
1469 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1470 |
|
|
1471 |
< |
g.complete(v2); |
1472 |
< |
checkIncomplete(h); |
1473 |
< |
f.complete(v1); |
1471 |
> |
if (fFirst) { |
1472 |
> |
f.complete(v1); |
1473 |
> |
g.complete(v2); |
1474 |
> |
} else { |
1475 |
> |
g.complete(v2); |
1476 |
> |
f.complete(v1); |
1477 |
> |
} |
1478 |
|
|
1479 |
|
checkCompletedWithWrappedCFException(h); |
1480 |
|
checkCompletedNormally(f, v1); |
1484 |
|
/** |
1485 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1486 |
|
*/ |
1487 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1685 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1686 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1687 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1688 |
< |
{ |
1689 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1690 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1691 |
< |
final SubtractAction r = new SubtractAction(); |
1692 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1693 |
< |
|
1694 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1695 |
< |
checkIncomplete(h); |
1696 |
< |
g.complete(v1); |
1697 |
< |
|
1698 |
< |
checkCompletedWithWrappedCancellationException(h); |
1699 |
< |
checkCancelled(f); |
1700 |
< |
assertEquals(0, r.invocationCount); |
1701 |
< |
checkCompletedNormally(g, v1); |
1702 |
< |
}} |
1703 |
< |
|
1704 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1705 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1706 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1707 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1708 |
< |
{ |
1709 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1710 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
< |
final SubtractAction r = new SubtractAction(); |
1712 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1713 |
< |
|
1714 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1715 |
< |
checkIncomplete(h); |
1716 |
< |
f.complete(v1); |
1717 |
< |
|
1718 |
< |
checkCompletedWithWrappedCancellationException(h); |
1719 |
< |
checkCancelled(g); |
1720 |
< |
assertEquals(0, r.invocationCount); |
1721 |
< |
checkCompletedNormally(f, v1); |
1722 |
< |
}} |
1723 |
< |
|
1724 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1725 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1726 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1727 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1728 |
< |
{ |
1729 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1730 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1731 |
< |
final SubtractAction r = new SubtractAction(); |
1732 |
< |
|
1733 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1734 |
< |
f.complete(v1); |
1735 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1736 |
< |
|
1737 |
< |
checkCompletedWithWrappedCancellationException(h); |
1738 |
< |
checkCancelled(g); |
1739 |
< |
assertEquals(0, r.invocationCount); |
1740 |
< |
checkCompletedNormally(f, v1); |
1741 |
< |
}} |
1742 |
< |
|
1743 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1487 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1488 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1489 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1490 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1491 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1492 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1493 |
|
{ |
1494 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1495 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1496 |
< |
final SubtractAction r = new SubtractAction(); |
1496 |
> |
final SubtractAction r = new SubtractAction(m); |
1497 |
|
|
1498 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1499 |
< |
g.complete(v1); |
1498 |
> |
(fFirst ? f : g).complete(v1); |
1499 |
> |
if (!createIncomplete) |
1500 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1501 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1502 |
+ |
if (createIncomplete) { |
1503 |
+ |
checkIncomplete(h); |
1504 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1505 |
+ |
} |
1506 |
|
|
1507 |
|
checkCompletedWithWrappedCancellationException(h); |
1508 |
< |
checkCancelled(f); |
1508 |
> |
checkCancelled(!fFirst ? f : g); |
1509 |
|
assertEquals(0, r.invocationCount); |
1510 |
< |
checkCompletedNormally(g, v1); |
1510 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1511 |
|
}} |
1512 |
|
|
1513 |
|
/** |
1514 |
|
* runAfterBoth result completes normally after normal |
1515 |
|
* completion of sources |
1516 |
|
*/ |
1517 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1767 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1768 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1769 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1770 |
< |
{ |
1771 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1772 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1773 |
< |
final Noop r = new Noop(); |
1774 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1775 |
< |
|
1776 |
< |
f.complete(v1); |
1777 |
< |
checkIncomplete(h); |
1778 |
< |
assertEquals(0, r.invocationCount); |
1779 |
< |
g.complete(v2); |
1780 |
< |
|
1781 |
< |
checkCompletedNormally(h, null); |
1782 |
< |
assertEquals(1, r.invocationCount); |
1783 |
< |
checkCompletedNormally(f, v1); |
1784 |
< |
checkCompletedNormally(g, v2); |
1785 |
< |
}} |
1786 |
< |
|
1787 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1788 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1789 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1790 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1791 |
< |
{ |
1792 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1793 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1794 |
< |
final Noop r = new Noop(); |
1795 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1796 |
< |
|
1797 |
< |
g.complete(v2); |
1798 |
< |
checkIncomplete(h); |
1799 |
< |
assertEquals(0, r.invocationCount); |
1800 |
< |
f.complete(v1); |
1801 |
< |
|
1802 |
< |
checkCompletedNormally(h, null); |
1803 |
< |
assertEquals(1, r.invocationCount); |
1804 |
< |
checkCompletedNormally(f, v1); |
1805 |
< |
checkCompletedNormally(g, v2); |
1806 |
< |
}} |
1807 |
< |
|
1808 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1809 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1810 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1811 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1812 |
< |
{ |
1813 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1814 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1815 |
< |
final Noop r = new Noop(); |
1816 |
< |
|
1817 |
< |
g.complete(v2); |
1818 |
< |
f.complete(v1); |
1819 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1820 |
< |
|
1821 |
< |
checkCompletedNormally(h, null); |
1822 |
< |
assertEquals(1, r.invocationCount); |
1823 |
< |
checkCompletedNormally(f, v1); |
1824 |
< |
checkCompletedNormally(g, v2); |
1825 |
< |
}} |
1826 |
< |
|
1827 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1517 |
> |
public void testRunAfterBoth_normalCompletion() { |
1518 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1519 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1520 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1521 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1522 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1523 |
|
{ |
1524 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1525 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1526 |
< |
final Noop r = new Noop(); |
1526 |
> |
final Noop r = new Noop(m); |
1527 |
|
|
1528 |
< |
f.complete(v1); |
1529 |
< |
g.complete(v2); |
1528 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1529 |
> |
if (!createIncomplete) |
1530 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1531 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1532 |
+ |
if (createIncomplete) { |
1533 |
+ |
checkIncomplete(h); |
1534 |
+ |
assertEquals(0, r.invocationCount); |
1535 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1536 |
+ |
} |
1537 |
|
|
1538 |
|
checkCompletedNormally(h, null); |
1539 |
|
assertEquals(1, r.invocationCount); |
1545 |
|
* runAfterBoth result completes exceptionally after exceptional |
1546 |
|
* completion of either source |
1547 |
|
*/ |
1548 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1851 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1852 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1853 |
< |
{ |
1854 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1855 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1856 |
< |
final Noop r = new Noop(); |
1857 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1858 |
< |
final CFException ex = new CFException(); |
1859 |
< |
|
1860 |
< |
f.completeExceptionally(ex); |
1861 |
< |
checkIncomplete(h); |
1862 |
< |
g.complete(v1); |
1863 |
< |
|
1864 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1865 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1866 |
< |
assertEquals(0, r.invocationCount); |
1867 |
< |
checkCompletedNormally(g, v1); |
1868 |
< |
}} |
1869 |
< |
|
1870 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1871 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1872 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1873 |
< |
{ |
1874 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1875 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1876 |
< |
final Noop r = new Noop(); |
1877 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1878 |
< |
final CFException ex = new CFException(); |
1879 |
< |
|
1880 |
< |
g.completeExceptionally(ex); |
1881 |
< |
checkIncomplete(h); |
1882 |
< |
f.complete(v1); |
1883 |
< |
|
1884 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1885 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1886 |
< |
assertEquals(0, r.invocationCount); |
1887 |
< |
checkCompletedNormally(f, v1); |
1888 |
< |
}} |
1889 |
< |
|
1890 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1891 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1892 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1893 |
< |
{ |
1894 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1895 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1896 |
< |
final Noop r = new Noop(); |
1897 |
< |
final CFException ex = new CFException(); |
1898 |
< |
|
1899 |
< |
g.completeExceptionally(ex); |
1900 |
< |
f.complete(v1); |
1901 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1902 |
< |
|
1903 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1904 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1905 |
< |
assertEquals(0, r.invocationCount); |
1906 |
< |
checkCompletedNormally(f, v1); |
1907 |
< |
}} |
1908 |
< |
|
1909 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1548 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1549 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1550 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1551 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1552 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1553 |
|
{ |
1554 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1555 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1915 |
– |
final Noop r = new Noop(); |
1556 |
|
final CFException ex = new CFException(); |
1557 |
+ |
final Noop r = new Noop(m); |
1558 |
|
|
1559 |
< |
f.completeExceptionally(ex); |
1560 |
< |
g.complete(v1); |
1559 |
> |
(fFirst ? f : g).complete(v1); |
1560 |
> |
if (!createIncomplete) |
1561 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1562 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1563 |
+ |
if (createIncomplete) { |
1564 |
+ |
checkIncomplete(h); |
1565 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1566 |
+ |
} |
1567 |
|
|
1568 |
|
checkCompletedWithWrappedCFException(h, ex); |
1923 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1569 |
|
assertEquals(0, r.invocationCount); |
1570 |
< |
checkCompletedNormally(g, v1); |
1570 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1571 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1572 |
|
}} |
1573 |
|
|
1574 |
|
/** |
1575 |
|
* runAfterBoth result completes exceptionally if action does |
1576 |
|
*/ |
1577 |
< |
public void testRunAfterBoth_actionFailed1() { |
1932 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1933 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1934 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1935 |
< |
{ |
1936 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1937 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1938 |
< |
final FailingRunnable r = new FailingRunnable(); |
1939 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1940 |
< |
|
1941 |
< |
f.complete(v1); |
1942 |
< |
checkIncomplete(h); |
1943 |
< |
g.complete(v2); |
1944 |
< |
|
1945 |
< |
checkCompletedWithWrappedCFException(h); |
1946 |
< |
checkCompletedNormally(f, v1); |
1947 |
< |
checkCompletedNormally(g, v2); |
1948 |
< |
}} |
1949 |
< |
|
1950 |
< |
public void testRunAfterBoth_actionFailed2() { |
1577 |
> |
public void testRunAfterBoth_actionFailed() { |
1578 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1579 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1580 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1581 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1582 |
|
{ |
1583 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1584 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1585 |
< |
final FailingRunnable r = new FailingRunnable(); |
1958 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1586 |
|
|
1587 |
< |
g.complete(v2); |
1588 |
< |
checkIncomplete(h); |
1589 |
< |
f.complete(v1); |
1587 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1588 |
> |
if (fFirst) { |
1589 |
> |
f.complete(v1); |
1590 |
> |
g.complete(v2); |
1591 |
> |
} else { |
1592 |
> |
g.complete(v2); |
1593 |
> |
f.complete(v1); |
1594 |
> |
} |
1595 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1596 |
|
|
1597 |
< |
checkCompletedWithWrappedCFException(h); |
1597 |
> |
checkCompletedWithWrappedCFException(h1); |
1598 |
> |
checkCompletedWithWrappedCFException(h2); |
1599 |
|
checkCompletedNormally(f, v1); |
1600 |
|
checkCompletedNormally(g, v2); |
1601 |
|
}} |
1603 |
|
/** |
1604 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1605 |
|
*/ |
1606 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1973 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1974 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1975 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1976 |
< |
{ |
1977 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1978 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1979 |
< |
final Noop r = new Noop(); |
1980 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1981 |
< |
|
1982 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1983 |
< |
checkIncomplete(h); |
1984 |
< |
g.complete(v1); |
1985 |
< |
|
1986 |
< |
checkCompletedWithWrappedCancellationException(h); |
1987 |
< |
checkCancelled(f); |
1988 |
< |
assertEquals(0, r.invocationCount); |
1989 |
< |
checkCompletedNormally(g, v1); |
1990 |
< |
}} |
1991 |
< |
|
1992 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1993 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1994 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1995 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1996 |
< |
{ |
1997 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1998 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1999 |
< |
final Noop r = new Noop(); |
2000 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
2001 |
< |
|
2002 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2003 |
< |
checkIncomplete(h); |
2004 |
< |
f.complete(v1); |
2005 |
< |
|
2006 |
< |
checkCompletedWithWrappedCancellationException(h); |
2007 |
< |
checkCancelled(g); |
2008 |
< |
assertEquals(0, r.invocationCount); |
2009 |
< |
checkCompletedNormally(f, v1); |
2010 |
< |
}} |
2011 |
< |
|
2012 |
< |
public void testRunAfterBoth_sourceCancelled3() { |
1606 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1607 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1608 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1609 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1610 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1611 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1612 |
|
{ |
1613 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1614 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1615 |
< |
final Noop r = new Noop(); |
1615 |
> |
final Noop r = new Noop(m); |
1616 |
|
|
2021 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2022 |
– |
f.complete(v1); |
2023 |
– |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1617 |
|
|
1618 |
< |
checkCompletedWithWrappedCancellationException(h); |
1619 |
< |
checkCancelled(g); |
1620 |
< |
assertEquals(0, r.invocationCount); |
2028 |
< |
checkCompletedNormally(f, v1); |
2029 |
< |
}} |
2030 |
< |
|
2031 |
< |
public void testRunAfterBoth_sourceCancelled4() { |
2032 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2033 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2034 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2035 |
< |
{ |
2036 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2037 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2038 |
< |
final Noop r = new Noop(); |
2039 |
< |
|
2040 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2041 |
< |
g.complete(v1); |
1618 |
> |
(fFirst ? f : g).complete(v1); |
1619 |
> |
if (!createIncomplete) |
1620 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1621 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1622 |
+ |
if (createIncomplete) { |
1623 |
+ |
checkIncomplete(h); |
1624 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1625 |
+ |
} |
1626 |
|
|
1627 |
|
checkCompletedWithWrappedCancellationException(h); |
1628 |
< |
checkCancelled(f); |
1628 |
> |
checkCancelled(!fFirst ? f : g); |
1629 |
|
assertEquals(0, r.invocationCount); |
1630 |
< |
checkCompletedNormally(g, v1); |
1630 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1631 |
|
}} |
1632 |
|
|
1633 |
|
/** |
1634 |
|
* applyToEither result completes normally after normal completion |
1635 |
|
* of either source |
1636 |
|
*/ |
1637 |
< |
public void testApplyToEither_normalCompletion1() { |
1637 |
> |
public void testApplyToEither_normalCompletion() { |
1638 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1639 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1640 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1641 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1642 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1643 |
|
{ |
1644 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1645 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1646 |
< |
final IncFunction r = new IncFunction(); |
2062 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1646 |
> |
final IncFunction r = new IncFunction(m); |
1647 |
|
|
1648 |
< |
f.complete(v1); |
1649 |
< |
checkCompletedNormally(h, inc(v1)); |
1650 |
< |
g.complete(v2); |
1648 |
> |
if (!createIncomplete) |
1649 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1650 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1651 |
> |
if (createIncomplete) { |
1652 |
> |
checkIncomplete(h); |
1653 |
> |
assertEquals(0, r.invocationCount); |
1654 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1655 |
> |
} |
1656 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1657 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1658 |
|
|
1659 |
|
checkCompletedNormally(f, v1); |
1660 |
|
checkCompletedNormally(g, v2); |
1661 |
< |
checkCompletedNormally(h, inc(v1)); |
1661 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1662 |
|
}} |
1663 |
|
|
1664 |
< |
public void testApplyToEither_normalCompletion2() { |
1664 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1665 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1666 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1667 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1668 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1669 |
|
{ |
1670 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1671 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1672 |
< |
final IncFunction r = new IncFunction(); |
2081 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1672 |
> |
final IncFunction r = new IncFunction(m); |
1673 |
|
|
1674 |
< |
g.complete(v2); |
1675 |
< |
checkCompletedNormally(h, inc(v2)); |
1676 |
< |
f.complete(v1); |
1677 |
< |
|
1678 |
< |
checkCompletedNormally(f, v1); |
1679 |
< |
checkCompletedNormally(g, v2); |
1680 |
< |
checkCompletedNormally(h, inc(v2)); |
2090 |
< |
}} |
2091 |
< |
|
2092 |
< |
public void testApplyToEither_normalCompletion3() { |
2093 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2094 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2095 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
2096 |
< |
{ |
2097 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2098 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2099 |
< |
final IncFunction r = new IncFunction(); |
1674 |
> |
if (fFirst) { |
1675 |
> |
f.complete(v1); |
1676 |
> |
g.complete(v2); |
1677 |
> |
} else { |
1678 |
> |
g.complete(v2); |
1679 |
> |
f.complete(v1); |
1680 |
> |
} |
1681 |
|
|
2101 |
– |
f.complete(v1); |
2102 |
– |
g.complete(v2); |
1682 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1683 |
|
|
1684 |
|
checkCompletedNormally(f, v1); |
1696 |
|
*/ |
1697 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1698 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1699 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1700 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1701 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1702 |
|
{ |
1703 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1704 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
– |
final IncFunction r = new IncFunction(); |
2125 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1705 |
|
final CFException ex = new CFException(); |
1706 |
+ |
final IncFunction r = new IncFunction(m); |
1707 |
|
|
1708 |
< |
f.completeExceptionally(ex); |
2129 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2130 |
< |
g.complete(v1); |
2131 |
< |
|
2132 |
< |
assertEquals(0, r.invocationCount); |
2133 |
< |
checkCompletedNormally(g, v1); |
2134 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2135 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2136 |
< |
}} |
2137 |
< |
|
2138 |
< |
public void testApplyToEither_exceptionalCompletion2() { |
2139 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2140 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2141 |
< |
{ |
2142 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2143 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2144 |
< |
final IncFunction r = new IncFunction(); |
1708 |
> |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1709 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1710 |
< |
final CFException ex = new CFException(); |
1710 |
> |
if (createIncomplete) { |
1711 |
> |
checkIncomplete(h); |
1712 |
> |
assertEquals(0, r.invocationCount); |
1713 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1714 |
> |
} |
1715 |
|
|
2148 |
– |
g.completeExceptionally(ex); |
1716 |
|
checkCompletedWithWrappedCFException(h, ex); |
1717 |
< |
f.complete(v1); |
1717 |
> |
(!fFirst ? f : g).complete(v1); |
1718 |
|
|
1719 |
|
assertEquals(0, r.invocationCount); |
1720 |
< |
checkCompletedNormally(f, v1); |
1721 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1720 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1721 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1722 |
|
checkCompletedWithWrappedCFException(h, ex); |
1723 |
|
}} |
1724 |
|
|
1725 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1725 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1726 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1727 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1728 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1729 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1730 |
|
{ |
1731 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1732 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1733 |
< |
final IncFunction r = new IncFunction(); |
1733 |
> |
final IncFunction r1 = new IncFunction(m); |
1734 |
> |
final IncFunction r2 = new IncFunction(m); |
1735 |
|
final CFException ex = new CFException(); |
1736 |
< |
|
1737 |
< |
g.completeExceptionally(ex); |
1738 |
< |
f.complete(v1); |
1739 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1736 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1737 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1738 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1739 |
> |
if (fFirst) { |
1740 |
> |
f.complete(v1); |
1741 |
> |
g.completeExceptionally(ex); |
1742 |
> |
} else { |
1743 |
> |
g.completeExceptionally(ex); |
1744 |
> |
f.complete(v1); |
1745 |
> |
} |
1746 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1747 |
|
|
1748 |
|
// unspecified behavior |
2172 |
– |
Integer v; |
1749 |
|
try { |
1750 |
< |
assertEquals(inc(v1), h.join()); |
1751 |
< |
assertEquals(1, r.invocationCount); |
1750 |
> |
assertEquals(inc(v1), h1.join()); |
1751 |
> |
assertEquals(1, r1.invocationCount); |
1752 |
|
} catch (CompletionException ok) { |
1753 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1754 |
< |
assertEquals(0, r.invocationCount); |
1753 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1754 |
> |
assertEquals(0, r1.invocationCount); |
1755 |
|
} |
1756 |
|
|
2181 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2182 |
– |
checkCompletedNormally(f, v1); |
2183 |
– |
}} |
2184 |
– |
|
2185 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2186 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2187 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2188 |
– |
{ |
2189 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2190 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2191 |
– |
final IncFunction r = new IncFunction(); |
2192 |
– |
final CFException ex = new CFException(); |
2193 |
– |
|
2194 |
– |
f.completeExceptionally(ex); |
2195 |
– |
g.complete(v1); |
2196 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2197 |
– |
|
2198 |
– |
// unspecified behavior |
2199 |
– |
Integer v; |
1757 |
|
try { |
1758 |
< |
assertEquals(inc(v1), h.join()); |
1759 |
< |
assertEquals(1, r.invocationCount); |
1758 |
> |
assertEquals(inc(v1), h2.join()); |
1759 |
> |
assertEquals(1, r2.invocationCount); |
1760 |
|
} catch (CompletionException ok) { |
1761 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1762 |
< |
assertEquals(0, r.invocationCount); |
1761 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1762 |
> |
assertEquals(0, r2.invocationCount); |
1763 |
|
} |
1764 |
|
|
1765 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1766 |
< |
checkCompletedNormally(g, v1); |
1765 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1766 |
> |
checkCompletedNormally(f, v1); |
1767 |
|
}} |
1768 |
|
|
1769 |
|
/** |
1776 |
|
{ |
1777 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1778 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1779 |
< |
final FailingFunction r = new FailingFunction(); |
1779 |
> |
final FailingFunction r = new FailingFunction(m); |
1780 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1781 |
|
|
1782 |
|
f.complete(v1); |
1793 |
|
{ |
1794 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1795 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1796 |
< |
final FailingFunction r = new FailingFunction(); |
1796 |
> |
final FailingFunction r = new FailingFunction(m); |
1797 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1798 |
|
|
1799 |
|
g.complete(v2); |
1809 |
|
public void testApplyToEither_sourceCancelled1() { |
1810 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1811 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1812 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1813 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1814 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1815 |
|
{ |
1816 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1817 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1818 |
< |
final IncFunction r = new IncFunction(); |
2260 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1818 |
> |
final IncFunction r = new IncFunction(m); |
1819 |
|
|
1820 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2263 |
< |
checkCompletedWithWrappedCancellationException(h); |
2264 |
< |
g.complete(v1); |
2265 |
< |
|
2266 |
< |
checkCancelled(f); |
2267 |
< |
assertEquals(0, r.invocationCount); |
2268 |
< |
checkCompletedNormally(g, v1); |
2269 |
< |
checkCompletedWithWrappedCancellationException(h); |
2270 |
< |
}} |
2271 |
< |
|
2272 |
< |
public void testApplyToEither_sourceCancelled2() { |
2273 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2274 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2275 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2276 |
< |
{ |
2277 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2278 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2279 |
< |
final IncFunction r = new IncFunction(); |
1820 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1821 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1822 |
+ |
if (createIncomplete) { |
1823 |
+ |
checkIncomplete(h); |
1824 |
+ |
assertEquals(0, r.invocationCount); |
1825 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1826 |
+ |
} |
1827 |
|
|
2282 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1828 |
|
checkCompletedWithWrappedCancellationException(h); |
1829 |
< |
f.complete(v1); |
1829 |
> |
(!fFirst ? f : g).complete(v1); |
1830 |
|
|
2286 |
– |
checkCancelled(g); |
1831 |
|
assertEquals(0, r.invocationCount); |
1832 |
< |
checkCompletedNormally(f, v1); |
1832 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1833 |
> |
checkCancelled(fFirst ? f : g); |
1834 |
|
checkCompletedWithWrappedCancellationException(h); |
1835 |
|
}} |
1836 |
|
|
1837 |
< |
public void testApplyToEither_sourceCancelled3() { |
1837 |
> |
public void testApplyToEither_sourceCancelled2() { |
1838 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1839 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1840 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1841 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1842 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1843 |
|
{ |
1844 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1845 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1846 |
< |
final IncFunction r = new IncFunction(); |
1846 |
> |
final IncFunction r1 = new IncFunction(m); |
1847 |
> |
final IncFunction r2 = new IncFunction(m); |
1848 |
> |
final CFException ex = new CFException(); |
1849 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1850 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1851 |
|
|
1852 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1853 |
< |
f.complete(v1); |
1854 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1852 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1853 |
> |
if (fFirst) { |
1854 |
> |
f.complete(v1); |
1855 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1856 |
> |
} else { |
1857 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1858 |
> |
f.complete(v1); |
1859 |
> |
} |
1860 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1861 |
|
|
1862 |
|
// unspecified behavior |
2306 |
– |
Integer v; |
1863 |
|
try { |
1864 |
< |
assertEquals(inc(v1), h.join()); |
1865 |
< |
assertEquals(1, r.invocationCount); |
1864 |
> |
assertEquals(inc(v1), h1.join()); |
1865 |
> |
assertEquals(1, r1.invocationCount); |
1866 |
|
} catch (CompletionException ok) { |
1867 |
< |
checkCompletedWithWrappedCancellationException(h); |
1868 |
< |
assertEquals(0, r.invocationCount); |
1867 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1868 |
> |
assertEquals(0, r1.invocationCount); |
1869 |
|
} |
1870 |
|
|
2315 |
– |
checkCancelled(g); |
2316 |
– |
checkCompletedNormally(f, v1); |
2317 |
– |
}} |
2318 |
– |
|
2319 |
– |
public void testApplyToEither_sourceCancelled4() { |
2320 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2321 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2322 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2323 |
– |
{ |
2324 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2325 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2326 |
– |
final IncFunction r = new IncFunction(); |
2327 |
– |
|
2328 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2329 |
– |
g.complete(v1); |
2330 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2331 |
– |
|
2332 |
– |
// unspecified behavior |
2333 |
– |
Integer v; |
1871 |
|
try { |
1872 |
< |
assertEquals(inc(v1), h.join()); |
1873 |
< |
assertEquals(1, r.invocationCount); |
1872 |
> |
assertEquals(inc(v1), h2.join()); |
1873 |
> |
assertEquals(1, r2.invocationCount); |
1874 |
|
} catch (CompletionException ok) { |
1875 |
< |
checkCompletedWithWrappedCancellationException(h); |
1876 |
< |
assertEquals(0, r.invocationCount); |
1875 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1876 |
> |
assertEquals(0, r2.invocationCount); |
1877 |
|
} |
1878 |
|
|
1879 |
< |
checkCancelled(f); |
1880 |
< |
checkCompletedNormally(g, v1); |
1879 |
> |
checkCancelled(g); |
1880 |
> |
checkCompletedNormally(f, v1); |
1881 |
|
}} |
1882 |
|
|
1883 |
|
/** |
2056 |
|
{ |
2057 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2058 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2059 |
< |
final FailingConsumer r = new FailingConsumer(); |
2059 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2060 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2061 |
|
|
2062 |
|
f.complete(v1); |
2073 |
|
{ |
2074 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2075 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2076 |
< |
final FailingConsumer r = new FailingConsumer(); |
2076 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2077 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2078 |
|
|
2079 |
|
g.complete(v2); |
2193 |
|
{ |
2194 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2195 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2196 |
< |
final Noop r = new Noop(); |
2196 |
> |
final Noop r = new Noop(m); |
2197 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2198 |
|
|
2199 |
|
f.complete(v1); |
2214 |
|
{ |
2215 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2216 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2217 |
< |
final Noop r = new Noop(); |
2217 |
> |
final Noop r = new Noop(m); |
2218 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2219 |
|
|
2220 |
|
g.complete(v2); |
2235 |
|
{ |
2236 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2237 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2238 |
< |
final Noop r = new Noop(); |
2238 |
> |
final Noop r = new Noop(m); |
2239 |
|
|
2240 |
|
f.complete(v1); |
2241 |
|
g.complete(v2); |
2257 |
|
{ |
2258 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2259 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2260 |
< |
final Noop r = new Noop(); |
2260 |
> |
final Noop r = new Noop(m); |
2261 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2262 |
|
final CFException ex = new CFException(); |
2263 |
|
|
2277 |
|
{ |
2278 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2279 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2280 |
< |
final Noop r = new Noop(); |
2280 |
> |
final Noop r = new Noop(m); |
2281 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2282 |
|
final CFException ex = new CFException(); |
2283 |
|
|
2297 |
|
{ |
2298 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2299 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2300 |
< |
final Noop r = new Noop(); |
2300 |
> |
final Noop r = new Noop(m); |
2301 |
|
final CFException ex = new CFException(); |
2302 |
|
|
2303 |
|
g.completeExceptionally(ex); |
2324 |
|
{ |
2325 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2326 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2327 |
< |
final Noop r = new Noop(); |
2327 |
> |
final Noop r = new Noop(m); |
2328 |
|
final CFException ex = new CFException(); |
2329 |
|
|
2330 |
|
f.completeExceptionally(ex); |
2355 |
|
{ |
2356 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2357 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2358 |
< |
final FailingRunnable r = new FailingRunnable(); |
2358 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2359 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2360 |
|
|
2361 |
|
f.complete(v1); |
2372 |
|
{ |
2373 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2374 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2375 |
< |
final FailingRunnable r = new FailingRunnable(); |
2375 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2376 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2377 |
|
|
2378 |
|
g.complete(v2); |
2392 |
|
{ |
2393 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2394 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2395 |
< |
final Noop r = new Noop(); |
2395 |
> |
final Noop r = new Noop(m); |
2396 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2397 |
|
|
2398 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2412 |
|
{ |
2413 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2414 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2415 |
< |
final Noop r = new Noop(); |
2415 |
> |
final Noop r = new Noop(m); |
2416 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2417 |
|
|
2418 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2432 |
|
{ |
2433 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2434 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2435 |
< |
final Noop r = new Noop(); |
2435 |
> |
final Noop r = new Noop(m); |
2436 |
|
|
2437 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2438 |
|
f.complete(v1); |
2459 |
|
{ |
2460 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2461 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2462 |
< |
final Noop r = new Noop(); |
2462 |
> |
final Noop r = new Noop(m); |
2463 |
|
|
2464 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2465 |
|
g.complete(v1); |
2488 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2489 |
|
{ |
2490 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2491 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2491 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2492 |
|
if (!createIncomplete) f.complete(v1); |
2493 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2493 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2494 |
|
if (createIncomplete) f.complete(v1); |
2495 |
|
|
2496 |
|
checkCompletedNormally(g, inc(v1)); |
2507 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2508 |
|
{ |
2509 |
|
final CFException ex = new CFException(); |
2510 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2510 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2511 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2512 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
2513 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2513 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2514 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2515 |
|
|
2516 |
|
checkCompletedWithWrappedCFException(g, ex); |
2528 |
|
{ |
2529 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2530 |
|
final FailingCompletableFutureFunction r |
2531 |
< |
= new FailingCompletableFutureFunction(); |
2531 |
> |
= new FailingCompletableFutureFunction(m); |
2532 |
|
if (!createIncomplete) f.complete(v1); |
2533 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2533 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2534 |
|
if (createIncomplete) f.complete(v1); |
2535 |
|
|
2536 |
|
checkCompletedWithWrappedCFException(g); |
2546 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2547 |
|
{ |
2548 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2549 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2549 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2550 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2551 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2551 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2552 |
|
if (createIncomplete) { |
2553 |
|
checkIncomplete(g); |
2554 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2720 |
|
|
2721 |
|
() -> f.thenCompose(null), |
2722 |
|
() -> f.thenComposeAsync(null), |
2723 |
< |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
2723 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null), |
2724 |
|
() -> f.thenComposeAsync(null, exec), |
2725 |
|
|
2726 |
|
() -> f.exceptionally(null), |