|
Akka/Scala example source code file (ForwardActorSpec.scala)
The ForwardActorSpec.scala Akka example source code/** * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> */ package akka.actor import language.postfixOps import akka.testkit._ import scala.concurrent.duration._ import akka.actor.Actor._ import scala.concurrent.Await import akka.pattern.{ ask, pipe } object ForwardActorSpec { val ExpectedMessage = "FOO" def createForwardingChain(system: ActorSystem): ActorRef = { val replier = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender() ! x } })) def mkforwarder(forwardTo: ActorRef) = system.actorOf(Props( new Actor { def receive = { case x ⇒ forwardTo forward x } })) mkforwarder(mkforwarder(mkforwarder(replier))) } } @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class ForwardActorSpec extends AkkaSpec { import ForwardActorSpec._ implicit val ec = system.dispatcher "A Forward Actor" must { "forward actor reference when invoking forward on tell" in { val replyTo = system.actorOf(Props(new Actor { def receive = { case ExpectedMessage ⇒ testActor ! ExpectedMessage } })) val chain = createForwardingChain(system) chain.tell(ExpectedMessage, replyTo) expectMsg(5 seconds, ExpectedMessage) } "forward actor reference when invoking forward on ask" in { val chain = createForwardingChain(system) chain.ask(ExpectedMessage)(5 seconds) pipeTo testActor expectMsg(5 seconds, ExpectedMessage) } } } Other Akka source code examplesHere is a short list of links related to this Akka ForwardActorSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.