Class RecordingEventStore

java.lang.Object
org.axonframework.test.fixture.RecordingEventSink
org.axonframework.test.fixture.RecordingEventStore
All Implemented Interfaces:
DescribableComponent, EventStore, SubscribableEventSource, EventBus, EventSink, StreamableEventSource, TrackingTokenSource

@Internal public class RecordingEventStore extends RecordingEventSink implements EventStore
An EventStore implementation recording all the events that are published.

The recorded events can then be used to assert expectations with test cases.

Since:
5.0.0
Author:
Allard Buijze, Mateusz Nowak
  • Constructor Details

    • RecordingEventStore

      public RecordingEventStore(@Nonnull EventStore delegate)
      Creates a new RecordingEventStore that will record all events published to the given delegate.
      Parameters:
      delegate - The EventStore to which events will be published.
  • Method Details

    • transaction

      public EventStoreTransaction transaction(@NotNull @NotNull ProcessingContext processingContext)
      Description copied from interface: EventStore
      Retrieves the transaction for appending events for the given processingContext. If no transaction is available, a new, empty transaction is created.
      Specified by:
      transaction in interface EventStore
      Parameters:
      processingContext - The context for which to retrieve the EventStoreTransaction.
      Returns:
      The EventStoreTransaction, existing or newly created, for the given processingContext.
    • describeTo

      public void describeTo(@NotNull @NotNull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Overrides:
      describeTo in class RecordingEventSink
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • open

      public MessageStream<EventMessage> open(@Nonnull StreamingCondition condition, @Nullable ProcessingContext context)
      Description copied from interface: StreamableEventSource
      Open an event stream containing all events matching the given condition.

      To retrieve the position of the returned events, the TrackingToken.fromContext(Context) operation should be used by providing the entire MessageStream.Entry wrapping the returned events.

      Note that the returned stream is infinite, so beware of applying terminal operations to the returned stream.

      When all events are of interest during streaming, then use EventCriteria.havingAnyTag() as the condition criteria.

      Specified by:
      open in interface StreamableEventSource
      Parameters:
      condition - The StreamingCondition defining the starting position of the stream and event criteria to filter the stream with.
      context - The current ProcessingContext, if any.
      Returns:
      An event stream matching the given condition.
    • firstToken

      public CompletableFuture<TrackingToken> firstToken(@Nullable ProcessingContext context)
      Description copied from interface: TrackingTokenSource
      Creates a TrackingToken representing the first position of the event stream.

      As the retrieved token represents the point from which to

      invalid reference
      open
      the event stream, the first event to be streamed when opening is the one right after the returned token.

      Subsequent invocation of this method will yield the same result, unless the stream's initial values are deleted.

      Specified by:
      firstToken in interface TrackingTokenSource
      Parameters:
      context - The current ProcessingContext, if any.
      Returns:
      A CompletableFuture of a TrackingToken representing the first event of the event stream.
    • latestToken

      public CompletableFuture<TrackingToken> latestToken(@Nullable ProcessingContext context)
      Description copied from interface: TrackingTokenSource
      Creates a TrackingToken representing the latest position, thus pointing at the next event of the event stream.

      As the retrieved token represents the point from which to

      invalid reference
      open
      the event stream, the first event to be streamed when opening is the one right after the returned token.

      Since the event stream of this source is theoretically infinite, subsequent invocation of this operation typically return a different token. Only if this StreamableEventSource is idle, will several latestToken() invocations result in the same TrackingToken.

      Specified by:
      latestToken in interface TrackingTokenSource
      Parameters:
      context - The current ProcessingContext, if any.
      Returns:
      A CompletableFuture of a TrackingToken representing the latest event, thus pointing at the next event of the event stream.
    • tokenAt

      public CompletableFuture<TrackingToken> tokenAt(@Nonnull Instant at, @Nullable ProcessingContext context)
      Description copied from interface: TrackingTokenSource
      Creates a TrackingToken tracking all events after the given at from an event stream.

      When there is an EventMessage exactly at the given dateTime, it will be tracked too.

      Specified by:
      tokenAt in interface TrackingTokenSource
      Parameters:
      at - The Instant determining how the TrackingToken should be created. The returned token points at very first event before this Instant.
      context - The current ProcessingContext, if any.
      Returns:
      A CompletableFuture of TrackingToken pointing at the very first event before the given at of the event stream.
    • subscribe

      public Registration subscribe(@Nonnull BiFunction<List<? extends EventMessage>,ProcessingContext,CompletableFuture<?>> eventsBatchConsumer)
      Description copied from interface: SubscribableEventSource
      Subscribe the given eventsBatchConsumer to this event source. When subscribed, it will receive all events published to this source since the subscription.

      If the given eventsBatchConsumer is already subscribed, nothing happens.

      Note on ProcessingContext: The ProcessingContext parameter passed to the consumer may be null. When null, it is the responsibility of the registered eventsBatchConsumer to create an appropriate ProcessingContext as needed for processing the events.

      Specified by:
      subscribe in interface SubscribableEventSource
      Parameters:
      eventsBatchConsumer - The event batches consumer to subscribe.
      Returns:
      A Registration handle to unsubscribe the eventsBatchConsumer. When unsubscribed, it will no longer receive events.