cool9850311 commented on code in PR #24199:
URL: https://github.com/apache/kafka/pull/24199#discussion_r4553825231


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/consumer/PlaintextConsumerCallbackTest.java:
##########
@@ -537,6 +537,63 @@ public void onPartitionsRevoked(Collection<TopicPartition> 
partitions, Rebalance
         assertEquals(2, revokedCount.get(), "close() should invoke 
onPartitionsRevoked");
     }
 
+    @ClusterTest
+    public void testClassicConsumerRebalanceListenerRemovedByNull() throws 
InterruptedException {
+        testRebalanceListenerRemovedByNull(CLASSIC);
+    }
+
+    @ClusterTest
+    public void testAsyncConsumerRebalanceListenerRemovedByNull() throws 
InterruptedException {
+        testRebalanceListenerRemovedByNull(CONSUMER);
+    }
+
+    private void testRebalanceListenerRemovedByNull(GroupProtocol 
groupProtocol) throws InterruptedException {
+        var assignedCount = new AtomicInteger(0);
+        var revokedCount = new AtomicInteger(0);
+        try (var consumer = createConsumer(groupProtocol)) {
+            consumer.setRebalanceListener(new RebalanceListener() {
+                @Override
+                public void onPartitionsAssigned(Collection<TopicPartition> 
partitions, RebalanceConsumer rc) {
+                    if (partitions.contains(tp)) {
+                        assignedCount.incrementAndGet();
+                    }
+                }
+
+                @Override
+                public void onPartitionsRevoked(Collection<TopicPartition> 
partitions, RebalanceConsumer rc) {
+                    if (partitions.contains(tp)) {
+                        revokedCount.incrementAndGet();
+                    }
+                }
+            });
+            consumer.subscribe(List.of(topic));
+            ClientsTestUtils.pollUntilTrue(
+                    consumer,
+                    () -> assignedCount.get() == 1,
+                    "Timed out before expected rebalance completed"
+            );
+
+            consumer.setRebalanceListener(null);
+
+            // with a listener set, unsubscribe() invokes onPartitionsRevoked 
without a poll, see
+            // testRebalanceListenerRetainedAfterUnsubscribe
+            consumer.unsubscribe();
+            assertEquals(0, revokedCount.get(), "unsubscribe() should not 
invoke the removed listener");

Review Comment:
   Done.



-- 
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]

Reply via email to