Scala 从参与者接收的消息中提取映射
我有一个演员在一条消息中接收一张地图。我想检查一下那张地图的组成部分 在看了这里之后,我做了以下工作:Scala 从参与者接收的消息中提取映射,scala,akka,Scala,Akka,我有一个演员在一条消息中接收一张地图。我想检查一下那张地图的组成部分 在看了这里之后,我做了以下工作: testReceiver.expectMsgPF() match { case SomeMessage(answer) => { assert(answer.keys.size == 1) assert(answer.keys.head == "appId") } case _ => Failed }
testReceiver.expectMsgPF() match {
case SomeMessage(answer) => {
assert(answer.keys.size == 1)
assert(answer.keys.head == "appId")
}
case _ => Failed
}
但是,我遇到了这个问题:
[error] You can make this conversion explicit by writing `expectMsgPF _` or `expectMsgPF(_,_)(_)` instead of `expectMsgPF`.
[error] testReceiver.expectMsgPF() match {
[error] ^
之后,我将第一行更改为:
testReceiver.expectMsgPF _ match {
之后,在第二行我得到:
constructor cannot be instantiated to expected type;
[error] found : my.package.SomeMessage
[error] required: (String, String) => PartialFunction[Any,Nothing] => Nothing
我想我的方法不对
如何从消息中提取映射,然后检查其属性?那个大括号的块它实际上是一个
部分函数
您作为第二个参数pfexpectMsgPF
传递的。因此,不需要匹配
testReceiver.expectMsgPF() {
case SomeMessage(answer) => {
assert(answer.keys.size == 1)
assert(answer.keys.head == "appId")
}
case _ => Failed
}
这个用大括号括起来的块实际上是一个
PartialFunction
作为第二个参数pfexpectMsgPF
传递。因此,不需要匹配
testReceiver.expectMsgPF() {
case SomeMessage(answer) => {
assert(answer.keys.size == 1)
assert(answer.keys.head == "appId")
}
case _ => Failed
}
你有没有规定时限?请参见下面的
expectMsgPF
方法说明:
expectMsgPF[T](d:持续时间)(pf:PartialFunction[Any,T]):T
在
在给定的时间段内,必须接收消息,并且给定的部分
必须为该消息定义函数;申请的结果
返回接收到的消息的部分函数持续时间
可能未指定(这种情况下需要空括号)
改为使用块内最内层封闭的截止日期
尝试将您的代码包含在块中的中:
within(1000.millis) {
testReceiver.expectMsgPF() match {
case SomeMessage(answer) => {
assert(answer.keys.size == 1)
assert(answer.keys.head == "appId")
}
case _ => Failed
}
}
你有没有规定时限?请参见下面的expectMsgPF
方法说明:
expectMsgPF[T](d:持续时间)(pf:PartialFunction[Any,T]):T
在
在给定的时间段内,必须接收消息,并且给定的部分
必须为该消息定义函数;申请的结果
返回接收到的消息的部分函数持续时间
可能未指定(这种情况下需要空括号)
改为使用块内最内层封闭的截止日期
尝试将您的代码包含在
块中的中:
within(1000.millis) {
testReceiver.expectMsgPF() match {
case SomeMessage(answer) => {
assert(answer.keys.size == 1)
assert(answer.keys.head == "appId")
}
case _ => Failed
}
}