Skip to content

Commit

Permalink
[FLINK-9987][tests] Harden ClassLoader E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Jul 31, 2018
1 parent 6ac0145 commit a9d556e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public static void main(String[] args) throws Exception {
.fromElements("Hello")
.map((MapFunction<String, String>) value -> {

String gitUrl;
String gitCommitId;

try (InputStream propFile = ClassLoaderTestProgram.class.getClassLoader().getResourceAsStream(".version.properties")) {
Properties properties = new Properties();
properties.load(propFile);
gitUrl = properties.getProperty("git.remote.origin.url");
gitCommitId = properties.getProperty("git.commit.id.abbrev");
}

Enumeration<URL> resources = ClassLoaderTestProgram.class.getClassLoader().getResources(
Expand All @@ -67,8 +67,8 @@ public static void main(String[] args) throws Exception {
try (InputStream in = url.openStream()) {
Properties properties = new Properties();
properties.load(in);
String orderedGitUrl = properties.getProperty("git.remote.origin.url");
sortedProperties.append(orderedGitUrl);
String orderedGitCommitId = properties.getProperty("git.commit.id.abbrev");
sortedProperties.append(orderedGitCommitId);
}
}

Expand All @@ -84,13 +84,13 @@ public static void main(String[] args) throws Exception {
} catch (NoSuchMethodError e) {
// expected
}
return "NoSuchMethodError:" + gitUrl + ":" + sortedProperties;
return "NoSuchMethodError:" + gitCommitId + ":" + 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;
return message + ":" + gitCommitId + ":" + sortedProperties;
} else {
throw new RuntimeException("Unknown resolve order: " + resolveOrder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git.remote.origin.url=hello-there-42
git.commit.id.abbrev=hello-there-42
28 changes: 9 additions & 19 deletions flink-end-to-end-tests/test-scripts/test_streaming_classloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@
################################################################################

source "$(dirname "$0")"/common.sh
EXIT_CODE=0

TEST_PROGRAM_JAR=${END_TO_END_DIR}/flink-parent-child-classloading-test/target/ClassLoaderTestProgram.jar

echo "Testing parent-first class loading"

# retrieve git.remote.origin.url from .version.properties
GIT_REMOTE_URL=`grep "git\.remote\.origin\.url" $TEST_INFRA_DIR/../../flink-runtime/src/main/resources/.version.properties \
|cut -d'=' -f2 \
|sed -e 's/\\\:/:/g'`

# remove any leftover classloader settings
sed -i -e 's/classloader.resolve-order: .*//' "$FLINK_DIR/conf/flink-conf.yaml"
sed -i -e 's/classloader.parent-first-patterns: .*//' $FLINK_DIR/conf/flink-conf.yaml
Expand All @@ -47,12 +41,12 @@ OUTPUT=`cat $TEST_DATA_DIR/out/cl_out_pf`
# first field: whether we found the method on TaskManager
# result of getResource(".version.properties"), should be from the parent
# ordered result of getResources(".version.properties"), should have parent first
EXPECTED="NoSuchMethodError:${GIT_REMOTE_URL}:${GIT_REMOTE_URL}hello-there-42"
if [[ "$OUTPUT" != "$EXPECTED" ]]; then
EXPECTED="NoSuchMethodError:[0-9a-f]{6,}:[0-9a-f]{6,}hello-there-42"
if ! [[ "$OUTPUT" =~ $EXPECTED ]]; then
echo "Output from Flink program does not match expected output."
echo -e "EXPECTED: $EXPECTED"
echo -e "ACTUAL: $OUTPUT"
EXIT_CODE=1
exit 1
fi

# This verifies that Flink classes are still resolved from the parent because the default
Expand All @@ -77,12 +71,12 @@ OUTPUT=`cat $TEST_DATA_DIR/out/cl_out_cf_pf`
# first field: whether we found the method on TaskManager
# result of getResource(".version.properties"), should be from the child
# ordered result of getResources(".version.properties"), should be child first
EXPECTED="NoSuchMethodError:hello-there-42:hello-there-42${GIT_REMOTE_URL}"
if [[ "$OUTPUT" != "$EXPECTED" ]]; then
EXPECTED="NoSuchMethodError:hello-there-42:hello-there-42[0-9a-f]{6,}"
if ! [[ "$OUTPUT" =~ $EXPECTED ]]; then
echo "Output from Flink program does not match expected output."
echo -e "EXPECTED: $EXPECTED"
echo -e "ACTUAL: $OUTPUT"
EXIT_CODE=1
exit 1
fi

echo "Testing child-first class loading"
Expand All @@ -106,14 +100,10 @@ OUTPUT=`cat $TEST_DATA_DIR/out/cl_out_cf`
# first field: whether we found the method on TaskManager
# result of getResource(".version.properties"), should be from the child
# ordered result of getResources(".version.properties"), should be child first
EXPECTED="Hello, World!:hello-there-42:hello-there-42${GIT_REMOTE_URL}"
if [[ "$OUTPUT" != "$EXPECTED" ]]; then
EXPECTED="Hello, World!:hello-there-42:hello-there-42[0-9a-f]{6,}"
if ! [[ "$OUTPUT" =~ $EXPECTED ]]; then
echo "Output from Flink program does not match expected output."
echo -e "EXPECTED: $EXPECTED"
echo -e "ACTUAL: $OUTPUT"
EXIT_CODE=1
fi

if [[ ${EXIT_CODE} != 0 ]]; then
exit ${EXIT_CODE}
exit 1
fi

0 comments on commit a9d556e

Please sign in to comment.