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

89 lines
2.6 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"
2022-02-20 16:11:35 +00:00
#include "tep.h"
2021-12-22 07:39:32 +00:00
2022-01-05 12:18:56 +00:00
static void processClientRsp(void* parent, SRpcMsg* pRsp, SEpSet* pEpSet) {
2021-12-22 07:39:32 +00:00
TestClient* client = (TestClient*)parent;
2022-01-05 12:18:56 +00:00
client->SetRpcRsp(pRsp);
2022-02-20 16:11:35 +00:00
uInfo("x response:%s from dnode, code:0x%x, msgSize: %d", TMSG_INFO(pRsp->msgType), pRsp->code, pRsp->contLen);
2021-12-22 07:39:32 +00:00
tsem_post(client->GetSem());
}
2022-02-20 16:11:35 +00:00
void TestClient::SetRpcRsp(SRpcMsg* rsp) {
2022-02-22 04:51:34 +00:00
if (this->pRsp) {
free(this->pRsp);
}
2022-02-20 16:11:35 +00:00
this->pRsp = (SRpcMsg*)calloc(1, sizeof(SRpcMsg));
this->pRsp->msgType = rsp->msgType;
this->pRsp->code = rsp->code;
this->pRsp->pCont = rsp->pCont;
this->pRsp->contLen = rsp->contLen;
};
2021-12-22 07:39:32 +00:00
tsem_t* TestClient::GetSem() { return &sem; }
2022-02-20 16:11:35 +00:00
void TestClient::DoInit() {
2022-01-23 11:50:18 +00:00
char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0};
taosEncryptPass_c((uint8_t*)pass, strlen(pass), secretEncrypt);
2021-12-22 07:39:32 +00:00
SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit));
2022-02-20 16:11:35 +00:00
rpcInit.label = (char*)"shell";
2021-12-22 07:39:32 +00:00
rpcInit.numOfThreads = 1;
rpcInit.cfp = processClientRsp;
rpcInit.sessions = 1024;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.idleTime = 30 * 1000;
2022-02-20 16:11:35 +00:00
rpcInit.user = (char*)this->user;
2021-12-22 07:39:32 +00:00
rpcInit.ckey = (char*)"key";
rpcInit.parent = this;
rpcInit.secret = (char*)secretEncrypt;
2022-01-23 11:50:18 +00:00
rpcInit.spi = 1;
2021-12-22 07:39:32 +00:00
clientRpc = rpcOpen(&rpcInit);
ASSERT(clientRpc);
2022-02-20 16:11:35 +00:00
tsem_init(&this->sem, 0, 0);
}
2021-12-22 07:39:32 +00:00
2022-02-20 16:11:35 +00:00
bool TestClient::Init(const char* user, const char* pass, const char* fqdn, uint16_t port) {
2021-12-22 07:39:32 +00:00
strcpy(this->fqdn, fqdn);
2022-02-20 16:11:35 +00:00
strcpy(this->user, user);
strcpy(this->pass, pass);
2021-12-22 07:39:32 +00:00
this->port = port;
2022-02-22 04:51:34 +00:00
this->pRsp = NULL;
2022-02-20 16:11:35 +00:00
this->DoInit();
2021-12-22 07:39:32 +00:00
return true;
}
void TestClient::Cleanup() {
tsem_destroy(&sem);
rpcClose(clientRpc);
}
2022-02-20 16:11:35 +00:00
void TestClient::Restart() {
this->Cleanup();
this->DoInit();
}
2022-01-05 12:18:56 +00:00
SRpcMsg* TestClient::SendReq(SRpcMsg* pReq) {
2021-12-22 07:39:32 +00:00
SEpSet epSet = {0};
2022-01-26 06:00:15 +00:00
addEpIntoEpSet(&epSet, fqdn, port);
2022-01-05 12:18:56 +00:00
rpcSendRequest(clientRpc, &epSet, pReq, NULL);
2021-12-22 07:39:32 +00:00
tsem_wait(&sem);
2022-02-20 16:11:35 +00:00
uInfo("y response:%s from dnode, code:0x%x, msgSize: %d", TMSG_INFO(pRsp->msgType), pRsp->code, pRsp->contLen);
2021-12-22 07:39:32 +00:00
return pRsp;
}