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() gives mutable CompletableFuture |
4053 |
|
*/ |
4054 |
|
public void testMinimalCompletionStage_toCompletableFuture_mutable() { |
4079 |
|
checkCompletedNormally(minimal.toCompletableFuture(), v1); |
4080 |
|
}} |
4081 |
|
|
4082 |
+ |
/** |
4083 |
+ |
* Completion of a toCompletableFuture copy of a minimal stage |
4084 |
+ |
* does not complete its source. |
4085 |
+ |
*/ |
4086 |
+ |
public void testMinimalCompletionStage_toCompletableFuture_oneWayPropagation() { |
4087 |
+ |
CompletableFuture<Integer> f = new CompletableFuture<>(); |
4088 |
+ |
CompletionStage<Integer> g = f.minimalCompletionStage(); |
4089 |
+ |
assertTrue(g.toCompletableFuture().complete(1)); |
4090 |
+ |
assertTrue(g.toCompletableFuture().complete(null)); |
4091 |
+ |
assertTrue(g.toCompletableFuture().cancel(true)); |
4092 |
+ |
assertTrue(g.toCompletableFuture().cancel(false)); |
4093 |
+ |
assertTrue(g.toCompletableFuture().completeExceptionally(new CFException())); |
4094 |
+ |
checkIncomplete(g.toCompletableFuture()); |
4095 |
+ |
f.complete(1); |
4096 |
+ |
checkCompletedNormally(g.toCompletableFuture(), 1); |
4097 |
+ |
} |
4098 |
+ |
|
4099 |
|
/** Demo utility method for external reliable toCompletableFuture */ |
4100 |
|
static <T> CompletableFuture<T> toCompletableFuture(CompletionStage<T> stage) { |
4101 |
|
CompletableFuture<T> f = new CompletableFuture<>(); |