Skip to content

Commit

Permalink
Add test cases for partially implemented read and write operations of…
Browse files Browse the repository at this point in the history
… BLOB log_entry
  • Loading branch information
umegane committed Jan 21, 2025
1 parent 5198eef commit 74b19cb
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 64 deletions.
50 changes: 50 additions & 0 deletions test/limestone/log/log_channel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <map>
#include <unistd.h>
#include "internal.h"
#include "log_entry.h"
#include "test_root.h"
#include "limestone/api/epoch_id_type.h"

#define LOGFORMAT_VER 2

Expand Down Expand Up @@ -217,4 +219,52 @@ TEST_F(log_channel_test, truncate_storage) {
EXPECT_EQ(m["42-120"], "v3"); // after truncate
}

TEST_F(log_channel_test, write_blob_entry) {
const limestone::api::epoch_id_type epoch_id = 31415;
const limestone::api::storage_id_type storage_id = 12345;
const std::string key = "this is a key";
const std::string value = "this is a value";
const limestone::api::write_version_type write_version = limestone::api::write_version_type(67898, 76543);
const std::vector<limestone::api::blob_id_type> large_objects = {314, 1592, 65358};


limestone::api::log_channel& channel = datastore_->create_channel(boost::filesystem::path(location));
datastore_->ready();
datastore_->switch_epoch(epoch_id);

channel.begin_session();
channel.add_entry(storage_id, key, value, write_version, large_objects);
channel.end_session();

limestone::api::log_entry log_entry_begin_;
limestone::api::log_entry log_entry_normal_with_blob_;
boost::filesystem::ifstream istrm;
istrm.open(boost::filesystem::path(location) / "pwal_0000", std::ios_base::in | std::ios_base::binary);
EXPECT_TRUE(log_entry_begin_.read(istrm));
EXPECT_TRUE(log_entry_normal_with_blob_.read(istrm));
istrm.close();

EXPECT_EQ(log_entry_begin_.type(), limestone::api::log_entry::entry_type::marker_begin);
EXPECT_EQ(log_entry_begin_.epoch_id(), epoch_id);

EXPECT_EQ(log_entry_normal_with_blob_.type(), limestone::api::log_entry::entry_type::normal_with_blob);
EXPECT_EQ(log_entry_normal_with_blob_.storage(), storage_id);

std::string buf_key;
log_entry_normal_with_blob_.key(buf_key);
EXPECT_EQ(buf_key, key);

std::string buf_value;
log_entry_normal_with_blob_.value(buf_value);
EXPECT_EQ(buf_value, value);

limestone::api::write_version_type buf_version;
log_entry_normal_with_blob_.write_version(buf_version);
EXPECT_EQ(buf_version, write_version);

EXPECT_EQ(log_entry_normal_with_blob_.large_objects(), large_objects);
}



} // namespace limestone::testing
129 changes: 65 additions & 64 deletions test/limestone/log/log_entry_type_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class log_entry_type_test : public ::testing::Test {
protected:
const std::string key = "this is a key";
const std::string value = "this is a value";
const std::string key2 = "this is a key2";
const std::string value2 = "this is a value2";
const std::vector<limestone::api::blob_id_type> large_objects = {314, 1592, 65358};
const limestone::api::storage_id_type storage_id = 12345;
const limestone::api::write_version_type write_version = limestone::api::write_version_type(67898, 76543);
const limestone::api::write_version_type write_version2 = limestone::api::write_version_type(2236, 1732);
const limestone::api::epoch_id_type epoch_id = 56873;

virtual void SetUp() {
Expand All @@ -53,58 +57,83 @@ class log_entry_type_test : public ::testing::Test {

limestone::api::log_entry log_entry_begin_{};
limestone::api::log_entry log_entry_normal_{};
limestone::api::log_entry log_entry_normal_with_blob_{};
limestone::api::log_entry log_entry_end_{};
boost::filesystem::path file1_{};
boost::filesystem::path file2_{};
};

TEST_F(log_entry_type_test, write_and_read) {
limestone::api::log_entry log_entry;
void write_log_entries(const boost::filesystem::path& file_path) {
FILE* ostrm = fopen(file_path.c_str(), "a");
limestone::api::log_entry::begin_session(ostrm, epoch_id);
limestone::api::log_entry::write(ostrm, storage_id, key, value, write_version);
limestone::api::log_entry::write_with_blob(ostrm, storage_id, key2, value2, write_version2, large_objects);
limestone::api::log_entry::end_session(ostrm, epoch_id + 1);
fclose(ostrm);
}

FILE *ostrm = fopen(file1_.c_str(), "a");
limestone::api::log_entry::begin_session(ostrm, epoch_id);
limestone::api::log_entry::write(ostrm, storage_id, key, value, write_version);
limestone::api::log_entry::end_session(ostrm, epoch_id + 1);
fclose(ostrm);
void verify_log_entries(const boost::filesystem::path& file_path) {
limestone::api::log_entry log_entry;
boost::filesystem::ifstream istrm;
istrm.open(file_path, std::ios_base::in | std::ios_base::binary);

boost::filesystem::ifstream istrm;
istrm.open(file1_, std::ios_base::in | std::ios_base::binary);
EXPECT_TRUE(log_entry_begin_.read(istrm));
EXPECT_TRUE(log_entry_normal_.read(istrm));
EXPECT_TRUE(log_entry_end_.read(istrm));
EXPECT_FALSE(log_entry.read(istrm));
istrm.close();
EXPECT_TRUE(log_entry_begin_.read(istrm));
EXPECT_TRUE(log_entry_normal_.read(istrm));
EXPECT_TRUE(log_entry_normal_with_blob_.read(istrm));
EXPECT_TRUE(log_entry_end_.read(istrm));
EXPECT_FALSE(log_entry.read(istrm));
istrm.close();

EXPECT_EQ(log_entry_begin_.type(), limestone::api::log_entry::entry_type::marker_begin);
EXPECT_EQ(log_entry_begin_.epoch_id(), epoch_id);
EXPECT_EQ(log_entry_begin_.type(), limestone::api::log_entry::entry_type::marker_begin);
EXPECT_EQ(log_entry_begin_.epoch_id(), epoch_id);

EXPECT_EQ(log_entry_normal_.type(), limestone::api::log_entry::entry_type::normal_entry);
EXPECT_EQ(log_entry_normal_.storage(), storage_id);
EXPECT_EQ(log_entry_normal_.type(), limestone::api::log_entry::entry_type::normal_entry);
EXPECT_EQ(log_entry_normal_.storage(), storage_id);

std::string buf_key;
log_entry_normal_.key(buf_key);
EXPECT_EQ(buf_key, key);
std::string buf_key;
log_entry_normal_.key(buf_key);
EXPECT_EQ(buf_key, key);

std::string buf_value;
log_entry_normal_.value(buf_value);
EXPECT_EQ(buf_value, value);
std::string buf_value;
log_entry_normal_.value(buf_value);
EXPECT_EQ(buf_value, value);

limestone::api::write_version_type buf_version;
log_entry_normal_.write_version(buf_version);
EXPECT_EQ(buf_version, write_version);
limestone::api::write_version_type buf_version;
log_entry_normal_.write_version(buf_version);
EXPECT_EQ(buf_version, write_version);

EXPECT_EQ(log_entry_end_.type(), limestone::api::log_entry::entry_type::marker_end);
EXPECT_EQ(log_entry_end_.epoch_id(), epoch_id + 1);
EXPECT_EQ(log_entry_normal_with_blob_.type(), limestone::api::log_entry::entry_type::normal_with_blob);
EXPECT_EQ(log_entry_normal_with_blob_.storage(), storage_id);

std::string buf_key2;
log_entry_normal_with_blob_.key(buf_key2);
EXPECT_EQ(buf_key2, key2);

std::string buf_value2;
log_entry_normal_with_blob_.value(buf_value2);
EXPECT_EQ(buf_value2, value2);

limestone::api::write_version_type buf_version2;
log_entry_normal_with_blob_.write_version(buf_version2);
EXPECT_EQ(buf_version2, write_version2);

EXPECT_EQ(log_entry_normal_with_blob_.large_objects(), large_objects);

EXPECT_EQ(log_entry_end_.type(), limestone::api::log_entry::entry_type::marker_end);
EXPECT_EQ(log_entry_end_.epoch_id(), epoch_id + 1);
}
};

TEST_F(log_entry_type_test, write_and_read) {
limestone::api::log_entry log_entry;

write_log_entries(file1_);
verify_log_entries(file1_);
}

TEST_F(log_entry_type_test, write_and_read_and_write_and_read) {
limestone::api::log_entry log_entry;

FILE* ostrm = fopen(file1_.c_str(), "a");
limestone::api::log_entry::begin_session(ostrm, epoch_id);
limestone::api::log_entry::write(ostrm, storage_id, key, value, write_version);
limestone::api::log_entry::end_session(ostrm, epoch_id + 1);
fclose(ostrm);
write_log_entries(file1_);

boost::filesystem::ifstream istrm;
istrm.open(file1_, std::ios_base::in | std::ios_base::binary);
Expand All @@ -115,35 +144,7 @@ TEST_F(log_entry_type_test, write_and_read_and_write_and_read) {
istrm.close();
fclose(ostrm2);

boost::filesystem::ifstream istrm2;
istrm2.open(file2_, std::ios_base::in | std::ios_base::binary);
EXPECT_TRUE(log_entry_begin_.read(istrm2));
EXPECT_TRUE(log_entry_normal_.read(istrm2));
EXPECT_TRUE(log_entry_end_.read(istrm2));
EXPECT_FALSE(log_entry.read(istrm2));
istrm2.close();


EXPECT_EQ(log_entry_begin_.type(), limestone::api::log_entry::entry_type::marker_begin);
EXPECT_EQ(log_entry_begin_.epoch_id(), epoch_id);

EXPECT_EQ(log_entry_normal_.type(), limestone::api::log_entry::entry_type::normal_entry);
EXPECT_EQ(log_entry_normal_.storage(), storage_id);

std::string buf_key;
log_entry_normal_.key(buf_key);
EXPECT_EQ(buf_key, key);

std::string buf_value;
log_entry_normal_.value(buf_value);
EXPECT_EQ(buf_value, value);

limestone::api::write_version_type buf_version;
log_entry_normal_.write_version(buf_version);
EXPECT_EQ(buf_version, write_version);

EXPECT_EQ(log_entry_end_.type(), limestone::api::log_entry::entry_type::marker_end);
EXPECT_EQ(log_entry_end_.epoch_id(), epoch_id + 1);
verify_log_entries(file2_);
}

} // namespace limestone::testing

0 comments on commit 74b19cb

Please sign in to comment.