syncRequestVoteReplyTest.cpp 2.9 KB
Newer Older
M
Minghao Li 已提交
1
#include <gtest/gtest.h>
2
#include "syncTest.h"
M
Minghao Li 已提交
3 4 5 6 7 8 9 10 11 12 13

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");
}

SyncRequestVoteReply *createMsg() {
M
Minghao Li 已提交
14
  SyncRequestVoteReply *pMsg = syncRequestVoteReplyBuild(1000);
M
Minghao Li 已提交
15 16 17 18 19 20
  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->term = 77;
  pMsg->voteGranted = true;
M
Minghao Li 已提交
21
  return pMsg;
M
Minghao Li 已提交
22 23 24 25
}

void test1() {
  SyncRequestVoteReply *pMsg = createMsg();
M
Minghao Li 已提交
26
  syncRequestVoteReplyLog2((char *)"test1:", pMsg);
M
Minghao Li 已提交
27 28 29 30 31
  syncRequestVoteReplyDestroy(pMsg);
}

void test2() {
  SyncRequestVoteReply *pMsg = createMsg();
M
Minghao Li 已提交
32
  uint32_t              len = pMsg->bytes;
H
Hongze Cheng 已提交
33
  char                 *serialized = (char *)taosMemoryMalloc(len);
M
Minghao Li 已提交
34
  syncRequestVoteReplySerialize(pMsg, serialized, len);
M
Minghao Li 已提交
35
  SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild(1000);
M
Minghao Li 已提交
36
  syncRequestVoteReplyDeserialize(serialized, len, pMsg2);
M
Minghao Li 已提交
37
  syncRequestVoteReplyLog2((char *)"test2: syncRequestVoteReplySerialize -> syncRequestVoteReplyDeserialize ", pMsg2);
M
Minghao Li 已提交
38

wafwerar's avatar
wafwerar 已提交
39
  taosMemoryFree(serialized);
M
Minghao Li 已提交
40 41 42 43 44 45
  syncRequestVoteReplyDestroy(pMsg);
  syncRequestVoteReplyDestroy(pMsg2);
}

void test3() {
  SyncRequestVoteReply *pMsg = createMsg();
M
Minghao Li 已提交
46
  uint32_t              len;
H
Hongze Cheng 已提交
47
  char                 *serialized = syncRequestVoteReplySerialize2(pMsg, &len);
M
Minghao Li 已提交
48
  SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyDeserialize2(serialized, len);
M
Minghao Li 已提交
49
  syncRequestVoteReplyLog2((char *)"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 ", pMsg2);
M
Minghao Li 已提交
50

wafwerar's avatar
wafwerar 已提交
51
  taosMemoryFree(serialized);
M
Minghao Li 已提交
52 53 54 55 56 57
  syncRequestVoteReplyDestroy(pMsg);
  syncRequestVoteReplyDestroy(pMsg2);
}

void test4() {
  SyncRequestVoteReply *pMsg = createMsg();
M
Minghao Li 已提交
58
  SRpcMsg               rpcMsg;
M
Minghao Li 已提交
59
  syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
M
Minghao Li 已提交
60
  SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild(1000);
M
Minghao Li 已提交
61
  syncRequestVoteReplyFromRpcMsg(&rpcMsg, pMsg2);
M
Minghao Li 已提交
62
  syncRequestVoteReplyLog2((char *)"test4: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg ", pMsg2);
M
Minghao Li 已提交
63

M
Minghao Li 已提交
64
  rpcFreeCont(rpcMsg.pCont);
M
Minghao Li 已提交
65 66 67 68 69 70
  syncRequestVoteReplyDestroy(pMsg);
  syncRequestVoteReplyDestroy(pMsg2);
}

void test5() {
  SyncRequestVoteReply *pMsg = createMsg();
M
Minghao Li 已提交
71
  SRpcMsg               rpcMsg;
M
Minghao Li 已提交
72 73
  syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
  SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyFromRpcMsg2(&rpcMsg);
M
Minghao Li 已提交
74
  syncRequestVoteReplyLog2((char *)"test5: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg2 ", pMsg2);
M
Minghao Li 已提交
75

M
Minghao Li 已提交
76
  rpcFreeCont(rpcMsg.pCont);
M
Minghao Li 已提交
77 78 79 80 81 82
  syncRequestVoteReplyDestroy(pMsg);
  syncRequestVoteReplyDestroy(pMsg2);
}

int main() {
  tsAsyncLog = 0;
M
Minghao Li 已提交
83
  sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
M
Minghao Li 已提交
84 85 86 87 88 89 90 91 92 93
  logTest();

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

  return 0;
}