Class FakeResilienceMetrics
java.lang.Object
io.github.teceli.resiliencia.test.FakeResilienceMetrics
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of captured counters.Returns an immutable view of all captured counters in emission order.Returns an immutable view of all captured snapshots in emission order.getCountersOfType(Class<T> type) Returns all captured counters of a specific type.getSnapshotsOfType(Class<T> type) Returns all captured snapshots of a specific type.booleanisEmpty()Returns true if no snapshots or counters have been captured.voidObserve a counter/timer-worthy occurrence from any pattern (Retry, Timeout, CircuitBreaker, Bulkhead, RateLimiter) or from Policy's order validation.voidObserve a gauge-worthy snapshot of live state from CircuitBreaker, Bulkhead, or RateLimiter.voidreset()Clears all captured snapshots and counters.intReturns the number of captured snapshots.
-
Constructor Details
-
FakeResilienceMetrics
public FakeResilienceMetrics()
-
-
Method Details
-
observe
Description copied from interface:ResilienceMetricsObserve a gauge-worthy snapshot of live state from CircuitBreaker, Bulkhead, or RateLimiter.- Specified by:
observein interfaceResilienceMetrics- Parameters:
snapshot- the snapshot to observe; never null
-
observe
Description copied from interface:ResilienceMetricsObserve a counter/timer-worthy occurrence from any pattern (Retry, Timeout, CircuitBreaker, Bulkhead, RateLimiter) or from Policy's order validation.- Specified by:
observein interfaceResilienceMetrics- Parameters:
counters- the counter event to observe; never null
-
getAllSnapshots
Returns an immutable view of all captured snapshots in emission order.- Returns:
- an immutable list, never null
-
getAllCounters
Returns an immutable view of all captured counters in emission order.- Returns:
- an immutable list, never null
-
getSnapshotsOfType
Returns all captured snapshots of a specific type.Performs an
instanceoffilter 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
Returns all captured counters of a specific type.Performs an
instanceoffilter 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
-