提交 113618be 编写于 作者: M Minghao Li

add sync test

上级 51adf7e2
......@@ -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) {}
\ 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
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
......
#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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册