Class RecordingLiabilitySink

java.lang.Object
com.tnsai.accountability.RecordingLiabilitySink
All Implemented Interfaces:
LiabilitySink

public final class RecordingLiabilitySink extends Object implements LiabilitySink
In-memory LiabilitySink for tests and assertions (TNS-298). Holds every record in a list; tests verify production code emitted the right liability shape via records, recordCount(), lastRecord().

Concurrency

Backed by a ReentrantReadWriteLock so concurrent dispatch threads don't lose records under contention. Test code typically doesn't hit that path; the lock is cheap when uncontended.

Append-only contract

Records aren't editable through this surface. clear() is provided for test isolation (set up / tear down between cases) and intentionally lives outside the LiabilitySink interface so production sinks don't see it.
Since:
0.10.0 (TNS-298)
  • Constructor Details

    • RecordingLiabilitySink

      public RecordingLiabilitySink()
  • Method Details

    • record

      public void record(AgentLiabilityRecord rec)
      Description copied from interface: LiabilitySink
      Persist a record. Returns when the entry is durable in the implementation's backing store. Implementations MUST NOT swallow exceptions — a sink failure under load is an operational incident that needs to surface.
      Specified by:
      record in interface LiabilitySink
    • query

      Description copied from interface: LiabilitySink
      Stream records matching q in invocation-order (oldest first). Stream MUST be closed by the caller — durable sinks may hold a cursor open.
      Specified by:
      query in interface LiabilitySink
    • records

      public List<AgentLiabilityRecord> records()
      Returns:
      defensive copy of every record so far.
    • recordCount

      public int recordCount()
      Test helper: how many records have been recorded.
    • lastRecord

      public Optional<AgentLiabilityRecord> lastRecord()
      Test helper: most recent record, or empty when none recorded.
    • clear

      public void clear()
      Test helper: drop every record.