Class ChaosProbability

java.lang.Object
org.mockserver.model.ChaosProbability

public final class ChaosProbability extends Object
Shared deterministic probability-draw logic for chaos injection, used by both HttpChaosProfile (HTTP fault injection) and LlmChaosProfile (LLM fault injection).

Determinism contract:

  • probability == null or probability >= 1.0 → always inject
  • probability <= 0.0 → never inject
  • Otherwise a single draw decides; when seed != null the draw is reproducible (same seed always yields the same result).
  • Method Details

    • shouldInject

      public static boolean shouldInject(Double probability, Long seed)
      Returns true when a chaos fault should be injected, based on the given probability and optional seed for reproducibility.
      Parameters:
      probability - a value in [0.0, 1.0], or null (treated as 1.0)
      seed - optional seed for reproducible draws; null uses ThreadLocalRandom
      Returns:
      true if the fault should fire