Java中的嵌入式弹性搜索服务器中的错误

时间:2018-08-28 14:24:42

标签: java elasticsearch junit

我正在尝试为Junit测试用例运行嵌入式弹性服务器。所以我只是扩展了一个类ESIntegTestCase。但这不允许我运行测试用例。我使用弹性搜索6.0.0。

import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;

public class AbstractElasticsearchTest extends ESIntegTestCase {

    @Test
    public void test() {
        org.elasticsearch.test.ESTestCase d;
        System.out.println("hello");
    }
}

错误:

Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.test.ESTestCase
    at java.lang.Thread.run(Thread.java:748)
    Suppressed: java.lang.IllegalStateException: No context information for thread: Thread[id=12, name=Thread-1, state=RUNNABLE, group=TGRP-AbstractElasticsearchTest]. Is this thread running under a class com.carrotsearch.randomizedtesting.RandomizedRunner runner context? Add @RunWith(class com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class. Make sure your code accesses random contexts within @BeforeClass and @AfterClass boundary (for example, static test class initializers are not permitted to access random contexts).
        at com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:248)
        at com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:134)
        at com.carrotsearch.randomizedtesting.RandomizedRunner.augmentStackTrace(RandomizedRunner.java:1848)
        at com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:20)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:1959)

Spring Boot jars似乎有问题,当我在单独的项目中运行它时,它工作正常。请帮助我解决

依赖项:

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <es.version>6.0.0</es.version>
    <flyway-maven-plugin.version>5.1.1</flyway-maven-plugin.version>
    <postgres.version>5.1.1</postgres.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${es.version}</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>${es.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.test</groupId>
        <artifactId>framework</artifactId>
        <version>${es.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.elasticsearch</groupId>
                <artifactId>securemock</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.zonky.test</groupId>
        <artifactId>embedded-database-spring-test</artifactId>
        <version>1.3.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>
</dependencies>

0 个答案:

没有答案