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;
|
||||
}
|
||||
|
||||
public static Builder builder(ElasticsearchClient client,
|
||||
BulkListener bulkListener) {
|
||||
public static Builder builder(ElasticsearchClient client, BulkListener bulkListener) {
|
||||
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");
|
||||
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.create.CreateIndexAction;
|
||||
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.common.Strings;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -40,9 +42,10 @@ class AliasTest {
|
|||
|
||||
@Test
|
||||
void testAlias() {
|
||||
ElasticsearchClient client = helper.client("1");
|
||||
ElasticsearchClient client = helper.client();
|
||||
CreateIndexRequest indexRequest = new CreateIndexRequest("test_index");
|
||||
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
|
||||
client.execute(RefreshAction.INSTANCE, new RefreshRequest()).actionGet();
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
String[] indices = new String[] { "test_index" };
|
||||
String[] aliases = new String[] { "test_alias" };
|
||||
|
@ -64,7 +67,7 @@ class AliasTest {
|
|||
|
||||
@Test
|
||||
void testMostRecentIndex() {
|
||||
ElasticsearchClient client = helper.client("1");
|
||||
ElasticsearchClient client = helper.client();
|
||||
String alias = "test";
|
||||
CreateIndexRequest indexRequest = new CreateIndexRequest("test20160101");
|
||||
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
|
||||
|
|
|
@ -29,7 +29,7 @@ class SearchTest {
|
|||
|
||||
@Test
|
||||
void testSearch() throws Exception {
|
||||
ElasticsearchClient client = helper.client("1");
|
||||
ElasticsearchClient client = helper.client();
|
||||
BulkRequestBuilder builder = new BulkRequestBuilder(client, BulkAction.INSTANCE);
|
||||
for (int i = 0; i < 1; i++) {
|
||||
IndexRequest indexRequest = new IndexRequest().index("pages")
|
||||
|
|
|
@ -34,7 +34,7 @@ class SimpleTest {
|
|||
try {
|
||||
DeleteIndexRequest deleteIndexRequest =
|
||||
new DeleteIndexRequest().indices("test");
|
||||
helper.client("1").execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet();
|
||||
helper.client().execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet();
|
||||
} catch (IndexNotFoundException e) {
|
||||
// ignore if index not found
|
||||
}
|
||||
|
@ -45,22 +45,22 @@ class SimpleTest {
|
|||
.build();
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
|
||||
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.index("test").id("1")
|
||||
.source(XContentFactory.jsonBuilder().startObject().field("field",
|
||||
"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.indices("test");
|
||||
helper.client("1").execute(RefreshAction.INSTANCE, refreshRequest).actionGet();
|
||||
helper.client().execute(RefreshAction.INSTANCE, refreshRequest).actionGet();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchQuery("field",
|
||||
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8"));
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("test");
|
||||
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();
|
||||
assertEquals(doc,
|
||||
"{\"field\":\"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8\"}");
|
||||
|
|
|
@ -36,9 +36,7 @@ import java.nio.file.Paths;
|
|||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
@ -82,14 +80,14 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|||
Helper helper = extensionContext.getParent().get().getStore(ns)
|
||||
.getOrComputeIfAbsent(key + count.get(), key -> create(), Helper.class);
|
||||
logger.info("starting cluster with helper " + helper + " at " + helper.getHome());
|
||||
helper.startNode("1");
|
||||
helper.startNode();
|
||||
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();
|
||||
String host = address.address().getHostName();
|
||||
int port = address.address().getPort();
|
||||
try {
|
||||
ClusterHealthResponse healthResponse = helper.client("1").execute(ClusterHealthAction.INSTANCE,
|
||||
ClusterHealthResponse healthResponse = helper.client().execute(ClusterHealthAction.INSTANCE,
|
||||
new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN)
|
||||
.timeout(TimeValue.timeValueSeconds(30))).actionGet();
|
||||
if (healthResponse != null && healthResponse.isTimedOut()) {
|
||||
|
@ -101,7 +99,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|||
}
|
||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all();
|
||||
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("host = {} port = {}", host, port);
|
||||
}
|
||||
|
@ -118,10 +116,8 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|||
|
||||
private void closeNodes(Helper helper) throws IOException {
|
||||
logger.info("closing all nodes");
|
||||
for (Node node : helper.nodes.values()) {
|
||||
if (node != null) {
|
||||
node.close();
|
||||
}
|
||||
if (helper.node != null) {
|
||||
helper.node.close();
|
||||
}
|
||||
logger.info("all nodes closed");
|
||||
}
|
||||
|
@ -158,7 +154,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|||
|
||||
String cluster;
|
||||
|
||||
Map<String, Node> nodes = new HashMap<>();
|
||||
Node node;
|
||||
|
||||
void setHome(String home) {
|
||||
this.home = home;
|
||||
|
@ -183,12 +179,12 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|||
.build();
|
||||
}
|
||||
|
||||
void startNode(String id) throws NodeValidationException {
|
||||
buildNode(id).start();
|
||||
void startNode() throws NodeValidationException {
|
||||
buildNode().start();
|
||||
}
|
||||
|
||||
ElasticsearchClient client(String id) {
|
||||
return nodes.get(id).client();
|
||||
ElasticsearchClient client() {
|
||||
return node.client();
|
||||
}
|
||||
|
||||
String randomString(int len) {
|
||||
|
@ -200,14 +196,13 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
|
|||
return new String(buf);
|
||||
}
|
||||
|
||||
private Node buildNode(String id) {
|
||||
private Node buildNode() {
|
||||
Settings nodeSettings = Settings.builder()
|
||||
.put(getNodeSettings())
|
||||
.put("node.name", id)
|
||||
.put("node.name", "1")
|
||||
.build();
|
||||
List<Class<? extends Plugin>> plugins = Collections.singletonList(Netty4Plugin.class);
|
||||
Node node = new MockNode(nodeSettings, plugins);
|
||||
nodes.put(id, node);
|
||||
this.node = new MockNode(nodeSettings, plugins);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class WildcardTest {
|
|||
|
||||
@Test
|
||||
void testWildcard() throws Exception {
|
||||
ElasticsearchClient client = helper.client("1");
|
||||
ElasticsearchClient client = helper.client();
|
||||
index(client, "1", "010");
|
||||
index(client, "2", "0*0");
|
||||
// exact
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.xbib.elx.common.test;
|
Loading…
Reference in a new issue