TDengine/source/libs/sync/test/syncRequestVoteReplyTest.cpp

98 lines
2.9 KiB
C++
Raw Normal View History

2022-03-11 03:47:56 +00:00
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.h"
void logTest() {
sTrace("--- sync log test: trace");
sDebug("--- sync log test: debug");
sInfo("--- sync log test: info");
sWarn("--- sync log test: warn");
sError("--- sync log test: error");
sFatal("--- sync log test: fatal");
}
SyncRequestVoteReply *createMsg() {
2022-04-18 13:50:56 +00:00
SyncRequestVoteReply *pMsg = syncRequestVoteReplyBuild(1000);
2022-03-11 03:47:56 +00:00
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
pMsg->srcId.vgId = 100;
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
pMsg->destId.vgId = 100;
pMsg->term = 77;
pMsg->voteGranted = true;
2022-03-11 11:52:59 +00:00
return pMsg;
2022-03-11 03:47:56 +00:00
}
void test1() {
SyncRequestVoteReply *pMsg = createMsg();
2022-04-18 13:50:56 +00:00
syncRequestVoteReplyLog2((char *)"test1:", pMsg);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyDestroy(pMsg);
}
void test2() {
SyncRequestVoteReply *pMsg = createMsg();
2022-03-11 07:05:10 +00:00
uint32_t len = pMsg->bytes;
2022-10-13 06:06:27 +00:00
char *serialized = (char *)taosMemoryMalloc(len);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplySerialize(pMsg, serialized, len);
2022-04-18 13:50:56 +00:00
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild(1000);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyDeserialize(serialized, len, pMsg2);
2022-04-18 13:50:56 +00:00
syncRequestVoteReplyLog2((char *)"test2: syncRequestVoteReplySerialize -> syncRequestVoteReplyDeserialize ", pMsg2);
2022-03-11 03:47:56 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyDestroy(pMsg);
syncRequestVoteReplyDestroy(pMsg2);
}
void test3() {
SyncRequestVoteReply *pMsg = createMsg();
2022-03-11 07:05:10 +00:00
uint32_t len;
2022-10-13 06:06:27 +00:00
char *serialized = syncRequestVoteReplySerialize2(pMsg, &len);
2022-03-11 03:47:56 +00:00
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyDeserialize2(serialized, len);
2022-04-18 13:50:56 +00:00
syncRequestVoteReplyLog2((char *)"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 ", pMsg2);
2022-03-11 03:47:56 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyDestroy(pMsg);
syncRequestVoteReplyDestroy(pMsg2);
}
void test4() {
SyncRequestVoteReply *pMsg = createMsg();
2022-03-11 07:05:10 +00:00
SRpcMsg rpcMsg;
2022-03-11 03:47:56 +00:00
syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
2022-04-18 13:50:56 +00:00
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild(1000);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyFromRpcMsg(&rpcMsg, pMsg2);
2022-04-18 13:50:56 +00:00
syncRequestVoteReplyLog2((char *)"test4: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg ", pMsg2);
2022-03-11 03:47:56 +00:00
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyDestroy(pMsg);
syncRequestVoteReplyDestroy(pMsg2);
}
void test5() {
SyncRequestVoteReply *pMsg = createMsg();
2022-03-11 07:05:10 +00:00
SRpcMsg rpcMsg;
2022-03-11 03:47:56 +00:00
syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyFromRpcMsg2(&rpcMsg);
2022-04-18 13:50:56 +00:00
syncRequestVoteReplyLog2((char *)"test5: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg2 ", pMsg2);
2022-03-11 03:47:56 +00:00
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
2022-03-11 03:47:56 +00:00
syncRequestVoteReplyDestroy(pMsg);
syncRequestVoteReplyDestroy(pMsg2);
}
int main() {
tsAsyncLog = 0;
2022-04-18 13:50:56 +00:00
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
2022-03-11 03:47:56 +00:00
logTest();
test1();
test2();
test3();
test4();
test5();
return 0;
}