44
55import java .util .concurrent .Callable ;
66import java .util .concurrent .CompletableFuture ;
7+ import java .util .concurrent .ExecutorService ;
8+ import java .util .concurrent .Executors ;
79
810import org .jooby .AsyncMapper ;
911import org .jooby .test .ServerFeature ;
1214public class Issue490 extends ServerFeature {
1315
1416 {
17+ ExecutorService executor = Executors .newSingleThreadExecutor (r -> {
18+ Thread thread = new Thread (r , CompletableFuture .class .getSimpleName ());
19+ thread .setDaemon (true );
20+ return thread ;
21+ });
22+ onStop (() -> executor .shutdown ());
1523 map (new AsyncMapper ());
1624
1725 get ("/490/callable" , () -> (Callable <String >) () -> Thread .currentThread ().getName ());
1826
1927 get ("/490/future" , () -> CompletableFuture
20- .supplyAsync (() -> Thread .currentThread ().getName ()));
28+ .supplyAsync (() -> Thread .currentThread ().getName (), executor ));
2129
2230 get ("/490" , () -> "OK" );
2331
@@ -28,6 +36,7 @@ public void shouldMapCallbale() throws Exception {
2836 request ()
2937 .get ("/490/callable" )
3038 .expect (rsp -> {
39+ System .out .println (rsp );
3140 assertTrue (rsp .toLowerCase ().contains ("task" ));
3241 });
3342 }
@@ -37,7 +46,8 @@ public void shouldMapCompletableFuture() throws Exception {
3746 request ()
3847 .get ("/490/future" )
3948 .expect (rsp -> {
40- assertTrue (rsp .toLowerCase ().startsWith ("forkjoinpool" ));
49+ String value = rsp ;
50+ assertTrue (value , CompletableFuture .class .getSimpleName ().equals (value ));
4151 });
4252 }
4353
0 commit comments