You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/05/29 01:29:51 UTC
[pulsar] branch master updated: Fix C++ consumer unsubscribe when
regex doesn't match (#4362)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 9ba1259 Fix C++ consumer unsubscribe when regex doesn't match (#4362)
9ba1259 is described below
commit 9ba125996f21acdd8f50a51bcd40a7a6eb0a6583
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Tue May 28 18:29:44 2019 -0700
Fix C++ consumer unsubscribe when regex doesn't match (#4362)
* Fix C++ consumer unsubscribe when regex doesn't match
* Fixed formatting
---
pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc | 6 ++++++
pulsar-client-cpp/tests/BasicEndToEndTest.cc | 18 ++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
index c5b3240..8f6da24 100644
--- a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
+++ b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
@@ -244,6 +244,12 @@ void MultiTopicsConsumerImpl::unsubscribeAsync(ResultCallback callback) {
state_ = Closing;
lock.unlock();
+ if (consumers_.empty()) {
+ // No need to unsubscribe, since the list matching the regex was empty
+ callback(ResultOk);
+ return;
+ }
+
std::shared_ptr<std::atomic<int>> consumerUnsubed = std::make_shared<std::atomic<int>>(0);
for (ConsumerMap::const_iterator consumer = consumers_.begin(); consumer != consumers_.end();
diff --git a/pulsar-client-cpp/tests/BasicEndToEndTest.cc b/pulsar-client-cpp/tests/BasicEndToEndTest.cc
index 2f82a15..e666ecd 100644
--- a/pulsar-client-cpp/tests/BasicEndToEndTest.cc
+++ b/pulsar-client-cpp/tests/BasicEndToEndTest.cc
@@ -1999,6 +1999,24 @@ TEST(BasicEndToEndTest, testpatternMultiTopicsHttpConsumerPubSub) {
client.shutdown();
}
+TEST(BasicEndToEndTest, testPatternEmptyUnsubscribe) {
+ Client client(lookupUrl);
+ std::string pattern = "persistent://public/default/patternEmptyUnsubscribe.*";
+
+ std::string subName = "testPatternMultiTopicsConsumer";
+
+ ConsumerConfiguration consConfig;
+ Consumer consumer;
+ Result result = client.subscribeWithRegex(pattern, subName, consConfig, consumer);
+ ASSERT_EQ(ResultOk, result);
+ ASSERT_EQ(consumer.getSubscriptionName(), subName);
+ LOG_INFO("created topics consumer on a pattern that match 0 topics");
+
+ ASSERT_EQ(ResultOk, consumer.unsubscribe());
+
+ client.shutdown();
+}
+
// create a pattern consumer, which contains no match topics at beginning.
// create 4 topics, in which 3 topics match the pattern.
// verify PatternMultiTopicsConsumer subscribed matched topics, after a while,