2011-10-16 18:33:35 +02:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-10-16 18:33:35 +02:00
|
|
|
*/
|
|
|
|
|
package akka.dataflow
|
|
|
|
|
|
|
|
|
|
import akka.actor.{ Actor, Props }
|
2011-12-12 22:50:08 +01:00
|
|
|
import akka.dispatch.{ Future, Await }
|
2011-10-16 18:33:35 +02:00
|
|
|
import akka.util.duration._
|
|
|
|
|
import akka.testkit.AkkaSpec
|
2011-12-05 20:01:42 +01:00
|
|
|
import akka.testkit.DefaultTimeout
|
2012-02-01 14:04:01 +01:00
|
|
|
import akka.pattern.{ ask, pipe }
|
2011-10-16 18:33:35 +02:00
|
|
|
|
2011-12-05 20:01:42 +01:00
|
|
|
class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
|
2011-10-16 18:33:35 +02:00
|
|
|
|
|
|
|
|
"The Future2Actor bridge" must {
|
|
|
|
|
|
|
|
|
|
"support convenient sending to multiple destinations" in {
|
|
|
|
|
Future(42) pipeTo testActor pipeTo testActor
|
|
|
|
|
expectMsgAllOf(1 second, 42, 42)
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-29 15:13:13 +02:00
|
|
|
"support reply via sender" in {
|
2011-11-16 17:18:36 +01:00
|
|
|
val actor = system.actorOf(Props(new Actor {
|
2011-10-16 18:33:35 +02:00
|
|
|
def receive = {
|
2011-10-22 16:06:20 +02:00
|
|
|
case "do" ⇒ Future(31) pipeTo context.sender
|
|
|
|
|
case "ex" ⇒ Future(throw new AssertionError) pipeTo context.sender
|
2011-10-16 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
}))
|
2011-12-12 22:50:08 +01:00
|
|
|
Await.result(actor ? "do", timeout.duration) must be(31)
|
2011-10-16 18:33:35 +02:00
|
|
|
intercept[AssertionError] {
|
2011-12-12 22:50:08 +01:00
|
|
|
Await.result(actor ? "ex", timeout.duration)
|
2011-10-16 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|