1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | |
16 | * \author Dianzhang.Chen |
17 | * \date Apr 2021 |
18 | * \brief |
19 | */ |
20 | |
21 | #include "repository/lsn_context_format.h" |
22 | #include <gtest/gtest.h> |
23 | |
24 | using namespace proxima::be::repository; |
25 | |
26 | int main(int argc, char *argv[]) { |
27 | testing::InitGoogleTest(&argc, argv); |
28 | return RUN_ALL_TESTS(); |
29 | } |
30 | |
31 | class LsnContextFormatTest : public ::testing::Test { |
32 | protected: |
33 | LsnContextFormatTest() {} |
34 | |
35 | ~LsnContextFormatTest() {} |
36 | void SetUp() {} |
37 | void TearDown() {} |
38 | }; |
39 | |
40 | TEST_F(LsnContextFormatTest, TestGeneral) { |
41 | std::string lsn_str = "binlog;123456789;123;0" ; |
42 | auto lsn_context = LsnContextFormat(); |
43 | lsn_context.parse_from_string(lsn_str); |
44 | auto filename = lsn_context.file_name(); |
45 | auto position = lsn_context.position(); |
46 | auto seq_id = lsn_context.seq_id(); |
47 | auto mode = lsn_context.mode(); |
48 | EXPECT_EQ(filename, "binlog" ); |
49 | EXPECT_EQ(position, 123456789); |
50 | EXPECT_EQ(seq_id, 123); |
51 | EXPECT_EQ(mode, ScanMode::FULL); |
52 | |
53 | lsn_str = "binlog2;87654321;123;1" ; |
54 | lsn_context = LsnContextFormat(); |
55 | lsn_context.parse_from_string(lsn_str); |
56 | filename = lsn_context.file_name(); |
57 | position = lsn_context.position(); |
58 | seq_id = lsn_context.seq_id(); |
59 | mode = lsn_context.mode(); |
60 | EXPECT_EQ(filename, "binlog2" ); |
61 | EXPECT_EQ(position, 87654321); |
62 | EXPECT_EQ(seq_id, 123); |
63 | EXPECT_EQ(mode, ScanMode::INCREMENTAL); |
64 | |
65 | lsn_context = |
66 | LsnContextFormat("binlog2" , 87654321, 123, ScanMode::INCREMENTAL); |
67 | auto lsn_str2 = lsn_context.convert_to_string(); |
68 | EXPECT_EQ(lsn_str, lsn_str2); |
69 | } |
70 | |