Search in sources :

Example 61 with Partitions

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

the class HealthyMajorityPartitionsConsensusUnitTests method sameSharedViewShouldDecideForHealthyNodes.

@Test
void sameSharedViewShouldDecideForHealthyNodes() {
    Partitions partitions1 = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions2 = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions3 = createPartitions(node1, node2, node3, node4, node5);
    Map<RedisURI, Partitions> map = createMap(partitions1, partitions2, partitions3);
    Partitions result = PartitionsConsensus.HEALTHY_MAJORITY.getPartitions(null, 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 62 with Partitions

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

the class HealthyMajorityPartitionsConsensusUnitTests method unhealthyNodeViewShouldDecideForHealthyNodes.

@Test
void unhealthyNodeViewShouldDecideForHealthyNodes() {
    Partitions partitions1 = createPartitions(node1, node2);
    Partitions partitions2 = createPartitions(node2, node3, node4, node5);
    Partitions partitions3 = createPartitions(node2, 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));
    node5.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
    Partitions result = PartitionsConsensus.HEALTHY_MAJORITY.getPartitions(null, map);
    assertThat(result).isSameAs(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 63 with Partitions

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

the class HealthyMajorityPartitionsConsensusUnitTests method splitNodeViewShouldDecideForHealthyNodes.

@Test
void splitNodeViewShouldDecideForHealthyNodes() {
    Partitions partitions1 = createPartitions(node1, node2, node3);
    Partitions partitions2 = createPartitions();
    Partitions partitions3 = createPartitions(node3, node4, node5);
    Map<RedisURI, Partitions> map = createMap(partitions1, partitions2, partitions3);
    node1.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
    node2.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
    node3.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.FAIL));
    Partitions result = PartitionsConsensus.HEALTHY_MAJORITY.getPartitions(null, map);
    assertThat(result).isSameAs(partitions3);
}
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 64 with Partitions

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

the class KnownMajorityPartitionsConsensusUnitTests method addedNodeViewShouldDecideForKnownMajority.

@Test
void addedNodeViewShouldDecideForKnownMajority() {
    Partitions current = createPartitions(node1, node2, node3, node4);
    Partitions partitions1 = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions2 = createPartitions(node1, node2, node3, node4, node5);
    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(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 65 with Partitions

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

the class KnownMajorityPartitionsConsensusUnitTests method mixedViewShouldDecideForKnownMajority.

@Test
void mixedViewShouldDecideForKnownMajority() {
    Partitions current = createPartitions(node1, node2, node3, node4, node5);
    Partitions partitions1 = createPartitions(node1, node2, node3, node4);
    Partitions partitions2 = createPartitions(node1, node2, node3, node5);
    Partitions partitions3 = createPartitions(node1, node2, node4, node5);
    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)

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