[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:
parent
b6bab14fd4
commit
32d4e7f9d0
|
@ -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
|
||||
|
|
|
@ -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-*")
|
||||
|
|
|
@ -156,7 +156,7 @@ public abstract class MonitoringIntegTestCase extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
protected void ensureMonitoringIndicesYellow() {
|
||||
ensureYellow(".monitoring-es-*");
|
||||
ensureYellowAndNoInitializingShards(".monitoring-es-*");
|
||||
}
|
||||
|
||||
protected List<Tuple<String, String>> monitoringTemplates() {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(() -> {
|
||||
|
|
Loading…
Reference in New Issue