Compare commits
13 Commits
3959067f22
...
1e2fd53b86
Author | SHA1 | Date | |
---|---|---|---|
1e2fd53b86 | |||
ab09407c3d | |||
9b2310a3e7 | |||
56a56e57c8 | |||
7908e7e982 | |||
92b32b838c | |||
65efa8590f | |||
d70aa968d6 | |||
591cd0ad2d | |||
1bdc78e5e0 | |||
7100708dfd | |||
08379ea622 | |||
161208a1fd |
@ -29,6 +29,8 @@ class i_meta_db {
|
||||
INTERFACE_SETUP(i_meta_db);
|
||||
|
||||
public:
|
||||
virtual void clear() = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error = 0;
|
||||
|
@ -27,7 +27,8 @@
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
auto create_meta_db(const app_config &cfg) -> std::unique_ptr<i_meta_db>;
|
||||
[[nodiscard]] auto create_meta_db(const app_config &cfg)
|
||||
-> std::unique_ptr<i_meta_db>;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_DB_META_DB_HPP_
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
auto operator=(rdb_meta_db &&) -> rdb_meta_db & = delete;
|
||||
|
||||
private:
|
||||
const app_config &cfg_;
|
||||
std::unique_ptr<rocksdb::DB> db_{nullptr};
|
||||
rocksdb::ColumnFamilyHandle *default_family_{};
|
||||
rocksdb::ColumnFamilyHandle *pinned_family_{};
|
||||
@ -49,6 +50,8 @@ private:
|
||||
[[nodiscard]] auto create_iterator(rocksdb::ColumnFamilyHandle *family) const
|
||||
-> std::shared_ptr<rocksdb::Iterator>;
|
||||
|
||||
void create_or_open(bool clear);
|
||||
|
||||
[[nodiscard]] auto get_item_meta_json(const std::string &api_path,
|
||||
json &json_data) const -> api_error;
|
||||
|
||||
@ -60,6 +63,8 @@ private:
|
||||
json json_data) -> api_error;
|
||||
|
||||
public:
|
||||
void clear() override;
|
||||
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
@ -48,6 +48,8 @@ private:
|
||||
api_meta_map meta) -> api_error;
|
||||
|
||||
public:
|
||||
void clear() override;
|
||||
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "app_config.hpp"
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
@ -31,10 +32,17 @@ namespace {
|
||||
[[nodiscard]] auto
|
||||
create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
const std::vector<rocksdb::ColumnFamilyDescriptor> &families,
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles)
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles, bool clear)
|
||||
-> std::unique_ptr<rocksdb::DB> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto path = repertory::utils::path::combine(cfg.get_data_directory(), {name});
|
||||
if (clear &&
|
||||
not repertory::utils::file::directory{path}.remove_recursively()) {
|
||||
repertory::utils::error::raise_error(function_name,
|
||||
"failed to remove meta db|" + path);
|
||||
}
|
||||
|
||||
rocksdb::Options options{};
|
||||
options.create_if_missing = true;
|
||||
options.create_missing_column_families = true;
|
||||
@ -42,10 +50,7 @@ create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
options.keep_log_file_num = 10;
|
||||
|
||||
rocksdb::DB *ptr{};
|
||||
auto status = rocksdb::DB::Open(
|
||||
options,
|
||||
repertory::utils::path::combine(cfg.get_data_directory(), {name}),
|
||||
families, &handles, &ptr);
|
||||
auto status = rocksdb::DB::Open(options, path, families, &handles, &ptr);
|
||||
if (not status.ok()) {
|
||||
repertory::utils::error::raise_error(function_name, status.ToString());
|
||||
throw repertory::startup_exception(status.ToString());
|
||||
@ -56,30 +61,34 @@ create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
} // namespace
|
||||
|
||||
namespace repertory {
|
||||
rdb_meta_db::rdb_meta_db(const app_config &cfg) {
|
||||
const auto create_resources = [this, &cfg](const std::string &name) {
|
||||
auto families = std::vector<rocksdb::ColumnFamilyDescriptor>();
|
||||
families.emplace_back(rocksdb::kDefaultColumnFamilyName,
|
||||
rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("pinned", rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("size", rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("source", rocksdb::ColumnFamilyOptions());
|
||||
|
||||
auto handles = std::vector<rocksdb::ColumnFamilyHandle *>();
|
||||
db_ = create_rocksdb(cfg, name, families, handles);
|
||||
|
||||
std::size_t idx{};
|
||||
default_family_ = handles[idx++];
|
||||
pinned_family_ = handles[idx++];
|
||||
size_family_ = handles[idx++];
|
||||
source_family_ = handles[idx++];
|
||||
};
|
||||
|
||||
create_resources("provider_meta");
|
||||
rdb_meta_db::rdb_meta_db(const app_config &cfg) : cfg_(cfg) {
|
||||
create_or_open(false);
|
||||
}
|
||||
|
||||
rdb_meta_db::~rdb_meta_db() { db_.reset(); }
|
||||
|
||||
void rdb_meta_db::create_or_open(bool clear) {
|
||||
db_.reset();
|
||||
|
||||
auto families = std::vector<rocksdb::ColumnFamilyDescriptor>();
|
||||
families.emplace_back(rocksdb::kDefaultColumnFamilyName,
|
||||
rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("pinned", rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("size", rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("source", rocksdb::ColumnFamilyOptions());
|
||||
|
||||
auto handles = std::vector<rocksdb::ColumnFamilyHandle *>();
|
||||
db_ = create_rocksdb(cfg_, "provider_meta", families, handles, clear);
|
||||
|
||||
std::size_t idx{};
|
||||
default_family_ = handles[idx++];
|
||||
pinned_family_ = handles[idx++];
|
||||
size_family_ = handles[idx++];
|
||||
source_family_ = handles[idx++];
|
||||
}
|
||||
|
||||
void rdb_meta_db::clear() { create_or_open(true); }
|
||||
|
||||
auto rdb_meta_db::create_iterator(rocksdb::ColumnFamilyHandle *family) const
|
||||
-> std::shared_ptr<rocksdb::Iterator> {
|
||||
return std::shared_ptr<rocksdb::Iterator>(
|
||||
@ -353,8 +362,8 @@ auto rdb_meta_db::set_item_meta(const std::string &api_path,
|
||||
return update_item_meta(api_path, json_data);
|
||||
}
|
||||
|
||||
auto rdb_meta_db::update_item_meta(const std::string &api_path,
|
||||
json json_data) -> api_error {
|
||||
auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data)
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
|
@ -55,6 +55,18 @@ sqlite_meta_db::sqlite_meta_db(const app_config &cfg) {
|
||||
|
||||
sqlite_meta_db::~sqlite_meta_db() { db_.reset(); }
|
||||
|
||||
void sqlite_meta_db::clear() {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto result = utils::db::sqlite::db_delete{*db_, table_name}.go();
|
||||
if (result.ok()) {
|
||||
return;
|
||||
}
|
||||
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to clear meta db|" + result.get_error());
|
||||
}
|
||||
|
||||
auto sqlite_meta_db::get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const -> api_error {
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
|
@ -435,7 +435,7 @@ auto base_provider::is_file_writeable(const std::string &api_path) const
|
||||
|
||||
void base_provider::process_removed_directories(
|
||||
std::deque<removed_item> removed_list, const stop_type &stop_requested) {
|
||||
for (auto &&item : removed_list) {
|
||||
for (const auto &item : removed_list) {
|
||||
if (stop_requested) {
|
||||
return;
|
||||
}
|
||||
@ -456,7 +456,7 @@ void base_provider::process_removed_files(std::deque<removed_item> removed_list,
|
||||
|
||||
auto orphaned_directory =
|
||||
utils::path::combine(config_.get_data_directory(), {"orphaned"});
|
||||
for (auto &&item : removed_list) {
|
||||
for (const auto &item : removed_list) {
|
||||
if (stop_requested) {
|
||||
return;
|
||||
}
|
||||
@ -535,9 +535,11 @@ void base_provider::process_removed_items(const stop_type &stop_requested) {
|
||||
return;
|
||||
}
|
||||
|
||||
// process_removed_directories({
|
||||
// removed_item{api_path, true, ""},
|
||||
// }, stop_requested2);
|
||||
process_removed_directories(
|
||||
{
|
||||
removed_item{api_path, true, ""},
|
||||
},
|
||||
stop_requested2);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -667,7 +669,7 @@ void base_provider::remove_unmatched_source_files(
|
||||
|
||||
auto source_list =
|
||||
utils::file::directory{config_.get_cache_directory()}.get_files();
|
||||
for (auto &&source_file : source_list) {
|
||||
for (const auto &source_file : source_list) {
|
||||
if (stop_requested) {
|
||||
return;
|
||||
}
|
||||
|
@ -32,12 +32,10 @@ void tasks::schedule(task_item task) {
|
||||
notify_.wait(lock);
|
||||
}
|
||||
|
||||
if (stop_requested_) {
|
||||
notify_.notify_all();
|
||||
return;
|
||||
if (not stop_requested_) {
|
||||
tasks_.push_back(std::move(task));
|
||||
}
|
||||
|
||||
tasks_.push_back(std::move(task));
|
||||
notify_.notify_all();
|
||||
}
|
||||
|
||||
|
@ -83,17 +83,6 @@ TYPED_TEST(meta_db_test,
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, set_item_meta_fails_with_missing_directory_meta) {
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(api_error::error, this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_SOURCE, test_source},
|
||||
}));
|
||||
EXPECT_EQ(api_error::error,
|
||||
this->meta_db->set_item_meta(test_file, META_SOURCE, test_source));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_api_file_list) {
|
||||
std::vector<std::string> directories{};
|
||||
for (auto idx = 0U; idx < 5U; ++idx) {
|
||||
@ -129,6 +118,27 @@ TYPED_TEST(meta_db_test, can_get_api_file_list) {
|
||||
}
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test,
|
||||
full_get_item_meta_returns_item_not_found_if_item_does_not_exist) {
|
||||
auto api_path = create_test_file();
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
this->meta_db->get_item_meta(api_path, meta));
|
||||
EXPECT_TRUE(meta.empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(
|
||||
meta_db_test,
|
||||
individual_get_item_meta_returns_item_not_found_if_item_does_not_exist) {
|
||||
auto api_path = create_test_file();
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
this->meta_db->get_item_meta(api_path, META_DIRECTORY, value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_full_item_meta_for_directory) {
|
||||
auto api_path = create_test_file();
|
||||
auto source_path = create_test_file();
|
||||
@ -169,4 +179,440 @@ TYPED_TEST(meta_db_test, can_get_full_item_meta_for_file) {
|
||||
EXPECT_EQ(2ULL, utils::string::to_uint64(meta[META_SIZE]));
|
||||
EXPECT_STREQ(source_path.c_str(), meta[META_SOURCE].c_str());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_individual_item_meta_for_directory) {
|
||||
auto api_path = create_test_file();
|
||||
auto source_path = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
api_path, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_PINNED, utils::string::from_bool(true)},
|
||||
{META_SIZE, std::to_string(2ULL)},
|
||||
{META_SOURCE, source_path},
|
||||
}));
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_DIRECTORY, value));
|
||||
EXPECT_TRUE(utils::string::to_bool(value));
|
||||
}
|
||||
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_PINNED, value));
|
||||
EXPECT_FALSE(utils::string::to_bool(value));
|
||||
}
|
||||
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_SIZE, value));
|
||||
EXPECT_EQ(0ULL, utils::string::to_uint64(value));
|
||||
}
|
||||
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_SOURCE, value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_individual_item_meta_for_file) {
|
||||
auto api_path = create_test_file();
|
||||
auto source_path = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
api_path, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_PINNED, utils::string::from_bool(true)},
|
||||
{META_SIZE, std::to_string(2ULL)},
|
||||
{META_SOURCE, source_path},
|
||||
}));
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_DIRECTORY, value));
|
||||
EXPECT_FALSE(utils::string::to_bool(value));
|
||||
}
|
||||
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_PINNED, value));
|
||||
EXPECT_TRUE(utils::string::to_bool(value));
|
||||
}
|
||||
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_SIZE, value));
|
||||
EXPECT_EQ(2ULL, utils::string::to_uint64(value));
|
||||
}
|
||||
|
||||
{
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->get_item_meta(api_path, META_SOURCE, value));
|
||||
EXPECT_STREQ(source_path.c_str(), value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_pinned_files) {
|
||||
std::vector<std::string> pinned_files{};
|
||||
std::vector<std::string> unpinned_files{};
|
||||
for (auto idx = 0U; idx < 20U; ++idx) {
|
||||
auto test_file = create_test_file();
|
||||
auto pinned = idx % 2U == 0U;
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_PINNED, utils::string::from_bool(pinned)},
|
||||
}));
|
||||
if (pinned) {
|
||||
pinned_files.push_back(test_file);
|
||||
continue;
|
||||
}
|
||||
unpinned_files.push_back(test_file);
|
||||
}
|
||||
|
||||
auto pinned = this->meta_db->get_pinned_files();
|
||||
EXPECT_GE(pinned.size(), pinned_files.size());
|
||||
for (const auto &api_path : pinned_files) {
|
||||
EXPECT_TRUE(utils::collection::includes(pinned, api_path));
|
||||
}
|
||||
|
||||
for (const auto &api_path : unpinned_files) {
|
||||
EXPECT_TRUE(utils::collection::excludes(pinned, api_path));
|
||||
}
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_total_item_count) {
|
||||
this->meta_db->clear();
|
||||
EXPECT_EQ(0U, this->meta_db->get_total_item_count());
|
||||
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
}));
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
}));
|
||||
|
||||
EXPECT_EQ(2U, this->meta_db->get_total_item_count());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test,
|
||||
get_total_item_count_decreases_after_directory_is_removed) {
|
||||
this->meta_db->clear();
|
||||
EXPECT_EQ(0U, this->meta_db->get_total_item_count());
|
||||
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
}));
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
}));
|
||||
|
||||
this->meta_db->remove_api_path(test_dir);
|
||||
EXPECT_EQ(1U, this->meta_db->get_total_item_count());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, get_total_item_count_decreases_after_file_is_removed) {
|
||||
this->meta_db->clear();
|
||||
EXPECT_EQ(0U, this->meta_db->get_total_item_count());
|
||||
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
}));
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
}));
|
||||
|
||||
this->meta_db->remove_api_path(test_file);
|
||||
EXPECT_EQ(1U, this->meta_db->get_total_item_count());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_get_total_size) {
|
||||
this->meta_db->clear();
|
||||
EXPECT_EQ(0U, this->meta_db->get_total_item_count());
|
||||
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "2"},
|
||||
}));
|
||||
|
||||
test_file = create_test_file();
|
||||
test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "1"},
|
||||
}));
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_SIZE, "7"},
|
||||
}));
|
||||
|
||||
EXPECT_EQ(3U, this->meta_db->get_total_size());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test,
|
||||
total_size_does_not_decrease_after_directory_is_removed) {
|
||||
this->meta_db->clear();
|
||||
EXPECT_EQ(0U, this->meta_db->get_total_item_count());
|
||||
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "2"},
|
||||
}));
|
||||
|
||||
test_file = create_test_file();
|
||||
test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "1"},
|
||||
}));
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_SIZE, "7"},
|
||||
}));
|
||||
this->meta_db->remove_api_path(test_dir);
|
||||
|
||||
EXPECT_EQ(3U, this->meta_db->get_total_size());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, total_size_decreases_after_file_is_removed) {
|
||||
this->meta_db->clear();
|
||||
EXPECT_EQ(0U, this->meta_db->get_total_item_count());
|
||||
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "2"},
|
||||
}));
|
||||
|
||||
test_file = create_test_file();
|
||||
test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "1"},
|
||||
}));
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_SIZE, "7"},
|
||||
}));
|
||||
this->meta_db->remove_api_path(test_file);
|
||||
|
||||
EXPECT_EQ(2U, this->meta_db->get_total_size());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_remove_api_path) {
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "2"},
|
||||
}));
|
||||
this->meta_db->remove_api_path(test_file);
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
this->meta_db->get_item_meta(test_file, meta));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_rename_item_meta) {
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
{META_SOURCE, test_source},
|
||||
{META_SIZE, "2"},
|
||||
}));
|
||||
auto test_file2 = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->rename_item_meta(test_file, test_file2));
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
this->meta_db->get_item_meta(test_file, meta));
|
||||
|
||||
EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(test_file2, meta));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, rename_item_meta_fails_if_not_found) {
|
||||
auto test_file = create_test_file();
|
||||
auto test_file2 = create_test_file();
|
||||
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
this->meta_db->rename_item_meta(test_file, test_file2));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, set_item_meta_fails_with_missing_directory_meta) {
|
||||
auto test_file = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(api_error::error, this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_SOURCE, test_source},
|
||||
}));
|
||||
EXPECT_EQ(api_error::error,
|
||||
this->meta_db->set_item_meta(test_file, META_SOURCE, test_source));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, check_size_is_ignored_for_directory) {
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_SIZE, "2"},
|
||||
}));
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(test_dir, meta));
|
||||
EXPECT_EQ(0U, utils::string::to_uint64(meta[META_SIZE]));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, check_pinned_is_ignored_for_directory) {
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_PINNED, utils::string::from_bool(true)},
|
||||
}));
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(test_dir, meta));
|
||||
EXPECT_FALSE(utils::string::to_bool(meta[META_PINNED]));
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, check_source_is_ignored_for_directory) {
|
||||
auto test_dir = create_test_file();
|
||||
auto test_source = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
{META_SOURCE, test_source},
|
||||
}));
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(test_dir, meta));
|
||||
EXPECT_TRUE(meta[META_SOURCE].empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, check_set_item_meta_directory_defaults) {
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
}));
|
||||
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(test_dir, meta));
|
||||
|
||||
EXPECT_TRUE(utils::string::to_bool(meta[META_DIRECTORY]));
|
||||
EXPECT_FALSE(utils::string::to_bool(meta[META_PINNED]));
|
||||
EXPECT_EQ(0U, utils::string::to_uint64(meta[META_SIZE]));
|
||||
EXPECT_TRUE(meta[META_SOURCE].empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, check_set_item_meta_file_defaults) {
|
||||
auto test_file = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
}));
|
||||
api_meta_map meta;
|
||||
EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(test_file, meta));
|
||||
|
||||
EXPECT_FALSE(utils::string::to_bool(meta[META_DIRECTORY]));
|
||||
EXPECT_FALSE(utils::string::to_bool(meta[META_PINNED]));
|
||||
EXPECT_EQ(0U, utils::string::to_uint64(meta[META_SIZE]));
|
||||
EXPECT_TRUE(meta[META_SOURCE].empty());
|
||||
}
|
||||
} // namespace repertory
|
||||
|
Reference in New Issue
Block a user