Integration test facility to ensure and assert processed events #1426
Labels
Status: Under Discussion
Use to signal that the issue in question is being discussed.
Type: Feature
Use to signal an issue is completely new to the project.
When integration testing an axon application that involves tracking event processors one quickly comes to the point when you need
a) to make sure that all events are processed by all event processors (so that the application is in a final state we can assert on), and
b) to determine, which events exactly have been published
To facilitate this, it would be nice to have some component in the axon-test module that allows to
a) "wait" for all TEPs to catch up to a certain state before continuing, and
b) return all events that have been published within a certain period of time (e.g. between two certain "marker"-events) to assert them in an integration test
We're currently doing this by implementing a
TestEventRecorder
that can be used from within an integration test. On a high level it works the following way:TestEventRecorder
to "record" state at the beginning of an integration test case and add a testCorrelationId to identify which events belong to the current test case.TestEventRecorder
record all events having this testCorrelationId until "stop" is called for a certain testCorrelationId.TestEventRecorder
by sending aRecordingCatchupEvent
directly to the event-bus and determine the tracking-token related to this event when it is processed in theTestEventRecorder
- then we can use the axon-config to get all other tracking event processors and simply block the stop method to wait until all production event processors have processsed up to this TrackingToken (see example code below)Since publishing and processing of events is happening at different times, we additionally implemented a
TestEventCorrelationIterceptor
(which is a regular axonMessageDispatchInterceptor
) that adds a testCorrelationId to the event metadata when publishing an event. Thus we make sure that the TestEventRecorder separates the recorded events per correlationId, even if the processing of in the TestEventRecorder happens after we already signaled the recorder to stop recording from within the integration test.Example for catching up other processors:
Example for the
TestEventCorrelationInterceptor
There has also been a recent discussion on this topic in the Axon Google Group: https://groups.google.com/d/msg/axonframework/AIIKVlYFEcs/Oi2UEsvQBgAJ
The text was updated successfully, but these errors were encountered: