Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测试阿克卡。检查JavaTestKit探测器是否收到毒药信息_Java_Scala_Testing_Akka - Fatal编程技术网

测试阿克卡。检查JavaTestKit探测器是否收到毒药信息

测试阿克卡。检查JavaTestKit探测器是否收到毒药信息,java,scala,testing,akka,Java,Scala,Testing,Akka,我测试了我的actor系统,我需要验证actor在某些场景中是否发送了毒药消息。我用JavaTestKit探针模拟目标参与者,并尝试检查它是否收到毒药。但它不起作用: ActorSystem system = ActorSystem.create(); JavaTestKit probe = new JavaTestKit(system); probe.getRef().tell(PoisonPill.getInstance(), ActorRef.noSender()); Object o =

我测试了我的actor系统,我需要验证actor在某些场景中是否发送了毒药消息。我用JavaTestKit探针模拟目标参与者,并尝试检查它是否收到毒药。但它不起作用:

ActorSystem system = ActorSystem.create();
JavaTestKit probe = new JavaTestKit(system);
probe.getRef().tell(PoisonPill.getInstance(), ActorRef.noSender());
Object o = probe.expectMsgClass(FiniteDuration.apply(1000, TimeUnit.MILLISECONDS), Object.class);
//here we get exception

有没有办法检查探针是否已终止?

您可以通过断言与该行为相关的行为来验证是否已收到
毒药丸
——收到毒药丸的参与者将自动停止。要跟踪参与者终止,您可以使用
probe.watch(target)
,然后使用
probe.expectMsgClass(Terminated.class)
验证参与者是否已正确终止。

@Horusiath感谢您的回复。 因此,我必须再创建一个探针来测试这种行为:

ActorSystem system = ActorSystem.create("x");
ActorRef victim = TestProbe.apply(system).ref();
TestProbe probe = TestProbe.apply(system);
probe.watch(victim);
ActorRef killer = system.actorOf(Props.create(Killer.class, victim));
killer.tell("kill!", ActorRef.noSender());
probe.expectMsgClass(Terminated.class);