Search in sources :

Example 21 with RedisClusterNode

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

the class RedisReactiveClusterClientIntegrationTests method testClusterCountFailureReports.

@Test
void testClusterCountFailureReports() {
    RedisClusterNode ownPartition = getOwnPartition(sync);
    StepVerifier.create(reactive.clusterCountFailureReports(ownPartition.getNodeId())).consumeNextWith(actual -> {
        assertThat(actual).isGreaterThanOrEqualTo(0);
    }).verifyComplete();
}
Also used : Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) StepVerifier(reactor.test.StepVerifier) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ClusterTestUtil.getOwnPartition(io.lettuce.core.cluster.ClusterTestUtil.getOwnPartition) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LettuceExtension(io.lettuce.test.LettuceExtension) RedisAdvancedClusterCommands(io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands) RedisAdvancedClusterReactiveCommands(io.lettuce.core.cluster.api.reactive.RedisAdvancedClusterReactiveCommands) TestSupport(io.lettuce.core.TestSupport) StatefulRedisClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 22 with RedisClusterNode

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

the class RoundRobinSocketAddressSupplierUnitTests method nodeIPChanges.

@Test
void nodeIPChanges() {
    RoundRobinSocketAddressSupplier sut = new RoundRobinSocketAddressSupplier(() -> partitions, redisClusterNodes -> redisClusterNodes, clientResourcesMock);
    assertThat(sut.get()).isEqualTo(addr1);
    assertThat(partitions.remove(new RedisClusterNode(hap1, "2", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()))).isTrue();
    assertThat(partitions.add(new RedisClusterNode(hap5, "2", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()))).isTrue();
    assertThat(sut.get()).isEqualTo(addr1);
    assertThat(sut.get()).isEqualTo(addr3);
    assertThat(sut.get()).isEqualTo(addr5);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 23 with RedisClusterNode

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

the class RoundRobinSocketAddressSupplierUnitTests method before.

@BeforeEach
void before() {
    when(clientResourcesMock.socketAddressResolver()).thenReturn(SocketAddressResolver.create(DnsResolvers.JVM_DEFAULT));
    partitions = new Partitions();
    partitions.addPartition(new RedisClusterNode(hap1, "1", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()));
    partitions.addPartition(new RedisClusterNode(hap2, "2", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()));
    partitions.addPartition(new RedisClusterNode(hap3, "3", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>()));
    partitions.updateCache();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with RedisClusterNode

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

the class RoundRobinUnitTests method shouldDetermineConsistencyWithEqualityCheck.

@Test
void shouldDetermineConsistencyWithEqualityCheck() {
    RedisClusterNode node1 = new RedisClusterNode(RedisURI.create("127.0.0.1", 1), "1", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>());
    RedisClusterNode node2 = new RedisClusterNode(RedisURI.create("127.0.0.0", 1), "2", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>());
    RedisClusterNode newNode1 = new RedisClusterNode(RedisURI.create("127.0.0.0", 1), "1", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>());
    RoundRobin<RedisClusterNode> roundRobin = new RoundRobin<>((l, r) -> l.getUri().equals(r.getUri()));
    roundRobin.rebuild(Arrays.asList(node1, node2));
    assertThat(roundRobin.isConsistent(Arrays.asList(node1, node2))).isTrue();
    // RedisClusterNode compares by Id only.
    assertThat(roundRobin.isConsistent(Arrays.asList(newNode1, node2))).isFalse();
    assertThat(roundRobin.isConsistent(Collections.singletonList(newNode1))).isFalse();
    assertThat(roundRobin.isConsistent(Collections.singletonList(node2))).isFalse();
    assertThat(roundRobin.isConsistent(Arrays.asList(RedisClusterNode.of("1"), node2))).isFalse();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 25 with RedisClusterNode

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

the class RoundRobinUnitTests method shouldDetermineConsistencyWithEqualityCheckOppositeCheck.

@Test
void shouldDetermineConsistencyWithEqualityCheckOppositeCheck() {
    RedisClusterNode node1 = RedisClusterNode.of("1");
    RedisClusterNode node2 = RedisClusterNode.of("2");
    RedisClusterNode newNode1 = new RedisClusterNode(RedisURI.create("127.0.0.0", 1), "1", true, "", 0, 0, 0, new ArrayList<>(), new HashSet<>());
    RoundRobin<RedisClusterNode> roundRobin = new RoundRobin<>((l, r) -> l.getUri() == r.getUri() || (l.getUri() != null && l.getUri().equals(r.getUri())));
    roundRobin.rebuild(Arrays.asList(node1, node2));
    assertThat(roundRobin.isConsistent(Arrays.asList(node1, node2))).isTrue();
    // RedisClusterNode compares by Id only.
    assertThat(roundRobin.isConsistent(Arrays.asList(newNode1, node2))).isFalse();
    assertThat(roundRobin.isConsistent(Collections.singletonList(newNode1))).isFalse();
    assertThat(roundRobin.isConsistent(Collections.singletonList(node2))).isFalse();
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Aggregations

RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)94 Test (org.junit.jupiter.api.Test)60 Partitions (io.lettuce.core.cluster.models.partitions.Partitions)36 ArrayList (java.util.ArrayList)18 RedisURI (io.lettuce.core.RedisURI)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)12 RedisNodeDescription (io.lettuce.core.models.role.RedisNodeDescription)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 ReadFrom (io.lettuce.core.ReadFrom)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 List (java.util.List)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Function (java.util.function.Function)6 CompletionStage (java.util.concurrent.CompletionStage)5 RedisException (io.lettuce.core.RedisException)4 RedisFuture (io.lettuce.core.RedisFuture)4 Exceptions (io.lettuce.core.internal.Exceptions)4 Futures (io.lettuce.core.internal.Futures)4 InternalLogger (io.netty.util.internal.logging.InternalLogger)4