2013-01-14 10:04:49 +01:00
|
|
|
package akka.remote
|
|
|
|
|
|
|
|
|
|
import akka.testkit.AkkaSpec
|
|
|
|
|
import akka.actor.{ Props, ActorRef, Address }
|
|
|
|
|
import akka.remote.EndpointManager._
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
|
|
|
|
|
class EndpointRegistrySpec extends AkkaSpec {
|
|
|
|
|
|
|
|
|
|
val actorA = system.actorOf(Props.empty, "actorA")
|
|
|
|
|
val actorB = system.actorOf(Props.empty, "actorB")
|
|
|
|
|
|
|
|
|
|
val address1 = Address("test", "testsys1", "testhost1", 1234)
|
|
|
|
|
val address2 = Address("test", "testsys2", "testhost2", 1234)
|
|
|
|
|
|
|
|
|
|
"EndpointRegistry" must {
|
|
|
|
|
|
|
|
|
|
"be able to register a writable endpoint and policy" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
|
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(None)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.registerWritableEndpoint(address1, None, actorA) should be(actorA)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(Some(Pass(actorA, None)))
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.readOnlyEndpointFor(address1) should be(None)
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isWritable(actorA) should be(true)
|
|
|
|
|
reg.isReadOnly(actorA) should be(false)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isQuarantined(address1, 42) should be(false)
|
2013-01-14 10:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"be able to register a read-only endpoint" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.readOnlyEndpointFor(address1) should be(None)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.registerReadOnlyEndpoint(address1, actorA) should be(actorA)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.readOnlyEndpointFor(address1) should be(Some(actorA))
|
|
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(None)
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isWritable(actorA) should be(false)
|
|
|
|
|
reg.isReadOnly(actorA) should be(true)
|
|
|
|
|
reg.isQuarantined(address1, 42) should be(false)
|
2013-01-14 10:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"be able to register a writable and a read-only endpoint correctly" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.readOnlyEndpointFor(address1) should be(None)
|
|
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(None)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.registerReadOnlyEndpoint(address1, actorA) should be(actorA)
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.registerWritableEndpoint(address1, None, actorB) should be(actorB)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.readOnlyEndpointFor(address1) should be(Some(actorA))
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(Some(Pass(actorB, None)))
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isWritable(actorA) should be(false)
|
|
|
|
|
reg.isWritable(actorB) should be(true)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isReadOnly(actorA) should be(true)
|
|
|
|
|
reg.isReadOnly(actorB) should be(false)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"be able to register Gated policy for an address" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
|
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(None)
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.registerWritableEndpoint(address1, None, actorA)
|
2013-01-14 10:04:49 +01:00
|
|
|
val deadline = Deadline.now
|
|
|
|
|
reg.markAsFailed(actorA, deadline)
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(Some(Gated(deadline)))
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isReadOnly(actorA) should be(false)
|
|
|
|
|
reg.isWritable(actorA) should be(false)
|
2013-01-14 10:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"remove read-only endpoints if marked as failed" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
|
|
|
|
|
|
|
|
|
reg.registerReadOnlyEndpoint(address1, actorA)
|
|
|
|
|
reg.markAsFailed(actorA, Deadline.now)
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.readOnlyEndpointFor(address1) should be(None)
|
2013-01-14 10:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"keep tombstones when removing an endpoint" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
|
|
|
|
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.registerWritableEndpoint(address1, None, actorA)
|
|
|
|
|
reg.registerWritableEndpoint(address2, None, actorB)
|
2013-01-14 10:04:49 +01:00
|
|
|
val deadline = Deadline.now
|
|
|
|
|
reg.markAsFailed(actorA, deadline)
|
2013-04-18 17:35:43 +02:00
|
|
|
reg.markAsQuarantined(address2, 42, deadline)
|
2013-01-14 10:04:49 +01:00
|
|
|
|
|
|
|
|
reg.unregisterEndpoint(actorA)
|
|
|
|
|
reg.unregisterEndpoint(actorB)
|
|
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(Some(Gated(deadline)))
|
|
|
|
|
reg.writableEndpointWithPolicyFor(address2) should be(Some(Quarantined(42, deadline)))
|
2013-01-14 10:04:49 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"prune outdated Gated directives properly" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
|
|
|
|
|
2014-03-21 20:22:16 +01:00
|
|
|
reg.registerWritableEndpoint(address1, None, actorA)
|
|
|
|
|
reg.registerWritableEndpoint(address2, None, actorB)
|
2013-01-14 10:04:49 +01:00
|
|
|
reg.markAsFailed(actorA, Deadline.now)
|
|
|
|
|
val farInTheFuture = Deadline.now + Duration(60, SECONDS)
|
|
|
|
|
reg.markAsFailed(actorB, farInTheFuture)
|
2013-04-18 17:35:43 +02:00
|
|
|
reg.prune()
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(None)
|
|
|
|
|
reg.writableEndpointWithPolicyFor(address2) should be(Some(Gated(farInTheFuture)))
|
2013-01-14 10:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"be able to register Quarantined policy for an address" in {
|
|
|
|
|
val reg = new EndpointRegistry
|
2013-04-18 17:35:43 +02:00
|
|
|
val deadline = Deadline.now + 30.minutes
|
2013-01-14 10:04:49 +01:00
|
|
|
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(None)
|
2013-04-18 17:35:43 +02:00
|
|
|
reg.markAsQuarantined(address1, 42, deadline)
|
2013-12-17 14:25:56 +01:00
|
|
|
reg.isQuarantined(address1, 42) should be(true)
|
|
|
|
|
reg.isQuarantined(address1, 33) should be(false)
|
2014-01-31 11:14:13 +01:00
|
|
|
reg.writableEndpointWithPolicyFor(address1) should be(Some(Quarantined(42, deadline)))
|
2013-01-14 10:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|