Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
add the ability to use inmem journal using the fluent builder
Browse files Browse the repository at this point in the history
  • Loading branch information
zapodot committed Aug 18, 2014
1 parent 4240951 commit 03d9b9f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@
<junit.version>4.11</junit.version>
<akka.version>2.3.4</akka.version>
<slf4j.version>1.7.7</slf4j.version>
<akka-persistence-inmemory.version>0.2.1</akka-persistence-inmemory.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>com.github.michaelpisula</groupId>
<artifactId>akka-persistence-inmemory_2.10</artifactId>
<version>${akka-persistence-inmemory.version}</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/org/zapodot/akka/junit/ActorSystemRuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -69,6 +70,7 @@ public ActorSystemRuleBuilder enableReceiveDebugLogging() {

/**
* Enables lifecycle debug logging by setting "akka.actor.debug.lifecycle = on"
*
* @return
*/
public ActorSystemRuleBuilder enableLifecycleDebugLogging() {
Expand All @@ -78,13 +80,32 @@ public ActorSystemRuleBuilder enableLifecycleDebugLogging() {

/**
* Sets the global log level for Akka to "debug", i.e sets "akka.loglevel= debug"
*
* @return
*/
public ActorSystemRuleBuilder setEventLogLevelDebug() {
setOrAddConfiguration(ConfigFactory.parseString("akka.loglevel = debug"));
return this;
}

/**
* Enables the Inmemory Journal which is very useful for testing event sourced actors
*
* @return
* @see <a href="https://github.com/michaelpisula/akka-journal-inmemory/">InMemory journal project page</a>
*/
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

0 comments on commit 03d9b9f

Please sign in to comment.