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

S
Shengliang Guan 已提交
12
#include "sut.h"
13

S
Shengliang Guan 已提交
14
class DndTestVnode : public ::testing::Test {
15
 protected:
S
Shengliang Guan 已提交
16
  static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vnode", 9150); }
S
Shengliang Guan 已提交
17
  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 DndTestVnode::test;
27

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

S
Shengliang Guan 已提交
33
      SCreateVnodeReq* pReq = (SCreateVnodeReq*)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 64
      SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen);
      ASSERT_NE(pRsp, nullptr);
65 66 67 68 69 70
      if (i == 0) {
        ASSERT_EQ(pRsp->code, 0);
        test.Restart();
      } else {
        ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED);
      }
71 72 73 74 75
    }
  }

  {
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
76
      int32_t contLen = sizeof(SAlterVnodeReq);
S
Shengliang Guan 已提交
77

S
Shengliang Guan 已提交
78
      SAlterVnodeReq* pReq = (SAlterVnodeReq*)rpcMallocCont(contLen);
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      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 已提交
108 109 110
      SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_VNODE, pReq, contLen);
      ASSERT_NE(pRsp, nullptr);
      ASSERT_EQ(pRsp->code, 0);
111
    }
112
  }
113

114 115
  {
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
116
      int32_t contLen = sizeof(SDropVnodeReq);
S
Shengliang Guan 已提交
117

S
Shengliang Guan 已提交
118
      SDropVnodeReq* pReq = (SDropVnodeReq*)rpcMallocCont(contLen);
119 120 121 122 123 124 125
      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 已提交
126
      rpcMsg.contLen = sizeof(SDropVnodeReq);
H
Hongze Cheng 已提交
127
      rpcMsg.msgType = TDMT_DND_DROP_VNODE;
128

S
Shengliang Guan 已提交
129 130
      SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen);
      ASSERT_NE(pRsp, nullptr);
131 132 133 134 135 136
      if (i == 0) {
        ASSERT_EQ(pRsp->code, 0);
        test.Restart();
      } else {
        ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_NOT_DEPLOYED);
      }
137
    }
138 139
  }
}