I fell down in a weird (at least for me) failure when using Set
instead List
to hold a collection of objects.
I was able to reproduce the issue in this public repo so that I hope might be helpful to give a real case to help understand better.
For some reason the hash table of my hashset
differs among test lifecycle, I mean event by event being applied when a command comes my collection of Schedules
differs although the values are the same.
The test result is:
org.axonframework.test.AxonAssertionError: Illegal state change detected! Property "com.acme.axonsample.axonsample.WorkDay" has different value when sourcing events. Working aggregate value: <WorkDay(id=workDay-for-2020-01-02, day=2020-01-02, schedules=[Schedule(id=5dca3df439881c002543876e, workDuration=PT41M, begin=2020-01-02T10:00Z, end=2020-01-02T11:00Z, workLogs=Optional[[WorkLog(start=2020-01-02T09:45Z, stop=2020-01-02T10:35Z), WorkLog(start=2020-01-02T10:54Z, stop=2020-01-02T13:00Z)]]), Schedule(id=7dca3bf439881c002543836b, workDuration=PT1H, begin=2020-01-02T12:00Z, end=2020-01-02T13:00Z, workLogs=Optional[[WorkLog(start=2020-01-02T10:54Z, stop=2020-01-02T13:00Z)]]), Schedule(id=2dca3be439871c022543836a, workDuration=PT45M, begin=2020-01-02T14:00Z, end=2020-01-02T14:45Z, workLogs=Optional[[WorkLog(start=2020-01-02T13:58Z, stop=2020-01-02T14:45Z)]])], workLogs=[WorkLog(start=2020-01-02T09:45Z, stop=2020-01-02T10:35Z), WorkLog(start=2020-01-02T10:54Z, stop=2020-01-02T13:00Z), WorkLog(start=2020-01-02T13:58Z, stop=2020-01-02T14:45Z)])> Value after applying events: <WorkDay(id=workDay-for-2020-01-02, day=2020-01-02, schedules=[Schedule(id=7dca3bf439881c002543836b, workDuration=PT1H, begin=2020-01-02T12:00Z, end=2020-01-02T13:00Z, workLogs=Optional[[WorkLog(start=2020-01-02T10:54Z, stop=2020-01-02T13:00Z)]]), Schedule(id=2dca3be439871c022543836a, workDuration=PT45M, begin=2020-01-02T14:00Z, end=2020-01-02T14:45Z, workLogs=Optional[[WorkLog(start=2020-01-02T13:58Z, stop=2020-01-02T14:45Z)]]), Schedule(id=5dca3df439881c002543876e, workDuration=PT41M, begin=2020-01-02T10:00Z, end=2020-01-02T11:00Z, workLogs=Optional[[WorkLog(start=2020-01-02T09:45Z, stop=2020-01-02T10:35Z), WorkLog(start=2020-01-02T10:54Z, stop=2020-01-02T13:00Z)]])], workLogs=[WorkLog(start=2020-01-02T09:45Z, stop=2020-01-02T10:35Z), WorkLog(start=2020-01-02T10:54Z, stop=2020-01-02T13:00Z), WorkLog(start=2020-01-02T13:58Z, stop=2020-01-02T14:45Z)])>
I didn’t find on documentation any restrictions to use Set
even though I got stuck with that failure. Set is important to me in order to guarantee no duplications