dsnode.cpp 4.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * @file dsnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module snode tests
 * @version 1.0
 * @date 2022-01-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

class DndTestSnode : public ::testing::Test {
 protected:
S
Shengliang Guan 已提交
16
  static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9113); }
S
Shengliang Guan 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29
  static void TearDownTestSuite() { test.Cleanup(); }

  static Testbase test;

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

Testbase DndTestSnode::test;

TEST_F(DndTestSnode, 01_Create_Snode) {
  {
S
Shengliang Guan 已提交
30 31
    SDCreateSnodeReq 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_SNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
39
    ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
S
Shengliang Guan 已提交
40 41 42
  }

  {
S
Shengliang Guan 已提交
43 44
    SDCreateSnodeReq 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_SNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
53 54 55
  }

  {
S
Shengliang Guan 已提交
56 57
    SDCreateSnodeReq 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_SNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
65
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
66 67 68 69 70
  }

  test.Restart();

  {
S
Shengliang Guan 已提交
71 72
    SDCreateSnodeReq 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_SNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
80
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
81 82 83 84 85
  }
}

TEST_F(DndTestSnode, 01_Drop_Snode) {
  {
S
Shengliang Guan 已提交
86 87
    SDDropSnodeReq dropReq = {0};
    dropReq.dnodeId = 2;
S
Shengliang Guan 已提交
88

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

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

  {
S
Shengliang Guan 已提交
99 100
    SDDropSnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
101

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

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

  {
S
Shengliang Guan 已提交
112 113
    SDDropSnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
114

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

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

  test.Restart();

  {
S
Shengliang Guan 已提交
127 128
    SDDropSnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
129

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

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

  {
S
Shengliang Guan 已提交
140 141
    SDCreateSnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
142

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

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