cool9850311 commented on code in PR #24199:
URL: https://github.com/apache/kafka/pull/24199#discussion_r4553700687
##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -3909,6 +3921,97 @@ public void
testEnforceRebalanceTriggersRebalanceOnNextPoll(GroupProtocol groupP
assertEquals(1, countingRebalanceListener.revokedCount);
}
+ // NOTE: this test uses the enforceRebalance API which is not implemented
in the CONSUMER group protocol.
+ @ParameterizedTest
+ @EnumSource(value = GroupProtocol.class, names = "CLASSIC")
+ public void
testSetRebalanceListenerNullSkipsCallbacksOnRebalance(GroupProtocol
groupProtocol) {
+ Time time = new MockTime(1L);
+ ConsumerMetadata metadata = createMetadata(subscription);
+ MockClient client = new MockClient(time, metadata);
+ consumer = newConsumer(groupProtocol, time, client, subscription,
metadata, assignor, false, groupInstanceId);
+ MockRebalanceListener countingRebalanceListener =
getCountingRebalanceListener();
+ initMetadata(client, Map.of(topic, 1, topic2, 1));
+
+ consumer.setRebalanceListener(countingRebalanceListener);
+ consumer.subscribe(Arrays.asList(topic, topic2));
+ Node node = metadata.fetch().nodes().get(0);
+ Node coordinator = prepareRebalance(client, node, assignor,
Arrays.asList(tp0, t2p0), null);
+
+ // two poll calls, since the first rebalance needs two round trips to
finish join / sync-group
+ consumer.poll(Duration.ZERO);
+ consumer.poll(Duration.ZERO);
+
+ assertEquals(Set.of(tp0, t2p0), consumer.assignment());
+ assertEquals(1, countingRebalanceListener.assignedCount);
+ assertEquals(0, countingRebalanceListener.revokedCount);
+
Review Comment:
Done, with one adjustment.
The first half is as you suggested: while the listener is set, the test
asserts
`position(tp0) == 0` and `position(t2p0) == 0`, which is the externally
visible evidence that the
callback ran.
The second half could not be "assign different offsets and verify they are
untouched". This test
uses `RoundRobinAssignor`, so the rebalance is eager and revokes every
partition, which drops its
position; with the listener removed there is nothing to seek it back. The
partition therefore ends
up assigned with no position at all, and the test asserts that instead:
`position(tp0, Duration.ZERO)` throws `TimeoutException`. I think this is
strictly stronger than
comparing against a different offset, because it shows the seek did not
happen rather than that it
produced a different value.
One small thing: I could not find `Consumer#offsetsForPartitions` anywhere,
so I assumed you meant
`position(TopicPartition)`.
--
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]