first commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include "BatchMessage.h"
|
||||
#include "MQMessage.h"
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
using namespace rocketmq;
|
||||
using ::testing::InitGoogleTest;
|
||||
using ::testing::InitGoogleMock;
|
||||
using testing::Return;
|
||||
|
||||
TEST(BatchMessageEncodeTest, encodeMQMessage) {
|
||||
MQMessage msg1("topic", "*", "test");
|
||||
// const map<string,string>& properties = msg1.getProperties();
|
||||
// for (auto& pair : properties) {
|
||||
// std::cout << pair.first << " : " << pair.second << std::endl;
|
||||
//}
|
||||
|
||||
EXPECT_EQ(msg1.getProperties().size(), 2);
|
||||
EXPECT_EQ(msg1.getBody().size(), 4);
|
||||
// 20 + bodyLen + 2 + propertiesLength;
|
||||
string encodeMessage = BatchMessage::encode(msg1);
|
||||
EXPECT_EQ(encodeMessage.size(), 43);
|
||||
|
||||
msg1.setProperty(MQMessage::PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, "1");
|
||||
encodeMessage = BatchMessage::encode(msg1);
|
||||
EXPECT_EQ(encodeMessage.size(), 54);
|
||||
}
|
||||
|
||||
TEST(BatchMessageEncodeTest, encodeMQMessages) {
|
||||
std::vector<MQMessage> msgs;
|
||||
MQMessage msg1("topic", "*", "test1");
|
||||
// const map<string,string>& properties = msg1.getProperties();
|
||||
// for (auto& pair : properties) {
|
||||
// std::cout << pair.first << " : " << pair.second << std::endl;
|
||||
//}
|
||||
msgs.push_back(msg1);
|
||||
// 20 + bodyLen + 2 + propertiesLength;
|
||||
string encodeMessage = BatchMessage::encode(msgs);
|
||||
EXPECT_EQ(encodeMessage.size(), 86);
|
||||
MQMessage msg2("topic", "*", "test2");
|
||||
MQMessage msg3("topic", "*", "test3");
|
||||
msgs.push_back(msg2);
|
||||
msgs.push_back(msg3);
|
||||
encodeMessage = BatchMessage::encode(msgs);
|
||||
EXPECT_EQ(encodeMessage.size(), 258); // 86*3
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
InitGoogleMock(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
205
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQDecoderTest.cpp
vendored
Normal file
205
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQDecoderTest.cpp
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "MemoryInputStream.h"
|
||||
#include "MemoryOutputStream.h"
|
||||
|
||||
#include "CommandHeader.h"
|
||||
#include "MQDecoder.h"
|
||||
#include "MQMessage.h"
|
||||
#include "MQMessageExt.h"
|
||||
#include "MQMessageId.h"
|
||||
#include "MessageSysFlag.h"
|
||||
#include "RemotingCommand.h"
|
||||
#include "UtilAll.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using ::testing::InitGoogleMock;
|
||||
using ::testing::InitGoogleTest;
|
||||
using testing::Return;
|
||||
|
||||
using rocketmq::MemoryBlock;
|
||||
using rocketmq::MemoryInputStream;
|
||||
using rocketmq::MemoryOutputStream;
|
||||
using rocketmq::MessageSysFlag;
|
||||
using rocketmq::MQDecoder;
|
||||
using rocketmq::MQMessage;
|
||||
using rocketmq::MQMessageExt;
|
||||
using rocketmq::MQMessageId;
|
||||
using rocketmq::RemotingCommand;
|
||||
using rocketmq::SendMessageRequestHeader;
|
||||
using rocketmq::UtilAll;
|
||||
|
||||
// TODO
|
||||
TEST(decoder, messageId) {
|
||||
int host;
|
||||
int port;
|
||||
int64 offset = 1234567890;
|
||||
string msgIdStr =
|
||||
MQDecoder::createMessageId(rocketmq::IPPort2socketAddress(ntohl(inet_addr("127.0.0.1")), 10091), offset);
|
||||
MQMessageId msgId = MQDecoder::decodeMessageId(msgIdStr);
|
||||
|
||||
EXPECT_EQ(msgId.getOffset(), offset);
|
||||
|
||||
rocketmq::socketAddress2IPPort(msgId.getAddress(), host, port);
|
||||
EXPECT_EQ(host, ntohl(inet_addr("127.0.0.1")));
|
||||
EXPECT_EQ(port, 10091);
|
||||
}
|
||||
|
||||
TEST(decoder, decoder) {
|
||||
MQMessageExt mext;
|
||||
MemoryOutputStream* memoryOut = new MemoryOutputStream(1024);
|
||||
|
||||
// 1 TOTALSIZE 4
|
||||
memoryOut->writeIntBigEndian(107);
|
||||
mext.setStoreSize(107);
|
||||
|
||||
// 2 MAGICCODE sizeof(int) 8=4+4
|
||||
memoryOut->writeIntBigEndian(14);
|
||||
|
||||
// 3 BODYCRC 12=8+4
|
||||
memoryOut->writeIntBigEndian(24);
|
||||
mext.setBodyCRC(24);
|
||||
// 4 QUEUEID 16=12+4
|
||||
memoryOut->writeIntBigEndian(4);
|
||||
mext.setQueueId(4);
|
||||
// 5 FLAG 20=16+4
|
||||
memoryOut->writeIntBigEndian(4);
|
||||
mext.setFlag(4);
|
||||
// 6 QUEUEOFFSET 28 = 20+8
|
||||
memoryOut->writeInt64BigEndian((int64)1024);
|
||||
mext.setQueueOffset(1024);
|
||||
// 7 PHYSICALOFFSET 36=28+8
|
||||
memoryOut->writeInt64BigEndian((int64)2048);
|
||||
mext.setCommitLogOffset(2048);
|
||||
// 8 SYSFLAG 40=36+4
|
||||
memoryOut->writeIntBigEndian(0);
|
||||
mext.setSysFlag(0);
|
||||
// 9 BORNTIMESTAMP 48 = 40+8
|
||||
memoryOut->writeInt64BigEndian((int64)4096);
|
||||
mext.setBornTimestamp(4096);
|
||||
// 10 BORNHOST 56= 48+8
|
||||
memoryOut->writeIntBigEndian(ntohl(inet_addr("127.0.0.1")));
|
||||
memoryOut->writeIntBigEndian(10091);
|
||||
mext.setBornHost(rocketmq::IPPort2socketAddress(ntohl(inet_addr("127.0.0.1")), 10091));
|
||||
// 11 STORETIMESTAMP 64 =56+8
|
||||
memoryOut->writeInt64BigEndian((int64)4096);
|
||||
mext.setStoreTimestamp(4096);
|
||||
// 12 STOREHOST 72 = 64+8
|
||||
memoryOut->writeIntBigEndian(ntohl(inet_addr("127.0.0.2")));
|
||||
memoryOut->writeIntBigEndian(10092);
|
||||
mext.setStoreHost(rocketmq::IPPort2socketAddress(ntohl(inet_addr("127.0.0.2")), 10092));
|
||||
// 13 RECONSUMETIMES 76 = 72+4
|
||||
mext.setReconsumeTimes(111111);
|
||||
memoryOut->writeIntBigEndian(mext.getReconsumeTimes());
|
||||
// 14 Prepared Transaction Offset 84 = 76+8
|
||||
memoryOut->writeInt64BigEndian((int64)12);
|
||||
mext.setPreparedTransactionOffset(12);
|
||||
// 15 BODY 88 = 84+4 10
|
||||
string* body = new string("1234567890");
|
||||
mext.setBody(body->c_str());
|
||||
memoryOut->writeIntBigEndian(10);
|
||||
memoryOut->write(body->c_str(), body->size());
|
||||
|
||||
// 16 TOPIC
|
||||
memoryOut->writeByte(10);
|
||||
memoryOut->write(body->c_str(), body->size());
|
||||
mext.setTopic(body->c_str());
|
||||
|
||||
// 17 PROPERTIES
|
||||
memoryOut->writeShortBigEndian(0);
|
||||
|
||||
mext.setMsgId(MQDecoder::createMessageId(mext.getStoreHost(), (int64)mext.getCommitLogOffset()));
|
||||
|
||||
vector<MQMessageExt> mqvec;
|
||||
MemoryBlock block = memoryOut->getMemoryBlock();
|
||||
MQDecoder::decodes(&block, mqvec);
|
||||
EXPECT_EQ(mqvec.size(), 1);
|
||||
std::cout << mext.toString() << "\n";
|
||||
std::cout << mqvec[0].toString() << "\n";
|
||||
EXPECT_EQ(mqvec[0].toString(), mext.toString());
|
||||
|
||||
mqvec.clear();
|
||||
MQDecoder::decodes(&block, mqvec, false);
|
||||
EXPECT_FALSE(mqvec[0].getBody().size());
|
||||
|
||||
//===============================================================
|
||||
// 8 SYSFLAG 40=36+4
|
||||
mext.setSysFlag(0 | MessageSysFlag::CompressedFlag);
|
||||
memoryOut->setPosition(36);
|
||||
memoryOut->writeIntBigEndian(mext.getSysFlag());
|
||||
|
||||
// 15 Body 84
|
||||
string outBody;
|
||||
string boody("123123123");
|
||||
UtilAll::deflate(boody, outBody, 5);
|
||||
mext.setBody(outBody);
|
||||
|
||||
memoryOut->setPosition(84);
|
||||
memoryOut->writeIntBigEndian(outBody.size());
|
||||
memoryOut->write(outBody.c_str(), outBody.size());
|
||||
|
||||
// 16 TOPIC
|
||||
memoryOut->writeByte(10);
|
||||
memoryOut->write(body->c_str(), body->size());
|
||||
mext.setTopic(body->c_str());
|
||||
|
||||
// 17 PROPERTIES
|
||||
map<string, string> properties;
|
||||
properties["RocketMQ"] = "cpp-client";
|
||||
properties[MQMessage::PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX] = "123456";
|
||||
mext.setProperties(properties);
|
||||
mext.setMsgId("123456");
|
||||
|
||||
string proString = MQDecoder::messageProperties2String(properties);
|
||||
|
||||
memoryOut->writeShortBigEndian(proString.size());
|
||||
memoryOut->write(proString.c_str(), proString.size());
|
||||
|
||||
mext.setStoreSize(memoryOut->getDataSize());
|
||||
memoryOut->setPosition(0);
|
||||
memoryOut->writeIntBigEndian(mext.getStoreSize());
|
||||
|
||||
block = memoryOut->getMemoryBlock();
|
||||
MQDecoder::decodes(&block, mqvec);
|
||||
EXPECT_EQ(mqvec[0].toString(), mext.toString());
|
||||
}
|
||||
|
||||
TEST(decoder, messagePropertiesAndToString) {
|
||||
map<string, string> properties;
|
||||
properties["RocketMQ"] = "cpp-client";
|
||||
string proString = MQDecoder::messageProperties2String(properties);
|
||||
|
||||
map<string, string> newProperties;
|
||||
MQDecoder::string2messageProperties(proString, newProperties);
|
||||
EXPECT_EQ(properties, newProperties);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
InitGoogleMock(&argc, argv);
|
||||
|
||||
testing::GTEST_FLAG(filter) = "decoder.*";
|
||||
int itestts = RUN_ALL_TESTS();
|
||||
return itestts;
|
||||
}
|
||||
138
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQMessageExtTest.cpp
vendored
Normal file
138
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQMessageExtTest.cpp
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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 "MQMessageExt.h"
|
||||
#include "MessageSysFlag.h"
|
||||
#include "SocketUtil.h"
|
||||
#include "TopicFilterType.h"
|
||||
|
||||
using ::testing::InitGoogleMock;
|
||||
using ::testing::InitGoogleTest;
|
||||
using testing::Return;
|
||||
|
||||
using rocketmq::MessageSysFlag;
|
||||
using rocketmq::MQMessageExt;
|
||||
using rocketmq::TopicFilterType;
|
||||
|
||||
TEST(messageExt, init) {
|
||||
MQMessageExt messageExt;
|
||||
EXPECT_EQ(messageExt.getQueueOffset(), 0);
|
||||
EXPECT_EQ(messageExt.getCommitLogOffset(), 0);
|
||||
EXPECT_EQ(messageExt.getBornTimestamp(), 0);
|
||||
EXPECT_EQ(messageExt.getStoreTimestamp(), 0);
|
||||
EXPECT_EQ(messageExt.getPreparedTransactionOffset(), 0);
|
||||
EXPECT_EQ(messageExt.getQueueId(), 0);
|
||||
EXPECT_EQ(messageExt.getStoreSize(), 0);
|
||||
EXPECT_EQ(messageExt.getReconsumeTimes(), 3);
|
||||
EXPECT_EQ(messageExt.getBodyCRC(), 0);
|
||||
EXPECT_EQ(messageExt.getMsgId(), "");
|
||||
EXPECT_EQ(messageExt.getOffsetMsgId(), "");
|
||||
|
||||
messageExt.setQueueOffset(1);
|
||||
EXPECT_EQ(messageExt.getQueueOffset(), 1);
|
||||
|
||||
messageExt.setCommitLogOffset(1024);
|
||||
EXPECT_EQ(messageExt.getCommitLogOffset(), 1024);
|
||||
|
||||
messageExt.setBornTimestamp(1024);
|
||||
EXPECT_EQ(messageExt.getBornTimestamp(), 1024);
|
||||
|
||||
messageExt.setStoreTimestamp(2048);
|
||||
EXPECT_EQ(messageExt.getStoreTimestamp(), 2048);
|
||||
|
||||
messageExt.setPreparedTransactionOffset(4096);
|
||||
EXPECT_EQ(messageExt.getPreparedTransactionOffset(), 4096);
|
||||
|
||||
messageExt.setQueueId(2);
|
||||
EXPECT_EQ(messageExt.getQueueId(), 2);
|
||||
|
||||
messageExt.setStoreSize(12);
|
||||
EXPECT_EQ(messageExt.getStoreSize(), 12);
|
||||
|
||||
messageExt.setReconsumeTimes(48);
|
||||
EXPECT_EQ(messageExt.getReconsumeTimes(), 48);
|
||||
|
||||
messageExt.setBodyCRC(32);
|
||||
EXPECT_EQ(messageExt.getBodyCRC(), 32);
|
||||
|
||||
messageExt.setMsgId("MsgId");
|
||||
EXPECT_EQ(messageExt.getMsgId(), "MsgId");
|
||||
|
||||
messageExt.setOffsetMsgId("offsetMsgId");
|
||||
EXPECT_EQ(messageExt.getOffsetMsgId(), "offsetMsgId");
|
||||
|
||||
messageExt.setBornTimestamp(1111);
|
||||
EXPECT_EQ(messageExt.getBornTimestamp(), 1111);
|
||||
|
||||
messageExt.setStoreTimestamp(2222);
|
||||
EXPECT_EQ(messageExt.getStoreTimestamp(), 2222);
|
||||
|
||||
struct sockaddr_in sa;
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons(10091);
|
||||
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
|
||||
sockaddr bornHost;
|
||||
memcpy(&bornHost, &sa, sizeof(sockaddr));
|
||||
|
||||
messageExt.setBornHost(bornHost);
|
||||
EXPECT_EQ(messageExt.getBornHostNameString(), rocketmq::getHostName(bornHost));
|
||||
EXPECT_EQ(messageExt.getBornHostString(), rocketmq::socketAddress2String(bornHost));
|
||||
|
||||
struct sockaddr_in storeSa;
|
||||
storeSa.sin_family = AF_INET;
|
||||
storeSa.sin_port = htons(10092);
|
||||
storeSa.sin_addr.s_addr = inet_addr("127.0.0.2");
|
||||
|
||||
sockaddr storeHost;
|
||||
memcpy(&storeHost, &storeSa, sizeof(sockaddr));
|
||||
messageExt.setStoreHost(storeHost);
|
||||
EXPECT_EQ(messageExt.getStoreHostString(), rocketmq::socketAddress2String(storeHost));
|
||||
|
||||
MQMessageExt twoMessageExt(2, 1024, bornHost, 2048, storeHost, "msgId");
|
||||
EXPECT_EQ(twoMessageExt.getQueueOffset(), 0);
|
||||
EXPECT_EQ(twoMessageExt.getCommitLogOffset(), 0);
|
||||
EXPECT_EQ(twoMessageExt.getBornTimestamp(), 1024);
|
||||
EXPECT_EQ(twoMessageExt.getStoreTimestamp(), 2048);
|
||||
EXPECT_EQ(twoMessageExt.getPreparedTransactionOffset(), 0);
|
||||
EXPECT_EQ(twoMessageExt.getQueueId(), 2);
|
||||
EXPECT_EQ(twoMessageExt.getStoreSize(), 0);
|
||||
EXPECT_EQ(twoMessageExt.getReconsumeTimes(), 3);
|
||||
EXPECT_EQ(twoMessageExt.getBodyCRC(), 0);
|
||||
EXPECT_EQ(twoMessageExt.getMsgId(), "msgId");
|
||||
EXPECT_EQ(twoMessageExt.getOffsetMsgId(), "");
|
||||
|
||||
EXPECT_EQ(twoMessageExt.getBornHostNameString(), rocketmq::getHostName(bornHost));
|
||||
EXPECT_EQ(twoMessageExt.getBornHostString(), rocketmq::socketAddress2String(bornHost));
|
||||
|
||||
EXPECT_EQ(twoMessageExt.getStoreHostString(), rocketmq::socketAddress2String(storeHost));
|
||||
|
||||
EXPECT_EQ(MQMessageExt::parseTopicFilterType(MessageSysFlag::MultiTagsFlag), TopicFilterType::MULTI_TAG);
|
||||
|
||||
EXPECT_EQ(MQMessageExt::parseTopicFilterType(0), TopicFilterType::SINGLE_TAG);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
InitGoogleMock(&argc, argv);
|
||||
|
||||
testing::GTEST_FLAG(filter) = "messageExt.*";
|
||||
int itestts = RUN_ALL_TESTS();
|
||||
return itestts;
|
||||
}
|
||||
59
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQMessageIdTest.cpp
vendored
Normal file
59
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQMessageIdTest.cpp
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
|
||||
#include "MQMessageId.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace std;
|
||||
using ::testing::InitGoogleMock;
|
||||
using ::testing::InitGoogleTest;
|
||||
using testing::Return;
|
||||
|
||||
using rocketmq::MQMessageId;
|
||||
|
||||
TEST(messageId, id) {
|
||||
int host;
|
||||
int port;
|
||||
sockaddr addr = rocketmq::IPPort2socketAddress(inet_addr("127.0.0.1"), 10091);
|
||||
MQMessageId id(addr, 1024);
|
||||
|
||||
rocketmq::socketAddress2IPPort(id.getAddress(), host, port);
|
||||
EXPECT_EQ(host, inet_addr("127.0.0.1"));
|
||||
EXPECT_EQ(port, 10091);
|
||||
EXPECT_EQ(id.getOffset(), 1024);
|
||||
|
||||
id.setAddress(rocketmq::IPPort2socketAddress(inet_addr("127.0.0.2"), 10092));
|
||||
id.setOffset(2048);
|
||||
|
||||
rocketmq::socketAddress2IPPort(id.getAddress(), host, port);
|
||||
EXPECT_EQ(host, inet_addr("127.0.0.2"));
|
||||
EXPECT_EQ(port, 10092);
|
||||
EXPECT_EQ(id.getOffset(), 2048);
|
||||
|
||||
MQMessageId id2 = id;
|
||||
EXPECT_EQ(id2.getOffset(), 2048);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
InitGoogleMock(&argc, argv);
|
||||
|
||||
testing::GTEST_FLAG(filter) = "messageId.*";
|
||||
int itestts = RUN_ALL_TESTS();
|
||||
return itestts;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 "MQMessageQueue.h"
|
||||
|
||||
using ::testing::InitGoogleMock;
|
||||
using ::testing::InitGoogleTest;
|
||||
using testing::Return;
|
||||
|
||||
using rocketmq::MQMessageQueue;
|
||||
|
||||
TEST(messageQueue, init) {
|
||||
MQMessageQueue messageQueue;
|
||||
EXPECT_EQ(messageQueue.getBrokerName(), "");
|
||||
EXPECT_EQ(messageQueue.getTopic(), "");
|
||||
EXPECT_EQ(messageQueue.getQueueId(), -1);
|
||||
|
||||
MQMessageQueue twoMessageQueue("testTopic", "testBroker", 1);
|
||||
EXPECT_EQ(twoMessageQueue.getBrokerName(), "testBroker");
|
||||
EXPECT_EQ(twoMessageQueue.getTopic(), "testTopic");
|
||||
EXPECT_EQ(twoMessageQueue.getQueueId(), 1);
|
||||
|
||||
MQMessageQueue threeMessageQueue("threeTestTopic", "threeTestBroker", 2);
|
||||
MQMessageQueue frouMessageQueue(threeMessageQueue);
|
||||
EXPECT_EQ(frouMessageQueue.getBrokerName(), "threeTestBroker");
|
||||
EXPECT_EQ(frouMessageQueue.getTopic(), "threeTestTopic");
|
||||
EXPECT_EQ(frouMessageQueue.getQueueId(), 2);
|
||||
|
||||
frouMessageQueue = twoMessageQueue;
|
||||
EXPECT_EQ(frouMessageQueue.getBrokerName(), "testBroker");
|
||||
EXPECT_EQ(frouMessageQueue.getTopic(), "testTopic");
|
||||
EXPECT_EQ(frouMessageQueue.getQueueId(), 1);
|
||||
|
||||
frouMessageQueue.setBrokerName("frouTestBroker");
|
||||
frouMessageQueue.setTopic("frouTestTopic");
|
||||
frouMessageQueue.setQueueId(4);
|
||||
EXPECT_EQ(frouMessageQueue.getBrokerName(), "frouTestBroker");
|
||||
EXPECT_EQ(frouMessageQueue.getTopic(), "frouTestTopic");
|
||||
EXPECT_EQ(frouMessageQueue.getQueueId(), 4);
|
||||
}
|
||||
|
||||
TEST(messageQueue, operators) {
|
||||
MQMessageQueue messageQueue;
|
||||
EXPECT_EQ(messageQueue, messageQueue);
|
||||
EXPECT_EQ(messageQueue.compareTo(messageQueue), 0);
|
||||
|
||||
MQMessageQueue twoMessageQueue;
|
||||
EXPECT_EQ(messageQueue, twoMessageQueue);
|
||||
EXPECT_EQ(messageQueue.compareTo(twoMessageQueue), 0);
|
||||
|
||||
twoMessageQueue.setTopic("testTopic");
|
||||
EXPECT_FALSE(messageQueue == twoMessageQueue);
|
||||
EXPECT_FALSE(messageQueue.compareTo(twoMessageQueue) == 0);
|
||||
|
||||
twoMessageQueue.setQueueId(1);
|
||||
EXPECT_FALSE(messageQueue == twoMessageQueue);
|
||||
EXPECT_FALSE(messageQueue.compareTo(twoMessageQueue) == 0);
|
||||
|
||||
twoMessageQueue.setBrokerName("testBroker");
|
||||
EXPECT_FALSE(messageQueue == twoMessageQueue);
|
||||
EXPECT_FALSE(messageQueue.compareTo(twoMessageQueue) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
InitGoogleMock(&argc, argv);
|
||||
|
||||
testing::GTEST_FLAG(filter) = "messageQueue.*";
|
||||
int itestts = RUN_ALL_TESTS();
|
||||
return itestts;
|
||||
}
|
||||
170
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQMessageTest.cpp
vendored
Normal file
170
source/third_party/rocketmq-client-cpp-2.2.0-source-release/test/src/message/MQMessageTest.cpp
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "MQMessage.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using ::testing::InitGoogleMock;
|
||||
using ::testing::InitGoogleTest;
|
||||
using testing::Return;
|
||||
|
||||
using rocketmq::MQMessage;
|
||||
|
||||
TEST(message, Init) {
|
||||
MQMessage messageOne;
|
||||
EXPECT_EQ(messageOne.getTopic(), "");
|
||||
EXPECT_EQ(messageOne.getBody(), "");
|
||||
EXPECT_EQ(messageOne.getTags(), "");
|
||||
EXPECT_EQ(messageOne.getFlag(), 0);
|
||||
|
||||
MQMessage messageTwo("test", "testBody");
|
||||
EXPECT_EQ(messageTwo.getTopic(), "test");
|
||||
EXPECT_EQ(messageTwo.getBody(), "testBody");
|
||||
EXPECT_EQ(messageTwo.getTags(), "");
|
||||
EXPECT_EQ(messageTwo.getFlag(), 0);
|
||||
|
||||
MQMessage messageThree("test", "tagTest", "testBody");
|
||||
EXPECT_EQ(messageThree.getTopic(), "test");
|
||||
EXPECT_EQ(messageThree.getBody(), "testBody");
|
||||
EXPECT_EQ(messageThree.getTags(), "tagTest");
|
||||
EXPECT_EQ(messageThree.getFlag(), 0);
|
||||
|
||||
MQMessage messageFour("test", "tagTest", "testKey", "testBody");
|
||||
EXPECT_EQ(messageFour.getTopic(), "test");
|
||||
EXPECT_EQ(messageFour.getBody(), "testBody");
|
||||
EXPECT_EQ(messageFour.getTags(), "tagTest");
|
||||
EXPECT_EQ(messageFour.getKeys(), "testKey");
|
||||
EXPECT_EQ(messageFour.getFlag(), 0);
|
||||
|
||||
MQMessage messageFive("test", "tagTest", "testKey", 1, "testBody", 2);
|
||||
EXPECT_EQ(messageFive.getTopic(), "test");
|
||||
EXPECT_EQ(messageFive.getBody(), "testBody");
|
||||
EXPECT_EQ(messageFive.getTags(), "tagTest");
|
||||
EXPECT_EQ(messageFive.getKeys(), "testKey");
|
||||
EXPECT_EQ(messageFive.getFlag(), 1);
|
||||
|
||||
MQMessage messageSix(messageFive);
|
||||
EXPECT_EQ(messageSix.getTopic(), "test");
|
||||
EXPECT_EQ(messageSix.getBody(), "testBody");
|
||||
EXPECT_EQ(messageSix.getTags(), "tagTest");
|
||||
EXPECT_EQ(messageSix.getKeys(), "testKey");
|
||||
EXPECT_EQ(messageSix.getFlag(), 1);
|
||||
|
||||
MQMessage messageSeven = messageSix;
|
||||
EXPECT_EQ(messageSeven.getTopic(), "test");
|
||||
EXPECT_EQ(messageSeven.getBody(), "testBody");
|
||||
EXPECT_EQ(messageSeven.getTags(), "tagTest");
|
||||
EXPECT_EQ(messageSeven.getKeys(), "testKey");
|
||||
EXPECT_EQ(messageSeven.getFlag(), 1);
|
||||
}
|
||||
|
||||
TEST(message, info) {
|
||||
MQMessage message;
|
||||
|
||||
EXPECT_EQ(message.getTopic(), "");
|
||||
message.setTopic("testTopic");
|
||||
EXPECT_EQ(message.getTopic(), "testTopic");
|
||||
string topic = "testTopic";
|
||||
const char* ctopic = topic.c_str();
|
||||
message.setTopic(ctopic, 5);
|
||||
EXPECT_EQ(message.getTopic(), "testT");
|
||||
|
||||
EXPECT_EQ(message.getBody(), "");
|
||||
message.setBody("testBody");
|
||||
EXPECT_EQ(message.getBody(), "testBody");
|
||||
|
||||
string body = "testBody";
|
||||
const char* b = body.c_str();
|
||||
message.setBody(b, 5);
|
||||
EXPECT_EQ(message.getBody(), "testB");
|
||||
|
||||
string tags(message.getTags());
|
||||
EXPECT_EQ(tags, "");
|
||||
EXPECT_EQ(message.getFlag(), 0);
|
||||
message.setFlag(2);
|
||||
EXPECT_EQ(message.getFlag(), 2);
|
||||
|
||||
EXPECT_EQ(message.isWaitStoreMsgOK(), true);
|
||||
message.setWaitStoreMsgOK(false);
|
||||
EXPECT_EQ(message.isWaitStoreMsgOK(), false);
|
||||
message.setWaitStoreMsgOK(true);
|
||||
EXPECT_EQ(message.isWaitStoreMsgOK(), true);
|
||||
|
||||
string keys(message.getTags());
|
||||
EXPECT_EQ(keys, "");
|
||||
message.setKeys("testKeys");
|
||||
EXPECT_EQ(message.getKeys(), "testKeys");
|
||||
|
||||
EXPECT_EQ(message.getDelayTimeLevel(), 0);
|
||||
message.setDelayTimeLevel(1);
|
||||
EXPECT_EQ(message.getDelayTimeLevel(), 1);
|
||||
|
||||
message.setSysFlag(1);
|
||||
EXPECT_EQ(message.getSysFlag(), 1);
|
||||
}
|
||||
|
||||
TEST(message, properties) {
|
||||
MQMessage message;
|
||||
EXPECT_EQ(message.getProperties().size(), 1);
|
||||
EXPECT_STREQ(message.getProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED).c_str(), "");
|
||||
|
||||
message.setProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED, "true");
|
||||
EXPECT_EQ(message.getProperties().size(), 2);
|
||||
EXPECT_EQ(message.getSysFlag(), 4);
|
||||
EXPECT_EQ(message.getProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED), "true");
|
||||
|
||||
message.setProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED, "false");
|
||||
EXPECT_EQ(message.getProperties().size(), 2);
|
||||
EXPECT_EQ(message.getSysFlag(), 0);
|
||||
EXPECT_EQ(message.getProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED), "false");
|
||||
|
||||
map<string, string> newProperties;
|
||||
|
||||
newProperties[MQMessage::PROPERTY_TRANSACTION_PREPARED] = "true";
|
||||
message.setProperties(newProperties);
|
||||
EXPECT_EQ(message.getSysFlag(), 4);
|
||||
EXPECT_EQ(message.getProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED), "true");
|
||||
|
||||
newProperties[MQMessage::PROPERTY_TRANSACTION_PREPARED] = "false";
|
||||
message.setProperties(newProperties);
|
||||
EXPECT_EQ(message.getSysFlag(), 0);
|
||||
EXPECT_EQ(message.getProperty(MQMessage::PROPERTY_TRANSACTION_PREPARED), "false");
|
||||
}
|
||||
|
||||
TEST(message, Keys) {
|
||||
MQMessage message;
|
||||
vector<string> keys;
|
||||
keys.push_back("abc");
|
||||
keys.push_back("efg");
|
||||
keys.push_back("hij");
|
||||
message.setKeys(keys);
|
||||
EXPECT_EQ(message.getKeys(), "abc efg hij");
|
||||
}
|
||||
int main(int argc, char* argv[]) {
|
||||
InitGoogleMock(&argc, argv);
|
||||
|
||||
// testing::GTEST_FLAG(filter) = "message.info";
|
||||
int itestts = RUN_ALL_TESTS();
|
||||
return itestts;
|
||||
}
|
||||
Reference in New Issue
Block a user