提交 d7c866ee 编写于 作者: M Minghao Li

enh(sync): add test

上级 54dfc8cd
...@@ -680,7 +680,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg); ...@@ -680,7 +680,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
// --------------------------------------------- // ---------------------------------------------
typedef enum { typedef enum {
SYNC_STEP_DOWN = 0, SYNC_LOCAL_CMD_STEP_DOWN = 100,
} ESyncLocalCmd; } ESyncLocalCmd;
typedef struct SyncLocalCmd { typedef struct SyncLocalCmd {
...@@ -695,7 +695,7 @@ typedef struct SyncLocalCmd { ...@@ -695,7 +695,7 @@ typedef struct SyncLocalCmd {
} SyncLocalCmd; } SyncLocalCmd;
SyncLocalCmd* syncLocalCmdBuild(uint32_t dataLen, int32_t vgId); SyncLocalCmd* syncLocalCmdBuild(int32_t vgId);
void syncLocalCmdDestroy(SyncLocalCmd* pMsg); void syncLocalCmdDestroy(SyncLocalCmd* pMsg);
void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen); void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen);
void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg); void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg);
......
...@@ -3097,7 +3097,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) { ...@@ -3097,7 +3097,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
} }
// --------------------------------------------- // ---------------------------------------------
SyncLocalCmd* syncLocalCmdBuild(uint32_t dataLen, int32_t vgId) { SyncLocalCmd* syncLocalCmdBuild(int32_t vgId) {
uint32_t bytes = sizeof(SyncLocalCmd); uint32_t bytes = sizeof(SyncLocalCmd);
SyncLocalCmd* pMsg = taosMemoryMalloc(bytes); SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
memset(pMsg, 0, bytes); memset(pMsg, 0, bytes);
...@@ -3206,7 +3206,7 @@ cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) { ...@@ -3206,7 +3206,7 @@ cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
} }
cJSON* pJson = cJSON_CreateObject(); cJSON* pJson = cJSON_CreateObject();
cJSON_AddItemToObject(pJson, "SyncSnapshotRsp", pRoot); cJSON_AddItemToObject(pJson, "SyncLocalCmd2Json", pRoot);
return pJson; return pJson;
} }
......
...@@ -14,78 +14,78 @@ void logTest() { ...@@ -14,78 +14,78 @@ void logTest() {
sFatal("--- sync log test: fatal"); sFatal("--- sync log test: fatal");
} }
SyncAppendEntries *createMsg() { SyncLocalCmd *createMsg() {
SyncAppendEntries *pMsg = syncAppendEntriesBuild(20, 1000); SyncLocalCmd *pMsg = syncLocalCmdBuild(1000);
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234); pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
pMsg->srcId.vgId = 100; pMsg->srcId.vgId = 100;
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
pMsg->destId.vgId = 100; pMsg->destId.vgId = 100;
pMsg->prevLogIndex = 11; pMsg->sdNewTerm = 123;
pMsg->prevLogTerm = 22; pMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
pMsg->commitIndex = 33;
pMsg->privateTerm = 44;
strcpy(pMsg->data, "hello world");
return pMsg; return pMsg;
} }
void test1() { void test1() {
SyncAppendEntries *pMsg = createMsg(); SyncLocalCmd *pMsg = createMsg();
syncAppendEntriesLog2((char *)"test1:", pMsg); syncLocalCmdLog2((char *)"test1:", pMsg);
syncAppendEntriesDestroy(pMsg); syncLocalCmdDestroy(pMsg);
} }
void test2() { void test2() {
SyncAppendEntries *pMsg = createMsg(); SyncLocalCmd *pMsg = createMsg();
uint32_t len = pMsg->bytes; uint32_t len = pMsg->bytes;
char *serialized = (char *)taosMemoryMalloc(len); char *serialized = (char *)taosMemoryMalloc(len);
syncAppendEntriesSerialize(pMsg, serialized, len); syncLocalCmdSerialize(pMsg, serialized, len);
SyncAppendEntries *pMsg2 = syncAppendEntriesBuild(pMsg->dataLen, 1000); SyncLocalCmd *pMsg2 = syncLocalCmdBuild(1000);
syncAppendEntriesDeserialize(serialized, len, pMsg2); syncLocalCmdDeserialize(serialized, len, pMsg2);
syncAppendEntriesLog2((char *)"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize ", pMsg2); syncLocalCmdLog2((char *)"test2: syncLocalCmdSerialize -> syncLocalCmdDeserialize ", pMsg2);
taosMemoryFree(serialized); taosMemoryFree(serialized);
syncAppendEntriesDestroy(pMsg); syncLocalCmdDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2); syncLocalCmdDestroy(pMsg2);
} }
void test3() { void test3() {
SyncAppendEntries *pMsg = createMsg(); SyncLocalCmd *pMsg = createMsg();
uint32_t len; uint32_t len;
char *serialized = syncAppendEntriesSerialize2(pMsg, &len); char *serialized = syncLocalCmdSerialize2(pMsg, &len);
SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len); SyncLocalCmd *pMsg2 = syncLocalCmdDeserialize2(serialized, len);
syncAppendEntriesLog2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2); syncLocalCmdLog2((char *)"test3: syncLocalCmdSerialize3 -> syncLocalCmdDeserialize2 ", pMsg2);
taosMemoryFree(serialized); taosMemoryFree(serialized);
syncAppendEntriesDestroy(pMsg); syncLocalCmdDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2); syncLocalCmdDestroy(pMsg2);
} }
void test4() { void test4() {
SyncAppendEntries *pMsg = createMsg(); SyncLocalCmd *pMsg = createMsg();
SRpcMsg rpcMsg; SRpcMsg rpcMsg;
syncAppendEntries2RpcMsg(pMsg, &rpcMsg); syncLocalCmd2RpcMsg(pMsg, &rpcMsg);
SyncAppendEntries *pMsg2 = (SyncAppendEntries *)taosMemoryMalloc(rpcMsg.contLen); SyncLocalCmd *pMsg2 = (SyncLocalCmd *)taosMemoryMalloc(rpcMsg.contLen);
syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2); syncLocalCmdFromRpcMsg(&rpcMsg, pMsg2);
syncAppendEntriesLog2((char *)"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg ", pMsg2); syncLocalCmdLog2((char *)"test4: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg ", pMsg2);
rpcFreeCont(rpcMsg.pCont); rpcFreeCont(rpcMsg.pCont);
syncAppendEntriesDestroy(pMsg); syncLocalCmdDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2); syncLocalCmdDestroy(pMsg2);
} }
void test5() { void test5() {
SyncAppendEntries *pMsg = createMsg(); SyncLocalCmd *pMsg = createMsg();
SRpcMsg rpcMsg; SRpcMsg rpcMsg;
syncAppendEntries2RpcMsg(pMsg, &rpcMsg); syncLocalCmd2RpcMsg(pMsg, &rpcMsg);
SyncAppendEntries *pMsg2 = syncAppendEntriesFromRpcMsg2(&rpcMsg); SyncLocalCmd *pMsg2 = syncLocalCmdFromRpcMsg2(&rpcMsg);
syncAppendEntriesLog2((char *)"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 ", pMsg2); syncLocalCmdLog2((char *)"test5: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg2 ", pMsg2);
rpcFreeCont(rpcMsg.pCont); rpcFreeCont(rpcMsg.pCont);
syncAppendEntriesDestroy(pMsg); syncLocalCmdDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2); syncLocalCmdDestroy(pMsg2);
} }
int main() { int main() {
gRaftDetailLog = true;
tsAsyncLog = 0; tsAsyncLog = 0;
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
logTest(); logTest();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册