sut.cpp 3.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16
#include "sut.h"
S
Shengliang Guan 已提交
17 18

void Testbase::InitLog(const char* path) {
S
Shengliang Guan 已提交
19
  dDebugFlag = 143;
S
Shengliang Guan 已提交
20
  vDebugFlag = 0;
S
Shengliang Guan 已提交
21
  mDebugFlag = 143;
S
Shengliang Guan 已提交
22 23
  cDebugFlag = 0;
  jniDebugFlag = 0;
S
shm  
Shengliang Guan 已提交
24 25
  tmrDebugFlag = 135;
  uDebugFlag = 135;
S
shm  
Shengliang Guan 已提交
26
  rpcDebugFlag = 143;
S
Shengliang Guan 已提交
27 28 29 30
  qDebugFlag = 0;
  wDebugFlag = 0;
  sDebugFlag = 0;
  tsdbDebugFlag = 0;
S
Shengliang Guan 已提交
31
  tsLogEmbedded = 1;
S
Shengliang Guan 已提交
32
  tsAsyncLog = 0;
33
  
S
Shengliang Guan 已提交
34 35
  taosRemoveDir(path);
  taosMkDir(path);
S
os env  
Shengliang Guan 已提交
36
  tstrncpy(tsLogDir, path, PATH_MAX);
37 38 39 40

  taosGetSystemInfo();
  tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 0.1;
if (taosInitLog("taosdlog", 1) != 0) {
S
Shengliang Guan 已提交
41 42 43 44 45
    printf("failed to init log file\n");
  }
}

void Testbase::Init(const char* path, int16_t port) {
wafwerar's avatar
wafwerar 已提交
46 47 48
#ifdef _TD_DARWIN_64
  osDefaultInit();
#endif
49 50 51 52 53 54 55
  tsServerPort = port;
  strcpy(tsLocalFqdn, "localhost");
  snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort);
  strcpy(tsFirst, tsLocalEp);
  strcpy(tsDataDir, path);
  taosRemoveDir(path);
  taosMkDir(path);
56
  InitLog(TD_TMP_DIR_PATH "td");
57 58 59

  server.Start();
  client.Init("root", "taosdata");
60
  showRsp = NULL;
S
Shengliang Guan 已提交
61 62 63
}

void Testbase::Cleanup() {
64 65 66 67
  if (showRsp != NULL) {
    rpcFreeCont(showRsp);
    showRsp = NULL;
  }
S
Shengliang Guan 已提交
68
  client.Cleanup();
dengyihao's avatar
fix bug  
dengyihao 已提交
69 70
  taosMsleep(10);
  server.Stop();
S
Shengliang Guan 已提交
71
  dmCleanup();
S
Shengliang Guan 已提交
72 73
}

dengyihao's avatar
fix bug  
dengyihao 已提交
74
void Testbase::Restart() {
75
  // server.Restart();
dengyihao's avatar
fix bug  
dengyihao 已提交
76 77
  client.Restart();
}
S
Shengliang Guan 已提交
78

S
Shengliang Guan 已提交
79
void Testbase::ServerStop() { server.Stop(); }
80
void Testbase::ServerStart() { server.Start(); }
dengyihao's avatar
fix bug  
dengyihao 已提交
81
void Testbase::ClientRestart() { client.Restart(); }
S
Shengliang Guan 已提交
82

S
Shengliang Guan 已提交
83
SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) {
S
Shengliang Guan 已提交
84 85
  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pCont;
S
Shengliang Guan 已提交
86
  rpcMsg.contLen = contLen;
S
Shengliang Guan 已提交
87 88
  rpcMsg.msgType = msgType;

S
Shengliang Guan 已提交
89
  return client.SendReq(&rpcMsg);
S
Shengliang Guan 已提交
90 91
}

dengyihao's avatar
dengyihao 已提交
92
int32_t Testbase::SendShowReq(int8_t showType, const char* tb, const char* db) {
93 94 95 96
  if (showRsp != NULL) {
    rpcFreeCont(showRsp);
    showRsp = NULL;
  }
S
Shengliang Guan 已提交
97

S
Shengliang Guan 已提交
98
  SRetrieveTableReq retrieveReq = {0};
99 100
  strcpy(retrieveReq.db, db);
  strcpy(retrieveReq.tb, tb);
S
Shengliang Guan 已提交
101

S
Shengliang Guan 已提交
102 103 104
  int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq);
S
Shengliang Guan 已提交
105

106 107
  SRpcMsg* pRsp = SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen);
  ASSERT(pRsp->pCont != nullptr);
S
Shengliang Guan 已提交
108

109
  if (pRsp->contLen == 0) return -1;
S
Shengliang Guan 已提交
110
  if (pRsp->code != 0) return -1;
S
Shengliang Guan 已提交
111

112 113 114 115 116 117
  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;
S
Shengliang Guan 已提交
118

119
  return 0;
S
Shengliang Guan 已提交
120 121
}

122 123 124 125 126 127
int32_t Testbase::GetShowRows() {
  if (showRsp != NULL) {
    return showRsp->numOfRows;
  } else {
    return 0;
  }
S
Shengliang Guan 已提交
128
}