unit-testing - Elasticsearch 6.2在单元测试中启动localhost http节点

标签 unit-testing elasticsearch junit aws-elasticsearch

我的目标是在我的junit测试中启动localhost flex 搜索节点,因此我可以索引一些文档,还可以通过高级rest客户端测试搜索查询(例如,对localhost ES节点进行http调用)。我正在使用Elasticsearch 6.2。

这是我尝试的代码

    String clusterName = "test";
    Settings settings = Settings.builder()
            .put("path.home", ES_WORKING_DIR)
            .build();
    new Node(settings).start();

这是我收到的错误消息。
java.lang.IllegalStateException: Unsupported transport.type []

at __randomizedtesting.SeedInfo.seed([74752622FDACDD5:AB9FD863FD5A2A5F]:0)
at org.elasticsearch.common.network.NetworkModule.getTransportSupplier(NetworkModule.java:212)
at org.elasticsearch.node.Node.<init>(Node.java:427)
at org.elasticsearch.node.Node.<init>(Node.java:246)
at org.elasticsearch.node.Node.<init>(Node.java:242)

基本上,我不确定要在“设置”中设置哪些参数。

提前致谢。

最佳答案

这些不再受 flex 支持,但它们可用于Junit测试

我有以下

对于5.6.7

Settings.Builder nodeSettings = Settings.builder()
            .put("cluster.name", "my-integration-test")
            .put("http.enabled", "true")
            .put("path.data", dataDirectory)
            .put("path.home", "/")
            .put("transport.type", "netty4")
            .put("network.host", "_local_")
            .put("transport.tcp.port", "19200-19400")
            .put("http.port", "19200-19400")
            .put("discovery.type", "single-node");

    LOG.info("Starting up embedded Elasticsearch");
    node = new LocalNode(nodeSettings.build(), Arrays.asList(Netty4Plugin.class,
            ReindexPlugin.class));
    node.start();

flex 6.8.3
        Settings.Builder nodeSettings = Settings.builder()
            .put("cluster.name", "integration-test")
            .put("node.name", "node-test")
            .put("path.data", dataDirectory)
            .put("path.home", "/")
            .put("transport.type", "netty4")
            .put("network.host", "127.0.0.1")
            .put("http.port", "19200");

    LOG.info("Starting up embedded Elasticsearch");
    node = new LocalNode(nodeSettings.build(), Arrays.asList(Netty4Plugin.class,
            ReindexPlugin.class,
            CommonAnalysisPlugin.class));

        node.start();

哪里
private static class LocalNode extends Node {

    LocalNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
        super(new Environment(settings, null), classpathPlugins, true);
    }

    @Override
    protected void registerDerivedNodeNameWithLogger(final String s) {}

}

对于6.8.x,您将需要
    <dependency>
        <groupId>org.codelibs.elasticsearch.module</groupId>
        <artifactId>analysis-common</artifactId>
        <version>6.8.2</version>
    </dependency>

关于unit-testing - Elasticsearch 6.2在单元测试中启动localhost http节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50509674/

相关文章:

c# - 数据库初始化运行太晚

azure - 如何模拟 Azure blobContainerClient.GetBlobsAsync()

elasticsearch - Kibana-Elastic Search 仅从界面返回特定字段

elasticsearch - Elasticsearch:查询数组元素

elasticsearch - 在 Elasticsearch 中检索热门术语查询

java - 遍历数组,每个元素一个 JUnit 测试

c# - FakeItEasy:模拟方法未返回预期结果

对简单集合类进行单元测试

java - Junit/Spring Boot 模拟类

java - com.github.tomakehurst.wiremock.client.VerificationException : Expected at least one request matching