默认调度程序未捕获的错误导致JavaTestKit发生致命错误 [英] Uncaught error from default dispatcher causes fatal error with JavaTestKit

查看:230
本文介绍了默认调度程序未捕获的错误导致JavaTestKit发生致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是和Akka沾湿了。我正在尝试从此Maven依赖关系中使用JavaTestKit编写JUNit测试:

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>

即使JavaTestKit实例不执行任何操作也不会引发致命异常,因此我怀疑存在配置问题。此类将重现该问题:

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

这里是个例外:

[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才能使其按预期工作吗?

I'm using the default configuration. Is there something else I need to set up for JavaTestKit to work as intended?

推荐答案

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

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>

这篇关于默认调度程序未捕获的错误导致JavaTestKit发生致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆