Search in sources :

Example 11 with RedisConnectionFactory

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

the class RedisHealthIndicatorTests method redisClusterIsUp.

@Test
public void redisClusterIsUp() throws Exception {
    Properties clusterProperties = new Properties();
    clusterProperties.setProperty("cluster_size", "4");
    clusterProperties.setProperty("cluster_slots_ok", "4");
    clusterProperties.setProperty("cluster_slots_fail", "0");
    List<RedisClusterNode> redisMasterNodes = Arrays.asList(new RedisClusterNode("127.0.0.1", 7001), new RedisClusterNode("127.0.0.2", 7001));
    RedisClusterConnection redisConnection = mock(RedisClusterConnection.class);
    given(redisConnection.clusterGetNodes()).willReturn(redisMasterNodes);
    given(redisConnection.clusterGetClusterInfo()).willReturn(new ClusterInfo(clusterProperties));
    RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class);
    given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
    verify(redisConnectionFactory, atLeastOnce()).getConnection();
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) RedisClusterNode(org.springframework.data.redis.connection.RedisClusterNode) Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Example 12 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory 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)

Example 13 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project cas by apereo.

the class CasMetricsRepositoryConfiguration method redisMetricWriter.

@ConditionalOnProperty(prefix = "cas.metrics.redis", name = "prefix")
@Bean
@ExportMetricWriter
public MetricWriter redisMetricWriter() {
    final MetricsProperties.Redis redis = casProperties.getMetrics().getRedis();
    final RedisObjectFactory factory = new RedisObjectFactory();
    final RedisConnectionFactory connectionFactory = factory.newRedisConnectionFactory(redis);
    return new RedisMetricRepository(connectionFactory, redis.getPrefix(), redis.getKey());
}
Also used : MetricsProperties(org.apereo.cas.configuration.model.core.metrics.MetricsProperties) RedisObjectFactory(org.apereo.cas.redis.core.RedisObjectFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisMetricRepository(org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository) ExportMetricWriter(org.springframework.boot.actuate.autoconfigure.ExportMetricWriter) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Bean(org.springframework.context.annotation.Bean)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)13 Test (org.junit.Test)12 ApplicationContext (org.springframework.context.ApplicationContext)8 Properties (java.util.Properties)2 RedisConnection (org.springframework.data.redis.connection.RedisConnection)2 MetricsProperties (org.apereo.cas.configuration.model.core.metrics.MetricsProperties)1 RedisObjectFactory (org.apereo.cas.redis.core.RedisObjectFactory)1 ExportMetricWriter (org.springframework.boot.actuate.autoconfigure.ExportMetricWriter)1 RedisMetricRepository (org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 RedisServiceInfo (org.springframework.cloud.service.common.RedisServiceInfo)1 Bean (org.springframework.context.annotation.Bean)1 RedisConnectionFailureException (org.springframework.data.redis.RedisConnectionFailureException)1 ClusterInfo (org.springframework.data.redis.connection.ClusterInfo)1 RedisClusterConnection (org.springframework.data.redis.connection.RedisClusterConnection)1 RedisClusterNode (org.springframework.data.redis.connection.RedisClusterNode)1