cadonna commented on code in PR #15613:
URL: https://github.com/apache/kafka/pull/15613#discussion_r1570932239
##########
core/src/test/scala/integration/kafka/api/PlaintextConsumerCommitTest.scala:
##########
@@ -304,6 +304,64 @@ class PlaintextConsumerCommitTest extends
AbstractConsumerTest {
consumeAndVerifyRecords(consumer = otherConsumer, numRecords = 1,
startingOffset = 5, startingTimestamp = startingTimestamp)
}
+ // TODO: This only works in the new consumer, but should be fixed for the
old consumer as well
+ @ParameterizedTest(name =
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+
@MethodSource(Array("getTestQuorumAndGroupProtocolParametersConsumerGroupProtocolOnly"))
+ def testCommitAsyncCompletedBeforeConsumerCloses(quorum: String,
groupProtocol: String): Unit = {
+ // This is testing the contract that asynchronous offset commit are
completed before the consumer
+ // is closed, even when no commit sync is performed as part of the close
(due to auto-commit
+ // disabled, or simply because there no consumed offsets).
+ val producer = createProducer()
+ sendRecords(producer, numRecords = 3, tp)
+ sendRecords(producer, numRecords = 3, tp2)
+
+ val consumer = createConsumer()
+ consumer.assign(List(tp, tp2).asJava)
+
+ // Try without looking up the coordinator first
+ val cb = new CountConsumerCommitCallback
+ consumer.commitAsync(Map[TopicPartition, OffsetAndMetadata]((tp, new
OffsetAndMetadata(1L))).asJava, cb)
+ consumer.commitAsync(Map[TopicPartition, OffsetAndMetadata]((tp2, new
OffsetAndMetadata(1L))).asJava, cb)
+ consumer.close()
+ assertEquals(2, cb.successCount)
+ }
+
+ // TODO: This only works in the new consumer, but should be fixed for the
old consumer as well
+ @ParameterizedTest(name =
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+
@MethodSource(Array("getTestQuorumAndGroupProtocolParametersConsumerGroupProtocolOnly"))
+ def testCommitAsyncCompletedBeforeCommitSyncReturns(quorum: String,
groupProtocol: String): Unit = {
+ // This is testing the contract that asynchronous offset commits sent
previously with the
+ // `commitAsync` are guaranteed to have their callbacks invoked prior to
completion of
+ // `commitSync` (given that it does not time out).
+ val producer = createProducer()
+ sendRecords(producer, numRecords = 3, tp)
+ sendRecords(producer, numRecords = 3, tp2)
+
+ val consumer = createConsumer()
+ consumer.assign(List(tp, tp2).asJava)
+
+ // Try without looking up the coordinator first
Review Comment:
I do not understand those comments. How do I recognize in the code that the
coordinator is not looked up first? And why is that so important?
##########
core/src/test/scala/integration/kafka/api/PlaintextConsumerCommitTest.scala:
##########
@@ -304,6 +304,64 @@ class PlaintextConsumerCommitTest extends
AbstractConsumerTest {
consumeAndVerifyRecords(consumer = otherConsumer, numRecords = 1,
startingOffset = 5, startingTimestamp = startingTimestamp)
}
+ // TODO: This only works in the new consumer, but should be fixed for the
old consumer as well
+ @ParameterizedTest(name =
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+
@MethodSource(Array("getTestQuorumAndGroupProtocolParametersConsumerGroupProtocolOnly"))
+ def testCommitAsyncCompletedBeforeConsumerCloses(quorum: String,
groupProtocol: String): Unit = {
+ // This is testing the contract that asynchronous offset commit are
completed before the consumer
+ // is closed, even when no commit sync is performed as part of the close
(due to auto-commit
+ // disabled, or simply because there no consumed offsets).
+ val producer = createProducer()
+ sendRecords(producer, numRecords = 3, tp)
+ sendRecords(producer, numRecords = 3, tp2)
+
+ val consumer = createConsumer()
+ consumer.assign(List(tp, tp2).asJava)
+
+ // Try without looking up the coordinator first
+ val cb = new CountConsumerCommitCallback
+ consumer.commitAsync(Map[TopicPartition, OffsetAndMetadata]((tp, new
OffsetAndMetadata(1L))).asJava, cb)
+ consumer.commitAsync(Map[TopicPartition, OffsetAndMetadata]((tp2, new
OffsetAndMetadata(1L))).asJava, cb)
+ consumer.close()
+ assertEquals(2, cb.successCount)
+ }
+
+ // TODO: This only works in the new consumer, but should be fixed for the
old consumer as well
+ @ParameterizedTest(name =
TestInfoUtils.TestWithParameterizedQuorumAndGroupProtocolNames)
+
@MethodSource(Array("getTestQuorumAndGroupProtocolParametersConsumerGroupProtocolOnly"))
+ def testCommitAsyncCompletedBeforeCommitSyncReturns(quorum: String,
groupProtocol: String): Unit = {
+ // This is testing the contract that asynchronous offset commits sent
previously with the
+ // `commitAsync` are guaranteed to have their callbacks invoked prior to
completion of
+ // `commitSync` (given that it does not time out).
+ val producer = createProducer()
+ sendRecords(producer, numRecords = 3, tp)
+ sendRecords(producer, numRecords = 3, tp2)
+
+ val consumer = createConsumer()
+ consumer.assign(List(tp, tp2).asJava)
+
+ // Try without looking up the coordinator first
+ val cb = new CountConsumerCommitCallback
+ consumer.commitAsync(Map[TopicPartition, OffsetAndMetadata]((tp, new
OffsetAndMetadata(1L))).asJava, cb)
+ consumer.commitSync(Map.empty[TopicPartition, OffsetAndMetadata].asJava)
+ assertEquals(1, consumer.committed(Set(tp).asJava).get(tp).offset)
+ assertEquals(1, cb.successCount)
+
+ // Try with coordinator known
Review Comment:
Same as above
--
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]