This is an automated email from the ASF dual-hosted git repository.

shuke987 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c72b4e0ef3 [test](be) Make six unit tests independent of file cache 
state (#71171)
1c72b4e0ef3 is described below

commit 1c72b4e0ef32daf50daa1d1d81b971ba0e93ce6b
Author: shuke <[email protected]>
AuthorDate: Tue Dec 1 16:58:21 2026 +0800

    [test](be) Make six unit tests independent of file cache state (#71171)
    
    The BE unit test binary initializes a smaller `ExecEnv` than a running
    BE. Tests in the same process share the file-cache flag and factory. A
    suite that leaves caching disabled can hide a missing cache dependency
    in a later test.
---
 ...hive_partition_writer_report_lifecycle_test.cpp |  6 ++++
 be/test/io/fs/hdfs_file_system_test.cpp            | 40 ++++++++++++++++++++--
 be/test/io/fs/obj_storage_file_writer_test.cpp     |  5 +++
 be/test/io/fs/packed_file_manager_test.cpp         |  1 +
 .../delta_writer/delta_writer_cluster_key_test.cpp |  5 +++
 be/test/runtime/snapshot_loader_test.cpp           |  5 +++
 6 files changed, 59 insertions(+), 3 deletions(-)

diff --git 
a/be/test/exec/sink/writer/vhive_partition_writer_report_lifecycle_test.cpp 
b/be/test/exec/sink/writer/vhive_partition_writer_report_lifecycle_test.cpp
index 749740223db..ea608ed175f 100644
--- a/be/test/exec/sink/writer/vhive_partition_writer_report_lifecycle_test.cpp
+++ b/be/test/exec/sink/writer/vhive_partition_writer_report_lifecycle_test.cpp
@@ -23,6 +23,7 @@
 #include <string_view>
 #include <vector>
 
+#include "common/config.h"
 #include "exec/pipeline/pipeline_fragment_context.h"
 #include "exec/sink/writer/vhive_partition_writer.h"
 #include "format/transformer/vfile_format_transformer.h"
@@ -30,6 +31,7 @@
 #include "io/fs/obj_storage_file_writer.h"
 #include "runtime/exec_env.h"
 #include "testutil/mock/mock_runtime_state.h"
+#include "util/defer_op.h"
 
 namespace doris {
 namespace {
@@ -129,6 +131,10 @@ std::unique_ptr<VHivePartitionWriter> 
create_closed_hive_writer(
 
     auto holder = 
std::make_shared<io::ObjStorageClientHolder>(std::move(config));
     holder->_client = client;
+    const bool saved_enable_file_cache = config::enable_file_cache;
+    Defer restore_file_cache {[&] { config::enable_file_cache = 
saved_enable_file_cache; }};
+    config::enable_file_cache = false;
+
     io::FileWriterOptions options {.used_by_s3_committer = true};
     auto file_writer = std::make_unique<io::ObjStorageFileWriter>(holder, 
"bucket",
                                                                   
"table/part.parquet", &options);
diff --git a/be/test/io/fs/hdfs_file_system_test.cpp 
b/be/test/io/fs/hdfs_file_system_test.cpp
index 859b728fcdd..4d7ab6fddd5 100644
--- a/be/test/io/fs/hdfs_file_system_test.cpp
+++ b/be/test/io/fs/hdfs_file_system_test.cpp
@@ -26,10 +26,16 @@
 #include "cpp/sync_point.h"
 #include "gen_cpp/PlanNodes_types.h"
 #include "gen_cpp/Status_types.h"
+#include "io/cache/block_file_cache.h"
+#include "io/cache/block_file_cache_factory.h"
+#include "io/cache/file_block.h"
+#include "io/cache/file_cache_common.h"
 #include "io/fs/file_reader.h"
 #include "io/fs/file_writer.h"
 #include "io/fs/hdfs_file_writer.h"
 #include "io/fs/local_file_system.h"
+#include "runtime/exec_env.h"
+#include "util/defer_op.h"
 
 namespace doris {
 
@@ -105,15 +111,30 @@ TEST(HdfsFileSystemTest, Write) {
             },
             &guard4);
 
+    constexpr size_t MB = 1024 * 1024;
+    io::FileCacheFactory factory;
+    auto* env = ExecEnv::GetInstance();
+    auto* saved_factory = env->file_cache_factory();
+    const bool saved_enable_file_cache = config::enable_file_cache;
+    const auto saved_batch_size_mb = config::hdfs_write_batch_buffer_size_mb;
+    Defer restore_cache {[&] {
+        env->set_file_cache_factory(saved_factory);
+        config::enable_file_cache = saved_enable_file_cache;
+        config::hdfs_write_batch_buffer_size_mb = saved_batch_size_mb;
+    }};
+    auto settings = io::get_file_cache_settings(32 * MB, 0);
+    settings.storage = "memory";
+    settings.max_file_block_size = MB;
+    ASSERT_TRUE(factory.create_file_cache("memory", settings).ok());
+    env->set_file_cache_factory(&factory);
+    config::enable_file_cache = true;
     config::hdfs_write_batch_buffer_size_mb = 1;
-    // TODO(plat1ko): Test write file cache
 
     io::FileWriterOptions opts {.write_file_cache = true};
     auto hdfs_file_writer = 
std::make_unique<io::HdfsFileWriter>("mock_hdfs_file", nullptr, nullptr,
                                                                  "fs_name", 
&opts);
 
     std::string content_1000(1000, 'a');
-    constexpr size_t MB = 1024 * 1024;
     std::string content_1M(MB, 'b');
     std::string content_2M(2 * MB, 'c');
 
@@ -156,7 +177,20 @@ TEST(HdfsFileSystemTest, Write) {
     ASSERT_EQ(std::string_view(buf.get(), bytes_read), content_2M);
     offset += bytes_read;
 
-    // TODO(plat1ko): Check cached content
+    const auto key = io::BlockFileCache::hash("mock_hdfs_file");
+    const auto blocks = factory.get_by_path(key)->get_blocks_by_key(key);
+    size_t cached_bytes = 0;
+    for (const auto& [block_offset, block] : blocks) {
+        ASSERT_EQ(cached_bytes, block_offset);
+        std::string cached(block->range().size(), '\0');
+        std::string expected(cached.size(), '\0');
+        ASSERT_TRUE(block->read(Slice(cached), 0).ok());
+        ASSERT_TRUE(local_file_reader->read_at(block_offset, Slice(expected), 
&bytes_read).ok());
+        ASSERT_EQ(bytes_read, cached.size());
+        EXPECT_EQ(0, cached.compare(expected)) << "cache block at offset " << 
block_offset;
+        cached_bytes += cached.size();
+    }
+    EXPECT_EQ(local_file_reader->size(), cached_bytes);
 
     st = local_fs->delete_directory(test_dir);
 }
diff --git a/be/test/io/fs/obj_storage_file_writer_test.cpp 
b/be/test/io/fs/obj_storage_file_writer_test.cpp
index 672bfb2d6d1..7901a7364eb 100644
--- a/be/test/io/fs/obj_storage_file_writer_test.cpp
+++ b/be/test/io/fs/obj_storage_file_writer_test.cpp
@@ -62,6 +62,7 @@
 #include "storage/index/index_file_writer.h"
 #include "storage/index/index_writer.h"
 #include "testutil/mock/obj_storage_client_test_stub.h"
+#include "util/defer_op.h"
 #include "util/slice.h"
 #include "util/threadpool.h"
 #include "util/uuid_generator.h"
@@ -358,6 +359,10 @@ TEST_F(S3FileWriterTest, 
DisableFileCacheWriteFromS3FileWriter) {
 }
 
 TEST_F(S3FileWriterTest, multi_part_io_error) {
+    const bool saved_enable_file_cache = config::enable_file_cache;
+    Defer restore_file_cache {[&] { config::enable_file_cache = 
saved_enable_file_cache; }};
+    config::enable_file_cache = false;
+
     mock_client = std::make_shared<MockS3Client>();
     doris::io::FileWriterOptions state;
     auto fs = io::global_local_filesystem();
diff --git a/be/test/io/fs/packed_file_manager_test.cpp 
b/be/test/io/fs/packed_file_manager_test.cpp
index c481be20c1a..c09bfa03668 100644
--- a/be/test/io/fs/packed_file_manager_test.cpp
+++ b/be/test/io/fs/packed_file_manager_test.cpp
@@ -316,6 +316,7 @@ TEST_F(PackedFileManagerTest, AppendSmallFileSuccess) {
     Slice slice(payload);
 
     auto info = default_append_info();
+    info.write_file_cache = false;
     Status st = append_small_file("s/path", slice, info);
     EXPECT_TRUE(st.ok());
     EXPECT_EQ(writer->append_calls(), 1);
diff --git a/be/test/load/delta_writer/delta_writer_cluster_key_test.cpp 
b/be/test/load/delta_writer/delta_writer_cluster_key_test.cpp
index 91ecfe5fa76..87f81920bcc 100644
--- a/be/test/load/delta_writer/delta_writer_cluster_key_test.cpp
+++ b/be/test/load/delta_writer/delta_writer_cluster_key_test.cpp
@@ -61,6 +61,7 @@
 #include "storage/tablet_info.h"
 #include "storage/task/engine_publish_version_task.h"
 #include "storage/txn/txn_manager.h"
+#include "util/defer_op.h"
 
 namespace doris {
 class OlapMeta;
@@ -243,6 +244,10 @@ public:
 };
 
 TEST_F(TestDeltaWriterClusterKey, vec_sequence_col) {
+    const bool saved_enable_file_cache = config::enable_file_cache;
+    Defer restore_file_cache {[&] { config::enable_file_cache = 
saved_enable_file_cache; }};
+    config::enable_file_cache = false;
+
     std::unique_ptr<RuntimeProfile> profile = 
std::make_unique<RuntimeProfile>("CreateTablet");
     TCreateTabletReq request;
     // sleep(20);
diff --git a/be/test/runtime/snapshot_loader_test.cpp 
b/be/test/runtime/snapshot_loader_test.cpp
index 05c12731282..1a65bdd89e8 100644
--- a/be/test/runtime/snapshot_loader_test.cpp
+++ b/be/test/runtime/snapshot_loader_test.cpp
@@ -70,6 +70,7 @@
 #include "storage/tablet_info.h"
 #include "storage/task/engine_publish_version_task.h"
 #include "storage/txn/txn_manager.h"
+#include "util/defer_op.h"
 
 namespace doris {
 
@@ -376,6 +377,10 @@ TEST_F(SnapshotLoaderTest, 
RejectBrokenSnapshotPathAfterCanonicalize) {
 }
 
 TEST_F(SnapshotLoaderTest, DirMoveTaskIsIdempotent) {
+    const bool saved_enable_file_cache = config::enable_file_cache;
+    Defer restore_file_cache {[&] { config::enable_file_cache = 
saved_enable_file_cache; }};
+    config::enable_file_cache = false;
+
     // 1. create a tablet
     int64_t tablet_id = 111;
     int32_t schema_hash = 222;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to