syncPingTest.cpp 2.3 KB
Newer Older
M
Minghao Li 已提交
1
#include <gtest/gtest.h>
M
Minghao Li 已提交
2 3 4
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
M
Minghao Li 已提交
5
#include "syncMessage.h"
M
Minghao Li 已提交
6
#include "syncUtil.h"
M
Minghao Li 已提交
7 8 9 10 11 12 13 14 15 16

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 已提交
17 18 19 20 21 22 23 24 25
SyncPing *createMsg() {
  SRaftId srcId, destId;
  srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
  srcId.vgId = 100;
  destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
  destId.vgId = 100;
  SyncPing *pMsg = syncPingBuild3(&srcId, &destId);
  return pMsg;
}
M
Minghao Li 已提交
26

M
Minghao Li 已提交
27 28 29 30 31
void test1() {
  SyncPing *pMsg = createMsg();
  syncPingPrint2((char *)"test1:", pMsg);
  syncPingDestroy(pMsg);
}
M
Minghao Li 已提交
32

M
Minghao Li 已提交
33 34
void test2() {
  SyncPing *pMsg = createMsg();
M
Minghao Li 已提交
35 36
  uint32_t  len = pMsg->bytes;
  char *    serialized = (char *)malloc(len);
M
Minghao Li 已提交
37 38 39 40 41 42 43 44 45
  syncPingSerialize(pMsg, serialized, len);
  SyncPing *pMsg2 = syncPingBuild(pMsg->dataLen);
  syncPingDeserialize(serialized, len, pMsg2);
  syncPingPrint2((char *)"test2: syncPingSerialize -> syncPingDeserialize ", pMsg2);

  free(serialized);
  syncPingDestroy(pMsg);
  syncPingDestroy(pMsg2);
}
M
Minghao Li 已提交
46

M
Minghao Li 已提交
47 48
void test3() {
  SyncPing *pMsg = createMsg();
M
Minghao Li 已提交
49 50
  uint32_t  len;
  char *    serialized = syncPingSerialize2(pMsg, &len);
M
Minghao Li 已提交
51 52
  SyncPing *pMsg2 = syncPingDeserialize2(serialized, len);
  syncPingPrint2((char *)"test3: syncPingSerialize3 -> syncPingDeserialize2 ", pMsg2);
M
Minghao Li 已提交
53

M
Minghao Li 已提交
54 55 56 57
  free(serialized);
  syncPingDestroy(pMsg);
  syncPingDestroy(pMsg2);
}
M
Minghao Li 已提交
58

M
Minghao Li 已提交
59 60
void test4() {
  SyncPing *pMsg = createMsg();
M
Minghao Li 已提交
61
  SRpcMsg   rpcMsg;
M
Minghao Li 已提交
62 63 64 65
  syncPing2RpcMsg(pMsg, &rpcMsg);
  SyncPing *pMsg2 = (SyncPing *)malloc(rpcMsg.contLen);
  syncPingFromRpcMsg(&rpcMsg, pMsg2);
  syncPingPrint2((char *)"test4: syncPing2RpcMsg -> syncPingFromRpcMsg ", pMsg2);
M
Minghao Li 已提交
66

M
Minghao Li 已提交
67 68
  syncPingDestroy(pMsg);
  syncPingDestroy(pMsg2);
M
Minghao Li 已提交
69 70
}

M
Minghao Li 已提交
71 72
void test5() {
  SyncPing *pMsg = createMsg();
M
Minghao Li 已提交
73
  SRpcMsg   rpcMsg;
M
Minghao Li 已提交
74 75 76
  syncPing2RpcMsg(pMsg, &rpcMsg);
  SyncPing *pMsg2 = syncPingFromRpcMsg2(&rpcMsg);
  syncPingPrint2((char *)"test5: syncPing2RpcMsg -> syncPingFromRpcMsg2 ", pMsg2);
M
Minghao Li 已提交
77

M
Minghao Li 已提交
78 79
  syncPingDestroy(pMsg);
  syncPingDestroy(pMsg2);
M
Minghao Li 已提交
80 81
}

M
Minghao Li 已提交
82
int main() {
M
Minghao Li 已提交
83
  // taosInitLog((char *)"syncTest.log", 100000, 10);
M
Minghao Li 已提交
84 85
  tsAsyncLog = 0;
  sDebugFlag = 143 + 64;
M
Minghao Li 已提交
86
  logTest();
M
Minghao Li 已提交
87

M
Minghao Li 已提交
88 89 90 91 92
  test1();
  test2();
  test3();
  test4();
  test5();
M
Minghao Li 已提交
93 94 95

  return 0;
}