Skip to content

Commit 9eab007

Browse files
committed
Merge pull request #48320 from youngledo
* gh-48320: Set the version to 'unknown' when redis_version is missing Closes gh-48320
2 parents 8becf59 + 2b67bbe commit 9eab007

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/data/redis/RedisHealth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private RedisHealth() {
3434
}
3535

3636
static Builder up(Health.Builder builder, Properties info) {
37-
builder.withDetail("version", info.getProperty("redis_version"));
37+
builder.withDetail("version", info.getProperty("redis_version", "unknown"));
3838
return builder.up();
3939
}
4040

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ void redisIsUp() {
6262
assertThat(health.getDetails()).containsEntry("version", "2.8.9");
6363
}
6464

65+
@Test
66+
void redisIsUpWithMissingVersion() {
67+
Properties info = new Properties();
68+
RedisConnection redisConnection = mock(RedisConnection.class);
69+
RedisServerCommands serverCommands = mock(RedisServerCommands.class);
70+
given(redisConnection.serverCommands()).willReturn(serverCommands);
71+
given(serverCommands.info()).willReturn(info);
72+
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
73+
Health health = healthIndicator.health();
74+
assertThat(health.getStatus()).isEqualTo(Status.UP);
75+
assertThat(health.getDetails()).containsEntry("version", "unknown");
76+
}
77+
6578
@Test
6679
void redisIsDown() {
6780
RedisConnection redisConnection = mock(RedisConnection.class);

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ void redisIsUp() {
6868
then(redisConnection).should().closeLater();
6969
}
7070

71+
@Test
72+
void redisIsUpWithMissingVersion() {
73+
Properties info = new Properties();
74+
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
75+
given(redisConnection.closeLater()).willReturn(Mono.empty());
76+
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
77+
given(commands.info("server")).willReturn(Mono.just(info));
78+
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
79+
Mono<Health> health = healthIndicator.health();
80+
StepVerifier.create(health).consumeNextWith((h) -> {
81+
assertThat(h.getStatus()).isEqualTo(Status.UP);
82+
assertThat(h.getDetails()).containsOnlyKeys("version");
83+
assertThat(h.getDetails()).containsEntry("version", "unknown");
84+
}).expectComplete().verify(Duration.ofSeconds(30));
85+
then(redisConnection).should().closeLater();
86+
}
87+
7188
@Test
7289
void healthWhenClusterStateIsAbsentShouldBeUp() {
7390
ReactiveRedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory(null);

0 commit comments

Comments
 (0)