我在Play的开头加载了一些演员! 2.5这样的应用程序:
class Module extends AbstractModule with AkkaGuiceSupport with ScalaModule {
override def configure() = {
bindActor[MainSupervisor]("main-supervisor")
}
}
问题在于,当我运行测试时,我从加载的actor(以及整个集群和远程系统)获得了很多日志(和不必要的调用),如
[INFO ] a.r.Remoting: Starting remoting
[INFO ] a.r.Remoting: Remoting started; listening on addresses :[akka.tcp://application@127.0.0.1:41496]
[INFO ] a.r.Remoting: Remoting now listens on addresses: [akka.tcp://application@127.0.0.1:41496]
例如,我有一个我测试的课程,我不需要任何演员,但是我找不到任何方法来禁用它们(甚至更好的是整个演员系统)。
我试过的是:
lazy val appWithoutActorsBuilder = new GuiceApplicationBuilder()
.disable[ActorSystem]
.disable[MainSupervisor]
.build()
lazy val injectorWithoutActors = appWithoutActorsBuilder.injector
lazy val wSClientWithoutActors = injectorWithoutActors.instanceOf[WSClient]
lazy val ec = scala.concurrent.ExecutionContext.Implicits.global
lazy val facebookAPI = new FacebookAPI(wSClientWithoutActors, ec)
但是当我测试FacebookAPI方法(例如facebookAPI.method(...) mustBe ...
)时,我仍然会看到来自Akka的日志。我该怎么办才能避免它?
答案 0 :(得分:4)
您必须禁用模块而不是演员。所以,考虑到你有这个课程:
package com.acme.modules
class Module extends AbstractModule with AkkaGuiceSupport with ScalaModule {
override def configure() = {
bindActor[MainSupervisor]("main-supervisor")
}
}
并且您正在conf/application.conf
注册它:
play.modules.enabled += "com.acme.modules.Module"
然后,在您的测试中,您必须执行以下操作:
lazy val appWithoutActorsBuilder = new GuiceApplicationBuilder()
.disable[com.acme.modules.Module]
.build()