lianetm commented on code in PR #15965:
URL: https://github.com/apache/kafka/pull/15965#discussion_r1601804725


##########
core/src/test/scala/integration/kafka/api/PlaintextConsumerCallbackTest.scala:
##########
@@ -84,29 +84,87 @@ class PlaintextConsumerCallbackTest extends 
AbstractConsumerTest {
   @ParameterizedTest(name = 
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
   @MethodSource(Array("getTestQuorumAndGroupProtocolParametersAll"))
   def testConsumerRebalanceListenerBeginningOffsetsOnPartitionsRevoked(quorum: 
String, groupProtocol: String): Unit = {
-    val tp = new TopicPartition(topic, 0);
+    val tp = new TopicPartition(topic, 0)
     triggerOnPartitionsRevoked { (consumer, _) =>
       val map = consumer.beginningOffsets(Collections.singletonList(tp))
       assertTrue(map.containsKey(tp))
       assertEquals(0, map.get(tp))
     }
   }
 
+  @ParameterizedTest(name = 
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+  @MethodSource(Array("getTestQuorumAndGroupProtocolParametersAll"))
+  def 
testGetPositionOfNewlyAssignedPartitionOnPartitionsAssignedCallback(quorum: 
String, groupProtocol: String): Unit = {
+    val tp = new TopicPartition(topic, 0)
+    triggerOnPartitionsAssigned { (consumer, _) => assertDoesNotThrow(() => 
consumer.position(tp)) }
+  }
+
+  @ParameterizedTest(name = 
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+  @MethodSource(Array("getTestQuorumAndGroupProtocolParametersAll"))
+  def 
testSeekPositionOfNewlyAssignedPartitionOnPartitionsAssignedCallback(quorum: 
String, groupProtocol: String): Unit = {
+    val consumer = createConsumer()
+    val startingOffset = 100L
+    val totalRecords = 120L
+
+    val producer = createProducer()
+    val startingTimestamp = 0
+    sendRecords(producer, totalRecords.toInt, tp, startingTimestamp)
+
+    consumer.subscribe(asList(topic), new ConsumerRebalanceListener {
+      override def onPartitionsAssigned(partitions: 
util.Collection[TopicPartition]): Unit = {
+        consumer.seek(tp, startingOffset)
+      }
+
+      override def onPartitionsRevoked(partitions: 
util.Collection[TopicPartition]): Unit = {
+        // noop
+      }
+    })
+    consumeAndVerifyRecords(consumer, numRecords = (totalRecords - 
startingOffset).toInt,
+      startingOffset = startingOffset.toInt, startingKeyAndValueIndex = 
startingOffset.toInt,
+      startingTimestamp = startingOffset)
+  }
+
+  @ParameterizedTest(name = 
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+  @MethodSource(Array("getTestQuorumAndGroupProtocolParametersAll"))
+  def testPauseOnPartitionsAssignedCallback(quorum: String, groupProtocol: 
String): Unit = {
+    val consumer = createConsumer()
+    val totalRecords = 100L
+    val partitionsAssigned = new AtomicBoolean(false)
+
+    val producer = createProducer()
+    val startingTimestamp = 0
+    sendRecords(producer, totalRecords.toInt, tp, startingTimestamp)
+
+    consumer.subscribe(asList(topic), new ConsumerRebalanceListener {
+      override def onPartitionsAssigned(partitions: 
util.Collection[TopicPartition]): Unit = {
+        consumer.pause(asList(tp))
+        partitionsAssigned.set(true)
+      }
+
+      override def onPartitionsRevoked(partitions: 
util.Collection[TopicPartition]): Unit = {
+        // noop
+      }
+    })
+    TestUtils.pollUntilTrue(consumer, () => partitionsAssigned.get(), "Timed 
out before expected rebalance completed")
+    assertTrue(consumer.paused().contains(tp))
+    consumer.resume(asList(tp))
+    consumeAndVerifyRecords(consumer, numRecords = totalRecords.toInt, 
startingOffset = 0, startingTimestamp)
+  }
+
   private def triggerOnPartitionsAssigned(execute: (Consumer[Array[Byte], 
Array[Byte]], util.Collection[TopicPartition]) => Unit): Unit = {
     val consumer = createConsumer()
-    val partitionsAssigned = new AtomicBoolean(false);
+    val partitionsAssigned = new AtomicBoolean(false)
     consumer.subscribe(asList(topic), new ConsumerRebalanceListener {
       override def onPartitionsAssigned(partitions: 
util.Collection[TopicPartition]): Unit = {
-        execute(consumer, partitions);
-        partitionsAssigned.set(true);
+        execute(consumer, partitions)
+        partitionsAssigned.set(true)
       }
 
       override def onPartitionsRevoked(partitions: 
util.Collection[TopicPartition]): Unit = {
         // noop
       }
     })
     TestUtils.pollUntilTrue(consumer, () => partitionsAssigned.get(), "Timed 
out before expected rebalance completed")
-    consumer.close()

Review Comment:
   Removed as it's not needed here, the test already has the logic for closing 
all consumers on 
([IntegrationTestHarness.tearDown](https://github.com/apache/kafka/blob/3f8d11f047bf2f388fee7e8b5ddb359b47cee554/core/src/test/scala/integration/kafka/api/IntegrationTestHarness.scala#L225)).
 (Left it on the `triggerOnPartitionsRevoked` as it was, where it's needed to 
assert the revocation)



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