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

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

This example Akka source code file (InitialHeartbeatSpec.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, cluster, concurrent, initialheartbeatmultijvmnode1, initialheartbeatmultijvmnode2, initialheartbeatmultijvmnode3, initialheartbeatmultijvmspec, initialheartbeatspec, longrunningtest, multinodeclusterspec, multinodeconfig, multinodespec, test, testing, time

The InitialHeartbeatSpec.scala Akka example source code

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

import language.postfixOps
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.cluster.ClusterEvent.CurrentClusterState
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.remote.transport.ThrottlerTransportAdapter.Direction
import akka.testkit._

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

  commonConfig(debugConfig(on = false).
      akka.cluster.failure-detector.threshold = 4""")).

  testTransport(on = true)

class InitialHeartbeatMultiJvmNode1 extends InitialHeartbeatSpec
class InitialHeartbeatMultiJvmNode2 extends InitialHeartbeatSpec
class InitialHeartbeatMultiJvmNode3 extends InitialHeartbeatSpec

abstract class InitialHeartbeatSpec
  extends MultiNodeSpec(InitialHeartbeatMultiJvmSpec)
  with MultiNodeClusterSpec {

  import InitialHeartbeatMultiJvmSpec._


  "A member" must {

    "detect failure even though no heartbeats have been received" taggedAs LongRunningTest in {
      val firstAddress = address(first)
      val secondAddress = address(second)

      runOn(first) {
        within(10 seconds) {
            expectMsgType[CurrentClusterState] should contain(secondAddress)
          }, interval = 50.millis)
      runOn(second) {
        within(10 seconds) {
            expectMsgType[CurrentClusterState] should contain(firstAddress)
          }, interval = 50.millis)

      runOn(controller) {
        // It is likely that second has not started heartbeating to first yet,
        // and when it does the messages doesn't go through and the first extra heartbeat is triggered.
        // If the first heartbeat arrives, it will detect the failure anyway but not really exercise the
        // part that we are trying to test here.
        testConductor.blackhole(first, second, Direction.Both).await

      runOn(second) {
        within(15 seconds) {


Other Akka source code examples

Here is a short list of links related to this Akka InitialHeartbeatSpec.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.