Search in sources :

Example 1 with ClusterInfo

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

the class RedisHealthIndicator method doHealthCheck.

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        if (connection instanceof RedisClusterConnection) {
            ClusterInfo clusterInfo = ((RedisClusterConnection) connection).clusterGetClusterInfo();
            builder.up().withDetail("cluster_size", clusterInfo.getClusterSize()).withDetail("slots_up", clusterInfo.getSlotsOk()).withDetail("slots_fail", clusterInfo.getSlotsFail());
        } else {
            Properties info = connection.info();
            builder.up().withDetail(VERSION, info.getProperty(REDIS_VERSION));
        }
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) Properties(java.util.Properties) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 2 with ClusterInfo

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

the class RedisReactiveHealthIndicatorTests method createClusterConnectionFactory.

private ReactiveRedisConnectionFactory 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");
    ReactiveRedisClusterConnection redisConnection = mock(ReactiveRedisClusterConnection.class);
    given(redisConnection.closeLater()).willReturn(Mono.empty());
    given(redisConnection.clusterGetClusterInfo()).willReturn(Mono.just(new ClusterInfo(clusterProperties)));
    ReactiveRedisConnectionFactory redisConnectionFactory = mock(ReactiveRedisConnectionFactory.class);
    given(redisConnectionFactory.getReactiveConnection()).willReturn(redisConnection);
    return redisConnectionFactory;
}
Also used : ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) ReactiveRedisClusterConnection(org.springframework.data.redis.connection.ReactiveRedisClusterConnection) ReactiveRedisConnectionFactory(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory) Properties(java.util.Properties)

Example 3 with ClusterInfo

use of org.springframework.data.redis.connection.ClusterInfo 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 4 with ClusterInfo

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

the class RedissonClusterConnectionTest method testClusterGetClusterInfo.

@Test
public void testClusterGetClusterInfo() {
    ClusterInfo info = connection.clusterGetClusterInfo();
    assertThat(info.getSlotsFail()).isEqualTo(0);
    assertThat(info.getSlotsOk()).isEqualTo(MasterSlaveConnectionManager.MAX_SLOT);
    assertThat(info.getSlotsAssigned()).isEqualTo(MasterSlaveConnectionManager.MAX_SLOT);
}
Also used : ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) Test(org.junit.Test)

Example 5 with ClusterInfo

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

Aggregations

ClusterInfo (org.springframework.data.redis.connection.ClusterInfo)5 Properties (java.util.Properties)4 RedisClusterConnection (org.springframework.data.redis.connection.RedisClusterConnection)3 Test (org.junit.Test)2 RedisClusterNode (org.springframework.data.redis.connection.RedisClusterNode)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 ReactiveRedisClusterConnection (org.springframework.data.redis.connection.ReactiveRedisClusterConnection)1 ReactiveRedisConnectionFactory (org.springframework.data.redis.connection.ReactiveRedisConnectionFactory)1 RedisConnection (org.springframework.data.redis.connection.RedisConnection)1