MCPcopy Create free account
hub / github.com/apache/arrow / TestCopyFiles

Method TestCopyFiles

cpp/src/arrow/filesystem/test_util.cc:591–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591void GenericFileSystemTest::TestCopyFiles(FileSystem* fs) {
592#if defined(ADDRESS_SANITIZER) || defined(ARROW_VALGRIND)
593 if (have_false_positive_memory_leak_with_async_close()) {
594 GTEST_SKIP() << "Filesystem have false positive memory leak with generator";
595 }
596#endif
597 auto io_thread_pool =
598 static_cast<arrow::internal::ThreadPool*>(fs->io_context().executor());
599 auto original_threads = io_thread_pool->GetCapacity();
600 // Needs to be smaller than the number of files we test with to catch GH-15233
601 ASSERT_OK(io_thread_pool->SetCapacity(2));
602 // Ensure the thread pool capacity is set back to the original value after the test
603 auto reset_thread_pool = [io_thread_pool, original_threads](void*) {
604 ASSERT_OK(io_thread_pool->SetCapacity(original_threads));
605 };
606 std::unique_ptr<void, decltype(reset_thread_pool)> reset_thread_pool_guard(
607 nullptr, reset_thread_pool);
608
609 auto mock_fs = std::make_shared<arrow::fs::internal::MockFileSystem>(
610 std::chrono::system_clock::now());
611 std::vector<std::string> dirs0{"0", "0/AB", "0/AB/CD"};
612 std::map<std::string, std::string> files0{
613 {"0/123", "123 data"}, {"0/AB/abc", "abc data"}, {"0/AB/CD/def", "def data"}};
614
615 std::vector<std::string> dirs0and1{"0", "0/AB", "0/AB/CD", "1", "1/AB", "1/AB/CD"};
616 std::map<std::string, std::string> files0and1{
617 {"0/123", "123 data"}, {"0/AB/abc", "abc data"}, {"0/AB/CD/def", "def data"},
618 {"1/123", "123 data"}, {"1/AB/abc", "abc data"}, {"1/AB/CD/def", "def data"}};
619
620 ASSERT_OK(mock_fs->CreateDir("0/AB/CD"));
621 for (const auto& kv : files0) {
622 CreateFile(mock_fs.get(), kv.first, kv.second);
623 }
624
625 auto selector0 = arrow::fs::FileSelector{};
626 selector0.base_dir = "0";
627 selector0.recursive = true;
628
629 ASSERT_OK(CopyFiles(mock_fs, selector0, fs->shared_from_this(), "0"));
630 AssertAllDirs(fs, dirs0);
631 for (const auto& kv : files0) {
632 AssertFileContents(fs, kv.first, kv.second);
633 }
634
635 ASSERT_OK(CopyFiles(fs->shared_from_this(), selector0, fs->shared_from_this(), "1"));
636 AssertAllDirs(fs, dirs0and1);
637 for (const auto& kv : files0and1) {
638 AssertFileContents(fs, kv.first, kv.second);
639 }
640
641 auto selector1 = arrow::fs::FileSelector{};
642 selector1.base_dir = "1";
643 selector1.recursive = true;
644
645 ASSERT_OK(CopyFiles(fs->shared_from_this(), selector1, mock_fs, "1"));
646 AssertAllDirs(mock_fs.get(), dirs0and1);
647 for (const auto& kv : files0and1) {
648 AssertFileContents(mock_fs.get(), kv.first, kv.second);

Callers

nothing calls this directly

Calls 10

CreateFileFunction · 0.85
CopyFilesFunction · 0.85
AssertAllDirsFunction · 0.85
SetCapacityMethod · 0.80
AssertFileContentsFunction · 0.70
executorMethod · 0.45
GetCapacityMethod · 0.45
CreateDirMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected