Search in sources :

Example 66 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.

the class KnownMajorityPartitionsConsensusUnitTests method removedNodeViewShouldDecideForKnownMajority.

@Test
void removedNodeViewShouldDecideForKnownMajority() {
    Partitions current = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions1 = createPartitions(node1, node2, node3, node4);
    Partitions partitions2 = createPartitions(node1, node2, node3, node4);
    Partitions partitions3 = createPartitions(node1, node2, node3, node4);
    Map<RedisURI, Partitions> map = createMap(partitions1, partitions2, partitions3);
    Partitions result = PartitionsConsensus.KNOWN_MAJORITY.getPartitions(current, map);
    assertThat(Arrays.asList(partitions1, partitions2, partitions3)).contains(result);
}
Also used : PartitionsConsensusTestSupport.createPartitions(io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisURI(io.lettuce.core.RedisURI) Test(org.junit.jupiter.api.Test)

Example 67 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.

the class KnownMajorityPartitionsConsensusUnitTests method strangeClusterSplitViewShouldDecideForKnownMajority.

@Test
void strangeClusterSplitViewShouldDecideForKnownMajority() {
    Partitions current = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions1 = createPartitions(node1);
    Partitions partitions2 = createPartitions(node2);
    Partitions partitions3 = createPartitions(node3);
    Map<RedisURI, Partitions> map = createMap(partitions1, partitions2, partitions3);
    Partitions result = PartitionsConsensus.KNOWN_MAJORITY.getPartitions(current, map);
    assertThat(Arrays.asList(partitions1, partitions2, partitions3)).contains(result);
}
Also used : PartitionsConsensusTestSupport.createPartitions(io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisURI(io.lettuce.core.RedisURI) Test(org.junit.jupiter.api.Test)

Example 68 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.

the class KnownMajorityPartitionsConsensusUnitTests method clusterSplitViewShouldDecideForKnownMajority.

@Test
void clusterSplitViewShouldDecideForKnownMajority() {
    Partitions current = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions1 = createPartitions(node1, node2);
    Partitions partitions2 = createPartitions(node1, node2);
    Partitions partitions3 = createPartitions(node1, node2, node3, node4, node5);
    Map<RedisURI, Partitions> map = createMap(partitions1, partitions2, partitions3);
    Partitions result = PartitionsConsensus.KNOWN_MAJORITY.getPartitions(current, map);
    assertThat(result).isEqualTo(partitions3).isNotEqualTo(partitions1);
}
Also used : PartitionsConsensusTestSupport.createPartitions(io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions) Partitions(io.lettuce.core.cluster.models.partitions.Partitions) RedisURI(io.lettuce.core.RedisURI) Test(org.junit.jupiter.api.Test)

Example 69 with Partitions

use of io.lettuce.core.cluster.models.partitions.Partitions in project lettuce-core by lettuce-io.

the class ClusterDistributionChannelWriterBenchmark method setup.

@Setup
public void setup() {
    writer = new ClusterDistributionChannelWriter(CLIENT_OPTIONS, EMPTY_WRITER, ClusterEventListener.NO_OP);
    Partitions partitions = new Partitions();
    partitions.add(new RedisClusterNode(RedisURI.create("localhost", 1), "1", true, null, 0, 0, 0, IntStream.range(0, 8191).boxed().collect(Collectors.toList()), new HashSet<>()));
    partitions.add(new RedisClusterNode(RedisURI.create("localhost", 2), "2", true, null, 0, 0, 0, IntStream.range(8192, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()), new HashSet<>()));
    partitions.updateCache();
    CompletableFuture<EmptyStatefulRedisConnection> connectionFuture = CompletableFuture.completedFuture(CONNECTION);
    writer.setPartitions(partitions);
    writer.setClusterConnectionProvider(new PooledClusterConnectionProvider(new EmptyRedisClusterClient(RedisURI.create("localhost", 7379)), EMPTY_WRITER, ByteArrayCodec.INSTANCE, ClusterEventListener.NO_OP) {

        public CompletableFuture getConnectionAsync(Intent intent, int slot) {
            return connectionFuture;
        }
    });
    writer.setPartitions(partitions);
}
Also used : Partitions(io.lettuce.core.cluster.models.partitions.Partitions) CompletableFuture(java.util.concurrent.CompletableFuture) RedisClusterNode(io.lettuce.core.cluster.models.partitions.RedisClusterNode) HashSet(java.util.HashSet) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

Partitions (io.lettuce.core.cluster.models.partitions.Partitions)69 Test (org.junit.jupiter.api.Test)50 RedisClusterNode (io.lettuce.core.cluster.models.partitions.RedisClusterNode)36 RedisURI (io.lettuce.core.RedisURI)20 ArrayList (java.util.ArrayList)13 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)10 PartitionsConsensusTestSupport.createPartitions (io.lettuce.core.cluster.PartitionsConsensusTestSupport.createPartitions)9 RedisCodec (io.lettuce.core.codec.RedisCodec)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Exceptions (io.lettuce.core.internal.Exceptions)6 Futures (io.lettuce.core.internal.Futures)6 InternalLogger (io.netty.util.internal.logging.InternalLogger)6 InternalLoggerFactory (io.netty.util.internal.logging.InternalLoggerFactory)6 List (java.util.List)6 Function (java.util.function.Function)6 LettuceAssert (io.lettuce.core.internal.LettuceAssert)5 Collection (java.util.Collection)5 Iterator (java.util.Iterator)5 Map (java.util.Map)5 CompletionStage (java.util.concurrent.CompletionStage)5