Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:26:58

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <iosfwd>
0021 #include <memory>
0022 #include <string>
0023 #include <string_view>
0024 #include <vector>
0025 
0026 #include "arrow/filesystem/filesystem.h"
0027 #include "arrow/util/windows_fixup.h"
0028 
0029 namespace arrow::fs::internal {
0030 
0031 struct MockDirInfo {
0032   std::string full_path;
0033   TimePoint mtime;
0034 
0035   bool operator==(const MockDirInfo& other) const {
0036     return mtime == other.mtime && full_path == other.full_path;
0037   }
0038 
0039   ARROW_FRIEND_EXPORT friend std::ostream& operator<<(std::ostream&, const MockDirInfo&);
0040 };
0041 
0042 struct MockFileInfo {
0043   std::string full_path;
0044   TimePoint mtime;
0045   std::string_view data;
0046 
0047   bool operator==(const MockFileInfo& other) const {
0048     return mtime == other.mtime && full_path == other.full_path && data == other.data;
0049   }
0050 
0051   ARROW_FRIEND_EXPORT friend std::ostream& operator<<(std::ostream&, const MockFileInfo&);
0052 };
0053 
0054 /// A mock FileSystem implementation that holds its contents in memory.
0055 ///
0056 /// Useful for validating the FileSystem API, writing conformance suite,
0057 /// and bootstrapping FileSystem-based APIs.
0058 class ARROW_EXPORT MockFileSystem : public FileSystem {
0059  public:
0060   explicit MockFileSystem(TimePoint current_time,
0061                           const io::IOContext& = io::default_io_context());
0062   ~MockFileSystem() override;
0063 
0064   std::string type_name() const override { return "mock"; }
0065 
0066   bool Equals(const FileSystem& other) const override;
0067   Result<std::string> PathFromUri(const std::string& uri_string) const override;
0068 
0069   /// \cond FALSE
0070   using FileSystem::CreateDir;
0071   using FileSystem::DeleteDirContents;
0072   using FileSystem::GetFileInfo;
0073   using FileSystem::OpenAppendStream;
0074   using FileSystem::OpenOutputStream;
0075   /// \endcond
0076 
0077   Result<FileInfo> GetFileInfo(const std::string& path) override;
0078   Result<std::vector<FileInfo>> GetFileInfo(const FileSelector& select) override;
0079 
0080   Status CreateDir(const std::string& path, bool recursive) override;
0081 
0082   Status DeleteDir(const std::string& path) override;
0083   Status DeleteDirContents(const std::string& path, bool missing_dir_ok) override;
0084   Status DeleteRootDirContents() override;
0085 
0086   Status DeleteFile(const std::string& path) override;
0087 
0088   Status Move(const std::string& src, const std::string& dest) override;
0089 
0090   Status CopyFile(const std::string& src, const std::string& dest) override;
0091 
0092   Result<std::shared_ptr<io::InputStream>> OpenInputStream(
0093       const std::string& path) override;
0094   Result<std::shared_ptr<io::RandomAccessFile>> OpenInputFile(
0095       const std::string& path) override;
0096   Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
0097       const std::string& path,
0098       const std::shared_ptr<const KeyValueMetadata>& metadata) override;
0099   Result<std::shared_ptr<io::OutputStream>> OpenAppendStream(
0100       const std::string& path,
0101       const std::shared_ptr<const KeyValueMetadata>& metadata) override;
0102 
0103   // Contents-dumping helpers to ease testing.
0104   // Output is lexicographically-ordered by full path.
0105   std::vector<MockDirInfo> AllDirs();
0106   std::vector<MockFileInfo> AllFiles();
0107 
0108   // Create a File with a content from a string.
0109   Status CreateFile(const std::string& path, std::string_view content,
0110                     bool recursive = true);
0111 
0112   // Create a MockFileSystem out of (empty) FileInfo. The content of every
0113   // file is empty and of size 0. All directories will be created recursively.
0114   static Result<std::shared_ptr<FileSystem>> Make(TimePoint current_time,
0115                                                   const std::vector<FileInfo>& infos);
0116 
0117   class Impl;
0118 
0119  protected:
0120   std::unique_ptr<Impl> impl_;
0121 };
0122 
0123 class ARROW_EXPORT MockAsyncFileSystem : public MockFileSystem {
0124  public:
0125   explicit MockAsyncFileSystem(TimePoint current_time,
0126                                const io::IOContext& io_context = io::default_io_context())
0127       : MockFileSystem(current_time, io_context) {
0128     default_async_is_sync_ = false;
0129   }
0130 
0131   FileInfoGenerator GetFileInfoGenerator(const FileSelector& select) override;
0132 };
0133 
0134 }  // namespace arrow::fs::internal