stb.cpp 24.9 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:
16
  static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "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
  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);
35
  void* BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes, int32_t* pContLen, int32_t verInBlock);
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
  SCreateDbReq createReq = {0};
  strcpy(createReq.db, dbname);
  createReq.numOfVgroups = 2;
S
Shengliang Guan 已提交
44 45 46
  createReq.buffer = -1;
  createReq.pageSize = -1;
  createReq.pages = -1;
S
Shengliang Guan 已提交
47 48 49 50
  createReq.daysPerFile = 1000;
  createReq.daysToKeep0 = 3650;
  createReq.daysToKeep1 = 3650;
  createReq.daysToKeep2 = 3650;
S
Shengliang Guan 已提交
51 52 53 54 55 56 57
  createReq.minRows = 100;
  createReq.maxRows = 4096;
  createReq.fsyncPeriod = 3000;
  createReq.walLevel = 1;
  createReq.precision = 0;
  createReq.compression = 2;
  createReq.replications = 1;
S
Shengliang Guan 已提交
58
  createReq.strict = 1;
S
Shengliang Guan 已提交
59 60
  createReq.cacheLastRow = 0;
  createReq.ignoreExist = 1;
S
Shengliang Guan 已提交
61

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

  *pContLen = contLen;
  return pReq;
}

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

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

  *pContLen = contLen;
  return pReq;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

S
Shengliang Guan 已提交
181 182
void* MndTestStb::BuildAlterStbUpdateTagNameReq(const char* stbname, const char* tagname, const char* newtagname,
                                                int32_t* pContLen) {
S
Shengliang Guan 已提交
183
  SMAlterStbReq req = {0};
S
Shengliang Guan 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  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 已提交
201
  int32_t contLen = tSerializeSMAlterStbReq(NULL, 0, &req);
S
Shengliang Guan 已提交
202
  void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
203
  tSerializeSMAlterStbReq(pHead, contLen, &req);
S
Shengliang Guan 已提交
204 205

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

S
Shengliang Guan 已提交
209 210
void* MndTestStb::BuildAlterStbUpdateTagBytesReq(const char* stbname, const char* tagname, int32_t bytes,
                                                 int32_t* pContLen) {
S
Shengliang Guan 已提交
211
  SMAlterStbReq req = {0};
S
Shengliang Guan 已提交
212 213 214 215 216 217 218 219 220 221 222
  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 已提交
223
  int32_t contLen = tSerializeSMAlterStbReq(NULL, 0, &req);
S
Shengliang Guan 已提交
224
  void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
225
  tSerializeSMAlterStbReq(pHead, contLen, &req);
S
Shengliang Guan 已提交
226 227

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

S
Shengliang Guan 已提交
231
void* MndTestStb::BuildAlterStbAddColumnReq(const char* stbname, const char* colname, int32_t* pContLen) {
S
Shengliang Guan 已提交
232
  SMAlterStbReq req = {0};
S
Shengliang Guan 已提交
233 234 235 236 237 238 239 240 241 242
  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 已提交
243

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

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

S
Shengliang Guan 已提交
252
void* MndTestStb::BuildAlterStbDropColumnReq(const char* stbname, const char* colname, int32_t* pContLen) {
S
Shengliang Guan 已提交
253
  SMAlterStbReq req = {0};
S
Shengliang Guan 已提交
254 255 256 257 258 259 260 261 262 263
  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 已提交
264

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

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

S
Shengliang Guan 已提交
273
void* MndTestStb::BuildAlterStbUpdateColumnBytesReq(const char* stbname, const char* colname, int32_t bytes,
274
                                                    int32_t* pContLen, int32_t verInBlock) {
S
Shengliang Guan 已提交
275
  SMAlterStbReq req = {0};
S
Shengliang Guan 已提交
276 277 278 279
  strcpy(req.name, stbname);
  req.numOfFields = 1;
  req.pFields = taosArrayInit(1, sizeof(SField));
  req.alterType = TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES;
280 281
  req.tagVer = verInBlock;
  req.colVer = verInBlock;
S
Shengliang Guan 已提交
282 283 284 285 286 287 288

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

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

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

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

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

  {
S
Shengliang Guan 已提交
310 311 312
    int32_t  contLen = 0;
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
313 314 315 316 317
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
318
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
319 320 321 322 323
    EXPECT_EQ(test.GetShowRows(), 1);
  }

  // ----- meta ------
  {
S
Shengliang Guan 已提交
324 325 326 327 328 329 330
    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 已提交
331

D
dapan1121 已提交
332
    SRpcMsg* pMsg = test.SendReq(TDMT_MND_TABLE_META, pReq, contLen);
S
Shengliang Guan 已提交
333 334 335
    ASSERT_NE(pMsg, nullptr);
    ASSERT_EQ(pMsg->code, 0);

S
Shengliang Guan 已提交
336 337 338 339 340 341 342 343 344 345 346
    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.sversion, 1);
D
dapan1121 已提交
347
    EXPECT_EQ(metaRsp.tversion, 1);
S
Shengliang Guan 已提交
348 349 350
    EXPECT_GT(metaRsp.suid, 0);
    EXPECT_GT(metaRsp.tuid, 0);
    EXPECT_EQ(metaRsp.vgId, 0);
S
Shengliang Guan 已提交
351 352

    {
S
Shengliang Guan 已提交
353
      SSchema* pSchema = &metaRsp.pSchemas[0];
S
Shengliang Guan 已提交
354 355 356 357 358 359 360
      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 已提交
361
      SSchema* pSchema = &metaRsp.pSchemas[1];
S
Shengliang Guan 已提交
362
      EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
S
Shengliang Guan 已提交
363
      EXPECT_EQ(pSchema->colId, 2);
S
Shengliang Guan 已提交
364
      EXPECT_EQ(pSchema->bytes, 12);
S
Shengliang Guan 已提交
365 366 367 368
      EXPECT_STREQ(pSchema->name, "col1");
    }

    {
S
Shengliang Guan 已提交
369
      SSchema* pSchema = &metaRsp.pSchemas[2];
S
Shengliang Guan 已提交
370 371 372 373 374 375 376
      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 已提交
377
      SSchema* pSchema = &metaRsp.pSchemas[3];
S
Shengliang Guan 已提交
378 379 380 381 382 383 384
      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 已提交
385
      SSchema* pSchema = &metaRsp.pSchemas[4];
S
Shengliang Guan 已提交
386 387 388 389 390
      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 已提交
391 392

    tFreeSTableMetaRsp(&metaRsp);
S
Shengliang Guan 已提交
393 394 395 396 397 398
  }

  // restart
  test.Restart();

  {
S
Shengliang Guan 已提交
399
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
400 401 402 403
    EXPECT_EQ(test.GetShowRows(), 1);
  }

  {
S
Shengliang Guan 已提交
404 405
    SMDropStbReq dropReq = {0};
    strcpy(dropReq.name, stbname);
S
Shengliang Guan 已提交
406

S
Shengliang Guan 已提交
407
    int32_t contLen = tSerializeSMDropStbReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
408
    void*   pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
409
    tSerializeSMDropStbReq(pHead, contLen, &dropReq);
S
Shengliang Guan 已提交
410

S
Shengliang Guan 已提交
411
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pHead, contLen);
S
Shengliang Guan 已提交
412 413 414 415
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

S
Shengliang Guan 已提交
416
  {
S
Shengliang Guan 已提交
417
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
418 419
    EXPECT_EQ(test.GetShowRows(), 0);
  }
S
Shengliang Guan 已提交
420

S
Shengliang Guan 已提交
421
  {
S
Shengliang Guan 已提交
422 423 424
    int32_t  contLen = 0;
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
425 426 427
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
428
}
S
Shengliang Guan 已提交
429

S
Shengliang Guan 已提交
430 431 432
TEST_F(MndTestStb, 02_Alter_Stb_AddTag) {
  const char* dbname = "1.d2";
  const char* stbname = "1.d2.stb";
S
Shengliang Guan 已提交
433
  int32_t     contLen = 0;
S
Shengliang Guan 已提交
434 435

  {
S
Shengliang Guan 已提交
436 437
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
438 439 440
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
441

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

S
Shengliang Guan 已提交
449
  {
S
Shengliang Guan 已提交
450 451
    void*    pReq = BuildAlterStbAddTagReq("1.d3.stb", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
452 453 454 455
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
S
Shengliang Guan 已提交
456 457
    void*    pReq = BuildAlterStbAddTagReq("1.d2.stb3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
458 459 460 461
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
462 463
    void*    pReq = BuildAlterStbAddTagReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
464 465 466 467
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
468 469
    void*    pReq = BuildAlterStbAddTagReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
470 471 472 473
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
474 475
    void*    pReq = BuildAlterStbAddTagReq(stbname, "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
476 477 478
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
479
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
480
  }
S
Shengliang Guan 已提交
481 482

  {
S
Shengliang Guan 已提交
483 484
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
485 486 487
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
488
}
S
Shengliang Guan 已提交
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;

  {
S
Shengliang Guan 已提交
496 497
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
498 499 500 501
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
502 503
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
504 505 506 507
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
508 509
    void*    pReq = BuildAlterStbDropTagReq(stbname, "tag5", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
510 511 512 513
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
514 515
    void*    pReq = BuildAlterStbDropTagReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
516 517 518
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
519
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
520 521
    EXPECT_EQ(test.GetShowRows(), 1);
  }
S
Shengliang Guan 已提交
522 523

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

S
Shengliang Guan 已提交
531
TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) {
S
Shengliang Guan 已提交
532 533 534 535 536
  const char* dbname = "1.d4";
  const char* stbname = "1.d4.stb";
  int32_t     contLen = 0;

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

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

  {
S
Shengliang Guan 已提交
549 550
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag5", "tag6", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
551 552 553 554
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
555 556
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "col1", "tag6", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
557 558 559 560
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
561 562
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
563 564 565 566
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
567 568
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
569 570 571
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }
  {
S
Shengliang Guan 已提交
572 573
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
574 575 576 577
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
578 579
    void*    pReq = BuildAlterStbUpdateTagNameReq(stbname, "tag3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
580 581 582
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
583
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
584 585 586
    EXPECT_EQ(test.GetShowRows(), 1);
  }

S
Shengliang Guan 已提交
587
  {
S
Shengliang Guan 已提交
588 589
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
590 591 592 593
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
}
S
Shengliang Guan 已提交
594

S
Shengliang Guan 已提交
595
TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) {
S
Shengliang Guan 已提交
596 597 598 599 600
  const char* dbname = "1.d5";
  const char* stbname = "1.d5.stb";
  int32_t     contLen = 0;

  {
S
Shengliang Guan 已提交
601 602
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
603 604 605 606
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
607 608
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
609 610 611 612
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
613 614
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag5", 12, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
615 616 617 618
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
619 620
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag1", 13, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
621 622 623 624
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION);
  }

  {
S
Shengliang Guan 已提交
625 626
    void*    pReq = BuildAlterStbUpdateTagBytesReq(stbname, "tag3", 8, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
627 628 629 630
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES);
  }

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

S
Shengliang Guan 已提交
635
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
636 637
    EXPECT_EQ(test.GetShowRows(), 1);
  }
S
Shengliang Guan 已提交
638 639

  {
S
Shengliang Guan 已提交
640 641
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
642 643 644 645 646 647 648 649 650 651 652
    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 已提交
653 654
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
655 656 657 658 659
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
660 661
    void*    pReq = BuildCreateStbReq(stbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
S
Shengliang Guan 已提交
662 663 664 665 666
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
667 668
    void*    pReq = BuildAlterStbAddColumnReq("1.d7.stb", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
669 670 671 672
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
  }

  {
S
Shengliang Guan 已提交
673 674
    void*    pReq = BuildAlterStbAddColumnReq("1.d6.stb3", "tag4", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
675 676 677 678
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_STB_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
679 680
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "tag3", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
681 682 683 684
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TAG_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
685 686
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
687 688 689 690
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_ALREADY_EXIST);
  }

  {
S
Shengliang Guan 已提交
691 692
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
693 694 695
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
696
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
697 698 699 700
    EXPECT_EQ(test.GetShowRows(), 1);
  }

  {
S
Shengliang Guan 已提交
701 702
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
703 704 705 706 707 708 709 710 711 712 713
    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 已提交
714 715
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
716 717 718 719
    ASSERT_EQ(pRsp->code, 0);
  }

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

  {
S
Shengliang Guan 已提交
726 727
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col4", &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_NOT_EXIST);
  }

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

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

  {
S
Shengliang Guan 已提交
744 745
    void*    pReq = BuildAlterStbAddColumnReq(stbname, "col2", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
746 747 748 749 750
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
751 752
    void*    pReq = BuildAlterStbDropColumnReq(stbname, "col1", &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
753 754 755
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
756
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
757 758 759 760
    EXPECT_EQ(test.GetShowRows(), 1);
  }

  {
S
Shengliang Guan 已提交
761 762
    void*    pReq = BuildDropDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
S
Shengliang Guan 已提交
763 764 765 766 767 768 769 770 771 772 773
    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 已提交
774 775
    void*    pReq = BuildCreateDbReq(dbname, &contLen);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
S
Shengliang Guan 已提交
776 777 778 779
    ASSERT_EQ(pRsp->code, 0);
  }

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

  {
786
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col5", 12, &contLen, 0);
S
Shengliang Guan 已提交
787
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
788 789 790 791
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST);
  }

  {
792
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "ts", 8, &contLen, 0);
S
Shengliang Guan 已提交
793
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
794 795 796 797
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_STB_OPTION);
  }

  {
798
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 8, &contLen, 0);
S
Shengliang Guan 已提交
799
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
800 801 802 803
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES);
  }

  {
804
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", TSDB_MAX_BYTES_PER_ROW, &contLen, 0);
S
Shengliang Guan 已提交
805
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
806 807 808 809
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_ROW_BYTES);
  }

  {
810 811 812 813 814 815 816 817 818 819
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col1", 20, &contLen, 0);
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
    ASSERT_EQ(pRsp->code, 0);

    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
    EXPECT_EQ(test.GetShowRows(), 1);
  }

  {
    void*    pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col_not_exist", 20, &contLen, 1);
S
Shengliang Guan 已提交
820
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen);
S
Shengliang Guan 已提交
821 822
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
823
    test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
S
Shengliang Guan 已提交
824 825 826 827
    EXPECT_EQ(test.GetShowRows(), 1);
  }

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