2011-06-13 22:36:46 +02:00
|
|
|
package akka.testkit
|
|
|
|
|
|
|
|
|
|
import org.scalatest.WordSpec
|
|
|
|
|
import org.scalatest.matchers.MustMatchers
|
|
|
|
|
import org.scalatest.{ BeforeAndAfterEach, WordSpec }
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.util.duration._
|
2011-12-12 22:50:08 +01:00
|
|
|
import akka.dispatch.{ Await, Future }
|
2011-12-31 17:42:13 -08:00
|
|
|
import akka.patterns.ask
|
2011-06-13 22:36:46 +02:00
|
|
|
|
2011-10-21 17:01:22 +02:00
|
|
|
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
2011-12-05 20:01:42 +01:00
|
|
|
class TestProbeSpec extends AkkaSpec with DefaultTimeout {
|
2011-06-13 22:36:46 +02:00
|
|
|
|
|
|
|
|
"A TestProbe" must {
|
|
|
|
|
|
|
|
|
|
"reply to futures" in {
|
|
|
|
|
val tk = TestProbe()
|
|
|
|
|
val future = tk.ref ? "hello"
|
|
|
|
|
tk.expectMsg(0 millis, "hello") // TestActor runs on CallingThreadDispatcher
|
2011-10-22 16:06:20 +02:00
|
|
|
tk.lastMessage.sender ! "world"
|
2011-06-13 22:36:46 +02:00
|
|
|
future must be('completed)
|
2011-12-12 22:50:08 +01:00
|
|
|
Await.result(future, timeout.duration) must equal("world")
|
2011-06-13 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"reply to messages" in {
|
|
|
|
|
val tk1 = TestProbe()
|
|
|
|
|
val tk2 = TestProbe()
|
|
|
|
|
tk1.ref.!("hello")(tk2.ref)
|
|
|
|
|
tk1.expectMsg(0 millis, "hello")
|
2011-10-22 16:06:20 +02:00
|
|
|
tk1.lastMessage.sender ! "world"
|
2011-06-13 22:36:46 +02:00
|
|
|
tk2.expectMsg(0 millis, "world")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"properly send and reply to messages" in {
|
|
|
|
|
val probe1 = TestProbe()
|
|
|
|
|
val probe2 = TestProbe()
|
|
|
|
|
probe1.send(probe2.ref, "hello")
|
|
|
|
|
probe2.expectMsg(0 millis, "hello")
|
2011-10-22 16:06:20 +02:00
|
|
|
probe2.lastMessage.sender ! "world"
|
2011-06-13 22:36:46 +02:00
|
|
|
probe1.expectMsg(0 millis, "world")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|