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

Mock Azure Blob client for testing without Azure SDK dependency. More...

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

Classes

struct  blob_data
 

Public Member Functions

 mock_azure_client (const azure_storage_config &)
 
auto put_blob (const std::string &blob_name, const std::vector< std::uint8_t > &data) -> VoidResult override
 
auto get_blob (const std::string &blob_name) -> Result< std::vector< std::uint8_t > > override
 
auto delete_blob (const std::string &blob_name) -> VoidResult override
 
auto head_blob (const std::string &blob_name) const -> bool override
 
auto get_blob_size (const std::string &blob_name) const -> std::size_t override
 
auto get_blob_etag (const std::string &blob_name) const -> std::string override
 
auto get_blob_md5 (const std::string &blob_name) const -> std::string override
 
auto list_blobs () const -> std::vector< std::string > override
 
auto is_connected () const -> bool override
 
auto stage_block (const std::string &blob_name, const std::string &block_id, const std::vector< std::uint8_t > &data) -> VoidResult override
 
auto commit_blocks (const std::string &blob_name, const std::vector< std::string > &block_ids) -> VoidResult override
 
auto set_tier (const std::string &blob_name, const std::string &tier) -> VoidResult override
 
- Public Member Functions inherited from kcenon::pacs::storage::azure_blob_storage::azure_client_interface
virtual ~azure_client_interface ()=default
 

Private Attributes

std::unordered_map< std::string, blob_datablobs_
 
std::unordered_map< std::string, std::unordered_map< std::string, std::vector< std::uint8_t > > > staged_blocks_
 
bool connected_
 

Detailed Description

Mock Azure Blob client for testing without Azure SDK dependency.

Simulates Azure Blob operations using in-memory storage. Always used when PACS_USE_MOCK_AZURE is defined or PACS_WITH_AZURE_SDK is not set.

Definition at line 143 of file azure_blob_storage.cpp.

Constructor & Destructor Documentation

◆ mock_azure_client()

kcenon::pacs::storage::mock_azure_client::mock_azure_client ( const azure_storage_config & )
inlineexplicit

Member Function Documentation

◆ commit_blocks()

auto kcenon::pacs::storage::mock_azure_client::commit_blocks ( const std::string & blob_name,
const std::vector< std::string > & block_ids ) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 255 of file azure_blob_storage.cpp.

257 {
258 if (!connected_) {
259 return make_error<std::monostate>(
260 kConnectionError, "Azure client not connected",
261 "azure_blob_storage");
262 }
263
264 auto it = staged_blocks_.find(blob_name);
265 if (it == staged_blocks_.end()) {
266 return make_error<std::monostate>(
267 kUploadError, "No staged blocks found for: " + blob_name,
268 "azure_blob_storage");
269 }
270
271 std::vector<std::uint8_t> combined_data;
272 for (const auto &block_id : block_ids) {
273 auto block_it = it->second.find(block_id);
274 if (block_it == it->second.end()) {
275 return make_error<std::monostate>(
276 kUploadError, "Block not found: " + block_id,
277 "azure_blob_storage");
278 }
279 combined_data.insert(combined_data.end(), block_it->second.begin(),
280 block_it->second.end());
281 }
282
283 blob_data blob;
284 blob.data = std::move(combined_data);
285 blob.etag = "\"" + compute_content_hash(blob.data) + "\"";
286 blob.content_md5 = compute_content_hash(blob.data);
287 blob.tier = "Hot";
288 blobs_[blob_name] = std::move(blob);
289
290 staged_blocks_.erase(blob_name);
291 return ok();
292 }
std::unordered_map< std::string, std::unordered_map< std::string, std::vector< std::uint8_t > > > staged_blocks_
std::unordered_map< std::string, blob_data > blobs_

References kcenon::pacs::storage::mock_azure_client::blob_data::content_md5, kcenon::pacs::storage::mock_azure_client::blob_data::data, kcenon::pacs::storage::mock_azure_client::blob_data::etag, and kcenon::pacs::storage::mock_azure_client::blob_data::tier.

◆ delete_blob()

auto kcenon::pacs::storage::mock_azure_client::delete_blob ( const std::string & blob_name) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 182 of file azure_blob_storage.cpp.

183 {
184 if (!connected_) {
185 return make_error<std::monostate>(
186 kConnectionError, "Azure client not connected",
187 "azure_blob_storage");
188 }
189 blobs_.erase(blob_name);
190 return ok();
191 }

◆ get_blob()

auto kcenon::pacs::storage::mock_azure_client::get_blob ( const std::string & blob_name) -> Result<std::vector<std::uint8_t>>
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 166 of file azure_blob_storage.cpp.

167 {
168 if (!connected_) {
169 return make_error<std::vector<std::uint8_t>>(
170 kConnectionError, "Azure client not connected",
171 "azure_blob_storage");
172 }
173 auto it = blobs_.find(blob_name);
174 if (it == blobs_.end()) {
175 return make_error<std::vector<std::uint8_t>>(
176 kBlobNotFound, "Blob not found: " + blob_name,
177 "azure_blob_storage");
178 }
179 return it->second.data;
180 }

◆ get_blob_etag()

auto kcenon::pacs::storage::mock_azure_client::get_blob_etag ( const std::string & blob_name) const -> std::string
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 210 of file azure_blob_storage.cpp.

211 {
212 auto it = blobs_.find(blob_name);
213 if (it != blobs_.end()) {
214 return it->second.etag;
215 }
216 return {};
217 }

◆ get_blob_md5()

auto kcenon::pacs::storage::mock_azure_client::get_blob_md5 ( const std::string & blob_name) const -> std::string
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 219 of file azure_blob_storage.cpp.

220 {
221 auto it = blobs_.find(blob_name);
222 if (it != blobs_.end()) {
223 return it->second.content_md5;
224 }
225 return {};
226 }

◆ get_blob_size()

auto kcenon::pacs::storage::mock_azure_client::get_blob_size ( const std::string & blob_name) const -> std::size_t
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 201 of file azure_blob_storage.cpp.

202 {
203 auto it = blobs_.find(blob_name);
204 if (it != blobs_.end()) {
205 return it->second.data.size();
206 }
207 return 0;
208 }

◆ head_blob()

auto kcenon::pacs::storage::mock_azure_client::head_blob ( const std::string & blob_name) const -> bool
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 193 of file azure_blob_storage.cpp.

194 {
195 if (!connected_) {
196 return false;
197 }
198 return blobs_.contains(blob_name);
199 }

◆ is_connected()

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

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 238 of file azure_blob_storage.cpp.

238 {
239 return connected_;
240 }

◆ list_blobs()

auto kcenon::pacs::storage::mock_azure_client::list_blobs ( ) const -> std::vector<std::string>
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 228 of file azure_blob_storage.cpp.

229 {
230 std::vector<std::string> names;
231 names.reserve(blobs_.size());
232 for (const auto &[name, data] : blobs_) {
233 names.push_back(name);
234 }
235 return names;
236 }
std::string_view name

References name.

◆ put_blob()

auto kcenon::pacs::storage::mock_azure_client::put_blob ( const std::string & blob_name,
const std::vector< std::uint8_t > & data ) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 149 of file azure_blob_storage.cpp.

151 {
152 if (!connected_) {
153 return make_error<std::monostate>(
154 kConnectionError, "Azure client not connected",
155 "azure_blob_storage");
156 }
157 blob_data blob;
158 blob.data = data;
159 blob.etag = "\"" + compute_content_hash(data) + "\"";
160 blob.content_md5 = compute_content_hash(data);
161 blob.tier = "Hot";
162 blobs_[blob_name] = std::move(blob);
163 return ok();
164 }

References kcenon::pacs::storage::mock_azure_client::blob_data::content_md5, kcenon::pacs::storage::mock_azure_client::blob_data::data, kcenon::pacs::storage::mock_azure_client::blob_data::etag, and kcenon::pacs::storage::mock_azure_client::blob_data::tier.

◆ set_tier()

auto kcenon::pacs::storage::mock_azure_client::set_tier ( const std::string & blob_name,
const std::string & tier ) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 294 of file azure_blob_storage.cpp.

296 {
297 if (!connected_) {
298 return make_error<std::monostate>(
299 kConnectionError, "Azure client not connected",
300 "azure_blob_storage");
301 }
302 auto it = blobs_.find(blob_name);
303 if (it == blobs_.end()) {
304 return make_error<std::monostate>(
305 kBlobNotFound, "Blob not found: " + blob_name,
306 "azure_blob_storage");
307 }
308 it->second.tier = tier;
309 return ok();
310 }

◆ stage_block()

auto kcenon::pacs::storage::mock_azure_client::stage_block ( const std::string & blob_name,
const std::string & block_id,
const std::vector< std::uint8_t > & data ) -> VoidResult
inlinenodiscardoverridevirtual

Implements kcenon::pacs::storage::azure_blob_storage::azure_client_interface.

Definition at line 242 of file azure_blob_storage.cpp.

245 {
246 if (!connected_) {
247 return make_error<std::monostate>(
248 kConnectionError, "Azure client not connected",
249 "azure_blob_storage");
250 }
251 staged_blocks_[blob_name][block_id] = data;
252 return ok();
253 }

Member Data Documentation

◆ blobs_

std::unordered_map<std::string, blob_data> kcenon::pacs::storage::mock_azure_client::blobs_
private

Definition at line 320 of file azure_blob_storage.cpp.

◆ connected_

bool kcenon::pacs::storage::mock_azure_client::connected_
private

Definition at line 324 of file azure_blob_storage.cpp.

◆ staged_blocks_

std::unordered_map<std::string, std::unordered_map<std::string, std::vector<std::uint8_t> > > kcenon::pacs::storage::mock_azure_client::staged_blocks_
private

Definition at line 323 of file azure_blob_storage.cpp.


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