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");
}
}
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");
}
}
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));
}
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));
}
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));
}
Aggregations