You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by fa...@apache.org on 2025/04/19 10:56:43 UTC

(pekko-persistence-jdbc) branch main updated: add Snapshot db test that uses a non-default schema (#281)

This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-persistence-jdbc.git


The following commit(s) were added to refs/heads/main by this push:
     new a4c683a  add Snapshot db test that uses a non-default schema (#281)
a4c683a is described below

commit a4c683ac2aed85b542d9238c2902244f0097a7e7
Author: PJ Fanning <pj...@users.noreply.github.com>
AuthorDate: Sat Apr 19 12:56:38 2025 +0200

    add Snapshot db test that uses a non-default schema (#281)
    
    * add snapshot tests (using db schema)
    
    fix: formatting
    
    refactor new tests
    
    temp disable test
    
    Update DurableStateStorePluginSpec.scala
    
    Update PostgresDurableStateStorePluginSpec.scala
    
    refactor
    
    Update DurableStateStorePluginSpec.scala
    
    close db
    
    Update DurableStateStorePluginSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    add snapshot tests
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update DurableStateStorePluginSpec.scala
    
    inline SnapshotStoreSpec temporarily
    
    Update BaseSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    revert temp change
    
    refactor test
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    Update JdbcSnapshotStoreSpec.scala
    
    * use TestKit shutdown
    
    ---------
    
    Co-authored-by: patsta32 <ma...@patrickstadler.dev>
---
 .../jdbc/snapshot/JdbcSnapshotStoreSpec.scala      | 55 ++++++++++++++++++----
 .../scaladsl/DurableStateStorePluginSpec.scala     |  5 +-
 .../jdbc/integration/JdbcSnapshotStoreSpec.scala   | 31 ++++++++----
 3 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/core/src/test/scala/org/apache/pekko/persistence/jdbc/snapshot/JdbcSnapshotStoreSpec.scala b/core/src/test/scala/org/apache/pekko/persistence/jdbc/snapshot/JdbcSnapshotStoreSpec.scala
index b6e3e67..107fd21 100644
--- a/core/src/test/scala/org/apache/pekko/persistence/jdbc/snapshot/JdbcSnapshotStoreSpec.scala
+++ b/core/src/test/scala/org/apache/pekko/persistence/jdbc/snapshot/JdbcSnapshotStoreSpec.scala
@@ -19,15 +19,17 @@ import pekko.persistence.CapabilityFlag
 import pekko.persistence.jdbc.config._
 import pekko.persistence.jdbc.util.{ ClasspathResources, DropCreate }
 import pekko.persistence.jdbc.db.SlickDatabase
+import pekko.persistence.jdbc.testkit.internal.H2
+import pekko.persistence.jdbc.testkit.internal.{ SchemaType, SchemaUtilsImpl }
 import pekko.persistence.snapshot.SnapshotStoreSpec
+import pekko.testkit.TestKit
+
 import com.typesafe.config.{ Config, ConfigFactory }
 import org.scalatest.BeforeAndAfterAll
 import org.scalatest.concurrent.ScalaFutures
-import scala.concurrent.duration._
-
-import pekko.persistence.jdbc.testkit.internal.H2
-import pekko.persistence.jdbc.testkit.internal.SchemaType
+import org.slf4j.LoggerFactory
 
+import scala.concurrent.duration._
 import scala.concurrent.ExecutionContext
 
 abstract class JdbcSnapshotStoreSpec(config: Config, schemaType: SchemaType)
@@ -40,11 +42,7 @@ abstract class JdbcSnapshotStoreSpec(config: Config, schemaType: SchemaType)
 
   implicit lazy val ec: ExecutionContext = system.dispatcher
 
-  lazy val cfg = system.settings.config.getConfig("jdbc-journal")
-
-  lazy val journalConfig = new JournalConfig(cfg)
-
-  lazy val db = SlickDatabase.database(cfg, new SlickConfiguration(cfg.getConfig("slick")), "slick.db")
+  lazy val db = SlickDatabase.database(config, new SlickConfiguration(config.getConfig("slick")), "slick.db")
 
   protected override def supportsSerialization: CapabilityFlag = newDao
   protected override def supportsMetadata: CapabilityFlag = newDao
@@ -56,7 +54,46 @@ abstract class JdbcSnapshotStoreSpec(config: Config, schemaType: SchemaType)
 
   override def afterAll(): Unit = {
     db.close()
+    TestKit.shutdownActorSystem(system)
+    super.afterAll()
+  }
+}
+
+abstract class JdbcSnapshotStoreSchemaSpec(config: Config, schemaType: SchemaType)
+    extends JdbcSnapshotStoreSpec(config, schemaType) {
+  private val logger = LoggerFactory.getLogger(this.getClass)
+  protected def defaultSchemaName: String = "public"
+  private val schemaName: String = "pekko"
+
+  override def beforeAll(): Unit = {
+    SchemaUtilsImpl.createWithSlickButChangeSchema(
+      schemaType, logger, db, defaultSchemaName, schemaName)
+    super.beforeAll()
+  }
+
+  override def afterAll(): Unit = {
+    SchemaUtilsImpl.dropWithSlickButChangeSchema(
+      schemaType, logger, db, defaultSchemaName, schemaName)
+    super.afterAll()
   }
+
 }
 
 class H2SnapshotStoreSpec extends JdbcSnapshotStoreSpec(ConfigFactory.load("h2-application.conf"), H2)
+
+object H2SnapshotStoreSchemaSpec {
+  val config: Config = ConfigFactory.parseString("""
+    jdbc-snapshot-store {
+      tables {
+        snapshot {
+          schemaName = "pekko"
+        }
+      }
+    }
+  """).withFallback(
+    ConfigFactory.load("h2-application.conf"))
+}
+
+class H2SnapshotStoreSchemaSpec extends JdbcSnapshotStoreSchemaSpec(H2SnapshotStoreSchemaSpec.config, H2) {
+  override protected def defaultSchemaName: String = "PUBLIC"
+}
diff --git a/core/src/test/scala/org/apache/pekko/persistence/jdbc/state/scaladsl/DurableStateStorePluginSpec.scala b/core/src/test/scala/org/apache/pekko/persistence/jdbc/state/scaladsl/DurableStateStorePluginSpec.scala
index 36c7d61..33afb98 100644
--- a/core/src/test/scala/org/apache/pekko/persistence/jdbc/state/scaladsl/DurableStateStorePluginSpec.scala
+++ b/core/src/test/scala/org/apache/pekko/persistence/jdbc/state/scaladsl/DurableStateStorePluginSpec.scala
@@ -16,6 +16,7 @@ import pekko.persistence.jdbc.config.SlickConfiguration
 import pekko.persistence.jdbc.db.SlickDatabase
 import pekko.persistence.jdbc.testkit.internal.SchemaUtilsImpl
 import pekko.persistence.state.DurableStateStoreRegistry
+import pekko.testkit.TestKit
 import pekko.util.Timeout
 import org.scalatest.concurrent.Eventually.eventually
 import org.scalatest.concurrent.ScalaFutures
@@ -50,7 +51,7 @@ abstract class DurableStateStorePluginSpec(config: Config, profile: JdbcProfile)
   }
 
   override def afterAll(): Unit = {
-    system.terminate().futureValue
+    TestKit.shutdownActorSystem(system)
   }
 }
 
@@ -99,7 +100,7 @@ abstract class DurableStateStoreSchemaPluginSpec(val config: Config, profile: Jd
       SchemaUtilsImpl.slickProfileToSchemaType(profile),
       logger, db, defaultSchemaName, schemaName)
     db.close()
-    system.terminate().futureValue
+    TestKit.shutdownActorSystem(system)
   }
 
   "A durable state store plugin" must {
diff --git a/integration-test/src/test/scala/org/apache/pekko/persistence/jdbc/integration/JdbcSnapshotStoreSpec.scala b/integration-test/src/test/scala/org/apache/pekko/persistence/jdbc/integration/JdbcSnapshotStoreSpec.scala
index 3c47c14..e939f93 100644
--- a/integration-test/src/test/scala/org/apache/pekko/persistence/jdbc/integration/JdbcSnapshotStoreSpec.scala
+++ b/integration-test/src/test/scala/org/apache/pekko/persistence/jdbc/integration/JdbcSnapshotStoreSpec.scala
@@ -10,18 +10,33 @@
 package org.apache.pekko.persistence.jdbc.integration
 
 import org.apache.pekko
-import pekko.persistence.jdbc.snapshot.JdbcSnapshotStoreSpec
-import pekko.persistence.jdbc.testkit.internal.MySQL
-import pekko.persistence.jdbc.testkit.internal.Oracle
-import pekko.persistence.jdbc.testkit.internal.Postgres
-import pekko.persistence.jdbc.testkit.internal.SqlServer
-import com.typesafe.config.ConfigFactory
+import pekko.persistence.jdbc.snapshot.{ JdbcSnapshotStoreSchemaSpec, JdbcSnapshotStoreSpec }
+import pekko.persistence.jdbc.testkit.internal.{ MySQL, Oracle, Postgres, SqlServer }
+import com.typesafe.config.{ Config, ConfigFactory }
 
 class PostgresSnapshotStoreSpec extends JdbcSnapshotStoreSpec(ConfigFactory.load("postgres-application.conf"), Postgres)
 
-class MySQLSnapshotStoreSpec extends JdbcSnapshotStoreSpec(ConfigFactory.load("mysql-application.conf"), MySQL)
+object PostgresSnapshotStoreSchemaSpec {
+  val config: Config = ConfigFactory.parseString("""
+    jdbc-snapshot-store {
+      tables {
+        snapshot {
+          schemaName = "pekko"
+        }
+      }
+    }
+  """).withFallback(
+    ConfigFactory.load("postgres-application.conf"))
+}
 
-class OracleSnapshotStoreSpec extends JdbcSnapshotStoreSpec(ConfigFactory.load("oracle-application.conf"), Oracle)
+class PostgresSnapshotStoreSchemaSpec
+    extends JdbcSnapshotStoreSchemaSpec(PostgresSnapshotStoreSchemaSpec.config, Postgres)
+
+class MySQLSnapshotStoreSpec
+    extends JdbcSnapshotStoreSpec(ConfigFactory.load("mysql-application.conf"), MySQL)
+
+class OracleSnapshotStoreSpec
+    extends JdbcSnapshotStoreSpec(ConfigFactory.load("oracle-application.conf"), Oracle)
 
 class SqlServerSnapshotStoreSpec
     extends JdbcSnapshotStoreSpec(ConfigFactory.load("sqlserver-application.conf"), SqlServer)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org