sut.cpp 3.0 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;
S
Shengliang Guan 已提交
33 34 35

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

void Testbase::Init(const char* path, int16_t port) {
S
Shengliang Guan 已提交
43
  dmInit();
S
Shengliang Guan 已提交
44

S
Shengliang Guan 已提交
45 46 47 48
  char fqdn[] = "localhost";
  char firstEp[TSDB_EP_LEN] = {0};
  snprintf(firstEp, TSDB_EP_LEN, "%s:%u", fqdn, port);

S
Shengliang Guan 已提交
49
  InitLog("/tmp/td");
S
Shengliang Guan 已提交
50 51
  server.Start(path, fqdn, port, firstEp);
  client.Init("root", "taosdata", fqdn, port);
52
  showRsp = NULL;
S
Shengliang Guan 已提交
53 54 55
}

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

dengyihao's avatar
fix bug  
dengyihao 已提交
66 67 68 69
void Testbase::Restart() {
  server.Restart();
  client.Restart();
}
S
Shengliang Guan 已提交
70

S
Shengliang Guan 已提交
71 72 73
void Testbase::ServerStop() { server.Stop(); }

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

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

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

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

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

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

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

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

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

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

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