Skip to content

Commit

Permalink
Merge pull request #148 from Jingw98/master
Browse files Browse the repository at this point in the history
Fix issue elastic#23231
  • Loading branch information
kblincoe authored Apr 3, 2017
2 parents e9116c4 + 6992889 commit ad380e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ private CloseableHttpAsyncClient createHttpClient() {

HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfigBuilder.build())
//default settings for connection pooling may be too constraining
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE).setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL);
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE)
.setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
// use system properties when it is validate
//this help on reindex as it uses the RestClient internally
//and can be easily configured to trust different certificates
.useSystemProperties();
if (httpClientConfigCallback != null) {
httpClientBuilder = httpClientConfigCallback.customizeHttpClient(httpClientBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,19 @@ private static void assertSetPathPrefixThrows(final String pathPrefix) {
assertThat(e.getMessage(), containsString(pathPrefix));
}
}

public void testSetSystemProperties(){
//this unit test tests if the ClientBuilder build client according to the system properties
//set the http.maxConnections properties to invalid value
//this will cause NumberFormatException when building the client with system properties
System.setProperty("http.maxConnections","invalid value");
try (RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build()) {
fail("should have failed");
} catch (NumberFormatException | IOException e1) {
//reset the system property to avoid break other test caeses
System.clearProperty("http.maxConnections");
}

}

}

0 comments on commit ad380e4

Please sign in to comment.