[
https://issues.apache.org/jira/browse/BEAM-8113?focusedWorklogId=305486&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-305486
]
ASF GitHub Bot logged work on BEAM-8113:
----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Sep/19 09:20
Start Date: 03/Sep/19 09:20
Worklog Time Spent: 10m
Work Description: mxm commented on pull request #9451: [BEAM-8113] Stage
files from context classloader
URL: https://github.com/apache/beam/pull/9451#discussion_r320168835
##########
File path:
runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/PipelineResourcesTest.java
##########
@@ -44,25 +46,68 @@
@Rule public transient TemporaryFolder tmpFolder = new TemporaryFolder();
@Rule public transient ExpectedException thrown = ExpectedException.none();
+ ClassLoader currentContext = null;
+
+ @Before
+ public void setUp() {
+ currentContext = Thread.currentThread().getContextClassLoader();
+ }
+
+ @After
+ public void tearDown() {
+ Thread.currentThread().setContextClassLoader(currentContext);
+ }
+
@Test
- public void detectClassPathResourceWithFileResources() throws Exception {
+ public void detectClassPathResourceWithFileResources() throws IOException {
File file = tmpFolder.newFile("file");
File file2 = tmpFolder.newFile("file2");
URLClassLoader classLoader =
- new URLClassLoader(new URL[] {file.toURI().toURL(),
file2.toURI().toURL()});
+ new URLClassLoader(
+ new URL[] {file.toURI().toURL(), file2.toURI().toURL()},
+ Thread.currentThread().getContextClassLoader());
+
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ List<String> detected =
PipelineResources.detectClassPathResourcesToStage(getClass());
+ assertTrue(detected.contains(file.getAbsolutePath()));
+ assertTrue(detected.contains(file2.getAbsolutePath()));
+
+ // locate java home and verify that we didn't pull any resource from JDK
+ String javaHome =
+ Optional.ofNullable(System.getProperty("java.home"))
+ .map(File::new)
+ .map(File::getAbsolutePath)
+ .orElse(null);
+ assertFalse(detected.stream().anyMatch(f -> f.startsWith(javaHome)));
+ }
+
+ @Test
+ public void detectClassPathResourcesFromHierarchy() throws IOException {
+ File file = tmpFolder.newFile("file");
+ File file2 = tmpFolder.newFile("file2");
+ URLClassLoader classLoader1 =
+ new URLClassLoader(
+ new URL[] {file.toURI().toURL()},
Thread.currentThread().getContextClassLoader());
+ ClassLoader classLoader2 = new ClassLoader(classLoader1) {};
+
+ URLClassLoader classLoader3 =
+ new URLClassLoader(new URL[] {file2.toURI().toURL()}, classLoader2);
- assertEquals(
- ImmutableList.of(file.getAbsolutePath(), file2.getAbsolutePath()),
- PipelineResources.detectClassPathResourcesToStage(classLoader));
+ Thread.currentThread().setContextClassLoader(classLoader3);
+
+ List<String> detected =
PipelineResources.detectClassPathResourcesToStage(getClass());
+ assertTrue(detected.contains(file.getAbsolutePath()));
+ assertTrue(detected.contains(file2.getAbsolutePath()));
}
@Test
public void detectClassPathResourcesWithUnsupportedClassLoader() {
ClassLoader mockClassLoader = Mockito.mock(ClassLoader.class);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unable to use ClassLoader to detect classpath
elements.");
-
- PipelineResources.detectClassPathResourcesToStage(mockClassLoader);
+ Thread.currentThread().setContextClassLoader(mockClassLoader);
+ PipelineResources.detectClassPathResourcesToStage(getClass());
Review comment:
Not sure why we throw here. According to the current logic, if there was one
other UrlClassloader, we would not fail.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 305486)
> FlinkRunner: Stage files from context classloader
> -------------------------------------------------
>
> Key: BEAM-8113
> URL: https://issues.apache.org/jira/browse/BEAM-8113
> Project: Beam
> Issue Type: Improvement
> Components: runner-flink
> Reporter: Jan Lukavský
> Assignee: Jan Lukavský
> Priority: Major
> Time Spent: 3h 50m
> Remaining Estimate: 0h
>
> Currently, only files from {{FlinkRunner.class.getClassLoader()}} are staged
> by default. Add also files from
> {{Thread.currentThread().getContextClassLoader()}}.
--
This message was sent by Atlassian Jira
(v8.3.2#803003)