align with es221
This commit is contained in:
parent
7191bb550b
commit
96eabdd32d
9 changed files with 27 additions and 42 deletions
|
@ -1,4 +0,0 @@
|
||||||
/**
|
|
||||||
* The API of the extended Elasticsearch clients.
|
|
||||||
*/
|
|
||||||
package org.xbib.elx.api;
|
|
|
@ -85,8 +85,7 @@ public class DefaultBulkProcessor implements BulkProcessor {
|
||||||
return bulkListener;
|
return bulkListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder(ElasticsearchClient client,
|
public static Builder builder(ElasticsearchClient client, BulkListener bulkListener) {
|
||||||
BulkListener bulkListener) {
|
|
||||||
Objects.requireNonNull(client, "The client you specified while building a BulkProcessor is null");
|
Objects.requireNonNull(client, "The client you specified while building a BulkProcessor is null");
|
||||||
Objects.requireNonNull(bulkListener, "A listener for the BulkProcessor is required but null");
|
Objects.requireNonNull(bulkListener, "A listener for the BulkProcessor is required but null");
|
||||||
return new Builder(client, bulkListener);
|
return new Builder(client, bulkListener);
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
/**
|
|
||||||
* Common classes for Elasticsearch client extensions.
|
|
||||||
*/
|
|
||||||
package org.xbib.elx.common;
|
|
|
@ -12,6 +12,8 @@ import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||||
|
import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
|
||||||
|
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -40,9 +42,10 @@ class AliasTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAlias() {
|
void testAlias() {
|
||||||
ElasticsearchClient client = helper.client("1");
|
ElasticsearchClient client = helper.client();
|
||||||
CreateIndexRequest indexRequest = new CreateIndexRequest("test_index");
|
CreateIndexRequest indexRequest = new CreateIndexRequest("test_index");
|
||||||
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
|
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
|
||||||
|
client.execute(RefreshAction.INSTANCE, new RefreshRequest()).actionGet();
|
||||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||||
String[] indices = new String[] { "test_index" };
|
String[] indices = new String[] { "test_index" };
|
||||||
String[] aliases = new String[] { "test_alias" };
|
String[] aliases = new String[] { "test_alias" };
|
||||||
|
@ -64,7 +67,7 @@ class AliasTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMostRecentIndex() {
|
void testMostRecentIndex() {
|
||||||
ElasticsearchClient client = helper.client("1");
|
ElasticsearchClient client = helper.client();
|
||||||
String alias = "test";
|
String alias = "test";
|
||||||
CreateIndexRequest indexRequest = new CreateIndexRequest("test20160101");
|
CreateIndexRequest indexRequest = new CreateIndexRequest("test20160101");
|
||||||
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
|
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
|
||||||
|
|
|
@ -29,7 +29,7 @@ class SearchTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSearch() throws Exception {
|
void testSearch() throws Exception {
|
||||||
ElasticsearchClient client = helper.client("1");
|
ElasticsearchClient client = helper.client();
|
||||||
BulkRequestBuilder builder = new BulkRequestBuilder(client, BulkAction.INSTANCE);
|
BulkRequestBuilder builder = new BulkRequestBuilder(client, BulkAction.INSTANCE);
|
||||||
for (int i = 0; i < 1; i++) {
|
for (int i = 0; i < 1; i++) {
|
||||||
IndexRequest indexRequest = new IndexRequest().index("pages")
|
IndexRequest indexRequest = new IndexRequest().index("pages")
|
||||||
|
|
|
@ -34,7 +34,7 @@ class SimpleTest {
|
||||||
try {
|
try {
|
||||||
DeleteIndexRequest deleteIndexRequest =
|
DeleteIndexRequest deleteIndexRequest =
|
||||||
new DeleteIndexRequest().indices("test");
|
new DeleteIndexRequest().indices("test");
|
||||||
helper.client("1").execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet();
|
helper.client().execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet();
|
||||||
} catch (IndexNotFoundException e) {
|
} catch (IndexNotFoundException e) {
|
||||||
// ignore if index not found
|
// ignore if index not found
|
||||||
}
|
}
|
||||||
|
@ -45,22 +45,22 @@ class SimpleTest {
|
||||||
.build();
|
.build();
|
||||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
|
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
|
||||||
createIndexRequest.index("test").settings(indexSettings);
|
createIndexRequest.index("test").settings(indexSettings);
|
||||||
helper.client("1").execute(CreateIndexAction.INSTANCE, createIndexRequest).actionGet();
|
helper.client().execute(CreateIndexAction.INSTANCE, createIndexRequest).actionGet();
|
||||||
IndexRequest indexRequest = new IndexRequest();
|
IndexRequest indexRequest = new IndexRequest();
|
||||||
indexRequest.index("test").id("1")
|
indexRequest.index("test").id("1")
|
||||||
.source(XContentFactory.jsonBuilder().startObject().field("field",
|
.source(XContentFactory.jsonBuilder().startObject().field("field",
|
||||||
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8").endObject());
|
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8").endObject());
|
||||||
helper.client("1").execute(IndexAction.INSTANCE, indexRequest).actionGet();
|
helper.client().execute(IndexAction.INSTANCE, indexRequest).actionGet();
|
||||||
RefreshRequest refreshRequest = new RefreshRequest();
|
RefreshRequest refreshRequest = new RefreshRequest();
|
||||||
refreshRequest.indices("test");
|
refreshRequest.indices("test");
|
||||||
helper.client("1").execute(RefreshAction.INSTANCE, refreshRequest).actionGet();
|
helper.client().execute(RefreshAction.INSTANCE, refreshRequest).actionGet();
|
||||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||||
builder.query(QueryBuilders.matchQuery("field",
|
builder.query(QueryBuilders.matchQuery("field",
|
||||||
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8"));
|
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8"));
|
||||||
SearchRequest searchRequest = new SearchRequest();
|
SearchRequest searchRequest = new SearchRequest();
|
||||||
searchRequest.indices("test");
|
searchRequest.indices("test");
|
||||||
searchRequest.source(builder);
|
searchRequest.source(builder);
|
||||||
String doc = helper.client("1").execute(SearchAction.INSTANCE, searchRequest).actionGet()
|
String doc = helper.client().execute(SearchAction.INSTANCE, searchRequest).actionGet()
|
||||||
.getHits().getAt(0).getSourceAsString();
|
.getHits().getAt(0).getSourceAsString();
|
||||||
assertEquals(doc,
|
assertEquals(doc,
|
||||||
"{\"field\":\"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8\"}");
|
"{\"field\":\"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8\"}");
|
||||||
|
|
|
@ -36,9 +36,7 @@ import java.nio.file.Paths;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
@ -82,14 +80,14 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
||||||
Helper helper = extensionContext.getParent().get().getStore(ns)
|
Helper helper = extensionContext.getParent().get().getStore(ns)
|
||||||
.getOrComputeIfAbsent(key + count.get(), key -> create(), Helper.class);
|
.getOrComputeIfAbsent(key + count.get(), key -> create(), Helper.class);
|
||||||
logger.info("starting cluster with helper " + helper + " at " + helper.getHome());
|
logger.info("starting cluster with helper " + helper + " at " + helper.getHome());
|
||||||
helper.startNode("1");
|
helper.startNode();
|
||||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().addMetric(NodesInfoRequest.Metric.TRANSPORT.metricName());
|
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().addMetric(NodesInfoRequest.Metric.TRANSPORT.metricName());
|
||||||
NodesInfoResponse response = helper.client("1").execute(NodesInfoAction.INSTANCE, nodesInfoRequest).actionGet();
|
NodesInfoResponse response = helper.client().execute(NodesInfoAction.INSTANCE, nodesInfoRequest).actionGet();
|
||||||
TransportAddress address = response.getNodes().get(0).getNode().getAddress();
|
TransportAddress address = response.getNodes().get(0).getNode().getAddress();
|
||||||
String host = address.address().getHostName();
|
String host = address.address().getHostName();
|
||||||
int port = address.address().getPort();
|
int port = address.address().getPort();
|
||||||
try {
|
try {
|
||||||
ClusterHealthResponse healthResponse = helper.client("1").execute(ClusterHealthAction.INSTANCE,
|
ClusterHealthResponse healthResponse = helper.client().execute(ClusterHealthAction.INSTANCE,
|
||||||
new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN)
|
new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN)
|
||||||
.timeout(TimeValue.timeValueSeconds(30))).actionGet();
|
.timeout(TimeValue.timeValueSeconds(30))).actionGet();
|
||||||
if (healthResponse != null && healthResponse.isTimedOut()) {
|
if (healthResponse != null && healthResponse.isTimedOut()) {
|
||||||
|
@ -101,7 +99,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
||||||
}
|
}
|
||||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all();
|
ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all();
|
||||||
ClusterStateResponse clusterStateResponse =
|
ClusterStateResponse clusterStateResponse =
|
||||||
helper.client("1").execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
|
helper.client().execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
|
||||||
logger.info("cluster name = {}", clusterStateResponse.getClusterName().value());
|
logger.info("cluster name = {}", clusterStateResponse.getClusterName().value());
|
||||||
logger.info("host = {} port = {}", host, port);
|
logger.info("host = {} port = {}", host, port);
|
||||||
}
|
}
|
||||||
|
@ -118,10 +116,8 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
||||||
|
|
||||||
private void closeNodes(Helper helper) throws IOException {
|
private void closeNodes(Helper helper) throws IOException {
|
||||||
logger.info("closing all nodes");
|
logger.info("closing all nodes");
|
||||||
for (Node node : helper.nodes.values()) {
|
if (helper.node != null) {
|
||||||
if (node != null) {
|
helper.node.close();
|
||||||
node.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
logger.info("all nodes closed");
|
logger.info("all nodes closed");
|
||||||
}
|
}
|
||||||
|
@ -158,7 +154,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
||||||
|
|
||||||
String cluster;
|
String cluster;
|
||||||
|
|
||||||
Map<String, Node> nodes = new HashMap<>();
|
Node node;
|
||||||
|
|
||||||
void setHome(String home) {
|
void setHome(String home) {
|
||||||
this.home = home;
|
this.home = home;
|
||||||
|
@ -183,12 +179,12 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startNode(String id) throws NodeValidationException {
|
void startNode() throws NodeValidationException {
|
||||||
buildNode(id).start();
|
buildNode().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
ElasticsearchClient client(String id) {
|
ElasticsearchClient client() {
|
||||||
return nodes.get(id).client();
|
return node.client();
|
||||||
}
|
}
|
||||||
|
|
||||||
String randomString(int len) {
|
String randomString(int len) {
|
||||||
|
@ -200,14 +196,13 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
||||||
return new String(buf);
|
return new String(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node buildNode(String id) {
|
private Node buildNode() {
|
||||||
Settings nodeSettings = Settings.builder()
|
Settings nodeSettings = Settings.builder()
|
||||||
.put(getNodeSettings())
|
.put(getNodeSettings())
|
||||||
.put("node.name", id)
|
.put("node.name", "1")
|
||||||
.build();
|
.build();
|
||||||
List<Class<? extends Plugin>> plugins = Collections.singletonList(Netty4Plugin.class);
|
List<Class<? extends Plugin>> plugins = Collections.singletonList(Netty4Plugin.class);
|
||||||
Node node = new MockNode(nodeSettings, plugins);
|
this.node = new MockNode(nodeSettings, plugins);
|
||||||
nodes.put(id, node);
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class WildcardTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWildcard() throws Exception {
|
void testWildcard() throws Exception {
|
||||||
ElasticsearchClient client = helper.client("1");
|
ElasticsearchClient client = helper.client();
|
||||||
index(client, "1", "010");
|
index(client, "1", "010");
|
||||||
index(client, "2", "0*0");
|
index(client, "2", "0*0");
|
||||||
// exact
|
// exact
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.xbib.elx.common.test;
|
|
Loading…
Reference in a new issue