Search in sources :

Example 96 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RedisConnectionFactoryXmlConfigTest method cloudRedisConnectionFactoryWithMinMaxPool.

@Test
public void cloudRedisConnectionFactoryWithMinMaxPool() {
    ApplicationContext testContext = getTestApplicationContext("cloud-redis-with-config.xml", createService("my-service"));
    RedisConnectionFactory connector = testContext.getBean("service-pool5-30-wait3000", getConnectorType());
    RedisConnectionFactoryCloudConfigTestHelper.assertPoolProperties(connector, 30, 5, 3000);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Example 97 with RedisConnectionFactory

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

the class RedisHealthIndicatorTests method healthWhenClusterStateIsAbsentShouldBeUp.

@Test
void healthWhenClusterStateIsAbsentShouldBeUp() {
    RedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory(null);
    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);
    then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
Also used : Health(org.springframework.boot.actuate.health.Health) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 98 with RedisConnectionFactory

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

the class RedisHealthIndicatorTests method createClusterConnectionFactory.

private RedisConnectionFactory createClusterConnectionFactory(String state) {
    Properties clusterProperties = new Properties();
    if (state != null) {
        clusterProperties.setProperty("cluster_state", state);
    }
    clusterProperties.setProperty("cluster_size", "4");
    boolean failure = "fail".equals(state);
    clusterProperties.setProperty("cluster_slots_ok", failure ? "3" : "4");
    clusterProperties.setProperty("cluster_slots_fail", failure ? "1" : "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);
    return redisConnectionFactory;
}
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)

Example 99 with RedisConnectionFactory

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

the class RedisHealthIndicatorTests method healthWhenClusterStateIsFailShouldBeDown.

@Test
void healthWhenClusterStateIsFailShouldBeDown() {
    RedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory("fail");
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_up")).isEqualTo(3L);
    assertThat(health.getDetails().get("slots_fail")).isEqualTo(1L);
    then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
Also used : Health(org.springframework.boot.actuate.health.Health) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 100 with RedisConnectionFactory

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

the class RedissonClusterConnectionTest method testConnectionFactoryReturnsClusterConnection.

@Test
public void testConnectionFactoryReturnsClusterConnection() {
    RedisConnectionFactory connectionFactory = new RedissonConnectionFactory(redisson);
    assertThat(connectionFactory.getConnection()).isInstanceOf(RedissonClusterConnection.class);
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)100 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 Properties (java.util.Properties)10 Message (org.springframework.messaging.Message)10 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