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;
}
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);
}
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());
}
}
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);
}
Aggregations