2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2019-01-02 18:55:26 +08:00
|
|
|
* Copyright (C) 2009-2019 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
|
2019-03-26 14:41:29 +01:00
|
|
|
import akka.util.ccompat._
|
2014-11-10 15:12:14 +01:00
|
|
|
|
2019-04-16 18:10:31 +01:00
|
|
|
@ccompatUsedUntil213
|
2014-11-10 15:12:14 +01:00
|
|
|
object RestartNodeMultiJvmSpec extends MultiNodeConfig {
|
|
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
val third = role("third")
|
|
|
|
|
|
2019-03-11 10:38:24 +01:00
|
|
|
commonConfig(
|
Disable Java serialization by default, #22333 (#27285)
* akka.actor.allow-java-serialization = off
* Moved primitive (Long, Int, String, ByteString) serializers
from akka-remote to akka-actor since they had no dependency
and are useful also in local systems, e.g. persistence.
* e.g. needed for persistence-tck
* less allow-java-serialization=on in tests
* CborSerializable in Jackson/test module for ease of use
* JavaSerializable for Java serialization in tests, already in akka-testkit,
but misconfigured
* Made tests pass
* allow-java-serialization=on in akka-persistence
* allow-java-serialization=on in classic remoting tests
* JavaSerializable and CborSerializable in other remoting tests
* Added serialization for
* Boolean
* java.util.concurrent.TimeoutException, AskTimeoutException
* support for testing serialization with the inmem journal
* utility to verifySerialization, in SerializationTestKit
* remove AccountExampleWithCommandHandlersInState becuase not possible to serialize State when it's not static
* Effect() is factory in EventSourcedBehavior class
* test the account examples
* SharedLeveldbJournal.configToEnableJavaSerializationForTest
* support for exceptions from remote deployed child actors
* fallback to akka.remote.serialization.ThrowableNotSerializableException
if exception is not serializable when wrapped in system messages from
remote deployed child actors and Status.Failure messages
* it's implemented in `WrappedPayloadSupport.payloadBuilder`
* update reference documentation
* serialize-messages=off in most places, separate ticket for
improving or removing that feature
* migration guide, including description of rolling update
* fix 2.13 compiler error
* minor review feedback
2019-07-11 14:04:24 +02:00
|
|
|
debugConfig(on = false)
|
|
|
|
|
.withFallback(ConfigFactory.parseString("""
|
2016-03-21 08:41:11 +01:00
|
|
|
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
|
Disable Java serialization by default, #22333 (#27285)
* akka.actor.allow-java-serialization = off
* Moved primitive (Long, Int, String, ByteString) serializers
from akka-remote to akka-actor since they had no dependency
and are useful also in local systems, e.g. persistence.
* e.g. needed for persistence-tck
* less allow-java-serialization=on in tests
* CborSerializable in Jackson/test module for ease of use
* JavaSerializable for Java serialization in tests, already in akka-testkit,
but misconfigured
* Made tests pass
* allow-java-serialization=on in akka-persistence
* allow-java-serialization=on in classic remoting tests
* JavaSerializable and CborSerializable in other remoting tests
* Added serialization for
* Boolean
* java.util.concurrent.TimeoutException, AskTimeoutException
* support for testing serialization with the inmem journal
* utility to verifySerialization, in SerializationTestKit
* remove AccountExampleWithCommandHandlersInState becuase not possible to serialize State when it's not static
* Effect() is factory in EventSourcedBehavior class
* test the account examples
* SharedLeveldbJournal.configToEnableJavaSerializationForTest
* support for exceptions from remote deployed child actors
* fallback to akka.remote.serialization.ThrowableNotSerializableException
if exception is not serializable when wrapped in system messages from
remote deployed child actors and Status.Failure messages
* it's implemented in `WrappedPayloadSupport.payloadBuilder`
* update reference documentation
* serialize-messages=off in most places, separate ticket for
improving or removing that feature
* migration guide, including description of rolling update
* fix 2.13 compiler error
* minor review feedback
2019-07-11 14:04:24 +02:00
|
|
|
# test is using Java serialization and not priority to rewrite
|
|
|
|
|
akka.actor.allow-java-serialization = on
|
|
|
|
|
akka.actor.warn-about-java-serializer-usage = off
|
|
|
|
|
"""))
|
|
|
|
|
.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 = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case ActorIdentity(None, Some(ref)) =>
|
2016-03-21 08:41:11 +01:00
|
|
|
context.watch(ref)
|
|
|
|
|
replyTo ! Done
|
2019-04-16 18:10:31 +01:00
|
|
|
case _: Terminated =>
|
2016-03-21 08:41:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
2014-11-10 15:12:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RestartNodeMultiJvmNode1 extends RestartNodeSpec
|
|
|
|
|
class RestartNodeMultiJvmNode2 extends RestartNodeSpec
|
|
|
|
|
class RestartNodeMultiJvmNode3 extends RestartNodeSpec
|
|
|
|
|
|
|
|
|
|
abstract class RestartNodeSpec
|
2019-03-11 10:38:24 +01:00
|
|
|
extends MultiNodeSpec(RestartNodeMultiJvmSpec)
|
|
|
|
|
with MultiNodeClusterSpec
|
|
|
|
|
with ImplicitSender {
|
2014-11-10 15:12:14 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2019-03-13 10:56:20 +01:00
|
|
|
lazy val restartedSecondSystem = ActorSystem(
|
|
|
|
|
system.name,
|
|
|
|
|
ConfigFactory.parseString(s"""
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.classic.netty.tcp.port = ${secondUniqueAddress.address.port.get}
|
2016-12-01 18:49:38 +01:00
|
|
|
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 = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case a: UniqueAddress =>
|
2014-11-10 15:12:14 +01:00
|
|
|
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
|
2019-03-11 10:38:24 +01:00
|
|
|
List(first, third).foreach { r =>
|
2014-11-10 15:12:14 +01:00
|
|
|
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))
|
2018-11-22 16:18:10 +01:00
|
|
|
awaitAssert(Cluster(secondSystem).readView.members.unsorted.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))
|
2018-11-22 16:18:10 +01:00
|
|
|
awaitAssert(Cluster(restartedSecondSystem).readView.members.unsorted.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)
|
2019-02-09 15:25:39 +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")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|