Giter Club home page Giter Club logo

akka-persistence-mock's Introduction

Build Status codecov.io Maven Central Scaladoc

Akka Persistence Mock

Mock/in-memory implementation of Akka persistence suitable for testing your persistent Actors.
This plugin implements both the Journal as well as the SnapshotStore.

What's this

"Akka persistence enables stateful actors to persist their internal state so that it can be recovered when an actor is started, restarted after a JVM crash or by a supervisor, or migrated in a cluster" /akka persistence (Typesafe)
Whilst the actual persistence mechanism of the Akka platform is generic it allows you to define which storage plugin to use, i.e. where to store the snapshot and journal/transaction data.

This project implements both the Journal and SnapshotStore plugins as in-memory structures. I.e. no data is written/persisted anywhere. This of course means that this implementation is not suitable for production but excellent for testing. There's no dependencies to anything like disc space or external databases meaning that the plugin requires no configuration to be used. It makes it extremely efficient to instantiate and use in testing adding virtually zero overhead.

Guaranteed compliance

This plugin is tested against Typesafes compatibility tests to guarantee its behavior is completely according to specifications.

When to use

When you have persistent actors you need to test for proper behavior.
To properly test your actors you need a storage plugin for the Akka persistence framework to work properly.
It's now you probably want a lightweight in-memory implementation of the persistence plugin.

How to use

Since testing is the primary use case there's a few ways to configure the plugin.
Basically what you need is to add the plugin configuration to the actor system.

akka.persistence.journal.plugin = "dummy-journal"
akka.persistence.snapshot-store.plugin = "dummy-snapshot-store"

dummy-journal {
  class = "org.dmonix.akka.persistence.JournalPlugin"
  plugin-dispatcher = "akka.actor.default-dispatcher"
}

dummy-snapshot-store {
  class = "org.dmonix.akka.persistence.SnapshotStorePlugin"
  plugin-dispatcher = "akka.persistence.dispatchers.default-plugin-dispatcher"
}

One can either add the above configuration to the resources.conf file.
Place the file in src/main/resources or src/test/resources depending on which scope you need.

But if it's for pure test cases Id' suggest to configure the actor system for the testkit.
E.g.

object PersistenceSuite {
  
  def journalId() = "dummy-journal"
  def snapStoreId() = "dummy-snapshot-store"
  
  def config() = ConfigFactory.parseString(
    """akka.loggers = [akka.testkit.TestEventListener] # makes both log-snooping and logging work
         akka.loglevel = "DEBUG"
         akka.persistence.journal.plugin = "dummy-journal"
         akka.persistence.snapshot-store.plugin = "dummy-snapshot-store"
         dummy-journal {
           class = "org.dmonix.akka.persistence.JournalPlugin"
           plugin-dispatcher = "akka.actor.default-dispatcher"
         }
        dummy-snapshot-store {
          class = "org.dmonix.akka.persistence.SnapshotStorePlugin"
          plugin-dispatcher = "akka.persistence.dispatchers.default-plugin-dispatcher"
         }          
         akka.actor.debug.receive = on""")
}

Then use the config for all your test cases.

class ExampleSuite extends TestKit(ActorSystem("ExampleSuite", PersistenceSuite.config))

Check out the Example suite class

LICENSE

Copyright 2015 Peter Nerg.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Download

The binary can be downloaded from Maven Central.

sbt

libraryDependencies += "org.dmonix.akka" % "akka-persistence-mock_2.11" % "1.1.1"
libraryDependencies += "org.dmonix.akka" %% "akka-persistence-mock" % "1.1.1"

Maven

<dependency>
    <groupId>org.dmonix.akka</groupId>
    <artifactId>akka-persistence-mock_2.11</artifactId>
    <version>1.1.1</version>
</dependency>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.