17 |
|
import java.util.concurrent.CompletableFuture; |
18 |
|
import java.util.concurrent.CompletionException; |
19 |
|
import java.util.concurrent.CompletionStage; |
20 |
+ |
import java.util.concurrent.ForkJoinPool; |
21 |
+ |
import java.util.concurrent.ForkJoinTask; |
22 |
|
import java.util.concurrent.TimeoutException; |
23 |
|
import java.util.concurrent.atomic.AtomicInteger; |
24 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
460 |
|
*/ |
461 |
|
enum ExecutionMode { |
462 |
|
DEFAULT { |
463 |
+ |
public void checkExecutionMode() { |
464 |
+ |
assertNull(ForkJoinTask.getPool()); |
465 |
+ |
} |
466 |
|
public <T> CompletableFuture<Void> thenRun |
467 |
|
(CompletableFuture<T> f, Runnable a) { |
468 |
|
return f.thenRun(a); |
526 |
|
} |
527 |
|
}, |
528 |
|
|
529 |
< |
DEFAULT_ASYNC { |
529 |
> |
ASYNC { |
530 |
> |
public void checkExecutionMode() { |
531 |
> |
assertSame(ForkJoinPool.commonPool(), |
532 |
> |
ForkJoinTask.getPool()); |
533 |
> |
} |
534 |
|
public <T> CompletableFuture<Void> thenRun |
535 |
|
(CompletableFuture<T> f, Runnable a) { |
536 |
|
return f.thenRunAsync(a); |
595 |
|
}, |
596 |
|
|
597 |
|
EXECUTOR { |
598 |
+ |
public void checkExecutionMode() { |
599 |
+ |
//TODO |
600 |
+ |
} |
601 |
|
public <T> CompletableFuture<Void> thenRun |
602 |
|
(CompletableFuture<T> f, Runnable a) { |
603 |
|
return f.thenRunAsync(a, new ThreadExecutor()); |
661 |
|
} |
662 |
|
}; |
663 |
|
|
664 |
+ |
public abstract void checkExecutionMode(); |
665 |
|
public abstract <T> CompletableFuture<Void> thenRun |
666 |
|
(CompletableFuture<T> f, Runnable a); |
667 |
|
public abstract <T> CompletableFuture<Void> thenAccept |
974 |
|
/** |
975 |
|
* thenRun result completes normally after normal completion of source |
976 |
|
*/ |
977 |
< |
public void testThenRun() { |
978 |
< |
CompletableFuture<Integer> f; |
979 |
< |
CompletableFuture<Void> g; |
980 |
< |
Noop r; |
981 |
< |
|
982 |
< |
f = new CompletableFuture<>(); |
983 |
< |
g = f.thenRun(r = new Noop()); |
984 |
< |
f.complete(null); |
985 |
< |
checkCompletedNormally(g, null); |
986 |
< |
assertEquals(1, r.invocationCount); |
977 |
> |
public void testThenRun_normalCompletion() { |
978 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
979 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
980 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
981 |
> |
{ |
982 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
983 |
> |
final Noop r = new Noop(); |
984 |
> |
if (!createIncomplete) f.complete(v1); |
985 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
986 |
> |
if (createIncomplete) f.complete(v1); |
987 |
|
|
975 |
– |
f = new CompletableFuture<>(); |
976 |
– |
f.complete(null); |
977 |
– |
g = f.thenRun(r = new Noop()); |
988 |
|
checkCompletedNormally(g, null); |
989 |
+ |
checkCompletedNormally(f, v1); |
990 |
|
assertEquals(1, r.invocationCount); |
991 |
< |
} |
991 |
> |
}} |
992 |
|
|
993 |
|
/** |
994 |
|
* thenRun result completes exceptionally after exceptional |
995 |
|
* completion of source |
996 |
|
*/ |
997 |
< |
public void testThenRun2() { |
998 |
< |
CompletableFuture<Integer> f; |
999 |
< |
CompletableFuture<Void> g; |
1000 |
< |
Noop r; |
1001 |
< |
|
1002 |
< |
f = new CompletableFuture<>(); |
1003 |
< |
g = f.thenRun(r = new Noop()); |
1004 |
< |
f.completeExceptionally(new CFException()); |
1005 |
< |
checkCompletedWithWrappedCFException(g); |
1006 |
< |
assertEquals(0, r.invocationCount); |
997 |
> |
public void testThenRun_exceptionalCompletion() { |
998 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
999 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1000 |
> |
{ |
1001 |
> |
final CFException ex = new CFException(); |
1002 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1003 |
> |
final Noop r = new Noop(); |
1004 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1005 |
> |
final CompletableFuture<Void> g = m.thenRun(f, r); |
1006 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
1007 |
|
|
1008 |
< |
f = new CompletableFuture<>(); |
1009 |
< |
f.completeExceptionally(new CFException()); |
999 |
< |
g = f.thenRun(r = new Noop()); |
1000 |
< |
checkCompletedWithWrappedCFException(g); |
1008 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1009 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1010 |
|
assertEquals(0, r.invocationCount); |
1011 |
< |
} |
1011 |
> |
}} |
1012 |
|
|
1013 |
|
/** |
1014 |
< |
* thenRun result completes exceptionally if action does |
1014 |
> |
* thenRun result completes exceptionally if source cancelled |
1015 |
|
*/ |
1016 |
< |
public void testThenRun3() { |
1017 |
< |
CompletableFuture<Integer> f; |
1018 |
< |
CompletableFuture<Void> g; |
1019 |
< |
FailingNoop r; |
1020 |
< |
|
1021 |
< |
f = new CompletableFuture<>(); |
1022 |
< |
g = f.thenRun(r = new FailingNoop()); |
1023 |
< |
f.complete(null); |
1024 |
< |
checkCompletedWithWrappedCFException(g); |
1016 |
> |
public void testThenRun_sourceCancelled() { |
1017 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1018 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1019 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1020 |
> |
{ |
1021 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1022 |
> |
final Noop r = new Noop(); |
1023 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1024 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1025 |
> |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1026 |
|
|
1027 |
< |
f = new CompletableFuture<>(); |
1028 |
< |
f.complete(null); |
1029 |
< |
g = f.thenRun(r = new FailingNoop()); |
1030 |
< |
checkCompletedWithWrappedCFException(g); |
1021 |
< |
} |
1027 |
> |
checkCompletedWithWrappedCancellationException(g); |
1028 |
> |
checkCancelled(f); |
1029 |
> |
assertEquals(0, r.invocationCount); |
1030 |
> |
}} |
1031 |
|
|
1032 |
|
/** |
1033 |
< |
* thenRun result completes exceptionally if source cancelled |
1033 |
> |
* thenRun result completes exceptionally if action does |
1034 |
|
*/ |
1035 |
< |
public void testThenRun4() { |
1036 |
< |
CompletableFuture<Integer> f; |
1037 |
< |
CompletableFuture<Void> g; |
1038 |
< |
Noop r; |
1039 |
< |
|
1040 |
< |
f = new CompletableFuture<>(); |
1041 |
< |
g = f.thenRun(r = new Noop()); |
1042 |
< |
assertTrue(f.cancel(true)); |
1043 |
< |
checkCompletedWithWrappedCancellationException(g); |
1035 |
> |
public void testThenRun_actionFailed() { |
1036 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1037 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1038 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1039 |
> |
{ |
1040 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1041 |
> |
final FailingNoop r = new FailingNoop(); |
1042 |
> |
if (!createIncomplete) f.complete(v1); |
1043 |
> |
final CompletableFuture<Void> g = f.thenRun(r); |
1044 |
> |
if (createIncomplete) f.complete(v1); |
1045 |
|
|
1046 |
< |
f = new CompletableFuture<>(); |
1047 |
< |
assertTrue(f.cancel(true)); |
1048 |
< |
g = f.thenRun(r = new Noop()); |
1039 |
< |
checkCompletedWithWrappedCancellationException(g); |
1040 |
< |
} |
1046 |
> |
checkCompletedWithWrappedCFException(g); |
1047 |
> |
checkCompletedNormally(f, v1); |
1048 |
> |
}} |
1049 |
|
|
1050 |
|
/** |
1051 |
|
* thenApply result completes normally after normal completion of source |
1052 |
|
*/ |
1053 |
< |
public void testThenApply() { |
1054 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1055 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1056 |
< |
f.complete(one); |
1057 |
< |
checkCompletedNormally(g, two); |
1058 |
< |
} |
1053 |
> |
public void testThenApply_normalCompletion() { |
1054 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1055 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1056 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1057 |
> |
{ |
1058 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1059 |
> |
final IncFunction r = new IncFunction(); |
1060 |
> |
if (!createIncomplete) f.complete(v1); |
1061 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1062 |
> |
if (createIncomplete) { |
1063 |
> |
checkIncomplete(g); |
1064 |
> |
f.complete(v1); |
1065 |
> |
} |
1066 |
> |
|
1067 |
> |
checkCompletedNormally(g, inc(v1)); |
1068 |
> |
checkCompletedNormally(f, v1); |
1069 |
> |
assertEquals(1, r.invocationCount); |
1070 |
> |
}} |
1071 |
|
|
1072 |
|
/** |
1073 |
|
* thenApply result completes exceptionally after exceptional |
1074 |
|
* completion of source |
1075 |
|
*/ |
1076 |
< |
public void testThenApply2() { |
1077 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1078 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1079 |
< |
f.completeExceptionally(new CFException()); |
1080 |
< |
checkCompletedWithWrappedCFException(g); |
1081 |
< |
} |
1076 |
> |
public void testThenApply_exceptionalCompletion() { |
1077 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1078 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1079 |
> |
{ |
1080 |
> |
final CFException ex = new CFException(); |
1081 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1082 |
> |
final IncFunction r = new IncFunction(); |
1083 |
> |
if (!createIncomplete) f.completeExceptionally(ex); |
1084 |
> |
final CompletableFuture<Integer> g = m.thenApply(f, r); |
1085 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
1086 |
|
|
1087 |
< |
/** |
1088 |
< |
* thenApply result completes exceptionally if action does |
1089 |
< |
*/ |
1090 |
< |
public void testThenApply3() { |
1067 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1068 |
< |
CompletableFuture<Integer> g = f.thenApply(new FailingFunction()); |
1069 |
< |
f.complete(one); |
1070 |
< |
checkCompletedWithWrappedCFException(g); |
1071 |
< |
} |
1087 |
> |
checkCompletedWithWrappedCFException(g, ex); |
1088 |
> |
checkCompletedWithWrappedCFException(f, ex); |
1089 |
> |
assertEquals(0, r.invocationCount); |
1090 |
> |
}} |
1091 |
|
|
1092 |
|
/** |
1093 |
|
* thenApply result completes exceptionally if source cancelled |
1094 |
|
*/ |
1095 |
< |
public void testThenApply4() { |
1096 |
< |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
1097 |
< |
CompletableFuture<Integer> g = f.thenApply(inc); |
1098 |
< |
assertTrue(f.cancel(true)); |
1095 |
> |
public void testThenApply_sourceCancelled() { |
1096 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1097 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1098 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
1099 |
> |
{ |
1100 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1101 |
> |
final IncFunction r = new IncFunction(); |
1102 |
> |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1103 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1104 |
> |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
1105 |
> |
|
1106 |
|
checkCompletedWithWrappedCancellationException(g); |
1107 |
< |
} |
1107 |
> |
checkCancelled(f); |
1108 |
> |
assertEquals(0, r.invocationCount); |
1109 |
> |
}} |
1110 |
> |
|
1111 |
> |
/** |
1112 |
> |
* thenApply result completes exceptionally if action does |
1113 |
> |
*/ |
1114 |
> |
public void testThenApply_actionFailed() { |
1115 |
> |
for (ExecutionMode m : ExecutionMode.values()) |
1116 |
> |
for (boolean createIncomplete : new boolean[] { true, false }) |
1117 |
> |
for (Integer v1 : new Integer[] { 1, null }) |
1118 |
> |
{ |
1119 |
> |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1120 |
> |
final FailingFunction r = new FailingFunction(); |
1121 |
> |
if (!createIncomplete) f.complete(v1); |
1122 |
> |
final CompletableFuture<Integer> g = f.thenApply(r); |
1123 |
> |
if (createIncomplete) f.complete(v1); |
1124 |
> |
|
1125 |
> |
checkCompletedWithWrappedCFException(g); |
1126 |
> |
checkCompletedNormally(f, v1); |
1127 |
> |
}} |
1128 |
|
|
1129 |
|
/** |
1130 |
|
* thenAccept result completes normally after normal completion of source |
2886 |
|
/** |
2887 |
|
* thenCompose result completes normally after normal completion of source |
2888 |
|
*/ |
2889 |
< |
public void testThenCompose_normalCompletion1() { |
2889 |
> |
public void testThenCompose_normalCompletion() { |
2890 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2891 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2892 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2893 |
|
{ |
2894 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2895 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2896 |
+ |
if (!createIncomplete) f.complete(v1); |
2897 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2898 |
< |
f.complete(v1); |
2851 |
< |
checkCompletedNormally(g, inc(v1)); |
2852 |
< |
checkCompletedNormally(f, v1); |
2853 |
< |
assertEquals(1, r.invocationCount); |
2854 |
< |
}} |
2898 |
> |
if (createIncomplete) f.complete(v1); |
2899 |
|
|
2856 |
– |
public void testThenCompose_normalCompletion2() { |
2857 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2858 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2859 |
– |
{ |
2860 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2861 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2862 |
– |
f.complete(v1); |
2863 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2900 |
|
checkCompletedNormally(g, inc(v1)); |
2901 |
|
checkCompletedNormally(f, v1); |
2902 |
|
assertEquals(1, r.invocationCount); |
2906 |
|
* thenCompose result completes exceptionally after exceptional |
2907 |
|
* completion of source |
2908 |
|
*/ |
2909 |
< |
public void testThenCompose_exceptionalCompletion1() { |
2909 |
> |
public void testThenCompose_exceptionalCompletion() { |
2910 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2911 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2912 |
|
{ |
2913 |
|
final CFException ex = new CFException(); |
2914 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2915 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2916 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
2917 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2918 |
< |
f.completeExceptionally(ex); |
2881 |
< |
checkCompletedWithWrappedCFException(g, ex); |
2882 |
< |
checkCompletedWithWrappedCFException(f, ex); |
2883 |
< |
}} |
2918 |
> |
if (createIncomplete) f.completeExceptionally(ex); |
2919 |
|
|
2885 |
– |
public void testThenCompose_exceptionalCompletion2() { |
2886 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2887 |
– |
{ |
2888 |
– |
final CFException ex = new CFException(); |
2889 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2890 |
– |
f.completeExceptionally(ex); |
2891 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2892 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2920 |
|
checkCompletedWithWrappedCFException(g, ex); |
2921 |
|
checkCompletedWithWrappedCFException(f, ex); |
2922 |
+ |
assertEquals(0, r.invocationCount); |
2923 |
|
}} |
2924 |
|
|
2925 |
|
/** |
2926 |
|
* thenCompose result completes exceptionally if action does |
2927 |
|
*/ |
2928 |
< |
public void testThenCompose_actionFailed1() { |
2928 |
> |
public void testThenCompose_actionFailed() { |
2929 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2930 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2931 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2932 |
|
{ |
2933 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2934 |
|
final FailingCompletableFutureFunction r |
2935 |
|
= new FailingCompletableFutureFunction(); |
2936 |
+ |
if (!createIncomplete) f.complete(v1); |
2937 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2938 |
< |
f.complete(v1); |
2909 |
< |
checkCompletedWithWrappedCFException(g); |
2910 |
< |
checkCompletedNormally(f, v1); |
2911 |
< |
}} |
2938 |
> |
if (createIncomplete) f.complete(v1); |
2939 |
|
|
2913 |
– |
public void testThenCompose_actionFailed2() { |
2914 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2915 |
– |
for (Integer v1 : new Integer[] { 1, null }) |
2916 |
– |
{ |
2917 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2918 |
– |
f.complete(v1); |
2919 |
– |
final FailingCompletableFutureFunction r |
2920 |
– |
= new FailingCompletableFutureFunction(); |
2921 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2940 |
|
checkCompletedWithWrappedCFException(g); |
2941 |
|
checkCompletedNormally(f, v1); |
2942 |
|
}} |
2944 |
|
/** |
2945 |
|
* thenCompose result completes exceptionally if source cancelled |
2946 |
|
*/ |
2947 |
< |
public void testThenCompose_sourceCancelled1() { |
2947 |
> |
public void testThenCompose_sourceCancelled() { |
2948 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2949 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
2950 |
|
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2951 |
|
{ |
2952 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2953 |
|
final CompletableFutureInc r = new CompletableFutureInc(); |
2954 |
+ |
if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2955 |
|
final CompletableFuture<Integer> g = f.thenCompose(r); |
2956 |
< |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2937 |
< |
checkCompletedWithWrappedCancellationException(g); |
2938 |
< |
checkCancelled(f); |
2939 |
< |
}} |
2956 |
> |
if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); |
2957 |
|
|
2941 |
– |
public void testThenCompose_sourceCancelled2() { |
2942 |
– |
for (ExecutionMode m : ExecutionMode.values()) |
2943 |
– |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) |
2944 |
– |
{ |
2945 |
– |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2946 |
– |
assertTrue(f.cancel(mayInterruptIfRunning)); |
2947 |
– |
final CompletableFutureInc r = new CompletableFutureInc(); |
2948 |
– |
final CompletableFuture<Integer> g = f.thenCompose(r); |
2958 |
|
checkCompletedWithWrappedCancellationException(g); |
2959 |
|
checkCancelled(f); |
2960 |
|
}} |
2962 |
|
// asyncs |
2963 |
|
|
2964 |
|
/** |
2956 |
– |
* thenRunAsync result completes normally after normal completion of source |
2957 |
– |
*/ |
2958 |
– |
public void testThenRunAsync() { |
2959 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2960 |
– |
Noop r = new Noop(); |
2961 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2962 |
– |
f.complete(null); |
2963 |
– |
checkCompletedNormally(g, null); |
2964 |
– |
|
2965 |
– |
// reordered version |
2966 |
– |
f = new CompletableFuture<>(); |
2967 |
– |
f.complete(null); |
2968 |
– |
r = new Noop(); |
2969 |
– |
g = f.thenRunAsync(r); |
2970 |
– |
checkCompletedNormally(g, null); |
2971 |
– |
} |
2972 |
– |
|
2973 |
– |
/** |
2974 |
– |
* thenRunAsync result completes exceptionally after exceptional |
2975 |
– |
* completion of source |
2976 |
– |
*/ |
2977 |
– |
public void testThenRunAsync2() { |
2978 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2979 |
– |
Noop r = new Noop(); |
2980 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2981 |
– |
f.completeExceptionally(new CFException()); |
2982 |
– |
try { |
2983 |
– |
g.join(); |
2984 |
– |
shouldThrow(); |
2985 |
– |
} catch (CompletionException success) {} |
2986 |
– |
checkCompletedWithWrappedCFException(g); |
2987 |
– |
} |
2988 |
– |
|
2989 |
– |
/** |
2990 |
– |
* thenRunAsync result completes exceptionally if action does |
2991 |
– |
*/ |
2992 |
– |
public void testThenRunAsync3() { |
2993 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2994 |
– |
FailingNoop r = new FailingNoop(); |
2995 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
2996 |
– |
f.complete(null); |
2997 |
– |
checkCompletedWithWrappedCFException(g); |
2998 |
– |
} |
2999 |
– |
|
3000 |
– |
/** |
3001 |
– |
* thenRunAsync result completes exceptionally if source cancelled |
3002 |
– |
*/ |
3003 |
– |
public void testThenRunAsync4() { |
3004 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3005 |
– |
Noop r = new Noop(); |
3006 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r); |
3007 |
– |
assertTrue(f.cancel(true)); |
3008 |
– |
checkCompletedWithWrappedCancellationException(g); |
3009 |
– |
} |
3010 |
– |
|
3011 |
– |
/** |
3012 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3013 |
– |
*/ |
3014 |
– |
public void testThenApplyAsync() { |
3015 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3016 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3017 |
– |
f.complete(one); |
3018 |
– |
checkCompletedNormally(g, two); |
3019 |
– |
} |
3020 |
– |
|
3021 |
– |
/** |
3022 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3023 |
– |
* completion of source |
3024 |
– |
*/ |
3025 |
– |
public void testThenApplyAsync2() { |
3026 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3027 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3028 |
– |
f.completeExceptionally(new CFException()); |
3029 |
– |
checkCompletedWithWrappedCFException(g); |
3030 |
– |
} |
3031 |
– |
|
3032 |
– |
/** |
3033 |
– |
* thenApplyAsync result completes exceptionally if action does |
3034 |
– |
*/ |
3035 |
– |
public void testThenApplyAsync3() { |
3036 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3037 |
– |
FailingFunction r = new FailingFunction(); |
3038 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r); |
3039 |
– |
f.complete(null); |
3040 |
– |
checkCompletedWithWrappedCFException(g); |
3041 |
– |
} |
3042 |
– |
|
3043 |
– |
/** |
3044 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3045 |
– |
*/ |
3046 |
– |
public void testThenApplyAsync4() { |
3047 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3048 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc); |
3049 |
– |
assertTrue(f.cancel(true)); |
3050 |
– |
checkCompletedWithWrappedCancellationException(g); |
3051 |
– |
} |
3052 |
– |
|
3053 |
– |
/** |
2965 |
|
* thenAcceptAsync result completes normally after normal |
2966 |
|
* completion of source |
2967 |
|
*/ |
3011 |
|
// async with explicit executors |
3012 |
|
|
3013 |
|
/** |
3103 |
– |
* thenRunAsync result completes normally after normal completion of source |
3104 |
– |
*/ |
3105 |
– |
public void testThenRunAsyncE() { |
3106 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3107 |
– |
Noop r = new Noop(); |
3108 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3109 |
– |
f.complete(null); |
3110 |
– |
checkCompletedNormally(g, null); |
3111 |
– |
|
3112 |
– |
// reordered version |
3113 |
– |
f = new CompletableFuture<>(); |
3114 |
– |
f.complete(null); |
3115 |
– |
r = new Noop(); |
3116 |
– |
g = f.thenRunAsync(r, new ThreadExecutor()); |
3117 |
– |
checkCompletedNormally(g, null); |
3118 |
– |
} |
3119 |
– |
|
3120 |
– |
/** |
3121 |
– |
* thenRunAsync result completes exceptionally after exceptional |
3122 |
– |
* completion of source |
3123 |
– |
*/ |
3124 |
– |
public void testThenRunAsync2E() { |
3125 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3126 |
– |
Noop r = new Noop(); |
3127 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3128 |
– |
f.completeExceptionally(new CFException()); |
3129 |
– |
try { |
3130 |
– |
g.join(); |
3131 |
– |
shouldThrow(); |
3132 |
– |
} catch (CompletionException success) {} |
3133 |
– |
checkCompletedWithWrappedCFException(g); |
3134 |
– |
} |
3135 |
– |
|
3136 |
– |
/** |
3137 |
– |
* thenRunAsync result completes exceptionally if action does |
3138 |
– |
*/ |
3139 |
– |
public void testThenRunAsync3E() { |
3140 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3141 |
– |
FailingNoop r = new FailingNoop(); |
3142 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3143 |
– |
f.complete(null); |
3144 |
– |
checkCompletedWithWrappedCFException(g); |
3145 |
– |
} |
3146 |
– |
|
3147 |
– |
/** |
3148 |
– |
* thenRunAsync result completes exceptionally if source cancelled |
3149 |
– |
*/ |
3150 |
– |
public void testThenRunAsync4E() { |
3151 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3152 |
– |
Noop r = new Noop(); |
3153 |
– |
CompletableFuture<Void> g = f.thenRunAsync(r, new ThreadExecutor()); |
3154 |
– |
assertTrue(f.cancel(true)); |
3155 |
– |
checkCompletedWithWrappedCancellationException(g); |
3156 |
– |
} |
3157 |
– |
|
3158 |
– |
/** |
3159 |
– |
* thenApplyAsync result completes normally after normal completion of source |
3160 |
– |
*/ |
3161 |
– |
public void testThenApplyAsyncE() { |
3162 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3163 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3164 |
– |
f.complete(one); |
3165 |
– |
checkCompletedNormally(g, two); |
3166 |
– |
} |
3167 |
– |
|
3168 |
– |
/** |
3169 |
– |
* thenApplyAsync result completes exceptionally after exceptional |
3170 |
– |
* completion of source |
3171 |
– |
*/ |
3172 |
– |
public void testThenApplyAsync2E() { |
3173 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3174 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3175 |
– |
f.completeExceptionally(new CFException()); |
3176 |
– |
checkCompletedWithWrappedCFException(g); |
3177 |
– |
} |
3178 |
– |
|
3179 |
– |
/** |
3180 |
– |
* thenApplyAsync result completes exceptionally if action does |
3181 |
– |
*/ |
3182 |
– |
public void testThenApplyAsync3E() { |
3183 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3184 |
– |
FailingFunction r = new FailingFunction(); |
3185 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(r, new ThreadExecutor()); |
3186 |
– |
f.complete(null); |
3187 |
– |
checkCompletedWithWrappedCFException(g); |
3188 |
– |
} |
3189 |
– |
|
3190 |
– |
/** |
3191 |
– |
* thenApplyAsync result completes exceptionally if source cancelled |
3192 |
– |
*/ |
3193 |
– |
public void testThenApplyAsync4E() { |
3194 |
– |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3195 |
– |
CompletableFuture<Integer> g = f.thenApplyAsync(inc, new ThreadExecutor()); |
3196 |
– |
assertTrue(f.cancel(true)); |
3197 |
– |
checkCompletedWithWrappedCancellationException(g); |
3198 |
– |
} |
3199 |
– |
|
3200 |
– |
/** |
3014 |
|
* thenAcceptAsync result completes normally after normal |
3015 |
|
* completion of source |
3016 |
|
*/ |