+tes #12681 add EchoActor
This commit is contained in:
parent
0e2f356d23
commit
7ca3a9699e
5 changed files with 53 additions and 37 deletions
|
|
@ -7,19 +7,10 @@ package docs.testkit
|
|||
import akka.actor.ActorSystem
|
||||
import akka.actor.Actor
|
||||
import akka.actor.Props
|
||||
import akka.testkit.TestKit
|
||||
import akka.testkit.{ TestActors, TestKit, ImplicitSender }
|
||||
import org.scalatest.WordSpecLike
|
||||
import org.scalatest.Matchers
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import akka.testkit.ImplicitSender
|
||||
|
||||
object MySpec {
|
||||
class EchoActor extends Actor {
|
||||
def receive = {
|
||||
case x => sender() ! x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#implicit-sender
|
||||
class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
|
||||
|
|
@ -28,8 +19,6 @@ class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
|
|||
|
||||
def this() = this(ActorSystem("MySpec"))
|
||||
|
||||
import MySpec._
|
||||
|
||||
override def afterAll {
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
|
|
@ -37,7 +26,7 @@ class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
|
|||
"An Echo actor" must {
|
||||
|
||||
"send back messages unchanged" in {
|
||||
val echo = system.actorOf(Props[EchoActor])
|
||||
val echo = system.actorOf(TestActors.echoActorProps)
|
||||
echo ! "hello world"
|
||||
expectMsg("hello world")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ import akka.actor.Actor
|
|||
import akka.actor.ActorRef
|
||||
import akka.actor.ActorSystem
|
||||
import akka.actor.Props
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.testkit.ImplicitSender
|
||||
import akka.testkit.TestKit
|
||||
import akka.testkit.{ TestActors, DefaultTimeout, ImplicitSender, TestKit }
|
||||
import scala.concurrent.duration._
|
||||
import scala.collection.immutable
|
||||
|
||||
|
|
@ -34,7 +32,7 @@ class TestKitUsageSpec
|
|||
with WordSpecLike with Matchers with BeforeAndAfterAll {
|
||||
import TestKitUsageSpec._
|
||||
|
||||
val echoRef = system.actorOf(Props[EchoActor])
|
||||
val echoRef = system.actorOf(TestActors.echoActorProps)
|
||||
val forwardRef = system.actorOf(Props(classOf[ForwardingActor], testActor))
|
||||
val filterRef = system.actorOf(Props(classOf[FilteringActor], testActor))
|
||||
val randomHead = Random.nextInt(6)
|
||||
|
|
@ -112,15 +110,6 @@ object TestKitUsageSpec {
|
|||
}
|
||||
"""
|
||||
|
||||
/**
|
||||
* An Actor that echoes everything you send to it
|
||||
*/
|
||||
class EchoActor extends Actor {
|
||||
def receive = {
|
||||
case msg => sender() ! msg
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An Actor that forwards every message to a next Actor
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue