提交 b47abd51 编写于 作者: S starlord

add unitest case


Former-commit-id: 2bb2413e846d69ee768be4f41de0f0d7f9bf300d
上级 3d20ee2c
......@@ -135,7 +135,7 @@ Status GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& tab
}
}
std::string msg = "Table file doesn't exist: " + table_file.file_id_;
std::string msg = "Table file doesn't exist: " + file_path;
ENGINE_LOG_ERROR << msg;
return Status(DB_ERROR, msg);
}
......
......@@ -814,7 +814,6 @@ Status MySQLMetaImpl::CreateTableFile(TableFileSchema &file_schema) {
file_schema.engine_type_ = table_schema.engine_type_;
file_schema.nlist_ = table_schema.nlist_;
file_schema.metric_type_ = table_schema.metric_type_;
utils::GetTableFilePath(options_, file_schema);
std::string id = "NULL"; //auto-increment
std::string table_id = file_schema.table_id_;
......@@ -924,7 +923,10 @@ Status MySQLMetaImpl::FilesToIndex(TableFilesSchema &files) {
table_file.nlist_ = groups[table_file.table_id_].nlist_;
table_file.metric_type_ = groups[table_file.table_id_].metric_type_;
utils::GetTableFilePath(options_, table_file);
auto status = utils::GetTableFilePath(options_, table_file);
if(!status.ok()) {
return status;
}
files.push_back(table_file);
}
......@@ -1027,7 +1029,10 @@ Status MySQLMetaImpl::FilesToSearch(const std::string &table_id,
table_file.dimension_ = table_schema.dimension_;
utils::GetTableFilePath(options_, table_file);
auto status = utils::GetTableFilePath(options_, table_file);
if(!status.ok()) {
return status;
}
auto dateItr = files.find(table_file.date_);
if (dateItr == files.end()) {
......@@ -1113,7 +1118,10 @@ Status MySQLMetaImpl::FilesToMerge(const std::string &table_id,
table_file.dimension_ = table_schema.dimension_;
utils::GetTableFilePath(options_, table_file);
auto status = utils::GetTableFilePath(options_, table_file);
if(!status.ok()) {
return status;
}
auto dateItr = files.find(table_file.date_);
if (dateItr == files.end()) {
......@@ -1203,7 +1211,10 @@ Status MySQLMetaImpl::GetTableFiles(const std::string &table_id,
file_schema.dimension_ = table_schema.dimension_;
utils::GetTableFilePath(options_, file_schema);
auto status = utils::GetTableFilePath(options_, file_schema);
if(!status.ok()) {
return status;
}
table_files.emplace_back(file_schema);
}
......
......@@ -614,7 +614,10 @@ Status SqliteMetaImpl::FilesToIndex(TableFilesSchema &files) {
table_file.engine_type_ = std::get<7>(file);
table_file.created_on_ = std::get<8>(file);
utils::GetTableFilePath(options_, table_file);
auto status = utils::GetTableFilePath(options_, table_file);
if(!status.ok()) {
return status;
}
auto groupItr = groups.find(table_file.table_id_);
if (groupItr == groups.end()) {
TableSchema table_schema;
......@@ -707,7 +710,11 @@ Status SqliteMetaImpl::FilesToSearch(const std::string &table_id,
table_file.nlist_ = table_schema.nlist_;
table_file.metric_type_ = table_schema.metric_type_;
utils::GetTableFilePath(options_, table_file);
auto status = utils::GetTableFilePath(options_, table_file);
if(!status.ok()) {
return status;
}
auto dateItr = files.find(table_file.date_);
if (dateItr == files.end()) {
files[table_file.date_] = TableFilesSchema();
......@@ -773,7 +780,11 @@ Status SqliteMetaImpl::FilesToMerge(const std::string &table_id,
table_file.nlist_ = table_schema.nlist_;
table_file.metric_type_ = table_schema.metric_type_;
utils::GetTableFilePath(options_, table_file);
auto status = utils::GetTableFilePath(options_, table_file);
if(!status.ok()) {
return status;
}
auto dateItr = files.find(table_file.date_);
if (dateItr == files.end()) {
files[table_file.date_] = TableFilesSchema();
......@@ -827,7 +838,10 @@ Status SqliteMetaImpl::GetTableFiles(const std::string& table_id,
file_schema.nlist_ = table_schema.nlist_;
file_schema.metric_type_ = table_schema.metric_type_;
utils::GetTableFilePath(options_, file_schema);
auto status = utils::GetTableFilePath(options_, file_schema);
if(!status.ok()) {
return status;
}
table_files.emplace_back(file_schema);
}
......
......@@ -315,6 +315,79 @@ TEST_F(DBTest, PRELOADTABLE_TEST) {
}
TEST_F(DBTest, SHUTDOWN_TEST) {
db_->Stop();
engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info);
ASSERT_FALSE(stat.ok());
stat = db_->DescribeTable(table_info);
ASSERT_FALSE(stat.ok());
bool has_table = false;
stat = db_->HasTable(table_info.table_id_, has_table);
ASSERT_FALSE(stat.ok());
engine::IDNumbers ids;
stat = db_->InsertVectors(table_info.table_id_, 0, nullptr, ids);
ASSERT_FALSE(stat.ok());
stat = db_->PreloadTable(table_info.table_id_);
ASSERT_FALSE(stat.ok());
uint64_t row_count = 0;
stat = db_->GetTableRowCount(table_info.table_id_, row_count);
ASSERT_FALSE(stat.ok());
engine::TableIndex index;
stat = db_->CreateIndex(table_info.table_id_, index);
ASSERT_FALSE(stat.ok());
stat = db_->DescribeIndex(table_info.table_id_, index);
ASSERT_FALSE(stat.ok());
engine::meta::DatesT dates;
engine::QueryResults results;
stat = db_->Query(table_info.table_id_, 1, 1, 1, nullptr, dates, results);
ASSERT_FALSE(stat.ok());
std::vector<std::string> file_ids;
stat = db_->Query(table_info.table_id_, file_ids, 1, 1, 1, nullptr, dates, results);
ASSERT_FALSE(stat.ok());
stat = db_->DeleteTable(table_info.table_id_, dates);
ASSERT_FALSE(stat.ok());
}
TEST_F(DBTest, INDEX_TEST) {
engine::meta::TableSchema table_info = BuildTableSchema();
engine::Status stat = db_->CreateTable(table_info);
int64_t nb = VECTOR_COUNT;
std::vector<float> xb;
BuildVectors(nb, xb);
engine::IDNumbers vector_ids;
db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
ASSERT_EQ(vector_ids.size(), nb);
engine::TableIndex index;
index.engine_type_ = (int)engine::EngineType::FAISS_IVFSQ8;
index.metric_type_ = (int)engine::MetricType::IP;
stat = db_->CreateIndex(table_info.table_id_, index);
ASSERT_TRUE(stat.ok());
engine::TableIndex index_out;
stat = db_->DescribeIndex(table_info.table_id_, index);
ASSERT_TRUE(stat.ok());
ASSERT_EQ(index.engine_type_, index_out.engine_type_);
ASSERT_EQ(index.nlist_, index_out.nlist_);
ASSERT_EQ(index.metric_type_, index_out.metric_type_);
stat = db_->DropIndex(table_info.table_id_);
ASSERT_TRUE(stat.ok());
}
TEST_F(DBTest2, ARHIVE_DISK_CHECK) {
engine::meta::TableSchema table_info = BuildTableSchema();
......
......@@ -5,6 +5,7 @@
////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include <thread>
#include <easylogging++.h>
#include "utils/CommonUtil.h"
#include "utils/Error.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册