Skip to content

Commit a372299

Browse files
authored
HADOOP-19890: s3a: fix isolated classloader test for jdk >=17 (#8491)
* HADOOP-19890: s3a: fix isolated classloader test for jdk >=17
1 parent ed29a6a commit a372299

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AFileSystemIsolatedClassloader.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.assertj.core.api.Assertions;
2828
import org.junit.jupiter.api.Test;
29+
2930
import software.amazon.awssdk.auth.credentials.AwsCredentials;
3031
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
3132

@@ -34,8 +35,6 @@
3435
import org.apache.hadoop.fs.s3a.impl.InstantiationIOException;
3536

3637
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
37-
import static org.mockito.Mockito.doReturn;
38-
import static org.mockito.Mockito.spy;
3938

4039
/**
4140
* Checks that classloader isolation for loading extension classes is applied
@@ -47,9 +46,9 @@ public class ITestS3AFileSystemIsolatedClassloader extends AbstractS3ATestBase {
4746

4847
private static String customClassName = "custom.class.name";
4948

50-
private static class CustomCredentialsProvider implements AwsCredentialsProvider {
49+
public static class CustomCredentialsProvider implements AwsCredentialsProvider {
5150

52-
CustomCredentialsProvider() {
51+
public CustomCredentialsProvider() {
5352
}
5453

5554
@Override
@@ -60,19 +59,23 @@ public AwsCredentials resolveCredentials() {
6059
}
6160

6261
private static class CustomClassLoader extends ClassLoader {
63-
}
6462

65-
private final ClassLoader customClassLoader = spy(new CustomClassLoader());
66-
{
67-
try {
68-
doReturn(CustomCredentialsProvider.class)
69-
.when(customClassLoader)
70-
.loadClass(customClassName);
71-
} catch (ClassNotFoundException ex) {
72-
throw new RuntimeException(ex);
63+
CustomClassLoader(ClassLoader parent) {
64+
super(parent);
65+
}
66+
67+
@Override
68+
public Class<?> loadClass(String name) throws ClassNotFoundException {
69+
if (customClassName.equals(name)) {
70+
return CustomCredentialsProvider.class;
71+
}
72+
return super.loadClass(name);
7373
}
7474
}
7575

76+
private final ClassLoader customClassLoader =
77+
new CustomClassLoader(ITestS3AFileSystemIsolatedClassloader.class.getClassLoader());
78+
7679
private S3AFileSystem createNewTestFs(Configuration conf) throws IOException {
7780
S3AFileSystem fs = new S3AFileSystem();
7881
fs.initialize(getFileSystem().getUri(), conf);

0 commit comments

Comments
 (0)