use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method expireStaleHostAndPortConnections.
@Test
public void expireStaleHostAndPortConnections() throws Exception {
clusterClient.setOptions(ClusterClientOptions.builder().build());
RedisAdvancedClusterAsyncCommands<String, String> clusterConnection = clusterClient.connect().async();
ClusterSetup.setup2Masters(clusterHelper);
final PooledClusterConnectionProvider<String, String> clusterConnectionProvider = getPooledClusterConnectionProvider(clusterConnection);
assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(0);
assertRoutedExecution(clusterConnection);
assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(2);
for (RedisClusterNode redisClusterNode : clusterClient.getPartitions()) {
clusterConnection.getConnection(redisClusterNode.getUri().getHost(), redisClusterNode.getUri().getPort());
clusterConnection.getConnection(redisClusterNode.getNodeId());
}
assertThat(clusterConnectionProvider.getConnectionCount()).isEqualTo(4);
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();
Wait.untilEquals(1, () -> clusterClient.getPartitions().size()).waitOrTimeout();
Wait.untilEquals(2L, () -> clusterConnectionProvider.getConnectionCount()).waitOrTimeout();
clusterConnection.getStatefulConnection().close();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method slotMigrationShouldUseAsking.
@Test
public void slotMigrationShouldUseAsking() {
ClusterSetup.setup2Masters(clusterHelper);
StatefulRedisClusterConnection<String, String> connection = clusterClient.connect();
RedisAdvancedClusterCommands<String, String> sync = connection.sync();
RedisAdvancedClusterAsyncCommands<String, String> async = connection.async();
Partitions partitions = connection.getPartitions();
assertThat(partitions.getPartitionBySlot(0).getSlots().size()).isEqualTo(12000);
assertThat(partitions.getPartitionBySlot(16380).getSlots().size()).isEqualTo(4384);
redis1.clusterSetSlotMigrating(3300, redis2.clusterMyId());
redis2.clusterSetSlotImporting(3300, redis1.clusterMyId());
assertThat(sync.get("b")).isNull();
async.getStatefulConnection().close();
}
use of io.lettuce.core.cluster.models.partitions.Partitions 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.Partitions in project lettuce-core by lettuce-io.
the class ClusterTopologyRefreshSchedulerUnitTests method shouldRetrievePartitionsViaAdaptiveRefreshTriggeredEvent.
@Test
void shouldRetrievePartitionsViaAdaptiveRefreshTriggeredEvent() {
ClusterClientOptions clusterClientOptions = ClusterClientOptions.builder().topologyRefreshOptions(immediateRefresh).build();
when(clusterClient.getClusterClientOptions()).thenReturn(clusterClientOptions);
sut.onMovedRedirection();
ArgumentCaptor<AdaptiveRefreshTriggeredEvent> captor = ArgumentCaptor.forClass(AdaptiveRefreshTriggeredEvent.class);
verify(eventBus).publish(captor.capture());
AdaptiveRefreshTriggeredEvent capture = captor.getValue();
Partitions partitions = new Partitions();
when(clusterClient.getPartitions()).thenReturn(partitions);
assertThat(capture.getPartitions()).isSameAs(partitions);
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class HealthyMajorityPartitionsConsensusUnitTests method splitUnhealthyNodeViewShouldDecideForHealthyNodes.
@Test
void splitUnhealthyNodeViewShouldDecideForHealthyNodes() {
Partitions partitions1 = createPartitions(node1, node2);
Partitions partitions2 = createPartitions(node2, node3);
Partitions partitions3 = createPartitions(node3, node4, node5);
Map<RedisURI, Partitions> map = createMap(partitions1, partitions2, partitions3);
node2.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
node3.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
node4.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
Partitions result = PartitionsConsensus.HEALTHY_MAJORITY.getPartitions(null, map);
assertThat(Arrays.asList(partitions1, partitions3)).contains(result);
}
Aggregations