Skip to content

Commit c6c9075

Browse files
authored
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 320f1d2 commit c6c9075

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
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;
@@ -32,14 +30,12 @@
3230

3331
import java.io.IOException;
3432
import java.util.ArrayList;
35-
import java.util.Collections;
3633
import java.util.List;
3734
import java.util.Map;
3835
import java.util.concurrent.Future;
3936
import java.util.function.Predicate;
4037

4138
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
42-
import static java.util.Collections.emptyMap;
4339
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
4440
import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING;
4541
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
@@ -65,8 +61,9 @@ public void testHistoryUUIDIsGenerated() throws Exception {
6561
createIndex(index, settings.build());
6662
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
6763
ensureGreen(index);
68-
Response response = client().performRequest("GET", index + "/_stats", Collections.singletonMap("level", "shards"));
69-
assertOK(response);
64+
Request shardStatsRequest = new Request("GET", index + "/_stats");
65+
shardStatsRequest.addParameter("level", "shards");
66+
Response response = client().performRequest(shardStatsRequest);
7067
ObjectPath objectPath = ObjectPath.createFromResponse(response);
7168
List<Object> shardStats = objectPath.evaluate("indices." + index + ".shards.0");
7269
assertThat(shardStats, hasSize(2));
@@ -87,8 +84,9 @@ public void testHistoryUUIDIsGenerated() throws Exception {
8784
private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
8885
for (int i = 0; i < numDocs; i++) {
8986
final int id = idStart + i;
90-
assertOK(client().performRequest("PUT", index + "/test/" + id, emptyMap(),
91-
new StringEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}", ContentType.APPLICATION_JSON)));
87+
Request indexDoc = new Request("PUT", index + "/test/" + id);
88+
indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}");
89+
client().performRequest(indexDoc);
9290
}
9391
return numDocs;
9492
}
@@ -113,7 +111,7 @@ protected void doRun() throws Exception {
113111

114112
public void testRecoveryWithConcurrentIndexing() throws Exception {
115113
final String index = "recovery_with_concurrent_indexing";
116-
Response response = client().performRequest("GET", "_nodes");
114+
Response response = client().performRequest(new Request("GET", "_nodes"));
117115
ObjectPath objectPath = ObjectPath.createFromResponse(response);
118116
final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
119117
List<String> nodes = new ArrayList<>(nodeMap.keySet());
@@ -139,7 +137,7 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
139137
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null));
140138
asyncIndexDocs(index, 10, 50).get();
141139
ensureGreen(index);
142-
assertOK(client().performRequest("POST", index + "/_refresh"));
140+
client().performRequest(new Request("POST", index + "/_refresh"));
143141
assertCount(index, "_only_nodes:" + nodes.get(0), 60);
144142
assertCount(index, "_only_nodes:" + nodes.get(1), 60);
145143
assertCount(index, "_only_nodes:" + nodes.get(2), 60);
@@ -150,7 +148,7 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
150148
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null));
151149
asyncIndexDocs(index, 60, 50).get();
152150
ensureGreen(index);
153-
assertOK(client().performRequest("POST", index + "/_refresh"));
151+
client().performRequest(new Request("POST", index + "/_refresh"));
154152
assertCount(index, "_only_nodes:" + nodes.get(0), 110);
155153
assertCount(index, "_only_nodes:" + nodes.get(1), 110);
156154
assertCount(index, "_only_nodes:" + nodes.get(2), 110);
@@ -161,15 +159,16 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
161159
}
162160

163161
private void assertCount(final String index, final String preference, final int expectedCount) throws IOException {
164-
final Response response = client().performRequest("GET", index + "/_count", Collections.singletonMap("preference", preference));
165-
assertOK(response);
162+
final Request request = new Request("GET", index + "/_count");
163+
request.addParameter("preference", preference);
164+
final Response response = client().performRequest(request);
166165
final int actualCount = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString());
167166
assertThat(actualCount, equalTo(expectedCount));
168167
}
169168

170169

171170
private String getNodeId(Predicate<Version> versionPredicate) throws IOException {
172-
Response response = client().performRequest("GET", "_nodes");
171+
Response response = client().performRequest(new Request("GET", "_nodes"));
173172
ObjectPath objectPath = ObjectPath.createFromResponse(response);
174173
Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
175174
for (String id : nodesAsMap.keySet()) {
@@ -216,7 +215,7 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
216215
updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
217216
asyncIndexDocs(index, 10, 50).get();
218217
ensureGreen(index);
219-
assertOK(client().performRequest("POST", index + "/_refresh"));
218+
client().performRequest(new Request("POST", index + "/_refresh"));
220219
assertCount(index, "_only_nodes:" + newNode, 60);
221220
break;
222221
case UPGRADED:
@@ -226,8 +225,8 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
226225
);
227226
asyncIndexDocs(index, 60, 50).get();
228227
ensureGreen(index);
229-
assertOK(client().performRequest("POST", index + "/_refresh"));
230-
Response response = client().performRequest("GET", "_nodes");
228+
client().performRequest(new Request("POST", index + "/_refresh"));
229+
Response response = client().performRequest(new Request("GET", "_nodes"));
231230
ObjectPath objectPath = ObjectPath.createFromResponse(response);
232231
final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
233232
List<String> nodes = new ArrayList<>(nodeMap.keySet());

0 commit comments

Comments
 (0)