diff --git a/cpp/src/server/RequestTask.h b/cpp/src/server/RequestTask.h index 3061b3b75d73b5f266974e4464b1c21c06aef33d..4bf9f964e098233c9f680dcf5e49406d0f0b5cdc 100644 --- a/cpp/src/server/RequestTask.h +++ b/cpp/src/server/RequestTask.h @@ -7,7 +7,6 @@ #include "RequestScheduler.h" #include "utils/Error.h" -#include "utils/AttributeSerializer.h" #include "db/Types.h" #include "milvus_types.h" diff --git a/cpp/src/utils/AttributeSerializer.cpp b/cpp/src/utils/AttributeSerializer.cpp deleted file mode 100644 index b351262e60b988ee6d346dd12ee26137da2f6c09..0000000000000000000000000000000000000000 --- a/cpp/src/utils/AttributeSerializer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved - * Unauthorized copying of this file, via any medium is strictly prohibited. - * Proprietary and confidential. - ******************************************************************************/ - -#include "AttributeSerializer.h" -#include "StringHelpFunctions.h" - -namespace zilliz { -namespace milvus { -namespace server { - - -ServerError AttributeSerializer::Encode(const AttribMap& attrib_map, std::string& attrib_str) { - attrib_str = ""; - for(auto iter : attrib_map) { - attrib_str += iter.first; - attrib_str += ":\""; - attrib_str += iter.second; - attrib_str += "\";"; - } - - return SERVER_SUCCESS; -} - -ServerError AttributeSerializer::Decode(const std::string& attrib_str, AttribMap& attrib_map) { - attrib_map.clear(); - - std::vector kv_pairs; - StringHelpFunctions::SplitStringByQuote(attrib_str, ";", "\"", kv_pairs); - for(std::string& str : kv_pairs) { - std::string key, val; - size_t index = str.find_first_of(":", 0); - if (index != std::string::npos) { - key = str.substr(0, index); - val = str.substr(index + 1); - } else { - key = str; - } - - attrib_map.insert(std::make_pair(key, val)); - } - - return SERVER_SUCCESS; -} - -} -} -} diff --git a/cpp/src/utils/AttributeSerializer.h b/cpp/src/utils/AttributeSerializer.h deleted file mode 100644 index 8d0341aa2e705b186fdc45f7af38f24bafb5d613..0000000000000000000000000000000000000000 --- a/cpp/src/utils/AttributeSerializer.h +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved - * Unauthorized copying of this file, via any medium is strictly prohibited. - * Proprietary and confidential. - ******************************************************************************/ -#pragma once - -#include - -#include "Error.h" - -namespace zilliz { -namespace milvus { -namespace server { - -using AttribMap = std::map; - -class AttributeSerializer { -public: - static ServerError Encode(const AttribMap& attrib_map, std::string& attrib_str); - static ServerError Decode(const std::string& attrib_str, AttribMap& attrib_map); -}; - - -} -} -} diff --git a/cpp/src/utils/StringHelpFunctions.cpp b/cpp/src/utils/StringHelpFunctions.cpp index aaefd7236a3f47fa5cc5245ef318193e754a22b5..36ba017beb60211ec80b013199d7ca9580052263 100644 --- a/cpp/src/utils/StringHelpFunctions.cpp +++ b/cpp/src/utils/StringHelpFunctions.cpp @@ -9,13 +9,6 @@ namespace zilliz { namespace milvus { namespace server { -void StringHelpFunctions::TrimStringLineBreak(std::string &string) { - if (!string.empty()) { - static std::string s_format("\n\r"); - string.erase(string.find_last_not_of(s_format) + 1); - } -} - void StringHelpFunctions::TrimStringBlank(std::string &string) { if (!string.empty()) { static std::string s_format(" \n\r\t"); diff --git a/cpp/src/utils/StringHelpFunctions.h b/cpp/src/utils/StringHelpFunctions.h index 2521c48e22afbf725a1cfe4a77faeaf4ef425480..b5d8ce22b7ef4d88872fcfd82d3cb2b278680ae7 100644 --- a/cpp/src/utils/StringHelpFunctions.h +++ b/cpp/src/utils/StringHelpFunctions.h @@ -18,8 +18,6 @@ private: StringHelpFunctions() = default; public: - static void TrimStringLineBreak(std::string &string); - static void TrimStringBlank(std::string &string); static void TrimStringQuote(std::string &string, const std::string &qoute); diff --git a/cpp/unittest/server/CMakeLists.txt b/cpp/unittest/server/CMakeLists.txt index d844b7a9a3daafd811837930120bdbcbf6c24b10..4d34f0e2b7add31f8f98d0c9d79351c26748563e 100644 --- a/cpp/unittest/server/CMakeLists.txt +++ b/cpp/unittest/server/CMakeLists.txt @@ -14,9 +14,10 @@ aux_source_directory(../../src/cache cache_srcs) aux_source_directory(../../src/wrapper wrapper_src) aux_source_directory(./ test_srcs) -set(server_src_files +set(utils_srcs ${MILVUS_ENGINE_SRC}/utils/StringHelpFunctions.cpp - ${MILVUS_ENGINE_SRC}/utils/AttributeSerializer.cpp + ${MILVUS_ENGINE_SRC}/utils/TimeRecorder.cpp + ${MILVUS_ENGINE_SRC}/utils/CommonUtil.cpp ) cuda_add_executable(server_test @@ -25,7 +26,7 @@ cuda_add_executable(server_test ${cache_srcs} ${wrapper_src} ${test_srcs} - ${server_src_files} + ${utils_srcs} ${require_files} ) diff --git a/cpp/unittest/server/common_test.cpp b/cpp/unittest/server/common_test.cpp deleted file mode 100644 index 27d8c522e56e3151b25ac6b41755a1a59843987e..0000000000000000000000000000000000000000 --- a/cpp/unittest/server/common_test.cpp +++ /dev/null @@ -1,26 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved -// Unauthorized copying of this file, via any medium is strictly prohibited. -// Proprietary and confidential. -//////////////////////////////////////////////////////////////////////////////// -#include -#include "utils/CommonUtil.h" -#include "utils/Error.h" - -using namespace zilliz::milvus; - - -TEST(CommonTest, COMMON_TEST) { - std::string path1 = "/tmp/milvus_test/"; - std::string path2 = path1 + "common_test_12345/"; - std::string path3 = path2 + "abcdef"; - server::ServerError err = server::CommonUtil::CreateDirectory(path3); - ASSERT_EQ(err, server::SERVER_SUCCESS); - - ASSERT_TRUE(server::CommonUtil::IsDirectoryExit(path3)); - - err = server::CommonUtil::DeleteDirectory(path1); - ASSERT_EQ(err, server::SERVER_SUCCESS); - - ASSERT_FALSE(server::CommonUtil::IsDirectoryExit(path1)); -} diff --git a/cpp/unittest/server/util_test.cpp b/cpp/unittest/server/util_test.cpp index 0bc951d88e4688c9e161b1fab39b4abae4896466..9a38092799aa988843c6c4e24e1df92174ee556c 100644 --- a/cpp/unittest/server/util_test.cpp +++ b/cpp/unittest/server/util_test.cpp @@ -4,31 +4,99 @@ // Proprietary and confidential. //////////////////////////////////////////////////////////////////////////////// #include +#include -#include "utils/AttributeSerializer.h" +#include "utils/CommonUtil.h" +#include "utils/Error.h" #include "utils/StringHelpFunctions.h" +#include "utils/TimeRecorder.h" +#include "utils/BlockingQueue.h" using namespace zilliz::milvus; -TEST(AttribSerializeTest, ATTRIBSERIAL_TEST) { - std::map attrib; - attrib["uid"] = "ABCDEF"; - attrib["color"] = "red"; - attrib["number"] = "9900"; - attrib["comment"] = "please note: it is a car, not a ship"; - attrib["address"] = " china;shanghai "; +namespace { - std::string attri_str; - server::AttributeSerializer::Encode(attrib, attri_str); +using TimeUnit = server::TimeRecorder::TimeDisplayUnit; +double TestTimeRecorder(TimeUnit unit, int64_t log_level) { + server::TimeRecorder rc("test rc", unit, log_level); + rc.Record("begin"); + std::this_thread::sleep_for(std::chrono::microseconds(10)); + rc.Elapse("end"); + return rc.Span(); +} + +} + +TEST(CommonTest, COMMON_TEST) { + std::string path1 = "/tmp/milvus_test/"; + std::string path2 = path1 + "common_test_12345/"; + std::string path3 = path2 + "abcdef"; + server::ServerError err = server::CommonUtil::CreateDirectory(path3); + ASSERT_EQ(err, server::SERVER_SUCCESS); - std::map attrib_out; - server::ServerError err = server::AttributeSerializer::Decode(attri_str, attrib_out); + ASSERT_TRUE(server::CommonUtil::IsDirectoryExit(path3)); + + err = server::CommonUtil::DeleteDirectory(path1); ASSERT_EQ(err, server::SERVER_SUCCESS); - ASSERT_EQ(attrib_out.size(), attrib.size()); - for(auto iter : attrib) { - ASSERT_EQ(attrib_out[iter.first], attrib_out[iter.first]); + ASSERT_FALSE(server::CommonUtil::IsDirectoryExit(path1)); +} + +TEST(UtilTest, STRINGFUNCTIONS_TEST) { + std::string str = " test zilliz"; + server::StringHelpFunctions::TrimStringBlank(str); + ASSERT_EQ(str, "test zilliz"); + + str = "a,b,c"; + std::vector result; + server::StringHelpFunctions::SplitStringByDelimeter(str , ",", result); + ASSERT_EQ(result.size(), 3UL); + + str = "55,\"aa,gg,yy\",b"; + result.clear(); + server::StringHelpFunctions::SplitStringByQuote(str , ",", "\"", result); + ASSERT_EQ(result.size(), 3UL); +} + +TEST(UtilTest, TIMERECORDER_TEST) { + double span = TestTimeRecorder(TimeUnit::eTimeAutoUnit, 0); + ASSERT_GT(span, 0.0); + span = TestTimeRecorder(TimeUnit::eTimeHourUnit, 1); + ASSERT_GT(span, 0.0); + span = TestTimeRecorder(TimeUnit::eTimeMinuteUnit, 2); + ASSERT_GT(span, 0.0); + span = TestTimeRecorder(TimeUnit::eTimeSecondUnit, 3); + ASSERT_GT(span, 0.0); + span = TestTimeRecorder(TimeUnit::eTimeMilliSecUnit, 4); + ASSERT_GT(span, 0.0); + span = TestTimeRecorder(TimeUnit::eTimeMicroSecUnit, -1); + ASSERT_GT(span, 0.0); +} + +TEST(UtilTest, BLOCKINGQUEUE_TEST) { + server::BlockingQueue bq; + + static const size_t count = 10; + bq.SetCapacity(count); + + for(size_t i = 1; i <= count; i++) { + std::string id = "No." + std::to_string(i); + bq.Put(id); } + ASSERT_EQ(bq.Size(), count); + ASSERT_FALSE(bq.Empty()); + + std::string str = bq.Front(); + ASSERT_EQ(str, "No.1"); + + str = bq.Back(); + ASSERT_EQ(str, "No." + std::to_string(count)); + + for(size_t i = 1; i <= count; i++) { + std::string id = "No." + std::to_string(i); + str = bq.Take(); + ASSERT_EQ(id, str); + } }