From b6446f50dd4fece98730ab67e567dd78491b2c4a Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 21 Apr 2011 21:31:24 +0200 Subject: [PATCH] proxy isDefinedAt/apply through TestActorRef --- .../src/main/scala/akka/testkit/TestActorRef.scala | 14 +++++++++++++- .../test/scala/akka/testkit/TestActorRefSpec.scala | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala b/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala index b3c197cf7a..a31582ac3a 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala @@ -18,6 +18,18 @@ class TestActorRef[T <: Actor](factory: () => T) extends LocalActorRef(factory, dispatcher = CallingThreadDispatcher.global receiveTimeout = None + /** + * Query actor's current receive behavior. + */ + override def isDefinedAt(o : Any) = actor.isDefinedAt(o) + + /** + * Directly inject messages into actor receive behavior. Any exceptions + * thrown will be available to you, while still being able to use + * become/unbecome and their message counterparts. + */ + def apply(o : Any) { actor(o) } + /** * Retrieve reference to the underlying actor, where the static type matches the factory used inside the * constructor. Beware that this reference is discarded by the ActorRef upon restarting the actor (should this @@ -68,4 +80,4 @@ object TestActorRef { "\nOR try to change: 'actorOf[MyActor]' to 'actorOf(new MyActor)'.")) }) -} \ No newline at end of file +} diff --git a/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala b/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala index 1d79100b71..f95b78d028 100644 --- a/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala +++ b/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala @@ -172,6 +172,7 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac override def preRestart(reason: Throwable) { counter -= 1 } override def postRestart(reason: Throwable) { counter -= 1 } }).start() + self.dispatcher = CallingThreadDispatcher.global self link ref def receiveT = { case "sendKill" => ref ! Kill } }).start() @@ -230,6 +231,17 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac EventHandler.removeListener(log) } + "proxy isDefinedAt/apply for the underlying actor" in { + val ref = TestActorRef[WorkerActor].start() + ref.isDefinedAt("work") must be (true) + ref.isDefinedAt("sleep") must be (false) + val ch = Future.channel() + ref ! ch + val f = ch.future + f must be ('completed) + f() must be ("complexReply") + } + } private def stopLog() = { @@ -242,4 +254,4 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac l foreach {a => EventHandler.addListener(Actor.actorOf[EventHandler.DefaultListener])} } -} \ No newline at end of file +}