-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AggregateTestFixture throws AggregateNotFoundException when a command handler with a creation policy applies no events #2242
Comments
This turns out to be a bug that sneaked into the framework, but for Command Handlers that construct Aggregates in general. class MyAggregate {
@CommandHandler
public MyAggregate(MyCommand command) {
if (someStateFromTheCommand) {
apply(new SomeEvent());
}
}
} Where the if-statement isn't met now results in an As seen from the sample, this predicament does not limit itself to the Creation Policy logic. |
During the commit phase of an Aggregate, the identifier is expected to be present. Otherwise, no events or state-stored aggregate can be inserted. However, if the identifier is not present at this point that means the command handler decided not to create the aggregate. As such, no commit action is necessary. Validate this behavior with a test case targeted towards a command handling constructor without publishing any events. #2242
If the AggregateNotFoundException is thrown within the test fixture and the identifier is null, that means the identifier hasn't been set by the command handling constructor. #2242
If the PessimisticLockFactory throws a dedicated exception instead of an IllegalArgumentException than the AlwaysCreateAggregateCommandHandler can deal with this scenario by defining the result as null instead of rethrowing the exception. This covers for the scenario when an ALWAYS creation policy decides not to publish any events or sets state. #2242
Except new NullLockIdentifierException instead of the previous IllegalArgumentException #2242
Instead of throwing a specific exception to handled in the case when the ALWAYS creation policy does not set the aggregateIdentifier, we'll instead construct a NoOpLock. This is safe and specific enough, since the AbstractRepository ensure we do not commit whenever the aggregate identifier is null. #2242
Adjust warning message to not be aggregate specific, as the LockFactory is not aggregate specific either. #2242
Remove useless public modifier on test method #2242
[#2242] Correctly support null-identifier and no-event scenarios from Command Handling constructors, `Always`, and `Create-If-Missing` creation policies
I am closing this issue since pull request #2248 resolves it. |
Basic information
Steps to reproduce
Create a test case for an aggregate with a command handler that uses the creation policy
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
. The command handler shouldn't apply any events.Reproducer:
Expected behaviour
The test case passes. It works on Axon Framework version 4.5.9
Actual behaviour
The exception is thrown:
The text was updated successfully, but these errors were encountered: