pekko/akka-cluster/src/multi-jvm/scala/akka/cluster/ClusterAccrualFailureDetectorSpec.scala

114 lines
3.5 KiB
Scala
Raw Normal View History

/*
2021-01-08 17:55:38 +01:00
* Copyright (C) 2009-2021 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.cluster
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.remote.transport.ThrottlerTransportAdapter.Direction
import akka.testkit._
object ClusterAccrualFailureDetectorMultiJvmSpec extends MultiNodeConfig {
val first = role("first")
val second = role("second")
val third = role("third")
2019-03-11 10:38:24 +01:00
commonConfig(
debugConfig(on = false)
.withFallback(ConfigFactory.parseString("akka.cluster.failure-detector.threshold = 4"))
.withFallback(MultiNodeClusterSpec.clusterConfig))
testTransport(on = true)
}
class ClusterAccrualFailureDetectorMultiJvmNode1 extends ClusterAccrualFailureDetectorSpec
class ClusterAccrualFailureDetectorMultiJvmNode2 extends ClusterAccrualFailureDetectorSpec
class ClusterAccrualFailureDetectorMultiJvmNode3 extends ClusterAccrualFailureDetectorSpec
abstract class ClusterAccrualFailureDetectorSpec
2019-03-11 10:38:24 +01:00
extends MultiNodeSpec(ClusterAccrualFailureDetectorMultiJvmSpec)
with MultiNodeClusterSpec {
import ClusterAccrualFailureDetectorMultiJvmSpec._
2012-10-01 20:08:21 +02:00
muteMarkingAsUnreachable()
"A heartbeat driven Failure Detector" must {
"receive heartbeats so that all member nodes in the cluster are marked 'available'" taggedAs LongRunningTest in {
awaitClusterUp(first, second, third)
2012-07-25 18:02:45 +02:00
Thread.sleep(5.seconds.dilated.toMillis) // let them heartbeat
2015-01-16 11:09:59 +01:00
cluster.failureDetector.isAvailable(first) should ===(true)
cluster.failureDetector.isAvailable(second) should ===(true)
cluster.failureDetector.isAvailable(third) should ===(true)
enterBarrier("after-1")
}
"mark node as 'unavailable' when network partition and then back to 'available' when partition is healed" taggedAs
2019-03-11 10:38:24 +01:00
LongRunningTest in {
runOn(first) {
testConductor.blackhole(first, second, Direction.Both).await
}
2019-03-11 10:38:24 +01:00
enterBarrier("broken")
2019-03-11 10:38:24 +01:00
runOn(first) {
// detect failure...
awaitCond(!cluster.failureDetector.isAvailable(second), 15.seconds)
// other connections still ok
cluster.failureDetector.isAvailable(third) should ===(true)
}
2019-03-11 10:38:24 +01:00
runOn(second) {
// detect failure...
awaitCond(!cluster.failureDetector.isAvailable(first), 15.seconds)
// other connections still ok
cluster.failureDetector.isAvailable(third) should ===(true)
}
2019-03-11 10:38:24 +01:00
enterBarrier("partitioned")
2019-03-11 10:38:24 +01:00
runOn(first) {
testConductor.passThrough(first, second, Direction.Both).await
}
2019-03-11 10:38:24 +01:00
enterBarrier("repaired")
2019-03-11 10:38:24 +01:00
runOn(first, third) {
awaitCond(cluster.failureDetector.isAvailable(second), 15.seconds)
}
2019-03-11 10:38:24 +01:00
runOn(second) {
awaitCond(cluster.failureDetector.isAvailable(first), 15.seconds)
}
2019-03-11 10:38:24 +01:00
enterBarrier("after-2")
}
"mark node as 'unavailable' if a node in the cluster is shut down (and its heartbeats stops)" taggedAs LongRunningTest in {
runOn(first) {
testConductor.exit(third, 0).await
}
enterBarrier("third-shutdown")
runOn(first, second) {
// remaining nodes should detect failure...
awaitCond(!cluster.failureDetector.isAvailable(third), 15.seconds)
// other connections still ok
2015-01-16 11:09:59 +01:00
cluster.failureDetector.isAvailable(first) should ===(true)
cluster.failureDetector.isAvailable(second) should ===(true)
}
enterBarrier("after-3")
}
}
}