add index prune test, clean up test, update to xbib metrics 1.2.0
This commit is contained in:
parent
fa84c61336
commit
2b3ac518b5
29 changed files with 368 additions and 198 deletions
25
build.gradle
25
build.gradle
|
@ -6,7 +6,7 @@ plugins {
|
|||
id "org.xbib.gradle.plugin.asciidoctor" version "1.6.0.1"
|
||||
}
|
||||
|
||||
printf "Host: %s\nOS: %s %s %s\nJava: %s %s %s %s\nGradle: %s Groovy: %s Java: %s\n" +
|
||||
printf "Host: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGradle: %s Groovy: %s Java: %s\n" +
|
||||
"Build: group: ${project.group} name: ${project.name} version: ${project.version}\n",
|
||||
InetAddress.getLocalHost(),
|
||||
System.getProperty("os.name"),
|
||||
|
@ -16,8 +16,9 @@ printf "Host: %s\nOS: %s %s %s\nJava: %s %s %s %s\nGradle: %s Groovy: %s Java: %
|
|||
System.getProperty("java.vm.version"),
|
||||
System.getProperty("java.vm.vendor"),
|
||||
System.getProperty("java.vm.name"),
|
||||
gradle.gradleVersion, GroovySystem.getVersion(), JavaVersion.current()
|
||||
|
||||
gradle.gradleVersion,
|
||||
GroovySystem.getVersion(),
|
||||
JavaVersion.current()
|
||||
|
||||
if (JavaVersion.current() < JavaVersion.VERSION_11) {
|
||||
throw new GradleException("This build must be run with java 11 or higher")
|
||||
|
@ -92,24 +93,6 @@ subprojects {
|
|||
}
|
||||
}*/
|
||||
|
||||
/*task javadocJar(type: Jar, dependsOn: classes) {
|
||||
baseName "${rootProject.name}-${project.name}"
|
||||
from javadoc
|
||||
into "build/tmp"
|
||||
classifier 'javadoc'
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
baseName "${rootProject.name}-${project.name}"
|
||||
from sourceSets.main.allSource
|
||||
into "build/tmp"
|
||||
classifier 'sources'
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives javadocJar, sourcesJar
|
||||
}*/
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier 'javadoc'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
dependencies {
|
||||
compile "org.xbib:metrics:${project.property('xbib-metrics.version')}"
|
||||
compile "org.xbib:metrics-common:${project.property('xbib-metrics.version')}"
|
||||
compile "org.xbib.elasticsearch:elasticsearch:${rootProject.property('elasticsearch-server.version')}"
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package org.xbib.elx.api;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.xbib.metrics.Count;
|
||||
import org.xbib.metrics.Metered;
|
||||
import org.xbib.metrics.api.Count;
|
||||
import org.xbib.metrics.api.Metered;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
|
|
|
@ -5,5 +5,5 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
|||
@FunctionalInterface
|
||||
public interface IndexAliasAdder {
|
||||
|
||||
void addIndexAlias(IndicesAliasesRequest requwst, String index, String alias);
|
||||
void addIndexAlias(IndicesAliasesRequest request, String index, String alias);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest
|
|||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
@ -70,6 +70,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
|
@ -445,11 +446,11 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
|
|||
public boolean waitForRecovery(String index, long maxWaitTime, TimeUnit timeUnit) {
|
||||
ensureActive();
|
||||
ensureIndexGiven(index);
|
||||
RecoveryRequest recoveryRequest = new RecoveryRequest();
|
||||
recoveryRequest.indices(index);
|
||||
recoveryRequest.activeOnly(true);
|
||||
RecoveryResponse response = client.execute(RecoveryAction.INSTANCE, recoveryRequest).actionGet();
|
||||
int shards = response.getTotalShards();
|
||||
GetSettingsRequest settingsRequest = new GetSettingsRequest();
|
||||
settingsRequest.indices(index);
|
||||
GetSettingsResponse settingsResponse = client.execute(GetSettingsAction.INSTANCE, settingsRequest).actionGet();
|
||||
int shards = settingsResponse.getIndexToSettings().get(index).getAsInt("index.number_of_shards", -1);
|
||||
if (shards > 0) {
|
||||
TimeValue timeout = toTimeValue(maxWaitTime, timeUnit);
|
||||
ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest()
|
||||
.indices(index)
|
||||
|
@ -460,6 +461,7 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
|
|||
logger.error("timeout waiting for recovery");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -736,7 +738,7 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
|
|||
if (m2.matches()) {
|
||||
Integer i2 = Integer.parseInt(m2.group(2));
|
||||
int kept = candidateIndices.size() - indicesToDelete.size();
|
||||
if ((delta == 0 || (delta > 0 && i1 - i2 > delta)) && mintokeep <= kept) {
|
||||
if ((delta == 0 || (delta > 0 && i1 - i2 >= delta)) && mintokeep <= kept) {
|
||||
indicesToDelete.add(s);
|
||||
}
|
||||
}
|
||||
|
@ -755,13 +757,16 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
|
|||
@Override
|
||||
public Long mostRecentDocument(String index, String timestampfieldname) {
|
||||
ensureActive();
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client, SearchAction.INSTANCE);
|
||||
SortBuilder<?> sort = SortBuilders.fieldSort(timestampfieldname).order(SortOrder.DESC);
|
||||
SearchResponse searchResponse = searchRequestBuilder.setIndices(index)
|
||||
.addStoredField(timestampfieldname)
|
||||
.setSize(1)
|
||||
.addSort(sort)
|
||||
.execute().actionGet();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.sort(sort);
|
||||
builder.storedField(timestampfieldname);
|
||||
builder.size(1);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices(index);
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse =
|
||||
client.execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
if (searchResponse.getHits().getHits().length == 1) {
|
||||
SearchHit hit = searchResponse.getHits().getHits()[0];
|
||||
if (hit.getFields().get(timestampfieldname) != null) {
|
||||
|
@ -903,13 +908,15 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
|
|||
|
||||
private void checkMapping(String index, String type, MappingMetaData mappingMetaData) {
|
||||
try {
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client, SearchAction.INSTANCE);
|
||||
SearchResponse searchResponse = searchRequestBuilder.setSize(0)
|
||||
.setIndices(index)
|
||||
.setTypes(type)
|
||||
.setQuery(QueryBuilders.matchAllQuery())
|
||||
.execute()
|
||||
.actionGet();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchAllQuery());
|
||||
builder.size(0);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices(index);
|
||||
searchRequest.types(type);
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse =
|
||||
client.execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
long total = searchResponse.getHits().getTotalHits();
|
||||
if (total > 0L) {
|
||||
Map<String, Long> fields = new TreeMap<>();
|
||||
|
@ -965,13 +972,15 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
|
|||
} else if ("type".equals(key)) {
|
||||
QueryBuilder filterBuilder = QueryBuilders.existsQuery(path);
|
||||
QueryBuilder queryBuilder = QueryBuilders.constantScoreQuery(filterBuilder);
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client, SearchAction.INSTANCE);
|
||||
SearchResponse searchResponse = searchRequestBuilder.setSize(0)
|
||||
.setIndices(index)
|
||||
.setTypes(type)
|
||||
.setQuery(queryBuilder)
|
||||
.execute()
|
||||
.actionGet();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(queryBuilder);
|
||||
builder.size(0);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices(index);
|
||||
searchRequest.types(type);
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse =
|
||||
client.execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
fields.put(path, searchResponse.getHits().getTotalHits());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ package org.xbib.elx.common;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.xbib.elx.api.BulkMetric;
|
||||
import org.xbib.metrics.Count;
|
||||
import org.xbib.metrics.CountMetric;
|
||||
import org.xbib.metrics.Meter;
|
||||
import org.xbib.metrics.Metered;
|
||||
import org.xbib.metrics.api.Count;
|
||||
import org.xbib.metrics.api.Metered;
|
||||
import org.xbib.metrics.common.CountMetric;
|
||||
import org.xbib.metrics.common.Meter;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
@ -71,9 +70,10 @@ public class AliasTest extends TestBase {
|
|||
indicesAliasesRequest.addAliasAction(aliasAction);
|
||||
client.admin().indices().aliases(indicesAliasesRequest).actionGet();
|
||||
|
||||
GetAliasesRequestBuilder getAliasesRequestBuilder = new GetAliasesRequestBuilder(client,
|
||||
GetAliasesAction.INSTANCE);
|
||||
GetAliasesResponse getAliasesResponse = getAliasesRequestBuilder.setAliases(alias).execute().actionGet();
|
||||
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
|
||||
getAliasesRequest.aliases(alias);
|
||||
GetAliasesResponse getAliasesResponse =
|
||||
client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet();
|
||||
Pattern pattern = Pattern.compile("^(.*?)(\\d+)$");
|
||||
Set<String> result = new TreeSet<>(Collections.reverseOrder());
|
||||
for (ObjectCursor<String> indexName : getAliasesResponse.getAliases().keys()) {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ClusterBlockTest extends TestBase {
|
|||
@Before
|
||||
public void startNodes() {
|
||||
try {
|
||||
setClusterName("test-cluster");
|
||||
setClusterName("test-cluster-" + System.getProperty("user.name"));
|
||||
startNode("1");
|
||||
// do not wait for green health state
|
||||
logger.info("ready");
|
||||
|
|
|
@ -36,8 +36,7 @@ public class SearchTest extends TestBase {
|
|||
.field("user9", "joerg")
|
||||
.field("rowcount", i)
|
||||
.field("rs", 1234)
|
||||
.endObject()
|
||||
);
|
||||
.endObject());
|
||||
builder.add(indexRequest);
|
||||
}
|
||||
client.bulk(builder.request()).actionGet();
|
||||
|
|
|
@ -3,17 +3,21 @@ package org.xbib.elx.common.test;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||
import org.elasticsearch.action.index.IndexAction;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimpleTest extends TestBase {
|
||||
|
@ -21,9 +25,9 @@ public class SimpleTest extends TestBase {
|
|||
@Test
|
||||
public void test() throws Exception {
|
||||
try {
|
||||
DeleteIndexRequestBuilder deleteIndexRequestBuilder =
|
||||
new DeleteIndexRequestBuilder(client("1"), DeleteIndexAction.INSTANCE, "test");
|
||||
deleteIndexRequestBuilder.execute().actionGet();
|
||||
DeleteIndexRequest deleteIndexRequest =
|
||||
new DeleteIndexRequest().indices("test");
|
||||
client("1").execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet();
|
||||
} catch (IndexNotFoundException e) {
|
||||
// ignore if index not found
|
||||
}
|
||||
|
@ -32,27 +36,24 @@ public class SimpleTest extends TestBase {
|
|||
.put("index.analysis.analyzer.default.filter.1", "trim")
|
||||
.put("index.analysis.analyzer.default.tokenizer", "keyword")
|
||||
.build();
|
||||
CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client("1"), CreateIndexAction.INSTANCE);
|
||||
createIndexRequestBuilder.setIndex("test")
|
||||
.setSettings(indexSettings).execute().actionGet();
|
||||
|
||||
IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client("1"), IndexAction.INSTANCE);
|
||||
indexRequestBuilder
|
||||
.setIndex("test")
|
||||
.setType("test")
|
||||
.setId("1")
|
||||
.setSource(XContentFactory.jsonBuilder().startObject().field("field",
|
||||
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8").endObject())
|
||||
.execute()
|
||||
.actionGet();
|
||||
RefreshRequestBuilder refreshRequestBuilder = new RefreshRequestBuilder(client("1"), RefreshAction.INSTANCE);
|
||||
refreshRequestBuilder.setIndices("test").execute().actionGet();
|
||||
String doc = client("1").prepareSearch("test")
|
||||
.setTypes("test")
|
||||
.setQuery(QueryBuilders.matchQuery("field",
|
||||
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8"))
|
||||
.execute()
|
||||
.actionGet()
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
|
||||
createIndexRequest.index("test").settings(indexSettings);
|
||||
client("1").execute(CreateIndexAction.INSTANCE, createIndexRequest).actionGet();
|
||||
IndexRequest indexRequest = new IndexRequest();
|
||||
indexRequest.index("test").type("test").id("1")
|
||||
.source(XContentFactory.jsonBuilder().startObject().field("field",
|
||||
"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8").endObject());
|
||||
client("1").execute(IndexAction.INSTANCE, indexRequest).actionGet();
|
||||
RefreshRequest refreshRequest = new RefreshRequest();
|
||||
refreshRequest.indices("test");
|
||||
client("1").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").types("test");
|
||||
searchRequest.source(builder);
|
||||
String doc = client("1").execute(SearchAction.INSTANCE, searchRequest).actionGet()
|
||||
.getHits().getAt(0).getSourceAsString();
|
||||
|
||||
assertEquals(doc,
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
|
||||
import org.elasticsearch.client.support.AbstractClient;
|
||||
|
@ -59,7 +59,7 @@ public class TestBase {
|
|||
public void startNodes() {
|
||||
try {
|
||||
logger.info("starting");
|
||||
setClusterName("test-cluster");
|
||||
setClusterName("test-cluster-" + System.getProperty("user.name"));
|
||||
startNode("1");
|
||||
findNodeAddress();
|
||||
try {
|
||||
|
@ -73,9 +73,10 @@ public class TestBase {
|
|||
} catch (ElasticsearchTimeoutException e) {
|
||||
throw new IOException("cluster does not respond to health request, cowardly refusing to continue");
|
||||
}
|
||||
ClusterStateRequestBuilder clusterStateRequestBuilder =
|
||||
new ClusterStateRequestBuilder(client("1"), ClusterStateAction.INSTANCE).all();
|
||||
ClusterStateResponse clusterStateResponse = clusterStateRequestBuilder.execute().actionGet();
|
||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.all();
|
||||
ClusterStateResponse clusterStateResponse =
|
||||
client("1").execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
|
||||
logger.info("cluster name = {}", clusterStateResponse.getClusterName().value());
|
||||
logger.info("host = {} port = {}", host, port);
|
||||
} catch (Throwable t) {
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package org.xbib.elx.common.test;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||
import org.elasticsearch.action.index.IndexAction;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -31,16 +36,20 @@ public class WildcardTest extends TestBase {
|
|||
}
|
||||
|
||||
private void index(Client client, String id, String fieldValue) throws IOException {
|
||||
client.index(new IndexRequest("index", "type", id)
|
||||
client.execute(IndexAction.INSTANCE, new IndexRequest("index", "type", id)
|
||||
.source(XContentFactory.jsonBuilder().startObject().field("field", fieldValue).endObject()))
|
||||
.actionGet();
|
||||
client.admin().indices().refresh(new RefreshRequest()).actionGet();
|
||||
client.execute(RefreshAction.INSTANCE, new RefreshRequest()).actionGet();
|
||||
}
|
||||
|
||||
private long count(Client client, QueryBuilder queryBuilder) {
|
||||
return client.prepareSearch("index").setTypes("type")
|
||||
.setQuery(queryBuilder)
|
||||
.execute().actionGet().getHits().getTotalHits();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(queryBuilder);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("index");
|
||||
searchRequest.types("type");
|
||||
searchRequest.source(builder);
|
||||
return client.execute(SearchAction.INSTANCE, searchRequest).actionGet().getHits().getTotalHits();
|
||||
}
|
||||
|
||||
private void validateCount(Client client, QueryBuilder queryBuilder, long expectedHits) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.xbib.elx.node;
|
||||
|
||||
import io.netty.util.Version;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
@ -12,7 +11,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.transport.netty4.Netty4Utils;
|
||||
import org.xbib.elx.common.AbstractExtendedClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class ClientTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ClientTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(ClientTest.class.getName());
|
||||
|
||||
private static final Long ACTIONS = 25000L;
|
||||
|
||||
|
@ -124,8 +124,6 @@ public class ClientTest extends TestBase {
|
|||
client.waitForResponses(30L, TimeUnit.SECONDS);
|
||||
} catch (NoNodeAvailableException e) {
|
||||
logger.warn("skipping, no node available");
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
assertEquals(numactions, client.getBulkMetric().getSucceeded().getCount());
|
||||
if (client.getBulkController().getLastBulkError() != null) {
|
||||
|
@ -149,7 +147,7 @@ public class ClientTest extends TestBase {
|
|||
logger.info("maxthreads={} maxactions={} maxloop={}", maxthreads, maxActionsPerRequest, actions);
|
||||
final ExtendedNodeClient client = ClientBuilder.builder(client("1"))
|
||||
.provider(ExtendedNodeClientProvider.class)
|
||||
.put(Parameters.MAX_CONCURRENT_REQUESTS.name(), maxthreads * 2)
|
||||
.put(Parameters.MAX_CONCURRENT_REQUESTS.name(), maxthreads)
|
||||
.put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), maxActionsPerRequest)
|
||||
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(60))
|
||||
.build();
|
||||
|
@ -187,8 +185,6 @@ public class ClientTest extends TestBase {
|
|||
assertEquals(maxthreads * actions, client.getBulkMetric().getSucceeded().getCount());
|
||||
} catch (NoNodeAvailableException e) {
|
||||
logger.warn("skipping, no node available");
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (client.getBulkController().getLastBulkError() != null) {
|
||||
logger.error("error", client.getBulkController().getLastBulkError());
|
||||
|
|
|
@ -3,8 +3,10 @@ package org.xbib.elx.node.test;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Test;
|
||||
import org.xbib.elx.common.ClientBuilder;
|
||||
import org.xbib.elx.common.Parameters;
|
||||
|
@ -18,7 +20,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class DuplicateIDTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(DuplicateIDTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(DuplicateIDTest.class.getName());
|
||||
|
||||
private static final Long MAX_ACTIONS_PER_REQUEST = 1000L;
|
||||
|
||||
|
@ -39,11 +41,13 @@ public class DuplicateIDTest extends TestBase {
|
|||
client.flush();
|
||||
client.waitForResponses(30L, TimeUnit.SECONDS);
|
||||
client.refreshIndex("test");
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.getClient(), SearchAction.INSTANCE)
|
||||
.setIndices("test")
|
||||
.setTypes("test")
|
||||
.setQuery(matchAllQuery());
|
||||
long hits = searchRequestBuilder.execute().actionGet().getHits().getTotalHits();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchAllQuery());
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("test");
|
||||
searchRequest.types("test");
|
||||
searchRequest.source(builder);
|
||||
long hits = client("1").execute(SearchAction.INSTANCE, searchRequest).actionGet().getHits().getTotalHits();
|
||||
logger.info("hits = {}", hits);
|
||||
assertTrue(hits < ACTIONS);
|
||||
} catch (NoNodeAvailableException e) {
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package org.xbib.elx.node.test;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.junit.Test;
|
||||
import org.xbib.elx.api.IndexPruneResult;
|
||||
import org.xbib.elx.common.ClientBuilder;
|
||||
import org.xbib.elx.node.ExtendedNodeClient;
|
||||
import org.xbib.elx.node.ExtendedNodeClientProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IndexPruneTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(IndexShiftTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void testPrune() throws IOException {
|
||||
final ExtendedNodeClient client = ClientBuilder.builder(client("1"))
|
||||
.provider(ExtendedNodeClientProvider.class)
|
||||
.build();
|
||||
try {
|
||||
Settings settings = Settings.builder()
|
||||
.put("index.number_of_shards", 1)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.build();
|
||||
client.newIndex("test1", settings);
|
||||
client.shiftIndex("test", "test1", Collections.emptyList());
|
||||
client.newIndex("test2", settings);
|
||||
client.shiftIndex("test", "test2", Collections.emptyList());
|
||||
client.newIndex("test3", settings);
|
||||
client.shiftIndex("test", "test3", Collections.emptyList());
|
||||
client.newIndex("test4", settings);
|
||||
client.shiftIndex("test", "test4", Collections.emptyList());
|
||||
|
||||
IndexPruneResult indexPruneResult =
|
||||
client.pruneIndex("test", "test4", 2, 2, true);
|
||||
|
||||
assertTrue(indexPruneResult.getDeletedIndices().contains("test1"));
|
||||
assertTrue(indexPruneResult.getDeletedIndices().contains("test2"));
|
||||
assertFalse(indexPruneResult.getDeletedIndices().contains("test3"));
|
||||
assertFalse(indexPruneResult.getDeletedIndices().contains("test4"));
|
||||
|
||||
List<Boolean> list = new ArrayList<>();
|
||||
for (String index : Arrays.asList("test1", "test2", "test3", "test4")) {
|
||||
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest();
|
||||
indicesExistsRequest.indices(index);
|
||||
IndicesExistsResponse indicesExistsResponse =
|
||||
client.getClient().execute(IndicesExistsAction.INSTANCE, indicesExistsRequest).actionGet();
|
||||
list.add(indicesExistsResponse.isExists());
|
||||
}
|
||||
logger.info(list);
|
||||
assertFalse(list.get(0));
|
||||
assertFalse(list.get(1));
|
||||
assertTrue(list.get(2));
|
||||
assertTrue(list.get(3));
|
||||
} catch (NoNodeAvailableException e) {
|
||||
logger.warn("skipping, no node available");
|
||||
} finally {
|
||||
client.close();
|
||||
if (client.getBulkController().getLastBulkError() != null) {
|
||||
logger.error("error", client.getBulkController().getLastBulkError());
|
||||
}
|
||||
assertNull(client.getBulkController().getLastBulkError());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
public class IndexShiftTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(IndexShiftTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(IndexShiftTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void testIndexShift() throws Exception {
|
||||
|
|
|
@ -30,7 +30,7 @@ import static org.junit.Assert.assertNull;
|
|||
@Ignore
|
||||
public class ReplicaTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ReplicaTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(ReplicaTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void testReplicaLevel() throws Exception {
|
||||
|
|
|
@ -17,7 +17,7 @@ import static org.junit.Assert.assertNull;
|
|||
|
||||
public class SmokeTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(SmokeTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(SmokeTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void smokeTest() throws Exception {
|
||||
|
@ -25,29 +25,26 @@ public class SmokeTest extends TestBase {
|
|||
.provider(ExtendedNodeClientProvider.class)
|
||||
.build();
|
||||
try {
|
||||
assertEquals(getClusterName(), client.getClusterName());
|
||||
|
||||
client.newIndex("test");
|
||||
client.index("test", "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest
|
||||
client.update("test", "1", "{ \"name\" : \"Another name\"}");
|
||||
client.delete("test", "1");
|
||||
client.flush();
|
||||
client.waitForResponses(30, TimeUnit.SECONDS);
|
||||
|
||||
assertEquals(getClusterName(), client.getClusterName());
|
||||
|
||||
client.checkMapping("test");
|
||||
|
||||
client.update("test", "1", "{ \"name\" : \"Another name\"}");
|
||||
client.flush();
|
||||
|
||||
client.waitForRecovery("test", 10L, TimeUnit.SECONDS);
|
||||
|
||||
client.delete("test", "1");
|
||||
client.deleteIndex("test");
|
||||
|
||||
IndexDefinition indexDefinition = client.buildIndexDefinitionFromSettings("test", Settings.builder()
|
||||
.build());
|
||||
assertEquals(0, indexDefinition.getReplicaLevel());
|
||||
client.newIndex(indexDefinition);
|
||||
client.waitForRecovery(indexDefinition.getFullIndexName(), 30L, TimeUnit.SECONDS);
|
||||
client.index(indexDefinition.getFullIndexName(), "1", true, "{ \"name\" : \"Hello World\"}");
|
||||
client.flush();
|
||||
client.waitForResponses(30, TimeUnit.SECONDS);
|
||||
client.updateReplicaLevel(indexDefinition, 2);
|
||||
|
||||
int replica = client.getReplicaLevel(indexDefinition);
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
|
||||
import org.elasticsearch.client.support.AbstractClient;
|
||||
|
@ -36,7 +36,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TestBase {
|
||||
|
||||
|
@ -50,8 +49,6 @@ public class TestBase {
|
|||
|
||||
private Map<String, AbstractClient> clients = new HashMap<>();
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
private String cluster;
|
||||
|
||||
private String host;
|
||||
|
@ -62,7 +59,7 @@ public class TestBase {
|
|||
public void startNodes() {
|
||||
try {
|
||||
logger.info("starting");
|
||||
this.cluster = "test-cluster-" + counter.incrementAndGet();
|
||||
this.cluster = "test-cluster-" + System.getProperty("user.name");
|
||||
startNode("1");
|
||||
findNodeAddress();
|
||||
try {
|
||||
|
@ -76,9 +73,10 @@ public class TestBase {
|
|||
} catch (ElasticsearchTimeoutException e) {
|
||||
throw new IOException("cluster does not respond to health request, cowardly refusing to continue");
|
||||
}
|
||||
ClusterStateRequestBuilder clusterStateRequestBuilder =
|
||||
new ClusterStateRequestBuilder(client("1"), ClusterStateAction.INSTANCE).all();
|
||||
ClusterStateResponse clusterStateResponse = clusterStateRequestBuilder.execute().actionGet();
|
||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.all();
|
||||
ClusterStateResponse clusterStateResponse =
|
||||
client("1").execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
|
||||
logger.info("cluster name = {}", clusterStateResponse.getClusterName().value());
|
||||
logger.info("host = {} port = {}", host, port);
|
||||
} catch (Throwable t) {
|
||||
|
|
|
@ -108,7 +108,6 @@ public class ExtendedTransportClient extends AbstractExtendedClient {
|
|||
addresses.add(address);
|
||||
}
|
||||
}
|
||||
logger.info("configured addresses = {}", addresses);
|
||||
return addresses;
|
||||
}
|
||||
|
||||
|
@ -116,7 +115,6 @@ public class ExtendedTransportClient extends AbstractExtendedClient {
|
|||
if (getClient() == null) {
|
||||
throw new IllegalStateException("no client present");
|
||||
}
|
||||
logger.debug("trying to connect to {}", addresses);
|
||||
TransportClient transportClient = (TransportClient) getClient();
|
||||
for (TransportAddress address : addresses) {
|
||||
transportClient.addTransportAddresses(address);
|
||||
|
|
|
@ -6,13 +6,15 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
|
|||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xbib.elx.common.ClientBuilder;
|
||||
|
@ -32,7 +34,7 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
public class ClientTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ClientTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(ClientTest.class.getName());
|
||||
|
||||
private static final Long ACTIONS = 25000L;
|
||||
|
||||
|
@ -137,10 +139,14 @@ public class ClientTest extends TestBase {
|
|||
}
|
||||
assertNull(client.getBulkController().getLastBulkError());
|
||||
client.refreshIndex("test");
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.getClient(), SearchAction.INSTANCE)
|
||||
.setQuery(QueryBuilders.matchAllQuery()).setSize(0);
|
||||
assertEquals(numactions,
|
||||
searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchAllQuery());
|
||||
builder.size(0);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("test");
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse = client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
assertEquals(numactions, searchResponse.getHits().getTotalHits());
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
@ -200,10 +206,14 @@ public class ClientTest extends TestBase {
|
|||
}
|
||||
assertNull(client.getBulkController().getLastBulkError());
|
||||
client.refreshIndex("test");
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.getClient(), SearchAction.INSTANCE)
|
||||
.setQuery(QueryBuilders.matchAllQuery()).setSize(0);
|
||||
assertEquals(maxthreads * actions,
|
||||
searchRequestBuilder.execute().actionGet().getHits().getTotalHits());
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchAllQuery());
|
||||
builder.size(0);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("test");
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse = client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
assertEquals(maxthreads * actions, searchResponse.getHits().getTotalHits());
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@ package org.xbib.elx.transport.test;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Test;
|
||||
import org.xbib.elx.common.ClientBuilder;
|
||||
import org.xbib.elx.common.Parameters;
|
||||
|
@ -13,14 +16,13 @@ import org.xbib.elx.transport.ExtendedTransportClientProvider;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class DuplicateIDTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(DuplicateIDTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(DuplicateIDTest.class.getName());
|
||||
|
||||
private static final Long MAX_ACTIONS_PER_REQUEST = 1000L;
|
||||
|
||||
|
@ -42,11 +44,16 @@ public class DuplicateIDTest extends TestBase {
|
|||
client.flush();
|
||||
client.waitForResponses(30L, TimeUnit.SECONDS);
|
||||
client.refreshIndex("test");
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.getClient(), SearchAction.INSTANCE)
|
||||
.setIndices("test")
|
||||
.setTypes("test")
|
||||
.setQuery(matchAllQuery());
|
||||
long hits = searchRequestBuilder.execute().actionGet().getHits().getTotalHits();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchAllQuery());
|
||||
builder.size(0);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("test");
|
||||
searchRequest.types("test");
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse =
|
||||
client("1").execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
long hits = searchResponse.getHits().getTotalHits();
|
||||
logger.info("hits = {}", hits);
|
||||
assertTrue(hits < ACTIONS);
|
||||
} catch (NoNodeAvailableException e) {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package org.xbib.elx.transport.test;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.junit.Test;
|
||||
import org.xbib.elx.api.IndexPruneResult;
|
||||
import org.xbib.elx.common.ClientBuilder;
|
||||
import org.xbib.elx.transport.ExtendedTransportClient;
|
||||
import org.xbib.elx.transport.ExtendedTransportClientProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IndexPruneTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(IndexShiftTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void testPrune() throws IOException {
|
||||
final ExtendedTransportClient client = ClientBuilder.builder()
|
||||
.provider(ExtendedTransportClientProvider.class)
|
||||
.put(getTransportSettings())
|
||||
.build();
|
||||
try {
|
||||
Settings settings = Settings.builder()
|
||||
.put("index.number_of_shards", 1)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.build();
|
||||
client.newIndex("test1", settings);
|
||||
client.shiftIndex("test", "test1", Collections.emptyList());
|
||||
client.newIndex("test2", settings);
|
||||
client.shiftIndex("test", "test2", Collections.emptyList());
|
||||
client.newIndex("test3", settings);
|
||||
client.shiftIndex("test", "test3", Collections.emptyList());
|
||||
client.newIndex("test4", settings);
|
||||
client.shiftIndex("test", "test4", Collections.emptyList());
|
||||
|
||||
IndexPruneResult indexPruneResult =
|
||||
client.pruneIndex("test", "test4", 2, 2, true);
|
||||
|
||||
assertTrue(indexPruneResult.getDeletedIndices().contains("test1"));
|
||||
assertTrue(indexPruneResult.getDeletedIndices().contains("test2"));
|
||||
assertFalse(indexPruneResult.getDeletedIndices().contains("test3"));
|
||||
assertFalse(indexPruneResult.getDeletedIndices().contains("test4"));
|
||||
|
||||
List<Boolean> list = new ArrayList<>();
|
||||
for (String index : Arrays.asList("test1", "test2", "test3", "test4")) {
|
||||
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest();
|
||||
indicesExistsRequest.indices(index);
|
||||
IndicesExistsResponse indicesExistsResponse =
|
||||
client.getClient().execute(IndicesExistsAction.INSTANCE, indicesExistsRequest).actionGet();
|
||||
list.add(indicesExistsResponse.isExists());
|
||||
}
|
||||
logger.info(list);
|
||||
assertFalse(list.get(0));
|
||||
assertFalse(list.get(1));
|
||||
assertTrue(list.get(2));
|
||||
assertTrue(list.get(3));
|
||||
} catch (NoNodeAvailableException e) {
|
||||
logger.warn("skipping, no node available");
|
||||
} finally {
|
||||
client.close();
|
||||
if (client.getBulkController().getLastBulkError() != null) {
|
||||
logger.error("error", client.getBulkController().getLastBulkError());
|
||||
}
|
||||
assertNull(client.getBulkController().getLastBulkError());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ import static org.junit.Assert.assertTrue;
|
|||
@Ignore
|
||||
public class IndexShiftTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(IndexShiftTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(IndexShiftTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void testIndexShift() throws Exception {
|
||||
|
|
|
@ -6,13 +6,16 @@ import org.elasticsearch.action.admin.indices.stats.CommonStats;
|
|||
import org.elasticsearch.action.admin.indices.stats.IndexShardStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndexStats;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.shard.IndexingStats;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.xbib.elx.common.ClientBuilder;
|
||||
|
@ -23,14 +26,13 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@Ignore
|
||||
public class ReplicaTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ReplicaTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(ReplicaTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void testReplicaLevel() throws Exception {
|
||||
|
@ -73,15 +75,21 @@ public class ReplicaTest extends TestBase {
|
|||
logger.info("refreshing");
|
||||
client.refreshIndex("test1");
|
||||
client.refreshIndex("test2");
|
||||
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client.getClient(), SearchAction.INSTANCE)
|
||||
.setIndices("test1", "test2")
|
||||
.setQuery(matchAllQuery());
|
||||
long hits = searchRequestBuilder.execute().actionGet().getHits().getTotalHits();
|
||||
SearchSourceBuilder builder = new SearchSourceBuilder();
|
||||
builder.query(QueryBuilders.matchAllQuery());
|
||||
builder.size(0);
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices("test1", "test2");
|
||||
searchRequest.source(builder);
|
||||
SearchResponse searchResponse =
|
||||
client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
||||
long hits = searchResponse.getHits().getTotalHits();
|
||||
logger.info("query total hits={}", hits);
|
||||
assertEquals(2468, hits);
|
||||
IndicesStatsRequestBuilder indicesStatsRequestBuilder = new IndicesStatsRequestBuilder(client.getClient(), IndicesStatsAction.INSTANCE)
|
||||
.all();
|
||||
IndicesStatsResponse response = indicesStatsRequestBuilder.execute().actionGet();
|
||||
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
|
||||
indicesStatsRequest.all();
|
||||
IndicesStatsResponse response =
|
||||
client.getClient().execute(IndicesStatsAction.INSTANCE, indicesStatsRequest).actionGet();
|
||||
for (Map.Entry<String, IndexStats> m : response.getIndices().entrySet()) {
|
||||
IndexStats indexStats = m.getValue();
|
||||
CommonStats commonStats = indexStats.getTotal();
|
||||
|
|
|
@ -17,7 +17,7 @@ import static org.junit.Assert.assertNull;
|
|||
|
||||
public class SmokeTest extends TestBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(SmokeTest.class.getSimpleName());
|
||||
private static final Logger logger = LogManager.getLogger(SmokeTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void smokeTest() throws Exception {
|
||||
|
@ -27,21 +27,14 @@ public class SmokeTest extends TestBase {
|
|||
.put(getTransportSettings())
|
||||
.build();
|
||||
try {
|
||||
assertEquals(getClusterName(), client.getClusterName());
|
||||
client.newIndex("test");
|
||||
client.index("test", "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest
|
||||
client.update("test", "1", "{ \"name\" : \"Another name\"}");
|
||||
client.delete("test", "1");
|
||||
client.flush();
|
||||
client.waitForResponses(30, TimeUnit.SECONDS);
|
||||
|
||||
assertEquals(getClusterName(), client.getClusterName());
|
||||
|
||||
client.checkMapping("test");
|
||||
|
||||
client.update("test", "1", "{ \"name\" : \"Another name\"}");
|
||||
client.flush();
|
||||
|
||||
client.waitForRecovery("test", 10L, TimeUnit.SECONDS);
|
||||
|
||||
client.delete("test", "1");
|
||||
client.deleteIndex("test");
|
||||
|
||||
IndexDefinition indexDefinition = client.buildIndexDefinitionFromSettings("test", Settings.builder()
|
||||
|
@ -50,8 +43,8 @@ public class SmokeTest extends TestBase {
|
|||
client.newIndex(indexDefinition);
|
||||
client.index(indexDefinition.getFullIndexName(), "1", true, "{ \"name\" : \"Hello World\"}");
|
||||
client.flush();
|
||||
client.waitForResponses(30, TimeUnit.SECONDS);
|
||||
client.updateReplicaLevel(indexDefinition, 2);
|
||||
|
||||
int replica = client.getReplicaLevel(indexDefinition);
|
||||
assertEquals(2, replica);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
|
||||
import org.elasticsearch.client.support.AbstractClient;
|
||||
|
@ -36,7 +36,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TestBase {
|
||||
|
||||
|
@ -50,8 +49,6 @@ public class TestBase {
|
|||
|
||||
private Map<String, AbstractClient> clients = new HashMap<>();
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
private String cluster;
|
||||
|
||||
private String host;
|
||||
|
@ -62,7 +59,7 @@ public class TestBase {
|
|||
public void startNodes() {
|
||||
try {
|
||||
logger.info("starting");
|
||||
this.cluster = "test-cluster-" + counter.incrementAndGet();
|
||||
this.cluster = "test-cluster-" + System.getProperty("user.name");
|
||||
startNode("1");
|
||||
findNodeAddress();
|
||||
try {
|
||||
|
@ -76,9 +73,10 @@ public class TestBase {
|
|||
} catch (ElasticsearchTimeoutException e) {
|
||||
throw new IOException("cluster does not respond to health request, cowardly refusing to continue");
|
||||
}
|
||||
ClusterStateRequestBuilder clusterStateRequestBuilder =
|
||||
new ClusterStateRequestBuilder(client("1"), ClusterStateAction.INSTANCE).all();
|
||||
ClusterStateResponse clusterStateResponse = clusterStateRequestBuilder.execute().actionGet();
|
||||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
|
||||
clusterStateRequest.all();
|
||||
ClusterStateResponse clusterStateResponse =
|
||||
client("1").execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
|
||||
logger.info("cluster name = {}", clusterStateResponse.getClusterName().value());
|
||||
logger.info("host = {} port = {}", host, port);
|
||||
} catch (Throwable t) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
group = org.xbib
|
||||
name = elx
|
||||
version = 6.3.2.0
|
||||
version = 6.3.2.1
|
||||
profile = default
|
||||
release = 0
|
||||
|
||||
elasticsearch-server.version = 6.3.2.2
|
||||
log4j.version = 2.11.1
|
||||
xbib-metrics.version = 1.1.0
|
||||
xbib-metrics.version = 1.2.0
|
||||
xbib-netty-http.version = 4.1.33.0
|
||||
|
||||
# test
|
||||
|
|
Loading…
Reference in a new issue