Skip to content
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

[#2242] Correctly support null-identifier and no-event scenarios from Command Handling constructors, Always, and Create-If-Missing creation policies #2248

Merged
merged 8 commits into from
Jun 20, 2022

Conversation

smcvb
Copy link
Member

@smcvb smcvb commented Jun 8, 2022

It is perfectly valid for an aggregate creating command handler to decide not to publish any events, nor if it sets the aggregate identifier.

This scenario did not work for command handling constructors, the Create-if-missing, and Always creation policies.

For constructors, this is a bug that sneaked into the framework as part of release 4.5.3.
The constructor predicament is resolved by not entering the prepare-for-commit phase of the UnitOfWork when the aggregate does not contain an identifier.

The create-if-missing policy had an issue in the AggregateTestFixture, which incorrectly assumed this to be a faulty state.
We solved this by checking whether the identifier is null when the aggregate couldn't be found during assertion.

The always policy rethrew the IllegalStateException of the PessimisticLockFactory that tried to obtain a lock for a null identifier.
By throwing a dedicated exception (the NullLockIdentifierException), the always creation policy command handler can react to this accordingly, assuming the scenario the identifier isn't set.

Note that issue #2242 only references the Create-If-Missing policy.
Nonetheless, it will resolve #2242 accordingly.

smcvb added 3 commits June 2, 2022 17:12
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
@smcvb smcvb added Type: Bug Use to signal issues that describe a bug within the system. Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: In Progress Use to signal this issue is actively worked on. labels Jun 8, 2022
@smcvb smcvb added this to the Release 4.5.11 milestone Jun 8, 2022
@smcvb smcvb self-assigned this Jun 8, 2022
Except new NullLockIdentifierException instead of the previous
IllegalArgumentException

#2242
@AxonFramework AxonFramework deleted a comment from stun4j Jun 9, 2022
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
@smcvb smcvb requested a review from abuijze June 10, 2022 11:01
Copy link
Contributor

@YvonneCeelie YvonneCeelie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@abuijze abuijze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just one minor comment on a Javadoc.

Adjust warning message to not be aggregate specific, as the LockFactory
is not aggregate specific either.

#2242
- Test NoOpLock
- Test NullLockFactory
- Test new conditions in the LockingRepository around not obtaining a
lock

#2242
Remove useless public modifier on test method

#2242
@smcvb smcvb merged commit 624101d into axon-4.5.x Jun 20, 2022
@smcvb smcvb deleted the bug/2242 branch June 20, 2022 13:14
@smcvb smcvb added Status: Resolved Use to signal that work on this issue is done. and removed Status: In Progress Use to signal this issue is actively worked on. labels Jun 20, 2022
@sonarcloud
Copy link

sonarcloud bot commented Jun 20, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

85.0% 85.0% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: Resolved Use to signal that work on this issue is done. Type: Bug Use to signal issues that describe a bug within the system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants