enh(sync): add test
This commit is contained in:
parent
54dfc8cd52
commit
d7c866ee12
|
@ -680,7 +680,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
|
|||
|
||||
// ---------------------------------------------
|
||||
typedef enum {
|
||||
SYNC_STEP_DOWN = 0,
|
||||
SYNC_LOCAL_CMD_STEP_DOWN = 100,
|
||||
} ESyncLocalCmd;
|
||||
|
||||
typedef struct SyncLocalCmd {
|
||||
|
@ -695,7 +695,7 @@ typedef struct SyncLocalCmd {
|
|||
|
||||
} SyncLocalCmd;
|
||||
|
||||
SyncLocalCmd* syncLocalCmdBuild(uint32_t dataLen, int32_t vgId);
|
||||
SyncLocalCmd* syncLocalCmdBuild(int32_t vgId);
|
||||
void syncLocalCmdDestroy(SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* 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);
|
||||
SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
|
@ -3206,7 +3206,7 @@ cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
|
|||
}
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SyncSnapshotRsp", pRoot);
|
||||
cJSON_AddItemToObject(pJson, "SyncLocalCmd2Json", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,78 +14,78 @@ void logTest() {
|
|||
sFatal("--- sync log test: fatal");
|
||||
}
|
||||
|
||||
SyncAppendEntries *createMsg() {
|
||||
SyncAppendEntries *pMsg = syncAppendEntriesBuild(20, 1000);
|
||||
SyncLocalCmd *createMsg() {
|
||||
SyncLocalCmd *pMsg = syncLocalCmdBuild(1000);
|
||||
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->prevLogIndex = 11;
|
||||
pMsg->prevLogTerm = 22;
|
||||
pMsg->commitIndex = 33;
|
||||
pMsg->privateTerm = 44;
|
||||
strcpy(pMsg->data, "hello world");
|
||||
pMsg->sdNewTerm = 123;
|
||||
pMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
syncAppendEntriesLog2((char *)"test1:", pMsg);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
syncLocalCmdLog2((char *)"test1:", pMsg);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char *serialized = (char *)taosMemoryMalloc(len);
|
||||
syncAppendEntriesSerialize(pMsg, serialized, len);
|
||||
SyncAppendEntries *pMsg2 = syncAppendEntriesBuild(pMsg->dataLen, 1000);
|
||||
syncAppendEntriesDeserialize(serialized, len, pMsg2);
|
||||
syncAppendEntriesLog2((char *)"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize ", pMsg2);
|
||||
syncLocalCmdSerialize(pMsg, serialized, len);
|
||||
SyncLocalCmd *pMsg2 = syncLocalCmdBuild(1000);
|
||||
syncLocalCmdDeserialize(serialized, len, pMsg2);
|
||||
syncLocalCmdLog2((char *)"test2: syncLocalCmdSerialize -> syncLocalCmdDeserialize ", pMsg2);
|
||||
|
||||
taosMemoryFree(serialized);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char *serialized = syncAppendEntriesSerialize2(pMsg, &len);
|
||||
SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len);
|
||||
syncAppendEntriesLog2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2);
|
||||
char *serialized = syncLocalCmdSerialize2(pMsg, &len);
|
||||
SyncLocalCmd *pMsg2 = syncLocalCmdDeserialize2(serialized, len);
|
||||
syncLocalCmdLog2((char *)"test3: syncLocalCmdSerialize3 -> syncLocalCmdDeserialize2 ", pMsg2);
|
||||
|
||||
taosMemoryFree(serialized);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntries *pMsg2 = (SyncAppendEntries *)taosMemoryMalloc(rpcMsg.contLen);
|
||||
syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncAppendEntriesLog2((char *)"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg ", pMsg2);
|
||||
syncLocalCmd2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncLocalCmd *pMsg2 = (SyncLocalCmd *)taosMemoryMalloc(rpcMsg.contLen);
|
||||
syncLocalCmdFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncLocalCmdLog2((char *)"test4: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg ", pMsg2);
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntries *pMsg2 = syncAppendEntriesFromRpcMsg2(&rpcMsg);
|
||||
syncAppendEntriesLog2((char *)"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 ", pMsg2);
|
||||
syncLocalCmd2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncLocalCmd *pMsg2 = syncLocalCmdFromRpcMsg2(&rpcMsg);
|
||||
syncLocalCmdLog2((char *)"test5: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg2 ", pMsg2);
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
gRaftDetailLog = true;
|
||||
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
||||
logTest();
|
||||
|
|
Loading…
Reference in New Issue