gpt4 book ai didi

scala - 玩!斯卡拉 : How to disable actor modules loaded at the start of the application when testing?

转载 作者:行者123 更新时间:2023-12-02 21:01:51 25 4
gpt4 key购买 nike

我在游戏开始时加载了一些 Actor ! 2.5应用程序如下:

class Module extends AbstractModule with AkkaGuiceSupport with ScalaModule {
override def configure() = {
bindActor[MainSupervisor]("main-supervisor")
}
}

问题是,当我运行测试时,我从加载的参与者(以及整个集群和远程系统)收到很多日志(和不必要的调用),例如

[INFO ] a.r.Remoting: Starting remoting 
[INFO ] a.r.Remoting: Remoting started; listening on addresses :[akka.tcp://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="660716160a0f0507120f090826575451485648564857" rel="noreferrer noopener nofollow">[email protected]</a>:41496]
[INFO ] a.r.Remoting: Remoting now listens on addresses: [akka.tcp://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="127362627e7b7173667b7d7c522320253c223c223c23" rel="noreferrer noopener nofollow">[email protected]</a>:41496]

例如,我测试了一个不需要任何 Actor 的类,但我找不到任何方法来禁用它们(甚至更好地禁用整个 Actor 系统)。

我尝试过的是:

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 的日志。我该怎么做才能避免这种情况?

最佳答案

您必须禁用您的模块而不是 Actor 。因此,考虑到您有此类:

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()

关于scala - 玩!斯卡拉 : How to disable actor modules loaded at the start of the application when testing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37816805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com