Hello Everyone.
I have just started using Axon, and maybe I don’t understand it correctly. As I understand it the @Timestamp annotation or .getTimestamp() on a Message should contain the Timestamp of when the event has been originally created. I want to save this time with an aggregate using an @EventSourcingHandler, but when I try it, I get the following error:
org.axonframework.test.AxonAssertionError: Illegal state change detected! Property "com.example.domain.model.Letter.imported" has different value when sourcing events. Working aggregate value: <2014-10-22T12:57:08.572+02:00> Value after applying events: <2014-10-22T12:57:10.670+02:00>
The test case that creates this error looks like this:
`
@Test
public void lettersCanBeCreated(){
final LetterId letterId = new LetterId(UUID.randomUUID().toString());
final LetterFileRef letterRef = mock(LetterFileRef.class);
fixture.given()
.when(new CreateLetterCommand(letterId, letterRef))
.expectReturnValue(letterId)
.expectEvents(new LetterImportedEvent(letterId, letterRef));
}
`
With the Handling Code for it being the following:
`
public class Letter extends AbstractAnnotatedAggregateRoot {
@AggregateIdentifier
private LetterId id;
@Version
private Long version;
private LetterFileRef fileRef;
private DateTime imported = null;
// constructor needed for reconstruction
protected Letter() {
}
@CommandHandler
public Letter(@NotNull CreateLetterCommand command) {
apply(new LetterImportedEvent(command.getLetterId(), command.getFileRef()));
}
@EventSourcingHandler
private void handleCreation(@NotNull LetterImportedEvent event, @Timestamp eventTime) {
this.id = event.getLetterId();
this.fileRef = event.getFileRef();
this.imported = eventTime;
}
}
`
As far as I can tell the apply method in AbstractEventSourcedAggregateRoot creates a new GenericDomainEventMessage when the event is replayed, which in turn sets a new timestamp. But while stepping through it in the debugger I noticed that inReplay is not set to true.
Now I’m confused as to what I did wrong, can anybody help me to find it?
Cheers,
Paul