• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3825

01 Apr 2025 11:58AM UTC coverage: 34.067% (+0.003%) from 34.064%
#3825

push

travis-ci

happyguoxy
test:alter gcda dir

148492 of 599532 branches covered (24.77%)

Branch coverage included in aggregate %.

222504 of 489471 relevant lines covered (45.46%)

762290.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

16
#include <gtest/gtest.h>
17
#include <iostream>
18

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

27
#ifdef WINDOWS
28
#define TD_USE_WINSOCK
29
#endif
30
#include "catalog.h"
31
#include "catalogInt.h"
32
#include "os.h"
33
#include "stub.h"
34
#include "taos.h"
35
#include "tdatablock.h"
36
#include "tdef.h"
37
#include "tglobal.h"
38
#include "trpc.h"
39
#include "tvariant.h"
40
#include "ttimer.h"
41

42
namespace {
43

44
extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog *pCatalog, int32_t type);
45
extern "C" int32_t ctgdGetStatNum(char *option, void *res);
46

47
void ctgTestSetRspTableMeta();
48
void ctgTestSetRspCTableMeta();
49
void ctgTestSetRspSTableMeta();
50
void ctgTestSetRspMultiSTableMeta();
51

52
extern int32_t clientConnRefPool;
53

54
enum {
55
  CTGT_RSP_VGINFO = 1,
56
  CTGT_RSP_TBMETA,
57
  CTGT_RSP_CTBMETA,
58
  CTGT_RSP_STBMETA,
59
  CTGT_RSP_MSTBMETA,
60
  CTGT_RSP_INDEXINFO_E,
61
  CTGT_RSP_USERAUTH,
62
  CTGT_RSP_TBLCFG,
63
  CTGT_RSP_TBLINDEX,
64
  CTGT_RSP_DBCFG,
65
  CTGT_RSP_QNODELIST,
66
  CTGT_RSP_UDF,
67
  CTGT_RSP_SVRVER,
68
  CTGT_RSP_DNODElIST,
69
  CTGT_RSP_TBMETA_NOT_EXIST,
70
};
71

72
bool    ctgTestStop = false;
73
bool    ctgTestEnableSleep = false;
74
bool    ctgTestEnableLog = true;
75
bool    ctgTestDeadLoop = false;
76
int32_t ctgTestPrintNum = 10000;
77
int32_t ctgTestMTRunSec = 5;
78

79
int32_t  ctgTestCurrentVgVersion = 0;
80
int32_t  ctgTestVgVersion = 1;
81
int32_t  ctgTestVgNum = 10;
82
int32_t  ctgTestColNum = 2;
83
int32_t  ctgTestTagNum = 1;
84
int32_t  ctgTestQnodeNum = 3;
85
int32_t  ctgTestIndexNum = 3;
86
int32_t  ctgTestFuncNum = 2;
87
int32_t  ctgTestFuncType = 3;
88
int32_t  ctgTestSVersion = 1;
89
int32_t  ctgTestTVersion = 1;
90
int32_t  ctgTestSuid = 2;
91
uint64_t ctgTestDbId = 33;
92
uint64_t ctgTestNormalTblUid = 1;
93

94
uint64_t ctgTestClusterId = 0x1;
95
char    *ctgTestDbname = "1.db1";
96
char    *ctgTestTablename = "table1";
97
char    *ctgTestCTablename = "ctable1";
98
char    *ctgTestSTablename = "stable1";
99
char    *ctgTestUsername = "user1";
100
char    *ctgTestCurrentCTableName = NULL;
101
char    *ctgTestCurrentTableName = NULL;
102
char    *ctgTestCurrentSTableName = NULL;
103

104
int32_t ctgTestRspFunc[100] = {0};
105
int32_t ctgTestRspIdx = 0;
106

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

129
  int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
×
130
  ASSERT(contLen > 0);
×
131
  void   *pReq = rpcMallocCont(contLen);
×
132
  ASSERT(pReq != NULL);
×
133
  contLen = tSerializeSCreateDbReq(pReq, contLen, &createReq);
×
134
  ASSERT(contLen > 0);
×
135
  
136
  SRpcMsg rpcMsg = {0};
×
137
  rpcMsg.pCont = pReq;
×
138
  rpcMsg.contLen = contLen;
×
139
  rpcMsg.msgType = TDMT_MND_CREATE_DB;
×
140

141
  SRpcMsg rpcRsp = {0};
×
142
  ASSERT(0 == rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp));
×
143

144
  ASSERT_EQ(rpcRsp.code, 0);
×
145
}
146

147
void ctgTestInitLogFile() {
29✔
148
  if (!ctgTestEnableLog) {
29!
149
    return;
×
150
  }
151

152
  const char   *defaultLogFileNamePrefix = "catalogTest";
29✔
153
  const int32_t maxLogFileNum = 10;
29✔
154

155
  tsAsyncLog = 0;
29✔
156
  qDebugFlag = 159;
29✔
157
  tmrDebugFlag = 159;
29✔
158
  tsNumOfLogLines = 1000000000;
29✔
159
  TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH);
29✔
160

161
  (void)ctgdEnableDebug("api", true);
29✔
162
  (void)ctgdEnableDebug("meta", true);
29✔
163
  (void)ctgdEnableDebug("cache", true);
29✔
164
  (void)ctgdEnableDebug("lock", true);
29✔
165

166
  if (taosInitLog(defaultLogFileNamePrefix, 1, false) < 0) {
29!
167
    (void)printf("failed to open log file in directory:%s\n", tsLogDir);
×
168
    ASSERT(0);
×
169
  }
170
}
171

172
int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) {
34,268✔
173
  return ((vgVersion % 2) == 0) ? ctgTestVgNum - 2 : ctgTestVgNum;
34,268✔
174
}
175

176
void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) {
184,156✔
177
  SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
184,156✔
178
  TAOS_STRCPY(cn.dbname, "db1");
184,156✔
179
  TAOS_STRCPY(cn.tname, ctgTestCTablename);
184,156✔
180

181
  SName sn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
184,156✔
182
  TAOS_STRCPY(sn.dbname, "db1");
184,156✔
183
  TAOS_STRCPY(sn.tname, ctgTestSTablename);
184,156✔
184

185
  char db[TSDB_DB_FNAME_LEN] = {0};
184,156✔
186
  (void)tNameGetFullDbName(&cn, db);
184,156!
187

188
  TAOS_STRCPY(output->dbFName, db);
184,156✔
189
  SET_META_TYPE_BOTH_TABLE(output->metaType);
184,156✔
190

191
  TAOS_STRCPY(output->ctbName, cn.tname);
184,156✔
192
  TAOS_STRCPY(output->tbName, sn.tname);
184,156✔
193

194
  output->ctbMeta.vgId = 9;
184,156✔
195
  output->ctbMeta.tableType = TSDB_CHILD_TABLE;
184,156✔
196
  output->ctbMeta.uid = 3;
184,156✔
197
  output->ctbMeta.suid = 2;
184,156✔
198

199
  output->tbMeta =
184,156!
200
      (STableMeta *)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum));
184,156!
201
  ASSERT(NULL != output->tbMeta);
184,156!
202
  output->tbMeta->vgId = 9;
184,156✔
203
  output->tbMeta->tableType = TSDB_SUPER_TABLE;
184,156✔
204
  output->tbMeta->uid = 2;
184,156✔
205
  output->tbMeta->suid = 2;
184,156✔
206

207
  output->tbMeta->tableInfo.numOfColumns = ctgTestColNum;
184,156✔
208
  output->tbMeta->tableInfo.numOfTags = ctgTestTagNum;
184,156✔
209

210
  output->tbMeta->sversion = ctgTestSVersion;
184,156✔
211
  output->tbMeta->tversion = ctgTestTVersion;
184,156✔
212

213
  output->vctbMeta = NULL;
184,156✔
214

215
  SSchema *s = NULL;
184,156✔
216
  s = &output->tbMeta->schema[0];
184,156✔
217
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
184,156✔
218
  s->colId = 1;
184,156✔
219
  s->bytes = 8;
184,156✔
220
  TAOS_STRCPY(s->name, "ts");
184,156✔
221

222
  s = &output->tbMeta->schema[1];
184,156✔
223
  s->type = TSDB_DATA_TYPE_INT;
184,156✔
224
  s->colId = 2;
184,156✔
225
  s->bytes = 4;
184,156✔
226
  TAOS_STRCPY(s->name, "col1s");
184,156✔
227

228
  s = &output->tbMeta->schema[2];
184,156✔
229
  s->type = TSDB_DATA_TYPE_BINARY;
184,156✔
230
  s->colId = 3;
184,156✔
231
  s->bytes = 12;
184,156✔
232
  TAOS_STRCPY(s->name, "tag1s");
184,156✔
233
}
184,156✔
234

235
void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
34,268✔
236
  static int32_t vgVersion = ctgTestVgVersion + 1;
34,268!
237
  int32_t        vgNum = 0;
34,268✔
238
  SVgroupInfo    vgInfo = {0};
34,268✔
239
  SDBVgInfo     *dbVgroup = (SDBVgInfo *)taosMemoryCalloc(1, sizeof(SDBVgInfo));
34,268!
240
  ASSERT(NULL != dbVgroup);
34,268!
241
  
242
  dbVgroup->vgVersion = vgVersion++;
34,268✔
243

244
  ctgTestCurrentVgVersion = dbVgroup->vgVersion;
34,268✔
245

246
  dbVgroup->hashMethod = 0;
34,268✔
247
  dbVgroup->hashPrefix = 0;
34,268✔
248
  dbVgroup->hashSuffix = 0;
34,268✔
249
  dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
34,268!
250
  ASSERT(NULL != dbVgroup->vgHash);
34,268!
251

252
  vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
34,268✔
253
  uint32_t hashUnit = UINT32_MAX / vgNum;
34,268✔
254

255
  for (int32_t i = 0; i < vgNum; ++i) {
342,680✔
256
    vgInfo.vgId = i + 1;
308,412✔
257
    vgInfo.hashBegin = i * hashUnit;
308,412✔
258
    vgInfo.hashEnd = hashUnit * (i + 1) - 1;
308,412✔
259
    vgInfo.epSet.numOfEps = i % TSDB_MAX_REPLICA + 1;
308,412✔
260
    vgInfo.epSet.inUse = i % vgInfo.epSet.numOfEps;
308,412✔
261
    for (int32_t n = 0; n < vgInfo.epSet.numOfEps; ++n) {
1,182,246✔
262
      SEp *addr = &vgInfo.epSet.eps[n];
873,834✔
263
      TAOS_STRCPY(addr->fqdn, "a0");
873,834✔
264
      addr->port = n + 22;
873,834✔
265
    }
266

267
    ASSERT(0 == taosHashPut(dbVgroup->vgHash, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo)));
308,412!
268
  }
269

270
  *pdbVgroup = dbVgroup;
34,268✔
271
}
34,268✔
272

273
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
1✔
274
  TAOS_STRCPY(rspMsg->dbFName, ctgTestDbname);
1✔
275
  (void)sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
1✔
276
  (void)sprintf(rspMsg->stbName, "%s", ctgTestSTablename);
1✔
277
  rspMsg->numOfTags = ctgTestTagNum;
1✔
278
  rspMsg->numOfColumns = ctgTestColNum;
1✔
279
  rspMsg->precision = 1 + 1;
1✔
280
  rspMsg->tableType = TSDB_SUPER_TABLE;
1✔
281
  rspMsg->sversion = ctgTestSVersion + 1;
1✔
282
  rspMsg->tversion = ctgTestTVersion + 1;
1✔
283
  rspMsg->suid = ctgTestSuid;
1✔
284
  rspMsg->tuid = ctgTestSuid;
1✔
285
  rspMsg->vgId = 1;
1✔
286

287
  rspMsg->pSchemas = (SSchema *)taosMemoryCalloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema));
1!
288
  ASSERT(NULL != rspMsg->pSchemas);
1!
289
  
290
  SSchema *s = NULL;
1✔
291
  s = &rspMsg->pSchemas[0];
1✔
292
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
1✔
293
  s->colId = 1;
1✔
294
  s->bytes = 8;
1✔
295
  TAOS_STRCPY(s->name, "ts");
1✔
296

297
  s = &rspMsg->pSchemas[1];
1✔
298
  s->type = TSDB_DATA_TYPE_INT;
1✔
299
  s->colId = 2;
1✔
300
  s->bytes = 4;
1✔
301
  TAOS_STRCPY(s->name, "col1s");
1✔
302

303
  s = &rspMsg->pSchemas[2];
1✔
304
  s->type = TSDB_DATA_TYPE_BINARY;
1✔
305
  s->colId = 3;
1✔
306
  s->bytes = 12 + 1;
1✔
307
  TAOS_STRCPY(s->name, "tag1s");
1✔
308

309
  return;
1✔
310
}
311

312
int32_t ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
985✔
313
  rpcFreeCont(pMsg->pCont);
985!
314

315
  SUseDbRsp usedbRsp = {0};
985✔
316
  TAOS_STRCPY(usedbRsp.db, ctgTestDbname);
985✔
317
  usedbRsp.vgVersion = ctgTestVgVersion;
985✔
318
  ctgTestCurrentVgVersion = ctgTestVgVersion;
985✔
319
  usedbRsp.vgNum = ctgTestVgNum;
985✔
320
  usedbRsp.hashMethod = 0;
985✔
321
  usedbRsp.uid = ctgTestDbId;
985✔
322
  usedbRsp.pVgroupInfos = taosArrayInit(usedbRsp.vgNum, sizeof(SVgroupInfo));
985!
323
  ASSERT(NULL != usedbRsp.pVgroupInfos);
985!
324
  
325
  uint32_t hashUnit = UINT32_MAX / ctgTestVgNum;
985✔
326
  for (int32_t i = 0; i < ctgTestVgNum; ++i) {
10,835✔
327
    SVgroupInfo vg = {0};
9,850✔
328
    vg.vgId = i + 1;
9,850✔
329
    vg.hashBegin = i * hashUnit;
9,850✔
330
    vg.hashEnd = hashUnit * (i + 1) - 1;
9,850✔
331
    if (i == ctgTestVgNum - 1) {
9,850✔
332
      vg.hashEnd = htonl(UINT32_MAX);
985✔
333
    }
334

335
    vg.epSet.numOfEps = i % TSDB_MAX_REPLICA + 1;
9,850✔
336
    vg.epSet.inUse = i % vg.epSet.numOfEps;
9,850✔
337
    for (int32_t n = 0; n < vg.epSet.numOfEps; ++n) {
39,400✔
338
      SEp *addr = &vg.epSet.eps[n];
29,550✔
339
      TAOS_STRCPY(addr->fqdn, "a0");
29,550✔
340
      addr->port = n + 22;
29,550✔
341
    }
342
    vg.numOfTable = i % 2;
9,850✔
343

344
    ASSERT(NULL != taosArrayPush(usedbRsp.pVgroupInfos, &vg));
19,700!
345
  }
346

347
  int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
985!
348
  ASSERT(contLen > 0);
985!
349
  void   *pReq = rpcMallocCont(contLen);
985!
350
  ASSERT(pReq != NULL);
985!
351
  contLen = tSerializeSUseDbRsp(pReq, contLen, &usedbRsp);
985!
352
  ASSERT(contLen > 0);
985!
353

354
  pRsp->code = 0;
985✔
355
  pRsp->contLen = contLen;
985✔
356
  pRsp->pCont = pReq;
985✔
357

358
  taosArrayDestroy(usedbRsp.pVgroupInfos);
985!
359

360
  return 0;
985✔
361
}
362

363
int32_t ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
8✔
364
  rpcFreeCont(pMsg->pCont);
8!
365

366
  STableMetaRsp metaRsp = {0};
8✔
367
  TAOS_STRCPY(metaRsp.dbFName, ctgTestDbname);
8✔
368
  TAOS_STRCPY(metaRsp.tbName, ctgTestTablename);
8✔
369
  metaRsp.numOfTags = 0;
8✔
370
  metaRsp.numOfColumns = ctgTestColNum;
8✔
371
  metaRsp.precision = 1;
8✔
372
  metaRsp.tableType = TSDB_NORMAL_TABLE;
8✔
373
  metaRsp.sversion = ctgTestSVersion;
8✔
374
  metaRsp.tversion = ctgTestTVersion;
8✔
375
  metaRsp.suid = 0;
8✔
376
  metaRsp.tuid = ctgTestNormalTblUid++;
8✔
377
  metaRsp.vgId = 8;
8✔
378
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
8!
379
  ASSERT(NULL != metaRsp.pSchemas);
8!
380

381
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchemaExt));
8!
382
  ASSERT(NULL != metaRsp.pSchemaExt);
8!
383
  
384
  SSchema *s = NULL;
8✔
385
  s = &metaRsp.pSchemas[0];
8✔
386
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
8✔
387
  s->colId = 1;
8✔
388
  s->bytes = 8;
8✔
389
  TAOS_STRCPY(s->name, "ts");
8✔
390

391
  s = &metaRsp.pSchemas[1];
8✔
392
  s->type = TSDB_DATA_TYPE_INT;
8✔
393
  s->colId = 2;
8✔
394
  s->bytes = 4;
8✔
395
  TAOS_STRCPY(s->name, "col1");
8✔
396

397
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
8!
398
  ASSERT(contLen > 0);
8!
399
  void   *pReq = rpcMallocCont(contLen);
8!
400
  ASSERT(pReq != NULL);
8!
401
  contLen = tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);
8!
402
  ASSERT(contLen > 0);
8!
403
  
404
  pRsp->code = 0;
8✔
405
  pRsp->contLen = contLen;
8✔
406
  pRsp->pCont = pReq;
8✔
407

408
  tFreeSTableMetaRsp(&metaRsp);
8!
409

410
  return 0;
8✔
411
}
412

413
void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
414
  rpcFreeCont(pMsg->pCont);
1✔
415

416
  pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST;
1✔
417
}
1✔
418

419
int32_t ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
9✔
420
  rpcFreeCont(pMsg->pCont);
9!
421

422
  STableMetaRsp metaRsp = {0};
9✔
423
  TAOS_STRCPY(metaRsp.dbFName, ctgTestDbname);
9✔
424
  TAOS_STRCPY(metaRsp.tbName, ctgTestCurrentCTableName ? ctgTestCurrentCTableName : ctgTestCTablename);
9✔
425
  TAOS_STRCPY(metaRsp.stbName, ctgTestSTablename);
9✔
426
  metaRsp.numOfTags = ctgTestTagNum;
9✔
427
  metaRsp.numOfColumns = ctgTestColNum;
9✔
428
  metaRsp.precision = 1;
9✔
429
  metaRsp.tableType = TSDB_CHILD_TABLE;
9✔
430
  metaRsp.sversion = ctgTestSVersion;
9✔
431
  metaRsp.tversion = ctgTestTVersion;
9✔
432
  metaRsp.suid = 0x0000000000000002;
9✔
433
  metaRsp.tuid = 0x0000000000000003;
9✔
434
  metaRsp.vgId = 9;
9✔
435
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
9!
436
  ASSERT(NULL != metaRsp.pSchemas);
9!
437

438
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchemaExt));
9!
439
  ASSERT(NULL != metaRsp.pSchemaExt);
9!
440
  
441
  SSchema *s = NULL;
9✔
442
  s = &metaRsp.pSchemas[0];
9✔
443
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
9✔
444
  s->colId = 1;
9✔
445
  s->bytes = 8;
9✔
446
  TAOS_STRCPY(s->name, "ts");
9✔
447

448
  s = &metaRsp.pSchemas[1];
9✔
449
  s->type = TSDB_DATA_TYPE_INT;
9✔
450
  s->colId = 2;
9✔
451
  s->bytes = 4;
9✔
452
  TAOS_STRCPY(s->name, "col1s");
9✔
453

454
  s = &metaRsp.pSchemas[2];
9✔
455
  s->type = TSDB_DATA_TYPE_BINARY;
9✔
456
  s->colId = 3;
9✔
457
  s->bytes = 12;
9✔
458
  TAOS_STRCPY(s->name, "tag1s");
9✔
459

460
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
9!
461
  ASSERT(contLen > 0);
9!
462
  void   *pReq = rpcMallocCont(contLen);
9!
463
  ASSERT(pReq != NULL);
9!
464
  contLen = tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);
9!
465
  ASSERT(contLen > 0);
9!
466

467

468
  pRsp->code = 0;
9✔
469
  pRsp->contLen = contLen;
9✔
470
  pRsp->pCont = pReq;
9✔
471

472
  tFreeSTableMetaRsp(&metaRsp);
9!
473

474
  return 0;
9✔
475
}
476

477
int32_t ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
20✔
478
  rpcFreeCont(pMsg->pCont);
20!
479

480
  STableMetaRsp metaRsp = {0};
20✔
481
  TAOS_STRCPY(metaRsp.dbFName, ctgTestDbname);
20✔
482
  TAOS_STRCPY(metaRsp.tbName, ctgTestCurrentSTableName ? ctgTestCurrentSTableName : ctgTestSTablename);
20✔
483
  TAOS_STRCPY(metaRsp.stbName, ctgTestSTablename);
20✔
484
  metaRsp.numOfTags = ctgTestTagNum;
20✔
485
  metaRsp.numOfColumns = ctgTestColNum;
20✔
486
  metaRsp.precision = 1;
20✔
487
  metaRsp.tableType = TSDB_SUPER_TABLE;
20✔
488
  metaRsp.sversion = ctgTestSVersion;
20✔
489
  metaRsp.tversion = ctgTestTVersion;
20✔
490
  metaRsp.suid = ctgTestSuid;
20✔
491
  metaRsp.tuid = ctgTestSuid + 1;
20✔
492
  metaRsp.vgId = 0;
20✔
493
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
20!
494
  ASSERT(NULL != metaRsp.pSchemas);
20!
495

496
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchemaExt));
20!
497
  ASSERT(NULL != metaRsp.pSchemaExt);
20!
498

499
  SSchema *s = NULL;
20✔
500
  s = &metaRsp.pSchemas[0];
20✔
501
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
20✔
502
  s->colId = 1;
20✔
503
  s->bytes = 8;
20✔
504
  TAOS_STRCPY(s->name, "ts");
20✔
505

506
  s = &metaRsp.pSchemas[1];
20✔
507
  s->type = TSDB_DATA_TYPE_INT;
20✔
508
  s->colId = 2;
20✔
509
  s->bytes = 4;
20✔
510
  TAOS_STRCPY(s->name, "col1s");
20✔
511

512
  s = &metaRsp.pSchemas[2];
20✔
513
  s->type = TSDB_DATA_TYPE_BINARY;
20✔
514
  s->colId = 3;
20✔
515
  s->bytes = 12;
20✔
516
  TAOS_STRCPY(s->name, "tag1s");
20✔
517

518
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
20!
519
  ASSERT(contLen > 0);
20!
520
  void   *pReq = rpcMallocCont(contLen);
20!
521
  ASSERT(pReq != NULL);
20!
522
  contLen = tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);
20!
523
  ASSERT(contLen > 0);
20!
524

525
  pRsp->code = 0;
20✔
526
  pRsp->contLen = contLen;
20✔
527
  pRsp->pCont = pReq;
20✔
528

529
  tFreeSTableMetaRsp(&metaRsp);
20!
530

531
  return 0;
20✔
532
}
533

534
int32_t ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
10✔
535
  rpcFreeCont(pMsg->pCont);
10!
536

537
  static int32_t idx = 1;
538

539
  STableMetaRsp metaRsp = {0};
10✔
540
  TAOS_STRCPY(metaRsp.dbFName, ctgTestDbname);
10✔
541
  (void)sprintf(metaRsp.tbName, "%s_%d", ctgTestSTablename, idx);
10✔
542
  (void)sprintf(metaRsp.stbName, "%s_%d", ctgTestSTablename, idx);
10✔
543
  metaRsp.numOfTags = ctgTestTagNum;
10✔
544
  metaRsp.numOfColumns = ctgTestColNum;
10✔
545
  metaRsp.precision = 1;
10✔
546
  metaRsp.tableType = TSDB_SUPER_TABLE;
10✔
547
  metaRsp.sversion = ctgTestSVersion;
10✔
548
  metaRsp.tversion = ctgTestTVersion;
10✔
549
  metaRsp.suid = ctgTestSuid + idx;
10✔
550
  metaRsp.tuid = ctgTestSuid + idx;
10✔
551
  metaRsp.vgId = 0;
10✔
552
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
10!
553
  ASSERT(NULL != metaRsp.pSchemas);
10!
554

555
  metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchemaExt));
10!
556
  ASSERT(NULL != metaRsp.pSchemaExt);
10!
557

558
  SSchema *s = NULL;
10✔
559
  s = &metaRsp.pSchemas[0];
10✔
560
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
10✔
561
  s->colId = 1;
10✔
562
  s->bytes = 8;
10✔
563
  TAOS_STRCPY(s->name, "ts");
10✔
564

565
  s = &metaRsp.pSchemas[1];
10✔
566
  s->type = TSDB_DATA_TYPE_INT;
10✔
567
  s->colId = 2;
10✔
568
  s->bytes = 4;
10✔
569
  TAOS_STRCPY(s->name, "col1s");
10✔
570

571
  s = &metaRsp.pSchemas[2];
10✔
572
  s->type = TSDB_DATA_TYPE_BINARY;
10✔
573
  s->colId = 3;
10✔
574
  s->bytes = 12;
10✔
575
  TAOS_STRCPY(s->name, "tag1s");
10✔
576

577
  ++idx;
10✔
578

579
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
10!
580
  ASSERT(contLen > 0);
10!
581
  void   *pReq = rpcMallocCont(contLen);
10!
582
  ASSERT(pReq != NULL);
10!
583
  contLen = tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);
10!
584
  ASSERT(contLen > 0);
10!
585

586
  pRsp->code = 0;
10✔
587
  pRsp->contLen = contLen;
10✔
588
  pRsp->pCont = pReq;
10✔
589

590
  tFreeSTableMetaRsp(&metaRsp);
10!
591

592
  return 0;
10✔
593
}
594

595
void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
596
  rpcFreeCont(pMsg->pCont);
1✔
597

598
  pRsp->code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
1✔
599
  pRsp->contLen = 0;
1✔
600
  pRsp->pCont = NULL;
1✔
601
}
1✔
602

603
void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
604
  rpcFreeCont(pMsg->pCont);
1!
605

606
  SGetUserAuthRsp userRsp = {0};
1✔
607
  TAOS_STRCPY(userRsp.user, ctgTestUsername);
1✔
608
  userRsp.version = 1;
1✔
609
  userRsp.superAuth = 1;
1✔
610
  userRsp.enable = 1;
1✔
611

612
  int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp);
1!
613
  ASSERT(contLen > 0);
1!
614
  void   *pReq = rpcMallocCont(contLen);
1!
615
  ASSERT(pReq != NULL);
1!
616
  contLen = tSerializeSGetUserAuthRsp(pReq, contLen, &userRsp);
1!
617
  ASSERT(contLen > 0);
1!
618

619
  pRsp->code = 0;
1✔
620
  pRsp->contLen = contLen;
1✔
621
  pRsp->pCont = pReq;
1✔
622
}
1✔
623

624
void ctgTestRspTableCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
625
  rpcFreeCont(pMsg->pCont);
1!
626

627
  static int32_t idx = 1;
628

629
  STableCfgRsp tblRsp = {0};
1✔
630
  TAOS_STRCPY(tblRsp.tbName, ctgTestTablename);
1✔
631
  tblRsp.numOfColumns = ctgTestColNum;
1✔
632

633
  tblRsp.pSchemas = (SSchema *)taosMemoryMalloc((tblRsp.numOfTags + tblRsp.numOfColumns) * sizeof(SSchema));
1!
634
  ASSERT(tblRsp.pSchemas != NULL);
1!
635

636
  tblRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc((tblRsp.numOfTags + tblRsp.numOfColumns) * sizeof(SSchemaExt));
1!
637
  ASSERT(NULL != tblRsp.pSchemaExt);
1!
638

639
  SSchema *s = NULL;
1✔
640
  s = &tblRsp.pSchemas[0];
1✔
641
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
1✔
642
  s->colId = 1;
1✔
643
  s->bytes = 8;
1✔
644
  TAOS_STRCPY(s->name, "ts");
1✔
645

646
  s = &tblRsp.pSchemas[1];
1✔
647
  s->type = TSDB_DATA_TYPE_INT;
1✔
648
  s->colId = 2;
1✔
649
  s->bytes = 4;
1✔
650
  TAOS_STRCPY(s->name, "col1");
1✔
651

652
  int32_t contLen = tSerializeSTableCfgRsp(NULL, 0, &tblRsp);
1!
653
  ASSERT(contLen > 0);
1!
654
  void   *pReq = rpcMallocCont(contLen);
1!
655
  ASSERT(pReq != NULL);
1!
656
  contLen = tSerializeSTableCfgRsp(pReq, contLen, &tblRsp);
1!
657
  ASSERT(contLen > 0);
1!
658

659
  pRsp->code = 0;
1✔
660
  pRsp->contLen = contLen;
1✔
661
  pRsp->pCont = pReq;
1✔
662

663
  tFreeSTableCfgRsp(&tblRsp);
1!
664
}
1✔
665

666
void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
667
  rpcFreeCont(pMsg->pCont);
1!
668

669
  static int32_t idx = 1;
670

671
  STableIndexRsp tblRsp = {0};
1✔
672
  TAOS_STRCPY(tblRsp.tbName, ctgTestSTablename);
1✔
673

674
  tblRsp.pIndex = taosArrayInit(ctgTestIndexNum, sizeof(STableIndexInfo));
1!
675
  ASSERT(NULL != tblRsp.pIndex);
1!
676
  
677
  STableIndexInfo info = {0};
1✔
678
  for (int32_t i = 0; i < ctgTestIndexNum; ++i) {
4✔
679
    info.interval = 1 + i;
3✔
680
    info.expr = (char *)taosMemoryCalloc(1, 10);
3!
681
    ASSERT(NULL != taosArrayPush(tblRsp.pIndex, &info));
6!
682
  }
683

684
  int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &tblRsp);
1!
685
  ASSERT(contLen > 0);
1!
686
  void   *pReq = rpcMallocCont(contLen);
1!
687
  ASSERT(pReq != NULL);
1!
688
  contLen = tSerializeSTableIndexRsp(pReq, contLen, &tblRsp);
1!
689
  ASSERT(contLen > 0);
1!
690

691
  pRsp->code = 0;
1✔
692
  pRsp->contLen = contLen;
1✔
693
  pRsp->pCont = pReq;
1✔
694

695
  tFreeSTableIndexRsp(&tblRsp);
1!
696
}
1✔
697

698
void ctgTestRspDBCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
699
  rpcFreeCont(pMsg->pCont);
1!
700

701
  static int32_t idx = 1;
702

703
  SDbCfgRsp dbRsp = {0};
1✔
704
  dbRsp.numOfVgroups = ctgTestVgNum;
1✔
705

706
  int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &dbRsp);
1!
707
  ASSERT(contLen > 0);
1!
708
  void   *pReq = rpcMallocCont(contLen);
1!
709
  ASSERT(pReq != NULL);
1!
710
  contLen = tSerializeSDbCfgRsp(pReq, contLen, &dbRsp);
1!
711
  ASSERT(contLen > 0);
1!
712

713
  pRsp->code = 0;
1✔
714
  pRsp->contLen = contLen;
1✔
715
  pRsp->pCont = pReq;
1✔
716
}
1✔
717

718
void ctgTestRspQnodeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
719
  rpcFreeCont(pMsg->pCont);
1!
720

721
  SQnodeListRsp qlistRsp = {0};
1✔
722
  qlistRsp.qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
1!
723
  for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
4✔
724
    SQueryNodeLoad nodeLoad = {0};
3✔
725
    nodeLoad.addr.nodeId = i;
3✔
726

727
    ASSERT(NULL != taosArrayPush(qlistRsp.qnodeList, &nodeLoad));
6!
728
  }
729

730
  int32_t contLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
1!
731
  ASSERT(contLen > 0);
1!
732
  void   *pReq = rpcMallocCont(contLen);
1!
733
  ASSERT(pReq != NULL);
1!
734
  contLen = tSerializeSQnodeListRsp(pReq, contLen, &qlistRsp);
1!
735
  ASSERT(contLen > 0);
1!
736

737
  pRsp->code = 0;
1✔
738
  pRsp->contLen = contLen;
1✔
739
  pRsp->pCont = pReq;
1✔
740

741
  tFreeSQnodeListRsp(&qlistRsp);
1!
742
}
1✔
743

744
void ctgTestRspUdfInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
745
  rpcFreeCont(pMsg->pCont);
1!
746

747
  SRetrieveFuncRsp funcRsp = {0};
1✔
748
  funcRsp.numOfFuncs = 1;
1✔
749
  funcRsp.pFuncInfos = taosArrayInit(1, sizeof(SFuncInfo));
1!
750
  funcRsp.pFuncExtraInfos = taosArrayInit(1, sizeof(SFuncExtraInfo));
1!
751
  SFuncInfo funcInfo = {0};
1✔
752
  TAOS_STRCPY(funcInfo.name, "func1");
1✔
753
  funcInfo.funcType = ctgTestFuncType;
1✔
754

755
  ASSERT(NULL != taosArrayPush(funcRsp.pFuncInfos, &funcInfo));
2!
756
  SFuncExtraInfo extraInfo = {0};
1✔
757
  extraInfo.funcVersion = 0;
1!
758
  extraInfo.funcCreatedTime = taosGetTimestampMs();
1✔
759
  ASSERT(NULL != taosArrayPush(funcRsp.pFuncExtraInfos, &extraInfo));
2!
760
  
761
  int32_t contLen = tSerializeSRetrieveFuncRsp(NULL, 0, &funcRsp);
1!
762
  ASSERT(contLen > 0);
1!
763
  void   *pReq = rpcMallocCont(contLen);
1!
764
  ASSERT(pReq != NULL);
1!
765
  contLen = tSerializeSRetrieveFuncRsp(pReq, contLen, &funcRsp);
1!
766
  ASSERT(contLen > 0);
1!
767

768
  pRsp->code = 0;
1✔
769
  pRsp->contLen = contLen;
1✔
770
  pRsp->pCont = pReq;
1✔
771

772
  tFreeSRetrieveFuncRsp(&funcRsp);
1!
773
}
1✔
774

775
void ctgTestRspSvrVer(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
776
  rpcFreeCont(pMsg->pCont);
1!
777

778
  SServerVerRsp verRsp = {0};
1✔
779
  TAOS_STRCPY(verRsp.ver, "1.0");
1✔
780

781
  int32_t contLen = tSerializeSServerVerRsp(NULL, 0, &verRsp);
1!
782
  ASSERT(contLen > 0);
1!
783
  void   *pReq = rpcMallocCont(contLen);
1!
784
  ASSERT(pReq != NULL);
1!
785
  contLen = tSerializeSServerVerRsp(pReq, contLen, &verRsp);
1!
786
  ASSERT(contLen > 0);
1!
787

788
  pRsp->code = 0;
1✔
789
  pRsp->contLen = contLen;
1✔
790
  pRsp->pCont = pReq;
1✔
791
}
1✔
792

793
void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
794
  rpcFreeCont(pMsg->pCont);
1!
795

796
  SDnodeListRsp dRsp = {0};
1✔
797
  dRsp.dnodeList = taosArrayInit(1, sizeof(SEpSet));
1!
798
  ASSERT(dRsp.dnodeList != NULL);
1!
799
  SEpSet epSet = {0};
1✔
800
  epSet.numOfEps = 1;
1✔
801
  tstrncpy(epSet.eps[0].fqdn, "localhost", TSDB_FQDN_LEN);
1✔
802
  epSet.eps[0].port = 6030;
1✔
803

804
  ASSERT(NULL != taosArrayPush(dRsp.dnodeList, &epSet));
2!
805

806
  int32_t contLen = tSerializeSDnodeListRsp(NULL, 0, &dRsp);
1!
807
  ASSERT(contLen > 0);
1!
808
  void   *pReq = rpcMallocCont(contLen);
1!
809
  ASSERT(pReq != NULL);
1!
810
  contLen = tSerializeSDnodeListRsp(pReq, contLen, &dRsp);
1!
811
  ASSERT(contLen > 0);
1!
812

813
  pRsp->code = 0;
1✔
814
  pRsp->contLen = contLen;
1✔
815
  pRsp->pCont = pReq;
1✔
816

817
  tFreeSDnodeListRsp(&dRsp);
1!
818
}
1✔
819

820
void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
2✔
821
  switch (pMsg->msgType) {
2!
822
    case TDMT_MND_USE_DB:
1✔
823
      ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
1✔
824
      break;
1✔
825
    case TDMT_VND_TABLE_CFG:
1✔
826
    case TDMT_MND_TABLE_CFG:
827
      ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp);
1✔
828
      break;
1✔
829
    case TDMT_MND_GET_TABLE_INDEX:
×
830
      ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp);
×
831
      break;
×
832
    case TDMT_MND_GET_DB_CFG:
×
833
      ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
×
834
      break;
×
835
    case TDMT_MND_QNODE_LIST:
×
836
      ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
×
837
      break;
×
838
    case TDMT_MND_RETRIEVE_FUNC:
×
839
      ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
×
840
      break;
×
841
    case TDMT_MND_SERVER_VERSION:
×
842
      ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
×
843
      break;
×
844
    case TDMT_MND_DNODE_LIST:
×
845
      ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp);
×
846
      break;
×
847
    default:
×
848
      break;
×
849
  }
850

851
  return;
2✔
852
}
853

854
int32_t ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
51✔
855
  switch (ctgTestRspFunc[ctgTestRspIdx]) {
51!
856
    case CTGT_RSP_VGINFO:
15✔
857
      ASSERT(0 == ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp));
15!
858
      break;
15✔
859
    case CTGT_RSP_TBMETA:
7✔
860
      ASSERT(0 == ctgTestRspTableMeta(shandle, pEpSet, pMsg, pRsp));
7!
861
      break;
7✔
862
    case CTGT_RSP_CTBMETA:
4✔
863
      ASSERT(0 == ctgTestRspCTableMeta(shandle, pEpSet, pMsg, pRsp));
4!
864
      break;
4✔
865
    case CTGT_RSP_STBMETA:
14✔
866
      ASSERT(0 == ctgTestRspSTableMeta(shandle, pEpSet, pMsg, pRsp));
14!
867
      break;
14✔
868
    case CTGT_RSP_MSTBMETA:
×
869
      ASSERT(0 == ctgTestRspMultiSTableMeta(shandle, pEpSet, pMsg, pRsp));
×
870
      break;
×
871
    case CTGT_RSP_INDEXINFO_E:
1✔
872
      ctgTestRspErrIndexInfo(shandle, pEpSet, pMsg, pRsp);
1✔
873
      break;
1✔
874
    case CTGT_RSP_USERAUTH:
1✔
875
      ctgTestRspUserAuth(shandle, pEpSet, pMsg, pRsp);
1✔
876
      break;
1✔
877
    case CTGT_RSP_TBLCFG:
×
878
      ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp);
×
879
      break;
×
880
    case CTGT_RSP_TBMETA_NOT_EXIST:
1✔
881
      ctgTestRspTableMetaNotExist(shandle, pEpSet, pMsg, pRsp);
1✔
882
      break;
1✔
883
    case CTGT_RSP_TBLINDEX:
1✔
884
      ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp);
1✔
885
      break;
1✔
886
    case CTGT_RSP_DBCFG:
1✔
887
      ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
1✔
888
      break;
1✔
889
    case CTGT_RSP_QNODELIST:
1✔
890
      ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
1✔
891
      break;
1✔
892
    case CTGT_RSP_UDF:
1✔
893
      ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
1✔
894
      break;
1✔
895
    case CTGT_RSP_SVRVER:
1✔
896
      ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
1✔
897
      break;
1✔
898
    case CTGT_RSP_DNODElIST:
1✔
899
      ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp);
1✔
900
      break;
1✔
901
    default:
2✔
902
      ctgTestRspAuto(shandle, pEpSet, pMsg, pRsp);
2✔
903
      break;
2✔
904
  }
905

906
  ctgTestRspIdx++;
51✔
907

908
  return 0;
51✔
909
}
910

911
int32_t ctgTestRspDbVgroupsAndNormalMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
×
912
  ASSERT(0 == ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp));
×
913

914
  ctgTestSetRspTableMeta();
×
915

916
  return 0;
×
917
}
918

919
int32_t ctgTestRspDbVgroupsAndChildMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
920
  ASSERT(0 == ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp));
1!
921

922
  ctgTestSetRspCTableMeta();
1✔
923

924
  return 0;
1✔
925
}
926

927
int32_t ctgTestRspDbVgroupsAndSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
3✔
928
  ASSERT(0 == ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp));
3!
929

930
  ctgTestSetRspSTableMeta();
3✔
931

932
  return 0;
3✔
933
}
934

935
int32_t ctgTestRspDbVgroupsAndMultiSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
1✔
936
  ASSERT(0 == ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp));
1!
937

938
  ctgTestSetRspMultiSTableMeta();
1✔
939

940
  return 0;
1✔
941
}
942

943
void ctgTestSetRspDbVgroups() {
3✔
944
  static Stub stub;
3!
945
  stub.set(rpcSendRecv, ctgTestRspDbVgroups);
3✔
946
  {
947
#ifdef WINDOWS
948
    AddrAny                       any;
949
    std::map<std::string, void *> result;
950
    any.get_func_addr("rpcSendRecv", result);
951
#endif
952
#ifdef LINUX
953
    AddrAny                       any("libtransport.so");
9!
954
    std::map<std::string, void *> result;
6✔
955
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
3!
956
#endif
957
    for (const auto &f : result) {
3!
958
      stub.set(f.second, ctgTestRspDbVgroups);
×
959
    }
960
  }
961
}
3✔
962

963
void ctgTestSetRspTableMeta() {
1✔
964
  static Stub stub;
1!
965
  stub.set(rpcSendRecv, ctgTestRspTableMeta);
1✔
966
  {
967
#ifdef WINDOWS
968
    AddrAny                       any;
969
    std::map<std::string, void *> result;
970
    any.get_func_addr("rpcSendRecv", result);
971
#endif
972
#ifdef LINUX
973
    AddrAny                       any("libtransport.so");
3!
974
    std::map<std::string, void *> result;
2✔
975
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
1!
976
#endif
977
    for (const auto &f : result) {
1!
978
      stub.set(f.second, ctgTestRspTableMeta);
×
979
    }
980
  }
981
}
1✔
982

983
void ctgTestSetRspCTableMeta() {
2✔
984
  static Stub stub;
2!
985
  stub.set(rpcSendRecv, ctgTestRspCTableMeta);
2✔
986
  {
987
#ifdef WINDOWS
988
    AddrAny                       any;
989
    std::map<std::string, void *> result;
990
    any.get_func_addr("rpcSendRecv", result);
991
#endif
992
#ifdef LINUX
993
    AddrAny                       any("libtransport.so");
6!
994
    std::map<std::string, void *> result;
4✔
995
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
2!
996
#endif
997
    for (const auto &f : result) {
2!
998
      stub.set(f.second, ctgTestRspCTableMeta);
×
999
    }
1000
  }
1001
}
2✔
1002

1003
void ctgTestSetRspSTableMeta() {
3✔
1004
  static Stub stub;
3!
1005
  stub.set(rpcSendRecv, ctgTestRspSTableMeta);
3✔
1006
  {
1007
#ifdef WINDOWS
1008
    AddrAny                       any;
1009
    std::map<std::string, void *> result;
1010
    any.get_func_addr("rpcSendRecv", result);
1011
#endif
1012
#ifdef LINUX
1013
    AddrAny                       any("libtransport.so");
9!
1014
    std::map<std::string, void *> result;
6✔
1015
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
3!
1016
#endif
1017
    for (const auto &f : result) {
3!
1018
      stub.set(f.second, ctgTestRspSTableMeta);
×
1019
    }
1020
  }
1021
}
3✔
1022

1023
void ctgTestSetRspMultiSTableMeta() {
1✔
1024
  static Stub stub;
1!
1025
  stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta);
1✔
1026
  {
1027
#ifdef WINDOWS
1028
    AddrAny                       any;
1029
    std::map<std::string, void *> result;
1030
    any.get_func_addr("rpcSendRecv", result);
1031
#endif
1032
#ifdef LINUX
1033
    AddrAny                       any("libtransport.so");
3!
1034
    std::map<std::string, void *> result;
2✔
1035
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
1!
1036
#endif
1037
    for (const auto &f : result) {
1!
1038
      stub.set(f.second, ctgTestRspMultiSTableMeta);
×
1039
    }
1040
  }
1041
}
1✔
1042

1043
void ctgTestSetRspByIdx() {
21✔
1044
  static Stub stub;
21!
1045
  stub.set(rpcSendRecv, ctgTestRspByIdx);
21✔
1046
  {
1047
#ifdef WINDOWS
1048
    AddrAny                       any;
1049
    std::map<std::string, void *> result;
1050
    any.get_func_addr("rpcSendRecv", result);
1051
#endif
1052
#ifdef LINUX
1053
    AddrAny                       any("libtransport.so");
63!
1054
    std::map<std::string, void *> result;
42✔
1055
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
21!
1056
#endif
1057
    for (const auto &f : result) {
21!
1058
      stub.set(f.second, ctgTestRspByIdx);
×
1059
    }
1060
  }
1061
}
21✔
1062

1063
void ctgTestSetRspDbVgroupsAndNormalMeta() {
×
1064
  static Stub stub;
×
1065
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta);
×
1066
  {
1067
#ifdef WINDOWS
1068
    AddrAny                       any;
1069
    std::map<std::string, void *> result;
1070
    any.get_func_addr("rpcSendRecv", result);
1071
#endif
1072
#ifdef LINUX
1073
    AddrAny                       any("libtransport.so");
×
1074
    std::map<std::string, void *> result;
×
1075
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
×
1076
#endif
1077
    for (const auto &f : result) {
×
1078
      stub.set(f.second, ctgTestRspDbVgroupsAndNormalMeta);
×
1079
    }
1080
  }
1081
}
×
1082

1083
void ctgTestSetRspDbVgroupsAndChildMeta() {
2✔
1084
  static Stub stub;
2!
1085
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta);
2✔
1086
  {
1087
#ifdef WINDOWS
1088
    AddrAny                       any;
1089
    std::map<std::string, void *> result;
1090
    any.get_func_addr("rpcSendRecv", result);
1091
#endif
1092
#ifdef LINUX
1093
    AddrAny                       any("libtransport.so");
6!
1094
    std::map<std::string, void *> result;
4✔
1095
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
2!
1096
#endif
1097
    for (const auto &f : result) {
2!
1098
      stub.set(f.second, ctgTestRspDbVgroupsAndChildMeta);
×
1099
    }
1100
  }
1101
}
2✔
1102

1103
void ctgTestSetRspDbVgroupsAndSuperMeta() {
3✔
1104
  static Stub stub;
3!
1105
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta);
3✔
1106
  {
1107
#ifdef WINDOWS
1108
    AddrAny                       any;
1109
    std::map<std::string, void *> result;
1110
    any.get_func_addr("rpcSendRecv", result);
1111
#endif
1112
#ifdef LINUX
1113
    AddrAny                       any("libtransport.so");
9!
1114
    std::map<std::string, void *> result;
6✔
1115
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
3!
1116
#endif
1117
    for (const auto &f : result) {
3!
1118
      stub.set(f.second, ctgTestRspDbVgroupsAndSuperMeta);
×
1119
    }
1120
  }
1121
}
3✔
1122

1123
void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
1✔
1124
  static Stub stub;
1!
1125
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta);
1✔
1126
  {
1127
#ifdef WINDOWS
1128
    AddrAny                       any;
1129
    std::map<std::string, void *> result;
1130
    any.get_func_addr("rpcSendRecv", result);
1131
#endif
1132
#ifdef LINUX
1133
    AddrAny                       any("libtransport.so");
3!
1134
    std::map<std::string, void *> result;
2✔
1135
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
1!
1136
#endif
1137
    for (const auto &f : result) {
1!
1138
      stub.set(f.second, ctgTestRspDbVgroupsAndMultiSuperMeta);
×
1139
    }
1140
  }
1141
}
1✔
1142

1143
}  // namespace
1144

1145
void *ctgTestGetDbVgroupThread(void *param) {
2✔
1146
  struct SCatalog  *pCtg = (struct SCatalog *)param;
2✔
1147
  int32_t           code = 0;
2✔
1148
  SRequestConnInfo  connInfo = {0};
2✔
1149
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
2✔
1150
  SArray           *vgList = NULL;
2✔
1151
  int32_t           n = 0;
2✔
1152

1153
  while (!ctgTestStop) {
16,244✔
1154
    code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList);
16,242!
1155
    if (code) {
16,242!
1156
      (void)printf("code:%x\n", code);
×
1157
      assert(0);
×
1158
    }
1159

1160
    if (vgList) {
16,242!
1161
      taosArrayDestroy(vgList);
16,242!
1162
    }
1163

1164
    if (ctgTestEnableSleep) {
16,242!
1165
      taosUsleep(taosRand() % 5);
×
1166
    }
1167
    if (++n % ctgTestPrintNum == 0) {
16,242!
1168
      (void)printf("Get:%d\n", n);
×
1169
    }
1170
  }
1171

1172
  return NULL;
2✔
1173
}
1174

1175
void *ctgTestSetSameDbVgroupThread(void *param) {
1✔
1176
  struct SCatalog *pCtg = (struct SCatalog *)param;
1✔
1177
  int32_t          code = 0;
1✔
1178
  SDBVgInfo       *dbVgroup = NULL;
1✔
1179
  int32_t          n = 0;
1✔
1180

1181
  while (!ctgTestStop) {
15,437✔
1182
    ctgTestBuildDBVgroup(&dbVgroup);
15,436!
1183
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
15,436!
1184
    if (code) {
15,436!
1185
      assert(0);
×
1186
    }
1187

1188
    if (ctgTestEnableSleep) {
15,436!
1189
      taosUsleep(taosRand() % 5);
×
1190
    }
1191
    if (++n % ctgTestPrintNum == 0) {
15,436✔
1192
      (void)printf("Set:%d\n", n);
1!
1193
    }
1194
  }
1195

1196
  return NULL;
1✔
1197
}
1198

1199
void *ctgTestSetDiffDbVgroupThread(void *param) {
1✔
1200
  struct SCatalog *pCtg = (struct SCatalog *)param;
1✔
1201
  int32_t          code = 0;
1✔
1202
  SDBVgInfo       *dbVgroup = NULL;
1✔
1203
  int32_t          n = 0;
1✔
1204

1205
  while (!ctgTestStop) {
18,832✔
1206
    ctgTestBuildDBVgroup(&dbVgroup);
18,831!
1207
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId++, dbVgroup);
18,831!
1208
    if (code) {
18,831!
1209
      assert(0);
×
1210
    }
1211

1212
    if (ctgTestEnableSleep) {
18,831!
1213
      taosUsleep(taosRand() % 5);
×
1214
    }
1215
    if (++n % ctgTestPrintNum == 0) {
18,831✔
1216
      (void)printf("Set:%d\n", n);
1!
1217
    }
1218
  }
1219

1220
  return NULL;
1✔
1221
}
1222

1223
void *ctgTestGetCtableMetaThread(void *param) {
1✔
1224
  struct SCatalog *pCtg = (struct SCatalog *)param;
1✔
1225
  int32_t          code = 0;
1✔
1226
  int32_t          n = 0;
1✔
1227
  STableMeta      *tbMeta = NULL;
1✔
1228
  bool             inCache = false;
1✔
1229

1230
  SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1231
  TAOS_STRCPY(cn.dbname, "db1");
1✔
1232
  TAOS_STRCPY(cn.tname, ctgTestCTablename);
1✔
1233

1234
  SCtgTbMetaCtx ctx = {0};
1✔
1235
  ctx.pName = &cn;
1✔
1236
  ctx.flag = CTG_FLAG_UNKNOWN_STB;
1✔
1237

1238
  while (!ctgTestStop) {
16,448✔
1239
    code = ctgReadTbMetaFromCache(pCtg, &ctx, &tbMeta);
16,447!
1240
    if (code || NULL == tbMeta) {
16,447!
1241
      assert(0);
×
1242
    }
1243

1244
    taosMemoryFreeClear(tbMeta);
16,447!
1245

1246
    if (ctgTestEnableSleep) {
16,447!
1247
      taosUsleep(taosRand() % 5);
×
1248
    }
1249

1250
    if (++n % ctgTestPrintNum == 0) {
16,447✔
1251
      (void)printf("Get:%d\n", n);
1!
1252
    }
1253
  }
1254

1255
  return NULL;
1✔
1256
}
1257

1258
void *ctgTestSetCtableMetaThread(void *param) {
1✔
1259
  struct SCatalog  *pCtg = (struct SCatalog *)param;
1✔
1260
  int32_t           code = 0;
1✔
1261
  SDBVgInfo         dbVgroup = {0};
1✔
1262
  int32_t           n = 0;
1✔
1263
  STableMetaOutput *output = NULL;
1✔
1264

1265
  SCtgCacheOperation operation = {0};
1✔
1266

1267
  operation.opId = CTG_OP_UPDATE_TB_META;
1✔
1268

1269
  while (!ctgTestStop) {
184,157✔
1270
    output = (STableMetaOutput *)taosMemoryMalloc(sizeof(STableMetaOutput));
184,156!
1271
    ASSERT(NULL != output);
184,156!
1272
    ctgTestBuildCTableMetaOutput(output);
184,156!
1273

1274
    SCtgUpdateTbMetaMsg *msg = (SCtgUpdateTbMetaMsg *)taosMemoryMalloc(sizeof(SCtgUpdateTbMetaMsg));
184,156!
1275
    ASSERT(NULL != msg);
184,156!
1276
    msg->pCtg = pCtg;
184,156✔
1277
    msg->pMeta = output;
184,156✔
1278
    operation.data = msg;
184,156✔
1279

1280
    code = ctgOpUpdateTbMeta(&operation);
184,156!
1281
    if (code) {
184,156!
1282
      assert(0);
×
1283
    }
1284

1285
    if (ctgTestEnableSleep) {
184,156!
1286
      taosUsleep(taosRand() % 5);
×
1287
    }
1288
    if (++n % ctgTestPrintNum == 0) {
184,156✔
1289
      (void)printf("Set:%d\n", n);
18!
1290
    }
1291
  }
1292

1293
  return NULL;
1✔
1294
}
1295

1296
void ctgTestFetchRows(TAOS_RES *result, int32_t *rows) {
×
1297
  TAOS_ROW    row;
1298
  int         num_fields = taos_num_fields(result);
×
1299
  TAOS_FIELD *fields = taos_fetch_fields(result);
×
1300
  char        temp[256];
1301

1302
  // fetch the records row by row
1303
  while ((row = taos_fetch_row(result))) {
×
1304
    (*rows)++;
×
1305
    TAOS_MEMSET(temp, 0, sizeof(temp));
×
1306
    (void)taos_print_row(temp, row, fields, num_fields);
×
1307
    (void)printf("\t[%s]\n", temp);
×
1308
  }
1309
}
×
1310

1311
void ctgTestExecQuery(TAOS *taos, char *sql, bool fetch, int32_t *rows) {
×
1312
  TAOS_RES *result = taos_query(taos, sql);
×
1313
  ASSERT(NULL != result);
×
1314
  int       code = taos_errno(result);
×
1315
  ASSERT_EQ(code, 0);
×
1316

1317
  if (fetch) {
×
1318
    ctgTestFetchRows(result, rows);
×
1319
  }
1320

1321
  taos_free_result(result);
×
1322
}
1323

1324
TEST(tableMeta, normalTable) {
4✔
1325
  struct SCatalog  *pCtg = NULL;
1✔
1326
  SVgroupInfo       vgInfo = {0};
1✔
1327
  SRequestConnInfo  connInfo = {0};
1✔
1328
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1329

1330
  ctgTestInitLogFile();
1!
1331

1332
  ctgTestSetRspDbVgroups();
1!
1333

1334
  initQueryModuleMsgHandle();
1!
1335

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

1338
  int32_t code = catalogInit(NULL);
1!
1339
  ASSERT_EQ(code, 0);
1!
1340

1341
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1342
  ASSERT_EQ(code, 0);
1!
1343

1344
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1345
  TAOS_STRCPY(n.dbname, "db1");
1✔
1346
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
1347

1348
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
1349
  ASSERT_EQ(code, 0);
1!
1350
  ASSERT_EQ(vgInfo.vgId, 8);
1!
1351
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
1352

1353
  while (true) {
1354
    uint64_t n = 0;
2✔
1355
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
1356
    if (n != 1) {
2✔
1357
      taosMsleep(50);
1!
1358
    } else {
1359
      break;
1✔
1360
    }
1361
  }
1✔
1362

1363
  TAOS_MEMSET(&vgInfo, 0, sizeof(vgInfo));
1✔
1364
  bool exists = false;
1✔
1365
  code = catalogGetCachedTableHashVgroup(pCtg, &n, &vgInfo, &exists);
1!
1366
  ASSERT_EQ(code, 0);
1!
1367
  ASSERT_EQ(vgInfo.vgId, 8);
1!
1368
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
1369
  ASSERT_EQ(exists, true);
1!
1370

1371
  ctgTestSetRspTableMeta();
1!
1372

1373
  STableMeta *tableMeta = NULL;
1✔
1374
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1375
  ASSERT_EQ(code, 0);
1!
1376
  ASSERT_EQ(tableMeta->vgId, 8);
1!
1377
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
1378
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
1!
1379
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1380
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1381
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1382
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
1383
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1384
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1385

1386
  taosMemoryFree(tableMeta);
1!
1387

1388
  while (true) {
1389
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
1!
1390
    if (0 == n) {
1!
1391
      taosMsleep(50);
×
1392
    } else {
1393
      break;
1✔
1394
    }
1395
  }
×
1396

1397
  tableMeta = NULL;
1✔
1398
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1399
  ASSERT_EQ(code, 0);
1!
1400
  ASSERT_EQ(tableMeta->vgId, 8);
1!
1401
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
1402
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1403
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1404
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1405
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
1406
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1407
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1408

1409
  taosMemoryFree(tableMeta);
1!
1410

1411
  tableMeta = NULL;
1✔
1412
  code = catalogGetCachedTableMeta(pCtg, &n, &tableMeta);
1!
1413
  ASSERT_EQ(code, 0);
1!
1414
  ASSERT_EQ(tableMeta->vgId, 8);
1!
1415
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
1416
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1417
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1418
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1419
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
1420
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1421
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1422

1423
  SDbCacheInfo   *dbs = NULL;
1✔
1424
  SSTableVersion *stb = NULL;
1✔
1425
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
1✔
1426
  int32_t         i = 0;
1✔
1427
  while (i < 5) {
6✔
1428
    ++i;
5✔
1429
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
5!
1430
    ASSERT_EQ(code, 0);
5!
1431
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
5!
1432
    ASSERT_EQ(code, 0);
5!
1433

1434
    if (dbNum) {
5✔
1435
      (void)printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
1!
1436
      taosMemoryFree(dbs);
1!
1437
      dbs = NULL;
1✔
1438
    } else {
1439
      (void)printf("no expired db\n");
4!
1440
    }
1441

1442
    if (stbNum) {
5!
1443
      (void)printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
×
1444
      taosMemoryFree(stb);
×
1445
      stb = NULL;
×
1446
    } else {
1447
      (void)printf("no expired stb\n");
5!
1448
    }
1449

1450
    allDbNum += dbNum;
5✔
1451
    allStbNum += stbNum;
5✔
1452
    taosSsleep(2);
5!
1453
  }
1454

1455
  ASSERT_EQ(allDbNum, 1);
1!
1456
  ASSERT_EQ(allStbNum, 0);
1!
1457

1458
  catalogDestroy();
1!
1459
}
1460

1461
TEST(tableMeta, childTableCase) {
4✔
1462
  struct SCatalog  *pCtg = NULL;
1✔
1463
  SRequestConnInfo  connInfo = {0};
1✔
1464
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1465
  SVgroupInfo       vgInfo = {0};
1✔
1466

1467
  ctgTestInitLogFile();
1!
1468

1469
  ctgTestSetRspDbVgroupsAndChildMeta();
1!
1470

1471
  initQueryModuleMsgHandle();
1!
1472

1473
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
1474
  int32_t code = catalogInit(NULL);
1!
1475
  ASSERT_EQ(code, 0);
1!
1476

1477
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1478
  ASSERT_EQ(code, 0);
1!
1479

1480
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1481
  TAOS_STRCPY(n.dbname, "db1");
1✔
1482
  TAOS_STRCPY(n.tname, ctgTestCTablename);
1✔
1483

1484
  STableMeta *tableMeta = NULL;
1✔
1485
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1486
  ASSERT_EQ(code, 0);
1!
1487
  ASSERT_EQ(tableMeta->vgId, 9);
1!
1488
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
1489
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1490
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1491
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1492
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1493
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1494
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1495

1496
  taosMemoryFree(tableMeta);
1!
1497

1498
  while (true) {
1499
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
2!
1500
    if (0 == n) {
2✔
1501
      taosMsleep(50);
1!
1502
    } else {
1503
      break;
1✔
1504
    }
1505
  }
1✔
1506

1507
  tableMeta = NULL;
1✔
1508
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1509
  ASSERT_EQ(code, 0);
1!
1510
  ASSERT_EQ(tableMeta->vgId, 9);
1!
1511
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
1512
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1513
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1514
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1515
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1516
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1517
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1518

1519
  taosMemoryFreeClear(tableMeta);
1!
1520

1521
  TAOS_STRCPY(n.tname, ctgTestSTablename);
1✔
1522
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1523
  ASSERT_EQ(code, 0);
1!
1524
  ASSERT_EQ(tableMeta->vgId, 0);
1!
1525
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
1526
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1527
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1528
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1529
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1530
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1531
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1532

1533
  taosMemoryFree(tableMeta);
1!
1534

1535
  SDbCacheInfo   *dbs = NULL;
1✔
1536
  SSTableVersion *stb = NULL;
1✔
1537
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
1✔
1538
  int32_t         i = 0;
1✔
1539
  while (i < 5) {
6✔
1540
    ++i;
5✔
1541
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
5!
1542
    ASSERT_EQ(code, 0);
5!
1543
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
5!
1544
    ASSERT_EQ(code, 0);
5!
1545

1546
    if (dbNum) {
5✔
1547
      (void)printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
1!
1548
      taosMemoryFree(dbs);
1!
1549
      dbs = NULL;
1✔
1550
    } else {
1551
      (void)printf("no expired db\n");
4!
1552
    }
1553

1554
    if (stbNum) {
5✔
1555
      (void)printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
1!
1556
      taosMemoryFree(stb);
1!
1557
      stb = NULL;
1✔
1558
    } else {
1559
      (void)printf("no expired stb\n");
4!
1560
    }
1561

1562
    allDbNum += dbNum;
5✔
1563
    allStbNum += stbNum;
5✔
1564
    taosSsleep(2);
5!
1565
  }
1566

1567
  ASSERT_EQ(allDbNum, 1);
1!
1568
  ASSERT_EQ(allStbNum, 1);
1!
1569

1570
  catalogDestroy();
1!
1571
}
1572

1573
TEST(tableMeta, superTableCase) {
4✔
1574
  struct SCatalog  *pCtg = NULL;
1✔
1575
  SRequestConnInfo  connInfo = {0};
1✔
1576
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1577
  SVgroupInfo       vgInfo = {0};
1✔
1578

1579
  ctgTestSetRspDbVgroupsAndSuperMeta();
1!
1580

1581
  initQueryModuleMsgHandle();
1!
1582

1583
  int32_t code = catalogInit(NULL);
1!
1584
  ASSERT_EQ(code, 0);
1!
1585

1586
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
1587
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1588
  ASSERT_EQ(code, 0);
1!
1589

1590
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1591
  TAOS_STRCPY(n.dbname, "db1");
1✔
1592
  TAOS_STRCPY(n.tname, ctgTestSTablename);
1✔
1593

1594
  STableMeta *tableMeta = NULL;
1✔
1595
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1596
  ASSERT_EQ(code, 0);
1!
1597
  ASSERT_EQ(tableMeta->vgId, 0);
1!
1598
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
1599
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1600
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1601
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
1602
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
1603
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1604
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1605
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1606
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1607

1608
  taosMemoryFree(tableMeta);
1!
1609

1610
  while (true) {
1611
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
2!
1612
    if (0 == n) {
2✔
1613
      taosMsleep(50);
1!
1614
    } else {
1615
      break;
1✔
1616
    }
1617
  }
1✔
1618

1619
  tableMeta = NULL;
1✔
1620
  code = catalogGetCachedSTableMeta(pCtg, &n, &tableMeta);
1!
1621
  ASSERT_EQ(code, 0);
1!
1622
  ASSERT_EQ(tableMeta->vgId, 0);
1!
1623
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
1624
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1625
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1626
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
1627
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
1628
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1629
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1630
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1631
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1632
  taosMemoryFree(tableMeta);
1!
1633

1634
  ctgTestSetRspCTableMeta();
1!
1635

1636
  tableMeta = NULL;
1✔
1637

1638
  TAOS_STRCPY(n.dbname, "db1");
1✔
1639
  TAOS_STRCPY(n.tname, ctgTestCTablename);
1✔
1640
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1641
  ASSERT_EQ(code, 0);
1!
1642
  ASSERT_EQ(tableMeta->vgId, 9);
1!
1643
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
1644
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1645
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1646
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1647
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1648
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1649
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1650

1651
  taosMemoryFree(tableMeta);
1!
1652

1653
  while (true) {
1654
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
1!
1655
    if (2 != n) {
1!
1656
      taosMsleep(50);
×
1657
    } else {
1658
      break;
1✔
1659
    }
1660
  }
×
1661

1662
  tableMeta = NULL;
1✔
1663
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
1664
  ASSERT_EQ(code, 0);
1!
1665
  ASSERT_EQ(tableMeta->vgId, 9);
1!
1666
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
1667
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1668
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1669
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1670
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1671
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1672
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1673

1674
  taosMemoryFree(tableMeta);
1!
1675

1676
  SDbCacheInfo   *dbs = NULL;
1✔
1677
  SSTableVersion *stb = NULL;
1✔
1678
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
1✔
1679
  int32_t         i = 0;
1✔
1680
  while (i < 5) {
6✔
1681
    ++i;
5✔
1682
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
5!
1683
    ASSERT_EQ(code, 0);
5!
1684
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
5!
1685
    ASSERT_EQ(code, 0);
5!
1686

1687
    if (dbNum) {
5✔
1688
      (void)printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
1!
1689
      taosMemoryFree(dbs);
1!
1690
      dbs = NULL;
1✔
1691
    } else {
1692
      (void)printf("no expired db\n");
4!
1693
    }
1694

1695
    if (stbNum) {
5✔
1696
      (void)printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
1!
1697

1698
      taosMemoryFree(stb);
1!
1699
      stb = NULL;
1✔
1700
    } else {
1701
      (void)printf("no expired stb\n");
4!
1702
    }
1703

1704
    allDbNum += dbNum;
5✔
1705
    allStbNum += stbNum;
5✔
1706
    taosSsleep(2);
5!
1707
  }
1708

1709
  ASSERT_EQ(allDbNum, 1);
1!
1710
  ASSERT_EQ(allStbNum, 1);
1!
1711

1712
  catalogDestroy();
1!
1713
}
1714

1715
TEST(tableMeta, rmStbMeta) {
4✔
1716
  struct SCatalog  *pCtg = NULL;
1✔
1717
  SRequestConnInfo  connInfo = {0};
1✔
1718
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1719
  SVgroupInfo       vgInfo = {0};
1✔
1720

1721
  ctgTestInitLogFile();
1!
1722

1723
  ctgTestSetRspDbVgroupsAndSuperMeta();
1!
1724

1725
  initQueryModuleMsgHandle();
1!
1726

1727
  int32_t code = catalogInit(NULL);
1!
1728
  ASSERT_EQ(code, 0);
1!
1729

1730
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
1731
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1732
  ASSERT_EQ(code, 0);
1!
1733

1734
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1735
  TAOS_STRCPY(n.dbname, "db1");
1✔
1736
  TAOS_STRCPY(n.tname, ctgTestSTablename);
1✔
1737

1738
  STableMeta *tableMeta = NULL;
1✔
1739
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1740
  ASSERT_EQ(code, 0);
1!
1741
  ASSERT_EQ(tableMeta->vgId, 0);
1!
1742
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
1743
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1744
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1745
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
1746
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
1747
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1748
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1749
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1750
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1751

1752
  taosMemoryFree(tableMeta);
1!
1753

1754
  while (true) {
1755
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
2!
1756
    if (0 == n) {
2✔
1757
      taosMsleep(50);
1!
1758
    } else {
1759
      break;
1✔
1760
    }
1761
  }
1✔
1762

1763
  code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid);
1!
1764
  ASSERT_EQ(code, 0);
1!
1765

1766
  while (true) {
1767
    int32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
1!
1768
    int32_t m = ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
1!
1769
    if (n || m) {
1!
1770
      taosMsleep(50);
×
1771
    } else {
1772
      break;
1773
    }
1774
  }
×
1775

1776
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
1!
1777
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0);
1!
1778
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
1!
1779
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
1!
1780
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
1!
1781

1782
  catalogDestroy();
1!
1783
}
1784

1785
TEST(tableMeta, updateStbMeta) {
4✔
1786
  struct SCatalog  *pCtg = NULL;
1✔
1787
  SRequestConnInfo  connInfo = {0};
1✔
1788
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1789
  SVgroupInfo       vgInfo = {0};
1✔
1790

1791
  ctgTestInitLogFile();
1!
1792

1793
  ctgTestSetRspDbVgroupsAndSuperMeta();
1!
1794

1795
  initQueryModuleMsgHandle();
1!
1796

1797
  int32_t code = catalogInit(NULL);
1!
1798
  ASSERT_EQ(code, 0);
1!
1799

1800
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
1801
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1802
  ASSERT_EQ(code, 0);
1!
1803

1804
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1805
  TAOS_STRCPY(n.dbname, "db1");
1✔
1806
  TAOS_STRCPY(n.tname, ctgTestSTablename);
1✔
1807

1808
  STableMeta *tableMeta = NULL;
1✔
1809
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1810
  ASSERT_EQ(code, 0);
1!
1811
  ASSERT_EQ(tableMeta->vgId, 0);
1!
1812
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
1813
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1814
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1815
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
1816
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
1817
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1818
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1819
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1820
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1821

1822
  while (true) {
1823
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
2!
1824
    if (0 == n) {
2✔
1825
      taosMsleep(50);
1!
1826
    } else {
1827
      break;
1✔
1828
    }
1829
  }
1✔
1830

1831
  taosMemoryFreeClear(tableMeta);
1!
1832

1833
  STableMetaRsp rsp = {0};
1✔
1834
  ctgTestBuildSTableMetaRsp(&rsp);
1!
1835

1836
  code = catalogUpdateTableMeta(pCtg, &rsp);
1!
1837
  ASSERT_EQ(code, 0);
1!
1838
  code = catalogAsyncUpdateTableMeta(pCtg, &rsp);
1!
1839
  ASSERT_EQ(code, 0);
1!
1840
  taosMemoryFreeClear(rsp.pSchemas);
1!
1841

1842
  while (true) {
1843
    uint64_t n = 0;
1✔
1844
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
1!
1845
    if (n < 3) {
1!
1846
      taosMsleep(50);
×
1847
    } else {
1848
      break;
1✔
1849
    }
1850
  }
×
1851

1852
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
1!
1853
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1);
1!
1854
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1);
1!
1855
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
1!
1856
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1);
1!
1857

1858
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1859
  ASSERT_EQ(code, 0);
1!
1860
  ASSERT_EQ(tableMeta->vgId, 0);
1!
1861
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
1862
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion + 1);
1!
1863
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion + 1);
1!
1864
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
1865
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
1866
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1867
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
1868
  ASSERT_EQ(tableMeta->tableInfo.precision, 1 + 1);
1!
1869
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1870

1871
  taosMemoryFreeClear(tableMeta);
1!
1872

1873
  catalogDestroy();
1!
1874
}
1875

1876
TEST(getIndexInfo, notExists) {
4✔
1877
  struct SCatalog  *pCtg = NULL;
1✔
1878
  SRequestConnInfo  connInfo = {0};
1✔
1879
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1880
  SVgroupInfo       vgInfo = {0};
1✔
1881
  SArray           *vgList = NULL;
1✔
1882

1883
  ctgTestInitLogFile();
1!
1884

1885
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
1886
  ctgTestRspIdx = 0;
1✔
1887
  ctgTestRspFunc[0] = CTGT_RSP_INDEXINFO_E;
1✔
1888

1889
  ctgTestSetRspByIdx();
1!
1890

1891
  initQueryModuleMsgHandle();
1!
1892

1893
  int32_t code = catalogInit(NULL);
1!
1894
  ASSERT_EQ(code, 0);
1!
1895

1896
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1897
  ASSERT_EQ(code, 0);
1!
1898

1899
  SIndexInfo info;
1900
  code = catalogGetIndexMeta(pCtg, mockPointer, "index1", &info);
1!
1901
  ASSERT_TRUE(code != 0);
1!
1902

1903
  catalogDestroy();
1!
1904
}
1905

1906
TEST(refreshGetMeta, normal2normal) {
4✔
1907
  struct SCatalog  *pCtg = NULL;
1✔
1908
  SRequestConnInfo  connInfo = {0};
1✔
1909
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1910
  SVgroupInfo       vgInfo = {0};
1✔
1911
  SArray           *vgList = NULL;
1✔
1912

1913
  ctgTestInitLogFile();
1!
1914

1915
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
1916
  ctgTestRspIdx = 0;
1✔
1917
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
1918
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
1✔
1919
  ctgTestRspFunc[2] = CTGT_RSP_TBMETA;
1✔
1920

1921
  ctgTestSetRspByIdx();
1!
1922

1923
  initQueryModuleMsgHandle();
1!
1924

1925
  int32_t code = catalogInit(NULL);
1!
1926
  ASSERT_EQ(code, 0);
1!
1927

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

1930
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
1931
  ASSERT_EQ(code, 0);
1!
1932

1933
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
1934
  TAOS_STRCPY(n.dbname, "db1");
1✔
1935
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
1936

1937
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
1938
  ASSERT_EQ(code, 0);
1!
1939
  ASSERT_EQ(vgInfo.vgId, 8);
1!
1940
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
1941

1942
  while (true) {
1943
    uint64_t n = 0;
2✔
1944
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
1945
    if (n > 0) {
2✔
1946
      break;
1✔
1947
    }
1948
    taosMsleep(50);
1!
1949
  }
1✔
1950

1951
  STableMeta *tableMeta = NULL;
1✔
1952
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
1953
  ASSERT_EQ(code, 0);
1!
1954
  ASSERT_EQ(tableMeta->vgId, 8);
1!
1955
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
1956
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
1!
1957
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1958
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1959
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1960
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
1961
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1962
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1963
  taosMemoryFreeClear(tableMeta);
1!
1964

1965
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
1!
1966
    taosMsleep(50);
×
1967
  }
1968

1969
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
1970
  ASSERT_EQ(code, 0);
1!
1971
  ASSERT_EQ(tableMeta->vgId, 8);
1!
1972
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
1973
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
1!
1974
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
1975
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
1976
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
1977
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
1978
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
1979
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
1980
  taosMemoryFreeClear(tableMeta);
1!
1981

1982
  catalogDestroy();
1!
1983
}
1984

1985
TEST(refreshGetMeta, normal2notexist) {
4✔
1986
  struct SCatalog  *pCtg = NULL;
1✔
1987
  SRequestConnInfo  connInfo = {0};
1✔
1988
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
1989
  SVgroupInfo       vgInfo = {0};
1✔
1990
  SArray           *vgList = NULL;
1✔
1991

1992
  ctgTestInitLogFile();
1!
1993

1994
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
1995
  ctgTestRspIdx = 0;
1✔
1996
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
1997
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
1✔
1998
  ctgTestRspFunc[2] = CTGT_RSP_TBMETA_NOT_EXIST;
1✔
1999

2000
  ctgTestSetRspByIdx();
1!
2001

2002
  initQueryModuleMsgHandle();
1!
2003

2004
  int32_t code = catalogInit(NULL);
1!
2005
  ASSERT_EQ(code, 0);
1!
2006

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

2009
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2010
  ASSERT_EQ(code, 0);
1!
2011

2012
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2013
  TAOS_STRCPY(n.dbname, "db1");
1✔
2014
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2015

2016
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2017
  ASSERT_EQ(code, 0);
1!
2018
  ASSERT_EQ(vgInfo.vgId, 8);
1!
2019
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
2020

2021
  while (true) {
2022
    uint64_t n = 0;
2✔
2023
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2024
    if (n > 0) {
2✔
2025
      break;
1✔
2026
    }
2027
    taosMsleep(50);
1!
2028
  }
1✔
2029

2030
  STableMeta *tableMeta = NULL;
1✔
2031
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
2032
  ASSERT_EQ(code, 0);
1!
2033
  ASSERT_EQ(tableMeta->vgId, 8);
1!
2034
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
2035
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
1!
2036
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2037
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2038
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2039
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
2040
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2041
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2042
  taosMemoryFreeClear(tableMeta);
1!
2043

2044
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
2!
2045
    taosMsleep(50);
1!
2046
  }
2047

2048
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
2049
  ASSERT_EQ(code, CTG_ERR_CODE_TABLE_NOT_EXIST);
1!
2050
  ASSERT_TRUE(tableMeta == NULL);
1!
2051

2052
  catalogDestroy();
1!
2053
}
2054

2055
TEST(refreshGetMeta, normal2child) {
4✔
2056
  struct SCatalog  *pCtg = NULL;
1✔
2057
  SRequestConnInfo  connInfo = {0};
1✔
2058
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2059
  SVgroupInfo       vgInfo = {0};
1✔
2060
  SArray           *vgList = NULL;
1✔
2061

2062
  ctgTestInitLogFile();
1!
2063

2064
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2065
  ctgTestRspIdx = 0;
1✔
2066
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2067
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
1✔
2068
  ctgTestRspFunc[2] = CTGT_RSP_CTBMETA;
1✔
2069
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
1✔
2070

2071
  ctgTestSetRspByIdx();
1!
2072

2073
  initQueryModuleMsgHandle();
1!
2074

2075
  int32_t code = catalogInit(NULL);
1!
2076
  ASSERT_EQ(code, 0);
1!
2077

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

2080
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2081
  ASSERT_EQ(code, 0);
1!
2082

2083
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2084
  TAOS_STRCPY(n.dbname, "db1");
1✔
2085
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2086
  ctgTestCurrentCTableName = ctgTestTablename;
1✔
2087
  ctgTestCurrentSTableName = ctgTestSTablename;
1✔
2088

2089
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2090
  ASSERT_EQ(code, 0);
1!
2091
  ASSERT_EQ(vgInfo.vgId, 8);
1!
2092
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
2093

2094
  while (true) {
2095
    uint64_t n = 0;
2✔
2096
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2097
    if (n > 0) {
2✔
2098
      break;
1✔
2099
    }
2100
    taosMsleep(50);
1!
2101
  }
1✔
2102

2103
  STableMeta *tableMeta = NULL;
1✔
2104
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
2105
  ASSERT_EQ(code, 0);
1!
2106
  ASSERT_EQ(tableMeta->vgId, 8);
1!
2107
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
1!
2108
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
1!
2109
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2110
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2111
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2112
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
1!
2113
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2114
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2115
  taosMemoryFreeClear(tableMeta);
1!
2116

2117
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
1!
2118
    taosMsleep(50);
×
2119
  }
2120

2121
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
2122
  ASSERT_EQ(code, 0);
1!
2123
  ASSERT_EQ(tableMeta->vgId, 9);
1!
2124
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
2125
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2126
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2127
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2128
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2129
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2130
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2131
  taosMemoryFreeClear(tableMeta);
1!
2132

2133
  catalogDestroy();
1!
2134
  ctgTestCurrentCTableName = NULL;
1✔
2135
  ctgTestCurrentSTableName = NULL;
1✔
2136
}
2137

2138
TEST(refreshGetMeta, stable2child) {
4✔
2139
  struct SCatalog  *pCtg = NULL;
1✔
2140
  SRequestConnInfo  connInfo = {0};
1✔
2141
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2142
  SVgroupInfo       vgInfo = {0};
1✔
2143
  SArray           *vgList = NULL;
1✔
2144

2145
  ctgTestInitLogFile();
1!
2146

2147
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2148
  ctgTestRspIdx = 0;
1✔
2149
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2150
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
1✔
2151
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
1✔
2152
  ctgTestRspFunc[3] = CTGT_RSP_CTBMETA;
1✔
2153
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
1✔
2154

2155
  ctgTestSetRspByIdx();
1!
2156

2157
  initQueryModuleMsgHandle();
1!
2158

2159
  int32_t code = catalogInit(NULL);
1!
2160
  ASSERT_EQ(code, 0);
1!
2161

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

2164
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2165
  ASSERT_EQ(code, 0);
1!
2166

2167
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2168
  TAOS_STRCPY(n.dbname, "db1");
1✔
2169
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2170
  ctgTestCurrentSTableName = ctgTestTablename;
1✔
2171
  ctgTestCurrentCTableName = ctgTestTablename;
1✔
2172

2173
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2174
  ASSERT_EQ(code, 0);
1!
2175
  ASSERT_EQ(vgInfo.vgId, 8);
1!
2176
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
2177

2178
  while (true) {
2179
    uint64_t n = 0;
2✔
2180
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2181
    if (n > 0) {
2✔
2182
      break;
1✔
2183
    }
2184
    taosMsleep(50);
1!
2185
  }
1✔
2186

2187
  STableMeta *tableMeta = NULL;
1✔
2188
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
2189
  ASSERT_EQ(code, 0);
1!
2190
  ASSERT_EQ(tableMeta->vgId, 0);
1!
2191
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
2192
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2193
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2194
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
2195
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
2196
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2197
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2198
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2199
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2200
  taosMemoryFreeClear(tableMeta);
1!
2201

2202
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
1!
2203
    taosMsleep(50);
×
2204
  }
2205

2206
  ctgTestCurrentSTableName = ctgTestSTablename;
1✔
2207
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
2208
  ASSERT_EQ(code, 0);
1!
2209
  ASSERT_EQ(tableMeta->vgId, 9);
1!
2210
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
2211
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2212
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2213
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2214
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2215
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2216
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2217
  taosMemoryFreeClear(tableMeta);
1!
2218

2219
  catalogDestroy();
1!
2220
  ctgTestCurrentCTableName = NULL;
1✔
2221
  ctgTestCurrentSTableName = NULL;
1✔
2222
}
2223

2224
TEST(refreshGetMeta, stable2stable) {
4✔
2225
  struct SCatalog  *pCtg = NULL;
1✔
2226
  SRequestConnInfo  connInfo = {0};
1✔
2227
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2228
  SVgroupInfo       vgInfo = {0};
1✔
2229
  SArray           *vgList = NULL;
1✔
2230

2231
  ctgTestInitLogFile();
1!
2232

2233
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2234
  ctgTestRspIdx = 0;
1✔
2235
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2236
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
1✔
2237
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
1✔
2238
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
1✔
2239
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
1✔
2240

2241
  ctgTestSetRspByIdx();
1!
2242

2243
  initQueryModuleMsgHandle();
1!
2244

2245
  int32_t code = catalogInit(NULL);
1!
2246
  ASSERT_EQ(code, 0);
1!
2247

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

2250
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2251
  ASSERT_EQ(code, 0);
1!
2252

2253
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2254
  TAOS_STRCPY(n.dbname, "db1");
1✔
2255
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2256
  ctgTestCurrentSTableName = ctgTestTablename;
1✔
2257

2258
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2259
  ASSERT_EQ(code, 0);
1!
2260
  ASSERT_EQ(vgInfo.vgId, 8);
1!
2261
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
2262

2263
  while (true) {
2264
    uint64_t n = 0;
2✔
2265
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2266
    if (n > 0) {
2✔
2267
      break;
1✔
2268
    }
2269
    taosMsleep(50);
1!
2270
  }
1✔
2271

2272
  STableMeta *tableMeta = NULL;
1✔
2273
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
2274
  ASSERT_EQ(code, 0);
1!
2275
  ASSERT_EQ(tableMeta->vgId, 0);
1!
2276
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
2277
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2278
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2279
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
2280
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
2281
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2282
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2283
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2284
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2285
  taosMemoryFreeClear(tableMeta);
1!
2286

2287
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
2!
2288
    taosMsleep(50);
1!
2289
  }
2290

2291
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
2292
  ASSERT_EQ(code, 0);
1!
2293
  ASSERT_EQ(tableMeta->vgId, 0);
1!
2294
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
2295
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2296
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2297
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
2298
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
2299
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2300
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2301
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2302
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2303
  taosMemoryFreeClear(tableMeta);
1!
2304

2305
  catalogDestroy();
1!
2306
  ctgTestCurrentCTableName = NULL;
1✔
2307
  ctgTestCurrentSTableName = NULL;
1✔
2308
}
2309

2310
TEST(refreshGetMeta, child2stable) {
4✔
2311
  struct SCatalog  *pCtg = NULL;
1✔
2312
  SRequestConnInfo  connInfo = {0};
1✔
2313
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2314
  SVgroupInfo       vgInfo = {0};
1✔
2315
  SArray           *vgList = NULL;
1✔
2316

2317
  ctgTestInitLogFile();
1!
2318

2319
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2320
  ctgTestRspIdx = 0;
1✔
2321
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2322
  ctgTestRspFunc[1] = CTGT_RSP_CTBMETA;
1✔
2323
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
1✔
2324
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
1✔
2325
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
1✔
2326

2327
  ctgTestSetRspByIdx();
1!
2328

2329
  initQueryModuleMsgHandle();
1!
2330

2331
  int32_t code = catalogInit(NULL);
1!
2332
  ASSERT_EQ(code, 0);
1!
2333

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

2336
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2337
  ASSERT_EQ(code, 0);
1!
2338

2339
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2340
  TAOS_STRCPY(n.dbname, "db1");
1✔
2341
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2342
  ctgTestCurrentCTableName = ctgTestTablename;
1✔
2343
  ctgTestCurrentSTableName = ctgTestSTablename;
1✔
2344

2345
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2346
  ASSERT_EQ(code, 0);
1!
2347
  ASSERT_EQ(vgInfo.vgId, 8);
1!
2348
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
2349

2350
  while (true) {
2351
    uint64_t n = 0;
2✔
2352
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2353
    if (n > 0) {
2✔
2354
      break;
1✔
2355
    }
2356
    taosMsleep(50);
1!
2357
  }
1✔
2358

2359
  STableMeta *tableMeta = NULL;
1✔
2360
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
1!
2361
  ASSERT_EQ(code, 0);
1!
2362
  ASSERT_EQ(tableMeta->vgId, 9);
1!
2363
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
1!
2364
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2365
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2366
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2367
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2368
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2369
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2370
  taosMemoryFreeClear(tableMeta);
1!
2371

2372
  while (2 != ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
2!
2373
    taosMsleep(50);
1!
2374
  }
2375

2376
  ctgTestCurrentSTableName = ctgTestTablename;
1✔
2377
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
1!
2378
  ASSERT_EQ(code, 0);
1!
2379
  ASSERT_EQ(tableMeta->vgId, 0);
1!
2380
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
1!
2381
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
1!
2382
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
1!
2383
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
1!
2384
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
1!
2385
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
1!
2386
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
1!
2387
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
1!
2388
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
1!
2389
  taosMemoryFreeClear(tableMeta);
1!
2390

2391
  catalogDestroy();
1!
2392
  ctgTestCurrentCTableName = NULL;
1✔
2393
  ctgTestCurrentSTableName = NULL;
1✔
2394
}
2395

2396
TEST(tableDistVgroup, normalTable) {
4✔
2397
  struct SCatalog  *pCtg = NULL;
1✔
2398
  SRequestConnInfo  connInfo = {0};
1✔
2399
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2400
  SVgroupInfo      *vgInfo = NULL;
1✔
2401
  SArray           *vgList = NULL;
1✔
2402

2403
  ctgTestInitLogFile();
1!
2404

2405
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2406
  ctgTestRspIdx = 0;
1✔
2407
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2408
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
1✔
2409
  ctgTestRspFunc[2] = CTGT_RSP_VGINFO;
1✔
2410

2411
  ctgTestSetRspByIdx();
1!
2412

2413
  initQueryModuleMsgHandle();
1!
2414

2415
  int32_t code = catalogInit(NULL);
1!
2416
  ASSERT_EQ(code, 0);
1!
2417

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

2420
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2421
  ASSERT_EQ(code, 0);
1!
2422

2423
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2424
  TAOS_STRCPY(n.dbname, "db1");
1✔
2425
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2426

2427
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
1!
2428
  ASSERT_TRUE(code != 0);
1!
2429

2430
  catalogDestroy();
1!
2431
}
2432

2433
TEST(tableDistVgroup, childTableCase) {
4✔
2434
  struct SCatalog  *pCtg = NULL;
1✔
2435
  SRequestConnInfo  connInfo = {0};
1✔
2436
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2437
  SVgroupInfo      *vgInfo = NULL;
1✔
2438
  SArray           *vgList = NULL;
1✔
2439

2440
  ctgTestInitLogFile();
1!
2441

2442
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2443
  ctgTestRspIdx = 0;
1✔
2444
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2445
  ctgTestRspFunc[1] = CTGT_RSP_CTBMETA;
1✔
2446
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
1✔
2447
  ctgTestRspFunc[3] = CTGT_RSP_VGINFO;
1✔
2448

2449
  ctgTestSetRspByIdx();
1!
2450

2451
  initQueryModuleMsgHandle();
1!
2452

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

2455
  int32_t code = catalogInit(NULL);
1!
2456
  ASSERT_EQ(code, 0);
1!
2457

2458
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2459
  ASSERT_EQ(code, 0);
1!
2460

2461
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2462
  TAOS_STRCPY(n.dbname, "db1");
1✔
2463
  TAOS_STRCPY(n.tname, ctgTestCTablename);
1✔
2464

2465
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
1!
2466
  ASSERT_TRUE(code != 0);
1!
2467

2468
  catalogDestroy();
1!
2469
}
2470

2471
TEST(tableDistVgroup, superTableCase) {
4✔
2472
  struct SCatalog  *pCtg = NULL;
1✔
2473
  SRequestConnInfo  connInfo = {0};
1✔
2474
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2475
  SVgroupInfo      *vgInfo = NULL;
1✔
2476
  SArray           *vgList = NULL;
1✔
2477

2478
  ctgTestInitLogFile();
1!
2479

2480
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2481
  ctgTestRspIdx = 0;
1✔
2482
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2483
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
1✔
2484
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
1✔
2485
  ctgTestRspFunc[3] = CTGT_RSP_VGINFO;
1✔
2486

2487
  ctgTestSetRspByIdx();
1!
2488

2489
  initQueryModuleMsgHandle();
1!
2490

2491
  int32_t code = catalogInit(NULL);
1!
2492
  ASSERT_EQ(code, 0);
1!
2493

2494
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
2495
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2496
  ASSERT_EQ(code, 0);
1!
2497

2498
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2499
  TAOS_STRCPY(n.dbname, "db1");
1✔
2500
  TAOS_STRCPY(n.tname, ctgTestSTablename);
1✔
2501

2502
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
1!
2503
  ASSERT_EQ(code, 0);
1!
2504
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10);
1!
2505
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
1!
2506
  ASSERT_EQ(vgInfo->vgId, 1);
1!
2507
  ASSERT_EQ(vgInfo->epSet.numOfEps, 1);
1!
2508
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1);
1!
2509
  ASSERT_EQ(vgInfo->vgId, 2);
1!
2510
  ASSERT_EQ(vgInfo->epSet.numOfEps, 2);
1!
2511
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2);
1!
2512
  ASSERT_EQ(vgInfo->vgId, 3);
1!
2513
  ASSERT_EQ(vgInfo->epSet.numOfEps, 3);
1!
2514

2515
  taosArrayDestroy(vgList);
1!
2516

2517
  catalogDestroy();
1!
2518
}
2519

2520
TEST(dbVgroup, getSetDbVgroupCase) {
4✔
2521
  struct SCatalog  *pCtg = NULL;
1✔
2522
  SRequestConnInfo  connInfo = {0};
1✔
2523
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2524
  SVgroupInfo       vgInfo = {0};
1✔
2525
  SVgroupInfo      *pvgInfo = NULL;
1✔
2526
  SDBVgInfo        *dbVgroup = NULL;
1✔
2527
  SArray           *vgList = NULL;
1✔
2528

2529
  ctgTestInitLogFile();
1!
2530

2531
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2532
  ctgTestRspIdx = 0;
1✔
2533
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2534
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
1✔
2535

2536
  ctgTestSetRspByIdx();
1!
2537

2538
  initQueryModuleMsgHandle();
1!
2539

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

2542
  int32_t code = catalogInit(NULL);
1!
2543
  ASSERT_EQ(code, 0);
1!
2544

2545
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2546
  ASSERT_EQ(code, 0);
1!
2547

2548
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2549
  TAOS_STRCPY(n.dbname, "db1");
1✔
2550
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2551

2552
  code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList);
1!
2553
  ASSERT_EQ(code, 0);
1!
2554
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
1!
2555

2556
  taosArrayDestroy(vgList);
1!
2557

2558
  while (true) {
2559
    uint64_t n = 0;
2✔
2560
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2561
    if (n > 0) {
2✔
2562
      break;
1✔
2563
    }
2564
    taosMsleep(50);
1!
2565
  }
1✔
2566

2567
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2568
  ASSERT_EQ(code, 0);
1!
2569
  ASSERT_EQ(vgInfo.vgId, 8);
1!
2570
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
1!
2571

2572
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
1!
2573
  ASSERT_TRUE(code != 0);
1!
2574

2575
  int32_t dbVer = 0;
1✔
2576
  int64_t dbId = 0;
1✔
2577
  int32_t tbNum = 0;
1✔
2578
  int64_t stateTs = 0;
1✔
2579
  code = catalogGetDBVgVersion(pCtg, ctgTestDbname, &dbVer, &dbId, &tbNum, &stateTs);
1!
2580
  ASSERT_EQ(code, 0);
1!
2581
  ASSERT_EQ(dbVer, ctgTestVgVersion);
1!
2582
  ASSERT_EQ(dbId, ctgTestDbId);
1!
2583
  ASSERT_EQ(tbNum, ctgTestVgNum / 2);
1!
2584

2585
  ctgTestBuildDBVgroup(&dbVgroup);
1!
2586
  code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
1!
2587
  ASSERT_EQ(code, 0);
1!
2588

2589
  while (true) {
2590
    uint64_t n = 0;
2✔
2591
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2592
    if (n != 3) {
2✔
2593
      taosMsleep(50);
1!
2594
    } else {
2595
      break;
1✔
2596
    }
2597
  }
1✔
2598

2599
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
1!
2600
  ASSERT_EQ(code, 0);
1!
2601
  ASSERT_EQ(vgInfo.vgId, 7);
1!
2602
  ASSERT_EQ(vgInfo.epSet.numOfEps, 2);
1!
2603

2604
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
1!
2605
  ASSERT_TRUE(code != 0);
1!
2606

2607
  catalogDestroy();
1!
2608
}
2609

2610
TEST(multiThread, getSetRmSameDbVgroup) {
4✔
2611
  struct SCatalog  *pCtg = NULL;
1✔
2612
  SRequestConnInfo  connInfo = {0};
1✔
2613
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2614
  SVgroupInfo       vgInfo = {0};
1✔
2615
  SVgroupInfo      *pvgInfo = NULL;
1✔
2616
  SDBVgInfo         dbVgroup = {0};
1✔
2617
  SArray           *vgList = NULL;
1✔
2618
  ctgTestStop = false;
1✔
2619

2620
  ctgTestInitLogFile();
1!
2621

2622
  ctgTestSetRspDbVgroups();
1!
2623

2624
  initQueryModuleMsgHandle();
1!
2625

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

2628
  int32_t code = catalogInit(NULL);
1!
2629
  ASSERT_EQ(code, 0);
1!
2630

2631
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2632
  ASSERT_EQ(code, 0);
1!
2633

2634
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2635
  TAOS_STRCPY(n.dbname, "db1");
1✔
2636
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2637

2638
  TdThreadAttr thattr;
2639
  (void)taosThreadAttrInit(&thattr);
1!
2640

2641
  TdThread thread1, thread2;
2642
  (void)taosThreadCreate(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
1!
2643

2644
  taosSsleep(1);
1!
2645
  (void)taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
1!
2646

2647
  while (true) {
2648
    if (ctgTestDeadLoop) {
1!
2649
      taosSsleep(1);
×
2650
    } else {
2651
      taosSsleep(ctgTestMTRunSec);
1!
2652
      break;
1✔
2653
    }
2654
  }
2655

2656
  ctgTestStop = true;
1✔
2657
  taosSsleep(1);
1!
2658

2659
  catalogDestroy();
1!
2660
}
2661

2662
TEST(multiThread, getSetRmDiffDbVgroup) {
4✔
2663
  struct SCatalog  *pCtg = NULL;
1✔
2664
  SRequestConnInfo  connInfo = {0};
1✔
2665
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2666
  SVgroupInfo       vgInfo = {0};
1✔
2667
  SVgroupInfo      *pvgInfo = NULL;
1✔
2668
  SDBVgInfo         dbVgroup = {0};
1✔
2669
  SArray           *vgList = NULL;
1✔
2670
  ctgTestStop = false;
1✔
2671

2672
  ctgTestInitLogFile();
1!
2673

2674
  ctgTestSetRspDbVgroups();
1!
2675

2676
  initQueryModuleMsgHandle();
1!
2677

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

2680
  int32_t code = catalogInit(NULL);
1!
2681
  ASSERT_EQ(code, 0);
1!
2682

2683
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2684
  ASSERT_EQ(code, 0);
1!
2685

2686
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2687
  TAOS_STRCPY(n.dbname, "db1");
1✔
2688
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2689

2690
  TdThreadAttr thattr;
2691
  (void)taosThreadAttrInit(&thattr);
1!
2692

2693
  TdThread thread1, thread2;
2694
  (void)taosThreadCreate(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
1!
2695

2696
  taosSsleep(1);
1!
2697
  (void)taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
1!
2698

2699
  while (true) {
2700
    if (ctgTestDeadLoop) {
1!
2701
      taosSsleep(1);
×
2702
    } else {
2703
      taosSsleep(ctgTestMTRunSec);
1!
2704
      break;
1✔
2705
    }
2706
  }
2707

2708
  ctgTestStop = true;
1✔
2709
  taosSsleep(1);
1!
2710

2711
  catalogDestroy();
1!
2712
}
2713

2714
TEST(multiThread, ctableMeta) {
4✔
2715
  struct SCatalog  *pCtg = NULL;
1✔
2716
  SRequestConnInfo  connInfo = {0};
1✔
2717
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2718
  SVgroupInfo       vgInfo = {0};
1✔
2719
  SVgroupInfo      *pvgInfo = NULL;
1✔
2720
  SDBVgInfo         dbVgroup = {0};
1✔
2721
  SArray           *vgList = NULL;
1✔
2722
  ctgTestStop = false;
1✔
2723

2724
  ctgTestInitLogFile();
1!
2725

2726
  ctgTestSetRspDbVgroupsAndChildMeta();
1!
2727

2728
  initQueryModuleMsgHandle();
1!
2729

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

2732
  int32_t code = catalogInit(NULL);
1!
2733
  ASSERT_EQ(code, 0);
1!
2734

2735
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2736
  ASSERT_EQ(code, 0);
1!
2737

2738
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2739
  TAOS_STRCPY(n.dbname, "db1");
1✔
2740
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2741

2742
  TdThreadAttr thattr;
2743
  (void)taosThreadAttrInit(&thattr);
1!
2744

2745
  TdThread thread1, thread2;
2746
  (void)taosThreadCreate(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
1!
2747
  taosSsleep(1);
1!
2748
  (void)taosThreadCreate(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
1!
2749

2750
  while (true) {
2751
    if (ctgTestDeadLoop) {
1!
2752
      taosSsleep(1);
×
2753
    } else {
2754
      taosSsleep(ctgTestMTRunSec);
1!
2755
      break;
1✔
2756
    }
2757
  }
2758

2759
  ctgTestStop = true;
1✔
2760
  taosSsleep(2);
1!
2761

2762
  catalogDestroy();
1!
2763
}
2764

2765
TEST(rentTest, allRent) {
4✔
2766
  struct SCatalog  *pCtg = NULL;
1✔
2767
  SRequestConnInfo  connInfo = {0};
1✔
2768
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2769
  SVgroupInfo       vgInfo = {0};
1✔
2770
  SVgroupInfo      *pvgInfo = NULL;
1✔
2771
  SDBVgInfo         dbVgroup = {0};
1✔
2772
  SArray           *vgList = NULL;
1✔
2773
  ctgTestStop = false;
1✔
2774
  SDbCacheInfo   *dbs = NULL;
1✔
2775
  SSTableVersion *stable = NULL;
1✔
2776
  uint32_t        num = 0;
1✔
2777

2778
  ctgTestInitLogFile();
1!
2779

2780
  ctgTestSetRspDbVgroupsAndMultiSuperMeta();
1!
2781

2782
  initQueryModuleMsgHandle();
1!
2783

2784
  int32_t code = catalogInit(NULL);
1!
2785
  ASSERT_EQ(code, 0);
1!
2786

2787
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2788
  ASSERT_EQ(code, 0);
1!
2789

2790
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2791
  TAOS_STRCPY(n.dbname, "db1");
1✔
2792

2793
  for (int32_t i = 1; i <= 10; ++i) {
11✔
2794
    (void)sprintf(n.tname, "%s_%d", ctgTestSTablename, i);
10✔
2795

2796
    STableMeta *tableMeta = NULL;
10✔
2797
    code = catalogGetSTableMeta(pCtg, mockPointer, &n, &tableMeta);
10!
2798
    ASSERT_EQ(code, 0);
10!
2799
    ASSERT_EQ(tableMeta->vgId, 0);
10!
2800
    ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
10!
2801
    ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
10!
2802
    ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
10!
2803
    ASSERT_EQ(tableMeta->uid, ctgTestSuid + i);
10!
2804
    ASSERT_EQ(tableMeta->suid, ctgTestSuid + i);
10!
2805
    ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
10!
2806
    ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
10!
2807
    ASSERT_EQ(tableMeta->tableInfo.precision, 1);
10!
2808
    ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
10!
2809

2810
    taosMemoryFree(tableMeta);
10!
2811

2812
    while (ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
16!
2813
      taosMsleep(50);
6!
2814
    }
2815

2816
    code = catalogGetExpiredDBs(pCtg, &dbs, &num);
10!
2817
    ASSERT_EQ(code, 0);
10!
2818
    (void)printf("%d - expired dbNum:%d\n", i, num);
10!
2819
    if (dbs) {
10✔
2820
      (void)printf("%d - expired dbId:%" PRId64 ", vgVersion:%d\n", i, dbs->dbId, dbs->vgVersion);
1!
2821
      taosMemoryFree(dbs);
1!
2822
      dbs = NULL;
1✔
2823
    }
2824

2825
    code = catalogGetExpiredSTables(pCtg, &stable, &num);
10!
2826
    ASSERT_EQ(code, 0);
10!
2827
    (void)printf("%d - expired stableNum:%d\n", i, num);
10!
2828
    if (stable) {
10✔
2829
      for (int32_t n = 0; n < num; ++n) {
18✔
2830
        (void)printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid,
10✔
2831
               stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion);
10!
2832
      }
2833
      taosMemoryFree(stable);
8!
2834
      stable = NULL;
8✔
2835
    }
2836
    (void)printf("*************************************************\n");
10!
2837

2838
    taosSsleep(2);
10!
2839
  }
2840

2841
  catalogDestroy();
1!
2842
}
2843

2844
TEST(apiTest, catalogRefreshDBVgInfo_test) {
4✔
2845
  struct SCatalog  *pCtg = NULL;
1✔
2846
  SRequestConnInfo  connInfo = {0};
1✔
2847
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2848

2849
  ctgTestInitLogFile();
1!
2850

2851
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2852
  ctgTestRspIdx = 0;
1✔
2853
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2854

2855
  ctgTestSetRspByIdx();
1!
2856

2857
  initQueryModuleMsgHandle();
1!
2858

2859
  int32_t code = catalogInit(NULL);
1!
2860
  ASSERT_EQ(code, 0);
1!
2861

2862
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2863
  ASSERT_EQ(code, 0);
1!
2864

2865
  code = catalogRefreshDBVgInfo(pCtg, mockPointer, ctgTestDbname);
1!
2866
  ASSERT_EQ(code, 0);
1!
2867

2868
  catalogDestroy();
1!
2869
}
2870

2871
TEST(apiTest, catalogChkAuth_test) {
4✔
2872
  struct SCatalog  *pCtg = NULL;
1✔
2873
  SRequestConnInfo  connInfo = {0};
1✔
2874
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2875

2876
  ctgTestInitLogFile();
1!
2877

2878
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2879
  ctgTestRspIdx = 0;
1✔
2880
  ctgTestRspFunc[0] = CTGT_RSP_USERAUTH;
1✔
2881

2882
  ctgTestSetRspByIdx();
1!
2883

2884
  initQueryModuleMsgHandle();
1!
2885

2886
  int32_t code = catalogInit(NULL);
1!
2887
  ASSERT_EQ(code, 0);
1!
2888

2889
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2890
  ASSERT_EQ(code, 0);
1!
2891

2892
  SUserAuthInfo authInfo = {0};
1✔
2893
  SUserAuthRes  authRes = {0};
1✔
2894
  TAOS_STRCPY(authInfo.user, ctgTestUsername);
1✔
2895
  toName(1, ctgTestDbname, ctgTestSTablename, &authInfo.tbName);
1!
2896
  authInfo.type = AUTH_TYPE_READ;
1✔
2897
  bool exists = false;
1✔
2898
  code = catalogChkAuthFromCache(pCtg, &authInfo, &authRes, &exists);
1!
2899
  ASSERT_EQ(code, 0);
1!
2900
  ASSERT_EQ(exists, false);
1!
2901

2902
  code = catalogChkAuth(pCtg, mockPointer, &authInfo, &authRes);
1!
2903
  ASSERT_EQ(code, 0);
1!
2904
  ASSERT_EQ(authRes.pass[AUTH_RES_BASIC], true);
1!
2905

2906
  while (true) {
2907
    uint64_t n = 0;
2✔
2908
    ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n));
2!
2909
    if (n != 1) {
2✔
2910
      taosMsleep(50);
1!
2911
    } else {
2912
      break;
1✔
2913
    }
2914
  }
1✔
2915

2916
  code = catalogChkAuthFromCache(pCtg, &authInfo, &authRes, &exists);
1!
2917
  ASSERT_EQ(code, 0);
1!
2918
  ASSERT_EQ(authRes.pass[AUTH_RES_BASIC], true);
1!
2919
  ASSERT_EQ(exists, true);
1!
2920

2921
  catalogDestroy();
1!
2922
}
2923

2924
TEST(apiTest, catalogRefreshGetTableCfg_test) {
4✔
2925
  struct SCatalog  *pCtg = NULL;
1✔
2926
  SRequestConnInfo  connInfo = {0};
1✔
2927
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2928

2929
  ctgTestInitLogFile();
1!
2930

2931
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2932
  ctgTestRspIdx = 0;
1✔
2933
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
1✔
2934
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
1✔
2935

2936
  ctgTestSetRspByIdx();
1!
2937

2938
  initQueryModuleMsgHandle();
1!
2939

2940
  int32_t code = catalogInit(NULL);
1!
2941
  ASSERT_EQ(code, 0);
1!
2942

2943
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2944
  ASSERT_EQ(code, 0);
1!
2945

2946
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2947
  TAOS_STRCPY(n.dbname, "db1");
1✔
2948
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2949
  STableCfg *pCfg = NULL;
1✔
2950

2951
  code = catalogRefreshGetTableCfg(pCtg, mockPointer, &n, &pCfg);
1!
2952
  ASSERT_EQ(code, 0);
1!
2953
  ASSERT_TRUE(NULL != pCfg);
1!
2954
  ASSERT_EQ(pCfg->numOfColumns, ctgTestColNum);
1!
2955

2956
  tFreeSTableCfgRsp((STableCfgRsp *)pCfg);
1!
2957
  taosMemoryFree(pCfg);
1!
2958

2959
  catalogDestroy();
1!
2960
}
2961

2962
TEST(apiTest, catalogGetTableIndex_test) {
4✔
2963
  struct SCatalog  *pCtg = NULL;
1✔
2964
  SRequestConnInfo  connInfo = {0};
1✔
2965
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
2966

2967
  ctgTestInitLogFile();
1!
2968

2969
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
2970
  ctgTestRspIdx = 0;
1✔
2971
  ctgTestRspFunc[0] = CTGT_RSP_TBLINDEX;
1✔
2972

2973
  ctgTestSetRspByIdx();
1!
2974

2975
  initQueryModuleMsgHandle();
1!
2976

2977
  int32_t code = catalogInit(NULL);
1!
2978
  ASSERT_EQ(code, 0);
1!
2979

2980
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
2981
  ASSERT_EQ(code, 0);
1!
2982

2983
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
2984
  TAOS_STRCPY(n.dbname, "db1");
1✔
2985
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
2986
  SArray *pRes = NULL;
1✔
2987

2988
  code = catalogGetTableIndex(pCtg, mockPointer, &n, &pRes);
1!
2989
  ASSERT_EQ(code, 0);
1!
2990
  ASSERT_TRUE(NULL != pRes);
1!
2991
  ASSERT_EQ(taosArrayGetSize(pRes), ctgTestIndexNum);
1!
2992

2993
  taosArrayDestroyEx(pRes, tFreeSTableIndexInfo);
1!
2994

2995
  catalogDestroy();
1!
2996
}
2997

2998

2999
TEST(apiTest, catalogGetDBCfg_test) {
4✔
3000
  struct SCatalog  *pCtg = NULL;
1✔
3001
  SRequestConnInfo  connInfo = {0};
1✔
3002
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
3003

3004
  ctgTestInitLogFile();
1!
3005

3006
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
3007
  ctgTestRspIdx = 0;
1✔
3008
  ctgTestRspFunc[0] = CTGT_RSP_DBCFG;
1✔
3009

3010
  ctgTestSetRspByIdx();
1!
3011

3012
  initQueryModuleMsgHandle();
1!
3013

3014
  int32_t code = catalogInit(NULL);
1!
3015
  ASSERT_EQ(code, 0);
1!
3016

3017
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
3018
  ASSERT_EQ(code, 0);
1!
3019

3020
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
1✔
3021
  TAOS_STRCPY(n.dbname, "db1");
1✔
3022
  TAOS_STRCPY(n.tname, ctgTestTablename);
1✔
3023

3024
  SDbCfgInfo cfgInfo = {0};
1✔
3025
  code = catalogGetDBCfg(pCtg, mockPointer, ctgTestDbname, &cfgInfo);
1!
3026
  ASSERT_EQ(code, 0);
1!
3027
  ASSERT_EQ(cfgInfo.numOfVgroups, ctgTestVgNum);
1!
3028

3029
  catalogDestroy();
1!
3030
}
3031

3032
TEST(apiTest, catalogGetQnodeList_test) {
4✔
3033
  struct SCatalog  *pCtg = NULL;
1✔
3034
  SRequestConnInfo  connInfo = {0};
1✔
3035
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
3036

3037
  ctgTestInitLogFile();
1!
3038

3039
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
3040
  ctgTestRspIdx = 0;
1✔
3041
  ctgTestRspFunc[0] = CTGT_RSP_QNODELIST;
1✔
3042

3043
  ctgTestSetRspByIdx();
1!
3044

3045
  initQueryModuleMsgHandle();
1!
3046

3047
  int32_t code = catalogInit(NULL);
1!
3048
  ASSERT_EQ(code, 0);
1!
3049

3050
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
3051
  ASSERT_EQ(code, 0);
1!
3052

3053
  SArray *qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
1!
3054
  code = catalogGetQnodeList(pCtg, mockPointer, qnodeList);
1!
3055
  ASSERT_EQ(code, 0);
1!
3056
  ASSERT_EQ(taosArrayGetSize(qnodeList), ctgTestQnodeNum);
1!
3057

3058
  for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
4✔
3059
    SQueryNodeLoad *pLoad = (SQueryNodeLoad *)taosArrayGet(qnodeList, i);
3!
3060
    ASSERT_EQ(pLoad->addr.nodeId, i);
3!
3061
  }
3062

3063
  catalogDestroy();
1!
3064
}
3065

3066
TEST(apiTest, catalogGetUdfInfo_test) {
4✔
3067
  struct SCatalog  *pCtg = NULL;
1✔
3068
  SRequestConnInfo  connInfo = {0};
1✔
3069
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
3070

3071
  ctgTestInitLogFile();
1!
3072

3073
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
3074
  ctgTestRspIdx = 0;
1✔
3075
  ctgTestRspFunc[0] = CTGT_RSP_UDF;
1✔
3076

3077
  ctgTestSetRspByIdx();
1!
3078

3079
  initQueryModuleMsgHandle();
1!
3080

3081
  int32_t code = catalogInit(NULL);
1!
3082
  ASSERT_EQ(code, 0);
1!
3083

3084
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
3085
  ASSERT_EQ(code, 0);
1!
3086

3087
  SFuncInfo funcInfo = {0};
1✔
3088
  code = catalogGetUdfInfo(pCtg, mockPointer, "func1", &funcInfo);
1!
3089
  ASSERT_EQ(code, 0);
1!
3090
  ASSERT_EQ(funcInfo.funcType, ctgTestFuncType);
1!
3091

3092
  catalogDestroy();
1!
3093
}
3094

3095
TEST(apiTest, catalogGetServerVersion_test) {
4✔
3096
  struct SCatalog  *pCtg = NULL;
1✔
3097
  SRequestConnInfo  connInfo = {0};
1✔
3098
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
3099

3100
  ctgTestInitLogFile();
1!
3101

3102
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
3103
  ctgTestRspIdx = 0;
1✔
3104
  ctgTestRspFunc[0] = CTGT_RSP_SVRVER;
1✔
3105

3106
  ctgTestSetRspByIdx();
1!
3107

3108
  initQueryModuleMsgHandle();
1!
3109

3110
  int32_t code = catalogInit(NULL);
1!
3111
  ASSERT_EQ(code, 0);
1!
3112

3113
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
3114
  ASSERT_EQ(code, 0);
1!
3115

3116
  char *ver = NULL;
1✔
3117
  code = catalogGetServerVersion(pCtg, mockPointer, &ver);
1!
3118
  ASSERT_EQ(code, 0);
1!
3119
  ASSERT_TRUE(0 == strcmp(ver, "1.0"));
1!
3120

3121
  catalogDestroy();
1!
3122
}
3123

3124
TEST(apiTest, catalogUpdateTableIndex_test) {
4✔
3125
  struct SCatalog  *pCtg = NULL;
1✔
3126
  SRequestConnInfo  connInfo = {0};
1✔
3127
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
3128

3129
  ctgTestInitLogFile();
1!
3130

3131
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
3132
  ctgTestRspIdx = 0;
1✔
3133
  ctgTestRspFunc[0] = CTGT_RSP_SVRVER;
1✔
3134

3135
  ctgTestSetRspByIdx();
1!
3136

3137
  initQueryModuleMsgHandle();
1!
3138

3139
  int32_t code = catalogInit(NULL);
1!
3140
  ASSERT_EQ(code, 0);
1!
3141

3142
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
3143
  ASSERT_EQ(code, 0);
1!
3144

3145
  STableIndexRsp rsp = {0};
1✔
3146
  TAOS_STRCPY(rsp.dbFName, ctgTestDbname);
1✔
3147
  TAOS_STRCPY(rsp.tbName, ctgTestSTablename);
1✔
3148
  rsp.suid = ctgTestSuid;
1✔
3149
  rsp.version = 1;
1✔
3150
  code = catalogUpdateTableIndex(pCtg, &rsp);
1!
3151
  ASSERT_EQ(code, 0);
1!
3152

3153
  catalogDestroy();
1!
3154
}
3155

3156
TEST(apiTest, catalogGetDnodeList_test) {
4✔
3157
  struct SCatalog  *pCtg = NULL;
1✔
3158
  SRequestConnInfo  connInfo = {0};
1✔
3159
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
1✔
3160

3161
  ctgTestInitLogFile();
1!
3162

3163
  TAOS_MEMSET(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
1✔
3164
  ctgTestRspIdx = 0;
1✔
3165
  ctgTestRspFunc[0] = CTGT_RSP_DNODElIST;
1✔
3166

3167
  ctgTestSetRspByIdx();
1!
3168

3169
  initQueryModuleMsgHandle();
1!
3170

3171
  int32_t code = catalogInit(NULL);
1!
3172
  ASSERT_EQ(code, 0);
1!
3173

3174
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
1!
3175
  ASSERT_EQ(code, 0);
1!
3176

3177
  SArray *pList = NULL;
1✔
3178
  code = catalogGetDnodeList(pCtg, mockPointer, &pList);
1!
3179
  ASSERT_EQ(code, 0);
1!
3180
  ASSERT_EQ(taosArrayGetSize(pList), 1);
1!
3181

3182
  taosArrayDestroy(pList);
1!
3183

3184
  catalogDestroy();
1!
3185
}
3186

3187
#ifdef INTEGRATION_TEST
3188
TEST(intTest, autoCreateTableTest) {
3189
  struct SCatalog *pCtg = NULL;
3190

3191
  TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
3192
  ASSERT_TRUE(NULL != taos);
3193

3194
  (void)ctgdEnableDebug("api", true);
3195
  (void)ctgdEnableDebug("meta", true);
3196
  (void)ctgdEnableDebug("cache", true);
3197
  (void)ctgdEnableDebug("lock", true);
3198

3199
  ctgTestExecQuery(taos, "drop database if exists db1", false, NULL);
3200
  ctgTestExecQuery(taos, "create database db1", false, NULL);
3201
  ctgTestExecQuery(taos, "create stable db1.st1 (ts timestamp, f1 int) tags(tg1 int)", false, NULL);
3202
  ctgTestExecQuery(taos, "insert into db1.tb1 using db1.st1 tags(1) values(now, 1)", false, NULL);
3203

3204
  (void)ctgdGetOneHandle(&pCtg);
3205

3206
  while (true) {
3207
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
3208
    if (2 != n) {
3209
      taosMsleep(50);
3210
    } else {
3211
      break;
3212
    }
3213
  }
3214

3215
  uint64_t n = 0, m = 0;
3216
  ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
3217

3218
  ctgTestExecQuery(taos, "insert into db1.tb1 using db1.st1 tags(1) values(now, 2)", false, NULL);
3219

3220
  ctgTestExecQuery(taos, "insert into db1.tb1 values(now, 3)", false, NULL);
3221

3222
  taosMsleep(1000);
3223
  ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&m);
3224

3225
  ASSERT_EQ(n, m);
3226

3227
  ctgdEnableDebug("stopUpdate", true);
3228
  ctgTestExecQuery(taos, "alter table db1.st1 add column f2 double", false, NULL);
3229

3230
  ctgdEnableDebug("stopUpdate", false);
3231

3232
  ctgTestExecQuery(taos, "insert into db1.tb1 (ts, f1) values(now, 4)", false, NULL);
3233

3234
  taos_close(taos);
3235
}
3236

3237
#endif
3238

3239
int main(int argc, char **argv) {
1✔
3240
  testing::InitGoogleTest(&argc, argv);
1✔
3241
  return RUN_ALL_TESTS();
1✔
3242
}
3243

3244
#pragma GCC diagnostic pop
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc