Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ protected CompletableFuture<Void> doAcknowledge(List<MessageId> messageIdList,
}
consumerToMessageIds.forEach((consumer, messageIds) -> {
resultFutures.add(consumer.doAcknowledgeWithTxn(messageIds, ackType, properties, txn)
.thenAccept((res) -> messageIdList.forEach(unAckedMessageTracker::remove)));
.thenAccept((res) -> messageIds.forEach(unAckedMessageTracker::remove)));
});
}
return CompletableFuture.allOf(resultFutures.toArray(new CompletableFuture[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.apache.pulsar.client.impl.ClientTestFixtures.createPulsarClientMockWithMockedClientCnx;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -320,4 +321,38 @@ public void testOnTopicsExtendedRemovedTopicCleansUnackedMessages() {
verify(partitionConsumer1).closeAsync();
}

@Test
@SuppressWarnings("unchecked")
public void testBatchAcknowledgeRemovesOnlyAckedMessageIdsFromTracker() {
String topic0 = "persistent://public/default/topic-a-partition-0";
String topic1 = "persistent://public/default/topic-b-partition-0";

ConsumerConfigurationData<byte[]> conf = new ConsumerConfigurationData<>();
conf.setSubscriptionName("subscriptionName");
conf.setAckTimeoutMillis(1000);
MultiTopicsConsumerImpl<byte[]> impl = createMultiTopicsConsumer(conf);
impl.setState(HandlerState.State.Ready);

ConsumerImpl<byte[]> consumer0 = mock(ConsumerImpl.class);
ConsumerImpl<byte[]> consumer1 = mock(ConsumerImpl.class);
CompletableFuture<Void> pendingAck = new CompletableFuture<>();
when(consumer0.getTopic()).thenReturn(topic0);
when(consumer1.getTopic()).thenReturn(topic1);
when(consumer0.doAcknowledgeWithTxn(anyList(), any(), any(), any())).thenReturn(pendingAck);
when(consumer1.doAcknowledgeWithTxn(anyList(), any(), any(), any())).thenReturn(new CompletableFuture<>());

impl.consumers.put(topic0, consumer0);
impl.consumers.put(topic1, consumer1);

TopicMessageIdImpl messageId0 = new TopicMessageIdImpl(topic0, new MessageIdImpl(1, 1, 0));
TopicMessageIdImpl messageId1 = new TopicMessageIdImpl(topic1, new MessageIdImpl(2, 2, 0));
impl.getUnAckedMessageTracker().add(messageId0);
impl.getUnAckedMessageTracker().add(messageId1);

impl.acknowledgeAsync(Arrays.asList(messageId0, messageId1));
pendingAck.complete(null);

assertEquals(impl.getUnAckedMessageTracker().size(), 1);
}

}
Loading