From 40cdde3ae86a7cdcc11498fc2340f84b829c6f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Thu, 22 Apr 2021 16:44:18 +0200 Subject: [PATCH] align with es221, cluster health, no IOException in Admin API --- .../java/org/xbib/elx/api/BasicClient.java | 23 ++------- .../java/org/xbib/elx/api/BulkClient.java | 13 ++--- .../java/org/xbib/elx/api/BulkProcessor.java | 5 +- .../xbib/elx/common/AbstractAdminClient.java | 9 ++-- .../xbib/elx/common/AbstractBasicClient.java | 45 +++++++--------- .../xbib/elx/common/AbstractBulkClient.java | 51 +++++++++++-------- .../xbib/elx/common/AbstractSearchClient.java | 2 +- .../xbib/elx/common/DefaultBulkProcessor.java | 4 +- .../xbib/elx/common/DefaultSearchMetric.java | 6 ++- .../org/xbib/elx/common/MockAdminClient.java | 10 ---- .../org/xbib/elx/common/MockBulkClient.java | 4 -- .../org/xbib/elx/common/MockSearchClient.java | 6 --- .../java/org/xbib/elx/common/Parameters.java | 4 ++ .../org/xbib/elx/http/HttpAdminClient.java | 6 +-- .../org/xbib/elx/http/HttpBulkClient.java | 2 +- .../org/xbib/elx/http/HttpClientHelper.java | 8 ++- .../org/xbib/elx/http/HttpSearchClient.java | 4 +- .../xbib/elx/http/test/BulkClientTest.java | 10 ++-- .../org/xbib/elx/http/test/DumpIDTest.java | 2 + .../xbib/elx/http/test/DuplicateIDTest.java | 2 +- .../xbib/elx/http/test/IndexPruneTest.java | 4 +- .../xbib/elx/http/test/IndexShiftTest.java | 4 +- .../org/xbib/elx/http/test/SearchTest.java | 4 +- .../org/xbib/elx/http/test/SmokeTest.java | 17 +++---- .../org/xbib/elx/http/test/TestExtension.java | 36 ++----------- .../xbib/elx/node/test/BulkClientTest.java | 12 ++--- .../xbib/elx/node/test/DuplicateIDTest.java | 2 +- .../xbib/elx/node/test/IndexPruneTest.java | 4 +- .../xbib/elx/node/test/IndexShiftTest.java | 4 +- .../org/xbib/elx/node/test/SearchTest.java | 4 +- .../org/xbib/elx/node/test/SmokeTest.java | 17 +++---- .../org/xbib/elx/node/test/TestExtension.java | 36 ++----------- .../elx/transport/TransportAdminClient.java | 6 +-- .../elx/transport/TransportBulkClient.java | 5 +- .../elx/transport/TransportClientHelper.java | 27 ++++++---- .../elx/transport/TransportSearchClient.java | 5 +- .../elx/transport/test/BulkClientTest.java | 8 +-- .../xbib/elx/transport/test/DumpIDTest.java | 2 + .../elx/transport/test/DuplicateIDTest.java | 2 +- .../elx/transport/test/IndexPruneTest.java | 4 +- .../elx/transport/test/IndexShiftTest.java | 4 +- .../xbib/elx/transport/test/SearchTest.java | 4 +- .../xbib/elx/transport/test/SmokeTest.java | 17 +++---- .../elx/transport/test/TestExtension.java | 28 ++-------- gradle.properties | 2 +- 45 files changed, 179 insertions(+), 295 deletions(-) diff --git a/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java b/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java index b65d05a..62b767b 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java +++ b/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java @@ -3,13 +3,12 @@ package org.xbib.elx.api; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; public interface BasicClient extends Closeable { - void putClusterSetting(String key, Object value, long timeout, TimeUnit timeUnit) throws IOException; + void putClusterSetting(String key, Object value, long timeout, TimeUnit timeUnit); /** * Set an Elasticsearch client to extend from it. May be null for TransportClient. @@ -24,14 +23,7 @@ public interface BasicClient extends Closeable { */ ElasticsearchClient getClient(); - /** - * Initiative the extended client, the bulk metric and bulk controller, - * creates instances and connect to cluster, if required. - * - * @param settings settings - * @throws IOException if init fails - */ - void init(Settings settings) throws IOException; + void init(Settings settings); /** * Get cluster name. @@ -48,16 +40,7 @@ public interface BasicClient extends Closeable { */ String getHealthColor(long maxWaitTime, TimeUnit timeUnit); - /** - * Wait for cluster being healthy. - * - * @param healthColor cluster health color to wait for - * @param maxWaitTime time value - * @param timeUnit time unit - */ - void waitForCluster(String healthColor, long maxWaitTime, TimeUnit timeUnit); - - void waitForShards(long maxWaitTime, TimeUnit timeUnit); + void waitForHealthyCluster(); long getSearchableDocs(IndexDefinition indexDefinition); diff --git a/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java b/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java index 2ce2fc6..28b9e3a 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java +++ b/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java @@ -5,7 +5,6 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.common.bytes.BytesReference; import java.io.Flushable; -import java.io.IOException; import java.util.concurrent.TimeUnit; public interface BulkClient extends BasicClient, Flushable { @@ -13,24 +12,21 @@ public interface BulkClient extends BasicClient, Flushable { /** * Create a new index. * @param indexDefinition the index definition - * @throws IOException if settings/mapping is invalid or index creation fails */ - void newIndex(IndexDefinition indexDefinition) throws IOException; + void newIndex(IndexDefinition indexDefinition); /** * Start bulk mode for indexes. * @param indexDefinition index definition - * @throws IOException if bulk could not be started */ - void startBulk(IndexDefinition indexDefinition) throws IOException; + void startBulk(IndexDefinition indexDefinition); /** * Stop bulk mode. * * @param indexDefinition index definition - * @throws IOException if bulk could not be startet */ - void stopBulk(IndexDefinition indexDefinition) throws IOException; + void stopBulk(IndexDefinition indexDefinition); /** * Add index request. Each request will be added to a queue for bulking requests. @@ -131,9 +127,8 @@ public interface BulkClient extends BasicClient, Flushable { * @param value the new value * @param timeout timeout * @param timeUnit time unit - * @throws IOException if update index setting failed */ - void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException; + void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit); /** * Refresh the index. diff --git a/elx-api/src/main/java/org/xbib/elx/api/BulkProcessor.java b/elx-api/src/main/java/org/xbib/elx/api/BulkProcessor.java index 82d9d7e..92786af 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/BulkProcessor.java +++ b/elx-api/src/main/java/org/xbib/elx/api/BulkProcessor.java @@ -4,16 +4,15 @@ import org.elasticsearch.action.DocWriteRequest; import java.io.Closeable; import java.io.Flushable; -import java.io.IOException; import java.util.concurrent.TimeUnit; public interface BulkProcessor extends Closeable, Flushable { void setEnabled(boolean enabled); - void startBulkMode(IndexDefinition indexDefinition) throws IOException; + void startBulkMode(IndexDefinition indexDefinition); - void stopBulkMode(IndexDefinition indexDefinition) throws IOException; + void stopBulkMode(IndexDefinition indexDefinition); void add(DocWriteRequest request); diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java index e05ac5b..193727f 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java @@ -105,7 +105,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements ensureClientIsPresent(); DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest().indices(index); client.execute(DeleteIndexAction.INSTANCE, deleteIndexRequest).actionGet(); - waitForCluster("GREEN", 300L, TimeUnit.SECONDS); + waitForHealthyCluster(); return this; } @@ -121,7 +121,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements logger.info("update replica level for " + indexDefinition + " to " + level); updateIndexSetting(indexDefinition.getFullIndexName(), "number_of_replicas", level, 30L, TimeUnit.SECONDS); - waitForCluster("GREEN", 300L, TimeUnit.SECONDS); + waitForHealthyCluster(); return this; } @@ -230,7 +230,6 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements if (index.equals(fullIndexName)) { return new EmptyIndexShiftResult(); // nothing to shift to } - waitForCluster("YELLOW", 30L, TimeUnit.SECONDS); // two situations: 1. a new alias 2. there is already an old index with the alias Optional oldIndex = resolveAlias(index).stream().sorted().findFirst(); Map oldAliasMap = oldIndex.map(this::getAliases).orElse(null); @@ -411,7 +410,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements if (forceMergeResponse.getFailedShards() > 0) { throw new IllegalStateException("failed shards after force merge: " + forceMergeResponse.getFailedShards()); } - waitForCluster("GREEN", 300L, TimeUnit.SECONDS); + waitForHealthyCluster(); return true; } @@ -423,7 +422,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(index) .settings(updateSettingsBuilder).timeout(toTimeValue(timeout, timeUnit)); client.execute(UpdateSettingsAction.INSTANCE, updateSettingsRequest).actionGet(); - waitForCluster("GREEN", 300L, TimeUnit.SECONDS); + waitForHealthyCluster(); } @Override diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java index 85137c4..26dc196 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java @@ -70,7 +70,7 @@ public abstract class AbstractBasicClient implements BasicClient { } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { if (closed.compareAndSet(false, true)) { logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(',')); this.settings = settings; @@ -99,13 +99,13 @@ public abstract class AbstractBasicClient implements BasicClient { } @Override - public void putClusterSetting(String key, Object value, long timeout, TimeUnit timeUnit) throws IOException { + public void putClusterSetting(String key, Object value, long timeout, TimeUnit timeUnit) { ensureClientIsPresent(); if (key == null) { - throw new IOException("no key given"); + throw new IllegalArgumentException("no key given"); } if (value == null) { - throw new IOException("no value given"); + throw new IllegalArgumentException("no value given"); } Settings.Builder updateSettingsBuilder = Settings.builder(); updateSettingsBuilder.put(key, value.toString()); @@ -115,8 +115,15 @@ public abstract class AbstractBasicClient implements BasicClient { } @Override - public void waitForCluster(String statusString, long maxWaitTime, TimeUnit timeUnit) { + public void waitForHealthyCluster() { ensureClientIsPresent(); + String statusString = settings.get(Parameters.CLUSTER_TARGET_HEALTH.getName(), + Parameters.CLUSTER_TARGET_HEALTH.getString()); + String waitTimeStr = settings.get(Parameters.CLUSTER_TARGET_HEALTH_TIMEOUT.getName(), + Parameters.CLUSTER_TARGET_HEALTH_TIMEOUT.getString()); + TimeValue timeValue = TimeValue.parseTimeValue(waitTimeStr, TimeValue.timeValueMinutes(30L), ""); + long maxWaitTime = timeValue.minutes(); + TimeUnit timeUnit = TimeUnit.MINUTES; logger.info("waiting for cluster status " + statusString + " for " + maxWaitTime + " " + timeUnit); ClusterHealthStatus status = ClusterHealthStatus.fromString(statusString); TimeValue timeout = toTimeValue(maxWaitTime, timeUnit); @@ -132,24 +139,6 @@ public abstract class AbstractBasicClient implements BasicClient { } } - @Override - public void waitForShards(long maxWaitTime, TimeUnit timeUnit) { - ensureClientIsPresent(); - logger.info("waiting for cluster shard settling"); - TimeValue timeout = toTimeValue(maxWaitTime, timeUnit); - ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest() - .waitForNoInitializingShards(true) - .waitForNoRelocatingShards(true) - .timeout(timeout); - ClusterHealthResponse healthResponse = - client.execute(ClusterHealthAction.INSTANCE, clusterHealthRequest).actionGet(); - if (healthResponse.isTimedOut()) { - String message = "timeout waiting for cluster shards: " + timeout; - logger.error(message); - throw new IllegalStateException(message); - } - } - @Override public String getHealthColor(long maxWaitTime, TimeUnit timeUnit) { ensureClientIsPresent(); @@ -205,20 +194,20 @@ public abstract class AbstractBasicClient implements BasicClient { } } - protected abstract ElasticsearchClient createClient(Settings settings) throws IOException; + protected abstract ElasticsearchClient createClient(Settings settings); protected abstract void closeClient(Settings settings) throws IOException; - protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException { + protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) { ensureClientIsPresent(); if (index == null) { - throw new IOException("no index name given"); + throw new IllegalArgumentException("no index name given"); } if (key == null) { - throw new IOException("no key given"); + throw new IllegalArgumentException("no key given"); } if (value == null) { - throw new IOException("no value given"); + throw new IllegalArgumentException("no value given"); } Settings.Builder updateSettingsBuilder = Settings.builder(); updateSettingsBuilder.put(key, value.toString()); diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java index ea84199..4110e9f 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java @@ -1,5 +1,6 @@ package org.xbib.elx.common; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.indices.create.CreateIndexAction; @@ -46,7 +47,7 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { if (closed.compareAndSet(true, false)) { super.init(settings); bulkProcessor = new DefaultBulkProcessor(this, settings); @@ -79,7 +80,7 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements } @Override - public void newIndex(IndexDefinition indexDefinition) throws IOException { + public void newIndex(IndexDefinition indexDefinition) { if (isIndexDefinitionDisabled(indexDefinition)) { return; } @@ -91,24 +92,32 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client, CreateIndexAction.INSTANCE) .setIndex(index); if (indexDefinition.getSettings() == null) { - XContentBuilder builder = JsonXContent.contentBuilder() - .startObject() - .startObject("index") - .field("number_of_shards", 1) - .field("number_of_replicas", 0) - .endObject() - .endObject(); - indexDefinition.setSettings(Strings.toString(builder)); + try { + XContentBuilder builder = JsonXContent.contentBuilder() + .startObject() + .startObject("index") + .field("number_of_shards", 1) + .field("number_of_replicas", 0) + .endObject() + .endObject(); + indexDefinition.setSettings(Strings.toString(builder)); + } catch (IOException e) { + logger.log(Level.WARN, e.getMessage(), e); + } } Settings settings = Settings.builder().loadFromSource(indexDefinition.getSettings(), XContentType.JSON).build(); createIndexRequestBuilder.setSettings(settings); - if (indexDefinition.getMappings() != null) { - Map mappings = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, indexDefinition.getMappings()).mapOrdered(); - createIndexRequestBuilder.addMapping(TYPE_NAME, mappings); - } else { - XContentBuilder builder = JsonXContent.contentBuilder().startObject().startObject(TYPE_NAME).endObject().endObject(); - createIndexRequestBuilder.addMapping(TYPE_NAME, builder); + try { + if (indexDefinition.getMappings() != null) { + Map mappings = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, + DeprecationHandler.THROW_UNSUPPORTED_OPERATION, indexDefinition.getMappings()).mapOrdered(); + createIndexRequestBuilder.addMapping(TYPE_NAME, mappings); + } else { + XContentBuilder builder = JsonXContent.contentBuilder().startObject().startObject(TYPE_NAME).endObject().endObject(); + createIndexRequestBuilder.addMapping(TYPE_NAME, builder); + } + } catch (IOException e) { + logger.log(Level.WARN, e.getMessage(), e); } CreateIndexResponse createIndexResponse = createIndexRequestBuilder.execute().actionGet(); if (createIndexResponse.isAcknowledged()) { @@ -118,11 +127,11 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements return; } // we really need state GREEN. If yellow, we may trigger shard write errors and queue will exceed quickly. - waitForCluster("GREEN", 300L, TimeUnit.SECONDS); + waitForHealthyCluster(); } @Override - public void startBulk(IndexDefinition indexDefinition) throws IOException { + public void startBulk(IndexDefinition indexDefinition) { if (isIndexDefinitionDisabled(indexDefinition)) { return; } @@ -133,7 +142,7 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements } @Override - public void stopBulk(IndexDefinition indexDefinition) throws IOException { + public void stopBulk(IndexDefinition indexDefinition) { if (isIndexDefinitionDisabled(indexDefinition)) { return; } @@ -216,7 +225,7 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements } @Override - public void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException { + public void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) { super.updateIndexSetting(index, key, value, timeout, timeUnit); } diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractSearchClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractSearchClient.java index c61aa19..dac8bf2 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractSearchClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractSearchClient.java @@ -49,7 +49,7 @@ public abstract class AbstractSearchClient extends AbstractBasicClient implement } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { if (closed.compareAndSet(true, false)) { super.init(settings); this.searchMetric = new DefaultSearchMetric(getScheduler(), settings); diff --git a/elx-common/src/main/java/org/xbib/elx/common/DefaultBulkProcessor.java b/elx-common/src/main/java/org/xbib/elx/common/DefaultBulkProcessor.java index aff75ac..d36d13f 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/DefaultBulkProcessor.java +++ b/elx-common/src/main/java/org/xbib/elx/common/DefaultBulkProcessor.java @@ -97,7 +97,7 @@ public class DefaultBulkProcessor implements BulkProcessor { } @Override - public void startBulkMode(IndexDefinition indexDefinition) throws IOException { + public void startBulkMode(IndexDefinition indexDefinition) { String indexName = indexDefinition.getFullIndexName(); int interval = indexDefinition.getStartBulkRefreshSeconds(); if (interval != 0) { @@ -110,7 +110,7 @@ public class DefaultBulkProcessor implements BulkProcessor { } @Override - public void stopBulkMode(IndexDefinition indexDefinition) throws IOException { + public void stopBulkMode(IndexDefinition indexDefinition) { String indexName = indexDefinition.getFullIndexName(); int interval = indexDefinition.getStopBulkRefreshSeconds(); flush(); diff --git a/elx-common/src/main/java/org/xbib/elx/common/DefaultSearchMetric.java b/elx-common/src/main/java/org/xbib/elx/common/DefaultSearchMetric.java index cde8c5f..2495f08 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/DefaultSearchMetric.java +++ b/elx-common/src/main/java/org/xbib/elx/common/DefaultSearchMetric.java @@ -125,7 +125,11 @@ public class DefaultSearchMetric implements SearchMetric { private void log() { if (logger.isInfoEnabled()) { - logger.info("docs = " + getTotalQueries().getCount()); + logger.info("queries = " + getTotalQueries().getCount() + + " succeeded = " + getSucceededQueries().getCount() + + " empty = " + getEmptyQueries().getCount() + + " failed = " + getFailedQueries() + + " timeouts = " + getTimeoutQueries().getCount()); } } } diff --git a/elx-common/src/main/java/org/xbib/elx/common/MockAdminClient.java b/elx-common/src/main/java/org/xbib/elx/common/MockAdminClient.java index 6e25fef..66619fd 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/MockAdminClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/MockAdminClient.java @@ -3,8 +3,6 @@ package org.xbib.elx.common; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; -import java.util.concurrent.TimeUnit; - /** * A mocked client, it does not perform any actions on a cluster. Useful for testing. */ @@ -28,14 +26,6 @@ public class MockAdminClient extends AbstractAdminClient { protected void closeClient(Settings settings) { } - @Override - public void waitForCluster(String healthColor, long timeValue, TimeUnit timeUnit) { - } - - @Override - public void waitForShards(long maxWaitTime, TimeUnit timeUnit) { - } - @Override public void close() { // nothing to do diff --git a/elx-common/src/main/java/org/xbib/elx/common/MockBulkClient.java b/elx-common/src/main/java/org/xbib/elx/common/MockBulkClient.java index e0e861b..0856fe5 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/MockBulkClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/MockBulkClient.java @@ -26,10 +26,6 @@ public class MockBulkClient extends AbstractBulkClient { return null; } - @Override - public void waitForShards(long maxWaitTime, TimeUnit timeUnit) { - } - @Override protected ElasticsearchClient createClient(Settings settings) { return null; diff --git a/elx-common/src/main/java/org/xbib/elx/common/MockSearchClient.java b/elx-common/src/main/java/org/xbib/elx/common/MockSearchClient.java index 9d182dc..82be6ef 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/MockSearchClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/MockSearchClient.java @@ -3,8 +3,6 @@ package org.xbib.elx.common; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; -import java.util.concurrent.TimeUnit; - /** * A mocked client, it does not perform any actions on a cluster. Useful for testing. */ @@ -24,10 +22,6 @@ public class MockSearchClient extends AbstractSearchClient { return null; } - @Override - public void waitForShards(long maxWaitTime, TimeUnit timeUnit) { - } - @Override protected ElasticsearchClient createClient(Settings settings) { return null; diff --git a/elx-common/src/main/java/org/xbib/elx/common/Parameters.java b/elx-common/src/main/java/org/xbib/elx/common/Parameters.java index 1dd55bc..30a3d9e 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/Parameters.java +++ b/elx-common/src/main/java/org/xbib/elx/common/Parameters.java @@ -2,6 +2,10 @@ package org.xbib.elx.common; public enum Parameters { + CLUSTER_TARGET_HEALTH("cluster.target_health", String.class, "GREEN"), + + CLUSTER_TARGET_HEALTH_TIMEOUT("cluster.target_health_timeout", String.class, "30m"), + DATE_TIME_FORMAT("dateTimeFormat", String.class, "yyyyMMdd"), BULK_MAX_WAIT_RESPONSE("bulk.max_wait_response", String.class, "30s"), diff --git a/elx-http/src/main/java/org/xbib/elx/http/HttpAdminClient.java b/elx-http/src/main/java/org/xbib/elx/http/HttpAdminClient.java index 13c3b4e..4e5d4f6 100644 --- a/elx-http/src/main/java/org/xbib/elx/http/HttpAdminClient.java +++ b/elx-http/src/main/java/org/xbib/elx/http/HttpAdminClient.java @@ -24,18 +24,18 @@ public class HttpAdminClient extends AbstractAdminClient implements Elasticsearc } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { super.init(settings); helper.init(settings); } @Override - protected ElasticsearchClient createClient(Settings settings) throws IOException { + protected ElasticsearchClient createClient(Settings settings) { return this; } @Override - protected void closeClient(Settings settings) throws IOException { + protected void closeClient(Settings settings) { helper.closeClient(settings); } diff --git a/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java b/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java index 1f196b4..33e2824 100644 --- a/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java +++ b/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java @@ -24,7 +24,7 @@ public class HttpBulkClient extends AbstractBulkClient implements ElasticsearchC } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { super.init(settings); helper.init(settings); } diff --git a/elx-http/src/main/java/org/xbib/elx/http/HttpClientHelper.java b/elx-http/src/main/java/org/xbib/elx/http/HttpClientHelper.java index be64ea5..59de54d 100644 --- a/elx-http/src/main/java/org/xbib/elx/http/HttpClientHelper.java +++ b/elx-http/src/main/java/org/xbib/elx/http/HttpClientHelper.java @@ -111,9 +111,13 @@ public class HttpClientHelper { return nettyHttpClient; } - protected void closeClient(Settings settings) throws IOException { + protected void closeClient(Settings settings) { if (closed.compareAndSet(false, true)) { - nettyHttpClient.shutdownGracefully(); + try { + nettyHttpClient.shutdownGracefully(); + } catch (IOException e) { + logger.log(Level.WARN, e.getMessage(), e); + } } } diff --git a/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java b/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java index f1d9a2d..3257284 100644 --- a/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java +++ b/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java @@ -24,13 +24,13 @@ public class HttpSearchClient extends AbstractSearchClient implements Elasticsea } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { super.init(settings); helper.init(settings); } @Override - protected ElasticsearchClient createClient(Settings settings) throws IOException { + protected ElasticsearchClient createClient(Settings settings) { return this; } diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/BulkClientTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/BulkClientTest.java index 3bdbf03..a24ac29 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/BulkClientTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/BulkClientTest.java @@ -2,13 +2,11 @@ package org.xbib.elx.http.test; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.common.unit.TimeValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.elx.api.IndexDefinition; import org.xbib.elx.common.ClientBuilder; import org.xbib.elx.common.DefaultIndexDefinition; -import org.xbib.elx.common.Parameters; import org.xbib.elx.http.HttpBulkClient; import org.xbib.elx.http.HttpBulkClientProvider; @@ -37,7 +35,7 @@ class BulkClientTest { void testNewIndex() throws Exception { try (HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -48,7 +46,7 @@ class BulkClientTest { void testSingleDoc() throws Exception { try (HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -68,7 +66,7 @@ class BulkClientTest { long numactions = ACTIONS; try (HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -94,7 +92,7 @@ class BulkClientTest { long timeout = 120L; try (HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/DumpIDTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/DumpIDTest.java index edc2508..789730d 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/DumpIDTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/DumpIDTest.java @@ -1,6 +1,7 @@ package org.xbib.elx.http.test; import org.elasticsearch.index.query.QueryBuilders; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.xbib.elx.api.IndexDefinition; import org.xbib.elx.common.ClientBuilder; @@ -14,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.stream.Stream; +@Disabled class DumpIDTest { @Test diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/DuplicateIDTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/DuplicateIDTest.java index 4539fef..acbbdbb 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/DuplicateIDTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/DuplicateIDTest.java @@ -34,7 +34,7 @@ class DuplicateIDTest { long numactions = ACTIONS; try (HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/IndexPruneTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/IndexPruneTest.java index c447ec5..3c0e98e 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/IndexPruneTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/IndexPruneTest.java @@ -40,11 +40,11 @@ class IndexPruneTest { void testPrune() throws IOException { try (HttpAdminClient adminClient = ClientBuilder.builder() .setAdminClientProvider(HttpAdminClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build(); HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setIndex("test"); diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/IndexShiftTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/IndexShiftTest.java index c0e1b62..ee3ea3a 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/IndexShiftTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/IndexShiftTest.java @@ -40,11 +40,11 @@ class IndexShiftTest { void testIndexShift() throws Exception { try (HttpAdminClient adminClient = ClientBuilder.builder() .setAdminClientProvider(HttpAdminClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build(); HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setFullIndexName("test_shift"); diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/SearchTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/SearchTest.java index 9f2b1b2..6f9f0b9 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/SearchTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/SearchTest.java @@ -39,7 +39,7 @@ class SearchTest { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); try (HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { bulkClient.newIndex(indexDefinition); for (int i = 0; i < ACTIONS; i++) { @@ -57,7 +57,7 @@ class SearchTest { } try (HttpSearchClient searchClient = ClientBuilder.builder() .setSearchClientProvider(HttpSearchClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { Stream stream = searchClient.search(qb -> qb .setIndices(indexDefinition.getFullIndexName()) diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/SmokeTest.java b/elx-http/src/test/java/org/xbib/elx/http/test/SmokeTest.java index eb2259e..f2e426c 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/SmokeTest.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/SmokeTest.java @@ -37,11 +37,11 @@ class SmokeTest { void smokeTest() throws Exception { try (HttpAdminClient adminClient = ClientBuilder.builder() .setAdminClientProvider(HttpAdminClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build(); HttpBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(HttpBulkClientProvider.class) - .put(helper.getHttpSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition(adminClient, "test_smoke", "doc", Settings.EMPTY); @@ -49,21 +49,20 @@ class SmokeTest { assertEquals(helper.getClusterName(), adminClient.getClusterName()); bulkClient.newIndex(indexDefinition); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); adminClient.checkMapping(indexDefinition); bulkClient.update(indexDefinition, "1", "{ \"name\" : \"Another name\"}"); bulkClient.delete(indexDefinition, "1"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); bulkClient.delete(indexDefinition, "1"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); adminClient.deleteIndex(indexDefinition); bulkClient.newIndex(indexDefinition); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); - adminClient.updateReplicaLevel(indexDefinition, 2); - int replica = adminClient.getReplicaLevel(indexDefinition); - assertEquals(2, replica); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); + adminClient.updateReplicaLevel(indexDefinition, 1); + assertEquals(1, adminClient.getReplicaLevel(indexDefinition)); assertEquals(0, bulkClient.getBulkProcessor().getBulkMetric().getFailed().getCount()); assertEquals(6, bulkClient.getBulkProcessor().getBulkMetric().getSucceeded().getCount()); if (bulkClient.getBulkProcessor().getLastBulkError() != null) { diff --git a/elx-http/src/test/java/org/xbib/elx/http/test/TestExtension.java b/elx-http/src/test/java/org/xbib/elx/http/test/TestExtension.java index a5c4641..1a4094e 100644 --- a/elx-http/src/test/java/org/xbib/elx/http/test/TestExtension.java +++ b/elx-http/src/test/java/org/xbib/elx/http/test/TestExtension.java @@ -3,21 +3,12 @@ package org.xbib.elx.http.test; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.ElasticsearchTimeoutException; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; 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.ClusterStateRequest; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.http.HttpInfo; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeValidationException; @@ -38,18 +29,10 @@ 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; -/** - * Junit 5 extension for testing Elasticsearch. - * The extension will be instantiated as a singleton. - * For parallel test method executions, for example in gradle, it requires a helper class - * to ensure different ES homes/clusters for each run. - */ public class TestExtension implements ParameterResolver, BeforeEachCallback, AfterEachCallback { private static final Logger logger = LogManager.getLogger("test"); @@ -93,21 +76,6 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft helper.httpHost = address.address().getHostName(); helper.httpPort = address.address().getPort(); logger.log(Level.INFO, "http host = " + helper.httpHost + " port = " + helper.httpPort); - try { - ClusterHealthResponse healthResponse = helper.client().execute(ClusterHealthAction.INSTANCE, - new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN) - .timeout(TimeValue.timeValueSeconds(30))).actionGet(); - if (healthResponse != null && healthResponse.isTimedOut()) { - throw new IOException("cluster state is " + healthResponse.getStatus().name() - + ", from here on, everything will fail!"); - } - } catch (ElasticsearchTimeoutException e) { - throw new IOException("cluster does not respond to health request, cowardly refusing to continue"); - } - ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all(); - ClusterStateResponse clusterStateResponse = - helper.client().execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet(); - logger.info("cluster name = {}", clusterStateResponse.getClusterName().value()); } @Override @@ -183,12 +151,14 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft return cluster; } - Settings getHttpSettings() { + Settings getClientSettings() { return Settings.builder() .put("cluster.name", getClusterName()) .put("path.home", getHome()) .put("host", httpHost) .put("port", httpPort) + .put("cluster.target_health", "YELLOW") + .put("cluster.target_health_timeout", "1m") .build(); } diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java index 5cb472d..00fe607 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/BulkClientTest.java @@ -2,15 +2,11 @@ package org.xbib.elx.node.test; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.json.JsonXContent; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.xbib.elx.api.IndexDefinition; import org.xbib.elx.common.ClientBuilder; import org.xbib.elx.common.DefaultIndexDefinition; -import org.xbib.elx.node.NodeAdminClient; -import org.xbib.elx.node.NodeAdminClientProvider; import org.xbib.elx.node.NodeBulkClient; import org.xbib.elx.node.NodeBulkClientProvider; @@ -39,7 +35,7 @@ class BulkClientTest { void testNewIndex() throws Exception { try (NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -50,7 +46,7 @@ class BulkClientTest { void testSingleDoc() throws Exception { try (NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -69,7 +65,7 @@ class BulkClientTest { long numactions = ACTIONS; try (NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -97,7 +93,7 @@ class BulkClientTest { long timeout = 120L; try (NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setStartBulkRefreshSeconds(0); diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/DuplicateIDTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/DuplicateIDTest.java index b9f3e02..d5241aa 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/DuplicateIDTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/DuplicateIDTest.java @@ -37,7 +37,7 @@ class DuplicateIDTest { long numactions = ACTIONS; try (NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .put(Parameters.BULK_MAX_ACTIONS_PER_REQUEST.getName(), MAX_ACTIONS_PER_REQUEST) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/IndexPruneTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/IndexPruneTest.java index 5560139..bae31c9 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/IndexPruneTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/IndexPruneTest.java @@ -40,11 +40,11 @@ class IndexPruneTest { void testPrune() throws IOException { try (NodeAdminClient adminClient = ClientBuilder.builder(helper.client()) .setAdminClientProvider(NodeAdminClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build(); NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setIndex("test_prune"); diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java index 741aeac..5f3fe68 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/IndexShiftTest.java @@ -39,11 +39,11 @@ class IndexShiftTest { void testIndexShift() throws Exception { try (NodeAdminClient adminClient = ClientBuilder.builder(helper.client()) .setAdminClientProvider(NodeAdminClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build(); NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setFullIndexName("test_shift"); diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/SearchTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/SearchTest.java index 78e2ba1..7872329 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/SearchTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/SearchTest.java @@ -43,7 +43,7 @@ class SearchTest { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); try (NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .put(Parameters.BULK_MAX_ACTIONS_PER_REQUEST.getName(), MAX_ACTIONS_PER_REQUEST) .build()) { bulkClient.newIndex(indexDefinition); @@ -64,7 +64,7 @@ class SearchTest { } try (NodeSearchClient searchClient = ClientBuilder.builder(helper.client()) .setSearchClientProvider(NodeSearchClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { // test stream count Stream stream = searchClient.search(qb -> qb diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/SmokeTest.java b/elx-node/src/test/java/org/xbib/elx/node/test/SmokeTest.java index bc431ca..a4181c2 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/SmokeTest.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/SmokeTest.java @@ -37,11 +37,11 @@ class SmokeTest { void smokeTest() throws Exception { try (NodeAdminClient adminClient = ClientBuilder.builder(helper.client()) .setAdminClientProvider(NodeAdminClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build(); NodeBulkClient bulkClient = ClientBuilder.builder(helper.client()) .setBulkClientProvider(NodeBulkClientProvider.class) - .put(helper.getNodeSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition(adminClient, "test_smoke", "doc", Settings.EMPTY); @@ -52,21 +52,20 @@ class SmokeTest { indexDefinition.setType("doc"); bulkClient.newIndex(indexDefinition); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); adminClient.checkMapping(indexDefinition); bulkClient.update(indexDefinition, "1", "{ \"name\" : \"Another name\"}"); bulkClient.delete(indexDefinition, "1"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); bulkClient.delete(indexDefinition, "1"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); adminClient.deleteIndex(indexDefinition); bulkClient.newIndex(indexDefinition); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); - adminClient.updateReplicaLevel(indexDefinition, 2); - int replica = adminClient.getReplicaLevel(indexDefinition); - assertEquals(2, replica); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); + adminClient.updateReplicaLevel(indexDefinition, 1); + assertEquals(1, adminClient.getReplicaLevel(indexDefinition)); assertEquals(0, bulkClient.getBulkProcessor().getBulkMetric().getFailed().getCount()); assertEquals(6, bulkClient.getBulkProcessor().getBulkMetric().getSucceeded().getCount()); if (bulkClient.getBulkProcessor().getLastBulkError() != null) { diff --git a/elx-node/src/test/java/org/xbib/elx/node/test/TestExtension.java b/elx-node/src/test/java/org/xbib/elx/node/test/TestExtension.java index 51b865f..e557069 100644 --- a/elx-node/src/test/java/org/xbib/elx/node/test/TestExtension.java +++ b/elx-node/src/test/java/org/xbib/elx/node/test/TestExtension.java @@ -2,21 +2,12 @@ package org.xbib.elx.node.test; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.ElasticsearchTimeoutException; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; 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.ClusterStateRequest; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.plugins.Plugin; @@ -36,18 +27,10 @@ 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; -/** - * Junit 5 extension for testing Elasticsearch. - * The extension will be instantiated as a singleton. - * For parallel test method executions, for example in gradle, it requires a helper class - * to ensure different ES homes/clusters for each run. - */ public class TestExtension implements ParameterResolver, BeforeEachCallback, AfterEachCallback { private static final Logger logger = LogManager.getLogger("test"); @@ -89,21 +72,6 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft helper.host = address.address().getHostName(); helper.port = address.address().getPort(); logger.info("host = " + helper.host + " port = " + helper.port); - try { - ClusterHealthResponse healthResponse = helper.client().execute(ClusterHealthAction.INSTANCE, - new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN) - .timeout(TimeValue.timeValueSeconds(30))).actionGet(); - if (healthResponse != null && healthResponse.isTimedOut()) { - throw new IOException("cluster state is " + healthResponse.getStatus().name() - + ", from here on, everything will fail!"); - } - } catch (ElasticsearchTimeoutException e) { - throw new IOException("cluster does not respond to health request, cowardly refusing to continue"); - } - ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all(); - ClusterStateResponse clusterStateResponse = - helper.client().execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet(); - logger.info("cluster up, name = {}", clusterStateResponse.getClusterName().value()); } @Override @@ -179,13 +147,15 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft return cluster; } - Settings getNodeSettings() { + Settings getClientSettings() { return Settings.builder() .put("cluster.name", getClusterName()) .put("path.home", getHome()) .put("node.max_local_storage_nodes", 2) .put("cluster.initial_master_nodes", "1") .put("discovery.seed_hosts", "127.0.0.1:9300") + .put("cluster.target_health", "YELLOW") + .put("cluster.target_health_timeout", "1m") .build(); } diff --git a/elx-transport/src/main/java/org/xbib/elx/transport/TransportAdminClient.java b/elx-transport/src/main/java/org/xbib/elx/transport/TransportAdminClient.java index 08b3cbc..ff5a88b 100644 --- a/elx-transport/src/main/java/org/xbib/elx/transport/TransportAdminClient.java +++ b/elx-transport/src/main/java/org/xbib/elx/transport/TransportAdminClient.java @@ -5,8 +5,6 @@ import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.xbib.elx.common.AbstractAdminClient; -import java.io.IOException; - /** * Transport admin client. */ @@ -20,12 +18,12 @@ public class TransportAdminClient extends AbstractAdminClient { } @Override - public ElasticsearchClient createClient(Settings settings) throws IOException { + public ElasticsearchClient createClient(Settings settings) { return helper.createClient(settings); } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { super.init(settings); helper.init((TransportClient) getClient(), settings); } diff --git a/elx-transport/src/main/java/org/xbib/elx/transport/TransportBulkClient.java b/elx-transport/src/main/java/org/xbib/elx/transport/TransportBulkClient.java index b591fc2..f7f9166 100644 --- a/elx-transport/src/main/java/org/xbib/elx/transport/TransportBulkClient.java +++ b/elx-transport/src/main/java/org/xbib/elx/transport/TransportBulkClient.java @@ -4,7 +4,6 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.xbib.elx.common.AbstractBulkClient; -import java.io.IOException; /** * Transport search client with additional methods. @@ -19,12 +18,12 @@ public class TransportBulkClient extends AbstractBulkClient { } @Override - public ElasticsearchClient createClient(Settings settings) throws IOException { + public ElasticsearchClient createClient(Settings settings) { return helper.createClient(settings); } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { super.init(settings); helper.init((TransportClient) getClient(), settings); } diff --git a/elx-transport/src/main/java/org/xbib/elx/transport/TransportClientHelper.java b/elx-transport/src/main/java/org/xbib/elx/transport/TransportClientHelper.java index bc74c1d..b718254 100644 --- a/elx-transport/src/main/java/org/xbib/elx/transport/TransportClientHelper.java +++ b/elx-transport/src/main/java/org/xbib/elx/transport/TransportClientHelper.java @@ -1,5 +1,6 @@ package org.xbib.elx.transport; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; @@ -55,7 +56,7 @@ public class TransportClientHelper { } } - public void init(TransportClient transportClient, Settings settings) throws IOException { + public void init(TransportClient transportClient, Settings settings) { Collection addrs = findAddresses(settings); if (!connect(transportClient, addrs, settings.getAsBoolean("autodiscover", false))) { throw new NoNodeAvailableException("no cluster nodes available, check settings = " @@ -63,7 +64,7 @@ public class TransportClientHelper { } } - private Collection findAddresses(Settings settings) throws IOException { + private Collection findAddresses(Settings settings) { final int defaultPort = settings.getAsInt("port", 9300); Collection addresses = new ArrayList<>(); for (String hostname : settings.getAsList("host")) { @@ -71,19 +72,27 @@ public class TransportClientHelper { if (splitHost.length == 2) { try { String host = splitHost[0]; - InetAddress inetAddress = NetworkUtils.resolveInetAddress(host, null); - int port = Integer.parseInt(splitHost[1]); - TransportAddress address = new TransportAddress(inetAddress, port); - addresses.add(address); + try { + InetAddress inetAddress = NetworkUtils.resolveInetAddress(host, null); + int port = Integer.parseInt(splitHost[1]); + TransportAddress address = new TransportAddress(inetAddress, port); + addresses.add(address); + } catch (IOException e) { + logger.log(Level.WARN, e.getMessage(), e); + } } catch (NumberFormatException e) { logger.warn(e.getMessage(), e); } } if (splitHost.length == 1) { String host = splitHost[0]; - InetAddress inetAddress = NetworkUtils.resolveInetAddress(host, null); - TransportAddress address = new TransportAddress(inetAddress, defaultPort); - addresses.add(address); + try { + InetAddress inetAddress = NetworkUtils.resolveInetAddress(host, null); + TransportAddress address = new TransportAddress(inetAddress, defaultPort); + addresses.add(address); + } catch (IOException e) { + logger.log(Level.WARN, e.getMessage(), e); + } } } return addresses; diff --git a/elx-transport/src/main/java/org/xbib/elx/transport/TransportSearchClient.java b/elx-transport/src/main/java/org/xbib/elx/transport/TransportSearchClient.java index 53bc8a7..eb39534 100644 --- a/elx-transport/src/main/java/org/xbib/elx/transport/TransportSearchClient.java +++ b/elx-transport/src/main/java/org/xbib/elx/transport/TransportSearchClient.java @@ -4,7 +4,6 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.xbib.elx.common.AbstractSearchClient; -import java.io.IOException; /** * Transport search client with additional methods. @@ -19,12 +18,12 @@ public class TransportSearchClient extends AbstractSearchClient { } @Override - public ElasticsearchClient createClient(Settings settings) throws IOException { + public ElasticsearchClient createClient(Settings settings) { return helper.createClient(settings); } @Override - public void init(Settings settings) throws IOException { + public void init(Settings settings) { super.init(settings); helper.init((TransportClient) getClient(), settings); } diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java index b4b287a..9f00e26 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/BulkClientTest.java @@ -35,7 +35,7 @@ class BulkClientTest { void testNewIndex() throws Exception { try (TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -46,7 +46,7 @@ class BulkClientTest { void testSingleDoc() throws Exception { try (TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -65,7 +65,7 @@ class BulkClientTest { long numactions = ACTIONS; try (TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); @@ -93,7 +93,7 @@ class BulkClientTest { final long timeout = 120L; try (TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/DumpIDTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/DumpIDTest.java index b6a18fd..a802191 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/DumpIDTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/DumpIDTest.java @@ -1,6 +1,7 @@ package org.xbib.elx.transport.test; import org.elasticsearch.index.query.QueryBuilders; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.xbib.elx.api.IndexDefinition; import org.xbib.elx.common.ClientBuilder; @@ -14,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.stream.Stream; +@Disabled class DumpIDTest { @Test diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/DuplicateIDTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/DuplicateIDTest.java index 20c9618..3fe40a4 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/DuplicateIDTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/DuplicateIDTest.java @@ -38,7 +38,7 @@ class DuplicateIDTest { try (TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) .put(Parameters.BULK_MAX_ACTIONS_PER_REQUEST.getName(), MAX_ACTIONS_PER_REQUEST) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); bulkClient.newIndex(indexDefinition); diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexPruneTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexPruneTest.java index cbe5132..43f7839 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexPruneTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexPruneTest.java @@ -40,11 +40,11 @@ class IndexPruneTest { void testPrune() throws IOException { try (TransportAdminClient adminClient = ClientBuilder.builder() .setAdminClientProvider(TransportAdminClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build(); TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setIndex("test_prune"); diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java index 521624b..30b0013 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/IndexShiftTest.java @@ -39,11 +39,11 @@ class IndexShiftTest { void testIndexShift() throws Exception { try (TransportAdminClient adminClient = ClientBuilder.builder() .setAdminClientProvider(TransportAdminClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build(); TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); indexDefinition.setFullIndexName("test_shift"); diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/SearchTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/SearchTest.java index d9762e2..c9dfc75 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/SearchTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/SearchTest.java @@ -40,7 +40,7 @@ class SearchTest { IndexDefinition indexDefinition = new DefaultIndexDefinition("test", "doc"); try (TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { bulkClient.newIndex(indexDefinition); bulkClient.startBulk(indexDefinition); @@ -59,7 +59,7 @@ class SearchTest { } try (TransportSearchClient searchClient = ClientBuilder.builder() .setSearchClientProvider(TransportSearchClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { // test stream count Stream stream = searchClient.search(qb -> qb diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/SmokeTest.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/SmokeTest.java index 519b262..1f6b887 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/SmokeTest.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/SmokeTest.java @@ -37,11 +37,11 @@ class SmokeTest { void smokeTest() throws Exception { try (TransportAdminClient adminClient = ClientBuilder.builder() .setAdminClientProvider(TransportAdminClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build(); TransportBulkClient bulkClient = ClientBuilder.builder() .setBulkClientProvider(TransportBulkClientProvider.class) - .put(helper.getTransportSettings()) + .put(helper.getClientSettings()) .build()) { IndexDefinition indexDefinition = new DefaultIndexDefinition(adminClient, "test", "doc", Settings.EMPTY); @@ -52,21 +52,20 @@ class SmokeTest { indexDefinition.setType("doc"); bulkClient.newIndex(indexDefinition); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); adminClient.checkMapping(indexDefinition); bulkClient.update(indexDefinition, "1", "{ \"name\" : \"Another name\"}"); bulkClient.delete(indexDefinition, "1"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); bulkClient.delete(indexDefinition, "1"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); adminClient.deleteIndex(indexDefinition); bulkClient.newIndex(indexDefinition); bulkClient.index(indexDefinition, "1", true, "{ \"name\" : \"Hello World\"}"); - bulkClient.waitForResponses(30, TimeUnit.SECONDS); - adminClient.updateReplicaLevel(indexDefinition, 2); - int replica = adminClient.getReplicaLevel(indexDefinition); - assertEquals(2, replica); + assertTrue(bulkClient.waitForResponses(30, TimeUnit.SECONDS)); + adminClient.updateReplicaLevel(indexDefinition, 1); + assertEquals(1, adminClient.getReplicaLevel(indexDefinition)); assertEquals(0, bulkClient.getBulkProcessor().getBulkMetric().getFailed().getCount()); assertEquals(6, bulkClient.getBulkProcessor().getBulkMetric().getSucceeded().getCount()); if (bulkClient.getBulkProcessor().getLastBulkError() != null) { diff --git a/elx-transport/src/test/java/org/xbib/elx/transport/test/TestExtension.java b/elx-transport/src/test/java/org/xbib/elx/transport/test/TestExtension.java index f8a4733..cedd639 100644 --- a/elx-transport/src/test/java/org/xbib/elx/transport/test/TestExtension.java +++ b/elx-transport/src/test/java/org/xbib/elx/transport/test/TestExtension.java @@ -2,21 +2,12 @@ package org.xbib.elx.transport.test; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.ElasticsearchTimeoutException; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; 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.ClusterStateRequest; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.plugins.Plugin; @@ -86,21 +77,6 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft TransportAddress address = response.getNodes().get(0).getNode().getAddress(); helper.host = address.address().getHostName(); helper.port = address.address().getPort(); - try { - ClusterHealthResponse healthResponse = helper.client().execute(ClusterHealthAction.INSTANCE, - new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN) - .timeout(TimeValue.timeValueSeconds(30))).actionGet(); - if (healthResponse != null && healthResponse.isTimedOut()) { - throw new IOException("cluster state is " + healthResponse.getStatus().name() - + ", from here on, everything will fail!"); - } - } catch (ElasticsearchTimeoutException e) { - throw new IOException("cluster does not respond to health request, cowardly refusing to continue"); - } - ClusterStateRequest clusterStateRequest = new ClusterStateRequest().all(); - ClusterStateResponse clusterStateResponse = - helper.client().execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet(); - logger.info("cluster name = {}", clusterStateResponse.getClusterName().value()); } @Override @@ -176,12 +152,14 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft return cluster; } - Settings getTransportSettings() { + Settings getClientSettings() { return Settings.builder() .put("cluster.name", cluster) .put("path.home", getHome()) .put("host", host) .put("port", port) + .put("cluster.target_health", "YELLOW") + .put("cluster.target_health_timeout", "1m") .build(); } diff --git a/gradle.properties b/gradle.properties index bcd4f33..5634a72 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = elx -version = 7.10.2.3 +version = 7.10.2.4 gradle.wrapper.version = 6.6.1 xbib-metrics.version = 2.1.0