liangyepianzhou commented on code in PR #15137:
URL: https://github.com/apache/pulsar/pull/15137#discussion_r858178575
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/pendingack/PendingAckPersistentTest.java:
##########
@@ -345,4 +350,103 @@ private void
testDeleteTopicThenDeletePendingAckManagedLedger() throws Exception
assertFalse(topics.contains(MLPendingAckStore.getTransactionPendingAckStoreSuffix(topic,
subName2)));
assertFalse(topics.contains(topic));
}
+
+ @Test
+ public void testDeleteUselessLogDataWhenSubCursorMoved() throws Exception {
+
getPulsarServiceList().get(0).getConfig().setTransactionPendingAckLogIndexMinLag(5);
+
getPulsarServiceList().get(0).getConfiguration().setManagedLedgerDefaultMarkDeleteRateLimit(5);
+ String subName = "test-log-delete";
+ String topic = TopicName.get(TopicDomain.persistent.toString(),
+ NamespaceName.get(NAMESPACE1), "test-log-delete").toString();
+
+ @Cleanup
+ Consumer<byte[]> consumer = pulsarClient.newConsumer()
+ .topic(topic)
+ .subscriptionName(subName)
+ .subscribe();
+ @Cleanup
+ Producer<byte[]> producer = pulsarClient.newProducer()
+ .topic(topic)
+ .sendTimeout(0, TimeUnit.SECONDS)
+ .enableBatching(false)
+ .create();
+
+ for (int i = 0; i < 20; i++) {
+ producer.newMessage().send();
+ }
+ // init
+ Message<byte[]> message = consumer.receive(5, TimeUnit.SECONDS);
+ Transaction transaction = pulsarClient.newTransaction()
+ .withTransactionTimeout(5, TimeUnit.SECONDS)
+ .build()
+ .get();
+ consumer.acknowledgeAsync(message.getMessageId(), transaction).get();
+
+ PersistentTopic persistentTopic = (PersistentTopic)
getPulsarServiceList().get(0)
+ .getBrokerService().getTopic(topic, false).get().get();
+
+ PersistentSubscription persistentSubscription =
persistentTopic.getSubscription(subName);
+ Field field =
PersistentSubscription.class.getDeclaredField("pendingAckHandle");
+ field.setAccessible(true);
Review Comment:
I don't think it can be done with spy. This test is reflected three times to
get the required private variables. The first two private variables are final
and have no set method.
--
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]