Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use store identifier to fetch plugin class #576

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void durableStatePlugin() {
@SuppressWarnings("unchecked")
JdbcDurableStateStore<String> store =
DurableStateStoreRegistry.get(system)
.getDurableStateStoreFor(JdbcDurableStateStore.class, "akka.persistence.state.jdbc");
.getDurableStateStoreFor(
JdbcDurableStateStore.class, JdbcDurableStateStore.Identifier());
// #jdbc-durable-state-store
}

Expand All @@ -71,7 +72,8 @@ void getObject() {
@SuppressWarnings("unchecked")
JdbcDurableStateStore<String> store =
DurableStateStoreRegistry.get(system)
.getDurableStateStoreFor(JdbcDurableStateStore.class, "akka.persistence.state.jdbc");
.getDurableStateStoreFor(
JdbcDurableStateStore.class, JdbcDurableStateStore.Identifier());

CompletionStage<GetObjectResult<String>> futureResult = store.getObject("InvalidPersistenceId");
try {
Expand All @@ -91,7 +93,8 @@ void upsertAndGetObject() {
@SuppressWarnings("unchecked")
JdbcDurableStateStore<String> store =
DurableStateStoreRegistry.get(system)
.getDurableStateStoreFor(JdbcDurableStateStore.class, "akka.persistence.state.jdbc");
.getDurableStateStoreFor(
JdbcDurableStateStore.class, JdbcDurableStateStore.Identifier());

CompletionStage<GetObjectResult<String>> r =
store
Expand All @@ -116,7 +119,8 @@ void deleteObject() {
@SuppressWarnings("unchecked")
JdbcDurableStateStore<String> store =
DurableStateStoreRegistry.get(system)
.getDurableStateStoreFor(JdbcDurableStateStore.class, "akka.persistence.state.jdbc");
.getDurableStateStoreFor(
JdbcDurableStateStore.class, JdbcDurableStateStore.Identifier());

CompletionStage<Done> futureResult = store.deleteObject("p123");
try {
Expand All @@ -135,7 +139,8 @@ void currentChanges() {
@SuppressWarnings("unchecked")
JdbcDurableStateStore<String> store =
DurableStateStoreRegistry.get(system)
.getDurableStateStoreFor(JdbcDurableStateStore.class, "akka.persistence.state.jdbc");
.getDurableStateStoreFor(
JdbcDurableStateStore.class, JdbcDurableStateStore.Identifier());

Source<DurableStateChange<String>, NotUsed> willCompleteTheStream =
store.currentChanges("tag-1", NoOffset.getInstance());
Expand All @@ -150,7 +155,8 @@ void changes() {
@SuppressWarnings("unchecked")
JdbcDurableStateStore<String> store =
DurableStateStoreRegistry.get(system)
.getDurableStateStoreFor(JdbcDurableStateStore.class, "akka.persistence.state.jdbc");
.getDurableStateStoreFor(
JdbcDurableStateStore.class, JdbcDurableStateStore.Identifier());

Source<DurableStateChange<String>, NotUsed> willNotCompleteTheStream =
store.changes("tag-1", NoOffset.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ScaladslSnippets extends ScalaFutures with Matchers {
import akka.persistence.jdbc.state.scaladsl.JdbcDurableStateStore
val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)
// #jdbc-durable-state-store
}

Expand All @@ -39,7 +39,7 @@ object ScaladslSnippets extends ScalaFutures with Matchers {

val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)

val futureResult: Future[GetObjectResult[String]] = store.getObject("InvalidPersistenceId")
futureResult.futureValue.value shouldBe None
Expand All @@ -57,7 +57,7 @@ object ScaladslSnippets extends ScalaFutures with Matchers {

val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)

val v: Future[GetObjectResult[String]] =
for {
Expand All @@ -83,7 +83,7 @@ object ScaladslSnippets extends ScalaFutures with Matchers {

val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)

store.deleteObject("p123").futureValue shouldBe Done
store.getObject("p123").futureValue.value shouldBe None
Expand All @@ -102,7 +102,7 @@ object ScaladslSnippets extends ScalaFutures with Matchers {

val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)

val willCompleteTheStream: Source[DurableStateChange[String], NotUsed] =
store.currentChanges("tag-1", NoOffset)
Expand All @@ -121,7 +121,7 @@ object ScaladslSnippets extends ScalaFutures with Matchers {

val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)

val willNotCompleteTheStream: Source[DurableStateChange[String], NotUsed] =
store.changes("tag-1", NoOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,17 @@ abstract class DurableStateStorePluginSpec(config: Config, profile: JdbcProfile)
with Matchers
with ScalaFutures {

val pluginConf: Config = ConfigFactory.parseString(s"""
akka.loglevel = INFO
akka.persistence.state.plugin = "akka.persistence.state.jdbc"
akka.persistence.state.jdbc {
class = "akka.persistence.jdbc.state.JdbcDurableStateStoreProvider"
}
""")

implicit lazy val system: ExtendedActorSystem =
ActorSystem("test", config.withFallback(pluginConf)).asInstanceOf[ExtendedActorSystem]
ActorSystem("test", config).asInstanceOf[ExtendedActorSystem]

"A durable state store plugin" must {
"instantiate a JdbcDurableDataStore successfully" in {
val store = DurableStateStoreRegistry
.get(system)
.durableStateStoreFor[JdbcDurableStateStore[String]]("akka.persistence.state.jdbc")
.durableStateStoreFor[JdbcDurableStateStore[String]](JdbcDurableStateStore.Identifier)

store shouldBe a[JdbcDurableStateStore[_]]
store.system.settings.config shouldBe system.settings.config
store.profile shouldBe profile
}
}
Expand Down