dbnode.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 dbnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module bnode tests
 * @version 1.0
 * @date 2022-01-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

class DndTestBnode : public ::testing::Test {
 protected:
S
shm  
Shengliang Guan 已提交
16
  static void SetUpTestSuite() {
17
    test.Init("/tmp/dbnodeTest", 9112);
S
shm  
Shengliang Guan 已提交
18 19
    taosMsleep(1100);
  }
S
Shengliang Guan 已提交
20 21 22 23 24 25 26 27 28 29 30 31
  static void TearDownTestSuite() { test.Cleanup(); }
  static Testbase test;

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

Testbase DndTestBnode::test;

TEST_F(DndTestBnode, 01_Create_Bnode) {
  {
S
Shengliang Guan 已提交
32 33
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 2;
S
Shengliang Guan 已提交
34

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

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

  {
S
Shengliang Guan 已提交
45 46
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
47

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

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

  {
S
Shengliang Guan 已提交
58 59
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
60

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

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

70
  // test.Restart();
S
Shengliang Guan 已提交
71 72

  {
S
Shengliang Guan 已提交
73 74
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
75

76
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
77
    void*   pReq = rpcMallocCont(contLen);
78
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
79 80
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
81
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
82 83 84
  }
}

S
shm  
Shengliang Guan 已提交
85
TEST_F(DndTestBnode, 02_Drop_Bnode) {
S
Shengliang Guan 已提交
86
  {
S
Shengliang Guan 已提交
87 88
    SDDropBnodeReq 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_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
96
    ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
S
Shengliang Guan 已提交
97
  }
98

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

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

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

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

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

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

125
  // test.Restart();
S
Shengliang Guan 已提交
126 127

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

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

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

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

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

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