Shekharrajak commented on code in PR #22357:
URL: https://github.com/apache/kafka/pull/22357#discussion_r3430454969
##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/consumer/ShareConsumerTransactionTest.java:
##########
@@ -111,6 +111,78 @@ public void testTransactionalShareAckCommitAccept() throws
Exception {
}
}
+ @ClusterTest
+ public void testTransactionalShareAckCommitAcrossMultiplePolls() throws
Exception {
+ String groupId = "txn-share-commit-multiple-polls";
+ alterShareAutoOffsetReset(groupId, "earliest");
+
+ try (Producer<byte[], byte[]> producer = createProducer();
+ Producer<byte[], byte[]> transactionalProducer =
createTransactionalProducer("txn-share-commit-multiple-polls-producer");
+ ShareConsumer<byte[], byte[]> shareConsumer = createShareConsumer(
+ groupId,
+ Map.of(ConsumerConfig.SHARE_ACKNOWLEDGEMENT_MODE_CONFIG,
EXPLICIT));
+ Admin admin = createAdminClient()) {
+
+ producer.send(record("first")).get();
+ producer.flush();
+
+ transactionalProducer.initTransactions();
+ transactionalProducer.partitionsFor(tp.topic());
+
+ shareConsumer.subscribe(Set.of(tp.topic()));
+ ConsumerRecords<byte[], byte[]> firstRecords =
waitedPoll(shareConsumer, 2500L, 1);
+ ConsumerRecord<byte[], byte[]> firstRecord =
firstRecords.iterator().next();
+ assertEquals(0L, firstRecord.offset());
+ assertEquals("first", new String(firstRecord.value(),
StandardCharsets.UTF_8));
+
+ ShareGroupMetadata groupMetadata =
shareConsumer.shareGroupMetadata();
+ shareConsumer.acknowledge(firstRecord, AcknowledgeType.ACCEPT);
+ ShareAcknowledgements firstAcknowledgements =
shareConsumer.acknowledgementsForTransaction();
+ assertFalse(firstAcknowledgements.isEmpty());
+ TopicIdPartition firstAcknowledgedPartition =
firstAcknowledgements.acknowledgements().keySet().iterator().next();
+ assertEquals(tp, firstAcknowledgedPartition.topicPartition());
+ ShareAcknowledgementBatch firstBatch =
firstAcknowledgements.acknowledgements().get(firstAcknowledgedPartition).get(0);
+ assertEquals(0L, firstBatch.firstOffset());
+ assertEquals(0L, firstBatch.lastOffset());
+ assertEquals(List.of(AcknowledgeType.ACCEPT.id),
firstBatch.acknowledgeTypes());
+ transactionalProducer.beginTransaction();
+ try {
+
transactionalProducer.sendShareAcknowledgementsToTransaction(firstAcknowledgements,
groupMetadata);
Review Comment:
Send the first share acknowledgement to the transaction.
--
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]