Search in sources :

Example 21 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class ReplicaTopologyProvider method getNodesFromInfo.

protected List<RedisNodeDescription> getNodesFromInfo(String info) {
    List<RedisNodeDescription> result = new ArrayList<>();
    RedisNodeDescription currentNodeDescription = getCurrentNodeDescription(info);
    result.add(currentNodeDescription);
    if (currentNodeDescription.getRole().isUpstream()) {
        result.addAll(getReplicasFromInfo(info));
    } else {
        result.add(getMasterFromInfo(info));
    }
    return result;
}
Also used : RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ArrayList(java.util.ArrayList)

Example 22 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class ReadFromUnitTests method subnetIpv4RuleIpv6NodeGiven.

@Test
void subnetIpv4RuleIpv6NodeGiven() {
    ReadFrom sut = ReadFrom.subnet("0.0.0.0/0");
    RedisClusterNode ipv6node = createNodeWithHost("2001:db8:abcd:1000::");
    List<RedisNodeDescription> result = sut.select(getNodes(ipv6node));
    assertThat(result).isEmpty();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 23 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class ReadFromUnitTests method subnetNodeWithHostname.

@Test
void subnetNodeWithHostname() {
    ReadFrom sut = ReadFrom.subnet("0.0.0.0/0");
    RedisClusterNode hostNode = createNodeWithHost("example.com");
    RedisClusterNode localhostNode = createNodeWithHost("localhost");
    List<RedisNodeDescription> result = sut.select(getNodes(hostNode, localhostNode));
    assertThat(result).isEmpty();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 24 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class ReadFromUnitTests method subnetIpv6RuleIpv4NodeGiven.

@Test
void subnetIpv6RuleIpv4NodeGiven() {
    ReadFrom sut = ReadFrom.subnet("::/0");
    RedisClusterNode node = createNodeWithHost("192.0.2.1");
    List<RedisNodeDescription> result = sut.select(getNodes(node));
    assertThat(result).isEmpty();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 25 with RedisNodeDescription

use of io.lettuce.core.models.role.RedisNodeDescription in project lettuce-core by lettuce-io.

the class MasterReplicaTopologyRefreshUnitTests method shouldRetrieveTopology.

@Test
void shouldRetrieveTopology() {
    MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(connectionFactory, executorService, provider);
    CompletableFuture<StatefulRedisConnection<String, String>> master = CompletableFuture.completedFuture(connection);
    CompletableFuture<StatefulRedisConnection<String, String>> replica = CompletableFuture.completedFuture(connection);
    when(connectionFactory.connectToNodeAsync(any(), any())).thenReturn((CompletableFuture) master, (CompletableFuture) replica);
    RedisURI redisURI = new RedisURI();
    redisURI.setTimeout(Duration.ofMillis(1));
    List<RedisNodeDescription> nodes = refresh.getNodes(redisURI).block();
    assertThat(nodes).hasSize(2);
}
Also used : RedisURI(io.lettuce.core.RedisURI) RedisNodeDescription(io.lettuce.core.models.role.RedisNodeDescription) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) Test(org.junit.jupiter.api.Test)

Aggregations

RedisNodeDescription (io.lettuce.core.models.role.RedisNodeDescription)25 Test (org.junit.jupiter.api.Test)15 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)9 ReadFrom (io.lettuce.core.ReadFrom)8 RedisURI (io.lettuce.core.RedisURI)7 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)5 ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Iterator (java.util.Iterator)3 List (java.util.List)3 RedisConnectionException (io.lettuce.core.RedisConnectionException)2 ConnectionKey (io.lettuce.core.cluster.ClusterNodeConnectionFactory.ConnectionKey)2 ConnectionFuture (io.lettuce.core.ConnectionFuture)1 OrderingReadFromAccessor (io.lettuce.core.OrderingReadFromAccessor)1 RedisChannelWriter (io.lettuce.core.RedisChannelWriter)1 RedisException (io.lettuce.core.RedisException)1 RedisFuture (io.lettuce.core.RedisFuture)1 StatefulConnection (io.lettuce.core.api.StatefulConnection)1 PushMessage (io.lettuce.core.api.push.PushMessage)1 RedisClusterPushListener (io.lettuce.core.cluster.api.push.RedisClusterPushListener)1