如何为Elasticsearch自定义插件编写测试?

如何为Elasticsearch自定义插件编写测试?,第1张

如何为Elasticsearch自定义插件编写测试

要为您的插件编写测试,您可以使用Elasticsearch Cluster
Runner
。作为参考,请检查MinHash插件如何编写测试。

更新:

我将

CustomParserPluginTest
类更改为使用Elasticsearch Cluster Runner:

import static org.prelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;import java.util.Map;import junit.framework.TestCase;import org.prelibs.elasticsearch.runner.ElasticsearchClusterRunner;import org.elasticsearch.action.get.GetResponse;import org.elasticsearch.action.index.IndexResponse;import org.elasticsearch.client.Client;import org.elasticsearch.common.bytes.BytesArray;import org.elasticsearch.common.settings.ImmutableSettings;import org.elasticsearch.common.settings.ImmutableSettings.Builder;import org.elasticsearch.common.xcontent.XContentBuilder;import org.elasticsearch.common.xcontent.XContentFactory;import org.elasticsearch.index.get.GetField;import org.junit.Assert;import org.elasticsearch.action.search.SearchResponse;import static org.hamcrest.core.Is.is;public class CustomParserPluginTest extends TestCase {    private ElasticsearchClusterRunner runner;    @Override    protected void setUp() throws Exception {        // create runner instance        runner = new ElasticsearchClusterRunner();        // create ES nodes        runner.onBuild(new ElasticsearchClusterRunner.Builder() { @Override public void build(final int number, final Builder settingsBuilder) { }        }).build(newConfigs().ramIndexStore().numOfNode(1));        // wait for yellow status        runner.ensureYellow();    }    @Override    protected void tearDown() throws Exception {        // close runner        runner.close();        // delete all files        runner.clean();    }    public void test_jsonParsing() throws Exception {        final String index = "test_index";        runner.createIndex(index, ImmutableSettings.builder().build());        runner.ensureYellow(index);        final SearchResponse test = runner.client().prepareSearch(index).setSource(addQuery()).execute().actionGet();    }    private String addQuery() {        return "{"match_all":{"boost":1.2}}";    }}

我创建了

es-plugin.properties
(pluginrootdirectory src main
resources)文件,其内容如下,这将迫使elasticsearch实例加载插件:

plugin=CustomQueryParserPlugin

当您运行此测试时,您将在输出中看到新创建的Elasticsearch实例加载了插件。

[2015-04-29 19:22:10,783] [INFO] [org.elasticsearch.node] [节点1]版本[1.5
.0],pid [34360],内部版本[5448160 / 2015-03-23T14:30: 58Z] [2015-04-29
19:22:10,784] [INFO] [org.elasticsearch.node] [Node 1]初始化… [2015-04-29
19:22:10,795] .elasticsearch.plugins] [节点1]已加载[ custom_query ],网站[]
[2015-04-29 19:22:13,342] [INFO] [org.elasticsearch.node] [节点1]已初始化

[2015-04-29 19:22:13,342] [信息] [org.elasticsearch.node] [节点1]开始..

希望这可以帮助。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4963234.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存