mnode.cpp 7.7 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11
/**
 * @file dnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module dnode-msg tests
 * @version 0.1
 * @date 2021-12-15
 *
 * @copyright Copyright (c) 2021
 *
 */

S
Shengliang Guan 已提交
12
#include "sut.h"
S
Shengliang Guan 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

class DndTestMnode : public ::testing::Test {
 public:
  void SetUp() override {}
  void TearDown() override {}

 public:
  static void SetUpTestSuite() {
    test.Init("/tmp/dnode_test_mnode1", 9061);
    const char* fqdn = "localhost";
    const char* firstEp = "localhost:9061";

    server2.Start("/tmp/dnode_test_mnode2", fqdn, 9062, firstEp);
    server3.Start("/tmp/dnode_test_mnode3", fqdn, 9063, firstEp);
    server4.Start("/tmp/dnode_test_mnode4", fqdn, 9064, firstEp);
    server5.Start("/tmp/dnode_test_mnode5", fqdn, 9065, firstEp);
    taosMsleep(300);
  }

  static void TearDownTestSuite() {
    server2.Stop();
    server3.Stop();
    server4.Stop();
    server5.Stop();
    test.Cleanup();
  }

  static Testbase   test;
  static TestServer server2;
  static TestServer server3;
  static TestServer server4;
  static TestServer server5;
};

Testbase   DndTestMnode::test;
TestServer DndTestMnode::server2;
TestServer DndTestMnode::server3;
TestServer DndTestMnode::server4;
TestServer DndTestMnode::server5;

TEST_F(DndTestMnode, 01_ShowDnode) {
S
Shengliang Guan 已提交
54
  test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
S
Shengliang Guan 已提交
55
  CHECK_META("show mnodes", 5);
S
Shengliang Guan 已提交
56 57 58

  CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
  CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
S
Shengliang Guan 已提交
59 60 61
  CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, 12 + VARSTR_HEADER_SIZE, "role");
  CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time");
  CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
S
Shengliang Guan 已提交
62

S
Shengliang Guan 已提交
63
  test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
64 65 66 67
  EXPECT_EQ(test.GetShowRows(), 1);

  CheckInt16(1);
  CheckBinary("localhost:9061", TSDB_EP_LEN);
S
Shengliang Guan 已提交
68 69
  CheckBinary("master", 12);
  CheckInt64(0);
S
Shengliang Guan 已提交
70 71 72
  CheckTimestamp();
}

S
Shengliang Guan 已提交
73
TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
S
Shengliang Guan 已提交
74
  {
S
Shengliang Guan 已提交
75
    int32_t contLen = sizeof(SMCreateMnodeMsg);
S
Shengliang Guan 已提交
76

S
Shengliang Guan 已提交
77
    SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
78
    pReq->dnodeId = htonl(1);
S
Shengliang Guan 已提交
79

S
Shengliang Guan 已提交
80 81 82
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
S
Shengliang Guan 已提交
83
  }
S
Shengliang Guan 已提交
84
}
S
Shengliang Guan 已提交
85

S
Shengliang Guan 已提交
86
TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
S
Shengliang Guan 已提交
87
  {
S
Shengliang Guan 已提交
88
    int32_t contLen = sizeof(SMCreateMnodeMsg);
S
Shengliang Guan 已提交
89

S
Shengliang Guan 已提交
90
    SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
91 92
    pReq->dnodeId = htonl(2);

S
Shengliang Guan 已提交
93 94 95
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
S
Shengliang Guan 已提交
96
  }
S
Shengliang Guan 已提交
97
}
S
Shengliang Guan 已提交
98

S
Shengliang Guan 已提交
99
TEST_F(DndTestMnode, 04_Create_Mnode) {
S
Shengliang Guan 已提交
100
  {
S
Shengliang Guan 已提交
101
    // create dnode
S
Shengliang Guan 已提交
102
    int32_t contLen = sizeof(SCreateDnodeReq);
S
Shengliang Guan 已提交
103

S
Shengliang Guan 已提交
104
    SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
105 106
    strcpy(pReq->fqdn, "localhost");
    pReq->port = htonl(9062);
S
Shengliang Guan 已提交
107

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

S
Shengliang Guan 已提交
112
    taosMsleep(1300);
S
Shengliang Guan 已提交
113 114
    test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
    test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
115
    EXPECT_EQ(test.GetShowRows(), 2);
S
Shengliang Guan 已提交
116 117 118
  }

  {
S
Shengliang Guan 已提交
119
    // create mnode
S
Shengliang Guan 已提交
120
    int32_t contLen = sizeof(SMCreateMnodeMsg);
S
Shengliang Guan 已提交
121

S
Shengliang Guan 已提交
122
    SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
123
    pReq->dnodeId = htonl(2);
S
Shengliang Guan 已提交
124

S
Shengliang Guan 已提交
125 126 127
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
128

S
Shengliang Guan 已提交
129 130
    test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
    test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143
    EXPECT_EQ(test.GetShowRows(), 2);

    CheckInt16(1);
    CheckInt16(2);
    CheckBinary("localhost:9061", TSDB_EP_LEN);
    CheckBinary("localhost:9062", TSDB_EP_LEN);
    CheckBinary("master", 12);
    CheckBinary("slave", 12);
    CheckInt64(0);
    CheckInt64(0);
    CheckTimestamp();
    CheckTimestamp();
  }
S
Shengliang Guan 已提交
144 145 146

  {
    // drop mnode
S
Shengliang Guan 已提交
147
    int32_t contLen = sizeof(SMDropMnodeMsg);
S
Shengliang Guan 已提交
148

S
Shengliang Guan 已提交
149
    SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
150 151
    pReq->dnodeId = htonl(2);

S
Shengliang Guan 已提交
152 153 154
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
155

S
Shengliang Guan 已提交
156 157
    test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
    test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
158 159 160 161 162 163 164 165
    EXPECT_EQ(test.GetShowRows(), 1);

    CheckInt16(1);
    CheckBinary("localhost:9061", TSDB_EP_LEN);
    CheckBinary("master", 12);
    CheckInt64(0);
    CheckTimestamp();
  }
S
Shengliang Guan 已提交
166
}
S
Shengliang Guan 已提交
167
// {
S
Shengliang Guan 已提交
168
//   int32_t contLen = sizeof(SDropDnodeReq);
S
Shengliang Guan 已提交
169

S
Shengliang Guan 已提交
170
//   SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
171 172
//   pReq->dnodeId = htonl(2);

S
Shengliang Guan 已提交
173 174 175
//   SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
//   ASSERT_NE(pRsp, nullptr);
//   ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
176 177
// }

S
Shengliang Guan 已提交
178
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
S
Shengliang Guan 已提交
179
// CHECK_META("show dnodes", 7);
S
Shengliang Guan 已提交
180
// test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
181 182 183 184 185 186 187 188 189 190 191
// EXPECT_EQ(test.GetShowRows(), 1);

// CheckInt16(1);
// CheckBinary("localhost:9061", TSDB_EP_LEN);
// CheckInt16(0);
// CheckInt16(1);
// CheckBinary("ready", 10);
// CheckTimestamp();
// CheckBinary("", 24);

// {
S
Shengliang Guan 已提交
192
//   int32_t contLen = sizeof(SCreateDnodeReq);
S
Shengliang Guan 已提交
193

S
Shengliang Guan 已提交
194
//   SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
195 196
//   strcpy(pReq->ep, "localhost:9063");

S
Shengliang Guan 已提交
197 198 199
//   SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
//   ASSERT_NE(pRsp, nullptr);
//   ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
200 201 202
// }

// {
S
Shengliang Guan 已提交
203
//   int32_t contLen = sizeof(SCreateDnodeReq);
S
Shengliang Guan 已提交
204

S
Shengliang Guan 已提交
205
//   SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
206 207
//   strcpy(pReq->ep, "localhost:9064");

S
Shengliang Guan 已提交
208 209 210
//   SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
//   ASSERT_NE(pRsp, nullptr);
//   ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
211 212 213
// }

// {
S
Shengliang Guan 已提交
214
//   int32_t contLen = sizeof(SCreateDnodeReq);
S
Shengliang Guan 已提交
215

S
Shengliang Guan 已提交
216
//   SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
S
Shengliang Guan 已提交
217 218
//   strcpy(pReq->ep, "localhost:9065");

S
Shengliang Guan 已提交
219 220 221
//   SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
//   ASSERT_NE(pRsp, nullptr);
//   ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
222 223 224
// }

// taosMsleep(1300);
S
Shengliang Guan 已提交
225
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
S
Shengliang Guan 已提交
226
// CHECK_META("show dnodes", 7);
S
Shengliang Guan 已提交
227
// test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
// EXPECT_EQ(test.GetShowRows(), 4);

// CheckInt16(1);
// CheckInt16(3);
// CheckInt16(4);
// CheckInt16(5);
// CheckBinary("localhost:9061", TSDB_EP_LEN);
// CheckBinary("localhost:9063", TSDB_EP_LEN);
// CheckBinary("localhost:9064", TSDB_EP_LEN);
// CheckBinary("localhost:9065", TSDB_EP_LEN);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);

// // restart
// uInfo("stop all server");
// test.Restart();
// server2.Restart();
// server3.Restart();
// server4.Restart();
// server5.Restart();

// taosMsleep(1300);
S
Shengliang Guan 已提交
268
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
S
Shengliang Guan 已提交
269
// CHECK_META("show dnodes", 7);
S
Shengliang Guan 已提交
270
// test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
// EXPECT_EQ(test.GetShowRows(), 4);

// CheckInt16(1);
// CheckInt16(3);
// CheckInt16(4);
// CheckInt16(5);
// CheckBinary("localhost:9061", TSDB_EP_LEN);
// CheckBinary("localhost:9063", TSDB_EP_LEN);
// CheckBinary("localhost:9064", TSDB_EP_LEN);
// CheckBinary("localhost:9065", TSDB_EP_LEN);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(0);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckInt16(1);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckBinary("ready", 10);
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckTimestamp();
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// CheckBinary("", 24);
// }