Search in sources :

Example 16 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method clusterForget.

@Test
public void clusterForget() {
    clusterHelper.clusterReset();
    String result = redis1.clusterMeet(host, ClusterTestSettings.port6);
    assertThat(result).isEqualTo("OK");
    Wait.untilTrue(() -> redis1.clusterNodes().contains(redis2.clusterMyId())).waitOrTimeout();
    Wait.untilTrue(() -> redis2.clusterNodes().contains(redis1.clusterMyId())).waitOrTimeout();
    Wait.untilTrue(() -> {
        Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
        if (partitions.size() != 2) {
            return false;
        }
        for (RedisClusterNode redisClusterNode : partitions) {
            if (redisClusterNode.is(RedisClusterNode.NodeFlag.HANDSHAKE)) {
                return false;
            }
        }
        return true;
    }).waitOrTimeout();
    redis1.clusterForget(redis2.clusterMyId());
    Wait.untilEquals(1, () -> ClusterPartitionParser.parse(redis1.clusterNodes()).size()).waitOrTimeout();
    Partitions partitionsAfterForget = ClusterPartitionParser.parse(redis1.clusterNodes());
    assertThat(partitionsAfterForget.getPartitions()).hasSize(1);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 17 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method doNotExpireStaleNodeIdConnections.

@Test
public void doNotExpireStaleNodeIdConnections() throws Exception {
    clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().closeStaleConnections(false).build()).build());
    RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
    ClusterSetup.setup2Masters(clusterHelper);
    PooledClusterConnectionProvider<String, String> clusterConnectionProvider = getPooledClusterConnectionProvider(clusterConnection);
    assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(0);
    assertRoutedExecution(clusterConnection);
    assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(2);
    Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
    for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
        if (!redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
            redis1.clusterForget(redisClusterNode.getNodeId());
        }
    }
    partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
    for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
        if (!redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
            redis2.clusterForget(redisClusterNode.getNodeId());
        }
    }
    clusterClient.reloadPartitions();
    assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(2);
    clusterConnection.getStatefulConnection().close();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 18 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method expireStaleDefaultConnection.

@Test
public void expireStaleDefaultConnection() {
    ClusterSetup.setup2Masters(clusterHelper);
    RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(), RedisURI.Builder.redis(host, port5).build());
    redisClusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().dynamicRefreshSources(false).build()).build());
    StatefulRedisClusterConnectionImpl<String, String> connection = (StatefulRedisClusterConnectionImpl<String, String>) redisClusterClient.connect();
    String firstMaster = connection.sync().clusterMyId();
    RedisClusterNode firstMasterNode = connection.getPartitions().getPartitionByNodeId(firstMaster);
    assertThat(firstMasterNode.getUri().getPort()).isEqualTo(port5);
    redis2.clusterForget(redis1.clusterMyId());
    redis1.clusterForget(redis2.clusterMyId());
    Partitions partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
    connection.setPartitions(partitions);
    Wait.untilTrue(connection::isOpen).waitOrTimeout();
    String secondMaster = connection.sync().clusterMyId();
    assertThat(secondMaster).isEqualTo(redis2.clusterMyId());
    connection.close();
    FastShutdown.shutdown(redisClusterClient);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 19 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method disconnectedConnectionRejectTest.

@Test
public void disconnectedConnectionRejectTest() throws Exception {
    clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED).disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build());
    RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
    clusterClient.setOptions(ClusterClientOptions.builder().disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build());
    ClusterSetup.setup2Masters(clusterHelper);
    assertRoutedExecution(clusterConnection);
    RedisClusterNode partition1 = getOwnPartition(redis1);
    RedisClusterAsyncCommands<String, String> node1Connection = clusterConnection.getConnection(partition1.getUri().getHost(), partition1.getUri().getPort());
    shiftAllSlotsToNode1();
    suspendConnection(node1Connection);
    // 15891
    RedisFuture<String> set = clusterConnection.set("t", "value");
    set.await(5, TimeUnit.SECONDS);
    assertThatThrownBy(() -> TestFutures.awaitOrTimeout(set)).hasRootCauseInstanceOf(RedisException.class);
    clusterConnection.getStatefulConnection().close();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 20 with RedisClusterNode

use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.

the class RedisClusterSetupTest method expireStaleDefaultPubSubConnection.

@Test
public void expireStaleDefaultPubSubConnection() {
    ClusterSetup.setup2Masters(clusterHelper);
    RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(), RedisURI.Builder.redis(host, port5).build());
    redisClusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().dynamicRefreshSources(false).build()).build());
    StatefulRedisClusterPubSubConnectionImpl<String, String> connection = (StatefulRedisClusterPubSubConnectionImpl<String, String>) redisClusterClient.connectPubSub();
    String firstMaster = connection.sync().clusterMyId();
    RedisClusterNode firstMasterNode = connection.getPartitions().getPartitionByNodeId(firstMaster);
    assertThat(firstMasterNode.getUri().getPort()).isEqualTo(port5);
    redis2.clusterForget(redis1.clusterMyId());
    redis1.clusterForget(redis2.clusterMyId());
    Partitions partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
    connection.setPartitions(partitions);
    Wait.untilTrue(connection::isOpen).waitOrTimeout();
    String secondMaster = connection.sync().clusterMyId();
    assertThat(secondMaster).isEqualTo(redis2.clusterMyId());
    connection.close();
    FastShutdown.shutdown(redisClusterClient);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Aggregations

RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)94 Test (org.junit.jupiter.api.Test)60 Partitions (io.lettuce.core.cluster.models.partitions.Partitions)36 ArrayList (java.util.ArrayList)18 RedisURI (io.lettuce.core.RedisURI)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)12 RedisNodeDescription (io.lettuce.core.models.role.RedisNodeDescription)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 ReadFrom (io.lettuce.core.ReadFrom)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 List (java.util.List)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Function (java.util.function.Function)6 CompletionStage (java.util.concurrent.CompletionStage)5 RedisException (io.lettuce.core.RedisException)4 RedisFuture (io.lettuce.core.RedisFuture)4 Exceptions (io.lettuce.core.internal.Exceptions)4 Futures (io.lettuce.core.internal.Futures)4 InternalLogger (io.netty.util.internal.logging.InternalLogger)4