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

88 lines
2.1 KiB
C++
Raw Normal View History

2022-02-26 18:24:50 +00:00
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
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-02-28 06:10:34 +00:00
SSyncNode* doSync() {
2022-02-27 02:22:15 +00:00
SSyncFSM* pFsm;
2022-02-26 18:24:50 +00:00
SSyncInfo syncInfo;
syncInfo.vgId = 1;
2022-02-28 09:47:47 +00:00
syncInfo.rpcClient = gSyncIO->clientRpc;
2022-02-27 02:22:15 +00:00
syncInfo.FpSendMsg = syncIOSendMsg;
syncInfo.pFsm = pFsm;
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_sync_ping");
2022-02-26 18:24:50 +00:00
SSyncCfg* pCfg = &syncInfo.syncCfg;
pCfg->myIndex = 0;
2022-03-02 12:43:03 +00:00
pCfg->replicaNum = 2;
2022-02-26 18:24:50 +00:00
pCfg->nodeInfo[0].nodePort = 7010;
2022-03-02 09:40:22 +00:00
snprintf(pCfg->nodeInfo[0].nodeFqdn, sizeof(pCfg->nodeInfo[0].nodeFqdn), "%s", "127.0.0.1");
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
2022-02-26 18:24:50 +00:00
pCfg->nodeInfo[1].nodePort = 7110;
2022-03-02 09:40:22 +00:00
snprintf(pCfg->nodeInfo[1].nodeFqdn, sizeof(pCfg->nodeInfo[1].nodeFqdn), "%s", "127.0.0.1");
// taosGetFqdn(pCfg->nodeInfo[1].nodeFqdn);
2022-02-26 18:24:50 +00:00
pCfg->nodeInfo[2].nodePort = 7210;
2022-03-02 09:40:22 +00:00
snprintf(pCfg->nodeInfo[2].nodeFqdn, sizeof(pCfg->nodeInfo[2].nodeFqdn), "%s", "127.0.0.1");
// taosGetFqdn(pCfg->nodeInfo[2].nodeFqdn);
2022-02-26 18:24:50 +00:00
SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
assert(pSyncNode != NULL);
2022-02-27 02:22:15 +00:00
2022-03-02 07:11:54 +00:00
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
2022-02-27 02:22:15 +00:00
gSyncIO->pSyncNode = pSyncNode;
2022-02-28 06:10:34 +00:00
return pSyncNode;
}
2022-02-28 08:36:57 +00:00
void timerPingAll(void* param, void* tmrId) {
SSyncNode* pSyncNode = (SSyncNode*)param;
2022-02-28 06:10:34 +00:00
syncNodePingAll(pSyncNode);
2022-02-26 18:24:50 +00:00
}
int main() {
2022-02-28 06:10:34 +00:00
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
2022-02-26 18:24:50 +00:00
tsAsyncLog = 0;
sDebugFlag = 143 + 64;
logTest();
2022-03-02 07:11:54 +00:00
int32_t ret = syncIOStart((char*)"127.0.0.1", 7010);
2022-02-26 18:24:50 +00:00
assert(ret == 0);
ret = syncEnvStart();
assert(ret == 0);
2022-03-02 07:20:49 +00:00
SSyncNode* pSyncNode = doSync();
2022-03-02 10:30:21 +00:00
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
2022-03-02 12:43:03 +00:00
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
2022-02-28 06:10:34 +00:00
2022-03-02 07:20:49 +00:00
ret = syncNodeStartPingTimer(pSyncNode);
assert(ret == 0);
2022-02-28 08:36:57 +00:00
2022-03-02 08:37:04 +00:00
/*
taosMsleep(10000);
2022-03-02 07:20:49 +00:00
ret = syncNodeStopPingTimer(pSyncNode);
assert(ret == 0);
2022-03-02 08:37:04 +00:00
*/
2022-02-26 18:24:50 +00:00
while (1) {
taosMsleep(1000);
}
return 0;
}