Skip to content

Commit

Permalink
[fix] [broker] Fix acknowledgeCumulativeAsync block when ackReceipt i…
Browse files Browse the repository at this point in the history
…s enabled (#23841)
  • Loading branch information
315157973 authored Jan 14, 2025
1 parent ba04a43 commit 999db2c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ public void testAckResponse() throws PulsarClientException, InterruptedException
Assert.assertTrue(e.getCause() instanceof PulsarClientException.NotAllowedException);
}
}
@Test(timeOut = 30000)
public void testAckReceipt() throws Exception {
String topic = "testAckReceipt";
@Cleanup
Producer<Integer> producer = pulsarClient.newProducer(Schema.INT32)
.topic(topic)
.enableBatching(false)
.create();
@Cleanup
ConsumerImpl<Integer> consumer = (ConsumerImpl<Integer>) pulsarClient.newConsumer(Schema.INT32)
.topic(topic)
.subscriptionName("sub")
.isAckReceiptEnabled(true)
.subscribe();
for (int i = 0; i < 10; i++) {
producer.send(i);
}
Message<Integer> message = consumer.receive();
MessageId messageId = message.getMessageId();
consumer.acknowledgeCumulativeAsync(messageId).get();
consumer.acknowledgeCumulativeAsync(messageId).get();
consumer.close();
@Cleanup
ConsumerImpl<Integer> consumer2 = (ConsumerImpl<Integer>) pulsarClient.newConsumer(Schema.INT32)
.topic(topic)
.subscriptionName("sub")
.isAckReceiptEnabled(true)
.acknowledgmentGroupTime(0, TimeUnit.SECONDS)
.subscribe();
message = consumer2.receive();
messageId = message.getMessageId();
consumer2.acknowledgeCumulativeAsync(messageId).get();
consumer2.acknowledgeCumulativeAsync(messageId).get();
}

@Test
public void testIndividualAck() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ private CompletableFuture<Void> doCumulativeAck(MessageIdAdv messageId, Map<Stri
Optional<Lock> readLock = acquireReadLock();
try {
doCumulativeAckAsync(messageId, bitSet);
return readLock.map(__ -> currentCumulativeAckFuture).orElse(CompletableFuture.completedFuture(null));
return readLock.map(__ -> {
if (consumer.isAckReceiptEnabled() && lastCumulativeAck.compareTo(messageId) == 0) {
return CompletableFuture.<Void>completedFuture(null);
}
return currentCumulativeAckFuture;
}).orElse(CompletableFuture.completedFuture(null));
} finally {
readLock.ifPresent(Lock::unlock);
}
Expand Down

0 comments on commit 999db2c

Please sign in to comment.