Spying on events#
Spies are useful when you need to track which events flow into a
Uni or a
Spies can track events from groups such as
io.smallrye.mutiny.helpers.spies.Spy interface offers factory methods to spy on selected groups, or even on all groups.
Spying selected groups#
The following example spies on requests and completion group events:
The standard output stream shall display the following text:
The number of requests corresponds to
Long.MAX_VALUE, and a completion event was sent.
It is important to note that spies observe and report events for all subscribers, not just one in particular.
You should call the
.reset() method on a given spy to resets its statistics such as the invocation count.
Spying all groups#
You can take advantage of a global spy if you are interested in all event groups:
Running the snippet above gives the following output:
onItem() events on a
Multi requires storing all items into a list, which can yield an out-of-memory
exception with large streams.
In such cases consider using
Spy.onItem(multi, false) to obtain a spy that does not store items, but that can
still report data such as the number of received events (see