+act #3769 Add toStringWithoutAddress to ActorPath

This commit is contained in:
Patrik Nordwall 2014-01-08 17:51:18 +01:00
parent e25455e935
commit 7648a50d53
12 changed files with 46 additions and 29 deletions

View file

@ -101,9 +101,9 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
}
"find actors by looking up their root-anchored relative path" in {
system.actorFor(c1.path.elements.mkString("/", "/", "")) should equal(c1)
system.actorFor(c2.path.elements.mkString("/", "/", "")) should equal(c2)
system.actorFor(c21.path.elements.mkString("/", "/", "")) should equal(c21)
system.actorFor(c1.path.toStringWithoutAddress) should equal(c1)
system.actorFor(c2.path.toStringWithoutAddress) should equal(c2)
system.actorFor(c21.path.toStringWithoutAddress) should equal(c21)
}
"find actors by looking up their relative path" in {
@ -200,7 +200,7 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
"find actors by looking up their root-anchored relative path" in {
def check(looker: ActorRef, pathOf: ActorRef, result: ActorRef) {
Await.result(looker ? LookupString(pathOf.path.elements.mkString("/", "/", "")), timeout.duration) should equal(result)
Await.result(looker ? LookupString(pathOf.path.toStringWithoutAddress), timeout.duration) should equal(result)
Await.result(looker ? LookupString(pathOf.path.elements.mkString("/", "/", "/")), timeout.duration) should equal(result)
}
for {
@ -231,7 +231,7 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
Await.result(looker ? LookupPath(target.path), timeout.duration) should equal(target)
Await.result(looker ? LookupString(target.path.toString), timeout.duration) should equal(target)
Await.result(looker ? LookupString(target.path.toString + "/"), timeout.duration) should equal(target)
Await.result(looker ? LookupString(target.path.elements.mkString("/", "/", "")), timeout.duration) should equal(target)
Await.result(looker ? LookupString(target.path.toStringWithoutAddress), timeout.duration) should equal(target)
if (target != root) Await.result(looker ? LookupString(target.path.elements.mkString("/", "/", "/")), timeout.duration) should equal(target)
}
}
@ -269,10 +269,10 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
a.path.elements.head should equal("temp")
Await.result(c2 ? LookupPath(a.path), timeout.duration) should equal(a)
Await.result(c2 ? LookupString(a.path.toString), timeout.duration) should equal(a)
Await.result(c2 ? LookupString(a.path.elements.mkString("/", "/", "")), timeout.duration) should equal(a)
Await.result(c2 ? LookupString(a.path.toStringWithoutAddress), timeout.duration) should equal(a)
Await.result(c2 ? LookupString("../../" + a.path.elements.mkString("/")), timeout.duration) should equal(a)
Await.result(c2 ? LookupString(a.path.toString + "/"), timeout.duration) should equal(a)
Await.result(c2 ? LookupString(a.path.elements.mkString("/", "/", "") + "/"), timeout.duration) should equal(a)
Await.result(c2 ? LookupString(a.path.toStringWithoutAddress + "/"), timeout.duration) should equal(a)
Await.result(c2 ? LookupString("../../" + a.path.elements.mkString("/") + "/"), timeout.duration) should equal(a)
Await.result(c2 ? LookupElems(Seq("..", "..") ++ a.path.elements), timeout.duration) should equal(a)
Await.result(c2 ? LookupElems(Seq("..", "..") ++ a.path.elements :+ ""), timeout.duration) should equal(a)

View file

@ -41,6 +41,14 @@ class ActorPathSpec extends WordSpec with Matchers {
(RootActorPath(Address("akka.tcp", "mysys")) / "user" / "foo" / "bar").elements.toSeq should be(Seq("user", "foo", "bar"))
}
"create correct toStringWithoutAddress" in {
val a = Address("akka.tcp", "mysys")
RootActorPath(a).toStringWithoutAddress should be("/")
(RootActorPath(a) / "user").toStringWithoutAddress should be("/user")
(RootActorPath(a) / "user" / "foo").toStringWithoutAddress should be("/user/foo")
(RootActorPath(a) / "user" / "foo" / "bar").toStringWithoutAddress should be("/user/foo/bar")
}
"create correct toStringWithAddress" in {
val local = Address("akka.tcp", "mysys")
val a = local.copy(host = Some("aaa"), port = Some(2552))

View file

@ -104,9 +104,9 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
identify(c2.path.toString) should equal(Some(c2))
identify(c21.path.toString) should equal(Some(c21))
identify(c1.path.elements.mkString("/", "/", "")) should equal(Some(c1))
identify(c2.path.elements.mkString("/", "/", "")) should equal(Some(c2))
identify(c21.path.elements.mkString("/", "/", "")) should equal(Some(c21))
identify(c1.path.toStringWithoutAddress) should equal(Some(c1))
identify(c2.path.toStringWithoutAddress) should equal(Some(c2))
identify(c21.path.toStringWithoutAddress) should equal(Some(c21))
}
"take actor incarnation into account when comparing actor references" in {
@ -131,9 +131,9 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
}
"select actors by their root-anchored relative path" in {
identify(c1.path.elements.mkString("/", "/", "")) should equal(Some(c1))
identify(c2.path.elements.mkString("/", "/", "")) should equal(Some(c2))
identify(c21.path.elements.mkString("/", "/", "")) should equal(Some(c21))
identify(c1.path.toStringWithoutAddress) should equal(Some(c1))
identify(c2.path.toStringWithoutAddress) should equal(Some(c2))
identify(c21.path.toStringWithoutAddress) should equal(Some(c21))
}
"select actors by their relative path" in {
@ -147,13 +147,13 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
identify("/deadLetters") should equal(Some(system.deadLetters))
identify("/system") should equal(Some(syst))
identify(syst.path) should equal(Some(syst))
identify(syst.path.elements.mkString("/", "/", "")) should equal(Some(syst))
identify(syst.path.toStringWithoutAddress) should equal(Some(syst))
identify("/") should equal(Some(root))
identify("") should equal(Some(root))
identify(RootActorPath(root.path.address)) should equal(Some(root))
identify("..") should equal(Some(root))
identify(root.path) should equal(Some(root))
identify(root.path.elements.mkString("/", "/", "")) should equal(Some(root))
identify(root.path.toStringWithoutAddress) should equal(Some(root))
identify("user") should equal(Some(user))
identify("deadLetters") should equal(Some(system.deadLetters))
identify("system") should equal(Some(syst))
@ -188,9 +188,9 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
"select actors by their string path representation" in {
def check(looker: ActorRef, pathOf: ActorRef, result: ActorRef) {
askNode(looker, SelectString(pathOf.path.elements.mkString("/", "/", ""))) should equal(Some(result))
askNode(looker, SelectString(pathOf.path.toStringWithoutAddress)) should equal(Some(result))
// with trailing /
askNode(looker, SelectString(pathOf.path.elements.mkString("/", "/", "") + "/")) should equal(Some(result))
askNode(looker, SelectString(pathOf.path.toStringWithoutAddress + "/")) should equal(Some(result))
}
for {
looker all
@ -200,7 +200,7 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
"select actors by their root-anchored relative path" in {
def check(looker: ActorRef, pathOf: ActorRef, result: ActorRef) {
askNode(looker, SelectString(pathOf.path.elements.mkString("/", "/", ""))) should equal(Some(result))
askNode(looker, SelectString(pathOf.path.toStringWithoutAddress)) should equal(Some(result))
askNode(looker, SelectString(pathOf.path.elements.mkString("/", "/", "/"))) should equal(Some(result))
}
for {
@ -339,7 +339,7 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
val d = p.expectMsgType[DeadLetter]
d.message should be("boom")
d.sender should be(testActor)
d.recipient.path.elements.mkString("/", "/", "") should be("/user/missing")
d.recipient.path.toStringWithoutAddress should be("/user/missing")
}
"send ActorSelection wildcard targeted to missing actor to deadLetters" in {
@ -356,7 +356,7 @@ class ActorSelectionSpec extends AkkaSpec("akka.loglevel=DEBUG") with DefaultTim
List(d1, d2) foreach { d
d.message should be("wild")
d.sender should be(testActor)
d.recipient.path.elements.mkString("/", "/", "") should (equal("/user/top/child1/a") or equal("/user/top/child2/a"))
d.recipient.path.toStringWithoutAddress should (equal("/user/top/child1/a") or equal("/user/top/child2/a"))
}
}

View file

@ -78,7 +78,9 @@ class TcpIntegrationSpec extends AkkaSpec("""
// a "random" endpoint hopefully unavailable
val endpoint = new InetSocketAddress("10.226.182.48", 23825)
connectCommander.send(IO(Tcp), Connect(endpoint))
connectCommander.expectNoMsg(1.second)
// expecting CommandFailed or no reply (within timeout)
val replies = connectCommander.receiveWhile(1.second) { case m: Connected m }
replies should be(Nil)
}
}

View file

@ -132,7 +132,7 @@ class RoundRobinSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
case "end" doneLatch.countDown()
}
}), name = "target-" + n)
ref.path.elements.mkString("/", "/", "")
ref.path.toStringWithoutAddress
}
val actor = system.actorOf(RoundRobinGroup(paths).props(), "round-robin-group1")

View file

@ -98,6 +98,13 @@ sealed trait ActorPath extends Comparable[ActorPath] with Serializable {
*/
def root: RootActorPath
/**
* String representation of the path elements, excluding the address
* information. The elements are separated with "/" and starts with "/",
* e.g. "/user/a/b".
*/
def toStringWithoutAddress: String = elements.mkString("/", "/", "")
/**
* Generate String representation, replacing the Address in the RootActor
* Path with the given one unless this paths address includes host and port

View file

@ -238,7 +238,7 @@ class ClusterReceptionistExtension(system: ExtendedActorSystem) extends Extensio
* but it can also be explicitly unregistered before termination.
*/
def unregisterService(actor: ActorRef): Unit =
pubSubMediator ! DistributedPubSubMediator.Remove(actor.path.elements.mkString("/", "/", ""))
pubSubMediator ! DistributedPubSubMediator.Remove(actor.path.toStringWithoutAddress)
/**
* Register an actor that should be reachable for the clients to a named topic.

View file

@ -359,7 +359,7 @@ private[akka] class ClusterShardingGuardian extends Actor {
case Start(typeName, entryProps, idExtractor, shardResolver, allocationStrategy)
val encName = URLEncoder.encode(typeName, "utf-8")
val coordinatorSingletonManagerName = encName + "Coordinator"
val coordinatorPath = (self.path / coordinatorSingletonManagerName / "singleton").elements.mkString("/", "/", "")
val coordinatorPath = (self.path / coordinatorSingletonManagerName / "singleton").toStringWithoutAddress
val shardRegion = context.child(encName).getOrElse {
if (HasNecessaryClusterRole && context.child(coordinatorSingletonManagerName).isEmpty) {
val singletonProps = ShardCoordinator.props(handOffTimeout = HandOffTimeout, rebalanceInterval = RebalanceInterval,

View file

@ -405,7 +405,7 @@ class DistributedPubSubMediator(
def mkKey(ref: ActorRef): String = mkKey(ref.path)
def mkKey(path: ActorPath): String = path.elements.mkString("/", "/", "")
def mkKey(path: ActorPath): String = path.toStringWithoutAddress
def myVersions: Map[Address, Long] = registry.map { case (owner, bucket) (owner -> bucket.version) }

View file

@ -539,9 +539,9 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
lastSender should equal(actor)
actor ! me
expectMsg("reply")
lastSender.path.elements.mkString("/", "/", "") should equal("/user")
lastSender.path.toStringWithoutAddress should equal("/user")
expectMsg("reply")
lastSender.path.elements.mkString("/", "/", "") should equal("/user")
lastSender.path.toStringWithoutAddress should equal("/user")
}
"using ActorDSL outside of akka.actor package" in {

View file

@ -86,5 +86,5 @@ class Persistence(val system: ExtendedActorSystem) extends Extension {
system.asInstanceOf[ActorSystemImpl].systemActorOf(Props(pluginClass).withDispatcher(pluginDispatcherId), pluginType)
}
private def id(ref: ActorRef) = ref.path.elements.mkString("/", "/", "")
private def id(ref: ActorRef) = ref.path.toStringWithoutAddress
}

View file

@ -155,7 +155,7 @@ akka.loglevel = DEBUG
Identify(None), p.ref)
val clientReceptionistRef = p.expectMsgType[ActorIdentity].ref.get
val sel = ActorSelection(clientReceptionistRef, receptionist.path.elements.mkString("/", "/", ""))
val sel = ActorSelection(clientReceptionistRef, receptionist.path.toStringWithoutAddress)
sel ! "hello"
expectNoMsg(1.second)
}