Question: given an aggregate has scheduled an event to be published in the future using some flavor of EventScheduler, how do I test that it actually gets published when expected?
I was hoping for some sort of deadline equivalent in AggregateTestFixture, e.g. expectScheduledDeadline(…) and whenThenTimeElapses(…).expectDeadlinesMet(…), but those seem to only support deadlines.
I could probably achieve the same with deadlines, but I would prefer to use AxonServerEventScheduler instead of one based on Quartz.
that’s correct. The AggregateTestFixture only supports deadlines, because aggregates cannot be triggered by the Event Scheduler. The latter will schedule events at a designated time on the Event Bus, but the Aggregate cannot interact with those events directly.
The Deadline Manager, on the other hand, will trigger a method on the component that registered the deadline. In this case, that would be the Aggregate instance. Therefore, since there is interaction with the Aggregate, the AggregateTestFixture will support it.
Hope tis clarifies it. If you feel there’s something we’ve overlooked, don’t hesitate to let us know.
I think I got it: scheduled events are broadcast, aggregate-published events target only the aggregate of origin. BTW, are aggregates included in broadcast recipients?
I do have use cases for both scheduled events and deadlines, it seems.
I still don’t understand how to test scheduled events, though. Is there an example? I did look at Axon source code, but only found tests that scheduled events a few ms ahead and then waited that time.
Or should I trust AxonServerEventScheduler unconditionally and simply test that my non-aggregate component handles the broadcast event to my satisfaction?
the aggregate test fixtures allow you to test the behaviour of your Aggregate or Saga. They include the ability to use a deadline manager or event scheduler. You can control time using ‘whenTimeElapses’ methods, which simulate time, rarher than actually waiting.
If you want to do an integration test, then you’d have to schedule and wait for a predefined amount of time.
Regarding Aggregates and scheduled events: no they don’t receive those events. Scheduled events are published on the Event Bus (which may happen to also be your Event Store). Aggregates don’t (and can’t) subscribe to receiving thise events.