How to change future timeout with play framework 2.1.0

房东的猫 提交于 2019-12-22 08:55:14

问题


i'm calling a webservice using play framework 2.1 which takes longer than 10s. because of that i always receive the following error:

play.api.Application$$anon$1: Execution exception[[TimeoutException: Futures timed out after [10000 milliseconds]]]
    at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0]
    at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10.jar:2.1.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) [play_2.10.jar:2.1.0]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96) ~[scala-library.jar:na]
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58) ~[scala-library.jar:na]
    at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
    at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]

how can i increase the timeout value?

i tried to change the values of:

promise.akka.actor.typed.timeout
play.akka.actor.typed.timeout

but without success...

Thanks in advance for the help


回答1:


Unfortunately, it is hard-coded in the framework... See https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/libs/concurrent/Promise.scala#L266

It seems that an issue is already opened about that : https://github.com/playframework/Play20/issues/1002




回答2:


It looks like its been fixed in 2.3 but they are not going to back port to any of the 2.2 builds

    javaOptions in Test += "-Dtest.timeout=10000"

Since I am using 2.2 this does not work for me but I hope it works for those on 2.3




回答3:


If you are writing unit tests this is how you would do it.

@Test
public void testInServer() {
    running(testServer(3333), new Runnable() {
        public void run() {
            assertThat(
                WS.url("http://localhost:3333").get().get(timeout).getStatus()
            ).isEqualTo(OK);
        }
    });
}


来源:https://stackoverflow.com/questions/16560348/how-to-change-future-timeout-with-play-framework-2-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!