|
|
@ -18,6 +18,7 @@ package org.springframework.boot.actuate.redis;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.lettuce.core.RedisConnectionException;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
import reactor.test.StepVerifier;
|
|
|
|
import reactor.test.StepVerifier;
|
|
|
@ -39,11 +40,12 @@ import static org.mockito.Mockito.verify;
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Mark Paluch
|
|
|
|
* @author Mark Paluch
|
|
|
|
|
|
|
|
* @author Nikolay Rybak
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class RedisReactiveHealthIndicatorTests {
|
|
|
|
public class RedisReactiveHealthIndicatorTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void redisIsUp() throws Exception {
|
|
|
|
public void redisIsUp() {
|
|
|
|
Properties info = new Properties();
|
|
|
|
Properties info = new Properties();
|
|
|
|
info.put("redis_version", "2.8.9");
|
|
|
|
info.put("redis_version", "2.8.9");
|
|
|
|
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
|
|
|
|
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
|
|
|
@ -61,7 +63,7 @@ public class RedisReactiveHealthIndicatorTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void redisIsDown() throws Exception {
|
|
|
|
public void redisCommandIsDown() {
|
|
|
|
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
|
|
|
|
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
|
|
|
|
given(commands.info()).willReturn(
|
|
|
|
given(commands.info()).willReturn(
|
|
|
|
Mono.error(new RedisConnectionFailureException("Connection failed")));
|
|
|
|
Mono.error(new RedisConnectionFailureException("Connection failed")));
|
|
|
@ -75,6 +77,20 @@ public class RedisReactiveHealthIndicatorTests {
|
|
|
|
verify(redisConnection).close();
|
|
|
|
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(
|
|
|
|
private RedisReactiveHealthIndicator createHealthIndicator(
|
|
|
|
ReactiveRedisConnection redisConnection,
|
|
|
|
ReactiveRedisConnection redisConnection,
|
|
|
|
ReactiveServerCommands serverCommands) {
|
|
|
|
ReactiveServerCommands serverCommands) {
|
|
|
|