Adapt to deprecations in Spring Data Redis

See gh-30200
This commit is contained in:
Andy Wilkinson
2022-03-18 10:52:17 +00:00
parent f693d7dfad
commit e60001fb16
5 changed files with 15 additions and 10 deletions

View File

@@ -60,7 +60,7 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
RedisHealth.fromClusterInfo(builder, ((RedisClusterConnection) connection).clusterGetClusterInfo());
}
else {
RedisHealth.up(builder, connection.info("server"));
RedisHealth.up(builder, connection.serverCommands().info());
}
}

View File

@@ -30,6 +30,7 @@ import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisServerCommands;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@@ -51,7 +52,9 @@ class RedisHealthIndicatorTests {
Properties info = new Properties();
info.put("redis_version", "2.8.9");
RedisConnection redisConnection = mock(RedisConnection.class);
given(redisConnection.info("server")).willReturn(info);
RedisServerCommands serverCommands = mock(RedisServerCommands.class);
given(redisConnection.serverCommands()).willReturn(serverCommands);
given(serverCommands.info()).willReturn(info);
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
@@ -61,7 +64,9 @@ class RedisHealthIndicatorTests {
@Test
void redisIsDown() {
RedisConnection redisConnection = mock(RedisConnection.class);
given(redisConnection.info("server")).willThrow(new RedisConnectionFailureException("Connection failed"));
RedisServerCommands serverCommands = mock(RedisServerCommands.class);
given(redisConnection.serverCommands()).willReturn(serverCommands);
given(serverCommands.info()).willThrow(new RedisConnectionFailureException("Connection failed"));
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);