/Users/deen/code/yugabyte-db/src/yb/common/ql_table_row-test.cc
Line | Count | Source |
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 | | #include <boost/functional/hash.hpp> |
15 | | #include <gtest/gtest.h> |
16 | | |
17 | | #include "yb/common/ql_expr.h" |
18 | | |
19 | | #include "yb/util/random_util.h" |
20 | | |
21 | | namespace yb { |
22 | | |
23 | 1 | TEST(QLTableRowTest, Simple) { |
24 | 1 | const ColumnIdRep column1 = kFirstColumnId.rep(); |
25 | 1 | const ColumnIdRep column2 = kFirstColumnId.rep() + 100; |
26 | | |
27 | 1 | QLTableRow row; |
28 | 1 | QLValuePB value1; |
29 | 1 | value1.set_int32_value(42); |
30 | 1 | QLValuePB value2; |
31 | 1 | value2.set_string_value("test"); |
32 | | |
33 | 1 | row.AllocColumn(column1, value1); |
34 | 1 | ASSERT_TRUE(row.IsColumnSpecified(column1)); |
35 | 1 | ASSERT_EQ(*row.GetColumn(column1), value1); |
36 | 1 | ASSERT_EQ( |
37 | 1 | Format("{ $0 => { value: int32_value: 42 ttl_seconds: 0 write_time: " |
38 | 1 | "kUninitializedWriteTime } }", |
39 | 1 | kFirstColumnIdRep), |
40 | 1 | row.ToString()); |
41 | | |
42 | 1 | row.AllocColumn(column2, value2); |
43 | | |
44 | 1 | ASSERT_TRUE(row.IsColumnSpecified(column2)); |
45 | 1 | ASSERT_EQ(*row.GetColumn(column2), value2); |
46 | 1 | } |
47 | | |
48 | 1 | TEST(QLTableRowTest, Random) { |
49 | 1 | constexpr int kRows = 100; |
50 | 1 | constexpr int kRowIterations = 100; |
51 | 1 | constexpr int kMutations = 10; |
52 | 1 | constexpr int kColumns = 16; |
53 | 101 | for (int i = kRows; i-- > 0;) { |
54 | 100 | QLTableRow row; |
55 | 10.1k | for (int j = kRowIterations; j-- > 0;) { |
56 | 10.0k | row.Clear(); |
57 | 10.0k | std::unordered_map<ColumnId, QLValuePB, boost::hash<ColumnId>> map; |
58 | 110k | for (int m = kMutations; m-- > 0;) { |
59 | 100k | ColumnId column_id(kFirstColumnIdRep + RandomUniformInt(0, kColumns)); |
60 | 100k | if (map.count(column_id)) { |
61 | 22.6k | continue; |
62 | 22.6k | } |
63 | 77.3k | QLValuePB value; |
64 | 77.3k | value.set_int32_value(RandomUniformInt(0, 100)); |
65 | 77.3k | map.emplace(column_id, value); |
66 | 77.3k | row.AllocColumn(column_id, std::move(value)); |
67 | | |
68 | 77.3k | ASSERT_EQ(row.ColumnCount(), map.size()); |
69 | | |
70 | 342k | for (const auto& p : map) { |
71 | 342k | ASSERT_EQ(*row.GetColumn(p.first), p.second); |
72 | 342k | } |
73 | 77.3k | } |
74 | 10.0k | } |
75 | 100 | } |
76 | 1 | } |
77 | | |
78 | | } // namespace yb |