forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-7442] Add option for using a child-first classloader for loadi…
…ng user code This also adds an end-to-end test that verifies correct order for both classes and resources.
- Loading branch information
Showing
26 changed files
with
584 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,107 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http:https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<project xmlns="http:https://maven.apache.org/POM/4.0.0" xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-parent</artifactId> | ||
<version>1.4-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>flink-end-to-end-tests_${scala.binary.version}</artifactId> | ||
<name>flink-end-to-end-tests</name> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.4</version> | ||
|
||
<executions> | ||
<!-- ClassLoaderTestProgram --> | ||
<execution> | ||
<id>ClassLoaderTestProgram</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>ClassLoaderTestProgram</classifier> | ||
|
||
<archive> | ||
<manifestEntries> | ||
<program-class>org.apache.flink.streaming.tests.ClassLoaderTestProgram</program-class> | ||
</manifestEntries> | ||
</archive> | ||
|
||
<includes> | ||
<include>org/apache/flink/streaming/tests/ClassLoaderTestProgram.class</include> | ||
<include>org/apache/flink/runtime/taskmanager/TaskManager.class</include> | ||
<include>.version.properties</include> | ||
</includes> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!--simplify the name of the testing JARs for referring to them in the end-to-end test scripts--> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<version>1.7</version> | ||
<executions> | ||
<execution> | ||
<id>rename</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<target> | ||
<copy file="${project.basedir}/target/flink-end-to-end-tests_${scala.binary.version}-${project.version}-ClassLoaderTestProgram.jar" tofile="${project.basedir}/target/ClassLoaderTestProgram.jar" /> | ||
</target> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains 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
102 changes: 102 additions & 0 deletions
102
...d-to-end-tests/src/main/java/org/apache/flink/streaming/tests/ClassLoaderTestProgram.java
This file contains 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,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.streaming.tests; | ||
|
||
import org.apache.flink.api.common.functions.MapFunction; | ||
import org.apache.flink.api.java.utils.ParameterTool; | ||
import org.apache.flink.core.fs.FileSystem; | ||
import org.apache.flink.runtime.taskmanager.TaskManager; | ||
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
|
||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
import java.util.Properties; | ||
|
||
/** | ||
* End-to-end test program for verifying that the {@code classloader.resolve-order} setting | ||
* is being honored by Flink. We test this by creating a fake {@code TaskManager} with a single | ||
* method that we call in the same package as the original Flink {@code TaskManager} and verify that | ||
* we get a {@link NoSuchMethodError} if we're running with {@code parent-first} class loading | ||
* and that we get the correct result from the method when we're running with {@code child-first} | ||
* class loading. | ||
*/ | ||
public class ClassLoaderTestProgram { | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
final ParameterTool params = ParameterTool.fromArgs(args); | ||
|
||
final String resolveOrder = params.getRequired("resolve-order"); | ||
|
||
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); | ||
|
||
env | ||
.fromElements("Hello") | ||
.map((MapFunction<String, String>) value -> { | ||
|
||
String gitUrl; | ||
|
||
try (InputStream propFile = ClassLoaderTestProgram.class.getClassLoader().getResourceAsStream(".version.properties")) { | ||
Properties properties = new Properties(); | ||
properties.load(propFile); | ||
gitUrl = properties.getProperty("git.remote.origin.url"); | ||
} | ||
|
||
Enumeration<URL> resources = ClassLoaderTestProgram.class.getClassLoader().getResources( | ||
".version.properties"); | ||
|
||
StringBuilder sortedProperties = new StringBuilder(); | ||
while (resources.hasMoreElements()) { | ||
URL url = resources.nextElement(); | ||
try (InputStream in = url.openStream()) { | ||
Properties properties = new Properties(); | ||
properties.load(in); | ||
String orderedGitUrl = properties.getProperty("git.remote.origin.url"); | ||
sortedProperties.append(orderedGitUrl); | ||
} | ||
} | ||
|
||
if (resolveOrder.equals("parent-first")) { | ||
try { | ||
@SuppressWarnings("unused") | ||
String ignored = TaskManager.getMessage(); | ||
|
||
throw new RuntimeException( | ||
"TaskManager.getMessage() should not be available with parent-first " + | ||
"ClassLoader order."); | ||
|
||
} catch (NoSuchMethodError e) { | ||
// expected | ||
} | ||
return "NoSuchMethodError:" + gitUrl + ":" + sortedProperties; | ||
} else if (resolveOrder.equals("child-first")) { | ||
String message = TaskManager.getMessage(); | ||
if (!message.equals("Hello, World!")) { | ||
throw new RuntimeException("Wrong message from fake TaskManager."); | ||
} | ||
return message + ":" + gitUrl + ":" + sortedProperties; | ||
} else { | ||
throw new RuntimeException("Unknown resolve order: " + resolveOrder); | ||
} | ||
}) | ||
.writeAsText(params.getRequired("output"), FileSystem.WriteMode.OVERWRITE); | ||
|
||
env.execute("ClassLoader Test Program"); | ||
} | ||
} |
This file contains 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 @@ | ||
git.remote.origin.url=hello-there-42 |
This file contains 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
Oops, something went wrong.