lhotari commented on issue #23315: URL: https://github.com/apache/pulsar/issues/23315#issuecomment-2364204087
Tested also by adding these methods: ```java private static Consumer createMockConsumer(String consumerName, String toString, long id) { // without stubOnly, the mock will record method invocations and run into OOME Consumer consumer = mock(Consumer.class, Mockito.withSettings().stubOnly()); when(consumer.consumerName()).thenReturn(consumerName); when(consumer.getPriorityLevel()).thenReturn(0); when(consumer.toString()).thenReturn(toString); when(consumer.consumerId()).thenReturn(id); return consumer; } @Test public void testShouldNotChangeSelectedConsumerWhenConsumerIsRemoved() { final ConsistentHashingStickyKeyConsumerSelector selector = new ConsistentHashingStickyKeyConsumerSelector(100); final String consumerName = "consumer"; final int numOfInitialConsumers = 100; 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; int validationPointCount = 200; int increment = hashRangeSize / validationPointCount; List<Consumer> selectedConsumerBeforeRemoval = new ArrayList<>(); for (int i = 0; i < validationPointCount; i++) { selectedConsumerBeforeRemoval.add(selector.select(i * increment)); } for (int i = 0; i < validationPointCount; i++) { Consumer selected = selector.select(i * increment); Consumer expected = selectedConsumerBeforeRemoval.get(i); assertThat(selected.consumerId()).as("validationPoint %d", i).isEqualTo(expected.consumerId()); } for (Consumer removedConsumer : consumers) { selector.removeConsumer(removedConsumer); for (int i = 0; i < validationPointCount; i++) { Consumer selected = selector.select(i * increment); Consumer expected = selectedConsumerBeforeRemoval.get(i); if (expected != removedConsumer) { assertThat(selected.consumerId()).as("validationPoint %d", i).isEqualTo(expected.consumerId()); } } } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org