Search in sources :

Example 1 with RedisClusterNode

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

the class ClusterSlotsParserUnitTests method testSameNode.

@Test
void testSameNode() {
    List<?> list = Arrays.asList(LettuceLists.newList("100", "200", LettuceLists.newList("1", "2", "nodeId1"), LettuceLists.newList("1", 2, "nodeId2")), LettuceLists.newList("200", "300", LettuceLists.newList("1", "2", "nodeId1"), LettuceLists.newList("1", 2, "nodeId2")));
    List<ClusterSlotRange> result = ClusterSlotsParser.parse(list);
    assertThat(result).hasSize(2);
    assertThat(result.get(0).getUpstream()).isSameAs(result.get(1).getUpstream());
    RedisClusterNode upstreamNode = result.get(0).getUpstream();
    assertThat(upstreamNode).isNotNull();
    assertThat(upstreamNode.getNodeId()).isEqualTo("nodeId1");
    assertThat(upstreamNode.getUri().getHost()).isEqualTo("1");
    assertThat(upstreamNode.getUri().getPort()).isEqualTo(2);
    assertThat(upstreamNode.is(RedisClusterNode.NodeFlag.MASTER)).isTrue();
    assertThat(upstreamNode.getSlots()).contains(100, 101, 199, 200, 203);
    assertThat(upstreamNode.getSlots()).doesNotContain(99, 301);
    assertThat(upstreamNode.getSlots()).hasSize(201);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 2 with RedisClusterNode

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

the class RedisClusterPubSubConnectionIntegrationTests method testGetConnectionAsyncByNodeId.

@Test
void testGetConnectionAsyncByNodeId() {
    RedisClusterNode partition = pubSubConnection.getPartitions().getPartition(0);
    StatefulRedisPubSubConnection<String, String> node = TestFutures.getOrTimeout(pubSubConnection.getConnectionAsync(partition.getNodeId()));
    assertThat(node.sync().ping()).isEqualTo("PONG");
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 3 with RedisClusterNode

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

the class RedisClusterPubSubConnectionIntegrationTests method testRegularClientPubSubChannels.

@Test
void testRegularClientPubSubChannels() {
    String nodeId = pubSubConnection.sync().clusterMyId();
    RedisClusterNode otherNode = getOtherThan(nodeId);
    pubSubConnection.sync().subscribe(key);
    List<String> channelsOnSubscribedNode = connection.getConnection(nodeId).sync().pubsubChannels();
    assertThat(channelsOnSubscribedNode).hasSize(1);
    List<String> channelsOnOtherNode = connection.getConnection(otherNode.getNodeId()).sync().pubsubChannels();
    assertThat(channelsOnOtherNode).isEmpty();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 4 with RedisClusterNode

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

the class RedisClusterPubSubConnectionIntegrationTests method testNodeMessagePropagationSubscription.

@Test
void testNodeMessagePropagationSubscription() throws Exception {
    RedisClusterNode partition = pubSubConnection.getPartitions().getPartition(0);
    pubSubConnection.setNodeMessagePropagation(true);
    pubSubConnection.addListener(connectionListener);
    StatefulRedisPubSubConnection<String, String> node = pubSubConnection.getConnection(partition.getNodeId());
    node.sync().subscribe("channel");
    pubSubConnection2.sync().publish("channel", "message");
    assertThat(connectionListener.getMessages().take()).isEqualTo("message");
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 5 with RedisClusterNode

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

the class RedisClusterPubSubConnectionIntegrationTests method testNodeIdSubscription.

@Test
void testNodeIdSubscription() throws Exception {
    RedisClusterNode partition = pubSubConnection.getPartitions().getPartition(0);
    StatefulRedisPubSubConnection<String, String> node = pubSubConnection.getConnection(partition.getNodeId());
    node.addListener(nodeListener);
    node.sync().subscribe("channel");
    pubSubConnection2.sync().publish("channel", "message");
    assertThat(nodeListener.getMessages().take()).isEqualTo("message");
    assertThat(connectionListener.getMessages().poll()).isNull();
}
Also used : 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