Remove tests which rely on an isolated ClassLoader

Java 9 returns jdk.internal.loader.ClassLoaders$AppClassLoader instead
of URLClassLoader so we cannot create an isolated ClassLoader.
This commit is contained in:
Andrew Gaul 2021-07-10 11:47:03 +09:00 committed by Andrew Gaul
parent 1321043c02
commit e49ce2e835
1 changed files with 0 additions and 76 deletions

View File

@ -23,13 +23,9 @@ import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify; import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List; import java.util.List;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
@ -48,15 +44,6 @@ import com.google.common.collect.Lists;
public class MetadataBundleListenerTest { public class MetadataBundleListenerTest {
@Test
public void testSanity() throws MalformedURLException, ClassNotFoundException {
// We are checking here that the class loader we create and use in this test series is indeed different and
// isolated from our tests classloader.
ClassLoader loader = createIsolatedClassLoader();
assertFalse(ProviderMetadata.class.isAssignableFrom(loader
.loadClass("org.jclouds.providers.JcloudsTestComputeProviderMetadata")));
}
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Test @Test
public void testGetProviderMetadata() throws Exception { public void testGetProviderMetadata() throws Exception {
@ -112,31 +99,6 @@ public class MetadataBundleListenerTest {
verify(bundle, providerListener); verify(bundle, providerListener);
} }
@SuppressWarnings("rawtypes")
@Test
public void testGetProviderMetadataFromMultipleClassLoaders() throws Exception {
ClassLoader isolatedClassLoader = createIsolatedClassLoader();
MetadataBundleListener listener = new MetadataBundleListener();
Bundle bundle = createMock(Bundle.class);
expect(bundle.getEntry("/META-INF/services/org.jclouds.providers.ProviderMetadata")).andReturn(
getClass().getResource("/META-INF/services/org.jclouds.providers.ProviderMetadata")).anyTimes();
expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata")).andReturn(
isolatedClassLoader.loadClass(JcloudsTestBlobStoreProviderMetadata.class.getName())).anyTimes();
expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestComputeProviderMetadata")).andReturn(
JcloudsTestComputeProviderMetadata.class).anyTimes();
expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata")).andReturn(
JcloudsTestYetAnotherComputeProviderMetadata.class).anyTimes();
replay(bundle);
List<ProviderMetadata> providerMetadataList = Lists.newArrayList(listener.listProviderMetadata(bundle));
assertNotNull(providerMetadataList);
assertEquals(2, providerMetadataList.size());
assertFalse(providerMetadataList.contains(new JcloudsTestBlobStoreProviderMetadata()));
assertTrue(providerMetadataList.contains(new JcloudsTestComputeProviderMetadata()));
assertTrue(providerMetadataList.contains(new JcloudsTestYetAnotherComputeProviderMetadata()));
verify(bundle);
}
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Test @Test
public void testGetApiMetadata() throws Exception { public void testGetApiMetadata() throws Exception {
@ -192,42 +154,4 @@ public class MetadataBundleListenerTest {
listener.bundleChanged(event); listener.bundleChanged(event);
verify(bundle, apiListener); verify(bundle, apiListener);
} }
@SuppressWarnings("rawtypes")
@Test
public void testGetApiMetadataFromMultipleClassLoaders() throws Exception {
ClassLoader isolatedClassLoader = createIsolatedClassLoader();
MetadataBundleListener listener = new MetadataBundleListener();
Bundle bundle = createMock(Bundle.class);
expect(bundle.getEntry("/META-INF/services/org.jclouds.apis.ApiMetadata")).andReturn(
getClass().getResource("/META-INF/services/org.jclouds.apis.ApiMetadata")).anyTimes();
expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestBlobStoreApiMetadata")).andReturn(
isolatedClassLoader.loadClass(JcloudsTestBlobStoreApiMetadata.class.getName())).anyTimes();
expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestComputeApiMetadata")).andReturn(
JcloudsTestComputeApiMetadata.class).anyTimes();
expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestYetAnotherComputeApiMetadata")).andReturn(
JcloudsTestYetAnotherComputeApiMetadata.class).anyTimes();
replay(bundle);
List<ApiMetadata> apiMetadataList = Lists.newArrayList(listener.listApiMetadata(bundle));
assertNotNull(apiMetadataList);
assertEquals(2, apiMetadataList.size());
assertFalse(apiMetadataList.contains(new JcloudsTestBlobStoreApiMetadata()));
assertTrue(apiMetadataList.contains(new JcloudsTestComputeApiMetadata()));
assertTrue(apiMetadataList.contains(new JcloudsTestYetAnotherComputeApiMetadata()));
verify(bundle);
}
/**
* Creates a different {@link ClassLoader}.
*
* @return
*/
private ClassLoader createIsolatedClassLoader() throws MalformedURLException {
URLClassLoader testClassLoader = (URLClassLoader) getClass().getClassLoader();
URL[] urls = testClassLoader.getURLs();
URLClassLoader loader = new URLClassLoader(urls, null);
return loader;
}
} }