Verify config override of router nr-of-instances. See #1607

* It wasn't a bug. I think the confusion came from config without 'router' defined.
* Added test
* Added some clarification to docs
This commit is contained in:
Patrik Nordwall 2012-01-10 17:50:17 +01:00
parent 0d4763c3b0
commit 762a6017e9
4 changed files with 34 additions and 5 deletions

View file

@ -15,6 +15,15 @@ import com.typesafe.config.ConfigFactory
object RoutingSpec {
val config = """
akka.actor.deployment {
/router1 {
router = round-robin
nr-of-instances = 3
}
}
"""
class TestActor extends Actor {
def receive = {
case _
@ -31,7 +40,7 @@ object RoutingSpec {
}
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with ImplicitSender {
import akka.routing.RoutingSpec._
@ -87,6 +96,18 @@ class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
Await.ready(doneLatch, 1 seconds)
}
"use configured nr-of-instances when FromConfig" in {
val router = system.actorOf(Props[TestActor].withRouter(FromConfig), "router1")
Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(3)
system.stop(router)
}
"use configured nr-of-instances when router is specified" in {
val router = system.actorOf(Props[TestActor].withRouter(RoundRobinRouter(nrOfInstances = 2)), "router1")
Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(3)
system.stop(router)
}
}
"no router" must {

View file

@ -76,6 +76,7 @@ akka {
# supplied in the source code (overridable using create-as below)
# - routees.paths: will look the paths up using actorFor and route to
# them, i.e. will not create children
# - resizer: dynamically resizable number of routees as specified in resizer below
router = "from-code"
# number of children to create in case of a non-direct router; this setting

View file

@ -44,8 +44,9 @@ You can also give the router already created routees as in:
When you create a router programatically you define the number of routees *or* you pass already created routees to it.
If you send both parameters to the router *only* the latter will be used, i.e. ``nrOfInstances`` is disregarded.
*It is also worth pointing out that if you define the number of routees in the configuration file then this
value will be used instead of any programmatically sent parameters.*
*It is also worth pointing out that if you define the number of routees (``nr-of-instances`` or ``routees``) in
the configuration file then this value will be used instead of any programmatically sent parameters, but you must
also define the ``router`` property in the configuration.*
Once you have the router actor it is just to send messages to it as you would to any actor:
@ -189,6 +190,9 @@ This is an example of how to programatically create a resizable router:
.. includecode:: code/akka/docs/jrouting/RouterViaProgramExample.java#programmaticRoutingWithResizer
*It is also worth pointing out that if you define the ``router`` in the configuration file then this value
will be used instead of any programmatically sent parameters.*
Custom Router
^^^^^^^^^^^^^

View file

@ -44,8 +44,9 @@ You can also give the router already created routees as in:
When you create a router programatically you define the number of routees *or* you pass already created routees to it.
If you send both parameters to the router *only* the latter will be used, i.e. ``nrOfInstances`` is disregarded.
*It is also worth pointing out that if you define the number of routees in the configuration file then this
value will be used instead of any programmatically sent parameters.*
*It is also worth pointing out that if you define the number of routees (``nr-of-instances`` or ``routees``) in
the configuration file then this value will be used instead of any programmatically sent parameters, but you must
also define the ``router`` property in the configuration.*
Once you have the router actor it is just to send messages to it as you would to any actor:
@ -190,6 +191,8 @@ This is an example of how to programatically create a resizable router:
.. includecode:: code/akka/docs/routing/RouterViaProgramExample.scala#programmaticRoutingWithResizer
*It is also worth pointing out that if you define the ``router`` in the configuration file then this value
will be used instead of any programmatically sent parameters.*
Custom Router
^^^^^^^^^^^^^