Skip to content

Commit

Permalink
[chore](UT) Add UT for cloud string util (apache#37552)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinchou authored Jul 14, 2024
1 parent 80c9796 commit fe50c25
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 13 deletions.
6 changes: 6 additions & 0 deletions cloud/src/recycler/recycler_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ void recycle_copy_jobs(const std::shared_ptr<TxnKv>& txn_kv, const std::string&
}
}
auto recycler = std::make_unique<InstanceRecycler>(txn_kv, instance);
if (recycler->init() != 0) {
LOG(WARNING) << "failed to init InstanceRecycler recycle_copy_jobs on instance "
<< instance_id;
return;
}

std::thread worker([recycler = std::move(recycler), instance_id] {
LOG(INFO) << "manually trigger recycle_copy_jobs on instance " << instance_id;
recycler->recycle_copy_jobs();
Expand Down
4 changes: 4 additions & 0 deletions cloud/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ add_executable(s3_accessor_test s3_accessor_test.cpp)

add_executable(hdfs_accessor_test hdfs_accessor_test.cpp)

add_executable(util_test util_test.cpp)

add_executable(stopwatch_test stopwatch_test.cpp)

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

target_link_libraries(hdfs_accessor_test ${TEST_LINK_LIBS})

target_link_libraries(util_test ${TEST_LINK_LIBS})

target_link_libraries(stopwatch_test ${TEST_LINK_LIBS})

target_link_libraries(network_util_test ${TEST_LINK_LIBS})
Expand Down
91 changes: 91 additions & 0 deletions cloud/test/util_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include <string>
#include <tuple>
#include <vector>

#include "common/config.h"
#include "common/string_util.h"
#include "glog/logging.h"
#include "gtest/gtest.h"

int main(int argc, char** argv) {
doris::cloud::config::init(nullptr, true);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

TEST(StringUtilTest, test_string_strip) {
// clang-format off
// str expect to_drop
std::vector<std::tuple<std::string, std::string, std::string>> leading_inputs {
{"" , "" , "" },
{"" , "" , "/" },
{"/" , "" , "/" },
{"\t////" , "" , "/ \t"},
{"/a///" , "a///" , "/" },
{"/a/b/c/", "a/b/c/", "/" },
{"a/b/c/" , "a/b/c/", "/" },
{"a/b/c/" , "/b/c/" , "a" },
};
int idx = 0;
for (auto&& i : leading_inputs) {
doris::cloud::strip_leading(std::get<0>(i), std::get<2>(i));
EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx;
++idx;
}

idx = 0;
std::vector<std::tuple<std::string, std::string, std::string>> trailing_inputs {
{"" , "" , "" },
{"/" , "" , "/" },
{"////\t" , "" , "/ \t"},
{"/a///" , "/a" , "/" },
{"/a/b/c/", "/a/b/c", "/" },
{"a/b/c/" , "a/b/c" , "/" },
{"a/b/c" , "a/b/c" , "/" },
{"a/b/c" , "a/b/" , "c" },
};
for (auto&& i : trailing_inputs) {
doris::cloud::strip_trailing(std::get<0>(i), std::get<2>(i));
EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx;
++idx;
}

idx = 0;
std::vector<std::tuple<std::string, std::string>> trim_inputs {
{"" , "" },
{"" , "" },
{"/" , "" },
{"\t////" , "" },
{"/a ///" , "a" },
{"/a/b/c/" , "a/b/c"},
{"a/b/c/" , "a/b/c"},
{"a/b/c" , "a/b/c"},
{"\t/bbc///" , "bbc" },
{"ab c" , "ab c" },
{"\t /a/b/c \t/", "a/b/c"},
};
for (auto&& i : trim_inputs) {
doris::cloud::trim(std::get<0>(i));
EXPECT_EQ(std::get<0>(i), std::get<1>(i)) << " index=" << idx;
++idx;
}

// clang-format on
}
27 changes: 14 additions & 13 deletions run-cloud-ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,25 @@ Usage: $0 <options>
--clean clean and build ut
--run build and run all ut
--coverage coverage after run ut
--run --filter=xx build and run specified ut
--run --filter=x build and run specified ut, filter x format is <binary_name>:<gtest_filter>,
a <binary_name> is the name of a cpp file without '.cpp' suffix.
e.g. binary_name of xxx_test.cpp is xxx_test
--fdb run with a specific fdb connection string, e.g fdb_cluster0:cluster0@192.168.1.100:4500
-j build parallel
-h print this help message
Eg.
$0 build tests
$0 --run build and run all tests
$0 --run --filter=* also runs everything
$0 --run --filter=FooTest.* runs everything in test suite FooTest
$0 --run --filter=*Null*:*Constructor* runs any test whose full name contains either 'Null' or 'Constructor'
$0 --run --filter=-*DeathTest.* runs all non-death tests
$0 --run --filter=FooTest.*-FooTest.Bar runs everything in test suite FooTest except FooTest.Bar
$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
$0 --run --fdb=fdb_cluster0:cluster0@192.168.1.100:4500 run with specific fdb
$0 --run --coverage run with coverage report
$0 --clean clean and build tests
$0 --clean --run clean, build and run all tests
$0 build tests
$0 --run build and run all tests
$0 --run --filter=recycler_test:FooTest.* runs everying of test suite FooTest in recycler_test.cpp
$0 --run --filter=recycler_test:*Null*:*Constructor* runs any test whose full name contains either 'Null' or 'Constructor' in recycler_test.cpp
$0 --run --filter=recycler_test:-*DeathTest.* runs all non-death tests in recycler_test.cpp
$0 --run --filter=recycler_test:FooTest.*-FooTest.Bar runs everything in test suite FooTest except FooTest.Bar in recycler_test.cpp
$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
$0 --run --fdb=fdb_cluster0:cluster0@192.168.1.100:4500 run with specific fdb
$0 --run --coverage run with coverage report
$0 --clean clean and build tests
$0 --clean --run clean, build and run all tests
"
exit 1
}
Expand Down

0 comments on commit fe50c25

Please sign in to comment.