Class StubEventScheduler
java.lang.Object
org.axonframework.test.eventscheduler.StubEventScheduler
- All Implemented Interfaces:
EventScheduler
EventScheduler implementation that uses it's own concept of "Current Time" for the purpose of testing. Instead of
publishing events, it allows (test) classes to obtain a reference to scheduled events for a certain time frame.
To obtain scheduled events, the conceptual "current time" of the Scheduler must be advanced. All events that have
been scheduled within the advanced time frame are returned. It is up to the calling class to decide what to do with
these events.
- Since:
- 1.1
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance of the StubScheduler that uses the current date time as its conceptual "current time".StubEventScheduler(TemporalAccessor currentDateTime) Creates an instance of the StubScheduler that uses the givencurrentDateTimeas its conceptual "current time". -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceTimeBy(Duration duration, EventConsumer<EventMessage<?>> eventConsumer) Advance time by the givendurationand invokes the giveneventConsumerfor each event scheduled for publication until that time.voidadvanceTimeTo(Instant newDateTime, EventConsumer<EventMessage<?>> eventConsumer) Advance time to the givennewDateTimeand invokes the giveneventConsumerfor each event scheduled for publication until that time.Advances the "current time" of the scheduler to the next scheduled Event, and returns that event.voidcancelSchedule(ScheduleToken scheduleToken) Cancel the publication of a scheduled event.Returns the "Current Date Time" as used by the scheduler.Returns a view of all the scheduled Events at the time this method is called.voidinitializeAt(TemporalAccessor currentDateTime) Resets the initial "current time" of this SubEventScheduler.Schedule the giveneventfor publication after the giventriggerDuration.Schedule the giveneventfor publication at the giventriggerDateTime.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.eventhandling.scheduling.EventScheduler
reschedule, reschedule, shutdown
-
Constructor Details
-
StubEventScheduler
public StubEventScheduler()Creates an instance of the StubScheduler that uses the current date time as its conceptual "current time". Unlike the real "current time", the time of the Event Scheduler is fixed. -
StubEventScheduler
Creates an instance of the StubScheduler that uses the givencurrentDateTimeas its conceptual "current time".- Parameters:
currentDateTime- The instant to use as current Date and Time
-
-
Method Details
-
initializeAt
Resets the initial "current time" of this SubEventScheduler. Must be called before any events are scheduled- Parameters:
currentDateTime- The instant to use as the current Date and Time- Throws:
IllegalStateException- when calling this method after events are scheduled
-
schedule
Description copied from interface:EventSchedulerSchedule the giveneventfor publication at the giventriggerDateTime. The returned ScheduleToken can be used to cancel the planned publication. The giveneventmay be any object, as well as an EventMessage. In the latter case, the instance provided is the donor for the payload and Meta Data of the actual message being dispatched. In the former case, the giveneventwill be wrapped as the payload of an EventMessage.- Specified by:
schedulein interfaceEventScheduler- Parameters:
triggerDateTime- The moment to trigger publication of the eventevent- The event to publish- Returns:
- the token to use when cancelling the schedule
-
schedule
Description copied from interface:EventSchedulerSchedule the giveneventfor publication after the giventriggerDuration. The returned ScheduleToken can be used to cancel the planned publication. The giveneventmay be any object, as well as an EventMessage. In the latter case, the instance provided is the donor for the payload and Meta Data of the actual message being dispatched. In the former case, the giveneventwill be wrapped as the payload of an EventMessage.- Specified by:
schedulein interfaceEventScheduler- Parameters:
triggerDuration- The amount of time to wait before publishing the eventevent- The event to publish- Returns:
- the token to use when cancelling the schedule
-
cancelSchedule
Description copied from interface:EventSchedulerCancel the publication of a scheduled event. If the events has already been published, this method does nothing.- Specified by:
cancelSchedulein interfaceEventScheduler- Parameters:
scheduleToken- the token returned when the event was scheduled
-
getScheduledItems
Returns a view of all the scheduled Events at the time this method is called.- Returns:
- a view of all the scheduled Events at the time this method is called
-
getCurrentDateTime
Returns the "Current Date Time" as used by the scheduler.- Returns:
- the "Current Date Time" as used by the scheduler
-
advanceToNextTrigger
Advances the "current time" of the scheduler to the next scheduled Event, and returns that event. In theory, this may cause "current time" to move backwards.- Returns:
- the first event scheduled
-
advanceTimeTo
Advance time to the givennewDateTimeand invokes the giveneventConsumerfor each event scheduled for publication until that time.- Parameters:
newDateTime- The time to advance the "current time" of the scheduler toeventConsumer- The function to invoke for each event to trigger
-
advanceTimeBy
Advance time by the givendurationand invokes the giveneventConsumerfor each event scheduled for publication until that time.- Parameters:
duration- The amount of time to advance the "current time" of the scheduler witheventConsumer- The function to invoke for each event to trigger
-