提交 ddf55f25 编写于 作者: S Shengliang Guan

refactor: make more object global

上级 1f886b11
...@@ -260,7 +260,7 @@ static void dmWatchNodes(SDnode *pDnode) { ...@@ -260,7 +260,7 @@ static void dmWatchNodes(SDnode *pDnode) {
taosThreadMutexUnlock(&pDnode->mutex); taosThreadMutexUnlock(&pDnode->mutex);
} }
int32_t dnRunDnode(SDnode *pDnode) { int32_t dmRunDnode(SDnode *pDnode) {
if (dmOpenNodes(pDnode) != 0) { if (dmOpenNodes(pDnode) != 0) {
dError("failed to open nodes since %s", terrstr()); dError("failed to open nodes since %s", terrstr());
return -1; return -1;
......
...@@ -24,10 +24,9 @@ class TestServer { ...@@ -24,10 +24,9 @@ class TestServer {
bool DoStart(); bool DoStart();
private: private:
SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); void BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
private: private:
SDnode* pDnode;
TdThread threadId; TdThread threadId;
char path[PATH_MAX]; char path[PATH_MAX];
char fqdn[TSDB_FQDN_LEN]; char fqdn[TSDB_FQDN_LEN];
......
...@@ -16,35 +16,29 @@ ...@@ -16,35 +16,29 @@
#include "sut.h" #include "sut.h"
void* serverLoop(void* param) { void* serverLoop(void* param) {
SDnode* pDnode = (SDnode*)param; dmRun();
dmRun(pDnode);
return NULL; return NULL;
} }
SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { void TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
SDnodeOpt option = {0}; tsNumOfSupportVnodes = 16;
option.numOfSupportVnodes = 16; tsServerPort = port;
option.serverPort = port; strcpy(tsDataDir, path);
strcpy(option.dataDir, path); snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
snprintf(option.localEp, TSDB_EP_LEN, "%s:%u", fqdn, port); snprintf(tsLocalFqdn, TSDB_FQDN_LEN, "%s", fqdn);
snprintf(option.localFqdn, TSDB_FQDN_LEN, "%s", fqdn); snprintf(tsFirst, TSDB_EP_LEN, "%s", firstEp);
snprintf(option.firstEp, TSDB_EP_LEN, "%s", firstEp); taosMkDir(path);
return option;
} }
bool TestServer::DoStart() { bool TestServer::DoStart() {
SDnodeOpt option = BuildOption(path, fqdn, port, firstEp); if (dmInit(0) != 0) {
taosMkDir(path);
pDnode = dmCreate(&option);
if (pDnode == NULL) {
return false; return false;
} }
TdThreadAttr thAttr; TdThreadAttr thAttr;
taosThreadAttrInit(&thAttr); taosThreadAttrInit(&thAttr);
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
taosThreadCreate(&threadId, &thAttr, serverLoop, pDnode); taosThreadCreate(&threadId, &thAttr, serverLoop, NULL);
taosThreadAttrDestroy(&thAttr); taosThreadAttrDestroy(&thAttr);
taosMsleep(2100); taosMsleep(2100);
return true; return true;
...@@ -68,11 +62,7 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const ...@@ -68,11 +62,7 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const
} }
void TestServer::Stop() { void TestServer::Stop() {
dmSetEvent(pDnode, DND_EVENT_STOP); dmStop();
taosThreadJoin(threadId, NULL); taosThreadJoin(threadId, NULL);
dmCleanup();
if (pDnode != NULL) {
dmClose(pDnode);
pDnode = NULL;
}
} }
...@@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) { ...@@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) {
} }
void Testbase::Init(const char* path, int16_t port) { void Testbase::Init(const char* path, int16_t port) {
dmInit(); dmInit(0);
char fqdn[] = "localhost"; char fqdn[] = "localhost";
char firstEp[TSDB_EP_LEN] = {0}; char firstEp[TSDB_EP_LEN] = {0};
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "mndUser.h" #include "mndUser.h"
#include "tcache.h" #include "tcache.h"
void reportStartup(SMgmtWrapper *pWrapper, const char *name, const char *desc) {} void reportStartup(const char *name, const char *desc) {}
class MndTestTrans2 : public ::testing::Test { class MndTestTrans2 : public ::testing::Test {
protected: protected:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册