16 |
|
import java.util.concurrent.Future; |
17 |
|
import java.util.concurrent.CompletableFuture; |
18 |
|
import java.util.concurrent.CompletionException; |
19 |
+ |
import java.util.concurrent.CompletionStage; |
20 |
|
import java.util.concurrent.TimeoutException; |
21 |
|
import java.util.concurrent.atomic.AtomicInteger; |
22 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
103 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
104 |
|
} |
105 |
|
|
106 |
+ |
void checkCompletedWithWrappedCFException(CompletableFuture<?> f, |
107 |
+ |
CFException ex) { |
108 |
+ |
try { |
109 |
+ |
f.get(LONG_DELAY_MS, MILLISECONDS); |
110 |
+ |
shouldThrow(); |
111 |
+ |
} catch (ExecutionException success) { |
112 |
+ |
assertSame(ex, success.getCause()); |
113 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
114 |
+ |
try { |
115 |
+ |
f.join(); |
116 |
+ |
shouldThrow(); |
117 |
+ |
} catch (CompletionException success) { |
118 |
+ |
assertSame(ex, success.getCause()); |
119 |
+ |
} |
120 |
+ |
try { |
121 |
+ |
f.getNow(null); |
122 |
+ |
shouldThrow(); |
123 |
+ |
} catch (CompletionException success) { |
124 |
+ |
assertSame(ex, success.getCause()); |
125 |
+ |
} |
126 |
+ |
try { |
127 |
+ |
f.get(); |
128 |
+ |
shouldThrow(); |
129 |
+ |
} catch (ExecutionException success) { |
130 |
+ |
assertSame(ex, success.getCause()); |
131 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
132 |
+ |
assertTrue(f.isDone()); |
133 |
+ |
assertFalse(f.isCancelled()); |
134 |
+ |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
135 |
+ |
} |
136 |
+ |
|
137 |
|
void checkCancelled(CompletableFuture<?> f) { |
138 |
|
try { |
139 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
291 |
|
assertEquals(g.getNumberOfDependents(), 0); |
292 |
|
} |
293 |
|
|
262 |
– |
|
294 |
|
/** |
295 |
|
* toString indicates current completion state |
296 |
|
*/ |
318 |
|
|
319 |
|
// Choose non-commutative actions for better coverage |
320 |
|
|
321 |
+ |
// A non-commutative function that handles null values as well, |
322 |
+ |
// and produces null values occasionally. |
323 |
+ |
public static Integer subtract(Integer x, Integer y) { |
324 |
+ |
return (x == null && y == null) ? null : |
325 |
+ |
((x == null) ? 42 : x.intValue()) |
326 |
+ |
- ((y == null) ? 99 : y.intValue()); |
327 |
+ |
} |
328 |
+ |
|
329 |
|
static final Supplier<Integer> supplyOne = |
330 |
|
() -> Integer.valueOf(1); |
331 |
|
static final Function<Integer, Integer> inc = |
332 |
|
(Integer x) -> Integer.valueOf(x.intValue() + 1); |
333 |
|
static final BiFunction<Integer, Integer, Integer> subtract = |
334 |
< |
(Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue()); |
334 |
> |
(Integer x, Integer y) -> subtract(x, y); |
335 |
|
static final class IncAction implements Consumer<Integer> { |
336 |
|
int value; |
337 |
|
public void accept(Integer x) { value = x.intValue() + 1; } |
338 |
|
} |
339 |
|
static final class SubtractAction implements BiConsumer<Integer, Integer> { |
340 |
< |
int value; |
340 |
> |
int invocationCount = 0; |
341 |
> |
Integer value; |
342 |
> |
// Check this action was invoked exactly once when result is computed. |
343 |
> |
public boolean ran() { return invocationCount == 1; } |
344 |
|
public void accept(Integer x, Integer y) { |
345 |
< |
value = x.intValue() - y.intValue(); |
345 |
> |
invocationCount++; |
346 |
> |
value = subtract(x, y); |
347 |
> |
} |
348 |
> |
} |
349 |
> |
static final class SubtractFunction implements BiFunction<Integer, Integer, Integer> { |
350 |
> |
int invocationCount = 0; |
351 |
> |
Integer value; |
352 |
> |
// Check this action was invoked exactly once when result is computed. |
353 |
> |
public boolean ran() { return invocationCount == 1; } |
354 |
> |
public Integer apply(Integer x, Integer y) { |
355 |
> |
invocationCount++; |
356 |
> |
return value = subtract(x, y); |
357 |
|
} |
358 |
|
} |
359 |
|
static final class Noop implements Runnable { |
427 |
|
} |
428 |
|
} |
429 |
|
|
430 |
+ |
/** |
431 |
+ |
* Permits the testing of parallel code for the 3 different |
432 |
+ |
* execution modes without repeating all the testing code. |
433 |
+ |
*/ |
434 |
+ |
enum ExecutionMode { |
435 |
+ |
DEFAULT { |
436 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
437 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
438 |
+ |
return f.runAfterBoth(g, a); |
439 |
+ |
} |
440 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
441 |
+ |
(CompletableFuture<T> f, |
442 |
+ |
CompletionStage<? extends U> g, |
443 |
+ |
BiConsumer<? super T,? super U> a) { |
444 |
+ |
return f.thenAcceptBoth(g, a); |
445 |
+ |
} |
446 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
447 |
+ |
(CompletableFuture<T> f, |
448 |
+ |
CompletionStage<? extends U> g, |
449 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
450 |
+ |
return f.thenCombine(g, a); |
451 |
+ |
} |
452 |
+ |
}, |
453 |
+ |
|
454 |
+ |
// /** Experimental way to do more testing */ |
455 |
+ |
// REVERSE_DEFAULT { |
456 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
457 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
458 |
+ |
// return g.runAfterBoth(f, a); |
459 |
+ |
// } |
460 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
461 |
+ |
// (CompletableFuture<T> f, |
462 |
+ |
// CompletionStage<? extends U> g, |
463 |
+ |
// BiConsumer<? super T,? super U> a) { |
464 |
+ |
// return DEFAULT.thenAcceptBoth(f, g, a); |
465 |
+ |
// } |
466 |
+ |
// }, |
467 |
+ |
|
468 |
+ |
DEFAULT_ASYNC { |
469 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
470 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
471 |
+ |
return f.runAfterBothAsync(g, a); |
472 |
+ |
} |
473 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
474 |
+ |
(CompletableFuture<T> f, |
475 |
+ |
CompletionStage<? extends U> g, |
476 |
+ |
BiConsumer<? super T,? super U> a) { |
477 |
+ |
return f.thenAcceptBothAsync(g, a); |
478 |
+ |
} |
479 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
480 |
+ |
(CompletableFuture<T> f, |
481 |
+ |
CompletionStage<? extends U> g, |
482 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
483 |
+ |
return f.thenCombineAsync(g, a); |
484 |
+ |
} |
485 |
+ |
}, |
486 |
+ |
|
487 |
+ |
// REVERSE_DEFAULT_ASYNC { |
488 |
+ |
// public <T,U> CompletableFuture<Void> runAfterBoth |
489 |
+ |
// (CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
490 |
+ |
// return f.runAfterBothAsync(g, a); |
491 |
+ |
// } |
492 |
+ |
// public <T,U> CompletableFuture<Void> thenAcceptBoth |
493 |
+ |
// (CompletableFuture<T> f, |
494 |
+ |
// CompletionStage<? extends U> g, |
495 |
+ |
// BiConsumer<? super T,? super U> a) { |
496 |
+ |
// return DEFAULT_ASYNC.thenAcceptBoth(f, g, a); |
497 |
+ |
// } |
498 |
+ |
// }, |
499 |
+ |
|
500 |
+ |
EXECUTOR { |
501 |
+ |
public <T,U> CompletableFuture<Void> runAfterBoth |
502 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a) { |
503 |
+ |
return f.runAfterBothAsync(g, a, new ThreadExecutor()); |
504 |
+ |
} |
505 |
+ |
public <T,U> CompletableFuture<Void> thenAcceptBoth |
506 |
+ |
(CompletableFuture<T> f, |
507 |
+ |
CompletionStage<? extends U> g, |
508 |
+ |
BiConsumer<? super T,? super U> a) { |
509 |
+ |
return f.thenAcceptBothAsync(g, a, new ThreadExecutor()); |
510 |
+ |
} |
511 |
+ |
public <T,U,V> CompletableFuture<V> thenCombine |
512 |
+ |
(CompletableFuture<T> f, |
513 |
+ |
CompletionStage<? extends U> g, |
514 |
+ |
BiFunction<? super T,? super U,? extends V> a) { |
515 |
+ |
return f.thenCombineAsync(g, a, new ThreadExecutor()); |
516 |
+ |
} |
517 |
+ |
}; |
518 |
+ |
|
519 |
+ |
public abstract <T,U> CompletableFuture<Void> runAfterBoth |
520 |
+ |
(CompletableFuture<T> f, CompletableFuture<U> g, Runnable a); |
521 |
+ |
public abstract <T,U> CompletableFuture<Void> thenAcceptBoth |
522 |
+ |
(CompletableFuture<T> f, |
523 |
+ |
CompletionStage<? extends U> g, |
524 |
+ |
BiConsumer<? super T,? super U> a); |
525 |
+ |
public abstract <T,U,V> CompletableFuture<V> thenCombine |
526 |
+ |
(CompletableFuture<T> f, |
527 |
+ |
CompletionStage<? extends U> g, |
528 |
+ |
BiFunction<? super T,? super U,? extends V> a); |
529 |
+ |
} |
530 |
|
|
531 |
|
/** |
532 |
|
* exceptionally action completes with function value on source |
533 |
< |
* exception; otherwise with source value |
533 |
> |
* exception; otherwise with source value |
534 |
|
*/ |
535 |
|
public void testExceptionally() { |
536 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
816 |
|
checkCompletedWithWrappedCancellationException(g); |
817 |
|
} |
818 |
|
|
666 |
– |
|
819 |
|
/** |
820 |
|
* thenCombine result completes normally after normal completion |
821 |
|
* of sources |
822 |
|
*/ |
823 |
< |
public void testThenCombine() { |
824 |
< |
CompletableFuture<Integer> f, g, h; |
823 |
> |
public void testThenCombine_normalCompletion1() { |
824 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
825 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
826 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
827 |
> |
|
828 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
829 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
830 |
> |
final SubtractFunction r = new SubtractFunction(); |
831 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
832 |
> |
|
833 |
> |
f.complete(v1); |
834 |
> |
checkIncomplete(h); |
835 |
> |
assertFalse(r.ran()); |
836 |
> |
g.complete(v2); |
837 |
> |
|
838 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
839 |
> |
checkCompletedNormally(f, v1); |
840 |
> |
checkCompletedNormally(g, v2); |
841 |
> |
} |
842 |
> |
} |
843 |
|
|
844 |
< |
f = new CompletableFuture<>(); |
845 |
< |
g = new CompletableFuture<>(); |
846 |
< |
h = f.thenCombine(g, subtract); |
847 |
< |
f.complete(3); |
848 |
< |
checkIncomplete(h); |
849 |
< |
g.complete(1); |
850 |
< |
checkCompletedNormally(h, 2); |
844 |
> |
public void testThenCombine_normalCompletion2() { |
845 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
846 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
847 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
848 |
> |
|
849 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
850 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
851 |
> |
final SubtractFunction r = new SubtractFunction(); |
852 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
853 |
> |
|
854 |
> |
g.complete(v2); |
855 |
> |
checkIncomplete(h); |
856 |
> |
assertFalse(r.ran()); |
857 |
> |
f.complete(v1); |
858 |
> |
|
859 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
860 |
> |
checkCompletedNormally(f, v1); |
861 |
> |
checkCompletedNormally(g, v2); |
862 |
> |
} |
863 |
> |
} |
864 |
|
|
865 |
< |
f = new CompletableFuture<>(); |
866 |
< |
g = new CompletableFuture<>(); |
867 |
< |
h = f.thenCombine(g, subtract); |
868 |
< |
g.complete(1); |
869 |
< |
checkIncomplete(h); |
870 |
< |
f.complete(3); |
871 |
< |
checkCompletedNormally(h, 2); |
865 |
> |
public void testThenCombine_normalCompletion3() { |
866 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
867 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
868 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
869 |
> |
|
870 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
871 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
872 |
> |
final SubtractFunction r = new SubtractFunction(); |
873 |
> |
|
874 |
> |
g.complete(v2); |
875 |
> |
f.complete(v1); |
876 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
877 |
> |
|
878 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
879 |
> |
checkCompletedNormally(f, v1); |
880 |
> |
checkCompletedNormally(g, v2); |
881 |
> |
} |
882 |
> |
} |
883 |
|
|
884 |
< |
f = new CompletableFuture<>(); |
885 |
< |
g = new CompletableFuture<>(); |
886 |
< |
g.complete(1); |
887 |
< |
f.complete(3); |
888 |
< |
h = f.thenCombine(g, subtract); |
889 |
< |
checkCompletedNormally(h, 2); |
884 |
> |
public void testThenCombine_normalCompletion4() { |
885 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
886 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
887 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
888 |
> |
|
889 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
890 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
891 |
> |
final SubtractFunction r = new SubtractFunction(); |
892 |
> |
|
893 |
> |
f.complete(v1); |
894 |
> |
g.complete(v2); |
895 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
896 |
> |
|
897 |
> |
checkCompletedNormally(h, subtract(v1, v2)); |
898 |
> |
checkCompletedNormally(f, v1); |
899 |
> |
checkCompletedNormally(g, v2); |
900 |
> |
} |
901 |
|
} |
902 |
|
|
903 |
|
/** |
904 |
|
* thenCombine result completes exceptionally after exceptional |
905 |
|
* completion of either source |
906 |
|
*/ |
907 |
< |
public void testThenCombine2() { |
908 |
< |
CompletableFuture<Integer> f, g, h; |
909 |
< |
|
910 |
< |
f = new CompletableFuture<>(); |
911 |
< |
g = new CompletableFuture<>(); |
912 |
< |
h = f.thenCombine(g, subtract); |
913 |
< |
f.completeExceptionally(new CFException()); |
914 |
< |
checkIncomplete(h); |
915 |
< |
g.complete(1); |
916 |
< |
checkCompletedWithWrappedCFException(h); |
907 |
> |
public void testThenCombine_exceptionalCompletion1() { |
908 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
909 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
910 |
> |
|
911 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
912 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
913 |
> |
final SubtractFunction r = new SubtractFunction(); |
914 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
915 |
> |
final CFException ex = new CFException(); |
916 |
> |
|
917 |
> |
f.completeExceptionally(ex); |
918 |
> |
checkIncomplete(h); |
919 |
> |
g.complete(v1); |
920 |
> |
|
921 |
> |
checkCompletedWithWrappedCFException(h, ex); |
922 |
> |
checkCompletedWithWrappedCFException(f, ex); |
923 |
> |
assertFalse(r.ran()); |
924 |
> |
checkCompletedNormally(g, v1); |
925 |
> |
} |
926 |
> |
} |
927 |
|
|
928 |
< |
f = new CompletableFuture<>(); |
929 |
< |
g = new CompletableFuture<>(); |
930 |
< |
h = f.thenCombine(g, subtract); |
931 |
< |
g.completeExceptionally(new CFException()); |
932 |
< |
checkIncomplete(h); |
933 |
< |
f.complete(3); |
934 |
< |
checkCompletedWithWrappedCFException(h); |
928 |
> |
public void testThenCombine_exceptionalCompletion2() { |
929 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
930 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
931 |
> |
|
932 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
933 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
934 |
> |
final SubtractFunction r = new SubtractFunction(); |
935 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
936 |
> |
final CFException ex = new CFException(); |
937 |
> |
|
938 |
> |
g.completeExceptionally(ex); |
939 |
> |
checkIncomplete(h); |
940 |
> |
f.complete(v1); |
941 |
> |
|
942 |
> |
checkCompletedWithWrappedCFException(h, ex); |
943 |
> |
checkCompletedWithWrappedCFException(g, ex); |
944 |
> |
assertFalse(r.ran()); |
945 |
> |
checkCompletedNormally(f, v1); |
946 |
> |
} |
947 |
> |
} |
948 |
|
|
949 |
< |
f = new CompletableFuture<>(); |
950 |
< |
g = new CompletableFuture<>(); |
951 |
< |
f.complete(3); |
952 |
< |
g.completeExceptionally(new CFException()); |
953 |
< |
h = f.thenCombine(g, subtract); |
954 |
< |
checkCompletedWithWrappedCFException(h); |
949 |
> |
public void testThenCombine_exceptionalCompletion3() { |
950 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
951 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
952 |
> |
|
953 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
954 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
955 |
> |
final SubtractFunction r = new SubtractFunction(); |
956 |
> |
final CFException ex = new CFException(); |
957 |
> |
|
958 |
> |
g.completeExceptionally(ex); |
959 |
> |
f.complete(v1); |
960 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
961 |
> |
|
962 |
> |
checkCompletedWithWrappedCFException(h, ex); |
963 |
> |
checkCompletedWithWrappedCFException(g, ex); |
964 |
> |
assertFalse(r.ran()); |
965 |
> |
checkCompletedNormally(f, v1); |
966 |
> |
} |
967 |
> |
} |
968 |
|
|
969 |
< |
f = new CompletableFuture<>(); |
970 |
< |
g = new CompletableFuture<>(); |
971 |
< |
f.completeExceptionally(new CFException()); |
972 |
< |
g.complete(3); |
973 |
< |
h = f.thenCombine(g, subtract); |
974 |
< |
checkCompletedWithWrappedCFException(h); |
969 |
> |
public void testThenCombine_exceptionalCompletion4() { |
970 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
971 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
972 |
> |
|
973 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
974 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
975 |
> |
final SubtractFunction r = new SubtractFunction(); |
976 |
> |
final CFException ex = new CFException(); |
977 |
> |
|
978 |
> |
f.completeExceptionally(ex); |
979 |
> |
g.complete(v1); |
980 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
981 |
> |
|
982 |
> |
checkCompletedWithWrappedCFException(h, ex); |
983 |
> |
checkCompletedWithWrappedCFException(f, ex); |
984 |
> |
assertFalse(r.ran()); |
985 |
> |
checkCompletedNormally(g, v1); |
986 |
> |
} |
987 |
|
} |
988 |
|
|
989 |
|
/** |
990 |
|
* thenCombine result completes exceptionally if action does |
991 |
|
*/ |
992 |
< |
public void testThenCombine3() { |
993 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
994 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
995 |
< |
FailingBiFunction r = new FailingBiFunction(); |
996 |
< |
CompletableFuture<Integer> g = f.thenCombine(f2, r); |
997 |
< |
f.complete(one); |
998 |
< |
checkIncomplete(g); |
999 |
< |
assertFalse(r.ran); |
1000 |
< |
f2.complete(two); |
1001 |
< |
checkCompletedWithWrappedCFException(g); |
1002 |
< |
assertTrue(r.ran); |
992 |
> |
public void testThenCombine_actionFailed1() { |
993 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
994 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
995 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
996 |
> |
|
997 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
998 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
999 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1000 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1001 |
> |
|
1002 |
> |
f.complete(v1); |
1003 |
> |
checkIncomplete(h); |
1004 |
> |
g.complete(v2); |
1005 |
> |
|
1006 |
> |
checkCompletedWithWrappedCFException(h); |
1007 |
> |
checkCompletedNormally(f, v1); |
1008 |
> |
checkCompletedNormally(g, v2); |
1009 |
> |
} |
1010 |
> |
} |
1011 |
> |
|
1012 |
> |
public void testThenCombine_actionFailed2() { |
1013 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1014 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1015 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1016 |
> |
|
1017 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1018 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1019 |
> |
final FailingBiFunction r = new FailingBiFunction(); |
1020 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1021 |
> |
|
1022 |
> |
g.complete(v2); |
1023 |
> |
checkIncomplete(h); |
1024 |
> |
f.complete(v1); |
1025 |
> |
|
1026 |
> |
checkCompletedWithWrappedCFException(h); |
1027 |
> |
checkCompletedNormally(f, v1); |
1028 |
> |
checkCompletedNormally(g, v2); |
1029 |
> |
} |
1030 |
|
} |
1031 |
|
|
1032 |
|
/** |
1033 |
|
* thenCombine result completes exceptionally if either source cancelled |
1034 |
|
*/ |
1035 |
< |
public void testThenCombine4() { |
1036 |
< |
CompletableFuture<Integer> f, g, h; |
1035 |
> |
public void testThenCombine_sourceCancelled1() { |
1036 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1037 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1038 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1039 |
> |
|
1040 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1041 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1042 |
> |
final SubtractFunction r = new SubtractFunction(); |
1043 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1044 |
|
|
1045 |
< |
f = new CompletableFuture<>(); |
759 |
< |
g = new CompletableFuture<>(); |
760 |
< |
h = f.thenCombine(g, subtract); |
761 |
< |
assertTrue(f.cancel(true)); |
1045 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1046 |
|
checkIncomplete(h); |
1047 |
< |
g.complete(1); |
1047 |
> |
g.complete(v1); |
1048 |
> |
|
1049 |
|
checkCompletedWithWrappedCancellationException(h); |
1050 |
+ |
checkCancelled(f); |
1051 |
+ |
assertFalse(r.ran()); |
1052 |
+ |
checkCompletedNormally(g, v1); |
1053 |
+ |
} |
1054 |
+ |
} |
1055 |
|
|
1056 |
< |
f = new CompletableFuture<>(); |
1057 |
< |
g = new CompletableFuture<>(); |
1058 |
< |
h = f.thenCombine(g, subtract); |
1059 |
< |
assertTrue(g.cancel(true)); |
1056 |
> |
public void testThenCombine_sourceCancelled2() { |
1057 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1058 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1059 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1060 |
> |
|
1061 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1062 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1063 |
> |
final SubtractFunction r = new SubtractFunction(); |
1064 |
> |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1065 |
> |
|
1066 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1067 |
|
checkIncomplete(h); |
1068 |
< |
f.complete(3); |
1068 |
> |
f.complete(v1); |
1069 |
> |
|
1070 |
|
checkCompletedWithWrappedCancellationException(h); |
1071 |
+ |
checkCancelled(g); |
1072 |
+ |
assertFalse(r.ran()); |
1073 |
+ |
checkCompletedNormally(f, v1); |
1074 |
+ |
} |
1075 |
+ |
} |
1076 |
+ |
|
1077 |
+ |
public void testThenCombine_sourceCancelled3() { |
1078 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1079 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1080 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1081 |
+ |
|
1082 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1083 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1084 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1085 |
+ |
|
1086 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1087 |
+ |
f.complete(v1); |
1088 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1089 |
+ |
|
1090 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1091 |
+ |
checkCancelled(g); |
1092 |
+ |
assertFalse(r.ran()); |
1093 |
+ |
checkCompletedNormally(f, v1); |
1094 |
+ |
} |
1095 |
+ |
} |
1096 |
+ |
|
1097 |
+ |
public void testThenCombine_sourceCancelled4() { |
1098 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1099 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1100 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1101 |
+ |
|
1102 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1103 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1104 |
+ |
final SubtractFunction r = new SubtractFunction(); |
1105 |
+ |
|
1106 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1107 |
+ |
g.complete(v1); |
1108 |
+ |
final CompletableFuture<Integer> h = m.thenCombine(f, g, r); |
1109 |
|
|
774 |
– |
f = new CompletableFuture<>(); |
775 |
– |
g = new CompletableFuture<>(); |
776 |
– |
assertTrue(f.cancel(true)); |
777 |
– |
assertTrue(g.cancel(true)); |
778 |
– |
h = f.thenCombine(g, subtract); |
1110 |
|
checkCompletedWithWrappedCancellationException(h); |
1111 |
+ |
checkCancelled(f); |
1112 |
+ |
assertFalse(r.ran()); |
1113 |
+ |
checkCompletedNormally(g, v1); |
1114 |
+ |
} |
1115 |
|
} |
1116 |
|
|
1117 |
|
/** |
1118 |
|
* thenAcceptBoth result completes normally after normal |
1119 |
|
* completion of sources |
1120 |
|
*/ |
1121 |
< |
public void testThenAcceptBoth() { |
1122 |
< |
CompletableFuture<Integer> f, g; |
1123 |
< |
CompletableFuture<Void> h; |
1124 |
< |
SubtractAction r; |
1121 |
> |
public void testThenAcceptBoth_normalCompletion1() { |
1122 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1123 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1124 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1125 |
> |
|
1126 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1127 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1128 |
> |
final SubtractAction r = new SubtractAction(); |
1129 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1130 |
|
|
1131 |
< |
f = new CompletableFuture<>(); |
792 |
< |
g = new CompletableFuture<>(); |
793 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
794 |
< |
f.complete(3); |
1131 |
> |
f.complete(v1); |
1132 |
|
checkIncomplete(h); |
1133 |
< |
g.complete(1); |
1133 |
> |
assertFalse(r.ran()); |
1134 |
> |
g.complete(v2); |
1135 |
> |
|
1136 |
|
checkCompletedNormally(h, null); |
1137 |
< |
assertEquals(r.value, 2); |
1137 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1138 |
> |
checkCompletedNormally(f, v1); |
1139 |
> |
checkCompletedNormally(g, v2); |
1140 |
> |
} |
1141 |
> |
} |
1142 |
|
|
1143 |
< |
f = new CompletableFuture<>(); |
1144 |
< |
g = new CompletableFuture<>(); |
1145 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1146 |
< |
g.complete(1); |
1143 |
> |
public void testThenAcceptBoth_normalCompletion2() { |
1144 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1145 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1146 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1147 |
> |
|
1148 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1149 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1150 |
> |
final SubtractAction r = new SubtractAction(); |
1151 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1152 |
> |
|
1153 |
> |
g.complete(v2); |
1154 |
|
checkIncomplete(h); |
1155 |
< |
f.complete(3); |
1155 |
> |
assertFalse(r.ran()); |
1156 |
> |
f.complete(v1); |
1157 |
> |
|
1158 |
|
checkCompletedNormally(h, null); |
1159 |
< |
assertEquals(r.value, 2); |
1159 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1160 |
> |
checkCompletedNormally(f, v1); |
1161 |
> |
checkCompletedNormally(g, v2); |
1162 |
> |
} |
1163 |
> |
} |
1164 |
> |
|
1165 |
> |
public void testThenAcceptBoth_normalCompletion3() { |
1166 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1167 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1168 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1169 |
> |
|
1170 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1171 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1172 |
> |
final SubtractAction r = new SubtractAction(); |
1173 |
> |
|
1174 |
> |
g.complete(v2); |
1175 |
> |
f.complete(v1); |
1176 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1177 |
|
|
809 |
– |
f = new CompletableFuture<>(); |
810 |
– |
g = new CompletableFuture<>(); |
811 |
– |
g.complete(1); |
812 |
– |
f.complete(3); |
813 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1178 |
|
checkCompletedNormally(h, null); |
1179 |
< |
assertEquals(r.value, 2); |
1179 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1180 |
> |
checkCompletedNormally(f, v1); |
1181 |
> |
checkCompletedNormally(g, v2); |
1182 |
> |
} |
1183 |
> |
} |
1184 |
> |
|
1185 |
> |
public void testThenAcceptBoth_normalCompletion4() { |
1186 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1187 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1188 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1189 |
> |
|
1190 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1191 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1192 |
> |
final SubtractAction r = new SubtractAction(); |
1193 |
> |
|
1194 |
> |
f.complete(v1); |
1195 |
> |
g.complete(v2); |
1196 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1197 |
> |
|
1198 |
> |
checkCompletedNormally(h, null); |
1199 |
> |
assertEquals(r.value, subtract(v1, v2)); |
1200 |
> |
checkCompletedNormally(f, v1); |
1201 |
> |
checkCompletedNormally(g, v2); |
1202 |
> |
} |
1203 |
|
} |
1204 |
|
|
1205 |
|
/** |
1206 |
|
* thenAcceptBoth result completes exceptionally after exceptional |
1207 |
|
* completion of either source |
1208 |
|
*/ |
1209 |
< |
public void testThenAcceptBoth2() { |
1210 |
< |
CompletableFuture<Integer> f, g; |
1211 |
< |
CompletableFuture<Void> h; |
1212 |
< |
SubtractAction r; |
1213 |
< |
|
1214 |
< |
f = new CompletableFuture<>(); |
1215 |
< |
g = new CompletableFuture<>(); |
1216 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1217 |
< |
f.completeExceptionally(new CFException()); |
1218 |
< |
checkIncomplete(h); |
1219 |
< |
g.complete(1); |
1220 |
< |
checkCompletedWithWrappedCFException(h); |
1209 |
> |
public void testThenAcceptBoth_exceptionalCompletion1() { |
1210 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1211 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1212 |
> |
|
1213 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1214 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1215 |
> |
final SubtractAction r = new SubtractAction(); |
1216 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1217 |
> |
final CFException ex = new CFException(); |
1218 |
> |
|
1219 |
> |
f.completeExceptionally(ex); |
1220 |
> |
checkIncomplete(h); |
1221 |
> |
g.complete(v1); |
1222 |
> |
|
1223 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1224 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1225 |
> |
assertFalse(r.ran()); |
1226 |
> |
checkCompletedNormally(g, v1); |
1227 |
> |
} |
1228 |
> |
} |
1229 |
|
|
1230 |
< |
f = new CompletableFuture<>(); |
1231 |
< |
g = new CompletableFuture<>(); |
1232 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1233 |
< |
g.completeExceptionally(new CFException()); |
1234 |
< |
checkIncomplete(h); |
1235 |
< |
f.complete(3); |
1236 |
< |
checkCompletedWithWrappedCFException(h); |
1230 |
> |
public void testThenAcceptBoth_exceptionalCompletion2() { |
1231 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1232 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1233 |
> |
|
1234 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1235 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1236 |
> |
final SubtractAction r = new SubtractAction(); |
1237 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1238 |
> |
final CFException ex = new CFException(); |
1239 |
> |
|
1240 |
> |
g.completeExceptionally(ex); |
1241 |
> |
checkIncomplete(h); |
1242 |
> |
f.complete(v1); |
1243 |
> |
|
1244 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1245 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1246 |
> |
assertFalse(r.ran()); |
1247 |
> |
checkCompletedNormally(f, v1); |
1248 |
> |
} |
1249 |
> |
} |
1250 |
|
|
1251 |
< |
f = new CompletableFuture<>(); |
1252 |
< |
g = new CompletableFuture<>(); |
1253 |
< |
f.complete(3); |
1254 |
< |
g.completeExceptionally(new CFException()); |
1255 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1256 |
< |
checkCompletedWithWrappedCFException(h); |
1251 |
> |
public void testThenAcceptBoth_exceptionalCompletion3() { |
1252 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1253 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1254 |
> |
|
1255 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1256 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1257 |
> |
final SubtractAction r = new SubtractAction(); |
1258 |
> |
final CFException ex = new CFException(); |
1259 |
> |
|
1260 |
> |
g.completeExceptionally(ex); |
1261 |
> |
f.complete(v1); |
1262 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1263 |
> |
|
1264 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1265 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1266 |
> |
assertFalse(r.ran()); |
1267 |
> |
checkCompletedNormally(f, v1); |
1268 |
> |
} |
1269 |
> |
} |
1270 |
|
|
1271 |
< |
f = new CompletableFuture<>(); |
1272 |
< |
g = new CompletableFuture<>(); |
1273 |
< |
f.completeExceptionally(new CFException()); |
1274 |
< |
g.complete(3); |
1275 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1276 |
< |
checkCompletedWithWrappedCFException(h); |
1271 |
> |
public void testThenAcceptBoth_exceptionalCompletion4() { |
1272 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1273 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1274 |
> |
|
1275 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1276 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1277 |
> |
final SubtractAction r = new SubtractAction(); |
1278 |
> |
final CFException ex = new CFException(); |
1279 |
> |
|
1280 |
> |
f.completeExceptionally(ex); |
1281 |
> |
g.complete(v1); |
1282 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1283 |
> |
|
1284 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1285 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1286 |
> |
assertFalse(r.ran()); |
1287 |
> |
checkCompletedNormally(g, v1); |
1288 |
> |
} |
1289 |
|
} |
1290 |
|
|
1291 |
|
/** |
1292 |
|
* thenAcceptBoth result completes exceptionally if action does |
1293 |
|
*/ |
1294 |
< |
public void testThenAcceptBoth3() { |
1295 |
< |
CompletableFuture<Integer> f, g; |
1296 |
< |
CompletableFuture<Void> h; |
1297 |
< |
FailingBiConsumer r; |
1294 |
> |
public void testThenAcceptBoth_actionFailed1() { |
1295 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1296 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1297 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1298 |
|
|
1299 |
< |
f = new CompletableFuture<>(); |
1300 |
< |
g = new CompletableFuture<>(); |
1301 |
< |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1302 |
< |
f.complete(3); |
1299 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1300 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1301 |
> |
final FailingBiConsumer r = new FailingBiConsumer(); |
1302 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1303 |
> |
|
1304 |
> |
f.complete(v1); |
1305 |
|
checkIncomplete(h); |
1306 |
< |
g.complete(1); |
1306 |
> |
g.complete(v2); |
1307 |
> |
|
1308 |
|
checkCompletedWithWrappedCFException(h); |
1309 |
+ |
checkCompletedNormally(f, v1); |
1310 |
+ |
checkCompletedNormally(g, v2); |
1311 |
+ |
} |
1312 |
+ |
} |
1313 |
+ |
|
1314 |
+ |
public void testThenAcceptBoth_actionFailed2() { |
1315 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1316 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1317 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1318 |
+ |
|
1319 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1320 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1321 |
+ |
final FailingBiConsumer r = new FailingBiConsumer(); |
1322 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1323 |
+ |
|
1324 |
+ |
g.complete(v2); |
1325 |
+ |
checkIncomplete(h); |
1326 |
+ |
f.complete(v1); |
1327 |
|
|
874 |
– |
f = new CompletableFuture<>(); |
875 |
– |
g = new CompletableFuture<>(); |
876 |
– |
f.complete(3); |
877 |
– |
g.complete(1); |
878 |
– |
h = f.thenAcceptBoth(g, r = new FailingBiConsumer()); |
1328 |
|
checkCompletedWithWrappedCFException(h); |
1329 |
+ |
checkCompletedNormally(f, v1); |
1330 |
+ |
checkCompletedNormally(g, v2); |
1331 |
+ |
} |
1332 |
|
} |
1333 |
|
|
1334 |
|
/** |
1335 |
|
* thenAcceptBoth result completes exceptionally if either source cancelled |
1336 |
|
*/ |
1337 |
< |
public void testThenAcceptBoth4() { |
1338 |
< |
CompletableFuture<Integer> f, g; |
1339 |
< |
CompletableFuture<Void> h; |
1340 |
< |
SubtractAction r; |
1337 |
> |
public void testThenAcceptBoth_sourceCancelled1() { |
1338 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1339 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1340 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1341 |
> |
|
1342 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1343 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1344 |
> |
final SubtractAction r = new SubtractAction(); |
1345 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1346 |
|
|
1347 |
< |
f = new CompletableFuture<>(); |
891 |
< |
g = new CompletableFuture<>(); |
892 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
893 |
< |
assertTrue(f.cancel(true)); |
1347 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1348 |
|
checkIncomplete(h); |
1349 |
< |
g.complete(1); |
1349 |
> |
g.complete(v1); |
1350 |
> |
|
1351 |
|
checkCompletedWithWrappedCancellationException(h); |
1352 |
+ |
checkCancelled(f); |
1353 |
+ |
assertFalse(r.ran()); |
1354 |
+ |
checkCompletedNormally(g, v1); |
1355 |
+ |
} |
1356 |
+ |
} |
1357 |
|
|
1358 |
< |
f = new CompletableFuture<>(); |
1359 |
< |
g = new CompletableFuture<>(); |
1360 |
< |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1361 |
< |
assertTrue(g.cancel(true)); |
1358 |
> |
public void testThenAcceptBoth_sourceCancelled2() { |
1359 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1360 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1361 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1362 |
> |
|
1363 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1364 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1365 |
> |
final SubtractAction r = new SubtractAction(); |
1366 |
> |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1367 |
> |
|
1368 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1369 |
|
checkIncomplete(h); |
1370 |
< |
f.complete(3); |
904 |
< |
checkCompletedWithWrappedCancellationException(h); |
1370 |
> |
f.complete(v1); |
1371 |
|
|
906 |
– |
f = new CompletableFuture<>(); |
907 |
– |
g = new CompletableFuture<>(); |
908 |
– |
f.complete(3); |
909 |
– |
assertTrue(g.cancel(true)); |
910 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1372 |
|
checkCompletedWithWrappedCancellationException(h); |
1373 |
+ |
checkCancelled(g); |
1374 |
+ |
assertFalse(r.ran()); |
1375 |
+ |
checkCompletedNormally(f, v1); |
1376 |
+ |
} |
1377 |
+ |
} |
1378 |
+ |
|
1379 |
+ |
public void testThenAcceptBoth_sourceCancelled3() { |
1380 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1381 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1382 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1383 |
+ |
|
1384 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1385 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1386 |
+ |
final SubtractAction r = new SubtractAction(); |
1387 |
+ |
|
1388 |
+ |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1389 |
+ |
f.complete(v1); |
1390 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1391 |
+ |
|
1392 |
+ |
checkCompletedWithWrappedCancellationException(h); |
1393 |
+ |
checkCancelled(g); |
1394 |
+ |
assertFalse(r.ran()); |
1395 |
+ |
checkCompletedNormally(f, v1); |
1396 |
+ |
} |
1397 |
+ |
} |
1398 |
+ |
|
1399 |
+ |
public void testThenAcceptBoth_sourceCancelled4() { |
1400 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1401 |
+ |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1402 |
+ |
for (Integer v1 : new Integer[] { 1, null }) { |
1403 |
+ |
|
1404 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1405 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1406 |
+ |
final SubtractAction r = new SubtractAction(); |
1407 |
+ |
|
1408 |
+ |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1409 |
+ |
g.complete(v1); |
1410 |
+ |
final CompletableFuture<Void> h = m.thenAcceptBoth(f, g, r); |
1411 |
|
|
913 |
– |
f = new CompletableFuture<>(); |
914 |
– |
g = new CompletableFuture<>(); |
915 |
– |
assertTrue(f.cancel(true)); |
916 |
– |
g.complete(3); |
917 |
– |
h = f.thenAcceptBoth(g, r = new SubtractAction()); |
1412 |
|
checkCompletedWithWrappedCancellationException(h); |
1413 |
+ |
checkCancelled(f); |
1414 |
+ |
assertFalse(r.ran()); |
1415 |
+ |
checkCompletedNormally(g, v1); |
1416 |
+ |
} |
1417 |
|
} |
1418 |
|
|
1419 |
|
/** |
1420 |
|
* runAfterBoth result completes normally after normal |
1421 |
|
* completion of sources |
1422 |
|
*/ |
1423 |
< |
public void testRunAfterBoth() { |
1424 |
< |
CompletableFuture<Integer> f, g; |
1425 |
< |
CompletableFuture<Void> h; |
1426 |
< |
Noop r; |
1423 |
> |
public void testRunAfterBoth_normalCompletion1() { |
1424 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1425 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1426 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1427 |
> |
|
1428 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1429 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1430 |
> |
final Noop r = new Noop(); |
1431 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1432 |
|
|
1433 |
< |
f = new CompletableFuture<>(); |
931 |
< |
g = new CompletableFuture<>(); |
932 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
933 |
< |
f.complete(3); |
1433 |
> |
f.complete(v1); |
1434 |
|
checkIncomplete(h); |
1435 |
< |
g.complete(1); |
1435 |
> |
assertFalse(r.ran); |
1436 |
> |
g.complete(v2); |
1437 |
> |
|
1438 |
|
checkCompletedNormally(h, null); |
1439 |
|
assertTrue(r.ran); |
1440 |
+ |
checkCompletedNormally(f, v1); |
1441 |
+ |
checkCompletedNormally(g, v2); |
1442 |
+ |
} |
1443 |
+ |
} |
1444 |
|
|
1445 |
< |
f = new CompletableFuture<>(); |
1446 |
< |
g = new CompletableFuture<>(); |
1447 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1448 |
< |
g.complete(1); |
1445 |
> |
public void testRunAfterBoth_normalCompletion2() { |
1446 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1447 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1448 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1449 |
> |
|
1450 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1451 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1452 |
> |
final Noop r = new Noop(); |
1453 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1454 |
> |
|
1455 |
> |
g.complete(v2); |
1456 |
|
checkIncomplete(h); |
1457 |
< |
f.complete(3); |
1457 |
> |
assertFalse(r.ran); |
1458 |
> |
f.complete(v1); |
1459 |
> |
|
1460 |
|
checkCompletedNormally(h, null); |
1461 |
|
assertTrue(r.ran); |
1462 |
+ |
checkCompletedNormally(f, v1); |
1463 |
+ |
checkCompletedNormally(g, v2); |
1464 |
+ |
} |
1465 |
+ |
} |
1466 |
+ |
|
1467 |
+ |
public void testRunAfterBoth_normalCompletion3() { |
1468 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1469 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1470 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1471 |
+ |
|
1472 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1473 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1474 |
+ |
final Noop r = new Noop(); |
1475 |
+ |
|
1476 |
+ |
g.complete(v2); |
1477 |
+ |
f.complete(v1); |
1478 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1479 |
|
|
948 |
– |
f = new CompletableFuture<>(); |
949 |
– |
g = new CompletableFuture<>(); |
950 |
– |
g.complete(1); |
951 |
– |
f.complete(3); |
952 |
– |
h = f.runAfterBoth(g, r = new Noop()); |
1480 |
|
checkCompletedNormally(h, null); |
1481 |
|
assertTrue(r.ran); |
1482 |
+ |
checkCompletedNormally(f, v1); |
1483 |
+ |
checkCompletedNormally(g, v2); |
1484 |
+ |
} |
1485 |
+ |
} |
1486 |
+ |
|
1487 |
+ |
public void testRunAfterBoth_normalCompletion4() { |
1488 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1489 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1490 |
+ |
for (Integer v2 : new Integer[] { 2, null }) { |
1491 |
+ |
|
1492 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1493 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1494 |
+ |
final Noop r = new Noop(); |
1495 |
+ |
|
1496 |
+ |
f.complete(v1); |
1497 |
+ |
g.complete(v2); |
1498 |
+ |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1499 |
+ |
|
1500 |
+ |
checkCompletedNormally(h, null); |
1501 |
+ |
assertTrue(r.ran); |
1502 |
+ |
checkCompletedNormally(f, v1); |
1503 |
+ |
checkCompletedNormally(g, v2); |
1504 |
+ |
} |
1505 |
|
} |
1506 |
|
|
1507 |
|
/** |
1508 |
|
* runAfterBoth result completes exceptionally after exceptional |
1509 |
|
* completion of either source |
1510 |
|
*/ |
1511 |
< |
public void testRunAfterBoth2() { |
1512 |
< |
CompletableFuture<Integer> f, g; |
1513 |
< |
CompletableFuture<Void> h; |
1514 |
< |
Noop r; |
1511 |
> |
public void testRunAfterBoth_exceptionalCompletion1() { |
1512 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1513 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1514 |
> |
|
1515 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1516 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1517 |
> |
final Noop r = new Noop(); |
1518 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1519 |
> |
final CFException ex = new CFException(); |
1520 |
|
|
1521 |
< |
f = new CompletableFuture<>(); |
967 |
< |
g = new CompletableFuture<>(); |
968 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
969 |
< |
f.completeExceptionally(new CFException()); |
1521 |
> |
f.completeExceptionally(ex); |
1522 |
|
checkIncomplete(h); |
1523 |
< |
g.complete(1); |
1524 |
< |
checkCompletedWithWrappedCFException(h); |
1523 |
> |
g.complete(v1); |
1524 |
> |
|
1525 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1526 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1527 |
|
assertFalse(r.ran); |
1528 |
+ |
checkCompletedNormally(g, v1); |
1529 |
+ |
} |
1530 |
+ |
} |
1531 |
|
|
1532 |
< |
f = new CompletableFuture<>(); |
1533 |
< |
g = new CompletableFuture<>(); |
1534 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1535 |
< |
g.completeExceptionally(new CFException()); |
1532 |
> |
public void testRunAfterBoth_exceptionalCompletion2() { |
1533 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1534 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1535 |
> |
|
1536 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1537 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1538 |
> |
final Noop r = new Noop(); |
1539 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1540 |
> |
final CFException ex = new CFException(); |
1541 |
> |
|
1542 |
> |
g.completeExceptionally(ex); |
1543 |
|
checkIncomplete(h); |
1544 |
< |
f.complete(3); |
1545 |
< |
checkCompletedWithWrappedCFException(h); |
1544 |
> |
f.complete(v1); |
1545 |
> |
|
1546 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1547 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1548 |
|
assertFalse(r.ran); |
1549 |
+ |
checkCompletedNormally(f, v1); |
1550 |
+ |
} |
1551 |
+ |
} |
1552 |
|
|
1553 |
< |
f = new CompletableFuture<>(); |
1554 |
< |
g = new CompletableFuture<>(); |
1555 |
< |
g.completeExceptionally(new CFException()); |
1556 |
< |
f.complete(3); |
1557 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1558 |
< |
checkCompletedWithWrappedCFException(h); |
1553 |
> |
public void testRunAfterBoth_exceptionalCompletion3() { |
1554 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1555 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1556 |
> |
|
1557 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1558 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1559 |
> |
final Noop r = new Noop(); |
1560 |
> |
final CFException ex = new CFException(); |
1561 |
> |
|
1562 |
> |
g.completeExceptionally(ex); |
1563 |
> |
f.complete(v1); |
1564 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1565 |
> |
|
1566 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1567 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1568 |
|
assertFalse(r.ran); |
1569 |
+ |
checkCompletedNormally(f, v1); |
1570 |
+ |
} |
1571 |
+ |
} |
1572 |
|
|
1573 |
< |
f = new CompletableFuture<>(); |
1574 |
< |
g = new CompletableFuture<>(); |
1575 |
< |
f.completeExceptionally(new CFException()); |
1576 |
< |
g.complete(1); |
1577 |
< |
h = f.runAfterBoth(g, r = new Noop()); |
1578 |
< |
checkCompletedWithWrappedCFException(h); |
1573 |
> |
public void testRunAfterBoth_exceptionalCompletion4() { |
1574 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1575 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1576 |
> |
|
1577 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1578 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1579 |
> |
final Noop r = new Noop(); |
1580 |
> |
final CFException ex = new CFException(); |
1581 |
> |
|
1582 |
> |
f.completeExceptionally(ex); |
1583 |
> |
g.complete(v1); |
1584 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1585 |
> |
|
1586 |
> |
checkCompletedWithWrappedCFException(h, ex); |
1587 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1588 |
|
assertFalse(r.ran); |
1589 |
+ |
checkCompletedNormally(g, v1); |
1590 |
+ |
} |
1591 |
|
} |
1592 |
|
|
1593 |
|
/** |
1594 |
|
* runAfterBoth result completes exceptionally if action does |
1595 |
|
*/ |
1596 |
< |
public void testRunAfterBoth3() { |
1597 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1598 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1599 |
< |
FailingNoop r = new FailingNoop(); |
1600 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1601 |
< |
f.complete(one); |
1602 |
< |
checkIncomplete(g); |
1603 |
< |
f2.complete(two); |
1604 |
< |
checkCompletedWithWrappedCFException(g); |
1596 |
> |
public void testRunAfterBoth_actionFailed1() { |
1597 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1598 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1599 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1600 |
> |
|
1601 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1602 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1603 |
> |
final FailingNoop r = new FailingNoop(); |
1604 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1605 |
> |
|
1606 |
> |
f.complete(v1); |
1607 |
> |
checkIncomplete(h); |
1608 |
> |
g.complete(v2); |
1609 |
> |
|
1610 |
> |
checkCompletedWithWrappedCFException(h); |
1611 |
> |
checkCompletedNormally(f, v1); |
1612 |
> |
checkCompletedNormally(g, v2); |
1613 |
> |
} |
1614 |
> |
} |
1615 |
> |
|
1616 |
> |
public void testRunAfterBoth_actionFailed2() { |
1617 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1618 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1619 |
> |
for (Integer v2 : new Integer[] { 2, null }) { |
1620 |
> |
|
1621 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1622 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1623 |
> |
final FailingNoop r = new FailingNoop(); |
1624 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1625 |
> |
|
1626 |
> |
g.complete(v2); |
1627 |
> |
checkIncomplete(h); |
1628 |
> |
f.complete(v1); |
1629 |
> |
|
1630 |
> |
checkCompletedWithWrappedCFException(h); |
1631 |
> |
checkCompletedNormally(f, v1); |
1632 |
> |
checkCompletedNormally(g, v2); |
1633 |
> |
} |
1634 |
|
} |
1635 |
|
|
1636 |
|
/** |
1637 |
|
* runAfterBoth result completes exceptionally if either source cancelled |
1638 |
|
*/ |
1639 |
< |
public void testRunAfterBoth4() { |
1640 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1641 |
< |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1642 |
< |
Noop r = new Noop(); |
1643 |
< |
CompletableFuture<Void> g = f.runAfterBoth(f2, r); |
1644 |
< |
assertTrue(f.cancel(true)); |
1645 |
< |
f2.complete(two); |
1646 |
< |
checkCompletedWithWrappedCancellationException(g); |
1647 |
< |
f = new CompletableFuture<>(); |
1648 |
< |
f2 = new CompletableFuture<>(); |
1649 |
< |
r = new Noop(); |
1650 |
< |
g = f.runAfterBoth(f2, r); |
1651 |
< |
f.complete(one); |
1652 |
< |
assertTrue(f2.cancel(true)); |
1653 |
< |
checkCompletedWithWrappedCancellationException(g); |
1639 |
> |
public void testRunAfterBoth_sourceCancelled1() { |
1640 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1641 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1642 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1643 |
> |
|
1644 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1645 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1646 |
> |
final Noop r = new Noop(); |
1647 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1648 |
> |
|
1649 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1650 |
> |
checkIncomplete(h); |
1651 |
> |
g.complete(v1); |
1652 |
> |
|
1653 |
> |
checkCompletedWithWrappedCancellationException(h); |
1654 |
> |
checkCancelled(f); |
1655 |
> |
assertFalse(r.ran); |
1656 |
> |
checkCompletedNormally(g, v1); |
1657 |
> |
} |
1658 |
> |
} |
1659 |
> |
|
1660 |
> |
public void testRunAfterBoth_sourceCancelled2() { |
1661 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1662 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1663 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1664 |
> |
|
1665 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1666 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1667 |
> |
final Noop r = new Noop(); |
1668 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1669 |
> |
|
1670 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1671 |
> |
checkIncomplete(h); |
1672 |
> |
f.complete(v1); |
1673 |
> |
|
1674 |
> |
checkCompletedWithWrappedCancellationException(h); |
1675 |
> |
checkCancelled(g); |
1676 |
> |
assertFalse(r.ran); |
1677 |
> |
checkCompletedNormally(f, v1); |
1678 |
> |
} |
1679 |
> |
} |
1680 |
> |
|
1681 |
> |
public void testRunAfterBoth_sourceCancelled3() { |
1682 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1683 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1684 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1685 |
> |
|
1686 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1687 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1688 |
> |
final Noop r = new Noop(); |
1689 |
> |
|
1690 |
> |
assertTrue(g.cancel(mayInterruptIfRunning)); |
1691 |
> |
f.complete(v1); |
1692 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1693 |
> |
|
1694 |
> |
checkCompletedWithWrappedCancellationException(h); |
1695 |
> |
checkCancelled(g); |
1696 |
> |
assertFalse(r.ran); |
1697 |
> |
checkCompletedNormally(f, v1); |
1698 |
> |
} |
1699 |
> |
} |
1700 |
> |
|
1701 |
> |
public void testRunAfterBoth_sourceCancelled4() { |
1702 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1703 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1704 |
> |
for (Integer v1 : new Integer[] { 1, null }) { |
1705 |
> |
|
1706 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1707 |
> |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1708 |
> |
final Noop r = new Noop(); |
1709 |
> |
|
1710 |
> |
assertTrue(f.cancel(mayInterruptIfRunning)); |
1711 |
> |
g.complete(v1); |
1712 |
> |
final CompletableFuture<Void> h = m.runAfterBoth(f, g, r); |
1713 |
> |
|
1714 |
> |
checkCompletedWithWrappedCancellationException(h); |
1715 |
> |
checkCancelled(f); |
1716 |
> |
assertFalse(r.ran); |
1717 |
> |
checkCompletedNormally(g, v1); |
1718 |
> |
} |
1719 |
|
} |
1720 |
|
|
1721 |
|
/** |
1857 |
|
checkCompletedWithWrappedCancellationException(g); |
1858 |
|
} |
1859 |
|
|
1174 |
– |
|
1860 |
|
/** |
1861 |
|
* runAfterEither result completes normally after normal completion |
1862 |
|
* of either source |
2005 |
|
checkCompletedWithWrappedCancellationException(g); |
2006 |
|
} |
2007 |
|
|
1323 |
– |
|
2008 |
|
// asyncs |
2009 |
|
|
2010 |
|
/** |
2037 |
|
try { |
2038 |
|
g.join(); |
2039 |
|
shouldThrow(); |
2040 |
< |
} catch (Exception ok) { |
1357 |
< |
} |
2040 |
> |
} catch (CompletionException success) {} |
2041 |
|
checkCompletedWithWrappedCFException(g); |
2042 |
|
} |
2043 |
|
|
2153 |
|
} |
2154 |
|
|
2155 |
|
/** |
1473 |
– |
* thenCombineAsync result completes normally after normal |
1474 |
– |
* completion of sources |
1475 |
– |
*/ |
1476 |
– |
public void testThenCombineAsync() { |
1477 |
– |
CompletableFuture<Integer> f, g, h; |
1478 |
– |
|
1479 |
– |
f = new CompletableFuture<>(); |
1480 |
– |
g = new CompletableFuture<>(); |
1481 |
– |
h = f.thenCombineAsync(g, subtract); |
1482 |
– |
f.complete(3); |
1483 |
– |
checkIncomplete(h); |
1484 |
– |
g.complete(1); |
1485 |
– |
checkCompletedNormally(h, 2); |
1486 |
– |
|
1487 |
– |
f = new CompletableFuture<>(); |
1488 |
– |
g = new CompletableFuture<>(); |
1489 |
– |
h = f.thenCombineAsync(g, subtract); |
1490 |
– |
g.complete(1); |
1491 |
– |
checkIncomplete(h); |
1492 |
– |
f.complete(3); |
1493 |
– |
checkCompletedNormally(h, 2); |
1494 |
– |
|
1495 |
– |
f = new CompletableFuture<>(); |
1496 |
– |
g = new CompletableFuture<>(); |
1497 |
– |
g.complete(1); |
1498 |
– |
f.complete(3); |
1499 |
– |
h = f.thenCombineAsync(g, subtract); |
1500 |
– |
checkCompletedNormally(h, 2); |
1501 |
– |
} |
1502 |
– |
|
1503 |
– |
/** |
1504 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
1505 |
– |
* completion of either source |
1506 |
– |
*/ |
1507 |
– |
public void testThenCombineAsync2() { |
1508 |
– |
CompletableFuture<Integer> f, g, h; |
1509 |
– |
|
1510 |
– |
f = new CompletableFuture<>(); |
1511 |
– |
g = new CompletableFuture<>(); |
1512 |
– |
h = f.thenCombineAsync(g, subtract); |
1513 |
– |
f.completeExceptionally(new CFException()); |
1514 |
– |
checkIncomplete(h); |
1515 |
– |
g.complete(1); |
1516 |
– |
checkCompletedWithWrappedCFException(h); |
1517 |
– |
|
1518 |
– |
f = new CompletableFuture<>(); |
1519 |
– |
g = new CompletableFuture<>(); |
1520 |
– |
h = f.thenCombineAsync(g, subtract); |
1521 |
– |
g.completeExceptionally(new CFException()); |
1522 |
– |
checkIncomplete(h); |
1523 |
– |
f.complete(3); |
1524 |
– |
checkCompletedWithWrappedCFException(h); |
1525 |
– |
|
1526 |
– |
f = new CompletableFuture<>(); |
1527 |
– |
g = new CompletableFuture<>(); |
1528 |
– |
g.completeExceptionally(new CFException()); |
1529 |
– |
f.complete(3); |
1530 |
– |
h = f.thenCombineAsync(g, subtract); |
1531 |
– |
checkCompletedWithWrappedCFException(h); |
1532 |
– |
} |
1533 |
– |
|
1534 |
– |
/** |
1535 |
– |
* thenCombineAsync result completes exceptionally if action does |
1536 |
– |
*/ |
1537 |
– |
public void testThenCombineAsync3() { |
1538 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1539 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1540 |
– |
FailingBiFunction r = new FailingBiFunction(); |
1541 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r); |
1542 |
– |
f.complete(one); |
1543 |
– |
checkIncomplete(g); |
1544 |
– |
assertFalse(r.ran); |
1545 |
– |
f2.complete(two); |
1546 |
– |
checkCompletedWithWrappedCFException(g); |
1547 |
– |
assertTrue(r.ran); |
1548 |
– |
} |
1549 |
– |
|
1550 |
– |
/** |
1551 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
1552 |
– |
*/ |
1553 |
– |
public void testThenCombineAsync4() { |
1554 |
– |
CompletableFuture<Integer> f, g, h; |
1555 |
– |
|
1556 |
– |
f = new CompletableFuture<>(); |
1557 |
– |
g = new CompletableFuture<>(); |
1558 |
– |
h = f.thenCombineAsync(g, subtract); |
1559 |
– |
assertTrue(f.cancel(true)); |
1560 |
– |
checkIncomplete(h); |
1561 |
– |
g.complete(1); |
1562 |
– |
checkCompletedWithWrappedCancellationException(h); |
1563 |
– |
|
1564 |
– |
f = new CompletableFuture<>(); |
1565 |
– |
g = new CompletableFuture<>(); |
1566 |
– |
h = f.thenCombineAsync(g, subtract); |
1567 |
– |
assertTrue(g.cancel(true)); |
1568 |
– |
checkIncomplete(h); |
1569 |
– |
f.complete(3); |
1570 |
– |
checkCompletedWithWrappedCancellationException(h); |
1571 |
– |
|
1572 |
– |
f = new CompletableFuture<>(); |
1573 |
– |
g = new CompletableFuture<>(); |
1574 |
– |
g.complete(3); |
1575 |
– |
assertTrue(f.cancel(true)); |
1576 |
– |
h = f.thenCombineAsync(g, subtract); |
1577 |
– |
checkCompletedWithWrappedCancellationException(h); |
1578 |
– |
|
1579 |
– |
f = new CompletableFuture<>(); |
1580 |
– |
g = new CompletableFuture<>(); |
1581 |
– |
f.complete(3); |
1582 |
– |
assertTrue(g.cancel(true)); |
1583 |
– |
h = f.thenCombineAsync(g, subtract); |
1584 |
– |
checkCompletedWithWrappedCancellationException(h); |
1585 |
– |
} |
1586 |
– |
|
1587 |
– |
/** |
1588 |
– |
* thenAcceptBothAsync result completes normally after normal |
1589 |
– |
* completion of sources |
1590 |
– |
*/ |
1591 |
– |
public void testThenAcceptBothAsync() { |
1592 |
– |
CompletableFuture<Integer> f, g; |
1593 |
– |
CompletableFuture<Void> h; |
1594 |
– |
SubtractAction r; |
1595 |
– |
|
1596 |
– |
f = new CompletableFuture<>(); |
1597 |
– |
g = new CompletableFuture<>(); |
1598 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1599 |
– |
f.complete(3); |
1600 |
– |
checkIncomplete(h); |
1601 |
– |
g.complete(1); |
1602 |
– |
checkCompletedNormally(h, null); |
1603 |
– |
assertEquals(r.value, 2); |
1604 |
– |
|
1605 |
– |
f = new CompletableFuture<>(); |
1606 |
– |
g = new CompletableFuture<>(); |
1607 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1608 |
– |
g.complete(1); |
1609 |
– |
checkIncomplete(h); |
1610 |
– |
f.complete(3); |
1611 |
– |
checkCompletedNormally(h, null); |
1612 |
– |
assertEquals(r.value, 2); |
1613 |
– |
|
1614 |
– |
f = new CompletableFuture<>(); |
1615 |
– |
g = new CompletableFuture<>(); |
1616 |
– |
g.complete(1); |
1617 |
– |
f.complete(3); |
1618 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1619 |
– |
checkCompletedNormally(h, null); |
1620 |
– |
assertEquals(r.value, 2); |
1621 |
– |
} |
1622 |
– |
|
1623 |
– |
/** |
1624 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
1625 |
– |
* completion of source |
1626 |
– |
*/ |
1627 |
– |
public void testThenAcceptBothAsync2() { |
1628 |
– |
CompletableFuture<Integer> f, g; |
1629 |
– |
CompletableFuture<Void> h; |
1630 |
– |
SubtractAction r; |
1631 |
– |
|
1632 |
– |
f = new CompletableFuture<>(); |
1633 |
– |
g = new CompletableFuture<>(); |
1634 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1635 |
– |
f.completeExceptionally(new CFException()); |
1636 |
– |
checkIncomplete(h); |
1637 |
– |
g.complete(1); |
1638 |
– |
checkCompletedWithWrappedCFException(h); |
1639 |
– |
|
1640 |
– |
f = new CompletableFuture<>(); |
1641 |
– |
g = new CompletableFuture<>(); |
1642 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1643 |
– |
g.completeExceptionally(new CFException()); |
1644 |
– |
checkIncomplete(h); |
1645 |
– |
f.complete(3); |
1646 |
– |
checkCompletedWithWrappedCFException(h); |
1647 |
– |
|
1648 |
– |
f = new CompletableFuture<>(); |
1649 |
– |
g = new CompletableFuture<>(); |
1650 |
– |
f.complete(3); |
1651 |
– |
g.completeExceptionally(new CFException()); |
1652 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1653 |
– |
checkCompletedWithWrappedCFException(h); |
1654 |
– |
|
1655 |
– |
f = new CompletableFuture<>(); |
1656 |
– |
g = new CompletableFuture<>(); |
1657 |
– |
f.completeExceptionally(new CFException()); |
1658 |
– |
g.complete(3); |
1659 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1660 |
– |
checkCompletedWithWrappedCFException(h); |
1661 |
– |
} |
1662 |
– |
|
1663 |
– |
/** |
1664 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
1665 |
– |
*/ |
1666 |
– |
public void testThenAcceptBothAsync3() { |
1667 |
– |
CompletableFuture<Integer> f, g; |
1668 |
– |
CompletableFuture<Void> h; |
1669 |
– |
FailingBiConsumer r; |
1670 |
– |
|
1671 |
– |
f = new CompletableFuture<>(); |
1672 |
– |
g = new CompletableFuture<>(); |
1673 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1674 |
– |
f.complete(3); |
1675 |
– |
checkIncomplete(h); |
1676 |
– |
g.complete(1); |
1677 |
– |
checkCompletedWithWrappedCFException(h); |
1678 |
– |
|
1679 |
– |
f = new CompletableFuture<>(); |
1680 |
– |
g = new CompletableFuture<>(); |
1681 |
– |
f.complete(3); |
1682 |
– |
g.complete(1); |
1683 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer()); |
1684 |
– |
checkCompletedWithWrappedCFException(h); |
1685 |
– |
} |
1686 |
– |
|
1687 |
– |
/** |
1688 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
1689 |
– |
*/ |
1690 |
– |
public void testThenAcceptBothAsync4() { |
1691 |
– |
CompletableFuture<Integer> f, g; |
1692 |
– |
CompletableFuture<Void> h; |
1693 |
– |
SubtractAction r; |
1694 |
– |
|
1695 |
– |
f = new CompletableFuture<>(); |
1696 |
– |
g = new CompletableFuture<>(); |
1697 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1698 |
– |
assertTrue(f.cancel(true)); |
1699 |
– |
checkIncomplete(h); |
1700 |
– |
g.complete(1); |
1701 |
– |
checkCompletedWithWrappedCancellationException(h); |
1702 |
– |
|
1703 |
– |
f = new CompletableFuture<>(); |
1704 |
– |
g = new CompletableFuture<>(); |
1705 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1706 |
– |
assertTrue(g.cancel(true)); |
1707 |
– |
checkIncomplete(h); |
1708 |
– |
f.complete(3); |
1709 |
– |
checkCompletedWithWrappedCancellationException(h); |
1710 |
– |
|
1711 |
– |
f = new CompletableFuture<>(); |
1712 |
– |
g = new CompletableFuture<>(); |
1713 |
– |
f.complete(3); |
1714 |
– |
assertTrue(g.cancel(true)); |
1715 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1716 |
– |
checkCompletedWithWrappedCancellationException(h); |
1717 |
– |
|
1718 |
– |
f = new CompletableFuture<>(); |
1719 |
– |
g = new CompletableFuture<>(); |
1720 |
– |
assertTrue(f.cancel(true)); |
1721 |
– |
g.complete(3); |
1722 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction()); |
1723 |
– |
checkCompletedWithWrappedCancellationException(h); |
1724 |
– |
} |
1725 |
– |
|
1726 |
– |
/** |
1727 |
– |
* runAfterBothAsync result completes normally after normal |
1728 |
– |
* completion of sources |
1729 |
– |
*/ |
1730 |
– |
public void testRunAfterBothAsync() { |
1731 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1732 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1733 |
– |
Noop r = new Noop(); |
1734 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1735 |
– |
f.complete(one); |
1736 |
– |
checkIncomplete(g); |
1737 |
– |
f2.complete(two); |
1738 |
– |
checkCompletedNormally(g, null); |
1739 |
– |
assertTrue(r.ran); |
1740 |
– |
} |
1741 |
– |
|
1742 |
– |
/** |
1743 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
1744 |
– |
* completion of source |
1745 |
– |
*/ |
1746 |
– |
public void testRunAfterBothAsync2() { |
1747 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1748 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1749 |
– |
Noop r = new Noop(); |
1750 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1751 |
– |
f.completeExceptionally(new CFException()); |
1752 |
– |
f2.complete(two); |
1753 |
– |
checkCompletedWithWrappedCFException(g); |
1754 |
– |
|
1755 |
– |
r = new Noop(); |
1756 |
– |
f = new CompletableFuture<>(); |
1757 |
– |
f2 = new CompletableFuture<>(); |
1758 |
– |
g = f.runAfterBothAsync(f2, r); |
1759 |
– |
f.complete(one); |
1760 |
– |
f2.completeExceptionally(new CFException()); |
1761 |
– |
checkCompletedWithWrappedCFException(g); |
1762 |
– |
} |
1763 |
– |
|
1764 |
– |
/** |
1765 |
– |
* runAfterBothAsync result completes exceptionally if action does |
1766 |
– |
*/ |
1767 |
– |
public void testRunAfterBothAsync3() { |
1768 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1769 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1770 |
– |
FailingNoop r = new FailingNoop(); |
1771 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1772 |
– |
f.complete(one); |
1773 |
– |
checkIncomplete(g); |
1774 |
– |
f2.complete(two); |
1775 |
– |
checkCompletedWithWrappedCFException(g); |
1776 |
– |
} |
1777 |
– |
|
1778 |
– |
/** |
1779 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
1780 |
– |
*/ |
1781 |
– |
public void testRunAfterBothAsync4() { |
1782 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1783 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
1784 |
– |
Noop r = new Noop(); |
1785 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r); |
1786 |
– |
assertTrue(f.cancel(true)); |
1787 |
– |
f2.complete(two); |
1788 |
– |
checkCompletedWithWrappedCancellationException(g); |
1789 |
– |
|
1790 |
– |
r = new Noop(); |
1791 |
– |
f = new CompletableFuture<>(); |
1792 |
– |
f2 = new CompletableFuture<>(); |
1793 |
– |
g = f.runAfterBothAsync(f2, r); |
1794 |
– |
f.complete(one); |
1795 |
– |
assertTrue(f2.cancel(true)); |
1796 |
– |
checkCompletedWithWrappedCancellationException(g); |
1797 |
– |
} |
1798 |
– |
|
1799 |
– |
/** |
2156 |
|
* applyToEitherAsync result completes normally after normal |
2157 |
|
* completion of sources |
2158 |
|
*/ |
2444 |
|
checkCompletedWithWrappedCancellationException(g); |
2445 |
|
} |
2446 |
|
|
2091 |
– |
|
2447 |
|
// async with explicit executors |
2448 |
|
|
2449 |
|
/** |
2476 |
|
try { |
2477 |
|
g.join(); |
2478 |
|
shouldThrow(); |
2479 |
< |
} catch (Exception ok) { |
2125 |
< |
} |
2479 |
> |
} catch (CompletionException success) {} |
2480 |
|
checkCompletedWithWrappedCFException(g); |
2481 |
|
} |
2482 |
|
|
2592 |
|
} |
2593 |
|
|
2594 |
|
/** |
2241 |
– |
* thenCombineAsync result completes normally after normal |
2242 |
– |
* completion of sources |
2243 |
– |
*/ |
2244 |
– |
public void testThenCombineAsyncE() { |
2245 |
– |
CompletableFuture<Integer> f, g, h; |
2246 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2247 |
– |
int count = 0; |
2248 |
– |
|
2249 |
– |
f = new CompletableFuture<>(); |
2250 |
– |
g = new CompletableFuture<>(); |
2251 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2252 |
– |
f.complete(3); |
2253 |
– |
checkIncomplete(h); |
2254 |
– |
g.complete(1); |
2255 |
– |
checkCompletedNormally(h, 2); |
2256 |
– |
assertEquals(++count, e.count.get()); |
2257 |
– |
|
2258 |
– |
f = new CompletableFuture<>(); |
2259 |
– |
g = new CompletableFuture<>(); |
2260 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2261 |
– |
g.complete(1); |
2262 |
– |
checkIncomplete(h); |
2263 |
– |
f.complete(3); |
2264 |
– |
checkCompletedNormally(h, 2); |
2265 |
– |
assertEquals(++count, e.count.get()); |
2266 |
– |
|
2267 |
– |
f = new CompletableFuture<>(); |
2268 |
– |
g = new CompletableFuture<>(); |
2269 |
– |
g.complete(1); |
2270 |
– |
f.complete(3); |
2271 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2272 |
– |
checkCompletedNormally(h, 2); |
2273 |
– |
assertEquals(++count, e.count.get()); |
2274 |
– |
} |
2275 |
– |
|
2276 |
– |
/** |
2277 |
– |
* thenCombineAsync result completes exceptionally after exceptional |
2278 |
– |
* completion of either source |
2279 |
– |
*/ |
2280 |
– |
public void testThenCombineAsync2E() { |
2281 |
– |
CompletableFuture<Integer> f, g, h; |
2282 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2283 |
– |
int count = 0; |
2284 |
– |
|
2285 |
– |
f = new CompletableFuture<>(); |
2286 |
– |
g = new CompletableFuture<>(); |
2287 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2288 |
– |
f.completeExceptionally(new CFException()); |
2289 |
– |
checkIncomplete(h); |
2290 |
– |
g.complete(1); |
2291 |
– |
checkCompletedWithWrappedCFException(h); |
2292 |
– |
|
2293 |
– |
f = new CompletableFuture<>(); |
2294 |
– |
g = new CompletableFuture<>(); |
2295 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2296 |
– |
g.completeExceptionally(new CFException()); |
2297 |
– |
checkIncomplete(h); |
2298 |
– |
f.complete(3); |
2299 |
– |
checkCompletedWithWrappedCFException(h); |
2300 |
– |
|
2301 |
– |
f = new CompletableFuture<>(); |
2302 |
– |
g = new CompletableFuture<>(); |
2303 |
– |
g.completeExceptionally(new CFException()); |
2304 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2305 |
– |
checkIncomplete(h); |
2306 |
– |
f.complete(3); |
2307 |
– |
checkCompletedWithWrappedCFException(h); |
2308 |
– |
|
2309 |
– |
assertEquals(0, e.count.get()); |
2310 |
– |
} |
2311 |
– |
|
2312 |
– |
/** |
2313 |
– |
* thenCombineAsync result completes exceptionally if action does |
2314 |
– |
*/ |
2315 |
– |
public void testThenCombineAsync3E() { |
2316 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2317 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2318 |
– |
FailingBiFunction r = new FailingBiFunction(); |
2319 |
– |
CompletableFuture<Integer> g = f.thenCombineAsync(f2, r, new ThreadExecutor()); |
2320 |
– |
f.complete(one); |
2321 |
– |
checkIncomplete(g); |
2322 |
– |
assertFalse(r.ran); |
2323 |
– |
f2.complete(two); |
2324 |
– |
checkCompletedWithWrappedCFException(g); |
2325 |
– |
assertTrue(r.ran); |
2326 |
– |
} |
2327 |
– |
|
2328 |
– |
/** |
2329 |
– |
* thenCombineAsync result completes exceptionally if either source cancelled |
2330 |
– |
*/ |
2331 |
– |
public void testThenCombineAsync4E() { |
2332 |
– |
CompletableFuture<Integer> f, g, h; |
2333 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2334 |
– |
|
2335 |
– |
f = new CompletableFuture<>(); |
2336 |
– |
g = new CompletableFuture<>(); |
2337 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2338 |
– |
assertTrue(f.cancel(true)); |
2339 |
– |
checkIncomplete(h); |
2340 |
– |
g.complete(1); |
2341 |
– |
checkCompletedWithWrappedCancellationException(h); |
2342 |
– |
|
2343 |
– |
f = new CompletableFuture<>(); |
2344 |
– |
g = new CompletableFuture<>(); |
2345 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2346 |
– |
assertTrue(g.cancel(true)); |
2347 |
– |
checkIncomplete(h); |
2348 |
– |
f.complete(3); |
2349 |
– |
checkCompletedWithWrappedCancellationException(h); |
2350 |
– |
|
2351 |
– |
f = new CompletableFuture<>(); |
2352 |
– |
g = new CompletableFuture<>(); |
2353 |
– |
assertTrue(g.cancel(true)); |
2354 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2355 |
– |
checkIncomplete(h); |
2356 |
– |
f.complete(3); |
2357 |
– |
checkCompletedWithWrappedCancellationException(h); |
2358 |
– |
|
2359 |
– |
f = new CompletableFuture<>(); |
2360 |
– |
g = new CompletableFuture<>(); |
2361 |
– |
assertTrue(f.cancel(true)); |
2362 |
– |
assertTrue(g.cancel(true)); |
2363 |
– |
h = f.thenCombineAsync(g, subtract, e); |
2364 |
– |
checkCompletedWithWrappedCancellationException(h); |
2365 |
– |
|
2366 |
– |
assertEquals(0, e.count.get()); |
2367 |
– |
} |
2368 |
– |
|
2369 |
– |
/** |
2370 |
– |
* thenAcceptBothAsync result completes normally after normal |
2371 |
– |
* completion of sources |
2372 |
– |
*/ |
2373 |
– |
public void testThenAcceptBothAsyncE() { |
2374 |
– |
CompletableFuture<Integer> f, g; |
2375 |
– |
CompletableFuture<Void> h; |
2376 |
– |
SubtractAction r; |
2377 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2378 |
– |
|
2379 |
– |
f = new CompletableFuture<>(); |
2380 |
– |
g = new CompletableFuture<>(); |
2381 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2382 |
– |
f.complete(3); |
2383 |
– |
checkIncomplete(h); |
2384 |
– |
g.complete(1); |
2385 |
– |
checkCompletedNormally(h, null); |
2386 |
– |
assertEquals(r.value, 2); |
2387 |
– |
|
2388 |
– |
f = new CompletableFuture<>(); |
2389 |
– |
g = new CompletableFuture<>(); |
2390 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2391 |
– |
g.complete(1); |
2392 |
– |
checkIncomplete(h); |
2393 |
– |
f.complete(3); |
2394 |
– |
checkCompletedNormally(h, null); |
2395 |
– |
assertEquals(r.value, 2); |
2396 |
– |
|
2397 |
– |
f = new CompletableFuture<>(); |
2398 |
– |
g = new CompletableFuture<>(); |
2399 |
– |
g.complete(1); |
2400 |
– |
f.complete(3); |
2401 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2402 |
– |
checkCompletedNormally(h, null); |
2403 |
– |
assertEquals(r.value, 2); |
2404 |
– |
|
2405 |
– |
assertEquals(3, e.count.get()); |
2406 |
– |
} |
2407 |
– |
|
2408 |
– |
/** |
2409 |
– |
* thenAcceptBothAsync result completes exceptionally after exceptional |
2410 |
– |
* completion of source |
2411 |
– |
*/ |
2412 |
– |
public void testThenAcceptBothAsync2E() { |
2413 |
– |
CompletableFuture<Integer> f, g; |
2414 |
– |
CompletableFuture<Void> h; |
2415 |
– |
SubtractAction r; |
2416 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2417 |
– |
|
2418 |
– |
f = new CompletableFuture<>(); |
2419 |
– |
g = new CompletableFuture<>(); |
2420 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2421 |
– |
f.completeExceptionally(new CFException()); |
2422 |
– |
checkIncomplete(h); |
2423 |
– |
g.complete(1); |
2424 |
– |
checkCompletedWithWrappedCFException(h); |
2425 |
– |
|
2426 |
– |
f = new CompletableFuture<>(); |
2427 |
– |
g = new CompletableFuture<>(); |
2428 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2429 |
– |
g.completeExceptionally(new CFException()); |
2430 |
– |
checkIncomplete(h); |
2431 |
– |
f.complete(3); |
2432 |
– |
checkCompletedWithWrappedCFException(h); |
2433 |
– |
|
2434 |
– |
f = new CompletableFuture<>(); |
2435 |
– |
g = new CompletableFuture<>(); |
2436 |
– |
f.complete(3); |
2437 |
– |
g.completeExceptionally(new CFException()); |
2438 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2439 |
– |
checkCompletedWithWrappedCFException(h); |
2440 |
– |
|
2441 |
– |
f = new CompletableFuture<>(); |
2442 |
– |
g = new CompletableFuture<>(); |
2443 |
– |
f.completeExceptionally(new CFException()); |
2444 |
– |
g.complete(3); |
2445 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2446 |
– |
checkCompletedWithWrappedCFException(h); |
2447 |
– |
|
2448 |
– |
assertEquals(0, e.count.get()); |
2449 |
– |
} |
2450 |
– |
|
2451 |
– |
/** |
2452 |
– |
* thenAcceptBothAsync result completes exceptionally if action does |
2453 |
– |
*/ |
2454 |
– |
public void testThenAcceptBothAsync3E() { |
2455 |
– |
CompletableFuture<Integer> f, g; |
2456 |
– |
CompletableFuture<Void> h; |
2457 |
– |
FailingBiConsumer r; |
2458 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2459 |
– |
|
2460 |
– |
f = new CompletableFuture<>(); |
2461 |
– |
g = new CompletableFuture<>(); |
2462 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2463 |
– |
f.complete(3); |
2464 |
– |
checkIncomplete(h); |
2465 |
– |
g.complete(1); |
2466 |
– |
checkCompletedWithWrappedCFException(h); |
2467 |
– |
|
2468 |
– |
f = new CompletableFuture<>(); |
2469 |
– |
g = new CompletableFuture<>(); |
2470 |
– |
f.complete(3); |
2471 |
– |
g.complete(1); |
2472 |
– |
h = f.thenAcceptBothAsync(g, r = new FailingBiConsumer(), e); |
2473 |
– |
checkCompletedWithWrappedCFException(h); |
2474 |
– |
|
2475 |
– |
assertEquals(2, e.count.get()); |
2476 |
– |
} |
2477 |
– |
|
2478 |
– |
/** |
2479 |
– |
* thenAcceptBothAsync result completes exceptionally if either source cancelled |
2480 |
– |
*/ |
2481 |
– |
public void testThenAcceptBothAsync4E() { |
2482 |
– |
CompletableFuture<Integer> f, g; |
2483 |
– |
CompletableFuture<Void> h; |
2484 |
– |
SubtractAction r; |
2485 |
– |
ThreadExecutor e = new ThreadExecutor(); |
2486 |
– |
|
2487 |
– |
f = new CompletableFuture<>(); |
2488 |
– |
g = new CompletableFuture<>(); |
2489 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2490 |
– |
assertTrue(f.cancel(true)); |
2491 |
– |
checkIncomplete(h); |
2492 |
– |
g.complete(1); |
2493 |
– |
checkCompletedWithWrappedCancellationException(h); |
2494 |
– |
|
2495 |
– |
f = new CompletableFuture<>(); |
2496 |
– |
g = new CompletableFuture<>(); |
2497 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2498 |
– |
assertTrue(g.cancel(true)); |
2499 |
– |
checkIncomplete(h); |
2500 |
– |
f.complete(3); |
2501 |
– |
checkCompletedWithWrappedCancellationException(h); |
2502 |
– |
|
2503 |
– |
f = new CompletableFuture<>(); |
2504 |
– |
g = new CompletableFuture<>(); |
2505 |
– |
f.complete(3); |
2506 |
– |
assertTrue(g.cancel(true)); |
2507 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2508 |
– |
checkCompletedWithWrappedCancellationException(h); |
2509 |
– |
|
2510 |
– |
f = new CompletableFuture<>(); |
2511 |
– |
g = new CompletableFuture<>(); |
2512 |
– |
assertTrue(f.cancel(true)); |
2513 |
– |
g.complete(3); |
2514 |
– |
h = f.thenAcceptBothAsync(g, r = new SubtractAction(), e); |
2515 |
– |
checkCompletedWithWrappedCancellationException(h); |
2516 |
– |
|
2517 |
– |
assertEquals(0, e.count.get()); |
2518 |
– |
} |
2519 |
– |
|
2520 |
– |
/** |
2521 |
– |
* runAfterBothAsync result completes normally after normal |
2522 |
– |
* completion of sources |
2523 |
– |
*/ |
2524 |
– |
public void testRunAfterBothAsyncE() { |
2525 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2526 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2527 |
– |
Noop r = new Noop(); |
2528 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2529 |
– |
f.complete(one); |
2530 |
– |
checkIncomplete(g); |
2531 |
– |
f2.complete(two); |
2532 |
– |
checkCompletedNormally(g, null); |
2533 |
– |
assertTrue(r.ran); |
2534 |
– |
} |
2535 |
– |
|
2536 |
– |
/** |
2537 |
– |
* runAfterBothAsync result completes exceptionally after exceptional |
2538 |
– |
* completion of source |
2539 |
– |
*/ |
2540 |
– |
public void testRunAfterBothAsync2E() { |
2541 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2542 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2543 |
– |
Noop r = new Noop(); |
2544 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2545 |
– |
f.completeExceptionally(new CFException()); |
2546 |
– |
f2.complete(two); |
2547 |
– |
checkCompletedWithWrappedCFException(g); |
2548 |
– |
|
2549 |
– |
r = new Noop(); |
2550 |
– |
f = new CompletableFuture<>(); |
2551 |
– |
f2 = new CompletableFuture<>(); |
2552 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2553 |
– |
f.complete(one); |
2554 |
– |
f2.completeExceptionally(new CFException()); |
2555 |
– |
checkCompletedWithWrappedCFException(g); |
2556 |
– |
} |
2557 |
– |
|
2558 |
– |
/** |
2559 |
– |
* runAfterBothAsync result completes exceptionally if action does |
2560 |
– |
*/ |
2561 |
– |
public void testRunAfterBothAsync3E() { |
2562 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2563 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2564 |
– |
FailingNoop r = new FailingNoop(); |
2565 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2566 |
– |
f.complete(one); |
2567 |
– |
checkIncomplete(g); |
2568 |
– |
f2.complete(two); |
2569 |
– |
checkCompletedWithWrappedCFException(g); |
2570 |
– |
} |
2571 |
– |
|
2572 |
– |
/** |
2573 |
– |
* runAfterBothAsync result completes exceptionally if either source cancelled |
2574 |
– |
*/ |
2575 |
– |
public void testRunAfterBothAsync4E() { |
2576 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2577 |
– |
CompletableFuture<Integer> f2 = new CompletableFuture<>(); |
2578 |
– |
Noop r = new Noop(); |
2579 |
– |
CompletableFuture<Void> g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2580 |
– |
assertTrue(f.cancel(true)); |
2581 |
– |
f2.complete(two); |
2582 |
– |
checkCompletedWithWrappedCancellationException(g); |
2583 |
– |
|
2584 |
– |
r = new Noop(); |
2585 |
– |
f = new CompletableFuture<>(); |
2586 |
– |
f2 = new CompletableFuture<>(); |
2587 |
– |
g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); |
2588 |
– |
f.complete(one); |
2589 |
– |
assertTrue(f2.cancel(true)); |
2590 |
– |
checkCompletedWithWrappedCancellationException(g); |
2591 |
– |
} |
2592 |
– |
|
2593 |
– |
/** |
2595 |
|
* applyToEitherAsync result completes normally after normal |
2596 |
|
* completion of sources |
2597 |
|
*/ |
2940 |
|
ThreadExecutor exec = new ThreadExecutor(); |
2941 |
|
|
2942 |
|
Runnable[] throwingActions = { |
2943 |
< |
() -> { CompletableFuture.supplyAsync(null); }, |
2944 |
< |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
2945 |
< |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
2946 |
< |
|
2947 |
< |
() -> { CompletableFuture.runAsync(null); }, |
2948 |
< |
() -> { CompletableFuture.runAsync(null, exec); }, |
2949 |
< |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
2950 |
< |
|
2951 |
< |
() -> { f.completeExceptionally(null); }, |
2952 |
< |
|
2953 |
< |
() -> { f.thenApply(null); }, |
2954 |
< |
() -> { f.thenApplyAsync(null); }, |
2955 |
< |
() -> { f.thenApplyAsync((x) -> x, null); }, |
2956 |
< |
() -> { f.thenApplyAsync(null, exec); }, |
2957 |
< |
|
2958 |
< |
() -> { f.thenAccept(null); }, |
2959 |
< |
() -> { f.thenAcceptAsync(null); }, |
2960 |
< |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
2961 |
< |
() -> { f.thenAcceptAsync(null, exec); }, |
2962 |
< |
|
2963 |
< |
() -> { f.thenRun(null); }, |
2964 |
< |
() -> { f.thenRunAsync(null); }, |
2965 |
< |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
2966 |
< |
() -> { f.thenRunAsync(null, exec); }, |
2967 |
< |
|
2968 |
< |
() -> { f.thenCombine(g, null); }, |
2969 |
< |
() -> { f.thenCombineAsync(g, null); }, |
2970 |
< |
() -> { f.thenCombineAsync(g, null, exec); }, |
2971 |
< |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
2972 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
2973 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
2974 |
< |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
2975 |
< |
|
2976 |
< |
() -> { f.thenAcceptBoth(g, null); }, |
2977 |
< |
() -> { f.thenAcceptBothAsync(g, null); }, |
2978 |
< |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
2979 |
< |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
2980 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
2981 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
2982 |
< |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
2983 |
< |
|
2984 |
< |
() -> { f.runAfterBoth(g, null); }, |
2985 |
< |
() -> { f.runAfterBothAsync(g, null); }, |
2986 |
< |
() -> { f.runAfterBothAsync(g, null, exec); }, |
2987 |
< |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
2988 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
2989 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
2990 |
< |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
2991 |
< |
|
2992 |
< |
() -> { f.applyToEither(g, null); }, |
2993 |
< |
() -> { f.applyToEitherAsync(g, null); }, |
2994 |
< |
() -> { f.applyToEitherAsync(g, null, exec); }, |
2995 |
< |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
2996 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
2997 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
2998 |
< |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
2999 |
< |
|
3000 |
< |
() -> { f.acceptEither(g, null); }, |
3001 |
< |
() -> { f.acceptEitherAsync(g, null); }, |
3002 |
< |
() -> { f.acceptEitherAsync(g, null, exec); }, |
3003 |
< |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
3004 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
3005 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
3006 |
< |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
3007 |
< |
|
3008 |
< |
() -> { f.runAfterEither(g, null); }, |
3009 |
< |
() -> { f.runAfterEitherAsync(g, null); }, |
3010 |
< |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
3011 |
< |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
3012 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
3013 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
3014 |
< |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
3015 |
< |
|
3016 |
< |
() -> { f.thenCompose(null); }, |
3017 |
< |
() -> { f.thenComposeAsync(null); }, |
3018 |
< |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
3019 |
< |
() -> { f.thenComposeAsync(null, exec); }, |
3020 |
< |
|
3021 |
< |
() -> { f.exceptionally(null); }, |
3022 |
< |
|
3023 |
< |
() -> { f.handle(null); }, |
3024 |
< |
|
3025 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
3026 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
3027 |
< |
() -> { CompletableFuture.allOf(f, null); }, |
3028 |
< |
() -> { CompletableFuture.allOf(null, f); }, |
3029 |
< |
|
3030 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
3031 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
3032 |
< |
() -> { CompletableFuture.anyOf(f, null); }, |
3033 |
< |
() -> { CompletableFuture.anyOf(null, f); }, |
2943 |
> |
() -> CompletableFuture.supplyAsync(null), |
2944 |
> |
() -> CompletableFuture.supplyAsync(null, exec), |
2945 |
> |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
2946 |
> |
|
2947 |
> |
() -> CompletableFuture.runAsync(null), |
2948 |
> |
() -> CompletableFuture.runAsync(null, exec), |
2949 |
> |
() -> CompletableFuture.runAsync(() -> {}, null), |
2950 |
> |
|
2951 |
> |
() -> f.completeExceptionally(null), |
2952 |
> |
|
2953 |
> |
() -> f.thenApply(null), |
2954 |
> |
() -> f.thenApplyAsync(null), |
2955 |
> |
() -> f.thenApplyAsync((x) -> x, null), |
2956 |
> |
() -> f.thenApplyAsync(null, exec), |
2957 |
> |
|
2958 |
> |
() -> f.thenAccept(null), |
2959 |
> |
() -> f.thenAcceptAsync(null), |
2960 |
> |
() -> f.thenAcceptAsync((x) -> {} , null), |
2961 |
> |
() -> f.thenAcceptAsync(null, exec), |
2962 |
> |
|
2963 |
> |
() -> f.thenRun(null), |
2964 |
> |
() -> f.thenRunAsync(null), |
2965 |
> |
() -> f.thenRunAsync(() -> {} , null), |
2966 |
> |
() -> f.thenRunAsync(null, exec), |
2967 |
> |
|
2968 |
> |
() -> f.thenCombine(g, null), |
2969 |
> |
() -> f.thenCombineAsync(g, null), |
2970 |
> |
() -> f.thenCombineAsync(g, null, exec), |
2971 |
> |
() -> f.thenCombine(nullFuture, (x, y) -> x), |
2972 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x), |
2973 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec), |
2974 |
> |
() -> f.thenCombineAsync(g, (x, y) -> x, null), |
2975 |
> |
|
2976 |
> |
() -> f.thenAcceptBoth(g, null), |
2977 |
> |
() -> f.thenAcceptBothAsync(g, null), |
2978 |
> |
() -> f.thenAcceptBothAsync(g, null, exec), |
2979 |
> |
() -> f.thenAcceptBoth(nullFuture, (x, y) -> {}), |
2980 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}), |
2981 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec), |
2982 |
> |
() -> f.thenAcceptBothAsync(g, (x, y) -> {}, null), |
2983 |
> |
|
2984 |
> |
() -> f.runAfterBoth(g, null), |
2985 |
> |
() -> f.runAfterBothAsync(g, null), |
2986 |
> |
() -> f.runAfterBothAsync(g, null, exec), |
2987 |
> |
() -> f.runAfterBoth(nullFuture, () -> {}), |
2988 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}), |
2989 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}, exec), |
2990 |
> |
() -> f.runAfterBothAsync(g, () -> {}, null), |
2991 |
> |
|
2992 |
> |
() -> f.applyToEither(g, null), |
2993 |
> |
() -> f.applyToEitherAsync(g, null), |
2994 |
> |
() -> f.applyToEitherAsync(g, null, exec), |
2995 |
> |
() -> f.applyToEither(nullFuture, (x) -> x), |
2996 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
2997 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
2998 |
> |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
2999 |
> |
|
3000 |
> |
() -> f.acceptEither(g, null), |
3001 |
> |
() -> f.acceptEitherAsync(g, null), |
3002 |
> |
() -> f.acceptEitherAsync(g, null, exec), |
3003 |
> |
() -> f.acceptEither(nullFuture, (x) -> {}), |
3004 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
3005 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
3006 |
> |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
3007 |
> |
|
3008 |
> |
() -> f.runAfterEither(g, null), |
3009 |
> |
() -> f.runAfterEitherAsync(g, null), |
3010 |
> |
() -> f.runAfterEitherAsync(g, null, exec), |
3011 |
> |
() -> f.runAfterEither(nullFuture, () -> {}), |
3012 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}), |
3013 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}, exec), |
3014 |
> |
() -> f.runAfterEitherAsync(g, () -> {}, null), |
3015 |
> |
|
3016 |
> |
() -> f.thenCompose(null), |
3017 |
> |
() -> f.thenComposeAsync(null), |
3018 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
3019 |
> |
() -> f.thenComposeAsync(null, exec), |
3020 |
> |
|
3021 |
> |
() -> f.exceptionally(null), |
3022 |
> |
|
3023 |
> |
() -> f.handle(null), |
3024 |
> |
|
3025 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>)null), |
3026 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>[])null), |
3027 |
> |
() -> CompletableFuture.allOf(f, null), |
3028 |
> |
() -> CompletableFuture.allOf(null, f), |
3029 |
> |
|
3030 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>)null), |
3031 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>[])null), |
3032 |
> |
() -> CompletableFuture.anyOf(f, null), |
3033 |
> |
() -> CompletableFuture.anyOf(null, f), |
3034 |
> |
|
3035 |
> |
() -> f.obtrudeException(null), |
3036 |
|
}; |
3037 |
|
|
3038 |
|
assertThrows(NullPointerException.class, throwingActions); |
3184 |
|
checkCompletedWithWrappedCFException(g); |
3185 |
|
} |
3186 |
|
|
3184 |
– |
|
3187 |
|
/** |
3188 |
< |
* handleAsync action action completes normally with function |
3189 |
< |
* value on either normal or exceptional completion of source |
3188 |
> |
* handleAsync action completes normally with function value on |
3189 |
> |
* either normal or exceptional completion of source |
3190 |
|
*/ |
3191 |
|
public void testHandleAsync() { |
3192 |
|
CompletableFuture<Integer> f, g; |