use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method clusterForget.
@Test
public void clusterForget() {
clusterHelper.clusterReset();
String result = redis1.clusterMeet(host, ClusterTestSettings.port6);
assertThat(result).isEqualTo("OK");
Wait.untilTrue(() -> redis1.clusterNodes().contains(redis2.clusterMyId())).waitOrTimeout();
Wait.untilTrue(() -> redis2.clusterNodes().contains(redis1.clusterMyId())).waitOrTimeout();
Wait.untilTrue(() -> {
Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
if (partitions.size() != 2) {
return false;
}
for (RedisClusterNode redisClusterNode : partitions) {
if (redisClusterNode.is(RedisClusterNode.NodeFlag.HANDSHAKE)) {
return false;
}
}
return true;
}).waitOrTimeout();
redis1.clusterForget(redis2.clusterMyId());
Wait.untilEquals(1, () -> ClusterPartitionParser.parse(redis1.clusterNodes()).size()).waitOrTimeout();
Partitions partitionsAfterForget = ClusterPartitionParser.parse(redis1.clusterNodes());
assertThat(partitionsAfterForget.getPartitions()).hasSize(1);
}
use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method doNotExpireStaleNodeIdConnections.
@Test
public void doNotExpireStaleNodeIdConnections() throws Exception {
clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().closeStaleConnections(false).build()).build());
RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
ClusterSetup.setup2Masters(clusterHelper);
PooledClusterConnectionProvider<String, String> clusterConnectionProvider = getPooledClusterConnectionProvider(clusterConnection);
assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(0);
assertRoutedExecution(clusterConnection);
assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(2);
Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
if (!redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
redis1.clusterForget(redisClusterNode.getNodeId());
}
}
partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
if (!redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
redis2.clusterForget(redisClusterNode.getNodeId());
}
}
clusterClient.reloadPartitions();
assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(2);
clusterConnection.getStatefulConnection().close();
}
use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method expireStaleDefaultConnection.
@Test
public void expireStaleDefaultConnection() {
ClusterSetup.setup2Masters(clusterHelper);
RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(), RedisURI.Builder.redis(host, port5).build());
redisClusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().dynamicRefreshSources(false).build()).build());
StatefulRedisClusterConnectionImpl<String, String> connection = (StatefulRedisClusterConnectionImpl<String, String>) redisClusterClient.connect();
String firstMaster = connection.sync().clusterMyId();
RedisClusterNode firstMasterNode = connection.getPartitions().getPartitionByNodeId(firstMaster);
assertThat(firstMasterNode.getUri().getPort()).isEqualTo(port5);
redis2.clusterForget(redis1.clusterMyId());
redis1.clusterForget(redis2.clusterMyId());
Partitions partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
connection.setPartitions(partitions);
Wait.untilTrue(connection::isOpen).waitOrTimeout();
String secondMaster = connection.sync().clusterMyId();
assertThat(secondMaster).isEqualTo(redis2.clusterMyId());
connection.close();
FastShutdown.shutdown(redisClusterClient);
}
use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method disconnectedConnectionRejectTest.
@Test
public void disconnectedConnectionRejectTest() throws Exception {
clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(PERIODIC_REFRESH_ENABLED).disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build());
RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
clusterClient.setOptions(ClusterClientOptions.builder().disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS).build());
ClusterSetup.setup2Masters(clusterHelper);
assertRoutedExecution(clusterConnection);
RedisClusterNode partition1 = getOwnPartition(redis1);
RedisClusterAsyncCommands<String, String> node1Connection = clusterConnection.getConnection(partition1.getUri().getHost(), partition1.getUri().getPort());
shiftAllSlotsToNode1();
suspendConnection(node1Connection);
// 15891
RedisFuture<String> set = clusterConnection.set("t", "value");
set.await(5, TimeUnit.SECONDS);
assertThatThrownBy(() -> TestFutures.awaitOrTimeout(set)).hasRootCauseInstanceOf(RedisException.class);
clusterConnection.getStatefulConnection().close();
}
use of io.lettuce.core.cluster.models.partitions.RedisClusterNode in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method expireStaleDefaultPubSubConnection.
@Test
public void expireStaleDefaultPubSubConnection() {
ClusterSetup.setup2Masters(clusterHelper);
RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(), RedisURI.Builder.redis(host, port5).build());
redisClusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().dynamicRefreshSources(false).build()).build());
StatefulRedisClusterPubSubConnectionImpl<String, String> connection = (StatefulRedisClusterPubSubConnectionImpl<String, String>) redisClusterClient.connectPubSub();
String firstMaster = connection.sync().clusterMyId();
RedisClusterNode firstMasterNode = connection.getPartitions().getPartitionByNodeId(firstMaster);
assertThat(firstMasterNode.getUri().getPort()).isEqualTo(port5);
redis2.clusterForget(redis1.clusterMyId());
redis1.clusterForget(redis2.clusterMyId());
Partitions partitions = ClusterPartitionParser.parse(redis2.clusterNodes());
connection.setPartitions(partitions);
Wait.untilTrue(connection::isOpen).waitOrTimeout();
String secondMaster = connection.sync().clusterMyId();
assertThat(secondMaster).isEqualTo(redis2.clusterMyId());
connection.close();
FastShutdown.shutdown(redisClusterClient);
}
Aggregations