Search in sources :

Example 1 with ReactiveServerCommands

use of org.springframework.data.redis.connection.ReactiveServerCommands in project spring-boot by spring-projects.

the class RedisReactiveHealthIndicatorTests method redisCommandIsDown.

@Test
void redisCommandIsDown() {
    ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
    given(commands.info("server")).willReturn(Mono.error(new RedisConnectionFailureException("Connection failed")));
    ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
    given(redisConnection.closeLater()).willReturn(Mono.empty());
    RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN)).verifyComplete();
    then(redisConnection).should().closeLater();
}
Also used : Status(org.springframework.boot.actuate.health.Status) Properties(java.util.Properties) StepVerifier(reactor.test.StepVerifier) RedisConnectionFailureException(org.springframework.data.redis.RedisConnectionFailureException) ReactiveServerCommands(org.springframework.data.redis.connection.ReactiveServerCommands) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReactiveRedisClusterConnection(org.springframework.data.redis.connection.ReactiveRedisClusterConnection) BDDMockito.then(org.mockito.BDDMockito.then) Mono(reactor.core.publisher.Mono) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test) RedisConnectionException(io.lettuce.core.RedisConnectionException) BDDMockito.given(org.mockito.BDDMockito.given) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) ReactiveRedisConnectionFactory(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory) ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) RedisConnectionFailureException(org.springframework.data.redis.RedisConnectionFailureException) ReactiveServerCommands(org.springframework.data.redis.connection.ReactiveServerCommands) Test(org.junit.jupiter.api.Test)

Example 2 with ReactiveServerCommands

use of org.springframework.data.redis.connection.ReactiveServerCommands in project spring-boot by spring-projects.

the class RedisReactiveHealthIndicatorTests method redisIsUp.

@Test
void redisIsUp() {
    Properties info = new Properties();
    info.put("redis_version", "2.8.9");
    ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
    given(redisConnection.closeLater()).willReturn(Mono.empty());
    ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
    given(commands.info("server")).willReturn(Mono.just(info));
    RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.UP);
        assertThat(h.getDetails()).containsOnlyKeys("version");
        assertThat(h.getDetails().get("version")).isEqualTo("2.8.9");
    }).verifyComplete();
    then(redisConnection).should().closeLater();
}
Also used : Status(org.springframework.boot.actuate.health.Status) Properties(java.util.Properties) StepVerifier(reactor.test.StepVerifier) RedisConnectionFailureException(org.springframework.data.redis.RedisConnectionFailureException) ReactiveServerCommands(org.springframework.data.redis.connection.ReactiveServerCommands) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReactiveRedisClusterConnection(org.springframework.data.redis.connection.ReactiveRedisClusterConnection) BDDMockito.then(org.mockito.BDDMockito.then) Mono(reactor.core.publisher.Mono) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test) RedisConnectionException(io.lettuce.core.RedisConnectionException) BDDMockito.given(org.mockito.BDDMockito.given) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) ReactiveRedisConnectionFactory(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory) ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) Properties(java.util.Properties) ReactiveServerCommands(org.springframework.data.redis.connection.ReactiveServerCommands) Test(org.junit.jupiter.api.Test)

Aggregations

RedisConnectionException (io.lettuce.core.RedisConnectionException)2 Properties (java.util.Properties)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Test (org.junit.jupiter.api.Test)2 BDDMockito.given (org.mockito.BDDMockito.given)2 BDDMockito.then (org.mockito.BDDMockito.then)2 Mockito.mock (org.mockito.Mockito.mock)2 Health (org.springframework.boot.actuate.health.Health)2 Status (org.springframework.boot.actuate.health.Status)2 RedisConnectionFailureException (org.springframework.data.redis.RedisConnectionFailureException)2 ClusterInfo (org.springframework.data.redis.connection.ClusterInfo)2 ReactiveRedisClusterConnection (org.springframework.data.redis.connection.ReactiveRedisClusterConnection)2 ReactiveRedisConnection (org.springframework.data.redis.connection.ReactiveRedisConnection)2 ReactiveRedisConnectionFactory (org.springframework.data.redis.connection.ReactiveRedisConnectionFactory)2 ReactiveServerCommands (org.springframework.data.redis.connection.ReactiveServerCommands)2 Mono (reactor.core.publisher.Mono)2 StepVerifier (reactor.test.StepVerifier)2