Skip to content

Commit

Permalink
Add hasNoSlots() method to RedisClusterNode
Browse files Browse the repository at this point in the history
  • Loading branch information
wmxl committed Oct 15, 2024
1 parent d255b1a commit f2e7679
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ public List<Integer> getSlots() {
return slots;
}

/**
* Checks if the node has no slots assigned.
*
* @return {@code true} if the slots field is null or empty, {@code false} otherwise.
*/
public boolean hasNoSlots() {
return slots == null || slots.isEmpty();
}

/**
* Performs the given action for each slot of this {@link RedisClusterNode} until all elements have been processed or the
* action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,35 @@ void testToString() {
assertThat(node.toString()).contains(RedisClusterNode.class.getSimpleName());
}

@Test
void shouldReturnTrueWhenSlotsAreNull() {

BitSet emptySlots = null;
RedisClusterNode node = new RedisClusterNode(RedisURI.create("localhost", 6379), "1", true, null, 0, 0, 0, emptySlots,
Collections.emptySet());

assertThat(node.hasNoSlots()).isTrue();
}

@Test
void shouldReturnTrueWhenSlotsAreEmpty() {

BitSet emptySlots = new BitSet(); // Empty BitSet
RedisClusterNode node = new RedisClusterNode(RedisURI.create("localhost", 6379), "1", true, null, 0, 0, 0, emptySlots,
Collections.emptySet());

assertThat(node.hasNoSlots()).isTrue();
}

@Test
void shouldReturnFalseWhenSlotsAreAssigned() {

BitSet slots = new BitSet();
slots.set(1); // Assign a slot
RedisClusterNode node = new RedisClusterNode(RedisURI.create("localhost", 6379), "1", true, null, 0, 0, 0, slots,
Collections.emptySet());

assertThat(node.hasNoSlots()).isFalse();
}

}

0 comments on commit f2e7679

Please sign in to comment.