nodece commented on code in PR #22794:
URL: https://github.com/apache/pulsar/pull/22794#discussion_r1621705155
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java:
##########
@@ -1313,6 +1314,67 @@ public void
testCheckInactiveSubscriptionsShouldNotDeleteCompactionCursor() thro
}
+ @Test
+ public void testCheckInactiveSubscriptionWhenNoMessageToAck() throws
Exception {
+ String namespace = "prop/testInactiveSubscriptionWhenNoMessageToAck";
+
+ try {
+ admin.namespaces().createNamespace(namespace);
+ } catch (PulsarAdminException.ConflictException e) {
+ // Ok.. (if test fails intermittently and namespace is already
created)
+ }
+ // set enable subscription expiration.
+ admin.namespaces().setSubscriptionExpirationTime(namespace, 1);
+
+ String topic = "persistent://" + namespace + "/my-topic";
+ Producer<byte[]> producer =
pulsarClient.newProducer().topic(topic).create();
+ producer.send("test".getBytes());
+ producer.close();
+
+ // create consumer to consume all messages
+ Consumer<byte[]> consumer =
pulsarClient.newConsumer().topic(topic).subscriptionName("sub1")
+
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe();
+ consumer.acknowledge(consumer.receive());
+
+ Optional<Topic> topicOptional =
pulsar.getBrokerService().getTopic(topic, true).get();
+ assertTrue(topicOptional.isPresent());
+ PersistentTopic persistentTopic = (PersistentTopic)
topicOptional.get();
+
+ // wait for 1min, but consumer is still connected all the time.
+ // so subscription should not be deleted.
+ Thread.sleep(60000);
+ persistentTopic.checkInactiveSubscriptions();
+ assertTrue(persistentTopic.getSubscriptions().containsKey("sub1"));
+ PersistentSubscription sub = persistentTopic.getSubscription("sub1");
+
+ // shutdown pulsar ungracefully
Review Comment:
A simpler way:
1. Close the topic
2. Remove the topic from the broker cache
3. Start the consumer, and then close the consumer to load the `sub1`.
4. Check inactive subscriptions
--
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]