Skip to content

Commit

Permalink
[cpp] make able to set acktimeout to 0 in consumerconfig (apache#7169)
Browse files Browse the repository at this point in the history
If user already set UnAckedMessagesTimeoutMs in consumer config, It is not able to set it back to 0. This change fix the issue.
  • Loading branch information
jiazhai authored Jun 5, 2020
1 parent 3fc969a commit a698637
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/ConsumerConfiguration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void ConsumerConfiguration::setConsumerName(const std::string& consumerName) {
long ConsumerConfiguration::getUnAckedMessagesTimeoutMs() const { return impl_->unAckedMessagesTimeoutMs; }

void ConsumerConfiguration::setUnAckedMessagesTimeoutMs(const uint64_t milliSeconds) {
if (milliSeconds < 10000) {
if (milliSeconds < 10000 && milliSeconds != 0) {
throw "Consumer Config Exception: Unacknowledged message timeout should be greater than 10 seconds.";
}
impl_->unAckedMessagesTimeoutMs = milliSeconds;
Expand Down
13 changes: 13 additions & 0 deletions pulsar-client-cpp/tests/ConsumerConfigurationTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ TEST(ConsumerConfigurationTest, testSubscriptionInitialPosition) {
ASSERT_EQ(ResultOk, producer.close());
ASSERT_EQ(ResultOk, client.close());
}

TEST(ConsumerConfigurationTest, testResetAckTimeOut) {
Result result;

uint64_t milliSeconds = 50000;
ConsumerConfiguration config;
config.setUnAckedMessagesTimeoutMs(milliSeconds);
ASSERT_EQ(milliSeconds, config.getUnAckedMessagesTimeoutMs());

// should be able to set it back to 0.
config.setUnAckedMessagesTimeoutMs(0);
ASSERT_EQ(0, config.getUnAckedMessagesTimeoutMs());
}

0 comments on commit a698637

Please sign in to comment.