Search in sources :

Example 6 with RedisClusterNode

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

the class RedisClusterPubSubConnectionIntegrationTests method testNodeHostAndPortMessagePropagationSubscription.

@Test
void testNodeHostAndPortMessagePropagationSubscription() throws Exception {
    RedisClusterNode partition = pubSubConnection.getPartitions().getPartition(0);
    pubSubConnection.setNodeMessagePropagation(true);
    pubSubConnection.addListener(connectionListener);
    RedisURI uri = partition.getUri();
    StatefulRedisPubSubConnection<String, String> node = pubSubConnection.getConnection(uri.getHost(), uri.getPort());
    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) RedisURI(io.lettuce.core.RedisURI) Test(org.junit.jupiter.api.Test)

Example 7 with RedisClusterNode

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

the class ClusterTopologyRefreshUnitTests method undiscoveredAdditionalNodesShouldBeLastUsingClientCount.

@Test
void undiscoveredAdditionalNodesShouldBeLastUsingClientCount() {
    List<RedisURI> seed = Collections.singletonList(RedisURI.create("127.0.0.1", 7380));
    when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(InetSocketAddress.createUnresolved("127.0.0.1", 7380)))).thenReturn(completedFuture((StatefulRedisConnection) connection1));
    Map<RedisURI, Partitions> partitionsMap = sut.loadViews(seed, Duration.ofSeconds(1), false).toCompletableFuture().join();
    Partitions partitions = partitionsMap.values().iterator().next();
    List<RedisClusterNode> nodes = TopologyComparators.sortByClientCount(partitions);
    assertThat(nodes).hasSize(2).extracting(RedisClusterNode::getUri).containsSequence(seed.get(0), RedisURI.create("127.0.0.1", 7381));
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisURI(io.lettuce.core.RedisURI) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 8 with RedisClusterNode

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

the class ClusterTopologyRefreshUnitTests method undiscoveredAdditionalNodesShouldBeLastUsingLatency.

@Test
void undiscoveredAdditionalNodesShouldBeLastUsingLatency() {
    List<RedisURI> seed = Collections.singletonList(RedisURI.create("127.0.0.1", 7380));
    when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(InetSocketAddress.createUnresolved("127.0.0.1", 7380)))).thenReturn(completedFuture((StatefulRedisConnection) connection1));
    Map<RedisURI, Partitions> partitionsMap = sut.loadViews(seed, Duration.ofSeconds(1), false).toCompletableFuture().join();
    Partitions partitions = partitionsMap.values().iterator().next();
    List<RedisClusterNode> nodes = TopologyComparators.sortByLatency(partitions);
    assertThat(nodes).hasSize(2).extracting(RedisClusterNode::getUri).containsSequence(seed.get(0), RedisURI.create("127.0.0.1", 7381));
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisURI(io.lettuce.core.RedisURI) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 9 with RedisClusterNode

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

the class ClusterTopologyRefreshUnitTests method discoveredAdditionalNodesShouldBeOrderedUsingClientCount.

@Test
void discoveredAdditionalNodesShouldBeOrderedUsingClientCount() {
    List<RedisURI> seed = Collections.singletonList(RedisURI.create("127.0.0.1", 7380));
    when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(InetSocketAddress.createUnresolved("127.0.0.1", 7380)))).thenReturn(completedFuture((StatefulRedisConnection) connection1));
    when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(InetSocketAddress.createUnresolved("127.0.0.1", 7381)))).thenReturn(completedFuture((StatefulRedisConnection) connection2));
    Map<RedisURI, Partitions> partitionsMap = sut.loadViews(seed, Duration.ofSeconds(1), true).toCompletableFuture().join();
    Partitions partitions = partitionsMap.values().iterator().next();
    List<RedisClusterNode> nodes = TopologyComparators.sortByClientCount(partitions);
    assertThat(nodes).hasSize(2).extracting(RedisClusterNode::getUri).contains(RedisURI.create("127.0.0.1", 7381), seed.get(0));
}
Also used : RedisCodec(io.lettuce.core.codec.RedisCodec) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisURI(io.lettuce.core.RedisURI) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Example 10 with RedisClusterNode

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

the class TopologyComparatorsUnitTests method nodesShouldHaveSameSlots.

@Test
void nodesShouldHaveSameSlots() {
    RedisClusterNode nodeA = createNode(1, 4, 36, 98);
    RedisClusterNode nodeB = createNode(4, 36, 1, 98);
    assertThat(nodeA.getSlots().containsAll(nodeB.getSlots())).isTrue();
    assertThat(nodeA.hasSameSlotsAs(nodeB)).isTrue();
}
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