Search in sources :

Example 56 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 57 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)

Example 58 with RedisConnectionFactory

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

the class RedisHttpSessionConfigurationXmlCustomExpireTests method connectionFactory.

static RedisConnectionFactory connectionFactory() {
    RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
    RedisConnection connection = mock(RedisConnection.class);
    given(factory.getConnection()).willReturn(connection);
    given(connection.getConfig(anyString())).willReturn(new Properties());
    return factory;
}
Also used : Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 59 with RedisConnectionFactory

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

the class RedisHttpSessionConfigurationClassPathXmlApplicationContextTests method connectionFactory.

static RedisConnectionFactory connectionFactory() {
    RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
    RedisConnection connection = mock(RedisConnection.class);
    given(factory.getConnection()).willReturn(connection);
    given(connection.getConfig(anyString())).willReturn(new Properties());
    return factory;
}
Also used : Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 60 with RedisConnectionFactory

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

the class RedisHttpSessionConfigurationTests method namedConnectionFactoryRedisConfig.

@Test
public void namedConnectionFactoryRedisConfig() {
    registerAndRefresh(RedisConfig.class, NamedConnectionFactoryRedisConfig.class);
    RedisOperationsSessionRepository repository = this.context.getBean(RedisOperationsSessionRepository.class);
    RedisConnectionFactory redisConnectionFactory = this.context.getBean("redisConnectionFactory", RedisConnectionFactory.class);
    assertThat(repository).isNotNull();
    assertThat(redisConnectionFactory).isNotNull();
    RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations");
    assertThat(redisOperations).isNotNull();
    assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")).isEqualTo(redisConnectionFactory);
}
Also used : RedisOperations(org.springframework.data.redis.core.RedisOperations) RedisOperationsSessionRepository(org.springframework.session.data.redis.RedisOperationsSessionRepository) SpringSessionRedisConnectionFactory(org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)95 Test (org.junit.Test)83 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)62 GenericMessage (org.springframework.messaging.support.GenericMessage)22 BeanFactory (org.springframework.beans.factory.BeanFactory)19 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)17 MessageGroup (org.springframework.integration.store.MessageGroup)14 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 ArrayList (java.util.ArrayList)12 Message (org.springframework.messaging.Message)10 Properties (java.util.Properties)9 ApplicationContext (org.springframework.context.ApplicationContext)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 DefaultRedisZSet (org.springframework.data.redis.support.collections.DefaultRedisZSet)7 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 TypedTuple (org.springframework.data.redis.core.ZSetOperations.TypedTuple)6 LiteralExpression (org.springframework.expression.common.LiteralExpression)6