dqnode.cpp 4.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/**
 * @file dqnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module qnode tests
 * @version 1.0
 * @date 2022-01-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

class DndTestQnode : public ::testing::Test {
 protected:
  static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); }
  static void TearDownTestSuite() { test.Cleanup(); }

  static Testbase test;

 public:
  void SetUp() override {}
  void TearDown() override {}
};

Testbase DndTestQnode::test;
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28
TEST_F(DndTestQnode, 01_Create_Qnode) {
S
Shengliang Guan 已提交
29
  {
S
Shengliang Guan 已提交
30 31
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 2;
S
Shengliang Guan 已提交
32

33
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
34
    void*   pReq = rpcMallocCont(contLen);
35
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
36

S
Shengliang Guan 已提交
37 38
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
39
    ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
S
Shengliang Guan 已提交
40 41
  }

S
Shengliang Guan 已提交
42
  {
S
Shengliang Guan 已提交
43 44
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
45

46
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
47
    void*   pReq = rpcMallocCont(contLen);
48
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
49

S
Shengliang Guan 已提交
50 51 52
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
53
  }
S
Shengliang Guan 已提交
54

S
Shengliang Guan 已提交
55
  {
S
Shengliang Guan 已提交
56 57
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
58

59
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
60
    void*   pReq = rpcMallocCont(contLen);
61
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
62

S
Shengliang Guan 已提交
63 64
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
65
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
66
  }
S
Shengliang Guan 已提交
67

S
Shengliang Guan 已提交
68
  test.Restart();
S
Shengliang Guan 已提交
69

S
Shengliang Guan 已提交
70
  {
S
Shengliang Guan 已提交
71 72
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
73

74
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
75
    void*   pReq = rpcMallocCont(contLen);
76
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
77

S
Shengliang Guan 已提交
78 79
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
80
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
81
  }
S
Shengliang Guan 已提交
82 83
}

S
Shengliang Guan 已提交
84
TEST_F(DndTestQnode, 02_Drop_Qnode) {
S
Shengliang Guan 已提交
85
#if 0
S
Shengliang Guan 已提交
86
  {
S
Shengliang Guan 已提交
87 88
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 2;
S
Shengliang Guan 已提交
89

90
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
91
    void*   pReq = rpcMallocCont(contLen);
92
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
93

S
Shengliang Guan 已提交
94 95
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
96
    ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
S
Shengliang Guan 已提交
97
  }
S
Shengliang Guan 已提交
98
#endif
S
Shengliang Guan 已提交
99 100

  {
S
Shengliang Guan 已提交
101 102
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
103

104
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
105
    void*   pReq = rpcMallocCont(contLen);
106
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
107

S
Shengliang Guan 已提交
108 109 110
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
111 112 113
  }

  {
S
Shengliang Guan 已提交
114 115
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
116

117
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
118
    void*   pReq = rpcMallocCont(contLen);
119
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
120

S
Shengliang Guan 已提交
121 122
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
123
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
S
Shengliang Guan 已提交
124 125 126 127 128
  }

  test.Restart();

  {
S
Shengliang Guan 已提交
129 130
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
131

132
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
133
    void*   pReq = rpcMallocCont(contLen);
134
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
135

S
Shengliang Guan 已提交
136 137
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
138
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
S
Shengliang Guan 已提交
139 140 141
  }

  {
S
Shengliang Guan 已提交
142 143
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
144

145
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
146
    void*   pReq = rpcMallocCont(contLen);
147
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
148

S
Shengliang Guan 已提交
149 150 151
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
152
  }
S
Shengliang Guan 已提交
153
}