Skip to content

Commit 22e0b66

Browse files
committed
test: enhance ReadContext, ScanContext, and WriteContext tests with default values and option overrides
1 parent f5841d1 commit 22e0b66

4 files changed

Lines changed: 85 additions & 6 deletions

File tree

src/paimon/core/operation/read_context_test.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
#include "gtest/gtest.h"
2222
#include "paimon/defs.h"
23+
#include "paimon/executor.h"
24+
#include "paimon/memory/memory_pool.h"
2325
#include "paimon/predicate/predicate_builder.h"
2426
#include "paimon/status.h"
2527
#include "paimon/testing/mock/mock_file_system.h"
2628
#include "paimon/testing/utils/testharness.h"
2729

2830
namespace paimon::test {
29-
TEST(ReadContextTest, TestSimple) {
31+
TEST(ReadContextTest, TestDefaultValue) {
3032
ReadContextBuilder builder("table_root_path");
3133
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
3234
ASSERT_EQ(ctx->GetPath(), "table_root_path");
@@ -50,6 +52,11 @@ TEST(ReadContextTest, TestSimple) {
5052

5153
TEST(ReadContextTest, TestSetContent) {
5254
ReadContextBuilder builder("table_root_path");
55+
std::shared_ptr<MemoryPool> memory_pool = GetDefaultPool();
56+
std::shared_ptr<Executor> executor = CreateDefaultExecutor();
57+
CacheConfig cache_config(/*buffer_size_limit=*/1024, /*range_size_limit=*/512,
58+
/*hole_size_limit=*/128, /*pre_buffer_limit=*/2048);
59+
5360
builder.AddOption("key", "value");
5461
builder.SetReadSchema({"f1", "f2"});
5562
builder.SetReadFieldIds({0, 1});
@@ -63,7 +70,11 @@ TEST(ReadContextTest, TestSetContent) {
6370
builder.SetPrefetchMaxParallelNum(6);
6471
builder.EnableMultiThreadRowToBatch(true);
6572
builder.SetRowToBatchThreadNumber(9);
73+
builder.WithMemoryPool(memory_pool);
74+
builder.WithExecutor(executor);
75+
builder.SetTableSchema("table-schema-json");
6676
builder.WithBranch("rt");
77+
builder.WithCacheConfig(cache_config);
6778
builder.WithFileSystemSchemeToIdentifierMap({{"file", "local"}});
6879
auto fs = std::make_shared<MockFileSystem>();
6980
builder.WithFileSystem(fs);
@@ -83,12 +94,31 @@ TEST(ReadContextTest, TestSetContent) {
8394
ASSERT_EQ(6, ctx->GetPrefetchMaxParallelNum());
8495
ASSERT_TRUE(ctx->EnableMultiThreadRowToBatch());
8596
ASSERT_EQ(9, ctx->GetRowToBatchThreadNumber());
97+
ASSERT_EQ(memory_pool, ctx->GetMemoryPool());
98+
ASSERT_EQ(executor, ctx->GetExecutor());
99+
ASSERT_TRUE(ctx->GetSpecificTableSchema().has_value());
100+
ASSERT_EQ("table-schema-json", ctx->GetSpecificTableSchema().value());
86101
ASSERT_EQ("rt", ctx->GetBranch());
102+
ASSERT_EQ(1024U, ctx->GetCacheConfig().GetBufferSizeLimit());
103+
ASSERT_EQ(512U, ctx->GetCacheConfig().GetRangeSizeLimit());
104+
ASSERT_EQ(128U, ctx->GetCacheConfig().GetHoleSizeLimit());
105+
ASSERT_EQ(2048U, ctx->GetCacheConfig().GetPreBufferLimit());
87106
std::map<std::string, std::string> expected_fs_map = {{"file", "local"}};
88107
ASSERT_EQ(expected_fs_map, ctx->GetFileSystemSchemeToIdentifierMap());
89108
std::map<std::string, std::string> expected_options = {{"key", "value"}};
90109
ASSERT_EQ(expected_options, ctx->GetOptions());
91110
ASSERT_EQ(ctx->GetSpecificFileSystem(), fs);
92111
}
93112

113+
TEST(ReadContextTest, TestSetOptionsOverridesAddedOptions) {
114+
ReadContextBuilder builder("table_root_path");
115+
builder.AddOption("old", "value");
116+
builder.SetOptions({{"key1", "value1"}, {"key2", "value2"}});
117+
118+
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
119+
120+
std::map<std::string, std::string> expected_options = {{"key1", "value1"}, {"key2", "value2"}};
121+
ASSERT_EQ(expected_options, ctx->GetOptions());
122+
}
123+
94124
} // namespace paimon::test

src/paimon/core/operation/scan_context_test.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818

1919
#include "gtest/gtest.h"
2020
#include "paimon/defs.h"
21+
#include "paimon/executor.h"
2122
#include "paimon/global_index/bitmap_global_index_result.h"
23+
#include "paimon/memory/memory_pool.h"
2224
#include "paimon/predicate/predicate_builder.h"
2325
#include "paimon/status.h"
2426
#include "paimon/testing/mock/mock_file_system.h"
2527
#include "paimon/testing/utils/testharness.h"
2628

2729
namespace paimon::test {
28-
TEST(ScanContextTest, TestSimple) {
30+
TEST(ScanContextTest, TestDefaultValue) {
2931
ScanContextBuilder builder("table_root_path");
3032
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
3133
ASSERT_EQ(ctx->GetPath(), "table_root_path");
@@ -37,12 +39,16 @@ TEST(ScanContextTest, TestSimple) {
3739
ASSERT_FALSE(ctx->GetScanFilters()->GetBucketFilter());
3840
ASSERT_FALSE(ctx->GetScanFilters()->GetPredicate());
3941
ASSERT_TRUE(ctx->GetScanFilters()->GetPartitionFilters().empty());
42+
ASSERT_TRUE(ctx->GetOptions().empty());
4043
ASSERT_FALSE(ctx->GetGlobalIndexResult());
4144
ASSERT_FALSE(ctx->GetSpecificFileSystem());
4245
}
4346

44-
TEST(ScanContextTest, TestSetFilter) {
47+
TEST(ScanContextTest, TestSetContent) {
4548
ScanContextBuilder builder("table_root_path");
49+
std::shared_ptr<MemoryPool> memory_pool = GetDefaultPool();
50+
std::shared_ptr<Executor> executor = CreateDefaultExecutor();
51+
4652
builder.SetBucketFilter(10);
4753
std::vector<std::map<std::string, std::string>> partition_filters = {{{"f1", "20"}}};
4854
builder.SetPartitionFilter(partition_filters);
@@ -55,6 +61,8 @@ TEST(ScanContextTest, TestSetFilter) {
5561
builder.SetLimit(1000);
5662
builder.AddOption("key", "value");
5763
builder.WithStreamingMode(true);
64+
builder.WithMemoryPool(memory_pool);
65+
builder.WithExecutor(executor);
5866
auto fs = std::make_shared<MockFileSystem>();
5967
builder.WithFileSystem(fs);
6068
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
@@ -66,9 +74,22 @@ TEST(ScanContextTest, TestSetFilter) {
6674
ASSERT_EQ(*predicate, *(ctx->GetScanFilters()->GetPredicate()));
6775
ASSERT_EQ(partition_filters, ctx->GetScanFilters()->GetPartitionFilters());
6876
ASSERT_EQ("{1,2,4,5}", ctx->GetGlobalIndexResult()->ToString());
77+
ASSERT_EQ(memory_pool, ctx->GetMemoryPool());
78+
ASSERT_EQ(executor, ctx->GetExecutor());
6979
std::map<std::string, std::string> expected_options = {{"key", "value"}};
7080
ASSERT_EQ(expected_options, ctx->GetOptions());
7181
ASSERT_EQ(fs, ctx->GetSpecificFileSystem());
7282
}
7383

84+
TEST(ScanContextTest, TestSetOptionsOverridesAddedOptions) {
85+
ScanContextBuilder builder("table_root_path");
86+
builder.AddOption("old", "value");
87+
builder.SetOptions({{"key1", "value1"}, {"key2", "value2"}});
88+
89+
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
90+
91+
std::map<std::string, std::string> expected_options = {{"key1", "value1"}, {"key2", "value2"}};
92+
ASSERT_EQ(expected_options, ctx->GetOptions());
93+
}
94+
7495
} // namespace paimon::test

src/paimon/core/operation/write_context_test.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
namespace paimon::test {
2828

29-
TEST(WriteContextTest, TestSimple) {
29+
TEST(WriteContextTest, TestDefaultValue) {
3030
WriteContextBuilder builder("table_root_path", "commit_user_1");
3131
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
3232
ASSERT_EQ(ctx->GetRootPath(), "table_root_path");
3333
ASSERT_EQ(ctx->GetCommitUser(), "commit_user_1");
3434
ASSERT_FALSE(ctx->IsStreamingMode());
3535
ASSERT_FALSE(ctx->IgnoreNumBucketCheck());
3636
ASSERT_FALSE(ctx->IgnorePreviousFiles());
37+
ASSERT_FALSE(ctx->EnableMultiThreadSpill());
3738
ASSERT_EQ(ctx->GetWriteId(), std::nullopt);
3839
ASSERT_EQ(ctx->GetBranch(), "main");
3940
ASSERT_TRUE(ctx->GetWriteSchema().empty());
@@ -42,9 +43,10 @@ TEST(WriteContextTest, TestSimple) {
4243
ASSERT_TRUE(ctx->GetTempDirectory().empty());
4344
ASSERT_TRUE(ctx->GetOptions().empty());
4445
ASSERT_TRUE(ctx->GetFileSystemSchemeToIdentifierMap().empty());
46+
ASSERT_FALSE(ctx->GetSpecificFileSystem());
4547
}
4648

47-
TEST(WriteContextTest, TestAllWithMethods) {
49+
TEST(WriteContextTest, TestSetContent) {
4850
WriteContextBuilder builder("table_root_path", "commit_user_1");
4951

5052
auto memory_pool = GetDefaultPool();
@@ -66,11 +68,13 @@ TEST(WriteContextTest, TestAllWithMethods) {
6668
.WithWriteSchema(write_schema)
6769
.WithFileSystemSchemeToIdentifierMap(fs_scheme_to_identifier_map)
6870
.WithFileSystem(file_system)
71+
.AddOption("key", "value")
6972
.Finish());
7073

7174
ASSERT_TRUE(ctx->IsStreamingMode());
7275
ASSERT_TRUE(ctx->IgnoreNumBucketCheck());
7376
ASSERT_TRUE(ctx->IgnorePreviousFiles());
77+
ASSERT_FALSE(ctx->EnableMultiThreadSpill());
7478
ASSERT_EQ(ctx->GetMemoryPool(), memory_pool);
7579
ASSERT_EQ(ctx->GetExecutor(), executor);
7680
ASSERT_EQ(ctx->GetTempDirectory(), "/tmp/with-all");
@@ -79,6 +83,28 @@ TEST(WriteContextTest, TestAllWithMethods) {
7983
ASSERT_EQ(ctx->GetWriteSchema(), write_schema);
8084
ASSERT_EQ(ctx->GetFileSystemSchemeToIdentifierMap(), fs_scheme_to_identifier_map);
8185
ASSERT_EQ(ctx->GetSpecificFileSystem(), file_system);
86+
std::map<std::string, std::string> expected_options = {{"key", "value"}};
87+
ASSERT_EQ(expected_options, ctx->GetOptions());
88+
}
89+
90+
TEST(WriteContextTest, TestSetOptionsOverridesAddedOptions) {
91+
WriteContextBuilder builder("table_root_path", "commit_user_1");
92+
builder.AddOption("old", "value");
93+
builder.SetOptions({{"key1", "value1"}, {"key2", "value2"}});
94+
95+
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
96+
97+
std::map<std::string, std::string> expected_options = {{"key1", "value1"}, {"key2", "value2"}};
98+
ASSERT_EQ(expected_options, ctx->GetOptions());
99+
}
100+
101+
TEST(WriteContextTest, TestSetWriteBufferSpillThreadNumber) {
102+
WriteContextBuilder builder("table_root_path", "commit_user_1");
103+
builder.SetWriteBufferSpillThreadNumber(2);
104+
105+
ASSERT_OK_AND_ASSIGN(auto ctx, builder.Finish());
106+
107+
ASSERT_TRUE(ctx->EnableMultiThreadSpill());
82108
}
83109

84110
} // namespace paimon::test

test/inte/write_inte_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4316,7 +4316,9 @@ TEST_P(WriteInteTest, TestPkSpillableMultiBucketMultiRoundDataCorrectness) {
43164316
};
43174317

43184318
WriteContextBuilder write_builder(table_path, "commit_user_1");
4319-
write_builder.WithStreamingMode(true).WithTempDirectory(tmp_dir);
4319+
write_builder.WithStreamingMode(true)
4320+
.WithTempDirectory(tmp_dir)
4321+
.SetWriteBufferSpillThreadNumber(3);
43204322
ASSERT_OK_AND_ASSIGN(std::unique_ptr<WriteContext> write_context, write_builder.Finish());
43214323
ASSERT_OK_AND_ASSIGN(auto file_store_write, FileStoreWrite::Create(std::move(write_context)));
43224324

0 commit comments

Comments
 (0)