pekko/akka-actor-tests/src/test/scala/akka/dataflow/Future2Actor.scala
Patrik Nordwall 5c96a5f556 replace unicode arrows
* ⇒, →, ←
* because we don't want to show them in documentation snippets and
  then it's complicated to avoid that when snippets are
  located in src/test/scala in individual modules
* dont replace object `→` in FSM.scala and PersistentFSM.scala
2019-03-11 16:58:51 +01:00

53 lines
1.7 KiB
Scala

/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.dataflow
import language.postfixOps
import akka.actor.{ Actor, Props }
import scala.concurrent.Future
import scala.concurrent.Await
import scala.concurrent.duration._
import akka.testkit.{ AkkaSpec, DefaultTimeout }
import akka.pattern.{ ask, pipe }
import scala.concurrent.ExecutionException
class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
implicit val ec = system.dispatcher
"The Future2Actor bridge" must {
"support convenient sending to multiple destinations" in {
Future(42) pipeTo testActor pipeTo testActor
expectMsgAllOf(1 second, 42, 42)
}
"support convenient sending to multiple destinations with implicit sender" in {
implicit val someActor = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }))
Future(42) pipeTo testActor pipeTo testActor
expectMsgAllOf(1 second, 42, 42)
lastSender should ===(someActor)
}
"support convenient sending with explicit sender" in {
val someActor = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }))
Future(42).to(testActor, someActor)
expectMsgAllOf(1 second, 42)
lastSender should ===(someActor)
}
"support reply via sender" in {
val actor = system.actorOf(Props(new Actor {
def receive = {
case "do" => Future(31) pipeTo context.sender()
case "ex" => Future(throw new AssertionError) pipeTo context.sender()
}
}))
Await.result(actor ? "do", timeout.duration) should ===(31)
intercept[ExecutionException] {
Await.result(actor ? "ex", timeout.duration)
}.getCause.isInstanceOf[AssertionError] should ===(true)
}
}
}