Skip to content

Commit fe50c25

Browse files
authored
[chore](UT) Add UT for cloud string util (apache#37552)
1 parent 80c9796 commit fe50c25

4 files changed

Lines changed: 115 additions & 13 deletions

File tree

cloud/src/recycler/recycler_service.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ void recycle_copy_jobs(const std::shared_ptr<TxnKv>& txn_kv, const std::string&
186186
}
187187
}
188188
auto recycler = std::make_unique<InstanceRecycler>(txn_kv, instance);
189+
if (recycler->init() != 0) {
190+
LOG(WARNING) << "failed to init InstanceRecycler recycle_copy_jobs on instance "
191+
<< instance_id;
192+
return;
193+
}
194+
189195
std::thread worker([recycler = std::move(recycler), instance_id] {
190196
LOG(INFO) << "manually trigger recycle_copy_jobs on instance " << instance_id;
191197
recycler->recycle_copy_jobs();

cloud/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ add_executable(s3_accessor_test s3_accessor_test.cpp)
5050

5151
add_executable(hdfs_accessor_test hdfs_accessor_test.cpp)
5252

53+
add_executable(util_test util_test.cpp)
54+
5355
add_executable(stopwatch_test stopwatch_test.cpp)
5456

5557
add_executable(network_util_test network_util_test.cpp)
@@ -83,6 +85,8 @@ target_link_libraries(s3_accessor_test ${TEST_LINK_LIBS})
8385

8486
target_link_libraries(hdfs_accessor_test ${TEST_LINK_LIBS})
8587

88+
target_link_libraries(util_test ${TEST_LINK_LIBS})
89+
8690
target_link_libraries(stopwatch_test ${TEST_LINK_LIBS})
8791

8892
target_link_libraries(network_util_test ${TEST_LINK_LIBS})

cloud/test/util_test.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
#include <string>
19+
#include <tuple>
20+
#include <vector>
21+
22+
#include "common/config.h"
23+
#include "common/string_util.h"
24+
#include "glog/logging.h"
25+
#include "gtest/gtest.h"
26+
27+
int main(int argc, char** argv) {
28+
doris::cloud::config::init(nullptr, true);
29+
::testing::InitGoogleTest(&argc, argv);
30+
return RUN_ALL_TESTS();
31+
}
32+
33+
TEST(StringUtilTest, test_string_strip) {
34+
// clang-format off
35+
// str expect to_drop
36+
std::vector<std::tuple<std::string, std::string, std::string>> leading_inputs {
37+
{"" , "" , "" },
38+
{"" , "" , "/" },
39+
{"/" , "" , "/" },
40+
{"\t////" , "" , "/ \t"},
41+
{"/a///" , "a///" , "/" },
42+
{"/a/b/c/", "a/b/c/", "/" },
43+
{"a/b/c/" , "a/b/c/", "/" },
44+
{"a/b/c/" , "/b/c/" , "a" },
45+
};
46+
int idx = 0;
47+
for (auto&& i : leading_inputs) {
48+
doris::cloud::strip_leading(std::get<0>(i), std::get<2>(i));
49+
EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx;
50+
++idx;
51+
}
52+
53+
idx = 0;
54+
std::vector<std::tuple<std::string, std::string, std::string>> trailing_inputs {
55+
{"" , "" , "" },
56+
{"/" , "" , "/" },
57+
{"////\t" , "" , "/ \t"},
58+
{"/a///" , "/a" , "/" },
59+
{"/a/b/c/", "/a/b/c", "/" },
60+
{"a/b/c/" , "a/b/c" , "/" },
61+
{"a/b/c" , "a/b/c" , "/" },
62+
{"a/b/c" , "a/b/" , "c" },
63+
};
64+
for (auto&& i : trailing_inputs) {
65+
doris::cloud::strip_trailing(std::get<0>(i), std::get<2>(i));
66+
EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx;
67+
++idx;
68+
}
69+
70+
idx = 0;
71+
std::vector<std::tuple<std::string, std::string>> trim_inputs {
72+
{"" , "" },
73+
{"" , "" },
74+
{"/" , "" },
75+
{"\t////" , "" },
76+
{"/a ///" , "a" },
77+
{"/a/b/c/" , "a/b/c"},
78+
{"a/b/c/" , "a/b/c"},
79+
{"a/b/c" , "a/b/c"},
80+
{"\t/bbc///" , "bbc" },
81+
{"ab c" , "ab c" },
82+
{"\t /a/b/c \t/", "a/b/c"},
83+
};
84+
for (auto&& i : trim_inputs) {
85+
doris::cloud::trim(std::get<0>(i));
86+
EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx;
87+
++idx;
88+
}
89+
90+
// clang-format on
91+
}

run-cloud-ut.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,25 @@ Usage: $0 <options>
4848
--clean clean and build ut
4949
--run build and run all ut
5050
--coverage coverage after run ut
51-
--run --filter=xx build and run specified ut
51+
--run --filter=x build and run specified ut, filter x format is <binary_name>:<gtest_filter>,
52+
a <binary_name> is the name of a cpp file without '.cpp' suffix.
53+
e.g. binary_name of xxx_test.cpp is xxx_test
5254
--fdb run with a specific fdb connection string, e.g fdb_cluster0:cluster0@192.168.1.100:4500
5355
-j build parallel
5456
-h print this help message
5557
5658
Eg.
57-
$0 build tests
58-
$0 --run build and run all tests
59-
$0 --run --filter=* also runs everything
60-
$0 --run --filter=FooTest.* runs everything in test suite FooTest
61-
$0 --run --filter=*Null*:*Constructor* runs any test whose full name contains either 'Null' or 'Constructor'
62-
$0 --run --filter=-*DeathTest.* runs all non-death tests
63-
$0 --run --filter=FooTest.*-FooTest.Bar runs everything in test suite FooTest except FooTest.Bar
64-
$0 --run --filter=FooTest.*:BarTest.*-FooTest.Bar:BarTest.Foo runs everything in test suite FooTest except FooTest.Bar and everything in test suite BarTest except BarTest.Foo
65-
$0 --run --fdb=fdb_cluster0:cluster0@192.168.1.100:4500 run with specific fdb
66-
$0 --run --coverage run with coverage report
67-
$0 --clean clean and build tests
68-
$0 --clean --run clean, build and run all tests
59+
$0 build tests
60+
$0 --run build and run all tests
61+
$0 --run --filter=recycler_test:FooTest.* runs everying of test suite FooTest in recycler_test.cpp
62+
$0 --run --filter=recycler_test:*Null*:*Constructor* runs any test whose full name contains either 'Null' or 'Constructor' in recycler_test.cpp
63+
$0 --run --filter=recycler_test:-*DeathTest.* runs all non-death tests in recycler_test.cpp
64+
$0 --run --filter=recycler_test:FooTest.*-FooTest.Bar runs everything in test suite FooTest except FooTest.Bar in recycler_test.cpp
65+
$0 --run --filter=recycler_test:FooTest.*:BarTest.*-FooTest.Bar:BarTest.Foo runs everything in test suite FooTest except FooTest.Bar and everything in test suite BarTest except BarTest.Foo in recycler_test.cpp
66+
$0 --run --fdb=fdb_cluster0:cluster0@192.168.1.100:4500 run with specific fdb
67+
$0 --run --coverage run with coverage report
68+
$0 --clean clean and build tests
69+
$0 --clean --run clean, build and run all tests
6970
"
7071
exit 1
7172
}

0 commit comments

Comments
 (0)