TDengine/source/libs/sync/test/syncRaftStoreTest.cpp

71 lines
1.8 KiB
C++
Raw Normal View History

#include "syncRaftStore.h"
2022-03-06 09:59:24 +00:00
//#include <gtest/gtest.h>
#include <stdio.h>
2022-03-03 02:46:48 +00:00
#include "syncIO.h"
#include "syncInt.h"
2022-03-16 07:09:56 +00:00
#include "syncUtil.h"
2022-03-03 02:46:48 +00:00
2022-03-07 06:18:46 +00:00
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");
2022-03-03 02:46:48 +00:00
}
2022-03-16 07:09:56 +00:00
uint16_t ports[] = {7010, 7110, 7210, 7310, 7410};
int32_t replicaNum = 5;
int32_t myIndex = 0;
SRaftId ids[TSDB_MAX_REPLICA];
void initRaftId() {
for (int i = 0; i < replicaNum; ++i) {
ids[i].addr = syncUtilAddr2U64("127.0.0.1", ports[i]);
ids[i].vgId = 1234;
char* s = syncUtilRaftId2Str(&ids[i]);
printf("raftId[%d] : %s\n", i, s);
2022-03-25 16:29:53 +00:00
taosMemoryFree(s);
2022-03-16 07:09:56 +00:00
}
}
2022-03-03 02:46:48 +00:00
int main() {
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog = 0;
sDebugFlag = 143 + 64;
2022-03-07 06:18:46 +00:00
logTest();
2022-03-03 02:46:48 +00:00
2022-03-16 07:09:56 +00:00
initRaftId();
SRaftStore* pRaftStore = raftStoreOpen("./test_raft_store.json");
2022-03-03 02:46:48 +00:00
assert(pRaftStore != NULL);
2022-03-16 07:09:56 +00:00
raftStorePrint2((char*)"==raftStoreOpen==", pRaftStore);
raftStoreSetTerm(pRaftStore, 100);
raftStorePrint2((char*)"==raftStoreSetTerm==", pRaftStore);
raftStoreVote(pRaftStore, &ids[0]);
raftStorePrint2((char*)"==raftStoreVote==", pRaftStore);
raftStoreClearVote(pRaftStore);
raftStorePrint2((char*)"==raftStoreClearVote==", pRaftStore);
raftStoreVote(pRaftStore, &ids[1]);
raftStorePrint2((char*)"==raftStoreVote==", pRaftStore);
raftStoreNextTerm(pRaftStore);
raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore);
raftStoreNextTerm(pRaftStore);
raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore);
raftStoreNextTerm(pRaftStore);
raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore);
raftStoreNextTerm(pRaftStore);
raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore);
2022-03-03 02:46:48 +00:00
return 0;
}