YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/master-test_base.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#ifndef YB_MASTER_MASTER_TEST_BASE_H
34
#define YB_MASTER_MASTER_TEST_BASE_H
35
36
#include <algorithm>
37
#include <map>
38
#include <memory>
39
#include <mutex>
40
#include <sstream>
41
#include <string>
42
#include <tuple>
43
#include <vector>
44
45
#include <boost/container/small_vector.hpp>
46
#include <boost/optional/optional_fwd.hpp>
47
#include <boost/version.hpp>
48
#include <gflags/gflags_declare.h>
49
#include <gtest/gtest.h>
50
51
#include "yb/common/common_types.pb.h"
52
53
#include "yb/gutil/strings/substitute.h"
54
55
#include "yb/master/master_ddl.fwd.h"
56
#include "yb/master/master_fwd.h"
57
#include "yb/master/master-test-util.h"
58
59
#include "yb/rpc/messenger.h"
60
#include "yb/rpc/proxy_base.h"
61
#include "yb/rpc/rpc_controller.h"
62
63
#include "yb/tserver/tablet_server.h"
64
65
#include "yb/util/status_fwd.h"
66
#include "yb/util/net/sockaddr.h"
67
#include "yb/util/status.h"
68
#include "yb/util/test_util.h"
69
70
using yb::rpc::Messenger;
71
using yb::rpc::MessengerBuilder;
72
using yb::rpc::RpcController;
73
using std::make_shared;
74
using std::shared_ptr;
75
76
77
#define NAMESPACE_ENTRY(namespace) \
78
87
    std::make_tuple(k##namespace##NamespaceName, k##namespace##NamespaceId)
79
80
#define EXPECTED_SYSTEM_NAMESPACES \
81
29
    NAMESPACE_ENTRY(System), \
82
29
    NAMESPACE_ENTRY(SystemSchema), \
83
29
    NAMESPACE_ENTRY(SystemAuth) \
84
    /**/
85
86
#define EXPECTED_DEFAULT_NAMESPACE \
87
29
    std::make_tuple(default_namespace_name, default_namespace_id)
88
89
#define EXPECTED_DEFAULT_AND_SYSTEM_NAMESPACES \
90
29
    EXPECTED_DEFAULT_NAMESPACE, \
91
29
    EXPECTED_SYSTEM_NAMESPACES \
92
    /**/
93
94
#define TABLE_ENTRY(namespace, table, relation_type) \
95
368
    std::make_tuple(k##namespace##table##TableName, \
96
368
        k##namespace##NamespaceName, k##namespace##NamespaceId, relation_type)
97
98
#define SYSTEM_TABLE_ENTRY(namespace, table) \
99
368
    TABLE_ENTRY(namespace, table, SYSTEM_TABLE_RELATION)
100
101
#define EXPECTED_SYSTEM_TABLES \
102
23
    SYSTEM_TABLE_ENTRY(System, Peers), \
103
23
    SYSTEM_TABLE_ENTRY(System, Local), \
104
23
    SYSTEM_TABLE_ENTRY(System, Partitions), \
105
23
    SYSTEM_TABLE_ENTRY(System, SizeEstimates), \
106
23
    std::make_tuple(kSysCatalogTableName, kSystemSchemaNamespaceName, kSystemSchemaNamespaceId, \
107
23
        SYSTEM_TABLE_RELATION), \
108
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Aggregates), \
109
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Columns), \
110
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Functions), \
111
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Indexes), \
112
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Triggers), \
113
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Types), \
114
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Views), \
115
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Keyspaces), \
116
23
    SYSTEM_TABLE_ENTRY(SystemSchema, Tables), \
117
23
    SYSTEM_TABLE_ENTRY(SystemAuth, Roles), \
118
23
    SYSTEM_TABLE_ENTRY(SystemAuth, RolePermissions), \
119
23
    SYSTEM_TABLE_ENTRY(SystemAuth, ResourceRolePermissionsIndex)
120
    /**/
121
122
namespace yb {
123
namespace master {
124
125
using strings::Substitute;
126
127
class MasterTestBase : public YBTest {
128
 protected:
129
130
  string default_namespace_name = "default_namespace";
131
  string default_namespace_id;
132
133
  MasterTestBase();
134
  ~MasterTestBase();
135
136
  void SetUp() override;
137
  void TearDown() override;
138
139
  void DoListTables(const ListTablesRequestPB& req, ListTablesResponsePB* resp);
140
  void DoListAllTables(ListTablesResponsePB* resp, const NamespaceName& namespace_name = "");
141
142
  Status CreateTable(const NamespaceName& namespace_name,
143
                     const TableName& table_name,
144
                     const Schema& schema,
145
                     TableId* table_id = nullptr);
146
  Status CreateTable(const TableName& table_name,
147
                     const Schema& schema,
148
11
                     TableId* table_id = nullptr) {
149
11
    return CreateTable(default_namespace_name, table_name, schema, table_id);
150
11
  }
151
152
  Status CreatePgsqlTable(const NamespaceId& namespace_id,
153
                          const TableName& table_name,
154
                          const Schema& schema);
155
156
  Status CreateTablegroupTable(const NamespaceId& namespace_id,
157
                               const TableName& table_name,
158
                               const TablegroupId& tablegroup_id,
159
                               const Schema& schema);
160
161
  Status DoCreateTable(const NamespaceName& namespace_name,
162
                       const TableName& table_name,
163
                       const Schema& schema,
164
                       CreateTableRequestPB* request,
165
                       TableId* table_id = nullptr);
166
  Status DoCreateTable(const TableName& table_name,
167
                       const Schema& schema,
168
                       CreateTableRequestPB* request,
169
3
                       TableId* table_id = nullptr) {
170
3
    return DoCreateTable(default_namespace_name, table_name, schema, request, table_id);
171
3
  }
172
173
  Status DeleteTable(const NamespaceName& namespace_name,
174
                     const TableName& table_name,
175
                     TableId* table_id = nullptr);
176
  Status DeleteTable(const TableName& table_name,
177
1
                     TableId* table_id = nullptr) {
178
1
    return DeleteTable(default_namespace_name, table_name, table_id);
179
1
  }
180
181
  // Delete table and wait for operation to complete.
182
  Status DeleteTableSync(const NamespaceName& namespace_name,
183
                         const TableName& table_name,
184
                         TableId* table_id);
185
186
  Status CreateTablegroup(const TablegroupId& tablegroup_id,
187
                          const NamespaceId& namespace_id,
188
                          const NamespaceName& namespace_name,
189
                          const TablespaceId& tablespace_id);
190
191
  Status DeleteTablegroup(const TablegroupId& tablegroup_id,
192
                          const NamespaceId& namespace_id);
193
194
  void DoListTablegroups(const ListTablegroupsRequestPB& req,
195
                         ListTablegroupsResponsePB* resp);
196
197
  void DoListAllNamespaces(ListNamespacesResponsePB* resp);
198
  void DoListAllNamespaces(const boost::optional<YQLDatabase>& database_type,
199
                           ListNamespacesResponsePB* resp);
200
201
  Status CreateNamespace(const NamespaceName& ns_name, CreateNamespaceResponsePB* resp);
202
  Status CreateNamespace(const NamespaceName& ns_name,
203
                         const boost::optional<YQLDatabase>& database_type,
204
                         CreateNamespaceResponsePB* resp);
205
  Status CreateNamespaceAsync(const NamespaceName& ns_name,
206
                              const boost::optional<YQLDatabase>& database_type,
207
                              CreateNamespaceResponsePB* resp);
208
  Status CreateNamespaceWait(const NamespaceId& ns_id,
209
                             const boost::optional<YQLDatabase>& database_type);
210
211
  Status AlterNamespace(const NamespaceName& ns_name,
212
                        const NamespaceId& ns_id,
213
                        const boost::optional<YQLDatabase>& database_type,
214
                        const std::string& new_name,
215
                        AlterNamespaceResponsePB* resp);
216
217
  Status DeleteNamespaceWait(IsDeleteNamespaceDoneRequestPB const& del_req);
218
219
444
  RpcController* ResetAndGetController() {
220
444
    controller_->Reset();
221
444
    return controller_.get();
222
444
  }
223
224
  void CheckNamespaces(const std::set<std::tuple<NamespaceName, NamespaceId>>& namespace_info,
225
                       const ListNamespacesResponsePB& namespaces);
226
227
  bool FindNamespace(const std::tuple<NamespaceName, NamespaceId>& namespace_info,
228
                     const ListNamespacesResponsePB& namespaces);
229
230
  void CheckTables(
231
      const std::set<std::tuple<TableName, NamespaceName, NamespaceId, bool>>& table_info,
232
      const ListTablesResponsePB& tables);
233
234
  void UpdateMasterClusterConfig(SysClusterConfigEntryPB* cluster_config);
235
  std::unique_ptr<Messenger> client_messenger_;
236
  std::unique_ptr<MiniMaster> mini_master_;
237
  std::unique_ptr<MasterClientProxy> proxy_client_;
238
  std::unique_ptr<MasterClusterProxy> proxy_cluster_;
239
  std::unique_ptr<MasterDdlProxy> proxy_ddl_;
240
  std::unique_ptr<MasterHeartbeatProxy> proxy_heartbeat_;
241
  std::unique_ptr<MasterReplicationProxy> proxy_replication_;
242
  shared_ptr<RpcController> controller_;
243
};
244
245
} // namespace master
246
} // namespace yb
247
248
#endif /* YB_MASTER_MASTER_TEST_BASE_H */