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()); |
4442 |
|
assertTrue(neverCompleted.thenRun(() -> {}).cancel(true)); |
4443 |
|
} |
4444 |
|
|
4445 |
+ |
/** |
4446 |
+ |
* Checks for garbage retention when MinimalStage.toCompletableFuture() |
4447 |
+ |
* is invoked many times. |
4448 |
+ |
* 8161600: Garbage retention when source CompletableFutures are never completed |
4449 |
+ |
* |
4450 |
+ |
* As of 2016-07, fails with OOME: |
4451 |
+ |
* ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testToCompletableFutureGarbageRetention tck |
4452 |
+ |
*/ |
4453 |
+ |
public void testToCompletableFutureGarbageRetention() throws Throwable { |
4454 |
+ |
final int n = expensiveTests ? 900_000 : 10; |
4455 |
+ |
CompletableFuture<Integer> neverCompleted = new CompletableFuture<>(); |
4456 |
+ |
CompletionStage minimal = neverCompleted.minimalCompletionStage(); |
4457 |
+ |
for (int i = 0; i < n; i++) |
4458 |
+ |
assertTrue(minimal.toCompletableFuture().cancel(true)); |
4459 |
+ |
} |
4460 |
+ |
|
4461 |
|
// static <U> U join(CompletionStage<U> stage) { |
4462 |
|
// CompletableFuture<U> f = new CompletableFuture<>(); |
4463 |
|
// stage.whenComplete((v, ex) -> { |