Package com.tnsai.observability.events
Class CapturingAgentEventPublisher
java.lang.Object
com.tnsai.observability.events.CapturingAgentEventPublisher
- All Implemented Interfaces:
AgentEventPublisher
In-memory
AgentEventPublisher for unit tests — records every
published event so the test can assert on them.
Not registered via SPI. Tests instantiate directly:
var capturer = new CapturingAgentEventPublisher();
agent.setEventPublisher(capturer);
agent.chat("hello");
assertThat(capturer.events()).hasSize(3);
assertThat(capturer.events().get(0)).isInstanceOf(ChatEvent.class);
Backed by CopyOnWriteArrayList — safe for concurrent
publication from multiple threads (e.g. when testing that streaming
chunks fire from worker threads).
- Since:
- 0.5.0 (issue #78)
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncaptured()voidclear()Drop everything captured so far.events()voidpublish(TnsAIEvent event) Publish a single event.voidpublish(TnsAIEvent event, EventLevel level, EventContext context) Publish a single event with explicit level / context overrides.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.observability.events.AgentEventPublisher
isEnabled
-
Constructor Details
-
CapturingAgentEventPublisher
public CapturingAgentEventPublisher()
-
-
Method Details
-
publish
Description copied from interface:AgentEventPublisherPublish a single event. Implementations must be safe to call from any thread; they may queue, batch, or write directly. Errors during publication must not propagate to the caller — log and drop.- Specified by:
publishin interfaceAgentEventPublisher
-
publish
Description copied from interface:AgentEventPublisherPublish a single event with explicit level / context overrides. Useful when emitting an event at a level different from the event's default (e.g. demoting a verbose ChatEvent to DEBUG in production).Default implementation ignores overrides — concrete publishers that care about level filtering (Slf4j) override this.
- Specified by:
publishin interfaceAgentEventPublisher
-
events
- Returns:
- all captured events in publication order.
-
captured
- Returns:
- all captures with their (level, context) at publication time.
-
clear
public void clear()Drop everything captured so far. Useful between test phases.
-