Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch high level rest tests to new style requests #31937

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public void testOpenExistingIndex() throws IOException {
createIndex(index, Settings.EMPTY);
closeIndex(index);
ResponseException exception = expectThrows(ResponseException.class,
() -> client().performRequest(HttpGet.METHOD_NAME, index + "/_search"));
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search")));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
assertThat(exception.getMessage().contains(index), equalTo(true));

Expand All @@ -621,7 +621,7 @@ public void testOpenExistingIndex() throws IOException {
highLevelClient().indices()::openAsync);
assertTrue(openIndexResponse.isAcknowledged());

Response response = client().performRequest(HttpGet.METHOD_NAME, index + "/_search");
Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
}

Expand Down Expand Up @@ -650,7 +650,7 @@ public void testOpenNonExistentIndex() throws IOException {
public void testCloseExistingIndex() throws IOException {
String index = "index";
createIndex(index, Settings.EMPTY);
Response response = client().performRequest(HttpGet.METHOD_NAME, index + "/_search");
Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));

CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index);
Expand All @@ -659,7 +659,7 @@ public void testCloseExistingIndex() throws IOException {
assertTrue(closeIndexResponse.isAcknowledged());

ResponseException exception = expectThrows(ResponseException.class,
() -> client().performRequest(HttpGet.METHOD_NAME, index + "/_search"));
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search")));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
assertThat(exception.getMessage().contains(index), equalTo(true));
}
Expand Down Expand Up @@ -817,7 +817,7 @@ public void testExistsAlias() throws IOException {
assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));

createIndex("index", Settings.EMPTY);
client().performRequest(HttpPut.METHOD_NAME, "/index/_alias/alias");
client().performRequest(new Request(HttpPut.METHOD_NAME, "/index/_alias/alias"));
assertTrue(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));

GetAliasesRequest getAliasesRequest2 = new GetAliasesRequest();
Expand Down Expand Up @@ -936,10 +936,10 @@ public void testRollover() throws IOException {
public void testGetAlias() throws IOException {
{
createIndex("index1", Settings.EMPTY);
client().performRequest(HttpPut.METHOD_NAME, "/index1/_alias/alias1");
client().performRequest(new Request(HttpPut.METHOD_NAME, "/index1/_alias/alias1"));

createIndex("index2", Settings.EMPTY);
client().performRequest(HttpPut.METHOD_NAME, "/index2/_alias/alias2");
client().performRequest(new Request(HttpPut.METHOD_NAME, "/index2/_alias/alias2"));

createIndex("index3", Settings.EMPTY);
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException {
assertThat(getAliasesResponse.getError(), equalTo("alias [" + alias + "] missing"));
}
createIndex(index, Settings.EMPTY);
client().performRequest(HttpPut.METHOD_NAME, index + "/_alias/" + alias);
client().performRequest(new Request(HttpPut.METHOD_NAME, index + "/_alias/" + alias));
{
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index");
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testPing() throws IOException {
public void testInfo() throws IOException {
MainResponse info = highLevelClient().info(RequestOptions.DEFAULT);
// compare with what the low level client outputs
Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(HttpGet.METHOD_NAME, "/"));
Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(new Request(HttpGet.METHOD_NAME, "/")));
assertEquals(infoAsMap.get("cluster_name"), info.getClusterName().value());
assertEquals(infoAsMap.get("cluster_uuid"), info.getClusterUuid());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.elasticsearch.client;

import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
Expand All @@ -37,7 +35,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -49,19 +46,17 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {

@Before
public void indexDocuments() throws IOException {
StringEntity doc = new StringEntity("{\"text\":\"berlin\"}", ContentType.APPLICATION_JSON);
client().performRequest("PUT", "/index/doc/1", Collections.emptyMap(), doc);
doc = new StringEntity("{\"text\":\"amsterdam\"}", ContentType.APPLICATION_JSON);
client().performRequest("PUT", "/index/doc/2", Collections.emptyMap(), doc);
client().performRequest("PUT", "/index/doc/3", Collections.emptyMap(), doc);
client().performRequest("PUT", "/index/doc/4", Collections.emptyMap(), doc);
client().performRequest("PUT", "/index/doc/5", Collections.emptyMap(), doc);
client().performRequest("PUT", "/index/doc/6", Collections.emptyMap(), doc);
client().performRequest("POST", "/index/_refresh");

// add another index to test basic multi index support
client().performRequest("PUT", "/index2/doc/7", Collections.emptyMap(), doc);
client().performRequest("POST", "/index2/_refresh");
Request berlin = new Request("PUT", "/index/doc/berlin");
berlin.setJsonEntity("{\"text\":\"berlin\"}");
client().performRequest(berlin);
for (int i = 0; i < 6; i++) {
// add another index to test basic multi index support
String index = i == 0 ? "index2" : "index";
Request amsterdam = new Request("PUT", "/" + index + "/doc/amsterdam" + i);
amsterdam.setJsonEntity("{\"text\":\"amsterdam\"}");
client().performRequest(amsterdam);
}
client().performRequest(new Request("POST", "/_refresh"));
}

/**
Expand All @@ -71,10 +66,10 @@ public void indexDocuments() throws IOException {
public void testRankEvalRequest() throws IOException {
SearchSourceBuilder testQuery = new SearchSourceBuilder();
testQuery.query(new MatchAllQueryBuilder());
List<RatedDocument> amsterdamRatedDocs = createRelevant("index" , "2", "3", "4", "5");
amsterdamRatedDocs.addAll(createRelevant("index2", "7"));
List<RatedDocument> amsterdamRatedDocs = createRelevant("index" , "amsterdam1", "amsterdam2", "amsterdam3", "amsterdam4");
amsterdamRatedDocs.addAll(createRelevant("index2", "amsterdam0"));
RatedRequest amsterdamRequest = new RatedRequest("amsterdam_query", amsterdamRatedDocs, testQuery);
RatedRequest berlinRequest = new RatedRequest("berlin_query", createRelevant("index", "1"), testQuery);
RatedRequest berlinRequest = new RatedRequest("berlin_query", createRelevant("index", "berlin"), testQuery);
List<RatedRequest> specifications = new ArrayList<>();
specifications.add(amsterdamRequest);
specifications.add(berlinRequest);
Expand All @@ -94,7 +89,7 @@ public void testRankEvalRequest() throws IOException {
assertEquals(7, hitsAndRatings.size());
for (RatedSearchHit hit : hitsAndRatings) {
String id = hit.getSearchHit().getId();
if (id.equals("1") || id.equals("6")) {
if (id.equals("berlin") || id.equals("amsterdam5")) {
assertFalse(hit.getRating().isPresent());
} else {
assertEquals(1, hit.getRating().get().intValue());
Expand All @@ -106,15 +101,15 @@ public void testRankEvalRequest() throws IOException {
assertEquals(7, hitsAndRatings.size());
for (RatedSearchHit hit : hitsAndRatings) {
String id = hit.getSearchHit().getId();
if (id.equals("1")) {
if (id.equals("berlin")) {
assertEquals(1, hit.getRating().get().intValue());
} else {
assertFalse(hit.getRating().isPresent());
}
}

// now try this when test2 is closed
client().performRequest("POST", "index2/_close", Collections.emptyMap());
client().performRequest(new Request("POST", "index2/_close"));
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, SearchRequest.DEFAULT_INDICES_OPTIONS));
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
}
Expand Down
Loading