Skip to content
Browse files

Added NodeGossipingSpec for testing gossiping and cluster membership.

Signed-off-by: Jonas Bonér <jonas@jonasboner.com>
  • Loading branch information...
1 parent cb9ce7b commit 9de7a2daae1c96aeb9d77df0acee3ab5098d43ee @jboner jboner committed Feb 14, 2012
Showing with 141 additions and 0 deletions.
  1. +141 −0 akka-cluster/src/test/scala/akka/cluster/NodeGossipingSpec.scala
View
141 akka-cluster/src/test/scala/akka/cluster/NodeGossipingSpec.scala
@@ -0,0 +1,141 @@
+/**
+ * Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
+ */
+package akka.cluster
+
+import java.net.InetSocketAddress
+
+import akka.testkit._
+import akka.dispatch._
+import akka.actor._
+import akka.remote._
+
+import com.typesafe.config._
+
+class NodeGossipingSpec extends AkkaSpec("""
+ akka {
+ loglevel = "DEBUG"
+ }
+ """) with ImplicitSender {
+
+ var gossiper0: Gossiper = _
+ var gossiper1: Gossiper = _
+ var gossiper2: Gossiper = _
+
+ var node0: ActorSystemImpl = _
+ var node1: ActorSystemImpl = _
+ var node2: ActorSystemImpl = _
+
+ try {
+ "A set of connected cluster nodes" must {
+ "(when two nodes) start gossiping to each other so that both nodes gets the same gossip info" in {
+ node0 = ActorSystem("NodeGossipingSpec", ConfigFactory
+ .parseString("""
+ akka {
+ actor.provider = "akka.remote.RemoteActorRefProvider"
+ remote.netty {
+ hostname = localhost
+ port=5550
+ }
+ }""")
+ .withFallback(system.settings.config))
+ .asInstanceOf[ActorSystemImpl]
+ val remote0 = node0.provider.asInstanceOf[RemoteActorRefProvider]
+ gossiper0 = Gossiper(node0, remote0)
+
+ node1 = ActorSystem("NodeGossipingSpec", ConfigFactory
+ .parseString("""
+ akka {
+ actor.provider = "akka.remote.RemoteActorRefProvider"
+ remote.netty {
+ hostname = localhost
+ port=5551
+ }
+ cluster.node-to-join = "akka://NodeGossipingSpec@localhost:5550"
+ }""")
+ .withFallback(system.settings.config))
+ .asInstanceOf[ActorSystemImpl]
+ val remote1 = node1.provider.asInstanceOf[RemoteActorRefProvider]
+ gossiper1 = Gossiper(node1, remote1)
+
+ Thread.sleep(5000)
+
+ val members0 = gossiper0.latestGossip.members.toArray
+ members0.size must be(2)
+ members0(0).address.port.get must be(5550)
+ members0(0).status must be(MemberStatus.Joining)
+ members0(1).address.port.get must be(5551)
+ members0(1).status must be(MemberStatus.Joining)
+
+ val members1 = gossiper1.latestGossip.members.toArray
+ members1.size must be(2)
+ members1(0).address.port.get must be(5550)
+ members1(0).status must be(MemberStatus.Joining)
+ members1(1).address.port.get must be(5551)
+ members1(1).status must be(MemberStatus.Joining)
+ }
+
+ "(when three nodes) start gossiping to each other so that both nodes gets the same gossip info" in {
+ node2 = ActorSystem("NodeGossipingSpec", ConfigFactory
+ .parseString("""
+ akka {
+ actor.provider = "akka.remote.RemoteActorRefProvider"
+ remote.netty {
+ hostname = localhost
+ port=5552
+ }
+ cluster.node-to-join = "akka://NodeGossipingSpec@localhost:5550"
+ }""")
+ .withFallback(system.settings.config))
+ .asInstanceOf[ActorSystemImpl]
+ val remote2 = node2.provider.asInstanceOf[RemoteActorRefProvider]
+ gossiper2 = Gossiper(node2, remote2)
+
+ Thread.sleep(10000)
+
+ val members0 = gossiper0.latestGossip.members.toArray
+ val version = gossiper0.latestGossip.version
+ members0.size must be(3)
+ members0(0).address.port.get must be(5550)
+ members0(0).status must be(MemberStatus.Joining)
+ members0(1).address.port.get must be(5551)
+ members0(1).status must be(MemberStatus.Joining)
+ members0(2).address.port.get must be(5552)
+ members0(2).status must be(MemberStatus.Joining)
+
+ val members1 = gossiper1.latestGossip.members.toArray
+ members1.size must be(3)
+ members1(0).address.port.get must be(5550)
+ members1(0).status must be(MemberStatus.Joining)
+ members1(1).address.port.get must be(5551)
+ members1(1).status must be(MemberStatus.Joining)
+ members1(2).address.port.get must be(5552)
+ members1(2).status must be(MemberStatus.Joining)
+
+ val members2 = gossiper2.latestGossip.members.toArray
+ members2.size must be(3)
+ members2(0).address.port.get must be(5550)
+ members2(0).status must be(MemberStatus.Joining)
+ members2(1).address.port.get must be(5551)
+ members2(1).status must be(MemberStatus.Joining)
+ members2(2).address.port.get must be(5552)
+ members2(2).status must be(MemberStatus.Joining)
+ }
+ }
+ } catch {
+ case e: Exception
+ e.printStackTrace
+ fail(e.toString)
+ }
+
+ override def atTermination() {
+ gossiper0.shutdown()
+ node0.shutdown()
+
+ gossiper1.shutdown()
+ node1.shutdown()
+
+ gossiper2.shutdown()
+ node2.shutdown()
+ }
+}

0 comments on commit 9de7a2d

Please sign in to comment.
Something went wrong with that request. Please try again.