From e49ce2e835d9ca8d4176bc7a67f81dad8f9f13f0 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 10 Jul 2021 11:47:03 +0900 Subject: [PATCH] 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. --- .../osgi/MetadataBundleListenerTest.java | 76 ------------------- 1 file changed, 76 deletions(-) diff --git a/core/src/test/java/org/jclouds/osgi/MetadataBundleListenerTest.java b/core/src/test/java/org/jclouds/osgi/MetadataBundleListenerTest.java index 536f6b5c77..6a9732f770 100644 --- a/core/src/test/java/org/jclouds/osgi/MetadataBundleListenerTest.java +++ b/core/src/test/java/org/jclouds/osgi/MetadataBundleListenerTest.java @@ -23,13 +23,9 @@ import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; import java.util.List; import org.jclouds.apis.ApiMetadata; @@ -48,15 +44,6 @@ import com.google.common.collect.Lists; 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") @Test public void testGetProviderMetadata() throws Exception { @@ -112,31 +99,6 @@ public class MetadataBundleListenerTest { 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 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") @Test public void testGetApiMetadata() throws Exception { @@ -192,42 +154,4 @@ public class MetadataBundleListenerTest { listener.bundleChanged(event); 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 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; - } }