mirror of https://github.com/milvus-io/milvus.git
add unit test
Former-commit-id: 7807128ae39dd66c812fa254be840d2c4c7a364epull/191/head
parent
941e4dc83c
commit
d804bed0f5
|
@ -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"
|
||||
|
@ -251,3 +254,30 @@ TEST(UtilTest, TIMERECORDER_TEST) {
|
|||
rc.RecordSection("end");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue