YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/client/ql-dml-test-base.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_CLIENT_QL_DML_TEST_BASE_H
15
#define YB_CLIENT_QL_DML_TEST_BASE_H
16
17
#include <algorithm>
18
#include <functional>
19
#include <vector>
20
21
#include <gtest/gtest.h>
22
23
#include "yb/client/callbacks.h"
24
#include "yb/client/table_handle.h"
25
#include "yb/common/ql_protocol.pb.h"
26
#include "yb/common/ql_rowblock.h"
27
28
#include "yb/server/server_fwd.h"
29
30
#include "yb/integration-tests/external_mini_cluster.h"
31
#include "yb/integration-tests/mini_cluster.h"
32
#include "yb/integration-tests/yb_mini_cluster_test_base.h"
33
#include "yb/master/mini_master.h"
34
#include "yb/tablet/tablet_fwd.h"
35
#include "yb/util/result.h"
36
#include "yb/util/test_util.h"
37
38
namespace yb {
39
namespace client {
40
41
extern const client::YBTableName kTableName;
42
43
template <class MiniClusterType>
44
class QLDmlTestBase : public MiniClusterTestWithClient<MiniClusterType> {
45
 public:
46
  QLDmlTestBase();
47
  void SetUp() override;
48
  void DoTearDown() override;
49
50
9
  virtual ~QLDmlTestBase() {}
_ZN2yb6client13QLDmlTestBaseINS_11MiniClusterEED2Ev
Line
Count
Source
50
2
  virtual ~QLDmlTestBase() {}
_ZN2yb6client13QLDmlTestBaseINS_19ExternalMiniClusterEED2Ev
Line
Count
Source
50
7
  virtual ~QLDmlTestBase() {}
51
52
 protected:
53
  virtual void SetFlags();
54
  void StartCluster();
55
56
  using MiniClusterTestWithClient<MiniClusterType>::client_;
57
  typename MiniClusterType::Options mini_cluster_opt_;
58
};
59
60
YB_STRONGLY_TYPED_BOOL(Transactional);
61
YB_DEFINE_ENUM(WriteOpType, (INSERT)(UPDATE)(DELETE));
62
YB_STRONGLY_TYPED_BOOL(Flush);
63
64
namespace kv_table_test {
65
66
constexpr const auto kKeyColumn = "key";
67
constexpr const auto kValueColumn = "value";
68
69
YB_DEFINE_ENUM(Partitioning, (kHash)(kRange))
70
71
void BuildSchema(Partitioning partitioning, Schema* schema);
72
73
CHECKED_STATUS CreateTable(
74
    const Schema& schema, int num_tablets, YBClient* client,
75
    TableHandle* table, const YBTableName& table_name = kTableName);
76
77
void CreateTable(
78
    Transactional transactional, int num_tablets, YBClient* client, TableHandle* table,
79
    const YBTableName& table_name = kTableName);
80
81
void CreateIndex(
82
    Transactional transactional, int indexed_column_index, bool use_mangled_names,
83
    const TableHandle& table, YBClient* client, TableHandle* index);
84
85
// Insert/update a full, single row, equivalent to the statement below. Return a YB write op that
86
// has been applied.
87
// op_type == WriteOpType::INSERT: insert into t values (key, value);
88
// op_type == WriteOpType::UPDATE: update t set v=value where k=key;
89
// op_type == WriteOpType::DELETE: delete from t where k=key; (parameter "value" is unused).
90
Result<YBqlWriteOpPtr> WriteRow(
91
    TableHandle* table, const YBSessionPtr& session, int32_t key, int32_t value,
92
    const WriteOpType op_type = WriteOpType::INSERT, Flush flush = Flush::kTrue);
93
94
Result<YBqlWriteOpPtr> DeleteRow(TableHandle* table, const YBSessionPtr& session, int32_t key);
95
96
Result<YBqlWriteOpPtr> UpdateRow(
97
    TableHandle* table, const YBSessionPtr& session, int32_t key, int32_t value);
98
99
// Select the specified columns of a row using a primary key, equivalent to the select statement
100
// below. Return a YB read op that has been applied.
101
//   select <columns...> from t where h1 = <h1> and h2 = <h2> and r1 = <r1> and r2 = <r2>;
102
Result<int32_t> SelectRow(
103
    TableHandle* table, const YBSessionPtr& session, int32_t key,
104
    const std::string& column = kValueColumn);
105
106
// Selects all rows from test table, returning map key => value.
107
Result<std::map<int32_t, int32_t>> SelectAllRows(TableHandle* table, const YBSessionPtr& session);
108
109
Result<YBqlWriteOpPtr> Increment(
110
    TableHandle* table, const YBSessionPtr& session, int32_t key, int32_t delta = 1,
111
    Flush flush = Flush::kFalse);
112
113
} // namespace kv_table_test
114
115
template <class MiniClusterType>
116
class KeyValueTableTest : public QLDmlTestBase<MiniClusterType> {
117
 protected:
118
  void CreateTable(Transactional transactional);
119
120
  CHECKED_STATUS CreateTable(const Schema& schema);
121
122
  void CreateIndex(Transactional transactional,
123
                   int indexed_column_index = 1,
124
                   bool use_mangled_names = true);
125
126
  void PrepareIndex(Transactional transactional,
127
                    const YBTableName& index_name,
128
                    int indexed_column_index = 1,
129
                    bool use_mangled_names = true);
130
131
  Result<YBqlWriteOpPtr> WriteRow(
132
      const YBSessionPtr& session, int32_t key, int32_t value,
133
      const WriteOpType op_type = WriteOpType::INSERT,
134
0
      Flush flush = Flush::kTrue) {
135
0
    return kv_table_test::WriteRow(&table_, session, key, value, op_type, flush);
136
0
  }
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_11MiniClusterEE8WriteRowERKNSt3__110shared_ptrINS0_9YBSessionEEEiiNS0_11WriteOpTypeENS_17StronglyTypedBoolINS0_9Flush_TagEEE
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_19ExternalMiniClusterEE8WriteRowERKNSt3__110shared_ptrINS0_9YBSessionEEEiiNS0_11WriteOpTypeENS_17StronglyTypedBoolINS0_9Flush_TagEEE
137
138
0
  Result<YBqlWriteOpPtr> DeleteRow(const YBSessionPtr& session, int32_t key) {
139
0
    return kv_table_test::DeleteRow(&table_, session, key);
140
0
  }
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_11MiniClusterEE9DeleteRowERKNSt3__110shared_ptrINS0_9YBSessionEEEi
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_19ExternalMiniClusterEE9DeleteRowERKNSt3__110shared_ptrINS0_9YBSessionEEEi
141
142
0
  Result<YBqlWriteOpPtr> UpdateRow(const YBSessionPtr& session, int32_t key, int32_t value) {
143
0
    return kv_table_test::UpdateRow(&table_, session, key, value);
144
0
  }
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_11MiniClusterEE9UpdateRowERKNSt3__110shared_ptrINS0_9YBSessionEEEii
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_19ExternalMiniClusterEE9UpdateRowERKNSt3__110shared_ptrINS0_9YBSessionEEEii
145
146
  // Select the specified columns of a row using a primary key, equivalent to the select statement
147
  // below. Return a YB read op that has been applied.
148
  //   select <columns...> from t where h1 = <h1> and h2 = <h2> and r1 = <r1> and r2 = <r2>;
149
  Result<int32_t> SelectRow(const YBSessionPtr& session, int32_t key,
150
0
                            const std::string& column = kValueColumn) {
151
0
    return kv_table_test::SelectRow(&table_, session, key, column);
152
0
  }
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_11MiniClusterEE9SelectRowERKNSt3__110shared_ptrINS0_9YBSessionEEEiRKNS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEE
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_19ExternalMiniClusterEE9SelectRowERKNSt3__110shared_ptrINS0_9YBSessionEEEiRKNS4_12basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEE
153
154
  YBSessionPtr CreateSession(const YBTransactionPtr& transaction = nullptr,
155
                             const server::ClockPtr& clock = nullptr);
156
157
  // Selects all rows from test table, returning map key => value.
158
0
  Result<std::map<int32_t, int32_t>> SelectAllRows(const YBSessionPtr& session) {
159
0
    return kv_table_test::SelectAllRows(&table_, session);
160
0
  }
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_11MiniClusterEE13SelectAllRowsERKNSt3__110shared_ptrINS0_9YBSessionEEE
Unexecuted instantiation: _ZN2yb6client17KeyValueTableTestINS_19ExternalMiniClusterEE13SelectAllRowsERKNSt3__110shared_ptrINS0_9YBSessionEEE
161
162
  virtual int NumTablets();
163
164
  // Sets number of tablets to use for test table creation.
165
59
  void SetNumTablets(int num_tablets) {
166
59
    num_tablets_ = num_tablets;
167
59
  }
_ZN2yb6client17KeyValueTableTestINS_11MiniClusterEE13SetNumTabletsEi
Line
Count
Source
165
43
  void SetNumTablets(int num_tablets) {
166
43
    num_tablets_ = num_tablets;
167
43
  }
_ZN2yb6client17KeyValueTableTestINS_19ExternalMiniClusterEE13SetNumTabletsEi
Line
Count
Source
165
16
  void SetNumTablets(int num_tablets) {
166
16
    num_tablets_ = num_tablets;
167
16
  }
168
169
  using MiniClusterTestWithClient<MiniClusterType>::client_;
170
171
  static const std::string kKeyColumn;
172
  static const std::string kValueColumn;
173
  TableHandle table_;
174
  TableHandle index_;
175
  int num_tablets_ = CalcNumTablets(3);
176
};
177
178
extern template class KeyValueTableTest<MiniCluster>;
179
extern template class KeyValueTableTest<ExternalMiniCluster>;
180
181
CHECKED_STATUS CheckOp(YBqlOp* op);
182
183
}  // namespace client
184
}  // namespace yb
185
186
#endif // YB_CLIENT_QL_DML_TEST_BASE_H