=clu #3517 Guard against wrong random selection

* When all weights in the map are zero total became 0, which is not
  valid in random pick. Treat this special case as empty WeightedRoutees, i.e.
  no availble targets and routing to deadLetters.
This commit is contained in:
Patrik Nordwall 2013-08-16 12:04:36 +02:00
parent 34eb48565b
commit 0afe653fe1
3 changed files with 12 additions and 2 deletions

View file

@ -399,7 +399,7 @@ private[cluster] class WeightedRoutees(refs: immutable.IndexedSeq[ActorRef], sel
buckets
}
def isEmpty: Boolean = buckets.length == 0
def isEmpty: Boolean = buckets.length == 0 || buckets(buckets.length - 1) == 0
def total: Int = {
require(!isEmpty, "WeightedRoutees must not be used when empty")

View file

@ -44,6 +44,16 @@ class WeightedRouteesSpec extends AkkaSpec(ConfigFactory.parseString("""
intercept[IllegalArgumentException] {
empty.total
}
val empty2 = new WeightedRoutees(Vector(refA), a1, Map(a1 -> 0))
empty2.isEmpty must be(true)
intercept[IllegalArgumentException] {
empty2.total
}
intercept[IllegalArgumentException] {
empty2(0)
}
val weighted = new WeightedRoutees(Vector(refA, refB, refC), a1, Map.empty)
weighted.total must be(3)
intercept[IllegalArgumentException] {