From 03d9b9f1f6d35a03448a3a77fd36da4137ef4a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Mon, 18 Aug 2014 14:15:44 +0200 Subject: [PATCH] add the ability to use inmem journal using the fluent builder --- pom.xml | 8 +++++++ .../akka/junit/ActorSystemRuleBuilder.java | 23 ++++++++++++++++++- .../junit/ActorSystemRuleBuilderTest.java | 7 ++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a69aca6..6da7467 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ 4.11 2.3.4 1.7.7 + 0.2.1 @@ -35,6 +36,13 @@ junit ${junit.version} + + com.github.michaelpisula + akka-persistence-inmemory_2.10 + ${akka-persistence-inmemory.version} + runtime + true + com.typesafe.akka akka-actor_2.10 diff --git a/src/main/java/org/zapodot/akka/junit/ActorSystemRuleBuilder.java b/src/main/java/org/zapodot/akka/junit/ActorSystemRuleBuilder.java index 8714728..efafd08 100644 --- a/src/main/java/org/zapodot/akka/junit/ActorSystemRuleBuilder.java +++ b/src/main/java/org/zapodot/akka/junit/ActorSystemRuleBuilder.java @@ -60,6 +60,7 @@ public ActorSystemRuleBuilder enableEventLogging() { /** * Enables debug logging of receive events for all actors, i.e sets "akka.actor.debug.receive = on" + * * @return */ public ActorSystemRuleBuilder enableReceiveDebugLogging() { @@ -69,6 +70,7 @@ public ActorSystemRuleBuilder enableReceiveDebugLogging() { /** * Enables lifecycle debug logging by setting "akka.actor.debug.lifecycle = on" + * * @return */ public ActorSystemRuleBuilder enableLifecycleDebugLogging() { @@ -78,6 +80,7 @@ public ActorSystemRuleBuilder enableLifecycleDebugLogging() { /** * Sets the global log level for Akka to "debug", i.e sets "akka.loglevel= debug" + * * @return */ public ActorSystemRuleBuilder setEventLogLevelDebug() { @@ -85,6 +88,24 @@ public ActorSystemRuleBuilder setEventLogLevelDebug() { return this; } + /** + * Enables the Inmemory Journal which is very useful for testing event sourced actors + * + * @return + * @see InMemory journal project page + */ + public ActorSystemRuleBuilder enableInmemoryJournal() { + try { + getClass().getClassLoader().loadClass("akka.persistence.journal.inmemory.InMemoryJournal"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException( + "Could not find the InMemoryJournal class on the classpath, did you add the akka-persistence-inmemory dependency?", + e); + } + setOrAddConfiguration(ConfigFactory.parseString("akka.persistence.journal.plugin = \"in-memory-journal\"")); + return this; + } + private void setOrAddConfiguration(final Config config) { if (this.config == null) { this.config = config; @@ -103,7 +124,7 @@ public ActorSystemRuleBuilder setConfigFromString(final String configString) { } Config currentConfig() { - if(this.config == null) { + if (this.config == null) { return ConfigFactory.empty(); } else { return ConfigFactory.empty().withFallback(config); diff --git a/src/test/java/org/zapodot/akka/junit/ActorSystemRuleBuilderTest.java b/src/test/java/org/zapodot/akka/junit/ActorSystemRuleBuilderTest.java index dcf6fa1..bb06230 100644 --- a/src/test/java/org/zapodot/akka/junit/ActorSystemRuleBuilderTest.java +++ b/src/test/java/org/zapodot/akka/junit/ActorSystemRuleBuilderTest.java @@ -73,4 +73,11 @@ public void testEnableLifecycleAndReceiveDebugLogging() throws Exception { assertEquals("on", config.getString("akka.actor.debug.receive")); } + + @Test + public void testEnableInMemoryJournal() throws Exception { + + final Config config = ActorSystemRule.builder().enableInmemoryJournal().currentConfig(); + assertEquals("in-memory-journal", config.getString("akka.persistence.journal.plugin")); + } } \ No newline at end of file