1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//! Fault injection framework for testing Cosmos DB client behavior under error conditions.
//!
//! This module is a pure re-export facade over the driver's fault-injection
//! primitives — every type is re-exported directly from
//! [`azure_data_cosmos_driver::fault_injection`]. Build
//! [`FaultInjectionRule`]s with [`FaultInjectionRuleBuilder`] and pass the
//! `Vec<Arc<FaultInjectionRule>>` to
//! [`CosmosClientBuilder::with_fault_injection`](crate::CosmosClientBuilder::with_fault_injection),
//! which forwards them into the driver runtime; the driver's own
//! fault-injection transport client evaluates the rules on every in-flight
//! request.
//!
//! Below the transport layer, fault injection intercepts HTTP requests and
//! triggers the same retry and failover behavior as a real service error.
//! It enables testing of:
//!
//! - Error handling for various HTTP status codes (503, 500, 429, 408, etc.)
//! - Retry logic and backoff behavior
//! - Regional failover scenarios
//! - Operation-specific error handling
//!
//! # Enabling Fault Injection
//!
//! Fault injection requires the `fault_injection` feature flag:
//!
//! ```toml
//! [dependencies]
//! azure_data_cosmos = { version = "0.31", features = ["fault_injection"] }
//! ```
//!
//! # Core Components
//!
//! - [`FaultInjectionRule`] — Combines a condition with a result and
//! additional controls like duration, start delay, and hit limit. Build
//! with [`FaultInjectionRuleBuilder`]; pass a `Vec<Arc<FaultInjectionRule>>`
//! to [`CosmosClientBuilder::with_fault_injection`](crate::CosmosClientBuilder::with_fault_injection).
//! - [`FaultInjectionCondition`] — Defines when a fault should be applied,
//! filtering by operation type, region, container ID, or transport kind.
//! - [`FaultInjectionResult`] — Defines what error to inject, including
//! error type, delay, and probability.
//!
//! # Usage
//!
//! ```rust,no_run
//! use azure_data_cosmos::fault_injection::{
//! FaultInjectionConditionBuilder, FaultInjectionErrorType,
//! FaultInjectionResultBuilder, FaultInjectionRuleBuilder, FaultOperationType,
//! };
//! use azure_data_cosmos::CosmosClientBuilder;
//! use azure_data_cosmos::AccountReference;
//! use azure_core::credentials::Secret;
//! use std::sync::Arc;
//! use std::time::{Duration, Instant};
//!
//! # async fn doc() {
//! // 1. Define what error to inject
//! let result = FaultInjectionResultBuilder::new()
//! .with_error(FaultInjectionErrorType::ServiceUnavailable)
//! .with_delay(Duration::from_millis(100))
//! .with_probability(1.0)
//! .build();
//!
//! // 2. Define when to inject it
//! let condition = FaultInjectionConditionBuilder::new()
//! .with_operation_type(FaultOperationType::ReadItem)
//! .with_region("West US".into())
//! .build();
//!
//! // 3. Create a rule with timing constraints
//! let rule = Arc::new(FaultInjectionRuleBuilder::new("region-failover-test", result)
//! .with_condition(condition)
//! .with_hit_limit(5)
//! .with_end_time(Instant::now() + Duration::from_secs(30))
//! .build());
//!
//! // 4. Create the client with fault injection — pass the rules directly,
//! // no SDK-side wrapper builder.
//! let client = CosmosClientBuilder::new()
//! .with_fault_injection(vec![rule])
//! .build(
//! AccountReference::with_authentication_key(
//! "https://myaccount.documents.azure.com/".parse().unwrap(),
//! Secret::new("my_account_key"),
//! ),
//! azure_data_cosmos::RoutingStrategy::ProximityTo("East US".into()),
//! )
//! .await
//! .unwrap();
//! # }
//! ```
//!
//! # Rule Evaluation
//!
//! Rules are evaluated in the order they were added. The first matching rule is applied.
//! All specified conditions in a [`FaultInjectionCondition`] must match (AND logic):
//! if no conditions are specified, the rule matches all requests.
pub use ;