From e9a6c16bdc14c6cde472a8660cecf05105248823 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 3 Apr 2012 15:38:54 +0200 Subject: [PATCH] fix CallingThreadMailbox.hasMessages, see #1918 --- .../scala/akka/testkit/CallingThreadDispatcher.scala | 5 +++++ .../test/scala/akka/testkit/TestActorRefSpec.scala | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala b/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala index aba582ae68..84ea7aa197 100644 --- a/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala +++ b/akka-testkit/src/main/scala/akka/testkit/CallingThreadDispatcher.scala @@ -291,6 +291,11 @@ class CallingThreadMailbox(_receiver: ActorCell, val mailboxType: MailboxType) e } } + override def enqueue(receiver: ActorRef, msg: Envelope): Unit = throw new UnsupportedOperationException("CallingThreadMailbox cannot enqueue normally") + override def dequeue(): Envelope = throw new UnsupportedOperationException("CallingThreadMailbox cannot dequeue normally") + override def hasMessages: Boolean = q.get.q.hasMessages + override def numberOfMessages: Int = -1 + def queue = q.get val ctdLock = new ReentrantLock diff --git a/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala b/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala index 92476a4249..7c977884fc 100644 --- a/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala +++ b/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala @@ -87,6 +87,13 @@ object TestActorRefSpec { } } + class ReceiveTimeoutActor(target: ActorRef) extends Actor { + context setReceiveTimeout 1.second + def receive = { + case ReceiveTimeout ⇒ target ! "timeout" + } + } + } @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) @@ -203,6 +210,11 @@ class TestActorRefSpec extends AkkaSpec("disp1.type=Dispatcher") with BeforeAndA Await.result(f, timeout.duration) must equal("workDone") } + "support receive timeout" in { + val a = TestActorRef(new ReceiveTimeoutActor(testActor)) + expectMsg("timeout") + } + } "A TestActorRef" must {