Search in sources :

Example 46 with Partitions

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

the class TopologyComparatorsUnitTests method isChangedNodeIdChanged.

@Test
void isChangedNodeIdChanged() {
    String nodes1 = "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
    String nodes2 = "3d005a179da7d8dc1adae6409d47b39c369e992aa 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
    Partitions partitions1 = ClusterPartitionParser.parse(nodes1);
    Partitions partitions2 = ClusterPartitionParser.parse(nodes2);
    assertThat(isChanged(partitions1, partitions2)).isTrue();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 47 with Partitions

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

the class TopologyComparatorsUnitTests method isChangedPortChanged.

@Test
void isChangedPortChanged() {
    String nodes1 = "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7382 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
    String nodes2 = "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n" + "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n";
    Partitions partitions1 = ClusterPartitionParser.parse(nodes1);
    Partitions partitions2 = ClusterPartitionParser.parse(nodes2);
    assertThat(isChanged(partitions1, partitions2)).isFalse();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 48 with Partitions

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

the class NodeSelectionAsyncIntegrationTests method testDynamicNodeSelection.

@Test
void testDynamicNodeSelection() {
    Partitions partitions = commands.getStatefulConnection().getPartitions();
    partitions.forEach(redisClusterNode -> redisClusterNode.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.UPSTREAM)));
    AsyncNodeSelection<String, String> selection = commands.nodes(redisClusterNode -> redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF), true);
    assertThat(selection.asMap()).hasSize(0);
    partitions.getPartition(0).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
    assertThat(selection.asMap()).hasSize(1);
    partitions.getPartition(1).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
    assertThat(selection.asMap()).hasSize(2);
    clusterClient.reloadPartitions();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 49 with Partitions

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

the class NodeSelectionSyncIntegrationTests method testDynamicNodeSelection.

@Test
void testDynamicNodeSelection() {
    Partitions partitions = commands.getStatefulConnection().getPartitions();
    partitions.forEach(redisClusterNode -> redisClusterNode.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.UPSTREAM)));
    NodeSelection<String, String> selection = commands.nodes(redisClusterNode -> redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF), true);
    assertThat(selection.asMap()).hasSize(0);
    partitions.getPartition(0).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
    assertThat(selection.asMap()).hasSize(1);
    partitions.getPartition(1).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
    assertThat(selection.asMap()).hasSize(2);
    clusterClient.reloadPartitions();
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) Test(org.junit.jupiter.api.Test)

Example 50 with Partitions

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

the class RedisClusterClientIntegrationTests method testClusterRedirection.

@Test
@SuppressWarnings({ "rawtypes" })
void testClusterRedirection() {
    TestCommandListener listener = new TestCommandListener();
    clusterClient.getPartitions();
    try {
        clusterClient.addListener(listener);
        RedisAdvancedClusterAsyncCommands<String, String> connection = clusterClient.connect().async();
        Partitions partitions = clusterClient.getPartitions();
        for (RedisClusterNode partition : partitions) {
            partition.setSlots(Collections.emptyList());
            if (partition.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
                partition.setSlots(IntStream.range(0, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()));
            }
        }
        partitions.updateCache();
        // appropriate cluster node
        RedisFuture<String> setB = connection.set(ClusterTestSettings.KEY_B, value);
        assertThat(setB.toCompletableFuture()).isInstanceOf(AsyncCommand.class);
        TestFutures.awaitOrTimeout(setB);
        assertThat(setB.getError()).isNull();
        assertThat(TestFutures.getOrTimeout(setB)).isEqualTo("OK");
        // gets redirection to node 3
        RedisFuture<String> setA = connection.set(ClusterTestSettings.KEY_A, value);
        assertThat((CompletionStage) setA).isInstanceOf(AsyncCommand.class);
        TestFutures.awaitOrTimeout(setA);
        assertThat(setA.getError()).isNull();
        assertThat(TestFutures.getOrTimeout(setA)).isEqualTo("OK");
        connection.getStatefulConnection().close();
    } finally {
        clusterClient.removeListener(listener);
    }
    assertThat(listener.started).hasSizeGreaterThanOrEqualTo(2);
    assertThat(listener.succeeded).hasSizeGreaterThanOrEqualTo(2);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) CompletionStage(java.util.concurrent.CompletionStage) Test(org.junit.jupiter.api.Test)

Aggregations

Partitions (io.lettuce.core.cluster.models.partitions.Partitions)69 Test (org.junit.jupiter.api.Test)50 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)36 RedisURI (io.lettuce.core.RedisURI)20 ArrayList (java.util.ArrayList)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)10 PartitionsConsensusTestSupport.createPartitions (io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Exceptions (io.lettuce.core.internal.Exceptions)6 Futures (io.lettuce.core.internal.Futures)6 InternalLogger (io.netty.util.internal.logging.InternalLogger)6 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)6 List (java.util.List)6 Function (java.util.function.Function)6 LettuceAssert (io.lettuce.core.internal.LettuceAssert)5 Collection (java.util.Collection)5 Iterator (java.util.Iterator)5 Map (java.util.Map)5 CompletionStage (java.util.concurrent.CompletionStage)5