Skip to content

Commit

Permalink
Fix apache#657: Use exceptions instead of assert() to do runtime para…
Browse files Browse the repository at this point in the history
…meter validations (apache#673)
  • Loading branch information
merlimat authored Aug 11, 2017
1 parent b037a7a commit c51eaad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pulsar-client-cpp/lib/ProducerConfiguration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ CompressionType ProducerConfiguration::getCompressionType() const {
}

ProducerConfiguration& ProducerConfiguration::setMaxPendingMessages(int maxPendingMessages) {
assert(maxPendingMessages > 0);
if (maxPendingMessages <= 0) {
throw "maxPendingMessages needs to be greater than 0";
}
impl_->maxPendingMessages = maxPendingMessages;
return *this;
}
Expand Down Expand Up @@ -104,7 +106,9 @@ const bool& ProducerConfiguration::getBatchingEnabled() const {

ProducerConfiguration& ProducerConfiguration::setBatchingMaxMessages(
const unsigned int& batchingMaxMessages) {
assert(batchingMaxMessages > 1);
if (batchingMaxMessages <= 1) {
throw "batchingMaxMessages needs to be greater than 1";
}
impl_->batchingMaxMessages = batchingMaxMessages;
return *this;
}
Expand Down
9 changes: 7 additions & 2 deletions pulsar-client-cpp/tests/BatchMessageTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ static void sendCallBackExpectingErrors(Result r, const Message& msg) {

TEST(BatchMessageTest, testProducerConfig) {
ProducerConfiguration conf;
ASSERT_DEATH(conf.setBatchingMaxMessages(1), "");
try {
conf.setBatchingMaxMessages(1);
FAIL();
} catch (const char* ex) {
// Ok
}
}

TEST(BatchMessageTest, testProducerTimeout) {
Expand Down Expand Up @@ -301,7 +306,7 @@ TEST(BatchMessageTest, testSmallReceiverQueueSize) {
LOG_DEBUG("Received Message with [ content - " << receivedMsg.getDataAsString() << "] [ messageID = " << receivedMsg.getMessageId() << "]");
ASSERT_EQ(receivedMsg.getProperty("msgIndex"), boost::lexical_cast<std::string>(i));
ASSERT_EQ(expectedMessageContent, receivedMsg.getDataAsString());
ASSERT_EQ(ResultOk, consumer.acknowledge(receivedMsg));
ASSERT_EQ(ResultOk, consumer.acknowledge(receivedMsg));
}

ConsumerStatsImplPtr consumerStatsImplPtr = PulsarFriend::getConsumerStatsPtr(consumer);
Expand Down

0 comments on commit c51eaad

Please sign in to comment.