Skip to content

Commit

Permalink
Tests: separate rollup and shrink action tests in own classes (elasti…
Browse files Browse the repository at this point in the history
…c#68363)

This separates the ILM rollup and shrink actions tests from TimeSeriesLifecycleActionsIT
into their own classes.
  • Loading branch information
andreidan committed Feb 2, 2021
1 parent c011181 commit d166317
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ private Set<String> runningTasks(Response response) throws IOException {
return runningTasks;
}

protected static void assertOK(Response response) {
public static void assertOK(Response response) {
assertThat(response.getStatusLine().getStatusCode(), anyOf(equalTo(200), equalTo(201)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLengthBetween;
import static org.elasticsearch.test.ESTestCase.randomBoolean;
import static org.elasticsearch.test.rest.ESRestTestCase.assertOK;
import static org.elasticsearch.test.rest.ESRestTestCase.ensureGreen;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -292,4 +293,26 @@ public static Integer getNumberOfSegments(RestClient client, String index) throw
List<Map<String, Object>> shards = (List<Map<String, Object>>) responseEntity.get("0");
return (Integer) shards.get(0).get("num_search_segments");
}

public static void updatePolicy(RestClient client, String indexName, String policy) throws IOException {
Request changePolicyRequest = new Request("PUT", "/" + indexName + "/_settings");
final StringEntity changePolicyEntity = new StringEntity("{ \"index.lifecycle.name\": \"" + policy + "\" }",
ContentType.APPLICATION_JSON);
changePolicyRequest.setEntity(changePolicyEntity);
assertOK(client.performRequest(changePolicyRequest));
}

@SuppressWarnings("unchecked")
public static String getSnapshotState(RestClient client, String snapshot) throws IOException {
Response response = client.performRequest(new Request("GET", "/_snapshot/repo/" + snapshot));
Map<String, Object> responseMap;
try (InputStream is = response.getEntity().getContent()) {
responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
}

Map<String, Object> repoResponse = ((List<Map<String, Object>>) responseMap.get("responses")).get(0);
Map<String, Object> snapResponse = ((List<Map<String, Object>>) repoResponse.get("snapshots")).get(0);
assertThat(snapResponse.get("snapshot"), equalTo(snapshot));
return (String) snapResponse.get("state");
}
}
Loading

0 comments on commit d166317

Please sign in to comment.