From: Steve L. <st...@us...> - 2004-11-17 15:00:48
|
Update of /cvsroot/smartfrog/core/components/junit/src/org/smartfrog/services/junit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv961/components/junit/src/org/smartfrog/services/junit Modified Files: JUnitTestSuiteImpl.java Log Message: Getting close to understanding why this isnt working. Index: JUnitTestSuiteImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/components/junit/src/org/smartfrog/services/junit/JUnitTestSuiteImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JUnitTestSuiteImpl.java 15 Nov 2004 22:13:19 -0000 1.6 --- JUnitTestSuiteImpl.java 17 Nov 2004 15:00:38 -0000 1.7 *************** *** 33,36 **** --- 33,37 ---- import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; + import java.net.UnknownHostException; import java.rmi.RemoteException; import java.util.ArrayList; *************** *** 38,53 **** import java.util.Iterator; import java.util.List; - import java.util.regex.Pattern; - import java.net.UnknownHostException; - /** ! * Implementation of the Junit test suite component. ! * This is where tests are actually run; we bring up Junit internally and run it here ! * created 14-May-2004 15:14:23 */ ! public class JUnitTestSuiteImpl extends PrimImpl implements JUnitTestSuite, junit.framework.TestListener { private Log log; --- 39,52 ---- import java.util.Iterator; import java.util.List; /** ! * Implementation of the Junit test suite component. This is where tests are ! * actually run; we bring up Junit internally and run it here created ! * 14-May-2004 15:14:23 */ ! public class JUnitTestSuiteImpl extends PrimImpl implements JUnitTestSuite, ! junit.framework.TestListener { private Log log; *************** *** 85,89 **** - public boolean getIf() throws RemoteException { return ifValue; --- 84,87 ---- *************** *** 122,126 **** * @throws java.rmi.RemoteException In case of network/rmi error */ ! public synchronized void sfDeploy() throws SmartFrogException, RemoteException { super.sfDeploy(); log = helper.getLogger(); --- 120,125 ---- * @throws java.rmi.RemoteException In case of network/rmi error */ ! public synchronized void sfDeploy() throws SmartFrogException, ! RemoteException { super.sfDeploy(); log = helper.getLogger(); *************** *** 135,139 **** * @throws java.rmi.RemoteException In case of network/rmi error */ ! public synchronized void sfStart() throws SmartFrogException, RemoteException { super.sfStart(); readConfiguration(); --- 134,139 ---- * @throws java.rmi.RemoteException In case of network/rmi error */ ! public synchronized void sfStart() throws SmartFrogException, ! RemoteException { super.sfStart(); readConfiguration(); *************** *** 141,176 **** } ! protected void readConfiguration() throws SmartFrogException, RemoteException { ! ifValue=sfResolve(ATTR_IF,ifValue,false); ! unlessValue=sfResolve(ATTR_UNLESS,unlessValue,false); ! classes = flattenStringList((List)sfResolve(ATTR_CLASSES,classes,false),ATTR_CLASSES); //package attribute names a package ! packageValue = sfResolve(ATTR_PACKAGE,packageValue,false); ! if(packageValue==null) { ! packageValue=""; } else { //add a dot at the end if we need it ! if(packageValue.length()>0 && packageValue.charAt(packageValue.length()-1)!='.') { ! packageValue= packageValue+'.'; } } buildClassList(); try { ! hostname=java.net.InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { ! hostname="localhost"; } //name ! suitename=sfResolve(ATTR_NAME,(String)null,true); } /** ! * build the list of classes to run. ! * At this point the list is already flat. */ protected void buildClassList() { testClasses = new HashMap(); ! Iterator it=classes.iterator(); while (it.hasNext()) { String testclass = (String) it.next(); --- 141,183 ---- } ! protected void readConfiguration() throws SmartFrogException, ! RemoteException { ! ifValue = sfResolve(ATTR_IF, ifValue, false); ! unlessValue = sfResolve(ATTR_UNLESS, unlessValue, false); ! classes = ! flattenStringList((List) sfResolve(ATTR_CLASSES, ! classes, ! false), ! ATTR_CLASSES); //package attribute names a package ! packageValue = sfResolve(ATTR_PACKAGE, packageValue, false); ! if (packageValue == null) { ! packageValue = ""; } else { //add a dot at the end if we need it ! if (packageValue.length() > 0 && ! packageValue.charAt(packageValue.length() - 1) != '.') { ! packageValue = packageValue + '.'; } } buildClassList(); try { ! hostname = java.net.InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { ! hostname = "localhost"; } //name ! suitename = sfResolve(ATTR_NAME, (String) null, true); ! log("Running test suite " + suitename + " on host " + hostname); } /** ! * build the list of classes to run. At this point the list is already ! * flat. */ protected void buildClassList() { testClasses = new HashMap(); ! Iterator it = classes.iterator(); while (it.hasNext()) { String testclass = (String) it.next(); *************** *** 181,191 **** /** * add a test to the list , prepending the package * @param classname */ private void addTest(String classname) { ! String fullname=packageValue+classname; ! if(testClasses.get(fullname)==null) { ! log.debug("adding test "+ fullname); testClasses.put(fullname, fullname); } --- 188,199 ---- /** * add a test to the list , prepending the package + * * @param classname */ private void addTest(String classname) { ! String fullname = packageValue + classname; ! if (testClasses.get(fullname) == null) { ! log.debug("adding test " + fullname); testClasses.put(fullname, fullname); } *************** *** 193,198 **** /** ! * flatten a string list, validating type as we go. recurses as much as we need to. ! * At its most efficient if no flattening is needed. * @param src * @param name --- 201,207 ---- /** ! * flatten a string list, validating type as we go. recurses as much as we ! * need to. At its most efficient if no flattening is needed. ! * * @param src * @param name *************** *** 200,210 **** * @throws SmartFrogInitException */ ! private List flattenStringList(final List src,String name) throws SmartFrogInitException { ! List dest=new ArrayList(src.size()); Iterator index = src.iterator(); while (index.hasNext()) { Object element = (Object) index.next(); if (element instanceof List) { ! dest.addAll(flattenStringList((List)element,name)); } else if (!(element instanceof String)) { throw new SmartFrogInitException("An element in " --- 209,220 ---- * @throws SmartFrogInitException */ ! private List flattenStringList(final List src, String name) ! throws SmartFrogInitException { ! List dest = new ArrayList(src.size()); Iterator index = src.iterator(); while (index.hasNext()) { Object element = (Object) index.next(); if (element instanceof List) { ! dest.addAll(flattenStringList((List) element, name)); } else if (!(element instanceof String)) { throw new SmartFrogInitException("An element in " *************** *** 216,242 **** } /** ! * run the test ! * bail out if we were interrupted. * @return true iff all tests passed * @throws java.rmi.RemoteException */ public boolean runTests() throws RemoteException, SmartFrogException { ! if(configuration==null || getListener()==null) { ! throw new SmartFrogException("TestSuite has not been configured yet"); } ! if(!getIf() || getUnless()) { ! log.debug("Skipping test as conditions preclude it"); return true; } //bind to our listener ! listener=configuration.getListenerFactory().listen(hostname,suitename,System.currentTimeMillis()); //now run all the tests try { ! boolean failed=false; ! Iterator it= testClasses.keySet().iterator(); while (it.hasNext()) { String classname = (String) it.next(); --- 226,261 ---- } + private void log(String message) { + log.info(message); + } + /** ! * run the test bail out if we were interrupted. ! * * @return true iff all tests passed * @throws java.rmi.RemoteException */ public boolean runTests() throws RemoteException, SmartFrogException { ! if (configuration == null || getListener() == null) { ! throw new SmartFrogException( ! "TestSuite has not been configured yet"); } ! ! if (!getIf() || getUnless()) { ! log("Skipping test as conditions preclude it"); return true; } //bind to our listener ! listener = ! configuration.getListenerFactory().listen(hostname, ! suitename, ! System.currentTimeMillis()); //now run all the tests try { ! boolean failed = false; ! Iterator it = testClasses.keySet().iterator(); while (it.hasNext()) { String classname = (String) it.next(); *************** *** 251,255 **** throw SmartFrogException.forward(e); } ! if(Thread.currentThread().isInterrupted()) { log.debug("Interrupted test thread"); return false; --- 270,274 ---- throw SmartFrogException.forward(e); } ! if (Thread.currentThread().isInterrupted()) { log.debug("Interrupted test thread"); return false; *************** *** 257,261 **** updateResultAttributes(true); failed = !stats.isSuccessful(); ! if(failed && !configuration.getKeepGoing()) { return false; } --- 276,280 ---- updateResultAttributes(true); failed = !stats.isSuccessful(); ! if (failed && !configuration.getKeepGoing()) { return false; } *************** *** 274,286 **** /** ! * write all our state to the results ! * order it so that we set the finished last */ ! private void updateResultAttributes(boolean finished) throws SmartFrogRuntimeException, RemoteException { ! stats.updateResultAttributes(this,finished); } /** * test a single class * @param classname * @throws ClassNotFoundException --- 293,307 ---- /** ! * write all our state to the results order it so that we set the finished ! * last */ ! private void updateResultAttributes(boolean finished) ! throws SmartFrogRuntimeException, RemoteException { ! stats.updateResultAttributes(this, finished); } /** * test a single class + * * @param classname * @throws ClassNotFoundException *************** *** 288,298 **** * @throws InvocationTargetException */ ! private void testSingleClass(String classname) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException { ! log.debug("testing "+classname); Test tests; ! Class clazz=loadTestClass(classname); ! tests=extractTest(clazz); ! TestResult result=new TestResult(); result.addListener(this); tests.run(result); --- 309,320 ---- * @throws InvocationTargetException */ ! private void testSingleClass(String classname) ! throws ClassNotFoundException, IllegalAccessException, InvocationTargetException { ! log("testing " + classname); Test tests; ! Class clazz = loadTestClass(classname); ! tests = extractTest(clazz); ! TestResult result = new TestResult(); result.addListener(this); tests.run(result); *************** *** 307,313 **** * @throws ClassNotFoundException */ ! private Class loadTestClass(String classname) throws ClassNotFoundException { //Class.forName(classname); ! Class clazz=SFClassLoader.forName(classname); return clazz; } --- 329,336 ---- * @throws ClassNotFoundException */ ! private Class loadTestClass(String classname) ! throws ClassNotFoundException { //Class.forName(classname); ! Class clazz = SFClassLoader.forName(classname); return clazz; } *************** *** 315,318 **** --- 338,342 ---- /** * get the tests from the class, either as a suite or as introspected tests + * * @param clazz * @return the test *************** *** 320,324 **** * @throws InvocationTargetException */ ! private Test extractTest(Class clazz) throws IllegalAccessException, InvocationTargetException { //todo: verify that the class implements test or testsuite try { --- 344,349 ---- * @throws InvocationTargetException */ ! private Test extractTest(Class clazz) throws IllegalAccessException, ! InvocationTargetException { //todo: verify that the class implements test or testsuite try { *************** *** 334,337 **** --- 359,363 ---- /** * get our listener + * * @return */ *************** *** 345,349 **** public void addError(Test test, Throwable throwable) { stats.incErrors(); ! TestInfo info=new TestInfo(test,throwable); try { getListener().addError(info); --- 371,375 ---- public void addError(Test test, Throwable throwable) { stats.incErrors(); ! TestInfo info = new TestInfo(test, throwable); try { getListener().addError(info); *************** *** 357,364 **** /** * ignore a remote fault by logging it * @param e */ private void IgnoreRemoteFault(Exception e) { ! log.warn("ignoring",e); } --- 383,391 ---- /** * ignore a remote fault by logging it + * * @param e */ private void IgnoreRemoteFault(Exception e) { ! log.warn("ignoring", e); } |