2013-10-09 13:11:53 +02:00
|
|
|
/**
|
2015-03-07 22:58:48 -08:00
|
|
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
2013-10-09 13:11:53 +02:00
|
|
|
*/
|
|
|
|
|
|
2013-10-08 11:46:02 +02:00
|
|
|
package docs.persistence
|
|
|
|
|
|
2015-06-23 21:01:36 +02:00
|
|
|
import scala.collection.immutable
|
2015-06-17 01:23:18 +02:00
|
|
|
import akka.actor.Actor.Receive
|
2013-10-08 11:46:02 +02:00
|
|
|
import akka.actor.ActorSystem
|
2014-07-08 18:30:15 +02:00
|
|
|
import akka.testkit.TestKit
|
|
|
|
|
import com.typesafe.config._
|
|
|
|
|
import org.scalatest.WordSpec
|
|
|
|
|
import scala.collection.immutable.Seq
|
|
|
|
|
import scala.concurrent.Future
|
2015-06-23 21:01:36 +02:00
|
|
|
import scala.util.Try
|
2014-07-08 18:30:15 +02:00
|
|
|
import scala.concurrent.duration._
|
2014-12-08 11:02:14 +01:00
|
|
|
|
|
|
|
|
//#plugin-imports
|
|
|
|
|
import akka.persistence._
|
|
|
|
|
import akka.persistence.journal._
|
|
|
|
|
import akka.persistence.snapshot._
|
|
|
|
|
|
2013-10-08 11:46:02 +02:00
|
|
|
//#plugin-imports
|
|
|
|
|
|
|
|
|
|
object PersistencePluginDocSpec {
|
|
|
|
|
val config =
|
|
|
|
|
"""
|
2014-01-17 06:58:25 +01:00
|
|
|
//#max-message-batch-size
|
|
|
|
|
akka.persistence.journal.max-message-batch-size = 200
|
|
|
|
|
//#max-message-batch-size
|
2013-10-08 11:46:02 +02:00
|
|
|
//#journal-config
|
|
|
|
|
akka.persistence.journal.leveldb.dir = "target/journal"
|
|
|
|
|
//#journal-config
|
|
|
|
|
//#snapshot-config
|
|
|
|
|
akka.persistence.snapshot-store.local.dir = "target/snapshots"
|
|
|
|
|
//#snapshot-config
|
2013-12-06 12:48:44 +01:00
|
|
|
//#native-config
|
|
|
|
|
akka.persistence.journal.leveldb.native = off
|
|
|
|
|
//#native-config
|
2013-10-08 11:46:02 +02:00
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PersistencePluginDocSpec extends WordSpec {
|
|
|
|
|
new AnyRef {
|
|
|
|
|
val providerConfig =
|
|
|
|
|
"""
|
|
|
|
|
//#journal-plugin-config
|
|
|
|
|
# Path to the journal plugin to be used
|
|
|
|
|
akka.persistence.journal.plugin = "my-journal"
|
|
|
|
|
|
|
|
|
|
# My custom journal plugin
|
|
|
|
|
my-journal {
|
|
|
|
|
# Class name of the plugin.
|
|
|
|
|
class = "docs.persistence.MyJournal"
|
|
|
|
|
# Dispatcher for the plugin actor.
|
|
|
|
|
plugin-dispatcher = "akka.actor.default-dispatcher"
|
|
|
|
|
}
|
|
|
|
|
//#journal-plugin-config
|
|
|
|
|
|
|
|
|
|
//#snapshot-store-plugin-config
|
|
|
|
|
# Path to the snapshot store plugin to be used
|
|
|
|
|
akka.persistence.snapshot-store.plugin = "my-snapshot-store"
|
|
|
|
|
|
|
|
|
|
# My custom snapshot store plugin
|
|
|
|
|
my-snapshot-store {
|
|
|
|
|
# Class name of the plugin.
|
|
|
|
|
class = "docs.persistence.MySnapshotStore"
|
|
|
|
|
# Dispatcher for the plugin actor.
|
|
|
|
|
plugin-dispatcher = "akka.persistence.dispatchers.default-plugin-dispatcher"
|
|
|
|
|
}
|
|
|
|
|
//#snapshot-store-plugin-config
|
|
|
|
|
"""
|
|
|
|
|
|
2014-01-17 15:52:20 +01:00
|
|
|
val system = ActorSystem("PersistencePluginDocSpec", ConfigFactory.parseString(providerConfig).withFallback(ConfigFactory.parseString(PersistencePluginDocSpec.config)))
|
|
|
|
|
try {
|
|
|
|
|
Persistence(system)
|
|
|
|
|
} finally {
|
|
|
|
|
TestKit.shutdownActorSystem(system, 10.seconds, false)
|
|
|
|
|
}
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 12:02:29 +01:00
|
|
|
object SharedLeveldbPluginDocSpec {
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbJournal
|
|
|
|
|
|
|
|
|
|
val config =
|
|
|
|
|
"""
|
|
|
|
|
//#shared-journal-config
|
|
|
|
|
akka.persistence.journal.plugin = "akka.persistence.journal.leveldb-shared"
|
|
|
|
|
//#shared-journal-config
|
2013-12-06 12:48:44 +01:00
|
|
|
//#shared-store-native-config
|
|
|
|
|
akka.persistence.journal.leveldb-shared.store.native = off
|
|
|
|
|
//#shared-store-native-config
|
2013-11-25 12:02:29 +01:00
|
|
|
//#shared-store-config
|
|
|
|
|
akka.persistence.journal.leveldb-shared.store.dir = "target/shared"
|
|
|
|
|
//#shared-store-config
|
2015-05-29 18:20:51 +02:00
|
|
|
//#event-adapter-config
|
|
|
|
|
akka.persistence.journal.leveldb-shared.adapter = "com.example.MyAdapter"
|
|
|
|
|
//#event-adapter-config
|
2013-11-25 12:02:29 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
trait SharedStoreUsage extends Actor {
|
|
|
|
|
override def preStart(): Unit = {
|
|
|
|
|
context.actorSelection("akka.tcp://example@127.0.0.1:2552/user/store") ! Identify(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def receive = {
|
2013-12-03 16:34:26 +01:00
|
|
|
case ActorIdentity(1, Some(store)) =>
|
2013-11-25 12:02:29 +01:00
|
|
|
SharedLeveldbJournal.setStore(store, context.system)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait SharedLeveldbPluginDocSpec {
|
|
|
|
|
val system: ActorSystem
|
|
|
|
|
|
|
|
|
|
new AnyRef {
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbStore
|
|
|
|
|
|
|
|
|
|
val store = system.actorOf(Props[SharedLeveldbStore], "store")
|
|
|
|
|
//#shared-store-creation
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 11:46:02 +02:00
|
|
|
class MyJournal extends AsyncWriteJournal {
|
2015-06-23 21:01:36 +02:00
|
|
|
def asyncWriteMessages(messages: immutable.Seq[AtomicWrite]): Future[immutable.Seq[Try[Unit]]] = ???
|
2015-06-25 07:44:52 +02:00
|
|
|
def asyncDeleteMessagesTo(persistenceId: String, toSequenceNr: Long): Future[Unit] = ???
|
2014-12-08 11:02:14 +01:00
|
|
|
def asyncReplayMessages(persistenceId: String, fromSequenceNr: Long,
|
|
|
|
|
toSequenceNr: Long, max: Long)(
|
|
|
|
|
replayCallback: (PersistentRepr) => Unit): Future[Unit] = ???
|
|
|
|
|
def asyncReadHighestSequenceNr(persistenceId: String,
|
|
|
|
|
fromSequenceNr: Long): Future[Long] = ???
|
2015-06-17 01:23:18 +02:00
|
|
|
|
|
|
|
|
// optionally override:
|
|
|
|
|
override def receivePluginInternal: Receive = super.receivePluginInternal
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MySnapshotStore extends SnapshotStore {
|
2014-12-08 11:02:14 +01:00
|
|
|
def loadAsync(persistenceId: String,
|
|
|
|
|
criteria: SnapshotSelectionCriteria): Future[Option[SelectedSnapshot]] = ???
|
2013-10-08 11:46:02 +02:00
|
|
|
def saveAsync(metadata: SnapshotMetadata, snapshot: Any): Future[Unit] = ???
|
2015-06-03 15:56:00 +02:00
|
|
|
def deleteAsync(metadata: SnapshotMetadata): Future[Unit] = ???
|
|
|
|
|
def deleteAsync(persistenceId: String, criteria: SnapshotSelectionCriteria): Future[Unit] = ???
|
2015-06-17 01:23:18 +02:00
|
|
|
|
|
|
|
|
// optionally override:
|
|
|
|
|
override def receivePluginInternal: Receive = super.receivePluginInternal
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
2014-07-08 18:30:15 +02:00
|
|
|
|
|
|
|
|
object PersistenceTCKDoc {
|
|
|
|
|
new AnyRef {
|
|
|
|
|
import akka.persistence.journal.JournalSpec
|
|
|
|
|
|
|
|
|
|
//#journal-tck-scala
|
2015-05-06 14:20:38 +02:00
|
|
|
class MyJournalSpec extends JournalSpec(
|
|
|
|
|
config = ConfigFactory.parseString(
|
2014-07-08 18:30:15 +02:00
|
|
|
"""
|
2014-12-08 11:02:14 +01:00
|
|
|
akka.persistence.journal.plugin = "my.journal.plugin"
|
2015-05-06 14:20:38 +02:00
|
|
|
"""))
|
2014-07-08 18:30:15 +02:00
|
|
|
//#journal-tck-scala
|
|
|
|
|
}
|
|
|
|
|
new AnyRef {
|
|
|
|
|
import akka.persistence.snapshot.SnapshotStoreSpec
|
|
|
|
|
|
|
|
|
|
//#snapshot-store-tck-scala
|
2015-05-06 14:20:38 +02:00
|
|
|
class MySnapshotStoreSpec extends SnapshotStoreSpec(
|
|
|
|
|
config = ConfigFactory.parseString(
|
2014-07-08 18:30:15 +02:00
|
|
|
"""
|
2014-12-08 11:02:14 +01:00
|
|
|
akka.persistence.snapshot-store.plugin = "my.snapshot-store.plugin"
|
2015-05-06 14:20:38 +02:00
|
|
|
"""))
|
2014-07-08 18:30:15 +02:00
|
|
|
//#snapshot-store-tck-scala
|
|
|
|
|
}
|
|
|
|
|
new AnyRef {
|
|
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
|
|
import akka.persistence.journal.JournalSpec
|
|
|
|
|
import org.iq80.leveldb.util.FileUtils
|
|
|
|
|
|
|
|
|
|
//#journal-tck-before-after-scala
|
2015-05-06 14:20:38 +02:00
|
|
|
class MyJournalSpec extends JournalSpec(
|
|
|
|
|
config = ConfigFactory.parseString(
|
2014-07-08 18:30:15 +02:00
|
|
|
"""
|
2014-12-08 11:02:14 +01:00
|
|
|
akka.persistence.journal.plugin = "my.journal.plugin"
|
2015-05-06 14:20:38 +02:00
|
|
|
""")) {
|
2014-07-08 18:30:15 +02:00
|
|
|
|
|
|
|
|
val storageLocations = List(
|
|
|
|
|
new File(system.settings.config.getString("akka.persistence.journal.leveldb.dir")),
|
|
|
|
|
new File(config.getString("akka.persistence.snapshot-store.local.dir")))
|
|
|
|
|
|
|
|
|
|
override def beforeAll() {
|
|
|
|
|
super.beforeAll()
|
|
|
|
|
storageLocations foreach FileUtils.deleteRecursively
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def afterAll() {
|
|
|
|
|
storageLocations foreach FileUtils.deleteRecursively
|
|
|
|
|
super.afterAll()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//#journal-tck-before-after-scala
|
|
|
|
|
}
|
2014-12-08 11:02:14 +01:00
|
|
|
}
|