“8bce9baab33c744bde3f73d77c8933a373e96174”上不存在“StyleTextRec/tools/synth_dataset.py”
syncRequestVoteTest.cpp 2.7 KB
Newer Older
M
Minghao Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.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");
}

SyncRequestVote *createMsg() {
  SyncRequestVote *pMsg = syncRequestVoteBuild();
  pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
  pMsg->srcId.vgId = 100;
  pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
  pMsg->destId.vgId = 100;
  pMsg->currentTerm = 11;
  pMsg->lastLogIndex = 22;
  pMsg->lastLogTerm = 33;
M
Minghao Li 已提交
26
  return pMsg;
M
Minghao Li 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
}

void test1() {
  SyncRequestVote *pMsg = createMsg();
  syncRequestVotePrint2((char *)"test1:", pMsg);
  syncRequestVoteDestroy(pMsg);
}

void test2() {
  SyncRequestVote *pMsg = createMsg();
  uint32_t         len = pMsg->bytes;
  char *           serialized = (char *)malloc(len);
  syncRequestVoteSerialize(pMsg, serialized, len);
  SyncRequestVote *pMsg2 = syncRequestVoteBuild();
  syncRequestVoteDeserialize(serialized, len, pMsg2);
M
Minghao Li 已提交
42
  syncRequestVotePrint2((char *)"test2: syncRequestVoteSerialize -> syncRequestVoteDeserialize ", pMsg2);
M
Minghao Li 已提交
43 44 45 46 47 48 49 50 51 52 53

  free(serialized);
  syncRequestVoteDestroy(pMsg);
  syncRequestVoteDestroy(pMsg2);
}

void test3() {
  SyncRequestVote *pMsg = createMsg();
  uint32_t         len;
  char *           serialized = syncRequestVoteSerialize2(pMsg, &len);
  SyncRequestVote *pMsg2 = syncRequestVoteDeserialize2(serialized, len);
M
Minghao Li 已提交
54
  syncRequestVotePrint2((char *)"test3: syncRequestVoteSerialize3 -> syncRequestVoteDeserialize2 ", pMsg2);
M
Minghao Li 已提交
55 56 57 58 59 60 61 62 63 64 65 66

  free(serialized);
  syncRequestVoteDestroy(pMsg);
  syncRequestVoteDestroy(pMsg2);
}

void test4() {
  SyncRequestVote *pMsg = createMsg();
  SRpcMsg          rpcMsg;
  syncRequestVote2RpcMsg(pMsg, &rpcMsg);
  SyncRequestVote *pMsg2 = syncRequestVoteBuild();
  syncRequestVoteFromRpcMsg(&rpcMsg, pMsg2);
M
Minghao Li 已提交
67
  syncRequestVotePrint2((char *)"test4: syncRequestVote2RpcMsg -> syncRequestVoteFromRpcMsg ", pMsg2);
M
Minghao Li 已提交
68 69 70 71 72 73 74 75 76 77

  syncRequestVoteDestroy(pMsg);
  syncRequestVoteDestroy(pMsg2);
}

void test5() {
  SyncRequestVote *pMsg = createMsg();
  SRpcMsg          rpcMsg;
  syncRequestVote2RpcMsg(pMsg, &rpcMsg);
  SyncRequestVote *pMsg2 = syncRequestVoteFromRpcMsg2(&rpcMsg);
M
Minghao Li 已提交
78
  syncRequestVotePrint2((char *)"test5: syncRequestVote2RpcMsg -> syncRequestVoteFromRpcMsg2 ", pMsg2);
M
Minghao Li 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

  syncRequestVoteDestroy(pMsg);
  syncRequestVoteDestroy(pMsg2);
}

int main() {
  // taosInitLog((char *)"syncTest.log", 100000, 10);
  tsAsyncLog = 0;
  sDebugFlag = 143 + 64;
  logTest();

  test1();
  test2();
  test3();
  test4();
  test5();

  return 0;
}