Created
February 13, 2018 16:55
-
-
Save m0essy/4346e710924ad5d67c104acec7ecde90 to your computer and use it in GitHub Desktop.
Akka Actor using faulty pipeTo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.snekyx.strange.actors | |
import akka.actor.{Actor, Props} | |
import akka.pattern.pipe | |
import com.bsh.hca.account.view.FaultyPipeToActor.SomeMsg | |
import scala.concurrent.Future | |
object FaultyPipeToActor { | |
def props: Props = Props(new FaultyPipeToActor()) | |
case class SomeMsg(payload: Int) | |
} | |
class FaultyPipeToActor extends Actor { | |
import scala.concurrent.ExecutionContext.Implicits.global | |
override def receive: Receive = { | |
case msg: SomeMsg => | |
if(msg.payload == 0) { | |
Future { msg.payload + 1 } | |
} else { | |
Future { msg.payload } | |
} pipeTo sender() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.snekyx.strange.actors | |
import akka.actor.ActorSystem | |
import akka.pattern.ask | |
import akka.testkit.{ImplicitSender, TestKit} | |
import akka.util.Timeout | |
import com.bsh.hca.account.view.FaultyPipeToActor.IncreaseBy1 | |
import org.specs2.mutable.SpecificationLike | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
class FaultyPipeToActorTest extends TestKit(ActorSystem()) with SpecificationLike with ImplicitSender { | |
val actorUnderTest = system.actorOf(FaultyPipeToActor.props) | |
implicit val timeout = Timeout(2 seconds) | |
"FaultyPipeToActor" should { | |
"increase the payload by 1" in { | |
val result = Await.result(actorUnderTest ? IncreaseBy1(1), 2 seconds) | |
result === 2 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment