1 22 package test.implementation.loading; 23 24 import java.net.URL ; 25 26 import javax.management.MBeanException ; 27 import javax.management.MBeanServer ; 28 import javax.management.MBeanServerFactory ; 29 import javax.management.ObjectName ; 30 import javax.management.ReflectionException ; 31 import javax.management.loading.DefaultLoaderRepository ; 32 import javax.management.loading.MLet ; 33 34 import junit.framework.TestCase; 35 36 import org.jboss.mx.loading.LoaderRepository; 37 import org.jboss.mx.loading.RepositoryClassLoader; 38 import org.jboss.mx.server.ServerConstants; 39 import org.jboss.mx.util.AgentID; 40 41 public class LoaderRepositoryTEST extends TestCase implements ServerConstants 42 { 43 public LoaderRepositoryTEST(String s) 44 { 45 super(s); 46 } 47 48 public void testRemoveDuplicateURL() throws Exception 49 { 50 final URL url = new URL ("file:./output/etc/test/implementation/loading/MyMBeans.jar"); 53 54 MBeanServer server = MBeanServerFactory.createMBeanServer(); 56 LoaderRepository lr = (LoaderRepository )server.getClassLoaderRepository(); 57 58 try 60 { 61 lr.loadClass("test.implementation.loading.support.Trivial"); 62 fail("test.implementation.loading.support.Trivial is already visible"); 63 } 64 catch (ClassNotFoundException expected) {} 65 66 RepositoryClassLoader ucl1 = lr.newClassLoader(url, true); 68 RepositoryClassLoader ucl2 = lr.newClassLoader(url, true); 69 70 lr.loadClass("test.implementation.loading.support.Trivial"); 72 73 ucl1.unregister(); 75 76 lr.loadClass("test.implementation.loading.support.Trivial"); 78 79 ucl2.unregister(); 81 } 82 83 public void testClassConflictBetweenMLets() throws Exception 84 { 85 88 String [] classes = { "test.implementation.loading.support.Start", 90 "test.implementation.loading.support.StartMBean", 91 "test.implementation.loading.support.Target", 92 "test.implementation.loading.support.TargetMBean", 93 "test.implementation.loading.support.AClass" 94 }; 95 96 for (int i = 0; i < classes.length; ++i) 97 { 98 try 99 { 100 DefaultLoaderRepository.loadClass(classes[i]); 101 102 fail("class " + classes[i] + " was already found in CL repository."); 103 } 104 catch (ClassNotFoundException e) 105 { 106 } 108 } 109 110 try 111 { 112 MBeanServer server = MBeanServerFactory.createMBeanServer(); 113 MLet mlet1 = new MLet (); 114 MLet mlet2 = new MLet (); 115 ObjectName m1Name = new ObjectName (":name=mlet1"); 116 ObjectName m2Name = new ObjectName (":name=mlet2"); 117 118 server.registerMBean(mlet1, m1Name); 119 server.registerMBean(mlet2, m2Name); 120 121 server.invoke(m1Name, "getMBeansFromURL", 122 new Object [] { "file:./output/etc/test/implementation/loading/CCTest1.mlet" }, 123 new String [] { String .class.getName() } 124 ); 125 126 server.invoke(m2Name, "getMBeansFromURL", 127 new Object [] { "file:./output/etc/test/implementation/loading/CCTest2.mlet" }, 128 new String [] { String .class.getName() } 129 ); 130 131 server.invoke(new ObjectName (":name=Start"), "startOp", 132 new Object [] { AgentID.get(server) }, 133 new String [] { String .class.getName() } 134 ); 135 136 } 138 catch (MBeanException e) 139 { 140 if (e.getTargetException() instanceof ReflectionException ) 141 { 142 if (System.getProperty(LOADER_REPOSITORY_CLASS_PROPERTY).equals(UNIFIED_LOADER_REPOSITORY_CLASS)) 145 throw e; 146 } 147 else throw e; 148 } 149 } 150 151 } 152 | Popular Tags |