sut.cpp 3.1 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;
dengyihao's avatar
dengyihao 已提交
33
  tsRpcQueueMemoryAllowed = 1024 * 1024 * 64;
S
Shengliang Guan 已提交
34 35 36

  taosRemoveDir(path);
  taosMkDir(path);
S
os env  
Shengliang Guan 已提交
37
  tstrncpy(tsLogDir, path, PATH_MAX);
S
Shengliang Guan 已提交
38
  if (taosInitLog("taosdlog", 1) != 0) {
S
Shengliang Guan 已提交
39 40 41 42 43
    printf("failed to init log file\n");
  }
}

void Testbase::Init(const char* path, int16_t port) {
44 45 46 47 48 49 50
  tsServerPort = port;
  strcpy(tsLocalFqdn, "localhost");
  snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort);
  strcpy(tsFirst, tsLocalEp);
  strcpy(tsDataDir, path);
  taosRemoveDir(path);
  taosMkDir(path);
51
  InitLog(TD_TMP_DIR_PATH "td");
52 53 54

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

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

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

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

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

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

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

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

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

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

104
  if (pRsp->contLen == 0) return -1;
S
Shengliang Guan 已提交
105

106 107 108 109 110 111
  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 已提交
112

113
  return 0;
S
Shengliang Guan 已提交
114 115
}

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