Class FakeResilienceMetrics

java.lang.Object
io.github.teceli.resiliencia.test.FakeResilienceMetrics
All Implemented Interfaces:
ResilienceMetrics

public final class FakeResilienceMetrics extends Object implements ResilienceMetrics
Fake implementation of ResilienceMetrics for testing code that consumes metrics.

Captures all Snapshot and Counters emissions in thread-safe, queryable lists. Provides methods to interrogate captured metrics by type, introspect their values, and reset state between test runs.

Thread-safety: All method calls are thread-safe. Safe to use from multiple virtual threads or platform threads simultaneously, including concurrent calls to record(...) and getter methods.

  • Constructor Details

    • FakeResilienceMetrics

      public FakeResilienceMetrics()
  • Method Details

    • observe

      public void observe(Snapshot snapshot)
      Description copied from interface: ResilienceMetrics
      Observe a gauge-worthy snapshot of live state from CircuitBreaker, Bulkhead, or RateLimiter.
      Specified by:
      observe in interface ResilienceMetrics
      Parameters:
      snapshot - the snapshot to observe; never null
    • observe

      public void observe(Counters counters)
      Description copied from interface: ResilienceMetrics
      Observe a counter/timer-worthy occurrence from any pattern (Retry, Timeout, CircuitBreaker, Bulkhead, RateLimiter) or from Policy's order validation.
      Specified by:
      observe in interface ResilienceMetrics
      Parameters:
      counters - the counter event to observe; never null
    • getAllSnapshots

      public List<Snapshot> getAllSnapshots()
      Returns an immutable view of all captured snapshots in emission order.
      Returns:
      an immutable list, never null
    • getAllCounters

      public List<Counters> getAllCounters()
      Returns an immutable view of all captured counters in emission order.
      Returns:
      an immutable list, never null
    • getSnapshotsOfType

      public <T extends Snapshot> List<T> getSnapshotsOfType(Class<T> type)
      Returns all captured snapshots of a specific type.

      Performs an instanceof filter and cast. Useful for filtering to a single pattern's gauge emissions (e.g. CircuitBreakerSnapshot.class).

      Type Parameters:
      T - the snapshot type
      Parameters:
      type - the snapshot interface or record type to filter by
      Returns:
      an immutable list of matching snapshots in emission order, never null
    • getCountersOfType

      public <T extends Counters> List<T> getCountersOfType(Class<T> type)
      Returns all captured counters of a specific type.

      Performs an instanceof filter and cast. Useful for filtering to a single pattern's counter emissions (e.g. RetryCounters.class).

      Type Parameters:
      T - the counters type
      Parameters:
      type - the counters interface or record type to filter by
      Returns:
      an immutable list of matching counters in emission order, never null
    • snapshotCount

      public int snapshotCount()
      Returns the number of captured snapshots.
      Returns:
      the snapshot count
    • countersCount

      public int countersCount()
      Returns the number of captured counters.
      Returns:
      the counters count
    • reset

      public void reset()
      Clears all captured snapshots and counters.

      Useful for resetting state between test cases or after assertions.

    • isEmpty

      public boolean isEmpty()
      Returns true if no snapshots or counters have been captured.
      Returns:
      true if empty, false otherwise