Skip to content

Commit

Permalink
Make ESRestTestCase client configuration more configurable in subclas…
Browse files Browse the repository at this point in the history
…ses (elastic#96987)

We want to be able to tweak client configuration in tests extending
ESRestTestCase. This makes that simpler by allowing overriding the
general client configuration.
  • Loading branch information
breskeby committed Jun 21, 2023
1 parent e0ec5fc commit 89a65b2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static Map<String, Object> createCrossClusterAccessApiKey() throws IOExc
final int portSeparator = url.lastIndexOf(':');
final var httpHost = new HttpHost(url.substring(0, portSeparator), Integer.parseInt(url.substring(portSeparator + 1)), "http");
RestClientBuilder builder = RestClient.builder(httpHost);
configureClient(builder, Settings.EMPTY);
doConfigureClient(builder, Settings.EMPTY);
builder.setStrictDeprecationMode(true);
try (RestClient fulfillingClusterClient = builder.build()) {
final Response createApiKeyResponse = fulfillingClusterClient.performRequest(createApiKeyRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,14 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
return builder.build();
}

protected static void configureClient(RestClientBuilder builder, Settings settings) throws IOException {
/**
* Override this to configure the client with additional settings.
*/
protected void configureClient(RestClientBuilder builder, Settings settings) throws IOException {
doConfigureClient(builder, settings);
}

protected static void doConfigureClient(RestClientBuilder builder, Settings settings) throws IOException {
String truststorePath = settings.get(TRUSTSTORE_PATH);
String certificateAuthorities = settings.get(CERTIFICATE_AUTHORITIES);
String clientCertificatePath = settings.get(CLIENT_CERT_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected static RestHighLevelClient highLevelClient(RestClient client) {

protected static RestClient clientBuilder(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
configureClient(builder, settings);
doConfigureClient(builder, settings);

int timeout = Math.toIntExact(timeout().millis());
builder.setRequestConfigCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static RestClient buildRestClient(ElasticsearchCluster targetCluster) {
final var httpHost = new HttpHost(url.substring(0, portSeparator), Integer.parseInt(url.substring(portSeparator + 1)), "http");
RestClientBuilder builder = RestClient.builder(httpHost);
try {
configureClient(builder, Settings.EMPTY);
doConfigureClient(builder, Settings.EMPTY);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void closeRemoteClients() throws IOException {

protected static RestClient clientBuilder(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
configureClient(builder, settings);
doConfigureClient(builder, settings);

int timeout = Math.toIntExact(timeout().millis());
builder.setRequestConfigCallback(
Expand Down

0 comments on commit 89a65b2

Please sign in to comment.