2012-06-05 22:16:15 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.cluster
|
|
|
|
|
|
2012-06-25 17:21:06 +02:00
|
|
|
import language.postfixOps
|
|
|
|
|
import language.reflectiveCalls
|
|
|
|
|
|
2012-06-29 13:33:20 +02:00
|
|
|
import scala.concurrent.util.duration._
|
|
|
|
|
import scala.concurrent.util.Duration
|
2012-07-06 17:04:04 +02:00
|
|
|
|
2012-06-05 22:16:15 +02:00
|
|
|
import akka.testkit.AkkaSpec
|
2012-07-04 14:39:27 +02:00
|
|
|
import akka.testkit.ImplicitSender
|
2012-06-05 22:16:15 +02:00
|
|
|
import akka.actor.ExtendedActorSystem
|
|
|
|
|
import akka.actor.Address
|
2012-07-06 17:04:04 +02:00
|
|
|
import akka.cluster.InternalClusterAction._
|
2012-06-21 10:58:35 +02:00
|
|
|
import akka.remote.RemoteActorRefProvider
|
2012-07-05 11:56:54 +02:00
|
|
|
import java.lang.management.ManagementFactory
|
|
|
|
|
import javax.management.ObjectName
|
2012-06-05 22:16:15 +02:00
|
|
|
|
|
|
|
|
object ClusterSpec {
|
|
|
|
|
val config = """
|
|
|
|
|
akka.cluster {
|
2012-06-21 10:58:35 +02:00
|
|
|
auto-join = off
|
2012-06-05 22:16:15 +02:00
|
|
|
auto-down = off
|
|
|
|
|
periodic-tasks-initial-delay = 120 seconds // turn off scheduled tasks
|
2012-08-15 16:47:34 +02:00
|
|
|
publish-stats-interval = 0 s # always, when it happens
|
2012-06-05 22:16:15 +02:00
|
|
|
}
|
|
|
|
|
akka.actor.provider = "akka.remote.RemoteActorRefProvider"
|
|
|
|
|
akka.remote.netty.port = 0
|
2012-06-07 13:32:12 +02:00
|
|
|
# akka.loglevel = DEBUG
|
2012-06-05 22:16:15 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
case class GossipTo(address: Address)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
2012-07-04 14:39:27 +02:00
|
|
|
class ClusterSpec extends AkkaSpec(ClusterSpec.config) with ImplicitSender {
|
2012-06-05 22:16:15 +02:00
|
|
|
import ClusterSpec._
|
|
|
|
|
|
2012-06-21 10:58:35 +02:00
|
|
|
val selfAddress = system.asInstanceOf[ExtendedActorSystem].provider.asInstanceOf[RemoteActorRefProvider].transport.address
|
2012-06-05 22:16:15 +02:00
|
|
|
|
2012-06-15 14:45:15 +02:00
|
|
|
val failureDetector = new FailureDetectorPuppet(system)
|
|
|
|
|
|
2012-07-04 14:39:27 +02:00
|
|
|
val cluster = new Cluster(system.asInstanceOf[ExtendedActorSystem], failureDetector)
|
2012-06-05 22:16:15 +02:00
|
|
|
|
2012-07-04 14:39:27 +02:00
|
|
|
def leaderActions(): Unit = {
|
|
|
|
|
cluster.clusterCore ! LeaderActionsTick
|
|
|
|
|
awaitPing()
|
2012-06-05 22:16:15 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-04 14:39:27 +02:00
|
|
|
def awaitPing(): Unit = {
|
|
|
|
|
val ping = Ping()
|
|
|
|
|
cluster.clusterCore ! ping
|
|
|
|
|
expectMsgPF() { case pong @ Pong(`ping`, _) ⇒ pong }
|
2012-06-05 22:16:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"A Cluster" must {
|
|
|
|
|
|
2012-06-21 10:58:35 +02:00
|
|
|
"use the address of the remote transport" in {
|
|
|
|
|
cluster.selfAddress must be(selfAddress)
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-05 11:56:54 +02:00
|
|
|
"register jmx mbean" in {
|
|
|
|
|
val name = new ObjectName("akka:type=Cluster")
|
|
|
|
|
val info = ManagementFactory.getPlatformMBeanServer.getMBeanInfo(name)
|
|
|
|
|
info.getAttributes.length must be > (0)
|
|
|
|
|
info.getOperations.length must be > (0)
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-25 21:07:44 +02:00
|
|
|
"initially become singleton cluster when joining itself and reach convergence" in {
|
2012-08-15 16:47:34 +02:00
|
|
|
cluster.members.size must be(0) // auto-join = off
|
2012-06-25 21:07:44 +02:00
|
|
|
cluster.join(selfAddress)
|
2012-08-15 16:47:34 +02:00
|
|
|
Thread.sleep(5000)
|
2012-06-25 21:07:44 +02:00
|
|
|
awaitCond(cluster.isSingletonCluster)
|
|
|
|
|
cluster.self.address must be(selfAddress)
|
2012-08-15 16:47:34 +02:00
|
|
|
cluster.members.map(_.address) must be(Set(selfAddress))
|
2012-07-04 14:39:27 +02:00
|
|
|
cluster.status must be(MemberStatus.Joining)
|
2012-08-15 16:47:34 +02:00
|
|
|
cluster.convergence must be(true)
|
2012-07-04 14:39:27 +02:00
|
|
|
leaderActions()
|
|
|
|
|
cluster.status must be(MemberStatus.Up)
|
2012-06-05 22:16:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|