Search in sources :

Example 16 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions 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 17 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions 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 18 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions 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)

Example 19 with Partitions

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

the class RedisClusterSetupTest method clusterMeet.

@Test
public void clusterMeet() {
    clusterHelper.clusterReset();
    Partitions partitionsBeforeMeet = ClusterPartitionParser.parse(redis1.clusterNodes());
    assertThat(partitionsBeforeMeet.getPartitions()).hasSize(1);
    String result = redis1.clusterMeet(host, ClusterTestSettings.port6);
    assertThat(result).isEqualTo("OK");
    Wait.untilEquals(2, () -> ClusterPartitionParser.parse(redis1.clusterNodes()).size()).waitOrTimeout();
    Partitions partitionsAfterMeet = ClusterPartitionParser.parse(redis1.clusterNodes());
    assertThat(partitionsAfterMeet.getPartitions()).hasSize(2);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 20 with Partitions

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

the class RoundRobinSocketAddressSupplierUnitTests method before.

@BeforeEach
void before() {
    when(clientResourcesMock.socketAddressResolver()).thenReturn(SocketAddressResolver.create(DnsResolvers.JVM_DEFAULT));
    partitions = new Partitions();
    partitions.addPartition(new RedisClusterNode(hap1, "1", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()));
    partitions.addPartition(new RedisClusterNode(hap2, "2", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()));
    partitions.addPartition(new RedisClusterNode(hap3, "3", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()));
    partitions.updateCache();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Partitions (io.lettuce.core.cluster.models.partitions.Partitions)69 Test (org.junit.jupiter.api.Test)50 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)36 RedisURI (io.lettuce.core.RedisURI)20 ArrayList (java.util.ArrayList)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)10 PartitionsConsensusTestSupport.createPartitions (io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Exceptions (io.lettuce.core.internal.Exceptions)6 Futures (io.lettuce.core.internal.Futures)6 InternalLogger (io.netty.util.internal.logging.InternalLogger)6 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)6 List (java.util.List)6 Function (java.util.function.Function)6 LettuceAssert (io.lettuce.core.internal.LettuceAssert)5 Collection (java.util.Collection)5 Iterator (java.util.Iterator)5 Map (java.util.Map)5 CompletionStage (java.util.concurrent.CompletionStage)5