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

108 lines
2.7 KiB
C++
Raw Normal View History

2022-03-09 10:33:41 +00:00
#include <gtest/gtest.h>
2022-11-10 04:43:23 +00:00
#include "syncTest.h"
2022-02-26 18:24:50 +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");
}
2022-03-11 11:11:38 +00:00
SyncPing *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
SyncPing *pMsg = syncPingBuild3(&srcId, &destId, 1000);
2022-03-11 11:11:38 +00:00
return pMsg;
}
2022-02-27 02:22:15 +00:00
2022-03-11 11:11:38 +00:00
void test1() {
SyncPing *pMsg = createMsg();
2022-04-18 13:50:56 +00:00
syncPingLog2((char *)"test1:", pMsg);
2022-03-11 11:11:38 +00:00
syncPingDestroy(pMsg);
}
2022-02-26 18:24:50 +00:00
2022-03-11 11:11:38 +00:00
void test2() {
SyncPing *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
syncPingSerialize(pMsg, serialized, len);
SyncPing *pMsg2 = syncPingBuild(pMsg->dataLen);
syncPingDeserialize(serialized, len, pMsg2);
2022-04-18 13:50:56 +00:00
syncPingLog2((char *)"test2: syncPingSerialize -> syncPingDeserialize ", 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
syncPingDestroy(pMsg);
syncPingDestroy(pMsg2);
}
2022-02-26 18:24:50 +00:00
2022-03-11 11:11:38 +00:00
void test3() {
SyncPing *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
uint32_t len;
2022-10-13 06:06:27 +00:00
char *serialized = syncPingSerialize2(pMsg, &len);
2022-03-11 11:11:38 +00:00
SyncPing *pMsg2 = syncPingDeserialize2(serialized, len);
2022-04-18 13:50:56 +00:00
syncPingLog2((char *)"test3: syncPingSerialize2 -> syncPingDeserialize2 ", pMsg2);
2022-02-26 18:24:50 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 11:11:38 +00:00
syncPingDestroy(pMsg);
syncPingDestroy(pMsg2);
}
2022-02-27 02:22:15 +00:00
2022-03-11 11:11:38 +00:00
void test4() {
SyncPing *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
SRpcMsg rpcMsg;
2022-03-11 11:11:38 +00:00
syncPing2RpcMsg(pMsg, &rpcMsg);
2022-03-25 16:29:53 +00:00
SyncPing *pMsg2 = (SyncPing *)taosMemoryMalloc(rpcMsg.contLen);
2022-03-11 11:11:38 +00:00
syncPingFromRpcMsg(&rpcMsg, pMsg2);
2022-04-18 13:50:56 +00:00
syncPingLog2((char *)"test4: syncPing2RpcMsg -> syncPingFromRpcMsg ", pMsg2);
2022-02-28 06:10:34 +00:00
2022-03-11 11:11:38 +00:00
syncPingDestroy(pMsg);
syncPingDestroy(pMsg2);
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
2022-02-28 06:10:34 +00:00
}
2022-03-11 11:11:38 +00:00
void test5() {
SyncPing *pMsg = createMsg();
2022-03-11 11:52:59 +00:00
SRpcMsg rpcMsg;
2022-03-11 11:11:38 +00:00
syncPing2RpcMsg(pMsg, &rpcMsg);
SyncPing *pMsg2 = syncPingFromRpcMsg2(&rpcMsg);
2022-04-18 13:50:56 +00:00
syncPingLog2((char *)"test5: syncPing2RpcMsg -> syncPingFromRpcMsg2 ", pMsg2);
2022-03-09 10:33:41 +00:00
2022-03-11 11:11:38 +00:00
syncPingDestroy(pMsg);
syncPingDestroy(pMsg2);
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
}
void test6() {
SyncPing *pMsg = createMsg();
int32_t bufLen = syncPingSerialize3(pMsg, NULL, 0);
2022-10-13 06:06:27 +00:00
char *serialized = (char *)taosMemoryMalloc(bufLen);
2022-04-18 13:50:56 +00:00
syncPingSerialize3(pMsg, serialized, bufLen);
SyncPing *pMsg2 = syncPingDeserialize3(serialized, bufLen);
assert(pMsg2 != NULL);
syncPingLog2((char *)"test6: syncPingSerialize3 -> syncPingDeserialize3 ", pMsg2);
taosMemoryFree(serialized);
syncPingDestroy(pMsg);
syncPingDestroy(pMsg2);
2022-02-26 18:24:50 +00:00
}
2022-03-11 11:11:38 +00:00
int main() {
2022-02-26 18:24:50 +00:00
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();
2022-02-26 18:24:50 +00:00
2022-03-11 11:11:38 +00:00
test1();
test2();
test3();
test4();
test5();
2022-04-18 13:50:56 +00:00
test6();
2022-02-26 18:24:50 +00:00
return 0;
}