+per #13815 akka-persistence-tck based on @krasserm's work

Original here: https://github.com/krasserm/akka-persistence-testkit

New features:
* merged martin's tests
* usable from java (junit 4)
* simple bench test, which helps checking if ordering is perserved under
  bigger workloads and simple perf checking
* does NOT include tests for already deprecated features (deleteMessages)
* docs

Resolves #13815

Conflicts:
	project/AkkaBuild.scala
This commit is contained in:
Konrad 'ktoso' Malawski 2014-07-08 18:30:15 +02:00
parent 7ca3a9699e
commit 90bc347607
22 changed files with 965 additions and 186 deletions

View file

@ -5,17 +5,27 @@
package docs.persistence;
//#plugin-imports
import akka.actor.UntypedActor;
import scala.concurrent.Future;
import akka.actor.*;
import akka.japi.Option;
import akka.japi.Procedure;
import akka.persistence.*;
import akka.persistence.journal.japi.*;
import akka.persistence.snapshot.japi.*;
//#plugin-imports
import akka.actor.*;
import akka.persistence.japi.journal.JavaJournalSpec;
import akka.persistence.japi.snapshot.JavaSnapshotStoreSpec;
import akka.persistence.journal.japi.AsyncWriteJournal;
import akka.persistence.journal.leveldb.SharedLeveldbJournal;
import akka.persistence.journal.leveldb.SharedLeveldbStore;
import akka.persistence.snapshot.japi.SnapshotStore;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.iq80.leveldb.util.FileUtils;
import scala.concurrent.Future;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
//#plugin-imports
public class PersistencePluginDocTest {
@ -106,4 +116,68 @@ public class PersistencePluginDocTest {
return null;
}
}
static Object o2 = new Object() {
//#journal-tck-java
class MyJournalSpecTest extends JavaJournalSpec {
public MyJournalSpecTest() {
super(ConfigFactory.parseString(
"persistence.journal.plugin = " +
"\"akka.persistence.journal.leveldb-shared\""));
}
}
//#journal-tck-java
};
static Object o3 = new Object() {
//#snapshot-store-tck-java
class MySnapshotStoreTest extends JavaSnapshotStoreSpec {
public MySnapshotStoreTest() {
super(ConfigFactory.parseString(
"akka.persistence.snapshot-store.plugin = " +
"\"akka.persistence.snapshot-store.local\""));
}
}
//#snapshot-store-tck-java
};
static Object o4 = new Object() {
//#journal-tck-before-after-java
class MyJournalSpecTest extends JavaJournalSpec {
List<File> storageLocations = new ArrayList<File>();
public MyJournalSpecTest() {
super(ConfigFactory.parseString(
"persistence.journal.plugin = " +
"\"akka.persistence.journal.leveldb-shared\""));
Config config = system().settings().config();
storageLocations.add(new File(
config.getString("akka.persistence.journal.leveldb.dir")));
storageLocations.add(new File(
config.getString("akka.persistence.snapshot-store.local.dir")));
}
@Override
public void beforeAll() {
for (File storageLocation : storageLocations) {
FileUtils.deleteRecursively(storageLocation);
}
super.beforeAll();
}
@Override
public void afterAll() {
super.afterAll();
for (File storageLocation : storageLocations) {
FileUtils.deleteRecursively(storageLocation);
}
}
}
//#journal-tck-before-after-java
};
}

View file

@ -498,6 +498,40 @@ A snapshot store plugin can be activated with the following minimal configuratio
The specified plugin ``class`` must have a no-arg constructor. The ``plugin-dispatcher`` is the dispatcher
used for the plugin actor. If not specified, it defaults to ``akka.persistence.dispatchers.default-plugin-dispatcher``.
Plugin TCK
----------
In order to help developers build correct and high quality storage plugins, we provide an Technology Compatibility Kit (`TCK <http://en.wikipedia.org/wiki/Technology_Compatibility_Kit>`_ for short).
The TCK is usable from Java as well as Scala projects, for Java you need to include the akka-persistence-tck-experimental dependency::
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-persistence-tck-experimental_${scala.version}</artifactId>
<version>2.3.5</version>
<scope>test</scope>
</dependency>
To include the Journal TCK tests in your test suite simply extend the provided ``JavaJournalSpec``:
.. includecode:: ./code/docs/persistence/PersistencePluginDocTest.java#journal-tck-java
We also provide a simple benchmarking class ``JavaJournalPerfSpec`` which includes all the tests that ``JavaJournalSpec``
has, and also performs some longer operations on the Journal while printing it's performance stats. While it is NOT aimed
to provide a proper benchmarking environment it can be used to get a rough feel about your journals performance in the most
typical scenarios.
In order to include the ``SnapshotStore`` TCK tests in your test suite simply extend the ``SnapshotStoreSpec:
.. includecode:: ./code/docs/persistence/PersistencePluginDocTest.java#snapshot-store-tck-java
In case your plugin requires some setting up (starting a mock database, removing temporary files etc.) you can override the
``beforeAll`` and ``afterAll`` methods to hook into the tests lifecycle:
.. includecode:: ./code/docs/persistence/PersistencePluginDocTest.java#journal-tck-before-after-java
We *highly recommend* including these specifications in your test suite, as they cover a broad range of cases you
might have otherwise forgotten to test for when writing a plugin from scratch.
Pre-packaged plugins
====================