Debian Codegraph @

unittest/gunit/binlogevents/grow_calculator-t.cc

raw symbols SCIP
1 /* Copyright (c) 2023, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "libbinlogevents/include/buffer/grow_calculator.h"
26
27 #include <gmock/gmock.h>
28 #include <gtest/gtest.h>
29
30 namespace mysqlns::buffer::grow_calculator::unittest {
31
32 using Grow_calculator_t = mysqlns::buffer::Grow_calculator;
33 using Size_t = mysqlns::buffer::Grow_calculator::Size_t;
34 using Result_t = mysqlns::buffer::Grow_calculator::Result_t;
35
36 TEST(GrowPolicyTest, BasicGrowPolicyTest) {
37 Grow_calculator_t grow_calculator;
38 grow_calculator.set_max_size(1000);
39 grow_calculator.set_grow_factor(1.5);
40 grow_calculator.set_grow_increment(100);
41 grow_calculator.set_block_size(101);
42 auto success = [](Size_t size) { return Result_t(false, size); };
43 auto error = Result_t(true, 0);
44
45 // increment decides size
46 EXPECT_EQ(success(101), grow_calculator.compute_new_size(0, 1));
47 // factor decides size
48 EXPECT_EQ(success(808), grow_calculator.compute_new_size(500, 501));
49 // max_capacity caps size
50 EXPECT_EQ(success(1000), grow_calculator.compute_new_size(700, 701));
51 // boundary around block_size
52 EXPECT_EQ(success(101), grow_calculator.compute_new_size(0, 100));
53 EXPECT_EQ(success(101), grow_calculator.compute_new_size(0, 101));
54 EXPECT_EQ(success(202), grow_calculator.compute_new_size(0, 102));
55
56 // can reach the max capacity
57 EXPECT_EQ(success(1000), grow_calculator.compute_new_size(0, 1000));
58 // cannot exceed the max capacity
59 EXPECT_EQ(error, grow_calculator.compute_new_size(0, 1001));
60 }
61
62 } // namespace mysqlns::buffer::grow_calculator::unittest