Skip to content

Commit

Permalink
Upgrade to Elasticsearch Client 8.17.1
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Nosan <[email protected]>
  • Loading branch information
nosan committed Feb 5, 2025
1 parent 271e2ec commit 7df219a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,6 +69,7 @@ private Health processResponse(Health.Builder builder, HealthResponse response)
builder.withDetail("task_max_waiting_in_queue_millis", response.taskMaxWaitingInQueueMillis());
builder.withDetail("active_shards_percent_as_number",
Double.parseDouble(response.activeShardsPercentAsNumber()));
builder.withDetail("unassigned_primary_shards", response.unassignedPrimaryShards());
return builder.build();
}
return builder.down().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,15 +72,15 @@ void shutdown() throws Exception {

@Test
void elasticsearchIsUp() {
setupMockResponse(200, "green");
setupMockResponse("green");
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertHealthDetailsWithStatus(health.getDetails(), "green");
}

@Test
void elasticsearchWithYellowStatusIsUp() {
setupMockResponse(200, "yellow");
setupMockResponse("yellow");
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertHealthDetailsWithStatus(health.getDetails(), "yellow");
Expand All @@ -104,7 +104,7 @@ void elasticsearchIsDownByResponseCode() {

@Test
void elasticsearchIsOutOfServiceByStatus() {
setupMockResponse(200, "red");
setupMockResponse("red");
Health health = this.healthIndicator.health().block(TIMEOUT);
assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
assertHealthDetailsWithStatus(health.getDetails(), "red");
Expand All @@ -116,10 +116,11 @@ private void assertHealthDetailsWithStatus(Map<String, Object> details, String s
entry("active_primary_shards", 0), entry("active_shards", 0), entry("relocating_shards", 0),
entry("initializing_shards", 0), entry("unassigned_shards", 0), entry("delayed_unassigned_shards", 0),
entry("number_of_pending_tasks", 0), entry("number_of_in_flight_fetch", 0),
entry("task_max_waiting_in_queue_millis", 0L), entry("active_shards_percent_as_number", 100.0));
entry("task_max_waiting_in_queue_millis", 0L), entry("active_shards_percent_as_number", 100.0),
entry("unassigned_primary_shards", 10));
}

private void setupMockResponse(int responseCode, String status) {
private void setupMockResponse(String status) {
MockResponse mockResponse = new MockResponse().setBody(createJsonResult(status))
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.setHeader("X-Elastic-Product", "Elasticsearch");
Expand All @@ -133,7 +134,8 @@ private String createJsonResult(String status) {
+ "\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,"
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,"
+ "\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,"
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0}",
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0,"
+ "\"unassigned_primary_shards\": 10 }",
status);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -122,20 +122,20 @@ private void assertHealthDetailsWithStatus(Map<String, Object> details, String s
entry("active_primary_shards", 0), entry("active_shards", 0), entry("relocating_shards", 0),
entry("initializing_shards", 0), entry("unassigned_shards", 0), entry("delayed_unassigned_shards", 0),
entry("number_of_pending_tasks", 0), entry("number_of_in_flight_fetch", 0),
entry("task_max_waiting_in_queue_millis", 0), entry("active_shards_percent_as_number", 100.0));
entry("task_max_waiting_in_queue_millis", 0), entry("active_shards_percent_as_number", 100.0),
entry("unassigned_primary_shards", 10));
}

private String createJsonResult(int responseCode, String status) {
if (responseCode == 200) {
return String.format(
"{\"cluster_name\":\"elasticsearch\","
+ "\"status\":\"%s\",\"timed_out\":false,\"number_of_nodes\":1,"
+ "\"number_of_data_nodes\":1,\"active_primary_shards\":0,"
+ "\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,"
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,"
+ "\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,"
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0}",
status);
return String.format("{\"cluster_name\":\"elasticsearch\","
+ "\"status\":\"%s\",\"timed_out\":false,\"number_of_nodes\":1,"
+ "\"number_of_data_nodes\":1,\"active_primary_shards\":0,"
+ "\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,"
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,"
+ "\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,"
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0,"
+ "\"unassigned_primary_shards\": 10 }", status);
}
return "{\n \"error\": \"Server Error\",\n \"status\": " + responseCode + "\n}";
}
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ bom {
releaseNotes("https://github.com/ehcache/ehcache3/releases/tag/v{version}")
}
}
library("Elasticsearch Client", "8.15.5") {
library("Elasticsearch Client", "8.17.1") {
alignWith {
version {
from "org.springframework.data:spring-data-elasticsearch"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.springframework.boot.testcontainers.service.connection.elasticsearch;

import java.io.IOException;
import java.time.Duration;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import org.junit.jupiter.api.Test;
Expand All @@ -30,7 +31,7 @@
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.container.TestImage;
import org.springframework.boot.testsupport.container.ElasticsearchContainer8;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

Expand All @@ -47,7 +48,8 @@ class ElasticsearchContainerConnectionDetailsFactoryTests {

@Container
@ServiceConnection
static final ElasticsearchContainer elasticsearch = TestImage.container(ElasticsearchContainer.class);
static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer8().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));

@Autowired(required = false)
private ElasticsearchConnectionDetails connectionDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.testsupport.container;

import org.testcontainers.elasticsearch.ElasticsearchContainer;

/**
* A container suitable for testing Elasticsearch 8.
*
* @author Dmytro Nosan
*/
public class ElasticsearchContainer8 extends ElasticsearchContainer {

public ElasticsearchContainer8() {
super(TestImage.ELASTICSEARCH_8.toString());
addEnv("ES_JAVA_OPTS", "-Xms32m -Xmx512m");
addEnv("xpack.security.enabled", "false");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -117,7 +117,7 @@ public enum TestImage {
/**
* A container image suitable for testing Elasticsearch 8.
*/
ELASTICSEARCH_8("elasticsearch", "8.6.1"),
ELASTICSEARCH_8("elasticsearch", "8.17.1"),

/**
* A container image suitable for testing Grafana OTel LGTM.
Expand Down

0 comments on commit 7df219a

Please sign in to comment.