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

Commit

Permalink
Merge branch 'Akka-2.5'
Browse files Browse the repository at this point in the history
Conflicts:
	.travis.yml
  • Loading branch information
zapodot committed Mar 21, 2018
2 parents 2fb2eef + 7ba7fc5 commit eef6a1b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: java
jdk:
- oraclejdk7
- oraclejdk8
after_success:
- mvn clean test jacoco:report coveralls:report
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.zapodot</groupId>
<artifactId>akka-test-junit</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<description>Useful JUnit hooks for testing Akka actors</description>
<name>${project.artifactId}</name>
<url>https://github.com/zapodot/akka-test-junit</url>
<prerequisites>
<maven>3.0.4</maven>
<maven>3.2.0</maven>
</prerequisites>
<developers>
<developer>
Expand Down Expand Up @@ -38,12 +38,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
<akka.version>2.3.15</akka.version>
<slf4j.version>1.7.21</slf4j.version>
<akka.version>2.5.11</akka.version>
<slf4j.version>1.7.25</slf4j.version>
<akka-persistence-inmemory.version>0.2.1</akka-persistence-inmemory.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-javadoc-plugin.version>2.10.2</maven-javadoc-plugin.version>
<nexus-staging-maven-plugin.version>1.6.5</nexus-staging-maven-plugin.version>
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
<maven-source-plugin.version>2.4</maven-source-plugin.version>
<coveralls-maven-plugin.version>3.1.0</coveralls-maven-plugin.version>
<jacoco-maven-plugin.version>0.7.5.201505241946</jacoco-maven-plugin.version>
Expand Down Expand Up @@ -140,8 +140,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -174,7 +174,7 @@
<encoding>UTF-8</encoding>
<links>
<link>http://junit.org/junit4/javadoc/latest/</link>
<link>http://docs.oracle.com/javase/7/docs/api/</link>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
<link>http://doc.akka.io/japi/akka/${akka.version}/</link>
</links>
<locale>en</locale>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/zapodot/akka/junit/ActorSystemRule.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.zapodot.akka.junit;

import akka.actor.ActorSystem;
import akka.testkit.JavaTestKit;
import akka.testkit.javadsl.TestKit;
import org.junit.rules.TestRule;

/**
Expand Down Expand Up @@ -38,10 +38,10 @@ public interface ActorSystemRule extends TestRule {
ActorSystem system();

/**
* Convienience method that provides easy access to a {@link JavaTestKit} instance.
* Convienience method that provides easy access to a {@link TestKit} instance.
*
* @return the {@link JavaTestKit} instance that was created before the test ran
* @return the {@link TestKit} instance that was created before the test ran
*/
JavaTestKit testKit();
TestKit testKit();

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public ActorSystemRuleBuilder enableInmemoryJournal() {
* Allows the developer to tune the shutdown timeout which is the maximum number of seconds to wait while shutting
* down the ActorSystem. Will default to {@link ActorSystemRule#DEFAULT_SHUTDOWN_TIMEOUT} if this method is not called.
*
* @param shutdownTimeoutInSeconds
* @param shutdownTimeoutInSeconds the number of seconds before ActorSystem shutdown will time out
* @return the same builder with the shutdown timeout set
*/
public ActorSystemRuleBuilder withShutdownTimeoutInSeconds(final long shutdownTimeoutInSeconds) {
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/org/zapodot/akka/junit/ActorSystemRuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UnhandledMessage;
import akka.testkit.JavaTestKit;
import akka.testkit.TestActorRef;
import akka.testkit.javadsl.TestKit;
import com.typesafe.config.Config;
import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
Expand All @@ -29,7 +29,7 @@ public class ActorSystemRuleImpl extends ExternalResource implements ActorSystem
private ActorSystem actorSystem;
private Config config = null;
private TestActorRef<ConsumingActor> unhandledMessagesConsumer;
private JavaTestKit javaTestKit;
private TestKit javaTestKit;
private final long shutdownTimeoutSeconds;


Expand Down Expand Up @@ -90,29 +90,26 @@ public ActorSystem system() {
}

@Override
public JavaTestKit testKit() {
public TestKit testKit() {
return javaTestKit;
}

@Override
protected void before() throws Throwable {
protected void before() {
LOGGER.debug("Instantiating ActorSystem \"{}\"", name);
actorSystem = config == null ? ActorSystem.create(name) : ActorSystem.create(name, config);

unhandledMessagesConsumer = TestActorRef.create(actorSystem, Props.create(ConsumingActor.class), "unhandledMessagesConsumer");
actorSystem.eventStream().subscribe(unhandledMessagesConsumer, UnhandledMessage.class);
javaTestKit = new JavaTestKit(actorSystem);
javaTestKit = new TestKit(actorSystem);

}

@Override
protected void after() {

javaTestKit = null;
if (!actorSystem.isTerminated()) {
LOGGER.debug("Shutting down ActorSystem \"{}\"", name);
JavaTestKit.shutdownActorSystem(actorSystem, Duration.apply(shutdownTimeoutSeconds, TimeUnit.SECONDS), true);
}
TestKit.shutdownActorSystem(actorSystem, Duration.apply(shutdownTimeoutSeconds, TimeUnit.SECONDS), true);
actorSystem = null;
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/zapodot/akka/junit/actor/ConsumingActor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.zapodot.akka.junit.actor;

import akka.actor.UntypedActor;
import akka.actor.AbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

Expand All @@ -10,13 +10,19 @@
/**
* A simple consuming actor that stores all messages that was received
*/
public class ConsumingActor extends UntypedActor {
public class ConsumingActor extends AbstractActor {

public List<Object> messagesReceived = new LinkedList<>();
private LoggingAdapter logger = Logging.getLogger(context().system(), self());

@Override
public void onReceive(final Object message) throws Exception {
public Receive createReceive() {
return receiveBuilder()
.matchAny(this::onReceive)
.build();
}

private void onReceive(final Object message) {
logger.debug("Received message \"{}\". Adding it to the list of received messages");

messagesReceived.add(message);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/zapodot/akka/junit/TestKitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.testkit.JavaTestKit;
import akka.testkit.javadsl.TestKit;
import org.junit.Rule;
import org.junit.Test;
import scala.concurrent.duration.FiniteDuration;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void onReceive(final Object message) throws Exception {

@Test
public void testRule() throws Exception {
final JavaTestKit javaTestKit = testKitRule.testKit();
final TestKit javaTestKit = testKitRule.testKit();
final ActorRef testActor = javaTestKit.getTestActor();

final String message = "test";
Expand All @@ -48,7 +48,7 @@ public void testRule() throws Exception {
public void testRuleAsync() throws Exception {
final Props simpleActorProps = Props.create(SimpleActor.class);
final ActorRef simpleActorRef = testKitRule.system().actorOf(simpleActorProps);
final JavaTestKit testProbe = testKitRule.testKit();
final TestKit testProbe = testKitRule.testKit();

final String msg = "Hello AKKA";
simpleActorRef.tell(msg, testProbe.getTestActor());
Expand Down

0 comments on commit eef6a1b

Please sign in to comment.