-
Notifications
You must be signed in to change notification settings - Fork 70
Fallback isolated ClassLoader to platform classes #340
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
Open
paul-hristea
wants to merge
6
commits into
OpenIntegrationEngine:main
Choose a base branch
from
NovaMap-Health:isolated-classloader-platform-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−7
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dabc06b
Fallback isolated ClassLoader to platform classes by setting its pare…
paul-hristea e62fa59
Merge remote-tracking branch 'refs/remotes/upstream/main' into isolat…
paul-hristea f62537f
Merge branch 'upstream-main' into isolated-classloader-platform-fallback
paul-hristea 4f96ba8
Merge branch 'main' into isolated-classloader-platform-fallback
paul-hristea 7e24227
Updated Javadoc to correctly explain Isolated ClassLoader behavior
paul-hristea cf094d2
Improve Javadoc wording for getIsolatedClassLoader
paul-hristea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
server/src/test/java/com/mirth/connect/server/util/javascript/MirthContextFactoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: Open Integration Engine | ||
|
|
||
| package com.mirth.connect.server.util.javascript; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.io.File; | ||
| import java.net.URL; | ||
| import java.util.HashSet; | ||
|
|
||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| import com.google.inject.AbstractModule; | ||
| import com.google.inject.Guice; | ||
| import com.google.inject.Injector; | ||
| import com.mirth.connect.server.builders.JavaScriptBuilder; | ||
| import com.mirth.connect.server.controllers.CodeTemplateController; | ||
| import com.mirth.connect.server.controllers.ConfigurationController; | ||
| import com.mirth.connect.server.controllers.ControllerFactory; | ||
| import com.mirth.connect.server.controllers.EventController; | ||
| import com.mirth.connect.server.controllers.ExtensionController; | ||
|
|
||
| public class MirthContextFactoryTest { | ||
|
|
||
| @BeforeClass | ||
| public static void setUpBeforeClass() { | ||
| // Same mocked ControllerFactory pattern as JavaScriptUtilTest, so this class is | ||
| // self-sufficient regardless of which test classes ran (and injected) before it. | ||
| ControllerFactory controllerFactory = mock(ControllerFactory.class); | ||
|
|
||
| EventController eventController = mock(EventController.class); | ||
| when(controllerFactory.createEventController()).thenReturn(eventController); | ||
|
|
||
| ConfigurationController configurationController = mock(ConfigurationController.class); | ||
| when(controllerFactory.createConfigurationController()).thenReturn(configurationController); | ||
|
|
||
| ExtensionController extensionController = mock(ExtensionController.class); | ||
| when(controllerFactory.createExtensionController()).thenReturn(extensionController); | ||
|
|
||
| CodeTemplateController codeTemplateController = mock(CodeTemplateController.class); | ||
| when(controllerFactory.createCodeTemplateController()).thenReturn(codeTemplateController); | ||
|
|
||
| Injector injector = Guice.createInjector(new AbstractModule() { | ||
| @Override | ||
| protected void configure() { | ||
| requestStaticInjection(ControllerFactory.class); | ||
| bind(ControllerFactory.class).toInstance(controllerFactory); | ||
| } | ||
| }); | ||
| injector.getInstance(ControllerFactory.class); | ||
|
|
||
| JavaScriptBuilder.setControllersForTesting(extensionController, codeTemplateController); | ||
| } | ||
|
|
||
| /* | ||
| * Regression test for #338: with a null parent, the isolated classloader cannot see java.sql | ||
| * on Java 9+, so custom driver resources failed to deploy. The parent must be the platform | ||
| * classloader: JRE classes visible, server classpath not. | ||
| */ | ||
| @Test | ||
| public void isolatedClassLoaderResolvesPlatformButNotServerClasses() throws Exception { | ||
| // This jar URL never gets read; it only exists because getIsolatedClassLoader() returns null on empty array. | ||
| URL dummyJar = new File("build/tmp/mirth-context-factory-test-dummy.jar").toURI().toURL(); | ||
| MirthContextFactory contextFactory = new MirthContextFactory(new URL[] { dummyJar }, new HashSet<>(), false); | ||
|
|
||
| ClassLoader isolated = contextFactory.getIsolatedClassLoader(); | ||
| assertNotNull(isolated); | ||
|
|
||
| // Fails with ClassNotFoundException if the parent ever goes back to null | ||
| isolated.loadClass("java.sql.Driver"); | ||
|
|
||
| // Fails if the parent is ever widened to a loader that can see the server classpath | ||
| assertThrows(ClassNotFoundException.class, () -> isolated.loadClass(MirthContextFactory.class.getName())); | ||
| } | ||
|
|
||
| @Test | ||
| public void isolatedClassLoaderIsNullWithoutResources() { | ||
| MirthContextFactory contextFactory = new MirthContextFactory(new URL[0], new HashSet<>(), false); | ||
| assertNull(contextFactory.getIsolatedClassLoader()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several issues with this, but I know you only used the suggestion you were given.