file mgr db unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
55a88e7576
commit
8c9c7254b4
@ -28,7 +28,6 @@
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] auto
|
||||
@ -101,7 +100,21 @@ auto rdb_file_mgr_db::add_resume(resume_entry entry) -> bool {
|
||||
});
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::add_upload(upload_entry entry) -> bool {}
|
||||
auto rdb_file_mgr_db::add_upload(upload_entry entry) -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
return perform_action(function_name, [this, &entry]() -> rocksdb::Status {
|
||||
auto data = json({
|
||||
{"date_time", entry.date_time},
|
||||
{"source_path", entry.source_path},
|
||||
});
|
||||
|
||||
return db_->Put(rocksdb::WriteOptions{}, upload_family_,
|
||||
utils::string::zero_pad(std::to_string(++id_), 19U) + '|' +
|
||||
entry.api_path,
|
||||
data.dump());
|
||||
});
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::add_upload_active(upload_active_entry entry) -> bool {}
|
||||
|
||||
@ -136,7 +149,28 @@ auto rdb_file_mgr_db::get_resume_list() const -> std::vector<resume_entry> {
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::get_upload(const std::string &api_path) const
|
||||
-> std::optional<upload_entry> {}
|
||||
-> std::optional<upload_entry> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
auto iter = create_iterator(upload_family_);
|
||||
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
auto parts = utils::string::split(iter->key().ToString(), '|', false);
|
||||
parts.erase(parts.begin());
|
||||
|
||||
if (api_path != utils::string::join(parts, '|')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto data = json::parse(iter->value().ToString());
|
||||
return upload_entry{
|
||||
api_path,
|
||||
data.at("date_time").get<std::uint64_t>(),
|
||||
data.at("source_path").get<std::string>(),
|
||||
};
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::get_upload_active_list() const
|
||||
-> std::vector<upload_active_entry> {}
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "fixtures/file_mgr_db_fixture.hpp"
|
||||
#include <utils/time.hpp>
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(file_mgr_db_test, file_mgr_db_types);
|
||||
@ -113,4 +114,50 @@ TYPED_TEST(file_mgr_db_test, can_rename_resume) {
|
||||
|
||||
EXPECT_TRUE(this->file_mgr_db->remove_resume("/test1"));
|
||||
}
|
||||
|
||||
TYPED_TEST(file_mgr_db_test, can_add_get_and_remove_upload) {
|
||||
this->file_mgr_db->clear();
|
||||
EXPECT_TRUE(this->file_mgr_db->add_upload({
|
||||
"/test0",
|
||||
2ULL,
|
||||
"/src/test0",
|
||||
}));
|
||||
|
||||
auto upload = this->file_mgr_db->get_upload("/test0");
|
||||
EXPECT_TRUE(upload.has_value());
|
||||
|
||||
EXPECT_TRUE(this->file_mgr_db->remove_upload("/test0"));
|
||||
|
||||
upload = this->file_mgr_db->get_next_upload();
|
||||
EXPECT_FALSE(upload.has_value());
|
||||
}
|
||||
|
||||
TYPED_TEST(file_mgr_db_test, uploads_are_correctly_ordered) {
|
||||
this->file_mgr_db->clear();
|
||||
EXPECT_TRUE(this->file_mgr_db->add_upload({
|
||||
"/test08",
|
||||
utils::time::get_time_now(),
|
||||
"/src/test0",
|
||||
}));
|
||||
|
||||
EXPECT_TRUE(this->file_mgr_db->add_upload({
|
||||
"/test07",
|
||||
utils::time::get_time_now(),
|
||||
"/src/test1",
|
||||
}));
|
||||
|
||||
auto upload = this->file_mgr_db->get_next_upload();
|
||||
EXPECT_TRUE(upload.has_value());
|
||||
EXPECT_STREQ("/test08", upload->api_path.c_str());
|
||||
|
||||
EXPECT_TRUE(this->file_mgr_db->remove_upload("/test08"));
|
||||
upload = this->file_mgr_db->get_next_upload();
|
||||
EXPECT_TRUE(upload.has_value());
|
||||
EXPECT_STREQ("/test07", upload->api_path.c_str());
|
||||
|
||||
EXPECT_TRUE(this->file_mgr_db->remove_upload("/test07"));
|
||||
|
||||
upload = this->file_mgr_db->get_next_upload();
|
||||
EXPECT_FALSE(upload.has_value());
|
||||
}
|
||||
} // namespace repertory
|
||||
|
Loading…
x
Reference in New Issue
Block a user