2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2021-01-08 17:55:38 +01:00
|
|
|
* Copyright (C) 2009-2021 Lightbend Inc. <https://www.lightbend.com>
|
2015-02-16 16:33:07 +01:00
|
|
|
*/
|
2018-04-24 16:03:55 +01:00
|
|
|
|
2015-02-16 16:33:07 +01:00
|
|
|
package akka.cluster
|
|
|
|
|
|
|
|
|
|
import scala.collection.immutable
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
|
2020-04-27 20:32:18 +08:00
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
|
2015-02-16 16:33:07 +01:00
|
|
|
import akka.actor.Actor
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.actor.Address
|
|
|
|
|
import akka.actor.Deploy
|
|
|
|
|
import akka.actor.Props
|
|
|
|
|
import akka.actor.RootActorPath
|
|
|
|
|
import akka.cluster.MemberStatus._
|
|
|
|
|
import akka.remote.testkit.MultiNodeConfig
|
|
|
|
|
import akka.remote.testkit.MultiNodeSpec
|
|
|
|
|
import akka.testkit._
|
2019-03-26 14:41:29 +01:00
|
|
|
import akka.util.ccompat._
|
2015-02-16 16:33:07 +01:00
|
|
|
|
2019-04-16 18:10:31 +01:00
|
|
|
@ccompatUsedUntil213
|
2015-02-16 16:33:07 +01:00
|
|
|
object RestartNode2SpecMultiJvmSpec extends MultiNodeConfig {
|
|
|
|
|
val seed1 = role("seed1")
|
|
|
|
|
val seed2 = role("seed2")
|
|
|
|
|
|
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("""
|
2019-10-03 14:08:43 +02:00
|
|
|
akka.cluster.downing-provider-class = akka.cluster.testkit.AutoDowning
|
|
|
|
|
akka.cluster.testkit.auto-down-unreachable-after = 2s
|
2015-02-16 16:33:07 +01:00
|
|
|
akka.cluster.retry-unsuccessful-join-after = 3s
|
2017-01-25 07:20:24 +01:00
|
|
|
akka.cluster.allow-weakly-up-members = off
|
2015-02-16 16:33:07 +01:00
|
|
|
akka.remote.retry-gate-closed-for = 45s
|
|
|
|
|
akka.remote.log-remote-lifecycle-events = INFO
|
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))
|
2015-02-16 16:33:07 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RestartNode2SpecMultiJvmNode1 extends RestartNode2SpecSpec
|
|
|
|
|
class RestartNode2SpecMultiJvmNode2 extends RestartNode2SpecSpec
|
|
|
|
|
|
|
|
|
|
abstract class RestartNode2SpecSpec
|
2019-03-11 10:38:24 +01:00
|
|
|
extends MultiNodeSpec(RestartNode2SpecMultiJvmSpec)
|
|
|
|
|
with MultiNodeClusterSpec
|
|
|
|
|
with ImplicitSender {
|
2015-02-16 16:33:07 +01:00
|
|
|
|
|
|
|
|
import RestartNode2SpecMultiJvmSpec._
|
|
|
|
|
|
|
|
|
|
@volatile var seedNode1Address: Address = _
|
|
|
|
|
|
|
|
|
|
// use a separate ActorSystem, to be able to simulate restart
|
2021-08-27 16:40:51 +01:00
|
|
|
lazy val seed1System = ActorSystem(system.name, MultiNodeSpec.configureNextPortIfFixed(system.settings.config))
|
|
|
|
|
|
|
|
|
|
override def verifySystemShutdown: Boolean = true
|
2015-02-16 16:33:07 +01:00
|
|
|
|
|
|
|
|
def seedNodes: immutable.IndexedSeq[Address] = Vector(seedNode1Address, seed2)
|
|
|
|
|
|
|
|
|
|
// this is the node that will attempt to re-join, keep gate times low so it can retry quickly
|
2019-03-13 10:56:20 +01:00
|
|
|
lazy val restartedSeed1System = ActorSystem(
|
|
|
|
|
system.name,
|
|
|
|
|
ConfigFactory.parseString(s"""
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.classic.netty.tcp.port = ${seedNodes.head.port.get}
|
2016-12-01 18:49:38 +01:00
|
|
|
akka.remote.artery.canonical.port = ${seedNodes.head.port.get}
|
2015-02-16 16:33:07 +01:00
|
|
|
#akka.remote.retry-gate-closed-for = 1s
|
2016-12-01 18:49:38 +01:00
|
|
|
""").withFallback(system.settings.config))
|
2015-02-16 16:33:07 +01:00
|
|
|
|
|
|
|
|
override def afterAll(): Unit = {
|
|
|
|
|
runOn(seed1) {
|
2019-03-11 10:38:24 +01:00
|
|
|
shutdown(if (seed1System.whenTerminated.isCompleted) restartedSeed1System else seed1System)
|
2015-02-16 16:33:07 +01:00
|
|
|
}
|
|
|
|
|
super.afterAll()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"Cluster seed nodes" must {
|
|
|
|
|
"be able to restart first seed node and join other seed nodes" taggedAs LongRunningTest in within(60.seconds) {
|
|
|
|
|
// seed1System is a separate ActorSystem, to be able to simulate restart
|
|
|
|
|
// we must transfer its address to seed2
|
|
|
|
|
runOn(seed2) {
|
|
|
|
|
system.actorOf(Props(new Actor {
|
|
|
|
|
def receive = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case a: Address =>
|
2015-02-16 16:33:07 +01:00
|
|
|
seedNode1Address = a
|
|
|
|
|
sender() ! "ok"
|
|
|
|
|
}
|
|
|
|
|
}).withDeploy(Deploy.local), name = "address-receiver")
|
|
|
|
|
enterBarrier("seed1-address-receiver-ready")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOn(seed1) {
|
|
|
|
|
enterBarrier("seed1-address-receiver-ready")
|
|
|
|
|
seedNode1Address = Cluster(seed1System).selfAddress
|
2019-03-11 10:38:24 +01:00
|
|
|
List(seed2).foreach { r =>
|
2015-02-16 16:33:07 +01:00
|
|
|
system.actorSelection(RootActorPath(r) / "user" / "address-receiver") ! seedNode1Address
|
|
|
|
|
expectMsg(5.seconds, "ok")
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-21 11:02:37 +09:00
|
|
|
enterBarrier("seed1-address-transferred")
|
2015-02-16 16:33:07 +01:00
|
|
|
|
|
|
|
|
// now we can join seed1System, seed2 together
|
|
|
|
|
|
|
|
|
|
runOn(seed1) {
|
|
|
|
|
Cluster(seed1System).joinSeedNodes(seedNodes)
|
|
|
|
|
awaitAssert(Cluster(seed1System).readView.members.size should be(2))
|
2018-11-22 16:18:10 +01:00
|
|
|
awaitAssert(Cluster(seed1System).readView.members.unsorted.map(_.status) should be(Set(Up)))
|
2015-02-16 16:33:07 +01:00
|
|
|
}
|
|
|
|
|
runOn(seed2) {
|
|
|
|
|
cluster.joinSeedNodes(seedNodes)
|
|
|
|
|
awaitMembersUp(2)
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("started")
|
|
|
|
|
|
|
|
|
|
// shutdown seed1System
|
|
|
|
|
runOn(seed1) {
|
|
|
|
|
shutdown(seed1System, remainingOrDefault)
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("seed1-shutdown")
|
|
|
|
|
|
|
|
|
|
// then start restartedSeed1System, which has the same address as seed1System
|
|
|
|
|
runOn(seed1) {
|
|
|
|
|
Cluster(restartedSeed1System).joinSeedNodes(seedNodes)
|
|
|
|
|
within(30.seconds) {
|
|
|
|
|
awaitAssert(Cluster(restartedSeed1System).readView.members.size should be(2))
|
2018-11-22 16:18:10 +01:00
|
|
|
awaitAssert(Cluster(restartedSeed1System).readView.members.unsorted.map(_.status) should be(Set(Up)))
|
2015-02-16 16:33:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
runOn(seed2) {
|
|
|
|
|
awaitMembersUp(2)
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("seed1-restarted")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2017-01-04 17:37:10 +01:00
|
|
|
}
|