Skip to content

Commit a210606

Browse files
author
Taichi Yamakawa
committed
SnapshotStore provides a persistence ID calculation method
1 parent a074852 commit a210606

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/main/scala/lerna/akka/entityreplication/raft/snapshot/SnapshotStore.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ private[entityreplication] object SnapshotStore {
1717
selfMemberIndex: MemberIndex,
1818
): Props =
1919
Props(new SnapshotStore(typeName, entityId, settings, selfMemberIndex))
20+
21+
/** Returns a persistence ID of SnapshotStore */
22+
def persistenceId(typeName: TypeName, entityId: NormalizedEntityId, selfMemberIndex: MemberIndex): String =
23+
ActorIds.persistenceId("SnapshotStore", typeName.underlying, entityId.underlying, selfMemberIndex.role)
24+
2025
}
2126

2227
private[entityreplication] class SnapshotStore(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package lerna.akka.entityreplication.raft.snapshot
2+
3+
import akka.actor.ActorSystem
4+
import akka.testkit.TestKit
5+
import lerna.akka.entityreplication.model.{ NormalizedEntityId, TypeName }
6+
import lerna.akka.entityreplication.raft.ActorSpec
7+
import lerna.akka.entityreplication.raft.routing.MemberIndex
8+
9+
final class SnapshotStoreSpec extends TestKit(ActorSystem("SnapshotStoreSpec")) with ActorSpec {
10+
11+
"SnapshotStore.persistenceId" should {
12+
13+
"return a persistence ID for the given type name, entity ID, and member index" in {
14+
val persistenceId = SnapshotStore.persistenceId(
15+
TypeName.from("test-type-name"),
16+
NormalizedEntityId.from("test-entity-id"),
17+
MemberIndex("test-member-index"),
18+
)
19+
assert(persistenceId === "SnapshotStore:test-type-name:test-entity-id:test-member-index")
20+
}
21+
22+
}
23+
24+
}

0 commit comments

Comments
 (0)