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); |
334 |
|
return (x == null) ? null : x + 1; |
335 |
|
} |
336 |
|
|
337 |
< |
static final Supplier<Integer> supplyOne = |
338 |
< |
() -> Integer.valueOf(1); |
339 |
< |
static final Function<Integer, Integer> inc = |
340 |
< |
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
341 |
< |
static final BiFunction<Integer, Integer, Integer> subtract = |
342 |
< |
(Integer x, Integer y) -> subtract(x, y); |
337 |
> |
static final class IntegerSupplier implements Supplier<Integer> { |
338 |
> |
final ExecutionMode m; |
339 |
> |
int invocationCount = 0; |
340 |
> |
final Integer value; |
341 |
> |
IntegerSupplier(ExecutionMode m, Integer value) { |
342 |
> |
this.m = m; |
343 |
> |
this.value = value; |
344 |
> |
} |
345 |
> |
public Integer get() { |
346 |
> |
m.checkExecutionMode(); |
347 |
> |
invocationCount++; |
348 |
> |
return value; |
349 |
> |
} |
350 |
> |
} |
351 |
> |
|
352 |
|
static final class IncAction implements Consumer<Integer> { |
353 |
|
int invocationCount = 0; |
354 |
|
Integer value; |
358 |
|
} |
359 |
|
} |
360 |
|
static final class IncFunction implements Function<Integer,Integer> { |
361 |
+ |
final ExecutionMode m; |
362 |
|
int invocationCount = 0; |
363 |
|
Integer value; |
364 |
+ |
IncFunction(ExecutionMode m) { this.m = m; } |
365 |
|
public Integer apply(Integer x) { |
366 |
+ |
m.checkExecutionMode(); |
367 |
|
invocationCount++; |
368 |
|
return value = inc(x); |
369 |
|
} |
370 |
|
} |
371 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
372 |
+ |
final ExecutionMode m; |
373 |
|
int invocationCount = 0; |
374 |
|
Integer value; |
375 |
|
// Check this action was invoked exactly once when result is computed. |
376 |
+ |
SubtractAction(ExecutionMode m) { this.m = m; } |
377 |
|
public void accept(Integer x, Integer y) { |
378 |
+ |
m.checkExecutionMode(); |
379 |
|
invocationCount++; |
380 |
|
value = subtract(x, y); |
381 |
|
} |
382 |
|
} |
383 |
|
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
384 |
+ |
final ExecutionMode m; |
385 |
|
int invocationCount = 0; |
386 |
|
Integer value; |
387 |
|
// Check this action was invoked exactly once when result is computed. |
388 |
+ |
SubtractFunction(ExecutionMode m) { this.m = m; } |
389 |
|
public Integer apply(Integer x, Integer y) { |
390 |
+ |
m.checkExecutionMode(); |
391 |
|
invocationCount++; |
392 |
|
return value = subtract(x, y); |
393 |
|
} |
394 |
|
} |
395 |
|
static final class Noop implements Runnable { |
396 |
+ |
final ExecutionMode m; |
397 |
|
int invocationCount = 0; |
398 |
+ |
Noop(ExecutionMode m) { this.m = m; } |
399 |
|
public void run() { |
400 |
+ |
m.checkExecutionMode(); |
401 |
|
invocationCount++; |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
static final class FailingSupplier implements Supplier<Integer> { |
406 |
+ |
final ExecutionMode m; |
407 |
|
int invocationCount = 0; |
408 |
+ |
FailingSupplier(ExecutionMode m) { this.m = m; } |
409 |
|
public Integer get() { |
410 |
+ |
m.checkExecutionMode(); |
411 |
|
invocationCount++; |
412 |
|
throw new CFException(); |
413 |
|
} |
414 |
|
} |
415 |
|
static final class FailingConsumer implements Consumer<Integer> { |
416 |
+ |
final ExecutionMode m; |
417 |
|
int invocationCount = 0; |
418 |
+ |
FailingConsumer(ExecutionMode m) { this.m = m; } |
419 |
|
public void accept(Integer x) { |
420 |
+ |
m.checkExecutionMode(); |
421 |
|
invocationCount++; |
422 |
|
throw new CFException(); |
423 |
|
} |
424 |
|
} |
425 |
|
static final class FailingBiConsumer implements BiConsumer<Integer, Integer> { |
426 |
+ |
final ExecutionMode m; |
427 |
|
int invocationCount = 0; |
428 |
+ |
FailingBiConsumer(ExecutionMode m) { this.m = m; } |
429 |
|
public void accept(Integer x, Integer y) { |
430 |
+ |
m.checkExecutionMode(); |
431 |
|
invocationCount++; |
432 |
|
throw new CFException(); |
433 |
|
} |
434 |
|
} |
435 |
|
static final class FailingFunction implements Function<Integer, Integer> { |
436 |
+ |
final ExecutionMode m; |
437 |
|
int invocationCount = 0; |
438 |
+ |
FailingFunction(ExecutionMode m) { this.m = m; } |
439 |
|
public Integer apply(Integer x) { |
440 |
+ |
m.checkExecutionMode(); |
441 |
|
invocationCount++; |
442 |
|
throw new CFException(); |
443 |
|
} |
444 |
|
} |
445 |
|
static final class FailingBiFunction implements BiFunction<Integer, Integer, Integer> { |
446 |
+ |
final ExecutionMode m; |
447 |
|
int invocationCount = 0; |
448 |
+ |
FailingBiFunction(ExecutionMode m) { this.m = m; } |
449 |
|
public Integer apply(Integer x, Integer y) { |
450 |
+ |
m.checkExecutionMode(); |
451 |
|
invocationCount++; |
452 |
|
throw new CFException(); |
453 |
|
} |
454 |
|
} |
455 |
|
static final class FailingRunnable implements Runnable { |
456 |
+ |
final ExecutionMode m; |
457 |
|
int invocationCount = 0; |
458 |
+ |
FailingRunnable(ExecutionMode m) { this.m = m; } |
459 |
|
public void run() { |
460 |
+ |
m.checkExecutionMode(); |
461 |
|
invocationCount++; |
462 |
|
throw new CFException(); |
463 |
|
} |
465 |
|
|
466 |
|
static final class CompletableFutureInc |
467 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
468 |
+ |
final ExecutionMode m; |
469 |
|
int invocationCount = 0; |
470 |
+ |
CompletableFutureInc(ExecutionMode m) { this.m = m; } |
471 |
|
public CompletableFuture<Integer> apply(Integer x) { |
472 |
+ |
m.checkExecutionMode(); |
473 |
|
invocationCount++; |
474 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
475 |
|
f.complete(inc(x)); |
479 |
|
|
480 |
|
static final class FailingCompletableFutureFunction |
481 |
|
implements Function<Integer, CompletableFuture<Integer>> { |
482 |
+ |
final ExecutionMode m; |
483 |
|
int invocationCount = 0; |
484 |
+ |
FailingCompletableFutureFunction(ExecutionMode m) { this.m = m; } |
485 |
|
public CompletableFuture<Integer> apply(Integer x) { |
486 |
+ |
m.checkExecutionMode(); |
487 |
|
invocationCount++; |
488 |
|
throw new CFException(); |
489 |
|
} |
491 |
|
|
492 |
|
// Used for explicit executor tests |
493 |
|
static final class ThreadExecutor implements Executor { |
494 |
< |
AtomicInteger count = new AtomicInteger(0); |
494 |
> |
final AtomicInteger count = new AtomicInteger(0); |
495 |
> |
static final ThreadGroup tg = new ThreadGroup("ThreadExecutor"); |
496 |
> |
static boolean startedCurrentThread() { |
497 |
> |
return Thread.currentThread().getThreadGroup() == tg; |
498 |
> |
} |
499 |
|
|
500 |
|
public void execute(Runnable r) { |
501 |
|
count.getAndIncrement(); |
502 |
< |
new Thread(r).start(); |
502 |
> |
new Thread(tg, r).start(); |
503 |
|
} |
504 |
|
} |
505 |
|
|
512 |
|
public void checkExecutionMode() { |
513 |
|
assertNull(ForkJoinTask.getPool()); |
514 |
|
} |
515 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
516 |
+ |
throw new UnsupportedOperationException(); |
517 |
+ |
} |
518 |
+ |
public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) { |
519 |
+ |
throw new UnsupportedOperationException(); |
520 |
+ |
} |
521 |
|
public <T> CompletableFuture<Void> thenRun |
522 |
|
(CompletableFuture<T> f, Runnable a) { |
523 |
|
return f.thenRun(a); |
586 |
|
assertSame(ForkJoinPool.commonPool(), |
587 |
|
ForkJoinTask.getPool()); |
588 |
|
} |
589 |
+ |
public CompletableFuture<Void> runAsync(Runnable a) { |
590 |
+ |
return CompletableFuture.runAsync(a); |
591 |
+ |
} |
592 |
+ |
public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) { |
593 |
+ |
return CompletableFuture.supplyAsync(a); |
594 |
+ |
} |
595 |
|
public <T> CompletableFuture<Void> thenRun |
596 |
|
(CompletableFuture<T> f, Runnable a) { |
597 |
|
return f.thenRunAsync(a); |
657 |
|
|
658 |
|
EXECUTOR { |
659 |
|
public void checkExecutionMode() { |
660 |
< |
//TODO |
660 |
> |
assertTrue(ThreadExecutor.startedCurrentThread()); |
661 |
> |
} |
662 |
> |
public CompletableFuture<Void> runAsync(Runnable a) { |
663 |
> |
return CompletableFuture.runAsync(a, new ThreadExecutor()); |
664 |
> |
} |
665 |
> |
public <U> CompletableFuture<U> supplyAsync(Supplier<U> a) { |
666 |
> |
return CompletableFuture.supplyAsync(a, new ThreadExecutor()); |
667 |
|
} |
668 |
|
public <T> CompletableFuture<Void> thenRun |
669 |
|
(CompletableFuture<T> f, Runnable a) { |
729 |
|
}; |
730 |
|
|
731 |
|
public abstract void checkExecutionMode(); |
732 |
+ |
public abstract CompletableFuture<Void> runAsync(Runnable a); |
733 |
+ |
public abstract <U> CompletableFuture<U> supplyAsync(Supplier<U> a); |
734 |
|
public abstract <T> CompletableFuture<Void> thenRun |
735 |
|
(CompletableFuture<T> f, Runnable a); |
736 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
809 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
810 |
|
final CompletableFuture<Integer> g = f.exceptionally |
811 |
|
((Throwable t) -> { |
812 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
813 |
|
threadAssertSame(t, ex); |
814 |
|
a.getAndIncrement(); |
815 |
|
return v1; |
831 |
|
if (!createIncomplete) f.completeExceptionally(ex1); |
832 |
|
final CompletableFuture<Integer> g = f.exceptionally |
833 |
|
((Throwable t) -> { |
834 |
+ |
ExecutionMode.DEFAULT.checkExecutionMode(); |
835 |
|
threadAssertSame(t, ex1); |
836 |
|
a.getAndIncrement(); |
837 |
|
throw ex2; |
857 |
|
final CompletableFuture<Integer> g = m.handle |
858 |
|
(f, |
859 |
|
(Integer x, Throwable t) -> { |
860 |
+ |
m.checkExecutionMode(); |
861 |
|
threadAssertSame(x, v1); |
862 |
|
threadAssertNull(t); |
863 |
|
a.getAndIncrement(); |
886 |
|
final CompletableFuture<Integer> g = m.handle |
887 |
|
(f, |
888 |
|
(Integer x, Throwable t) -> { |
889 |
+ |
m.checkExecutionMode(); |
890 |
|
threadAssertNull(x); |
891 |
|
threadAssertSame(t, ex); |
892 |
|
a.getAndIncrement(); |
915 |
|
final CompletableFuture<Integer> g = m.handle |
916 |
|
(f, |
917 |
|
(Integer x, Throwable t) -> { |
918 |
+ |
m.checkExecutionMode(); |
919 |
|
threadAssertNull(x); |
920 |
|
threadAssertTrue(t instanceof CancellationException); |
921 |
|
a.getAndIncrement(); |
943 |
|
final CompletableFuture<Integer> g = m.handle |
944 |
|
(f, |
945 |
|
(Integer x, Throwable t) -> { |
946 |
+ |
m.checkExecutionMode(); |
947 |
|
threadAssertNull(x); |
948 |
|
threadAssertSame(ex1, t); |
949 |
|
a.getAndIncrement(); |
968 |
|
final CompletableFuture<Integer> g = m.handle |
969 |
|
(f, |
970 |
|
(Integer x, Throwable t) -> { |
971 |
+ |
m.checkExecutionMode(); |
972 |
|
threadAssertSame(x, v1); |
973 |
|
threadAssertNull(t); |
974 |
|
a.getAndIncrement(); |
984 |
|
/** |
985 |
|
* runAsync completes after running Runnable |
986 |
|
*/ |
987 |
< |
public void testRunAsync() { |
988 |
< |
Noop r = new Noop(); |
989 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
987 |
> |
public void testRunAsync_normalCompletion() { |
988 |
> |
ExecutionMode[] executionModes = { |
989 |
> |
ExecutionMode.ASYNC, |
990 |
> |
ExecutionMode.EXECUTOR, |
991 |
> |
}; |
992 |
> |
for (ExecutionMode m : executionModes) |
993 |
> |
{ |
994 |
> |
final Noop r = new Noop(m); |
995 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
996 |
|
assertNull(f.join()); |
915 |
– |
assertEquals(1, r.invocationCount); |
997 |
|
checkCompletedNormally(f, null); |
917 |
– |
} |
918 |
– |
|
919 |
– |
/** |
920 |
– |
* runAsync with executor completes after running Runnable |
921 |
– |
*/ |
922 |
– |
public void testRunAsync2() { |
923 |
– |
Noop r = new Noop(); |
924 |
– |
ThreadExecutor exec = new ThreadExecutor(); |
925 |
– |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
926 |
– |
assertNull(f.join()); |
998 |
|
assertEquals(1, r.invocationCount); |
999 |
< |
checkCompletedNormally(f, null); |
929 |
< |
assertEquals(1, exec.count.get()); |
930 |
< |
} |
999 |
> |
}} |
1000 |
|
|
1001 |
|
/** |
1002 |
|
* failing runAsync completes exceptionally after running Runnable |
1003 |
|
*/ |
1004 |
< |
public void testRunAsync3() { |
1005 |
< |
FailingRunnable r = new FailingRunnable(); |
1006 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r); |
1004 |
> |
public void testRunAsync_exceptionalCompletion() { |
1005 |
> |
ExecutionMode[] executionModes = { |
1006 |
> |
ExecutionMode.ASYNC, |
1007 |
> |
ExecutionMode.EXECUTOR, |
1008 |
> |
}; |
1009 |
> |
for (ExecutionMode m : executionModes) |
1010 |
> |
{ |
1011 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1012 |
> |
final CompletableFuture<Void> f = m.runAsync(r); |
1013 |
|
checkCompletedWithWrappedCFException(f); |
1014 |
|
assertEquals(1, r.invocationCount); |
1015 |
< |
} |
1015 |
> |
}} |
1016 |
|
|
1017 |
|
/** |
1018 |
|
* supplyAsync completes with result of supplier |
1019 |
|
*/ |
1020 |
< |
public void testSupplyAsync() { |
1021 |
< |
CompletableFuture<Integer> f; |
1022 |
< |
f = CompletableFuture.supplyAsync(supplyOne); |
1023 |
< |
assertEquals(f.join(), one); |
1024 |
< |
checkCompletedNormally(f, one); |
1025 |
< |
} |
1026 |
< |
|
1027 |
< |
/** |
1028 |
< |
* supplyAsync with executor completes with result of supplier |
1029 |
< |
*/ |
1030 |
< |
public void testSupplyAsync2() { |
1031 |
< |
CompletableFuture<Integer> f; |
1032 |
< |
f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); |
1033 |
< |
assertEquals(f.join(), one); |
959 |
< |
checkCompletedNormally(f, one); |
960 |
< |
} |
1020 |
> |
public void testSupplyAsync_normalCompletion() { |
1021 |
> |
ExecutionMode[] executionModes = { |
1022 |
> |
ExecutionMode.ASYNC, |
1023 |
> |
ExecutionMode.EXECUTOR, |
1024 |
> |
}; |
1025 |
> |
for (ExecutionMode m : executionModes) |
1026 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1027 |
> |
{ |
1028 |
> |
final IntegerSupplier r = new IntegerSupplier(m, v1); |
1029 |
> |
final CompletableFuture<Integer> f = m.supplyAsync(r); |
1030 |
> |
assertSame(v1, f.join()); |
1031 |
> |
checkCompletedNormally(f, v1); |
1032 |
> |
assertEquals(1, r.invocationCount); |
1033 |
> |
}} |
1034 |
|
|
1035 |
|
/** |
1036 |
|
* Failing supplyAsync completes exceptionally |
1037 |
|
*/ |
1038 |
< |
public void testSupplyAsync3() { |
1039 |
< |
FailingSupplier r = new FailingSupplier(); |
1040 |
< |
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(r); |
1038 |
> |
public void testSupplyAsync_exceptionalCompletion() { |
1039 |
> |
ExecutionMode[] executionModes = { |
1040 |
> |
ExecutionMode.ASYNC, |
1041 |
> |
ExecutionMode.EXECUTOR, |
1042 |
> |
}; |
1043 |
> |
for (ExecutionMode m : executionModes) |
1044 |
> |
{ |
1045 |
> |
FailingSupplier r = new FailingSupplier(m); |
1046 |
> |
CompletableFuture<Integer> f = m.supplyAsync(r); |
1047 |
|
checkCompletedWithWrappedCFException(f); |
1048 |
|
assertEquals(1, r.invocationCount); |
1049 |
< |
} |
1049 |
> |
}} |
1050 |
|
|
1051 |
|
// seq completion methods |
1052 |
|
|
1059 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1060 |
|
{ |
1061 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1062 |
< |
final Noop r = new Noop(); |
1062 |
> |
final Noop r = new Noop(m); |
1063 |
|
if (!createIncomplete) f.complete(v1); |
1064 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1065 |
|
if (createIncomplete) { |
1082 |
|
{ |
1083 |
|
final CFException ex = new CFException(); |
1084 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1085 |
< |
final Noop r = new Noop(); |
1085 |
> |
final Noop r = new Noop(m); |
1086 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1087 |
|
final CompletableFuture<Void> g = m.thenRun(f, r); |
1088 |
|
if (createIncomplete) { |
1104 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1105 |
|
{ |
1106 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1107 |
< |
final Noop r = new Noop(); |
1107 |
> |
final Noop r = new Noop(m); |
1108 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1109 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1109 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1110 |
|
if (createIncomplete) { |
1111 |
|
checkIncomplete(g); |
1112 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1126 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1127 |
|
{ |
1128 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1129 |
< |
final FailingRunnable r = new FailingRunnable(); |
1129 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1130 |
|
if (!createIncomplete) f.complete(v1); |
1131 |
< |
final CompletableFuture<Void> g = f.thenRun(r); |
1131 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1132 |
|
if (createIncomplete) { |
1133 |
|
checkIncomplete(g); |
1134 |
|
f.complete(v1); |
1147 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1148 |
|
{ |
1149 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1150 |
< |
final IncFunction r = new IncFunction(); |
1150 |
> |
final IncFunction r = new IncFunction(m); |
1151 |
|
if (!createIncomplete) f.complete(v1); |
1152 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1153 |
|
if (createIncomplete) { |
1170 |
|
{ |
1171 |
|
final CFException ex = new CFException(); |
1172 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1173 |
< |
final IncFunction r = new IncFunction(); |
1173 |
> |
final IncFunction r = new IncFunction(m); |
1174 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
1175 |
|
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1176 |
|
if (createIncomplete) { |
1192 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1193 |
|
{ |
1194 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1195 |
< |
final IncFunction r = new IncFunction(); |
1195 |
> |
final IncFunction r = new IncFunction(m); |
1196 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1197 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1197 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1198 |
|
if (createIncomplete) { |
1199 |
|
checkIncomplete(g); |
1200 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1214 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1215 |
|
{ |
1216 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1217 |
< |
final FailingFunction r = new FailingFunction(); |
1217 |
> |
final FailingFunction r = new FailingFunction(m); |
1218 |
|
if (!createIncomplete) f.complete(v1); |
1219 |
< |
final CompletableFuture<Integer> g = f.thenApply(r); |
1219 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1220 |
|
if (createIncomplete) { |
1221 |
|
checkIncomplete(g); |
1222 |
|
f.complete(v1); |
1281 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1282 |
|
{ |
1283 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1284 |
< |
final FailingConsumer r = new FailingConsumer(); |
1284 |
> |
final FailingConsumer r = new FailingConsumer(m); |
1285 |
|
if (!createIncomplete) f.complete(v1); |
1286 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1286 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1287 |
|
if (createIncomplete) { |
1288 |
|
checkIncomplete(g); |
1289 |
|
f.complete(v1); |
1304 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1305 |
|
final IncAction r = new IncAction(); |
1306 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1307 |
< |
final CompletableFuture<Void> g = f.thenAccept(r); |
1307 |
> |
final CompletableFuture<Void> g = m.thenAccept(f, r); |
1308 |
|
if (createIncomplete) { |
1309 |
|
checkIncomplete(g); |
1310 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
1328 |
|
{ |
1329 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1330 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1331 |
< |
final SubtractFunction r = new SubtractFunction(); |
1331 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1332 |
|
|
1333 |
|
if (fFirst) f.complete(v1); else g.complete(v2); |
1334 |
|
if (!createIncomplete) |
1350 |
|
* thenCombine result completes exceptionally after exceptional |
1351 |
|
* completion of either source |
1352 |
|
*/ |
1353 |
< |
public void testThenCombine_exceptionalCompletion1() { |
1275 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1276 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1277 |
< |
{ |
1278 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1279 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1280 |
< |
final SubtractFunction r = new SubtractFunction(); |
1281 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1282 |
< |
final CFException ex = new CFException(); |
1283 |
< |
|
1284 |
< |
f.completeExceptionally(ex); |
1285 |
< |
checkIncomplete(h); |
1286 |
< |
g.complete(v1); |
1287 |
< |
|
1288 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1289 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1290 |
< |
assertEquals(0, r.invocationCount); |
1291 |
< |
checkCompletedNormally(g, v1); |
1292 |
< |
}} |
1293 |
< |
|
1294 |
< |
public void testThenCombine_exceptionalCompletion2() { |
1295 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1296 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1297 |
< |
{ |
1298 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1299 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1300 |
< |
final SubtractFunction r = new SubtractFunction(); |
1301 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1302 |
< |
final CFException ex = new CFException(); |
1303 |
< |
|
1304 |
< |
g.completeExceptionally(ex); |
1305 |
< |
checkIncomplete(h); |
1306 |
< |
f.complete(v1); |
1307 |
< |
|
1308 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1309 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1310 |
< |
assertEquals(0, r.invocationCount); |
1311 |
< |
checkCompletedNormally(f, v1); |
1312 |
< |
}} |
1313 |
< |
|
1314 |
< |
public void testThenCombine_exceptionalCompletion3() { |
1315 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1317 |
< |
{ |
1318 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1319 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1320 |
< |
final SubtractFunction r = new SubtractFunction(); |
1321 |
< |
final CFException ex = new CFException(); |
1322 |
< |
|
1323 |
< |
g.completeExceptionally(ex); |
1324 |
< |
f.complete(v1); |
1325 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1326 |
< |
|
1327 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1328 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1329 |
< |
assertEquals(0, r.invocationCount); |
1330 |
< |
checkCompletedNormally(f, v1); |
1331 |
< |
}} |
1332 |
< |
|
1333 |
< |
public void testThenCombine_exceptionalCompletion4() { |
1353 |
> |
public void testThenCombine_exceptionalCompletion() { |
1354 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1355 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1356 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1357 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1358 |
|
{ |
1359 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1360 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1339 |
– |
final SubtractFunction r = new SubtractFunction(); |
1361 |
|
final CFException ex = new CFException(); |
1362 |
+ |
final SubtractFunction r = new SubtractFunction(m); |
1363 |
|
|
1364 |
< |
f.completeExceptionally(ex); |
1365 |
< |
g.complete(v1); |
1364 |
> |
(fFirst ? f : g).complete(v1); |
1365 |
> |
if (!createIncomplete) |
1366 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1367 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1368 |
+ |
if (createIncomplete) { |
1369 |
+ |
checkIncomplete(h); |
1370 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1371 |
+ |
} |
1372 |
|
|
1373 |
|
checkCompletedWithWrappedCFException(h, ex); |
1347 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1374 |
|
assertEquals(0, r.invocationCount); |
1375 |
< |
checkCompletedNormally(g, v1); |
1375 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1376 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1377 |
|
}} |
1378 |
|
|
1379 |
|
/** |
1380 |
|
* thenCombine result completes exceptionally if action does |
1381 |
|
*/ |
1382 |
< |
public void testThenCombine_actionFailed1() { |
1356 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1357 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1358 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1359 |
< |
{ |
1360 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1361 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1362 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1363 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1364 |
< |
|
1365 |
< |
f.complete(v1); |
1366 |
< |
checkIncomplete(h); |
1367 |
< |
g.complete(v2); |
1368 |
< |
|
1369 |
< |
checkCompletedWithWrappedCFException(h); |
1370 |
< |
checkCompletedNormally(f, v1); |
1371 |
< |
checkCompletedNormally(g, v2); |
1372 |
< |
}} |
1373 |
< |
|
1374 |
< |
public void testThenCombine_actionFailed2() { |
1382 |
> |
public void testThenCombine_actionFailed() { |
1383 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1384 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1385 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1386 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1387 |
|
{ |
1388 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1389 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1390 |
< |
final FailingBiFunction r = new FailingBiFunction(); |
1390 |
> |
final FailingBiFunction r = new FailingBiFunction(m); |
1391 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1392 |
|
|
1393 |
< |
g.complete(v2); |
1394 |
< |
checkIncomplete(h); |
1395 |
< |
f.complete(v1); |
1393 |
> |
if (fFirst) { |
1394 |
> |
f.complete(v1); |
1395 |
> |
g.complete(v2); |
1396 |
> |
} else { |
1397 |
> |
g.complete(v2); |
1398 |
> |
f.complete(v1); |
1399 |
> |
} |
1400 |
|
|
1401 |
|
checkCompletedWithWrappedCFException(h); |
1402 |
|
checkCompletedNormally(f, v1); |
1406 |
|
/** |
1407 |
|
* thenCombine result completes exceptionally if either source cancelled |
1408 |
|
*/ |
1409 |
< |
public void testThenCombine_sourceCancelled1() { |
1397 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1398 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1399 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1400 |
< |
{ |
1401 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1402 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1403 |
< |
final SubtractFunction r = new SubtractFunction(); |
1404 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1405 |
< |
|
1406 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1407 |
< |
checkIncomplete(h); |
1408 |
< |
g.complete(v1); |
1409 |
< |
|
1410 |
< |
checkCompletedWithWrappedCancellationException(h); |
1411 |
< |
checkCancelled(f); |
1412 |
< |
assertEquals(0, r.invocationCount); |
1413 |
< |
checkCompletedNormally(g, v1); |
1414 |
< |
}} |
1415 |
< |
|
1416 |
< |
public void testThenCombine_sourceCancelled2() { |
1417 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1418 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1419 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1420 |
< |
{ |
1421 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1422 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1423 |
< |
final SubtractFunction r = new SubtractFunction(); |
1424 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1425 |
< |
|
1426 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1427 |
< |
checkIncomplete(h); |
1428 |
< |
f.complete(v1); |
1429 |
< |
|
1430 |
< |
checkCompletedWithWrappedCancellationException(h); |
1431 |
< |
checkCancelled(g); |
1432 |
< |
assertEquals(0, r.invocationCount); |
1433 |
< |
checkCompletedNormally(f, v1); |
1434 |
< |
}} |
1435 |
< |
|
1436 |
< |
public void testThenCombine_sourceCancelled3() { |
1437 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1438 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1439 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1440 |
< |
{ |
1441 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1442 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1443 |
< |
final SubtractFunction r = new SubtractFunction(); |
1444 |
< |
|
1445 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1446 |
< |
f.complete(v1); |
1447 |
< |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1448 |
< |
|
1449 |
< |
checkCompletedWithWrappedCancellationException(h); |
1450 |
< |
checkCancelled(g); |
1451 |
< |
assertEquals(0, r.invocationCount); |
1452 |
< |
checkCompletedNormally(f, v1); |
1453 |
< |
}} |
1454 |
< |
|
1455 |
< |
public void testThenCombine_sourceCancelled4() { |
1409 |
> |
public void testThenCombine_sourceCancelled() { |
1410 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1411 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1412 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1413 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1414 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1415 |
|
{ |
1416 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1417 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1418 |
< |
final SubtractFunction r = new SubtractFunction(); |
1418 |
> |
final SubtractFunction r = new SubtractFunction(m); |
1419 |
|
|
1420 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1421 |
< |
g.complete(v1); |
1420 |
> |
(fFirst ? f : g).complete(v1); |
1421 |
> |
if (!createIncomplete) |
1422 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1423 |
|
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1424 |
+ |
if (createIncomplete) { |
1425 |
+ |
checkIncomplete(h); |
1426 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1427 |
+ |
} |
1428 |
|
|
1429 |
|
checkCompletedWithWrappedCancellationException(h); |
1430 |
< |
checkCancelled(f); |
1430 |
> |
checkCancelled(!fFirst ? f : g); |
1431 |
|
assertEquals(0, r.invocationCount); |
1432 |
< |
checkCompletedNormally(g, v1); |
1432 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1433 |
|
}} |
1434 |
|
|
1435 |
|
/** |
1436 |
|
* thenAcceptBoth result completes normally after normal |
1437 |
|
* completion of sources |
1438 |
|
*/ |
1439 |
< |
public void testThenAcceptBoth_normalCompletion1() { |
1479 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1480 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1481 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1482 |
< |
{ |
1483 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1484 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1485 |
< |
final SubtractAction r = new SubtractAction(); |
1486 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1487 |
< |
|
1488 |
< |
f.complete(v1); |
1489 |
< |
checkIncomplete(h); |
1490 |
< |
assertEquals(0, r.invocationCount); |
1491 |
< |
g.complete(v2); |
1492 |
< |
|
1493 |
< |
checkCompletedNormally(h, null); |
1494 |
< |
assertEquals(subtract(v1, v2), r.value); |
1495 |
< |
checkCompletedNormally(f, v1); |
1496 |
< |
checkCompletedNormally(g, v2); |
1497 |
< |
}} |
1498 |
< |
|
1499 |
< |
public void testThenAcceptBoth_normalCompletion2() { |
1500 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1501 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1502 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1503 |
< |
{ |
1504 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1505 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1506 |
< |
final SubtractAction r = new SubtractAction(); |
1507 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1508 |
< |
|
1509 |
< |
g.complete(v2); |
1510 |
< |
checkIncomplete(h); |
1511 |
< |
assertEquals(0, r.invocationCount); |
1512 |
< |
f.complete(v1); |
1513 |
< |
|
1514 |
< |
checkCompletedNormally(h, null); |
1515 |
< |
assertEquals(subtract(v1, v2), r.value); |
1516 |
< |
checkCompletedNormally(f, v1); |
1517 |
< |
checkCompletedNormally(g, v2); |
1518 |
< |
}} |
1519 |
< |
|
1520 |
< |
public void testThenAcceptBoth_normalCompletion3() { |
1521 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1522 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1523 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1524 |
< |
{ |
1525 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1526 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1527 |
< |
final SubtractAction r = new SubtractAction(); |
1528 |
< |
|
1529 |
< |
g.complete(v2); |
1530 |
< |
f.complete(v1); |
1531 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1532 |
< |
|
1533 |
< |
checkCompletedNormally(h, null); |
1534 |
< |
assertEquals(subtract(v1, v2), r.value); |
1535 |
< |
checkCompletedNormally(f, v1); |
1536 |
< |
checkCompletedNormally(g, v2); |
1537 |
< |
}} |
1538 |
< |
|
1539 |
< |
public void testThenAcceptBoth_normalCompletion4() { |
1439 |
> |
public void testThenAcceptBoth_normalCompletion() { |
1440 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1441 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1442 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1443 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1444 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1445 |
|
{ |
1446 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1447 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1448 |
< |
final SubtractAction r = new SubtractAction(); |
1448 |
> |
final SubtractAction r = new SubtractAction(m); |
1449 |
|
|
1450 |
< |
f.complete(v1); |
1451 |
< |
g.complete(v2); |
1450 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1451 |
> |
if (!createIncomplete) |
1452 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1453 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1454 |
+ |
if (createIncomplete) { |
1455 |
+ |
checkIncomplete(h); |
1456 |
+ |
assertEquals(0, r.invocationCount); |
1457 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1458 |
+ |
} |
1459 |
|
|
1460 |
|
checkCompletedNormally(h, null); |
1461 |
|
assertEquals(subtract(v1, v2), r.value); |
1467 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1468 |
|
* completion of either source |
1469 |
|
*/ |
1470 |
< |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1563 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1564 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1565 |
< |
{ |
1566 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1567 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1568 |
< |
final SubtractAction r = new SubtractAction(); |
1569 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1570 |
< |
final CFException ex = new CFException(); |
1571 |
< |
|
1572 |
< |
f.completeExceptionally(ex); |
1573 |
< |
checkIncomplete(h); |
1574 |
< |
g.complete(v1); |
1575 |
< |
|
1576 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1577 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1578 |
< |
assertEquals(0, r.invocationCount); |
1579 |
< |
checkCompletedNormally(g, v1); |
1580 |
< |
}} |
1581 |
< |
|
1582 |
< |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1583 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1584 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1585 |
< |
{ |
1586 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1587 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1588 |
< |
final SubtractAction r = new SubtractAction(); |
1589 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1590 |
< |
final CFException ex = new CFException(); |
1591 |
< |
|
1592 |
< |
g.completeExceptionally(ex); |
1593 |
< |
checkIncomplete(h); |
1594 |
< |
f.complete(v1); |
1595 |
< |
|
1596 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1597 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1598 |
< |
assertEquals(0, r.invocationCount); |
1599 |
< |
checkCompletedNormally(f, v1); |
1600 |
< |
}} |
1601 |
< |
|
1602 |
< |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1603 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1604 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1605 |
< |
{ |
1606 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1607 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1608 |
< |
final SubtractAction r = new SubtractAction(); |
1609 |
< |
final CFException ex = new CFException(); |
1610 |
< |
|
1611 |
< |
g.completeExceptionally(ex); |
1612 |
< |
f.complete(v1); |
1613 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1614 |
< |
|
1615 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1616 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1617 |
< |
assertEquals(0, r.invocationCount); |
1618 |
< |
checkCompletedNormally(f, v1); |
1619 |
< |
}} |
1620 |
< |
|
1621 |
< |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1470 |
> |
public void testThenAcceptBoth_exceptionalCompletion() { |
1471 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1472 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1473 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1474 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1475 |
|
{ |
1476 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1477 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1627 |
– |
final SubtractAction r = new SubtractAction(); |
1478 |
|
final CFException ex = new CFException(); |
1479 |
+ |
final SubtractAction r = new SubtractAction(m); |
1480 |
|
|
1481 |
< |
f.completeExceptionally(ex); |
1482 |
< |
g.complete(v1); |
1481 |
> |
(fFirst ? f : g).complete(v1); |
1482 |
> |
if (!createIncomplete) |
1483 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1484 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1485 |
+ |
if (createIncomplete) { |
1486 |
+ |
checkIncomplete(h); |
1487 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1488 |
+ |
} |
1489 |
|
|
1490 |
|
checkCompletedWithWrappedCFException(h, ex); |
1635 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1491 |
|
assertEquals(0, r.invocationCount); |
1492 |
< |
checkCompletedNormally(g, v1); |
1492 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1493 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1494 |
|
}} |
1495 |
|
|
1496 |
|
/** |
1497 |
|
* thenAcceptBoth result completes exceptionally if action does |
1498 |
|
*/ |
1499 |
< |
public void testThenAcceptBoth_actionFailed1() { |
1644 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1645 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1646 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1647 |
< |
{ |
1648 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1649 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1650 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1651 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1652 |
< |
|
1653 |
< |
f.complete(v1); |
1654 |
< |
checkIncomplete(h); |
1655 |
< |
g.complete(v2); |
1656 |
< |
|
1657 |
< |
checkCompletedWithWrappedCFException(h); |
1658 |
< |
checkCompletedNormally(f, v1); |
1659 |
< |
checkCompletedNormally(g, v2); |
1660 |
< |
}} |
1661 |
< |
|
1662 |
< |
public void testThenAcceptBoth_actionFailed2() { |
1499 |
> |
public void testThenAcceptBoth_actionFailed() { |
1500 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1501 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1502 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1503 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1504 |
|
{ |
1505 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1506 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1507 |
< |
final FailingBiConsumer r = new FailingBiConsumer(); |
1507 |
> |
final FailingBiConsumer r = new FailingBiConsumer(m); |
1508 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1509 |
|
|
1510 |
< |
g.complete(v2); |
1511 |
< |
checkIncomplete(h); |
1512 |
< |
f.complete(v1); |
1510 |
> |
if (fFirst) { |
1511 |
> |
f.complete(v1); |
1512 |
> |
g.complete(v2); |
1513 |
> |
} else { |
1514 |
> |
g.complete(v2); |
1515 |
> |
f.complete(v1); |
1516 |
> |
} |
1517 |
|
|
1518 |
|
checkCompletedWithWrappedCFException(h); |
1519 |
|
checkCompletedNormally(f, v1); |
1523 |
|
/** |
1524 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1525 |
|
*/ |
1526 |
< |
public void testThenAcceptBoth_sourceCancelled1() { |
1685 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1686 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1687 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1688 |
< |
{ |
1689 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1690 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1691 |
< |
final SubtractAction r = new SubtractAction(); |
1692 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1693 |
< |
|
1694 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1695 |
< |
checkIncomplete(h); |
1696 |
< |
g.complete(v1); |
1697 |
< |
|
1698 |
< |
checkCompletedWithWrappedCancellationException(h); |
1699 |
< |
checkCancelled(f); |
1700 |
< |
assertEquals(0, r.invocationCount); |
1701 |
< |
checkCompletedNormally(g, v1); |
1702 |
< |
}} |
1703 |
< |
|
1704 |
< |
public void testThenAcceptBoth_sourceCancelled2() { |
1705 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1706 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1707 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1708 |
< |
{ |
1709 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1710 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
< |
final SubtractAction r = new SubtractAction(); |
1712 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1713 |
< |
|
1714 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1715 |
< |
checkIncomplete(h); |
1716 |
< |
f.complete(v1); |
1717 |
< |
|
1718 |
< |
checkCompletedWithWrappedCancellationException(h); |
1719 |
< |
checkCancelled(g); |
1720 |
< |
assertEquals(0, r.invocationCount); |
1721 |
< |
checkCompletedNormally(f, v1); |
1722 |
< |
}} |
1723 |
< |
|
1724 |
< |
public void testThenAcceptBoth_sourceCancelled3() { |
1725 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1726 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1727 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1728 |
< |
{ |
1729 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1730 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1731 |
< |
final SubtractAction r = new SubtractAction(); |
1732 |
< |
|
1733 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1734 |
< |
f.complete(v1); |
1735 |
< |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1736 |
< |
|
1737 |
< |
checkCompletedWithWrappedCancellationException(h); |
1738 |
< |
checkCancelled(g); |
1739 |
< |
assertEquals(0, r.invocationCount); |
1740 |
< |
checkCompletedNormally(f, v1); |
1741 |
< |
}} |
1742 |
< |
|
1743 |
< |
public void testThenAcceptBoth_sourceCancelled4() { |
1526 |
> |
public void testThenAcceptBoth_sourceCancelled() { |
1527 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1528 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1529 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1530 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1531 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1532 |
|
{ |
1533 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1534 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1535 |
< |
final SubtractAction r = new SubtractAction(); |
1535 |
> |
final SubtractAction r = new SubtractAction(m); |
1536 |
|
|
1537 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1538 |
< |
g.complete(v1); |
1537 |
> |
(fFirst ? f : g).complete(v1); |
1538 |
> |
if (!createIncomplete) |
1539 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1540 |
|
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1541 |
+ |
if (createIncomplete) { |
1542 |
+ |
checkIncomplete(h); |
1543 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1544 |
+ |
} |
1545 |
|
|
1546 |
|
checkCompletedWithWrappedCancellationException(h); |
1547 |
< |
checkCancelled(f); |
1547 |
> |
checkCancelled(!fFirst ? f : g); |
1548 |
|
assertEquals(0, r.invocationCount); |
1549 |
< |
checkCompletedNormally(g, v1); |
1549 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1550 |
|
}} |
1551 |
|
|
1552 |
|
/** |
1553 |
|
* runAfterBoth result completes normally after normal |
1554 |
|
* completion of sources |
1555 |
|
*/ |
1556 |
< |
public void testRunAfterBoth_normalCompletion1() { |
1767 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1768 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1769 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1770 |
< |
{ |
1771 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1772 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1773 |
< |
final Noop r = new Noop(); |
1774 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1775 |
< |
|
1776 |
< |
f.complete(v1); |
1777 |
< |
checkIncomplete(h); |
1778 |
< |
assertEquals(0, r.invocationCount); |
1779 |
< |
g.complete(v2); |
1780 |
< |
|
1781 |
< |
checkCompletedNormally(h, null); |
1782 |
< |
assertEquals(1, r.invocationCount); |
1783 |
< |
checkCompletedNormally(f, v1); |
1784 |
< |
checkCompletedNormally(g, v2); |
1785 |
< |
}} |
1786 |
< |
|
1787 |
< |
public void testRunAfterBoth_normalCompletion2() { |
1788 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1789 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1790 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1791 |
< |
{ |
1792 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1793 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1794 |
< |
final Noop r = new Noop(); |
1795 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1796 |
< |
|
1797 |
< |
g.complete(v2); |
1798 |
< |
checkIncomplete(h); |
1799 |
< |
assertEquals(0, r.invocationCount); |
1800 |
< |
f.complete(v1); |
1801 |
< |
|
1802 |
< |
checkCompletedNormally(h, null); |
1803 |
< |
assertEquals(1, r.invocationCount); |
1804 |
< |
checkCompletedNormally(f, v1); |
1805 |
< |
checkCompletedNormally(g, v2); |
1806 |
< |
}} |
1807 |
< |
|
1808 |
< |
public void testRunAfterBoth_normalCompletion3() { |
1809 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1810 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1811 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1812 |
< |
{ |
1813 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1814 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1815 |
< |
final Noop r = new Noop(); |
1816 |
< |
|
1817 |
< |
g.complete(v2); |
1818 |
< |
f.complete(v1); |
1819 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1820 |
< |
|
1821 |
< |
checkCompletedNormally(h, null); |
1822 |
< |
assertEquals(1, r.invocationCount); |
1823 |
< |
checkCompletedNormally(f, v1); |
1824 |
< |
checkCompletedNormally(g, v2); |
1825 |
< |
}} |
1826 |
< |
|
1827 |
< |
public void testRunAfterBoth_normalCompletion4() { |
1556 |
> |
public void testRunAfterBoth_normalCompletion() { |
1557 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1558 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1559 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1560 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1561 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1562 |
|
{ |
1563 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1564 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1565 |
< |
final Noop r = new Noop(); |
1565 |
> |
final Noop r = new Noop(m); |
1566 |
|
|
1567 |
< |
f.complete(v1); |
1568 |
< |
g.complete(v2); |
1567 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1568 |
> |
if (!createIncomplete) |
1569 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1570 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1571 |
+ |
if (createIncomplete) { |
1572 |
+ |
checkIncomplete(h); |
1573 |
+ |
assertEquals(0, r.invocationCount); |
1574 |
+ |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1575 |
+ |
} |
1576 |
|
|
1577 |
|
checkCompletedNormally(h, null); |
1578 |
|
assertEquals(1, r.invocationCount); |
1584 |
|
* runAfterBoth result completes exceptionally after exceptional |
1585 |
|
* completion of either source |
1586 |
|
*/ |
1587 |
< |
public void testRunAfterBoth_exceptionalCompletion1() { |
1851 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1852 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1853 |
< |
{ |
1854 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1855 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1856 |
< |
final Noop r = new Noop(); |
1857 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1858 |
< |
final CFException ex = new CFException(); |
1859 |
< |
|
1860 |
< |
f.completeExceptionally(ex); |
1861 |
< |
checkIncomplete(h); |
1862 |
< |
g.complete(v1); |
1863 |
< |
|
1864 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1865 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1866 |
< |
assertEquals(0, r.invocationCount); |
1867 |
< |
checkCompletedNormally(g, v1); |
1868 |
< |
}} |
1869 |
< |
|
1870 |
< |
public void testRunAfterBoth_exceptionalCompletion2() { |
1871 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1872 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1873 |
< |
{ |
1874 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1875 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1876 |
< |
final Noop r = new Noop(); |
1877 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1878 |
< |
final CFException ex = new CFException(); |
1879 |
< |
|
1880 |
< |
g.completeExceptionally(ex); |
1881 |
< |
checkIncomplete(h); |
1882 |
< |
f.complete(v1); |
1883 |
< |
|
1884 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1885 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1886 |
< |
assertEquals(0, r.invocationCount); |
1887 |
< |
checkCompletedNormally(f, v1); |
1888 |
< |
}} |
1889 |
< |
|
1890 |
< |
public void testRunAfterBoth_exceptionalCompletion3() { |
1891 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1892 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1893 |
< |
{ |
1894 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1895 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1896 |
< |
final Noop r = new Noop(); |
1897 |
< |
final CFException ex = new CFException(); |
1898 |
< |
|
1899 |
< |
g.completeExceptionally(ex); |
1900 |
< |
f.complete(v1); |
1901 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1902 |
< |
|
1903 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1904 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1905 |
< |
assertEquals(0, r.invocationCount); |
1906 |
< |
checkCompletedNormally(f, v1); |
1907 |
< |
}} |
1908 |
< |
|
1909 |
< |
public void testRunAfterBoth_exceptionalCompletion4() { |
1587 |
> |
public void testRunAfterBoth_exceptionalCompletion() { |
1588 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1589 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1590 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1591 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1592 |
|
{ |
1593 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1594 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1915 |
– |
final Noop r = new Noop(); |
1595 |
|
final CFException ex = new CFException(); |
1596 |
+ |
final Noop r = new Noop(m); |
1597 |
|
|
1598 |
< |
f.completeExceptionally(ex); |
1599 |
< |
g.complete(v1); |
1598 |
> |
(fFirst ? f : g).complete(v1); |
1599 |
> |
if (!createIncomplete) |
1600 |
> |
(!fFirst ? f : g).completeExceptionally(ex); |
1601 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1602 |
+ |
if (createIncomplete) { |
1603 |
+ |
checkIncomplete(h); |
1604 |
+ |
(!fFirst ? f : g).completeExceptionally(ex); |
1605 |
+ |
} |
1606 |
|
|
1607 |
|
checkCompletedWithWrappedCFException(h, ex); |
1923 |
– |
checkCompletedWithWrappedCFException(f, ex); |
1608 |
|
assertEquals(0, r.invocationCount); |
1609 |
< |
checkCompletedNormally(g, v1); |
1609 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1610 |
> |
checkCompletedWithWrappedCFException(!fFirst ? f : g, ex); |
1611 |
|
}} |
1612 |
|
|
1613 |
|
/** |
1614 |
|
* runAfterBoth result completes exceptionally if action does |
1615 |
|
*/ |
1616 |
< |
public void testRunAfterBoth_actionFailed1() { |
1932 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1933 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1934 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1935 |
< |
{ |
1936 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1937 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1938 |
< |
final FailingRunnable r = new FailingRunnable(); |
1939 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1940 |
< |
|
1941 |
< |
f.complete(v1); |
1942 |
< |
checkIncomplete(h); |
1943 |
< |
g.complete(v2); |
1944 |
< |
|
1945 |
< |
checkCompletedWithWrappedCFException(h); |
1946 |
< |
checkCompletedNormally(f, v1); |
1947 |
< |
checkCompletedNormally(g, v2); |
1948 |
< |
}} |
1949 |
< |
|
1950 |
< |
public void testRunAfterBoth_actionFailed2() { |
1616 |
> |
public void testRunAfterBoth_actionFailed() { |
1617 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1618 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1619 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1620 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1621 |
|
{ |
1622 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1623 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1624 |
< |
final FailingRunnable r = new FailingRunnable(); |
1958 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1624 |
> |
final FailingRunnable r = new FailingRunnable(m); |
1625 |
|
|
1626 |
< |
g.complete(v2); |
1627 |
< |
checkIncomplete(h); |
1628 |
< |
f.complete(v1); |
1626 |
> |
CompletableFuture<Void> h1 = m.runAfterBoth(f, g, r); |
1627 |
> |
if (fFirst) { |
1628 |
> |
f.complete(v1); |
1629 |
> |
g.complete(v2); |
1630 |
> |
} else { |
1631 |
> |
g.complete(v2); |
1632 |
> |
f.complete(v1); |
1633 |
> |
} |
1634 |
> |
CompletableFuture<Void> h2 = m.runAfterBoth(f, g, r); |
1635 |
|
|
1636 |
< |
checkCompletedWithWrappedCFException(h); |
1636 |
> |
checkCompletedWithWrappedCFException(h1); |
1637 |
> |
checkCompletedWithWrappedCFException(h2); |
1638 |
|
checkCompletedNormally(f, v1); |
1639 |
|
checkCompletedNormally(g, v2); |
1640 |
|
}} |
1642 |
|
/** |
1643 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1644 |
|
*/ |
1645 |
< |
public void testRunAfterBoth_sourceCancelled1() { |
1973 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1974 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1975 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1976 |
< |
{ |
1977 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1978 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1979 |
< |
final Noop r = new Noop(); |
1980 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1981 |
< |
|
1982 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1983 |
< |
checkIncomplete(h); |
1984 |
< |
g.complete(v1); |
1985 |
< |
|
1986 |
< |
checkCompletedWithWrappedCancellationException(h); |
1987 |
< |
checkCancelled(f); |
1988 |
< |
assertEquals(0, r.invocationCount); |
1989 |
< |
checkCompletedNormally(g, v1); |
1990 |
< |
}} |
1991 |
< |
|
1992 |
< |
public void testRunAfterBoth_sourceCancelled2() { |
1645 |
> |
public void testRunAfterBoth_sourceCancelled() { |
1646 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1647 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1648 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1649 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1650 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1651 |
|
{ |
1652 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1653 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1654 |
< |
final Noop r = new Noop(); |
2000 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
2001 |
< |
|
2002 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
2003 |
< |
checkIncomplete(h); |
2004 |
< |
f.complete(v1); |
2005 |
< |
|
2006 |
< |
checkCompletedWithWrappedCancellationException(h); |
2007 |
< |
checkCancelled(g); |
2008 |
< |
assertEquals(0, r.invocationCount); |
2009 |
< |
checkCompletedNormally(f, v1); |
2010 |
< |
}} |
1654 |
> |
final Noop r = new Noop(m); |
1655 |
|
|
2012 |
– |
public void testRunAfterBoth_sourceCancelled3() { |
2013 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2014 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2015 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2016 |
– |
{ |
2017 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2018 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2019 |
– |
final Noop r = new Noop(); |
1656 |
|
|
1657 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1658 |
< |
f.complete(v1); |
1659 |
< |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
2024 |
< |
|
2025 |
< |
checkCompletedWithWrappedCancellationException(h); |
2026 |
< |
checkCancelled(g); |
2027 |
< |
assertEquals(0, r.invocationCount); |
2028 |
< |
checkCompletedNormally(f, v1); |
2029 |
< |
}} |
2030 |
< |
|
2031 |
< |
public void testRunAfterBoth_sourceCancelled4() { |
2032 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2033 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2034 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2035 |
< |
{ |
2036 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2037 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2038 |
< |
final Noop r = new Noop(); |
2039 |
< |
|
2040 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2041 |
< |
g.complete(v1); |
1657 |
> |
(fFirst ? f : g).complete(v1); |
1658 |
> |
if (!createIncomplete) |
1659 |
> |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1660 |
|
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1661 |
+ |
if (createIncomplete) { |
1662 |
+ |
checkIncomplete(h); |
1663 |
+ |
assertTrue((!fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1664 |
+ |
} |
1665 |
|
|
1666 |
|
checkCompletedWithWrappedCancellationException(h); |
1667 |
< |
checkCancelled(f); |
1667 |
> |
checkCancelled(!fFirst ? f : g); |
1668 |
|
assertEquals(0, r.invocationCount); |
1669 |
< |
checkCompletedNormally(g, v1); |
1669 |
> |
checkCompletedNormally(fFirst ? f : g, v1); |
1670 |
|
}} |
1671 |
|
|
1672 |
|
/** |
1673 |
|
* applyToEither result completes normally after normal completion |
1674 |
|
* of either source |
1675 |
|
*/ |
1676 |
< |
public void testApplyToEither_normalCompletion1() { |
1676 |
> |
public void testApplyToEither_normalCompletion() { |
1677 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1678 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1679 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1680 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1681 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1682 |
|
{ |
1683 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1684 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1685 |
< |
final IncFunction r = new IncFunction(); |
2062 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1685 |
> |
final IncFunction r = new IncFunction(m); |
1686 |
|
|
1687 |
< |
f.complete(v1); |
1688 |
< |
checkCompletedNormally(h, inc(v1)); |
1689 |
< |
g.complete(v2); |
1687 |
> |
if (!createIncomplete) |
1688 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1689 |
> |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1690 |
> |
if (createIncomplete) { |
1691 |
> |
checkIncomplete(h); |
1692 |
> |
assertEquals(0, r.invocationCount); |
1693 |
> |
if (fFirst) f.complete(v1); else g.complete(v2); |
1694 |
> |
} |
1695 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1696 |
> |
if (!fFirst) f.complete(v1); else g.complete(v2); |
1697 |
|
|
1698 |
|
checkCompletedNormally(f, v1); |
1699 |
|
checkCompletedNormally(g, v2); |
1700 |
< |
checkCompletedNormally(h, inc(v1)); |
1700 |
> |
checkCompletedNormally(h, inc(fFirst ? v1 : v2)); |
1701 |
|
}} |
1702 |
|
|
1703 |
< |
public void testApplyToEither_normalCompletion2() { |
1703 |
> |
public void testApplyToEither_normalCompletionBothAvailable() { |
1704 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1705 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1706 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1707 |
|
for (Integer v2 : new Integer[] { 2, null }) |
1708 |
|
{ |
1709 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1710 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1711 |
< |
final IncFunction r = new IncFunction(); |
2081 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2082 |
< |
|
2083 |
< |
g.complete(v2); |
2084 |
< |
checkCompletedNormally(h, inc(v2)); |
2085 |
< |
f.complete(v1); |
2086 |
< |
|
2087 |
< |
checkCompletedNormally(f, v1); |
2088 |
< |
checkCompletedNormally(g, v2); |
2089 |
< |
checkCompletedNormally(h, inc(v2)); |
2090 |
< |
}} |
1711 |
> |
final IncFunction r = new IncFunction(m); |
1712 |
|
|
1713 |
< |
public void testApplyToEither_normalCompletion3() { |
1714 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
1715 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
1716 |
< |
for (Integer v2 : new Integer[] { 2, null }) |
1717 |
< |
{ |
1718 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1719 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2099 |
< |
final IncFunction r = new IncFunction(); |
1713 |
> |
if (fFirst) { |
1714 |
> |
f.complete(v1); |
1715 |
> |
g.complete(v2); |
1716 |
> |
} else { |
1717 |
> |
g.complete(v2); |
1718 |
> |
f.complete(v1); |
1719 |
> |
} |
1720 |
|
|
2101 |
– |
f.complete(v1); |
2102 |
– |
g.complete(v2); |
1721 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1722 |
|
|
1723 |
|
checkCompletedNormally(f, v1); |
1735 |
|
*/ |
1736 |
|
public void testApplyToEither_exceptionalCompletion1() { |
1737 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1738 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1739 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1740 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1741 |
|
{ |
1742 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1743 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2124 |
– |
final IncFunction r = new IncFunction(); |
2125 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1744 |
|
final CFException ex = new CFException(); |
1745 |
+ |
final IncFunction r = new IncFunction(m); |
1746 |
|
|
1747 |
< |
f.completeExceptionally(ex); |
2129 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2130 |
< |
g.complete(v1); |
2131 |
< |
|
2132 |
< |
assertEquals(0, r.invocationCount); |
2133 |
< |
checkCompletedNormally(g, v1); |
2134 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2135 |
< |
checkCompletedWithWrappedCFException(h, ex); |
2136 |
< |
}} |
2137 |
< |
|
2138 |
< |
public void testApplyToEither_exceptionalCompletion2() { |
2139 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2140 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2141 |
< |
{ |
2142 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2143 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2144 |
< |
final IncFunction r = new IncFunction(); |
1747 |
> |
if (!createIncomplete) (fFirst ? f : g).completeExceptionally(ex); |
1748 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1749 |
< |
final CFException ex = new CFException(); |
1749 |
> |
if (createIncomplete) { |
1750 |
> |
checkIncomplete(h); |
1751 |
> |
assertEquals(0, r.invocationCount); |
1752 |
> |
(fFirst ? f : g).completeExceptionally(ex); |
1753 |
> |
} |
1754 |
|
|
2148 |
– |
g.completeExceptionally(ex); |
1755 |
|
checkCompletedWithWrappedCFException(h, ex); |
1756 |
< |
f.complete(v1); |
1756 |
> |
(!fFirst ? f : g).complete(v1); |
1757 |
|
|
1758 |
|
assertEquals(0, r.invocationCount); |
1759 |
< |
checkCompletedNormally(f, v1); |
1760 |
< |
checkCompletedWithWrappedCFException(g, ex); |
1759 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1760 |
> |
checkCompletedWithWrappedCFException(fFirst ? f : g, ex); |
1761 |
|
checkCompletedWithWrappedCFException(h, ex); |
1762 |
|
}} |
1763 |
|
|
1764 |
< |
public void testApplyToEither_exceptionalCompletion3() { |
1764 |
> |
public void testApplyToEither_exceptionalCompletion2() { |
1765 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1766 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1767 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1768 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1769 |
|
{ |
1770 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1771 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1772 |
< |
final IncFunction r = new IncFunction(); |
1772 |
> |
final IncFunction r1 = new IncFunction(m); |
1773 |
> |
final IncFunction r2 = new IncFunction(m); |
1774 |
|
final CFException ex = new CFException(); |
1775 |
< |
|
1776 |
< |
g.completeExceptionally(ex); |
1777 |
< |
f.complete(v1); |
1778 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1775 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1776 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1777 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1778 |
> |
if (fFirst) { |
1779 |
> |
f.complete(v1); |
1780 |
> |
g.completeExceptionally(ex); |
1781 |
> |
} else { |
1782 |
> |
g.completeExceptionally(ex); |
1783 |
> |
f.complete(v1); |
1784 |
> |
} |
1785 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1786 |
|
|
1787 |
|
// unspecified behavior |
2172 |
– |
Integer v; |
1788 |
|
try { |
1789 |
< |
assertEquals(inc(v1), h.join()); |
1790 |
< |
assertEquals(1, r.invocationCount); |
1789 |
> |
assertEquals(inc(v1), h1.join()); |
1790 |
> |
assertEquals(1, r1.invocationCount); |
1791 |
|
} catch (CompletionException ok) { |
1792 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1793 |
< |
assertEquals(0, r.invocationCount); |
1792 |
> |
checkCompletedWithWrappedCFException(h1, ex); |
1793 |
> |
assertEquals(0, r1.invocationCount); |
1794 |
|
} |
1795 |
|
|
2181 |
– |
checkCompletedWithWrappedCFException(g, ex); |
2182 |
– |
checkCompletedNormally(f, v1); |
2183 |
– |
}} |
2184 |
– |
|
2185 |
– |
public void testApplyToEither_exceptionalCompletion4() { |
2186 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2187 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2188 |
– |
{ |
2189 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2190 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2191 |
– |
final IncFunction r = new IncFunction(); |
2192 |
– |
final CFException ex = new CFException(); |
2193 |
– |
|
2194 |
– |
f.completeExceptionally(ex); |
2195 |
– |
g.complete(v1); |
2196 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2197 |
– |
|
2198 |
– |
// unspecified behavior |
2199 |
– |
Integer v; |
1796 |
|
try { |
1797 |
< |
assertEquals(inc(v1), h.join()); |
1798 |
< |
assertEquals(1, r.invocationCount); |
1797 |
> |
assertEquals(inc(v1), h2.join()); |
1798 |
> |
assertEquals(1, r2.invocationCount); |
1799 |
|
} catch (CompletionException ok) { |
1800 |
< |
checkCompletedWithWrappedCFException(h, ex); |
1801 |
< |
assertEquals(0, r.invocationCount); |
1800 |
> |
checkCompletedWithWrappedCFException(h2, ex); |
1801 |
> |
assertEquals(0, r2.invocationCount); |
1802 |
|
} |
1803 |
|
|
1804 |
< |
checkCompletedWithWrappedCFException(f, ex); |
1805 |
< |
checkCompletedNormally(g, v1); |
1804 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1805 |
> |
checkCompletedNormally(f, v1); |
1806 |
|
}} |
1807 |
|
|
1808 |
|
/** |
1815 |
|
{ |
1816 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1817 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1818 |
< |
final FailingFunction r = new FailingFunction(); |
1818 |
> |
final FailingFunction r = new FailingFunction(m); |
1819 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1820 |
|
|
1821 |
|
f.complete(v1); |
1832 |
|
{ |
1833 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1834 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1835 |
< |
final FailingFunction r = new FailingFunction(); |
1835 |
> |
final FailingFunction r = new FailingFunction(m); |
1836 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1837 |
|
|
1838 |
|
g.complete(v2); |
1848 |
|
public void testApplyToEither_sourceCancelled1() { |
1849 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1850 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1851 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
1852 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1853 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1854 |
|
{ |
1855 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1856 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1857 |
< |
final IncFunction r = new IncFunction(); |
2260 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1857 |
> |
final IncFunction r = new IncFunction(m); |
1858 |
|
|
1859 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2263 |
< |
checkCompletedWithWrappedCancellationException(h); |
2264 |
< |
g.complete(v1); |
2265 |
< |
|
2266 |
< |
checkCancelled(f); |
2267 |
< |
assertEquals(0, r.invocationCount); |
2268 |
< |
checkCompletedNormally(g, v1); |
2269 |
< |
checkCompletedWithWrappedCancellationException(h); |
2270 |
< |
}} |
2271 |
< |
|
2272 |
< |
public void testApplyToEither_sourceCancelled2() { |
2273 |
< |
for (ExecutionMode m : ExecutionMode.values()) |
2274 |
< |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2275 |
< |
for (Integer v1 : new Integer[] { 1, null }) |
2276 |
< |
{ |
2277 |
< |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2278 |
< |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2279 |
< |
final IncFunction r = new IncFunction(); |
1859 |
> |
if (!createIncomplete) assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1860 |
|
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1861 |
+ |
if (createIncomplete) { |
1862 |
+ |
checkIncomplete(h); |
1863 |
+ |
assertEquals(0, r.invocationCount); |
1864 |
+ |
assertTrue((fFirst ? f : g).cancel(mayInterruptIfRunning)); |
1865 |
+ |
} |
1866 |
|
|
2282 |
– |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1867 |
|
checkCompletedWithWrappedCancellationException(h); |
1868 |
< |
f.complete(v1); |
1868 |
> |
(!fFirst ? f : g).complete(v1); |
1869 |
|
|
2286 |
– |
checkCancelled(g); |
1870 |
|
assertEquals(0, r.invocationCount); |
1871 |
< |
checkCompletedNormally(f, v1); |
1871 |
> |
checkCompletedNormally(!fFirst ? f : g, v1); |
1872 |
> |
checkCancelled(fFirst ? f : g); |
1873 |
|
checkCompletedWithWrappedCancellationException(h); |
1874 |
|
}} |
1875 |
|
|
1876 |
< |
public void testApplyToEither_sourceCancelled3() { |
1876 |
> |
public void testApplyToEither_sourceCancelled2() { |
1877 |
|
for (ExecutionMode m : ExecutionMode.values()) |
1878 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1879 |
+ |
for (boolean reverseArgs : new boolean[] { true, false }) |
1880 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1881 |
|
for (Integer v1 : new Integer[] { 1, null }) |
1882 |
|
{ |
1883 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1884 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1885 |
< |
final IncFunction r = new IncFunction(); |
1885 |
> |
final IncFunction r1 = new IncFunction(m); |
1886 |
> |
final IncFunction r2 = new IncFunction(m); |
1887 |
> |
final CFException ex = new CFException(); |
1888 |
> |
final CompletableFuture<Integer> j = (reverseArgs ? g : f); |
1889 |
> |
final CompletableFuture<Integer> k = (reverseArgs ? f : g); |
1890 |
|
|
1891 |
< |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1892 |
< |
f.complete(v1); |
1893 |
< |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
1891 |
> |
final CompletableFuture<Integer> h1 = m.applyToEither(j, k, r1); |
1892 |
> |
if (fFirst) { |
1893 |
> |
f.complete(v1); |
1894 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1895 |
> |
} else { |
1896 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1897 |
> |
f.complete(v1); |
1898 |
> |
} |
1899 |
> |
final CompletableFuture<Integer> h2 = m.applyToEither(j, k, r2); |
1900 |
|
|
1901 |
|
// unspecified behavior |
2306 |
– |
Integer v; |
1902 |
|
try { |
1903 |
< |
assertEquals(inc(v1), h.join()); |
1904 |
< |
assertEquals(1, r.invocationCount); |
1903 |
> |
assertEquals(inc(v1), h1.join()); |
1904 |
> |
assertEquals(1, r1.invocationCount); |
1905 |
|
} catch (CompletionException ok) { |
1906 |
< |
checkCompletedWithWrappedCancellationException(h); |
1907 |
< |
assertEquals(0, r.invocationCount); |
1906 |
> |
checkCompletedWithWrappedCancellationException(h1); |
1907 |
> |
assertEquals(0, r1.invocationCount); |
1908 |
|
} |
1909 |
|
|
2315 |
– |
checkCancelled(g); |
2316 |
– |
checkCompletedNormally(f, v1); |
2317 |
– |
}} |
2318 |
– |
|
2319 |
– |
public void testApplyToEither_sourceCancelled4() { |
2320 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2321 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2322 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2323 |
– |
{ |
2324 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2325 |
– |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2326 |
– |
final IncFunction r = new IncFunction(); |
2327 |
– |
|
2328 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2329 |
– |
g.complete(v1); |
2330 |
– |
final CompletableFuture<Integer> h = m.applyToEither(f, g, r); |
2331 |
– |
|
2332 |
– |
// unspecified behavior |
2333 |
– |
Integer v; |
1910 |
|
try { |
1911 |
< |
assertEquals(inc(v1), h.join()); |
1912 |
< |
assertEquals(1, r.invocationCount); |
1911 |
> |
assertEquals(inc(v1), h2.join()); |
1912 |
> |
assertEquals(1, r2.invocationCount); |
1913 |
|
} catch (CompletionException ok) { |
1914 |
< |
checkCompletedWithWrappedCancellationException(h); |
1915 |
< |
assertEquals(0, r.invocationCount); |
1914 |
> |
checkCompletedWithWrappedCancellationException(h2); |
1915 |
> |
assertEquals(0, r2.invocationCount); |
1916 |
|
} |
1917 |
|
|
1918 |
< |
checkCancelled(f); |
1919 |
< |
checkCompletedNormally(g, v1); |
1918 |
> |
checkCancelled(g); |
1919 |
> |
checkCompletedNormally(f, v1); |
1920 |
|
}} |
1921 |
|
|
1922 |
|
/** |
2095 |
|
{ |
2096 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2097 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2098 |
< |
final FailingConsumer r = new FailingConsumer(); |
2098 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2099 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2100 |
|
|
2101 |
|
f.complete(v1); |
2112 |
|
{ |
2113 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2114 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2115 |
< |
final FailingConsumer r = new FailingConsumer(); |
2115 |
> |
final FailingConsumer r = new FailingConsumer(m); |
2116 |
|
final CompletableFuture<Void> h = m.acceptEither(f, g, r); |
2117 |
|
|
2118 |
|
g.complete(v2); |
2232 |
|
{ |
2233 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2234 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2235 |
< |
final Noop r = new Noop(); |
2235 |
> |
final Noop r = new Noop(m); |
2236 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2237 |
|
|
2238 |
|
f.complete(v1); |
2253 |
|
{ |
2254 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2255 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2256 |
< |
final Noop r = new Noop(); |
2256 |
> |
final Noop r = new Noop(m); |
2257 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2258 |
|
|
2259 |
|
g.complete(v2); |
2274 |
|
{ |
2275 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2276 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2277 |
< |
final Noop r = new Noop(); |
2277 |
> |
final Noop r = new Noop(m); |
2278 |
|
|
2279 |
|
f.complete(v1); |
2280 |
|
g.complete(v2); |
2296 |
|
{ |
2297 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2298 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2299 |
< |
final Noop r = new Noop(); |
2299 |
> |
final Noop r = new Noop(m); |
2300 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2301 |
|
final CFException ex = new CFException(); |
2302 |
|
|
2316 |
|
{ |
2317 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2318 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2319 |
< |
final Noop r = new Noop(); |
2319 |
> |
final Noop r = new Noop(m); |
2320 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2321 |
|
final CFException ex = new CFException(); |
2322 |
|
|
2336 |
|
{ |
2337 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2338 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2339 |
< |
final Noop r = new Noop(); |
2339 |
> |
final Noop r = new Noop(m); |
2340 |
|
final CFException ex = new CFException(); |
2341 |
|
|
2342 |
|
g.completeExceptionally(ex); |
2363 |
|
{ |
2364 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2365 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2366 |
< |
final Noop r = new Noop(); |
2366 |
> |
final Noop r = new Noop(m); |
2367 |
|
final CFException ex = new CFException(); |
2368 |
|
|
2369 |
|
f.completeExceptionally(ex); |
2394 |
|
{ |
2395 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2396 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2397 |
< |
final FailingRunnable r = new FailingRunnable(); |
2397 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2398 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2399 |
|
|
2400 |
|
f.complete(v1); |
2411 |
|
{ |
2412 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2413 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2414 |
< |
final FailingRunnable r = new FailingRunnable(); |
2414 |
> |
final FailingRunnable r = new FailingRunnable(m); |
2415 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2416 |
|
|
2417 |
|
g.complete(v2); |
2431 |
|
{ |
2432 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2433 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2434 |
< |
final Noop r = new Noop(); |
2434 |
> |
final Noop r = new Noop(m); |
2435 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2436 |
|
|
2437 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2451 |
|
{ |
2452 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2453 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2454 |
< |
final Noop r = new Noop(); |
2454 |
> |
final Noop r = new Noop(m); |
2455 |
|
final CompletableFuture<Void> h = m.runAfterEither(f, g, r); |
2456 |
|
|
2457 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2471 |
|
{ |
2472 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2473 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2474 |
< |
final Noop r = new Noop(); |
2474 |
> |
final Noop r = new Noop(m); |
2475 |
|
|
2476 |
|
assertTrue(g.cancel(mayInterruptIfRunning)); |
2477 |
|
f.complete(v1); |
2498 |
|
{ |
2499 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2500 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2501 |
< |
final Noop r = new Noop(); |
2501 |
> |
final Noop r = new Noop(m); |
2502 |
|
|
2503 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2504 |
|
g.complete(v1); |
2527 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2528 |
|
{ |
2529 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2530 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2530 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2531 |
|
if (!createIncomplete) f.complete(v1); |
2532 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2532 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2533 |
|
if (createIncomplete) f.complete(v1); |
2534 |
|
|
2535 |
|
checkCompletedNormally(g, inc(v1)); |
2546 |
|
for (boolean createIncomplete : new boolean[] { true, false }) |
2547 |
|
{ |
2548 |
|
final CFException ex = new CFException(); |
2549 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2549 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2550 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2551 |
|
if (!createIncomplete) f.completeExceptionally(ex); |
2552 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2552 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2553 |
|
if (createIncomplete) f.completeExceptionally(ex); |
2554 |
|
|
2555 |
|
checkCompletedWithWrappedCFException(g, ex); |
2567 |
|
{ |
2568 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2569 |
|
final FailingCompletableFutureFunction r |
2570 |
< |
= new FailingCompletableFutureFunction(); |
2570 |
> |
= new FailingCompletableFutureFunction(m); |
2571 |
|
if (!createIncomplete) f.complete(v1); |
2572 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2572 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2573 |
|
if (createIncomplete) f.complete(v1); |
2574 |
|
|
2575 |
|
checkCompletedWithWrappedCFException(g); |
2585 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2586 |
|
{ |
2587 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2588 |
< |
final CompletableFutureInc r = new CompletableFutureInc(); |
2588 |
> |
final CompletableFutureInc r = new CompletableFutureInc(m); |
2589 |
|
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2590 |
< |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2590 |
> |
final CompletableFuture<Integer> g = m.thenCompose(f, r); |
2591 |
|
if (createIncomplete) { |
2592 |
|
checkIncomplete(g); |
2593 |
|
assertTrue(f.cancel(mayInterruptIfRunning)); |
2614 |
|
*/ |
2615 |
|
public void testAllOf_normal() throws Exception { |
2616 |
|
for (int k = 1; k < 20; ++k) { |
2617 |
< |
CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
2617 |
> |
CompletableFuture<Integer>[] fs |
2618 |
> |
= (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
2619 |
|
for (int i = 0; i < k; ++i) |
2620 |
|
fs[i] = new CompletableFuture<>(); |
2621 |
|
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
2629 |
|
} |
2630 |
|
} |
2631 |
|
|
2632 |
+ |
public void testAllOf_backwards() throws Exception { |
2633 |
+ |
for (int k = 1; k < 20; ++k) { |
2634 |
+ |
CompletableFuture<Integer>[] fs |
2635 |
+ |
= (CompletableFuture<Integer>[]) new CompletableFuture[k]; |
2636 |
+ |
for (int i = 0; i < k; ++i) |
2637 |
+ |
fs[i] = new CompletableFuture<>(); |
2638 |
+ |
CompletableFuture<Void> f = CompletableFuture.allOf(fs); |
2639 |
+ |
for (int i = k - 1; i >= 0; i--) { |
2640 |
+ |
checkIncomplete(f); |
2641 |
+ |
checkIncomplete(CompletableFuture.allOf(fs)); |
2642 |
+ |
fs[i].complete(one); |
2643 |
+ |
} |
2644 |
+ |
checkCompletedNormally(f, null); |
2645 |
+ |
checkCompletedNormally(CompletableFuture.allOf(fs), null); |
2646 |
+ |
} |
2647 |
+ |
} |
2648 |
+ |
|
2649 |
|
/** |
2650 |
|
* anyOf(no component futures) returns an incomplete future |
2651 |
|
*/ |
2704 |
|
Runnable[] throwingActions = { |
2705 |
|
() -> CompletableFuture.supplyAsync(null), |
2706 |
|
() -> CompletableFuture.supplyAsync(null, exec), |
2707 |
< |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
2707 |
> |
() -> CompletableFuture.supplyAsync(new IntegerSupplier(ExecutionMode.DEFAULT, 42), null), |
2708 |
|
|
2709 |
|
() -> CompletableFuture.runAsync(null), |
2710 |
|
() -> CompletableFuture.runAsync(null, exec), |
2777 |
|
|
2778 |
|
() -> f.thenCompose(null), |
2779 |
|
() -> f.thenComposeAsync(null), |
2780 |
< |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
2780 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(ExecutionMode.EXECUTOR), null), |
2781 |
|
() -> f.thenComposeAsync(null, exec), |
2782 |
|
|
2783 |
|
() -> f.exceptionally(null), |