PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::storage::mock_s3_client Class Reference

Mock S3 client for testing without AWS SDK dependency. More...

Inheritance diagram for kcenon::pacs::storage::mock_s3_client:
Inheritance graph
Collaboration diagram for kcenon::pacs::storage::mock_s3_client:
Collaboration graph

Public Member Functions

 mock_s3_client (const cloud_storage_config &)
 
auto put_object (const std::string &key, const std::vector< std::uint8_t > &data) -> VoidResult override
 
auto get_object (const std::string &key) -> Result< std::vector< std::uint8_t > > override
 
auto delete_object (const std::string &key) -> VoidResult override
 
auto head_object (const std::string &key) const -> bool override
 
auto get_object_size (const std::string &key) const -> std::size_t override
 
auto list_objects () const -> std::vector< std::string > override
 
auto is_connected () const -> bool override
 
auto multipart_upload (const std::string &key, const std::vector< std::uint8_t > &data, std::size_t part_size, progress_callback callback) -> VoidResult override
 
- Public Member Functions inherited from kcenon::pacs::storage::s3_storage::s3_client_interface
virtual ~s3_client_interface ()=default
 

Private Attributes

std::unordered_map< std::string, std::vector< std::uint8_t > > objects_
 
bool connected_
 

Detailed Description

Mock S3 client for testing without AWS SDK dependency.

Simulates S3 operations using in-memory storage. Always used when PACS_USE_MOCK_S3 is defined or PACS_WITH_AWS_SDK is not set.

Definition at line 112 of file s3_storage.cpp.

Constructor & Destructor Documentation

◆ mock_s3_client()

kcenon::pacs::storage::mock_s3_client::mock_s3_client ( const cloud_storage_config & )
inlineexplicit

Definition at line 114 of file s3_storage.cpp.

Member Function Documentation

◆ delete_object()

auto kcenon::pacs::storage::mock_s3_client::delete_object ( const std::string & key) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 142 of file s3_storage.cpp.

143 {
144 if (!connected_) {
145 return make_error<std::monostate>(
146 kConnectionError, "S3 client not connected", "s3_storage");
147 }
148 objects_.erase(key);
149 return ok();
150 }
std::unordered_map< std::string, std::vector< std::uint8_t > > objects_

◆ get_object()

auto kcenon::pacs::storage::mock_s3_client::get_object ( const std::string & key) -> Result<std::vector<std::uint8_t>>
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 128 of file s3_storage.cpp.

129 {
130 if (!connected_) {
131 return make_error<std::vector<std::uint8_t>>(
132 kConnectionError, "S3 client not connected", "s3_storage");
133 }
134 auto it = objects_.find(key);
135 if (it == objects_.end()) {
136 return make_error<std::vector<std::uint8_t>>(
137 kObjectNotFound, "Object not found: " + key, "s3_storage");
138 }
139 return it->second;
140 }

◆ get_object_size()

auto kcenon::pacs::storage::mock_s3_client::get_object_size ( const std::string & key) const -> std::size_t
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 160 of file s3_storage.cpp.

161 {
162 auto it = objects_.find(key);
163 if (it != objects_.end()) {
164 return it->second.size();
165 }
166 return 0;
167 }

◆ head_object()

auto kcenon::pacs::storage::mock_s3_client::head_object ( const std::string & key) const -> bool
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 152 of file s3_storage.cpp.

153 {
154 if (!connected_) {
155 return false;
156 }
157 return objects_.contains(key);
158 }

◆ is_connected()

auto kcenon::pacs::storage::mock_s3_client::is_connected ( ) const -> bool
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 179 of file s3_storage.cpp.

179 {
180 return connected_;
181 }

◆ list_objects()

auto kcenon::pacs::storage::mock_s3_client::list_objects ( ) const -> std::vector<std::string>
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 169 of file s3_storage.cpp.

170 {
171 std::vector<std::string> keys;
172 keys.reserve(objects_.size());
173 for (const auto &[key, data] : objects_) {
174 keys.push_back(key);
175 }
176 return keys;
177 }

◆ multipart_upload()

auto kcenon::pacs::storage::mock_s3_client::multipart_upload ( const std::string & key,
const std::vector< std::uint8_t > & data,
std::size_t part_size,
progress_callback callback ) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 183 of file s3_storage.cpp.

187 {
188 std::size_t total_bytes = data.size();
189 std::size_t bytes_uploaded = 0;
190
191 while (bytes_uploaded < total_bytes) {
192 std::size_t chunk = (std::min)(part_size, total_bytes - bytes_uploaded);
193 bytes_uploaded += chunk;
194
195 if (callback && !callback(bytes_uploaded, total_bytes)) {
196 return make_error<std::monostate>(
197 kUploadError, "Upload cancelled by user", "s3_storage");
198 }
199 }
200
201 return put_object(key, data);
202 }
auto put_object(const std::string &key, const std::vector< std::uint8_t > &data) -> VoidResult override

References kcenon::pacs::storage::s3_storage::s3_client_interface::put_object().

Here is the call graph for this function:

◆ put_object()

auto kcenon::pacs::storage::mock_s3_client::put_object ( const std::string & key,
const std::vector< std::uint8_t > & data ) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::s3_storage::s3_client_interface.

Definition at line 117 of file s3_storage.cpp.

119 {
120 if (!connected_) {
121 return make_error<std::monostate>(
122 kConnectionError, "S3 client not connected", "s3_storage");
123 }
124 objects_[key] = data;
125 return ok();
126 }

Member Data Documentation

◆ connected_

bool kcenon::pacs::storage::mock_s3_client::connected_
private

Definition at line 206 of file s3_storage.cpp.

◆ objects_

std::unordered_map<std::string, std::vector<std::uint8_t> > kcenon::pacs::storage::mock_s3_client::objects_
private

Definition at line 205 of file s3_storage.cpp.


The documentation for this class was generated from the following file: