|
7 | 7 | import scala.concurrent.Future;
|
8 | 8 | import scala.concurrent.Promise;
|
9 | 9 |
|
10 |
| -import java.util.concurrent.CompletableFuture; |
11 |
| -import java.util.concurrent.CompletionStage; |
12 |
| -import java.util.concurrent.CountDownLatch; |
13 |
| -import java.util.concurrent.ExecutionException; |
| 10 | +import java.util.concurrent.*; |
14 | 11 |
|
| 12 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; |
15 | 13 | import static java.util.concurrent.TimeUnit.SECONDS;
|
16 | 14 | import static org.junit.Assert.*;
|
17 | 15 | import static scala.compat.java8.FutureConverters.*;
|
@@ -319,6 +317,30 @@ public void testToJavaExceptionally() throws InterruptedException,
|
319 | 317 | assertEquals("Hello", second.toCompletableFuture().get());
|
320 | 318 | }
|
321 | 319 |
|
| 320 | + @Test |
| 321 | + public void testToJavaThenComposeWithToJavaThenAccept() throws InterruptedException, |
| 322 | + ExecutionException, TimeoutException { |
| 323 | + final Promise<String> p1 = promise(); |
| 324 | + final CompletableFuture<String> future = new CompletableFuture<>(); |
| 325 | + |
| 326 | + final CompletionStage<String> second = |
| 327 | + CompletableFuture.supplyAsync(() -> "Hello"). |
| 328 | + thenCompose(x -> toJava(p1.future())); |
| 329 | + |
| 330 | + second.handle((x, t) -> { |
| 331 | + if (t != null) { |
| 332 | + t.printStackTrace(); |
| 333 | + future.completeExceptionally(t); |
| 334 | + } else { |
| 335 | + future.complete(x); |
| 336 | + } |
| 337 | + return null; |
| 338 | + }); |
| 339 | + |
| 340 | + p1.success("Hello"); |
| 341 | + assertEquals("Hello", future.get(1000, MILLISECONDS)); |
| 342 | + } |
| 343 | + |
322 | 344 | @Test
|
323 | 345 | public void testToJavaToCompletableFuture() throws ExecutionException, InterruptedException {
|
324 | 346 | final Promise<String> p = promise();
|
|
0 commit comments