This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new 57b36ebabb2 branch-3.1: [test](filecache) fix lru dumper test #54456
(#55403)
57b36ebabb2 is described below
commit 57b36ebabb2c79b64c0f838a5e4e7bf7bc90b6f1
Author: zhengyu <[email protected]>
AuthorDate: Thu Aug 28 14:01:50 2025 +0800
branch-3.1: [test](filecache) fix lru dumper test #54456 (#55403)
picked from #54456
Signed-off-by: zhengyu <[email protected]>
---
be/test/io/cache/cache_lru_dumper_test.cpp | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/be/test/io/cache/cache_lru_dumper_test.cpp
b/be/test/io/cache/cache_lru_dumper_test.cpp
index fd4260b012b..cf51fef4c0a 100644
--- a/be/test/io/cache/cache_lru_dumper_test.cpp
+++ b/be/test/io/cache/cache_lru_dumper_test.cpp
@@ -17,6 +17,8 @@
#include "io/cache/cache_lru_dumper.h"
+#include <filesystem>
+
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "io/cache/block_file_cache.h"
@@ -30,12 +32,14 @@ using ::testing::NiceMock;
namespace doris::io {
std::mutex _mutex;
+static const std::string test_dir = "./cache_lru_dumper_test_dir/";
+
class MockBlockFileCache : public BlockFileCache {
public:
LRUQueue* dst_queue; // Pointer to the destination queue
MockBlockFileCache(LRUQueue* queue) : BlockFileCache("", {}),
dst_queue(queue) {
- _cache_base_path = "./";
+ _cache_base_path = test_dir;
}
FileBlockCell* add_cell(const UInt128Wrapper& hash, const CacheContext&
ctx, size_t offset,
@@ -59,6 +63,9 @@ protected:
LRUQueue dst_queue; // Member variable for destination queue
void SetUp() override {
+ std::filesystem::remove_all(test_dir);
+ std::filesystem::create_directory(test_dir);
+
mock_cache =
std::make_unique<NiceMock<MockBlockFileCache>>(&dst_queue);
recorder = std::make_unique<LRUQueueRecorder>(mock_cache.get());
@@ -68,6 +75,7 @@ protected:
void TearDown() override {
dumper.reset();
mock_cache.reset();
+ std::filesystem::remove_all(test_dir);
}
std::unique_ptr<NiceMock<MockBlockFileCache>> mock_cache;
@@ -76,9 +84,9 @@ protected:
};
TEST_F(CacheLRUDumperTest, test_finalize_dump_and_parse_dump_footer) {
- std::ofstream out("test_finalize.bin", std::ios::binary);
- std::string tmp_filename = "test_finalize.bin.tmp";
- std::string final_filename = "test_finalize.bin";
+ std::string tmp_filename = test_dir + "test_finalize.bin.tmp";
+ std::string final_filename = test_dir + "test_finalize.bin";
+ std::ofstream out(tmp_filename, std::ios::binary);
size_t file_size = 0;
size_t entry_num = 10;
@@ -87,21 +95,18 @@ TEST_F(CacheLRUDumperTest,
test_finalize_dump_and_parse_dump_footer) {
dumper->finalize_dump(out, entry_num, tmp_filename,
final_filename, file_size).ok());
// Test parse footer
- std::ifstream in("test_finalize.bin", std::ios::binary);
+ std::ifstream in(final_filename, std::ios::binary);
size_t parsed_entry_num = 0;
EXPECT_TRUE(dumper->parse_dump_footer(in, final_filename,
parsed_entry_num).ok());
EXPECT_EQ(entry_num, parsed_entry_num);
-
- out.close();
in.close();
- std::remove("test_finalize.bin");
}
TEST_F(CacheLRUDumperTest, test_remove_lru_dump_files) {
// Create test files
std::vector<std::string> queue_names = {"disposable", "index", "normal",
"ttl"};
for (const auto& name : queue_names) {
- std::ofstream(fmt::format("lru_dump_{}.tail", name));
+ std::ofstream(fmt::format("{}lru_dump_{}.tail", test_dir, name));
}
// Test remove
@@ -109,7 +114,7 @@ TEST_F(CacheLRUDumperTest, test_remove_lru_dump_files) {
// Verify files are removed
for (const auto& name : queue_names) {
- EXPECT_FALSE(std::filesystem::exists(fmt::format("lru_dump_{}.tail",
name)));
+ EXPECT_FALSE(std::filesystem::exists(fmt::format("{}lru_dump_{}.tail",
test_dir, name)));
}
}
@@ -141,9 +146,6 @@ TEST_F(CacheLRUDumperTest, test_dump_and_restore_queue) {
++src_it;
++dst_it;
}
-
- // Clean up
- std::remove(fmt::format("lru_dump_{}.tail", queue_name).c_str());
}
} // namespace doris::io
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]