Skip to content

Commit 44c74bb

Browse files
authored
Fix TimeSeriesLifecycleActionsIT.testRolloverAlreadyExists (#48747)
* ILM Test asserts on the same ilm/_explain output With the introduction of retryable steps subsequent ilm/_explain calls can see the state of an ilm cycle move out of the error step. This test made several assertions assuming that the cycle remains in the error step so this commit changes the test to make one _explain call and have all the asserts work on the same ilm state (so subsequent assumptions to the cycle being in the error step are valid). * Drop unused field in test.
1 parent e9367ef commit 44c74bb

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,14 @@ public void testRolloverAlreadyExists() throws Exception {
312312
// index another doc to trigger the policy
313313
index(client(), originalIndex, "_id", "foo", "bar");
314314
assertBusy(() -> {
315-
logger.info(originalIndex + ": " + getStepKeyForIndex(originalIndex));
315+
Map<String, Object> explainIndexResponse = explainIndex(originalIndex);
316+
logger.info(originalIndex + ": " + getStepKey(explainIndexResponse));
316317
logger.info(secondIndex + ": " + getStepKeyForIndex(secondIndex));
317-
assertThat(getStepKeyForIndex(originalIndex), equalTo(new StepKey("hot", RolloverAction.NAME, ErrorStep.NAME)));
318-
assertThat(getFailedStepForIndex(originalIndex), equalTo(WaitForRolloverReadyStep.NAME));
319-
assertThat(getReasonForIndex(originalIndex), containsString("already exists"));
318+
assertThat(getStepKey(explainIndexResponse), equalTo(new StepKey("hot", RolloverAction.NAME, ErrorStep.NAME)));
319+
assertThat(explainIndexResponse.get("failed_step"), equalTo(WaitForRolloverReadyStep.NAME));
320+
@SuppressWarnings("unchecked")
321+
String reason = ((Map<String, String>) explainIndexResponse.get("step_info")).get("reason");
322+
assertThat(reason, containsString("already exists"));
320323
});
321324
}
322325

@@ -1088,15 +1091,20 @@ private Map<String, Object> getOnlyIndexSettings(String index) throws IOExceptio
10881091
return (Map<String, Object>) response.get("settings");
10891092
}
10901093

1094+
10911095
public static StepKey getStepKeyForIndex(String indexName) throws IOException {
10921096
Map<String, Object> indexResponse = explainIndex(indexName);
10931097
if (indexResponse == null) {
10941098
return new StepKey(null, null, null);
10951099
}
10961100

1097-
String phase = (String) indexResponse.get("phase");
1098-
String action = (String) indexResponse.get("action");
1099-
String step = (String) indexResponse.get("step");
1101+
return getStepKey(indexResponse);
1102+
}
1103+
1104+
private static StepKey getStepKey(Map<String, Object> explainIndexResponse) {
1105+
String phase = (String) explainIndexResponse.get("phase");
1106+
String action = (String) explainIndexResponse.get("action");
1107+
String step = (String) explainIndexResponse.get("step");
11001108
return new StepKey(phase, action, step);
11011109
}
11021110

@@ -1107,14 +1115,6 @@ private String getFailedStepForIndex(String indexName) throws IOException {
11071115
return (String) indexResponse.get("failed_step");
11081116
}
11091117

1110-
@SuppressWarnings("unchecked")
1111-
private String getReasonForIndex(String indexName) throws IOException {
1112-
Map<String, Object> indexResponse = explainIndex(indexName);
1113-
if (indexResponse == null) return null;
1114-
1115-
return ((Map<String, String>) indexResponse.get("step_info")).get("reason");
1116-
}
1117-
11181118
private static Map<String, Object> explainIndex(String indexName) throws IOException {
11191119
return explain(indexName, false, false).get(indexName);
11201120
}

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ public void testRunPolicyErrorStepOnRetryableFailedStep() {
214214
RolloverAction action = RolloverActionTests.randomInstance();
215215
actions.put(RolloverAction.NAME, action);
216216
Phase phase = new Phase(phaseName, after, actions);
217-
Map<String, Phase> phases = Map.of(phaseName, phase);
218217
PhaseExecutionInfo phaseExecutionInfo = new PhaseExecutionInfo(policyName, phase, 1, randomNonNegativeLong());
219218
String phaseJson = Strings.toString(phaseExecutionInfo);
220219
NoOpClient client = new NoOpClient(threadPool);

0 commit comments

Comments
 (0)