congbobo184 commented on a change in pull request #8256:
URL: https://github.com/apache/pulsar/pull/8256#discussion_r513335449
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TransactionEndToEndTest.java
##########
@@ -378,6 +382,91 @@ public void txnMessageAckTest() throws Exception {
log.info("receive transaction messages count: {}", receiveCnt);
}
+ @Test
+ public void txnAckTestBatchAndCumulativeSub() throws Exception {
+ txnCumulativeAckTest(true, 200, SubscriptionType.Failover);
+ }
+
+ @Test
+ public void txnAckTestNoBatchAndCumulativeSub() throws Exception {
+ txnCumulativeAckTest(false, 1, SubscriptionType.Failover);
+ }
+
+ public void txnCumulativeAckTest(boolean batchEnable, int maxBatchSize,
SubscriptionType subscriptionType)
+ throws Exception {
+ String normalTopic = NAMESPACE1 + "/normal-topic";
+
+ @Cleanup
+ ConsumerImpl<byte[]> consumer = (ConsumerImpl<byte[]>)
pulsarClient.newConsumer()
+ .topic(normalTopic)
+ .subscriptionName("test")
+ .enableBatchIndexAcknowledgment(true)
+ .subscriptionType(subscriptionType)
+ .ackTimeout(1, TimeUnit.MINUTES)
+ .subscribe();
+
+ @Cleanup
+ Producer<byte[]> producer = pulsarClient.newProducer()
+ .topic(normalTopic)
+ .enableBatching(batchEnable)
+ .batchingMaxMessages(maxBatchSize)
+ .batchingMaxPublishDelay(1, TimeUnit.SECONDS)
+ .create();
+
+ for (int retryCnt = 0; retryCnt < 2; retryCnt++) {
+ Transaction abortTxn = getTxn();
+ int messageCnt = 130;
+ // produce normal messages
+ for (int i = 0; i < messageCnt; i++){
+ producer.newMessage().value("hello".getBytes()).sendAsync();
+ }
+ Message<byte[]> message = null;
+ Thread.sleep(1000L);
+ for (int i = 0; i < messageCnt; i++) {
+ message = consumer.receive(1, TimeUnit.SECONDS);
+ Assert.assertNotNull(message);
+ if (i % 3 == 0) {
+
consumer.acknowledgeCumulativeAsync(message.getMessageId(), abortTxn).get();
+ }
+ log.info("receive msgId abort: {}, retryCount : {}, count :
{}", message.getMessageId(), retryCnt, i);
+ }
+ try {
+ consumer.acknowledgeCumulativeAsync(message.getMessageId(),
abortTxn).get();
+ fail("not ack conflict ");
+ } catch (Exception e) {
+ Assert.assertTrue(e.getCause() instanceof
PulsarClientException.TransactionConflictException);
+ }
+ abortTxn.abort().get();
+ Thread.sleep(2000);
Review comment:
client commit txn and the TC will not call TB before, now it don't need
to sleep.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]