show.cpp 2.8 KB
Newer Older
S
Shengliang Guan 已提交
1
/**
S
Shengliang Guan 已提交
2
 * @file show.cpp
S
Shengliang Guan 已提交
3
 * @author slguan (slguan@taosdata.com)
S
Shengliang Guan 已提交
4 5 6
 * @brief MNODE module show tests
 * @version 1.0
 * @date 2022-01-06
S
Shengliang Guan 已提交
7
 *
S
Shengliang Guan 已提交
8
 * @copyright Copyright (c) 2022
S
Shengliang Guan 已提交
9 10 11
 *
 */

S
Shengliang Guan 已提交
12
#include "sut.h"
S
Shengliang Guan 已提交
13

S
Shengliang Guan 已提交
14
class MndTestShow : public ::testing::Test {
S
Shengliang Guan 已提交
15
 protected:
S
Shengliang Guan 已提交
16
  static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9020); }
S
Shengliang Guan 已提交
17
  static void TearDownTestSuite() { test.Cleanup(); }
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19
  static Testbase test;
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21 22 23 24
 public:
  void SetUp() override {}
  void TearDown() override {}
};
S
Shengliang Guan 已提交
25

S
Shengliang Guan 已提交
26
Testbase MndTestShow::test;
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
S
Shengliang Guan 已提交
29
  int32_t contLen = sizeof(SShowReq);
S
Shengliang Guan 已提交
30

S
Shengliang Guan 已提交
31
  SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
32 33 34
  pReq->type = TSDB_MGMT_TABLE_MAX;
  strcpy(pReq->db, "");

S
Shengliang Guan 已提交
35 36 37
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
S
Shengliang Guan 已提交
38 39
}

S
Shengliang Guan 已提交
40
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
S
Shengliang Guan 已提交
41
  int32_t contLen = sizeof(SShowReq);
S
Shengliang Guan 已提交
42

S
Shengliang Guan 已提交
43
  SShowReq* pReq = (SShowReq*)rpcMallocCont(sizeof(SShowReq));
S
Shengliang Guan 已提交
44 45 46
  pReq->type = TSDB_MGMT_TABLE_START;
  strcpy(pReq->db, "");

S
Shengliang Guan 已提交
47 48 49
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
S
Shengliang Guan 已提交
50
}
S
Shengliang Guan 已提交
51

S
Shengliang Guan 已提交
52
TEST_F(MndTestShow, 03_ShowMsg_Conn) {
S
Shengliang Guan 已提交
53 54 55 56
  int32_t contLen = sizeof(SConnectMsg);

  SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
  pReq->pid = htonl(1234);
S
Shengliang Guan 已提交
57
  strcpy(pReq->app, "mnode_test_show");
S
Shengliang Guan 已提交
58 59
  strcpy(pReq->db, "");

S
Shengliang Guan 已提交
60 61 62
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
63

S
Shengliang Guan 已提交
64
  test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, "");
S
Shengliang Guan 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77

  STableMetaMsg* pMeta = test.GetShowMeta();
  EXPECT_STREQ(pMeta->tbFname, "show connections");
  EXPECT_EQ(pMeta->numOfTags, 0);
  EXPECT_EQ(pMeta->numOfColumns, 7);
  EXPECT_EQ(pMeta->precision, 0);
  EXPECT_EQ(pMeta->tableType, 0);
  EXPECT_EQ(pMeta->update, 0);
  EXPECT_EQ(pMeta->sversion, 0);
  EXPECT_EQ(pMeta->tversion, 0);
  EXPECT_EQ(pMeta->tuid, 0);
  EXPECT_EQ(pMeta->suid, 0);

S
Shengliang Guan 已提交
78
  test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
79 80 81 82 83 84 85 86 87

  SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp();
  EXPECT_EQ(pRetrieveRsp->numOfRows, 1);
  EXPECT_EQ(pRetrieveRsp->useconds, 0);
  EXPECT_EQ(pRetrieveRsp->completed, 1);
  EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
  EXPECT_EQ(pRetrieveRsp->compressed, 0);
  EXPECT_EQ(pRetrieveRsp->compLen, 0);
}
S
Shengliang Guan 已提交
88 89

TEST_F(MndTestShow, 04_ShowMsg_Cluster) {
S
Shengliang Guan 已提交
90
  test.SendShowMetaReq(TSDB_MGMT_TABLE_CLUSTER, "");
S
Shengliang Guan 已提交
91 92 93 94 95
  CHECK_META( "show cluster", 3);
  CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id");
  CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
  CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");

S
Shengliang Guan 已提交
96
  test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
97 98 99 100 101 102
  EXPECT_EQ(test.GetShowRows(), 1);

  IgnoreInt64();
  IgnoreBinary(TSDB_CLUSTER_ID_LEN);
  CheckTimestamp();
}