use of org.opensearch.client.indices.CloseIndexResponse in project OpenSearch by opensearch-project.
the class IndicesClientIT method testCloseExistingIndex.
public void testCloseExistingIndex() throws IOException {
final String[] indices = new String[randomIntBetween(1, 5)];
for (int i = 0; i < indices.length; i++) {
String index = "index-" + i;
createIndex(index, Settings.EMPTY);
indices[i] = index;
}
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync);
assertTrue(closeIndexResponse.isAcknowledged());
assertTrue(closeIndexResponse.isShardsAcknowledged());
assertThat(closeIndexResponse.getIndices(), notNullValue());
assertThat(closeIndexResponse.getIndices(), hasSize(indices.length));
closeIndexResponse.getIndices().forEach(indexResult -> {
assertThat(indexResult.getIndex(), startsWith("index-"));
assertThat(indexResult.hasFailures(), is(false));
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(new Request(HttpGet.METHOD_NAME, indexResult.getIndex() + "/_search")));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
assertThat(exception.getMessage().contains(indexResult.getIndex()), equalTo(true));
});
}
Aggregations