Skip to content

Commit a7f028f

Browse files
committed
refactor(wal_history): add [[nodiscard]] attribute to list and parse_record methods
1 parent f69e129 commit a7f028f

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/limestone/wal_sync/wal_history.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,23 @@ class wal_history {
3939
explicit wal_history(boost::filesystem::path dir_path);
4040

4141
void append(epoch_id_type epoch);
42-
std::vector<record> list() const;
42+
[[nodiscard]] std::vector<record> list() const;
4343
void check_and_recover();
4444

4545

4646

4747
protected:
48-
// for Unit Testing
49-
void set_file_operations(std::unique_ptr<file_operations> file_ops) { file_ops_ = std::move(file_ops); }
50-
void reset_file_operations() { file_ops_ = std::make_unique<real_file_operations>(); }
48+
// Note: These members are protected (not private) to allow access from test subclasses.
5149
static constexpr std::size_t record_size = sizeof(epoch_id_type) + 16 + sizeof(std::int64_t);
52-
void write_record(std::ofstream& ofs, epoch_id_type epoch, const boost::uuids::uuid& uuid, std::int64_t timestamp);
53-
static record parse_record(const std::array<std::byte, record_size>& buf);
54-
std::vector<record> read_all_records(const boost::filesystem::path& file_path) const;
5550
static constexpr const char* file_name_ = "wal_history";
5651
static constexpr const char* tmp_file_name_ = "wal_history.tmp";
5752

53+
void set_file_operations(std::unique_ptr<file_operations> file_ops) { file_ops_ = std::move(file_ops); }
54+
void reset_file_operations() { file_ops_ = std::make_unique<real_file_operations>(); }
55+
void write_record(std::ofstream& ofs, epoch_id_type epoch, const boost::uuids::uuid& uuid, std::int64_t timestamp);
56+
[[nodiscard]] static record parse_record(const std::array<std::byte, record_size>& buf);
57+
[[nodiscard]] std::vector<record> read_all_records(const boost::filesystem::path& file_path) const;
58+
5859
private:
5960
boost::filesystem::path dir_path_;
6061
std::unique_ptr<file_operations> file_ops_ = std::make_unique<real_file_operations>();

test/limestone/wal_sync/wal_history_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ TEST_F(wal_history_test, read_all_records_throws_on_open_failure) {
182182
ofs << "dummy";
183183
ofs.close();
184184
try {
185-
wh.list();
185+
auto _ = wh.list();
186186
FAIL() << "Exception was not thrown";
187187
} catch (const limestone_exception& ex) {
188188
EXPECT_TRUE(std::string(ex.what()).find("Failed to open wal_history for read:") != std::string::npos);
@@ -201,7 +201,7 @@ TEST_F(wal_history_test, read_all_records_throws_on_exists_error) {
201201
auto failing_ops = std::make_unique<FailingExistsFileOps>();
202202
wh.set_file_operations(std::move(failing_ops));
203203
try {
204-
wh.list();
204+
auto _ = wh.list();
205205
FAIL() << "Exception was not thrown";
206206
} catch (const limestone_exception& ex) {
207207
EXPECT_TRUE(std::string(ex.what()).find("Failed to check existence of wal_history:") != std::string::npos);
@@ -216,7 +216,7 @@ TEST_F(wal_history_test, read_all_records_throws_on_partial_record_read) {
216216
ofs.put('x');
217217
ofs.close();
218218
try {
219-
wh.list();
219+
auto _ = wh.list();
220220
FAIL() << "Exception was not thrown";
221221
} catch (const limestone_exception& ex) {
222222
EXPECT_TRUE(std::string(ex.what()).find("Failed to read wal_history file: partial record read:") != std::string::npos);
@@ -234,7 +234,7 @@ TEST_F(wal_history_test, read_all_records_throws_on_stream_error) {
234234
auto failing_ops = std::make_unique<FailingFileOps>();
235235
wh.set_file_operations(std::move(failing_ops));
236236
try {
237-
wh.list();
237+
auto _ = wh.list();
238238
FAIL() << "Exception was not thrown";
239239
} catch (const limestone_exception& ex) {
240240
EXPECT_TRUE(std::string(ex.what()).find("Failed to read wal_history file: stream error:") != std::string::npos);

0 commit comments

Comments
 (0)