DefaultChaosPolicy

Default implementation of the chaos policy.

Behaviour (in order):

  1. If ChaosConfig.latency is not null, suspends for that duration.

  2. If ChaosConfig.failureRate > 0, rolls a random double; if < failureRate, throws the configured ChaosConfig.exception (defaults to RuntimeException("Chaos fault injected")).

  3. If ChaosConfig.injectResult is set and no fault fired, executes the block (for side-effects), discards its result, and returns ChaosConfig.injectResult instead.

  4. Otherwise executes the block normally and returns its result.

When ChaosConfig.enabled is false, this policy must NOT be installed — the resilient builder handles this guard and will not instantiate DefaultChaosPolicy for disabled configs.

Parameters

config

The ChaosConfig driving this policy's behaviour.

Constructors

Link copied to clipboard
constructor(config: ChaosConfig)

Functions

Link copied to clipboard
suspend fun <T> execute(block: suspend () -> T): T

Executes block, potentially injecting latency, a fault, or an overridden result.