catalogTests.cpp 82.7 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 <iostream>

S
Shengliang Guan 已提交
19 20
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
21 22 23
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
S
Shengliang Guan 已提交
24
#pragma GCC diagnostic ignored "-Wformat"
25
#include <addr_any.h>
26

wafwerar's avatar
wafwerar 已提交
27 28 29
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
H
Haojun Liao 已提交
30
#include "catalogInt.h"
31
#include "catalog.h"
H
Hongze Cheng 已提交
32
#include "os.h"
S
Shengliang Guan 已提交
33
#include "stub.h"
D
dapan1121 已提交
34
#include "taos.h"
H
Haojun Liao 已提交
35
#include "tdatablock.h"
36
#include "tdef.h"
H
Hongze Cheng 已提交
37
#include "tglobal.h"
D
ut test  
dapan1121 已提交
38
#include "trpc.h"
S
Shengliang Guan 已提交
39
#include "tvariant.h"
40

D
dapan1121 已提交
41
namespace {
42

H
Hongze Cheng 已提交
43
extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog *pCatalog, int32_t type);
D
dapan1121 已提交
44 45
extern "C" int32_t ctgdEnableDebug(char *option);
extern "C" int32_t ctgdGetStatNum(char *option, void *res);
D
dapan1121 已提交
46

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

enum {
  CTGT_RSP_VGINFO = 1,
  CTGT_RSP_TBMETA,
  CTGT_RSP_CTBMETA,
  CTGT_RSP_STBMETA,
  CTGT_RSP_MSTBMETA,
D
dapan1121 已提交
58
  CTGT_RSP_INDEXINFO_E,
D
dapan1121 已提交
59 60 61
  CTGT_RSP_USERAUTH,
  CTGT_RSP_TBLCFG,
  CTGT_RSP_TBLINDEX,
D
dapan1121 已提交
62 63 64 65
  CTGT_RSP_DBCFG,
  CTGT_RSP_QNODELIST,
  CTGT_RSP_UDF,
  CTGT_RSP_SVRVER,
D
dapan1121 已提交
66
  CTGT_RSP_DNODElIST,
D
dapan1121 已提交
67
  CTGT_RSP_TBMETA_NOT_EXIST,
D
dapan 已提交
68
};
D
dapan1121 已提交
69

S
Shengliang Guan 已提交
70 71
bool    ctgTestStop = false;
bool    ctgTestEnableSleep = false;
D
dapan1121 已提交
72
bool    ctgTestEnableLog = true;
S
Shengliang Guan 已提交
73
bool    ctgTestDeadLoop = false;
D
dapan1121 已提交
74
int32_t ctgTestPrintNum = 10000;
D
dapan1121 已提交
75
int32_t ctgTestMTRunSec = 5;
D
dapan1121 已提交
76

S
Shengliang Guan 已提交
77 78 79 80 81
int32_t  ctgTestCurrentVgVersion = 0;
int32_t  ctgTestVgVersion = 1;
int32_t  ctgTestVgNum = 10;
int32_t  ctgTestColNum = 2;
int32_t  ctgTestTagNum = 1;
D
dapan1121 已提交
82
int32_t  ctgTestQnodeNum = 3;
D
dapan1121 已提交
83
int32_t  ctgTestIndexNum = 3;
D
dapan1121 已提交
84 85
int32_t  ctgTestFuncNum = 2;
int32_t  ctgTestFuncType = 3;
S
Shengliang Guan 已提交
86 87 88
int32_t  ctgTestSVersion = 1;
int32_t  ctgTestTVersion = 1;
int32_t  ctgTestSuid = 2;
D
dapan1121 已提交
89
uint64_t ctgTestDbId = 33;
D
dapan1121 已提交
90
uint64_t ctgTestNormalTblUid = 1;
D
dapan1121 已提交
91

92
uint64_t ctgTestClusterId = 0x1;
S
Shengliang Guan 已提交
93 94 95 96
char    *ctgTestDbname = "1.db1";
char    *ctgTestTablename = "table1";
char    *ctgTestCTablename = "ctable1";
char    *ctgTestSTablename = "stable1";
D
dapan1121 已提交
97
char    *ctgTestUsername = "user1";
D
dapan1121 已提交
98 99 100
char    *ctgTestCurrentCTableName = NULL;
char    *ctgTestCurrentTableName = NULL;
char    *ctgTestCurrentSTableName = NULL;
D
dapan1121 已提交
101

D
dapan1121 已提交
102
int32_t ctgTestRspFunc[100] = {0};
D
dapan 已提交
103 104
int32_t ctgTestRspIdx = 0;

D
ut test  
dapan1121 已提交
105
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
S
Shengliang Guan 已提交
106 107 108
  SCreateDbReq createReq = {0};
  strcpy(createReq.db, "1.db1");
  createReq.numOfVgroups = 2;
S
Shengliang Guan 已提交
109 110 111
  createReq.buffer = -1;
  createReq.pageSize = -1;
  createReq.pages = -1;
S
Shengliang Guan 已提交
112 113 114 115
  createReq.daysPerFile = 10;
  createReq.daysToKeep0 = 3650;
  createReq.daysToKeep1 = 3650;
  createReq.daysToKeep2 = 3650;
S
Shengliang Guan 已提交
116 117
  createReq.minRows = 100;
  createReq.maxRows = 4096;
118
  createReq.walFsyncPeriod = 3000;
S
Shengliang Guan 已提交
119 120 121 122
  createReq.walLevel = 1;
  createReq.precision = 0;
  createReq.compression = 2;
  createReq.replications = 1;
S
Shengliang Guan 已提交
123
  createReq.strict = 1;
124
  createReq.cacheLast = 0;
S
Shengliang Guan 已提交
125 126 127 128 129
  createReq.ignoreExist = 1;

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

D
ut test  
dapan1121 已提交
131 132
  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
S
Shengliang Guan 已提交
133
  rpcMsg.contLen = contLen;
H
Hongze Cheng 已提交
134
  rpcMsg.msgType = TDMT_MND_CREATE_DB;
D
ut test  
dapan1121 已提交
135 136 137 138 139 140 141

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

  ASSERT_EQ(rpcRsp.code, 0);
}

D
dapan1121 已提交
142
void ctgTestInitLogFile() {
D
dapan1121 已提交
143 144 145
  if (!ctgTestEnableLog) {
    return;
  }
H
Hongze Cheng 已提交
146

S
Shengliang Guan 已提交
147 148
  const char   *defaultLogFileNamePrefix = "taoslog";
  const int32_t maxLogFileNum = 10;
D
dapan1121 已提交
149 150

  tsAsyncLog = 0;
D
dapan1121 已提交
151
  qDebugFlag = 159;
wafwerar's avatar
wafwerar 已提交
152
  strcpy(tsLogDir, TD_LOG_DIR_PATH);
D
dapan1121 已提交
153

D
dapan1121 已提交
154 155 156
  ctgdEnableDebug("api");
  ctgdEnableDebug("meta");
  ctgdEnableDebug("cache");
D
dapan1121 已提交
157
  ctgdEnableDebug("lock");
H
Hongze Cheng 已提交
158

S
Shengliang Guan 已提交
159
  if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
D
dapan1121 已提交
160 161 162 163 164 165 166 167 168
    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) {
H
Hongze Cheng 已提交
169
  SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
170 171 172
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);

H
Hongze Cheng 已提交
173
  SName sn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
174 175 176
  strcpy(sn.dbname, "db1");
  strcpy(sn.tname, ctgTestSTablename);

D
dapan 已提交
177 178 179 180
  char db[TSDB_DB_FNAME_LEN] = {0};
  tNameGetFullDbName(&cn, db);

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

D
dapan1121 已提交
183 184
  strcpy(output->ctbName, cn.tname);
  strcpy(output->tbName, sn.tname);
D
dapan1121 已提交
185 186 187 188 189 190

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

H
Hongze Cheng 已提交
191 192
  output->tbMeta =
      (STableMeta *)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum));
D
dapan1121 已提交
193 194 195 196 197 198 199
  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 已提交
200

D
dapan1121 已提交
201 202
  output->tbMeta->sversion = ctgTestSVersion;
  output->tbMeta->tversion = ctgTestTVersion;
S
Shengliang Guan 已提交
203

D
dapan1121 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
  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 已提交
224
void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
D
dapan1121 已提交
225
  static int32_t vgVersion = ctgTestVgVersion + 1;
S
Shengliang Guan 已提交
226 227
  int32_t        vgNum = 0;
  SVgroupInfo    vgInfo = {0};
H
Hongze Cheng 已提交
228
  SDBVgInfo     *dbVgroup = (SDBVgInfo *)taosMemoryCalloc(1, sizeof(SDBVgInfo));
S
Shengliang Guan 已提交
229

D
dapan1121 已提交
230
  dbVgroup->vgVersion = vgVersion++;
S
Shengliang Guan 已提交
231

D
dapan1121 已提交
232
  ctgTestCurrentVgVersion = dbVgroup->vgVersion;
S
Shengliang Guan 已提交
233

D
dapan1121 已提交
234
  dbVgroup->hashMethod = 0;
235 236
  dbVgroup->hashPrefix = 0;
  dbVgroup->hashSuffix = 0;
D
dapan1121 已提交
237
  dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
D
dapan1121 已提交
238 239 240 241 242 243 244 245

  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;
L
Liu Jicong 已提交
246 247 248 249
    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 已提交
250
      strcpy(addr->fqdn, "a0");
S
Shengliang Guan 已提交
251
      addr->port = n + 22;
D
dapan1121 已提交
252 253
    }

D
dapan1121 已提交
254
    taosHashPut(dbVgroup->vgHash, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo));
D
dapan1121 已提交
255
  }
D
dapan 已提交
256 257

  *pdbVgroup = dbVgroup;
D
dapan1121 已提交
258 259
}

D
dapan1121 已提交
260 261 262 263 264 265 266 267 268 269
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->sversion = ctgTestSVersion + 1;
  rspMsg->tversion = ctgTestTVersion + 1;
D
dapan1121 已提交
270 271
  rspMsg->suid = ctgTestSuid;
  rspMsg->tuid = ctgTestSuid;
D
dapan1121 已提交
272
  rspMsg->vgId = 1;
H
Hongze Cheng 已提交
273

wafwerar's avatar
wafwerar 已提交
274
  rspMsg->pSchemas = (SSchema *)taosMemoryCalloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema));
D
dapan1121 已提交
275 276

  SSchema *s = NULL;
S
Shengliang Guan 已提交
277
  s = &rspMsg->pSchemas[0];
D
dapan1121 已提交
278 279 280 281 282
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = 1;
  s->bytes = 8;
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
283
  s = &rspMsg->pSchemas[1];
D
dapan1121 已提交
284 285 286 287 288
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = 2;
  s->bytes = 4;
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
289
  s = &rspMsg->pSchemas[2];
D
dapan1121 已提交
290 291 292 293 294 295 296 297
  s->type = TSDB_DATA_TYPE_BINARY;
  s->colId = 3;
  s->bytes = 12 + 1;
  strcpy(s->name, "tag1s");

  return;
}

D
dapan 已提交
298
void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
299 300
  rpcFreeCont(pMsg->pCont);
  
S
Shengliang Guan 已提交
301 302 303
  SUseDbRsp usedbRsp = {0};
  strcpy(usedbRsp.db, ctgTestDbname);
  usedbRsp.vgVersion = ctgTestVgVersion;
D
dapan1121 已提交
304
  ctgTestCurrentVgVersion = ctgTestVgVersion;
S
Shengliang Guan 已提交
305 306 307 308
  usedbRsp.vgNum = ctgTestVgNum;
  usedbRsp.hashMethod = 0;
  usedbRsp.uid = ctgTestDbId;
  usedbRsp.pVgroupInfos = taosArrayInit(usedbRsp.vgNum, sizeof(SVgroupInfo));
D
dapan1121 已提交
309

S
Shengliang Guan 已提交
310
  uint32_t hashUnit = UINT32_MAX / ctgTestVgNum;
D
dapan1121 已提交
311
  for (int32_t i = 0; i < ctgTestVgNum; ++i) {
S
Shengliang Guan 已提交
312 313 314 315 316 317 318 319
    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);
    }

L
Liu Jicong 已提交
320 321 322 323
    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 已提交
324
      strcpy(addr->fqdn, "a0");
S
Shengliang Guan 已提交
325
      addr->port = n + 22;
D
dapan1121 已提交
326
    }
D
dapan1121 已提交
327
    vg.numOfTable = i % 2;
S
Shengliang Guan 已提交
328 329

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

S
Shengliang Guan 已提交
332 333 334
  int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSUseDbRsp(pReq, contLen, &usedbRsp);
D
dapan1121 已提交
335

S
Shengliang Guan 已提交
336 337 338
  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;
339 340

  taosArrayDestroy(usedbRsp.pVgroupInfos);
D
dapan1121 已提交
341 342
}

D
dapan 已提交
343
void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
344 345
  rpcFreeCont(pMsg->pCont);
  
S
Shengliang Guan 已提交
346 347 348 349 350 351 352 353 354 355
  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.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = 0;
D
dapan1121 已提交
356
  metaRsp.tuid = ctgTestNormalTblUid++;
S
Shengliang Guan 已提交
357
  metaRsp.vgId = 8;
wafwerar's avatar
wafwerar 已提交
358
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
359 360

  SSchema *s = NULL;
S
Shengliang Guan 已提交
361
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
362
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
363 364
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
365 366
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
367
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
368
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
369 370
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
371
  strcpy(s->name, "col1");
S
Shengliang Guan 已提交
372

S
Shengliang Guan 已提交
373 374 375 376 377 378 379 380 381
  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 已提交
382 383
}

D
dapan1121 已提交
384
void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
385 386
  rpcFreeCont(pMsg->pCont);
  
D
dapan1121 已提交
387 388 389
  pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST;
}

D
dapan 已提交
390
void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
391 392
  rpcFreeCont(pMsg->pCont);
  
S
Shengliang Guan 已提交
393 394
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
D
dapan1121 已提交
395
  strcpy(metaRsp.tbName, ctgTestCurrentCTableName ? ctgTestCurrentCTableName : ctgTestCTablename);
S
Shengliang Guan 已提交
396 397 398 399 400 401 402 403 404 405
  strcpy(metaRsp.stbName, ctgTestSTablename);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_CHILD_TABLE;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = 0x0000000000000002;
  metaRsp.tuid = 0x0000000000000003;
  metaRsp.vgId = 9;
wafwerar's avatar
wafwerar 已提交
406
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
407 408

  SSchema *s = NULL;
S
Shengliang Guan 已提交
409
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
410
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
411 412
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
413 414
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
415
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
416
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
417 418
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
419 420
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
421
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
422
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
423 424
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
425 426
  strcpy(s->name, "tag1s");

S
Shengliang Guan 已提交
427 428 429 430 431 432 433 434 435
  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 已提交
436 437
}

D
dapan 已提交
438
void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
439 440
  rpcFreeCont(pMsg->pCont);
  
S
Shengliang Guan 已提交
441 442
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
D
dapan1121 已提交
443
  strcpy(metaRsp.tbName, ctgTestCurrentSTableName ? ctgTestCurrentSTableName : ctgTestSTablename);
S
Shengliang Guan 已提交
444 445 446 447 448 449 450 451
  strcpy(metaRsp.stbName, ctgTestSTablename);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_SUPER_TABLE;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = ctgTestSuid;
D
dapan1121 已提交
452
  metaRsp.tuid = ctgTestSuid+1;
S
Shengliang Guan 已提交
453
  metaRsp.vgId = 0;
wafwerar's avatar
wafwerar 已提交
454
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
455 456

  SSchema *s = NULL;
S
Shengliang Guan 已提交
457
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
458
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
459 460
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
461 462
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
463
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
464
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
465 466
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
467 468
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
469
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
470
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
471 472
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
473 474
  strcpy(s->name, "tag1s");

S
Shengliang Guan 已提交
475 476 477 478 479 480 481 482 483
  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 已提交
484 485
}

D
dapan 已提交
486
void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
487 488
  rpcFreeCont(pMsg->pCont);
  
D
dapan1121 已提交
489 490
  static int32_t idx = 1;

S
Shengliang Guan 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503
  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.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = ctgTestSuid + idx;
  metaRsp.tuid = ctgTestSuid + idx;
  metaRsp.vgId = 0;
wafwerar's avatar
wafwerar 已提交
504
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
505 506

  SSchema *s = NULL;
S
Shengliang Guan 已提交
507
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
508
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
509 510
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
511 512
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
513
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
514
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
515 516
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
517 518
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
519
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
520
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
521 522
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
523 524 525
  strcpy(s->name, "tag1s");

  ++idx;
S
Shengliang Guan 已提交
526

S
Shengliang Guan 已提交
527 528 529 530 531 532 533
  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 已提交
534

S
Shengliang Guan 已提交
535 536
  tFreeSTableMetaRsp(&metaRsp);
}
S
Shengliang Guan 已提交
537

D
dapan1121 已提交
538 539

void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
540 541
  rpcFreeCont(pMsg->pCont);
  
D
dapan1121 已提交
542 543 544 545 546 547
  pRsp->code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
  pRsp->contLen = 0;
  pRsp->pCont = NULL;
}


D
dapan1121 已提交
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);

  SGetUserAuthRsp userRsp = {0};
  strcpy(userRsp.user, ctgTestUsername);
  userRsp.version = 1;
  userRsp.superAuth = 1;

  int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSGetUserAuthRsp(pReq, contLen, &userRsp);

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

void ctgTestRspTableCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);
  
  static int32_t idx = 1;

  STableCfgRsp tblRsp = {0};
  strcpy(tblRsp.tbName, ctgTestTablename);
  tblRsp.numOfColumns = ctgTestColNum;

  tblRsp.pSchemas = (SSchema *)taosMemoryMalloc((tblRsp.numOfTags + tblRsp.numOfColumns) * sizeof(SSchema));

  SSchema *s = NULL;
  s = &tblRsp.pSchemas[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = 1;
  s->bytes = 8;
  strcpy(s->name, "ts");

  s = &tblRsp.pSchemas[1];
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = 2;
  s->bytes = 4;
  strcpy(s->name, "col1");

  int32_t contLen = tSerializeSTableCfgRsp(NULL, 0, &tblRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableCfgRsp(pReq, contLen, &tblRsp);

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

  tFreeSTableCfgRsp(&tblRsp);
}

void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);
  
  static int32_t idx = 1;

  STableIndexRsp tblRsp = {0};
  strcpy(tblRsp.tbName, ctgTestSTablename);

  tblRsp.pIndex = taosArrayInit(ctgTestIndexNum, sizeof(STableIndexInfo));

  STableIndexInfo info = {0};
  for (int32_t i = 0; i < ctgTestIndexNum; ++i) {
    info.interval = 1 + i;
    info.expr = (char*)taosMemoryCalloc(1, 10);
    taosArrayPush(tblRsp.pIndex, &info);
  }
  
  int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &tblRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableIndexRsp(pReq, contLen, &tblRsp);

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

  tFreeSTableIndexRsp(&tblRsp);
}

D
dapan1121 已提交
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
void ctgTestRspDBCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);
  
  static int32_t idx = 1;

  SDbCfgRsp dbRsp = {0};
  dbRsp.numOfVgroups = ctgTestVgNum;
  
  int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &dbRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSDbCfgRsp(pReq, contLen, &dbRsp);

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

void ctgTestRspQnodeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);

  SQnodeListRsp qlistRsp = {0};
  qlistRsp.qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
  for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
    SQueryNodeLoad nodeLoad = {0};
    nodeLoad.addr.nodeId = i;
    
    (void)taosArrayPush(qlistRsp.qnodeList, &nodeLoad);
  }

  int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
  void   *pReq = rpcMallocCont(rspLen);
  tSerializeSQnodeListRsp(pReq, rspLen, &qlistRsp);

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

  tFreeSQnodeListRsp(&qlistRsp);
}

void ctgTestRspUdfInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);

  SRetrieveFuncRsp funcRsp = {0};
  funcRsp.numOfFuncs = 1;
  funcRsp.pFuncInfos = taosArrayInit(1, sizeof(SFuncInfo));
  SFuncInfo funcInfo = {0};
  strcpy(funcInfo.name, "func1");
  funcInfo.funcType = ctgTestFuncType;
    
  (void)taosArrayPush(funcRsp.pFuncInfos, &funcInfo);

  int32_t rspLen = tSerializeSRetrieveFuncRsp(NULL, 0, &funcRsp);
  void   *pReq = rpcMallocCont(rspLen);
  tSerializeSRetrieveFuncRsp(pReq, rspLen, &funcRsp);

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

  tFreeSRetrieveFuncRsp(&funcRsp);
}

void ctgTestRspSvrVer(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);

  SServerVerRsp verRsp = {0};
  strcpy(verRsp.ver, "1.0");
  
  int32_t rspLen = tSerializeSServerVerRsp(NULL, 0, &verRsp);
  void   *pReq = rpcMallocCont(rspLen);
  tSerializeSServerVerRsp(pReq, rspLen, &verRsp);

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

D
dapan1121 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  rpcFreeCont(pMsg->pCont);

  SDnodeListRsp dRsp = {0};
  dRsp.dnodeList = taosArrayInit(1, sizeof(SEpSet));
  SEpSet epSet = {0};
  epSet.numOfEps = 1;
  tstrncpy(epSet.eps[0].fqdn, "localhost", TSDB_FQDN_LEN);
  epSet.eps[0].port = 6030;
  
  (void)taosArrayPush(dRsp.dnodeList, &epSet);
  
  int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &dRsp);
  void   *pReq = rpcMallocCont(rspLen);
  tSerializeSDnodeListRsp(pReq, rspLen, &dRsp);

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

  tFreeSDnodeListRsp(&dRsp);
}


D
dapan1121 已提交
730 731 732 733 734 735 736 737 738 739 740 741 742

void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  switch (pMsg->msgType) {
    case TDMT_MND_USE_DB:
      ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
      break;
    case TDMT_VND_TABLE_CFG:
    case TDMT_MND_TABLE_CFG:
      ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp);
      break;
    case TDMT_MND_GET_TABLE_INDEX:
      ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
743 744 745 746 747 748 749 750 751 752 753 754
    case TDMT_MND_GET_DB_CFG:
      ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
      break;
    case TDMT_MND_QNODE_LIST:
      ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);  
      break;
    case TDMT_MND_RETRIEVE_FUNC:
      ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
      break;
    case TDMT_MND_SERVER_VERSION:
      ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
755 756 757
    case TDMT_MND_DNODE_LIST:
      ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
758 759 760 761 762 763 764 765
    default:
      break;
  }

  return;
}


D
dapan 已提交
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
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;
D
dapan1121 已提交
783 784 785
    case CTGT_RSP_INDEXINFO_E:
      ctgTestRspErrIndexInfo(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
786 787 788 789 790 791
    case CTGT_RSP_USERAUTH:
      ctgTestRspUserAuth(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_TBLCFG:
      ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
792 793 794
    case CTGT_RSP_TBMETA_NOT_EXIST:
      ctgTestRspTableMetaNotExist(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
795 796 797
    case CTGT_RSP_TBLINDEX:
      ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
798 799 800 801 802 803 804 805 806 807 808 809
    case CTGT_RSP_DBCFG:
      ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_QNODELIST:
      ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_UDF:
      ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_SVRVER:
      ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
810 811 812
    case CTGT_RSP_DNODElIST:
      ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan 已提交
813
    default:
D
dapan1121 已提交
814
      ctgTestRspAuto(shandle, pEpSet, pMsg, pRsp);
D
dapan 已提交
815 816 817 818
      break;
  }

  ctgTestRspIdx++;
S
Shengliang Guan 已提交
819

D
dapan 已提交
820 821 822
  return;
}

D
dapan 已提交
823 824 825 826
void ctgTestRspDbVgroupsAndNormalMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);

  ctgTestSetRspTableMeta();
S
Shengliang Guan 已提交
827

D
dapan 已提交
828 829 830
  return;
}

D
dapan 已提交
831 832
void ctgTestRspDbVgroupsAndChildMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
833

D
dapan 已提交
834
  ctgTestSetRspCTableMeta();
S
Shengliang Guan 已提交
835

D
dapan 已提交
836 837 838
  return;
}

D
dapan 已提交
839 840
void ctgTestRspDbVgroupsAndSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
841

D
dapan 已提交
842
  ctgTestSetRspSTableMeta();
S
Shengliang Guan 已提交
843

D
dapan1121 已提交
844 845 846
  return;
}

D
dapan 已提交
847 848
void ctgTestRspDbVgroupsAndMultiSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
849

D
dapan 已提交
850
  ctgTestSetRspMultiSTableMeta();
S
Shengliang Guan 已提交
851

D
dapan1121 已提交
852 853 854
  return;
}

D
dapan 已提交
855
void ctgTestSetRspDbVgroups() {
D
dapan1121 已提交
856
  static Stub stub;
D
dapan 已提交
857
  stub.set(rpcSendRecv, ctgTestRspDbVgroups);
D
dapan1121 已提交
858
  {
wafwerar's avatar
wafwerar 已提交
859
#ifdef WINDOWS
H
Hongze Cheng 已提交
860 861
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
862 863 864
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
865 866
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
867
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
868
#endif
S
Shengliang Guan 已提交
869
    for (const auto &f : result) {
D
dapan 已提交
870
      stub.set(f.second, ctgTestRspDbVgroups);
D
dapan1121 已提交
871 872 873 874
    }
  }
}

D
dapan 已提交
875
void ctgTestSetRspTableMeta() {
D
dapan1121 已提交
876
  static Stub stub;
D
dapan 已提交
877
  stub.set(rpcSendRecv, ctgTestRspTableMeta);
D
dapan1121 已提交
878
  {
wafwerar's avatar
wafwerar 已提交
879
#ifdef WINDOWS
H
Hongze Cheng 已提交
880 881
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
882 883 884
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
885 886
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
887
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
888
#endif
S
Shengliang Guan 已提交
889
    for (const auto &f : result) {
D
dapan 已提交
890
      stub.set(f.second, ctgTestRspTableMeta);
D
dapan1121 已提交
891 892 893 894
    }
  }
}

D
dapan 已提交
895
void ctgTestSetRspCTableMeta() {
D
dapan1121 已提交
896
  static Stub stub;
D
dapan 已提交
897
  stub.set(rpcSendRecv, ctgTestRspCTableMeta);
D
dapan1121 已提交
898
  {
wafwerar's avatar
wafwerar 已提交
899
#ifdef WINDOWS
H
Hongze Cheng 已提交
900 901
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
902 903 904
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
905 906
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
907
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
908
#endif
S
Shengliang Guan 已提交
909
    for (const auto &f : result) {
D
dapan 已提交
910
      stub.set(f.second, ctgTestRspCTableMeta);
D
dapan1121 已提交
911 912 913 914
    }
  }
}

D
dapan 已提交
915
void ctgTestSetRspSTableMeta() {
D
dapan1121 已提交
916
  static Stub stub;
D
dapan 已提交
917
  stub.set(rpcSendRecv, ctgTestRspSTableMeta);
D
dapan1121 已提交
918
  {
wafwerar's avatar
wafwerar 已提交
919
#ifdef WINDOWS
H
Hongze Cheng 已提交
920 921
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
922 923 924
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
925 926
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
927
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
928
#endif
S
Shengliang Guan 已提交
929
    for (const auto &f : result) {
D
dapan 已提交
930
      stub.set(f.second, ctgTestRspSTableMeta);
D
dapan1121 已提交
931 932 933 934
    }
  }
}

D
dapan 已提交
935
void ctgTestSetRspMultiSTableMeta() {
D
dapan1121 已提交
936
  static Stub stub;
D
dapan 已提交
937
  stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta);
D
dapan1121 已提交
938
  {
wafwerar's avatar
wafwerar 已提交
939
#ifdef WINDOWS
H
Hongze Cheng 已提交
940 941
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
942 943 944
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
945 946
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
947
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
948
#endif
S
Shengliang Guan 已提交
949
    for (const auto &f : result) {
D
dapan 已提交
950
      stub.set(f.second, ctgTestRspMultiSTableMeta);
D
dapan1121 已提交
951 952 953 954
    }
  }
}

D
dapan 已提交
955
void ctgTestSetRspByIdx() {
D
dapan1121 已提交
956
  static Stub stub;
D
dapan 已提交
957
  stub.set(rpcSendRecv, ctgTestRspByIdx);
D
dapan1121 已提交
958
  {
wafwerar's avatar
wafwerar 已提交
959
#ifdef WINDOWS
H
Hongze Cheng 已提交
960 961
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
962 963 964
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
965 966
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
967
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
968
#endif
S
Shengliang Guan 已提交
969
    for (const auto &f : result) {
D
dapan 已提交
970
      stub.set(f.second, ctgTestRspByIdx);
D
dapan1121 已提交
971 972 973 974
    }
  }
}

D
dapan 已提交
975
void ctgTestSetRspDbVgroupsAndNormalMeta() {
D
dapan 已提交
976
  static Stub stub;
D
dapan 已提交
977
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta);
D
dapan 已提交
978
  {
wafwerar's avatar
wafwerar 已提交
979
#ifdef WINDOWS
H
Hongze Cheng 已提交
980 981
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
982 983 984
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
985 986
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan 已提交
987
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
988
#endif
S
Shengliang Guan 已提交
989
    for (const auto &f : result) {
D
dapan 已提交
990
      stub.set(f.second, ctgTestRspDbVgroupsAndNormalMeta);
D
dapan 已提交
991 992 993 994
    }
  }
}

D
dapan 已提交
995
void ctgTestSetRspDbVgroupsAndChildMeta() {
D
dapan1121 已提交
996
  static Stub stub;
D
dapan 已提交
997
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta);
D
dapan1121 已提交
998
  {
wafwerar's avatar
wafwerar 已提交
999
#ifdef WINDOWS
H
Hongze Cheng 已提交
1000 1001
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
1002 1003 1004
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
1005 1006
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
1007
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
1008
#endif
S
Shengliang Guan 已提交
1009
    for (const auto &f : result) {
D
dapan 已提交
1010
      stub.set(f.second, ctgTestRspDbVgroupsAndChildMeta);
D
dapan1121 已提交
1011 1012 1013 1014
    }
  }
}

D
dapan 已提交
1015
void ctgTestSetRspDbVgroupsAndSuperMeta() {
D
dapan1121 已提交
1016
  static Stub stub;
D
dapan 已提交
1017
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta);
D
dapan1121 已提交
1018
  {
wafwerar's avatar
wafwerar 已提交
1019
#ifdef WINDOWS
H
Hongze Cheng 已提交
1020 1021
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
1022 1023 1024
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
1025 1026
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
1027
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
1028
#endif
S
Shengliang Guan 已提交
1029
    for (const auto &f : result) {
D
dapan 已提交
1030
      stub.set(f.second, ctgTestRspDbVgroupsAndSuperMeta);
D
dapan1121 已提交
1031 1032 1033 1034
    }
  }
}

D
dapan 已提交
1035
void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
D
dapan1121 已提交
1036
  static Stub stub;
D
dapan 已提交
1037
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta);
D
dapan1121 已提交
1038
  {
wafwerar's avatar
wafwerar 已提交
1039
#ifdef WINDOWS
H
Hongze Cheng 已提交
1040 1041
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
1042 1043 1044
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
1045 1046
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
1047
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
1048
#endif
S
Shengliang Guan 已提交
1049
    for (const auto &f : result) {
D
dapan 已提交
1050
      stub.set(f.second, ctgTestRspDbVgroupsAndMultiSuperMeta);
D
dapan1121 已提交
1051 1052 1053 1054
    }
  }
}

S
Shengliang Guan 已提交
1055
}  // namespace
1056

D
dapan1121 已提交
1057
void *ctgTestGetDbVgroupThread(void *param) {
H
Hongze Cheng 已提交
1058 1059
  struct SCatalog  *pCtg = (struct SCatalog *)param;
  int32_t           code = 0;
D
dapan1121 已提交
1060 1061
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1062 1063
  SArray           *vgList = NULL;
  int32_t           n = 0;
S
Shengliang Guan 已提交
1064

D
dapan1121 已提交
1065
  while (!ctgTestStop) {
1066
    code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList);
D
dapan1121 已提交
1067
    if (code) {
D
dapan1121 已提交
1068
      printf("code:%x\n", code);
D
dapan1121 已提交
1069 1070 1071 1072 1073 1074 1075 1076
      assert(0);
    }

    if (vgList) {
      taosArrayDestroy(vgList);
    }

    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
1077
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
1078
    }
D
dapan1121 已提交
1079
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
1080 1081 1082 1083 1084 1085 1086
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
1087
void *ctgTestSetSameDbVgroupThread(void *param) {
S
Shengliang Guan 已提交
1088 1089
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
D
dapan1121 已提交
1090
  SDBVgInfo       *dbVgroup = NULL;
S
Shengliang Guan 已提交
1091 1092
  int32_t          n = 0;

D
dapan1121 已提交
1093 1094
  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
1095
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
D
dapan1121 已提交
1096 1097 1098 1099
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
1100
    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
1101
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
1102
    }
D
dapan1121 已提交
1103
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
1104 1105 1106 1107 1108 1109 1110
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
1111 1112 1113
void *ctgTestSetDiffDbVgroupThread(void *param) {
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
H
Hongze Cheng 已提交
1114
  SDBVgInfo       *dbVgroup = NULL;
D
dapan1121 已提交
1115 1116 1117 1118
  int32_t          n = 0;

  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
1119
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId++, dbVgroup);
D
dapan1121 已提交
1120 1121 1122 1123 1124
    if (code) {
      assert(0);
    }

    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
1125
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
1126 1127 1128 1129 1130 1131 1132 1133 1134
    }
    if (++n % ctgTestPrintNum == 0) {
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
1135
void *ctgTestGetCtableMetaThread(void *param) {
S
Shengliang Guan 已提交
1136 1137 1138 1139
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  int32_t          n = 0;
  STableMeta      *tbMeta = NULL;
D
dapan1121 已提交
1140
  bool             inCache = false;
D
dapan1121 已提交
1141

H
Hongze Cheng 已提交
1142
  SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1143 1144
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);
S
Shengliang Guan 已提交
1145

D
dapan1121 已提交
1146 1147 1148 1149
  SCtgTbMetaCtx ctx = {0};
  ctx.pName = &cn;
  ctx.flag = CTG_FLAG_UNKNOWN_STB;

D
dapan1121 已提交
1150
  while (!ctgTestStop) {
D
dapan1121 已提交
1151
    code = ctgReadTbMetaFromCache(pCtg, &ctx, &tbMeta);
D
dapan1121 已提交
1152
    if (code || NULL == tbMeta) {
D
dapan1121 已提交
1153 1154 1155
      assert(0);
    }

wafwerar's avatar
wafwerar 已提交
1156
    taosMemoryFreeClear(tbMeta);
D
dapan1121 已提交
1157

D
dapan1121 已提交
1158
    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
1159
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
1160
    }
S
Shengliang Guan 已提交
1161

D
dapan1121 已提交
1162
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
1163 1164 1165 1166 1167 1168 1169 1170
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

void *ctgTestSetCtableMetaThread(void *param) {
H
Hongze Cheng 已提交
1171 1172 1173 1174
  struct SCatalog  *pCtg = (struct SCatalog *)param;
  int32_t           code = 0;
  SDBVgInfo         dbVgroup = {0};
  int32_t           n = 0;
D
dapan 已提交
1175
  STableMetaOutput *output = NULL;
D
dapan1121 已提交
1176

D
dapan1121 已提交
1177
  SCtgCacheOperation operation = {0};
H
Hongze Cheng 已提交
1178

D
dapan1121 已提交
1179
  operation.opId = CTG_OP_UPDATE_TB_META;
S
Shengliang Guan 已提交
1180

D
dapan1121 已提交
1181
  while (!ctgTestStop) {
wafwerar's avatar
wafwerar 已提交
1182
    output = (STableMetaOutput *)taosMemoryMalloc(sizeof(STableMetaOutput));
D
dapan 已提交
1183 1184
    ctgTestBuildCTableMetaOutput(output);

D
dapan1121 已提交
1185
    SCtgUpdateTbMetaMsg *msg = (SCtgUpdateTbMetaMsg *)taosMemoryMalloc(sizeof(SCtgUpdateTbMetaMsg));
D
dapan1121 已提交
1186
    msg->pCtg = pCtg;
D
dapan1121 已提交
1187
    msg->pMeta = output;
D
dapan1121 已提交
1188
    operation.data = msg;
D
dapan1121 已提交
1189

D
dapan1121 已提交
1190
    code = ctgOpUpdateTbMeta(&operation);
D
dapan1121 已提交
1191 1192 1193 1194
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
1195
    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
1196
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
1197
    }
D
dapan1121 已提交
1198
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
1199 1200 1201 1202 1203 1204 1205
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan 已提交
1206

D
dapan 已提交
1207
TEST(tableMeta, normalTable) {
H
Hongze Cheng 已提交
1208 1209
  struct SCatalog  *pCtg = NULL;
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1210 1211
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1212

D
dapan1121 已提交
1213 1214
  ctgTestInitLogFile();

D
dapan 已提交
1215
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
1216

1217
  initQueryModuleMsgHandle();
D
ut test  
dapan1121 已提交
1218

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

D
dapan1121 已提交
1221 1222
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
1223

D
dapan1121 已提交
1224
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
1225
  ASSERT_EQ(code, 0);
1226

H
Hongze Cheng 已提交
1227
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
1228 1229 1230
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
1231
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1232
  ASSERT_EQ(code, 0);
D
dapan1121 已提交
1233
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1234
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1235

D
dapan1121 已提交
1236 1237 1238 1239 1240 1241 1242 1243
  while (true) {
    uint64_t n = 0;
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
    if (n != 1) {
      taosMsleep(50);
    } else {
      break;
    }
D
dapan 已提交
1244
  }
H
Hongze Cheng 已提交
1245

D
dapan1121 已提交
1246 1247 1248 1249 1250 1251 1252 1253
  memset(&vgInfo, 0, sizeof(vgInfo));
  bool exists = false;
  code = catalogGetCachedTableHashVgroup(pCtg, mockPointer, &n, &vgInfo, &exists);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
  ASSERT_EQ(exists, true);

D
dapan 已提交
1254
  ctgTestSetRspTableMeta();
D
dapan1121 已提交
1255 1256

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1257
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1258 1259 1260
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
D
dapan1121 已提交
1261
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1262 1263 1264 1265 1266 1267 1268
  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);

1269 1270
  taosMemoryFree(tableMeta);

D
dapan 已提交
1271
  while (true) {
D
dapan1121 已提交
1272
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1273
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1274
      taosMsleep(50);
D
dapan 已提交
1275 1276 1277
    } else {
      break;
    }
D
dapan 已提交
1278 1279
  }

D
dapan1121 已提交
1280
  tableMeta = NULL;
D
dapan1121 已提交
1281
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
  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);

1292 1293
  taosMemoryFree(tableMeta);

D
dapan1121 已提交
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
  tableMeta = NULL;
  catalogGetCachedTableMeta(pCtg, mockPointer, &n, &tableMeta);
  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);

H
Hongze Cheng 已提交
1306
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
1307
  SSTableVersion *stb = NULL;
H
Hongze Cheng 已提交
1308 1309
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t         i = 0;
D
dapan1121 已提交
1310 1311 1312 1313 1314 1315
  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 已提交
1316

D
dapan1121 已提交
1317
    if (dbNum) {
S
Shengliang Guan 已提交
1318
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
wafwerar's avatar
wafwerar 已提交
1319
      taosMemoryFree(dbs);
D
dapan1121 已提交
1320 1321 1322 1323 1324 1325
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
1326
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
wafwerar's avatar
wafwerar 已提交
1327
      taosMemoryFree(stb);
D
dapan1121 已提交
1328 1329 1330 1331 1332 1333 1334
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
wafwerar's avatar
wafwerar 已提交
1335
    taosSsleep(2);
D
dapan1121 已提交
1336
  }
S
Shengliang Guan 已提交
1337

D
dapan1121 已提交
1338 1339 1340
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 0);

D
dapan1121 已提交
1341 1342 1343
  catalogDestroy();
}

D
dapan 已提交
1344
TEST(tableMeta, childTableCase) {
H
Hongze Cheng 已提交
1345
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1346 1347
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1348
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1349

D
dapan1121 已提交
1350 1351
  ctgTestInitLogFile();

D
dapan 已提交
1352
  ctgTestSetRspDbVgroupsAndChildMeta();
D
dapan1121 已提交
1353 1354 1355

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
1356
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1357 1358
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1359

D
dapan1121 已提交
1360
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
1361 1362
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1363
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
1364 1365
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
D
dapan1121 已提交
1366 1367

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1368
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
  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);

1379 1380
  taosMemoryFree(tableMeta);

D
dapan 已提交
1381
  while (true) {
D
dapan1121 已提交
1382
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1383
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1384
      taosMsleep(50);
D
dapan 已提交
1385 1386 1387
    } else {
      break;
    }
D
dapan 已提交
1388 1389
  }

D
dapan1121 已提交
1390
  tableMeta = NULL;
D
dapan1121 已提交
1391
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
  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);

wafwerar's avatar
wafwerar 已提交
1402
  taosMemoryFreeClear(tableMeta);
H
Haojun Liao 已提交
1403 1404

  strcpy(n.tname, ctgTestSTablename);
D
dapan1121 已提交
1405
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
  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);

1416 1417
  taosMemoryFree(tableMeta);

H
Hongze Cheng 已提交
1418
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
1419
  SSTableVersion *stb = NULL;
H
Hongze Cheng 已提交
1420 1421
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t         i = 0;
D
dapan1121 已提交
1422 1423 1424 1425 1426 1427
  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 已提交
1428

D
dapan1121 已提交
1429
    if (dbNum) {
S
Shengliang Guan 已提交
1430
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
wafwerar's avatar
wafwerar 已提交
1431
      taosMemoryFree(dbs);
D
dapan1121 已提交
1432 1433 1434 1435 1436 1437
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
S
Shengliang Guan 已提交
1438
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
wafwerar's avatar
wafwerar 已提交
1439
      taosMemoryFree(stb);
D
dapan1121 已提交
1440 1441 1442 1443 1444 1445 1446
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
wafwerar's avatar
wafwerar 已提交
1447
    taosSsleep(2);
D
dapan1121 已提交
1448
  }
S
Shengliang Guan 已提交
1449

D
dapan1121 已提交
1450 1451 1452
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);

D
dapan1121 已提交
1453 1454 1455
  catalogDestroy();
}

D
dapan 已提交
1456
TEST(tableMeta, superTableCase) {
H
Hongze Cheng 已提交
1457
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1458 1459
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1460
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1461

D
dapan 已提交
1462
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1463 1464 1465

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1466 1467 1468
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1469
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1470
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
1471 1472
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1473
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
1474 1475
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan1121 已提交
1476 1477

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1478
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1479 1480 1481 1482 1483
  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 已提交
1484 1485
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1486 1487 1488 1489 1490
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

1491 1492
  taosMemoryFree(tableMeta);

D
dapan 已提交
1493
  while (true) {
D
dapan1121 已提交
1494
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1495
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1496
      taosMsleep(50);
D
dapan 已提交
1497 1498 1499
    } else {
      break;
    }
D
dapan 已提交
1500 1501
  }

D
dapan1121 已提交
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516
  tableMeta = NULL;
  code = catalogGetCachedSTableMeta(pCtg, 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);
  taosMemoryFree(tableMeta);

D
dapan 已提交
1517
  ctgTestSetRspCTableMeta();
D
dapan1121 已提交
1518 1519

  tableMeta = NULL;
H
Haojun Liao 已提交
1520 1521 1522

  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
D
dapan1121 已提交
1523
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533
  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);

1534 1535
  taosMemoryFree(tableMeta);

D
dapan 已提交
1536
  while (true) {
D
dapan1121 已提交
1537
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1538
    if (2 != n) {
wafwerar's avatar
wafwerar 已提交
1539
      taosMsleep(50);
D
dapan 已提交
1540 1541 1542
    } else {
      break;
    }
D
dapan 已提交
1543 1544
  }

D
dapan1121 已提交
1545
  tableMeta = NULL;
D
dapan1121 已提交
1546
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
  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);

1557 1558
  taosMemoryFree(tableMeta);

H
Hongze Cheng 已提交
1559
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
1560
  SSTableVersion *stb = NULL;
H
Hongze Cheng 已提交
1561 1562
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t         i = 0;
D
dapan1121 已提交
1563 1564 1565 1566 1567 1568
  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 已提交
1569

D
dapan1121 已提交
1570
    if (dbNum) {
S
Shengliang Guan 已提交
1571
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
wafwerar's avatar
wafwerar 已提交
1572
      taosMemoryFree(dbs);
D
dapan1121 已提交
1573 1574 1575 1576 1577 1578
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

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

wafwerar's avatar
wafwerar 已提交
1581
      taosMemoryFree(stb);
D
dapan1121 已提交
1582 1583 1584 1585 1586 1587 1588
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
wafwerar's avatar
wafwerar 已提交
1589
    taosSsleep(2);
D
dapan1121 已提交
1590
  }
S
Shengliang Guan 已提交
1591

D
dapan1121 已提交
1592 1593
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);
D
dapan1121 已提交
1594 1595

  catalogDestroy();
D
dapan1121 已提交
1596
}
1597

D
dapan1121 已提交
1598
TEST(tableMeta, rmStbMeta) {
H
Hongze Cheng 已提交
1599
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1600 1601
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1602
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1603 1604 1605

  ctgTestInitLogFile();

D
dapan 已提交
1606
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616

  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);

H
Hongze Cheng 已提交
1617
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1618 1619 1620 1621
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1622
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1623 1624 1625 1626 1627
  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 已提交
1628 1629
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1630 1631 1632 1633 1634
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

1635 1636
  taosMemoryFree(tableMeta);

D
dapan 已提交
1637
  while (true) {
D
dapan1121 已提交
1638
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1639
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1640
      taosMsleep(50);
D
dapan 已提交
1641 1642 1643
    } else {
      break;
    }
D
dapan 已提交
1644 1645
  }

D
dapan1121 已提交
1646
  code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid);
D
dapan1121 已提交
1647 1648
  ASSERT_EQ(code, 0);

D
dapan 已提交
1649
  while (true) {
D
dapan1121 已提交
1650 1651
    int32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    int32_t m = ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
D
dapan 已提交
1652
    if (n || m) {
wafwerar's avatar
wafwerar 已提交
1653
      taosMsleep(50);
D
dapan 已提交
1654 1655 1656
    } else {
      break;
    }
D
dapan 已提交
1657 1658
  }

D
dapan1121 已提交
1659 1660 1661 1662 1663
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
S
Shengliang Guan 已提交
1664

D
dapan1121 已提交
1665 1666 1667 1668
  catalogDestroy();
}

TEST(tableMeta, updateStbMeta) {
H
Hongze Cheng 已提交
1669
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1670 1671
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1672
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1673 1674 1675

  ctgTestInitLogFile();

D
dapan 已提交
1676
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686

  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);

H
Hongze Cheng 已提交
1687
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1688 1689 1690 1691
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1692
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1693 1694 1695 1696 1697
  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 已提交
1698 1699
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1700 1701 1702 1703 1704
  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 已提交
1705
  while (true) {
D
dapan1121 已提交
1706
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1707
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1708
      taosMsleep(50);
D
dapan 已提交
1709 1710 1711
    } else {
      break;
    }
D
dapan 已提交
1712 1713
  }

wafwerar's avatar
wafwerar 已提交
1714
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1715 1716 1717 1718

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

D
dapan1121 已提交
1719
  code = catalogUpdateTableMeta(pCtg, &rsp);
D
dapan1121 已提交
1720
  ASSERT_EQ(code, 0);
wafwerar's avatar
wafwerar 已提交
1721
  taosMemoryFreeClear(rsp.pSchemas);
D
dapan1121 已提交
1722

D
dapan 已提交
1723 1724
  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1725
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan 已提交
1726
    if (n != 3) {
wafwerar's avatar
wafwerar 已提交
1727
      taosMsleep(50);
D
dapan 已提交
1728 1729 1730 1731 1732
    } else {
      break;
    }
  }

D
dapan1121 已提交
1733 1734 1735 1736 1737
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1);
D
dapan1121 已提交
1738

D
dapan1121 已提交
1739
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1740 1741 1742 1743 1744
  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);
D
dapan1121 已提交
1745 1746
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1747 1748 1749 1750 1751
  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);

wafwerar's avatar
wafwerar 已提交
1752
  taosMemoryFreeClear(tableMeta);
S
Shengliang Guan 已提交
1753

D
dapan1121 已提交
1754 1755 1756
  catalogDestroy();
}

D
dapan1121 已提交
1757 1758
TEST(getIndexInfo, notExists) {
  struct SCatalog  *pCtg = NULL;
1759 1760
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
D
dapan1121 已提交
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_INDEXINFO_E;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  SIndexInfo info;
  code = catalogGetIndexMeta(pCtg, mockPointer, "index1", &info);
  ASSERT_TRUE(code != 0);
1783 1784
  
  catalogDestroy();
D
dapan1121 已提交
1785 1786
}

D
dapan1121 已提交
1787
TEST(refreshGetMeta, normal2normal) {
H
Hongze Cheng 已提交
1788
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1789 1790
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1791 1792
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1793 1794 1795 1796 1797 1798 1799 1800

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_TBMETA;
H
Hongze Cheng 已提交
1801

D
dapan1121 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
  ctgTestSetRspByIdx();

  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);

H
Hongze Cheng 已提交
1814
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1815 1816 1817
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
1818
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1819 1820
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1821
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1822 1823 1824

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1825
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1826 1827 1828
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1829
    taosMsleep(50);
D
dapan1121 已提交
1830 1831 1832
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1833
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1834 1835 1836
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1837
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1838 1839 1840 1841 1842 1843
  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);
wafwerar's avatar
wafwerar 已提交
1844
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1845

D
dapan1121 已提交
1846
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1847
    taosMsleep(50);
D
dapan1121 已提交
1848 1849
  }

D
dapan1121 已提交
1850
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1851 1852 1853
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1854
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1855 1856 1857 1858 1859 1860
  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);
wafwerar's avatar
wafwerar 已提交
1861
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1862 1863 1864 1865 1866

  catalogDestroy();
}

TEST(refreshGetMeta, normal2notexist) {
H
Hongze Cheng 已提交
1867
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1868 1869
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1870 1871
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1872 1873 1874 1875 1876 1877 1878 1879

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_TBMETA_NOT_EXIST;
H
Hongze Cheng 已提交
1880

D
dapan1121 已提交
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
  ctgTestSetRspByIdx();

  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);

H
Hongze Cheng 已提交
1893
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1894 1895 1896
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
1897
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1898 1899
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1900
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1901 1902 1903

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1904
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1905 1906 1907
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1908
    taosMsleep(50);
D
dapan1121 已提交
1909 1910 1911
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1912
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1913 1914 1915
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1916
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1917 1918 1919 1920 1921 1922
  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);
wafwerar's avatar
wafwerar 已提交
1923
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1924

D
dapan1121 已提交
1925
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1926
    taosMsleep(50);
D
dapan1121 已提交
1927 1928
  }

D
dapan1121 已提交
1929
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1930 1931 1932 1933 1934 1935 1936
  ASSERT_EQ(code, CTG_ERR_CODE_TABLE_NOT_EXIST);
  ASSERT_TRUE(tableMeta == NULL);

  catalogDestroy();
}

TEST(refreshGetMeta, normal2child) {
H
Hongze Cheng 已提交
1937
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1938 1939
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1940 1941
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1942 1943 1944 1945 1946 1947 1948 1949 1950

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_CTBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
1951

D
dapan1121 已提交
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
  ctgTestSetRspByIdx();

  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);

H
Hongze Cheng 已提交
1964
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1965 1966 1967 1968 1969
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentCTableName = ctgTestTablename;
  ctgTestCurrentSTableName = ctgTestSTablename;

D
dapan1121 已提交
1970
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1971 1972
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1973
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1974 1975 1976

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1977
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1978 1979 1980
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1981
    taosMsleep(50);
D
dapan1121 已提交
1982 1983 1984
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1985
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1986 1987 1988
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1989
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1990 1991 1992 1993 1994 1995
  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);
wafwerar's avatar
wafwerar 已提交
1996
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1997

D
dapan1121 已提交
1998
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1999
    taosMsleep(50);
D
dapan1121 已提交
2000 2001
  }

D
dapan1121 已提交
2002
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
2003 2004 2005 2006 2007 2008 2009 2010 2011
  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);
wafwerar's avatar
wafwerar 已提交
2012
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2013 2014 2015 2016 2017 2018

  catalogDestroy();
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

D
dapan1121 已提交
2019

D
dapan1121 已提交
2020
TEST(refreshGetMeta, stable2child) {
H
Hongze Cheng 已提交
2021
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2022 2023
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2024 2025
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035

  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_CTBMETA;
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
2036

D
dapan1121 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
  ctgTestSetRspByIdx();

  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);

H
Hongze Cheng 已提交
2049
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2050 2051 2052 2053 2054
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentSTableName = ctgTestTablename;
  ctgTestCurrentCTableName = ctgTestTablename;

D
dapan1121 已提交
2055
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2056 2057
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
2058
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
2059 2060 2061

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2062
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
2063 2064 2065
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
2066
    taosMsleep(50);
D
dapan1121 已提交
2067 2068 2069
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
2070
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
2071 2072 2073 2074 2075
  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 已提交
2076 2077
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
2078 2079 2080 2081
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
2082
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2083

D
dapan1121 已提交
2084
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
2085
    taosMsleep(50);
D
dapan1121 已提交
2086 2087 2088
  }

  ctgTestCurrentSTableName = ctgTestSTablename;
D
dapan1121 已提交
2089
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
2090 2091 2092 2093 2094 2095 2096 2097 2098
  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);
wafwerar's avatar
wafwerar 已提交
2099
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2100 2101 2102 2103 2104 2105 2106

  catalogDestroy();
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

TEST(refreshGetMeta, stable2stable) {
H
Hongze Cheng 已提交
2107
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2108 2109
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2110 2111
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121

  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_STBMETA;
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
2122

D
dapan1121 已提交
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134
  ctgTestSetRspByIdx();

  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);

H
Hongze Cheng 已提交
2135
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2136 2137 2138 2139
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentSTableName = ctgTestTablename;

D
dapan1121 已提交
2140
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2141 2142
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
2143
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
2144 2145 2146

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2147
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
2148 2149 2150
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
2151
    taosMsleep(50);
D
dapan1121 已提交
2152 2153 2154
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
2155
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
2156 2157 2158 2159 2160
  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 已提交
2161 2162
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
2163 2164 2165 2166
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
2167
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2168

D
dapan1121 已提交
2169
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
2170
    taosMsleep(50);
D
dapan1121 已提交
2171 2172
  }

D
dapan1121 已提交
2173
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
2174 2175 2176 2177 2178
  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 已提交
2179 2180
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
2181 2182 2183 2184
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
2185
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2186 2187 2188 2189 2190 2191 2192

  catalogDestroy();
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

TEST(refreshGetMeta, child2stable) {
H
Hongze Cheng 已提交
2193
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2194 2195
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2196 2197
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207

  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_STBMETA;
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
2208

D
dapan1121 已提交
2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220
  ctgTestSetRspByIdx();

  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);

H
Hongze Cheng 已提交
2221
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2222 2223 2224 2225 2226
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentCTableName = ctgTestTablename;
  ctgTestCurrentSTableName = ctgTestSTablename;

D
dapan1121 已提交
2227
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2228 2229
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
2230
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
2231 2232 2233

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2234
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
2235 2236 2237
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
2238
    taosMsleep(50);
D
dapan1121 已提交
2239 2240 2241
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
2242
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
2243 2244 2245 2246 2247 2248 2249 2250 2251
  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);
wafwerar's avatar
wafwerar 已提交
2252
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2253

D
dapan1121 已提交
2254
  while (2 != ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
2255
    taosMsleep(50);
D
dapan1121 已提交
2256 2257 2258
  }

  ctgTestCurrentSTableName = ctgTestTablename;
D
dapan1121 已提交
2259
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
2260 2261 2262 2263 2264
  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 已提交
2265 2266
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
2267 2268 2269 2270
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
2271
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
2272 2273 2274 2275 2276 2277

  catalogDestroy();
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

D
dapan 已提交
2278
TEST(tableDistVgroup, normalTable) {
H
Hongze Cheng 已提交
2279
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2280 2281
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2282 2283
  SVgroupInfo      *vgInfo = NULL;
  SArray           *vgList = NULL;
D
dapan 已提交
2284

D
dapan 已提交
2285 2286 2287 2288 2289 2290 2291
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_VGINFO;
H
Hongze Cheng 已提交
2292

D
dapan 已提交
2293
  ctgTestSetRspByIdx();
D
dapan 已提交
2294 2295 2296

  initQueryModuleMsgHandle();

D
dapan1121 已提交
2297 2298 2299
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

D
dapan1121 已提交
2302
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
2303 2304
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2305
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
2306 2307
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
D
dapan 已提交
2308

D
dapan1121 已提交
2309
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2310
  ASSERT_TRUE(code != 0);
D
dapan 已提交
2311 2312 2313 2314 2315

  catalogDestroy();
}

TEST(tableDistVgroup, childTableCase) {
H
Hongze Cheng 已提交
2316
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2317 2318
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2319 2320
  SVgroupInfo      *vgInfo = NULL;
  SArray           *vgList = NULL;
D
dapan 已提交
2321

D
dapan 已提交
2322 2323 2324 2325 2326 2327 2328 2329
  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;
H
Hongze Cheng 已提交
2330

D
dapan 已提交
2331
  ctgTestSetRspByIdx();
D
dapan 已提交
2332 2333 2334

  initQueryModuleMsgHandle();

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

D
dapan 已提交
2337 2338 2339 2340 2341 2342
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

H
Hongze Cheng 已提交
2343
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
2344 2345 2346
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);

D
dapan1121 已提交
2347
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2348
  ASSERT_TRUE(code != 0);
D
dapan 已提交
2349 2350 2351 2352 2353

  catalogDestroy();
}

TEST(tableDistVgroup, superTableCase) {
H
Hongze Cheng 已提交
2354
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2355 2356
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2357 2358
  SVgroupInfo      *vgInfo = NULL;
  SArray           *vgList = NULL;
D
dapan 已提交
2359

D
dapan 已提交
2360 2361 2362 2363 2364 2365 2366 2367 2368
  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;

H
Hongze Cheng 已提交
2369
  ctgTestSetRspByIdx();
D
dapan 已提交
2370 2371 2372

  initQueryModuleMsgHandle();

D
dapan1121 已提交
2373 2374 2375
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
2376
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
2377
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
2378 2379
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2380
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
2381 2382
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan 已提交
2383

D
dapan1121 已提交
2384
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan 已提交
2385 2386 2387 2388
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 1);
L
Liu Jicong 已提交
2389
  ASSERT_EQ(vgInfo->epSet.numOfEps, 1);
D
dapan 已提交
2390 2391
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1);
  ASSERT_EQ(vgInfo->vgId, 2);
L
Liu Jicong 已提交
2392
  ASSERT_EQ(vgInfo->epSet.numOfEps, 2);
D
dapan 已提交
2393 2394
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2);
  ASSERT_EQ(vgInfo->vgId, 3);
L
Liu Jicong 已提交
2395
  ASSERT_EQ(vgInfo->epSet.numOfEps, 3);
D
dapan 已提交
2396

2397 2398
  taosArrayDestroy(vgList);

D
dapan 已提交
2399 2400 2401
  catalogDestroy();
}

D
dapan1121 已提交
2402
TEST(dbVgroup, getSetDbVgroupCase) {
H
Hongze Cheng 已提交
2403
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2404 2405
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2406 2407 2408 2409
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo        *dbVgroup = NULL;
  SArray           *vgList = NULL;
D
dapan1121 已提交
2410

D
dapan 已提交
2411 2412
  ctgTestInitLogFile();

D
dapan 已提交
2413 2414 2415 2416 2417 2418 2419
  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;

  ctgTestSetRspByIdx();

D
dapan1121 已提交
2420 2421
  initQueryModuleMsgHandle();

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

D
dapan1121 已提交
2424 2425 2426 2427 2428 2429
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

H
Hongze Cheng 已提交
2430
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2431 2432 2433
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

2434
  code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList);
D
dapan1121 已提交
2435 2436
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
S
Shengliang Guan 已提交
2437

2438 2439
  taosArrayDestroy(vgList);

D
dapan1121 已提交
2440 2441
  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2442
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
2443 2444 2445
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
2446
    taosMsleep(50);
D
dapan 已提交
2447 2448
  }

D
dapan1121 已提交
2449
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2450 2451
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
2452
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
2453

D
dapan1121 已提交
2454
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2455
  ASSERT_TRUE(code != 0);
D
dapan1121 已提交
2456

D
dapan1121 已提交
2457 2458 2459 2460 2461 2462 2463 2464 2465
  int32_t dbVer = 0;
  int64_t dbId = 0;
  int32_t tbNum = 0;
  code = catalogGetDBVgVersion(pCtg, ctgTestDbname, &dbVer, &dbId, &tbNum);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(dbVer, ctgTestVgVersion);
  ASSERT_EQ(dbId, ctgTestDbId);
  ASSERT_EQ(tbNum, ctgTestVgNum / 2);

D
dapan1121 已提交
2466
  ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
2467
  code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
D
dapan1121 已提交
2468 2469
  ASSERT_EQ(code, 0);

D
dapan 已提交
2470 2471
  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2472
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan 已提交
2473
    if (n != 3) {
wafwerar's avatar
wafwerar 已提交
2474
      taosMsleep(50);
D
dapan 已提交
2475 2476 2477 2478 2479
    } else {
      break;
    }
  }

D
dapan1121 已提交
2480
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2481 2482
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 7);
L
Liu Jicong 已提交
2483
  ASSERT_EQ(vgInfo.epSet.numOfEps, 2);
D
dapan1121 已提交
2484

D
dapan1121 已提交
2485
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2486
  ASSERT_TRUE(code != 0);
S
Shengliang Guan 已提交
2487

D
dapan1121 已提交
2488 2489 2490
  catalogDestroy();
}

D
dapan1121 已提交
2491
TEST(multiThread, getSetRmSameDbVgroup) {
H
Hongze Cheng 已提交
2492
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2493 2494
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2495 2496 2497 2498
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2499
  ctgTestStop = false;
D
dapan1121 已提交
2500 2501

  ctgTestInitLogFile();
S
Shengliang Guan 已提交
2502

D
dapan 已提交
2503
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
2504 2505 2506

  initQueryModuleMsgHandle();

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

D
dapan1121 已提交
2509 2510 2511 2512 2513 2514
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

H
Hongze Cheng 已提交
2515
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2516 2517 2518
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

wafwerar's avatar
wafwerar 已提交
2519 2520
  TdThreadAttr thattr;
  taosThreadAttrInit(&thattr);
D
dapan1121 已提交
2521

wafwerar's avatar
wafwerar 已提交
2522 2523
  TdThread thread1, thread2;
  taosThreadCreate(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
D
dapan1121 已提交
2524

wafwerar's avatar
wafwerar 已提交
2525
  taosSsleep(1);
wafwerar's avatar
wafwerar 已提交
2526
  taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
D
dapan1121 已提交
2527 2528 2529

  while (true) {
    if (ctgTestDeadLoop) {
wafwerar's avatar
wafwerar 已提交
2530
      taosSsleep(1);
D
dapan1121 已提交
2531
    } else {
wafwerar's avatar
wafwerar 已提交
2532
      taosSsleep(ctgTestMTRunSec);
D
dapan1121 已提交
2533 2534 2535
      break;
    }
  }
S
Shengliang Guan 已提交
2536

D
dapan1121 已提交
2537
  ctgTestStop = true;
wafwerar's avatar
wafwerar 已提交
2538
  taosSsleep(1);
S
Shengliang Guan 已提交
2539

D
dapan1121 已提交
2540 2541 2542
  catalogDestroy();
}

D
dapan1121 已提交
2543
TEST(multiThread, getSetRmDiffDbVgroup) {
H
Hongze Cheng 已提交
2544
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2545 2546
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2547 2548 2549 2550
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2551 2552 2553 2554
  ctgTestStop = false;

  ctgTestInitLogFile();

D
dapan 已提交
2555
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566

  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);

H
Hongze Cheng 已提交
2567
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2568 2569 2570
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

wafwerar's avatar
wafwerar 已提交
2571 2572
  TdThreadAttr thattr;
  taosThreadAttrInit(&thattr);
D
dapan1121 已提交
2573

wafwerar's avatar
wafwerar 已提交
2574 2575
  TdThread thread1, thread2;
  taosThreadCreate(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
D
dapan1121 已提交
2576

wafwerar's avatar
wafwerar 已提交
2577
  taosSsleep(1);
wafwerar's avatar
wafwerar 已提交
2578
  taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
D
dapan1121 已提交
2579 2580 2581

  while (true) {
    if (ctgTestDeadLoop) {
wafwerar's avatar
wafwerar 已提交
2582
      taosSsleep(1);
D
dapan1121 已提交
2583
    } else {
wafwerar's avatar
wafwerar 已提交
2584
      taosSsleep(ctgTestMTRunSec);
D
dapan1121 已提交
2585 2586 2587 2588 2589
      break;
    }
  }

  ctgTestStop = true;
wafwerar's avatar
wafwerar 已提交
2590
  taosSsleep(1);
D
dapan1121 已提交
2591 2592 2593 2594

  catalogDestroy();
}

D
dapan1121 已提交
2595
TEST(multiThread, ctableMeta) {
H
Hongze Cheng 已提交
2596
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2597 2598
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2599 2600 2601 2602
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2603
  ctgTestStop = false;
D
dapan1121 已提交
2604

D
dapan 已提交
2605 2606
  ctgTestInitLogFile();

D
dapan 已提交
2607
  ctgTestSetRspDbVgroupsAndChildMeta();
D
dapan1121 已提交
2608 2609 2610

  initQueryModuleMsgHandle();

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

D
dapan1121 已提交
2613 2614 2615 2616 2617 2618
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

H
Hongze Cheng 已提交
2619
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2620 2621 2622
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

wafwerar's avatar
wafwerar 已提交
2623 2624
  TdThreadAttr thattr;
  taosThreadAttrInit(&thattr);
D
dapan1121 已提交
2625

wafwerar's avatar
wafwerar 已提交
2626 2627
  TdThread thread1, thread2;
  taosThreadCreate(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
wafwerar's avatar
wafwerar 已提交
2628
  taosSsleep(1);
wafwerar's avatar
wafwerar 已提交
2629
  taosThreadCreate(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
D
dapan1121 已提交
2630 2631 2632

  while (true) {
    if (ctgTestDeadLoop) {
wafwerar's avatar
wafwerar 已提交
2633
      taosSsleep(1);
D
dapan1121 已提交
2634
    } else {
wafwerar's avatar
wafwerar 已提交
2635
      taosSsleep(ctgTestMTRunSec);
D
dapan1121 已提交
2636 2637 2638
      break;
    }
  }
S
Shengliang Guan 已提交
2639

D
dapan1121 已提交
2640
  ctgTestStop = true;
wafwerar's avatar
wafwerar 已提交
2641
  taosSsleep(2);
S
Shengliang Guan 已提交
2642

D
dapan1121 已提交
2643 2644
  catalogDestroy();
}
D
dapan 已提交
2645

D
dapan1121 已提交
2646
TEST(rentTest, allRent) {
H
Hongze Cheng 已提交
2647
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2648 2649
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2650 2651 2652 2653
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2654
  ctgTestStop = false;
H
Hongze Cheng 已提交
2655
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
2656
  SSTableVersion *stable = NULL;
H
Hongze Cheng 已提交
2657
  uint32_t        num = 0;
D
dapan1121 已提交
2658

D
dapan 已提交
2659 2660
  ctgTestInitLogFile();

D
dapan 已提交
2661
  ctgTestSetRspDbVgroupsAndMultiSuperMeta();
D
dapan1121 已提交
2662 2663 2664 2665 2666 2667 2668 2669 2670

  initQueryModuleMsgHandle();

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

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

H
Hongze Cheng 已提交
2671
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2672 2673 2674 2675 2676 2677
  strcpy(n.dbname, "db1");

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

    STableMeta *tableMeta = NULL;
D
dapan1121 已提交
2678
    code = catalogGetSTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689
    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 已提交
2690

2691 2692
    taosMemoryFree(tableMeta);

D
dapan1121 已提交
2693
    while (ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
wafwerar's avatar
wafwerar 已提交
2694
      taosMsleep(50);
D
dapan 已提交
2695 2696
    }

D
dapan1121 已提交
2697 2698 2699 2700
    code = catalogGetExpiredDBs(pCtg, &dbs, &num);
    ASSERT_EQ(code, 0);
    printf("%d - expired dbNum:%d\n", i, num);
    if (dbs) {
S
Shengliang Guan 已提交
2701
      printf("%d - expired dbId:%" PRId64 ", vgVersion:%d\n", i, dbs->dbId, dbs->vgVersion);
wafwerar's avatar
wafwerar 已提交
2702
      taosMemoryFree(dbs);
D
dapan1121 已提交
2703 2704
      dbs = NULL;
    }
S
Shengliang Guan 已提交
2705

D
dapan1121 已提交
2706 2707 2708 2709 2710
    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 已提交
2711 2712
        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 已提交
2713
      }
wafwerar's avatar
wafwerar 已提交
2714
      taosMemoryFree(stable);
D
dapan1121 已提交
2715 2716 2717
      stable = NULL;
    }
    printf("*************************************************\n");
S
Shengliang Guan 已提交
2718

wafwerar's avatar
wafwerar 已提交
2719
    taosSsleep(2);
D
dapan1121 已提交
2720
  }
S
Shengliang Guan 已提交
2721

D
dapan1121 已提交
2722 2723 2724
  catalogDestroy();
}

D
dapan1121 已提交
2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854
TEST(apiTest, catalogRefreshDBVgInfo_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  code = catalogRefreshDBVgInfo(pCtg, mockPointer, ctgTestDbname);
  ASSERT_EQ(code, 0);

  catalogDestroy();
}

TEST(apiTest, catalogChkAuth_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_USERAUTH;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  bool pass = false;
  code = catalogChkAuth(pCtg, mockPointer, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(pass, true);

  catalogDestroy();
}

TEST(apiTest, catalogRefreshGetTableCfg_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  STableCfg *pCfg = NULL;

  code = catalogRefreshGetTableCfg(pCtg, mockPointer, &n, &pCfg);
  ASSERT_EQ(code, 0);
  ASSERT_TRUE(NULL != pCfg);
  ASSERT_EQ(pCfg->numOfColumns, ctgTestColNum);

  tFreeSTableCfgRsp((STableCfgRsp *)pCfg);
  taosMemoryFree(pCfg);

  catalogDestroy();
}

TEST(apiTest, catalogGetTableIndex_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_TBLINDEX;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  SArray *pRes = NULL;

  code = catalogGetTableIndex(pCtg, mockPointer, &n, &pRes);
  ASSERT_EQ(code, 0);
  ASSERT_TRUE(NULL != pRes);
  ASSERT_EQ(taosArrayGetSize(pRes), ctgTestIndexNum);

  taosArrayDestroyEx(pRes, tFreeSTableIndexInfo);

  catalogDestroy();
}

D
dapan1121 已提交
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981
TEST(apiTest, catalogGetDBCfg_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_DBCFG;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

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

  SDbCfgInfo cfgInfo = {0};
  code = catalogGetDBCfg(pCtg, mockPointer, ctgTestDbname, &cfgInfo);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(cfgInfo.numOfVgroups, ctgTestVgNum);

  catalogDestroy();
}

TEST(apiTest, catalogGetQnodeList_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_QNODELIST;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  SArray *qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
  code = catalogGetQnodeList(pCtg, mockPointer, qnodeList);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize(qnodeList), ctgTestQnodeNum);

  for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
    SQueryNodeLoad * pLoad = (SQueryNodeLoad *)taosArrayGet(qnodeList, i);
    ASSERT_EQ(pLoad->addr.nodeId, i);
  }

  catalogDestroy();
}


TEST(apiTest, catalogGetUdfInfo_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_UDF;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  SFuncInfo funcInfo = {0};
  code = catalogGetUdfInfo(pCtg, mockPointer, "func1", &funcInfo);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(funcInfo.funcType, ctgTestFuncType);

  catalogDestroy();
}


TEST(apiTest, catalogGetServerVersion_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_SVRVER;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  char* ver = NULL;
  code = catalogGetServerVersion(pCtg, mockPointer, &ver);
  ASSERT_EQ(code, 0);
  ASSERT_TRUE(0 == strcmp(ver, "1.0"));

  catalogDestroy();
}

D
dapan1121 已提交
2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044
TEST(apiTest, catalogUpdateTableIndex_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_SVRVER;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  STableIndexRsp rsp = {0};
  strcpy(rsp.dbFName, ctgTestDbname);
  strcpy(rsp.tbName, ctgTestSTablename);
  rsp.suid = ctgTestSuid;
  rsp.version = 1;
  code = catalogUpdateTableIndex(pCtg, &rsp);
  ASSERT_EQ(code, 0);

  catalogDestroy();
}


TEST(apiTest, catalogGetDnodeList_test) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_DNODElIST;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

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

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

  SArray* pList = NULL;
  code = catalogGetDnodeList(pCtg, mockPointer, &pList);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize(pList), 1);

  taosArrayDestroy(pList);

  catalogDestroy();
}
D
dapan1121 已提交
3045

D
dapan1121 已提交
3046

S
Shengliang Guan 已提交
3047
int main(int argc, char **argv) {
3048 3049 3050
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
D
dapan1121 已提交
3051

D
dapan1121 已提交
3052
#pragma GCC diagnostic pop