8
8
import org .apache .http .HttpHost ;
9
9
import org .apache .http .entity .ContentType ;
10
10
import org .apache .http .entity .StringEntity ;
11
+ import org .elasticsearch .client .Request ;
11
12
import org .elasticsearch .client .Response ;
12
13
import org .elasticsearch .client .RestClient ;
13
14
import org .elasticsearch .common .Strings ;
@@ -53,7 +54,7 @@ public void testIndexOnWrongNode() throws IOException {
53
54
String firstHostName = null ;
54
55
55
56
String match = firstHost .getHostName () + ":" + firstHost .getPort ();
56
- Map <String , Object > nodesInfo = responseToMap (client ().performRequest ("GET" , "/_nodes" ));
57
+ Map <String , Object > nodesInfo = responseToMap (client ().performRequest (new Request ( "GET" , "/_nodes" ) ));
57
58
@ SuppressWarnings ("unchecked" )
58
59
Map <String , Object > nodes = (Map <String , Object >) nodesInfo .get ("nodes" );
59
60
for (Map .Entry <String , Object > node : nodes .entrySet ()) {
@@ -74,7 +75,9 @@ public void testIndexOnWrongNode() throws IOException {
74
75
}
75
76
index .endObject ();
76
77
index .endObject ();
77
- client ().performRequest ("PUT" , "/test" , emptyMap (), new StringEntity (Strings .toString (index ), ContentType .APPLICATION_JSON ));
78
+ Request request = new Request ("PUT" , "/test" );
79
+ request .setJsonEntity (Strings .toString (index ));
80
+ client ().performRequest (request );
78
81
int documents = between (10 , 100 );
79
82
createTestData (documents );
80
83
@@ -84,6 +87,9 @@ public void testIndexOnWrongNode() throws IOException {
84
87
}
85
88
86
89
private void createTestData (int documents ) throws UnsupportedCharsetException , IOException {
90
+ Request request = new Request ("PUT" , "/test/test/_bulk" );
91
+ request .addParameter ("refresh" , "true" );
92
+
87
93
StringBuilder bulk = new StringBuilder ();
88
94
for (int i = 0 ; i < documents ; i ++) {
89
95
int a = 3 * i ;
@@ -92,8 +98,9 @@ private void createTestData(int documents) throws UnsupportedCharsetException, I
92
98
bulk .append ("{\" index\" :{\" _id\" :\" " + i + "\" }\n " );
93
99
bulk .append ("{\" a\" : " + a + ", \" b\" : " + b + ", \" c\" : " + c + "}\n " );
94
100
}
95
- client ().performRequest ("PUT" , "/test/test/_bulk" , singletonMap ("refresh" , "true" ),
96
- new StringEntity (bulk .toString (), ContentType .APPLICATION_JSON ));
101
+ request .setJsonEntity (bulk .toString ());
102
+
103
+ client ().performRequest (request );
97
104
}
98
105
99
106
private Map <String , Object > responseToMap (Response response ) throws IOException {
@@ -108,14 +115,12 @@ private void assertCount(RestClient client, int count) throws IOException {
108
115
expected .put ("columns" , singletonList (columnInfo (mode , "COUNT(1)" , "long" , JDBCType .BIGINT , 20 )));
109
116
expected .put ("rows" , singletonList (singletonList (count )));
110
117
111
- Map <String , String > params = new TreeMap <>();
112
- params .put ("format" , "json" ); // JSON is easier to parse then a table
113
- if (Strings .hasText (mode )) {
114
- params .put ("mode" , mode ); // JDBC or PLAIN mode
118
+ Request request = new Request ("POST" , "/_xpack/sql" );
119
+ if (false == mode .isEmpty ()) {
120
+ request .addParameter ("mode" , mode );
115
121
}
116
-
117
- Map <String , Object > actual = responseToMap (client .performRequest ("POST" , "/_xpack/sql" , params ,
118
- new StringEntity ("{\" query\" : \" SELECT COUNT(*) FROM test\" }" , ContentType .APPLICATION_JSON )));
122
+ request .setJsonEntity ("{\" query\" : \" SELECT COUNT(*) FROM test\" }" );
123
+ Map <String , Object > actual = responseToMap (client .performRequest (request ));
119
124
120
125
if (false == expected .equals (actual )) {
121
126
NotEqualMessageBuilder message = new NotEqualMessageBuilder ();
0 commit comments