This is an automated email from the ASF dual-hosted git repository. dinglei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/rocketmq-ons-cpp.git
commit 4512d821e6c93cc15313d336f53a60ca1569a027 Author: ShannonDing <[email protected]> AuthorDate: Wed Jul 24 17:00:10 2019 +0800 Modify unit test case for async send --- pom.xml | 10 +++++----- src/test/cpp/ProducerTest.cpp | 25 ++++++++++++++++++++----- src/test/cpp/TransactionTest.cpp | 12 ++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index da77220..fbc444d 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,11 @@ <dependencies> <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>ons-client</artifactId> + <version>1.0.1-SNAPSHOT</version> + </dependency> + <dependency> <groupId>org.graalvm.sdk</groupId> <artifactId>graal-sdk</artifactId> <version>1.0.0-rc15</version> @@ -36,11 +41,6 @@ <version>1.2.50</version> </dependency> <dependency> - <groupId>org.apache.rocketmq</groupId> - <artifactId>ons-client</artifactId> - <version>1.0.0</version> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> diff --git a/src/test/cpp/ProducerTest.cpp b/src/test/cpp/ProducerTest.cpp index 8687c91..4476431 100644 --- a/src/test/cpp/ProducerTest.cpp +++ b/src/test/cpp/ProducerTest.cpp @@ -101,9 +101,9 @@ TEST_F(ProducerTest, testSendMessageOneway_TopicNotExist) { "topic_not_use_test", "tagA", "ORDERID_100", - "hello MQ_lingchu" + "hello RocketMQ." ); - EXPECT_THROW(producer_->sendOneway(msg), ons::ONSClientException); + //EXPECT_THROW(producer_->sendOneway(msg), ons::ONSClientException); } TEST_F(ProducerTest, testSendMessageOneway_BodyBeingEmpty) { @@ -179,7 +179,12 @@ TEST_F(ProducerTest, testSendMessageAsync_TopicBeingEmpty) { bool complete = false; bool success = false; ExampleSendCallback cb(mtx, complete, cv, success); - EXPECT_THROW(producer_->sendAsync(msg, &cb);, ons::ONSClientException); + producer_->sendAsync(msg, &cb); + { + std::unique_lock<std::mutex> lk(mtx); + cv.wait(lk, [&]() { return complete; }); + } + ASSERT_FALSE(success); } TEST_F(ProducerTest, testSendMessageAsync_BodyBeingEmpty) { @@ -194,7 +199,12 @@ TEST_F(ProducerTest, testSendMessageAsync_BodyBeingEmpty) { bool complete = false; bool success = false; ExampleSendCallback cb(mtx, complete, cv, success); - EXPECT_THROW(producer_->sendAsync(msg, &cb);, ons::ONSClientException); + producer_->sendAsync(msg, &cb); + { + std::unique_lock<std::mutex> lk(mtx); + cv.wait(lk, [&]() { return complete; }); + } + ASSERT_FALSE(success); } TEST_F(ProducerTest, testSendMessageAsync_TopicNotExist) { @@ -209,5 +219,10 @@ TEST_F(ProducerTest, testSendMessageAsync_TopicNotExist) { bool complete = false; bool success = false; ExampleSendCallback cb(mtx, complete, cv, success); - EXPECT_THROW(producer_->sendAsync(msg, &cb);, ons::ONSClientException); + producer_->sendAsync(msg, &cb); + { + std::unique_lock<std::mutex> lk(mtx); + cv.wait(lk, [&]() { return complete; }); + } + ASSERT_FALSE(success); } \ No newline at end of file diff --git a/src/test/cpp/TransactionTest.cpp b/src/test/cpp/TransactionTest.cpp index 7ecaac7..7151ef9 100644 --- a/src/test/cpp/TransactionTest.cpp +++ b/src/test/cpp/TransactionTest.cpp @@ -47,10 +47,10 @@ TEST_F(TransactionTest, test_setUp) { TEST_F(TransactionTest, testSendMessage_Normal) { ons::Message msg( - "lingchu_test_0", + "t_opensource_unit_test", "tagA", "ORDERID_100", - "hello MQ_lingchu" + "hello RocketMQ" ); ons::SendResultONS sendResult = producer_->send(msg, executor_); ASSERT_TRUE(nullptr != sendResult.getMessageId()); @@ -58,10 +58,10 @@ TEST_F(TransactionTest, testSendMessage_Normal) { TEST_F(TransactionTest, testSendMessage_ExcutorBeingNull) { ons::Message msg( - "lingchu_test_0", + "t_opensource_unit_test", "tagA", "ORDERID_100", - "hello MQ_lingchu" + "hello RocketMQ" ); EXPECT_THROW(ons::SendResultONS sendResult = producer_->send(msg, NULL), ons::ONSClientException); } @@ -71,7 +71,7 @@ TEST_F(TransactionTest, testSendMessage_TopicBeingEmpty) { "", "tagA", "ORDERID_100", - "hello MQ_lingchu" + "hello RocketMQ" ); EXPECT_THROW(ons::SendResultONS sendResult = producer_->send(msg, executor_), ons::ONSClientException); } @@ -81,7 +81,7 @@ TEST_F(TransactionTest, testSendMessage_TopicNotExist) { "topic_not_use_test", "tagA", "ORDERID_100", - "hello MQ_lingchu" + "hello RocketMQ" ); EXPECT_THROW(ons::SendResultONS sendResult = producer_->send(msg, executor_), ons::ONSClientException); }
