use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class TopologyComparatorsUnitTests method isChangedNodeIdChanged.
@Test
void isChangedNodeIdChanged() {
String nodes1 = "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
String nodes2 = "3d005a179da7d8dc1adae6409d47b39c369e992aa 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
Partitions partitions1 = ClusterPartitionParser.parse(nodes1);
Partitions partitions2 = ClusterPartitionParser.parse(nodes2);
assertThat(isChanged(partitions1, partitions2)).isTrue();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class TopologyComparatorsUnitTests method isChangedPortChanged.
@Test
void isChangedPortChanged() {
String nodes1 = "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7382 master - 0 1401258245007 2 disconnected 8000-11999\n" + "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";
String nodes2 = "c37ab8396be428403d4e55c0d317348be27ed973 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n" + "3d005a179da7d8dc1adae6409d47b39c369e992b 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n";
Partitions partitions1 = ClusterPartitionParser.parse(nodes1);
Partitions partitions2 = ClusterPartitionParser.parse(nodes2);
assertThat(isChanged(partitions1, partitions2)).isFalse();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class NodeSelectionAsyncIntegrationTests method testDynamicNodeSelection.
@Test
void testDynamicNodeSelection() {
Partitions partitions = commands.getStatefulConnection().getPartitions();
partitions.forEach(redisClusterNode -> redisClusterNode.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.UPSTREAM)));
AsyncNodeSelection<String, String> selection = commands.nodes(redisClusterNode -> redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF), true);
assertThat(selection.asMap()).hasSize(0);
partitions.getPartition(0).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
assertThat(selection.asMap()).hasSize(1);
partitions.getPartition(1).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
assertThat(selection.asMap()).hasSize(2);
clusterClient.reloadPartitions();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class NodeSelectionSyncIntegrationTests method testDynamicNodeSelection.
@Test
void testDynamicNodeSelection() {
Partitions partitions = commands.getStatefulConnection().getPartitions();
partitions.forEach(redisClusterNode -> redisClusterNode.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.UPSTREAM)));
NodeSelection<String, String> selection = commands.nodes(redisClusterNode -> redisClusterNode.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF), true);
assertThat(selection.asMap()).hasSize(0);
partitions.getPartition(0).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
assertThat(selection.asMap()).hasSize(1);
partitions.getPartition(1).setFlags(LettuceSets.unmodifiableSet(RedisClusterNode.NodeFlag.MYSELF, RedisClusterNode.NodeFlag.UPSTREAM));
assertThat(selection.asMap()).hasSize(2);
clusterClient.reloadPartitions();
}
use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.
the class RedisClusterClientIntegrationTests method testClusterRedirection.
@Test
@SuppressWarnings({ "rawtypes" })
void testClusterRedirection() {
TestCommandListener listener = new TestCommandListener();
clusterClient.getPartitions();
try {
clusterClient.addListener(listener);
RedisAdvancedClusterAsyncCommands<String, String> connection = clusterClient.connect().async();
Partitions partitions = clusterClient.getPartitions();
for (RedisClusterNode partition : partitions) {
partition.setSlots(Collections.emptyList());
if (partition.getFlags().contains(RedisClusterNode.NodeFlag.MYSELF)) {
partition.setSlots(IntStream.range(0, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()));
}
}
partitions.updateCache();
// appropriate cluster node
RedisFuture<String> setB = connection.set(ClusterTestSettings.KEY_B, value);
assertThat(setB.toCompletableFuture()).isInstanceOf(AsyncCommand.class);
TestFutures.awaitOrTimeout(setB);
assertThat(setB.getError()).isNull();
assertThat(TestFutures.getOrTimeout(setB)).isEqualTo("OK");
// gets redirection to node 3
RedisFuture<String> setA = connection.set(ClusterTestSettings.KEY_A, value);
assertThat((CompletionStage) setA).isInstanceOf(AsyncCommand.class);
TestFutures.awaitOrTimeout(setA);
assertThat(setA.getError()).isNull();
assertThat(TestFutures.getOrTimeout(setA)).isEqualTo("OK");
connection.getStatefulConnection().close();
} finally {
clusterClient.removeListener(listener);
}
assertThat(listener.started).hasSizeGreaterThanOrEqualTo(2);
assertThat(listener.succeeded).hasSizeGreaterThanOrEqualTo(2);
}
Aggregations