chia7712 commented on code in PR #24199:
URL: https://github.com/apache/kafka/pull/24199#discussion_r4624086429
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerSubscriptionStateTest.java:
##########
@@ -1204,6 +1206,84 @@ public void
onPartitionsRevoked(Collection<TopicPartition> partitions) {
assertEquals(List.of("assigned-1arg", "revoked-1arg", "revoked-1arg"),
calls);
}
+ @Test
+ public void testSetRebalanceListenerNullRemovesListener() {
+ RebalanceListener listener = mock(RebalanceListener.class);
+ state.setRebalanceListener(listener, consumer);
+ state.subscribe(Set.of(topic));
+ assertTrue(state.hasRebalanceListener());
+ assertEquals(Optional.of(listener.getClass().getName()),
state.listenerName());
+
+ // the consumer argument is irrelevant once the listener is null
+ state.setRebalanceListener(null, consumer);
+
+ assertFalse(state.hasRebalanceListener());
+ assertEquals(Optional.empty(), state.listenerName());
+ }
+
+ @Test
+ public void testNullRebalanceListenerSkipsAllCallbacks() {
+ RebalanceListener listener = mock(RebalanceListener.class);
+ state.setRebalanceListener(listener, consumer);
+ state.setRebalanceListener(null, consumer);
+
+ // the null listener context carries no consumer either, so the
dispatch must
+ // return on the null listener before it ever looks for one
+ assertDoesNotThrow(() -> state.onPartitionsAssigned(partitions));
+ assertDoesNotThrow(() -> state.onPartitionsRevoked(partitions));
+ assertDoesNotThrow(() -> state.onPartitionsLost(partitions));
+
+ verifyNoInteractions(listener);
+ }
+
+ @Test
+ public void testNullRebalanceListenerFromInitialState() {
+ // never registering a listener behaves the same as setting one and
removing it
+ state.setRebalanceListener(null, consumer);
+
+ assertFalse(state.hasRebalanceListener());
+ assertEquals(Optional.empty(), state.listenerName());
+ assertDoesNotThrow(() -> state.onPartitionsAssigned(partitions));
+ assertDoesNotThrow(() -> state.onPartitionsRevoked(partitions));
+ assertDoesNotThrow(() -> state.onPartitionsLost(partitions));
+ }
+
+ @Test
+ public void testSingleArgSetRebalanceListenerRejectsNull() {
Review Comment:
This is pretty weird to me, since we are writing a test for a test-only
helper :(
I opened https://issues.apache.org/jira/browse/KAFKA-21577 to be the
follow-up to clean them up
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]