add sync test
This commit is contained in:
parent
51adf7e25e
commit
113618bea3
|
@ -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
|
||||
|
|
|
@ -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) {}
|
||||
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; }
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue