+tes #17023 Adding ForwardActor among test-kit actors
This commit is contained in:
parent
823ccdd3ca
commit
6b1b8316c7
2 changed files with 25 additions and 2 deletions
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
package akka.testkit
|
||||
|
||||
import akka.actor.{ Props, Actor }
|
||||
import akka.actor.{ Props, Actor, ActorRef }
|
||||
|
||||
/**
|
||||
* A collection of common actor patterns used in tests.
|
||||
|
|
@ -19,6 +19,18 @@ object TestActors {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ForwardActor forwards all messages as-is to specified ActorRef.
|
||||
*
|
||||
* @param ref target ActorRef to forward messages to
|
||||
*/
|
||||
class ForwardActor(ref: ActorRef) extends Actor {
|
||||
override def receive = {
|
||||
case message ⇒ ref forward message
|
||||
}
|
||||
}
|
||||
|
||||
val echoActorProps = Props[EchoActor]()
|
||||
def forwardActorProps(ref: ActorRef) = Props(classOf[ForwardActor], ref)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ package akka.testkit
|
|||
|
||||
class TestActorsSpec extends AkkaSpec with ImplicitSender {
|
||||
|
||||
import TestActors.echoActorProps
|
||||
import TestActors.{ echoActorProps, forwardActorProps }
|
||||
|
||||
"A EchoActor" must {
|
||||
"send back messages unchanged" in {
|
||||
|
|
@ -17,4 +17,15 @@ class TestActorsSpec extends AkkaSpec with ImplicitSender {
|
|||
expectMsg(message)
|
||||
}
|
||||
}
|
||||
|
||||
"A ForwardActor" must {
|
||||
"forward messages to target actor" in {
|
||||
val message = "forward me"
|
||||
val forward = system.actorOf(forwardActorProps(testActor))
|
||||
|
||||
forward ! message
|
||||
|
||||
expectMsg(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue