从嵌入式弹性搜索中休息高级客户端

时间:2021-06-11 21:09:35

标签: elasticsearch elasticsearch-plugin

我正在从 elasticsearch 5.6 升级到 7.12。我们利用嵌入式弹性进行单元测试

public EmbeddedElastic() throws NodeValidationException, IOException {
        tempDir = "some_temp";

        int port = some_port;
        Settings settings = Settings.builder()
              .put("path.home", tempDir)
              .put("http.port", port)
              .put("transport.tcp.port", port + 1)
              .put("transport.type", "local")
              .put("http.enabled", false)
              .build();
        client = new PluginNode(settings).start().client();
    }

    private class PluginNode extends Node {
        public PluginNode(Settings preparedSettings) {
            super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null),
                  Lists.newArrayList(PainlessPlugin.class));
            System.out.println("Started local elastic with PainlessPlugin loaded.");
        }
    }

这里返回的客户端当然是 Client,现在我需要休息高级客户端来为 ElasticsearchOperations 创建一个 bean。我正在阅读有关利用 ESIntegTestCase 的信息。我正在从 ESIntegrationTest 复制位 当我收到错误

INFO: An exception was caught and reported. Message: java.lang.IllegalStateException: No context information for thread: Thread[id=15, name=Test worker, state=RUNNABLE, group=main]. 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).

错误来自方法中 Node 库中的 nodeEnvironment = new NodeEnvironment(tmpSettings, environment)

    public static String generateNodeId(Settings settings) {
        Random random = Randomness.get(settings, NODE_ID_SEED_SETTING);
        return UUIDs.randomBase64UUID(random);

所以我认为我的设置有问题。我添加了 settings.put("node.id.seed", "0"); 这部分代码成功,但现在同样的错误来自不同的地方。我可以一一调试,但我希望你能从你的经验中分享一些例子来初始化这些设置。

编辑:在调用 currentMethod

时,ES 的 Randomness 库中出现了最新错误

附录:atm类


@ClusterScope(scope = Scope.SUITE)
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
@RunWith(RandomizedRunner.class)
public class EmbeddedElastic extends ESIntegTestCase {

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        embed();
    }

    public EmbeddedElastic() throws Exception {
        setUp();
    }

    public void embed() throws Exception {
        tempDir = "some_dir";

        int port = some_port;
        Map<String, String> settings = new HashMap<>();
        settings.put("path.home", tempDir);
        settings.put("http.port", Integer.toString(port));
        settings.put("transport.tcp.port", Integer.toString(port + 1));
        settings.put("transport.type", "netty4");
        settings.put("node.id.seed", "1");
        settings.put("http.cors.enabled", Boolean.FALSE.toString());
        client = new PluginNode(settings).start().client();
    }

}
@ClusterScope(scope = Scope.SUITE)
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
@RunWith(RandomizedRunner.class)
class PluginNode extends Node {
    public PluginNode(Map<String, String> preparedSettings) {
        super(InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, preparedSettings,
                                                          null, () -> "node-test"),
              Lists.newArrayList(Netty4Plugin.class),
              false);
    }
}

0 个答案:

没有答案