!per #17249 Avoid init problems of persistence tck
* in the end TestKitBase eagerly initialize the ActorSystem and to avoid the need for using lazy val tricks I changed the trait to abstract class with config constructor parameter
This commit is contained in:
parent
5c7235acbd
commit
85be3045bb
13 changed files with 38 additions and 47 deletions
|
|
@ -145,24 +145,22 @@ object PersistenceTCKDoc {
|
||||||
import akka.persistence.journal.JournalSpec
|
import akka.persistence.journal.JournalSpec
|
||||||
|
|
||||||
//#journal-tck-scala
|
//#journal-tck-scala
|
||||||
class MyJournalSpec extends JournalSpec {
|
class MyJournalSpec extends JournalSpec(
|
||||||
override val config = ConfigFactory.parseString(
|
config = ConfigFactory.parseString(
|
||||||
"""
|
"""
|
||||||
akka.persistence.journal.plugin = "my.journal.plugin"
|
akka.persistence.journal.plugin = "my.journal.plugin"
|
||||||
""")
|
"""))
|
||||||
}
|
|
||||||
//#journal-tck-scala
|
//#journal-tck-scala
|
||||||
}
|
}
|
||||||
new AnyRef {
|
new AnyRef {
|
||||||
import akka.persistence.snapshot.SnapshotStoreSpec
|
import akka.persistence.snapshot.SnapshotStoreSpec
|
||||||
|
|
||||||
//#snapshot-store-tck-scala
|
//#snapshot-store-tck-scala
|
||||||
class MySnapshotStoreSpec extends SnapshotStoreSpec {
|
class MySnapshotStoreSpec extends SnapshotStoreSpec(
|
||||||
override val config = ConfigFactory.parseString(
|
config = ConfigFactory.parseString(
|
||||||
"""
|
"""
|
||||||
akka.persistence.snapshot-store.plugin = "my.snapshot-store.plugin"
|
akka.persistence.snapshot-store.plugin = "my.snapshot-store.plugin"
|
||||||
""")
|
"""))
|
||||||
}
|
|
||||||
//#snapshot-store-tck-scala
|
//#snapshot-store-tck-scala
|
||||||
}
|
}
|
||||||
new AnyRef {
|
new AnyRef {
|
||||||
|
|
@ -172,11 +170,11 @@ object PersistenceTCKDoc {
|
||||||
import org.iq80.leveldb.util.FileUtils
|
import org.iq80.leveldb.util.FileUtils
|
||||||
|
|
||||||
//#journal-tck-before-after-scala
|
//#journal-tck-before-after-scala
|
||||||
class MyJournalSpec extends JournalSpec {
|
class MyJournalSpec extends JournalSpec(
|
||||||
override val config = ConfigFactory.parseString(
|
config = ConfigFactory.parseString(
|
||||||
"""
|
"""
|
||||||
akka.persistence.journal.plugin = "my.journal.plugin"
|
akka.persistence.journal.plugin = "my.journal.plugin"
|
||||||
""")
|
""")) {
|
||||||
|
|
||||||
val storageLocations = List(
|
val storageLocations = List(
|
||||||
new File(system.settings.config.getString("akka.persistence.journal.leveldb.dir")),
|
new File(system.settings.config.getString("akka.persistence.journal.leveldb.dir")),
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import com.typesafe.config._
|
||||||
|
|
||||||
import org.scalatest._
|
import org.scalatest._
|
||||||
|
|
||||||
trait PluginSpec extends TestKitBase with WordSpecLike with Matchers with BeforeAndAfterAll with BeforeAndAfterEach {
|
abstract class PluginSpec(val config: Config) extends TestKitBase with WordSpecLike with Matchers with BeforeAndAfterAll with BeforeAndAfterEach {
|
||||||
private val counter = new AtomicInteger(0)
|
private val counter = new AtomicInteger(0)
|
||||||
|
|
||||||
private var _extension: Persistence = _
|
private var _extension: Persistence = _
|
||||||
|
|
@ -21,17 +21,15 @@ trait PluginSpec extends TestKitBase with WordSpecLike with Matchers with Before
|
||||||
// this is akka-persistence internals and journals themselfes don't really care
|
// this is akka-persistence internals and journals themselfes don't really care
|
||||||
protected val actorInstanceId = 1
|
protected val actorInstanceId = 1
|
||||||
|
|
||||||
override protected def beforeEach(): Unit = {
|
override protected def beforeEach(): Unit =
|
||||||
_pid = s"p-${counter.incrementAndGet()}"
|
_pid = s"p-${counter.incrementAndGet()}"
|
||||||
}
|
|
||||||
override protected def beforeAll(): Unit =
|
override protected def beforeAll(): Unit =
|
||||||
_extension = Persistence(system)
|
_extension = Persistence(system)
|
||||||
|
|
||||||
override protected def afterAll(): Unit =
|
override protected def afterAll(): Unit =
|
||||||
shutdown(system)
|
shutdown(system)
|
||||||
|
|
||||||
val config: Config
|
|
||||||
|
|
||||||
def extension: Persistence =
|
def extension: Persistence =
|
||||||
_extension
|
_extension
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import org.scalatest.junit.JUnitRunner
|
||||||
* @param config configures the Journal plugin to be tested
|
* @param config configures the Journal plugin to be tested
|
||||||
*/
|
*/
|
||||||
@RunWith(classOf[JUnitRunner])
|
@RunWith(classOf[JUnitRunner])
|
||||||
class JavaJournalPerfSpec(val config: Config) extends JournalSpec with JournalPerfSpec {
|
class JavaJournalPerfSpec(config: Config) extends JournalPerfSpec(config) {
|
||||||
override protected def info: Informer = new Informer {
|
override protected def info: Informer = new Informer {
|
||||||
override def apply(message: String, payload: Option[Any]): Unit = System.out.println(message)
|
override def apply(message: String, payload: Option[Any]): Unit = System.out.println(message)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,4 @@ import org.scalatest.junit.JUnitRunner
|
||||||
* @param config configures the Journal plugin to be tested
|
* @param config configures the Journal plugin to be tested
|
||||||
*/
|
*/
|
||||||
@RunWith(classOf[JUnitRunner])
|
@RunWith(classOf[JUnitRunner])
|
||||||
class JavaJournalSpec(val config: Config) extends JournalSpec
|
class JavaJournalSpec(config: Config) extends JournalSpec(config)
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,4 @@ import org.scalatest.junit.JUnitRunner
|
||||||
* @see [[akka.persistence.snapshot.SnapshotStoreSpec]]
|
* @see [[akka.persistence.snapshot.SnapshotStoreSpec]]
|
||||||
*/
|
*/
|
||||||
@RunWith(classOf[JUnitRunner])
|
@RunWith(classOf[JUnitRunner])
|
||||||
class JavaSnapshotStoreSpec(val config: Config) extends SnapshotStoreSpec
|
class JavaSnapshotStoreSpec(config: Config) extends SnapshotStoreSpec(config)
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ import akka.actor.{ ActorLogging, ActorRef, Props }
|
||||||
import akka.persistence.journal.JournalPerfSpec.{ BenchActor, Cmd, ResetCounter }
|
import akka.persistence.journal.JournalPerfSpec.{ BenchActor, Cmd, ResetCounter }
|
||||||
import akka.persistence.{ PersistentActor, PluginSpec }
|
import akka.persistence.{ PersistentActor, PluginSpec }
|
||||||
import akka.testkit.TestProbe
|
import akka.testkit.TestProbe
|
||||||
|
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
import com.typesafe.config.Config
|
||||||
|
|
||||||
object JournalPerfSpec {
|
object JournalPerfSpec {
|
||||||
class BenchActor(override val persistenceId: String, replyTo: ActorRef, replyAfter: Int) extends PersistentActor
|
class BenchActor(override val persistenceId: String, replyTo: ActorRef, replyAfter: Int) extends PersistentActor
|
||||||
|
|
@ -75,8 +75,7 @@ object JournalPerfSpec {
|
||||||
*
|
*
|
||||||
* @see [[akka.persistence.journal.JournalSpec]]
|
* @see [[akka.persistence.journal.JournalSpec]]
|
||||||
*/
|
*/
|
||||||
trait JournalPerfSpec extends PluginSpec {
|
abstract class JournalPerfSpec(config: Config) extends JournalSpec(config) {
|
||||||
this: JournalSpec ⇒
|
|
||||||
|
|
||||||
private val testProbe = TestProbe()
|
private val testProbe = TestProbe()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ object JournalSpec {
|
||||||
* @see [[akka.persistence.journal.JournalPerfSpec]]
|
* @see [[akka.persistence.journal.JournalPerfSpec]]
|
||||||
* @see [[akka.persistence.japi.journal.JavaJournalPerfSpec]]
|
* @see [[akka.persistence.japi.journal.JavaJournalPerfSpec]]
|
||||||
*/
|
*/
|
||||||
trait JournalSpec extends PluginSpec {
|
abstract class JournalSpec(config: Config) extends PluginSpec(config) {
|
||||||
import JournalSpec._
|
|
||||||
|
|
||||||
implicit lazy val system: ActorSystem = ActorSystem("JournalSpec", config.withFallback(JournalSpec.config))
|
implicit lazy val system: ActorSystem = ActorSystem("JournalSpec", config.withFallback(JournalSpec.config))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
package akka.persistence.snapshot
|
package akka.persistence.snapshot
|
||||||
|
|
||||||
import scala.collection.immutable.Seq
|
import scala.collection.immutable.Seq
|
||||||
|
|
||||||
import akka.actor._
|
import akka.actor._
|
||||||
import akka.persistence._
|
import akka.persistence._
|
||||||
import akka.persistence.SnapshotProtocol._
|
import akka.persistence.SnapshotProtocol._
|
||||||
import akka.testkit.TestProbe
|
import akka.testkit.TestProbe
|
||||||
|
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
|
import com.typesafe.config.Config
|
||||||
|
|
||||||
object SnapshotStoreSpec {
|
object SnapshotStoreSpec {
|
||||||
val config = ConfigFactory.parseString("akka.persistence.publish-plugin-commands = on")
|
val config = ConfigFactory.parseString("akka.persistence.publish-plugin-commands = on")
|
||||||
|
|
@ -24,7 +23,7 @@ object SnapshotStoreSpec {
|
||||||
*
|
*
|
||||||
* @see [[akka.persistence.japi.snapshot.JavaSnapshotStoreSpec]]
|
* @see [[akka.persistence.japi.snapshot.JavaSnapshotStoreSpec]]
|
||||||
*/
|
*/
|
||||||
trait SnapshotStoreSpec extends PluginSpec {
|
abstract class SnapshotStoreSpec(config: Config) extends PluginSpec(config) {
|
||||||
implicit lazy val system = ActorSystem("SnapshotStoreSpec", config.withFallback(SnapshotStoreSpec.config))
|
implicit lazy val system = ActorSystem("SnapshotStoreSpec", config.withFallback(SnapshotStoreSpec.config))
|
||||||
|
|
||||||
private var senderProbe: TestProbe = _
|
private var senderProbe: TestProbe = _
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package akka.persistence
|
package akka.persistence
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
|
import org.scalatest.BeforeAndAfterAll
|
||||||
|
|
||||||
trait PluginCleanup extends PluginSpec {
|
trait PluginCleanup extends BeforeAndAfterAll { _: PluginSpec ⇒
|
||||||
val storageLocations = List(
|
val storageLocations = List(
|
||||||
"akka.persistence.journal.leveldb.dir",
|
"akka.persistence.journal.leveldb.dir",
|
||||||
"akka.persistence.snapshot-store.local.dir").map(s ⇒ new File(system.settings.config.getString(s)))
|
"akka.persistence.snapshot-store.local.dir").map(s ⇒ new File(system.settings.config.getString(s)))
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package akka.persistence.journal.leveldb
|
||||||
import akka.persistence.journal.JournalSpec
|
import akka.persistence.journal.JournalSpec
|
||||||
import akka.persistence.{ PersistenceSpec, PluginCleanup }
|
import akka.persistence.{ PersistenceSpec, PluginCleanup }
|
||||||
|
|
||||||
class LeveldbJournalJavaSpec extends JournalSpec with PluginCleanup {
|
class LeveldbJournalJavaSpec extends JournalSpec(
|
||||||
lazy val config = PersistenceSpec.config(
|
config = PersistenceSpec.config(
|
||||||
"leveldb",
|
"leveldb",
|
||||||
"LeveldbJournalJavaSpec",
|
"LeveldbJournalJavaSpec",
|
||||||
extraConfig = Some("akka.persistence.journal.leveldb.native = off"))
|
extraConfig = Some("akka.persistence.journal.leveldb.native = off")))
|
||||||
}
|
with PluginCleanup
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ import akka.persistence.{ PersistenceSpec, PluginCleanup }
|
||||||
import org.scalatest.DoNotDiscover
|
import org.scalatest.DoNotDiscover
|
||||||
|
|
||||||
@DoNotDiscover // because only checking that compilation is OK with JournalPerfSpec
|
@DoNotDiscover // because only checking that compilation is OK with JournalPerfSpec
|
||||||
class LeveldbJournalNativePerfSpec extends JournalSpec with JournalPerfSpec with PluginCleanup {
|
class LeveldbJournalNativePerfSpec extends JournalPerfSpec(
|
||||||
lazy val config = PersistenceSpec.config(
|
config = PersistenceSpec.config(
|
||||||
"leveldb",
|
"leveldb",
|
||||||
"LeveldbJournalNativePerfSpec",
|
"LeveldbJournalNativePerfSpec",
|
||||||
extraConfig = Some("akka.persistence.journal.leveldb.native = on"))
|
extraConfig = Some("akka.persistence.journal.leveldb.native = on")))
|
||||||
}
|
with PluginCleanup
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,9 @@ package akka.persistence.journal.leveldb
|
||||||
import akka.persistence.journal.JournalSpec
|
import akka.persistence.journal.JournalSpec
|
||||||
import akka.persistence.{ PersistenceSpec, PluginCleanup }
|
import akka.persistence.{ PersistenceSpec, PluginCleanup }
|
||||||
|
|
||||||
class LeveldbJournalNativeSpec extends JournalSpec with PluginCleanup {
|
class LeveldbJournalNativeSpec extends JournalSpec(
|
||||||
lazy val config = PersistenceSpec.config(
|
config = PersistenceSpec.config(
|
||||||
"leveldb",
|
"leveldb",
|
||||||
"LeveldbJournalNativeSpec",
|
"LeveldbJournalNativeSpec",
|
||||||
extraConfig = Some("akka.persistence.journal.leveldb.native = on"))
|
extraConfig = Some("akka.persistence.journal.leveldb.native = on")))
|
||||||
|
with PluginCleanup
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,11 @@ import com.typesafe.config.ConfigFactory
|
||||||
import akka.persistence.PluginCleanup
|
import akka.persistence.PluginCleanup
|
||||||
import akka.persistence.snapshot.SnapshotStoreSpec
|
import akka.persistence.snapshot.SnapshotStoreSpec
|
||||||
|
|
||||||
class LocalSnapshotStoreSpec extends SnapshotStoreSpec with PluginCleanup {
|
class LocalSnapshotStoreSpec extends SnapshotStoreSpec(
|
||||||
lazy val config = ConfigFactory.parseString(
|
config = ConfigFactory.parseString(
|
||||||
"""
|
"""
|
||||||
akka.test.timefactor = 3
|
akka.test.timefactor = 3
|
||||||
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
|
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
|
||||||
akka.persistence.snapshot-store.local.dir = "target/snapshots"
|
akka.persistence.snapshot-store.local.dir = "target/snapshots"
|
||||||
""")
|
"""))
|
||||||
|
with PluginCleanup
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue