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

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
  SCreateDbReq createReq = {0};
  strcpy(createReq.db, dbname);
  createReq.numOfVgroups = 2;
  createReq.cacheBlockSize = 16;
  createReq.totalBlocks = 10;
  createReq.daysPerFile = 10;
  createReq.daysToKeep0 = 3650;
  createReq.daysToKeep1 = 3650;
  createReq.daysToKeep2 = 3650;
  createReq.minRows = 100;
  createReq.maxRows = 4096;
  createReq.commitTime = 3600;
  createReq.fsyncPeriod = 3000;
  createReq.walLevel = 1;
  createReq.precision = 0;
  createReq.compression = 2;
  createReq.replications = 1;
  createReq.quorum = 1;
  createReq.update = 0;
  createReq.cacheLastRow = 0;
  createReq.ignoreExist = 1;
S
Shengliang Guan 已提交
62

S
Shengliang Guan 已提交
63 64 65
  int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSCreateDbReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
66 67 68 69 70

  *pContLen = contLen;
  return pReq;
}

S
Shengliang Guan 已提交
71
void* MndTestStb::BuildDropDbReq(const char* dbname, int32_t* pContLen) {
S
Shengliang Guan 已提交
72 73
  SDropDbReq dropdbReq = {0};
  strcpy(dropdbReq.db, dbname);
S
Shengliang Guan 已提交
74

S
Shengliang Guan 已提交
75 76 77
  int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSDropDbReq(pReq, contLen, &dropdbReq);
S
Shengliang Guan 已提交
78 79 80 81 82

  *pContLen = contLen;
  return pReq;
}

S
Shengliang Guan 已提交
83 84 85 86 87 88 89 90
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 已提交
91

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

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

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

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

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

S
Shengliang Guan 已提交
132
  int32_t tlen = tSerializeSMCreateStbReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
133
  void*   pHead = rpcMallocCont(tlen);
S
Shengliang Guan 已提交
134 135
  tSerializeSMCreateStbReq(pHead, tlen, &createReq);
  tFreeSMCreateStbReq(&createReq);
S
Shengliang Guan 已提交
136 137
  *pContLen = tlen;
  return pHead;
S
Shengliang Guan 已提交
138
}
S
Shengliang Guan 已提交
139

S
Shengliang Guan 已提交
140 141 142 143 144 145
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 已提交
146

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

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

  *pContLen = contLen;
S
Shengliang Guan 已提交
158
  return pHead;
S
Shengliang Guan 已提交
159 160
}

S
Shengliang Guan 已提交
161 162 163 164 165 166
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 已提交
167

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

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

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

S
Shengliang Guan 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
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);

S
Shengliang Guan 已提交
202
  int32_t contLen = tSerializeSMAlterStbReq(NULL, 0, &req);
S
Shengliang Guan 已提交
203
  void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
204
  tSerializeSMAlterStbReq(pHead, contLen, &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
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);

S
Shengliang Guan 已提交
224
  int32_t contLen = tSerializeSMAlterStbReq(NULL, 0, &req);
S
Shengliang Guan 已提交
225
  void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
226
  tSerializeSMAlterStbReq(pHead, contLen, &req);
S
Shengliang Guan 已提交
227 228

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

S
Shengliang Guan 已提交
232 233 234 235 236 237 238 239 240 241 242 243
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 已提交
244

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

  *pContLen = contLen;
S
Shengliang Guan 已提交
250
  return pHead;
S
Shengliang Guan 已提交
251 252
}

S
Shengliang Guan 已提交
253 254 255 256 257 258 259 260 261 262 263 264
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 已提交
265

S
Shengliang Guan 已提交
266
  int32_t contLen = tSerializeSMAlterStbReq(NULL, 0, &req);
S
Shengliang Guan 已提交
267
  void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
268
  tSerializeSMAlterStbReq(pHead, contLen, &req);
S
Shengliang Guan 已提交
269 270

  *pContLen = contLen;
S
Shengliang Guan 已提交
271
  return pHead;
S
Shengliang Guan 已提交
272 273
}

S
Shengliang Guan 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287
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);

S
Shengliang Guan 已提交
288
  int32_t contLen = tSerializeSMAlterStbReq(NULL, 0, &req);
S
Shengliang Guan 已提交
289
  void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
290
  tSerializeSMAlterStbReq(pHead, contLen, &req);
S
Shengliang Guan 已提交
291 292

  *pContLen = contLen;
S
Shengliang Guan 已提交
293
  return pHead;
S
Shengliang Guan 已提交
294 295
}

S
Shengliang Guan 已提交
296 297 298 299 300
TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
  const char* dbname = "1.d1";
  const char* stbname = "1.d1.stb";

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

  {
S
Shengliang Guan 已提交
309 310 311
    int32_t  contLen = 0;
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    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 ------
  {
S
Shengliang Guan 已提交
334 335 336 337 338 339 340
    STableInfoReq infoReq = {0};
    strcpy(infoReq.dbFName, dbname);
    strcpy(infoReq.tbName, "stb");

    int32_t contLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSTableInfoReq(pReq, contLen, &infoReq);
S
Shengliang Guan 已提交
341 342 343 344 345

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

S
Shengliang Guan 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    STableMetaRsp metaRsp = {0};
    tDeserializeSTableMetaRsp(pMsg->pCont, pMsg->contLen, &metaRsp);

    EXPECT_STREQ(metaRsp.dbFName, dbname);
    EXPECT_STREQ(metaRsp.tbName, "stb");
    EXPECT_STREQ(metaRsp.stbName, "stb");
    EXPECT_EQ(metaRsp.numOfColumns, 2);
    EXPECT_EQ(metaRsp.numOfTags, 3);
    EXPECT_EQ(metaRsp.precision, TSDB_TIME_PRECISION_MILLI);
    EXPECT_EQ(metaRsp.tableType, TSDB_SUPER_TABLE);
    EXPECT_EQ(metaRsp.update, 0);
    EXPECT_EQ(metaRsp.sversion, 1);
    EXPECT_EQ(metaRsp.tversion, 0);
    EXPECT_GT(metaRsp.suid, 0);
    EXPECT_GT(metaRsp.tuid, 0);
    EXPECT_EQ(metaRsp.vgId, 0);
S
Shengliang Guan 已提交
362 363

    {
S
Shengliang Guan 已提交
364
      SSchema* pSchema = &metaRsp.pSchemas[0];
S
Shengliang Guan 已提交
365 366 367 368 369 370 371
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
      EXPECT_EQ(pSchema->colId, 1);
      EXPECT_EQ(pSchema->bytes, 8);
      EXPECT_STREQ(pSchema->name, "ts");
    }

    {
S
Shengliang Guan 已提交
372
      SSchema* pSchema = &metaRsp.pSchemas[1];
S
Shengliang Guan 已提交
373
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
S
Shengliang Guan 已提交
374
      EXPECT_EQ(pSchema->colId, 2);
S
Shengliang Guan 已提交
375
      EXPECT_EQ(pSchema->bytes, 12);
S
Shengliang Guan 已提交
376 377 378 379
      EXPECT_STREQ(pSchema->name, "col1");
    }

    {
S
Shengliang Guan 已提交
380
      SSchema* pSchema = &metaRsp.pSchemas[2];
S
Shengliang Guan 已提交
381 382 383 384 385 386 387
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TINYINT);
      EXPECT_EQ(pSchema->colId, 3);
      EXPECT_EQ(pSchema->bytes, 2);
      EXPECT_STREQ(pSchema->name, "tag1");
    }

    {
S
Shengliang Guan 已提交
388
      SSchema* pSchema = &metaRsp.pSchemas[3];
S
Shengliang Guan 已提交
389 390 391 392 393 394 395
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BIGINT);
      EXPECT_EQ(pSchema->colId, 4);
      EXPECT_EQ(pSchema->bytes, 8);
      EXPECT_STREQ(pSchema->name, "tag2");
    }

    {
S
Shengliang Guan 已提交
396
      SSchema* pSchema = &metaRsp.pSchemas[4];
S
Shengliang Guan 已提交
397 398 399 400 401
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
      EXPECT_EQ(pSchema->colId, 5);
      EXPECT_EQ(pSchema->bytes, 16);
      EXPECT_STREQ(pSchema->name, "tag3");
    }
S
Shengliang Guan 已提交
402 403

    tFreeSTableMetaRsp(&metaRsp);
S
Shengliang Guan 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
  }

  // 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 已提交
422 423
    SMDropStbReq dropReq = {0};
    strcpy(dropReq.name, stbname);
S
Shengliang Guan 已提交
424

S
Shengliang Guan 已提交
425
    int32_t contLen = tSerializeSMDropStbReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
426
    void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
427
    tSerializeSMDropStbReq(pHead, contLen, &dropReq);
S
Shengliang Guan 已提交
428

S
Shengliang Guan 已提交
429
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pHead, contLen);
S
Shengliang Guan 已提交
430 431 432 433
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

S
Shengliang Guan 已提交
434 435 436 437 438 439
  {
    test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname);
    CHECK_META("show stables", 4);
    test.SendShowRetrieveReq();
    EXPECT_EQ(test.GetShowRows(), 0);
  }
S
Shengliang Guan 已提交
440

S
Shengliang Guan 已提交
441
  {
S
Shengliang Guan 已提交
442 443 444
    int32_t  contLen = 0;
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
445 446 447
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
448
}
S
Shengliang Guan 已提交
449

S
Shengliang Guan 已提交
450 451 452
TEST_F(MndTestStb, 02_Alter_Stb_AddTag) {
  const char* dbname = "1.d2";
  const char* stbname = "1.d2.stb";
S
Shengliang Guan 已提交
453
  int32_t     contLen = 0;
S
Shengliang Guan 已提交
454 455

  {
S
Shengliang Guan 已提交
456 457
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
458 459 460
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
461

S
Shengliang Guan 已提交
462
  {
S
Shengliang Guan 已提交
463 464
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
465 466
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
467 468
  }

S
Shengliang Guan 已提交
469
  {
S
Shengliang Guan 已提交
470 471
    void*    pReq = BuildAlterStbAddTagReq("1.d3.stb", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
472 473 474 475
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
S
Shengliang Guan 已提交
476 477
    void*    pReq = BuildAlterStbAddTagReq("1.d2.stb3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
478 479 480 481
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
482 483
    void*    pReq = BuildAlterStbAddTagReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
484 485 486 487
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
488 489
    void*    pReq = BuildAlterStbAddTagReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
490 491 492 493
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
494 495
    void*    pReq = BuildAlterStbAddTagReq(stbname, "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
496 497 498 499 500 501 502 503 504 505 506
    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 已提交
507 508

  {
S
Shengliang Guan 已提交
509 510
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
511 512 513
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
514
}
S
Shengliang Guan 已提交
515 516 517 518 519 520 521

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 已提交
522 523
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
524 525 526 527
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
528 529
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
530 531 532 533
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
534 535
    void*    pReq = BuildAlterStbDropTagReq(stbname, "tag5", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
536 537 538 539
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
540 541
    void*    pReq = BuildAlterStbDropTagReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
542 543 544 545 546 547 548 549 550 551 552
    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 已提交
553 554

  {
S
Shengliang Guan 已提交
555 556
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
557 558 559
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
560 561
}

S
Shengliang Guan 已提交
562
TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) {
S
Shengliang Guan 已提交
563 564 565 566 567
  const char* dbname = "1.d4";
  const char* stbname = "1.d4.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
568 569
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
570 571 572 573
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
574 575
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
576 577 578 579
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
580 581
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag5", "tag6", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
582 583 584 585
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
586 587
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "col1", "tag6", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
588 589 590 591
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

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

  {
S
Shengliang Guan 已提交
598 599
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
600 601 602
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }
  {
S
Shengliang Guan 已提交
603 604
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &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_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
609 610
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
611 612 613
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
614 615 616 617 618 619 620 621 622
    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 已提交
623
  {
S
Shengliang Guan 已提交
624 625
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
626 627 628 629
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}
S
Shengliang Guan 已提交
630

S
Shengliang Guan 已提交
631
TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) {
S
Shengliang Guan 已提交
632 633 634 635 636
  const char* dbname = "1.d5";
  const char* stbname = "1.d5.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
637 638
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
639 640 641 642
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
643 644
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
645 646 647 648
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
649 650
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag5", 12, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
651 652 653 654
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
655 656
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag1", 13, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
657 658 659 660
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION);
  }

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

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

S
Shengliang Guan 已提交
671 672 673 674 675 676 677 678
    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 已提交
679 680

  {
S
Shengliang Guan 已提交
681 682
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
683 684 685 686 687 688 689 690 691 692 693
    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 已提交
694 695
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
696 697 698 699 700
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
701 702
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
703 704 705 706 707
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
708 709
    void*    pReq = BuildAlterStbAddColumnReq("1.d7.stb", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
710 711 712 713
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
S
Shengliang Guan 已提交
714 715
    void*    pReq = BuildAlterStbAddColumnReq("1.d6.stb3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
716 717 718 719
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
720 721
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
722 723 724 725
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
726 727
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
728 729 730 731
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
732 733
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
734 735 736 737 738 739 740 741 742 743 744 745 746
    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 已提交
747 748
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
749 750 751 752 753 754 755 756 757 758 759
    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 已提交
760 761
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
762 763 764 765
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
766 767
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
768 769 770 771
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
772 773
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
774 775 776 777
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
778 779
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
780 781 782 783
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_ALTER_OPTION);
  }

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

  {
S
Shengliang Guan 已提交
790 791
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
792 793 794 795 796
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
797 798
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
799 800 801 802 803 804 805 806 807 808 809 810 811
    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 已提交
812 813
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
814 815 816 817 818 819 820 821 822 823 824
    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 已提交
825 826
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
827 828 829 830
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
831 832
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
833 834 835 836
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
837 838
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col5", 12, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
839 840 841 842
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
843 844
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "ts", 8, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
845 846 847 848
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION);
  }

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

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

  {
S
Shengliang Guan 已提交
861 862
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 20, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
863 864 865 866 867 868 869 870 871 872 873 874
    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 已提交
875 876
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
877 878 879 880
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}