2012-08-31 16:35:23 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.cluster
|
|
|
|
|
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
import org.scalatest.BeforeAndAfter
|
|
|
|
|
import akka.remote.testkit.MultiNodeConfig
|
|
|
|
|
import akka.remote.testkit.MultiNodeSpec
|
|
|
|
|
import akka.testkit._
|
2012-10-01 20:08:21 +02:00
|
|
|
import akka.testkit.TestEvent._
|
2012-08-31 16:35:23 +02:00
|
|
|
import akka.actor.Props
|
|
|
|
|
import akka.actor.Actor
|
2012-09-04 09:55:08 +02:00
|
|
|
import akka.actor.Address
|
2012-08-31 16:35:23 +02:00
|
|
|
import akka.actor.RootActorPath
|
|
|
|
|
import akka.actor.Terminated
|
2012-09-04 09:55:08 +02:00
|
|
|
import akka.actor.Address
|
2012-08-31 16:35:23 +02:00
|
|
|
|
|
|
|
|
object ClusterDeathWatchMultiJvmSpec extends MultiNodeConfig {
|
|
|
|
|
val first = role("first")
|
|
|
|
|
val second = role("second")
|
|
|
|
|
val third = role("third")
|
2012-09-04 09:55:08 +02:00
|
|
|
val fourth = role("fourth")
|
2012-08-31 16:35:23 +02:00
|
|
|
|
2012-09-11 16:59:59 +02:00
|
|
|
commonConfig(debugConfig(on = false).withFallback(MultiNodeClusterSpec.clusterConfigWithFailureDetectorPuppet))
|
2012-08-31 16:35:23 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-11 16:59:59 +02:00
|
|
|
class ClusterDeathWatchMultiJvmNode1 extends ClusterDeathWatchSpec
|
|
|
|
|
class ClusterDeathWatchMultiJvmNode2 extends ClusterDeathWatchSpec
|
|
|
|
|
class ClusterDeathWatchMultiJvmNode3 extends ClusterDeathWatchSpec
|
|
|
|
|
class ClusterDeathWatchMultiJvmNode4 extends ClusterDeathWatchSpec
|
2012-08-31 16:35:23 +02:00
|
|
|
|
|
|
|
|
abstract class ClusterDeathWatchSpec
|
|
|
|
|
extends MultiNodeSpec(ClusterDeathWatchMultiJvmSpec)
|
|
|
|
|
with MultiNodeClusterSpec {
|
|
|
|
|
|
|
|
|
|
import ClusterDeathWatchMultiJvmSpec._
|
|
|
|
|
|
2012-10-01 20:08:21 +02:00
|
|
|
override def atStartup(): Unit = {
|
|
|
|
|
super.atStartup()
|
|
|
|
|
if (!log.isDebugEnabled) {
|
|
|
|
|
muteMarkingAsUnreachable()
|
|
|
|
|
system.eventStream.publish(Mute(EventFilter[java.net.UnknownHostException]("unknownhost")))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 16:35:23 +02:00
|
|
|
"An actor watching a remote actor in the cluster" must {
|
|
|
|
|
"receive Terminated when watched node becomes unreachable" taggedAs LongRunningTest in {
|
|
|
|
|
awaitClusterUp(roles: _*)
|
|
|
|
|
enterBarrier("cluster-up")
|
|
|
|
|
|
|
|
|
|
runOn(first) {
|
|
|
|
|
enterBarrier("subjected-started")
|
|
|
|
|
|
|
|
|
|
val path2 = RootActorPath(second) / "user" / "subject"
|
|
|
|
|
val path3 = RootActorPath(third) / "user" / "subject"
|
|
|
|
|
val watchEstablished = TestLatch(1)
|
|
|
|
|
system.actorOf(Props(new Actor {
|
|
|
|
|
context.watch(context.actorFor(path2))
|
|
|
|
|
context.watch(context.actorFor(path3))
|
|
|
|
|
watchEstablished.countDown
|
|
|
|
|
def receive = {
|
|
|
|
|
case t: Terminated ⇒ testActor ! t.actor.path
|
|
|
|
|
}
|
2012-09-04 09:55:08 +02:00
|
|
|
}), name = "observer1")
|
2012-08-31 16:35:23 +02:00
|
|
|
|
|
|
|
|
watchEstablished.await
|
|
|
|
|
enterBarrier("watch-established")
|
|
|
|
|
expectMsg(path2)
|
2012-09-04 09:55:08 +02:00
|
|
|
expectNoMsg
|
2012-08-31 16:35:23 +02:00
|
|
|
enterBarrier("second-terminated")
|
|
|
|
|
|
|
|
|
|
markNodeAsUnavailable(third)
|
|
|
|
|
expectMsg(path3)
|
|
|
|
|
enterBarrier("third-terminated")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 09:55:08 +02:00
|
|
|
runOn(second, third, fourth) {
|
2012-08-31 16:35:23 +02:00
|
|
|
system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }), name = "subject")
|
|
|
|
|
enterBarrier("subjected-started")
|
|
|
|
|
enterBarrier("watch-established")
|
|
|
|
|
runOn(third) {
|
|
|
|
|
markNodeAsUnavailable(second)
|
|
|
|
|
}
|
|
|
|
|
enterBarrier("second-terminated")
|
|
|
|
|
enterBarrier("third-terminated")
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 13:11:45 +02:00
|
|
|
enterBarrier("after-1")
|
2012-08-31 16:35:23 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 09:55:08 +02:00
|
|
|
"receive Terminated when watched node is unknown host" taggedAs LongRunningTest in {
|
|
|
|
|
runOn(first) {
|
|
|
|
|
val path = RootActorPath(Address("akka", system.name, "unknownhost", 2552)) / "user" / "subject"
|
|
|
|
|
system.actorOf(Props(new Actor {
|
|
|
|
|
context.watch(context.actorFor(path))
|
|
|
|
|
def receive = {
|
|
|
|
|
case t: Terminated ⇒ testActor ! t.actor.path
|
|
|
|
|
}
|
|
|
|
|
}), name = "observer2")
|
|
|
|
|
|
|
|
|
|
expectMsg(path)
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 13:11:45 +02:00
|
|
|
enterBarrier("after-2")
|
2012-09-04 09:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"receive Terminated when watched path doesn't exist" taggedAs LongRunningTest in {
|
|
|
|
|
runOn(first) {
|
|
|
|
|
val path = RootActorPath(second) / "user" / "non-existing"
|
|
|
|
|
system.actorOf(Props(new Actor {
|
|
|
|
|
context.watch(context.actorFor(path))
|
|
|
|
|
def receive = {
|
|
|
|
|
case t: Terminated ⇒ testActor ! t.actor.path
|
|
|
|
|
}
|
|
|
|
|
}), name = "observer3")
|
|
|
|
|
|
|
|
|
|
expectMsg(path)
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 13:11:45 +02:00
|
|
|
enterBarrier("after-3")
|
2012-09-04 09:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-31 16:35:23 +02:00
|
|
|
}
|
|
|
|
|
}
|