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) |
1320 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1321 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1322 |
|
final CFException ex = new CFException(); |
1323 |
< |
final SubtractFunction r = new SubtractFunction(); |
1323 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1324 |
|
|
1325 |
|
(fFirst ? f : g).complete(v1); |
1326 |
|
if (!createIncomplete) |
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 |
|
if (fFirst) { |
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 |
|
(fFirst ? f : g).complete(v1); |
1382 |
|
if (!createIncomplete) |
1397 |
|
* thenAcceptBoth result completes normally after normal |
1398 |
|
* completion of sources |
1399 |
|
*/ |
1400 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1361 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1362 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1363 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1364 |
< |
{ |
1365 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1366 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1367 |
< |
final SubtractAction r = new SubtractAction(); |
1368 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1369 |
< |
|
1370 |
< |
f.complete(v1); |
1371 |
< |
checkIncomplete(h); |
1372 |
< |
assertEquals(0, r.invocationCount); |
1373 |
< |
g.complete(v2); |
1374 |
< |
|
1375 |
< |
checkCompletedNormally(h, null); |
1376 |
< |
assertEquals(subtract(v1, v2), r.value); |
1377 |
< |
checkCompletedNormally(f, v1); |
1378 |
< |
checkCompletedNormally(g, v2); |
1379 |
< |
}} |
1380 |
< |
|
1381 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1382 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1383 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1384 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1385 |
< |
{ |
1386 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1387 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1388 |
< |
final SubtractAction r = new SubtractAction(); |
1389 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1390 |
< |
|
1391 |
< |
g.complete(v2); |
1392 |
< |
checkIncomplete(h); |
1393 |
< |
assertEquals(0, r.invocationCount); |
1394 |
< |
f.complete(v1); |
1395 |
< |
|
1396 |
< |
checkCompletedNormally(h, null); |
1397 |
< |
assertEquals(subtract(v1, v2), r.value); |
1398 |
< |
checkCompletedNormally(f, v1); |
1399 |
< |
checkCompletedNormally(g, v2); |
1400 |
< |
}} |
1401 |
< |
|
1402 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1403 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
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(); |
1410 |
< |
|
1411 |
< |
g.complete(v2); |
1412 |
< |
f.complete(v1); |
1413 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1414 |
< |
|
1415 |
< |
checkCompletedNormally(h, null); |
1416 |
< |
assertEquals(subtract(v1, v2), r.value); |
1417 |
< |
checkCompletedNormally(f, v1); |
1418 |
< |
checkCompletedNormally(g, v2); |
1419 |
< |
}} |
1420 |
< |
|
1421 |
< |
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() { |
1445 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1446 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1447 |
< |
{ |
1448 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1449 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1450 |
< |
final SubtractAction r = new SubtractAction(); |
1451 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1452 |
< |
final CFException ex = new CFException(); |
1453 |
< |
|
1454 |
< |
f.completeExceptionally(ex); |
1455 |
< |
checkIncomplete(h); |
1456 |
< |
g.complete(v1); |
1457 |
< |
|
1458 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1459 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1460 |
< |
assertEquals(0, r.invocationCount); |
1461 |
< |
checkCompletedNormally(g, v1); |
1462 |
< |
}} |
1463 |
< |
|
1464 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1465 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1466 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1467 |
< |
{ |
1468 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1469 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1470 |
< |
final SubtractAction r = new SubtractAction(); |
1471 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1472 |
< |
final CFException ex = new CFException(); |
1473 |
< |
|
1474 |
< |
g.completeExceptionally(ex); |
1475 |
< |
checkIncomplete(h); |
1476 |
< |
f.complete(v1); |
1477 |
< |
|
1478 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1479 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1480 |
< |
assertEquals(0, r.invocationCount); |
1481 |
< |
checkCompletedNormally(f, v1); |
1482 |
< |
}} |
1483 |
< |
|
1484 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1485 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1486 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1487 |
< |
{ |
1488 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1489 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1490 |
< |
final SubtractAction r = new SubtractAction(); |
1491 |
< |
final CFException ex = new CFException(); |
1492 |
< |
|
1493 |
< |
g.completeExceptionally(ex); |
1494 |
< |
f.complete(v1); |
1495 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1496 |
< |
|
1497 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1498 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1499 |
< |
assertEquals(0, r.invocationCount); |
1500 |
< |
checkCompletedNormally(f, v1); |
1501 |
< |
}} |
1502 |
< |
|
1503 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
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<>(); |
1509 |
– |
final SubtractAction r = new SubtractAction(); |
1439 |
|
final CFException ex = new CFException(); |
1440 |
+ |
final SubtractAction r = new SubtractAction(m); |
1441 |
|
|
1442 |
< |
f.completeExceptionally(ex); |
1443 |
< |
g.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); |
1517 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1452 |
|
assertEquals(0, r.invocationCount); |
1453 |
< |
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() { |
1526 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1527 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1528 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1529 |
< |
{ |
1530 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1531 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1532 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1533 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1534 |
< |
|
1535 |
< |
f.complete(v1); |
1536 |
< |
checkIncomplete(h); |
1537 |
< |
g.complete(v2); |
1538 |
< |
|
1539 |
< |
checkCompletedWithWrappedCFException(h); |
1540 |
< |
checkCompletedNormally(f, v1); |
1541 |
< |
checkCompletedNormally(g, v2); |
1542 |
< |
}} |
1543 |
< |
|
1544 |
< |
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() { |
1567 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1568 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1569 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1570 |
< |
{ |
1571 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1572 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1573 |
< |
final SubtractAction r = new SubtractAction(); |
1574 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1575 |
< |
|
1576 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1577 |
< |
checkIncomplete(h); |
1578 |
< |
g.complete(v1); |
1579 |
< |
|
1580 |
< |
checkCompletedWithWrappedCancellationException(h); |
1581 |
< |
checkCancelled(f); |
1582 |
< |
assertEquals(0, r.invocationCount); |
1583 |
< |
checkCompletedNormally(g, v1); |
1584 |
< |
}} |
1585 |
< |
|
1586 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1587 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1588 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1589 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1590 |
< |
{ |
1591 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1592 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1593 |
< |
final SubtractAction r = new SubtractAction(); |
1594 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1595 |
< |
|
1596 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1597 |
< |
checkIncomplete(h); |
1598 |
< |
f.complete(v1); |
1599 |
< |
|
1600 |
< |
checkCompletedWithWrappedCancellationException(h); |
1601 |
< |
checkCancelled(g); |
1602 |
< |
assertEquals(0, r.invocationCount); |
1603 |
< |
checkCompletedNormally(f, v1); |
1604 |
< |
}} |
1605 |
< |
|
1606 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1607 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1608 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1609 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1610 |
< |
{ |
1611 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1612 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1613 |
< |
final SubtractAction r = new SubtractAction(); |
1614 |
< |
|
1615 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1616 |
< |
f.complete(v1); |
1617 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1618 |
< |
|
1619 |
< |
checkCompletedWithWrappedCancellationException(h); |
1620 |
< |
checkCancelled(g); |
1621 |
< |
assertEquals(0, r.invocationCount); |
1622 |
< |
checkCompletedNormally(f, v1); |
1623 |
< |
}} |
1624 |
< |
|
1625 |
< |
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() { |
1649 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1650 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1651 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1652 |
< |
{ |
1653 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1654 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1655 |
< |
final Noop r = new Noop(); |
1656 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1657 |
< |
|
1658 |
< |
f.complete(v1); |
1659 |
< |
checkIncomplete(h); |
1660 |
< |
assertEquals(0, r.invocationCount); |
1661 |
< |
g.complete(v2); |
1662 |
< |
|
1663 |
< |
checkCompletedNormally(h, null); |
1664 |
< |
assertEquals(1, r.invocationCount); |
1665 |
< |
checkCompletedNormally(f, v1); |
1666 |
< |
checkCompletedNormally(g, v2); |
1667 |
< |
}} |
1668 |
< |
|
1669 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1670 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1671 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1672 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1673 |
< |
{ |
1674 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1675 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1676 |
< |
final Noop r = new Noop(); |
1677 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1678 |
< |
|
1679 |
< |
g.complete(v2); |
1680 |
< |
checkIncomplete(h); |
1681 |
< |
assertEquals(0, r.invocationCount); |
1682 |
< |
f.complete(v1); |
1683 |
< |
|
1684 |
< |
checkCompletedNormally(h, null); |
1685 |
< |
assertEquals(1, r.invocationCount); |
1686 |
< |
checkCompletedNormally(f, v1); |
1687 |
< |
checkCompletedNormally(g, v2); |
1688 |
< |
}} |
1689 |
< |
|
1690 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1691 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1692 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1693 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1694 |
< |
{ |
1695 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1696 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1697 |
< |
final Noop r = new Noop(); |
1698 |
< |
|
1699 |
< |
g.complete(v2); |
1700 |
< |
f.complete(v1); |
1701 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1702 |
< |
|
1703 |
< |
checkCompletedNormally(h, null); |
1704 |
< |
assertEquals(1, r.invocationCount); |
1705 |
< |
checkCompletedNormally(f, v1); |
1706 |
< |
checkCompletedNormally(g, v2); |
1707 |
< |
}} |
1708 |
< |
|
1709 |
< |
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() { |
1733 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1734 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1735 |
< |
{ |
1736 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1737 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1738 |
< |
final Noop r = new Noop(); |
1739 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1740 |
< |
final CFException ex = new CFException(); |
1741 |
< |
|
1742 |
< |
f.completeExceptionally(ex); |
1743 |
< |
checkIncomplete(h); |
1744 |
< |
g.complete(v1); |
1745 |
< |
|
1746 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1747 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1748 |
< |
assertEquals(0, r.invocationCount); |
1749 |
< |
checkCompletedNormally(g, v1); |
1750 |
< |
}} |
1751 |
< |
|
1752 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1753 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1754 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1755 |
< |
{ |
1756 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1757 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1758 |
< |
final Noop r = new Noop(); |
1759 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1760 |
< |
final CFException ex = new CFException(); |
1761 |
< |
|
1762 |
< |
g.completeExceptionally(ex); |
1763 |
< |
checkIncomplete(h); |
1764 |
< |
f.complete(v1); |
1765 |
< |
|
1766 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1767 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1768 |
< |
assertEquals(0, r.invocationCount); |
1769 |
< |
checkCompletedNormally(f, v1); |
1770 |
< |
}} |
1771 |
< |
|
1772 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1773 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1774 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1775 |
< |
{ |
1776 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1777 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1778 |
< |
final Noop r = new Noop(); |
1779 |
< |
final CFException ex = new CFException(); |
1780 |
< |
|
1781 |
< |
g.completeExceptionally(ex); |
1782 |
< |
f.complete(v1); |
1783 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1784 |
< |
|
1785 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1786 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1787 |
< |
assertEquals(0, r.invocationCount); |
1788 |
< |
checkCompletedNormally(f, v1); |
1789 |
< |
}} |
1790 |
< |
|
1791 |
< |
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<>(); |
1797 |
– |
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); |
1805 |
– |
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() { |
1814 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1815 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1816 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1817 |
< |
{ |
1818 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1819 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1820 |
< |
final FailingRunnable r = new FailingRunnable(); |
1821 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1822 |
< |
|
1823 |
< |
f.complete(v1); |
1824 |
< |
checkIncomplete(h); |
1825 |
< |
g.complete(v2); |
1826 |
< |
|
1827 |
< |
checkCompletedWithWrappedCFException(h); |
1828 |
< |
checkCompletedNormally(f, v1); |
1829 |
< |
checkCompletedNormally(g, v2); |
1830 |
< |
}} |
1831 |
< |
|
1832 |
< |
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(); |
1840 |
< |
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() { |
1855 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1856 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1857 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1858 |
< |
{ |
1859 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1860 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1861 |
< |
final Noop r = new Noop(); |
1862 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1863 |
< |
|
1864 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1865 |
< |
checkIncomplete(h); |
1866 |
< |
g.complete(v1); |
1867 |
< |
|
1868 |
< |
checkCompletedWithWrappedCancellationException(h); |
1869 |
< |
checkCancelled(f); |
1870 |
< |
assertEquals(0, r.invocationCount); |
1871 |
< |
checkCompletedNormally(g, v1); |
1872 |
< |
}} |
1873 |
< |
|
1874 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1875 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1876 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1877 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1878 |
< |
{ |
1879 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1880 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1881 |
< |
final Noop r = new Noop(); |
1882 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1883 |
< |
|
1884 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1885 |
< |
checkIncomplete(h); |
1886 |
< |
f.complete(v1); |
1887 |
< |
|
1888 |
< |
checkCompletedWithWrappedCancellationException(h); |
1889 |
< |
checkCancelled(g); |
1890 |
< |
assertEquals(0, r.invocationCount); |
1891 |
< |
checkCompletedNormally(f, v1); |
1892 |
< |
}} |
1893 |
< |
|
1894 |
< |
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(); |
1902 |
< |
|
1903 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1904 |
< |
f.complete(v1); |
1905 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1615 |
> |
final Noop r = new Noop(m); |
1616 |
|
|
1907 |
– |
checkCompletedWithWrappedCancellationException(h); |
1908 |
– |
checkCancelled(g); |
1909 |
– |
assertEquals(0, r.invocationCount); |
1910 |
– |
checkCompletedNormally(f, v1); |
1911 |
– |
}} |
1912 |
– |
|
1913 |
– |
public void testRunAfterBoth_sourceCancelled4() { |
1914 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
1915 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1916 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
1917 |
– |
{ |
1918 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1919 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1920 |
– |
final Noop r = new Noop(); |
1617 |
|
|
1618 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1619 |
< |
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(); |
1944 |
< |
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(); |
1963 |
< |
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)); |
1972 |
< |
}} |
1973 |
< |
|
1974 |
< |
public void testApplyToEither_normalCompletion3() { |
1975 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1976 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1977 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1978 |
< |
{ |
1979 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1980 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1981 |
< |
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 |
|
|
1983 |
– |
f.complete(v1); |
1984 |
– |
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<>(); |
2006 |
– |
final IncFunction r = new IncFunction(); |
2007 |
– |
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); |
2011 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2012 |
< |
g.complete(v1); |
2013 |
< |
|
2014 |
< |
assertEquals(0, r.invocationCount); |
2015 |
< |
checkCompletedNormally(g, v1); |
2016 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2017 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2018 |
< |
}} |
2019 |
< |
|
2020 |
< |
public void testApplyToEither_exceptionalCompletion2() { |
2021 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2022 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2023 |
< |
{ |
2024 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2025 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2026 |
< |
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 |
|
|
2030 |
– |
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 |
2054 |
– |
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 |
|
|
2063 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2064 |
– |
checkCompletedNormally(f, v1); |
2065 |
– |
}} |
2066 |
– |
|
2067 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2068 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2069 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2070 |
– |
{ |
2071 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2072 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2073 |
– |
final IncFunction r = new IncFunction(); |
2074 |
– |
final CFException ex = new CFException(); |
2075 |
– |
|
2076 |
– |
f.completeExceptionally(ex); |
2077 |
– |
g.complete(v1); |
2078 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2079 |
– |
|
2080 |
– |
// unspecified behavior |
2081 |
– |
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(); |
2142 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2143 |
< |
|
2144 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2145 |
< |
checkCompletedWithWrappedCancellationException(h); |
2146 |
< |
g.complete(v1); |
1818 |
> |
final IncFunction r = new IncFunction(m); |
1819 |
|
|
1820 |
< |
checkCancelled(f); |
2149 |
< |
assertEquals(0, r.invocationCount); |
2150 |
< |
checkCompletedNormally(g, v1); |
2151 |
< |
checkCompletedWithWrappedCancellationException(h); |
2152 |
< |
}} |
2153 |
< |
|
2154 |
< |
public void testApplyToEither_sourceCancelled2() { |
2155 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2156 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2157 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2158 |
< |
{ |
2159 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2160 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2161 |
< |
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 |
|
|
2164 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1828 |
|
checkCompletedWithWrappedCancellationException(h); |
1829 |
< |
f.complete(v1); |
1829 |
> |
(!fFirst ? f : g).complete(v1); |
1830 |
|
|
2168 |
– |
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 |
2188 |
– |
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 |
|
|
2197 |
– |
checkCancelled(g); |
2198 |
– |
checkCompletedNormally(f, v1); |
2199 |
– |
}} |
2200 |
– |
|
2201 |
– |
public void testApplyToEither_sourceCancelled4() { |
2202 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2203 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2204 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2205 |
– |
{ |
2206 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2207 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2208 |
– |
final IncFunction r = new IncFunction(); |
2209 |
– |
|
2210 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2211 |
– |
g.complete(v1); |
2212 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2213 |
– |
|
2214 |
– |
// unspecified behavior |
2215 |
– |
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), |