Skip to content

Commit 98200e7

Browse files
committed
Switch rolling restart to new style Requests (#32147)
In #29623 we added `Request` object flavored requests to the low level REST client and in #30315 we deprecated the old `performRequest`s. This changes all calls in the `qa/rolling-upgrade` project to use the new versions.
1 parent 1b5dc39 commit 98200e7

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package org.elasticsearch.upgrades;
2020

21-
import org.apache.http.entity.ContentType;
22-
import org.apache.http.entity.StringEntity;
2321
import org.elasticsearch.Version;
2422
import org.elasticsearch.action.support.PlainActionFuture;
2523
import org.elasticsearch.client.Request;
@@ -33,14 +31,12 @@
3331

3432
import java.io.IOException;
3533
import java.util.ArrayList;
36-
import java.util.Collections;
3734
import java.util.List;
3835
import java.util.Map;
3936
import java.util.concurrent.Future;
4037
import java.util.function.Predicate;
4138

4239
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
43-
import static java.util.Collections.emptyMap;
4440
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
4541
import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING;
4642
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
@@ -68,8 +64,9 @@ public void testHistoryUUIDIsGenerated() throws Exception {
6864
createIndex(index, settings.build());
6965
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
7066
ensureGreen(index);
71-
Response response = client().performRequest("GET", index + "/_stats", Collections.singletonMap("level", "shards"));
72-
assertOK(response);
67+
Request shardStatsRequest = new Request("GET", index + "/_stats");
68+
shardStatsRequest.addParameter("level", "shards");
69+
Response response = client().performRequest(shardStatsRequest);
7370
ObjectPath objectPath = ObjectPath.createFromResponse(response);
7471
List<Object> shardStats = objectPath.evaluate("indices." + index + ".shards.0");
7572
assertThat(shardStats, hasSize(2));
@@ -90,8 +87,9 @@ public void testHistoryUUIDIsGenerated() throws Exception {
9087
private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
9188
for (int i = 0; i < numDocs; i++) {
9289
final int id = idStart + i;
93-
assertOK(client().performRequest("PUT", index + "/test/" + id, emptyMap(),
94-
new StringEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}", ContentType.APPLICATION_JSON)));
90+
Request indexDoc = new Request("PUT", index + "/test/" + id);
91+
indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}");
92+
client().performRequest(indexDoc);
9593
}
9694
return numDocs;
9795
}
@@ -116,7 +114,7 @@ protected void doRun() throws Exception {
116114

117115
public void testRecoveryWithConcurrentIndexing() throws Exception {
118116
final String index = "recovery_with_concurrent_indexing";
119-
Response response = client().performRequest("GET", "_nodes");
117+
Response response = client().performRequest(new Request("GET", "_nodes"));
120118
ObjectPath objectPath = ObjectPath.createFromResponse(response);
121119
final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
122120
List<String> nodes = new ArrayList<>(nodeMap.keySet());
@@ -142,7 +140,7 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
142140
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null));
143141
asyncIndexDocs(index, 10, 50).get();
144142
ensureGreen(index);
145-
assertOK(client().performRequest("POST", index + "/_refresh"));
143+
client().performRequest(new Request("POST", index + "/_refresh"));
146144
assertCount(index, "_only_nodes:" + nodes.get(0), 60);
147145
assertCount(index, "_only_nodes:" + nodes.get(1), 60);
148146
assertCount(index, "_only_nodes:" + nodes.get(2), 60);
@@ -153,7 +151,7 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
153151
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null));
154152
asyncIndexDocs(index, 60, 50).get();
155153
ensureGreen(index);
156-
assertOK(client().performRequest("POST", index + "/_refresh"));
154+
client().performRequest(new Request("POST", index + "/_refresh"));
157155
assertCount(index, "_only_nodes:" + nodes.get(0), 110);
158156
assertCount(index, "_only_nodes:" + nodes.get(1), 110);
159157
assertCount(index, "_only_nodes:" + nodes.get(2), 110);
@@ -164,15 +162,16 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
164162
}
165163

166164
private void assertCount(final String index, final String preference, final int expectedCount) throws IOException {
167-
final Response response = client().performRequest("GET", index + "/_count", Collections.singletonMap("preference", preference));
168-
assertOK(response);
165+
final Request request = new Request("GET", index + "/_count");
166+
request.addParameter("preference", preference);
167+
final Response response = client().performRequest(request);
169168
final int actualCount = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString());
170169
assertThat(actualCount, equalTo(expectedCount));
171170
}
172171

173172

174173
private String getNodeId(Predicate<Version> versionPredicate) throws IOException {
175-
Response response = client().performRequest("GET", "_nodes");
174+
Response response = client().performRequest(new Request("GET", "_nodes"));
176175
ObjectPath objectPath = ObjectPath.createFromResponse(response);
177176
Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
178177
for (String id : nodesAsMap.keySet()) {
@@ -219,7 +218,7 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
219218
updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
220219
asyncIndexDocs(index, 10, 50).get();
221220
ensureGreen(index);
222-
assertOK(client().performRequest("POST", index + "/_refresh"));
221+
client().performRequest(new Request("POST", index + "/_refresh"));
223222
assertCount(index, "_primary", 60);
224223
break;
225224
case UPGRADED:
@@ -229,8 +228,8 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
229228
);
230229
asyncIndexDocs(index, 60, 50).get();
231230
ensureGreen(index);
232-
assertOK(client().performRequest("POST", index + "/_refresh"));
233-
Response response = client().performRequest("GET", "_nodes");
231+
client().performRequest(new Request("POST", index + "/_refresh"));
232+
Response response = client().performRequest(new Request("GET", "_nodes"));
234233
ObjectPath objectPath = ObjectPath.createFromResponse(response);
235234
final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
236235
List<String> nodes = new ArrayList<>(nodeMap.keySet());
@@ -280,10 +279,11 @@ public void testSearchGeoPoints() throws Exception {
280279

281280
// we need to make sure that requests are routed from a new node to the old node so we are sending the request a few times
282281
for (int i = 0; i < 10; i++) {
283-
Response response = client().performRequest("GET", index + "/_search",
284-
Collections.singletonMap("preference", "_only_nodes:gen:old"), // Make sure we only send this request to old nodes
285-
new StringEntity(requestBody, ContentType.APPLICATION_JSON));
286-
assertOK(response);
282+
Request request = new Request("GET", index + "/_search");
283+
request.setJsonEntity(requestBody);
284+
// Make sure we only send this request to old nodes
285+
request.addParameter("preference", "_only_nodes:gen:old");
286+
client().performRequest(request);
287287
}
288288
}
289289
}

0 commit comments

Comments
 (0)