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

Support programmatic registration of resource locks #3889

Merged
merged 30 commits into from
Oct 7, 2024
Merged

Support programmatic registration of resource locks #3889

merged 30 commits into from
Oct 7, 2024

Conversation

vdmitrienko
Copy link
Contributor

@vdmitrienko vdmitrienko commented Jul 16, 2024

Solves: #2677

Overview

Introduce adding shared resources programmatically via @ResourceLock(providers = ...) attribute
which accepts an array of one or more classes implementing ResourceLocksProvider interface.

It allows to add resources in runtime (immediately before starting execution on the engine level).

Resources can be distributed based on any test class / nested test class / test method attributes (e.g. package name, class / method name etc.) or any other user logic.

This approach serves as a more flexible and less verbose alternative for cases in which:

  • adding lots of @ResourceLock(value, mode) annotations manually may be inconvenient;
  • shared resources are not known until runtime.

I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@vdmitrienko vdmitrienko marked this pull request as draft July 17, 2024 06:39
@vdmitrienko vdmitrienko changed the title Draft: Implement adding ExclusiveResource programmatically. Implement adding ExclusiveResource programmatically. Jul 17, 2024
@vdmitrienko vdmitrienko changed the title Implement adding ExclusiveResource programmatically. Introduce adding 'shared resources' programmatically Aug 6, 2024
@vdmitrienko vdmitrienko marked this pull request as ready for review August 8, 2024 06:52
@marcphilipp marcphilipp linked an issue Aug 9, 2024 that may be closed by this pull request
Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Looks very promising! Sorry for the late request to change the API.

@vdmitrienko
Copy link
Contributor Author

Hi @marcphilipp
Maybe you have any updates regarding this PR?

@marcphilipp marcphilipp self-requested a review October 4, 2024 11:33
Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Thanks! I'll take it from here.

Comment on lines +207 to +210
List<ResourceLock> enclosingClassesAnnotations = getEnclosingTestClasses().stream()
.map(clazz -> findRepeatableAnnotations(clazz, ResourceLock.class))
.flatMap(Collection::stream)
.collect(toList());
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be slightly better to get the registered ResourceLockProviders from the parent test descriptor rather than collecting them again for every test and reinstantiating them but I'll take care of that in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, many method / nested class descriptors may share the same parent 👍

@vdmitrienko
Copy link
Contributor Author

Thanks! I'll take it from here.

Thank you!
This was my first contribution, and it was very interesting and valuable experience.

@marcphilipp marcphilipp changed the title Introduce adding 'shared resources' programmatically Allow determining exclusive resources programmatically Oct 7, 2024
@marcphilipp marcphilipp merged commit 8e9094d into junit-team:main Oct 7, 2024
15 checks passed
@sbrannen sbrannen changed the title Allow determining exclusive resources programmatically Support programmatic registration of resource locks Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support programmatic registration of resource locks
3 participants