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>
|
2015-04-22 11:25:24 +02:00
|
|
|
*/
|
2018-04-24 16:03:55 +01:00
|
|
|
|
2015-04-22 11:25:24 +02:00
|
|
|
package akka.remote
|
|
|
|
|
|
|
|
|
|
import language.postfixOps
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.remote.testconductor.RoleName
|
|
|
|
|
import akka.remote.testkit.MultiNodeConfig
|
|
|
|
|
import akka.testkit._
|
|
|
|
|
import akka.actor.ActorIdentity
|
|
|
|
|
import akka.remote.testconductor.RoleName
|
|
|
|
|
import akka.actor.Identify
|
|
|
|
|
import scala.concurrent.Await
|
|
|
|
|
|
|
|
|
|
object RemoteRestartedQuarantinedSpec extends MultiNodeConfig {
|
|
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
|
|
|
|
|
commonConfig(debugConfig(on = false).withFallback(
|
|
|
|
|
ConfigFactory.parseString("""
|
|
|
|
|
# Keep it long, we don't want reconnects
|
|
|
|
|
akka.remote.retry-gate-closed-for = 1 s
|
|
|
|
|
|
|
|
|
|
# Important, otherwise it is very racy to get a non-writing endpoint: the only way to do it if the two nodes
|
|
|
|
|
# associate to each other at the same time. Setting this will ensure that the right scenario happens.
|
|
|
|
|
akka.remote.use-passive-connections = off
|
|
|
|
|
|
|
|
|
|
# TODO should not be needed, but see TODO at the end of the test
|
|
|
|
|
akka.remote.transport-failure-detector.heartbeat-interval = 1 s
|
|
|
|
|
akka.remote.transport-failure-detector.acceptable-heartbeat-pause = 10 s
|
|
|
|
|
""")))
|
|
|
|
|
|
|
|
|
|
testTransport(on = true)
|
|
|
|
|
|
|
|
|
|
class Subject extends Actor {
|
|
|
|
|
def receive = {
|
2016-01-17 15:48:52 +01:00
|
|
|
case "shutdown" ⇒ context.system.terminate()
|
2016-06-02 14:06:57 +02:00
|
|
|
case "identify" ⇒ sender() ! (AddressUidExtension(context.system).addressUid → self)
|
2015-04-22 11:25:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RemoteRestartedQuarantinedSpecMultiJvmNode1 extends RemoteRestartedQuarantinedSpec
|
|
|
|
|
class RemoteRestartedQuarantinedSpecMultiJvmNode2 extends RemoteRestartedQuarantinedSpec
|
|
|
|
|
|
|
|
|
|
abstract class RemoteRestartedQuarantinedSpec
|
2016-09-19 13:22:54 +02:00
|
|
|
extends RemotingMultiNodeSpec(RemoteRestartedQuarantinedSpec) {
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
import RemoteRestartedQuarantinedSpec._
|
|
|
|
|
|
|
|
|
|
override def initialParticipants = 2
|
|
|
|
|
|
|
|
|
|
def identifyWithUid(role: RoleName, actorName: String): (Int, ActorRef) = {
|
|
|
|
|
system.actorSelection(node(role) / "user" / actorName) ! "identify"
|
|
|
|
|
expectMsgType[(Int, ActorRef)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"A restarted quarantined system" must {
|
|
|
|
|
|
|
|
|
|
"should not crash the other system (#17213)" taggedAs LongRunningTest in {
|
|
|
|
|
|
|
|
|
|
system.actorOf(Props[Subject], "subject")
|
|
|
|
|
enterBarrier("subject-started")
|
|
|
|
|
|
|
|
|
|
runOn(first) {
|
|
|
|
|
val secondAddress = node(second).address
|
|
|
|
|
|
|
|
|
|
val (uid, ref) = identifyWithUid(second, "subject")
|
|
|
|
|
|
2016-09-07 16:07:29 +02:00
|
|
|
RARP(system).provider.transport.quarantine(node(second).address, Some(uid), "test")
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
enterBarrier("quarantined")
|
|
|
|
|
enterBarrier("still-quarantined")
|
|
|
|
|
|
|
|
|
|
testConductor.shutdown(second).await
|
|
|
|
|
|
|
|
|
|
within(30.seconds) {
|
|
|
|
|
awaitAssert {
|
|
|
|
|
system.actorSelection(RootActorPath(secondAddress) / "user" / "subject") ! Identify("subject")
|
|
|
|
|
expectMsgType[ActorIdentity](1.second).ref.get
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
system.actorSelection(RootActorPath(secondAddress) / "user" / "subject") ! "shutdown"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOn(second) {
|
2017-08-08 19:18:56 +08:00
|
|
|
val address = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
2015-04-22 11:25:24 +02:00
|
|
|
val firstAddress = node(first).address
|
2015-12-06 20:14:44 -05:00
|
|
|
system.eventStream.subscribe(testActor, classOf[ThisActorSystemQuarantinedEvent])
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
val (_, ref) = identifyWithUid(first, "subject")
|
|
|
|
|
|
|
|
|
|
enterBarrier("quarantined")
|
|
|
|
|
|
|
|
|
|
// Check that quarantine is intact
|
|
|
|
|
within(10.seconds) {
|
|
|
|
|
awaitAssert {
|
|
|
|
|
EventFilter.warning(pattern = "The remote system has quarantined this system", occurrences = 1).intercept {
|
|
|
|
|
ref ! "boo!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 20:14:44 -05:00
|
|
|
expectMsgPF(10 seconds) {
|
|
|
|
|
case ThisActorSystemQuarantinedEvent(local, remote) ⇒
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-22 11:25:24 +02:00
|
|
|
enterBarrier("still-quarantined")
|
|
|
|
|
|
2016-01-17 16:37:45 +01:00
|
|
|
Await.result(system.whenTerminated, 10.seconds)
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
val freshSystem = ActorSystem(system.name, ConfigFactory.parseString(s"""
|
|
|
|
|
akka.remote.retry-gate-closed-for = 0.5 s
|
|
|
|
|
akka.remote.netty.tcp {
|
2017-08-08 19:18:56 +08:00
|
|
|
hostname = ${address.host.get}
|
|
|
|
|
port = ${address.port.get}
|
2015-04-22 11:25:24 +02:00
|
|
|
}
|
|
|
|
|
""").withFallback(system.settings.config))
|
|
|
|
|
|
2017-08-08 14:31:31 +02:00
|
|
|
// retry because it's possible to loose the initial message here, see issue #17314
|
2015-04-22 11:25:24 +02:00
|
|
|
val probe = TestProbe()(freshSystem)
|
2017-08-08 14:31:31 +02:00
|
|
|
probe.awaitAssert({
|
|
|
|
|
freshSystem.actorSelection(RootActorPath(firstAddress) / "user" / "subject").tell(Identify("subject"), probe.ref)
|
|
|
|
|
probe.expectMsgType[ActorIdentity](1.second).ref should not be (None)
|
|
|
|
|
}, 30.seconds)
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
// Now the other system will be able to pass, too
|
|
|
|
|
freshSystem.actorOf(Props[Subject], "subject")
|
|
|
|
|
|
|
|
|
|
Await.ready(freshSystem.whenTerminated, 10.seconds)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|