syncPingTest.cpp 2.3 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 17 18
uint16_t ports[3] = {7010, 7110, 7210};

SSyncNode* doSync(int myIndex) {
M
Minghao Li 已提交
19 20
  SSyncFSM* pFsm;

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

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

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

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

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

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

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

  return pSyncNode;
}

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

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

  logTest();

M
Minghao Li 已提交
65 66 67 68 69 70
  int myIndex = 0;
  if (argc >= 2) {
    myIndex = atoi(argv[1]);
  }

  int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
M
Minghao Li 已提交
71 72 73 74 75
  assert(ret == 0);

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

M
Minghao Li 已提交
76
  SSyncNode* pSyncNode = doSync(myIndex);
M
Minghao Li 已提交
77
  gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
M
Minghao Li 已提交
78
  gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
M
Minghao Li 已提交
79

M
sync io  
Minghao Li 已提交
80 81
  ret = syncNodeStartPingTimer(pSyncNode);
  assert(ret == 0);
M
Minghao Li 已提交
82

M
sync io  
Minghao Li 已提交
83
  /*
M
Minghao Li 已提交
84 85 86
    taosMsleep(10000);
    ret = syncNodeStopPingTimer(pSyncNode);
    assert(ret == 0);
M
sync io  
Minghao Li 已提交
87
  */
M
Minghao Li 已提交
88 89 90 91 92 93 94

  while (1) {
    taosMsleep(1000);
  }

  return 0;
}