From 32d4e7f9d0dea913fc504509f1d57a0fdc7c1f78 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 29 Jan 2018 20:46:35 +0100 Subject: [PATCH] [TEST] Use `ensureYellowAndNoInitializingShards` in monitoring test (elastic/x-pack-elasticsearch#3768) Monitoring creates indices concurrently to the test execution. In that case ensureYellow might not be enough and will cause test-failures when shards are not active etc. This change uses a new method added in core to ensure shards are not initializing anymore. relates elastic/x-pack-elasticsearch#2672 Relates to elastic/elasticsearch#28416 Original commit: elastic/x-pack-elasticsearch@661e87f2eeb5119f9f94154070e1a32542f98820 --- .../cleaner/local/LocalIndicesCleanerTests.java | 1 - .../exporter/local/LocalExporterIntegTests.java | 6 +++--- .../monitoring/test/MonitoringIntegTestCase.java | 2 +- .../security/audit/index/IndexAuditTrailTests.java | 14 +++++++++----- .../xpack/security/audit/IndexAuditIT.java | 2 +- .../SmokeTestMonitoringWithSecurityIT.java | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/local/LocalIndicesCleanerTests.java b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/local/LocalIndicesCleanerTests.java index c749e318abf..b74701d35fe 100644 --- a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/local/LocalIndicesCleanerTests.java +++ b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/local/LocalIndicesCleanerTests.java @@ -50,7 +50,6 @@ public class LocalIndicesCleanerTests extends AbstractIndicesCleanerTestCase { protected void createIndex(String name, DateTime creationDate) { assertAcked(prepareCreate(name) .setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, creationDate.getMillis()).build())); - ensureYellow(name); } @Override diff --git a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java index 0250736ca4e..5075bb1066d 100644 --- a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java +++ b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java @@ -113,7 +113,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase { refresh(); assertThat(client().admin().indices().prepareExists(".monitoring-*").get().isExists(), is(true)); - ensureYellow(".monitoring-*"); + ensureYellowAndNoInitializingShards(".monitoring-*"); SearchResponse response = client().prepareSearch(".monitoring-*").get(); assertEquals(nbDocs, response.getHits().getTotalHits()); @@ -132,7 +132,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase { final int numNodes = internalCluster().getNodeNames().length; assertBusy(() -> { assertThat(client().admin().indices().prepareExists(".monitoring-*").get().isExists(), is(true)); - ensureYellow(".monitoring-*"); + ensureYellowAndNoInitializingShards(".monitoring-*"); assertThat(client().prepareSearch(".monitoring-es-*") .setSize(0) @@ -193,7 +193,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase { assertBusy(() -> { IndicesExistsResponse indicesExistsResponse = client().admin().indices().prepareExists(".monitoring-*").get(); if (indicesExistsResponse.isExists()) { - ensureYellow(".monitoring-*"); + ensureYellowAndNoInitializingShards(".monitoring-*"); refresh(".monitoring-es-*"); SearchResponse response = client().prepareSearch(".monitoring-es-*") diff --git a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java index 8951b33f319..9bf9e530af5 100644 --- a/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java +++ b/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java @@ -156,7 +156,7 @@ public abstract class MonitoringIntegTestCase extends ESIntegTestCase { } protected void ensureMonitoringIndicesYellow() { - ensureYellow(".monitoring-es-*"); + ensureYellowAndNoInitializingShards(".monitoring-es-*"); } protected List> monitoringTemplates() { diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java index e4cc92ebe91..12654e2e23d 100644 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java @@ -886,7 +886,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { private SearchHit getIndexedAuditMessage(Message message) throws InterruptedException { assertNotNull("no audit message was enqueued", message); final String indexName = IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, message.timestamp, rollover); - ensureYellow(indexName); + ensureYellowAndNoInitializingShards(indexName); GetSettingsResponse settingsResponse = getClient().admin().indices().prepareGetSettings(indexName).get(); assertThat(settingsResponse.getSetting(indexName, "index.number_of_shards"), is(Integer.toString(numShards))); assertThat(settingsResponse.getSetting(indexName, "index.number_of_replicas"), is(Integer.toString(numReplicas))); @@ -916,14 +916,18 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { } @Override - public ClusterHealthStatus ensureYellow(String... indices) { + public ClusterHealthStatus ensureYellowAndNoInitializingShards(String... indices) { if (remoteIndexing == false) { - return super.ensureYellow(indices); + return super.ensureYellowAndNoInitializingShards(indices); } - // pretty ugly but just a rip of ensureYellow that uses a different client + // pretty ugly but just a rip of ensureYellowAndNoInitializingShards that uses a different client ClusterHealthResponse actionGet = getClient().admin().cluster().health(Requests.clusterHealthRequest(indices) - .waitForNoRelocatingShards(true).waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet(); + .waitForNoRelocatingShards(true) + .waitForYellowStatus() + .waitForEvents(Priority.LANGUID) + .waitForNoInitializingShards(true)) + .actionGet(); if (actionGet.isTimedOut()) { logger.info("ensureYellow timed out, cluster state:\n{}\n{}", getClient().admin().cluster().prepareState().get().getState(), diff --git a/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java b/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java index 86bc2f57c15..1d4b8004463 100644 --- a/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java +++ b/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java @@ -61,7 +61,7 @@ public class IndexAuditIT extends ESIntegTestCase { } } - ensureYellow(".security_audit_log*"); + ensureYellowAndNoInitializingShards(".security_audit_log*"); logger.info("security audit log index is yellow"); ClusterState state = client().admin().cluster().prepareState().get().getState(); lastClusterState.set(state); diff --git a/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java b/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java index d87ae7b8b38..06f66990ad4 100644 --- a/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java +++ b/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java @@ -89,7 +89,7 @@ public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase { }); // Waits for indices to be ready - ensureYellow(MONITORING_PATTERN); + ensureYellowAndNoInitializingShards(MONITORING_PATTERN); // Checks that the HTTP exporter has successfully exported some data assertBusy(() -> {