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

Add resource container selector resolver #3718

Open
wants to merge 102 commits into
base: main
Choose a base branch
from

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Mar 8, 2024

Overview

Resolve resource container selectors

As a follow up for #3630 and #3705 this adds a
addResourceContainerSelectorResolver()
method to EngineDiscoveryRequestResolver.Builder analogous to
addClassContainerSelectorResolver().

Points of note:

  • As classpath resources can be selected from packages, the package
    filter should also be applied. To make this possible the base path of
    a resource is rewritten to a package name prior to being filtered.

  • The ClasspathResourceSelector now has a getClasspathResources
    method. This method will lazily try to load the resources if not
    already provided when discovering resources in a container.

  • selectClasspathResource(Set<Resource>) was added to short circuit the
    need to resolve resources twice. And to make it possible to use
    this method as part of the public API,
    ReflectionSupport.tryToLoadResources was also added.


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


Definition of Done

As a follow up for junit-team#3630 and junit-team#3705 this adds a
`addResourceContainerSelectorResolver()`
method to `EngineDiscoveryRequestResolver.Builder` analogous to
`addClassContainerSelectorResolver()`.

Points of note:

 * As classpath resources can be selected from packages, the package
   filter should also be applied. To make this possible the base path of
   a resource is rewritten to a package name prior to being filtered.

 * The `ClasspathResourceSelector` now has a `getClasspathResource`
   method. This method will lazily try to load the resource if not was
   not already provided when discovering resources in a container.

 * `selectClasspathResource(Resource)` was added to short circuit the
    need to resolve resources twice. And to make it possible to use
    this method as part of the public API,
    `ReflectionSupport.tryToLoadResource` was also added.
@marcphilipp marcphilipp modified the milestones: 5.11 RC1, 5.12 Jul 17, 2024
@marcphilipp
Copy link
Member

marcphilipp commented Aug 6, 2024

So the problem I have been running into is that:

  1. Resources are only uniquely identified by their URI.

  2. Resources are not uniquely identified by their name. Searching a container may return multiple results that need to be de-duplicated in some fashion.

  3. Resources are uniquely identified by their name and module name. So searching a module yields theoretically unique resources.

  4. Resources discovered in a container should also be discoverable using the resource selector.

Currently, there are two options: ClasspathResourceSelector and UriSelector. Using the former with a non-unique name/path would result in all resources for that name/path being discovered. In that case, one could use a DiscoveryFilter to exclude those that are not wanted, e.g., based on parts of the URI. Using the latter would work (assuming the engine in question supports UriSelector for resources).

We briefly discussed the problem in the team. Do you have a concrete use case that would require solving the problem of having a machine-independent identifier for re-running a test based on a non-unique classpath resource? Otherwise, maybe we can move forward as-is and see if it actually becomes a problem?

@mpkorstanje
Copy link
Contributor Author

We briefly discussed the problem in the team. Do you have a concrete use case that would require solving the problem of having a machine-independent identifier for re-running a test based on a non-unique classpath resource? Otherwise, maybe we can move forward as-is and see if it actually becomes a problem?

Haven't got any concrete examples in mind right now. So that seems reasonable.

@mpkorstanje mpkorstanje marked this pull request as draft August 27, 2024 19:58
@mpkorstanje mpkorstanje marked this pull request as ready for review September 1, 2024 18:10
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.

None yet

3 participants