Search in sources :

Example 1 with RedisConnectionFailureException

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

the class RedisHealthIndicatorTests method redisIsDown.

@Test
public void redisIsDown() throws Exception {
    RedisConnection redisConnection = mock(RedisConnection.class);
    RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class);
    given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
    given(redisConnection.info()).willThrow(new RedisConnectionFailureException("Connection failed"));
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(((String) health.getDetails().get("error")).contains("Connection failed"));
    verify(redisConnectionFactory).getConnection();
    verify(redisConnection).info();
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnectionFailureException(org.springframework.data.redis.RedisConnectionFailureException) RedisConnection(org.springframework.data.redis.connection.RedisConnection) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 RedisConnectionFailureException (org.springframework.data.redis.RedisConnectionFailureException)1 RedisConnection (org.springframework.data.redis.connection.RedisConnection)1 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)1