diff --git a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/health/DataRedisHealth.java b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/health/DataRedisHealth.java index b0c63cb33d6f..7cd41b9e4d8a 100644 --- a/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/health/DataRedisHealth.java +++ b/module/spring-boot-data-redis/src/main/java/org/springframework/boot/data/redis/health/DataRedisHealth.java @@ -33,7 +33,7 @@ private DataRedisHealth() { } static Health.Builder up(Health.Builder builder, Properties info) { - builder.withDetail("version", info.getProperty("redis_version")); + builder.withDetail("version", info.getProperty("redis_version", "unknown")); return builder.up(); } diff --git a/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/DataRedisReactiveHealthIndicatorTests.java b/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/DataRedisReactiveHealthIndicatorTests.java index 6770ca383895..dc43c5588bcb 100644 --- a/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/DataRedisReactiveHealthIndicatorTests.java +++ b/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/DataRedisReactiveHealthIndicatorTests.java @@ -68,6 +68,23 @@ void redisIsUp() { then(redisConnection).should().closeLater(); } + @Test + void redisIsUpWithMissingVersion() { + Properties info = new Properties(); + ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class); + given(redisConnection.closeLater()).willReturn(Mono.empty()); + ReactiveServerCommands commands = mock(ReactiveServerCommands.class); + given(commands.info("server")).willReturn(Mono.just(info)); + DataRedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands); + Mono health = healthIndicator.health(); + StepVerifier.create(health).consumeNextWith((h) -> { + assertThat(h.getStatus()).isEqualTo(Status.UP); + assertThat(h.getDetails()).containsOnlyKeys("version"); + assertThat(h.getDetails()).containsEntry("version", "unknown"); + }).expectComplete().verify(Duration.ofSeconds(30)); + then(redisConnection).should().closeLater(); + } + @Test void healthWhenClusterStateIsAbsentShouldBeUp() { ReactiveRedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory(null); diff --git a/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/RedisHealthIndicatorTests.java b/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/RedisHealthIndicatorTests.java index 4ef548e85f38..7d772d5496ae 100644 --- a/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/RedisHealthIndicatorTests.java +++ b/module/spring-boot-data-redis/src/test/java/org/springframework/boot/data/redis/health/RedisHealthIndicatorTests.java @@ -62,6 +62,19 @@ void redisIsUp() { assertThat(health.getDetails()).containsEntry("version", "2.8.9"); } + @Test + void redisIsUpWithMissingVersion() { + Properties info = new Properties(); + RedisConnection redisConnection = mock(RedisConnection.class); + RedisServerCommands serverCommands = mock(RedisServerCommands.class); + given(redisConnection.serverCommands()).willReturn(serverCommands); + given(serverCommands.info()).willReturn(info); + DataRedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection); + Health health = healthIndicator.health(); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()).containsEntry("version", "unknown"); + } + @Test void redisIsDown() { RedisConnection redisConnection = mock(RedisConnection.class);