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

108 lines
3.1 KiB
C++
Raw Normal View History

2022-03-11 11:11:38 +00:00
#include <gtest/gtest.h>
2022-11-10 04:43:23 +00:00
#include "syncTest.h"
2022-03-11 11:11:38 +00:00
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");
}
SyncPingReply *createMsg() {
SRaftId srcId, destId;
srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
srcId.vgId = 100;
destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
destId.vgId = 100;
2022-04-18 13:50:56 +00:00
SyncPingReply *pMsg = syncPingReplyBuild3(&srcId, &destId, 1000);
2022-03-11 11:11:38 +00:00
return pMsg;
}
void test1() {
SyncPingReply *pMsg = createMsg();
2022-04-18 13:50:56 +00:00
syncPingReplyLog2((char *)"test1:", pMsg);
2022-03-11 11:11:38 +00:00
syncPingReplyDestroy(pMsg);
}
void test2() {
SyncPingReply *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
uint32_t len = pMsg->bytes;
2022-10-13 06:06:27 +00:00
char *serialized = (char *)taosMemoryMalloc(len);
2022-03-11 11:11:38 +00:00
syncPingReplySerialize(pMsg, serialized, len);
SyncPingReply *pMsg2 = syncPingReplyBuild(pMsg->dataLen);
syncPingReplyDeserialize(serialized, len, pMsg2);
2022-04-18 13:50:56 +00:00
syncPingReplyLog2((char *)"test2: syncPingReplySerialize -> syncPingReplyDeserialize ", pMsg2);
2022-03-11 11:11:38 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 11:11:38 +00:00
syncPingReplyDestroy(pMsg);
syncPingReplyDestroy(pMsg2);
}
void test3() {
SyncPingReply *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
uint32_t len;
2022-10-13 06:06:27 +00:00
char *serialized = syncPingReplySerialize2(pMsg, &len);
2022-03-11 11:11:38 +00:00
SyncPingReply *pMsg2 = syncPingReplyDeserialize2(serialized, len);
2022-04-18 13:50:56 +00:00
syncPingReplyLog2((char *)"test3: syncPingReplySerialize2 -> syncPingReplyDeserialize2 ", pMsg2);
2022-03-11 11:11:38 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 11:11:38 +00:00
syncPingReplyDestroy(pMsg);
syncPingReplyDestroy(pMsg2);
}
void test4() {
SyncPingReply *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
SRpcMsg rpcMsg;
2022-03-11 11:11:38 +00:00
syncPingReply2RpcMsg(pMsg, &rpcMsg);
2022-03-25 16:29:53 +00:00
SyncPingReply *pMsg2 = (SyncPingReply *)taosMemoryMalloc(rpcMsg.contLen);
2022-03-11 11:11:38 +00:00
syncPingReplyFromRpcMsg(&rpcMsg, pMsg2);
2022-04-18 13:50:56 +00:00
syncPingReplyLog2((char *)"test4: syncPingReply2RpcMsg -> syncPingReplyFromRpcMsg ", pMsg2);
2022-03-11 11:11:38 +00:00
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
2022-03-11 11:11:38 +00:00
syncPingReplyDestroy(pMsg);
syncPingReplyDestroy(pMsg2);
}
void test5() {
SyncPingReply *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
SRpcMsg rpcMsg;
2022-03-11 11:11:38 +00:00
syncPingReply2RpcMsg(pMsg, &rpcMsg);
SyncPingReply *pMsg2 = syncPingReplyFromRpcMsg2(&rpcMsg);
2022-04-18 13:50:56 +00:00
syncPingReplyLog2((char *)"test5: syncPingReply2RpcMsg -> syncPingReplyFromRpcMsg2 ", pMsg2);
2022-03-11 11:11:38 +00:00
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
syncPingReplyDestroy(pMsg);
syncPingReplyDestroy(pMsg2);
}
void test6() {
SyncPingReply *pMsg = createMsg();
int32_t bufLen = syncPingReplySerialize3(pMsg, NULL, 0);
2022-10-13 06:06:27 +00:00
char *serialized = (char *)taosMemoryMalloc(bufLen);
2022-04-18 13:50:56 +00:00
syncPingReplySerialize3(pMsg, serialized, bufLen);
SyncPingReply *pMsg2 = syncPingReplyDeserialize3(serialized, bufLen);
TD_ALWAYS_ASSERT(pMsg2 != NULL);
2022-04-18 13:50:56 +00:00
syncPingReplyLog2((char *)"test6: syncPingReplySerialize3 -> syncPingReplyDeserialize3 ", pMsg2);
taosMemoryFree(serialized);
2022-03-11 11:11:38 +00:00
syncPingReplyDestroy(pMsg);
syncPingReplyDestroy(pMsg2);
}
int main() {
tsAsyncLog = 0;
2022-04-18 13:50:56 +00:00
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
2022-03-11 11:11:38 +00:00
logTest();
test1();
test2();
test3();
test4();
test5();
2022-04-18 13:50:56 +00:00
test6();
2022-03-11 11:11:38 +00:00
return 0;
}