Skip to content

Commit 096c63a

Browse files
committed
[FLINK-11155][fs] Fix hadoop-free factory tests on Java 9
1 parent 1d5dda3 commit 096c63a

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.util;
19+
20+
import java.io.File;
21+
import java.net.MalformedURLException;
22+
import java.net.URL;
23+
import java.util.Arrays;
24+
25+
/**
26+
* Collection of class-loading utilities.
27+
*/
28+
public final class ClassLoaderUtils {
29+
30+
public static URL[] getClasspathURLs() {
31+
final String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
32+
33+
return Arrays.stream(cp)
34+
.filter(str -> !str.isEmpty())
35+
.map(ClassLoaderUtils::parse)
36+
.toArray(URL[]::new);
37+
}
38+
39+
private static URL parse(String fileName) {
40+
try {
41+
return new File(fileName).toURI().toURL();
42+
} catch (MalformedURLException e) {
43+
throw new RuntimeException(e);
44+
}
45+
}
46+
47+
private ClassLoaderUtils() {}
48+
}

flink-filesystems/flink-hadoop-fs/src/test/java/org/apache/flink/runtime/fs/hdfs/HadoopFreeFsFactoryTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
package org.apache.flink.runtime.fs.hdfs;
2020

21+
import org.apache.flink.util.ClassLoaderUtils;
2122
import org.apache.flink.util.ExceptionUtils;
2223
import org.apache.flink.util.TestLogger;
2324

2425
import org.junit.Test;
2526

2627
import java.lang.reflect.InvocationTargetException;
2728
import java.lang.reflect.Method;
29+
import java.net.URL;
2830
import java.net.URLClassLoader;
2931

3032
/**
@@ -43,8 +45,10 @@ public void testHadoopFactoryInstantiationWithoutHadoop() throws Exception {
4345

4446
final String testClassName = "org.apache.flink.runtime.fs.hdfs.HadoopFreeTests";
4547

46-
URLClassLoader parent = (URLClassLoader) getClass().getClassLoader();
47-
ClassLoader hadoopFreeClassLoader = new HadoopFreeClassLoader(parent);
48+
final URL[] urls = ClassLoaderUtils.getClasspathURLs();
49+
50+
ClassLoader parent = getClass().getClassLoader();
51+
ClassLoader hadoopFreeClassLoader = new HadoopFreeClassLoader(urls, parent);
4852
Class<?> testClass = Class.forName(testClassName, false, hadoopFreeClassLoader);
4953
Method m = testClass.getDeclaredMethod("test");
5054

@@ -62,8 +66,8 @@ private static final class HadoopFreeClassLoader extends URLClassLoader {
6266

6367
private final ClassLoader properParent;
6468

65-
HadoopFreeClassLoader(URLClassLoader parent) {
66-
super(parent.getURLs(), null);
69+
HadoopFreeClassLoader(URL[] urls, ClassLoader parent) {
70+
super(urls, null);
6771
properParent = parent;
6872
}
6973

flink-filesystems/flink-mapr-fs/src/test/java/org/apache/flink/runtime/fs/maprfs/MapRFsFactoryTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.flink.configuration.Configuration;
2222
import org.apache.flink.core.fs.FileSystem;
23+
import org.apache.flink.util.ClassLoaderUtils;
2324
import org.apache.flink.util.ExceptionUtils;
2425
import org.apache.flink.util.TestLogger;
2526

@@ -29,6 +30,7 @@
2930
import java.lang.reflect.InvocationTargetException;
3031
import java.lang.reflect.Method;
3132
import java.net.URI;
33+
import java.net.URL;
3234
import java.net.URLClassLoader;
3335

3436
import static org.junit.Assert.assertEquals;
@@ -50,8 +52,10 @@ public void testInstantiationWithoutMapRClasses() throws Exception {
5052

5153
final String testClassName = "org.apache.flink.runtime.fs.maprfs.MapRFreeTests";
5254

53-
URLClassLoader parent = (URLClassLoader) getClass().getClassLoader();
54-
ClassLoader maprFreeClassLoader = new MapRFreeClassLoader(parent);
55+
final URL[] urls = ClassLoaderUtils.getClasspathURLs();
56+
57+
ClassLoader parent = getClass().getClassLoader();
58+
ClassLoader maprFreeClassLoader = new MapRFreeClassLoader(urls, parent);
5559
Class<?> testClass = Class.forName(testClassName, false, maprFreeClassLoader);
5660
Method m = testClass.getDeclaredMethod("test");
5761

@@ -95,8 +99,8 @@ private static final class MapRFreeClassLoader extends URLClassLoader {
9599

96100
private final ClassLoader properParent;
97101

98-
MapRFreeClassLoader(URLClassLoader parent) {
99-
super(parent.getURLs(), null);
102+
MapRFreeClassLoader(URL[] urls, ClassLoader parent) {
103+
super(urls, null);
100104
properParent = parent;
101105
}
102106

tools/travis/stage.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ flink-connectors/flink-connector-rabbitmq,\
9797
flink-connectors/flink-connector-twitter"
9898

9999
MODULES_CONNECTORS_JDK9_EXCLUSIONS="\
100-
!flink-filesystems/flink-hadoop-fs,\
101-
!flink-filesystems/flink-mapr-fs,\
102100
!flink-filesystems/flink-s3-fs-hadoop,\
103101
!flink-filesystems/flink-s3-fs-presto,\
104102
!flink-formats/flink-avro,\

0 commit comments

Comments
 (0)