2011-12-13 01:09:05 +01:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-12-13 01:09:05 +01:00
|
|
|
*/
|
|
|
|
|
package akka.remote
|
|
|
|
|
|
|
|
|
|
import akka.testkit._
|
|
|
|
|
import akka.routing._
|
|
|
|
|
import akka.actor._
|
2012-09-17 12:54:08 +02:00
|
|
|
import akka.remote.routing._
|
2011-12-13 01:09:05 +01:00
|
|
|
import com.typesafe.config._
|
|
|
|
|
|
|
|
|
|
object RemoteRouterSpec {
|
|
|
|
|
class Echo extends Actor {
|
|
|
|
|
def receive = {
|
2012-01-27 12:14:28 +01:00
|
|
|
case _ ⇒ sender ! self
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-17 08:45:07 +01:00
|
|
|
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
2011-12-13 01:09:05 +01:00
|
|
|
class RemoteRouterSpec extends AkkaSpec("""
|
|
|
|
|
akka {
|
|
|
|
|
actor.provider = "akka.remote.RemoteActorRefProvider"
|
2012-01-20 14:29:50 +01:00
|
|
|
remote.netty {
|
2011-12-13 01:09:05 +01:00
|
|
|
hostname = localhost
|
2012-01-27 15:21:05 +01:00
|
|
|
port = 0
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
actor.deployment {
|
|
|
|
|
/blub {
|
2012-01-17 08:45:07 +01:00
|
|
|
router = round-robin
|
2011-12-13 01:09:05 +01:00
|
|
|
nr-of-instances = 2
|
2012-04-03 15:14:40 +02:00
|
|
|
target.nodes = ["akka://remote-sys@localhost:12347"]
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
2012-01-17 08:45:07 +01:00
|
|
|
/elastic-blub {
|
|
|
|
|
router = round-robin
|
|
|
|
|
resizer {
|
|
|
|
|
lower-bound = 2
|
|
|
|
|
upper-bound = 3
|
|
|
|
|
}
|
2012-04-03 15:14:40 +02:00
|
|
|
target.nodes = ["akka://remote-sys@localhost:12347"]
|
2012-01-17 08:45:07 +01:00
|
|
|
}
|
2012-01-31 21:19:28 +01:00
|
|
|
/remote-blub {
|
2012-04-03 15:14:40 +02:00
|
|
|
remote = "akka://remote-sys@localhost:12347"
|
2012-01-31 21:19:28 +01:00
|
|
|
router = round-robin
|
|
|
|
|
nr-of-instances = 2
|
|
|
|
|
}
|
|
|
|
|
/local-blub {
|
|
|
|
|
remote = "akka://RemoteRouterSpec"
|
|
|
|
|
router = round-robin
|
|
|
|
|
nr-of-instances = 2
|
2012-04-03 15:14:40 +02:00
|
|
|
target.nodes = ["akka://remote-sys@localhost:12347"]
|
2012-01-31 21:19:28 +01:00
|
|
|
}
|
|
|
|
|
/local-blub2 {
|
|
|
|
|
router = round-robin
|
|
|
|
|
nr-of-instances = 4
|
2012-04-03 15:14:40 +02:00
|
|
|
target.nodes = ["akka://remote-sys@localhost:12347"]
|
2012-01-31 21:19:28 +01:00
|
|
|
}
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
""") with ImplicitSender {
|
|
|
|
|
|
|
|
|
|
import RemoteRouterSpec._
|
|
|
|
|
|
2012-01-31 21:19:28 +01:00
|
|
|
val conf = ConfigFactory.parseString("""akka.remote.netty.port=12347
|
|
|
|
|
akka.actor.deployment {
|
|
|
|
|
/remote-override {
|
|
|
|
|
router = round-robin
|
|
|
|
|
nr-of-instances = 4
|
|
|
|
|
}
|
|
|
|
|
}""").withFallback(system.settings.config)
|
2012-09-10 11:45:13 +02:00
|
|
|
val otherSystem = ActorSystem("remote-sys", conf)
|
2011-12-13 01:09:05 +01:00
|
|
|
|
|
|
|
|
override def atTermination() {
|
2012-09-10 11:45:13 +02:00
|
|
|
otherSystem.shutdown()
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"A Remote Router" must {
|
|
|
|
|
|
|
|
|
|
"deploy its children on remote host driven by configuration" in {
|
2011-12-13 11:32:24 +01:00
|
|
|
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(2)), "blub")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 2
|
|
|
|
|
children.map(_.parent) must have size 1
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-17 08:45:07 +01:00
|
|
|
"deploy its children on remote host driven by programatic definition" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(new RemoteRouterConfig(RoundRobinRouter(2),
|
2012-04-03 15:14:40 +02:00
|
|
|
Seq(Address("akka", "remote-sys", "localhost", 12347)))), "blub2")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 2
|
|
|
|
|
children.map(_.parent) must have size 1
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
2012-01-17 08:45:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"deploy dynamic resizable number of children on remote host driven by configuration" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(FromConfig), "elastic-blub")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5000) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children.size must be >= 2
|
|
|
|
|
children.map(_.parent) must have size 1
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"deploy remote routers based on configuration" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(FromConfig), "remote-blub")
|
2012-04-03 15:14:40 +02:00
|
|
|
router.path.address.toString must be("akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 2
|
|
|
|
|
val parents = children.map(_.parent)
|
|
|
|
|
parents must have size 1
|
|
|
|
|
parents.head must be(router.path)
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"deploy remote routers based on explicit deployment" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(2))
|
2012-04-03 15:14:40 +02:00
|
|
|
.withDeploy(Deploy(scope = RemoteScope(AddressFromURIString("akka://remote-sys@localhost:12347")))), "remote-blub2")
|
|
|
|
|
router.path.address.toString must be("akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 2
|
|
|
|
|
val parents = children.map(_.parent)
|
|
|
|
|
parents must have size 1
|
|
|
|
|
parents.head must be(router.path)
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"let remote deployment be overridden by local configuration" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(2))
|
2012-04-03 15:14:40 +02:00
|
|
|
.withDeploy(Deploy(scope = RemoteScope(AddressFromURIString("akka://remote-sys@localhost:12347")))), "local-blub")
|
2012-01-31 21:19:28 +01:00
|
|
|
router.path.address.toString must be("akka://RemoteRouterSpec")
|
|
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 2
|
|
|
|
|
val parents = children.map(_.parent)
|
|
|
|
|
parents must have size 1
|
2012-04-03 15:14:40 +02:00
|
|
|
parents.head.address must be(Address("akka", "remote-sys", "localhost", 12347))
|
|
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"let remote deployment router be overridden by local configuration" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(2))
|
2012-04-03 15:14:40 +02:00
|
|
|
.withDeploy(Deploy(scope = RemoteScope(AddressFromURIString("akka://remote-sys@localhost:12347")))), "local-blub2")
|
|
|
|
|
router.path.address.toString must be("akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 4
|
|
|
|
|
val parents = children.map(_.parent)
|
|
|
|
|
parents must have size 1
|
|
|
|
|
parents.head must be(router.path)
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"let remote deployment be overridden by remote configuration" in {
|
|
|
|
|
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(2))
|
2012-04-03 15:14:40 +02:00
|
|
|
.withDeploy(Deploy(scope = RemoteScope(AddressFromURIString("akka://remote-sys@localhost:12347")))), "remote-override")
|
|
|
|
|
router.path.address.toString must be("akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
val replies = for (i ← 1 to 5) yield {
|
|
|
|
|
router ! ""
|
|
|
|
|
expectMsgType[ActorRef].path
|
|
|
|
|
}
|
|
|
|
|
val children = replies.toSet
|
|
|
|
|
children must have size 4
|
|
|
|
|
val parents = children.map(_.parent)
|
|
|
|
|
parents must have size 1
|
|
|
|
|
parents.head must be(router.path)
|
2012-04-03 15:14:40 +02:00
|
|
|
children foreach (_.address.toString must be === "akka://remote-sys@localhost:12347")
|
2012-01-31 21:19:28 +01:00
|
|
|
system.stop(router)
|
2012-01-17 08:45:07 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-10 11:45:13 +02:00
|
|
|
"set supplied supervisorStrategy" in {
|
|
|
|
|
val escalator = OneForOneStrategy() {
|
2012-09-11 15:39:48 +02:00
|
|
|
case e ⇒ testActor ! e; SupervisorStrategy.Escalate
|
2012-09-10 11:45:13 +02:00
|
|
|
}
|
|
|
|
|
val router = system.actorOf(Props.empty.withRouter(new RemoteRouterConfig(
|
|
|
|
|
RoundRobinRouter(1, supervisorStrategy = escalator),
|
|
|
|
|
Seq(Address("akka", "remote-sys", "localhost", 12347)))), "blub3")
|
|
|
|
|
|
|
|
|
|
router ! CurrentRoutees
|
|
|
|
|
EventFilter[ActorKilledException](occurrences = 1) intercept {
|
|
|
|
|
EventFilter[ActorKilledException](occurrences = 1).intercept {
|
|
|
|
|
expectMsgType[RouterRoutees].routees.head ! Kill
|
|
|
|
|
}(otherSystem)
|
|
|
|
|
}
|
|
|
|
|
expectMsgType[ActorKilledException]
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-13 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
2011-12-14 01:06:20 +01:00
|
|
|
}
|