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

Fix duplicate command handler resolver not being used for annotated aggregates #2207

Merged

Conversation

CodeDrivenMitch
Copy link
Member

When the AggregateAnnotationCommandHandler subscribes to the commandBus, it does so once for every payload type. This is independent of how many handlers are present for that type, since it does so using a set. In addition, it passes itself as the handler, making the DuplicateCommandHandlerResolver useless since comparing handlers is impossible (both handler arguments are the AggregateAnnotationCommandHandler itself, instead of the conflicting handlers).

In this PR this has been changed so the AggregateAnnotationCommandHandler subscribes the child command handlers to the CommandBus, instead of itself. This bypasses its handle and canHandle methods (since it is never really subscribed), but then uses these of the handlers in its list.

In addition, this PR solves an issue with the AnnotatedHandlerInspector. Even when methods were abstract in a superclass, they were considered a member. This leads to double registrations on the command bus.

Closes #1756

@CodeDrivenMitch CodeDrivenMitch added Type: Bug Use to signal issues that describe a bug within the system. Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. Status: In Progress Use to signal this issue is actively worked on. labels Apr 26, 2022
@CodeDrivenMitch CodeDrivenMitch added this to the Release 4.5.10 milestone Apr 26, 2022
@CodeDrivenMitch CodeDrivenMitch self-assigned this Apr 26, 2022
@CodeDrivenMitch CodeDrivenMitch force-pushed the 1756-no-errorwarning-for-duplicate-commandhandler branch from 446834a to 4b8f007 Compare April 26, 2022 12:33
@sonarcloud
Copy link

sonarcloud bot commented Apr 26, 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

100.0% 100.0% Coverage
0.0% 0.0% Duplication

verify(commandBus).subscribe(eq(UpdateCommandWithAnnotatedMethod.class.getName()),
// Is subscribed two times because of the duplicate handler. This is good and indicates usage of the
// DuplicateCommandHandlerResolver
verify(commandBus, times(2)).subscribe(eq(UpdateCommandWithAnnotatedMethod.class.getName()),
Copy link
Member

Choose a reason for hiding this comment

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

This test should be obsolete with the change in the AnnotatedHandlerInspector, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean by obsolete? the times(2) change is valid, see the comment. I have added an additional handler, with a different signature. The change in AnnotatedHandlerInspector is to prevent abstract methods from being registered twice (for the same implementation)

Copy link
Member

Choose a reason for hiding this comment

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

Aaah thanks for clarifying, I wasn't thinking straight enough when I wrote that I guess 😅

Copy link
Member

@smcvb smcvb 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 👍

@CodeDrivenMitch CodeDrivenMitch merged commit 167e535 into axon-4.5.x Apr 28, 2022
@smcvb smcvb deleted the 1756-no-errorwarning-for-duplicate-commandhandler branch April 28, 2022 16:16
@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 Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. 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

2 participants