[TEST] Minor REST tests infra cleanup
Make the http addresses within the REST client final. It makes no sense to update them before each test if we don't check the version of the nodes again, which would mean adding too much overhead (an additional http call before each test) for no reason. We just reuse the same nodes for the whole suite and check the version once while initializing the client. Would be nice to make the REST client within the execution context final but its initialization still needs to happen after the `ElasticsearchIntegrationTest#beforeInternal` that assigns `GLOBAL_CLUSTER` to `currentCluster`. Closes #7723
This commit is contained in:
parent
b619cd1112
commit
ede39edbba
|
@ -165,7 +165,6 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
String[] specPaths = resolvePathsProperty(REST_TESTS_SPEC, DEFAULT_SPEC_PATH);
|
||||
RestSpec restSpec = RestSpec.parseFrom(DEFAULT_SPEC_PATH, specPaths);
|
||||
assert restTestExecutionContext == null;
|
||||
restTestExecutionContext = new RestTestExecutionContext(restSpec);
|
||||
}
|
||||
|
||||
|
@ -191,7 +190,7 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest {
|
|||
String testPath = testCandidate.getSuitePath() + "/" + testSection;
|
||||
assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.matches(Paths.get(testPath)));
|
||||
}
|
||||
|
||||
//The client needs non static info to get initialized, therefore it can't be initialized in the before class
|
||||
restTestExecutionContext.resetClient(cluster().httpAddresses(), restClientSettings());
|
||||
restTestExecutionContext.clear();
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class RestTestExecutionContext implements Closeable {
|
|||
|
||||
private RestResponse response;
|
||||
|
||||
public RestTestExecutionContext(RestSpec restSpec) throws RestException, IOException {
|
||||
public RestTestExecutionContext(RestSpec restSpec) {
|
||||
this.restSpec = restSpec;
|
||||
}
|
||||
|
||||
|
@ -116,13 +116,11 @@ public class RestTestExecutionContext implements Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Resets (or creates) the embedded REST client which will point to the given addresses
|
||||
* Creates the embedded REST client when needed. Needs to be called before executing any test.
|
||||
*/
|
||||
public void resetClient(InetSocketAddress[] addresses, Settings settings) throws IOException, RestException {
|
||||
if (restClient == null) {
|
||||
restClient = new RestClient(restSpec, settings, addresses);
|
||||
} else {
|
||||
restClient.updateAddresses(addresses);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,6 +148,8 @@ public class RestTestExecutionContext implements Closeable {
|
|||
* Closes the execution context and releases the underlying resources
|
||||
*/
|
||||
public void close() {
|
||||
this.restClient.close();
|
||||
if (restClient != null) {
|
||||
restClient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,7 @@ public class RestClient implements Closeable {
|
|||
private final RestSpec restSpec;
|
||||
private final CloseableHttpClient httpClient;
|
||||
private final Headers headers;
|
||||
|
||||
private InetSocketAddress[] addresses;
|
||||
|
||||
private final InetSocketAddress[] addresses;
|
||||
private final String esVersion;
|
||||
|
||||
public RestClient(RestSpec restSpec, Settings settings, InetSocketAddress[] addresses) throws IOException, RestException {
|
||||
|
@ -99,13 +97,6 @@ public class RestClient implements Closeable {
|
|||
return esVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to update the addresses the client needs to connect to
|
||||
*/
|
||||
public void updateAddresses(InetSocketAddress[] addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls an api with the provided parameters and body
|
||||
* @throws RestException if the obtained status code is non ok, unless the specific error code needs to be ignored
|
||||
|
|
Loading…
Reference in New Issue