Skip to content

Commit

Permalink
Add test that checks hash ranges to get a visual clue of the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Sep 20, 2024
1 parent d9bde04 commit bae30bc
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@ public void testShouldNotChangeSelectedConsumerWhenConsumerIsRemoved() {
}
}

@Test
public void testShouldNotChangeSelectedConsumerWhenConsumerIsRemovedCheckHashRanges() {
final ConsistentHashingStickyKeyConsumerSelector selector = new ConsistentHashingStickyKeyConsumerSelector(5);
final String consumerName = "consumer";
final int numOfInitialConsumers = 10;
List<Consumer> consumers = new ArrayList<>();
for (int i = 0; i < numOfInitialConsumers; i++) {
final Consumer consumer = createMockConsumer(consumerName, "index " + i, i);
consumers.add(consumer);
selector.addConsumer(consumer);
}

int hashRangeSize = Integer.MAX_VALUE;

Map<Consumer, List<Range>> expected = selector.getConsumerKeyHashRanges();
assertThat(selector.getConsumerKeyHashRanges()).as("sanity check").isEqualTo(expected);

for (Consumer removedConsumer : consumers) {
selector.removeConsumer(removedConsumer);
Map<Consumer, List<Range>> actual = selector.getConsumerKeyHashRanges();
expected.remove(removedConsumer);
assertThat(actual).as("removed %s", removedConsumer.toString())
.containsExactlyInAnyOrderEntriesOf(expected);
}
}

@Test
public void testShouldNotChangeSelectedConsumerWhenConsumerIsAdded() {
final ConsistentHashingStickyKeyConsumerSelector selector = new ConsistentHashingStickyKeyConsumerSelector(100);
Expand Down

0 comments on commit bae30bc

Please sign in to comment.