From da1b219f48568ca51895b4b1ac26d6af31d79756 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 12 Jan 2021 14:46:30 +0000 Subject: [PATCH] Minor tidy-up for close-index REST requests Some changes for `master` that make #67246 a bit easier. Relates #67158 --- .../org/elasticsearch/client/IndicesRequestConverters.java | 1 + .../elasticsearch/client/IndicesRequestConvertersTests.java | 1 + .../src/test/java/org/elasticsearch/client/RankEvalIT.java | 2 +- .../main/java/org/elasticsearch/test/rest/ESRestTestCase.java | 3 +-- .../test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java | 2 +- .../AbstractSearchableSnapshotsRestTestCase.java | 3 +-- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java index 623a0dacb60b7..787a0ac28fb77 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java @@ -137,6 +137,7 @@ static Request closeIndex(CloseIndexRequest closeIndexRequest) { parameters.withTimeout(closeIndexRequest.timeout()); parameters.withMasterTimeout(closeIndexRequest.masterNodeTimeout()); parameters.withIndicesOptions(closeIndexRequest.indicesOptions()); + parameters.withWaitForActiveShards(closeIndexRequest.waitForActiveShards()); request.addParameters(parameters.asMap()); return request; } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java index 9506a533b633e..63ad54148d4e2 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java @@ -426,6 +426,7 @@ public void testCloseIndex() { RequestConvertersTests.setRandomMasterTimeout(closeIndexRequest, expectedParams); RequestConvertersTests.setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions, expectedParams); + RequestConvertersTests.setRandomWaitForActiveShards(closeIndexRequest::waitForActiveShards, expectedParams); Request request = IndicesRequestConverters.closeIndex(closeIndexRequest); StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close"); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java index 7de2af477d9f8..4b549425f2485 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java @@ -108,7 +108,7 @@ public void testRankEvalRequest() throws IOException { } // now try this when test2 is closed - client().performRequest(new Request("POST", "index2/_close")); + closeIndex("index2"); rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS)); response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index e36fee2352042..68362190a9c4b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -1217,8 +1217,7 @@ protected static boolean indexExists(String index) throws IOException { } protected static void closeIndex(String index) throws IOException { - Response response = client().performRequest(new Request("POST", "/" + index + "/_close")); - assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); + assertOK(client().performRequest(new Request(HttpPost.METHOD_NAME, "/" + index + "/_close"))); } protected static void openIndex(String index) throws IOException { diff --git a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java index 156c0835fbebb..e73326afd80ec 100644 --- a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java +++ b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java @@ -81,7 +81,7 @@ public void testFollowIndex() throws Exception { assertBusy(() -> verifyCcrMonitoring(leaderIndexName, followIndexName), 30, TimeUnit.SECONDS); pauseFollow(followIndexName); - assertOK(client().performRequest(new Request("POST", "/" + followIndexName + "/_close"))); + closeIndex(followIndexName); assertOK(client().performRequest(new Request("POST", "/" + followIndexName + "/_ccr/unfollow"))); Exception e = expectThrows(ResponseException.class, () -> resumeFollow(followIndexName)); assertThat(e.getMessage(), containsString("follow index [" + followIndexName + "] does not have ccr metadata")); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java index c35d45e49dd65..7dcbb7a974eac 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java @@ -142,8 +142,7 @@ public void testSearchResultsWhenFrozen() throws Exception { public void testCloseAndReopen() throws Exception { runSearchableSnapshotsTest((restoredIndexName, numDocs) -> { - final Request closeRequest = new Request(HttpPost.METHOD_NAME, restoredIndexName + "/_close"); - assertOK(client().performRequest(closeRequest)); + closeIndex(restoredIndexName); ensureGreen(restoredIndexName); final Request openRequest = new Request(HttpPost.METHOD_NAME, restoredIndexName + "/_open");