vgroup.cpp 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/**
 * @file db.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module vgroup-msg tests
 * @version 0.1
 * @date 2021-12-20
 *
 * @copyright Copyright (c) 2021
 *
 */

S
Shengliang Guan 已提交
12
#include "base.h"
13 14 15

class DndTestVgroup : public ::testing::Test {
 protected:
S
Shengliang Guan 已提交
16 17
  static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vgroup", 9150); }
  static void TearDownTestSuite() { test.Cleanup(); }
18

S
Shengliang Guan 已提交
19
  static Testbase test;
20 21 22 23 24 25

 public:
  void SetUp() override {}
  void TearDown() override {}
};

S
Shengliang Guan 已提交
26
Testbase DndTestVgroup::test;
27 28 29

TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
  {
30
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
31 32 33
      int32_t contLen = sizeof(SCreateVnodeMsg);

      SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(contLen);
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
      pReq->vgId = htonl(2);
      pReq->dnodeId = htonl(1);
      strcpy(pReq->db, "1.d1");
      pReq->dbUid = htobe64(9527);
      pReq->vgVersion = htonl(1);
      pReq->cacheBlockSize = htonl(16);
      pReq->totalBlocks = htonl(10);
      pReq->daysPerFile = htonl(10);
      pReq->daysToKeep0 = htonl(3650);
      pReq->daysToKeep1 = htonl(3650);
      pReq->daysToKeep2 = htonl(3650);
      pReq->minRows = htonl(100);
      pReq->minRows = htonl(4096);
      pReq->commitTime = htonl(3600);
      pReq->fsyncPeriod = htonl(3000);
      pReq->walLevel = 1;
      pReq->precision = 0;
      pReq->compression = 2;
      pReq->replica = 1;
      pReq->quorum = 1;
      pReq->update = 0;
      pReq->cacheLastRow = 0;
      pReq->selfIndex = 0;
      for (int r = 0; r < pReq->replica; ++r) {
        SReplica* pReplica = &pReq->replicas[r];
        pReplica->id = htonl(1);
        pReplica->port = htons(9150);
      }

S
Shengliang Guan 已提交
63
      SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_VNODE_IN, pReq, contLen);
64 65 66 67 68 69 70
      ASSERT_NE(pMsg, nullptr);
      ASSERT_EQ(pMsg->code, 0);
    }
  }

  {
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
71 72 73
      int32_t contLen = sizeof(SAlterVnodeMsg);

      SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(contLen);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
      pReq->vgId = htonl(2);
      pReq->dnodeId = htonl(1);
      strcpy(pReq->db, "1.d1");
      pReq->dbUid = htobe64(9527);
      pReq->vgVersion = htonl(2);
      pReq->cacheBlockSize = htonl(16);
      pReq->totalBlocks = htonl(10);
      pReq->daysPerFile = htonl(10);
      pReq->daysToKeep0 = htonl(3650);
      pReq->daysToKeep1 = htonl(3650);
      pReq->daysToKeep2 = htonl(3650);
      pReq->minRows = htonl(100);
      pReq->minRows = htonl(4096);
      pReq->commitTime = htonl(3600);
      pReq->fsyncPeriod = htonl(3000);
      pReq->walLevel = 1;
      pReq->precision = 0;
      pReq->compression = 2;
      pReq->replica = 1;
      pReq->quorum = 1;
      pReq->update = 0;
      pReq->cacheLastRow = 0;
      pReq->selfIndex = 0;
      for (int r = 0; r < pReq->replica; ++r) {
        SReplica* pReplica = &pReq->replicas[r];
        pReplica->id = htonl(1);
        pReplica->port = htons(9150);
      }

S
Shengliang Guan 已提交
103
      SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_VNODE_IN, pReq, contLen);
104 105
      ASSERT_NE(pMsg, nullptr);
      ASSERT_EQ(pMsg->code, 0);
106
    }
107
  }
108

109 110
  {
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
111 112 113
      int32_t contLen = sizeof(SDropVnodeMsg);

      SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(contLen);
114 115 116 117 118 119 120
      pReq->vgId = htonl(2);
      pReq->dnodeId = htonl(1);
      strcpy(pReq->db, "1.d1");
      pReq->dbUid = htobe64(9527);

      SRpcMsg rpcMsg = {0};
      rpcMsg.pCont = pReq;
S
Shengliang Guan 已提交
121
      rpcMsg.contLen = sizeof(SDropVnodeMsg);
122
      rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN;
123

S
Shengliang Guan 已提交
124
      SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_VNODE_IN, pReq, contLen);
125 126 127
      ASSERT_NE(pMsg, nullptr);
      ASSERT_EQ(pMsg->code, 0);
    }
128 129
  }
}