rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ding...@apache.org
Subject [rocketmq-client-cpp] branch master updated: unit-test-protocol-2 (#113)
Date Thu, 04 Apr 2019 07:07:44 GMT
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-client-cpp.git


The following commit(s) were added to refs/heads/master by this push:
     new b371731  unit-test-protocol-2 (#113)
b371731 is described below

commit b371731480bfa7298323227535d2706aafd4cacb
Author: githublaohu <2372554140@qq.com>
AuthorDate: Thu Apr 4 15:07:40 2019 +0800

    unit-test-protocol-2 (#113)
---
 src/protocol/KVTable.h                             |  19 ++--
 .../KVTable.h => test/src/protocol/KVTableTest.cpp |  44 +++++----
 test/src/protocol/LockBatchBodyTest.cpp            | 103 +++++++++++++++++++++
 test/src/protocol/MessageQueueTest.cpp             |  89 ++++++++++++++++++
 4 files changed, 230 insertions(+), 25 deletions(-)

diff --git a/src/protocol/KVTable.h b/src/protocol/KVTable.h
index 69191b7..6cc557f 100755
--- a/src/protocol/KVTable.h
+++ b/src/protocol/KVTable.h
@@ -21,21 +21,24 @@
 #include <string>
 #include "RemotingSerializable.h"
 
+using std::map;
+using std::string;
+
 namespace rocketmq {
 //<!***************************************************************************
 class KVTable : public RemotingSerializable {
- public:
-  virtual ~KVTable() { m_table.clear(); }
+   public:
+    virtual ~KVTable() { m_table.clear(); }
 
-  void Encode(string& outData) {}
+    void Encode(string &outData) {}
 
-  const map<string, string>& getTable() { return m_table; }
+    const map<string, string> &getTable() { return m_table; }
 
-  void setTable(const map<string, string>& table) { m_table = table; }
+    void setTable(const map<string, string> &table) { m_table = table; }
 
- private:
-  map<string, string> m_table;
+   private:
+    map<string, string> m_table;
 };
-}  //<!end namespace;
+}  // namespace rocketmq
 
 #endif
diff --git a/src/protocol/KVTable.h b/test/src/protocol/KVTableTest.cpp
old mode 100755
new mode 100644
similarity index 56%
copy from src/protocol/KVTable.h
copy to test/src/protocol/KVTableTest.cpp
index 69191b7..312d35c
--- a/src/protocol/KVTable.h
+++ b/test/src/protocol/KVTableTest.cpp
@@ -14,28 +14,38 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#ifndef __KVTABLE_H__
-#define __KVTABLE_H__
 #include <map>
 #include <string>
-#include "RemotingSerializable.h"
 
-namespace rocketmq {
-//<!***************************************************************************
-class KVTable : public RemotingSerializable {
- public:
-  virtual ~KVTable() { m_table.clear(); }
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "KVTable.h"
+
+using std::map;
+using std::string;
+
+using ::testing::InitGoogleMock;
+using ::testing::InitGoogleTest;
+using testing::Return;
 
-  void Encode(string& outData) {}
+using rocketmq::KVTable;
 
-  const map<string, string>& getTable() { return m_table; }
+TEST(KVTable, init) {
+    KVTable table;
 
-  void setTable(const map<string, string>& table) { m_table = table; }
+    EXPECT_EQ(table.getTable().size(), 0);
 
- private:
-  map<string, string> m_table;
-};
-}  //<!end namespace;
+    map<string, string> maps;
+    maps["string"] = "string";
+    table.setTable(maps);
+    EXPECT_EQ(table.getTable().size(), 1);
+}
 
-#endif
+int main(int argc, char *argv[]) {
+    InitGoogleMock(&argc, argv);
+    testing::GTEST_FLAG(throw_on_failure) = true;
+    testing::GTEST_FLAG(filter) = "KVTable.*";
+    int itestts = RUN_ALL_TESTS();
+    return itestts;
+}
diff --git a/test/src/protocol/LockBatchBodyTest.cpp b/test/src/protocol/LockBatchBodyTest.cpp
new file mode 100644
index 0000000..fec3b27
--- /dev/null
+++ b/test/src/protocol/LockBatchBodyTest.cpp
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vector"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "LockBatchBody.h"
+#include "MQMessageQueue.h"
+#include "dataBlock.h"
+
+using std::vector;
+
+using ::testing::InitGoogleMock;
+using ::testing::InitGoogleTest;
+using testing::Return;
+
+using rocketmq::LockBatchRequestBody;
+using rocketmq::LockBatchResponseBody;
+using rocketmq::MemoryBlock;
+using rocketmq::MQMessageQueue;
+using rocketmq::UnlockBatchRequestBody;
+
+TEST(lockBatchBody, LockBatchRequestBody) {
+    LockBatchRequestBody lockBatchRequestBody;
+
+    lockBatchRequestBody.setClientId("testClientId");
+    EXPECT_EQ(lockBatchRequestBody.getClientId(), "testClientId");
+
+    lockBatchRequestBody.setConsumerGroup("testGroup");
+    EXPECT_EQ(lockBatchRequestBody.getConsumerGroup(), "testGroup");
+
+    vector<MQMessageQueue> vectorMessageQueue;
+    vectorMessageQueue.push_back(MQMessageQueue());
+    vectorMessageQueue.push_back(MQMessageQueue());
+
+    lockBatchRequestBody.setMqSet(vectorMessageQueue);
+    EXPECT_EQ(lockBatchRequestBody.getMqSet(), vectorMessageQueue);
+
+    Json::Value outJson = lockBatchRequestBody.toJson(MQMessageQueue("topicTest", "testBroker",
10));
+    EXPECT_EQ(outJson["topic"], "topicTest");
+    EXPECT_EQ(outJson["brokerName"], "testBroker");
+    EXPECT_EQ(outJson["queueId"], 10);
+
+    string outData;
+    lockBatchRequestBody.Encode(outData);
+
+    Json::Value root;
+    Json::Reader reader;
+    reader.parse(outData, root);
+    EXPECT_EQ(root["clientId"], "testClientId");
+    EXPECT_EQ(root["consumerGroup"], "testGroup");
+}
+
+TEST(lockBatchBody, UnlockBatchRequestBody) {}
+
+TEST(lockBatchBody, LockBatchResponseBody) {
+    Json::Value root;
+    Json::Value mqs;
+
+    Json::Value mq;
+    mq["topic"] = "testTopic";
+    mq["brokerName"] = "testBroker";
+    mq["queueId"] = 1;
+    mqs[0] = mq;
+    root["lockOKMQSet"] = mqs;
+
+    Json::FastWriter fastwrite;
+    string outData = fastwrite.write(root);
+
+    MemoryBlock *mem = new MemoryBlock(outData.c_str(), outData.size());
+
+    LockBatchResponseBody lockBatchResponseBody;
+
+    vector<MQMessageQueue> messageQueues;
+    LockBatchResponseBody::Decode(mem, messageQueues);
+
+    MQMessageQueue messageQueue("testTopic", "testBroker", 1);
+    EXPECT_EQ(messageQueue, messageQueues[0]);
+}
+
+int main(int argc, char *argv[]) {
+    InitGoogleMock(&argc, argv);
+    testing::GTEST_FLAG(throw_on_failure) = true;
+    testing::GTEST_FLAG(filter) = "lockBatchBody.*";
+    int itestts = RUN_ALL_TESTS();
+    return itestts;
+}
diff --git a/test/src/protocol/MessageQueueTest.cpp b/test/src/protocol/MessageQueueTest.cpp
new file mode 100644
index 0000000..68d137e
--- /dev/null
+++ b/test/src/protocol/MessageQueueTest.cpp
@@ -0,0 +1,89 @@
+/*"
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "MessageQueue.h"
+
+using ::testing::InitGoogleMock;
+using ::testing::InitGoogleTest;
+using testing::Return;
+
+using rocketmq::MessageQueue;
+
+TEST(messageExt, init) {
+    MessageQueue messageQueue;
+    EXPECT_EQ(messageQueue.getQueueId(), -1);
+
+    MessageQueue twoMessageQueue("testTopic", "testBroker", 1);
+    EXPECT_EQ(twoMessageQueue.getQueueId(), 1);
+    EXPECT_EQ(twoMessageQueue.getTopic(), "testTopic");
+    EXPECT_EQ(twoMessageQueue.getBrokerName(), "testBroker");
+
+    MessageQueue threeMessageQueue(twoMessageQueue);
+    EXPECT_EQ(threeMessageQueue.getQueueId(), 1);
+    EXPECT_EQ(threeMessageQueue.getTopic(), "testTopic");
+    EXPECT_EQ(threeMessageQueue.getBrokerName(), "testBroker");
+
+    Json::Value outJson = twoMessageQueue.toJson();
+    EXPECT_EQ(outJson["queueId"], 1);
+    EXPECT_EQ(outJson["topic"], "testTopic");
+    EXPECT_EQ(outJson["brokerName"], "testBroker");
+
+    MessageQueue fiveMessageQueue = threeMessageQueue;
+    EXPECT_EQ(fiveMessageQueue.getQueueId(), 1);
+    EXPECT_EQ(fiveMessageQueue.getTopic(), "testTopic");
+    EXPECT_EQ(fiveMessageQueue.getBrokerName(), "testBroker");
+}
+
+TEST(messageExt, info) {
+    MessageQueue messageQueue;
+
+    messageQueue.setQueueId(11);
+    EXPECT_EQ(messageQueue.getQueueId(), 11);
+
+    messageQueue.setTopic("testTopic");
+    EXPECT_EQ(messageQueue.getTopic(), "testTopic");
+
+    messageQueue.setBrokerName("testBroker");
+    EXPECT_EQ(messageQueue.getBrokerName(), "testBroker");
+}
+
+TEST(messageExt, operators) {
+    MessageQueue messageQueue;
+    EXPECT_TRUE(messageQueue == messageQueue);
+
+    MessageQueue twoMessageQueue;
+    EXPECT_TRUE(messageQueue == twoMessageQueue);
+
+    twoMessageQueue.setTopic("testTopic");
+    EXPECT_FALSE(messageQueue == twoMessageQueue);
+
+    messageQueue.setQueueId(11);
+    EXPECT_FALSE(messageQueue == twoMessageQueue);
+
+    messageQueue.setBrokerName("testBroker");
+    EXPECT_FALSE(messageQueue == twoMessageQueue);
+}
+
+int main(int argc, char *argv[]) {
+    InitGoogleMock(&argc, argv);
+    testing::GTEST_FLAG(throw_on_failure) = true;
+    testing::GTEST_FLAG(filter) = "messageExt.*";
+    int itestts = RUN_ALL_TESTS();
+    return itestts;
+}


Mime
View raw message