syncPingTest.cpp 2.5 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
  syncInfo.FpSendMsg = syncIOSendMsg;
M
Minghao Li 已提交
25 26
  syncInfo.queue = gSyncIO->pMsgQ;
  syncInfo.FpEqMsg = syncIOEqMsg;
M
Minghao Li 已提交
27
  syncInfo.pFsm = pFsm;
M
Minghao Li 已提交
28
  snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./path");
M
Minghao Li 已提交
29 30

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

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

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

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

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

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

  return pSyncNode;
}

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

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

  logTest();

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

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

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

M
Minghao Li 已提交
78
  SSyncNode* pSyncNode = doSync(myIndex);
M
Minghao Li 已提交
79
  gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
M
Minghao Li 已提交
80
  gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
M
Minghao Li 已提交
81
  gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
M
Minghao Li 已提交
82

M
sync io  
Minghao Li 已提交
83 84
  ret = syncNodeStartPingTimer(pSyncNode);
  assert(ret == 0);
M
Minghao Li 已提交
85

M
Minghao Li 已提交
86
  taosMsleep(10000);
M
Minghao Li 已提交
87 88 89 90 91 92 93 94 95 96 97

  ret = syncNodeStopPingTimer(pSyncNode);
  assert(ret == 0);

  taosMsleep(10000);

  ret = syncNodeStartPingTimer(pSyncNode);
  assert(ret == 0);

  taosMsleep(10000);

M
Minghao Li 已提交
98 99
  ret = syncNodeStopPingTimer(pSyncNode);
  assert(ret == 0);
M
Minghao Li 已提交
100 101 102 103 104 105 106

  while (1) {
    taosMsleep(1000);
  }

  return 0;
}