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 |
|
} |
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 |
|
|
503 |
|
public void checkExecutionMode() { |
504 |
|
assertNull(ForkJoinTask.getPool()); |
505 |
|
} |
506 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
507 |
+ |
throw new UnsupportedOperationException(); |
508 |
+ |
} |
509 |
|
public <T> CompletableFuture<Void> thenRun |
510 |
|
(CompletableFuture<T> f, Runnable a) { |
511 |
|
return f.thenRun(a); |
574 |
|
assertSame(ForkJoinPool.commonPool(), |
575 |
|
ForkJoinTask.getPool()); |
576 |
|
} |
577 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
578 |
+ |
return CompletableFuture.runAsync(a); |
579 |
+ |
} |
580 |
|
public <T> CompletableFuture<Void> thenRun |
581 |
|
(CompletableFuture<T> f, Runnable a) { |
582 |
|
return f.thenRunAsync(a); |
642 |
|
|
643 |
|
EXECUTOR { |
644 |
|
public void checkExecutionMode() { |
645 |
< |
//TODO |
645 |
> |
assertTrue(ThreadExecutor.startedCurrentThread()); |
646 |
> |
} |
647 |
> |
public CompletableFuture<Void> runAsync(Runnable a) { |
648 |
> |
return CompletableFuture.runAsync(a, new ThreadExecutor()); |
649 |
|
} |
650 |
|
public <T> CompletableFuture<Void> thenRun |
651 |
|
(CompletableFuture<T> f, Runnable a) { |
711 |
|
}; |
712 |
|
|
713 |
|
public abstract void checkExecutionMode(); |
714 |
+ |
public abstract CompletableFuture<Void> runAsync(Runnable a); |
715 |
|
public abstract <T> CompletableFuture<Void> thenRun |
716 |
|
(CompletableFuture<T> f, Runnable a); |
717 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
790 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
791 |
|
final CompletableFuture<Integer> g = f.exceptionally |
792 |
|
((Throwable t) -> { |
793 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
794 |
|
threadAssertSame(t, ex); |
795 |
|
a.getAndIncrement(); |
796 |
|
return v1; |
812 |
|
if (!createIncomplete) f.completeExceptionally(ex1); |
813 |
|
final CompletableFuture<Integer> g = f.exceptionally |
814 |
|
((Throwable t) -> { |
815 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
816 |
|
threadAssertSame(t, ex1); |
817 |
|
a.getAndIncrement(); |
818 |
|
throw ex2; |
838 |
|
final CompletableFuture<Integer> g = m.handle |
839 |
|
(f, |
840 |
|
(Integer x, Throwable t) -> { |
841 |
+ |
m.checkExecutionMode(); |
842 |
|
threadAssertSame(x, v1); |
843 |
|
threadAssertNull(t); |
844 |
|
a.getAndIncrement(); |
867 |
|
final CompletableFuture<Integer> g = m.handle |
868 |
|
(f, |
869 |
|
(Integer x, Throwable t) -> { |
870 |
+ |
m.checkExecutionMode(); |
871 |
|
threadAssertNull(x); |
872 |
|
threadAssertSame(t, ex); |
873 |
|
a.getAndIncrement(); |
896 |
|
final CompletableFuture<Integer> g = m.handle |
897 |
|
(f, |
898 |
|
(Integer x, Throwable t) -> { |
899 |
+ |
m.checkExecutionMode(); |
900 |
|
threadAssertNull(x); |
901 |
|
threadAssertTrue(t instanceof CancellationException); |
902 |
|
a.getAndIncrement(); |
924 |
|
final CompletableFuture<Integer> g = m.handle |
925 |
|
(f, |
926 |
|
(Integer x, Throwable t) -> { |
927 |
+ |
m.checkExecutionMode(); |
928 |
|
threadAssertNull(x); |
929 |
|
threadAssertSame(ex1, t); |
930 |
|
a.getAndIncrement(); |
949 |
|
final CompletableFuture<Integer> g = m.handle |
950 |
|
(f, |
951 |
|
(Integer x, Throwable t) -> { |
952 |
+ |
m.checkExecutionMode(); |
953 |
|
threadAssertSame(x, v1); |
954 |
|
threadAssertNull(t); |
955 |
|
a.getAndIncrement(); |
965 |
|
/** |
966 |
|
* runAsync completes after running Runnable |
967 |
|
*/ |
968 |
< |
public void testRunAsync() { |
969 |
< |
Noop r = new Noop(ExecutionMode.ASYNC); |
970 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
968 |
> |
public void testRunAsync_normalCompletion() { |
969 |
> |
ExecutionMode[] executionModes = { |
970 |
> |
ExecutionMode.ASYNC, |
971 |
> |
ExecutionMode.EXECUTOR, |
972 |
> |
}; |
973 |
> |
for (ExecutionMode m : executionModes) |
974 |
> |
{ |
975 |
> |
final Noop r = new Noop(m); |
976 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
977 |
|
assertNull(f.join()); |
918 |
– |
assertEquals(1, r.invocationCount); |
978 |
|
checkCompletedNormally(f, null); |
920 |
– |
} |
921 |
– |
|
922 |
– |
/** |
923 |
– |
* runAsync with executor completes after running Runnable |
924 |
– |
*/ |
925 |
– |
public void testRunAsync2() { |
926 |
– |
Noop r = new Noop(ExecutionMode.EXECUTOR); |
927 |
– |
ThreadExecutor exec = new ThreadExecutor(); |
928 |
– |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
929 |
– |
assertNull(f.join()); |
979 |
|
assertEquals(1, r.invocationCount); |
980 |
< |
checkCompletedNormally(f, null); |
932 |
< |
assertEquals(1, exec.count.get()); |
933 |
< |
} |
980 |
> |
}} |
981 |
|
|
982 |
|
/** |
983 |
|
* failing runAsync completes exceptionally after running Runnable |
984 |
|
*/ |
985 |
< |
public void testRunAsync3() { |
986 |
< |
FailingRunnable r = new FailingRunnable(); |
987 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
985 |
> |
public void testRunAsync_exceptionalCompletion() { |
986 |
> |
ExecutionMode[] executionModes = { |
987 |
> |
ExecutionMode.ASYNC, |
988 |
> |
ExecutionMode.EXECUTOR, |
989 |
> |
}; |
990 |
> |
for (ExecutionMode m : executionModes) |
991 |
> |
{ |
992 |
> |
final FailingRunnable r = new FailingRunnable(m); |
993 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
994 |
|
checkCompletedWithWrappedCFException(f); |
995 |
|
assertEquals(1, r.invocationCount); |
996 |
< |
} |
996 |
> |
}} |
997 |
|
|
998 |
|
/** |
999 |
|
* supplyAsync completes with result of supplier |
1019 |
|
* Failing supplyAsync completes exceptionally |
1020 |
|
*/ |
1021 |
|
public void testSupplyAsync3() { |
1022 |
< |
FailingSupplier r = new FailingSupplier(); |
1022 |
> |
FailingSupplier r = new FailingSupplier(ExecutionMode.ASYNC); |
1023 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r); |
1024 |
|
checkCompletedWithWrappedCFException(f); |
1025 |
|
assertEquals(1, r.invocationCount); |
1083 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1084 |
|
final Noop r = new Noop(m); |
1085 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1086 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1086 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1087 |
|
if (createIncomplete) { |
1088 |
|
checkIncomplete(g); |
1089 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1103 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1104 |
|
{ |
1105 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1106 |
< |
final FailingRunnable r = new FailingRunnable(); |
1106 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1107 |
|
if (!createIncomplete) f.complete(v1); |
1108 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1108 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1109 |
|
if (createIncomplete) { |
1110 |
|
checkIncomplete(g); |
1111 |
|
f.complete(v1); |
1124 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1125 |
|
{ |
1126 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1127 |
< |
final IncFunction r = new IncFunction(); |
1127 |
> |
final IncFunction r = new IncFunction(m); |
1128 |
|
if (!createIncomplete) f.complete(v1); |
1129 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1130 |
|
if (createIncomplete) { |
1147 |
|
{ |
1148 |
|
final CFException ex = new CFException(); |
1149 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1150 |
< |
final IncFunction r = new IncFunction(); |
1150 |
> |
final IncFunction r = new IncFunction(m); |
1151 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1152 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1153 |
|
if (createIncomplete) { |
1169 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1170 |
|
{ |
1171 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1172 |
< |
final IncFunction r = new IncFunction(); |
1172 |
> |
final IncFunction r = new IncFunction(m); |
1173 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1174 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1174 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1175 |
|
if (createIncomplete) { |
1176 |
|
checkIncomplete(g); |
1177 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1191 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1192 |
|
{ |
1193 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1194 |
< |
final FailingFunction r = new FailingFunction(); |
1194 |
> |
final FailingFunction r = new FailingFunction(m); |
1195 |
|
if (!createIncomplete) f.complete(v1); |
1196 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1196 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1197 |
|
if (createIncomplete) { |
1198 |
|
checkIncomplete(g); |
1199 |
|
f.complete(v1); |
1258 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1259 |
|
{ |
1260 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1261 |
< |
final FailingConsumer r = new FailingConsumer(); |
1261 |
> |
final FailingConsumer r = new FailingConsumer(m); |
1262 |
|
if (!createIncomplete) f.complete(v1); |
1263 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1263 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1264 |
|
if (createIncomplete) { |
1265 |
|
checkIncomplete(g); |
1266 |
|
f.complete(v1); |
1281 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1282 |
|
final IncAction r = new IncAction(); |
1283 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1284 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1284 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1285 |
|
if (createIncomplete) { |
1286 |
|
checkIncomplete(g); |
1287 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1305 |
|
{ |
1306 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1307 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1308 |
< |
final SubtractFunction r = new SubtractFunction(); |
1308 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1309 |
|
|
1310 |
|
if (fFirst) f.complete(v1); else g.complete(v2); |
1311 |
|
if (!createIncomplete) |
1336 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1337 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1338 |
|
final CFException ex = new CFException(); |
1339 |
< |
final SubtractFunction r = new SubtractFunction(); |
1339 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1340 |
|
|
1341 |
|
(fFirst ? f : g).complete(v1); |
1342 |
|
if (!createIncomplete) |
1364 |
|
{ |
1365 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1366 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1367 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1367 |
> |
final FailingBiFunction r = new FailingBiFunction(m); |
1368 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1369 |
|
|
1370 |
|
if (fFirst) { |
1392 |
|
{ |
1393 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1394 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1395 |
< |
final SubtractFunction r = new SubtractFunction(); |
1395 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1396 |
|
|
1397 |
|
(fFirst ? f : g).complete(v1); |
1398 |
|
if (!createIncomplete) |
1422 |
|
{ |
1423 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1424 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1425 |
< |
final SubtractAction r = new SubtractAction(); |
1425 |
> |
final SubtractAction r = new SubtractAction(m); |
1426 |
|
|
1427 |
|
if (fFirst) f.complete(v1); else g.complete(v2); |
1428 |
|
if (!createIncomplete) |
1453 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1454 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1455 |
|
final CFException ex = new CFException(); |
1456 |
< |
final SubtractAction r = new SubtractAction(); |
1456 |
> |
final SubtractAction r = new SubtractAction(m); |
1457 |
|
|
1458 |
|
(fFirst ? f : g).complete(v1); |
1459 |
|
if (!createIncomplete) |
1481 |
|
{ |
1482 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1483 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1484 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1484 |
> |
final FailingBiConsumer r = new FailingBiConsumer(m); |
1485 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1486 |
|
|
1487 |
|
if (fFirst) { |
1509 |
|
{ |
1510 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1511 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1512 |
< |
final SubtractAction r = new SubtractAction(); |
1512 |
> |
final SubtractAction r = new SubtractAction(m); |
1513 |
|
|
1514 |
|
(fFirst ? f : g).complete(v1); |
1515 |
|
if (!createIncomplete) |
1598 |
|
{ |
1599 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1600 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1601 |
< |
final FailingRunnable r = new FailingRunnable(); |
1601 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1602 |
|
|
1603 |
|
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1604 |
|
if (fFirst) { |
1659 |
|
{ |
1660 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1661 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1662 |
< |
final IncFunction r = new IncFunction(); |
1662 |
> |
final IncFunction r = new IncFunction(m); |
1663 |
|
|
1664 |
|
if (!createIncomplete) |
1665 |
|
if (fFirst) f.complete(v1); else g.complete(v2); |
1685 |
|
{ |
1686 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1687 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1688 |
< |
final IncFunction r = new IncFunction(); |
1688 |
> |
final IncFunction r = new IncFunction(m); |
1689 |
|
|
1690 |
|
if (fFirst) { |
1691 |
|
f.complete(v1); |
1719 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1720 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1721 |
|
final CFException ex = new CFException(); |
1722 |
< |
final IncFunction r = new IncFunction(); |
1722 |
> |
final IncFunction r = new IncFunction(m); |
1723 |
|
|
1724 |
|
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1725 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1746 |
|
{ |
1747 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1748 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1749 |
< |
final IncFunction r1 = new IncFunction(); |
1750 |
< |
final IncFunction r2 = new IncFunction(); |
1749 |
> |
final IncFunction r1 = new IncFunction(m); |
1750 |
> |
final IncFunction r2 = new IncFunction(m); |
1751 |
|
final CFException ex = new CFException(); |
1752 |
|
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1753 |
|
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1792 |
|
{ |
1793 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1794 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1795 |
< |
final FailingFunction r = new FailingFunction(); |
1795 |
> |
final FailingFunction r = new FailingFunction(m); |
1796 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1797 |
|
|
1798 |
|
f.complete(v1); |
1809 |
|
{ |
1810 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1811 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1812 |
< |
final FailingFunction r = new FailingFunction(); |
1812 |
> |
final FailingFunction r = new FailingFunction(m); |
1813 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1814 |
|
|
1815 |
|
g.complete(v2); |
1831 |
|
{ |
1832 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1833 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1834 |
< |
final IncFunction r = new IncFunction(); |
1834 |
> |
final IncFunction r = new IncFunction(m); |
1835 |
|
|
1836 |
|
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1837 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1859 |
|
{ |
1860 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1861 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1862 |
< |
final IncFunction r1 = new IncFunction(); |
1863 |
< |
final IncFunction r2 = new IncFunction(); |
1862 |
> |
final IncFunction r1 = new IncFunction(m); |
1863 |
> |
final IncFunction r2 = new IncFunction(m); |
1864 |
|
final CFException ex = new CFException(); |
1865 |
|
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1866 |
|
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
2072 |
|
{ |
2073 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2074 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2075 |
< |
final FailingConsumer r = new FailingConsumer(); |
2075 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2076 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2077 |
|
|
2078 |
|
f.complete(v1); |
2089 |
|
{ |
2090 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2091 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2092 |
< |
final FailingConsumer r = new FailingConsumer(); |
2092 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2093 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2094 |
|
|
2095 |
|
g.complete(v2); |
2371 |
|
{ |
2372 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2373 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2374 |
< |
final FailingRunnable r = new FailingRunnable(); |
2374 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2375 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2376 |
|
|
2377 |
|
f.complete(v1); |
2388 |
|
{ |
2389 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2390 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2391 |
< |
final FailingRunnable r = new FailingRunnable(); |
2391 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2392 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2393 |
|
|
2394 |
|
g.complete(v2); |
2504 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2505 |
|
{ |
2506 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2507 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2507 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2508 |
|
if (!createIncomplete) f.complete(v1); |
2509 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2509 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2510 |
|
if (createIncomplete) f.complete(v1); |
2511 |
|
|
2512 |
|
checkCompletedNormally(g, inc(v1)); |
2523 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2524 |
|
{ |
2525 |
|
final CFException ex = new CFException(); |
2526 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2526 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2527 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2528 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
2529 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2529 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2530 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2531 |
|
|
2532 |
|
checkCompletedWithWrappedCFException(g, ex); |
2544 |
|
{ |
2545 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2546 |
|
final FailingCompletableFutureFunction r |
2547 |
< |
= new FailingCompletableFutureFunction(); |
2547 |
> |
= new FailingCompletableFutureFunction(m); |
2548 |
|
if (!createIncomplete) f.complete(v1); |
2549 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2549 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2550 |
|
if (createIncomplete) f.complete(v1); |
2551 |
|
|
2552 |
|
checkCompletedWithWrappedCFException(g); |
2562 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2563 |
|
{ |
2564 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2565 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2565 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2566 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2567 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2567 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2568 |
|
if (createIncomplete) { |
2569 |
|
checkIncomplete(g); |
2570 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2736 |
|
|
2737 |
|
() -> f.thenCompose(null), |
2738 |
|
() -> f.thenComposeAsync(null), |
2739 |
< |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
2739 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null), |
2740 |
|
() -> f.thenComposeAsync(null, exec), |
2741 |
|
|
2742 |
|
() -> f.exceptionally(null), |