stb.cpp 15.0 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3
/**
 * @file stb.cpp
 * @author slguan (slguan@taosdata.com)
S
Shengliang Guan 已提交
4 5 6
 * @brief MNODE module stb tests
 * @version 1.0
 * @date 2022-01-12
S
Shengliang Guan 已提交
7
 *
S
Shengliang Guan 已提交
8
 * @copyright Copyright (c) 2022
S
Shengliang Guan 已提交
9 10 11
 *
 */

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

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

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

 public:
  void SetUp() override {}
  void TearDown() override {}
S
Shengliang Guan 已提交
24 25 26

  SCreateDbReq*   BuildCreateDbReq(const char* dbname, int32_t* pContLen);
  SMCreateStbReq* BuildCreateStbReq(const char* stbname, int32_t* pContLen);
S
Shengliang Guan 已提交
27 28 29 30 31 32
  SMAltertbReq*   BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen);
  SMAltertbReq*   BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen);
  SMAltertbReq*   BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname,
                                                int32_t* pContLen);
  SMAltertbReq*   BuildAlterStbDUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes,
                                                  int32_t* pContLen);
S
Shengliang Guan 已提交
33 34
};

S
Shengliang Guan 已提交
35
Testbase MndTestStb::test;
S
Shengliang Guan 已提交
36

S
Shengliang Guan 已提交
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
SCreateDbReq* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) {
  int32_t contLen = sizeof(SCreateDbReq);

  SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen);
  strcpy(pReq->db, dbname);
  pReq->numOfVgroups = 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->maxRows = htonl(4096);
  pReq->commitTime = htonl(3600);
  pReq->fsyncPeriod = htonl(3000);
  pReq->walLevel = 1;
  pReq->precision = 0;
  pReq->compression = 2;
  pReq->replications = 1;
  pReq->quorum = 1;
  pReq->update = 0;
  pReq->cacheLastRow = 0;
  pReq->ignoreExist = 1;

  *pContLen = contLen;
  return pReq;
}

S
Shengliang Guan 已提交
66
SMCreateStbReq* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pContLen) {
S
Shengliang Guan 已提交
67 68 69 70 71 72 73 74 75
  int32_t cols = 2;
  int32_t tags = 3;
  int32_t contLen = (tags + cols) * sizeof(SSchema) + sizeof(SMCreateStbReq);

  SMCreateStbReq* pReq = (SMCreateStbReq*)rpcMallocCont(contLen);
  strcpy(pReq->name, stbname);
  pReq->numOfTags = htonl(tags);
  pReq->numOfColumns = htonl(cols);

S
Shengliang Guan 已提交
76
  {
S
Shengliang Guan 已提交
77 78 79 80
    SSchema* pSchema = &pReq->pSchemas[0];
    pSchema->bytes = htonl(8);
    pSchema->type = TSDB_DATA_TYPE_TIMESTAMP;
    strcpy(pSchema->name, "ts");
S
Shengliang Guan 已提交
81 82 83
  }

  {
S
Shengliang Guan 已提交
84 85 86 87
    SSchema* pSchema = &pReq->pSchemas[1];
    pSchema->bytes = htonl(4);
    pSchema->type = TSDB_DATA_TYPE_INT;
    strcpy(pSchema->name, "col1");
S
Shengliang Guan 已提交
88 89
  }

S
Shengliang Guan 已提交
90 91 92 93 94 95
  {
    SSchema* pSchema = &pReq->pSchemas[2];
    pSchema->bytes = htonl(2);
    pSchema->type = TSDB_DATA_TYPE_TINYINT;
    strcpy(pSchema->name, "tag1");
  }
S
Shengliang Guan 已提交
96

S
Shengliang Guan 已提交
97 98 99 100 101 102
  {
    SSchema* pSchema = &pReq->pSchemas[3];
    pSchema->bytes = htonl(8);
    pSchema->type = TSDB_DATA_TYPE_BIGINT;
    strcpy(pSchema->name, "tag2");
  }
S
Shengliang Guan 已提交
103 104

  {
S
Shengliang Guan 已提交
105 106 107 108
    SSchema* pSchema = &pReq->pSchemas[4];
    pSchema->bytes = htonl(16);
    pSchema->type = TSDB_DATA_TYPE_BINARY;
    strcpy(pSchema->name, "tag3");
S
Shengliang Guan 已提交
109
  }
S
Shengliang Guan 已提交
110

S
Shengliang Guan 已提交
111 112 113
  *pContLen = contLen;
  return pReq;
}
S
Shengliang Guan 已提交
114

S
Shengliang Guan 已提交
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
  const char* dbname = "1.d1";
  const char* stbname = "1.d1.stb";

  {
    int32_t       contLen = 0;
    SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
    int32_t         contLen = 0;
    SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg*        pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    CHECK_META("show stables", 4);
    CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
    CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
    CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns");
    CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags");

    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 1);
    CheckBinary("stb", TSDB_TABLE_NAME_LEN);
    CheckTimestamp();
    CheckInt32(2);
    CheckInt32(3);
  }

  // ----- meta ------
  {
    int32_t        contLen = sizeof(STableInfoReq);
    STableInfoReq* pReq = (STableInfoReq*)rpcMallocCont(contLen);
    strcpy(pReq->dbFName, dbname);
    strcpy(pReq->tbName, "stb");

    SRpcMsg* pMsg = test.SendReq(TDMT_MND_STB_META, pReq, contLen);
    ASSERT_NE(pMsg, nullptr);
    ASSERT_EQ(pMsg->code, 0);

    STableMetaRsp* pRsp = (STableMetaRsp*)pMsg->pCont;
    pRsp->numOfTags = htonl(pRsp->numOfTags);
    pRsp->numOfColumns = htonl(pRsp->numOfColumns);
    pRsp->sversion = htonl(pRsp->sversion);
    pRsp->tversion = htonl(pRsp->tversion);
    pRsp->suid = be64toh(pRsp->suid);
    pRsp->tuid = be64toh(pRsp->tuid);
    pRsp->vgId = be64toh(pRsp->vgId);
    for (int32_t i = 0; i < pRsp->numOfTags + pRsp->numOfColumns; ++i) {
      SSchema* pSchema = &pRsp->pSchema[i];
      pSchema->colId = htonl(pSchema->colId);
      pSchema->bytes = htonl(pSchema->bytes);
    }

    EXPECT_STREQ(pRsp->dbFName, dbname);
    EXPECT_STREQ(pRsp->tbName, "stb");
    EXPECT_STREQ(pRsp->stbName, "stb");
    EXPECT_EQ(pRsp->numOfColumns, 2);
    EXPECT_EQ(pRsp->numOfTags, 3);
    EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
    EXPECT_EQ(pRsp->tableType, TSDB_SUPER_TABLE);
    EXPECT_EQ(pRsp->update, 0);
    EXPECT_EQ(pRsp->sversion, 1);
    EXPECT_EQ(pRsp->tversion, 0);
    EXPECT_GT(pRsp->suid, 0);
    EXPECT_GT(pRsp->tuid, 0);
    EXPECT_EQ(pRsp->vgId, 0);

    {
      SSchema* pSchema = &pRsp->pSchema[0];
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
      EXPECT_EQ(pSchema->colId, 1);
      EXPECT_EQ(pSchema->bytes, 8);
      EXPECT_STREQ(pSchema->name, "ts");
    }

    {
      SSchema* pSchema = &pRsp->pSchema[1];
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
      EXPECT_EQ(pSchema->colId, 2);
      EXPECT_EQ(pSchema->bytes, 4);
      EXPECT_STREQ(pSchema->name, "col1");
    }

    {
      SSchema* pSchema = &pRsp->pSchema[2];
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TINYINT);
      EXPECT_EQ(pSchema->colId, 3);
      EXPECT_EQ(pSchema->bytes, 2);
      EXPECT_STREQ(pSchema->name, "tag1");
    }

    {
      SSchema* pSchema = &pRsp->pSchema[3];
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BIGINT);
      EXPECT_EQ(pSchema->colId, 4);
      EXPECT_EQ(pSchema->bytes, 8);
      EXPECT_STREQ(pSchema->name, "tag2");
    }

    {
      SSchema* pSchema = &pRsp->pSchema[4];
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
      EXPECT_EQ(pSchema->colId, 5);
      EXPECT_EQ(pSchema->bytes, 16);
      EXPECT_STREQ(pSchema->name, "tag3");
    }
  }

  // restart
  test.Restart();

  {
    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    CHECK_META("show stables", 4);
    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 1);

    CheckBinary("stb", TSDB_TABLE_NAME_LEN);
    CheckTimestamp();
    CheckInt32(2);
    CheckInt32(3);
  }

  {
    int32_t contLen = sizeof(SMDropStbReq);

    SMDropStbReq* pReq = (SMDropStbReq*)rpcMallocCont(contLen);
    strcpy(pReq->name, stbname);

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

  test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
  CHECK_META("show stables", 4);
  test.SendShowRetrieveReq();
  EXPECT_EQ(test.GetShowRows(), 0);
}

SMAltertbReq* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
  int32_t       contLen = sizeof(SMAltertbReq) + sizeof(SSchema);
  SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen);
  strcpy(pReq->name, stbname);
  pReq->numOfSchemas = htonl(1);
  pReq->alterType = TSDB_ALTER_TABLE_ADD_TAG;

  SSchema* pSchema = &pReq->pSchemas[0];
  pSchema->bytes = htonl(12);
  pSchema->type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema->name, tagname);

  *pContLen = contLen;
  return pReq;
}

SMAltertbReq* MndTestStb::BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
  int32_t       contLen = sizeof(SMAltertbReq) + sizeof(SSchema);
  SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen);
  strcpy(pReq->name, stbname);
  pReq->numOfSchemas = htonl(1);
  pReq->alterType = TSDB_ALTER_TABLE_DROP_TAG;

  SSchema* pSchema = &pReq->pSchemas[0];
  pSchema->bytes = htonl(12);
  pSchema->type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema->name, tagname);

  *pContLen = contLen;
  return pReq;
}

SMAltertbReq* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname,
                                                        const char* newtagname, int32_t* pContLen) {
  int32_t       contLen = sizeof(SMAltertbReq) + 2 * sizeof(SSchema);
  SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen);
  strcpy(pReq->name, stbname);
  pReq->numOfSchemas = htonl(1);
  pReq->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_NAME;

  SSchema* pSchema = &pReq->pSchemas[0];
  pSchema->bytes = htonl(12);
  pSchema->type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema->name, tagname);

  pSchema = &pReq->pSchemas[1];
  pSchema->bytes = htonl(12);
  pSchema->type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema->name, newtagname);

  *pContLen = contLen;
  return pReq;
}

SMAltertbReq* MndTestStb::BuildAlterStbDUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes,
                                                          int32_t* pContLen) {
S
Shengliang Guan 已提交
319 320 321 322
  int32_t       contLen = sizeof(SMAltertbReq) + sizeof(SSchema);
  SMAltertbReq* pReq = (SMAltertbReq*)rpcMallocCont(contLen);
  strcpy(pReq->name, stbname);
  pReq->numOfSchemas = htonl(1);
S
Shengliang Guan 已提交
323
  pReq->alterType = TSDB_ALTER_TABLE_DROP_TAG;
S
Shengliang Guan 已提交
324 325

  SSchema* pSchema = &pReq->pSchemas[0];
S
Shengliang Guan 已提交
326 327 328
  pSchema->bytes = htonl(bytes);
  pSchema->type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema->name, tagname);
S
Shengliang Guan 已提交
329 330 331 332

  *pContLen = contLen;
  return pReq;
}
S
Shengliang Guan 已提交
333

S
Shengliang Guan 已提交
334 335 336
TEST_F(MndTestStb, 02_Alter_Stb_AddTag) {
  const char* dbname = "1.d2";
  const char* stbname = "1.d2.stb";
S
Shengliang Guan 已提交
337 338

  {
S
Shengliang Guan 已提交
339 340 341 342 343 344
    int32_t       contLen = 0;
    SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
345

S
Shengliang Guan 已提交
346 347 348 349
  {
    int32_t         contLen = 0;
    SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg*        pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
350 351
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
352 353
  }

S
Shengliang Guan 已提交
354 355
  int32_t contLen = 0;

S
Shengliang Guan 已提交
356
  {
S
Shengliang Guan 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    SMAltertbReq* pReq = BuildAlterStbAddTagReq("1.d3.stb", "tag4", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbAddTagReq("1.d2.stb3", "tag4", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbAddTagReq(stbname, "tag3", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbAddTagReq(stbname, "col1", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbAddTagReq(stbname, "tag4", &contLen);
S
Shengliang Guan 已提交
382 383 384 385 386 387 388 389 390 391 392 393
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 1);
    CheckBinary("stb", TSDB_TABLE_NAME_LEN);
    CheckTimestamp();
    CheckInt32(2);
    CheckInt32(4);
  }
S
Shengliang Guan 已提交
394
}
S
Shengliang Guan 已提交
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495

TEST_F(MndTestStb, 03_Alter_Stb_DropTag) {
  const char* dbname = "1.d3";
  const char* stbname = "1.d3.stb";
  int32_t     contLen = 0;

  {
    SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
    SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg*        pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbDropTagReq(stbname, "tag5", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbDropTagReq(stbname, "tag3", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 1);
    CheckBinary("stb", TSDB_TABLE_NAME_LEN);
    CheckTimestamp();
    CheckInt32(2);
    CheckInt32(2);
  }
}

TEST_F(MndTestStb, 04_Alter_Stb_AddTagName) {
  const char* dbname = "1.d4";
  const char* stbname = "1.d4.stb";
  int32_t     contLen = 0;

  {
    SCreateDbReq* pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
    SMCreateStbReq* pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg*        pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag5", "tag6", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbUpdateTagNameReq(stbname, "col1", "tag6", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "col1", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }
  {
    SMAltertbReq* pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
    SMAltertbReq* pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag4", &contLen);
    SRpcMsg*      pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 1);
    CheckBinary("stb", TSDB_TABLE_NAME_LEN);
    CheckTimestamp();
    CheckInt32(2);
    CheckInt32(3);
  }
}