|
Akka/Scala example source code file (NodeLeavingAndExitingSpec.scala)
The NodeLeavingAndExitingSpec.scala Akka example source code
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.cluster
import scala.collection.immutable.SortedSet
import com.typesafe.config.ConfigFactory
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.testkit._
import scala.concurrent.duration._
import akka.actor.Props
import akka.actor.Actor
import akka.cluster.MemberStatus._
import akka.actor.Deploy
object NodeLeavingAndExitingMultiJvmSpec extends MultiNodeConfig {
val first = role("first")
val second = role("second")
val third = role("third")
commonConfig(debugConfig(on = false).
withFallback(MultiNodeClusterSpec.clusterConfigWithFailureDetectorPuppet))
}
class NodeLeavingAndExitingMultiJvmNode1 extends NodeLeavingAndExitingSpec
class NodeLeavingAndExitingMultiJvmNode2 extends NodeLeavingAndExitingSpec
class NodeLeavingAndExitingMultiJvmNode3 extends NodeLeavingAndExitingSpec
abstract class NodeLeavingAndExitingSpec
extends MultiNodeSpec(NodeLeavingAndExitingMultiJvmSpec)
with MultiNodeClusterSpec {
import NodeLeavingAndExitingMultiJvmSpec._
import ClusterEvent._
"A node that is LEAVING a non-singleton cluster" must {
"be moved to EXITING by the leader" taggedAs LongRunningTest in {
awaitClusterUp(first, second, third)
runOn(first, third) {
val secondAddess = address(second)
val exitingLatch = TestLatch()
cluster.subscribe(system.actorOf(Props(new Actor {
def receive = {
case state: CurrentClusterState ⇒
if (state.members.exists(m ⇒ m.address == secondAddess && m.status == Exiting))
exitingLatch.countDown()
case MemberExited(m) if m.address == secondAddess ⇒ exitingLatch.countDown()
case _: MemberRemoved ⇒ // not tested here
}
}).withDeploy(Deploy.local)), classOf[MemberEvent])
enterBarrier("registered-listener")
runOn(third) {
cluster.leave(second)
}
enterBarrier("second-left")
// Verify that 'second' node is set to EXITING
exitingLatch.await
}
// node that is leaving
runOn(second) {
enterBarrier("registered-listener")
enterBarrier("second-left")
}
enterBarrier("finished")
}
}
}
Other Akka source code examplesHere is a short list of links related to this Akka NodeLeavingAndExitingSpec.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.