AxonFramework/AxonFramework — Issue #16: Generic test to verify that Aggregate state is only manipulated through event handlers
Author: abuijze
Created: 2011-12-03 14:48:04+00:00
State: open
Labels: Enhancement

Having seen bits of code from multiple Axon projects, I notice that one of the major pitfalls in Axon is that internal aggregate state (counters, lists, etc) is inadvertently manipulated while handling commands, instead of through the event handlers. This can easily introduce bugs since it will cause the aggregate in memory to differ from the same aggregate when it is recreated by replaying the events from scratch (f.i. after restarting application).

It would be nice it there was a generic test to verify that aggregate state is only manipulated through event handlers. One way to verify this would be to

- Create an aggregate with internal state by firing a batch of commands (might be random commands, or user-defined list).
- Store the current aggregate internal state, and store any events caused by these commands
- Create a new instance of the aggregate and apply each of the events
- Compare the internal state of the new aggregate with the internal state of the stored aggregate.

If state was manipulated outside of the event handlers, then the 2 aggregates will differ and the test should fail. The test can indicate which aggregate fields contain the differences.

Alternatively, static code analysis can be used to detect field assignments in non-eventhandler methods