From 5849a4f8f63ac217327b795feea47c41ecb8bc1b Mon Sep 17 00:00:00 2001 From: groot Date: Sun, 30 Jun 2019 16:19:04 +0800 Subject: [PATCH] fix build error Former-commit-id: 0d9ee6e9f2cc875efdf8cfab6aec07723d238c57 --- cpp/conf/server_config.template | 2 +- cpp/src/server/DBWrapper.cpp | 10 ++- cpp/unittest/metrics/CMakeLists.txt | 10 +-- cpp/unittest/metrics/metricbase_test.cpp | 2 +- cpp/unittest/metrics/metrics_test.cpp | 4 +- cpp/unittest/metrics/prometheus_test.cpp | 2 +- cpp/unittest/metrics/utils.cpp | 79 ++++++++++++++++++++++++ cpp/unittest/metrics/utils.h | 64 +++++++++++++++++++ 8 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 cpp/unittest/metrics/utils.cpp create mode 100644 cpp/unittest/metrics/utils.h diff --git a/cpp/conf/server_config.template b/cpp/conf/server_config.template index 1a1c8303..6082969f 100644 --- a/cpp/conf/server_config.template +++ b/cpp/conf/server_config.template @@ -6,7 +6,7 @@ server_config: db_config: db_path: @MILVUS_DB_PATH@ # milvus data storage path - db_backend_url: http://127.0.0.1 # meta database uri + db_backend_url: sqlite://:@:/ # meta database uri index_building_threshold: 1024 # index building trigger threshold, default: 1024, unit: MB archive_disk_threshold: 512 # triger archive action if storage size exceed this value, unit: GB archive_days_threshold: 30 # files older than x days will be archived, unit: day diff --git a/cpp/src/server/DBWrapper.cpp b/cpp/src/server/DBWrapper.cpp index a3db0bf1..bf859b3b 100644 --- a/cpp/src/server/DBWrapper.cpp +++ b/cpp/src/server/DBWrapper.cpp @@ -70,9 +70,15 @@ DBWrapper::DBWrapper() { kill(0, SIGUSR1); } - zilliz::milvus::engine::DB::Open(opt, &db_); + std::string msg = opt.meta.path; + try { + zilliz::milvus::engine::DB::Open(opt, &db_); + } catch(std::exception& ex) { + msg = ex.what(); + } + if(db_ == nullptr) { - std::cout << "ERROR! Failed to open database" << std::endl; + std::cout << "ERROR! Failed to open database: " << msg << std::endl; kill(0, SIGUSR1); } } diff --git a/cpp/unittest/metrics/CMakeLists.txt b/cpp/unittest/metrics/CMakeLists.txt index 80210772..d31e44c0 100644 --- a/cpp/unittest/metrics/CMakeLists.txt +++ b/cpp/unittest/metrics/CMakeLists.txt @@ -17,6 +17,7 @@ aux_source_directory(../../src/config config_files) aux_source_directory(../../src/cache cache_srcs) aux_source_directory(../../src/wrapper wrapper_src) aux_source_directory(../../src/metrics metrics_src) +aux_source_directory(./ test_srcs) aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler scheduler_files) aux_source_directory(${MILVUS_ENGINE_SRC}/db/scheduler/context scheduler_context_files) @@ -35,6 +36,7 @@ link_directories("/usr/local/cuda/lib64") #include_directories(../db/utils.h) include_directories(../../src/metrics) +include_directories(/usr/include/mysql) #set(metrics_src_files # ../../src/metrics/Metrics.cpp @@ -47,17 +49,14 @@ include_directories(../../src/metrics) # ) set(count_test_src - ${unittest_srcs} ${config_files} ${cache_srcs} ${db_srcs} ${db_scheduler_srcs} ${wrapper_src} ${metrics_src} - metrics_test.cpp - prometheus_test.cpp - ../db/utils.cpp - metricbase_test.cpp) + ${test_srcs} + ) add_executable(metrics_test ${count_test_src} ${require_files} ) @@ -75,6 +74,7 @@ target_link_libraries(metrics_test gtest pthread z + mysqlpp ${unittest_libs} ) diff --git a/cpp/unittest/metrics/metricbase_test.cpp b/cpp/unittest/metrics/metricbase_test.cpp index ac850c7b..1997748f 100644 --- a/cpp/unittest/metrics/metricbase_test.cpp +++ b/cpp/unittest/metrics/metricbase_test.cpp @@ -11,7 +11,7 @@ using namespace zilliz::milvus; -TEST(MetricbaseTest, Metricbase_Test){ +TEST(MetricbaseTest, METRICBASE_TEST){ server::MetricsBase instance = server::MetricsBase::GetInstance(); instance.Init(); server::SystemInfo::GetInstance().Init(); diff --git a/cpp/unittest/metrics/metrics_test.cpp b/cpp/unittest/metrics/metrics_test.cpp index 923c7b71..883e63ed 100644 --- a/cpp/unittest/metrics/metrics_test.cpp +++ b/cpp/unittest/metrics/metrics_test.cpp @@ -15,7 +15,7 @@ #include #include "metrics/Metrics.h" -#include "../db/utils.h" +#include "utils.h" #include "db/DB.h" #include "db/DBMetaImpl.h" #include "db/Factories.h" @@ -24,7 +24,7 @@ using namespace zilliz::milvus; -TEST_F(DBTest, Metric_Tes) { +TEST_F(MetricTest, Metric_Tes) { server::SystemInfo::GetInstance().Init(); // server::Metrics::GetInstance().Init(); diff --git a/cpp/unittest/metrics/prometheus_test.cpp b/cpp/unittest/metrics/prometheus_test.cpp index 885abed5..521e00fc 100644 --- a/cpp/unittest/metrics/prometheus_test.cpp +++ b/cpp/unittest/metrics/prometheus_test.cpp @@ -11,7 +11,7 @@ using namespace zilliz::milvus; -TEST(PrometheusTest, Prometheus_Test){ +TEST(PrometheusTest, PROMETHEUS_TEST){ server::PrometheusMetrics instance = server::PrometheusMetrics::GetInstance(); instance.Init(); instance.SetStartup(true); diff --git a/cpp/unittest/metrics/utils.cpp b/cpp/unittest/metrics/utils.cpp new file mode 100644 index 00000000..81e924a8 --- /dev/null +++ b/cpp/unittest/metrics/utils.cpp @@ -0,0 +1,79 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +// Unauthorized copying of this file, via any medium is strictly prohibited. +// Proprietary and confidential. +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include "utils.h" +#include "db/Factories.h" +#include "db/Options.h" + +INITIALIZE_EASYLOGGINGPP + +using namespace zilliz::milvus; + +static std::string uri; + +class DBTestEnvironment : public ::testing::Environment { +public: + +// explicit DBTestEnvironment(std::string uri) : uri_(uri) {} + + static std::string getURI() { + return uri; + } + + void SetUp() override { + getURI(); + } + +}; + +void ASSERT_STATS(engine::Status& stat) { + ASSERT_TRUE(stat.ok()); + if(!stat.ok()) { + std::cout << stat.ToString() << std::endl; + } +} + + +void MetricTest::InitLog() { + el::Configurations defaultConf; + defaultConf.setToDefault(); + defaultConf.set(el::Level::Debug, + el::ConfigurationType::Format, "[%thread-%datetime-%level]: %msg (%fbase:%line)"); + el::Loggers::reconfigureLogger("default", defaultConf); +} + +engine::Options MetricTest::GetOptions() { + auto options = engine::OptionsFactory::Build(); + options.meta.path = "/tmp/milvus_test"; + options.meta.backend_uri = "sqlite://:@:/"; + return options; +} + +void MetricTest::SetUp() { + InitLog(); + auto options = GetOptions(); + db_ = engine::DBFactory::Build(options); +} + +void MetricTest::TearDown() { + delete db_; + boost::filesystem::remove_all("/tmp/milvus_test"); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + if (argc > 1) { + uri = argv[1]; + } +// std::cout << uri << std::endl; + ::testing::AddGlobalTestEnvironment(new DBTestEnvironment); + return RUN_ALL_TESTS(); +} diff --git a/cpp/unittest/metrics/utils.h b/cpp/unittest/metrics/utils.h new file mode 100644 index 00000000..1badce00 --- /dev/null +++ b/cpp/unittest/metrics/utils.h @@ -0,0 +1,64 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved +// Unauthorized copying of this file, via any medium is strictly prohibited. +// Proprietary and confidential. +//////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +//#include + +#include "db/DB.h" +#include "db/DBMetaImpl.h" +#include "db/MySQLMetaImpl.h" + + +#define TIMING + +#ifdef TIMING +#define INIT_TIMER auto start = std::chrono::high_resolution_clock::now(); +#define START_TIMER start = std::chrono::high_resolution_clock::now(); +#define STOP_TIMER(name) LOG(DEBUG) << "RUNTIME of " << name << ": " << \ + std::chrono::duration_cast( \ + std::chrono::high_resolution_clock::now()-start \ + ).count() << " ms "; +#else +#define INIT_TIMER +#define START_TIMER +#define STOP_TIMER(name) +#endif + +void ASSERT_STATS(zilliz::milvus::engine::Status& stat); + +//class TestEnv : public ::testing::Environment { +//public: +// +// static std::string getURI() { +// if (const char* uri = std::getenv("MILVUS_DBMETA_URI")) { +// return uri; +// } +// else { +// return ""; +// } +// } +// +// void SetUp() override { +// getURI(); +// } +// +//}; +// +//::testing::Environment* const test_env = +// ::testing::AddGlobalTestEnvironment(new TestEnv); + +class MetricTest : public ::testing::Test { +protected: + zilliz::milvus::engine::DB* db_; + + void InitLog(); + virtual void SetUp() override; + virtual void TearDown() override; + virtual zilliz::milvus::engine::Options GetOptions(); +}; \ No newline at end of file -- GitLab