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