adikou commented on code in PR #24241:
URL: https://github.com/apache/kafka/pull/24241#discussion_r4582758940
##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -754,6 +754,28 @@ public void
shouldIgnoreGroupInstanceIdForEmptyGroupId(GroupProtocol groupProtoc
consumer = newConsumer(config, new ByteArrayDeserializer(), new
ByteArrayDeserializer());
}
+ @ParameterizedTest
+ @EnumSource(GroupProtocol.class)
+ public void testSetRebalanceListenerWithoutGroupId(GroupProtocol
groupProtocol) {
+ consumer = newConsumer(groupProtocol, null);
+
+ assertDoesNotThrow(() ->
consumer.setRebalanceListener(mock(RebalanceListener.class)));
Review Comment:
There's no documented behaviour that setRebalanceListener throws for any
state of consumer. So I'm not sure about this assertion.
Without groupId check the assign flow continues to send records? That's your
assertion that we didn't throw anything
##########
clients/src/main/java/org/apache/kafka/clients/consumer/KafkaConsumer.java:
##########
@@ -900,6 +900,10 @@ public void unsubscribe() {
* the previous pattern of passing a listener to the {@code subscribe()}
methods (which are now deprecated).
*
* <p>
+ * The listener is only invoked when the consumer uses group management
through {@code subscribe()}.
Review Comment:
It would make sense to state the unaffected behaviour from the perspective
of registration, not just invocation for use with and without group management.
I realise we need some wording around what happened if we move from assign
to subscribe and back.
##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -754,6 +754,28 @@ public void
shouldIgnoreGroupInstanceIdForEmptyGroupId(GroupProtocol groupProtoc
consumer = newConsumer(config, new ByteArrayDeserializer(), new
ByteArrayDeserializer());
}
+ @ParameterizedTest
+ @EnumSource(GroupProtocol.class)
+ public void testSetRebalanceListenerWithoutGroupId(GroupProtocol
groupProtocol) {
+ consumer = newConsumer(groupProtocol, null);
+
+ assertDoesNotThrow(() ->
consumer.setRebalanceListener(mock(RebalanceListener.class)));
+ }
+
+ @ParameterizedTest
+ @EnumSource(GroupProtocol.class)
+ public void
testRebalanceListenerNotInvokedWithManualAssignment(GroupProtocol
groupProtocol) {
+ consumer = newConsumer(groupProtocol, groupId);
+ RebalanceListener listener = mock(RebalanceListener.class);
+ consumer.setRebalanceListener(listener);
+
+ consumer.assign(List.of(tp0));
+ consumer.unsubscribe();
+ consumer.close();
+
+ Mockito.verifyNoInteractions(listener);
Review Comment:
nit: Mockito methods are usually statically imported
##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -754,6 +754,28 @@ public void
shouldIgnoreGroupInstanceIdForEmptyGroupId(GroupProtocol groupProtoc
consumer = newConsumer(config, new ByteArrayDeserializer(), new
ByteArrayDeserializer());
}
+ @ParameterizedTest
+ @EnumSource(GroupProtocol.class)
+ public void testSetRebalanceListenerWithoutGroupId(GroupProtocol
groupProtocol) {
+ consumer = newConsumer(groupProtocol, null);
+
+ assertDoesNotThrow(() ->
consumer.setRebalanceListener(mock(RebalanceListener.class)));
+ }
+
+ @ParameterizedTest
+ @EnumSource(GroupProtocol.class)
+ public void
testRebalanceListenerNotInvokedWithManualAssignment(GroupProtocol
groupProtocol) {
+ consumer = newConsumer(groupProtocol, groupId);
+ RebalanceListener listener = mock(RebalanceListener.class);
+ consumer.setRebalanceListener(listener);
+
+ consumer.assign(List.of(tp0));
+ consumer.unsubscribe();
Review Comment:
Subscribe() again to a topic and observe that now listeners are being
invoked?
##########
clients/src/main/java/org/apache/kafka/clients/consumer/KafkaConsumer.java:
##########
@@ -900,6 +900,10 @@ public void unsubscribe() {
* the previous pattern of passing a listener to the {@code subscribe()}
methods (which are now deprecated).
*
* <p>
+ * The listener is only invoked when the consumer uses group management
through {@code subscribe()}.
+ * It is safe to call this method without group management; the listener
is simply never invoked.
Review Comment:
This just seems like a rephrasing of the previous statement. I'm not sure
it's adding much value here
--
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]