Search in sources :

Example 91 with RedisClusterNode

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

the class ClusterTestHelper method isStable.

/**
 * @return true if the cluster state is {@code ok} and there are no failing nodes
 */
public boolean isStable() {
    for (RedisAsyncCommands<String, String> commands : connectionCache.values()) {
        try {
            RedisCommands<String, String> sync = commands.getStatefulConnection().sync();
            String info = sync.clusterInfo();
            if (info != null && info.contains("cluster_state:ok")) {
                String s = sync.clusterNodes();
                Partitions parse = ClusterPartitionParser.parse(s);
                for (RedisClusterNode redisClusterNode : parse) {
                    if (redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.FAIL) || redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.EVENTUAL_FAIL) || redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.HANDSHAKE)) {
                        return false;
                    }
                }
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        // nothing to do
        }
    }
    return true;
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 92 with RedisClusterNode

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

the class AdvancedClusterClientIntegrationTests method clientSetname.

@Test
void clientSetname() {
    String name = "test-cluster-client";
    assertThat(clusterClient.getPartitions().size()).isGreaterThan(0);
    sync.clientSetname(name);
    for (RedisClusterNode redisClusterNode : clusterClient.getPartitions()) {
        RedisClusterCommands<String, String> nodeConnection = async.getStatefulConnection().sync().getConnection(redisClusterNode.getNodeId());
        assertThat(nodeConnection.clientList()).contains(name);
    }
    assertThat(sync.clientGetname()).isEqualTo(name);
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 93 with RedisClusterNode

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

the class AdvancedClusterClientIntegrationTests method nodeConnections.

@Test
void nodeConnections() {
    assertThat(clusterClient.getPartitions()).hasSize(4);
    for (RedisClusterNode redisClusterNode : clusterClient.getPartitions()) {
        RedisClusterAsyncCommands<String, String> nodeConnection = async.getConnection(redisClusterNode.getNodeId());
        String myid = TestFutures.getOrTimeout(nodeConnection.clusterMyId());
        assertThat(myid).isEqualTo(redisClusterNode.getNodeId());
    }
}
Also used : RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) Test(org.junit.jupiter.api.Test)

Example 94 with RedisClusterNode

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

the class ClusterDistributionChannelWriterBenchmark method setup.

@Setup
public void setup() {
    writer = new ClusterDistributionChannelWriter(CLIENT_OPTIONS, EMPTY_WRITER, ClusterEventListener.NO_OP);
    Partitions partitions = new Partitions();
    partitions.add(new RedisClusterNode(RedisURI.create("localhost", 1), "1", true, null, 0, 0, 0, IntStream.range(0, 8191).boxed().collect(Collectors.toList()), new HashSet<>()));
    partitions.add(new RedisClusterNode(RedisURI.create("localhost", 2), "2", true, null, 0, 0, 0, IntStream.range(8192, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()), new HashSet<>()));
    partitions.updateCache();
    CompletableFuture<EmptyStatefulRedisConnection> connectionFuture = CompletableFuture.completedFuture(CONNECTION);
    writer.setPartitions(partitions);
    writer.setClusterConnectionProvider(new PooledClusterConnectionProvider(new EmptyRedisClusterClient(RedisURI.create("localhost", 7379)), EMPTY_WRITER, ByteArrayCodec.INSTANCE, ClusterEventListener.NO_OP) {

        public CompletableFuture getConnectionAsync(Intent intent, int slot) {
            return connectionFuture;
        }
    });
    writer.setPartitions(partitions);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) CompletableFuture(java.util.concurrent.CompletableFuture) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) HashSet(java.util.HashSet) Setup(org.openjdk.jmh.annotations.Setup)

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