wrap up local routing
- pull some more generic stuff out of the individual routers, add factories which take only target lists - add router parsing to Deployer, removing everything which is not strictly related to local scope, which left only few things, so move them to Deployer.scala and delete DeploymentConfig - fix ConfiguredLocalRoutingSpec to use the new configuration mechanism and verify that configuration overrides code - fix DeployerSpec by using (mostly) correct lookup paths and removing everything which was not local - change config file layout, removing everything which is not local from akka-actor/.../reference.conf, putting the remote stuff into the akka-remote/.../reference.conf (unused as of yet); adapt comments according to changed functionality
This commit is contained in:
parent
d8bc57dc17
commit
0a7e5fe296
22 changed files with 209 additions and 1427 deletions
|
|
@ -4,29 +4,31 @@ import akka.actor._
|
|||
import akka.routing._
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.actor.DeploymentConfig._
|
||||
import akka.routing.Routing.Broadcast
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.testkit._
|
||||
import akka.util.duration._
|
||||
|
||||
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
||||
class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
||||
class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||
|
||||
val deployer = system.asInstanceOf[ActorSystemImpl].provider.deployer
|
||||
|
||||
"RouterConfig" must {
|
||||
|
||||
"be overridable in config" in {
|
||||
deployer.deploy(Deploy("/config", null, None, RandomRouter(4), LocalScope))
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "get" ⇒ sender ! context.props
|
||||
}
|
||||
}).withRouting(RoundRobinRouter(12)), "config")
|
||||
actor.asInstanceOf[LocalActorRef].underlying.props.routerConfig must be === RandomRouter(4)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"round robin router" must {
|
||||
|
||||
"be able to shut down its instance" in {
|
||||
val path = system / "round-robin-0"
|
||||
|
||||
deployer.deploy(
|
||||
Deploy(
|
||||
path.toString,
|
||||
None,
|
||||
RoundRobin,
|
||||
NrOfInstances(5),
|
||||
LocalScope))
|
||||
|
||||
val helloLatch = new CountDownLatch(5)
|
||||
val stopLatch = new CountDownLatch(5)
|
||||
|
||||
|
|
@ -38,7 +40,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
override def postStop() {
|
||||
stopLatch.countDown()
|
||||
}
|
||||
}), path.name)
|
||||
}).withRouting(RoundRobinRouter(5)), "round-robin-shutdown")
|
||||
|
||||
actor ! "hello"
|
||||
actor ! "hello"
|
||||
|
|
@ -52,16 +54,6 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
}
|
||||
|
||||
"deliver messages in a round robin fashion" in {
|
||||
val path = system / "round-robin-1"
|
||||
|
||||
deployer.deploy(
|
||||
Deploy(
|
||||
path.toString,
|
||||
None,
|
||||
RoundRobin,
|
||||
NrOfInstances(10),
|
||||
LocalScope))
|
||||
|
||||
val connectionCount = 10
|
||||
val iterationCount = 10
|
||||
val doneLatch = new CountDownLatch(connectionCount)
|
||||
|
|
@ -69,7 +61,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
val counter = new AtomicInteger
|
||||
var replies = Map.empty[Int, Int]
|
||||
for (i ← 0 until connectionCount) {
|
||||
replies = replies + (i -> 0)
|
||||
replies += i -> 0
|
||||
}
|
||||
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
|
|
@ -78,7 +70,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
case "hit" ⇒ sender ! id
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
}
|
||||
}), path.name)
|
||||
}).withRouting(RoundRobinRouter(connectionCount)), "round-robin")
|
||||
|
||||
for (i ← 0 until iterationCount) {
|
||||
for (k ← 0 until connectionCount) {
|
||||
|
|
@ -92,20 +84,10 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
actor ! Broadcast("end")
|
||||
doneLatch.await(5, TimeUnit.SECONDS) must be(true)
|
||||
|
||||
replies.values foreach { _ must be(10) }
|
||||
replies.values foreach { _ must be(iterationCount) }
|
||||
}
|
||||
|
||||
"deliver a broadcast message using the !" in {
|
||||
val path = system / "round-robin-2"
|
||||
|
||||
deployer.deploy(
|
||||
Deploy(
|
||||
path.toString,
|
||||
None,
|
||||
RoundRobin,
|
||||
NrOfInstances(5),
|
||||
LocalScope))
|
||||
|
||||
val helloLatch = new CountDownLatch(5)
|
||||
val stopLatch = new CountDownLatch(5)
|
||||
|
||||
|
|
@ -117,7 +99,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
override def postStop() {
|
||||
stopLatch.countDown()
|
||||
}
|
||||
}), path.name)
|
||||
}).withRouting(RoundRobinRouter(5)), "round-robin-broadcast")
|
||||
|
||||
actor ! Broadcast("hello")
|
||||
helloLatch.await(5, TimeUnit.SECONDS) must be(true)
|
||||
|
|
@ -130,27 +112,17 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
"random router" must {
|
||||
|
||||
"be able to shut down its instance" in {
|
||||
val path = system / "random-0"
|
||||
|
||||
deployer.deploy(
|
||||
Deploy(
|
||||
path.toString,
|
||||
None,
|
||||
Random,
|
||||
NrOfInstances(7),
|
||||
LocalScope))
|
||||
|
||||
val stopLatch = new CountDownLatch(7)
|
||||
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "hello" ⇒ {}
|
||||
case "hello" ⇒ sender ! "world"
|
||||
}
|
||||
|
||||
override def postStop() {
|
||||
stopLatch.countDown()
|
||||
}
|
||||
}), path.name)
|
||||
}).withRouting(RandomRouter(7)), "random-shutdown")
|
||||
|
||||
actor ! "hello"
|
||||
actor ! "hello"
|
||||
|
|
@ -158,21 +130,15 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
actor ! "hello"
|
||||
actor ! "hello"
|
||||
|
||||
within(2 seconds) {
|
||||
for (i ← 1 to 5) expectMsg("world")
|
||||
}
|
||||
|
||||
actor.stop()
|
||||
stopLatch.await(5, TimeUnit.SECONDS) must be(true)
|
||||
}
|
||||
|
||||
"deliver messages in a random fashion" in {
|
||||
val path = system / "random-1"
|
||||
|
||||
deployer.deploy(
|
||||
Deploy(
|
||||
path.toString,
|
||||
None,
|
||||
Random,
|
||||
NrOfInstances(10),
|
||||
LocalScope))
|
||||
|
||||
val connectionCount = 10
|
||||
val iterationCount = 10
|
||||
val doneLatch = new CountDownLatch(connectionCount)
|
||||
|
|
@ -189,7 +155,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
case "hit" ⇒ sender ! id
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
}
|
||||
}), path.name)
|
||||
}).withRouting(RandomRouter(connectionCount)), "random")
|
||||
|
||||
for (i ← 0 until iterationCount) {
|
||||
for (k ← 0 until connectionCount) {
|
||||
|
|
@ -204,19 +170,10 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
doneLatch.await(5, TimeUnit.SECONDS) must be(true)
|
||||
|
||||
replies.values foreach { _ must be > (0) }
|
||||
replies.values.sum must be === iterationCount * connectionCount
|
||||
}
|
||||
|
||||
"deliver a broadcast message using the !" in {
|
||||
val path = system / "random-2"
|
||||
|
||||
deployer.deploy(
|
||||
Deploy(
|
||||
path.toString,
|
||||
None,
|
||||
Random,
|
||||
NrOfInstances(6),
|
||||
LocalScope))
|
||||
|
||||
val helloLatch = new CountDownLatch(6)
|
||||
val stopLatch = new CountDownLatch(6)
|
||||
|
||||
|
|
@ -228,7 +185,7 @@ class ConfiguredLocalRoutingSpec extends AkkaSpec with DefaultTimeout {
|
|||
override def postStop() {
|
||||
stopLatch.countDown()
|
||||
}
|
||||
}), path.name)
|
||||
}).withRouting(RandomRouter(6)), "random-broadcast")
|
||||
|
||||
actor ! Broadcast("hello")
|
||||
helloLatch.await(5, TimeUnit.SECONDS) must be(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue