Skip to content

Add one test for plugin type to PluginsLoaderTests#117725

Merged
ldematte merged 6 commits intoelastic:mainfrom
ldematte:entitlements/plugin-loader-tests
Dec 12, 2024
Merged

Add one test for plugin type to PluginsLoaderTests#117725
ldematte merged 6 commits intoelastic:mainfrom
ldematte:entitlements/plugin-loader-tests

Conversation

@ldematte
Copy link
Contributor

Add one test per plugin type (modular, stable, non-modular) to PluginsLoaderTests.

We split responsibility of PluginsService in a separate PluginsLoader; the PluginsLoader now is responsible to find and create all plugins bundles and descriptors (which is delegated to PluginsUtils, and partially covered by PluginsUtilsTests), and particularly to create all the ClassLoaders and Layers that will be used to load the plugin classes and create the plugin objects.

Currently, PluginsLoader functions are tested (in part) by PluginsServiceTests; this PR borrows from these tests (with partial duplication, ATM) and adds new ones to PluginsLoaderTests; the new tests focus on the responsibilities of PluginsLoader (find the jars, build the descriptors, build the layers), covering all 3 plugin types we can create.

Tests in PluginsServiceTests should probably be re-worked to remove duplication, and focus more on what responsibilities remain in PluginsService (actual plugin loading/creation, filtering, holding the registry), but I'd like to work incrementally and do that in a separate PR.

@ldematte ldematte added >test Issues or PRs that are addressing/adding tests :Core/Infra/Core Core issues without another label auto-backport Automatically create backport pull requests when merged v9.0.0 v8.18.0 labels Nov 28, 2024
private record LoadedPluginLayer(
PluginBundle pluginBundle,
ClassLoader pluginClassLoader,
ModuleLayer pluginModuleLayer,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fear not, this is not added here just for this test: we need it anyway/it's one of the reasons we wanted to split PluginsLoader out (see it in use in #117239)

}

static final String toPackageName(String className) {
static String toPackageName(String className) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Automatic cleanup (IJ complaining)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that wasn't caught before.

@ldematte ldematte marked this pull request as ready for review November 28, 2024 17:23
@ldematte ldematte requested a review from a team as a code owner November 28, 2024 17:23
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Nov 28, 2024
Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding these additional tests.

}

static final String toPackageName(String className) {
static String toPackageName(String className) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that wasn't caught before.

);

Path jar = plugin.resolve("impl.jar");
JarUtils.createJarWithEntries(jar, Map.of("p/A.class", InMemoryJavaCompiler.compile("p.A", """
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite clever to use in testing :)

@ldematte ldematte merged commit adddfa2 into elastic:main Dec 12, 2024
@ldematte ldematte deleted the entitlements/plugin-loader-tests branch December 12, 2024 08:36
ldematte added a commit to ldematte/elasticsearch that referenced this pull request Dec 12, 2024
* Add one test for plugin type to PluginsLoaderTests

* Suppress ExtraFs (or PluginsUtils etc could fail with extra0 files)
elasticsearchmachine pushed a commit that referenced this pull request Dec 12, 2024
* Add one test for plugin type to PluginsLoaderTests

* Suppress ExtraFs (or PluginsUtils etc could fail with extra0 files)
maxhniebergall pushed a commit to maxhniebergall/elasticsearch that referenced this pull request Dec 16, 2024
…elastic#118529)

* Add one test for plugin type to PluginsLoaderTests

* Suppress ExtraFs (or PluginsUtils etc could fail with extra0 files)
maxhniebergall pushed a commit to maxhniebergall/elasticsearch that referenced this pull request Dec 16, 2024
…elastic#118529)

* Add one test for plugin type to PluginsLoaderTests

* Suppress ExtraFs (or PluginsUtils etc could fail with extra0 files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants