| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Akka/Scala example source code file (NodeUpSpec.scala)

This example Akka source code file (NodeUpSpec.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Akka and Scala source code examples by using tags.

All credit for the original source code belongs to; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Akka tags/keywords

a, actor, akka, collection, concurrent, currentclusterstate, longrunningtest, memberevent, multinodeclusterspec, multinodespec, nodeupmultijvmnode1, nodeupmultijvmspec, nodeupspec, test, testing, time

The NodeUpSpec.scala Akka example source code

 * Copyright (C) 2009-2014 Typesafe Inc. <>
package akka.cluster

import com.typesafe.config.ConfigFactory
import org.scalatest.BeforeAndAfter
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.testkit._
import scala.concurrent.duration._
import scala.collection.immutable.SortedSet
import java.util.concurrent.atomic.AtomicReference

object NodeUpMultiJvmSpec extends MultiNodeConfig {
  val first = role("first")
  val second = role("second")

  commonConfig(debugConfig(on = false).withFallback(MultiNodeClusterSpec.clusterConfigWithFailureDetectorPuppet))

class NodeUpMultiJvmNode1 extends NodeUpSpec
class NodeUpMultiJvmNode2 extends NodeUpSpec

abstract class NodeUpSpec
  extends MultiNodeSpec(NodeUpMultiJvmSpec)
  with MultiNodeClusterSpec {

  import NodeUpMultiJvmSpec._
  import ClusterEvent._

  "A cluster node that is joining another cluster" must {
    "not be able to join a node that is not a cluster member" taggedAs LongRunningTest in {

      runOn(first) {

      clusterView.members should be(Set.empty)


    "be moved to UP by the leader after a convergence" taggedAs LongRunningTest in {
      awaitClusterUp(first, second)

    "be unaffected when joining again" taggedAs LongRunningTest in {

      val unexpected = new AtomicReference[SortedSet[Member]](SortedSet.empty)
      cluster.subscribe(system.actorOf(Props(new Actor {
        def receive = {
          case event: MemberEvent ⇒
            unexpected.set(unexpected.get + event.member)
          case _: CurrentClusterState ⇒ // ignore
      })), classOf[MemberEvent])

      runOn(second) {

      // let it run for a while to make sure that nothing bad happens
      for (n ← 1 to 20) {
        unexpected.get should be(SortedSet.empty)
        clusterView.members.forall(_.status == MemberStatus.Up) should be(true)


Other Akka source code examples

Here is a short list of links related to this Akka NodeUpSpec.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
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.