Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hasNoSlots() method to RedisClusterNode #3015

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*
* @author Mark Paluch
* @author Alessandro Simi
* @author Tony Zhang
* @since 3.0
*/
@SuppressWarnings("serial")
Expand Down Expand Up @@ -294,6 +295,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();
}

}
Loading