TDengine/source/dnode/mgmt/impl/test/sut/src/sut.cpp

190 lines
5 KiB
C++
Raw Normal View History

2021-12-22 07:39:32 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-01-04 12:36:54 +00:00
#include "sut.h"
2021-12-22 07:39:32 +00:00
void Testbase::InitLog(const char* path) {
2022-01-07 10:30:20 +00:00
dDebugFlag = 143;
2021-12-22 07:39:32 +00:00
vDebugFlag = 0;
2022-01-04 09:17:25 +00:00
mDebugFlag = 143;
2021-12-22 07:39:32 +00:00
cDebugFlag = 0;
jniDebugFlag = 0;
tmrDebugFlag = 0;
2022-01-04 09:17:25 +00:00
uDebugFlag = 0;
2021-12-22 07:39:32 +00:00
rpcDebugFlag = 0;
qDebugFlag = 0;
wDebugFlag = 0;
sDebugFlag = 0;
tsdbDebugFlag = 0;
cqDebugFlag = 0;
tscEmbeddedInUtil = 1;
2021-12-27 09:14:20 +00:00
tsAsyncLog = 0;
2021-12-22 07:39:32 +00:00
taosRemoveDir(path);
taosMkDir(path);
char temp[PATH_MAX];
snprintf(temp, PATH_MAX, "%s/taosdlog", path);
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
printf("failed to init log file\n");
}
}
void Testbase::Init(const char* path, int16_t port) {
2022-01-12 02:46:52 +00:00
SDnodeEnvCfg cfg = {0};
2022-01-12 03:44:42 +00:00
cfg.numOfCommitThreads = 1;
2022-01-12 03:52:02 +00:00
cfg.numOfCores = 1;
2022-01-12 02:46:52 +00:00
dndInit(&cfg);
2021-12-22 07:39:32 +00:00
char fqdn[] = "localhost";
char firstEp[TSDB_EP_LEN] = {0};
snprintf(firstEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
2021-12-27 09:14:20 +00:00
InitLog("/tmp/td");
2021-12-22 07:39:32 +00:00
server.Start(path, fqdn, port, firstEp);
client.Init("root", "taosdata", fqdn, port);
taosMsleep(1100);
}
void Testbase::Cleanup() {
server.Stop();
client.Cleanup();
2022-01-12 02:46:52 +00:00
dndCleanup();
2021-12-22 07:39:32 +00:00
}
2021-12-22 08:38:20 +00:00
void Testbase::Restart() { server.Restart(); }
2022-01-04 09:17:25 +00:00
void Testbase::ServerStop() { server.Stop(); }
void Testbase::ServerStart() { server.DoStart(); }
2022-01-05 12:18:56 +00:00
SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) {
2021-12-22 07:39:32 +00:00
SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pCont;
2021-12-22 08:38:20 +00:00
rpcMsg.contLen = contLen;
2021-12-22 07:39:32 +00:00
rpcMsg.msgType = msgType;
2022-01-05 12:18:56 +00:00
return client.SendReq(&rpcMsg);
2021-12-22 07:39:32 +00:00
}
2022-01-05 12:18:56 +00:00
void Testbase::SendShowMetaReq(int8_t showType, const char* db) {
int32_t contLen = sizeof(SShowReq);
SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen);
2021-12-22 07:39:32 +00:00
pShow->type = showType;
2021-12-22 08:38:20 +00:00
strcpy(pShow->db, db);
2021-12-22 07:39:32 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen);
SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont;
2021-12-22 07:39:32 +00:00
ASSERT(pShowRsp != nullptr);
2021-12-31 02:52:10 +00:00
pShowRsp->showId = htobe64(pShowRsp->showId);
2021-12-22 07:39:32 +00:00
pMeta = &pShowRsp->tableMeta;
pMeta->numOfTags = htonl(pMeta->numOfTags);
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
pMeta->sversion = htonl(pMeta->sversion);
pMeta->tversion = htonl(pMeta->tversion);
pMeta->tuid = htobe64(pMeta->tuid);
pMeta->suid = htobe64(pMeta->suid);
showId = pShowRsp->showId;
}
int32_t Testbase::GetMetaColId(int32_t index) {
SSchema* pSchema = &pMeta->pSchema[index];
pSchema->colId = htonl(pSchema->colId);
return pSchema->colId;
}
int8_t Testbase::GetMetaType(int32_t index) {
SSchema* pSchema = &pMeta->pSchema[index];
return pSchema->type;
}
int32_t Testbase::GetMetaBytes(int32_t index) {
SSchema* pSchema = &pMeta->pSchema[index];
pSchema->bytes = htonl(pSchema->bytes);
return pSchema->bytes;
}
const char* Testbase::GetMetaName(int32_t index) {
SSchema* pSchema = &pMeta->pSchema[index];
return pSchema->name;
}
int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; }
2022-02-11 07:50:20 +00:00
const char* Testbase::GetMetaTbName() { return pMeta->tbName; }
2021-12-22 07:39:32 +00:00
2022-01-05 12:18:56 +00:00
void Testbase::SendShowRetrieveReq() {
int32_t contLen = sizeof(SRetrieveTableReq);
2021-12-22 07:39:32 +00:00
2022-01-05 12:18:56 +00:00
SRetrieveTableReq* pRetrieve = (SRetrieveTableReq*)rpcMallocCont(contLen);
2021-12-31 02:52:10 +00:00
pRetrieve->showId = htobe64(showId);
2021-12-22 07:39:32 +00:00
pRetrieve->free = 0;
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen);
pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont;
2021-12-22 08:38:20 +00:00
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
2021-12-22 07:39:32 +00:00
pData = pRetrieveRsp->data;
pos = 0;
}
2022-02-11 07:50:20 +00:00
const char* Testbase::GetShowName() { return pMeta->tbName; }
2021-12-22 07:39:32 +00:00
int8_t Testbase::GetShowInt8() {
int8_t data = *((int8_t*)(pData + pos));
pos += sizeof(int8_t);
return data;
}
int16_t Testbase::GetShowInt16() {
int16_t data = *((int16_t*)(pData + pos));
pos += sizeof(int16_t);
return data;
}
int32_t Testbase::GetShowInt32() {
int32_t data = *((int32_t*)(pData + pos));
pos += sizeof(int32_t);
return data;
}
int64_t Testbase::GetShowInt64() {
int64_t data = *((int64_t*)(pData + pos));
pos += sizeof(int64_t);
return data;
}
int64_t Testbase::GetShowTimestamp() {
int64_t data = *((int64_t*)(pData + pos));
pos += sizeof(int64_t);
return data;
}
const char* Testbase::GetShowBinary(int32_t len) {
pos += sizeof(VarDataLenT);
char* data = (char*)(pData + pos);
pos += len;
return data;
2021-12-22 08:38:20 +00:00
}
int32_t Testbase::GetShowRows() { return pRetrieveRsp->numOfRows; }
2022-01-10 12:44:11 +00:00
STableMetaRsp* Testbase::GetShowMeta() { return pMeta; }
2021-12-22 08:38:20 +00:00
SRetrieveTableRsp* Testbase::GetRetrieveRsp() { return pRetrieveRsp; }