7
7
*/
8
8
package org .opensearch .customcodecs .bwc ;
9
9
10
- import java .io .IOException ;
11
- import java .security .KeyManagementException ;
12
- import java .security .KeyStoreException ;
13
- import java .security .NoSuchAlgorithmException ;
14
- import java .util .HashMap ;
15
- import java .util .List ;
16
- import java .util .Map ;
17
- import java .util .Objects ;
18
- import javax .net .ssl .SSLEngine ;
19
-
20
10
import org .apache .hc .client5 .http .auth .AuthScope ;
21
11
import org .apache .hc .client5 .http .auth .UsernamePasswordCredentials ;
22
12
import org .apache .hc .client5 .http .impl .auth .BasicCredentialsProvider ;
29
19
import org .apache .hc .core5 .http .nio .ssl .TlsStrategy ;
30
20
import org .apache .hc .core5 .reactor .ssl .TlsDetails ;
31
21
import org .apache .hc .core5 .ssl .SSLContextBuilder ;
32
-
33
- import org .junit .AfterClass ;
34
- import org .junit .Assume ;
35
- import org .junit .Before ;
36
22
import org .opensearch .client .Response ;
37
23
import org .opensearch .client .RestClient ;
38
24
import org .opensearch .client .RestClientBuilder ;
45
31
import org .opensearch .core .xcontent .XContentBuilder ;
46
32
import org .opensearch .customcodecs .bwc .helper .RestHelper ;
47
33
import org .opensearch .test .rest .OpenSearchRestTestCase ;
34
+ import org .junit .AfterClass ;
35
+ import org .junit .Assume ;
36
+ import org .junit .Before ;
37
+
38
+ import javax .net .ssl .SSLEngine ;
39
+
40
+ import java .io .IOException ;
41
+ import java .security .KeyManagementException ;
42
+ import java .security .KeyStoreException ;
43
+ import java .security .NoSuchAlgorithmException ;
44
+ import java .util .HashMap ;
45
+ import java .util .List ;
46
+ import java .util .Map ;
47
+ import java .util .Objects ;
48
48
49
49
import static org .opensearch .client .RestClientBuilder .DEFAULT_MAX_CONN_PER_ROUTE ;
50
50
import static org .opensearch .client .RestClientBuilder .DEFAULT_MAX_CONN_TOTAL ;
@@ -62,14 +62,10 @@ public void testSetup() throws IOException {
62
62
logger .info ("Running Test for Cluster Type: {}" , CLUSTER_TYPE );
63
63
CLUSTER_NAME = System .getProperty ("tests.clustername" );
64
64
if (testUserRestClient == null ) {
65
- testUserRestClient = buildClient (
66
- super .restClientSettings (),
67
- super .getClusterHosts ().toArray (new HttpHost [0 ])
68
- );
65
+ testUserRestClient = buildClient (super .restClientSettings (), super .getClusterHosts ().toArray (new HttpHost [0 ]));
69
66
}
70
67
}
71
68
72
-
73
69
@ Override
74
70
protected RestClient buildClient (Settings settings , HttpHost [] hosts ) throws IOException {
75
71
RestClientBuilder builder = RestClient .builder (hosts );
@@ -97,30 +93,26 @@ protected void configureHttpOrHttpsClient(RestClientBuilder builder, Settings se
97
93
credentialsProvider .setCredentials (anyScope , new UsernamePasswordCredentials (username , password .toCharArray ()));
98
94
99
95
try {
100
- final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder
101
- .create ()
102
- .setHostnameVerifier (NoopHostnameVerifier .INSTANCE )
103
- .setSslContext (SSLContextBuilder .create ().loadTrustMaterial (null , (chains , authType ) -> true ).build ())
104
- // See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
105
- .setTlsDetailsFactory (new Factory <SSLEngine , TlsDetails >() {
106
- @ Override
107
- public TlsDetails create (final SSLEngine sslEngine ) {
108
- return new TlsDetails (sslEngine .getSession (), sslEngine .getApplicationProtocol ());
109
- }
110
- })
111
- .build ();
96
+ final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder .create ()
97
+ .setHostnameVerifier (NoopHostnameVerifier .INSTANCE )
98
+ .setSslContext (SSLContextBuilder .create ().loadTrustMaterial (null , (chains , authType ) -> true ).build ())
99
+ // See https://issues.apache.org/jira/browse/HTTPCLIENT-2219
100
+ .setTlsDetailsFactory (new Factory <SSLEngine , TlsDetails >() {
101
+ @ Override
102
+ public TlsDetails create (final SSLEngine sslEngine ) {
103
+ return new TlsDetails (sslEngine .getSession (), sslEngine .getApplicationProtocol ());
104
+ }
105
+ })
106
+ .build ();
112
107
113
108
builder .setHttpClientConfigCallback (httpClientBuilder -> {
114
- final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
115
- .create ()
116
- .setMaxConnPerRoute (DEFAULT_MAX_CONN_PER_ROUTE )
117
- .setMaxConnTotal (DEFAULT_MAX_CONN_TOTAL )
118
- .setTlsStrategy (tlsStrategy )
119
- .build ();
120
-
121
- return httpClientBuilder
122
- .setDefaultCredentialsProvider (credentialsProvider )
123
- .setConnectionManager (connectionManager );
109
+ final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder .create ()
110
+ .setMaxConnPerRoute (DEFAULT_MAX_CONN_PER_ROUTE )
111
+ .setMaxConnTotal (DEFAULT_MAX_CONN_TOTAL )
112
+ .setTlsStrategy (tlsStrategy )
113
+ .build ();
114
+
115
+ return httpClientBuilder .setDefaultCredentialsProvider (credentialsProvider ).setConnectionManager (connectionManager );
124
116
});
125
117
} catch (final NoSuchAlgorithmException | KeyManagementException | KeyStoreException ex ) {
126
118
throw new IOException (ex );
@@ -149,19 +141,17 @@ protected final boolean preserveReposUponCompletion() {
149
141
return true ;
150
142
}
151
143
152
-
153
144
@ Override
154
145
protected final Settings restClientSettings () {
155
146
return Settings .builder ()
156
- .put (super .restClientSettings ())
157
- // increase the timeout here to 90 seconds to handle long waits for a green
158
- // cluster health. the waits for green need to be longer than a minute to
159
- // account for delayed shards
160
- .put (OpenSearchRestTestCase .CLIENT_SOCKET_TIMEOUT , "90s" )
161
- .build ();
147
+ .put (super .restClientSettings ())
148
+ // increase the timeout here to 90 seconds to handle long waits for a green
149
+ // cluster health. the waits for green need to be longer than a minute to
150
+ // account for delayed shards
151
+ .put (OpenSearchRestTestCase .CLIENT_SOCKET_TIMEOUT , "90s" )
152
+ .build ();
162
153
}
163
154
164
-
165
155
/**
166
156
* Tests backward compatibility by created a test user and role with DLS, FLS and masked field settings. Ingests
167
157
* data into a test index and runs a matchAll query against the same.
@@ -176,7 +166,6 @@ public void testDataIngestionAndSearchBackwardsCompatibility() throws Exception
176
166
searchMatchAll (index );
177
167
}
178
168
179
-
180
169
/**
181
170
* Ingests data into the test index
182
171
*
@@ -195,7 +184,7 @@ private void ingestData(String index) throws IOException {
195
184
put ("_index" , index );
196
185
}
197
186
});
198
-
187
+
199
188
try (final XContentBuilder contentBuilder = MediaTypeRegistry .JSON .contentBuilder ()) {
200
189
contentBuilder .map (indexRequest );
201
190
bulkRequestBody .append (contentBuilder .toString () + "\n " );
@@ -204,10 +193,10 @@ private void ingestData(String index) throws IOException {
204
193
bulkRequestBody .append (Song .randomSong ().asJson () + "\n " );
205
194
}
206
195
List <Response > responses = RestHelper .requestAgainstAllNodes (
207
- testUserRestClient ,
208
- "POST" ,
209
- "_bulk?refresh=wait_for" ,
210
- RestHelper .toHttpEntity (bulkRequestBody .toString ())
196
+ testUserRestClient ,
197
+ "POST" ,
198
+ "_bulk?refresh=wait_for" ,
199
+ RestHelper .toHttpEntity (bulkRequestBody .toString ())
211
200
);
212
201
responses .forEach (r -> assertEquals (200 , r .getStatusLine ().getStatusCode ()));
213
202
}
@@ -223,10 +212,10 @@ private void searchMatchAll(String index) throws IOException {
223
212
int numberOfRequests = Randomness .get ().nextInt (10 );
224
213
while (numberOfRequests -- > 0 ) {
225
214
List <Response > responses = RestHelper .requestAgainstAllNodes (
226
- testUserRestClient ,
227
- "POST" ,
228
- index + "/_search" ,
229
- RestHelper .toHttpEntity (matchAllQuery )
215
+ testUserRestClient ,
216
+ "POST" ,
217
+ index + "/_search" ,
218
+ RestHelper .toHttpEntity (matchAllQuery )
230
219
);
231
220
responses .forEach (r -> assertEquals (200 , r .getStatusLine ().getStatusCode ()));
232
221
}
@@ -247,13 +236,13 @@ private void createIndexIfNotExists(String index) throws IOException {
247
236
248
237
// creating index
249
238
createIndex (
250
- index ,
251
- Settings .builder ()
252
- .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
253
- .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
254
- .put ("index.codec" , randomFrom ("zstd" , "zstd_no_dict" ))
255
- .put ("index.codec.compression_level" , randomIntBetween (1 , 6 ))
256
- .build ()
239
+ index ,
240
+ Settings .builder ()
241
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
242
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
243
+ .put ("index.codec" , randomFrom ("zstd" , "zstd_no_dict" ))
244
+ .put ("index.codec.compression_level" , randomIntBetween (1 , 6 ))
245
+ .build ()
257
246
);
258
247
ensureGreen (index );
259
248
}
0 commit comments