enh(sync): add test
This commit is contained in:
parent
8b5d005db7
commit
54dfc8cd52
|
@ -59,6 +59,7 @@ add_executable(syncRestoreFromSnapshot "")
|
||||||
add_executable(syncRaftCfgIndexTest "")
|
add_executable(syncRaftCfgIndexTest "")
|
||||||
add_executable(syncHeartbeatTest "")
|
add_executable(syncHeartbeatTest "")
|
||||||
add_executable(syncHeartbeatReplyTest "")
|
add_executable(syncHeartbeatReplyTest "")
|
||||||
|
add_executable(syncLocalCmdTest "")
|
||||||
|
|
||||||
|
|
||||||
target_sources(syncTest
|
target_sources(syncTest
|
||||||
|
@ -305,6 +306,10 @@ target_sources(syncHeartbeatReplyTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncHeartbeatReplyTest.cpp"
|
"syncHeartbeatReplyTest.cpp"
|
||||||
)
|
)
|
||||||
|
target_sources(syncLocalCmdTest
|
||||||
|
PRIVATE
|
||||||
|
"syncLocalCmdTest.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_include_directories(syncTest
|
target_include_directories(syncTest
|
||||||
|
@ -612,6 +617,11 @@ target_include_directories(syncHeartbeatReplyTest
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
|
target_include_directories(syncLocalCmdTest
|
||||||
|
PUBLIC
|
||||||
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(syncTest
|
target_link_libraries(syncTest
|
||||||
|
@ -858,6 +868,10 @@ target_link_libraries(syncHeartbeatReplyTest
|
||||||
sync
|
sync
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
|
target_link_libraries(syncLocalCmdTest
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
|
@ -270,7 +270,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
||||||
pMsg->msgType = 9999;
|
pMsg->msgType = 9999;
|
||||||
pMsg->contLen = 256;
|
pMsg->contLen = 256;
|
||||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||||
taosGetTimestampMs());
|
taosGetTimestampMs());
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
||||||
pMsg->msgType = 9999;
|
pMsg->msgType = 9999;
|
||||||
pMsg->contLen = 256;
|
pMsg->contLen = 256;
|
||||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||||
taosGetTimestampMs());
|
taosGetTimestampMs());
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ int main(int argc, char **argv) {
|
||||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, pEntry->index, &pEntry);
|
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, pEntry->index, &pEntry);
|
||||||
ASSERT(code == 0);
|
ASSERT(code == 0);
|
||||||
|
|
||||||
syncEntryLog2((char *)"==pEntry2==", pEntry2);
|
syncEntryLog2((char *)"==pEntry==", pEntry);
|
||||||
|
|
||||||
// step5
|
// step5
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
|
@ -13,7 +13,7 @@ void print(SHashObj *pNextIndex) {
|
||||||
|
|
||||||
SRaftId *pRaftId = (SRaftId *)key;
|
SRaftId *pRaftId = (SRaftId *)key;
|
||||||
|
|
||||||
printf("key:<" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p);
|
printf("key:<%" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p);
|
||||||
p = (uint64_t *)taosHashIterate(pNextIndex, p);
|
p = (uint64_t *)taosHashIterate(pNextIndex, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
#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");
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncAppendEntries *createMsg() {
|
||||||
|
SyncAppendEntries *pMsg = syncAppendEntriesBuild(20, 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");
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test1() {
|
||||||
|
SyncAppendEntries *pMsg = createMsg();
|
||||||
|
syncAppendEntriesLog2((char *)"test1:", pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2() {
|
||||||
|
SyncAppendEntries *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);
|
||||||
|
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test3() {
|
||||||
|
SyncAppendEntries *pMsg = createMsg();
|
||||||
|
uint32_t len;
|
||||||
|
char *serialized = syncAppendEntriesSerialize2(pMsg, &len);
|
||||||
|
SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len);
|
||||||
|
syncAppendEntriesLog2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2);
|
||||||
|
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test4() {
|
||||||
|
SyncAppendEntries *pMsg = createMsg();
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||||
|
SyncAppendEntries *pMsg2 = (SyncAppendEntries *)taosMemoryMalloc(rpcMsg.contLen);
|
||||||
|
syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2);
|
||||||
|
syncAppendEntriesLog2((char *)"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg ", pMsg2);
|
||||||
|
|
||||||
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test5() {
|
||||||
|
SyncAppendEntries *pMsg = createMsg();
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||||
|
SyncAppendEntries *pMsg2 = syncAppendEntriesFromRpcMsg2(&rpcMsg);
|
||||||
|
syncAppendEntriesLog2((char *)"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 ", pMsg2);
|
||||||
|
|
||||||
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
tsAsyncLog = 0;
|
||||||
|
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
||||||
|
logTest();
|
||||||
|
|
||||||
|
test1();
|
||||||
|
test2();
|
||||||
|
test3();
|
||||||
|
test4();
|
||||||
|
test5();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ int main(int argc, char** argv) {
|
||||||
char host[128];
|
char host[128];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
printf("" PRIu64 " -> %s:%d \n", u64, host, port);
|
printf("%" PRIu64 " -> %s:%d \n", u64, host, port);
|
||||||
|
|
||||||
} else if (argc == 3) {
|
} else if (argc == 3) {
|
||||||
uint64_t u64;
|
uint64_t u64;
|
||||||
|
|
|
@ -97,8 +97,8 @@ void test1() {
|
||||||
sTrace("lastIndex: %" PRId64, lastIndex);
|
sTrace("lastIndex: %" PRId64, lastIndex);
|
||||||
sTrace("lastTerm: %" PRIu64, lastTerm);
|
sTrace("lastTerm: %" PRIu64, lastTerm);
|
||||||
sTrace("syncStartIndex: %" PRId64, syncStartIndex);
|
sTrace("syncStartIndex: %" PRId64, syncStartIndex);
|
||||||
sTrace("" PRId64 "'s preIndex: %" PRId64, testIndex, preIndex);
|
sTrace("testIndex: %" PRId64 " preIndex: %" PRId64, testIndex, preIndex);
|
||||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, testIndex, preTerm);
|
sTrace("testIndex: %" PRId64 " preTerm: %" PRIu64, testIndex, preTerm);
|
||||||
|
|
||||||
if (gAssert) {
|
if (gAssert) {
|
||||||
assert(lastIndex == -1);
|
assert(lastIndex == -1);
|
||||||
|
@ -170,8 +170,8 @@ void test2() {
|
||||||
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
||||||
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
||||||
|
|
||||||
sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex);
|
sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex);
|
||||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm);
|
sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm);
|
||||||
|
|
||||||
if (gAssert) {
|
if (gAssert) {
|
||||||
SyncIndex preIndexArr[12] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
SyncIndex preIndexArr[12] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||||
|
@ -292,8 +292,8 @@ void test4() {
|
||||||
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
||||||
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
||||||
|
|
||||||
sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex);
|
sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex);
|
||||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm);
|
sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm);
|
||||||
}
|
}
|
||||||
|
|
||||||
logStoreDestory(pLogStore);
|
logStoreDestory(pLogStore);
|
||||||
|
@ -354,8 +354,8 @@ void test5() {
|
||||||
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
||||||
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
||||||
|
|
||||||
sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex);
|
sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex);
|
||||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm);
|
sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm);
|
||||||
|
|
||||||
if (gAssert) {
|
if (gAssert) {
|
||||||
SyncIndex preIndexArr[12] = {9999, 9999, 9999, 9999, 9999, 9999, 5, 6, 7, 8, 9, 10};
|
SyncIndex preIndexArr[12] = {9999, 9999, 9999, 9999, 9999, 9999, 5, 6, 7, 8, 9, 10};
|
||||||
|
|
|
@ -145,7 +145,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
||||||
pMsg->msgType = 9999;
|
pMsg->msgType = 9999;
|
||||||
pMsg->contLen = 256;
|
pMsg->contLen = 256;
|
||||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||||
taosGetTimestampMs());
|
taosGetTimestampMs());
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,18 +58,18 @@ void syncRespMgrGetTest(uint64_t i) {
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
printStub(&stub);
|
printStub(&stub);
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
printf("" PRId64 " notFound \n", i);
|
printf("%" PRId64 " notFound \n", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRespMgrGetAndDelTest(uint64_t i) {
|
void syncRespMgrGetAndDelTest(uint64_t i) {
|
||||||
printf("------syncRespMgrGetAndDelTest-------" PRIu64 "-- \n", i);
|
printf("------syncRespMgrGetAndDelTest-------%" PRIu64 "-- \n", i);
|
||||||
SRespStub stub;
|
SRespStub stub;
|
||||||
int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
|
int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
printStub(&stub);
|
printStub(&stub);
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
printf("" PRId64 " notFound \n", i);
|
printf("%" PRId64 " notFound \n", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
||||||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb== pFsm:%p", pFsm); }
|
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb== pFsm:%p", pFsm); }
|
||||||
|
|
||||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) {
|
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) {
|
||||||
char* s = syncCfg2Str(&(cbMeta.newCfg));
|
char* s = syncCfg2Str(&(cbMeta->newCfg));
|
||||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64
|
sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64
|
||||||
", newCfg:%s",
|
", newCfg:%s",
|
||||||
cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term, s);
|
cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term, s);
|
||||||
|
@ -308,7 +308,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
||||||
pMsg->msgType = TDMT_VND_SUBMIT;
|
pMsg->msgType = TDMT_VND_SUBMIT;
|
||||||
pMsg->contLen = 256;
|
pMsg->contLen = 256;
|
||||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||||
taosGetTimestampMs());
|
taosGetTimestampMs());
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue