栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何为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]开始..

希望这可以帮助。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388194.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号