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

Allow determining exclusive resources programmatically #3889

Conversation

VladimirDmitrienko
Copy link
Contributor

@VladimirDmitrienko VladimirDmitrienko 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

@VladimirDmitrienko VladimirDmitrienko marked this pull request as draft July 17, 2024 06:39
@VladimirDmitrienko VladimirDmitrienko changed the title Draft: Implement adding ExclusiveResource programmatically. Implement adding ExclusiveResource programmatically. Jul 17, 2024
@VladimirDmitrienko VladimirDmitrienko force-pushed the #2677_add_exclusive_resource_programmatically branch from 50377ba to 194832d Compare July 22, 2024 15:43
@VladimirDmitrienko VladimirDmitrienko changed the title Implement adding ExclusiveResource programmatically. Introduce adding 'shared resources' programmatically Aug 6, 2024
@VladimirDmitrienko VladimirDmitrienko force-pushed the #2677_add_exclusive_resource_programmatically branch 3 times, most recently from c0b3d77 to a90636d Compare August 6, 2024 20:30
@VladimirDmitrienko VladimirDmitrienko marked this pull request as ready for review August 8, 2024 06:52
@VladimirDmitrienko VladimirDmitrienko force-pushed the #2677_add_exclusive_resource_programmatically branch from 3e1d2a6 to 7d894c5 Compare August 8, 2024 07:07
@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.

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

@VladimirDmitrienko
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ExclusiveResource programmatically
2 participants