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) {
46 47 48 49 50 51 52
  tsServerPort = port;
  strcpy(tsLocalFqdn, "localhost");
  snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort);
  strcpy(tsFirst, tsLocalEp);
  strcpy(tsDataDir, path);
  taosRemoveDir(path);
  taosMkDir(path);
53
  InitLog(TD_TMP_DIR_PATH "td");
54 55 56

  server.Start();
  client.Init("root", "taosdata");
57
  showRsp = NULL;
S
Shengliang Guan 已提交
58 59 60
}

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

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

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

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

S
Shengliang Guan 已提交
86
  return client.SendReq(&rpcMsg);
S
Shengliang Guan 已提交
87 88
}

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

S
Shengliang Guan 已提交
95
  SRetrieveTableReq retrieveReq = {0};
96 97
  strcpy(retrieveReq.db, db);
  strcpy(retrieveReq.tb, tb);
S
Shengliang Guan 已提交
98

S
Shengliang Guan 已提交
99 100 101
  int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq);
S
Shengliang Guan 已提交
102

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

106
  if (pRsp->contLen == 0) return -1;
S
Shengliang Guan 已提交
107
  if (pRsp->code != 0) return -1;
S
Shengliang Guan 已提交
108

109 110 111 112 113 114
  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 已提交
115

116
  return 0;
S
Shengliang Guan 已提交
117 118
}

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