玩框架测试连接拒绝

时间:2015-10-02 08:08:04

标签: java testing playframework-2.0

我的Play 2.4应用程序存在很大问题。每次我尝试使用activator test启动我的应用程序时,都会收到以下错误:

java.net.ConnectException: Connection refused: localhost/127.0.0.1:9000, took 0.0 sec 
[error] at com.ning.http.client.providers.netty.request.NettyConnectListener.onFutureFailure(NettyConnectListener.java:128)
[error]     at com.ning.http.client.providers.netty.request.NettyConnectListener.operationComplete(NettyConnectListener.java:140)
[error]     at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:409)
[error]     at org.jboss.netty.channel.DefaultChannelFuture.addListener(DefaultChannelFuture.java:145)
[error]     at com.ning.http.client.providers.netty.request.NettyRequestSender.sendRequestWithNewChannel(NettyRequestSender.java:283)
[error]     at com.ning.http.client.providers.netty.request.NettyRequestSender.sendRequestWithCertainForceConnect(NettyRequestSender.java:140)
[error]     at com.ning.http.client.providers.netty.request.NettyRequestSender.sendRequest(NettyRequestSender.java:115)
[error]     at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(NettyAsyncHttpProvider.java:87)
[error]     at com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.java:506)
[error]     at play.libs.ws.ning.NingWSRequest.execute(NingWSRequest.java:509)
[error]     at play.libs.ws.ning.NingWSRequest.execute(NingWSRequest.java:395)
[error]     at play.libs.ws.ning.NingWSRequest.post(NingWSRequest.java:322)
[error]     at controllers.projeckerSystem.LoginController.login(LoginController.java:28)
[error]     at projeckerSystem.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:504)
[error]     at projeckerSystem.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:504)
[error]     at play.core.routing.HandlerInvokerFactory$$anon$5.resultCall(HandlerInvoker.scala:139)
[error]     at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvoker.scala:127)
[error]     at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:70)
[error]     at play.GlobalSettings$1.call(GlobalSettings.java:67)
[error]     at play.db.jpa.TransactionalAction.lambda$call$5(TransactionalAction.java:19)
[error]     at play.db.jpa.DefaultJPAApi.withTransaction(DefaultJPAApi.java:136)
[error]     at play.db.jpa.JPA.withTransaction(JPA.java:159)
[error]     at play.db.jpa.TransactionalAction.call(TransactionalAction.java:16)
[error]     at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94)
[error]     at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94)
[error]     at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
[error]     at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
[error]     at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:40)
[error]     at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70)
[error]     at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32)
[error]     at scala.concurrent.impl.Future$.apply(Future.scala:31)
[error]     at scala.concurrent.Future$.apply(Future.scala:492)
[error]     at play.core.j.JavaAction.apply(JavaAction.scala:94)
[error]     at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105)
[error]     at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105)
[error]     at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
[error]     at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104)
[error]     at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:103)
[error]     at scala.Option.map(Option.scala:146)
[error]     at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103)
[error]     at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96)
[error]     at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524)
[error]     at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524)
[error]     at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560)
[error]     at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560)
[error]     at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$14.apply(Iteratee.scala:537)
[error]     at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$14.apply(Iteratee.scala:537)
[error]     at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
[error]     at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
[error]     at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
[error]     at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397)
[error]     at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
[error]     at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
[error]     at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
[error]     at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
[error] Caused by: java.net.ConnectException: Connection refused: localhost/127.0.0.1:9000
[error]     at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
[error]     at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
[error]     at org.jboss.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:152)
[error]     at org.jboss.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
[error]     at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
[error]     at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
[error]     at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
[error]     at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
[error]     at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error]     at java.lang.Thread.run(Thread.java:745)

当我使用activator run启动第二个应用程序并再次执行测试时,没有问题,测试成功运行。我怀疑配置有问题,但我找不到问题。有人可以帮忙吗?

编辑: 这是我的一些代码。

@Test
public void test(){
   RequestBuilder requestBuilder = new RequestBuilder()
   .method(Helpers.POST)
   .uri("...");
   Result result = Helpers.route(request);

   assertEquals(OK, result.status());
}

我在BeforeClass方法中全局启动FakeApplication。

@BeforeClass
public static void startApp(){
    app = Helpers.fakeApplication();
    Helpers.start(app);
}

0 个答案:

没有答案