[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@661e87f2ee
This commit is contained in:
Simon Willnauer 2018-01-29 20:46:35 +01:00 committed by GitHub
parent b6bab14fd4
commit 32d4e7f9d0
6 changed files with 15 additions and 12 deletions

View File

@ -50,7 +50,6 @@ public class LocalIndicesCleanerTests extends AbstractIndicesCleanerTestCase {
protected void createIndex(String name, DateTime creationDate) { protected void createIndex(String name, DateTime creationDate) {
assertAcked(prepareCreate(name) assertAcked(prepareCreate(name)
.setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, creationDate.getMillis()).build())); .setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, creationDate.getMillis()).build()));
ensureYellow(name);
} }
@Override @Override

View File

@ -113,7 +113,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
refresh(); refresh();
assertThat(client().admin().indices().prepareExists(".monitoring-*").get().isExists(), is(true)); assertThat(client().admin().indices().prepareExists(".monitoring-*").get().isExists(), is(true));
ensureYellow(".monitoring-*"); ensureYellowAndNoInitializingShards(".monitoring-*");
SearchResponse response = client().prepareSearch(".monitoring-*").get(); SearchResponse response = client().prepareSearch(".monitoring-*").get();
assertEquals(nbDocs, response.getHits().getTotalHits()); assertEquals(nbDocs, response.getHits().getTotalHits());
@ -132,7 +132,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
final int numNodes = internalCluster().getNodeNames().length; final int numNodes = internalCluster().getNodeNames().length;
assertBusy(() -> { assertBusy(() -> {
assertThat(client().admin().indices().prepareExists(".monitoring-*").get().isExists(), is(true)); assertThat(client().admin().indices().prepareExists(".monitoring-*").get().isExists(), is(true));
ensureYellow(".monitoring-*"); ensureYellowAndNoInitializingShards(".monitoring-*");
assertThat(client().prepareSearch(".monitoring-es-*") assertThat(client().prepareSearch(".monitoring-es-*")
.setSize(0) .setSize(0)
@ -193,7 +193,7 @@ public class LocalExporterIntegTests extends LocalExporterIntegTestCase {
assertBusy(() -> { assertBusy(() -> {
IndicesExistsResponse indicesExistsResponse = client().admin().indices().prepareExists(".monitoring-*").get(); IndicesExistsResponse indicesExistsResponse = client().admin().indices().prepareExists(".monitoring-*").get();
if (indicesExistsResponse.isExists()) { if (indicesExistsResponse.isExists()) {
ensureYellow(".monitoring-*"); ensureYellowAndNoInitializingShards(".monitoring-*");
refresh(".monitoring-es-*"); refresh(".monitoring-es-*");
SearchResponse response = client().prepareSearch(".monitoring-es-*") SearchResponse response = client().prepareSearch(".monitoring-es-*")

View File

@ -156,7 +156,7 @@ public abstract class MonitoringIntegTestCase extends ESIntegTestCase {
} }
protected void ensureMonitoringIndicesYellow() { protected void ensureMonitoringIndicesYellow() {
ensureYellow(".monitoring-es-*"); ensureYellowAndNoInitializingShards(".monitoring-es-*");
} }
protected List<Tuple<String, String>> monitoringTemplates() { protected List<Tuple<String, String>> monitoringTemplates() {

View File

@ -886,7 +886,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase {
private SearchHit getIndexedAuditMessage(Message message) throws InterruptedException { private SearchHit getIndexedAuditMessage(Message message) throws InterruptedException {
assertNotNull("no audit message was enqueued", message); assertNotNull("no audit message was enqueued", message);
final String indexName = IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, message.timestamp, rollover); final String indexName = IndexNameResolver.resolve(IndexAuditTrailField.INDEX_NAME_PREFIX, message.timestamp, rollover);
ensureYellow(indexName); ensureYellowAndNoInitializingShards(indexName);
GetSettingsResponse settingsResponse = getClient().admin().indices().prepareGetSettings(indexName).get(); 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_shards"), is(Integer.toString(numShards)));
assertThat(settingsResponse.getSetting(indexName, "index.number_of_replicas"), is(Integer.toString(numReplicas))); assertThat(settingsResponse.getSetting(indexName, "index.number_of_replicas"), is(Integer.toString(numReplicas)));
@ -916,14 +916,18 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase {
} }
@Override @Override
public ClusterHealthStatus ensureYellow(String... indices) { public ClusterHealthStatus ensureYellowAndNoInitializingShards(String... indices) {
if (remoteIndexing == false) { 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) 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()) { if (actionGet.isTimedOut()) {
logger.info("ensureYellow timed out, cluster state:\n{}\n{}", logger.info("ensureYellow timed out, cluster state:\n{}\n{}",
getClient().admin().cluster().prepareState().get().getState(), getClient().admin().cluster().prepareState().get().getState(),

View File

@ -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"); logger.info("security audit log index is yellow");
ClusterState state = client().admin().cluster().prepareState().get().getState(); ClusterState state = client().admin().cluster().prepareState().get().getState();
lastClusterState.set(state); lastClusterState.set(state);

View File

@ -89,7 +89,7 @@ public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase {
}); });
// Waits for indices to be ready // Waits for indices to be ready
ensureYellow(MONITORING_PATTERN); ensureYellowAndNoInitializingShards(MONITORING_PATTERN);
// Checks that the HTTP exporter has successfully exported some data // Checks that the HTTP exporter has successfully exported some data
assertBusy(() -> { assertBusy(() -> {