add sync test

This commit is contained in:
Minghao Li 2022-02-25 14:38:12 +08:00
parent 51adf7e25e
commit 113618bea3
5 changed files with 96 additions and 9 deletions

View File

@ -29,9 +29,6 @@ extern "C" {
extern int32_t sDebugFlag; extern int32_t sDebugFlag;
#define sLog(...) \
{ taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); }
#define sFatal(...) \ #define sFatal(...) \
{ \ { \
if (sDebugFlag & DEBUG_FATAL) { \ if (sDebugFlag & DEBUG_FATAL) { \
@ -79,6 +76,12 @@ typedef struct SSyncNode {
int64_t rid; int64_t rid;
} SSyncNode; } SSyncNode;
SSyncNode* syncNodeStart(const SSyncInfo* pSyncInfo);
void syncNodeStop(SSyncNode* pSyncNode);
// int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak);
int32_t syncNodeForwardToPeer(SSyncNode* pSyncNode, const SSyncBuffer* pBuf, bool isWeak);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -35,4 +35,9 @@ int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak) { r
ESyncState syncGetMyRole(int64_t rid) { return TAOS_SYNC_STATE_LEADER; } ESyncState syncGetMyRole(int64_t rid) { return TAOS_SYNC_STATE_LEADER; }
void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {} void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {}
SSyncNode* syncNodeStart(const SSyncInfo* pSyncInfo) { return NULL; }
void syncNodeStop(SSyncNode* pSyncNode) {}
int32_t syncNodeForwardToPeer(SSyncNode* pSyncNode, const SSyncBuffer* pBuf, bool isWeak) { return 0; }

View File

@ -1,18 +1,39 @@
add_executable(syncTest "") add_executable(syncTest "")
add_executable(syncEnvTest "")
target_sources(syncTest target_sources(syncTest
PRIVATE PRIVATE
"syncTest.cpp" "syncTest.cpp"
) )
target_sources(syncEnvTest
PRIVATE
"syncEnvTest.cpp"
)
target_include_directories(syncTest target_include_directories(syncTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncEnvTest
PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
)
target_link_libraries(syncTest target_link_libraries(syncTest
sync sync
gtest_main gtest_main
) )
target_link_libraries(syncEnvTest
sync
gtest_main
)
enable_testing() enable_testing()
add_test( add_test(
NAME sync_test NAME sync_test

View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
void *pingFunc(void *param) {
SSyncIO *io = (SSyncIO *)param;
while (1) {
sDebug("io->ping");
io->ping(io);
sleep(1);
}
return NULL;
}
int main() {
tsAsyncLog = 0;
taosInitLog((char *)"syncTest.log", 100000, 10);
SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json");
assert(pRaftStore != NULL);
raftStorePrint(pRaftStore);
pRaftStore->currentTerm = 100;
pRaftStore->voteFor.addr = 200;
pRaftStore->voteFor.vgId = 300;
raftStorePrint(pRaftStore);
raftStorePersist(pRaftStore);
tsAsyncLog = 0;
taosInitLog((char *)"syncTest.log", 100000, 10);
sDebug("sync test");
SSyncIO *syncIO = syncIOCreate();
assert(syncIO != NULL);
syncIO->start(syncIO);
sleep(2);
pthread_t tid;
pthread_create(&tid, NULL, pingFunc, syncIO);
while (1) {
sleep(1);
}
return 0;
}

View File

@ -14,8 +14,18 @@ void *pingFunc(void *param) {
} }
int main() { int main() {
tsAsyncLog = 0;
taosInitLog((char *)"syncTest.log", 100000, 10); taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog = 0;
sDebugFlag = 143 + 64;
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");
SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json"); SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json");
assert(pRaftStore != NULL); assert(pRaftStore != NULL);
@ -30,12 +40,8 @@ int main() {
raftStorePersist(pRaftStore); raftStorePersist(pRaftStore);
tsAsyncLog = 0;
taosInitLog((char *)"syncTest.log", 100000, 10);
sDebug("sync test"); sDebug("sync test");
SSyncIO *syncIO = syncIOCreate(); SSyncIO *syncIO = syncIOCreate();
assert(syncIO != NULL); assert(syncIO != NULL);