Skip to content

Commit

Permalink
[TEST] Fix MlMappingsUpgradeIT testMappingsUpgrade
Browse files Browse the repository at this point in the history
Made the test tolerant to index upgrade being run
in between the old/mixed/upgraded portions.  This
can occur because the rolling upgrade tests all
share the same indices.

Fixes elastic#37763
  • Loading branch information
droberts195 committed Jan 23, 2019
1 parent 6a5d9d9 commit 6686323
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ protected Collection<String> templatesToWaitFor() {
* The purpose of this test is to ensure that when a job is open through a rolling upgrade we upgrade the results
* index mappings when it is assigned to an upgraded node even if no other ML endpoint is called after the upgrade
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37763")
public void testMappingsUpgrade() throws Exception {

switch (CLUSTER_TYPE) {
Expand All @@ -65,6 +64,8 @@ private void createAndOpenTestJob() throws IOException {
Job.Builder job = new Job.Builder(JOB_ID);
job.setAnalysisConfig(analysisConfig);
job.setDataDescription(new DataDescription.Builder());
// Use a custom index because other rolling upgrade tests meddle with the shared index
job.setResultsIndexName("mappings-upgrade-test");

Request putJob = new Request("PUT", "_ml/anomaly_detectors/" + JOB_ID);
putJob.setJsonEntity(Strings.toString(job.build()));
Expand All @@ -85,7 +86,16 @@ private void assertUpgradedMappings() throws Exception {

Map<String, Object> responseLevel = entityAsMap(response);
assertNotNull(responseLevel);
Map<String, Object> indexLevel = (Map<String, Object>) responseLevel.get(".ml-anomalies-shared");
Map<String, Object> indexLevel = null;
// The name of the concrete index underlying the results index alias may or may not have been changed
// by the upgrade process (depending on what other tests are being run and the order they're run in),
// so navigating to the next level of the tree must account for both cases
for (Map.Entry<String, Object> entry : responseLevel.entrySet()) {
if (entry.getKey().startsWith(".ml-anomalies-") && entry.getKey().contains("mappings-upgrade-test")) {
indexLevel = (Map<String, Object>) entry.getValue();
break;
}
}
assertNotNull(indexLevel);
Map<String, Object> mappingsLevel = (Map<String, Object>) indexLevel.get("mappings");
assertNotNull(mappingsLevel);
Expand Down

0 comments on commit 6686323

Please sign in to comment.