2013-08-19 17:50:15 +02:00
|
|
|
/**
|
2014-02-02 19:05:45 -06:00
|
|
|
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
2013-08-19 17:50:15 +02:00
|
|
|
*/
|
|
|
|
|
package akka.remote
|
|
|
|
|
|
|
|
|
|
import language.postfixOps
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
import akka.actor.Actor
|
|
|
|
|
import akka.actor.ActorIdentity
|
|
|
|
|
import akka.actor.ActorRef
|
|
|
|
|
import akka.actor.Identify
|
|
|
|
|
import akka.actor.Props
|
|
|
|
|
import akka.actor.Terminated
|
|
|
|
|
import akka.remote.testconductor.RoleName
|
|
|
|
|
import akka.remote.transport.ThrottlerTransportAdapter.Direction
|
|
|
|
|
import akka.remote.testkit.MultiNodeConfig
|
|
|
|
|
import akka.remote.testkit.MultiNodeSpec
|
|
|
|
|
import akka.remote.testkit.STMultiNodeSpec
|
|
|
|
|
import akka.testkit._
|
|
|
|
|
import akka.actor.ExtendedActorSystem
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.actor.RootActorPath
|
|
|
|
|
|
|
|
|
|
object RemoteNodeRestartDeathWatchMultiJvmSpec extends MultiNodeConfig {
|
|
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
|
|
|
|
|
commonConfig(debugConfig(on = false).withFallback(
|
|
|
|
|
ConfigFactory.parseString("""
|
|
|
|
|
akka.loglevel = INFO
|
|
|
|
|
akka.remote.log-remote-lifecycle-events = off
|
2013-12-12 13:05:59 +01:00
|
|
|
akka.remote.transport-failure-detector.heartbeat-interval = 1 s
|
|
|
|
|
akka.remote.transport-failure-detector.acceptable-heartbeat-pause = 3 s
|
|
|
|
|
""")))
|
2013-08-19 17:50:15 +02:00
|
|
|
|
|
|
|
|
testTransport(on = true)
|
|
|
|
|
|
|
|
|
|
class Subject extends Actor {
|
|
|
|
|
def receive = {
|
|
|
|
|
case "shutdown" ⇒
|
2014-01-16 15:16:35 +01:00
|
|
|
sender() ! "shutdown-ack"
|
2013-08-19 17:50:15 +02:00
|
|
|
context.system.shutdown()
|
2014-01-16 15:16:35 +01:00
|
|
|
case msg ⇒ sender() ! msg
|
2013-08-19 17:50:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Several different variations of the test
|
|
|
|
|
|
|
|
|
|
class RemoteNodeRestartDeathWatchMultiJvmNode1 extends RemoteNodeRestartDeathWatchSpec
|
|
|
|
|
class RemoteNodeRestartDeathWatchMultiJvmNode2 extends RemoteNodeRestartDeathWatchSpec
|
|
|
|
|
|
|
|
|
|
abstract class RemoteNodeRestartDeathWatchSpec
|
|
|
|
|
extends MultiNodeSpec(RemoteNodeRestartDeathWatchMultiJvmSpec)
|
|
|
|
|
with STMultiNodeSpec with ImplicitSender {
|
|
|
|
|
|
|
|
|
|
import RemoteNodeRestartDeathWatchMultiJvmSpec._
|
|
|
|
|
|
|
|
|
|
override def initialParticipants = roles.size
|
|
|
|
|
|
|
|
|
|
def identify(role: RoleName, actorName: String): ActorRef = {
|
|
|
|
|
system.actorSelection(node(role) / "user" / actorName) ! Identify(actorName)
|
|
|
|
|
expectMsgType[ActorIdentity].ref.get
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"RemoteNodeRestartDeathWatch" must {
|
|
|
|
|
|
|
|
|
|
"receive Terminated when remote actor system is restarted" taggedAs LongRunningTest in {
|
|
|
|
|
runOn(first) {
|
|
|
|
|
val secondAddress = node(second).address
|
|
|
|
|
enterBarrier("actors-started")
|
|
|
|
|
|
|
|
|
|
val subject = identify(second, "subject")
|
|
|
|
|
watch(subject)
|
|
|
|
|
subject ! "hello"
|
|
|
|
|
expectMsg("hello")
|
|
|
|
|
enterBarrier("watch-established")
|
|
|
|
|
|
|
|
|
|
// simulate a hard shutdown, nothing sent from the shutdown node
|
|
|
|
|
testConductor.blackhole(second, first, Direction.Send).await
|
|
|
|
|
testConductor.shutdown(second).await
|
|
|
|
|
|
|
|
|
|
expectTerminated(subject, 15.seconds)
|
|
|
|
|
|
2013-09-04 11:41:24 +02:00
|
|
|
within(5.seconds) {
|
|
|
|
|
// retry because the Subject actor might not be started yet
|
|
|
|
|
awaitAssert {
|
|
|
|
|
system.actorSelection(RootActorPath(secondAddress) / "user" / "subject") ! "shutdown"
|
|
|
|
|
expectMsg(1.second, "shutdown-ack")
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-19 17:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runOn(second) {
|
|
|
|
|
val addr = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
|
|
|
|
system.actorOf(Props[Subject], "subject")
|
|
|
|
|
enterBarrier("actors-started")
|
|
|
|
|
|
|
|
|
|
enterBarrier("watch-established")
|
|
|
|
|
|
|
|
|
|
system.awaitTermination(30.seconds)
|
|
|
|
|
|
|
|
|
|
val freshSystem = ActorSystem(system.name, ConfigFactory.parseString(s"""
|
|
|
|
|
akka.remote.netty.tcp {
|
|
|
|
|
hostname = ${addr.host.get}
|
|
|
|
|
port = ${addr.port.get}
|
|
|
|
|
}
|
|
|
|
|
""").withFallback(system.settings.config))
|
|
|
|
|
freshSystem.actorOf(Props[Subject], "subject")
|
|
|
|
|
|
|
|
|
|
freshSystem.awaitTermination(30.seconds)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|