提交 ef3daec8 编写于 作者: J jinhai

Merge branch 'add_unitest' into 'branch-0.4.0'

MS-119 The problem of combining the log files

See merge request megasearch/milvus!546

Former-commit-id: 41327d3c5aaeaf25aa01922bed7e4dadfe19688c
......@@ -27,7 +27,7 @@ static int fatal_idx = 0;
}
// TODO(yzb) : change the easylogging library to get the log level from parameter rather than filename
void rolloutHandler(const char *filename, std::size_t size) {
void RolloutHandler(const char *filename, std::size_t size) {
char *dirc = strdup(filename);
char *basec = strdup(filename);
char *dir = dirname(dirc);
......@@ -112,7 +112,7 @@ int32_t InitLog(const std::string &log_config_file) {
el::Loggers::reconfigureAllLoggers(conf);
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
el::Helpers::installPreRollOutCallback(rolloutHandler);
el::Helpers::installPreRollOutCallback(RolloutHandler);
return 0;
}
......
......@@ -16,6 +16,7 @@ inline std::string GetFileName(std::string filename) {
int pos = filename.find_last_of('/');
return filename.substr(pos + 1);
}
void RolloutHandler(const char *filename, std::size_t size);
#define SHOW_LOCATION
#ifdef SHOW_LOCATION
......
......@@ -6,6 +6,9 @@
#include <gtest/gtest.h>
#include <thread>
#include <easylogging++.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include "utils/CommonUtil.h"
#include "utils/Error.h"
......@@ -282,3 +285,30 @@ TEST(ValidationUtilTest, VALIDATE_DBURI_TEST) {
ASSERT_EQ(server::ValidationUtil::ValidateDbURI("mysql://root:123456@127.0.0.1:3303/milvus"), SERVER_SUCCESS);
ASSERT_NE(server::ValidationUtil::ValidateDbURI("mysql://root:123456@127.0.0.1:port/milvus"), SERVER_SUCCESS);
}
TEST(UtilTest, ROLLOUTHANDLER_TEST){
std::string dir1 = "/tmp/milvus_test";
std::string dir2 = "/tmp/milvus_test/log_test";
std::string filename[6] = {"log_global.log", "log_debug.log", "log_warning.log", "log_trace.log", "log_error.log", "log_fatal.log"};
mkdir(dir1.c_str(), S_IRWXU);
mkdir(dir2.c_str(), S_IRWXU);
for (int i = 0; i < 6; ++i) {
std::string tmp = dir2 + "/" + filename[i];
std::ofstream file;
file.open(tmp.c_str());
file << "zilliz" << std::endl;
server::RolloutHandler(tmp.c_str(), 0);
tmp.append(".1");
std::ifstream file2;
file2.open(tmp);
std::string tmp2;
file2 >> tmp2;
ASSERT_EQ(tmp2, "zilliz");
}
boost::filesystem::remove_all(dir2);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册