Skip to content

Commit 3d15677

Browse files
committed
Switch distribution to new style Requests
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `distribution/archives/integ-test-zip` project to use the new versions.
1 parent 21d67d1 commit 3d15677

File tree

4 files changed

+78
-61
lines changed

4 files changed

+78
-61
lines changed

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/CreatedLocationHeaderIT.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,31 @@ public void testIndexWithoutId() throws IOException {
5050
}
5151

5252
public void testUpsert() throws IOException {
53-
locationTestCase(client().performRequest("POST", "test/test/1/_update", emptyMap(), new StringEntity("{"
54-
+ "\"doc\": {\"test\": \"test\"},"
55-
+ "\"doc_as_upsert\": true}", ContentType.APPLICATION_JSON)));
53+
Request request = new Request("POST", "test/test/1/_update");
54+
request.setJsonEntity("{"
55+
+ "\"doc\": {\"test\": \"test\"},"
56+
+ "\"doc_as_upsert\": true}");
57+
locationTestCase(client().performRequest(request));
5658
}
5759

5860
private void locationTestCase(String method, String url) throws IOException {
59-
locationTestCase(client().performRequest(method, url, emptyMap(),
60-
new StringEntity("{\"test\": \"test\"}", ContentType.APPLICATION_JSON)));
61+
Request request = new Request(method, url);
62+
request.setJsonEntity("{\"test\": \"test\"}");
63+
locationTestCase(client().performRequest(request));
6164
// we have to delete the index otherwise the second indexing request will route to the single shard and not produce a 201
6265
final Response response = client().performRequest(new Request("DELETE", "test"));
6366
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
64-
locationTestCase(client().performRequest(method, url + "?routing=cat", emptyMap(),
65-
new StringEntity("{\"test\": \"test\"}", ContentType.APPLICATION_JSON)));
67+
request = new Request(method, url);
68+
request.addParameter("routing", "cat");
69+
request.setJsonEntity("{\"test\": \"test\"}");
70+
locationTestCase(client().performRequest(request));
6671
}
6772

6873
private void locationTestCase(Response response) throws IOException {
6974
assertEquals(201, response.getStatusLine().getStatusCode());
7075
String location = response.getHeader("Location");
7176
assertThat(location, startsWith("/test/test/"));
72-
Response getResponse = client().performRequest("GET", location);
77+
Response getResponse = client().performRequest(new Request("GET", location));
7378
assertEquals(singletonMap("test", "test"), entityAsMap(getResponse).get("_source"));
7479
}
7580

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/NodeRestUsageIT.java

+25-20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.http.entity.StringEntity;
2424
import org.elasticsearch.client.Response;
2525
import org.elasticsearch.client.ResponseException;
26+
import org.elasticsearch.client.Request;
2627

2728
import java.io.IOException;
2829
import java.util.Collections;
@@ -39,8 +40,8 @@ public class NodeRestUsageIT extends ESRestTestCase {
3940
@SuppressWarnings("unchecked")
4041
public void testWithRestUsage() throws IOException {
4142
// First get the current usage figures
42-
Response beforeResponse = client().performRequest("GET",
43-
randomFrom("_nodes/usage", "_nodes/usage/rest_actions", "_nodes/usage/_all"));
43+
String path = randomFrom("_nodes/usage", "_nodes/usage/rest_actions", "_nodes/usage/_all");
44+
Response beforeResponse = client().performRequest(new Request("GET", path));
4445
Map<String, Object> beforeResponseBodyMap = entityAsMap(beforeResponse);
4546
assertThat(beforeResponseBodyMap, notNullValue());
4647
Map<String, Object> before_nodesMap = (Map<String, Object>) beforeResponseBodyMap.get("_nodes");
@@ -80,24 +81,28 @@ public void testWithRestUsage() throws IOException {
8081
}
8182

8283
// Do some requests to get some rest usage stats
83-
client().performRequest("PUT", "/test");
84-
client().performRequest("POST", "/test/doc/1", Collections.emptyMap(),
85-
new StringEntity("{ \"foo\": \"bar\"}", ContentType.APPLICATION_JSON));
86-
client().performRequest("POST", "/test/doc/2", Collections.emptyMap(),
87-
new StringEntity("{ \"foo\": \"bar\"}", ContentType.APPLICATION_JSON));
88-
client().performRequest("POST", "/test/doc/3", Collections.emptyMap(),
89-
new StringEntity("{ \"foo\": \"bar\"}", ContentType.APPLICATION_JSON));
90-
client().performRequest("GET", "/test/_search");
91-
client().performRequest("POST", "/test/doc/4", Collections.emptyMap(),
92-
new StringEntity("{ \"foo\": \"bar\"}", ContentType.APPLICATION_JSON));
93-
client().performRequest("POST", "/test/_refresh");
94-
client().performRequest("GET", "/_cat/indices");
95-
client().performRequest("GET", "/_nodes");
96-
client().performRequest("GET", "/test/_search");
97-
client().performRequest("GET", "/_nodes/stats");
98-
client().performRequest("DELETE", "/test");
84+
client().performRequest(new Request("PUT", "/test"));
85+
Request request = new Request("POST", "/test/doc/1");
86+
request.setJsonEntity("{\"foo\": \"bar\"}");
87+
client().performRequest(request);
88+
request = new Request("POST", "/test/doc/2");
89+
request.setJsonEntity("{\"foo\": \"bar\"}");
90+
client().performRequest(request);
91+
request = new Request("POST", "/test/doc/3");
92+
request.setJsonEntity("{\"foo\": \"bar\"}");
93+
client().performRequest(request);
94+
client().performRequest(new Request("GET", "/test/_search"));
95+
request = new Request("POST", "/test/doc/4");
96+
request.setJsonEntity("{\"foo\": \"bar\"}");
97+
client().performRequest(request);
98+
client().performRequest(new Request("POST", "/test/_refresh"));
99+
client().performRequest(new Request("GET", "/_cat/indices"));
100+
client().performRequest(new Request("GET", "/_nodes"));
101+
client().performRequest(new Request("GET", "/test/_search"));
102+
client().performRequest(new Request("GET", "/_nodes/stats"));
103+
client().performRequest(new Request("DELETE", "/test"));
99104

100-
Response response = client().performRequest("GET", "_nodes/usage");
105+
Response response = client().performRequest(new Request("GET", "_nodes/usage"));
101106
Map<String, Object> responseBodyMap = entityAsMap(response);
102107
assertThat(responseBodyMap, notNullValue());
103108
Map<String, Object> _nodesMap = (Map<String, Object>) responseBodyMap.get("_nodes");
@@ -139,7 +144,7 @@ public void testWithRestUsage() throws IOException {
139144

140145
public void testMetricsWithAll() throws IOException {
141146
ResponseException exception = expectThrows(ResponseException.class,
142-
() -> client().performRequest("GET", "_nodes/usage/_all,rest_actions"));
147+
() -> client().performRequest(new Request("GET", "_nodes/usage/_all,rest_actions")));
143148
assertNotNull(exception);
144149
assertThat(exception.getMessage(), containsString("\"type\":\"illegal_argument_exception\","
145150
+ "\"reason\":\"request [_nodes/usage/_all,rest_actions] contains _all and individual metrics [_all,rest_actions]\""));

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RequestsWithoutContentIT.java

+19-18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.test.rest;
2121

2222
import org.elasticsearch.client.ResponseException;
23+
import org.elasticsearch.client.Request;
2324

2425
import java.io.IOException;
2526

@@ -28,56 +29,56 @@
2829
public class RequestsWithoutContentIT extends ESRestTestCase {
2930

3031
public void testIndexMissingBody() throws IOException {
31-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
32-
randomBoolean() ? "POST" : "PUT", "/idx/type/123"));
32+
ResponseException responseException = expectThrows(ResponseException.class, () ->
33+
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/idx/type/123")));
3334
assertResponseException(responseException, "request body is required");
3435
}
3536

3637
public void testBulkMissingBody() throws IOException {
37-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
38-
randomBoolean() ? "POST" : "PUT", "/_bulk"));
38+
ResponseException responseException = expectThrows(ResponseException.class, () ->
39+
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/_bulk")));
3940
assertResponseException(responseException, "request body is required");
4041
}
4142

4243
public void testPutSettingsMissingBody() throws IOException {
43-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
44-
"PUT", "/_settings"));
44+
ResponseException responseException = expectThrows(ResponseException.class, () ->
45+
client().performRequest(new Request("PUT", "/_settings")));
4546
assertResponseException(responseException, "request body is required");
4647
}
4748

4849
public void testPutMappingsMissingBody() throws IOException {
49-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
50-
randomBoolean() ? "POST" : "PUT", "/test_index/test_type/_mapping"));
50+
ResponseException responseException = expectThrows(ResponseException.class, () ->
51+
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/test_index/test_type/_mapping")));
5152
assertResponseException(responseException, "request body is required");
5253
}
5354

5455
public void testPutIndexTemplateMissingBody() throws IOException {
55-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
56-
randomBoolean() ? "PUT" : "POST", "/_template/my_template"));
56+
ResponseException responseException = expectThrows(ResponseException.class, () ->
57+
client().performRequest(new Request(randomBoolean() ? "PUT" : "POST", "/_template/my_template")));
5758
assertResponseException(responseException, "request body is required");
5859
}
5960

6061
public void testMultiSearchMissingBody() throws IOException {
61-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
62-
randomBoolean() ? "POST" : "GET", "/_msearch"));
62+
ResponseException responseException = expectThrows(ResponseException.class, () ->
63+
client().performRequest(new Request(randomBoolean() ? "POST" : "GET", "/_msearch")));
6364
assertResponseException(responseException, "request body or source parameter is required");
6465
}
6566

6667
public void testPutPipelineMissingBody() throws IOException {
67-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
68-
"PUT", "/_ingest/pipeline/my_pipeline"));
68+
ResponseException responseException = expectThrows(ResponseException.class, () ->
69+
client().performRequest(new Request("PUT", "/_ingest/pipeline/my_pipeline")));
6970
assertResponseException(responseException, "request body or source parameter is required");
7071
}
7172

7273
public void testSimulatePipelineMissingBody() throws IOException {
73-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
74-
randomBoolean() ? "POST" : "GET", "/_ingest/pipeline/my_pipeline/_simulate"));
74+
ResponseException responseException = expectThrows(ResponseException.class, () ->
75+
client().performRequest(new Request(randomBoolean() ? "POST" : "GET", "/_ingest/pipeline/my_pipeline/_simulate")));
7576
assertResponseException(responseException, "request body or source parameter is required");
7677
}
7778

7879
public void testPutScriptMissingBody() throws IOException {
79-
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
80-
randomBoolean() ? "POST" : "PUT", "/_scripts/lang"));
80+
ResponseException responseException = expectThrows(ResponseException.class, () ->
81+
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/_scripts/lang")));
8182
assertResponseException(responseException, "request body is required");
8283
}
8384

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.client.Response;
2929
import org.elasticsearch.client.ResponseException;
3030
import org.elasticsearch.client.ResponseListener;
31+
import org.elasticsearch.client.Request;
3132
import org.junit.After;
3233
import org.junit.Before;
3334

@@ -46,13 +47,14 @@ public class WaitForRefreshAndCloseTests extends ESRestTestCase {
4647
@Before
4748
public void setupIndex() throws IOException {
4849
try {
49-
client().performRequest("DELETE", indexName());
50+
client().performRequest(new Request("DELETE", indexName()));
5051
} catch (ResponseException e) {
5152
// If we get an error, it should be because the index doesn't exist
5253
assertEquals(404, e.getResponse().getStatusLine().getStatusCode());
5354
}
54-
client().performRequest("PUT", indexName(), emptyMap(),
55-
new StringEntity("{\"settings\":{\"refresh_interval\":-1}}", ContentType.APPLICATION_JSON));
55+
Request request = new Request("PUT", indexName());
56+
request.setJsonEntity("{\"settings\":{\"refresh_interval\":-1}}");
57+
client().performRequest(request);
5658
}
5759

5860
@After
@@ -69,17 +71,20 @@ private String docPath() {
6971
}
7072

7173
public void testIndexAndThenClose() throws Exception {
72-
closeWhileListenerEngaged(start("PUT", "", new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON)));
74+
closeWhileListenerEngaged(start("PUT", "", "{\"test\":\"test\"}"));
7375
}
7476

7577
public void testUpdateAndThenClose() throws Exception {
76-
client().performRequest("PUT", docPath(), emptyMap(), new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON));
77-
closeWhileListenerEngaged(start("POST", "/_update",
78-
new StringEntity("{\"doc\":{\"name\":\"test\"}}", ContentType.APPLICATION_JSON)));
78+
Request request = new Request("PUT", docPath());
79+
request.setJsonEntity("{\"test\":\"test\"}");
80+
client().performRequest(request);
81+
closeWhileListenerEngaged(start("POST", "/_update", "{\"doc\":{\"name\":\"test\"}}"));
7982
}
8083

8184
public void testDeleteAndThenClose() throws Exception {
82-
client().performRequest("PUT", docPath(), emptyMap(), new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON));
85+
Request request = new Request("PUT", docPath());
86+
request.setJsonEntity("{\"test\":\"test\"}");
87+
client().performRequest(request);
8388
closeWhileListenerEngaged(start("DELETE", "", null));
8489
}
8590

@@ -88,7 +93,7 @@ private void closeWhileListenerEngaged(ActionFuture<String> future) throws Excep
8893
assertBusy(() -> {
8994
Map<String, Object> stats;
9095
try {
91-
stats = entityAsMap(client().performRequest("GET", indexName() + "/_stats/refresh"));
96+
stats = entityAsMap(client().performRequest(new Request("GET", indexName() + "/_stats/refresh")));
9297
} catch (IOException e) {
9398
throw new RuntimeException(e);
9499
}
@@ -105,18 +110,19 @@ private void closeWhileListenerEngaged(ActionFuture<String> future) throws Excep
105110
});
106111

107112
// Close the index. That should flush the listener.
108-
client().performRequest("POST", indexName() + "/_close");
113+
client().performRequest(new Request("POST", indexName() + "/_close"));
109114

110115
// The request shouldn't fail. It certainly shouldn't hang.
111116
future.get();
112117
}
113118

114-
private ActionFuture<String> start(String method, String path, HttpEntity body) {
119+
private ActionFuture<String> start(String method, String path, String body) {
115120
PlainActionFuture<String> future = new PlainActionFuture<>();
116-
Map<String, String> params = new HashMap<>();
117-
params.put("refresh", "wait_for");
118-
params.put("error_trace", "");
119-
client().performRequestAsync(method, docPath() + path, params, body, new ResponseListener() {
121+
Request request = new Request(method, docPath() + path);
122+
request.addParameter("refresh", "wait_for");
123+
request.addParameter("error_trace", "");
124+
request.setJsonEntity(body);
125+
client().performRequestAsync(request, new ResponseListener() {
120126
@Override
121127
public void onSuccess(Response response) {
122128
try {

0 commit comments

Comments
 (0)