Package com.tnsai.observability.errors
Class CapturingErrorReportPublisher
java.lang.Object
com.tnsai.observability.errors.CapturingErrorReportPublisher
- All Implemented Interfaces:
ErrorReportPublisher
In-memory
ErrorReportPublisher for tests. Holds every
published report in insertion order; assertions can drain or
filter.
Not registered via SPI — must be wired
explicitly via ErrorReports.setPublisher(ErrorReportPublisher)
in the test's setUp / @BeforeEach, and torn down in @AfterEach.
Tests that forget the teardown leak captured reports across
methods.
Thread-safety: backed by a CopyOnWriteArrayList so
concurrent publish(ErrorReport) and
don't blow up. Reads see a snapshot at the moment of iteration.invalid reference
#drain()
- Since:
- 0.5.0 (issue #86)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncaptured()Immutable snapshot of every captured report so far.voidclear()Empties the buffer.last()Last captured report, ornullif none.matching(Predicate<ErrorReport> filter) Reports matching a predicate (e.g. by fingerprint or category).voidpublish(ErrorReport report) Publish a single error report.intsize()Number of reports captured so far.
-
Constructor Details
-
CapturingErrorReportPublisher
public CapturingErrorReportPublisher()
-
-
Method Details
-
publish
Description copied from interface:ErrorReportPublisherPublish a single error report. Errors during publication must not propagate to the caller — the caller is already in an error path; an exception here would mask the original failure.- Specified by:
publishin interfaceErrorReportPublisher
-
captured
Immutable snapshot of every captured report so far. -
size
public int size()Number of reports captured so far. -
last
Last captured report, ornullif none. -
matching
Reports matching a predicate (e.g. by fingerprint or category). -
clear
public void clear()Empties the buffer. Use between test cases for isolation.
-