catalogTests.cpp 48.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

D
dapan1121 已提交
16
#include <gtest/gtest.h>
17 18
#include <tglobal.h>
#include <iostream>
S
Shengliang Guan 已提交
19
#include "os.h"
20

S
Shengliang Guan 已提交
21 22
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
23 24 25
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
S
Shengliang Guan 已提交
26
#pragma GCC diagnostic ignored "-Wformat"
27

S
Shengliang Guan 已提交
28 29 30
#include "addr_any.h"
#include "catalog.h"
#include "stub.h"
D
dapan1121 已提交
31
#include "taos.h"
32
#include "tdef.h"
D
dapan1121 已提交
33
#include "tep.h"
D
ut test  
dapan1121 已提交
34
#include "trpc.h"
S
Shengliang Guan 已提交
35
#include "tvariant.h"
D
dapan 已提交
36
#include "catalogInt.h"
37

D
dapan1121 已提交
38
namespace {
39

S
Shengliang Guan 已提交
40
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
D
dapan1121 已提交
41
                                            int32_t *exist, int32_t flag);
D
dapan1121 已提交
42
extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type);
D
dapan 已提交
43
extern "C" int32_t ctgActUpdateTbl(SCtgMetaAction *action);
D
dapan 已提交
44 45
extern "C" int32_t ctgDbgEnableDebug(char *option);
extern "C" int32_t ctgDbgGetStatNum(char *option, void *res);
D
dapan1121 已提交
46

D
dapan 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60
void ctgTestSetRspTableMeta();
void ctgTestSetRspCTableMeta();
void ctgTestSetRspSTableMeta();
void ctgTestSetRspMultiSTableMeta();

extern "C" SCatalogMgmt gCtgMgmt;

enum {
  CTGT_RSP_VGINFO = 1,
  CTGT_RSP_TBMETA,
  CTGT_RSP_CTBMETA,
  CTGT_RSP_STBMETA,
  CTGT_RSP_MSTBMETA,
};
D
dapan1121 已提交
61

S
Shengliang Guan 已提交
62 63 64
bool    ctgTestStop = false;
bool    ctgTestEnableSleep = false;
bool    ctgTestDeadLoop = false;
D
dapan1121 已提交
65
int32_t ctgTestPrintNum = 200000;
D
dapan1121 已提交
66
int32_t ctgTestMTRunSec = 5;
D
dapan1121 已提交
67

S
Shengliang Guan 已提交
68 69 70 71 72 73 74 75
int32_t  ctgTestCurrentVgVersion = 0;
int32_t  ctgTestVgVersion = 1;
int32_t  ctgTestVgNum = 10;
int32_t  ctgTestColNum = 2;
int32_t  ctgTestTagNum = 1;
int32_t  ctgTestSVersion = 1;
int32_t  ctgTestTVersion = 1;
int32_t  ctgTestSuid = 2;
D
dapan1121 已提交
76
uint64_t ctgTestDbId = 33;
D
dapan1121 已提交
77

78
uint64_t ctgTestClusterId = 0x1;
S
Shengliang Guan 已提交
79 80 81 82
char    *ctgTestDbname = "1.db1";
char    *ctgTestTablename = "table1";
char    *ctgTestCTablename = "ctable1";
char    *ctgTestSTablename = "stable1";
D
dapan1121 已提交
83

D
dapan 已提交
84 85 86
int32_t ctgTestRspFunc[10] = {0};
int32_t ctgTestRspIdx = 0;

D
ut test  
dapan1121 已提交
87
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
S
Shengliang Guan 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
  SCreateDbReq createReq = {0};
  strcpy(createReq.db, "1.db1");
  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;

  int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSCreateDbReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
113

D
ut test  
dapan1121 已提交
114 115
  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
S
Shengliang Guan 已提交
116
  rpcMsg.contLen = contLen;
H
Hongze Cheng 已提交
117
  rpcMsg.msgType = TDMT_MND_CREATE_DB;
D
ut test  
dapan1121 已提交
118 119 120 121 122 123 124

  SRpcMsg rpcRsp = {0};
  rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp);

  ASSERT_EQ(rpcRsp.code, 0);
}

D
dapan1121 已提交
125
void ctgTestInitLogFile() {
S
Shengliang Guan 已提交
126 127
  const char   *defaultLogFileNamePrefix = "taoslog";
  const int32_t maxLogFileNum = 10;
D
dapan1121 已提交
128 129

  tsAsyncLog = 0;
D
dapan1121 已提交
130
  qDebugFlag = 159;
D
dapan1121 已提交
131

D
dapan 已提交
132 133
  ctgDbgEnableDebug("api");
  
S
Shengliang Guan 已提交
134
  if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
D
dapan1121 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    printf("failed to open log file in directory:%s\n", tsLogDir);
  }
}

int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) {
  return ((vgVersion % 2) == 0) ? ctgTestVgNum - 2 : ctgTestVgNum;
}

void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) {
  SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);

  SName sn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(sn.dbname, "db1");
  strcpy(sn.tname, ctgTestSTablename);

D
dapan 已提交
152 153 154 155
  char db[TSDB_DB_FNAME_LEN] = {0};
  tNameGetFullDbName(&cn, db);

  strcpy(output->dbFName, db);
D
dapan1121 已提交
156
  SET_META_TYPE_BOTH_TABLE(output->metaType);
D
dapan1121 已提交
157

D
dapan1121 已提交
158 159
  strcpy(output->ctbName, cn.tname);
  strcpy(output->tbName, sn.tname);
D
dapan1121 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173

  output->ctbMeta.vgId = 9;
  output->ctbMeta.tableType = TSDB_CHILD_TABLE;
  output->ctbMeta.uid = 3;
  output->ctbMeta.suid = 2;

  output->tbMeta = (STableMeta *)calloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum));
  output->tbMeta->vgId = 9;
  output->tbMeta->tableType = TSDB_SUPER_TABLE;
  output->tbMeta->uid = 2;
  output->tbMeta->suid = 2;

  output->tbMeta->tableInfo.numOfColumns = ctgTestColNum;
  output->tbMeta->tableInfo.numOfTags = ctgTestTagNum;
S
Shengliang Guan 已提交
174

D
dapan1121 已提交
175 176
  output->tbMeta->sversion = ctgTestSVersion;
  output->tbMeta->tversion = ctgTestTVersion;
S
Shengliang Guan 已提交
177

D
dapan1121 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
  SSchema *s = NULL;
  s = &output->tbMeta->schema[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = 1;
  s->bytes = 8;
  strcpy(s->name, "ts");

  s = &output->tbMeta->schema[1];
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = 2;
  s->bytes = 4;
  strcpy(s->name, "col1s");

  s = &output->tbMeta->schema[2];
  s->type = TSDB_DATA_TYPE_BINARY;
  s->colId = 3;
  s->bytes = 12;
  strcpy(s->name, "tag1s");
}

D
dapan1121 已提交
198
void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
D
dapan1121 已提交
199
  static int32_t vgVersion = ctgTestVgVersion + 1;
S
Shengliang Guan 已提交
200 201
  int32_t        vgNum = 0;
  SVgroupInfo    vgInfo = {0};
D
dapan1121 已提交
202
  SDBVgInfo *dbVgroup = (SDBVgInfo *)calloc(1, sizeof(SDBVgInfo));
S
Shengliang Guan 已提交
203

D
dapan1121 已提交
204
  dbVgroup->vgVersion = vgVersion++;
S
Shengliang Guan 已提交
205

D
dapan1121 已提交
206
  ctgTestCurrentVgVersion = dbVgroup->vgVersion;
S
Shengliang Guan 已提交
207

D
dapan1121 已提交
208
  dbVgroup->hashMethod = 0;
D
dapan1121 已提交
209
  dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
D
dapan1121 已提交
210 211 212 213 214 215 216 217

  vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
  uint32_t hashUnit = UINT32_MAX / vgNum;

  for (int32_t i = 0; i < vgNum; ++i) {
    vgInfo.vgId = i + 1;
    vgInfo.hashBegin = i * hashUnit;
    vgInfo.hashEnd = hashUnit * (i + 1) - 1;
H
Haojun Liao 已提交
218 219 220 221
    vgInfo.epset.numOfEps = i % TSDB_MAX_REPLICA + 1;
    vgInfo.epset.inUse = i % vgInfo.epset.numOfEps;
    for (int32_t n = 0; n < vgInfo.epset.numOfEps; ++n) {
      SEp *addr = &vgInfo.epset.eps[n];
D
dapan1121 已提交
222
      strcpy(addr->fqdn, "a0");
S
Shengliang Guan 已提交
223
      addr->port = n + 22;
D
dapan1121 已提交
224 225
    }

D
dapan1121 已提交
226
    taosHashPut(dbVgroup->vgHash, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo));
D
dapan1121 已提交
227
  }
D
dapan 已提交
228 229

  *pdbVgroup = dbVgroup;
D
dapan1121 已提交
230 231
}

D
dapan1121 已提交
232 233 234 235 236 237 238 239 240 241 242 243 244 245
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
  strcpy(rspMsg->dbFName, ctgTestDbname);
  sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
  sprintf(rspMsg->stbName, "%s", ctgTestSTablename);
  rspMsg->numOfTags = ctgTestTagNum;
  rspMsg->numOfColumns = ctgTestColNum;
  rspMsg->precision = 1 + 1;
  rspMsg->tableType = TSDB_SUPER_TABLE;
  rspMsg->update = 1 + 1;
  rspMsg->sversion = ctgTestSVersion + 1;
  rspMsg->tversion = ctgTestTVersion + 1;
  rspMsg->suid = ctgTestSuid + 1;
  rspMsg->tuid = ctgTestSuid + 1;
  rspMsg->vgId = 1;
D
dapan1121 已提交
246 247
  
  rspMsg->pSchemas = (SSchema *)calloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema));
D
dapan1121 已提交
248 249

  SSchema *s = NULL;
S
Shengliang Guan 已提交
250
  s = &rspMsg->pSchemas[0];
D
dapan1121 已提交
251 252 253 254 255
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = 1;
  s->bytes = 8;
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
256
  s = &rspMsg->pSchemas[1];
D
dapan1121 已提交
257 258 259 260 261
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = 2;
  s->bytes = 4;
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
262
  s = &rspMsg->pSchemas[2];
D
dapan1121 已提交
263 264 265 266 267 268 269 270
  s->type = TSDB_DATA_TYPE_BINARY;
  s->colId = 3;
  s->bytes = 12 + 1;
  strcpy(s->name, "tag1s");

  return;
}

D
dapan 已提交
271
void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
272 273 274
  SUseDbRsp usedbRsp = {0};
  strcpy(usedbRsp.db, ctgTestDbname);
  usedbRsp.vgVersion = ctgTestVgVersion;
D
dapan1121 已提交
275
  ctgTestCurrentVgVersion = ctgTestVgVersion;
S
Shengliang Guan 已提交
276 277 278 279
  usedbRsp.vgNum = ctgTestVgNum;
  usedbRsp.hashMethod = 0;
  usedbRsp.uid = ctgTestDbId;
  usedbRsp.pVgroupInfos = taosArrayInit(usedbRsp.vgNum, sizeof(SVgroupInfo));
D
dapan1121 已提交
280

S
Shengliang Guan 已提交
281
  uint32_t hashUnit = UINT32_MAX / ctgTestVgNum;
D
dapan1121 已提交
282
  for (int32_t i = 0; i < ctgTestVgNum; ++i) {
S
Shengliang Guan 已提交
283 284 285 286 287 288 289 290 291 292 293 294
    SVgroupInfo vg = {0};
    vg.vgId = i + 1;
    vg.hashBegin = i * hashUnit;
    vg.hashEnd = hashUnit * (i + 1) - 1;
    if (i == ctgTestVgNum - 1) {
      vg.hashEnd = htonl(UINT32_MAX);
    }

    vg.epset.numOfEps = i % TSDB_MAX_REPLICA + 1;
    vg.epset.inUse = i % vg.epset.numOfEps;
    for (int32_t n = 0; n < vg.epset.numOfEps; ++n) {
      SEp *addr = &vg.epset.eps[n];
D
dapan1121 已提交
295
      strcpy(addr->fqdn, "a0");
S
Shengliang Guan 已提交
296
      addr->port = n + 22;
D
dapan1121 已提交
297
    }
S
Shengliang Guan 已提交
298 299

    taosArrayPush(usedbRsp.pVgroupInfos, &vg);
D
dapan1121 已提交
300 301
  }

S
Shengliang Guan 已提交
302 303 304
  int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSUseDbRsp(pReq, contLen, &usedbRsp);
D
dapan1121 已提交
305

S
Shengliang Guan 已提交
306 307 308
  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;
D
dapan1121 已提交
309 310
}

D
dapan 已提交
311
void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
  strcpy(metaRsp.tbName, ctgTestTablename);
  metaRsp.numOfTags = 0;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_NORMAL_TABLE;
  metaRsp.update = 1;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = 0;
  metaRsp.tuid = 0x0000000000000001;
  metaRsp.vgId = 8;
  metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
326 327

  SSchema *s = NULL;
S
Shengliang Guan 已提交
328
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
329
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
330 331
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
332 333
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
334
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
335
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
336 337
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
338
  strcpy(s->name, "col1");
S
Shengliang Guan 已提交
339

S
Shengliang Guan 已提交
340 341 342 343 344 345 346 347 348
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
349 350
}

D
dapan 已提交
351
void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
  strcpy(metaRsp.tbName, ctgTestCTablename);
  strcpy(metaRsp.stbName, ctgTestSTablename);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_CHILD_TABLE;
  metaRsp.update = 1;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = 0x0000000000000002;
  metaRsp.tuid = 0x0000000000000003;
  metaRsp.vgId = 9;
  metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
367 368

  SSchema *s = NULL;
S
Shengliang Guan 已提交
369
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
370
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
371 372
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
373 374
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
375
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
376
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
377 378
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
379 380
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
381
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
382
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
383 384
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
385 386
  strcpy(s->name, "tag1s");

S
Shengliang Guan 已提交
387 388 389 390 391 392 393 394 395
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
396 397
}

D
dapan 已提交
398
void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
  strcpy(metaRsp.tbName, ctgTestSTablename);
  strcpy(metaRsp.stbName, ctgTestSTablename);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_SUPER_TABLE;
  metaRsp.update = 1;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = ctgTestSuid;
  metaRsp.tuid = ctgTestSuid;
  metaRsp.vgId = 0;
  metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
414 415

  SSchema *s = NULL;
S
Shengliang Guan 已提交
416
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
417
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
418 419
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
420 421
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
422
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
423
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
424 425
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
426 427
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
428
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
429
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
430 431
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
432 433
  strcpy(s->name, "tag1s");

S
Shengliang Guan 已提交
434 435 436 437 438 439 440 441 442
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
443 444
}

D
dapan 已提交
445
void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
D
dapan1121 已提交
446 447
  static int32_t idx = 1;

S
Shengliang Guan 已提交
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
  sprintf(metaRsp.tbName, "%s_%d", ctgTestSTablename, idx);
  sprintf(metaRsp.stbName, "%s_%d", ctgTestSTablename, idx);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_SUPER_TABLE;
  metaRsp.update = 1;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = ctgTestSuid + idx;
  metaRsp.tuid = ctgTestSuid + idx;
  metaRsp.vgId = 0;
  metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
463 464

  SSchema *s = NULL;
S
Shengliang Guan 已提交
465
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
466
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
467 468
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
469 470
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
471
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
472
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
473 474
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
475 476
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
477
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
478
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
479 480
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
481 482 483
  strcpy(s->name, "tag1s");

  ++idx;
S
Shengliang Guan 已提交
484

S
Shengliang Guan 已提交
485 486 487 488 489 490 491
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;
D
dapan1121 已提交
492

S
Shengliang Guan 已提交
493 494
  tFreeSTableMetaRsp(&metaRsp);
}
S
Shengliang Guan 已提交
495

D
dapan 已提交
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  switch (ctgTestRspFunc[ctgTestRspIdx]) {
    case CTGT_RSP_VGINFO:
      ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_TBMETA:
      ctgTestRspTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_CTBMETA:
      ctgTestRspCTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_STBMETA:
      ctgTestRspSTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_MSTBMETA:
      ctgTestRspMultiSTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    default:
      break;
  }

  ctgTestRspIdx++;
S
Shengliang Guan 已提交
518

D
dapan 已提交
519 520 521
  return;
}

D
dapan 已提交
522 523 524 525
void ctgTestRspDbVgroupsAndNormalMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);

  ctgTestSetRspTableMeta();
S
Shengliang Guan 已提交
526

D
dapan 已提交
527 528 529
  return;
}

D
dapan 已提交
530 531
void ctgTestRspDbVgroupsAndChildMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
532

D
dapan 已提交
533
  ctgTestSetRspCTableMeta();
S
Shengliang Guan 已提交
534

D
dapan 已提交
535 536 537
  return;
}

D
dapan 已提交
538 539
void ctgTestRspDbVgroupsAndSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
540

D
dapan 已提交
541
  ctgTestSetRspSTableMeta();
S
Shengliang Guan 已提交
542

D
dapan1121 已提交
543 544 545
  return;
}

D
dapan 已提交
546 547
void ctgTestRspDbVgroupsAndMultiSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
548

D
dapan 已提交
549
  ctgTestSetRspMultiSTableMeta();
S
Shengliang Guan 已提交
550

D
dapan1121 已提交
551 552 553
  return;
}

D
dapan 已提交
554
void ctgTestSetRspDbVgroups() {
D
dapan1121 已提交
555
  static Stub stub;
D
dapan 已提交
556
  stub.set(rpcSendRecv, ctgTestRspDbVgroups);
D
dapan1121 已提交
557
  {
S
Shengliang Guan 已提交
558 559
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
560
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
561
    for (const auto &f : result) {
D
dapan 已提交
562
      stub.set(f.second, ctgTestRspDbVgroups);
D
dapan1121 已提交
563 564 565 566
    }
  }
}

D
dapan 已提交
567
void ctgTestSetRspTableMeta() {
D
dapan1121 已提交
568
  static Stub stub;
D
dapan 已提交
569
  stub.set(rpcSendRecv, ctgTestRspTableMeta);
D
dapan1121 已提交
570
  {
S
Shengliang Guan 已提交
571 572
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
573
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
574
    for (const auto &f : result) {
D
dapan 已提交
575
      stub.set(f.second, ctgTestRspTableMeta);
D
dapan1121 已提交
576 577 578 579
    }
  }
}

D
dapan 已提交
580
void ctgTestSetRspCTableMeta() {
D
dapan1121 已提交
581
  static Stub stub;
D
dapan 已提交
582
  stub.set(rpcSendRecv, ctgTestRspCTableMeta);
D
dapan1121 已提交
583
  {
S
Shengliang Guan 已提交
584 585
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
586
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
587
    for (const auto &f : result) {
D
dapan 已提交
588
      stub.set(f.second, ctgTestRspCTableMeta);
D
dapan1121 已提交
589 590 591 592
    }
  }
}

D
dapan 已提交
593
void ctgTestSetRspSTableMeta() {
D
dapan1121 已提交
594
  static Stub stub;
D
dapan 已提交
595
  stub.set(rpcSendRecv, ctgTestRspSTableMeta);
D
dapan1121 已提交
596
  {
S
Shengliang Guan 已提交
597 598
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
599
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
600
    for (const auto &f : result) {
D
dapan 已提交
601
      stub.set(f.second, ctgTestRspSTableMeta);
D
dapan1121 已提交
602 603 604 605
    }
  }
}

D
dapan 已提交
606
void ctgTestSetRspMultiSTableMeta() {
D
dapan1121 已提交
607
  static Stub stub;
D
dapan 已提交
608
  stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta);
D
dapan1121 已提交
609
  {
S
Shengliang Guan 已提交
610 611
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
612
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
613
    for (const auto &f : result) {
D
dapan 已提交
614
      stub.set(f.second, ctgTestRspMultiSTableMeta);
D
dapan1121 已提交
615 616 617 618
    }
  }
}

D
dapan 已提交
619
void ctgTestSetRspByIdx() {
D
dapan1121 已提交
620
  static Stub stub;
D
dapan 已提交
621
  stub.set(rpcSendRecv, ctgTestRspByIdx);
D
dapan1121 已提交
622
  {
S
Shengliang Guan 已提交
623 624
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
625
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
626
    for (const auto &f : result) {
D
dapan 已提交
627
      stub.set(f.second, ctgTestRspByIdx);
D
dapan1121 已提交
628 629 630 631
    }
  }
}

D
dapan 已提交
632 633

void ctgTestSetRspDbVgroupsAndNormalMeta() {
D
dapan 已提交
634
  static Stub stub;
D
dapan 已提交
635
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta);
D
dapan 已提交
636
  {
S
Shengliang Guan 已提交
637 638
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan 已提交
639
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
640
    for (const auto &f : result) {
D
dapan 已提交
641
      stub.set(f.second, ctgTestRspDbVgroupsAndNormalMeta);
D
dapan 已提交
642 643 644 645
    }
  }
}

D
dapan 已提交
646
void ctgTestSetRspDbVgroupsAndChildMeta() {
D
dapan1121 已提交
647
  static Stub stub;
D
dapan 已提交
648
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta);
D
dapan1121 已提交
649
  {
S
Shengliang Guan 已提交
650 651
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
652
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
653
    for (const auto &f : result) {
D
dapan 已提交
654
      stub.set(f.second, ctgTestRspDbVgroupsAndChildMeta);
D
dapan1121 已提交
655 656 657 658
    }
  }
}

D
dapan 已提交
659
void ctgTestSetRspDbVgroupsAndSuperMeta() {
D
dapan1121 已提交
660
  static Stub stub;
D
dapan 已提交
661
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta);
D
dapan1121 已提交
662
  {
S
Shengliang Guan 已提交
663 664
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
665
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
666
    for (const auto &f : result) {
D
dapan 已提交
667
      stub.set(f.second, ctgTestRspDbVgroupsAndSuperMeta);
D
dapan1121 已提交
668 669 670 671
    }
  }
}

D
dapan 已提交
672
void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
D
dapan1121 已提交
673
  static Stub stub;
D
dapan 已提交
674
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta);
D
dapan1121 已提交
675
  {
S
Shengliang Guan 已提交
676 677
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
678
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
679
    for (const auto &f : result) {
D
dapan 已提交
680
      stub.set(f.second, ctgTestRspDbVgroupsAndMultiSuperMeta);
D
dapan1121 已提交
681 682 683 684
    }
  }
}

S
Shengliang Guan 已提交
685
}  // namespace
686

D
dapan1121 已提交
687
void *ctgTestGetDbVgroupThread(void *param) {
S
Shengliang Guan 已提交
688 689 690 691 692 693
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  void            *mockPointer = (void *)0x1;
  SArray          *vgList = NULL;
  int32_t          n = 0;

D
dapan1121 已提交
694
  while (!ctgTestStop) {
D
dapan1121 已提交
695
    code = catalogGetDBVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList);
D
dapan1121 已提交
696 697 698 699 700 701 702 703 704
    if (code) {
      assert(0);
    }

    if (vgList) {
      taosArrayDestroy(vgList);
    }

    if (ctgTestEnableSleep) {
S
Shengliang Guan 已提交
705
      usleep(rand() % 5);
D
dapan1121 已提交
706
    }
D
dapan1121 已提交
707
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
708 709 710 711 712 713 714
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
715
void *ctgTestSetSameDbVgroupThread(void *param) {
S
Shengliang Guan 已提交
716 717
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
D
dapan1121 已提交
718
  SDBVgInfo       *dbVgroup = NULL;
S
Shengliang Guan 已提交
719 720
  int32_t          n = 0;

D
dapan1121 已提交
721 722
  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
723
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
D
dapan1121 已提交
724 725 726 727
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
728 729
    if (ctgTestEnableSleep) {
      usleep(rand() % 5);
D
dapan1121 已提交
730
    }
D
dapan1121 已提交
731
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
732 733 734 735 736 737 738
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
739 740 741
void *ctgTestSetDiffDbVgroupThread(void *param) {
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
D
dapan1121 已提交
742
  SDBVgInfo    *dbVgroup = NULL;
D
dapan1121 已提交
743 744 745 746
  int32_t          n = 0;

  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
747
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId++, dbVgroup);
D
dapan1121 已提交
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
    if (code) {
      assert(0);
    }

    if (ctgTestEnableSleep) {
      usleep(rand() % 5);
    }
    if (++n % ctgTestPrintNum == 0) {
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
763
void *ctgTestGetCtableMetaThread(void *param) {
S
Shengliang Guan 已提交
764 765 766 767 768
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  int32_t          n = 0;
  STableMeta      *tbMeta = NULL;
  int32_t          exist = 0;
D
dapan1121 已提交
769 770 771 772

  SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);
S
Shengliang Guan 已提交
773

D
dapan1121 已提交
774
  while (!ctgTestStop) {
D
dapan1121 已提交
775
    code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist, 0);
D
dapan1121 已提交
776 777 778 779
    if (code || 0 == exist) {
      assert(0);
    }

D
dapan1121 已提交
780 781
    tfree(tbMeta);

D
dapan1121 已提交
782
    if (ctgTestEnableSleep) {
S
Shengliang Guan 已提交
783
      usleep(rand() % 5);
D
dapan1121 已提交
784
    }
S
Shengliang Guan 已提交
785

D
dapan1121 已提交
786
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
787 788 789 790 791 792 793 794
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

void *ctgTestSetCtableMetaThread(void *param) {
S
Shengliang Guan 已提交
795 796
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
D
dapan1121 已提交
797
  SDBVgInfo    dbVgroup = {0};
S
Shengliang Guan 已提交
798
  int32_t          n = 0;
D
dapan 已提交
799
  STableMetaOutput *output = NULL;
D
dapan1121 已提交
800

D
dapan1121 已提交
801 802 803
  SCtgMetaAction action = {0};
  
  action.act = CTG_ACT_UPDATE_TBL;
S
Shengliang Guan 已提交
804

D
dapan1121 已提交
805
  while (!ctgTestStop) {
D
dapan 已提交
806 807 808
    output = (STableMetaOutput *)malloc(sizeof(STableMetaOutput));
    ctgTestBuildCTableMetaOutput(output);

D
dapan 已提交
809
    SCtgUpdateTblMsg *msg = (SCtgUpdateTblMsg *)malloc(sizeof(SCtgUpdateTblMsg));
D
dapan1121 已提交
810
    msg->pCtg = pCtg;
D
dapan 已提交
811
    msg->output = output;
D
dapan1121 已提交
812 813 814
    action.data = msg;

    code = ctgActUpdateTbl(&action);
D
dapan1121 已提交
815 816 817 818
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
819 820
    if (ctgTestEnableSleep) {
      usleep(rand() % 5);
D
dapan1121 已提交
821
    }
D
dapan1121 已提交
822
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
823 824 825 826 827 828 829
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
830
#if 0
D
dapan 已提交
831

D
dapan1121 已提交
832

D
dapan 已提交
833
TEST(tableMeta, normalTable) {
S
Shengliang Guan 已提交
834 835 836
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
837

D
dapan1121 已提交
838 839
  ctgTestInitLogFile();

D
dapan 已提交
840
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
841

842
  initQueryModuleMsgHandle();
D
ut test  
dapan1121 已提交
843

S
Shengliang Guan 已提交
844 845
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
846 847
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
848

D
dapan1121 已提交
849
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
850
  ASSERT_EQ(code, 0);
851

D
dapan1121 已提交
852
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
853 854 855 856
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
D
dapan1121 已提交
857
  ASSERT_EQ(code, 0);
D
dapan1121 已提交
858
  ASSERT_EQ(vgInfo.vgId, 8);
H
Haojun Liao 已提交
859
  ASSERT_EQ(vgInfo.epset.numOfEps, 3);
D
dapan1121 已提交
860

D
dapan 已提交
861
  while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
D
dapan 已提交
862
    usleep(10000);
D
dapan 已提交
863 864 865
  }
  
  ctgTestSetRspTableMeta();
D
dapan1121 已提交
866 867

  STableMeta *tableMeta = NULL;
H
Haojun Liao 已提交
868
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
869 870 871 872 873 874 875 876 877 878
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
879 880 881 882 883 884 885
  while (true) {
    uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    if (0 == n) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
886 887 888
  }

  
D
dapan1121 已提交
889
  tableMeta = NULL;
H
Haojun Liao 已提交
890
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
891 892 893 894 895 896 897 898 899 900
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

S
Shengliang Guan 已提交
901
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
902
  SSTableMetaVersion *stb = NULL;
S
Shengliang Guan 已提交
903 904
  uint32_t            dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t             i = 0;
D
dapan1121 已提交
905 906 907 908 909 910
  while (i < 5) {
    ++i;
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
    ASSERT_EQ(code, 0);
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
    ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
911

D
dapan1121 已提交
912
    if (dbNum) {
S
Shengliang Guan 已提交
913
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
D
dapan1121 已提交
914 915 916 917 918 919 920
      free(dbs);
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
921
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
D
dapan1121 已提交
922 923 924 925 926 927 928 929 930 931
      free(stb);
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
    sleep(2);
  }
S
Shengliang Guan 已提交
932

D
dapan1121 已提交
933 934 935
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 0);

D
dapan1121 已提交
936
  catalogDestroy();
D
dapan 已提交
937
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
938 939
}

D
dapan 已提交
940
TEST(tableMeta, childTableCase) {
S
Shengliang Guan 已提交
941 942 943
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
D
dapan1121 已提交
944

D
dapan1121 已提交
945 946
  ctgTestInitLogFile();

D
dapan 已提交
947
  ctgTestSetRspDbVgroupsAndChildMeta();
D
dapan1121 已提交
948 949 950

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
951
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
952 953
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
954

D
dapan1121 已提交
955
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
956 957
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
958
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
959 960
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
D
dapan1121 已提交
961 962

  STableMeta *tableMeta = NULL;
H
Haojun Liao 已提交
963
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
964 965 966 967 968 969 970 971 972 973
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
974 975 976 977 978 979 980
  while (true) {
    uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    if (0 == n) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
981 982
  }

D
dapan 已提交
983

D
dapan1121 已提交
984
  tableMeta = NULL;
H
Haojun Liao 已提交
985
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
986 987 988 989 990 991 992 993 994 995 996
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

  tableMeta = NULL;
H
Haojun Liao 已提交
997 998 999

  strcpy(n.tname, ctgTestSTablename);
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

S
Shengliang Guan 已提交
1010
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
1011
  SSTableMetaVersion *stb = NULL;
S
Shengliang Guan 已提交
1012 1013
  uint32_t            dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t             i = 0;
D
dapan1121 已提交
1014 1015 1016 1017 1018 1019
  while (i < 5) {
    ++i;
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
    ASSERT_EQ(code, 0);
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
    ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1020

D
dapan1121 已提交
1021
    if (dbNum) {
S
Shengliang Guan 已提交
1022
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
D
dapan1121 已提交
1023 1024 1025 1026 1027 1028 1029
      free(dbs);
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
S
Shengliang Guan 已提交
1030
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
D
dapan1121 已提交
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
      free(stb);
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
    sleep(2);
  }
S
Shengliang Guan 已提交
1041

D
dapan1121 已提交
1042 1043 1044
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);

D
dapan1121 已提交
1045
  catalogDestroy();
D
dapan 已提交
1046
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1047 1048
}

D
dapan 已提交
1049
TEST(tableMeta, superTableCase) {
S
Shengliang Guan 已提交
1050 1051 1052
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
D
dapan1121 已提交
1053

D
dapan 已提交
1054
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1055 1056 1057

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1058 1059 1060
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1061
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1062
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
1063 1064
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
1065
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
1066 1067
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan1121 已提交
1068 1069

  STableMeta *tableMeta = NULL;
H
Haojun Liao 已提交
1070
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1071 1072 1073 1074 1075
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1076 1077
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1078 1079 1080 1081 1082
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1083 1084 1085 1086 1087 1088 1089
  while (true) {
    uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    if (0 == n) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
1090 1091
  }

D
dapan 已提交
1092

D
dapan 已提交
1093
  ctgTestSetRspCTableMeta();
D
dapan1121 已提交
1094 1095

  tableMeta = NULL;
H
Haojun Liao 已提交
1096 1097 1098 1099

  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1110 1111 1112 1113 1114 1115 1116
  while (true) {
    uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    if (2 != n) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
1117 1118
  }

D
dapan 已提交
1119

D
dapan1121 已提交
1120
  tableMeta = NULL;
D
dapan1121 已提交
1121
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

S
Shengliang Guan 已提交
1132
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
1133
  SSTableMetaVersion *stb = NULL;
S
Shengliang Guan 已提交
1134 1135
  uint32_t            dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t             i = 0;
D
dapan1121 已提交
1136 1137 1138 1139 1140 1141
  while (i < 5) {
    ++i;
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
    ASSERT_EQ(code, 0);
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
    ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1142

D
dapan1121 已提交
1143
    if (dbNum) {
S
Shengliang Guan 已提交
1144
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
D
dapan1121 已提交
1145 1146 1147 1148 1149 1150 1151
      free(dbs);
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
1152
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
S
Shengliang Guan 已提交
1153

D
dapan1121 已提交
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
      free(stb);
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
    sleep(2);
  }
S
Shengliang Guan 已提交
1164

D
dapan1121 已提交
1165 1166
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);
D
dapan1121 已提交
1167 1168

  catalogDestroy();
D
dapan 已提交
1169
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1170
}
1171

D
dapan1121 已提交
1172 1173 1174 1175 1176 1177 1178
TEST(tableMeta, rmStbMeta) {
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};

  ctgTestInitLogFile();

D
dapan 已提交
1179
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);

  STableMeta *tableMeta = NULL;
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1208 1209 1210 1211 1212 1213 1214
  while (true) {
    uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    if (0 == n) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
1215 1216
  }

D
dapan 已提交
1217

D
dapan 已提交
1218
  code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid);
D
dapan1121 已提交
1219 1220
  ASSERT_EQ(code, 0);

D
dapan 已提交
1221 1222 1223 1224 1225 1226 1227 1228
  while (true) {
    int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
    if (n || m) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
1229 1230
  }

D
dapan 已提交
1231

D
dapan1121 已提交
1232 1233 1234 1235 1236
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
S
Shengliang Guan 已提交
1237

D
dapan1121 已提交
1238
  catalogDestroy();
D
dapan 已提交
1239
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1240 1241 1242 1243 1244 1245 1246 1247 1248
}

TEST(tableMeta, updateStbMeta) {
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};

  ctgTestInitLogFile();

D
dapan 已提交
1249
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);

  STableMeta *tableMeta = NULL;
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1278 1279 1280 1281 1282 1283 1284
  while (true) {
    uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    if (0 == n) {
      usleep(10000);
    } else {
      break;
    }
D
dapan 已提交
1285 1286
  }

D
dapan 已提交
1287

D
dapan1121 已提交
1288 1289 1290 1291 1292 1293 1294
  tfree(tableMeta);

  STableMetaRsp rsp = {0};
  ctgTestBuildSTableMetaRsp(&rsp);

  code = catalogUpdateSTableMeta(pCtg, &rsp);
  ASSERT_EQ(code, 0);
D
dapan1121 已提交
1295
  tfree(rsp.pSchemas);
D
dapan1121 已提交
1296

D
dapan 已提交
1297 1298 1299 1300
  while (true) {
    uint64_t n = 0;
    ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
    if (n != 3) {
D
dapan 已提交
1301
      usleep(10000);
D
dapan 已提交
1302 1303 1304 1305 1306
    } else {
      break;
    }
  }

D
dapan1121 已提交
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
  ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1);

  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion + 1);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion + 1);
  ASSERT_EQ(tableMeta->uid, ctgTestSuid + 1);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid + 1);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1 + 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

  tfree(tableMeta);
S
Shengliang Guan 已提交
1327

D
dapan1121 已提交
1328
  catalogDestroy();
D
dapan 已提交
1329
  memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat));
D
dapan1121 已提交
1330 1331
}

D
dapan 已提交
1332
TEST(tableDistVgroup, normalTable) {
S
Shengliang Guan 已提交
1333 1334 1335 1336
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo     *vgInfo = NULL;
  SArray          *vgList = NULL;
D
dapan 已提交
1337

D
dapan 已提交
1338 1339 1340 1341 1342 1343 1344 1345 1346
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_VGINFO;
  
  ctgTestSetRspByIdx();
D
dapan 已提交
1347 1348 1349

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1350 1351 1352
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1353 1354
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
1355
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
1356 1357
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
1358
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
1359 1360
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
D
dapan 已提交
1361

D
dapan1121 已提交
1362
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan 已提交
1363 1364 1365 1366
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 8);
H
Haojun Liao 已提交
1367
  ASSERT_EQ(vgInfo->epset.numOfEps, 3);
D
dapan 已提交
1368 1369

  catalogDestroy();
D
dapan 已提交
1370
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan 已提交
1371 1372 1373
}

TEST(tableDistVgroup, childTableCase) {
S
Shengliang Guan 已提交
1374 1375 1376 1377
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo     *vgInfo = NULL;
  SArray          *vgList = NULL;
D
dapan 已提交
1378

D
dapan 已提交
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_CTBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_VGINFO;
  
  ctgTestSetRspByIdx();
D
dapan 已提交
1389 1390 1391

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
1392 1393
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan 已提交
1394 1395 1396 1397 1398 1399
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
1400
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
1401 1402 1403
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);

D
dapan1121 已提交
1404
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan 已提交
1405 1406 1407 1408
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 9);
H
Haojun Liao 已提交
1409
  ASSERT_EQ(vgInfo->epset.numOfEps, 4);
D
dapan 已提交
1410 1411

  catalogDestroy();
D
dapan 已提交
1412
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan 已提交
1413 1414 1415
}

TEST(tableDistVgroup, superTableCase) {
S
Shengliang Guan 已提交
1416 1417 1418 1419
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo     *vgInfo = NULL;
  SArray          *vgList = NULL;
D
dapan 已提交
1420

D
dapan 已提交
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_VGINFO;
  
  ctgTestSetRspByIdx();


D
dapan 已提交
1433 1434 1435

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1436 1437 1438
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1439
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1440
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
1441 1442
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
1443
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
1444 1445
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan 已提交
1446

D
dapan1121 已提交
1447
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan 已提交
1448 1449 1450 1451
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 1);
H
Haojun Liao 已提交
1452
  ASSERT_EQ(vgInfo->epset.numOfEps, 1);
D
dapan 已提交
1453 1454
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1);
  ASSERT_EQ(vgInfo->vgId, 2);
H
Haojun Liao 已提交
1455
  ASSERT_EQ(vgInfo->epset.numOfEps, 2);
D
dapan 已提交
1456 1457
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2);
  ASSERT_EQ(vgInfo->vgId, 3);
H
Haojun Liao 已提交
1458
  ASSERT_EQ(vgInfo->epset.numOfEps, 3);
D
dapan 已提交
1459 1460

  catalogDestroy();
D
dapan 已提交
1461
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan 已提交
1462 1463
}

D
dapan1121 已提交
1464
TEST(dbVgroup, getSetDbVgroupCase) {
S
Shengliang Guan 已提交
1465 1466 1467 1468
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
1469
  SDBVgInfo       *dbVgroup = NULL;
S
Shengliang Guan 已提交
1470
  SArray          *vgList = NULL;
D
dapan1121 已提交
1471

D
dapan 已提交
1472 1473
  ctgTestInitLogFile();

D
dapan 已提交
1474 1475 1476 1477 1478 1479 1480 1481
  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;

  
  ctgTestSetRspByIdx();

D
dapan1121 已提交
1482 1483 1484

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
1485 1486
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
1497
  code = catalogGetDBVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList);
D
dapan1121 已提交
1498 1499
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
S
Shengliang Guan 已提交
1500

D
dapan 已提交
1501
  while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
D
dapan 已提交
1502
    usleep(10000);
D
dapan 已提交
1503 1504 1505
  }


D
dapan1121 已提交
1506 1507 1508
  code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
H
Haojun Liao 已提交
1509
  ASSERT_EQ(vgInfo.epset.numOfEps, 3);
D
dapan1121 已提交
1510

D
dapan1121 已提交
1511
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan1121 已提交
1512 1513 1514 1515
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(pvgInfo->vgId, 8);
H
Haojun Liao 已提交
1516
  ASSERT_EQ(pvgInfo->epset.numOfEps, 3);
D
dapan1121 已提交
1517 1518 1519
  taosArrayDestroy(vgList);

  ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
1520
  code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
D
dapan1121 已提交
1521 1522
  ASSERT_EQ(code, 0);

D
dapan 已提交
1523 1524 1525 1526
  while (true) {
    uint64_t n = 0;
    ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
    if (n != 3) {
D
dapan 已提交
1527
      usleep(10000);
D
dapan 已提交
1528 1529 1530 1531 1532 1533
    } else {
      break;
    }
  }


D
dapan1121 已提交
1534 1535 1536
  code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 7);
H
Haojun Liao 已提交
1537
  ASSERT_EQ(vgInfo.epset.numOfEps, 2);
D
dapan1121 已提交
1538

D
dapan1121 已提交
1539
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan1121 已提交
1540 1541 1542 1543
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(pvgInfo->vgId, 8);
H
Haojun Liao 已提交
1544
  ASSERT_EQ(pvgInfo->epset.numOfEps, 3);
D
dapan1121 已提交
1545
  taosArrayDestroy(vgList);
S
Shengliang Guan 已提交
1546

D
dapan1121 已提交
1547
  catalogDestroy();
D
dapan 已提交
1548
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1549 1550
}

D
dapan1121 已提交
1551
TEST(multiThread, getSetRmSameDbVgroup) {
S
Shengliang Guan 已提交
1552 1553 1554 1555
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
D
dapan1121 已提交
1556
  SDBVgInfo    dbVgroup = {0};
S
Shengliang Guan 已提交
1557
  SArray          *vgList = NULL;
D
dapan1121 已提交
1558
  ctgTestStop = false;
D
dapan1121 已提交
1559 1560

  ctgTestInitLogFile();
S
Shengliang Guan 已提交
1561

D
dapan 已提交
1562
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
1563 1564 1565

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
1566 1567
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  pthread_attr_t thattr;
  pthread_attr_init(&thattr);

  pthread_t thread1, thread2;
D
dapan1121 已提交
1582
  pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
D
dapan1121 已提交
1583 1584

  sleep(1);
D
dapan1121 已提交
1585
  pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
D
dapan1121 已提交
1586 1587 1588 1589 1590

  while (true) {
    if (ctgTestDeadLoop) {
      sleep(1);
    } else {
D
dapan1121 已提交
1591
      sleep(ctgTestMTRunSec);
D
dapan1121 已提交
1592 1593 1594
      break;
    }
  }
S
Shengliang Guan 已提交
1595

D
dapan1121 已提交
1596 1597
  ctgTestStop = true;
  sleep(1);
S
Shengliang Guan 已提交
1598

D
dapan1121 已提交
1599
  catalogDestroy();
D
dapan 已提交
1600
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1601 1602
}

D
dapan1121 已提交
1603 1604 1605 1606 1607
TEST(multiThread, getSetRmDiffDbVgroup) {
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
D
dapan1121 已提交
1608
  SDBVgInfo    dbVgroup = {0};
D
dapan1121 已提交
1609 1610 1611 1612 1613
  SArray          *vgList = NULL;
  ctgTestStop = false;

  ctgTestInitLogFile();

D
dapan 已提交
1614
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651

  initQueryModuleMsgHandle();

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  pthread_attr_t thattr;
  pthread_attr_init(&thattr);

  pthread_t thread1, thread2;
  pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);

  sleep(1);
  pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);

  while (true) {
    if (ctgTestDeadLoop) {
      sleep(1);
    } else {
      sleep(ctgTestMTRunSec);
      break;
    }
  }

  ctgTestStop = true;
  sleep(1);

  catalogDestroy();
D
dapan 已提交
1652
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1653 1654
}

D
dapan1121 已提交
1655
TEST(multiThread, ctableMeta) {
S
Shengliang Guan 已提交
1656 1657 1658 1659
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
D
dapan1121 已提交
1660
  SDBVgInfo    dbVgroup = {0};
S
Shengliang Guan 已提交
1661
  SArray          *vgList = NULL;
D
dapan1121 已提交
1662
  ctgTestStop = false;
D
dapan1121 已提交
1663

D
dapan 已提交
1664 1665
  ctgTestInitLogFile();

D
dapan 已提交
1666
  ctgTestSetRspDbVgroupsAndChildMeta();
D
dapan1121 已提交
1667 1668 1669

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
1670 1671
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  pthread_attr_t thattr;
  pthread_attr_init(&thattr);

  pthread_t thread1, thread2;
  pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
D
dapan1121 已提交
1687 1688
  sleep(1);
  pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
D
dapan1121 已提交
1689 1690 1691 1692 1693

  while (true) {
    if (ctgTestDeadLoop) {
      sleep(1);
    } else {
D
dapan1121 已提交
1694
      sleep(ctgTestMTRunSec);
D
dapan1121 已提交
1695 1696 1697
      break;
    }
  }
S
Shengliang Guan 已提交
1698

D
dapan1121 已提交
1699
  ctgTestStop = true;
D
dapan 已提交
1700
  sleep(2);
S
Shengliang Guan 已提交
1701

D
dapan1121 已提交
1702
  catalogDestroy();
D
dapan 已提交
1703
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1704
}
D
dapan 已提交
1705

D
dapan1121 已提交
1706
TEST(rentTest, allRent) {
S
Shengliang Guan 已提交
1707 1708 1709 1710
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
D
dapan1121 已提交
1711
  SDBVgInfo    dbVgroup = {0};
S
Shengliang Guan 已提交
1712
  SArray          *vgList = NULL;
D
dapan1121 已提交
1713
  ctgTestStop = false;
S
Shengliang Guan 已提交
1714
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
1715
  SSTableMetaVersion *stable = NULL;
S
Shengliang Guan 已提交
1716
  uint32_t            num = 0;
D
dapan1121 已提交
1717

D
dapan 已提交
1718 1719
  ctgTestInitLogFile();

D
dapan 已提交
1720
  ctgTestSetRspDbVgroupsAndMultiSuperMeta();
D
dapan1121 已提交
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");

  for (int32_t i = 1; i <= 10; ++i) {
    sprintf(n.tname, "%s_%d", ctgTestSTablename, i);

    STableMeta *tableMeta = NULL;
    code = catalogGetSTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
    ASSERT_EQ(code, 0);
    ASSERT_EQ(tableMeta->vgId, 0);
    ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
    ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
    ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
    ASSERT_EQ(tableMeta->uid, ctgTestSuid + i);
    ASSERT_EQ(tableMeta->suid, ctgTestSuid + i);
    ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
    ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
    ASSERT_EQ(tableMeta->tableInfo.precision, 1);
    ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
S
Shengliang Guan 已提交
1749

D
dapan 已提交
1750
    while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
D
dapan 已提交
1751
      usleep(10000);
D
dapan 已提交
1752 1753
    }

D
dapan1121 已提交
1754 1755 1756 1757
    code = catalogGetExpiredDBs(pCtg, &dbs, &num);
    ASSERT_EQ(code, 0);
    printf("%d - expired dbNum:%d\n", i, num);
    if (dbs) {
S
Shengliang Guan 已提交
1758
      printf("%d - expired dbId:%" PRId64 ", vgVersion:%d\n", i, dbs->dbId, dbs->vgVersion);
D
dapan1121 已提交
1759 1760 1761
      free(dbs);
      dbs = NULL;
    }
S
Shengliang Guan 已提交
1762

D
dapan1121 已提交
1763 1764 1765 1766 1767
    code = catalogGetExpiredSTables(pCtg, &stable, &num);
    ASSERT_EQ(code, 0);
    printf("%d - expired stableNum:%d\n", i, num);
    if (stable) {
      for (int32_t n = 0; n < num; ++n) {
S
Shengliang Guan 已提交
1768 1769
        printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid,
               stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion);
D
dapan1121 已提交
1770 1771 1772 1773 1774
      }
      free(stable);
      stable = NULL;
    }
    printf("*************************************************\n");
S
Shengliang Guan 已提交
1775

D
dapan1121 已提交
1776 1777
    sleep(2);
  }
S
Shengliang Guan 已提交
1778

D
dapan1121 已提交
1779
  catalogDestroy();
D
dapan 已提交
1780
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1781 1782
}

D
dapan1121 已提交
1783 1784
#endif

S
Shengliang Guan 已提交
1785
int main(int argc, char **argv) {
1786 1787 1788
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
D
dapan1121 已提交
1789

D
dapan1121 已提交
1790
#pragma GCC diagnostic pop