syncSnapshotSenderTest.cpp 2.5 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 14 15 16 17 18 19 20 21

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

void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {}
void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {}
void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {}

void RestoreFinishCb(struct SSyncFSM* pFsm) {}
void ReConfigCb(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {}

int32_t GetSnapshot(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { return 0; }

22
int32_t SnapshotStartRead(struct SSyncFSM* pFsm, void* pParam, void** ppReader) { return 0; }
M
Minghao Li 已提交
23 24 25 26 27 28 29 30 31 32 33
int32_t SnapshotStopRead(struct SSyncFSM* pFsm, void* pReader) { return 0; }
int32_t SnapshotDoRead(struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32_t* len) { return 0; }

int32_t SnapshotStartWrite(struct SSyncFSM* pFsm, void** ppWriter) { return 0; }
int32_t SnapshotStopWrite(struct SSyncFSM* pFsm, void* pWriter, bool isApply) { return 0; }
int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_t len) { return 0; }

SSyncSnapshotSender* createSender() {
  SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode));
  pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore)));
  pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm)));
M
Minghao Li 已提交
34 35

 #if 0 
M
Minghao Li 已提交
36 37 38
  pSyncNode->pFsm->FpSnapshotStartRead = SnapshotStartRead;
  pSyncNode->pFsm->FpSnapshotStopRead = SnapshotStopRead;
  pSyncNode->pFsm->FpSnapshotDoRead = SnapshotDoRead;
39
  pSyncNode->pFsm->FpGetSnapshotInfo = GetSnapshot;
M
Minghao Li 已提交
40
#endif
M
Minghao Li 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54

  SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, 2);
  pSender->start = true;
  pSender->seq = 10;
  pSender->ack = 20;
  pSender->pReader = (void*)0x11;
  pSender->blockLen = 20;
  pSender->pCurrentBlock = taosMemoryMalloc(pSender->blockLen);
  snprintf((char*)(pSender->pCurrentBlock), pSender->blockLen, "%s", "hello");

  pSender->snapshot.lastApplyIndex = 99;
  pSender->snapshot.lastApplyTerm = 88;
  pSender->sendingMS = 77;
  pSender->term = 66;
M
Minghao Li 已提交
55 56
  
  //pSender->privateTerm = 99;
M
Minghao Li 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70

  return pSender;
}

int main() {
  tsAsyncLog = 0;
  sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
  logTest();

  SSyncSnapshotSender* pSender = createSender();
  sTrace("%s", snapshotSender2Str(pSender));

  return 0;
}