2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
|
2015-04-22 11:25:24 +02:00
|
|
|
*/
|
2018-04-24 16:03:55 +01:00
|
|
|
|
2019-05-01 08:12:09 +01:00
|
|
|
package akka.remote.classic
|
2015-04-22 11:25:24 +02:00
|
|
|
|
2021-11-12 17:30:49 +01:00
|
|
|
import scala.annotation.nowarn
|
2020-04-27 20:32:18 +08:00
|
|
|
import scala.concurrent.Await
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
import scala.language.postfixOps
|
|
|
|
|
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
|
2019-05-01 08:12:09 +01:00
|
|
|
import akka.actor.{ ActorIdentity, Identify, _ }
|
2020-04-27 20:32:18 +08:00
|
|
|
import akka.remote.{ AddressUidExtension, RARP, RemotingMultiNodeSpec, ThisActorSystemQuarantinedEvent }
|
2015-04-22 11:25:24 +02:00
|
|
|
import akka.remote.testconductor.RoleName
|
|
|
|
|
import akka.remote.testkit.MultiNodeConfig
|
|
|
|
|
import akka.testkit._
|
|
|
|
|
|
|
|
|
|
object RemoteRestartedQuarantinedSpec extends MultiNodeConfig {
|
|
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
|
2019-03-11 10:38:24 +01:00
|
|
|
commonConfig(
|
|
|
|
|
debugConfig(on = false).withFallback(ConfigFactory.parseString(
|
|
|
|
|
"""
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.artery.enabled = off
|
2015-04-22 11:25:24 +02:00
|
|
|
# Keep it long, we don't want reconnects
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.classic.retry-gate-closed-for = 1 s
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
# 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.
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.classic.use-passive-connections = off
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
# TODO should not be needed, but see TODO at the end of the test
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.classic.transport-failure-detector.heartbeat-interval = 1 s
|
|
|
|
|
akka.remote.classic.transport-failure-detector.acceptable-heartbeat-pause = 10 s
|
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
|
|
|
|
|
""")))
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
testTransport(on = true)
|
|
|
|
|
|
|
|
|
|
class Subject extends Actor {
|
|
|
|
|
def receive = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case "shutdown" => context.system.terminate()
|
2019-04-15 09:54:16 +01:00
|
|
|
case "identify" => sender() ! (AddressUidExtension(context.system).longAddressUid -> self)
|
2015-04-22 11:25:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RemoteRestartedQuarantinedSpecMultiJvmNode1 extends RemoteRestartedQuarantinedSpec
|
|
|
|
|
class RemoteRestartedQuarantinedSpecMultiJvmNode2 extends RemoteRestartedQuarantinedSpec
|
|
|
|
|
|
2019-03-11 10:38:24 +01:00
|
|
|
abstract class RemoteRestartedQuarantinedSpec extends RemotingMultiNodeSpec(RemoteRestartedQuarantinedSpec) {
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
import RemoteRestartedQuarantinedSpec._
|
|
|
|
|
|
|
|
|
|
override def initialParticipants = 2
|
|
|
|
|
|
2019-04-15 15:55:42 +02:00
|
|
|
def identifyWithUid(role: RoleName, actorName: String): (Long, ActorRef) = {
|
2015-04-22 11:25:24 +02:00
|
|
|
system.actorSelection(node(role) / "user" / actorName) ! "identify"
|
2019-04-15 15:55:42 +02:00
|
|
|
expectMsgType[(Long, ActorRef)]
|
2015-04-22 11:25:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"A restarted quarantined system" must {
|
|
|
|
|
|
|
|
|
|
"should not crash the other system (#17213)" taggedAs LongRunningTest in {
|
|
|
|
|
|
2020-04-27 17:31:16 +07:00
|
|
|
system.actorOf(Props[Subject](), "subject")
|
2015-04-22 11:25:24 +02:00
|
|
|
enterBarrier("subject-started")
|
|
|
|
|
|
|
|
|
|
runOn(first) {
|
|
|
|
|
val secondAddress = node(second).address
|
|
|
|
|
|
2019-04-15 09:54:16 +01:00
|
|
|
val (uid, _) = identifyWithUid(second, "subject")
|
2015-04-22 11:25:24 +02:00
|
|
|
|
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
|
2021-11-12 17:30:49 +01:00
|
|
|
@nowarn
|
|
|
|
|
val thisActorSystemQuarantinedEventCls = classOf[ThisActorSystemQuarantinedEvent]
|
|
|
|
|
system.eventStream.subscribe(testActor, thisActorSystemQuarantinedEventCls)
|
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) {
|
2019-04-15 09:54:16 +01:00
|
|
|
case ThisActorSystemQuarantinedEvent(_, _) =>
|
2015-12-06 20:14:44 -05:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2019-03-13 10:56:20 +01:00
|
|
|
val freshSystem = ActorSystem(
|
|
|
|
|
system.name,
|
|
|
|
|
ConfigFactory.parseString(s"""
|
2015-04-22 11:25:24 +02:00
|
|
|
akka.remote.retry-gate-closed-for = 0.5 s
|
2019-05-01 08:12:09 +01:00
|
|
|
akka.remote.classic.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)
|
2019-03-11 10:38:24 +01:00
|
|
|
probe.awaitAssert(
|
|
|
|
|
{
|
|
|
|
|
freshSystem
|
|
|
|
|
.actorSelection(RootActorPath(firstAddress) / "user" / "subject")
|
|
|
|
|
.tell(Identify("subject"), probe.ref)
|
2019-05-01 08:12:09 +01:00
|
|
|
probe.expectMsgType[ActorIdentity](1.second).ref should not be None
|
2019-03-11 10:38:24 +01:00
|
|
|
},
|
|
|
|
|
30.seconds)
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
// Now the other system will be able to pass, too
|
2020-04-27 17:31:16 +07:00
|
|
|
freshSystem.actorOf(Props[Subject](), "subject")
|
2015-04-22 11:25:24 +02:00
|
|
|
|
|
|
|
|
Await.ready(freshSystem.whenTerminated, 10.seconds)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|