YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/docdb/value-test.cc
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
#include "yb/docdb/value.h"
15
#include "yb/docdb/value_type.h"
16
17
#include "yb/util/random.h"
18
#include "yb/util/test_util.h"
19
#include "yb/util/uuid.h"
20
21
namespace yb {
22
namespace docdb {
23
24
class ValueTest : public YBTest {
25
};
26
27
0
TEST_F(ValueTest, TestEncodeDecode) {
28
0
  Random r(0);
29
0
  PrimitiveValue primitive_value(r.Next64());
30
0
  MonoDelta ttl = MonoDelta::FromSeconds(r.Next32());
31
0
  int64_t timestamp = r.Next64();
32
0
  Value value(primitive_value, ttl, timestamp);
33
0
  LOG(INFO) << "Testing Value: " << value.ToString();
34
35
0
  std::string value_bytes = value.Encode();
36
0
  Value decoded_value;
37
  // Test values without decoding.
38
0
  ASSERT_TRUE(decoded_value.ttl().Equals(Value::kMaxTtl));
39
0
  ASSERT_EQ(Value::kInvalidUserTimestamp, decoded_value.user_timestamp());
40
41
  // Now decode and test.
42
0
  ASSERT_OK(decoded_value.Decode(value_bytes));
43
0
  ASSERT_EQ(primitive_value, decoded_value.primitive_value());
44
0
  ASSERT_TRUE(ttl.Equals(decoded_value.ttl()));
45
0
  ASSERT_EQ(timestamp, decoded_value.user_timestamp());
46
47
  // Test decode value type.
48
0
  ValueType value_type;
49
0
  ASSERT_OK(Value::DecodePrimitiveValueType(value_bytes, &value_type));
50
0
  ASSERT_EQ(ValueType::kInt64, value_type);
51
52
  // Test decode value type without ttl and timestamp.
53
0
  Value val1(PrimitiveValue(r.Next64()));
54
0
  value_bytes = val1.Encode();
55
0
  ASSERT_OK(Value::DecodePrimitiveValueType(value_bytes, &value_type));
56
0
  ASSERT_EQ(ValueType::kInt64, value_type);
57
0
}
58
59
}  // namespace docdb
60
}  // namespace yb