From 5101e518918ffeb05e679b10504a8bb5c5bd2632 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Fri, 11 Jan 2019 13:29:30 -0600 Subject: [PATCH] ML: Fix testMigrateConfigs (#37373) * ML: :s/execute/get * Fixing other broken tests * unmuting test --- .../xpack/ml/action/TransportOpenJobActionTests.java | 7 +++++-- .../xpack/ml/integration/BasicDistributedJobsIT.java | 6 ++++-- .../xpack/ml/integration/MlConfigMigratorIT.java | 3 +-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java index 04dfa5f2750..7d72ef7f633 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java @@ -8,9 +8,11 @@ package org.elasticsearch.xpack.ml.action; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.Version; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -455,8 +457,9 @@ public class TransportOpenJobActionTests extends ESTestCase { metaData = new MetaData.Builder(cs.metaData()); routingTable = new RoutingTable.Builder(cs.routingTable()); - - String indexToRemove = randomFrom(TransportOpenJobAction.indicesOfInterest(".ml-anomalies-shared")); + IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(); + String indexToRemove = randomFrom(indexNameExpressionResolver.concreteIndexNames(cs, IndicesOptions.lenientExpandOpen(), + TransportOpenJobAction.indicesOfInterest(".ml-anomalies-shared"))); if (randomBoolean()) { routingTable.remove(indexToRemove); } else { diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java index 77041f40e0f..7779f4e13d0 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/BasicDistributedJobsIT.java @@ -51,6 +51,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import static org.elasticsearch.persistent.PersistentTasksClusterService.needsReassignment; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasEntry; public class BasicDistributedJobsIT extends BaseMlIntegTestCase { @@ -399,8 +400,9 @@ public class BasicDistributedJobsIT extends BaseMlIntegTestCase { String detailedMessage = detail.getMessage(); assertTrue(detailedMessage, detailedMessage.startsWith("Could not open job because no suitable nodes were found, allocation explanation")); - assertTrue(detailedMessage, detailedMessage.endsWith("because not all primary shards are active for the following indices " + - "[.ml-state,.ml-anomalies-shared]]")); + assertThat(detailedMessage, containsString("because not all primary shards are active for the following indices")); + assertThat(detailedMessage, containsString(".ml-state")); + assertThat(detailedMessage, containsString(".ml-anomalies-shared")); logger.info("Start data node"); String nonMlNode = internalCluster().startNode(Settings.builder() diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java index 023286af6b9..4993da215af 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java @@ -120,7 +120,6 @@ public class MlConfigMigratorIT extends MlSingleNodeTestCase { assertNull(alreadyMigratedJob.getCustomSettings()); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37374") public void testMigrateConfigs() throws InterruptedException, IOException { // and jobs and datafeeds clusterstate MlMetadata.Builder mlMetadata = new MlMetadata.Builder(); @@ -311,7 +310,7 @@ public class MlConfigMigratorIT extends MlSingleNodeTestCase { } public void assertSnapshot(MlMetadata expectedMlMetadata) throws IOException { - client().admin().indices().prepareRefresh(AnomalyDetectorsIndex.jobStateIndexPattern()).execute(); + client().admin().indices().prepareRefresh(AnomalyDetectorsIndex.jobStateIndexPattern()).get(); SearchResponse searchResponse = client() .prepareSearch(AnomalyDetectorsIndex.jobStateIndexPattern()) .setTypes(ElasticsearchMappings.DOC_TYPE)