fishForSpecificMessage #20118
This commit is contained in:
parent
b2721b9dc3
commit
a9efcf7098
3 changed files with 52 additions and 1 deletions
|
|
@ -439,6 +439,21 @@ trait TestKitBase {
|
||||||
recv
|
recv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as `fishForMessage`, but gets a different partial function and returns properly typed message.
|
||||||
|
*/
|
||||||
|
def fishForSpecificMessage[T](max: Duration = Duration.Undefined, hint: String = "")(f: PartialFunction[Any, T]): T = {
|
||||||
|
val _max = remainingOrDilated(max)
|
||||||
|
val end = now + _max
|
||||||
|
@tailrec
|
||||||
|
def recv: T = {
|
||||||
|
val o = receiveOne(end - now)
|
||||||
|
assert(o ne null, s"timeout (${_max}) during fishForSpecificMessage, hint: $hint")
|
||||||
|
if (f.isDefinedAt(o)) f(o) else recv
|
||||||
|
}
|
||||||
|
recv
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as `expectMsgType[T](remainingOrDefault)`, but correctly treating the timeFactor.
|
* Same as `expectMsgType[T](remainingOrDefault)`, but correctly treating the timeFactor.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,37 @@ class TestProbeSpec extends AkkaSpec with DefaultTimeout {
|
||||||
expectMsgAllClassOf(5 seconds, classOf[Int]) should ===(Seq(42))
|
expectMsgAllClassOf(5 seconds, classOf[Int]) should ===(Seq(42))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"be able to fish for messages" in {
|
||||||
|
val probe = TestProbe()
|
||||||
|
probe.ref ! "hallo"
|
||||||
|
probe.ref ! "welt"
|
||||||
|
probe.ref ! "fishForMe"
|
||||||
|
probe.ref ! "done"
|
||||||
|
|
||||||
|
probe.fishForMessage() {
|
||||||
|
case "fishForMe" ⇒ true
|
||||||
|
case _ ⇒ false
|
||||||
|
}
|
||||||
|
|
||||||
|
probe.expectMsg(1 second, "done")
|
||||||
|
}
|
||||||
|
|
||||||
|
"be able to fish for specific messages" in {
|
||||||
|
val probe = TestProbe()
|
||||||
|
probe.ref ! "hallo"
|
||||||
|
probe.ref ! "welt"
|
||||||
|
probe.ref ! "fishForMe"
|
||||||
|
probe.ref ! "done"
|
||||||
|
|
||||||
|
val msg: String = probe.fishForSpecificMessage() {
|
||||||
|
case msg @ "fishForMe" ⇒ msg
|
||||||
|
}
|
||||||
|
|
||||||
|
msg should be("fishForMe")
|
||||||
|
|
||||||
|
probe.expectMsg(1 second, "done")
|
||||||
|
}
|
||||||
|
|
||||||
"be able to ignore primitive types" in {
|
"be able to ignore primitive types" in {
|
||||||
ignoreMsg { case 42 ⇒ true }
|
ignoreMsg { case 42 ⇒ true }
|
||||||
testActor ! 42
|
testActor ! 42
|
||||||
|
|
|
||||||
|
|
@ -1043,7 +1043,12 @@ object MiMa extends AutoPlugin {
|
||||||
// #22277 changes to internal classes
|
// #22277 changes to internal classes
|
||||||
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.remote.transport.netty.TcpServerHandler.this"),
|
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.remote.transport.netty.TcpServerHandler.this"),
|
||||||
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.remote.transport.netty.TcpClientHandler.this"),
|
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.remote.transport.netty.TcpClientHandler.this"),
|
||||||
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.remote.transport.netty.TcpHandlers.log")
|
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.remote.transport.netty.TcpHandlers.log"),
|
||||||
|
|
||||||
|
// #22374 introduce fishForSpecificMessage in TestKit
|
||||||
|
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.testkit.TestKitBase.fishForSpecificMessage$default$1"),
|
||||||
|
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.testkit.TestKitBase.fishForSpecificMessage"),
|
||||||
|
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.testkit.TestKitBase.fishForSpecificMessage$default$2")
|
||||||
)
|
)
|
||||||
// make sure that
|
// make sure that
|
||||||
// * this list ends with the latest released version number
|
// * this list ends with the latest released version number
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue