Skip to main content

MockDurableServiceClient

Struct MockDurableServiceClient 

Source
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

Source

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.

Source

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")));
Source

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);
Source

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]);
Source

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,
    }));
Source

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");
Source

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.

Source

pub fn clear_checkpoint_calls(&self)

Clears all recorded checkpoint calls.

This is useful when reusing a mock client across multiple test cases.

Source

pub fn clear_get_operations_calls(&self)

Clears all recorded get_operations calls.

Source

pub fn clear_all_calls(&self)

Clears all recorded calls (both checkpoint and get_operations).

Source

pub fn checkpoint_call_count(&self) -> usize

Returns the number of checkpoint calls made.

Source

pub fn get_operations_call_count(&self) -> usize

Returns the number of get_operations calls made.

Trait Implementations§

Source§

impl Debug for MockDurableServiceClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MockDurableServiceClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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,

Sends a batch of checkpoint operations to the service. Read more
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,

Retrieves additional operations for pagination. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more