gpt4 book ai didi

java - ElasticSearchTestCase:使用ESIntegTestCase创建客户端实例时

转载 作者:行者123 更新时间:2023-12-02 22:36:47 26 4
gpt4 key购买 nike

当我声明@BeforeClass Notation并声明我的ElasticSerach Client时
这给了我这种错误。

在测试类中,我只希望Client实例一个。我正在使用ESIntegTestCase这个类编写测试用例。

这是我的代码。

public class PersonTest extends ESIntegTestCase {

private static Client client;

@BeforeClass
public static void setUpClient() {
client = ESIntegTestCase.client();
}

@Test
public void createIndex() {
// Using client's instance creating an index.
}

@Test
public void search() {
// Using client's instance Seach would be perform.
}

}

我遇到这种错误。
java.lang.NullPointerException
at __randomizedtesting.SeedInfo.seed([F541A8F42426AB1C]:0)
at org.elasticsearch.test.ESIntegTestCase.client(ESIntegTestCase.java:633)
at org.elasticsearch.test.ESIntegTestCase.client(ESIntegTestCase.java:626)
at com.saba.search.elasticSearch.PersonTest.setUpClient(PersonTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1713)
at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:847)
at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:863)
at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:41)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
at org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:54)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:367)
at java.lang.Thread.run(Thread.java:745)

最佳答案

我想是因为测试集群尚未初始化而发生的。不需要使客户端变量静态。我建议使用@Before注释和实例变量

关于java - ElasticSearchTestCase:使用ESIntegTestCase创建客户端实例时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48822516/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com