Allow using hypen in actorSystem name and do not replace it with underscore #28994 (#29399)

Co-authored-by: andrii.ryzhenko <andrii.ryzhenko@betlab.com>
This commit is contained in:
Andrii 2020-07-21 12:19:19 +03:00 committed by GitHub
parent a51a85c8ad
commit beda844b8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -44,7 +44,7 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike wi
} finally testkit2.shutdownTestKit()
}
"use name from given class name" in {
"use name from given class name with replaced package name" in {
val testkit2 = ActorTestKit(classOf[Vector[_]].getName)
try {
// removing package name and such
@ -52,6 +52,23 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike wi
} finally testkit2.shutdownTestKit()
}
"use sanitized name if passed invalid characters" in {
val testkit2 = ActorTestKit("actor~!sys-tem&Name#1%(with*invalid^ch@racter$)`")
try {
// replacing invalid characters with underscore
testkit2.system.name should ===("actor__sys-tem_Name_1__with_invalid_ch_racter___")
} finally testkit2.shutdownTestKit()
}
"use the same name if passed valid ActorSystem name" in {
val validActorSystemNameChars = "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789_"
val testkit2 = ActorTestKit(validActorSystemNameChars)
try {
// all characters should be the same
testkit2.system.name should ===(validActorSystemNameChars)
} finally testkit2.shutdownTestKit()
}
"spawn an actor" in {
val sawMessage = Promise[Boolean]()
spawn(Behaviors.setup[AnyRef] { _ =>

View file

@ -56,7 +56,7 @@ private[akka] object TestKitUtils {
name
.replaceFirst("""^.*\.""", "") // drop package name
.replaceAll("""\$\$?\w+""", "") // drop scala anonymous functions/classes
.replaceAll("[^a-zA-Z_0-9]", "_")
.replaceAll("[^a-zA-Z_0-9-]", "_")
.replaceAll("""MultiJvmNode\d+""", "") // drop MultiJvm suffix
}
}