Class InMemoryInvocationEventEmitter
- All Implemented Interfaces:
InvocationEventEmitter
InvocationEventEmitter that records every event it receives in
memory instead of publishing it anywhere, so a test can assert on what
@Logged actually observed about a call.
Registering this as the InvocationEventEmitter bean (or passing
it directly to a framework-free LoggedAspect) turns the emission
side effect into something a test can inspect synchronously, without
capturing log output or standing up a real sink.
Backed by a CopyOnWriteArrayList because a @Logged
method under test may itself dispatch work to another thread (for example
through FlowContextPropagatingExecutor); emission from more than
one thread must not corrupt the recorded list or lose an event.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Discards every event recorded so far, so this instance can be reused across test methods without leaking state between them.intcount()Returns the number of events recorded so far.voidemit(MethodInvocationEvent event) Publishes the given invocation event to whatever sink this implementation targets.events()Returns every event recorded so far, in emission order.Returns the most recently recorded event.
-
Constructor Details
-
InMemoryInvocationEventEmitter
public InMemoryInvocationEventEmitter()
-
-
Method Details
-
emit
Description copied from interface:InvocationEventEmitterPublishes the given invocation event to whatever sink this implementation targets.Implementations must not throw checked or unchecked exceptions that would propagate back into the intercepted method call. Emission failures (for example a logging backend being unavailable) should be handled internally by the implementation.
- Specified by:
emitin interfaceInvocationEventEmitter- Parameters:
event- the invocation event to publish, nevernull
-
events
Returns every event recorded so far, in emission order.- Returns:
- an immutable snapshot of the recorded events
-
count
public int count()Returns the number of events recorded so far.- Returns:
- the recorded event count
-
lastEvent
Returns the most recently recorded event.- Returns:
- the last recorded event
- Throws:
IllegalStateException- if no event has been recorded yet
-
clear
public void clear()Discards every event recorded so far, so this instance can be reused across test methods without leaking state between them.
-