Class StubEventScheduler

java.lang.Object
org.axonframework.test.eventscheduler.StubEventScheduler
All Implemented Interfaces:
org.axonframework.eventhandling.scheduling.EventScheduler

public class StubEventScheduler extends Object implements org.axonframework.eventhandling.scheduling.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

    Constructors
    Constructor
    Description
    Creates an instance of the StubScheduler that uses the current date time as its conceptual "current time".
    Creates an instance of the StubScheduler that uses the given currentDateTime as its conceptual "current time".
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advanceTimeBy(Duration duration, EventConsumer<org.axonframework.eventhandling.EventMessage<?>> eventConsumer)
    Advance time by the given duration and invokes the given eventConsumer for each event scheduled for publication until that time.
    void
    advanceTimeTo(Instant newDateTime, EventConsumer<org.axonframework.eventhandling.EventMessage<?>> eventConsumer)
    Advance time to the given newDateTime and invokes the given eventConsumer for each event scheduled for publication until that time.
    org.axonframework.eventhandling.EventMessage
    Advances the "current time" of the scheduler to the next scheduled Event, and returns that event.
    void
    cancelSchedule(org.axonframework.eventhandling.scheduling.ScheduleToken scheduleToken)
     
    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.
    void
    initializeAt(TemporalAccessor currentDateTime)
    Resets the initial "current time" of this SubEventScheduler.
    org.axonframework.eventhandling.scheduling.ScheduleToken
    schedule(Duration triggerDuration, Object event)
     
    org.axonframework.eventhandling.scheduling.ScheduleToken
    schedule(Instant triggerDateTime, Object event)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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

      public StubEventScheduler(TemporalAccessor currentDateTime)
      Creates an instance of the StubScheduler that uses the given currentDateTime as its conceptual "current time".
      Parameters:
      currentDateTime - The instant to use as current Date and Time
  • Method Details

    • initializeAt

      public void initializeAt(TemporalAccessor currentDateTime)
      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

      public org.axonframework.eventhandling.scheduling.ScheduleToken schedule(Instant triggerDateTime, Object event)
      Specified by:
      schedule in interface org.axonframework.eventhandling.scheduling.EventScheduler
    • schedule

      public org.axonframework.eventhandling.scheduling.ScheduleToken schedule(Duration triggerDuration, Object event)
      Specified by:
      schedule in interface org.axonframework.eventhandling.scheduling.EventScheduler
    • cancelSchedule

      public void cancelSchedule(org.axonframework.eventhandling.scheduling.ScheduleToken scheduleToken)
      Specified by:
      cancelSchedule in interface org.axonframework.eventhandling.scheduling.EventScheduler
    • getScheduledItems

      public List<ScheduledItem> 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

      public Instant getCurrentDateTime()
      Returns the "Current Date Time" as used by the scheduler.
      Returns:
      the "Current Date Time" as used by the scheduler
    • advanceToNextTrigger

      public org.axonframework.eventhandling.EventMessage 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

      public void advanceTimeTo(Instant newDateTime, EventConsumer<org.axonframework.eventhandling.EventMessage<?>> eventConsumer)
      Advance time to the given newDateTime and invokes the given eventConsumer for each event scheduled for publication until that time.
      Parameters:
      newDateTime - The time to advance the "current time" of the scheduler to
      eventConsumer - The function to invoke for each event to trigger
    • advanceTimeBy

      public void advanceTimeBy(Duration duration, EventConsumer<org.axonframework.eventhandling.EventMessage<?>> eventConsumer)
      Advance time by the given duration and invokes the given eventConsumer for each event scheduled for publication until that time.
      Parameters:
      duration - The amount of time to advance the "current time" of the scheduler with
      eventConsumer - The function to invoke for each event to trigger