- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
代码是:
// pilot = Await.result(context.actorSelection(s"../$pilotName").resolveOne, 5.seconds)
pilot = context.actorFor("../" + pilotName)
actorFor 在应用和测试中运行良好。
评论的代码在应用程序中工作但在运行测试时因 akka.actor.ActorNotFound
(它查找的 Actor 存在并且我认为超时足够)而失败,这真的很奇怪。
测试是:
class PilotsSpec extends TestKit(ActorSystem("PilotsSpec",
ConfigFactory.parseString(PilotsSpec.configStr)))
with ImplicitSender with WordSpecLike with MustMatchers {
import PilotsSpec._
import plane.Plane._
def nilActor: ActorRef = TestProbe().ref
val pilotPath = s"/user/TestPilots/$pilotName"
val copilotPath = s"/user/TestPilots/$copilotName"
def pilotsReadyToGo(): ActorRef = {
implicit val timeout = Timeout(5.seconds)
val a = system.actorOf(Props(
new IsolatedStopSupervisor with OneForOneStrategyFactory {
def childrenStart() = {
context.actorOf(Props[FakePilot], pilotName)
context.actorOf(Props(new CoPilot(testActor, nilActor, nilActor)), copilotName)
}
}), "TestPilots")
Await.result(a ? IsolatedLifeCycleSupervisor.WaitForStart, 5.seconds)
system.actorFor(copilotPath) ! Pilots.ReadyToGo
a
}
"CoPilot" should {
"takecontrol when the Pilotdies" in {
pilotsReadyToGo()
// Kill the Pilot
system.actorFor(pilotPath) ! PoisonPill
// Sincethe test classis the "Plane" we can
// expect to see this request
expectMsg(GiveMeControl)
// The girl who sent it had better be Mary
lastSender must be (system.actorFor(copilotPath))
}
}
}
不知道是不是我的ActorSelection做错了。
我尝试使用 onComplete
但它仍然不起作用并在测试中抛出 ActorNotFound
异常。
val f = context.actorSelection("../" + pilotName).resolveOne
f onComplete {
case Success(v) => { pilot = v; context.watch(pilot); println("pilot get") }
case Failure(e) => throw e
}
有谁知道 actorFor 有效但 actorSelection 失败的原因(在测试中)?
然后我将下面的代码添加到测试代码中:
system.actorSelection(pilotPath).resolveOne map {v => println("------pilot:"+v)}
system.actorSelection(copilotPath).resolveOne map {v => println("------copilot:"+v)}
Thread.sleep(1000)
它可以工作并打印这些 actorRef然后我尝试用常量字符串 pilotPath
替换 ../+pilotName
但它再次失败(无论 context.actorSelection
还是 context .system.actorSelection
)
这是异常(片段):
test-only cc.akka.avionics.PilotsSpec
[info] Compiling 1 Scala source to G:\scala_workspace\akka_test_u7\target\scala-2.10\test-classes...
[warn] there were 2 deprecation warning(s); re-run with -deprecation for details
[warn] one warning found
------copilot:Actor[akka://PilotsSpec/user/TestPilots/Mary#962346268]
------pilot:Actor[akka://PilotsSpec/user/TestPilots/Mark#-320295209]
ActorSelection[Anchor(akka://PilotsSpec/user/TestPilots/Mary#962346268), Path(/../Mark)]
[ERROR] [04/29/2014 15:13:16.080] [PilotsSpec-akka.actor.default-dispatcher-4] [akka.dispatch.Dispatcher] Actor not found for: ActorSelection[Ancho r(akka://PilotsSpec/user/TestPilots/Mary#962346268), Path(/../Mark)]
akka.actor.ActorNotFound: Actor not found for: ActorSelection[Anchor(akka://PilotsSpec/user/TestPilots/Mary#962346268), Path(/../Mark)]
at akka.actor.ActorSelection$$anonfun$resolveOne$1.apply(ActorSelection.scala:65)
at akka.actor.ActorSelection$$anonfun$resolveOne$1.apply(ActorSelection.scala:63)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:67)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:82)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
at akka.dispatch.BatchingExecutor$Batch.run(BatchingExecutor.scala:58)
at akka.dispatch.ExecutionContexts$sameThreadExecutionContext$.unbatchedExecute(Future.scala:74)
at akka.dispatch.BatchingExecutor$class.execute(BatchingExecutor.scala:110)
只有actorFor在测试中有效,其他使用actorSelection
注释的代码在应用中有效但在测试中失败(很奇怪):
class CoPilot(plane: ActorRef,
var controls: ActorRef,
altimeter: ActorRef) extends Actor {
implicit val timeout = Timeout(1.second)
implicit val ct = context.dispatcher
var pilot: ActorRef = context.system.deadLetters
val pilotName: String = context.system.settings.config.getString("cc.akka.avionics.flightcrew.pilotName")
val pilotId : Int = 200
def receive = {
case ReadyToGo =>
// fails in test
// pilot = Await.result(context.actorSelection(s"../$pilotName").resolveOne, 3.seconds)
// println("get pilot:" + pilot.path + " dead:" + pilot.isTerminated)
// actorFor works
// pilot = context.actorFor("../" + pilotName)
// context.watch(pilot)
// autopilot = Await.result(context.actorSelection("../AutoPilot").resolveOne, 100.millis)
// fails in test
// val f = context.actorSelection("../" + pilotName).resolveOne
// f onComplete {
// case Success(v) => { pilot = v; context.watch(pilot); println("pilot get") }
// case Failure(e) => throw e
// }
println("-----------"+pilotName)
// fails in test
context.actorSelection("../" + pilotName) ! Identify(pilotId)
case Terminated(_) =>
plane ! GiveMeControl
case Controls(controlSurfaces) =>
controls = controlSurfaces
case ActorIdentity(pilotId, Some(ref)) =>
pilot = ref
context.watch(pilot)
println("find copilot:"+pilot)
case ActorIdentity(pilotId, None) =>
println("failed to find pilot")
}
}
最佳答案
actorFor 创建新的 Actors,而 actorSelection 寻找已经存在的 actors。
我怀疑你的 actorSelection 不起作用而你的 actorFor 起作用的原因是 Actor 目前不存在。
关于scala - “Actor not found” on context.actorSelection where actorFor works,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23356540/
Akka 已弃用 actorFor赞成 actorSelection .前者返回 ActorRef而后者返回 ActorSelection这可能是 ActorRef 的集合s。 从 actorFor
我正在制作一个基于 scala akka 的系统,它将动态地将新参与者(代表用户)添加到现有的层次结构中,因此我需要知道给定的消息是否应该导致在层次结构中创建一个新的参与者(如果它没有'已经存在)或不
我有一个 Actor ,它监视另一个 Actor (这是远程的,因此不能直接引用)。它通过使用 actorSelection 获得对 actor 的引用。和 Identify然后观察结果 ActorR
我有一个简单的集群,每个节点上都有一个名为“service”的服务参与者。该服务分别通过 ClusterClientRecptionist 公开,以便能够通过 ClusterClient 从集群外部使
我尝试从 ActorSelection 获取多个 ActorRef。有人知道是否可能吗? 我的代码 ActorRef actorRef = Await.result(getContext().acto
我对此进行了很多搜索,但仍然没有答案。 我有一个 Actor“A”(user/A) 在接收到消息“M”。为此, Actor A 使用 ActorSelection 我需要测试当我将 M 发送到 A 时
这两者有区别吗?当我做: context.actorSelection(actorNameString) 我得到一个 ActorSelection 引用,我可以使用 resolveOne 来解析它,然
akka 文档解释了在使用 ActorSelection ( http://doc.akka.io/docs/akka/snapshot/general/addressing.html#Queryin
我正在尝试使用 Akka 并在不同的 PC 上使用 actor。首先,我尝试连接到同一 JVM 和同一 ActorSystem 中的 Actor,但使用远程选择。然而,即使是这个简单的任务我也失败了。
您好!首先让我说一下,我们是 Akka 的新成员 问题 我们处于一种奇怪的情况,我们想通过 actorSelection 方法使用其路径来解析一个 actor,但在源代码中的许多情况下都会解析该路径,
akka.net 有问题。我需要访问我已经用特定名称创建的 Actor 。我可以从 IActorContext 检索 Actor ,但我很难从 ActorSystem 访问它。 我创建了一个名为 Ge
代码是: // pilot = Await.result(context.actorSelection(s"../$pilotName").resolveOne, 5.seconds)
我有一个带有 ParentOrderActor 的 Akka 系统,它接收 Create 和 Read 消息以创建和读取子级 OrderActor分别。 如果我在 main "/user/..." 路
将 Akka.net 与远程处理结合使用。 This article关于使用 ActorSelection 有以下说法: The other time when I tend to use an Ac
我从这里得到上面的错误信息: implicit val askTimeout = Timeout(60 seconds) val workerFuture = workerContext actorS
为了复制这个问题,在下面的 yaml 文件上运行 docker run zookeeper 然后 docker-compose up。 我正在使用 zookeeper 最新图像 wurstmeiste
我是一名优秀的程序员,十分优秀!