Skip to content

Commit

Permalink
test(redis#2341):Add test cases for hasSameSlotsAs()
Browse files Browse the repository at this point in the history
  • Loading branch information
zeze1004 authored and tishun committed Jul 12, 2024
1 parent e5ea295 commit c5b8720
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashSet;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -68,6 +69,42 @@ void shouldCopyNodeWithNonEmptySlots() {
assertThat(copiedNode.getSlots()).containsExactly(1, 2);
}

@Test
public void testHasSameSlotsAs() {

BitSet slots1 = new BitSet(SlotHash.SLOT_COUNT);
slots1.set(1);
slots1.set(2);

BitSet slots2 = new BitSet(SlotHash.SLOT_COUNT);
slots2.set(1);
slots2.set(2);

RedisClusterNode node1 = new RedisClusterNode(RedisURI.create("localhost", 6379), "nodeId1", true, "slaveOf", 0L, 0L,
0L, slots1, new HashSet<>());
RedisClusterNode node2 = new RedisClusterNode(RedisURI.create("localhost", 6379), "nodeId2", true, "slaveOf", 0L, 0L,
0L, slots2, new HashSet<>());

assertThat(node1.hasSameSlotsAs(node2)).isTrue();
}

@Test
public void testHasDifferentSlotsAs() {

BitSet slots1 = new BitSet(SlotHash.SLOT_COUNT);
slots1.set(1);

BitSet slots2 = new BitSet(SlotHash.SLOT_COUNT);
slots2.set(2);

RedisClusterNode node1 = new RedisClusterNode(RedisURI.create("localhost", 6379), "nodeId1", true, "slaveOf", 0L, 0L,
0L, slots1, new HashSet<>());
RedisClusterNode node2 = new RedisClusterNode(RedisURI.create("localhost", 6379), "nodeId2", true, "slaveOf", 0L, 0L,
0L, slots2, new HashSet<>());

assertThat(node1.hasSameSlotsAs(node2)).isFalse();
}

@Test
void shouldCopyNode() {

Expand Down

0 comments on commit c5b8720

Please sign in to comment.