omkreddy commented on code in PR #17537:
URL: https://github.com/apache/kafka/pull/17537#discussion_r1827556947
##########
core/src/test/java/kafka/test/api/ShareConsumerTest.java:
##########
@@ -255,6 +257,44 @@ public void testSubscriptionAndPollMultiple(String
persister) {
producer.close();
}
+ @ParameterizedTest(name = "{displayName}.persister={0}")
+ @ValueSource(strings = {NO_OP_PERSISTER, DEFAULT_STATE_PERSISTER})
+ public void testAcknowledgementSentOnSubscriptionChange(String persister)
throws ExecutionException, InterruptedException {
+ Map<TopicPartition, Set<Long>> partitionOffsetsMap = new HashMap<>();
+ Map<TopicPartition, Exception> partitionExceptionMap = new HashMap<>();
+
+ ProducerRecord<byte[], byte[]> record = new
ProducerRecord<>(tp.topic(), tp.partition(), null, "key".getBytes(),
"value".getBytes());
+ KafkaProducer<byte[], byte[]> producer = createProducer(new
ByteArraySerializer(), new ByteArraySerializer());
+ producer.send(record);
+ ProducerRecord<byte[], byte[]> record2 = new
ProducerRecord<>(tp2.topic(), tp2.partition(), null, "key".getBytes(),
"value".getBytes());
+ producer.send(record2).get();
+ KafkaShareConsumer<byte[], byte[]> shareConsumer =
createShareConsumer(new ByteArrayDeserializer(), new ByteArrayDeserializer(),
"group1");
+ shareConsumer.setAcknowledgementCommitCallback(new
TestableAcknowledgeCommitCallback(partitionOffsetsMap, partitionExceptionMap));
+
+ shareConsumer.subscribe(Collections.singleton(tp.topic()));
+
+ ConsumerRecords<byte[], byte[]> records =
shareConsumer.poll(Duration.ofMillis(5000));
+ assertEquals(1, records.count());
+
+ shareConsumer.subscribe(Collections.singletonList(tp2.topic()));
+
+ // Waiting for heartbeat to propagate the subscription change.
+ TestUtils.waitForCondition(() ->
shareConsumer.poll(Duration.ofMillis(2000)).count() == 1,
+ DEFAULT_MAX_WAIT_MS, 100L, () -> "Failed to consume records
from the updated subscription");
+
+ producer.send(record2).get();
+
+ //Starting the 3rd poll to invoke the callback
+ shareConsumer.poll(Duration.ofMillis(500));
+
+ // Verifying if the callback was invoked for the partitions in the old
subscription.
+ assertTrue(partitionExceptionMap.containsKey(tp));
+ assertNull(partitionExceptionMap.get(tp));
+
+ producer.close();
Review Comment:
nit: can we use try..finally to close the resources here and other tests
--
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]