stb.cpp 26.2 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

S
Shengliang Guan 已提交
25 26 27 28 29 30 31 32 33 34 35
  void* BuildCreateDbReq(const char* dbname, int32_t* pContLen);
  void* BuildDropDbReq(const char* dbname, int32_t* pContLen);
  void* BuildCreateStbReq(const char* stbname, int32_t* pContLen);
  void* BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen);
  void* BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen);
  void* BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname,
                                      int32_t* pContLen);
  void* BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes, int32_t* pContLen);
  void* BuildAlterStbAddColumnReq(const char* stbname, const char* colname, int32_t* pContLen);
  void* BuildAlterStbDropColumnReq(const char* stbname, const char* colname, int32_t* pContLen);
  void* BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes, int32_t* pContLen);
S
Shengliang Guan 已提交
36 37
};

S
Shengliang Guan 已提交
38
Testbase MndTestStb::test;
S
Shengliang Guan 已提交
39

S
Shengliang Guan 已提交
40
void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) {
S
Shengliang Guan 已提交
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
  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 已提交
69
void* MndTestStb::BuildDropDbReq(const char* dbname, int32_t* pContLen) {
S
Shengliang Guan 已提交
70 71 72 73 74 75 76 77 78
  int32_t contLen = sizeof(SDropDbReq);

  SDropDbReq* pReq = (SDropDbReq*)rpcMallocCont(contLen);
  strcpy(pReq->db, dbname);

  *pContLen = contLen;
  return pReq;
}

S
Shengliang Guan 已提交
79 80 81 82 83 84 85 86
void* MndTestStb::BuildCreateStbReq(const char* stbname, int32_t* pContLen) {
  SMCreateStbReq createReq = {0};
  createReq.numOfColumns = 2;
  createReq.numOfTags = 3;
  createReq.igExists = 0;
  createReq.pColumns = taosArrayInit(createReq.numOfColumns, sizeof(SField));
  createReq.pTags = taosArrayInit(createReq.numOfTags, sizeof(SField));
  strcpy(createReq.name, stbname);
S
Shengliang Guan 已提交
87

S
Shengliang Guan 已提交
88
  {
S
Shengliang Guan 已提交
89 90 91 92 93
    SField field = {0};
    field.bytes = 8;
    field.type = TSDB_DATA_TYPE_TIMESTAMP;
    strcpy(field.name, "ts");
    taosArrayPush(createReq.pColumns, &field);
S
Shengliang Guan 已提交
94 95 96
  }

  {
S
Shengliang Guan 已提交
97 98 99 100 101
    SField field = {0};
    field.bytes = 12;
    field.type = TSDB_DATA_TYPE_BINARY;
    strcpy(field.name, "col1");
    taosArrayPush(createReq.pColumns, &field);
S
Shengliang Guan 已提交
102 103
  }

S
Shengliang Guan 已提交
104
  {
S
Shengliang Guan 已提交
105 106 107 108 109
    SField field = {0};
    field.bytes = 2;
    field.type = TSDB_DATA_TYPE_TINYINT;
    strcpy(field.name, "tag1");
    taosArrayPush(createReq.pTags, &field);
S
Shengliang Guan 已提交
110
  }
S
Shengliang Guan 已提交
111

S
Shengliang Guan 已提交
112
  {
S
Shengliang Guan 已提交
113 114 115 116 117
    SField field = {0};
    field.bytes = 8;
    field.type = TSDB_DATA_TYPE_BIGINT;
    strcpy(field.name, "tag2");
    taosArrayPush(createReq.pTags, &field);
S
Shengliang Guan 已提交
118
  }
S
Shengliang Guan 已提交
119 120

  {
S
Shengliang Guan 已提交
121 122 123 124 125
    SField field = {0};
    field.bytes = 16;
    field.type = TSDB_DATA_TYPE_BINARY;
    strcpy(field.name, "tag3");
    taosArrayPush(createReq.pTags, &field);
S
Shengliang Guan 已提交
126
  }
S
Shengliang Guan 已提交
127

S
Shengliang Guan 已提交
128 129 130 131 132 133 134
  int32_t tlen = tSerializeSMCreateStbReq(NULL, &createReq);
  void*   pHead = rpcMallocCont(tlen);

  void* pBuf = pHead;
  tSerializeSMCreateStbReq(&pBuf, &createReq);
  *pContLen = tlen;
  return pHead;
S
Shengliang Guan 已提交
135
}
S
Shengliang Guan 已提交
136

S
Shengliang Guan 已提交
137 138 139 140 141 142
void* MndTestStb::BuildAlterStbAddTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_ADD_TAG;
S
Shengliang Guan 已提交
143

S
Shengliang Guan 已提交
144 145 146 147 148 149 150 151 152 153
  SField field = {0};
  field.bytes = 12;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, tagname);
  taosArrayPush(req.pFields, &field);

  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
154 155

  *pContLen = contLen;
S
Shengliang Guan 已提交
156
  return pHead;
S
Shengliang Guan 已提交
157 158
}

S
Shengliang Guan 已提交
159 160 161 162 163 164
void* MndTestStb::BuildAlterStbDropTagReq(const char* stbname, const char* tagname, int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_DROP_TAG;
S
Shengliang Guan 已提交
165

S
Shengliang Guan 已提交
166 167 168 169 170 171 172 173 174 175
  SField field = {0};
  field.bytes = 12;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, tagname);
  taosArrayPush(req.pFields, &field);

  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
176 177

  *pContLen = contLen;
S
Shengliang Guan 已提交
178
  return pHead;
S
Shengliang Guan 已提交
179 180
}

S
Shengliang Guan 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
void* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname,
                                                int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 2;
  req.pFields = taosArrayInit(2, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_UPDATE_TAG_NAME;

  SField field = {0};
  field.bytes = 12;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, tagname);
  taosArrayPush(req.pFields, &field);

  SField field2 = {0};
  field2.bytes = 12;
  field2.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field2.name, newtagname);
  taosArrayPush(req.pFields, &field2);

  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
205 206

  *pContLen = contLen;
S
Shengliang Guan 已提交
207
  return pHead;
S
Shengliang Guan 已提交
208 209
}

S
Shengliang Guan 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
void* MndTestStb::BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes,
                                                 int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_UPDATE_TAG_BYTES;

  SField field = {0};
  field.bytes = bytes;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, tagname);
  taosArrayPush(req.pFields, &field);

  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
228 229

  *pContLen = contLen;
S
Shengliang Guan 已提交
230
  return pHead;
S
Shengliang Guan 已提交
231 232
}

S
Shengliang Guan 已提交
233 234 235 236 237 238 239 240 241 242 243 244
void* MndTestStb::BuildAlterStbAddColumnReq(const char* stbname, const char* colname, int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_ADD_COLUMN;

  SField field = {0};
  field.bytes = 12;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, colname);
  taosArrayPush(req.pFields, &field);
S
Shengliang Guan 已提交
245

S
Shengliang Guan 已提交
246 247 248 249
  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
250 251

  *pContLen = contLen;
S
Shengliang Guan 已提交
252
  return pHead;
S
Shengliang Guan 已提交
253 254
}

S
Shengliang Guan 已提交
255 256 257 258 259 260 261 262 263 264 265 266
void* MndTestStb::BuildAlterStbDropColumnReq(const char* stbname, const char* colname, int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_DROP_COLUMN;

  SField field = {0};
  field.bytes = 12;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, colname);
  taosArrayPush(req.pFields, &field);
S
Shengliang Guan 已提交
267

S
Shengliang Guan 已提交
268 269 270 271
  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
272 273

  *pContLen = contLen;
S
Shengliang Guan 已提交
274
  return pHead;
S
Shengliang Guan 已提交
275 276
}

S
Shengliang Guan 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
void* MndTestStb::BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes,
                                                    int32_t* pContLen) {
  SMAltertbReq req = {0};
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES;

  SField field = {0};
  field.bytes = bytes;
  field.type = TSDB_DATA_TYPE_BINARY;
  strcpy(field.name, colname);
  taosArrayPush(req.pFields, &field);

  int32_t contLen = tSerializeSMAlterStbReq(NULL, &req);
  void*   pHead = rpcMallocCont(contLen);
  void*   pBuf = pHead;
  tSerializeSMAlterStbReq(&pBuf, &req);
S
Shengliang Guan 已提交
295 296

  *pContLen = contLen;
S
Shengliang Guan 已提交
297
  return pHead;
S
Shengliang Guan 已提交
298 299
}

S
Shengliang Guan 已提交
300 301 302 303 304
TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
  const char* dbname = "1.d1";
  const char* stbname = "1.d1.stb";

  {
S
Shengliang Guan 已提交
305 306 307
    int32_t  contLen = 0;
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
308 309 310 311 312
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
313 314 315
    int32_t  contLen = 0;
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 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 382 383 384
    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];
S
Shengliang Guan 已提交
385
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
S
Shengliang Guan 已提交
386
      EXPECT_EQ(pSchema->colId, 2);
S
Shengliang Guan 已提交
387
      EXPECT_EQ(pSchema->bytes, 12);
S
Shengliang Guan 已提交
388 389 390 391 392 393 394 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
      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);
  }

  {
S
Shengliang Guan 已提交
432 433
    SMDropStbReq dropReq = {0};
    strcpy(dropReq.name, stbname);
S
Shengliang Guan 已提交
434

S
Shengliang Guan 已提交
435 436 437 438
    int32_t contLen = tSerializeSMDropStbReq(NULL, &dropReq);
    void*   pHead = rpcMallocCont(contLen);
    void*   pBuf = pHead;
    tSerializeSMDropStbReq(&pBuf, &dropReq);
S
Shengliang Guan 已提交
439

S
Shengliang Guan 已提交
440
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pHead, contLen);
S
Shengliang Guan 已提交
441 442 443 444
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

S
Shengliang Guan 已提交
445 446 447 448 449 450
  {
    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    CHECK_META("show stables", 4);
    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 0);
  }
S
Shengliang Guan 已提交
451

S
Shengliang Guan 已提交
452
  {
S
Shengliang Guan 已提交
453 454 455
    int32_t  contLen = 0;
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
456 457 458
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
459
}
S
Shengliang Guan 已提交
460

S
Shengliang Guan 已提交
461 462 463
TEST_F(MndTestStb, 02_Alter_Stb_AddTag) {
  const char* dbname = "1.d2";
  const char* stbname = "1.d2.stb";
S
Shengliang Guan 已提交
464
  int32_t     contLen = 0;
S
Shengliang Guan 已提交
465 466

  {
S
Shengliang Guan 已提交
467 468
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
469 470 471
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
472

S
Shengliang Guan 已提交
473
  {
S
Shengliang Guan 已提交
474 475
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
476 477
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
478 479
  }

S
Shengliang Guan 已提交
480
  {
S
Shengliang Guan 已提交
481 482
    void*    pReq = BuildAlterStbAddTagReq("1.d3.stb", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
483 484 485 486
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
S
Shengliang Guan 已提交
487 488
    void*    pReq = BuildAlterStbAddTagReq("1.d2.stb3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
489 490 491 492
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
493 494
    void*    pReq = BuildAlterStbAddTagReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
495 496 497 498
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
499 500
    void*    pReq = BuildAlterStbAddTagReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
501 502 503 504
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
505 506
    void*    pReq = BuildAlterStbAddTagReq(stbname, "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
507 508 509 510 511 512 513 514 515 516 517
    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 已提交
518 519

  {
S
Shengliang Guan 已提交
520 521
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
522 523 524
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
525
}
S
Shengliang Guan 已提交
526 527 528 529 530 531 532

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

  {
S
Shengliang Guan 已提交
533 534
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
535 536 537 538
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
539 540
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
541 542 543 544
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
545 546
    void*    pReq = BuildAlterStbDropTagReq(stbname, "tag5", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
547 548 549 550
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
551 552
    void*    pReq = BuildAlterStbDropTagReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
553 554 555 556 557 558 559 560 561 562 563
    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);
  }
S
Shengliang Guan 已提交
564 565

  {
S
Shengliang Guan 已提交
566 567
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
568 569 570
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
571 572
}

S
Shengliang Guan 已提交
573
TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) {
S
Shengliang Guan 已提交
574 575 576 577 578
  const char* dbname = "1.d4";
  const char* stbname = "1.d4.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
579 580
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
581 582 583 584
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
585 586
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
587 588 589 590
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
591 592
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag5", "tag6", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
593 594 595 596
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
597 598
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "col1", "tag6", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
599 600 601 602
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
603 604
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
605 606 607 608
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
609 610
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
611 612 613
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }
  {
S
Shengliang Guan 已提交
614 615
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
616 617 618 619
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
620 621
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
622 623 624
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
625 626 627 628 629 630 631 632 633
    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);
  }

S
Shengliang Guan 已提交
634
  {
S
Shengliang Guan 已提交
635 636
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
637 638 639 640
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}
S
Shengliang Guan 已提交
641

S
Shengliang Guan 已提交
642
TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) {
S
Shengliang Guan 已提交
643 644 645 646 647
  const char* dbname = "1.d5";
  const char* stbname = "1.d5.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
648 649
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
650 651 652 653
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
654 655
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
656 657 658 659
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
660 661
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag5", 12, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
662 663 664 665
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
666 667
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag1", 13, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
668 669 670 671
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION);
  }

  {
S
Shengliang Guan 已提交
672 673
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag3", 8, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
674 675 676 677
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES);
  }

  {
S
Shengliang Guan 已提交
678 679
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag3", 20, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
680
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
681

S
Shengliang Guan 已提交
682 683 684 685 686 687 688 689
    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);
  }
S
Shengliang Guan 已提交
690 691

  {
S
Shengliang Guan 已提交
692 693
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
694 695 696 697 698 699 700 701 702 703 704
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}

TEST_F(MndTestStb, 06_Alter_Stb_AddColumn) {
  const char* dbname = "1.d6";
  const char* stbname = "1.d6.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
705 706
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
707 708 709 710 711
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
712 713
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
714 715 716 717 718
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
719 720
    void*    pReq = BuildAlterStbAddColumnReq("1.d7.stb", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
721 722 723 724
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
S
Shengliang Guan 已提交
725 726
    void*    pReq = BuildAlterStbAddColumnReq("1.d6.stb3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
727 728 729 730
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
731 732
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
733 734 735 736
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
737 738
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
739 740 741 742
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
743 744
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757
    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(3);
    CheckInt32(3);
  }

  {
S
Shengliang Guan 已提交
758 759
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
760 761 762 763 764 765 766 767 768 769 770
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}

TEST_F(MndTestStb, 07_Alter_Stb_DropColumn) {
  const char* dbname = "1.d7";
  const char* stbname = "1.d7.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
771 772
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
773 774 775 776
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
777 778
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
779 780 781 782
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
783 784
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
785 786 787 788
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
789 790
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
791 792 793 794
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_ALTER_OPTION);
  }

  {
S
Shengliang Guan 已提交
795 796
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "ts", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
797 798 799 800
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_ALTER_OPTION);
  }

  {
S
Shengliang Guan 已提交
801 802
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
803 804 805 806 807
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
808 809
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
810 811 812 813 814 815 816 817 818 819 820 821 822
    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);
  }

  {
S
Shengliang Guan 已提交
823 824
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
825 826 827 828 829 830 831 832 833 834 835
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}

TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) {
  const char* dbname = "1.d8";
  const char* stbname = "1.d8.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
836 837
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
838 839 840 841
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
842 843
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
844 845 846 847
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
848 849
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col5", 12, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
850 851 852 853
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
854 855
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "ts", 8, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
856 857 858 859
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION);
  }

  {
S
Shengliang Guan 已提交
860 861
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 8, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
862 863 864 865
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES);
  }

  {
S
Shengliang Guan 已提交
866 867
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", TSDB_MAX_BYTES_PER_ROW, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
868 869 870 871
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES);
  }

  {
S
Shengliang Guan 已提交
872 873
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 20, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
874 875 876 877 878 879 880 881 882 883 884 885
    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);
  }

  {
S
Shengliang Guan 已提交
886 887
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
888 889 890 891
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}