diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index df8412ab23..e03835fc54 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -29,9 +29,6 @@ extern "C" { extern int32_t sDebugFlag; -#define sLog(...) \ - { taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); } - #define sFatal(...) \ { \ if (sDebugFlag & DEBUG_FATAL) { \ @@ -79,6 +76,12 @@ typedef struct SSyncNode { int64_t rid; } 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 } #endif diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 9b5a7a0a38..4606496141 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -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; } -void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {} \ No newline at end of file +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; } \ No newline at end of file diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index f24a1a9a46..17405989f5 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -1,18 +1,39 @@ add_executable(syncTest "") +add_executable(syncEnvTest "") + + target_sources(syncTest PRIVATE "syncTest.cpp" ) +target_sources(syncEnvTest + PRIVATE + "syncEnvTest.cpp" +) + + target_include_directories(syncTest PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" "${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 sync gtest_main ) +target_link_libraries(syncEnvTest + sync + gtest_main +) + + enable_testing() add_test( NAME sync_test diff --git a/source/libs/sync/test/syncEnvTest.cpp b/source/libs/sync/test/syncEnvTest.cpp new file mode 100644 index 0000000000..5b8ccabdcc --- /dev/null +++ b/source/libs/sync/test/syncEnvTest.cpp @@ -0,0 +1,52 @@ +#include +#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; +} diff --git a/source/libs/sync/test/syncTest.cpp b/source/libs/sync/test/syncTest.cpp index f247be2711..8e85278960 100644 --- a/source/libs/sync/test/syncTest.cpp +++ b/source/libs/sync/test/syncTest.cpp @@ -14,8 +14,18 @@ void *pingFunc(void *param) { } int main() { - tsAsyncLog = 0; 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"); assert(pRaftStore != NULL); @@ -30,12 +40,8 @@ int main() { raftStorePersist(pRaftStore); - tsAsyncLog = 0; - taosInitLog((char *)"syncTest.log", 100000, 10); - sDebug("sync test"); - SSyncIO *syncIO = syncIOCreate(); assert(syncIO != NULL);