Skip to content

Commit 4a14ecc

Browse files
authored
Elasticsearch: Fix startup check for 8.3 and above (#5521)
1 parent e23f378 commit 4a14ecc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/ElasticsearchContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ public ElasticsearchContainer(final DockerImageName dockerImageName) {
102102
this.isAtLeastMajorVersion8 =
103103
new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("8.0.0");
104104
// regex that
105+
// matches 8.3 JSON logging with started message and some follow up content within the message field
105106
// matches 8.0 JSON logging with no whitespace between message field and content
106107
// matches 7.x JSON logging with whitespace between message field and content
107108
// matches 6.x text logging with node name in brackets and just a 'started' message till the end of the line
108-
String regex = ".*(\"message\":\\s?\"started\".*|] started\n$)";
109+
String regex = ".*(\"message\":\\s?\"started[\\s?|\"].*|] started\n$)";
109110
setWaitStrategy(new LogMessageWaitStrategy().withRegEx(regex));
110111
if (isAtLeastMajorVersion8) {
111112
withPassword(ELASTICSEARCH_DEFAULT_PASSWORD);

modules/elasticsearch/src/test/java/org/testcontainers/elasticsearch/ElasticsearchContainerTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ public void elasticsearchVersion() throws IOException {
150150
}
151151
}
152152

153+
@Test
154+
public void elasticsearchVersion83() throws IOException {
155+
try (
156+
ElasticsearchContainer container = new ElasticsearchContainer(
157+
"docker.elastic.co/elasticsearch/elasticsearch:8.3.0"
158+
)
159+
) {
160+
container.start();
161+
Response response = getClient(container).performRequest(new Request("GET", "/"));
162+
assertThat(response.getStatusLine().getStatusCode(), is(200));
163+
assertThat(EntityUtils.toString(response.getEntity()), containsString("8.3.0"));
164+
}
165+
}
166+
153167
@Test
154168
public void elasticsearchOssImage() throws IOException {
155169
try (
@@ -406,10 +420,15 @@ private RestClient getClient(ElasticsearchContainer container) {
406420
new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD)
407421
);
408422

423+
String protocol = container.caCertAsBytes().isPresent() ? "https://" : "http://";
424+
409425
client =
410426
RestClient
411-
.builder(HttpHost.create(container.getHttpHostAddress()))
427+
.builder(HttpHost.create(protocol + container.getHttpHostAddress()))
412428
.setHttpClientConfigCallback(httpClientBuilder -> {
429+
if (container.caCertAsBytes().isPresent()) {
430+
httpClientBuilder.setSSLContext(container.createSslContextFromCa());
431+
}
413432
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
414433
})
415434
.build();

0 commit comments

Comments
 (0)