syncPingTest.cpp 2.1 KB
Newer Older
M
Minghao Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#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");
}

M
Minghao Li 已提交
16
SSyncNode* doSync() {
M
Minghao Li 已提交
17 18
  SSyncFSM* pFsm;

M
Minghao Li 已提交
19 20
  SSyncInfo syncInfo;
  syncInfo.vgId = 1;
M
Minghao Li 已提交
21
  syncInfo.rpcClient = gSyncIO->clientRpc;
M
Minghao Li 已提交
22 23 24
  syncInfo.FpSendMsg = syncIOSendMsg;
  syncInfo.pFsm = pFsm;
  snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_sync_ping");
M
Minghao Li 已提交
25 26 27

  SSyncCfg* pCfg = &syncInfo.syncCfg;
  pCfg->myIndex = 0;
M
Minghao Li 已提交
28
  pCfg->replicaNum = 2;
M
Minghao Li 已提交
29 30

  pCfg->nodeInfo[0].nodePort = 7010;
M
Minghao Li 已提交
31 32
  snprintf(pCfg->nodeInfo[0].nodeFqdn, sizeof(pCfg->nodeInfo[0].nodeFqdn), "%s", "127.0.0.1");
  // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
M
Minghao Li 已提交
33 34

  pCfg->nodeInfo[1].nodePort = 7110;
M
Minghao Li 已提交
35 36
  snprintf(pCfg->nodeInfo[1].nodeFqdn, sizeof(pCfg->nodeInfo[1].nodeFqdn), "%s", "127.0.0.1");
  // taosGetFqdn(pCfg->nodeInfo[1].nodeFqdn);
M
Minghao Li 已提交
37 38

  pCfg->nodeInfo[2].nodePort = 7210;
M
Minghao Li 已提交
39 40
  snprintf(pCfg->nodeInfo[2].nodeFqdn, sizeof(pCfg->nodeInfo[2].nodeFqdn), "%s", "127.0.0.1");
  // taosGetFqdn(pCfg->nodeInfo[2].nodeFqdn);
M
Minghao Li 已提交
41 42 43

  SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
  assert(pSyncNode != NULL);
M
Minghao Li 已提交
44

M
sync io  
Minghao Li 已提交
45
  gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
M
Minghao Li 已提交
46
  gSyncIO->pSyncNode = pSyncNode;
M
Minghao Li 已提交
47 48 49 50

  return pSyncNode;
}

M
Minghao Li 已提交
51 52
void timerPingAll(void* param, void* tmrId) {
  SSyncNode* pSyncNode = (SSyncNode*)param;
M
Minghao Li 已提交
53
  syncNodePingAll(pSyncNode);
M
Minghao Li 已提交
54 55 56
}

int main() {
M
Minghao Li 已提交
57
  // taosInitLog((char*)"syncPingTest.log", 100000, 10);
M
Minghao Li 已提交
58 59 60 61 62
  tsAsyncLog = 0;
  sDebugFlag = 143 + 64;

  logTest();

M
sync io  
Minghao Li 已提交
63
  int32_t ret = syncIOStart((char*)"127.0.0.1", 7010);
M
Minghao Li 已提交
64 65 66 67 68
  assert(ret == 0);

  ret = syncEnvStart();
  assert(ret == 0);

M
sync io  
Minghao Li 已提交
69
  SSyncNode* pSyncNode = doSync();
M
Minghao Li 已提交
70
  gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
M
Minghao Li 已提交
71
  gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
M
Minghao Li 已提交
72

M
sync io  
Minghao Li 已提交
73 74
  ret = syncNodeStartPingTimer(pSyncNode);
  assert(ret == 0);
M
Minghao Li 已提交
75

M
sync io  
Minghao Li 已提交
76 77
  /*
  taosMsleep(10000);
M
sync io  
Minghao Li 已提交
78 79
  ret = syncNodeStopPingTimer(pSyncNode);
  assert(ret == 0);
M
sync io  
Minghao Li 已提交
80
  */
M
Minghao Li 已提交
81 82 83 84 85 86 87

  while (1) {
    taosMsleep(1000);
  }

  return 0;
}