Skip to content

Commit

Permalink
[fix][client] Fix negative acknowledgement by messageId (#23060)
Browse files Browse the repository at this point in the history
(cherry picked from commit d4bbf10)
  • Loading branch information
izumo27 authored and lhotari committed Aug 9, 2024
1 parent ecbfcdc commit f9ba4d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void testNegativeAcks(boolean batching, boolean usePartitions, Subscripti
Set<String> sentMessages = new HashSet<>();

final int N = 10;
for (int i = 0; i < N; i++) {
for (int i = 0; i < N * 2; i++) {
String value = "test-" + i;
producer.sendAsync(value);
sentMessages.add(value);
Expand All @@ -151,13 +151,18 @@ public void testNegativeAcks(boolean batching, boolean usePartitions, Subscripti
consumer.negativeAcknowledge(msg);
}

for (int i = 0; i < N; i++) {
Message<String> msg = consumer.receive();
consumer.negativeAcknowledge(msg.getMessageId());
}

assertTrue(consumer instanceof ConsumerBase);
assertEquals(((ConsumerBase<String>) consumer).getUnAckedMessageTracker().size(), 0);

Set<String> receivedMessages = new HashSet<>();

// All the messages should be received again
for (int i = 0; i < N; i++) {
for (int i = 0; i < N * 2; i++) {
Message<String> msg = consumer.receive();
receivedMessages.add(msg.getValue());
consumer.acknowledge(msg);
Expand Down Expand Up @@ -304,9 +309,7 @@ public void testNegativeAcksDeleteFromUnackedTracker() throws Exception {
assertEquals(unAckedMessageTracker.size(), 0);
nackedMessages.clear();
// negative batch message id
unAckedMessageTracker.add(batchMessageId);
unAckedMessageTracker.add(batchMessageId2);
unAckedMessageTracker.add(batchMessageId3);
unAckedMessageTracker.add(messageId);
consumer.negativeAcknowledge(batchMessageId);
consumer.negativeAcknowledge(batchMessageId2);
consumer.negativeAcknowledge(batchMessageId3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public void negativeAcknowledge(MessageId messageId) {
negativeAcksTracker.add(messageId);

// Ensure the message is not redelivered for ack-timeout, since we did receive an "ack"
unAckedMessageTracker.remove(messageId);
unAckedMessageTracker.remove(discardBatch(messageId));
}

@Override
Expand Down

0 comments on commit f9ba4d8

Please sign in to comment.