-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: ack timeout in pulsar cpp client when subscribing to regex topic #3879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
merlimat
merged 7 commits into
apache:master
from
jerrypeng:fix_cpp_client_regex_ack_timeout
Mar 24, 2019
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a3342a2
fix bug involving ack timeout in pulsar cpp client when subscribing …
jerrypeng 4185c75
remove newline
jerrypeng c8bdcfd
fix indent
jerrypeng 4a07be3
add test
jerrypeng af5cf10
addressing comments
jerrypeng dadc4d0
fix formatting
jerrypeng dc24569
fix formatting
jerrypeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
#include <lib/PatternMultiTopicsConsumerImpl.h> | ||
#include "lib/Future.h" | ||
#include "lib/Utils.h" | ||
|
||
#include <unistd.h> | ||
#include <functional> | ||
|
||
DECLARE_LOG_OBJECT() | ||
|
@@ -2940,3 +2940,50 @@ TEST(BasicEndToEndTest, testPreventDupConsumersAllowSameSubForDifferentTopics) { | |
// consumer C should be a different instance from A and B and should be with open state. | ||
ASSERT_EQ(ResultOk, consumerC.close()); | ||
} | ||
|
||
static long regexTestMessagesReceived = 0; | ||
|
||
static void regexMessageListenerFunction(Consumer consumer, const Message &msg) { | ||
regexTestMessagesReceived++; | ||
} | ||
|
||
TEST(BasicEndToEndTest, testRegexTopicsWithMessageListener) { | ||
ClientConfiguration config; | ||
Client client(lookupUrl); | ||
long unAckedMessagesTimeoutMs = 10000; | ||
std::string subsName = "testRegexTopicsWithMessageListener-sub"; | ||
std::string pattern = | ||
"persistent://public/default/testRegexTopicsWithMessageListenerTopic-.*"; | ||
ConsumerConfiguration consumerConf; | ||
consumerConf.setConsumerType(ConsumerShared); | ||
consumerConf.setMessageListener( | ||
std::bind(regexMessageListenerFunction, std::placeholders::_1, std::placeholders::_2)); | ||
consumerConf.setUnAckedMessagesTimeoutMs(unAckedMessagesTimeoutMs); | ||
|
||
Producer producer; | ||
ProducerConfiguration producerConf; | ||
Result result = client.createProducer("persistent://public/default/testRegexTopicsWithMessageListenerTopic-1", producerConf, producer); | ||
ASSERT_EQ(ResultOk, result); | ||
|
||
Consumer consumer; | ||
result = client.subscribeWithRegex(pattern, subsName, consumerConf, consumer); | ||
ASSERT_EQ(ResultOk, result); | ||
ASSERT_EQ(consumer.getSubscriptionName(), subsName); | ||
|
||
for (int i = 0; i < 10; i++) { | ||
Message msg = MessageBuilder().setContent("test-" + std::to_string(i)).build(); | ||
producer.sendAsync(msg, nullptr); | ||
} | ||
|
||
producer.flush(); | ||
long timeWaited = 0; | ||
while(true) { | ||
// maximum wait time | ||
ASSERT_LE(timeWaited, unAckedMessagesTimeoutMs * 1000 * 3); | ||
if (regexTestMessagesReceived >= 10 * 2) { | ||
break; | ||
} | ||
usleep(500000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok will update |
||
timeWaited += 500000; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets updated from one thread and read from another. We should use
std::atomic<long>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can but does it really matter since its only one writer? Also we doing the same thing in a couple places:
https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/tests/BasicEndToEndTest.cc#L47
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the number will be correct because of the single writer, but the reader is technically not guaranteed to see the latest value. Though, yes, with sleep and retries it would settle anyway.