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

107 lines
2.6 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-03-03 03:37:19 +00:00
uint16_t ports[3] = {7010, 7110, 7210};
SSyncNode* doSync(int myIndex) {
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;
2022-03-04 07:48:09 +00:00
syncInfo.queue = gSyncIO->pMsgQ;
syncInfo.FpEqMsg = syncIOEqMsg;
2022-02-27 02:22:15 +00:00
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;
2022-03-03 03:37:19 +00:00
pCfg->myIndex = myIndex;
pCfg->replicaNum = 3;
2022-02-26 18:24:50 +00:00
2022-03-03 03:37:19 +00:00
pCfg->nodeInfo[0].nodePort = ports[0];
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
2022-03-03 03:37:19 +00:00
pCfg->nodeInfo[1].nodePort = ports[1];
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
2022-03-03 03:37:19 +00:00
pCfg->nodeInfo[2].nodePort = ports[2];
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
}
2022-03-03 03:37:19 +00:00
int main(int argc, char** argv) {
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-03 03:37:19 +00:00
int myIndex = 0;
if (argc >= 2) {
myIndex = atoi(argv[1]);
}
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
2022-02-26 18:24:50 +00:00
assert(ret == 0);
ret = syncEnvStart();
assert(ret == 0);
2022-03-03 03:37:19 +00:00
SSyncNode* pSyncNode = doSync(myIndex);
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-03-05 04:28:34 +00:00
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
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-04 07:48:09 +00:00
taosMsleep(10000);
2022-03-06 09:59:24 +00:00
ret = syncNodeStopPingTimer(pSyncNode);
assert(ret == 0);
taosMsleep(10000);
ret = syncNodeStartPingTimer(pSyncNode);
assert(ret == 0);
taosMsleep(10000);
2022-03-04 07:48:09 +00:00
ret = syncNodeStopPingTimer(pSyncNode);
assert(ret == 0);
2022-02-26 18:24:50 +00:00
while (1) {
taosMsleep(1000);
}
return 0;
}