Skip to content

Commit

Permalink
Elasticsearch: Fix startup check for 8.3 and above (#5521)
Browse files Browse the repository at this point in the history
  • Loading branch information
spinscale committed Jun 28, 2022
1 parent e23f378 commit 4a14ecc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ public ElasticsearchContainer(final DockerImageName dockerImageName) {
this.isAtLeastMajorVersion8 =
new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("8.0.0");
// regex that
// matches 8.3 JSON logging with started message and some follow up content within the message field
// matches 8.0 JSON logging with no whitespace between message field and content
// matches 7.x JSON logging with whitespace between message field and content
// matches 6.x text logging with node name in brackets and just a 'started' message till the end of the line
String regex = ".*(\"message\":\\s?\"started\".*|] started\n$)";
String regex = ".*(\"message\":\\s?\"started[\\s?|\"].*|] started\n$)";
setWaitStrategy(new LogMessageWaitStrategy().withRegEx(regex));
if (isAtLeastMajorVersion8) {
withPassword(ELASTICSEARCH_DEFAULT_PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ public void elasticsearchVersion() throws IOException {
}
}

@Test
public void elasticsearchVersion83() throws IOException {
try (
ElasticsearchContainer container = new ElasticsearchContainer(
"docker.elastic.co/elasticsearch/elasticsearch:8.3.0"
)
) {
container.start();
Response response = getClient(container).performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(EntityUtils.toString(response.getEntity()), containsString("8.3.0"));
}
}

@Test
public void elasticsearchOssImage() throws IOException {
try (
Expand Down Expand Up @@ -406,10 +420,15 @@ private RestClient getClient(ElasticsearchContainer container) {
new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD)
);

String protocol = container.caCertAsBytes().isPresent() ? "https://" : "http://";

client =
RestClient
.builder(HttpHost.create(container.getHttpHostAddress()))
.builder(HttpHost.create(protocol + container.getHttpHostAddress()))
.setHttpClientConfigCallback(httpClientBuilder -> {
if (container.caCertAsBytes().isPresent()) {
httpClientBuilder.setSSLContext(container.createSslContextFromCa());
}
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
})
.build();
Expand Down

0 comments on commit 4a14ecc

Please sign in to comment.