From ccae535c798e64aa34ddbaee15aad98edea39fa4 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Mon, 20 Feb 2012 00:44:56 +0100 Subject: [PATCH] Adding testcase for Receiver --- .../scala/akka/actor/TypedActorSpec.scala | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala index 5a9fab6c63..26f510d08a 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/TypedActorSpec.scala @@ -12,13 +12,13 @@ import java.util.concurrent.atomic.AtomicReference import annotation.tailrec import akka.testkit.{ EventFilter, filterEvents, AkkaSpec } import akka.serialization.SerializationExtension -import akka.actor.TypedActor.{ PostRestart, PreRestart, PostStop, PreStart } import java.util.concurrent.{ TimeUnit, CountDownLatch } import akka.japi.{ Creator, Option ⇒ JOption } import akka.testkit.DefaultTimeout import akka.dispatch.{ Await, Dispatchers, Future, Promise } import akka.pattern.ask import akka.serialization.JavaSerializer +import akka.actor.TypedActor._ object TypedActorSpec { @@ -160,7 +160,7 @@ object TypedActorSpec { def crash(): Unit } - class LifeCyclesImpl(val latch: CountDownLatch) extends PreStart with PostStop with PreRestart with PostRestart with LifeCycles { + class LifeCyclesImpl(val latch: CountDownLatch) extends PreStart with PostStop with PreRestart with PostRestart with LifeCycles with Receiver { override def crash(): Unit = throw new IllegalStateException("Crash!") @@ -171,6 +171,12 @@ object TypedActorSpec { override def preRestart(reason: Throwable, message: Option[Any]): Unit = for (i ← 1 to 5) latch.countDown() override def postRestart(reason: Throwable): Unit = for (i ← 1 to 7) latch.countDown() + + override def onReceive(msg: Any, sender: ActorRef): Unit = { + msg match { + case "pigdog" ⇒ sender ! "dogpig" + } + } } } @@ -415,6 +421,16 @@ class TypedActorSpec extends AkkaSpec(TypedActorSpec.config) EventFilter[IllegalStateException]("Crash!", occurrences = 1) intercept { t.crash() } + + //Sneak in a check for the Receiver override + val ref = ta getActorRefFor t + + ref.tell("pigdog", testActor) + + expectMsg(timeout.duration, "dogpig") + + //Done with that now + ta.poisonPill(t) latch.await(10, TimeUnit.SECONDS) must be === true }