From e3846a9c061bfb8be71b396d405a0ee74cab890e Mon Sep 17 00:00:00 2001 From: olcbean <26058559+olcbean@users.noreply.github.com> Date: Mon, 29 Jan 2018 13:22:26 +0100 Subject: [PATCH] Java high-level REST : minor code clean up (#28409) --- .../org/elasticsearch/client/Request.java | 2 +- .../elasticsearch/client/IndicesClientIT.java | 38 +++++++++---------- .../elasticsearch/client/RequestTests.java | 6 +-- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java index 08b7638abdb..487aecc7dd3 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java @@ -675,7 +675,7 @@ public final class Request { if (indicesOptions.expandWildcardsOpen() == false && indicesOptions.expandWildcardsClosed() == false) { expandWildcards = "none"; } else { - StringJoiner joiner = new StringJoiner(","); + StringJoiner joiner = new StringJoiner(","); if (indicesOptions.expandWildcardsOpen()) { joiner.add("open"); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index e2ffe310bfd..3a4912c91f5 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -335,6 +335,22 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { assertEquals(RestStatus.NOT_FOUND, exception.status()); } + public void testExistsAlias() throws IOException { + GetAliasesRequest getAliasesRequest = new GetAliasesRequest("alias"); + assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); + + createIndex("index"); + client().performRequest(HttpPut.METHOD_NAME, "/index/_alias/alias"); + assertTrue(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); + + GetAliasesRequest getAliasesRequest2 = new GetAliasesRequest(); + getAliasesRequest2.aliases("alias"); + getAliasesRequest2.indices("index"); + assertTrue(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); + getAliasesRequest2.indices("does_not_exist"); + assertFalse(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); + } + private static void createIndex(String index) throws IOException { Response response = client().performRequest(HttpPut.METHOD_NAME, index); assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); @@ -360,24 +376,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode(); } - public void testExistsAlias() throws IOException { - GetAliasesRequest getAliasesRequest = new GetAliasesRequest("alias"); - assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); - - createIndex("index"); - client().performRequest(HttpPut.METHOD_NAME, "/index/_alias/alias"); - assertTrue(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); - - GetAliasesRequest getAliasesRequest2 = new GetAliasesRequest(); - getAliasesRequest2.aliases("alias"); - getAliasesRequest2.indices("index"); - assertTrue(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); - getAliasesRequest2.indices("does_not_exist"); - assertFalse(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync)); - } - @SuppressWarnings({ "unchecked", "rawtypes" }) - private Map getIndexMetadata(String index) throws IOException { + private static Map getIndexMetadata(String index) throws IOException { Response response = client().performRequest(HttpGet.METHOD_NAME, index); XContentType entityContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue()); @@ -399,11 +399,11 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { if (false == Strings.isEmpty(alias)) { endpoint = endpoint + "/" + alias; } - Map performGet = performGet(endpoint); + Map performGet = get(endpoint); return (Map) ((Map) ((Map) performGet.get(index)).get("aliases")).get(alias); } - private static Map performGet(final String endpoint) throws IOException { + private static Map get(final String endpoint) throws IOException { Response response = client().performRequest(HttpGet.METHOD_NAME, endpoint); XContentType entityContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue()); Map responseEntity = XContentHelper.convertToMap(entityContentType.xContent(), response.getEntity().getContent(), diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java index 74ef0bfa807..f348e9017d4 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java @@ -345,11 +345,7 @@ public class RequestTests extends ESTestCase { public void testPutMapping() throws IOException { PutMappingRequest putMappingRequest = new PutMappingRequest(); - int numIndices = randomIntBetween(0, 5); - String[] indices = new String[numIndices]; - for (int i = 0; i < numIndices; i++) { - indices[i] = "index-" + randomAlphaOfLengthBetween(2, 5); - } + String[] indices = randomIndicesNames(0, 5); putMappingRequest.indices(indices); String type = randomAlphaOfLengthBetween(3, 10);