Skip to content

Commit 7e7e2a5

Browse files
author
nullccxsy
committed
fix: solve merge conflicts
1 parent 9163c2f commit 7e7e2a5

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

test/schema_test.cc

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <gmock/gmock.h>
2727
#include <gtest/gtest.h>
2828

29+
#include "gtest/gtest.h"
2930
#include "iceberg/result.h"
3031
#include "iceberg/schema_field.h"
3132
#include "iceberg/util/formatter.h" // IWYU pragma: keep
@@ -762,7 +763,7 @@ TEST_P(ProjectParamTest, ProjectFields) {
762763

763764
if (param.should_succeed) {
764765
ASSERT_TRUE(result.has_value());
765-
ASSERT_THAT(*result.value(), *param.expected_schema());
766+
ASSERT_EQ(*result.value(), *param.expected_schema());
766767
} else {
767768
ASSERT_FALSE(result.has_value());
768769
ASSERT_THAT(result, iceberg::IsError(iceberg::ErrorKind::kInvalidArgument));
@@ -942,3 +943,70 @@ INSTANTIATE_TEST_SUITE_P(
942943
.selected_ids = {999}, // Select non-existent field
943944
.expected_schema = []() { return MakeSchema(); },
944945
.should_succeed = true}));
946+
947+
class SchemaThreadSafetyTest : public ::testing::Test {
948+
protected:
949+
void SetUp() override {
950+
field1_ = std::make_unique<iceberg::SchemaField>(1, "id", iceberg::int32(), true);
951+
field2_ = std::make_unique<iceberg::SchemaField>(2, "name", iceberg::string(), true);
952+
field3_ = std::make_unique<iceberg::SchemaField>(3, "age", iceberg::int32(), true);
953+
schema_ = std::make_unique<iceberg::Schema>(
954+
std::vector<iceberg::SchemaField>{*field1_, *field2_, *field3_}, 100);
955+
}
956+
957+
std::unique_ptr<iceberg::Schema> schema_;
958+
std::unique_ptr<iceberg::SchemaField> field1_;
959+
std::unique_ptr<iceberg::SchemaField> field2_;
960+
std::unique_ptr<iceberg::SchemaField> field3_;
961+
};
962+
963+
TEST_F(SchemaThreadSafetyTest, ConcurrentFindFieldById) {
964+
const int num_threads = 10;
965+
const int iterations_per_thread = 100;
966+
std::vector<std::thread> threads;
967+
968+
for (int i = 0; i < num_threads; ++i) {
969+
threads.emplace_back([this, iterations_per_thread]() {
970+
for (int j = 0; j < iterations_per_thread; ++j) {
971+
ASSERT_THAT(schema_->FindFieldById(1), ::testing::Optional(*field1_));
972+
ASSERT_THAT(schema_->FindFieldById(999), ::testing::Optional(std::nullopt));
973+
}
974+
});
975+
}
976+
977+
for (auto& thread : threads) {
978+
thread.join();
979+
}
980+
}
981+
982+
TEST_F(SchemaThreadSafetyTest, MixedConcurrentOperations) {
983+
const int num_threads = 8;
984+
const int iterations_per_thread = 50;
985+
std::vector<std::thread> threads;
986+
987+
for (int i = 0; i < num_threads; ++i) {
988+
threads.emplace_back([this, iterations_per_thread, i]() {
989+
for (int j = 0; j < iterations_per_thread; ++j) {
990+
if (i % 4 == 0) {
991+
ASSERT_THAT(schema_->FindFieldById(1), ::testing::Optional(*field1_));
992+
} else if (i % 4 == 1) {
993+
ASSERT_THAT(schema_->FindFieldByName("name", true),
994+
::testing::Optional(*field2_));
995+
} else if (i % 4 == 2) {
996+
ASSERT_THAT(schema_->FindFieldByName("AGE", false),
997+
::testing::Optional(*field3_));
998+
} else {
999+
ASSERT_THAT(schema_->FindFieldById(2), ::testing::Optional(*field2_));
1000+
ASSERT_THAT(schema_->FindFieldByName("id", true),
1001+
::testing::Optional(*field1_));
1002+
ASSERT_THAT(schema_->FindFieldByName("age", false),
1003+
::testing::Optional(*field3_));
1004+
}
1005+
}
1006+
});
1007+
}
1008+
1009+
for (auto& thread : threads) {
1010+
thread.join();
1011+
}
1012+
}

0 commit comments

Comments
 (0)