7171namespace paimon ::test {
7272class GmockFileSystem : public LocalFileSystem {
7373 public:
74+ GmockFileSystem () {
75+ ON_CALL (*this , ListDir (testing::_, testing::_))
76+ .WillByDefault (testing::Invoke (
77+ [&](const std::string& directory,
78+ std::vector<std::unique_ptr<BasicFileStatus>>* file_status_list) {
79+ return this ->LocalFileSystem ::ListDir (directory, file_status_list);
80+ }));
81+ ON_CALL (*this , ReadFile (testing::_, testing::_))
82+ .WillByDefault (testing::Invoke ([&](const std::string& path, std::string* content) {
83+ return this ->FileSystem ::ReadFile (path, content);
84+ }));
85+ ON_CALL (*this , AtomicStore (::testing::_, ::testing::_))
86+ .WillByDefault (
87+ testing::Invoke ([&](const std::string& path, const std::string& content) {
88+ return this ->FileSystem ::AtomicStore (path, content);
89+ }));
90+ }
91+
7492 MOCK_METHOD (Status, ReadFile, (const std::string& path, std::string* content), (override ));
7593 MOCK_METHOD (Status, ListDir,
7694 (const std::string& directory,
@@ -88,29 +106,32 @@ class GmockFileSystemFactory : public LocalFileSystemFactory {
88106
89107 Result<std::unique_ptr<FileSystem>> Create (
90108 const std::string& path, const std::map<std::string, std::string>& options) const override {
91- auto fs = std::make_unique<GmockFileSystem>();
92- using ::testing::A;
93- using ::testing::Invoke;
94-
95- ON_CALL (*fs, ListDir (A<const std::string&>(),
96- A<std::vector<std::unique_ptr<BasicFileStatus>>*>()))
97- .WillByDefault (
98- Invoke ([&](const std::string& directory,
99- std::vector<std::unique_ptr<BasicFileStatus>>* file_status_list) {
100- return fs->LocalFileSystem ::ListDir (directory, file_status_list);
101- }));
102-
103- ON_CALL (*fs, ReadFile (A<const std::string&>(), A<std::string*>()))
104- .WillByDefault (Invoke ([&](const std::string& path, std::string* content) {
105- return fs->FileSystem ::ReadFile (path, content);
106- }));
107-
108- ON_CALL (*fs, AtomicStore (A<const std::string&>(), A<const std::string&>()))
109- .WillByDefault (Invoke ([&](const std::string& path, const std::string& content) {
110- return fs->FileSystem ::AtomicStore (path, content);
111- }));
112-
113- return fs;
109+ return std::make_unique<testing::NiceMock<GmockFileSystem>>();
110+ // auto fs = std::make_unique<testing::NiceMock<GmockFileSystem>>();
111+ // auto fs_ptr = fs.get();
112+ // using ::testing::A;
113+ // using ::testing::Invoke;
114+
115+ // ON_CALL(*fs, ListDir(A<const std::string&>(),
116+ // A<std::vector<std::unique_ptr<BasicFileStatus>>*>()))
117+ // .WillByDefault(
118+ // Invoke([fs_ptr](const std::string& directory,
119+ // std::vector<std::unique_ptr<BasicFileStatus>>* file_status_list)
120+ // {
121+ // return fs_ptr->LocalFileSystem::ListDir(directory, file_status_list);
122+ // }));
123+
124+ // ON_CALL(*fs, ReadFile(A<const std::string&>(), A<std::string*>()))
125+ // .WillByDefault(Invoke([fs_ptr](const std::string& path, std::string* content) {
126+ // return fs_ptr->FileSystem::ReadFile(path, content);
127+ // }));
128+
129+ // ON_CALL(*fs, AtomicStore(A<const std::string&>(), A<const std::string&>()))
130+ // .WillByDefault(Invoke([fs_ptr](const std::string& path, const std::string& content) {
131+ // return fs_ptr->FileSystem::AtomicStore(path, content);
132+ // }));
133+
134+ // return fs;
114135 }
115136};
116137
@@ -364,33 +385,32 @@ TEST_F(FileStoreCommitImplTest, TestRESTCatalogCommit) {
364385 ASSERT_FALSE (exist);
365386}
366387
367- // TODO(jinli.zjw): fix disabled case
368- TEST_F (FileStoreCommitImplTest, DISABLED_TestCommitWithConflictSnapshotAndRetryTenTimes) {
388+ TEST_F (FileStoreCommitImplTest, TestCommitWithConflictSnapshotAndRetryTenTimes) {
369389 std::string test_data_path = paimon::test::GetDataDir () + " /orc/append_09.db/append_09/" ;
370390 auto dir = UniqueTestDirectory::Create ();
371391 std::string table_path = dir->Str ();
372392 ASSERT_TRUE (TestUtil::CopyDirectory (test_data_path, table_path));
393+ ASSERT_OK_AND_ASSIGN (std::shared_ptr<FileSystem> fs,
394+ FileSystemFactory::Get (" gmock_fs" , table_path, {}));
373395 CommitContextBuilder context_builder (table_path, " commit_user_1" );
374396 ASSERT_OK_AND_ASSIGN (std::unique_ptr<CommitContext> commit_context,
375397 context_builder.AddOption (Options::MANIFEST_FORMAT , " orc" )
376398 .AddOption (Options::MANIFEST_TARGET_FILE_SIZE , " 8mb" )
377399 .AddOption (Options::COMMIT_MAX_RETRIES , " 10" )
378- .AddOption (Options:: FILE_SYSTEM , " gmock_fs " )
400+ .WithFileSystem (fs )
379401 .Finish ());
380402
381403 ASSERT_OK_AND_ASSIGN (auto commit, FileStoreCommit::Create (std::move (commit_context)));
382404 auto commit_impl = dynamic_cast <FileStoreCommitImpl*>(commit.get ());
383405 std::string latest_hint = PathUtil::JoinPath (table_path, " snapshot/LATEST" );
384406
385- auto * resolving_fs =
386- dynamic_cast <ResolvingFileSystem*>(commit_impl->snapshot_manager_ ->fs_ .get ());
387- ASSERT_OK_AND_ASSIGN (auto real_fs, resolving_fs->GetRealFileSystem (table_path));
388- auto * mock_fs = dynamic_cast <GmockFileSystem*>(real_fs.get ());
407+ auto * mock_fs = dynamic_cast <GmockFileSystem*>(fs.get ());
389408 EXPECT_CALL (*mock_fs, ReadFile (testing::StrEq (latest_hint), testing::_))
390409 .WillRepeatedly (testing::Invoke ([](const std::string& path, std::string* content) {
391410 *content = " -1" ;
392411 return Status::OK ();
393412 }));
413+ EXPECT_CALL (*mock_fs, ListDir (testing::_, testing::_)).Times (testing::AnyNumber ());
394414 EXPECT_CALL (*mock_fs,
395415 ListDir (testing::StrEq (PathUtil::JoinPath (table_path, " snapshot" )), testing::_))
396416 .WillRepeatedly (
@@ -407,25 +427,24 @@ TEST_F(FileStoreCommitImplTest, DISABLED_TestCommitWithConflictSnapshotAndRetryT
407427 ASSERT_NOK (commit->Commit (msgs));
408428}
409429
410- TEST_F (FileStoreCommitImplTest, DISABLED_TestCommitWithConflictSnapshotAndRetryOnce ) {
430+ TEST_F (FileStoreCommitImplTest, TestCommitWithConflictSnapshotAndRetryOnce ) {
411431 std::string test_data_path = paimon::test::GetDataDir () + " /orc/append_09.db/append_09/" ;
412432 auto dir = UniqueTestDirectory::Create ();
413433 std::string table_path = dir->Str ();
414434 ASSERT_TRUE (TestUtil::CopyDirectory (test_data_path, table_path));
435+ ASSERT_OK_AND_ASSIGN (std::shared_ptr<FileSystem> fs,
436+ FileSystemFactory::Get (" gmock_fs" , table_path, {}));
415437 CommitContextBuilder context_builder (table_path, " commit_user_1" );
416438 ASSERT_OK_AND_ASSIGN (std::unique_ptr<CommitContext> commit_context,
417439 context_builder.AddOption (Options::MANIFEST_FORMAT , " orc" )
418440 .AddOption (Options::MANIFEST_TARGET_FILE_SIZE , " 8mb" )
419- .AddOption (Options:: FILE_SYSTEM , " gmock_fs " )
441+ .WithFileSystem (fs )
420442 .Finish ());
421443
422444 ASSERT_OK_AND_ASSIGN (auto commit, FileStoreCommit::Create (std::move (commit_context)));
423445 auto commit_impl = dynamic_cast <FileStoreCommitImpl*>(commit.get ());
424446 std::string latest_hint = PathUtil::JoinPath (table_path, " snapshot/LATEST" );
425- auto * resolving_fs =
426- dynamic_cast <ResolvingFileSystem*>(commit_impl->snapshot_manager_ ->fs_ .get ());
427- ASSERT_OK_AND_ASSIGN (auto real_fs, resolving_fs->GetRealFileSystem (table_path));
428- auto * mock_fs = dynamic_cast <GmockFileSystem*>(real_fs.get ());
447+ auto * mock_fs = dynamic_cast <GmockFileSystem*>(fs.get ());
429448 EXPECT_CALL (*mock_fs, ReadFile (testing::StrEq (latest_hint), testing::_))
430449 .WillRepeatedly (testing::Invoke ([](const std::string& path, std::string* content) {
431450 *content = " -1" ;
@@ -439,6 +458,7 @@ TEST_F(FileStoreCommitImplTest, DISABLED_TestCommitWithConflictSnapshotAndRetryO
439458 return mock_fs->FileSystem ::ReadFile (path, content);
440459 }));
441460
461+ EXPECT_CALL (*mock_fs, ListDir (testing::_, testing::_)).Times (testing::AnyNumber ());
442462 EXPECT_CALL (*mock_fs,
443463 ListDir (testing::StrEq (PathUtil::JoinPath (table_path, " snapshot" )), testing::_))
444464 .WillOnce (
@@ -468,25 +488,24 @@ TEST_F(FileStoreCommitImplTest, DISABLED_TestCommitWithConflictSnapshotAndRetryO
468488 ASSERT_TRUE (exist);
469489}
470490
471- TEST_F (FileStoreCommitImplTest,
472- DISABLED_TestCommitWithAtomicWriteSnapshotTimeoutAndActuallySucceed) {
491+ TEST_F (FileStoreCommitImplTest, TestCommitWithAtomicWriteSnapshotTimeoutAndActuallySucceed) {
473492 std::string test_data_path = paimon::test::GetDataDir () + " /orc/append_09.db/append_09/" ;
474493 auto dir = UniqueTestDirectory::Create ();
475494 std::string table_path = dir->Str ();
476495 ASSERT_TRUE (TestUtil::CopyDirectory (test_data_path, table_path));
496+ ASSERT_OK_AND_ASSIGN (std::shared_ptr<FileSystem> fs,
497+ FileSystemFactory::Get (" gmock_fs" , table_path, {}));
477498 CommitContextBuilder context_builder (table_path, " commit_user_1" );
478499 ASSERT_OK_AND_ASSIGN (std::unique_ptr<CommitContext> commit_context,
479500 context_builder.AddOption (Options::MANIFEST_FORMAT , " orc" )
480501 .AddOption (Options::MANIFEST_TARGET_FILE_SIZE , " 8mb" )
481- .AddOption (Options:: FILE_SYSTEM , " gmock_fs " )
502+ .WithFileSystem (fs )
482503 .Finish ());
483504
484505 ASSERT_OK_AND_ASSIGN (auto commit, FileStoreCommit::Create (std::move (commit_context)));
485506 std::string new_snapshot_6 = PathUtil::JoinPath (table_path, " snapshot/snapshot-6" );
486507 auto commit_impl = dynamic_cast <FileStoreCommitImpl*>(commit.get ());
487- auto * resolving_fs = dynamic_cast <ResolvingFileSystem*>(commit_impl->fs_ .get ());
488- ASSERT_OK_AND_ASSIGN (auto real_fs, resolving_fs->GetRealFileSystem (table_path));
489- auto * mock_fs = dynamic_cast <GmockFileSystem*>(real_fs.get ());
508+ auto * mock_fs = dynamic_cast <GmockFileSystem*>(fs.get ());
490509 EXPECT_CALL (*mock_fs, AtomicStore (testing::StrEq (new_snapshot_6), testing::_))
491510 .WillOnce (testing::Invoke ([&](const std::string& path, const std::string& content) {
492511 // to mock atomic store timeout actually succeed
@@ -509,20 +528,17 @@ TEST_F(FileStoreCommitImplTest,
509528 ASSERT_OK_AND_ASSIGN (std::unique_ptr<CommitContext> commit_context_2,
510529 context_builder.AddOption (Options::MANIFEST_FORMAT , " orc" )
511530 .AddOption (Options::MANIFEST_TARGET_FILE_SIZE , " 8mb" )
512- .AddOption (Options:: FILE_SYSTEM , " gmock_fs " )
531+ .WithFileSystem (fs )
513532 .Finish ());
514533
515534 ASSERT_OK_AND_ASSIGN (auto commit_2, FileStoreCommit::Create (std::move (commit_context_2)));
516535 ASSERT_OK_AND_ASSIGN (int32_t num_committed, commit_2->FilterAndCommit ({{1 , msgs}}));
517536 ASSERT_EQ (0 , num_committed);
518537 auto commit_impl_2 = dynamic_cast <FileStoreCommitImpl*>(commit_2.get ());
519- auto * resolving_fs_2 = dynamic_cast <ResolvingFileSystem*>(commit_impl_2->fs_ .get ());
520- ASSERT_OK_AND_ASSIGN (auto real_fs_2, resolving_fs_2->GetRealFileSystem (table_path));
521- auto * mock_fs_2 = dynamic_cast <GmockFileSystem*>(real_fs_2.get ());
522538 std::string new_snapshot_7 = PathUtil::JoinPath (table_path, " snapshot/snapshot-7" );
523- EXPECT_CALL (*mock_fs_2 , AtomicStore (testing::StrEq (new_snapshot_7), testing::_))
539+ EXPECT_CALL (*mock_fs , AtomicStore (testing::StrEq (new_snapshot_7), testing::_))
524540 .WillOnce (testing::Invoke ([&](const std::string& path, const std::string& content) {
525- return mock_fs_2 ->FileSystem ::AtomicStore (path, content);
541+ return mock_fs ->FileSystem ::AtomicStore (path, content);
526542 }));
527543 std::vector<std::shared_ptr<CommitMessage>> msgs_2 =
528544 GetCommitMessages (paimon::test::GetDataDir () +
0 commit comments