Skip to content

Commit c570c31

Browse files
committed
Refactor tests
1 parent 214b929 commit c570c31

File tree

2 files changed

+106
-184
lines changed

2 files changed

+106
-184
lines changed

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.common.xcontent.XContentHelper;
2424
import org.elasticsearch.core.Nullable;
2525
import org.elasticsearch.core.TimeValue;
26+
import org.elasticsearch.test.rest.ESRestTestCase;
2627
import org.elasticsearch.xcontent.ToXContent;
2728
import org.elasticsearch.xcontent.XContentBuilder;
2829
import org.elasticsearch.xcontent.XContentType;
@@ -58,7 +59,6 @@
5859
import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
5960
import static org.hamcrest.Matchers.anyOf;
6061
import static org.hamcrest.Matchers.equalTo;
61-
import static org.hamcrest.Matchers.is;
6262
import static org.junit.Assert.assertThat;
6363

6464
/**
@@ -403,6 +403,28 @@ public static void updatePolicy(RestClient client, String indexName, String poli
403403
assertOK(client.performRequest(changePolicyRequest));
404404
}
405405

406+
/**
407+
* Moves the specified index from the current ILM step to the next step.
408+
*/
409+
public static void moveIndexToStep(RestClient client, String indexName, Step.StepKey currentStep, Step.StepKey nextStep)
410+
throws IOException {
411+
Request moveToStepRequest = new Request("POST", "_ilm/move/" + indexName);
412+
moveToStepRequest.setJsonEntity(Strings.format("""
413+
{
414+
"current_step": {
415+
"phase": "%s",
416+
"action": "%s",
417+
"name": "%s"
418+
},
419+
"next_step": {
420+
"phase": "%s",
421+
"action": "%s",
422+
"name": "%s"
423+
}
424+
}""", currentStep.phase(), currentStep.action(), currentStep.name(), nextStep.phase(), nextStep.action(), nextStep.name()));
425+
ESRestTestCase.assertAcknowledged(client.performRequest(moveToStepRequest));
426+
}
427+
406428
@SuppressWarnings("unchecked")
407429
public static String getSnapshotState(RestClient client, String snapshot) throws IOException {
408430
Response response = client.performRequest(new Request("GET", "/_snapshot/repo/" + snapshot));
@@ -485,24 +507,6 @@ public static String waitAndGetShrinkIndexName(RestClient client, String origina
485507
return shrunkenIndexName[0];
486508
}
487509

488-
@SuppressWarnings("unchecked")
489-
public static List<String> getBackingIndices(RestClient client, String dataStreamName) throws IOException {
490-
Response getDataStream = client.performRequest(new Request("GET", "_data_stream/" + dataStreamName));
491-
Map<String, Object> responseMap;
492-
try (InputStream is = getDataStream.getEntity().getContent()) {
493-
responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
494-
}
495-
496-
List<Map<String, Object>> dataStreams = (List<Map<String, Object>>) responseMap.get("data_streams");
497-
assertThat(dataStreams.size(), is(1));
498-
Map<String, Object> dataStream = dataStreams.get(0);
499-
assertThat(dataStream.get("name"), is(dataStreamName));
500-
List<String> indices = ((List<Map<String, Object>>) dataStream.get("indices")).stream()
501-
.map(indexMap -> (String) indexMap.get("index_name"))
502-
.toList();
503-
return indices;
504-
}
505-
506510
private static void executeDummyClusterStateUpdate(RestClient client) throws IOException {
507511
createIndexWithSettings(
508512
client,

0 commit comments

Comments
 (0)