diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorLookupSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorLookupSpec.scala index 45178d131e..9c16cf9dec 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorLookupSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorLookupSpec.scala @@ -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) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala index 862b5145fd..64489e1fb2 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala @@ -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)) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala index a9308723fd..5f64622d51 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala @@ -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")) } } diff --git a/akka-actor-tests/src/test/scala/akka/io/TcpIntegrationSpec.scala b/akka-actor-tests/src/test/scala/akka/io/TcpIntegrationSpec.scala index 712ef0755c..c630d069dc 100644 --- a/akka-actor-tests/src/test/scala/akka/io/TcpIntegrationSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/io/TcpIntegrationSpec.scala @@ -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) } } diff --git a/akka-actor-tests/src/test/scala/akka/routing/RoundRobinSpec.scala b/akka-actor-tests/src/test/scala/akka/routing/RoundRobinSpec.scala index f04ebc3d17..cde3edd41c 100644 --- a/akka-actor-tests/src/test/scala/akka/routing/RoundRobinSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/routing/RoundRobinSpec.scala @@ -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") diff --git a/akka-actor/src/main/scala/akka/actor/ActorPath.scala b/akka-actor/src/main/scala/akka/actor/ActorPath.scala index f88af3b913..2928d6e554 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorPath.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorPath.scala @@ -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 path’s address includes host and port diff --git a/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterClient.scala b/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterClient.scala index f4c023aca5..1fc5ba9ce4 100644 --- a/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterClient.scala +++ b/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterClient.scala @@ -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. diff --git a/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterSharding.scala b/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterSharding.scala index d05ae61ec5..b5129d458e 100644 --- a/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterSharding.scala +++ b/akka-contrib/src/main/scala/akka/contrib/pattern/ClusterSharding.scala @@ -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, diff --git a/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala b/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala index 4a8eadf304..1081496bab 100644 --- a/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala +++ b/akka-contrib/src/main/scala/akka/contrib/pattern/DistributedPubSubMediator.scala @@ -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) } diff --git a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala index ba3cf7ddc5..4f5d86ef52 100644 --- a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala @@ -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 { diff --git a/akka-persistence/src/main/scala/akka/persistence/Persistence.scala b/akka-persistence/src/main/scala/akka/persistence/Persistence.scala index a7cd106646..753a48baf9 100644 --- a/akka-persistence/src/main/scala/akka/persistence/Persistence.scala +++ b/akka-persistence/src/main/scala/akka/persistence/Persistence.scala @@ -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 } diff --git a/akka-remote/src/test/scala/akka/remote/UntrustedSpec.scala b/akka-remote/src/test/scala/akka/remote/UntrustedSpec.scala index ed88f4baca..a2004561bd 100644 --- a/akka-remote/src/test/scala/akka/remote/UntrustedSpec.scala +++ b/akka-remote/src/test/scala/akka/remote/UntrustedSpec.scala @@ -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) }