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

115 lines
2.8 KiB
C++
Raw Normal View History

2022-03-11 09:08:27 +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");
}
int gg = 0;
SyncTimeout *createMsg() {
2022-04-18 13:50:56 +00:00
SyncTimeout *pMsg = syncTimeoutBuild2(SYNC_TIMEOUT_PING, 999, 333, 1000, &gg);
2022-03-11 09:08:27 +00:00
return pMsg;
}
void test1() {
SyncTimeout *pMsg = createMsg();
2022-04-18 13:50:56 +00:00
syncTimeoutLog2((char *)"test1:", pMsg);
2022-03-11 09:08:27 +00:00
syncTimeoutDestroy(pMsg);
}
void test2() {
SyncTimeout *pMsg = createMsg();
2022-03-11 11:11:38 +00:00
uint32_t len = pMsg->bytes;
2022-03-25 16:29:53 +00:00
char * serialized = (char *)taosMemoryMalloc(len);
2022-03-11 09:08:27 +00:00
syncTimeoutSerialize(pMsg, serialized, len);
SyncTimeout *pMsg2 = syncTimeoutBuild();
syncTimeoutDeserialize(serialized, len, pMsg2);
2022-04-18 13:50:56 +00:00
syncTimeoutLog2((char *)"test2: syncTimeoutSerialize -> syncTimeoutDeserialize ", pMsg2);
2022-03-11 09:08:27 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 09:08:27 +00:00
syncTimeoutDestroy(pMsg);
syncTimeoutDestroy(pMsg2);
}
void test3() {
SyncTimeout *pMsg = createMsg();
2022-03-11 11:11:38 +00:00
uint32_t len;
char * serialized = syncTimeoutSerialize2(pMsg, &len);
2022-03-11 09:08:27 +00:00
SyncTimeout *pMsg2 = syncTimeoutDeserialize2(serialized, len);
2022-04-18 13:50:56 +00:00
syncTimeoutLog2((char *)"test3: syncTimeoutSerialize3 -> syncTimeoutDeserialize2 ", pMsg2);
2022-03-11 09:08:27 +00:00
2022-03-25 16:29:53 +00:00
taosMemoryFree(serialized);
2022-03-11 09:08:27 +00:00
syncTimeoutDestroy(pMsg);
syncTimeoutDestroy(pMsg2);
}
void test4() {
SyncTimeout *pMsg = createMsg();
2022-03-11 11:11:38 +00:00
SRpcMsg rpcMsg;
2022-03-11 09:08:27 +00:00
syncTimeout2RpcMsg(pMsg, &rpcMsg);
2022-03-25 16:29:53 +00:00
SyncTimeout *pMsg2 = (SyncTimeout *)taosMemoryMalloc(rpcMsg.contLen);
2022-03-11 09:08:27 +00:00
syncTimeoutFromRpcMsg(&rpcMsg, pMsg2);
2022-04-18 13:50:56 +00:00
syncTimeoutLog2((char *)"test4: syncTimeout2RpcMsg -> syncTimeoutFromRpcMsg ", pMsg2);
2022-03-11 09:08:27 +00:00
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
2022-03-11 09:08:27 +00:00
syncTimeoutDestroy(pMsg);
syncTimeoutDestroy(pMsg2);
}
void test5() {
SyncTimeout *pMsg = createMsg();
2022-03-11 11:11:38 +00:00
SRpcMsg rpcMsg;
2022-03-11 09:08:27 +00:00
syncTimeout2RpcMsg(pMsg, &rpcMsg);
SyncTimeout *pMsg2 = syncTimeoutFromRpcMsg2(&rpcMsg);
2022-04-18 13:50:56 +00:00
syncTimeoutLog2((char *)"test5: syncTimeout2RpcMsg -> syncTimeoutFromRpcMsg2 ", pMsg2);
2022-03-11 09:08:27 +00:00
2022-04-18 13:50:56 +00:00
rpcFreeCont(rpcMsg.pCont);
2022-03-11 09:08:27 +00:00
syncTimeoutDestroy(pMsg);
syncTimeoutDestroy(pMsg2);
}
2022-06-08 03:25:24 +00:00
void test6() {
SyncTimeout *pMsg = createMsg();
2022-06-08 08:45:40 +00:00
char * jsonStr = syncTimeout2Str(pMsg);
2022-06-08 03:25:24 +00:00
sTrace("jsonStr: %s", jsonStr);
syncUtilJson2Line(jsonStr);
sTrace("jsonStr: %s", jsonStr);
char str[10];
snprintf(str, sizeof(str), "%s", "{}");
sTrace("str: %s", str);
syncUtilJson2Line(str);
sTrace("str: %s", str);
snprintf(str, sizeof(str), "%s", "");
sTrace("str: %s", str);
syncUtilJson2Line(str);
sTrace("str: %s", str);
}
2022-03-11 09:08:27 +00:00
int main() {
tsAsyncLog = 0;
2022-04-18 13:50:56 +00:00
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
2022-03-11 09:08:27 +00:00
logTest();
test1();
test2();
test3();
test4();
test5();
2022-06-08 03:25:24 +00:00
test6();
2022-03-11 09:08:27 +00:00
return 0;
}