Class StubDeadlineManager
- All Implemented Interfaces:
DeadlineManager
DeadlineManager. Records all scheduled, canceled and met deadlines.
Nothing fires on its own: a test advances the stub's time with advanceTimeBy(Duration, DeadlineConsumer) or
advanceTimeTo(Instant, DeadlineConsumer), which hands every deadline that is due by then to the given
DeadlineConsumer. Each fired deadline runs in a unit of work from the UnitOfWorkFactory this stub was
built with, with the registered handler interceptors around the consumer.
The SagaTestFixture registers a stub as its DeadlineManager, so a Saga
handler that takes a DeadlineManager parameter schedules on it, and the fixture's deadline assertions read
what it recorded.
- Since:
- 3.3
- Author:
- Milan Savic, Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes the manager withZonedDateTime.now()as current time.StubDeadlineManager(TemporalAccessor currentDateTime) Initializes the manager with providedcurrentDateTimeas current time.StubDeadlineManager(TemporalAccessor currentDateTime, UnitOfWorkFactory unitOfWorkFactory) Initializes the manager with providedcurrentDateTimeas current time, firing deadlines in units of work from the givenunitOfWorkFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceTimeBy(Duration duration, DeadlineConsumer deadlineConsumer) Advances time by the givendurationand invokes the givendeadlineConsumerfor each deadline scheduled until that time.voidadvanceTimeTo(Instant newDateTime, DeadlineConsumer deadlineConsumer) Advances time to the givennewDateTimeand invokes the givendeadlineConsumerfor each deadline scheduled until that time.Advances the "current time" of the manager to the next scheduled deadline, and returns that deadline.voidCancels all the deadlines corresponding to the givendeadlineName.voidcancelAllWithinScope(String deadlineName, ScopeDescriptor scope) Cancels all deadlines corresponding to the givendeadlineNameandscope.voidcancelSchedule(String deadlineName, String scheduleId) Cancels the deadline corresponding to the givendeadlineName/scheduleIdcombination.Return the current date and time as anInstantas is being used by thisDeadlineManager.Deprecated.Return all scheduled deadlines which have not been met (yet).Return all triggered deadlines.voidinitializeAt(TemporalAccessor currentDateTime) Resets the initial "current time" of this manager.registerDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage> dispatchInterceptor) Registers the givendispatchInterceptor, which is invoked for each deadline that is scheduled.registerHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage> handlerInterceptor) Registers the givenhandlerInterceptor, which is invoked around the consumer of each fired deadline.schedule(Duration triggerDuration, String deadlineName, @Nullable Object payloadOrMessage, ScopeDescriptor deadlineScope) Schedules a deadline after the giventriggerDurationwith provided context.schedule(Instant triggerDateTime, String deadlineName, @Nullable Object payloadOrMessage, ScopeDescriptor deadlineScope) Schedules a deadline at giventriggerDateTimewith provided context.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.deadline.DeadlineManager
cancelAllWithinScope, schedule, schedule, schedule, schedule, shutdown
-
Constructor Details
-
StubDeadlineManager
public StubDeadlineManager()Initializes the manager withZonedDateTime.now()as current time. -
StubDeadlineManager
Initializes the manager with providedcurrentDateTimeas current time.Fired deadlines run in a unit of work bound to no application, the counterpart of the plain unit of work Axon Framework 4 started. A consumer that needs components from the context, such as a Saga dispatching a command, needs the
constructortaking the configuration'sUnitOfWorkFactoryinstead.- Parameters:
currentDateTime- the instance to use as current date and time
-
StubDeadlineManager
Initializes the manager with providedcurrentDateTimeas current time, firing deadlines in units of work from the givenunitOfWorkFactory.New in Axon Framework 5, where a unit of work is created by a factory rather than started on the current thread. Passing the configuration's
UnitOfWorkFactorygives a fired deadline the same components a handler gets anywhere else in that configuration.- Parameters:
currentDateTime- the instant to use as current date and timeunitOfWorkFactory- the factory of the unit of work each fired deadline runs in
-
-
Method Details
-
initializeAt
Resets the initial "current time" of this manager. Must be called before any deadlines are scheduled.- Parameters:
currentDateTime- the instant to use as the current date and time- Throws:
IllegalStateException- when calling this method after deadlines are scheduled
-
schedule
public String schedule(Instant triggerDateTime, String deadlineName, @Nullable Object payloadOrMessage, ScopeDescriptor deadlineScope) Description copied from interface:DeadlineManagerSchedules a deadline at giventriggerDateTimewith provided context. The returnedscheduleIdand provideddeadlineNamecombination can be used to cancel the scheduled deadline.The given
messageOrPayloadmay be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload andMetadataof the actual deadline being used. In the former case, the givenmessageOrPayloadwill be wrapped as the payload of aDeadlineMessage.- Specified by:
schedulein interfaceDeadlineManager- Parameters:
triggerDateTime- aInstantdenoting the moment to trigger the deadline handlingdeadlineName- aStringrepresenting the name of the deadline to schedulepayloadOrMessage- aMessageor payload for a message as anObjectdeadlineScope- aScopeDescriptordescribing the scope within which the deadline was scheduled- Returns:
- the
scheduleIdas aStringto use when cancelling the schedule
-
schedule
public String schedule(Duration triggerDuration, String deadlineName, @Nullable Object payloadOrMessage, ScopeDescriptor deadlineScope) Description copied from interface:DeadlineManagerSchedules a deadline after the giventriggerDurationwith provided context. The provideddeadlineName/scheduleIdcombination can be used to cancel the scheduled deadline.The given
messageOrPayloadmay be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload andMetadataof the actual deadline being used. In the former case, the givenmessageOrPayloadwill be wrapped as the payload of aDeadlineMessage.- Specified by:
schedulein interfaceDeadlineManager- Parameters:
triggerDuration- aDurationdescribing the waiting period before handling the deadlinedeadlineName- aStringrepresenting the name of the deadline to schedulepayloadOrMessage- aMessageor payload for a message as anObjectdeadlineScope- aScopeDescriptordescribing the scope within which the deadline was scheduled- Returns:
- the
scheduleIdas aStringto use when cancelling the schedule
-
cancelSchedule
Description copied from interface:DeadlineManagerCancels the deadline corresponding to the givendeadlineName/scheduleIdcombination. This method has no impact on deadlines which have already been triggered.- Specified by:
cancelSchedulein interfaceDeadlineManager- Parameters:
deadlineName- aStringrepresenting the name of the deadline to cancelscheduleId- theStringdenoting the scheduled deadline to cancel
-
cancelAll
Description copied from interface:DeadlineManagerCancels all the deadlines corresponding to the givendeadlineName. This method has no impact on deadlines which have already been triggered.- Specified by:
cancelAllin interfaceDeadlineManager- Parameters:
deadlineName- aStringrepresenting the name of the deadlines to cancel
-
cancelAllWithinScope
Description copied from interface:DeadlineManagerCancels all deadlines corresponding to the givendeadlineNameandscope. This method has no impact on deadlines which have already been triggered.- Specified by:
cancelAllWithinScopein interfaceDeadlineManager- Parameters:
deadlineName- aStringrepresenting the name of the deadlines to cancelscope- aScopeDescriptordescribing the scope within which the deadline was scheduled
-
getScheduledDeadlines
Return all scheduled deadlines which have not been met (yet).- Returns:
- all scheduled deadlines which have not been met (yet)
-
getDeadlinesMet
Deprecated.in favor ofgetTriggeredDeadlines()Return all deadlines which have been met.- Returns:
- all deadlines which have been met
-
getTriggeredDeadlines
Return all triggered deadlines.- Returns:
- all triggered deadlines
-
getCurrentDateTime
Return the current date and time as anInstantas is being used by thisDeadlineManager.- Returns:
- the current date and time used by the manager
-
advanceToNextTrigger
Advances the "current time" of the manager to the next scheduled deadline, and returns that deadline. In theory, this may cause "current time" to move backwards.- Returns:
ScheduledDeadlineInfoof the first scheduled deadline
-
advanceTimeTo
Advances time to the givennewDateTimeand invokes the givendeadlineConsumerfor each deadline scheduled until that time.- Parameters:
newDateTime- the time to advance the "current time" of the manager todeadlineConsumer- the consumer to invoke for each deadline to trigger
-
advanceTimeBy
Advances time by the givendurationand invokes the givendeadlineConsumerfor each deadline scheduled until that time.- Parameters:
duration- the amount of time to advance the "current time" of the manager withdeadlineConsumer- the consumer to invoke for each deadline to trigger
-
registerDispatchInterceptor
public Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super DeadlineMessage> dispatchInterceptor) Registers the givendispatchInterceptor, which is invoked for each deadline that is scheduled.- Parameters:
dispatchInterceptor- the interceptor deciding which deadline message is scheduled- Returns:
- a registration to remove the interceptor again
-
registerHandlerInterceptor
public Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super DeadlineMessage> handlerInterceptor) Registers the givenhandlerInterceptor, which is invoked around the consumer of each fired deadline.- Parameters:
handlerInterceptor- the interceptor to invoke around the consumer of a fired deadline- Returns:
- a registration to remove the interceptor again
-
getTriggeredDeadlines()