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;
|
2022-03-18 10:30:12 +00:00
|
|
|
tmrDebugFlag = 135;
|
|
|
|
|
uDebugFlag = 135;
|
2022-03-19 16:25:37 +00:00
|
|
|
rpcDebugFlag = 143;
|
2021-12-22 07:39:32 +00:00
|
|
|
qDebugFlag = 0;
|
|
|
|
|
wDebugFlag = 0;
|
|
|
|
|
sDebugFlag = 0;
|
|
|
|
|
tsdbDebugFlag = 0;
|
2022-03-04 05:53:50 +00:00
|
|
|
tsLogEmbedded = 1;
|
2021-12-27 09:14:20 +00:00
|
|
|
tsAsyncLog = 0;
|
2022-10-13 03:56:16 +00:00
|
|
|
|
2021-12-22 07:39:32 +00:00
|
|
|
taosRemoveDir(path);
|
|
|
|
|
taosMkDir(path);
|
2022-02-24 13:27:13 +00:00
|
|
|
tstrncpy(tsLogDir, path, PATH_MAX);
|
2022-07-04 11:03:10 +00:00
|
|
|
|
|
|
|
|
taosGetSystemInfo();
|
2025-01-21 03:33:08 +00:00
|
|
|
tsQueueMemoryAllowed = tsTotalMemoryKB * 0.06;
|
|
|
|
|
tsApplyMemoryAllowed = tsTotalMemoryKB * 0.04;
|
2024-08-02 08:29:48 +00:00
|
|
|
if (taosInitLog("taosdlog", 1, false) != 0) {
|
2021-12-22 07:39:32 +00:00
|
|
|
printf("failed to init log file\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Testbase::Init(const char* path, int16_t port) {
|
2022-07-06 12:47:38 +00:00
|
|
|
osDefaultInit();
|
2022-05-17 08:01:06 +00:00
|
|
|
tsServerPort = port;
|
|
|
|
|
strcpy(tsLocalFqdn, "localhost");
|
|
|
|
|
snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort);
|
|
|
|
|
strcpy(tsFirst, tsLocalEp);
|
|
|
|
|
strcpy(tsDataDir, path);
|
|
|
|
|
taosRemoveDir(path);
|
|
|
|
|
taosMkDir(path);
|
2022-05-21 15:47:39 +00:00
|
|
|
InitLog(TD_TMP_DIR_PATH "td");
|
2022-05-17 08:01:06 +00:00
|
|
|
|
2022-10-28 07:24:32 +00:00
|
|
|
if (!server.Start()) {
|
|
|
|
|
printf("failed to start server, exit\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
};
|
2022-05-17 08:01:06 +00:00
|
|
|
client.Init("root", "taosdata");
|
2022-04-14 12:54:43 +00:00
|
|
|
showRsp = NULL;
|
2021-12-22 07:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Testbase::Cleanup() {
|
2022-04-14 12:54:43 +00:00
|
|
|
if (showRsp != NULL) {
|
|
|
|
|
rpcFreeCont(showRsp);
|
|
|
|
|
showRsp = NULL;
|
|
|
|
|
}
|
2021-12-22 07:39:32 +00:00
|
|
|
client.Cleanup();
|
2022-02-20 16:11:35 +00:00
|
|
|
taosMsleep(10);
|
|
|
|
|
server.Stop();
|
2022-04-13 06:00:56 +00:00
|
|
|
dmCleanup();
|
2021-12-22 07:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-20 16:11:35 +00:00
|
|
|
void Testbase::Restart() {
|
2022-05-17 08:01:06 +00:00
|
|
|
// server.Restart();
|
2022-02-20 16:11:35 +00:00
|
|
|
client.Restart();
|
|
|
|
|
}
|
2021-12-22 08:38:20 +00:00
|
|
|
|
2022-01-04 09:17:25 +00:00
|
|
|
void Testbase::ServerStop() { server.Stop(); }
|
2022-05-17 08:01:06 +00:00
|
|
|
void Testbase::ServerStart() { server.Start(); }
|
2022-02-20 16:11:35 +00:00
|
|
|
void Testbase::ClientRestart() { client.Restart(); }
|
2022-01-04 09:17:25 +00:00
|
|
|
|
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-05-17 03:33:18 +00:00
|
|
|
int32_t Testbase::SendShowReq(int8_t showType, const char* tb, const char* db) {
|
2022-04-14 12:54:43 +00:00
|
|
|
if (showRsp != NULL) {
|
|
|
|
|
rpcFreeCont(showRsp);
|
|
|
|
|
showRsp = NULL;
|
|
|
|
|
}
|
2021-12-22 07:39:32 +00:00
|
|
|
|
2022-02-14 13:00:39 +00:00
|
|
|
SRetrieveTableReq retrieveReq = {0};
|
2022-04-14 12:54:43 +00:00
|
|
|
strcpy(retrieveReq.db, db);
|
|
|
|
|
strcpy(retrieveReq.tb, tb);
|
2021-12-22 07:39:32 +00:00
|
|
|
|
2022-02-14 13:00:39 +00:00
|
|
|
int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq);
|
|
|
|
|
void* pReq = rpcMallocCont(contLen);
|
|
|
|
|
tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq);
|
2021-12-22 07:39:32 +00:00
|
|
|
|
2022-04-14 12:54:43 +00:00
|
|
|
SRpcMsg* pRsp = SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen);
|
2022-12-07 13:51:17 +00:00
|
|
|
ASSERT(pRsp->pCont != nullptr);
|
2021-12-22 07:39:32 +00:00
|
|
|
|
2022-04-14 12:54:43 +00:00
|
|
|
if (pRsp->contLen == 0) return -1;
|
2022-06-21 08:18:01 +00:00
|
|
|
if (pRsp->code != 0) return -1;
|
2021-12-22 07:39:32 +00:00
|
|
|
|
2022-04-14 12:54:43 +00:00
|
|
|
showRsp = (SRetrieveMetaTableRsp*)pRsp->pCont;
|
|
|
|
|
showRsp->handle = htobe64(showRsp->handle); // show Id
|
|
|
|
|
showRsp->useconds = htobe64(showRsp->useconds);
|
|
|
|
|
showRsp->numOfRows = htonl(showRsp->numOfRows);
|
|
|
|
|
showRsp->compLen = htonl(showRsp->compLen);
|
|
|
|
|
if (showRsp->numOfRows <= 0) return -1;
|
2021-12-22 07:39:32 +00:00
|
|
|
|
2022-04-14 12:54:43 +00:00
|
|
|
return 0;
|
2021-12-22 07:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 12:54:43 +00:00
|
|
|
int32_t Testbase::GetShowRows() {
|
|
|
|
|
if (showRsp != NULL) {
|
|
|
|
|
return showRsp->numOfRows;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-12-22 08:38:20 +00:00
|
|
|
}
|