Search in sources :

Example 1 with ReadFrom

use of io.lettuce.core.ReadFrom in project lettuce-core by lettuce-io.

the class MasterReplicaTest method noReplicaForRead.

@Test
void noReplicaForRead() {
    connection.setReadFrom(new ReadFrom() {

        @Override
        public List<RedisNodeDescription> select(Nodes nodes) {
            return Collections.emptyList();
        }
    });
    assertThatThrownBy(() -> replicaCall(connection)).isInstanceOf(RedisException.class);
}
Also used : List(java.util.List) ReadFrom(io.lettuce.core.ReadFrom) AbstractRedisClientTest(io.lettuce.core.AbstractRedisClientTest) Test(org.junit.jupiter.api.Test)

Example 2 with ReadFrom

use of io.lettuce.core.ReadFrom in project lettuce-core by lettuce-io.

the class PooledClusterConnectionProviderUnitTests method shouldNotifyListerOnUncoveredReadSlotAfterSelection.

@Test
void shouldNotifyListerOnUncoveredReadSlotAfterSelection() {
    sut.setReadFrom(new ReadFrom() {

        @Override
        public List<RedisNodeDescription> select(Nodes nodes) {
            return Collections.emptyList();
        }
    });
    sut.getConnectionAsync(Intent.READ, 2);
    verify(clusterEventListener).onUncoveredSlot(2);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ReadFrom(io.lettuce.core.ReadFrom) Test(org.junit.jupiter.api.Test)

Example 3 with ReadFrom

use of io.lettuce.core.ReadFrom in project lettuce-core by lettuce-io.

the class ReadFromUnitTests method subnetIpv6RuleAnyNode.

@Test
void subnetIpv6RuleAnyNode() {
    ReadFrom sut = ReadFrom.subnet("::/0");
    RedisClusterNode node = createNodeWithHost("2001:db8:abcd:1000::");
    List<RedisNodeDescription> result = sut.select(getNodes(node));
    assertThat(result).hasSize(1).containsExactly(node);
}
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 4 with ReadFrom

use of io.lettuce.core.ReadFrom in project lettuce-core by lettuce-io.

the class ReadFromUnitTests method subnetIpv4RuleAnyNode.

@Test
void subnetIpv4RuleAnyNode() {
    ReadFrom sut = ReadFrom.subnet("0.0.0.0/0");
    RedisClusterNode node = createNodeWithHost("192.0.2.1");
    List<RedisNodeDescription> result = sut.select(getNodes(node));
    assertThat(result).hasSize(1).containsExactly(node);
}
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 5 with ReadFrom

use of io.lettuce.core.ReadFrom in project lettuce-core by lettuce-io.

the class ReadFromUnitTests method subnetIpv4Ipv6Mixed.

@Test
void subnetIpv4Ipv6Mixed() {
    ReadFrom sut = ReadFrom.subnet("192.0.2.0/24", "2001:db8:abcd:0000::/52");
    RedisClusterNode nodeInSubnetIpv4 = createNodeWithHost("192.0.2.1");
    RedisClusterNode nodeNotInSubnetIpv4 = createNodeWithHost("198.51.100.1");
    RedisClusterNode nodeInSubnetIpv6 = createNodeWithHost("2001:db8:abcd:0000::1");
    RedisClusterNode nodeNotInSubnetIpv6 = createNodeWithHost("2001:db8:abcd:1000::");
    List<RedisNodeDescription> result = sut.select(getNodes(nodeInSubnetIpv4, nodeNotInSubnetIpv4, nodeInSubnetIpv6, nodeNotInSubnetIpv6));
    assertThat(result).hasSize(2).containsExactly(nodeInSubnetIpv4, nodeInSubnetIpv6);
}
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)

Aggregations

ReadFrom (io.lettuce.core.ReadFrom)11 Test (org.junit.jupiter.api.Test)10 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)8 RedisNodeDescription (io.lettuce.core.models.role.RedisNodeDescription)8 List (java.util.List)4 AbstractRedisClientTest (io.lettuce.core.AbstractRedisClientTest)2 ArrayList (java.util.ArrayList)2 ConnectionFuture (io.lettuce.core.ConnectionFuture)1 OrderingReadFromAccessor (io.lettuce.core.OrderingReadFromAccessor)1 RedisChannelWriter (io.lettuce.core.RedisChannelWriter)1 RedisConnectionException (io.lettuce.core.RedisConnectionException)1 RedisException (io.lettuce.core.RedisException)1 RedisFuture (io.lettuce.core.RedisFuture)1 RedisURI (io.lettuce.core.RedisURI)1 StatefulConnection (io.lettuce.core.api.StatefulConnection)1 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1 PushMessage (io.lettuce.core.api.push.PushMessage)1 ConnectionKey (io.lettuce.core.cluster.ClusterNodeConnectionFactory.ConnectionKey)1 RedisClusterPushListener (io.lettuce.core.cluster.api.push.RedisClusterPushListener)1 Partitions (io.lettuce.core.cluster.models.partitions.Partitions)1