I’ve set the threshold of my EventCountSnapshotTriggerDefinition to 1, for testing purposes. With this setting some of my integration tests fail, which work otherwise perfectly if I use a very high threshold (>25).
One of these tests triggers a Saga that leads to about 19 events on the same aggregate.
Since the threshold is set to 1, every applied event should trigger the creation of a snapshot. The problem I’m facing is that the aggregates are not correctly initialized in the AggregateSnapshotter class. I’ve debugged into
it and it seems that events are published on the aggregate object via the initializeState method but the aggregate object already has the state changes from the event through the previous snapshot. In my case, this
leads to duplicate entries in a list that is stored in the aggregate.
My hunch is that the same UnitOfWork dispatches ‘scheduleSnapshot’ multiple times and therefore could lead to this problems. But unfortunately, this is just a guess.
Do you have an idea what could be the problem and if it’s sufficient for me to set the threshold to a higher value?
I’m also wondering why EventSourcedAggregate.initializeState increases the Snapshot counter when it’s simply rehydrating the aggregate.
Thanks a lot!