diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java index 6387cbc265f16..b55694a57360b 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/TransportMonitoringMigrateAlertsActionTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchAction; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequest; +import org.elasticsearch.xpack.core.watcher.watch.Watch; import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.monitoring.MonitoringService; import org.elasticsearch.xpack.monitoring.exporter.ClusterAlertsUtil; @@ -119,12 +120,7 @@ public void testLocalAlertsRemoval() throws Exception { assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(exporterSettings)); // ensure resources exist - assertBusy(() -> { - assertThat(indexExists(".monitoring-*"), is(true)); - ensureYellowAndNoInitializingShards(".monitoring-*"); - checkMonitoringTemplates(); - assertWatchesExist(true); - }); + ensureInitialLocalResources(); // call migration api MonitoringMigrateAlertsResponse response = client().execute(MonitoringMigrateAlertsAction.INSTANCE, @@ -158,12 +154,7 @@ public void testRepeatedLocalAlertsRemoval() throws Exception { assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(exporterSettings)); // ensure resources exist - assertBusy(() -> { - assertThat(indexExists(".monitoring-*"), is(true)); - ensureYellowAndNoInitializingShards(".monitoring-*"); - checkMonitoringTemplates(); - assertWatchesExist(true); - }); + ensureInitialLocalResources(); // call migration api MonitoringMigrateAlertsResponse response = client().execute(MonitoringMigrateAlertsAction.INSTANCE, @@ -463,6 +454,7 @@ public void testRemoteAlertsRemoteDisallowsWatcher() throws Exception { } private void ensureInitialLocalResources() throws Exception { + waitForWatcherIndices(); assertBusy(() -> { assertThat(indexExists(".monitoring-*"), is(true)); ensureYellowAndNoInitializingShards(".monitoring-*"); @@ -579,4 +571,9 @@ private void assertMonitorWatches(final MockWebServer webServer, final boolean r } } } + + protected void waitForWatcherIndices() throws Exception { + awaitIndexExists(Watch.INDEX); + assertBusy(() -> ensureYellowAndNoInitializingShards(Watch.INDEX)); + } } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java index a3303cbeaae37..0ec95c7232587 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/test/MonitoringIntegTestCase.java @@ -176,7 +176,7 @@ protected void waitForMonitoringIndices() throws Exception { assertBusy(this::ensureMonitoringIndicesYellow); } - private void awaitIndexExists(final String index) throws Exception { + protected void awaitIndexExists(final String index) throws Exception { assertBusy(() -> assertIndicesExists(index), 30, TimeUnit.SECONDS); }