Support ReplicationId in PersistenceId extract utilities (#31122)
This commit is contained in:
parent
5f78f78263
commit
7a25618748
2 changed files with 28 additions and 6 deletions
|
|
@ -130,9 +130,13 @@ object PersistenceId {
|
|||
* If the separator `|` is not found it return the empty String (`""`).
|
||||
*/
|
||||
def extractEntityType(id: String): String = {
|
||||
val i = id.indexOf(PersistenceId.DefaultSeparator)
|
||||
if (i == -1) ""
|
||||
else id.substring(0, i)
|
||||
if (ReplicationId.isReplicationId(id))
|
||||
ReplicationId.fromString(id).typeName
|
||||
else {
|
||||
val i = id.indexOf(PersistenceId.DefaultSeparator)
|
||||
if (i == -1) ""
|
||||
else id.substring(0, i)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,9 +144,13 @@ object PersistenceId {
|
|||
* If the separator `|` is not found it return the `id`.
|
||||
*/
|
||||
def extractEntityId(id: String): String = {
|
||||
val i = id.indexOf(PersistenceId.DefaultSeparator)
|
||||
if (i == -1) id
|
||||
else id.substring(i + 1)
|
||||
if (ReplicationId.isReplicationId(id))
|
||||
ReplicationId.fromString(id).entityId
|
||||
else {
|
||||
val i = id.indexOf(PersistenceId.DefaultSeparator)
|
||||
if (i == -1) id
|
||||
else id.substring(i + 1)
|
||||
}
|
||||
}
|
||||
|
||||
def unapply(persistenceId: PersistenceId): Option[(String, String)] =
|
||||
|
|
|
|||
|
|
@ -54,6 +54,13 @@ class PersistenceIdSpec extends AnyWordSpec with Matchers with LogCapturing {
|
|||
PersistenceId("SomeType", "abc").entityTypeHint should ===("SomeType")
|
||||
}
|
||||
|
||||
"be able to extract entityTypeHint from ReplicationId" in {
|
||||
val replicaId = ReplicationId("SomeType", "abc", ReplicaId("A"))
|
||||
val pid = replicaId.persistenceId
|
||||
pid.entityTypeHint should ===("SomeType")
|
||||
PersistenceId.extractEntityType(pid.id) should ===("SomeType")
|
||||
}
|
||||
|
||||
"be able to extract entityId" in {
|
||||
PersistenceId.extractEntityId("SomeType|abc") should ===("abc")
|
||||
PersistenceId.extractEntityId("abc") should ===("abc")
|
||||
|
|
@ -68,6 +75,13 @@ class PersistenceIdSpec extends AnyWordSpec with Matchers with LogCapturing {
|
|||
case _ => fail()
|
||||
}
|
||||
}
|
||||
|
||||
"be able to extract entityId from ReplicationId" in {
|
||||
val replicaId = ReplicationId("SomeType", "abc", ReplicaId("A"))
|
||||
val pid = replicaId.persistenceId
|
||||
pid.entityId should ===("abc")
|
||||
PersistenceId.extractEntityId(pid.id) should ===("abc")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue