This file contains hidden or 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
@Override | |
public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry) { | |
return getRetryDecision(cl, nbRetry); | |
} | |
private RetryDecision getRetryDecision(ConsistencyLevel cl, int nbRetry) { | |
if (nbRetry >= numberOfTimesToRetry) { | |
return RetryDecision.rethrow(); | |
} | |
return RetryDecision.retry(cl); |
This file contains hidden or 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
Cluster cluster = Cluster.builder() | |
.addContactPoint("127.0.0.1") | |
.withRetryPolicy(new LoggingRetryPolicy(new FixedNumberRetryPolicy(3))) | |
.build(); |
This file contains hidden or 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 batey.akka.testing.backtosender | |
import akka.actor.Actor | |
class Server extends Actor { | |
def receive: Actor.Receive = { | |
case msg @ _ => { | |
println("I should really send something back!") | |
} | |
} |
This file contains hidden or 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 batey.akka.testing.backtosender | |
import akka.testkit.{ImplicitSender, TestKit} | |
import akka.actor.{Props, ActorSystem} | |
import org.scalatest.FunSuiteLike | |
class ServerTest extends TestKit(ActorSystem("TestSystem")) with FunSuiteLike with ImplicitSender { | |
test("Should send back Ready message when Startup message is received") { | |
val actorRef = system.actorOf(Props[Server]) |
This file contains hidden or 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 batey.akka.testing.backtosender | |
import akka.actor.Actor | |
import batey.akka.testing.backtosender.Messages.{Ready, Startup} | |
class Server extends Actor { | |
def receive: Actor.Receive = { | |
case Startup => { | |
sender ! Ready | |
} |
This file contains hidden or 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
class ParentActor extends Actor { | |
def receive: Actor.Receive = { | |
case msg @ _ => { | |
println(s"Received msg, delegating work to a child actor") | |
val childActor = context.actorOf(Props[ChildActor]) | |
childActor ! "Go and do something important!" | |
} | |
} | |
} |
This file contains hidden or 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
class ParentActorTest extends TestKit(ActorSystem("TestSystem")) with FunSuiteLike { | |
test("Should delegate the important work to the client") { | |
val underTest = TestActorRef(new ParentActor) | |
underTest ! "Go do some work" | |
// how do i test this? | |
} | |
} |
This file contains hidden or 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
class ParentActor(childFactory: (ActorRefFactory) => ActorRef) extends Actor { | |
def receive: Actor.Receive = { | |
case msg @ _ => { | |
println(s"Received msg, delegating work to a child actor") | |
val childActor = childFactory(context) | |
childActor ! "Go and do something important!" | |
} | |
} | |
} |
This file contains hidden or 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
class ParentActorTest extends TestKit(ActorSystem("TestSystem")) with FunSuiteLike { | |
test("Should delegate the important work to the client") { | |
val testProbeForChild = TestProbe() | |
val underTest = TestActorRef(new ParentActor(_ => testProbeForChild.ref)) | |
underTest ! "Go do some work" | |
testProbeForChild.expectMsg("Go and do something important!") | |
} | |
} |
This file contains hidden or 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
test("Using a real child actor") { | |
val underTest = TestActorRef(new ParentActor(actorFactory => actorFactory.actorOf(Props[ChildActor]))) | |
underTest ! "Go do some work" | |
// Can't test this but shows how to crate a ParentActor in production code | |
} |