Search in sources :

Example 1 with Partitions

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

the class ClusterTopologyRefreshUnitTests method getNodeSpecificViewsNode1IsFasterThanNode2.

@Test
void getNodeSpecificViewsNode1IsFasterThanNode2() throws Exception {
    Requests requests = createClusterNodesRequests(1, NODE_1_VIEW);
    requests = createClusterNodesRequests(2, NODE_2_VIEW).mergeWith(requests);
    Requests clientRequests = createClientListRequests(1, "c1\nc2\n").mergeWith(createClientListRequests(2, "c1\nc2\n"));
    NodeTopologyViews nodeSpecificViews = sut.getNodeSpecificViews(requests, clientRequests);
    Collection<Partitions> values = nodeSpecificViews.toMap().values();
    assertThat(values).hasSize(2);
    for (Partitions value : values) {
        assertThat(value).extracting("nodeId").containsSequence("1", "2");
    }
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 2 with Partitions

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

the class ClusterTopologyRefreshUnitTests method getNodeSpecificViewsNode2IsFasterThanNode1.

@Test
void getNodeSpecificViewsNode2IsFasterThanNode1() {
    Requests clusterNodesRequests = createClusterNodesRequests(5, NODE_1_VIEW);
    clusterNodesRequests = createClusterNodesRequests(1, NODE_2_VIEW).mergeWith(clusterNodesRequests);
    Requests clientRequests = createClientListRequests(5, "c1\nc2\n").mergeWith(createClientListRequests(1, "c1\nc2\n"));
    NodeTopologyViews nodeSpecificViews = sut.getNodeSpecificViews(clusterNodesRequests, clientRequests);
    List<Partitions> values = new ArrayList<>(nodeSpecificViews.toMap().values());
    assertThat(values).hasSize(2);
    for (Partitions value : values) {
        assertThat(value).extracting("nodeId").containsExactly("2", "1");
    }
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with Partitions

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

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

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

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