|
Akka/Scala example source code file (HeartbeatNodeRingSpec.scala)
The HeartbeatNodeRingSpec.scala Akka example source code
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.cluster
import org.scalatest.WordSpec
import org.scalatest.Matchers
import akka.actor.Address
import akka.routing.ConsistentHash
import scala.concurrent.duration._
import scala.collection.immutable
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class HeartbeatNodeRingSpec extends WordSpec with Matchers {
val aa = UniqueAddress(Address("akka.tcp", "sys", "aa", 2552), 1)
val bb = UniqueAddress(Address("akka.tcp", "sys", "bb", 2552), 2)
val cc = UniqueAddress(Address("akka.tcp", "sys", "cc", 2552), 3)
val dd = UniqueAddress(Address("akka.tcp", "sys", "dd", 2552), 4)
val ee = UniqueAddress(Address("akka.tcp", "sys", "ee", 2552), 5)
val nodes = Set(aa, bb, cc, dd, ee)
"A HashedNodeRing" must {
"pick specified number of nodes as receivers" in {
val ring = HeartbeatNodeRing(cc, nodes, 3)
ring.myReceivers should be(ring.receivers(cc))
nodes foreach { n ⇒
val receivers = ring.receivers(n)
receivers.size should be(3)
receivers should not contain (n)
}
}
"pick all except own as receivers when less than total number of nodes" in {
val expected = Set(aa, bb, dd, ee)
HeartbeatNodeRing(cc, nodes, 4).myReceivers should be(expected)
HeartbeatNodeRing(cc, nodes, 5).myReceivers should be(expected)
HeartbeatNodeRing(cc, nodes, 6).myReceivers should be(expected)
}
"pick none when alone" in {
val ring = HeartbeatNodeRing(cc, Set(cc), 3)
ring.myReceivers should be(Set())
}
}
}
Other Akka source code examplesHere is a short list of links related to this Akka HeartbeatNodeRingSpec.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.