use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterClientIntegrationTests method reloadPartitionsWithDynamicSourcesFallsBackToInitialSeedNodes.
@Test
void reloadPartitionsWithDynamicSourcesFallsBackToInitialSeedNodes() {
client.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().dynamicRefreshSources(true).build()).build());
Partitions partitions = clusterClient.getPartitions();
partitions.clear();
partitions.add(new RedisClusterNode(RedisURI.create("localhost", 1), "foo", false, null, 0, 0, 0, Collections.emptyList(), Collections.emptySet()));
Partitions reloaded = clusterClient.loadPartitions();
assertThat(reloaded).hasSize(4);
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterClientIntegrationTests method testClusterRedirectionLimit.
@Test
@SuppressWarnings({ "rawtypes" })
void testClusterRedirectionLimit() throws Exception {
clusterClient.setOptions(ClusterClientOptions.builder().maxRedirects(0).build());
RedisAdvancedClusterAsyncCommands<String, String> connection = clusterClient.connect().async();
Partitions partitions = clusterClient.getPartitions();
for (RedisClusterNode partition : partitions) {
if (partition.getSlots().contains(15495)) {
partition.setSlots(Collections.emptyList());
} else {
partition.setSlots(IntStream.range(0, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()));
}
}
partitions.updateCache();
// gets redirection to node 3
RedisFuture<String> setA = connection.set(ClusterTestSettings.KEY_A, value);
assertThat(setA instanceof AsyncCommand).isTrue();
setA.await(10, TimeUnit.SECONDS);
assertThat(setA.getError()).isEqualTo("MOVED 15495 127.0.0.1:7380");
connection.getStatefulConnection().close();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method clusterSetSlots.
@Test
public void clusterSetSlots() {
ClusterSetup.setup2Masters(clusterHelper);
redis1.clusterSetSlotNode(6, getNodeId(redis2));
waitForSlots(redis1, 11999);
waitForSlots(redis2, 4384);
Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
for (RedisClusterNode redisClusterNode : partitions.getPartitions()) {
if (redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
assertThat(redisClusterNode.getSlots()).contains(1, 2, 3, 4, 5).doesNotContain(6);
}
}
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method changeTopologyWhileOperations.
@Test
public void changeTopologyWhileOperations() throws Exception {
ClusterSetup.setup2Masters(clusterHelper);
ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder().enableAllAdaptiveRefreshTriggers().build();
clusterClient.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(clusterTopologyRefreshOptions).build());
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);
assertRoutedExecution(async);
sync.del("A");
sync.del("t");
sync.del("p");
shiftAllSlotsToNode1();
assertRoutedExecution(async);
Wait.untilTrue(() -> {
if (clusterClient.getPartitions().size() == 2) {
for (RedisClusterNode redisClusterNode : clusterClient.getPartitions()) {
if (redisClusterNode.getSlots().size() > 16380) {
return true;
}
}
}
return false;
}).waitOrTimeout();
assertThat(partitions.getPartitionBySlot(0).getSlots().size()).isEqualTo(16384);
assertThat(sync.get("A")).isEqualTo("value");
assertThat(sync.get("t")).isEqualTo("value");
assertThat(sync.get("p")).isEqualTo("value");
async.getStatefulConnection().close();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterSetupTest method shiftAllSlotsToNode1.
private void shiftAllSlotsToNode1() {
redis1.clusterDelSlots(createSlots(12000, 16384));
redis2.clusterDelSlots(createSlots(12000, 16384));
waitForSlots(redis2, 0);
RedisClusterNode redis2Partition = getOwnPartition(redis2);
Wait.untilTrue(new Supplier<Boolean>() {
@Override
public Boolean get() {
Partitions partitions = ClusterPartitionParser.parse(redis1.clusterNodes());
RedisClusterNode partition = partitions.getPartitionByNodeId(redis2Partition.getNodeId());
if (!partition.getSlots().isEmpty()) {
removeRemaining(partition);
}
return partition.getSlots().size() == 0;
}
private void removeRemaining(RedisClusterNode partition) {
try {
redis1.clusterDelSlots(toIntArray(partition.getSlots()));
} catch (Exception o_O) {
// ignore
}
}
}).waitOrTimeout();
redis1.clusterAddSlots(createSlots(12000, 16384));
waitForSlots(redis1, 16384);
Wait.untilTrue(clusterHelper::isStable).waitOrTimeout();
}
Aggregations