|
|
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.redis;
|
|
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
import io.lettuce.core.RedisConnectionException;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
import reactor.test.StepVerifier;
|
|
|
|
@ -39,11 +40,12 @@ import static org.mockito.Mockito.verify;
|
|
|
|
|
*
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
* @author Mark Paluch
|
|
|
|
|
* @author Nikolay Rybak
|
|
|
|
|
*/
|
|
|
|
|
public class RedisReactiveHealthIndicatorTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void redisIsUp() throws Exception {
|
|
|
|
|
public void redisIsUp() {
|
|
|
|
|
Properties info = new Properties();
|
|
|
|
|
info.put("redis_version", "2.8.9");
|
|
|
|
|
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
|
|
|
|
@ -61,7 +63,7 @@ public class RedisReactiveHealthIndicatorTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void redisIsDown() throws Exception {
|
|
|
|
|
public void redisCommandIsDown() {
|
|
|
|
|
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
|
|
|
|
|
given(commands.info()).willReturn(
|
|
|
|
|
Mono.error(new RedisConnectionFailureException("Connection failed")));
|
|
|
|
@ -75,6 +77,20 @@ public class RedisReactiveHealthIndicatorTests {
|
|
|
|
|
verify(redisConnection).close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void redisConnectionIsDown() {
|
|
|
|
|
ReactiveRedisConnectionFactory redisConnectionFactory = mock(
|
|
|
|
|
ReactiveRedisConnectionFactory.class);
|
|
|
|
|
given(redisConnectionFactory.getReactiveConnection()).willThrow(
|
|
|
|
|
new RedisConnectionException("Unable to connect to localhost:6379"));
|
|
|
|
|
RedisReactiveHealthIndicator healthIndicator = new RedisReactiveHealthIndicator(
|
|
|
|
|
redisConnectionFactory);
|
|
|
|
|
Mono<Health> health = healthIndicator.health();
|
|
|
|
|
StepVerifier.create(health)
|
|
|
|
|
.consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN))
|
|
|
|
|
.verifyComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RedisReactiveHealthIndicator createHealthIndicator(
|
|
|
|
|
ReactiveRedisConnection redisConnection,
|
|
|
|
|
ReactiveServerCommands serverCommands) {
|
|
|
|
|