Java high-level REST : minor code clean up (#28409)

This commit is contained in:
olcbean 2018-01-29 13:22:26 +01:00 committed by Luca Cavanna
parent e208e959bd
commit e3846a9c06
3 changed files with 21 additions and 25 deletions

View File

@ -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");
}

View File

@ -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<String, Object> getIndexMetadata(String index) throws IOException {
private static Map<String, Object> 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<String, Object> performGet = performGet(endpoint);
Map<String, Object> performGet = get(endpoint);
return (Map) ((Map) ((Map) performGet.get(index)).get("aliases")).get(alias);
}
private static Map<String, Object> performGet(final String endpoint) throws IOException {
private static Map<String, Object> get(final String endpoint) throws IOException {
Response response = client().performRequest(HttpGet.METHOD_NAME, endpoint);
XContentType entityContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue());
Map<String, Object> responseEntity = XContentHelper.convertToMap(entityContentType.xContent(), response.getEntity().getContent(),

View File

@ -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);