4028 |
|
} |
4029 |
|
|
4030 |
|
/** |
4031 |
+ |
* minimalStage.toCompletableFuture() returns a CompletableFuture that |
4032 |
+ |
* is completed normally, with the same value, when source is. |
4033 |
+ |
*/ |
4034 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() { |
4035 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
4036 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
4037 |
+ |
{ |
4038 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4039 |
+ |
CompletionStage<Integer> minimal = f.minimalCompletionStage(); |
4040 |
+ |
if (!createIncomplete) assertTrue(f.complete(v1)); |
4041 |
+ |
CompletableFuture<Integer> g = minimal.toCompletableFuture(); |
4042 |
+ |
if (createIncomplete) { |
4043 |
+ |
checkIncomplete(f); |
4044 |
+ |
checkIncomplete(g); |
4045 |
+ |
assertTrue(f.complete(v1)); |
4046 |
+ |
} |
4047 |
+ |
checkCompletedNormally(f, v1); |
4048 |
+ |
checkCompletedNormally(g, v1); |
4049 |
+ |
}} |
4050 |
+ |
|
4051 |
+ |
/** |
4052 |
+ |
* minimalStage.toCompletableFuture() returns a CompletableFuture that |
4053 |
+ |
* is completed exceptionally when source is. |
4054 |
+ |
*/ |
4055 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() { |
4056 |
+ |
for (boolean createIncomplete : new boolean[] { true, false }) |
4057 |
+ |
{ |
4058 |
+ |
CFException ex = new CFException(); |
4059 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4060 |
+ |
CompletionStage<Integer> minimal = f.minimalCompletionStage(); |
4061 |
+ |
if (!createIncomplete) f.completeExceptionally(ex); |
4062 |
+ |
CompletableFuture<Integer> g = minimal.toCompletableFuture(); |
4063 |
+ |
if (createIncomplete) { |
4064 |
+ |
checkIncomplete(f); |
4065 |
+ |
checkIncomplete(g); |
4066 |
+ |
f.completeExceptionally(ex); |
4067 |
+ |
} |
4068 |
+ |
checkCompletedExceptionally(f, ex); |
4069 |
+ |
checkCompletedWithWrappedException(g, ex); |
4070 |
+ |
}} |
4071 |
+ |
|
4072 |
+ |
/** |
4073 |
|
* minimalStage.toCompletableFuture() gives mutable CompletableFuture |
4074 |
|
*/ |
4075 |
|
public void testMinimalCompletionStage_toCompletableFuture_mutable() { |
4078 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4079 |
|
CompletionStage minimal = f.minimalCompletionStage(); |
4080 |
|
CompletableFuture<Integer> g = minimal.toCompletableFuture(); |
4081 |
< |
g.complete(v1); |
4081 |
> |
assertTrue(g.complete(v1)); |
4082 |
|
checkCompletedNormally(g, v1); |
4083 |
|
checkIncomplete(f); |
4084 |
|
checkIncomplete(minimal.toCompletableFuture()); |
4100 |
|
checkCompletedNormally(minimal.toCompletableFuture(), v1); |
4101 |
|
}} |
4102 |
|
|
4103 |
+ |
/** |
4104 |
+ |
* Completion of a toCompletableFuture copy of a minimal stage |
4105 |
+ |
* does not complete its source. |
4106 |
+ |
*/ |
4107 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() { |
4108 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4109 |
+ |
CompletionStage<Integer> g = f.minimalCompletionStage(); |
4110 |
+ |
assertTrue(g.toCompletableFuture().complete(1)); |
4111 |
+ |
assertTrue(g.toCompletableFuture().complete(null)); |
4112 |
+ |
assertTrue(g.toCompletableFuture().cancel(true)); |
4113 |
+ |
assertTrue(g.toCompletableFuture().cancel(false)); |
4114 |
+ |
assertTrue(g.toCompletableFuture().completeExceptionally(new CFException())); |
4115 |
+ |
checkIncomplete(g.toCompletableFuture()); |
4116 |
+ |
f.complete(1); |
4117 |
+ |
checkCompletedNormally(g.toCompletableFuture(), 1); |
4118 |
+ |
} |
4119 |
+ |
|
4120 |
|
/** Demo utility method for external reliable toCompletableFuture */ |
4121 |
|
static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) { |
4122 |
|
CompletableFuture<T> f = new CompletableFuture<>(); |