2014-11-10 15:12:14 +01:00
|
|
|
/**
|
2018-01-04 17:26:29 +00:00
|
|
|
* Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com>
|
2014-11-10 15:12:14 +01:00
|
|
|
*/
|
2018-04-24 16:03:55 +01:00
|
|
|
|
2014-11-10 15:12:14 +01:00
|
|
|
package akka.cluster
|
|
|
|
|
|
|
|
|
|
import scala.collection.immutable
|
|
|
|
|
import scala.concurrent.duration._
|
2016-03-21 08:41:11 +01:00
|
|
|
|
|
|
|
|
import akka.Done
|
|
|
|
|
import akka.actor.Actor
|
|
|
|
|
import akka.actor.ActorIdentity
|
|
|
|
|
import akka.actor.ActorRef
|
2014-11-10 15:12:14 +01:00
|
|
|
import akka.actor.ActorSystem
|
2016-03-21 08:41:11 +01:00
|
|
|
import akka.actor.Address
|
|
|
|
|
import akka.actor.Deploy
|
|
|
|
|
import akka.actor.Identify
|
2014-11-10 15:12:14 +01:00
|
|
|
import akka.actor.Props
|
|
|
|
|
import akka.actor.RootActorPath
|
2016-03-21 08:41:11 +01:00
|
|
|
import akka.actor.Terminated
|
2014-11-10 15:12:14 +01:00
|
|
|
import akka.cluster.MemberStatus._
|
2016-03-21 08:41:11 +01:00
|
|
|
import akka.remote.testkit.MultiNodeConfig
|
|
|
|
|
import akka.remote.testkit.MultiNodeSpec
|
|
|
|
|
import akka.testkit._
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
2014-11-10 15:12:14 +01:00
|
|
|
|
|
|
|
|
object RestartNodeMultiJvmSpec extends MultiNodeConfig {
|
|
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
val third = role("third")
|
|
|
|
|
|
|
|
|
|
commonConfig(debugConfig(on = false).
|
2016-03-21 08:41:11 +01:00
|
|
|
withFallback(ConfigFactory.parseString("""
|
|
|
|
|
akka.cluster.auto-down-unreachable-after = 5s
|
2017-01-25 07:20:24 +01:00
|
|
|
akka.cluster.allow-weakly-up-members = off
|
2016-03-21 08:41:11 +01:00
|
|
|
#akka.remote.use-passive-connections = off
|
|
|
|
|
""")).
|
2014-11-10 15:12:14 +01:00
|
|
|
withFallback(MultiNodeClusterSpec.clusterConfig))
|
2016-03-21 08:41:11 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This was used together with sleep in EndpointReader before deliverAndAck
|
|
|
|
|
* to reproduce issue with misaligned ACKs when restarting system,
|
|
|
|
|
* issue #19780
|
|
|
|
|
*/
|
|
|
|
|
class Watcher(a: Address, replyTo: ActorRef) extends Actor {
|
|
|
|
|
context.actorSelection(RootActorPath(a) / "user" / "address-receiver") ! Identify(None)
|
|
|
|
|
|
|
|
|
|
def receive = {
|
|
|
|
|
case ActorIdentity(None, Some(ref)) ⇒
|
|
|
|
|
context.watch(ref)
|
|
|
|
|
replyTo ! Done
|
|
|
|
|
case t: Terminated ⇒
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-10 15:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RestartNodeMultiJvmNode1 extends RestartNodeSpec
|
|
|
|
|
class RestartNodeMultiJvmNode2 extends RestartNodeSpec
|
|
|
|
|
class RestartNodeMultiJvmNode3 extends RestartNodeSpec
|
|
|
|
|
|
|
|
|
|
abstract class RestartNodeSpec
|
|
|
|
|
extends MultiNodeSpec(RestartNodeMultiJvmSpec)
|
|
|
|
|
with MultiNodeClusterSpec with ImplicitSender {
|
|
|
|
|
|
|
|
|
|
import RestartNodeMultiJvmSpec._
|
|
|
|
|
|
|
|
|
|
@volatile var secondUniqueAddress: UniqueAddress = _
|
|
|
|
|
|
|
|
|
|
// use a separate ActorSystem, to be able to simulate restart
|
|
|
|
|
lazy val secondSystem = ActorSystem(system.name, system.settings.config)
|
|
|
|
|
|
|
|
|
|
def seedNodes: immutable.IndexedSeq[Address] = Vector(first, secondUniqueAddress.address, third)
|
|
|
|
|
|
2016-06-02 14:06:57 +02:00
|
|
|
lazy val restartedSecondSystem = ActorSystem(
|
|
|
|
|
system.name,
|
2016-12-01 18:49:38 +01:00
|
|
|
ConfigFactory.parseString(s"""
|
|
|
|
|
akka.remote.netty.tcp.port = ${secondUniqueAddress.address.port.get}
|
|
|
|
|
akka.remote.artery.canonical.port = ${secondUniqueAddress.address.port.get}
|
|
|
|
|
""").withFallback(system.settings.config))
|
2014-11-10 15:12:14 +01:00
|
|
|
|
|
|
|
|
override def afterAll(): Unit = {
|
|
|
|
|
runOn(second) {
|
2015-12-26 11:30:18 +01:00
|
|
|
if (secondSystem.whenTerminated.isCompleted)
|
2014-11-10 15:12:14 +01:00
|
|
|
shutdown(restartedSecondSystem)
|
|
|
|
|
else
|
|
|
|
|
shutdown(secondSystem)
|
|
|
|
|
}
|
|
|
|
|
super.afterAll()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"Cluster nodes" must {
|
2016-03-21 08:41:11 +01:00
|
|
|
"be able to restart and join again" taggedAs LongRunningTest in within(60.seconds) {
|
2014-11-10 15:12:14 +01:00
|
|
|
// secondSystem is a separate ActorSystem, to be able to simulate restart
|
|
|
|
|
// we must transfer its address to first
|
|
|
|
|
runOn(first, third) {
|
|
|
|
|
system.actorOf(Props(new Actor {
|
|
|
|
|
def receive = {
|
|
|
|
|
case a: UniqueAddress ⇒
|
|
|
|
|
secondUniqueAddress = a
|
|
|
|
|
sender() ! "ok"
|
|
|
|
|
}
|
|
|
|
|
}).withDeploy(Deploy.local), name = "address-receiver")
|
|
|
|
|
enterBarrier("second-address-receiver-ready")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOn(second) {
|
|
|
|
|
enterBarrier("second-address-receiver-ready")
|
|
|
|
|
secondUniqueAddress = Cluster(secondSystem).selfUniqueAddress
|
|
|
|
|
List(first, third) foreach { r ⇒
|
|
|
|
|
system.actorSelection(RootActorPath(r) / "user" / "address-receiver") ! secondUniqueAddress
|
2016-03-21 08:41:11 +01:00
|
|
|
expectMsg(5.seconds, "ok")
|
2014-11-10 15:12:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-08-21 11:02:37 +09:00
|
|
|
enterBarrier("second-address-transferred")
|
2014-11-10 15:12:14 +01:00
|
|
|
|
|
|
|
|
// now we can join first, secondSystem, third together
|
|
|
|
|
runOn(first, third) {
|
|
|
|
|
cluster.joinSeedNodes(seedNodes)
|
|
|
|
|
awaitMembersUp(3)
|
|
|
|
|
}
|
|
|
|
|
runOn(second) {
|
|
|
|
|
Cluster(secondSystem).joinSeedNodes(seedNodes)
|
2015-01-16 11:09:59 +01:00
|
|
|
awaitAssert(Cluster(secondSystem).readView.members.size should ===(3))
|
|
|
|
|
awaitAssert(Cluster(secondSystem).readView.members.map(_.status) should ===(Set(Up)))
|
2014-11-10 15:12:14 +01:00
|
|
|
}
|
|
|
|
|
enterBarrier("started")
|
|
|
|
|
|
|
|
|
|
// shutdown secondSystem
|
|
|
|
|
runOn(second) {
|
2016-03-21 08:41:11 +01:00
|
|
|
// send system message just before shutdown, reproducer for issue #19780
|
|
|
|
|
secondSystem.actorOf(Props(classOf[Watcher], address(first), testActor), "testwatcher")
|
|
|
|
|
expectMsg(Done)
|
|
|
|
|
|
2014-11-10 15:12:14 +01:00
|
|
|
shutdown(secondSystem, remaining)
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("second-shutdown")
|
|
|
|
|
|
|
|
|
|
// then immediately start restartedSecondSystem, which has the same address as secondSystem
|
|
|
|
|
runOn(second) {
|
|
|
|
|
Cluster(restartedSecondSystem).joinSeedNodes(seedNodes)
|
2015-01-16 11:09:59 +01:00
|
|
|
awaitAssert(Cluster(restartedSecondSystem).readView.members.size should ===(3))
|
|
|
|
|
awaitAssert(Cluster(restartedSecondSystem).readView.members.map(_.status) should ===(Set(Up)))
|
2014-11-10 15:12:14 +01:00
|
|
|
}
|
|
|
|
|
runOn(first, third) {
|
|
|
|
|
awaitAssert {
|
2015-01-16 11:09:59 +01:00
|
|
|
Cluster(system).readView.members.size should ===(3)
|
2014-11-10 15:12:14 +01:00
|
|
|
Cluster(system).readView.members.exists { m ⇒
|
2016-09-26 15:34:59 +02:00
|
|
|
m.address == secondUniqueAddress.address && m.uniqueAddress.longUid != secondUniqueAddress.longUid
|
2014-11-10 15:12:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("second-restarted")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|