默认调度程序中未捕获的错误会导致JavaTestKit出现致命错误

时间:2015-08-20 14:01:46

标签: akka akka-testkit

我刚刚和Akka擦肩而过。我正在尝试使用此Maven依赖项中的JavaTestKit编写JUNit测试:

    <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>

即使是没有做任何事情的JavaTestKit实例也会引发致命异常,所以我怀疑存在配置问题。这堂课将重现这个问题:

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
      }};
  }
}

这是例外:

[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)
    ...

我使用默认配置。我需要为JavaTestKit设置其他工作吗?

1 个答案:

答案 0 :(得分:2)

我想出了这个问题。它与Akka和Testkit库的不兼容组合有关(Scala 2.10 vs 2.11)。以下Maven依赖项按预期工作:

UndoOperation()