|
Akka/Scala example source code file (PipeToSpec.scala)
The PipeToSpec.scala Akka example source code/** * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> */ package akka.pattern import akka.testkit.AkkaSpec import akka.testkit.TestProbe import scala.concurrent.Future import akka.actor.Status class PipeToSpec extends AkkaSpec { import system.dispatcher "PipeTo" must { "work" in { val p = TestProbe() Future(42) pipeTo p.ref p.expectMsg(42) } "signal failure" in { val p = TestProbe() Future.failed(new Exception("failed")) pipeTo p.ref p.expectMsgType[Status.Failure].cause.getMessage should be("failed") } "pick up an implicit sender()" in { val p = TestProbe() implicit val s = testActor Future(42) pipeTo p.ref p.expectMsg(42) p.lastSender should be(s) } "work in Java form" in { val p = TestProbe() pipe(Future(42)) to p.ref p.expectMsg(42) } "work in Java form with sender()" in { val p = TestProbe() pipe(Future(42)) to (p.ref, testActor) p.expectMsg(42) p.lastSender should be(testActor) } } "PipeToSelection" must { "work" in { val p = TestProbe() val sel = system.actorSelection(p.ref.path) Future(42) pipeToSelection sel p.expectMsg(42) } "signal failure" in { val p = TestProbe() val sel = system.actorSelection(p.ref.path) Future.failed(new Exception("failed")) pipeToSelection sel p.expectMsgType[Status.Failure].cause.getMessage should be("failed") } "pick up an implicit sender()" in { val p = TestProbe() val sel = system.actorSelection(p.ref.path) implicit val s = testActor Future(42) pipeToSelection sel p.expectMsg(42) p.lastSender should be(s) } "work in Java form" in { val p = TestProbe() val sel = system.actorSelection(p.ref.path) pipe(Future(42)) to sel p.expectMsg(42) } "work in Java form with sender()" in { val p = TestProbe() val sel = system.actorSelection(p.ref.path) pipe(Future(42)) to (sel, testActor) p.expectMsg(42) p.lastSender should be(testActor) } } } Other Akka source code examplesHere is a short list of links related to this Akka PipeToSpec.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.