[jboss-cvs] JBossAS SVN: r82456 - projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 19 18:20:18 EST 2008
Author: kabir.khan at jboss.com
Date: 2008-12-19 18:20:18 -0500 (Fri, 19 Dec 2008)
New Revision: 82456
Added:
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java
Modified:
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTest.java
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java
Log:
[JBAOP-666] Port some tests from jboss-cl as 'sanity' tests to form the basis of tests using the javassist classpools
Added: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java 2008-12-19 23:20:18 UTC (rev 82456)
@@ -0,0 +1,323 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.classpool.jbosscl.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.aop.classpool.jbosscl.support.BundleInfoBuilder;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.ModuleDependencyUnitTestCase using our test framework,
+ * the original tests are testImportNoVersionCheck, testImportVersionCheck and testImportVersionCheckFailed.
+ * ClassPoolWithModuleDependencyTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithModuleDependencySanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithModuleDependencySanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithModuleDependencySanityTestCase.class);
+ }
+
+ public void testImportNoVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader("A", builderA, JAR_A_1);
+
+ Class<?> aFromA = assertLoadClass(CLASS_A, clA, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("ModuleB").
+ createRequireModule("ModuleA");
+ clB = createClassLoader("B", builderB, JAR_B_1);
+
+ Class<?> aFromA1 = assertLoadClass(CLASS_A, clA, clA);
+ assertSame(aFromA, aFromA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(aFromA, aFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> aFromA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(aFromA, aFromA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ //TODO assertNoClassLoader(b);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ public void testImportVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "1.0.0").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader("A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")).
+ createPackage(PACKAGE_B);
+ clB = createClassLoader("B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ public void testImportVersionCheckFailed() throws Exception
+ {
+ ClassLoader clA = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "3.0.0").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader("A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")).
+ createPackage(PACKAGE_B);
+ try
+ {
+ createClassLoader("B", builderB, JAR_B_1);
+ fail("Should not have been able to create loader");
+ }
+ catch(NoSuchClassLoaderException expected)
+ {
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader("B");
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ //These are my extra tests
+ public void testSeveralModulesWithSamePackages() throws Exception
+ {
+ ClassLoader clAModuleX = null;
+ ClassLoader clAModuleA = null;
+ ClassLoader clAModuleY = null;
+
+ try
+ {
+ BundleInfoBuilder builderAX = BundleInfoBuilder.getBuilder().
+ createModule("ModuleX").
+ createPackage(PACKAGE_A);
+ clAModuleX = createClassLoader("X", builderAX, JAR_A_1);
+
+ BundleInfoBuilder builderAA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clAModuleA = createClassLoader("A", builderAA, JAR_A_1);
+
+ BundleInfoBuilder builderAY = BundleInfoBuilder.getBuilder().
+ createModule("ModuleY").
+ createPackage(PACKAGE_A);
+ clAModuleY = createClassLoader("Y", builderAY, JAR_A_1);
+
+ Class<?> classAX = assertLoadClass(CLASS_A, clAModuleX);
+ Class<?> classAA = assertLoadClass(CLASS_A, clAModuleA);
+ Class<?> classAY = assertLoadClass(CLASS_A, clAModuleY);
+ assertCannotLoadClass(clAModuleX, CLASS_B);
+ assertCannotLoadClass(clAModuleA, CLASS_B);
+ assertCannotLoadClass(clAModuleY, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA").
+ createPackage(PACKAGE_B);
+ clB = createClassLoader("B", builderB, JAR_B_1);
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleX);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleY);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleX, CLASS_B);
+ assertCannotLoadClass(clAModuleA, CLASS_B);
+ assertCannotLoadClass(clAModuleY, CLASS_B);
+
+ assertLoadClass(CLASS_B, clB, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clAModuleA);
+ assertSame(aFromB, classAA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleX);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleY);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleX, CLASS_B);
+ assertCannotLoadClass(clAModuleA, CLASS_B);
+ assertCannotLoadClass(clAModuleY, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clAModuleY);
+ unregisterClassLoader(clAModuleA);
+ unregisterClassLoader(clAModuleX);
+ }
+ }
+
+ public void testSeveralModulesWithSameNamesDifferentVersions() throws Exception
+ {
+ ClassLoader clAModuleA1 = null;
+ ClassLoader clAModuleA2 = null;
+ ClassLoader clAModuleA3 = null;
+
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "1.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA1 = createClassLoader("X", builderA1, JAR_A_1);
+
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "2.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA2 = createClassLoader("A", builderA2, JAR_A_1);
+
+ BundleInfoBuilder builderA3 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "3.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA3 = createClassLoader("Y", builderA3, JAR_A_1);
+
+ Class<?> classAX = assertLoadClass(CLASS_A, clAModuleA1);
+ Class<?> classAA = assertLoadClass(CLASS_A, clAModuleA2);
+ Class<?> classAY = assertLoadClass(CLASS_A, clAModuleA3);
+ assertCannotLoadClass(clAModuleA1, CLASS_B);
+ assertCannotLoadClass(clAModuleA2, CLASS_B);
+ assertCannotLoadClass(clAModuleA3, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("2.0.0", true, "3.0.0", false)).
+ createPackage(PACKAGE_B);
+ clB = createClassLoader("B", builderB, JAR_B_1);
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleA1);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA2);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleA3);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleA1, CLASS_B);
+ assertCannotLoadClass(clAModuleA2, CLASS_B);
+ assertCannotLoadClass(clAModuleA3, CLASS_B);
+
+ assertLoadClass(CLASS_B, clB, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clAModuleA2);
+ assertSame(aFromB, classAA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleA1);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA2);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleA3);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleA1, CLASS_B);
+ assertCannotLoadClass(clAModuleA2, CLASS_B);
+ assertCannotLoadClass(clAModuleA3, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clAModuleA3);
+ unregisterClassLoader(clAModuleA2);
+ unregisterClassLoader(clAModuleA1);
+ }
+
+ }
+}
Added: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java 2008-12-19 23:20:18 UTC (rev 82456)
@@ -0,0 +1,247 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.classpool.jbosscl.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.aop.classpool.jbosscl.support.BundleInfoBuilder;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.PackageDependencyUnitTestCase using our test framework,
+ * the original tests are testImportNoVersionCheck, testImportVersionCheck and testImportVersionCheckFailed.
+ * ClassPoolWithPackageDependencyTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithPackageDependencySanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithPackageDependencySanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithPackageDependencySanityTestCase.class);
+ }
+
+ public void testImportNoVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader("A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A);
+ clB = createClassLoader("B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, aFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ public void testImportVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A, "1.0.0");
+ clA = createClassLoader("A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", "2.0.0"));
+ clB = createClassLoader("B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, aFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ public void testImportVersionCheckFailed() throws Exception
+ {
+ ClassLoader clA = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A, "3.0.0");
+ clA = createClassLoader("A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", "2.0.0"));
+ try
+ {
+ createClassLoader("B", builderB, JAR_B_1);
+ fail("Should not have been able to create loader");
+ }
+ catch(NoSuchClassLoaderException expected)
+ {
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader("B");
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ //These are mine
+
+ public void testSeveralModulesWithSamePackagesDifferentVersions() throws Exception
+ {
+ ClassLoader clA1 = null;
+ ClassLoader clA2 = null;
+ ClassLoader clA3 = null;
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "1.0.0");
+ clA1 = createClassLoader("A1", builderA1, JAR_A_1);
+
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "2.0.0");
+ clA2 = createClassLoader("A2", builderA2, JAR_A_1);
+
+ BundleInfoBuilder builderA3 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "3.0.0");
+ clA3 = createClassLoader("A3", builderA3, JAR_A_1);
+
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA1);
+ Class<?> classA2 = assertLoadClass(CLASS_A, clA2);
+ Class<?> classA3 = assertLoadClass(CLASS_A, clA3);
+ assertCannotLoadClass(clA1, CLASS_B);
+ assertCannotLoadClass(clA2, CLASS_B);
+ assertCannotLoadClass(clA3, CLASS_B);
+
+ ClassLoader clB = null;
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", false, "2.0.0", true));
+ clB = createClassLoader("B", builderB, JAR_B_1);
+ Class<?> classA11 = assertLoadClass(CLASS_A, clA1);
+ assertSame(classA1, classA11);
+ Class<?> classA21 = assertLoadClass(CLASS_A, clA2);
+ assertSame(classA2, classA21);
+ Class<?> classA31 = assertLoadClass(CLASS_A, clA3);
+ assertSame(classA3, classA31);
+ assertCannotLoadClass(clA1, CLASS_B);
+ assertCannotLoadClass(clA2, CLASS_B);
+ assertCannotLoadClass(clA3, CLASS_B);
+
+ assertLoadClass(CLASS_B, clB);
+ Class<?> classAFromB = assertLoadClass(CLASS_A, clB, clA2);
+ assertSame(classA2, classAFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> classA11 = assertLoadClass(CLASS_A, clA1);
+ assertSame(classA1, classA11);
+ Class<?> classA21 = assertLoadClass(CLASS_A, clA2);
+ assertSame(classA2, classA21);
+ Class<?> classA31 = assertLoadClass(CLASS_A, clA3);
+ assertSame(classA3, classA31);
+ assertCannotLoadClass(clA1, CLASS_B);
+ assertCannotLoadClass(clA2, CLASS_B);
+ assertCannotLoadClass(clA3, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA3);
+ unregisterClassLoader(clA2);
+ unregisterClassLoader(clA1);
+ }
+
+ }
+}
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTest.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTest.java 2008-12-19 21:51:41 UTC (rev 82455)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTest.java 2008-12-19 23:20:18 UTC (rev 82456)
@@ -85,7 +85,7 @@
private Map<ClassLoader, ClassLoaderDomain> scopedChildDomainsByLoader = new WeakHashMap<ClassLoader, ClassLoaderDomain>();
- private Map<ClassLoader, KernelDeployment> deploymentsByLoader = new HashMap<ClassLoader, KernelDeployment>();
+ private LoaderNameDeploymentRegistry loaderNameDeploymentRegistry = new LoaderNameDeploymentRegistry();
/** The classloader helper */
//protected static IsolatedClassLoaderTestHelper helper;
@@ -254,10 +254,11 @@
}
KernelDeployment deployment = install(factory);
+ loaderNameDeploymentRegistry.registerDeployment(factory.getName(), deployment);
+ ClassLoader loader = assertClassLoader(factory);
Module module = assertModule(getContextName(factory));
- ClassLoader loader = assertClassLoader(factory);
registerModule(loader, module);
- deploymentsByLoader.put(loader, deployment);
+ loaderNameDeploymentRegistry.registerLoaderName(factory.getName(), loader);
return loader;
}
@@ -449,14 +450,25 @@
if (registeredURLClassLoaders.remove(classLoader) == false)
{
domainRegistry.cleanupLoader(classLoader);
- KernelDeployment deployment = deploymentsByLoader.remove(classLoader);
- if (deployment != null)
- {
- undeploy(deployment);
- }
+ KernelDeployment deployment = loaderNameDeploymentRegistry.unregisterDeployment(classLoader);
+ unregisterDeployment(deployment);
}
}
}
+
+ protected void unregisterClassLoader(String name) throws Exception
+ {
+ KernelDeployment deployment = loaderNameDeploymentRegistry.unregisterDeployment(name);
+ unregisterDeployment(deployment);
+ }
+
+ private void unregisterDeployment(KernelDeployment deployment)
+ {
+ if (deployment != null)
+ {
+ undeploy(deployment);
+ }
+ }
/**
* Unregister a domain
@@ -496,9 +508,31 @@
protected ClassLoader assertClassLoader(String name) throws Exception
{
- Object obj = getBean(name);
- return assertInstanceOf(obj, ClassLoader.class);
+ try
+ {
+ Object obj = getBean(name);
+ return assertInstanceOf(obj, ClassLoader.class);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new NoSuchClassLoaderException(e);
+ }
}
+
+ protected Class<?> assertLoadClass(String name, ClassLoader initiating) throws Exception
+ {
+ return assertLoadClass(name, initiating, initiating);
+ }
+
+ protected Class<?> assertLoadClass(String name, ClassLoader initiating, ClassLoader expected) throws Exception
+ {
+ Class<?> clazz = initiating.loadClass(name);
+ if (expected != null)
+ {
+ assertSame(expected, clazz.getClassLoader());
+ }
+ return clazz;
+ }
protected Module assertModule(String contextName)
{
@@ -514,4 +548,49 @@
assertCannotLoadClass(this.getClass().getClassLoader(), CLASS_B);
assertCannotLoadClass(this.getClass().getClassLoader(), CLASS_C);
}
+
+ static class NoSuchClassLoaderException extends Exception
+ {
+ private static final long serialVersionUID = 1L;
+
+ public NoSuchClassLoaderException(Exception e)
+ {
+ super(e);
+ }
+ }
+
+ private static class LoaderNameDeploymentRegistry
+ {
+ private Map<String, KernelDeployment> deploymentsByName = new HashMap<String, KernelDeployment>();
+
+ private Map<ClassLoader, String> namesByLoader = new HashMap<ClassLoader, String>();
+
+ private void registerDeployment(String name, KernelDeployment deployment)
+ {
+ if (!deploymentsByName.containsKey(name))
+ {
+ deploymentsByName.put(name, deployment);
+ }
+ }
+
+ private void registerLoaderName(String name, ClassLoader loader)
+ {
+ if (loader != null)
+ {
+ namesByLoader.put(loader, name);
+ }
+ }
+
+ private KernelDeployment unregisterDeployment(String name)
+ {
+ return deploymentsByName.remove(name);
+ }
+
+ private KernelDeployment unregisterDeployment(ClassLoader loader)
+ {
+ String name = namesByLoader.remove(loader);
+ return unregisterDeployment(name);
+ }
+ }
+
}
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java 2008-12-19 21:51:41 UTC (rev 82455)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/JBossClClassPoolTestSuite.java 2008-12-19 23:20:18 UTC (rev 82456)
@@ -43,8 +43,8 @@
suite.addTest(ClassLoaderWithRepositorySanityTestCase.suite());
suite.addTest(ClassPoolWithRepositoryTestCase.suite());
-// suite.addTest(ClassLoaderWithModuleSanityTestCase.suite());
-
+ suite.addTest(ClassLoaderWithModuleDependencySanityTestCase.suite());
+ suite.addTest(ClassLoaderWithPackageDependencySanityTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list