Merge pull request #17731 from taosdata/fix/TD-19815
fix: add more ut cases and fix issues
This commit is contained in:
commit
ffdfd39c5e
|
@ -203,6 +203,14 @@ int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg);
|
|||
|
||||
int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg);
|
||||
|
||||
int32_t catalogGetCachedTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
|
||||
STableMeta** pTableMeta);
|
||||
|
||||
int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
|
||||
SVgroupInfo* pVgroup, bool* exists);
|
||||
|
||||
/**
|
||||
* Force refresh DB's local cached vgroup info.
|
||||
* @param pCtg (input, got with catalogGetHandle)
|
||||
|
|
|
@ -56,6 +56,13 @@ enum {
|
|||
CTGT_RSP_STBMETA,
|
||||
CTGT_RSP_MSTBMETA,
|
||||
CTGT_RSP_INDEXINFO_E,
|
||||
CTGT_RSP_USERAUTH,
|
||||
CTGT_RSP_TBLCFG,
|
||||
CTGT_RSP_TBLINDEX,
|
||||
CTGT_RSP_DBCFG,
|
||||
CTGT_RSP_QNODELIST,
|
||||
CTGT_RSP_UDF,
|
||||
CTGT_RSP_SVRVER,
|
||||
CTGT_RSP_TBMETA_NOT_EXIST,
|
||||
};
|
||||
|
||||
|
@ -71,6 +78,10 @@ int32_t ctgTestVgVersion = 1;
|
|||
int32_t ctgTestVgNum = 10;
|
||||
int32_t ctgTestColNum = 2;
|
||||
int32_t ctgTestTagNum = 1;
|
||||
int32_t ctgTestQnodeNum = 3;
|
||||
int32_t ctgTestIndexNum = 3;
|
||||
int32_t ctgTestFuncNum = 2;
|
||||
int32_t ctgTestFuncType = 3;
|
||||
int32_t ctgTestSVersion = 1;
|
||||
int32_t ctgTestTVersion = 1;
|
||||
int32_t ctgTestSuid = 2;
|
||||
|
@ -82,6 +93,7 @@ char *ctgTestDbname = "1.db1";
|
|||
char *ctgTestTablename = "table1";
|
||||
char *ctgTestCTablename = "ctable1";
|
||||
char *ctgTestSTablename = "stable1";
|
||||
char *ctgTestUsername = "user1";
|
||||
char *ctgTestCurrentCTableName = NULL;
|
||||
char *ctgTestCurrentTableName = NULL;
|
||||
char *ctgTestCurrentSTableName = NULL;
|
||||
|
@ -311,6 +323,7 @@ void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
|
|||
strcpy(addr->fqdn, "a0");
|
||||
addr->port = n + 22;
|
||||
}
|
||||
vg.numOfTable = i % 2;
|
||||
|
||||
taosArrayPush(usedbRsp.pVgroupInfos, &vg);
|
||||
}
|
||||
|
@ -531,6 +544,197 @@ void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMs
|
|||
}
|
||||
|
||||
|
||||
void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
SGetUserAuthRsp userRsp = {0};
|
||||
strcpy(userRsp.user, ctgTestUsername);
|
||||
userRsp.version = 1;
|
||||
userRsp.superAuth = 1;
|
||||
|
||||
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSGetUserAuthRsp(pReq, contLen, &userRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = contLen;
|
||||
pRsp->pCont = pReq;
|
||||
}
|
||||
|
||||
void ctgTestRspTableCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
STableCfgRsp tblRsp = {0};
|
||||
strcpy(tblRsp.tbName, ctgTestTablename);
|
||||
tblRsp.numOfColumns = ctgTestColNum;
|
||||
|
||||
tblRsp.pSchemas = (SSchema *)taosMemoryMalloc((tblRsp.numOfTags + tblRsp.numOfColumns) * sizeof(SSchema));
|
||||
|
||||
SSchema *s = NULL;
|
||||
s = &tblRsp.pSchemas[0];
|
||||
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
s->colId = 1;
|
||||
s->bytes = 8;
|
||||
strcpy(s->name, "ts");
|
||||
|
||||
s = &tblRsp.pSchemas[1];
|
||||
s->type = TSDB_DATA_TYPE_INT;
|
||||
s->colId = 2;
|
||||
s->bytes = 4;
|
||||
strcpy(s->name, "col1");
|
||||
|
||||
int32_t contLen = tSerializeSTableCfgRsp(NULL, 0, &tblRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSTableCfgRsp(pReq, contLen, &tblRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = contLen;
|
||||
pRsp->pCont = pReq;
|
||||
|
||||
tFreeSTableCfgRsp(&tblRsp);
|
||||
}
|
||||
|
||||
void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
STableIndexRsp tblRsp = {0};
|
||||
strcpy(tblRsp.tbName, ctgTestSTablename);
|
||||
|
||||
tblRsp.pIndex = taosArrayInit(ctgTestIndexNum, sizeof(STableIndexInfo));
|
||||
|
||||
STableIndexInfo info = {0};
|
||||
for (int32_t i = 0; i < ctgTestIndexNum; ++i) {
|
||||
info.interval = 1 + i;
|
||||
info.expr = (char*)taosMemoryCalloc(1, 10);
|
||||
taosArrayPush(tblRsp.pIndex, &info);
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &tblRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSTableIndexRsp(pReq, contLen, &tblRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = contLen;
|
||||
pRsp->pCont = pReq;
|
||||
|
||||
tFreeSTableIndexRsp(&tblRsp);
|
||||
}
|
||||
|
||||
void ctgTestRspDBCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
SDbCfgRsp dbRsp = {0};
|
||||
dbRsp.numOfVgroups = ctgTestVgNum;
|
||||
|
||||
int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &dbRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSDbCfgRsp(pReq, contLen, &dbRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = contLen;
|
||||
pRsp->pCont = pReq;
|
||||
}
|
||||
|
||||
void ctgTestRspQnodeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
SQnodeListRsp qlistRsp = {0};
|
||||
qlistRsp.qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
|
||||
for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
|
||||
SQueryNodeLoad nodeLoad = {0};
|
||||
nodeLoad.addr.nodeId = i;
|
||||
|
||||
(void)taosArrayPush(qlistRsp.qnodeList, &nodeLoad);
|
||||
}
|
||||
|
||||
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
||||
void *pReq = rpcMallocCont(rspLen);
|
||||
tSerializeSQnodeListRsp(pReq, rspLen, &qlistRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = rspLen;
|
||||
pRsp->pCont = pReq;
|
||||
|
||||
tFreeSQnodeListRsp(&qlistRsp);
|
||||
}
|
||||
|
||||
void ctgTestRspUdfInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
SRetrieveFuncRsp funcRsp = {0};
|
||||
funcRsp.numOfFuncs = 1;
|
||||
funcRsp.pFuncInfos = taosArrayInit(1, sizeof(SFuncInfo));
|
||||
SFuncInfo funcInfo = {0};
|
||||
strcpy(funcInfo.name, "func1");
|
||||
funcInfo.funcType = ctgTestFuncType;
|
||||
|
||||
(void)taosArrayPush(funcRsp.pFuncInfos, &funcInfo);
|
||||
|
||||
int32_t rspLen = tSerializeSRetrieveFuncRsp(NULL, 0, &funcRsp);
|
||||
void *pReq = rpcMallocCont(rspLen);
|
||||
tSerializeSRetrieveFuncRsp(pReq, rspLen, &funcRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = rspLen;
|
||||
pRsp->pCont = pReq;
|
||||
|
||||
tFreeSRetrieveFuncRsp(&funcRsp);
|
||||
}
|
||||
|
||||
void ctgTestRspSvrVer(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
SServerVerRsp verRsp = {0};
|
||||
strcpy(verRsp.ver, "1.0");
|
||||
|
||||
int32_t rspLen = tSerializeSServerVerRsp(NULL, 0, &verRsp);
|
||||
void *pReq = rpcMallocCont(rspLen);
|
||||
tSerializeSServerVerRsp(pReq, rspLen, &verRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = rspLen;
|
||||
pRsp->pCont = pReq;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_MND_USE_DB:
|
||||
ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_VND_TABLE_CFG:
|
||||
case TDMT_MND_TABLE_CFG:
|
||||
ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_GET_TABLE_INDEX:
|
||||
ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_GET_DB_CFG:
|
||||
ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_QNODE_LIST:
|
||||
ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_RETRIEVE_FUNC:
|
||||
ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_SERVER_VERSION:
|
||||
ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
switch (ctgTestRspFunc[ctgTestRspIdx]) {
|
||||
case CTGT_RSP_VGINFO:
|
||||
|
@ -551,10 +755,32 @@ void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp
|
|||
case CTGT_RSP_INDEXINFO_E:
|
||||
ctgTestRspErrIndexInfo(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_USERAUTH:
|
||||
ctgTestRspUserAuth(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_TBLCFG:
|
||||
ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_TBMETA_NOT_EXIST:
|
||||
ctgTestRspTableMetaNotExist(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_TBLINDEX:
|
||||
ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_DBCFG:
|
||||
ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_QNODELIST:
|
||||
ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_UDF:
|
||||
ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_SVRVER:
|
||||
ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
default:
|
||||
ctgTestRspAuto(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -976,9 +1202,23 @@ TEST(tableMeta, normalTable) {
|
|||
ASSERT_EQ(vgInfo.vgId, 8);
|
||||
ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
|
||||
|
||||
while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n != 1) {
|
||||
taosMsleep(50);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&vgInfo, 0, sizeof(vgInfo));
|
||||
bool exists = false;
|
||||
code = catalogGetCachedTableHashVgroup(pCtg, mockPointer, &n, &vgInfo, &exists);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(vgInfo.vgId, 8);
|
||||
ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
|
||||
ASSERT_EQ(exists, true);
|
||||
|
||||
ctgTestSetRspTableMeta();
|
||||
|
||||
|
@ -1020,6 +1260,18 @@ TEST(tableMeta, normalTable) {
|
|||
|
||||
taosMemoryFree(tableMeta);
|
||||
|
||||
tableMeta = NULL;
|
||||
catalogGetCachedTableMeta(pCtg, mockPointer, &n, &tableMeta);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(tableMeta->vgId, 8);
|
||||
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
|
||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||
|
||||
SDbVgVersion *dbs = NULL;
|
||||
SSTableVersion *stb = NULL;
|
||||
uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
|
||||
|
@ -1216,6 +1468,21 @@ TEST(tableMeta, superTableCase) {
|
|||
}
|
||||
}
|
||||
|
||||
tableMeta = NULL;
|
||||
code = catalogGetCachedSTableMeta(pCtg, mockPointer, &n, &tableMeta);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(tableMeta->vgId, 0);
|
||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid);
|
||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||
taosMemoryFree(tableMeta);
|
||||
|
||||
ctgTestSetRspCTableMeta();
|
||||
|
||||
tableMeta = NULL;
|
||||
|
@ -2156,6 +2423,15 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
|||
code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
|
||||
ASSERT_TRUE(code != 0);
|
||||
|
||||
int32_t dbVer = 0;
|
||||
int64_t dbId = 0;
|
||||
int32_t tbNum = 0;
|
||||
code = catalogGetDBVgVersion(pCtg, ctgTestDbname, &dbVer, &dbId, &tbNum);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(dbVer, ctgTestVgVersion);
|
||||
ASSERT_EQ(dbId, ctgTestDbId);
|
||||
ASSERT_EQ(tbNum, ctgTestVgNum / 2);
|
||||
|
||||
ctgTestBuildDBVgroup(&dbVgroup);
|
||||
code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -2415,6 +2691,264 @@ TEST(rentTest, allRent) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogRefreshDBVgInfo_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogRefreshDBVgInfo(pCtg, mockPointer, ctgTestDbname);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogChkAuth_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_USERAUTH;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
bool pass = false;
|
||||
code = catalogChkAuth(pCtg, mockPointer, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(pass, true);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogRefreshGetTableCfg_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||
ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
|
||||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
STableCfg *pCfg = NULL;
|
||||
|
||||
code = catalogRefreshGetTableCfg(pCtg, mockPointer, &n, &pCfg);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(NULL != pCfg);
|
||||
ASSERT_EQ(pCfg->numOfColumns, ctgTestColNum);
|
||||
|
||||
tFreeSTableCfgRsp((STableCfgRsp *)pCfg);
|
||||
taosMemoryFree(pCfg);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogGetTableIndex_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_TBLINDEX;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
|
||||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
SArray *pRes = NULL;
|
||||
|
||||
code = catalogGetTableIndex(pCtg, mockPointer, &n, &pRes);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(NULL != pRes);
|
||||
ASSERT_EQ(taosArrayGetSize(pRes), ctgTestIndexNum);
|
||||
|
||||
taosArrayDestroyEx(pRes, tFreeSTableIndexInfo);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogGetDBCfg_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_DBCFG;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
|
||||
strcpy(n.dbname, "db1");
|
||||
strcpy(n.tname, ctgTestTablename);
|
||||
|
||||
SDbCfgInfo cfgInfo = {0};
|
||||
code = catalogGetDBCfg(pCtg, mockPointer, ctgTestDbname, &cfgInfo);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(cfgInfo.numOfVgroups, ctgTestVgNum);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogGetQnodeList_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_QNODELIST;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SArray *qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
|
||||
code = catalogGetQnodeList(pCtg, mockPointer, qnodeList);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(qnodeList), ctgTestQnodeNum);
|
||||
|
||||
for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
|
||||
SQueryNodeLoad * pLoad = (SQueryNodeLoad *)taosArrayGet(qnodeList, i);
|
||||
ASSERT_EQ(pLoad->addr.nodeId, i);
|
||||
}
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
TEST(apiTest, catalogGetUdfInfo_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_UDF;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SFuncInfo funcInfo = {0};
|
||||
code = catalogGetUdfInfo(pCtg, mockPointer, "func1", &funcInfo);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(funcInfo.funcType, ctgTestFuncType);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
TEST(apiTest, catalogGetServerVersion_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_SVRVER;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
char* ver = NULL;
|
||||
code = catalogGetServerVersion(pCtg, mockPointer, &ver);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(0 == strcmp(ver, "1.0"));
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
|
Loading…
Reference in New Issue