use of org.opensearch.client.indices.CloseIndexRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testCloseNonExistentIndex.
public void testCloseNonExistentIndex() throws IOException {
String nonExistentIndex = "non_existent_index";
assertFalse(indexExists(nonExistentIndex));
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex);
OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
}
use of org.opensearch.client.indices.CloseIndexRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method closeIndex.
static Request closeIndex(CloseIndexRequest closeIndexRequest) {
String endpoint = RequestConverters.endpoint(closeIndexRequest.indices(), "_close");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withTimeout(closeIndexRequest.timeout());
parameters.withMasterTimeout(closeIndexRequest.masterNodeTimeout());
parameters.withIndicesOptions(closeIndexRequest.indicesOptions());
request.addParameters(parameters.asMap());
return request;
}
use of org.opensearch.client.indices.CloseIndexRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testCloseEmptyOrNullIndex.
public void testCloseEmptyOrNullIndex() {
String[] indices = randomBoolean() ? Strings.EMPTY_ARRAY : null;
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
org.opensearch.client.ValidationException exception = expectThrows(org.opensearch.client.ValidationException.class, () -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
assertThat(exception.validationErrors().get(0), equalTo("index is missing"));
}
use of org.opensearch.client.indices.CloseIndexRequest 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));
});
}
use of org.opensearch.client.indices.CloseIndexRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConvertersTests method testCloseIndex.
public void testCloseIndex() {
String[] indices = RequestConvertersTests.randomIndicesNames(1, 5);
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomTimeout(timeout -> closeIndexRequest.setTimeout(TimeValue.parseTimeValue(timeout, "test")), AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
RequestConvertersTests.setRandomMasterTimeout(closeIndexRequest, expectedParams);
RequestConvertersTests.setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions, expectedParams);
Request request = IndicesRequestConverters.closeIndex(closeIndexRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close");
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
Assert.assertThat(expectedParams, equalTo(request.getParameters()));
Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
Assert.assertThat(request.getEntity(), nullValue());
}
Aggregations