I'm just getting my feet wet with Akka. I'm trying to write a JUNit test using the JavaTestKit from this Maven dependency:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.11</artifactId>
<version>2.3.12</version>
</dependency>
Even a JavaTestKit instance that does nothing will throw a fatal exception, so I suspect there's a configuration issue. This class will reproduce the problem:
import akka.actor.ActorSystem;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import akka.testkit.JavaTestKit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class GameTest {
static ActorSystem system;
static LoggingAdapter log;
@BeforeClass
public static void setup() {
system = ActorSystem.create();
log = Logging.getLogger(system, GameTest.class);
}
@AfterClass
public static void teardown() {
JavaTestKit.shutdownActorSystem(system);
system = null;
}
@Test
public void gutterGameTest() {
log.info("gutterGameTest started");
new JavaTestKit(system) {{
// even when empty, the exception is thrown during initialization
}};
}
}
Here's the exception:
[ERROR] [08/20/2015 07:55:10.614] [default-akka.actor.default-dispatcher-4] [ActorSystem(default)] Uncaught error from thread [default-akka.actor.default-dispatcher-4] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
java.lang.NoSuchMethodError: scala.Predef$.ArrowAssoc(Ljava/lang/Object;)Ljava/lang/Object;
at akka.testkit.CallingThreadDispatcherQueues.registerQueue(CallingThreadDispatcher.scala:64)
at akka.testkit.CallingThreadMailbox$$anon$1.initialValue(CallingThreadDispatcher.scala:318)
at akka.testkit.CallingThreadMailbox$$anon$1.initialValue(CallingThreadDispatcher.scala:315)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
at java.lang.ThreadLocal.get(ThreadLocal.java:170)
...
I'm using the default configuration. Is there something else I need to set up for JavaTestKit to work as intended?
I figured out the issue. It had to do with an incompatible combination of the Akka and Testkit libraries (Scala 2.10 vs 2.11). The following Maven dependencies worked as expected:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.10</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.5</version>
</dependency>
来源:https://stackoverflow.com/questions/32120369/uncaught-error-from-default-dispatcher-causes-fatal-error-with-javatestkit