YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/wire_protocol-test-util.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_COMMON_WIRE_PROTOCOL_TEST_UTIL_H_
34
#define YB_COMMON_WIRE_PROTOCOL_TEST_UTIL_H_
35
36
#include <string>
37
38
#include "yb/common/ql_protocol.pb.h"
39
#include "yb/common/schema.h"
40
41
#include "yb/docdb/docdb_fwd.h"
42
#include "yb/docdb/docdb.pb.h"
43
44
#include "yb/util/yb_partition.h"
45
46
namespace yb {
47
48
using docdb::KeyValuePairPB;
49
using docdb::SubDocKey;
50
using docdb::DocKey;
51
using docdb::PrimitiveValue;
52
53
252
inline Schema GetSimpleTestSchema() {
54
252
  return Schema({ ColumnSchema("key", INT32, false, true),
55
252
                  ColumnSchema("int_val", INT32),
56
252
                  ColumnSchema("string_val", STRING, true) },
57
252
                1);
58
252
}
59
60
template <class WriteRequestPB, class Type>
61
39.5k
QLWriteRequestPB* TestRow(int32_t key, Type type, WriteRequestPB* req) {
62
39.5k
  auto wb = req->add_ql_write_batch();
63
39.5k
  wb->set_schema_version(0);
64
39.5k
  wb->set_type(type);
65
66
39.5k
  std::string hash_key;
67
39.5k
  YBPartition::AppendIntToKey<int32_t, uint32_t>(key, &hash_key);
68
39.5k
  wb->set_hash_code(YBPartition::HashColumnCompoundValue(hash_key));
69
39.5k
  wb->add_hashed_column_values()->mutable_value()->set_int32_value(key);
70
39.5k
  return wb;
71
39.5k
}
72
73
template <class WriteRequestPB>
74
5
QLWriteRequestPB* AddTestRowDelete(int32_t key, WriteRequestPB* req) {
75
5
  return TestRow(key, QLWriteRequestPB::QL_STMT_DELETE, req);
76
5
}
77
78
template <class WriteRequestPB>
79
QLWriteRequestPB* AddTestRowInsert(int32_t key, WriteRequestPB* req) {
80
  return TestRow(key, QLWriteRequestPB::QL_STMT_INSERT, req);
81
}
82
83
template <class Type, class WriteRequestPB>
84
QLWriteRequestPB* AddTestRow(int32_t key,
85
                             int32_t int_val,
86
                             Type type,
87
39.5k
                             WriteRequestPB* req) {
88
39.5k
  auto wb = TestRow(key, type, req);
89
39.5k
  auto column_value = wb->add_column_values();
90
39.5k
  column_value->set_column_id(kFirstColumnId + 1);
91
39.5k
  column_value->mutable_expr()->mutable_value()->set_int32_value(int_val);
92
39.5k
  return wb;
93
39.5k
}
94
95
template <class Type, class WriteRequestPB>
96
void AddTestRow(int32_t key,
97
                int32_t int_val,
98
                const string& string_val,
99
                Type type,
100
39.5k
                WriteRequestPB* req) {
101
39.5k
  auto wb = AddTestRow(key, int_val, type, req);
102
39.5k
  auto column_value = wb->add_column_values();
103
39.5k
  column_value->set_column_id(kFirstColumnId + 2);
104
39.5k
  column_value->mutable_expr()->mutable_value()->set_string_value(string_val);
105
39.5k
}
106
107
template <class WriteRequestPB>
108
void AddTestRowInsert(int32_t key,
109
                      int32_t int_val,
110
1
                      WriteRequestPB* req) {
111
1
  AddTestRow(key, int_val, QLWriteRequestPB::QL_STMT_INSERT, req);
112
1
}
113
114
template <class WriteRequestPB>
115
void AddTestRowInsert(int32_t key,
116
                      int32_t int_val,
117
                      const string& string_val,
118
39.5k
                      WriteRequestPB* req) {
119
39.5k
  AddTestRow(key, int_val, string_val, QLWriteRequestPB::QL_STMT_INSERT, req);
120
39.5k
}
121
122
template <class WriteRequestPB>
123
void AddTestRowUpdate(int32_t key,
124
                      int32_t int_val,
125
                      const string& string_val,
126
6
                      WriteRequestPB* req) {
127
6
  AddTestRow(key, int_val, string_val, QLWriteRequestPB::QL_STMT_UPDATE, req);
128
6
}
129
130
void AddKVToPB(int32_t key_val,
131
               int32_t int_val,
132
               const string& string_val,
133
               docdb::KeyValueWriteBatchPB* write_batch);
134
135
} // namespace yb
136
137
#endif // YB_COMMON_WIRE_PROTOCOL_TEST_UTIL_H_