18
18
*/
19
19
package org .elasticsearch .upgrades ;
20
20
21
- import org .apache .http .entity .ContentType ;
22
- import org .apache .http .entity .StringEntity ;
23
21
import org .elasticsearch .Version ;
24
22
import org .elasticsearch .action .support .PlainActionFuture ;
25
23
import org .elasticsearch .client .Request ;
33
31
34
32
import java .io .IOException ;
35
33
import java .util .ArrayList ;
36
- import java .util .Collections ;
37
34
import java .util .List ;
38
35
import java .util .Map ;
39
36
import java .util .concurrent .Future ;
40
37
import java .util .function .Predicate ;
41
38
42
39
import static com .carrotsearch .randomizedtesting .RandomizedTest .randomAsciiOfLength ;
43
- import static java .util .Collections .emptyMap ;
44
40
import static org .elasticsearch .cluster .routing .UnassignedInfo .INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING ;
45
41
import static org .elasticsearch .cluster .routing .allocation .decider .EnableAllocationDecider .INDEX_ROUTING_ALLOCATION_ENABLE_SETTING ;
46
42
import static org .elasticsearch .cluster .routing .allocation .decider .MaxRetryAllocationDecider .SETTING_ALLOCATION_MAX_RETRY ;
@@ -68,8 +64,9 @@ public void testHistoryUUIDIsGenerated() throws Exception {
68
64
createIndex (index , settings .build ());
69
65
} else if (CLUSTER_TYPE == ClusterType .UPGRADED ) {
70
66
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 );
73
70
ObjectPath objectPath = ObjectPath .createFromResponse (response );
74
71
List <Object > shardStats = objectPath .evaluate ("indices." + index + ".shards.0" );
75
72
assertThat (shardStats , hasSize (2 ));
@@ -90,8 +87,9 @@ public void testHistoryUUIDIsGenerated() throws Exception {
90
87
private int indexDocs (String index , final int idStart , final int numDocs ) throws IOException {
91
88
for (int i = 0 ; i < numDocs ; i ++) {
92
89
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 );
95
93
}
96
94
return numDocs ;
97
95
}
@@ -116,7 +114,7 @@ protected void doRun() throws Exception {
116
114
117
115
public void testRecoveryWithConcurrentIndexing () throws Exception {
118
116
final String index = "recovery_with_concurrent_indexing" ;
119
- Response response = client ().performRequest ("GET" , "_nodes" );
117
+ Response response = client ().performRequest (new Request ( "GET" , "_nodes" ) );
120
118
ObjectPath objectPath = ObjectPath .createFromResponse (response );
121
119
final Map <String , Object > nodeMap = objectPath .evaluate ("nodes" );
122
120
List <String > nodes = new ArrayList <>(nodeMap .keySet ());
@@ -142,7 +140,7 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
142
140
updateIndexSettings (index , Settings .builder ().put (INDEX_ROUTING_ALLOCATION_ENABLE_SETTING .getKey (), (String )null ));
143
141
asyncIndexDocs (index , 10 , 50 ).get ();
144
142
ensureGreen (index );
145
- assertOK ( client ().performRequest ("POST" , index + "/_refresh" ));
143
+ client ().performRequest ( new Request ("POST" , index + "/_refresh" ));
146
144
assertCount (index , "_only_nodes:" + nodes .get (0 ), 60 );
147
145
assertCount (index , "_only_nodes:" + nodes .get (1 ), 60 );
148
146
assertCount (index , "_only_nodes:" + nodes .get (2 ), 60 );
@@ -153,7 +151,7 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
153
151
updateIndexSettings (index , Settings .builder ().put (INDEX_ROUTING_ALLOCATION_ENABLE_SETTING .getKey (), (String )null ));
154
152
asyncIndexDocs (index , 60 , 50 ).get ();
155
153
ensureGreen (index );
156
- assertOK ( client ().performRequest ("POST" , index + "/_refresh" ));
154
+ client ().performRequest ( new Request ("POST" , index + "/_refresh" ));
157
155
assertCount (index , "_only_nodes:" + nodes .get (0 ), 110 );
158
156
assertCount (index , "_only_nodes:" + nodes .get (1 ), 110 );
159
157
assertCount (index , "_only_nodes:" + nodes .get (2 ), 110 );
@@ -164,15 +162,16 @@ public void testRecoveryWithConcurrentIndexing() throws Exception {
164
162
}
165
163
166
164
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 );
169
168
final int actualCount = Integer .parseInt (ObjectPath .createFromResponse (response ).evaluate ("count" ).toString ());
170
169
assertThat (actualCount , equalTo (expectedCount ));
171
170
}
172
171
173
172
174
173
private String getNodeId (Predicate <Version > versionPredicate ) throws IOException {
175
- Response response = client ().performRequest ("GET" , "_nodes" );
174
+ Response response = client ().performRequest (new Request ( "GET" , "_nodes" ) );
176
175
ObjectPath objectPath = ObjectPath .createFromResponse (response );
177
176
Map <String , Object > nodesAsMap = objectPath .evaluate ("nodes" );
178
177
for (String id : nodesAsMap .keySet ()) {
@@ -219,7 +218,7 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
219
218
updateIndexSettings (index , Settings .builder ().put ("index.routing.allocation.include._id" , newNode ));
220
219
asyncIndexDocs (index , 10 , 50 ).get ();
221
220
ensureGreen (index );
222
- assertOK ( client ().performRequest ("POST" , index + "/_refresh" ));
221
+ client ().performRequest ( new Request ("POST" , index + "/_refresh" ));
223
222
assertCount (index , "_primary" , 60 );
224
223
break ;
225
224
case UPGRADED :
@@ -229,8 +228,8 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
229
228
);
230
229
asyncIndexDocs (index , 60 , 50 ).get ();
231
230
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" ) );
234
233
ObjectPath objectPath = ObjectPath .createFromResponse (response );
235
234
final Map <String , Object > nodeMap = objectPath .evaluate ("nodes" );
236
235
List <String > nodes = new ArrayList <>(nodeMap .keySet ());
@@ -280,10 +279,11 @@ public void testSearchGeoPoints() throws Exception {
280
279
281
280
// 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
282
281
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 );
287
287
}
288
288
}
289
289
}
0 commit comments