我通过扩展 ElasticsearchIntegrationTest 为 ElasticSearch 编写了集成测试。以下测试的顶部部分:
import org.junit.*;
import static org.junit.Assert.assertEquals;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
public class ProductSearchTest extends ElasticsearchIntegrationTest
尝试通过 Maven 运行测试时,我在 JUnit 中看到此错误
java.lang.NoSuchMethodError: com.carrotsearch.randomizedtesting.RandomizedContext.runWithPrivateRandomness(Lcom/carrotsearch/randomizedtesting/Randomness;Ljava/util/concurrent/Callable;)Ljava/lang/Object; 在 __randomizedtesting.SeedInfo.seed([9DE685AB75B54F0A:10B1B129F9E3CB67]:0)我已将依赖项包含在 pom 中,如 on the elasticsearch site 中所述
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>4.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
有人见过这个吗?看起来我缺少一个依赖项(我尝试将几个 carlotsearch maven 依赖项添加到 pom 中,但没有成功)。或者,是否有人对我正在使用的版本进行集成测试,因此至少如果我花费数小时尝试查找依赖项问题,我可以确信一旦确定它就会工作。
感谢您的宝贵时间。
最佳答案
确实,Lucene 使用的 randomizedtesting
jar 与 ES 使用的 jar 之间似乎不匹配。在您的 pom.xml
中尝试一下:
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>4.10.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>randomizedtesting-runner</artifactId>
<groupId>
com.carrotsearch.randomizedtesting
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>randomizedtesting-runner</artifactId>
<version>2.1.10</version>
<scope>test</scope>
</dependency>
关于java - elasticsearch Elasticsearch集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26876977/