use of io.lettuce.core.cluster.models.partitions.Partitions 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.Partitions 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.Partitions 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);
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method clusterMeet.
@Test
public void clusterMeet() {
clusterHelper.clusterReset();
Partitions partitionsBeforeMeet = ClusterPartitionParser.parse(redis1.clusterNodes());
assertThat(partitionsBeforeMeet.getPartitions()).hasSize(1);
String result = redis1.clusterMeet(host, ClusterTestSettings.port6);
assertThat(result).isEqualTo("OK");
Wait.untilEquals(2, () -> ClusterPartitionParser.parse(redis1.clusterNodes()).size()).waitOrTimeout();
Partitions partitionsAfterMeet = ClusterPartitionParser.parse(redis1.clusterNodes());
assertThat(partitionsAfterMeet.getPartitions()).hasSize(2);
}
use of io.lettuce.core.cluster.models.partitions.Partitions 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();
}
Aggregations