This is an automated email from the ASF dual-hosted git repository. gavinchou pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new fe50c256bcf [chore](UT) Add UT for cloud string util (#37552) fe50c256bcf is described below commit fe50c256bcf27eb232a556fa465c3034ce375b4b Author: Gavin Chou <gavineaglec...@gmail.com> AuthorDate: Sun Jul 14 17:59:39 2024 +0800 [chore](UT) Add UT for cloud string util (#37552) --- cloud/src/recycler/recycler_service.cpp | 6 +++ cloud/test/CMakeLists.txt | 4 ++ cloud/test/util_test.cpp | 91 +++++++++++++++++++++++++++++++++ run-cloud-ut.sh | 27 +++++----- 4 files changed, 115 insertions(+), 13 deletions(-) diff --git a/cloud/src/recycler/recycler_service.cpp b/cloud/src/recycler/recycler_service.cpp index 198c61db0a2..eca3bc6563b 100644 --- a/cloud/src/recycler/recycler_service.cpp +++ b/cloud/src/recycler/recycler_service.cpp @@ -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(); diff --git a/cloud/test/CMakeLists.txt b/cloud/test/CMakeLists.txt index c64c351f246..a27f7a1c538 100644 --- a/cloud/test/CMakeLists.txt +++ b/cloud/test/CMakeLists.txt @@ -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) @@ -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}) diff --git a/cloud/test/util_test.cpp b/cloud/test/util_test.cpp new file mode 100644 index 00000000000..02921170761 --- /dev/null +++ b/cloud/test/util_test.cpp @@ -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 +} diff --git a/run-cloud-ut.sh b/run-cloud-ut.sh index c1ff636d174..07d4fc4bb5b 100755 --- a/run-cloud-ut.sh +++ b/run-cloud-ut.sh @@ -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 } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org