Skip to content

Commit 7df219a

Browse files
committed
Upgrade to Elasticsearch Client 8.17.1
Signed-off-by: Dmytro Nosan <[email protected]>
1 parent 271e2ec commit 7df219a

File tree

7 files changed

+64
-25
lines changed

7 files changed

+64
-25
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/elasticsearch/ElasticsearchReactiveHealthIndicator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ private Health processResponse(Health.Builder builder, HealthResponse response)
6969
builder.withDetail("task_max_waiting_in_queue_millis", response.taskMaxWaitingInQueueMillis());
7070
builder.withDetail("active_shards_percent_as_number",
7171
Double.parseDouble(response.activeShardsPercentAsNumber()));
72+
builder.withDetail("unassigned_primary_shards", response.unassignedPrimaryShards());
7273
return builder.build();
7374
}
7475
return builder.down().build();

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicatorTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,15 +72,15 @@ void shutdown() throws Exception {
7272

7373
@Test
7474
void elasticsearchIsUp() {
75-
setupMockResponse(200, "green");
75+
setupMockResponse("green");
7676
Health health = this.healthIndicator.health().block(TIMEOUT);
7777
assertThat(health.getStatus()).isEqualTo(Status.UP);
7878
assertHealthDetailsWithStatus(health.getDetails(), "green");
7979
}
8080

8181
@Test
8282
void elasticsearchWithYellowStatusIsUp() {
83-
setupMockResponse(200, "yellow");
83+
setupMockResponse("yellow");
8484
Health health = this.healthIndicator.health().block(TIMEOUT);
8585
assertThat(health.getStatus()).isEqualTo(Status.UP);
8686
assertHealthDetailsWithStatus(health.getDetails(), "yellow");
@@ -104,7 +104,7 @@ void elasticsearchIsDownByResponseCode() {
104104

105105
@Test
106106
void elasticsearchIsOutOfServiceByStatus() {
107-
setupMockResponse(200, "red");
107+
setupMockResponse("red");
108108
Health health = this.healthIndicator.health().block(TIMEOUT);
109109
assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
110110
assertHealthDetailsWithStatus(health.getDetails(), "red");
@@ -116,10 +116,11 @@ private void assertHealthDetailsWithStatus(Map<String, Object> details, String s
116116
entry("active_primary_shards", 0), entry("active_shards", 0), entry("relocating_shards", 0),
117117
entry("initializing_shards", 0), entry("unassigned_shards", 0), entry("delayed_unassigned_shards", 0),
118118
entry("number_of_pending_tasks", 0), entry("number_of_in_flight_fetch", 0),
119-
entry("task_max_waiting_in_queue_millis", 0L), entry("active_shards_percent_as_number", 100.0));
119+
entry("task_max_waiting_in_queue_millis", 0L), entry("active_shards_percent_as_number", 100.0),
120+
entry("unassigned_primary_shards", 10));
120121
}
121122

122-
private void setupMockResponse(int responseCode, String status) {
123+
private void setupMockResponse(String status) {
123124
MockResponse mockResponse = new MockResponse().setBody(createJsonResult(status))
124125
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
125126
.setHeader("X-Elastic-Product", "Elasticsearch");
@@ -133,7 +134,8 @@ private String createJsonResult(String status) {
133134
+ "\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,"
134135
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,"
135136
+ "\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,"
136-
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0}",
137+
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0,"
138+
+ "\"unassigned_primary_shards\": 10 }",
137139
status);
138140
}
139141

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchRestClientHealthIndicatorTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -122,20 +122,20 @@ private void assertHealthDetailsWithStatus(Map<String, Object> details, String s
122122
entry("active_primary_shards", 0), entry("active_shards", 0), entry("relocating_shards", 0),
123123
entry("initializing_shards", 0), entry("unassigned_shards", 0), entry("delayed_unassigned_shards", 0),
124124
entry("number_of_pending_tasks", 0), entry("number_of_in_flight_fetch", 0),
125-
entry("task_max_waiting_in_queue_millis", 0), entry("active_shards_percent_as_number", 100.0));
125+
entry("task_max_waiting_in_queue_millis", 0), entry("active_shards_percent_as_number", 100.0),
126+
entry("unassigned_primary_shards", 10));
126127
}
127128

128129
private String createJsonResult(int responseCode, String status) {
129130
if (responseCode == 200) {
130-
return String.format(
131-
"{\"cluster_name\":\"elasticsearch\","
132-
+ "\"status\":\"%s\",\"timed_out\":false,\"number_of_nodes\":1,"
133-
+ "\"number_of_data_nodes\":1,\"active_primary_shards\":0,"
134-
+ "\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,"
135-
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,"
136-
+ "\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,"
137-
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0}",
138-
status);
131+
return String.format("{\"cluster_name\":\"elasticsearch\","
132+
+ "\"status\":\"%s\",\"timed_out\":false,\"number_of_nodes\":1,"
133+
+ "\"number_of_data_nodes\":1,\"active_primary_shards\":0,"
134+
+ "\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,"
135+
+ "\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,"
136+
+ "\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,"
137+
+ "\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0,"
138+
+ "\"unassigned_primary_shards\": 10 }", status);
139139
}
140140
return "{\n \"error\": \"Server Error\",\n \"status\": " + responseCode + "\n}";
141141
}

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ bom {
337337
releaseNotes("https://github.com/ehcache/ehcache3/releases/tag/v{version}")
338338
}
339339
}
340-
library("Elasticsearch Client", "8.15.5") {
340+
library("Elasticsearch Client", "8.17.1") {
341341
alignWith {
342342
version {
343343
from "org.springframework.data:spring-data-elasticsearch"

spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/elasticsearch/ElasticsearchContainerConnectionDetailsFactoryTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.testcontainers.service.connection.elasticsearch;
1818

1919
import java.io.IOException;
20+
import java.time.Duration;
2021

2122
import co.elastic.clients.elasticsearch.ElasticsearchClient;
2223
import org.junit.jupiter.api.Test;
@@ -30,7 +31,7 @@
3031
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails;
3132
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
3233
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
33-
import org.springframework.boot.testsupport.container.TestImage;
34+
import org.springframework.boot.testsupport.container.ElasticsearchContainer8;
3435
import org.springframework.context.annotation.Configuration;
3536
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3637

@@ -47,7 +48,8 @@ class ElasticsearchContainerConnectionDetailsFactoryTests {
4748

4849
@Container
4950
@ServiceConnection
50-
static final ElasticsearchContainer elasticsearch = TestImage.container(ElasticsearchContainer.class);
51+
static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer8().withStartupAttempts(5)
52+
.withStartupTimeout(Duration.ofMinutes(10));
5153

5254
@Autowired(required = false)
5355
private ElasticsearchConnectionDetails connectionDetails;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testsupport.container;
18+
19+
import org.testcontainers.elasticsearch.ElasticsearchContainer;
20+
21+
/**
22+
* A container suitable for testing Elasticsearch 8.
23+
*
24+
* @author Dmytro Nosan
25+
*/
26+
public class ElasticsearchContainer8 extends ElasticsearchContainer {
27+
28+
public ElasticsearchContainer8() {
29+
super(TestImage.ELASTICSEARCH_8.toString());
30+
addEnv("ES_JAVA_OPTS", "-Xms32m -Xmx512m");
31+
addEnv("xpack.security.enabled", "false");
32+
}
33+
34+
}

spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/src/main/java/org/springframework/boot/testsupport/container/TestImage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,7 +117,7 @@ public enum TestImage {
117117
/**
118118
* A container image suitable for testing Elasticsearch 8.
119119
*/
120-
ELASTICSEARCH_8("elasticsearch", "8.6.1"),
120+
ELASTICSEARCH_8("elasticsearch", "8.17.1"),
121121

122122
/**
123123
* A container image suitable for testing Grafana OTel LGTM.

0 commit comments

Comments
 (0)