pub struct MockDurableServiceClient { /* private fields */ }Expand description
Mock implementation of DurableServiceClient for testing.
This mock client allows you to:
- Configure responses for checkpoint and get_operations calls
- Record all calls made for verification in tests
- Simulate error conditions
§Thread Safety
The mock client uses internal mutexes to allow safe concurrent access from multiple tasks.
§Examples
§Basic Usage
use durable_execution_sdk_testing::MockDurableServiceClient;
let client = MockDurableServiceClient::new();§With Custom Responses
use durable_execution_sdk_testing::MockDurableServiceClient;
use durable_execution_sdk::{CheckpointResponse, DurableError};
let client = MockDurableServiceClient::new()
.with_checkpoint_response(Ok(CheckpointResponse::new("token-1")))
.with_checkpoint_response(Err(DurableError::checkpoint_retriable("Temporary error")));§Verifying Calls
use durable_execution_sdk_testing::{MockDurableServiceClient, DurableServiceClient};
use durable_execution_sdk::{OperationUpdate, OperationType};
let client = MockDurableServiceClient::new();
client.checkpoint("arn:test", "token", vec![]).await.unwrap();
let calls = client.get_checkpoint_calls();
assert_eq!(calls.len(), 1);Implementations§
Source§impl MockDurableServiceClient
impl MockDurableServiceClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new mock client with no pre-configured responses.
When no responses are configured, the client will return default successful responses.
Sourcepub fn with_checkpoint_response(
self,
response: Result<CheckpointResponse, DurableError>,
) -> Self
pub fn with_checkpoint_response( self, response: Result<CheckpointResponse, DurableError>, ) -> Self
Adds a checkpoint response to be returned.
Responses are returned in the order they were added (FIFO). Once all configured responses are consumed, the client returns default successful responses.
§Examples
use durable_execution_sdk_testing::MockDurableServiceClient;
use durable_execution_sdk::CheckpointResponse;
let client = MockDurableServiceClient::new()
.with_checkpoint_response(Ok(CheckpointResponse::new("token-1")));Sourcepub fn with_checkpoint_responses(self, count: usize) -> Self
pub fn with_checkpoint_responses(self, count: usize) -> Self
Adds multiple default checkpoint responses.
Each response will have a unique token in the format “token-{index}”.
§Examples
use durable_execution_sdk_testing::MockDurableServiceClient;
// Add 5 default checkpoint responses
let client = MockDurableServiceClient::new()
.with_checkpoint_responses(5);Sourcepub fn with_checkpoint_response_with_operations(
self,
token: impl Into<String>,
operations: Vec<Operation>,
) -> Self
pub fn with_checkpoint_response_with_operations( self, token: impl Into<String>, operations: Vec<Operation>, ) -> Self
Adds a checkpoint response that includes operations in the new execution state.
This is useful for testing scenarios where the checkpoint response includes service-generated values like callback IDs.
§Examples
use durable_execution_sdk_testing::MockDurableServiceClient;
use durable_execution_sdk::{Operation, OperationType};
let op = Operation::new("op-1", OperationType::Callback);
let client = MockDurableServiceClient::new()
.with_checkpoint_response_with_operations("token-1", vec![op]);Sourcepub fn with_get_operations_response(
self,
response: Result<GetOperationsResponse, DurableError>,
) -> Self
pub fn with_get_operations_response( self, response: Result<GetOperationsResponse, DurableError>, ) -> Self
Adds a get_operations response to be returned.
Responses are returned in the order they were added (FIFO). Once all configured responses are consumed, the client returns default empty responses.
§Examples
use durable_execution_sdk_testing::MockDurableServiceClient;
use durable_execution_sdk::{GetOperationsResponse, Operation, OperationType};
let client = MockDurableServiceClient::new()
.with_get_operations_response(Ok(GetOperationsResponse {
operations: vec![Operation::new("op-1", OperationType::Step)],
next_marker: None,
}));Sourcepub fn get_checkpoint_calls(&self) -> Vec<CheckpointCall>
pub fn get_checkpoint_calls(&self) -> Vec<CheckpointCall>
Gets all checkpoint calls made to this mock client.
Returns a clone of the recorded calls, allowing verification without consuming the records.
§Examples
use durable_execution_sdk_testing::{MockDurableServiceClient, DurableServiceClient};
let client = MockDurableServiceClient::new();
client.checkpoint("arn:test", "token", vec![]).await.unwrap();
let calls = client.get_checkpoint_calls();
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].durable_execution_arn, "arn:test");Sourcepub fn get_get_operations_calls(&self) -> Vec<GetOperationsCall>
pub fn get_get_operations_calls(&self) -> Vec<GetOperationsCall>
Gets all get_operations calls made to this mock client.
Returns a clone of the recorded calls, allowing verification without consuming the records.
Sourcepub fn clear_checkpoint_calls(&self)
pub fn clear_checkpoint_calls(&self)
Clears all recorded checkpoint calls.
This is useful when reusing a mock client across multiple test cases.
Sourcepub fn clear_get_operations_calls(&self)
pub fn clear_get_operations_calls(&self)
Clears all recorded get_operations calls.
Sourcepub fn clear_all_calls(&self)
pub fn clear_all_calls(&self)
Clears all recorded calls (both checkpoint and get_operations).
Sourcepub fn checkpoint_call_count(&self) -> usize
pub fn checkpoint_call_count(&self) -> usize
Returns the number of checkpoint calls made.
Sourcepub fn get_operations_call_count(&self) -> usize
pub fn get_operations_call_count(&self) -> usize
Returns the number of get_operations calls made.
Trait Implementations§
Source§impl Debug for MockDurableServiceClient
impl Debug for MockDurableServiceClient
Source§impl Default for MockDurableServiceClient
impl Default for MockDurableServiceClient
Source§impl DurableServiceClient for MockDurableServiceClient
impl DurableServiceClient for MockDurableServiceClient
Source§fn checkpoint<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
durable_execution_arn: &'life1 str,
checkpoint_token: &'life2 str,
operations: Vec<OperationUpdate>,
) -> Pin<Box<dyn Future<Output = Result<CheckpointResponse, DurableError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn checkpoint<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
durable_execution_arn: &'life1 str,
checkpoint_token: &'life2 str,
operations: Vec<OperationUpdate>,
) -> Pin<Box<dyn Future<Output = Result<CheckpointResponse, DurableError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn get_operations<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
durable_execution_arn: &'life1 str,
next_marker: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<GetOperationsResponse, DurableError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_operations<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
durable_execution_arn: &'life1 str,
next_marker: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<GetOperationsResponse, DurableError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl !Freeze for MockDurableServiceClient
impl RefUnwindSafe for MockDurableServiceClient
impl Send for MockDurableServiceClient
impl Sync for MockDurableServiceClient
impl Unpin for MockDurableServiceClient
impl UnsafeUnpin for MockDurableServiceClient
impl UnwindSafe for MockDurableServiceClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more