vnode.cpp 6.1 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", 9115); }
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 29 30
TEST_F(DndTestVnode, 01_Create_Vnode) {
  for (int i = 0; i < 3; ++i) {
    int32_t contLen = sizeof(SCreateVnodeReq);
31

S
Shengliang Guan 已提交
32 33 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 63 64 65 66 67 68
    SCreateVnodeReq* pReq = (SCreateVnodeReq*)rpcMallocCont(contLen);
    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(9527);
    }

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    if (i == 0) {
      ASSERT_EQ(pRsp->code, 0);
      test.Restart();
    } else {
      ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED);
69 70
    }
  }
S
Shengliang Guan 已提交
71 72 73 74 75
}

TEST_F(DndTestVnode, 02_ALTER_Vnode) {
  for (int i = 0; i < 3; ++i) {
    int32_t contLen = sizeof(SAlterVnodeReq);
76

S
Shengliang Guan 已提交
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    SAlterVnodeReq* pReq = (SAlterVnodeReq*)rpcMallocCont(contLen);
    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(9527);
    }

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_VNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}

TEST_F(DndTestVnode, 03_Create_Stb) {
  for (int i = 0; i < 1; ++i) {
    SVCreateTbReq req = {0};
    req.ver = 0;
    req.name = (char*)"stb1";
    req.ttl = 0;
    req.keep = 0;
    req.type = TD_SUPER_TABLE;

    SSchema schemas[5] = {0};
    {
      SSchema* pSchema = &schemas[0];
      pSchema->bytes = htonl(8);
      pSchema->type = TSDB_DATA_TYPE_TIMESTAMP;
      strcpy(pSchema->name, "ts");
    }

    {
      SSchema* pSchema = &schemas[1];
      pSchema->bytes = htonl(4);
      pSchema->type = TSDB_DATA_TYPE_INT;
      strcpy(pSchema->name, "col1");
    }

    {
      SSchema* pSchema = &schemas[2];
      pSchema->bytes = htonl(2);
      pSchema->type = TSDB_DATA_TYPE_TINYINT;
      strcpy(pSchema->name, "tag1");
    }

    {
      SSchema* pSchema = &schemas[3];
      pSchema->bytes = htonl(8);
      pSchema->type = TSDB_DATA_TYPE_BIGINT;
      strcpy(pSchema->name, "tag2");
    }

    {
      SSchema* pSchema = &schemas[4];
      pSchema->bytes = htonl(16);
      pSchema->type = TSDB_DATA_TYPE_BINARY;
      strcpy(pSchema->name, "tag3");
    }

    req.stbCfg.suid = 9527;
    req.stbCfg.nCols = 2;
    req.stbCfg.pSchema = &schemas[0];
    req.stbCfg.nTagCols = 3;
    req.stbCfg.pTagSchema = &schemas[2];

    int32_t   bsize = tSerializeSVCreateTbReq(NULL, &req);
    void*     buf = rpcMallocCont(sizeof(SMsgHead) + bsize);
    SMsgHead* pMsgHead = (SMsgHead*)buf;

    pMsgHead->contLen = htonl(sizeof(SMsgHead) + bsize);
    pMsgHead->vgId = htonl(2);

    void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
    tSerializeSVCreateTbReq(&pBuf, &req);

    int32_t contLen = sizeof(SMsgHead) + bsize;

    SRpcMsg* pRsp = test.SendReq(TDMT_VND_CREATE_STB, buf, contLen);
    ASSERT_NE(pRsp, nullptr);
    if (i == 0) {
      ASSERT_EQ(pRsp->code, 0);
      test.Restart();
    } else {
      ASSERT_EQ(pRsp->code, TSDB_CODE_TDB_TABLE_ALREADY_EXIST);
    }
  }
}

TEST_F(DndTestVnode, 04_ALTER_Stb) {
#if 0
189 190
  {
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
191
      SRpcMsg* pRsp = test.SendReq(TDMT_VND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
192 193
      ASSERT_NE(pRsp, nullptr);
      ASSERT_EQ(pRsp->code, 0);
194
    }
195
  }
S
Shengliang Guan 已提交
196 197
#endif
}
198

S
Shengliang Guan 已提交
199 200
TEST_F(DndTestVnode, 05_DROP_Stb) {
#if 0
201 202
  {
    for (int i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
203
      SRpcMsg* pRsp = test.SendReq(TDMT_VND_DROP_STB, pReq, contLen);
S
Shengliang Guan 已提交
204
      ASSERT_NE(pRsp, nullptr);
205 206 207 208
      if (i == 0) {
        ASSERT_EQ(pRsp->code, 0);
        test.Restart();
      } else {
S
Shengliang Guan 已提交
209
        ASSERT_EQ(pRsp->code, TSDB_CODE_TDB_INVALID_TABLE_ID);
210
      }
211
    }
212
  }
S
Shengliang Guan 已提交
213
#endif
214
}
S
Shengliang Guan 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240

TEST_F(DndTestVnode, 06_DROP_Vnode) {
  for (int i = 0; i < 3; ++i) {
    int32_t contLen = sizeof(SDropVnodeReq);

    SDropVnodeReq* pReq = (SDropVnodeReq*)rpcMallocCont(contLen);
    pReq->vgId = htonl(2);
    pReq->dnodeId = htonl(1);
    strcpy(pReq->db, "1.d1");
    pReq->dbUid = htobe64(9527);

    SRpcMsg rpcMsg = {0};
    rpcMsg.pCont = pReq;
    rpcMsg.contLen = sizeof(SDropVnodeReq);
    rpcMsg.msgType = TDMT_DND_DROP_VNODE;

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    if (i == 0) {
      ASSERT_EQ(pRsp->code, 0);
      test.Restart();
    } else {
      ASSERT_EQ(pRsp->code, TSDB_CODE_DND_VNODE_NOT_DEPLOYED);
    }
  }
}