1 22 package org.jboss.test.classloader.circularity.test; 23 24 import java.net.URL ; 25 import java.lang.reflect.Constructor ; 26 27 import org.jboss.logging.Logger; 28 29 import org.jboss.test.classloader.circularity.support.Support; 30 import org.jboss.mx.loading.UnifiedClassLoader; 31 import org.jboss.mx.loading.UnifiedClassLoader3; 32 import org.jboss.mx.loading.UnifiedLoaderRepository3; 33 34 39 public class CircularityErrorTests3 40 { 41 private static Logger log = Logger.getLogger(CircularityErrorTests.class); 42 43 private Object lock = new Object (); 44 private boolean sawCircularity; 45 private boolean sawClassNotFound; 46 47 public CircularityErrorTests3() 48 { 49 } 50 51 public void testClassCircularityError() throws Exception 52 { 53 60 UnifiedLoaderRepository3 repository = new UnifiedLoaderRepository3(); 61 Class thisClass = getClass(); 62 UnifiedClassLoader thisUCL = (UnifiedClassLoader) thisClass.getClassLoader(); 63 URL origURL = thisUCL.getOrigURL(); 64 log.debug("Service origURL="+origURL); 65 URL url = thisClass.getProtectionDomain().getCodeSource().getLocation(); 66 final UnifiedLoader ucl = new UnifiedLoader(url); 67 repository.addClassLoader(ucl); 68 log.debug("Unified ClassLoader created, url="+url); 69 70 Class cls = ucl.loadClass("org.jboss.test.classloader.circularity.support.Support"); 71 72 Thread thread1 = new Thread (new Runnable () 73 { 74 public void run() 75 { 76 try 77 { 78 try {Thread.sleep(1000);} 80 catch (InterruptedException x) {} 81 82 try 83 { 84 log.debug("Thread " + Thread.currentThread() + " loading..."); 86 ucl.loadClass("org.jboss.test.classloader.circularity.support.Derived"); 87 log.debug("Thread " + Thread.currentThread() + " loading done !"); 88 } 89 catch (ClassCircularityError x) 90 { 91 log.error("Saw ClassCircularityError", x); 92 sawCircularity = true; 93 } 94 } 95 catch (ClassNotFoundException x) 96 { 97 log.error("Bug in the test: ", x); 98 sawClassNotFound = true; 99 } 100 } 101 }, "CircularityError Thread"); 102 thread1.start(); 103 104 synchronized (lock) 105 { 106 log.debug("Thread " + Thread.currentThread() + " waiting..."); 107 lock.wait(); 108 log.debug("Thread " + Thread.currentThread() + " woken up !"); 109 } 110 111 cls.newInstance(); 115 116 if( sawCircularity ) 118 throw new ClassCircularityError ("Got ClassCircularityError, UnifiedLoaderRepository is buggy"); 119 if( sawClassNotFound ) 120 throw new ClassNotFoundException ("Got ClassNotFoundException, UnifiedLoaderRepository is buggy"); 121 } 122 123 public class UnifiedLoader extends UnifiedClassLoader3 124 { 125 public UnifiedLoader(URL url) 126 { 127 super(url); 128 } 129 130 public Class loadClass(String name) throws ClassNotFoundException 131 { 132 return super.loadClass(name); 133 } 134 135 public Class loadClassLocally(String name, boolean resolve) throws ClassNotFoundException 136 { 137 log.debug(Thread.currentThread() + " is now asked to load class: " + name); 138 139 if (name.equals("org.jboss.test.classloader.circularity.support.Derived")) 140 { 141 synchronized (lock) 142 { 143 lock.notifyAll(); 144 } 145 146 try 149 { 150 log.debug("Loading " + name + ", waiting..."); 151 Thread.sleep(2000); 152 log.debug("Loading " + name + " end wait"); 153 } 154 catch (InterruptedException x) 155 { 156 log.debug("Sleep was interrupted", x); 157 } 158 } 159 160 return super.loadClassLocally(name, resolve); 161 } 162 } 163 164 } 165 | Popular Tags |