[jboss-cvs] JBossAS SVN: r59424 - in branches/Branch_4_2/testsuite/src: main/org/jboss/test/classloader main/org/jboss/test/classloader/leak main/org/jboss/test/classloader/leak/clstore main/org/jboss/test/classloader/leak/ejb main/org/jboss/test/classloader/leak/ejb/bean main/org/jboss/test/classloader/leak/ejb/interfaces main/org/jboss/test/classloader/leak/test main/org/jboss/test/classloader/leak/web resources/classloader resources/classloader/leak resources/classloader/leak/ear resources/classloader/leak/ear/META-INF resources/classloader/leak/ejb resources/classloader/leak/ejb/META-INF resources/classloader/leak/sar resources/classloader/leak/sar/META-INF resources/classloader/leak/war resources/classloader/leak/war/WEB-INF

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 8 18:29:28 EST 2007


Author: bstansberry at jboss.com
Date: 2007-01-08 18:29:24 -0500 (Mon, 08 Jan 2007)
New Revision: 59424

Added:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderStore.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTracker.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTrackerMBean.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/bean/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/bean/StatelessSessionBean.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSession.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSessionHome.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/test/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTest.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/ClassloaderLeakContextListener.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/EjbServlet.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleServlet.java
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-dual.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-nolink.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-noweb.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/jboss-app.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/MANIFEST.MF
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/ejb-jar.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/sar/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/sar/META-INF/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/sar/META-INF/jboss-service.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/jboss-web.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web-simple.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web.xml
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/ejb.jsp
   branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/simple.jsp
Log:
[JBAS-3971] Add basic classloader leak test

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderStore.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderStore.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderStore.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,174 @@
+/*
+ * 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.classloader.leak.clstore;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.profiler.jvmti.JVMTIInterface;
+
+public class ClassLoaderStore
+{
+   private static final Logger log = Logger.getLogger(ClassLoaderStore.class);
+   
+   private static ClassLoaderStore instance = new ClassLoaderStore();
+   
+   private final Map classloaders = new HashMap();
+   private ClassLoaderStore()
+   {
+      
+   }
+   
+   public static ClassLoaderStore getInstance()
+   {
+      return instance;
+   }
+   
+   public void storeClassLoader(String key, ClassLoader loader)
+   {
+      log.debug("Storing " + loader + " under " + key);
+      ClassLoader parent = loader.getParent();
+      while (parent != null)
+      {
+         System.out.println("Parent is " + parent);
+         parent = parent.getParent();
+      }
+      WeakReference ref = new WeakReference(loader);
+      classloaders.put(key, ref);
+   }
+   
+   public ClassLoader getClassLoader(String key, boolean forceGC, String reportFile)
+   {
+      ClassLoader result = null;
+      WeakReference ref = (WeakReference) classloaders.get(key);
+      if (ref != null)
+      {
+         result = (ClassLoader) ref.get();
+         if (result != null && forceGC)
+         {
+            try
+            {
+               result = null; // Don't hold a ref to it here while analyzing heap
+               result = getClassLoader(ref, reportFile);
+            }
+            catch (Exception e)
+            {
+               log.error("Caught exception checking for classloader release", e);
+            }
+         }
+      }
+      
+      return result;
+   }
+   
+
+   /**
+    * If you started your class with -agentlib:jbossAgent in case of leakage (if className still loaded) a file (reportFile) will be created, and a heapSnapshot(./snapshot,mem)
+    * 
+    * @param weakReferenceOnLoader A weakReference to the created ClassLoader. If there is no references to this classLoader this reference will be cleared
+    * @param className The class name supposed to be unloade.
+    * @param reportHTMLFile the report file 
+    * @throws Exception
+    */
+   private ClassLoader getClassLoader(WeakReference weakReferenceOnLoader, String reportHTMLFile) throws Exception
+   {
+      JVMTIInterface jvmti = new JVMTIInterface();
+      if (jvmti.isActive())
+      {
+         jvmti.forceGC();
+         
+         if (weakReferenceOnLoader.get() == null)
+         {
+            return null;
+         }
+         
+         fillMemory(weakReferenceOnLoader);
+         
+         if (weakReferenceOnLoader.get() == null)
+         {
+            return null;
+         }
+         
+         jvmti.heapSnapshot("snapshot", "mem");
+            
+         HashMap datapoints = jvmti.createIndexMatrix();
+         
+         String report = jvmti.exploreObjectReferences(datapoints, weakReferenceOnLoader.get(), 18, true);
+         log.info(report);
+         if (reportHTMLFile != null)
+         {
+            File outputfile = new File(reportHTMLFile);
+            FileOutputStream outfile = new FileOutputStream(outputfile);
+            PrintStream realoutput = new PrintStream(outfile);
+            realoutput.println(report);
+            realoutput.close();
+         }
+         
+         
+         jvmti.forceGC();
+      }
+      else
+      {
+         log.debug("JVMTI not active; using System.gc()");
+         System.gc();
+         Thread.sleep(1000);
+         
+         if (weakReferenceOnLoader.get() != null)
+            fillMemory(weakReferenceOnLoader);
+      }
+      
+      return (ClassLoader) weakReferenceOnLoader.get();
+   }
+   
+   private void fillMemory(WeakReference ref)
+   {
+      int bytz = 2 * 1024;
+      while(true) {
+          System.gc();
+          
+          if (ref.get() == null)
+             break;
+          
+          // create garbage:
+          try
+          {
+             byte[] b =  new byte[bytz];
+             bytz = bytz * 2;
+          }
+          catch (Throwable t)
+          {
+             System.gc();
+             break;
+          }
+      }      
+   }
+   
+   public void removeClassLoader(String key)
+   {
+      classloaders.remove(key);
+   }
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTracker.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTracker.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTracker.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,66 @@
+/*
+ * 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.classloader.leak.clstore;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.plugins.JaasSecurityManagerServiceMBean;
+
+public class ClassLoaderTracker implements ClassLoaderTrackerMBean
+{
+   private static final Logger log = Logger.getLogger(ClassLoaderTracker.class);
+   
+   private ClassLoaderStore store = ClassLoaderStore.getInstance();
+   private JaasSecurityManagerServiceMBean securityManagerService;
+   
+   public boolean hasClassLoader(String key)
+   {
+      System.gc();
+      return (store.getClassLoader(key, false, null) != null);
+   }
+   
+   public boolean hasClassLoaderBeenReleased(String key)
+   {
+      return (store.getClassLoader(key, true, null) == null);
+   }
+
+   public void removeClassLoader(String key)
+   {
+      store.removeClassLoader(key);
+   }
+
+   public JaasSecurityManagerServiceMBean getSecurityManagerService()
+   {
+      return securityManagerService;
+   }
+
+   public void setSecurityManagerService(JaasSecurityManagerServiceMBean securityManagerService)
+   {
+      this.securityManagerService = securityManagerService;
+   }
+   
+   public void flushSecurityCache(String securityDomain)
+   {
+      log.debug("Flushing security domain " + securityDomain);
+      this.securityManagerService.flushAuthenticationCache(securityDomain);
+   }
+
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTrackerMBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTrackerMBean.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/clstore/ClassLoaderTrackerMBean.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,42 @@
+/*
+ * 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.classloader.leak.clstore;
+
+import org.jboss.security.plugins.JaasSecurityManagerServiceMBean;
+
+
+public interface ClassLoaderTrackerMBean
+{
+   public static final String OBJECT_NAME = "jboss.test:service=ClassLoaderTracker";
+   
+   public boolean hasClassLoader(String key);
+   
+   public boolean hasClassLoaderBeenReleased(String key);
+   
+   public void removeClassLoader(String key);
+   
+   public JaasSecurityManagerServiceMBean getSecurityManagerService();
+   
+   public void setSecurityManagerService(JaasSecurityManagerServiceMBean svc);
+
+   public void flushSecurityCache(String securityDomain);
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/bean/StatelessSessionBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/bean/StatelessSessionBean.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/bean/StatelessSessionBean.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,75 @@
+/*
+ * 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.classloader.leak.ejb.bean;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Brian Stansberry
+ */
+public class StatelessSessionBean implements SessionBean
+{
+   private static final long serialVersionUID = 1L;
+   
+   private SessionContext sessionContext;
+
+   public void ejbCreate() throws RemoteException, CreateException
+   {
+//      
+      org.jboss.test.classloader.leak.clstore.ClassLoaderStore.getInstance().storeClassLoader("EJB", StatelessSessionBean.class.getClassLoader());
+   }
+
+   public void ejbActivate() throws RemoteException
+   {
+      
+   }
+
+   public void ejbPassivate() throws RemoteException
+   {
+      
+   }
+
+   public void ejbRemove() throws RemoteException
+   {
+      
+   }
+
+   public void setSessionContext(SessionContext context) throws RemoteException
+   {
+      sessionContext = context;
+   }
+
+   public void log(String category)
+   {
+      Log log = LogFactory.getLog(category);
+      log.fatal("Logging for " + category);  
+      org.jboss.test.classloader.leak.clstore.ClassLoaderStore.getInstance().storeClassLoader("EJB", Thread.currentThread().getContextClassLoader());
+   }
+
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSession.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSession.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSession.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,34 @@
+/*
+ * 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.classloader.leak.ejb.interfaces;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBObject;
+
+/**
+ * @author Brian Stansberry
+ */
+public interface StatelessSession extends EJBObject {
+
+  public void log(String category) throws RemoteException;;
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSessionHome.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSessionHome.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/ejb/interfaces/StatelessSessionHome.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,33 @@
+/*
+ * 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.classloader.leak.ejb.interfaces;
+
+import javax.ejb.*;
+import java.rmi.*;
+
+/**
+ * @author Marc Fleury
+ */
+public interface StatelessSessionHome extends EJBHome {
+
+  public StatelessSession create() throws java.rmi.RemoteException, javax.ejb.CreateException;
+} 

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTest.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTest.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTest.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,348 @@
+/*
+ * 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.classloader.leak.test;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.classloader.leak.clstore.ClassLoaderTrackerMBean;
+import org.jboss.test.classloader.leak.ejb.interfaces.StatelessSession;
+import org.jboss.test.classloader.leak.ejb.interfaces.StatelessSessionHome;
+
+/**
+ * Test for classloader leaks following deployment, use and undeployment
+ * of various packages (wars, ejb jars and ears with and without scoped
+ * classloaders).
+ * <p/>
+ * These tests were originally written to test for leaks caused by Jakarta 
+ * Commons Logging.  As a result, there are various permutations of the tests
+ * that store copies of commons-logging in different locations on the classpath.
+ * <p/>
+ * If these test are run with JBoss Profiler's jbossAgent (.dll or .so) on the path
+ * and the AS is started with -agentlib:jbossAgent, in case of classloader leakage
+ * an extensive report will be logged to the server log, showing the path to root of
+ * all references to the classloader.
+ * 
+ * @author Brian Stansberry
+ */
+public class ClassloaderLeakTest extends JBossTestCase
+{
+   private static final String SIMPLE_WAR = "classloader-leak-simple.war";
+   private static final String WAR_WITH_JCL = "classloader-leak-in-war.war";
+   private static final String SIMPLE_EJB = "classloader-leak-ejb.jar"; 
+   private static final String SIMPLE_EAR = "classloader-leak-simple.ear"; 
+   private static final String EAR_WITH_JCL = "classloader-leak-in-ear.ear";
+   private static final String SIMPLE_ISOLATED_EAR = "classloader-leak-simple-isolated.ear";
+   private static final String ISOLATED_EAR_WITH_JCL = "classloader-leak-in-ear-isolated.ear";
+   private static final String EAR_WITH_DUAL_JCL = "classloader-leak-dual.ear";
+   private static final String ISOLATED_EAR_WITH_DUAL_JCL = "classloader-leak-dual-isolated.ear";
+   private static final String NO_WEB_EAR = "classloader-leak-noweb.ear";
+   private static final String ISOLATED_NO_WEB_EAR = "classloader-leak-noweb-isolated.ear";
+   
+   private static final String WEBAPP = "WEBAPP";
+   private static final String EJB = "EJB";
+   
+   private static final Set deployments = new HashSet();
+   
+   private String baseURL = null;
+
+   public ClassloaderLeakTest(String name)
+   {
+      super(name);
+   }
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      cleanDeployments();
+      
+      removeClassLoader(WEBAPP);
+      removeClassLoader(EJB);
+      
+      baseURL = "http://" + getServerHost() + ":8080/classloader-leak/";
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      cleanDeployments();
+      
+      removeClassLoader(WEBAPP);
+      removeClassLoader(EJB);
+      
+      super.tearDown();
+   }
+   
+   private void cleanDeployments() throws Exception
+   {
+      Iterator it = deployments.iterator();
+      while (it.hasNext())
+      {
+         undeploy((String) it.next(), false);
+         it = deployments.iterator();
+      }
+   }
+   
+   private void undeploy(String deployment, boolean propagateFailure)
+         throws Exception
+   {
+      try
+      {
+         undeploy(deployment);
+         deployments.remove(deployment);
+      }
+      catch (Exception e)
+      {
+         if (propagateFailure)
+            throw e;
+         else
+            log.error("Exception during undeploy of " + deployment, e);
+      }
+   }
+   
+   private void deployJCLUser(String deployment) throws Exception
+   {
+      deploy(deployment);
+      deployments.add(deployment);
+   }
+   
+   public void testSimpleWar() throws Exception
+   {
+      warTest(SIMPLE_WAR, true);
+   }
+   
+   public void testWarWithJcl() throws Exception
+   {
+      warTest(WAR_WITH_JCL, true);
+   }
+   
+   public void testSimpleEjb() throws Exception
+   {
+      ejbTest(SIMPLE_EJB);
+   }
+   
+   public void testSimpleEar() throws Exception
+   {
+      earTest(SIMPLE_EAR);
+   }
+   
+   public void testEarWithJcl() throws Exception
+   {
+      earTest(EAR_WITH_JCL);
+   }
+   
+   public void testNoWebEar() throws Exception
+   {
+      ejbTest(NO_WEB_EAR);
+   }
+   
+   public void testSimpleIsolatedEar() throws Exception
+   {
+      earTest(SIMPLE_ISOLATED_EAR);
+   }
+   
+   public void testIsolatedNoWebEar() throws Exception
+   {
+      ejbTest(ISOLATED_NO_WEB_EAR);
+   }
+   
+   public void testIsolatedEarWithJcl() throws Exception
+   {
+      earTest(ISOLATED_EAR_WITH_JCL);
+   }
+   
+   public void testEarWithDualJcl() throws Exception
+   {
+      earTest(EAR_WITH_DUAL_JCL);
+   }
+   
+   public void testIsolatedEarWithDualJcl() throws Exception
+   {
+      earTest(ISOLATED_EAR_WITH_DUAL_JCL);
+   }
+   
+   private void warTest(String deployment, boolean makeRequest) throws Exception
+   {
+      if (hasClassLoader(WEBAPP))
+         throw new IllegalStateException("Classloader already registered for " + WEBAPP);
+      
+      deployJCLUser(deployment);
+      
+
+      if (makeRequest)
+      {
+         makeWebRequest(baseURL + "SimpleServlet", WEBAPP);
+         makeWebRequest(baseURL + "simple.jsp", WEBAPP);
+      }
+      
+      assertTrue("WEBAPP classloader registered", hasClassLoader(WEBAPP));
+      
+      undeploy(deployment, true);
+      
+      flushSecurityCache("HsqlDbRealm");
+      
+      sleep(500);
+      
+      assertTrue("WEBAPP classloader unregistered", hasClassLoaderBeenReleased(WEBAPP));
+   }
+   
+   private void ejbTest(String deployment) throws Exception
+   {
+      if (hasClassLoader(EJB))
+         throw new IllegalStateException("Classloader already registered for " + WEBAPP);
+      
+      deployJCLUser(deployment);
+      
+      makeEjbRequest();
+      
+      assertTrue("EJB classloader registered", hasClassLoader(EJB));
+      
+      undeploy(deployment, true);
+      
+      flushSecurityCache("HsqlDbRealm");
+      
+      sleep(500);
+      
+      assertTrue("WEBAPP classloader unregistered", hasClassLoaderBeenReleased(WEBAPP));
+   }
+   
+   private void earTest(String deployment) throws Exception
+   {
+      if (hasClassLoader(WEBAPP))
+         throw new IllegalStateException("Classloader already registered for " + WEBAPP);
+      
+      if (hasClassLoader(EJB))
+         throw new IllegalStateException("Classloader already registered for " + EJB);
+      
+      deployJCLUser(deployment);
+      
+      makeWebRequest(baseURL + "simple.jsp", WEBAPP);
+      makeWebRequest(baseURL + "SimpleServlet", WEBAPP);
+      
+      assertTrue("WEBAPP classloader registered", hasClassLoader(WEBAPP));
+      
+      makeWebRequest(baseURL + "ejb.jsp", EJB);
+      makeWebRequest(baseURL + "EJBServlet", EJB);
+      
+      makeEjbRequest();
+      
+      assertTrue("EJB classloader registered", hasClassLoader(EJB));
+         
+      undeploy(deployment, true);
+      
+      flushSecurityCache("HsqlDbRealm");
+      
+      sleep(500);
+
+      if (!hasClassLoaderBeenReleased(WEBAPP))
+      {
+         if (!hasClassLoaderBeenReleased(EJB))
+            fail("Both EJB and WEBAPP classloaders unregistered");
+         fail("WEBAPP classloader unregistered");
+      }
+      assertTrue("EJB classloader unregistered", hasClassLoaderBeenReleased(EJB));
+      
+   }
+   
+   private boolean hasClassLoader(String key) throws Exception
+   {
+      MBeanServerConnection adaptor = delegate.getServer();
+      ObjectName on = new ObjectName(ClassLoaderTrackerMBean.OBJECT_NAME);
+      Object[] params = { key };
+      String[] signature = new String[] { String.class.getName() };
+      return ((Boolean) adaptor.invoke(on, "hasClassLoader", params, signature)).booleanValue();
+   }
+   
+   private boolean hasClassLoaderBeenReleased(String key) throws Exception
+   {
+      MBeanServerConnection adaptor = delegate.getServer();
+      ObjectName on = new ObjectName(ClassLoaderTrackerMBean.OBJECT_NAME);
+      Object[] params = { key };
+      String[] signature = new String[] { String.class.getName() };
+      return ((Boolean) adaptor.invoke(on, "hasClassLoaderBeenReleased", params, signature)).booleanValue();
+   }
+   
+   private void removeClassLoader(String key) throws Exception
+   {
+      MBeanServerConnection adaptor = delegate.getServer();
+      ObjectName on = new ObjectName(ClassLoaderTrackerMBean.OBJECT_NAME);
+      Object[] params = { key };
+      String[] signature = new String[] { String.class.getName() };
+      adaptor.invoke(on, "removeClassLoader", params, signature);
+   }
+   
+   private void flushSecurityCache(String domain) throws Exception
+   {
+      log.debug("Flushing security cache " + domain);
+      MBeanServerConnection adaptor = delegate.getServer();
+      ObjectName on = new ObjectName(ClassLoaderTrackerMBean.OBJECT_NAME);
+      Object[] params = { domain };
+      String[] signature = new String[] { String.class.getName() };
+      adaptor.invoke(on, "flushSecurityCache", params, signature);
+   }
+   
+   private void makeWebRequest(String url, String responseContent)
+   {
+      HttpClient client = new HttpClient();
+      GetMethod method = new GetMethod(url);
+      int responseCode = 0;
+      try
+      {
+         responseCode = client.executeMethod(method);
+         
+         assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
+               , responseCode == HttpURLConnection.HTTP_OK);
+         
+         String rsp = new String(method.getResponseBody());
+         
+         assertTrue("Response contains " + responseContent, rsp.indexOf(responseContent) >= 0);
+      } catch (IOException e)
+      {
+         e.printStackTrace();
+         fail("HttpClient executeMethod fails." +e.toString());
+      }
+   }
+   
+   private void makeEjbRequest() throws Exception
+   {
+      InitialContext ctx = this.getInitialContext();
+      StatelessSessionHome home = (StatelessSessionHome) ctx.lookup("ClassloaderLeakStatelessSession");
+      StatelessSession bean = home.create();
+      bean.log("EJB");
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ClassloaderLeakTest.class, "classloader-leak-test.sar");
+   }
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/ClassloaderLeakContextListener.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/ClassloaderLeakContextListener.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/ClassloaderLeakContextListener.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.jboss.test.classloader.leak.web;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.commons.logging.LogFactory;
+
+public class ClassloaderLeakContextListener implements ServletContextListener
+{
+   private Class[] RELEASE_SIGNATURE = {ClassLoader.class};
+   
+   public void contextDestroyed(ServletContextEvent arg0)
+   {
+      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+
+      Object[] params = new Object[1];
+      params[0] = tccl;
+
+      // Walk up the tree of classloaders, finding all the available
+      // LogFactory classes and releasing any objects associated with
+      // the tccl (ie the webapp).
+      //
+      // When there is only one LogFactory in the classpath, and it
+      // is within the webapp being undeployed then there is no problem;
+      // garbage collection works fine.
+      //
+      // When there are multiple LogFactory classes in the classpath but
+      // parent-first classloading is used everywhere, this loop is really
+      // short. The first instance of LogFactory found will
+      // be the highest in the classpath, and then no more will be found.
+      // This is ok, as with this setup this will be the only LogFactory
+      // holding any data associated with the tccl being released.
+      //
+      // When there are multiple LogFactory classes in the classpath and
+      // child-first classloading is used in any classloader, then multiple
+      // LogFactory instances may hold info about this TCCL; whenever the
+      // webapp makes a call into a class loaded via an ancestor classloader
+      // and that class calls LogFactory the tccl gets registered in
+      // the LogFactory instance that is visible from the ancestor
+      // classloader. However the concrete logging library it points
+      // to is expected to have been loaded via the TCCL, so the 
+      // underlying logging lib is only initialised/configured once.
+      // These references from ancestor LogFactory classes down to
+      // TCCL classloaders are held via weak references and so should
+      // be released but there are circumstances where they may not.
+      // Walking up the classloader ancestry ladder releasing
+      // the current tccl at each level tree, though, will definitely
+      // clear any problem references.
+//      ClassLoader loader = tccl;
+//      while (loader != null) {
+//          // Load via the current loader. Note that if the class is not accessable
+//          // via this loader, but is accessable via some ancestor then that class
+//          // will be returned.
+//          try {
+//              System.out.println("Calling LogFactory.release() for " + loader);
+//              Class logFactoryClass = loader.loadClass("org.apache.commons.logging.LogFactory");
+//              Method releaseMethod = logFactoryClass.getMethod("release", RELEASE_SIGNATURE);
+//              releaseMethod.invoke(null, params);
+//              loader = logFactoryClass.getClassLoader().getParent();
+//          } catch(ClassNotFoundException ex) {
+//              // Neither the current classloader nor any of its ancestors could find
+//              // the LogFactory class, so we can stop now.
+//              loader = null;
+//          } catch(NoSuchMethodException ex) {
+//              // This is not expected; every version of JCL has this method
+//              System.err.println("LogFactory instance found which does not support release method!");
+//              loader = null;
+//          } catch(IllegalAccessException ex) {
+//              // This is not expected; every ancestor class should be accessable
+//              System.err.println("LogFactory instance found which is not accessable!");
+//              loader = null;
+//          } catch(InvocationTargetException ex) {
+//              // This is not expected
+//              System.err.println("LogFactory instance release method failed!");
+//              loader = null;
+//          }
+//      }
+//      
+//      // Just to be sure, invoke release on the LogFactory that is visible from
+//      // this ServletContextCleaner class too. This should already have been caught
+//      // by the above loop but just in case...
+//      LogFactory.release(tccl);
+   }
+
+   public void contextInitialized(ServletContextEvent arg0)
+   {
+      org.jboss.test.classloader.leak.clstore.ClassLoaderStore.getInstance().storeClassLoader("WEBAPP", ClassloaderLeakContextListener.class.getClassLoader());
+   }
+
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/EjbServlet.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/EjbServlet.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/EjbServlet.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,58 @@
+/*
+ * 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.classloader.leak.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.naming.InitialContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.test.classloader.leak.ejb.interfaces.StatelessSession;
+import org.jboss.test.classloader.leak.ejb.interfaces.StatelessSessionHome;
+
+public class EjbServlet extends HttpServlet
+{
+   private static final long serialVersionUID = 1L;
+
+   protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException
+   {
+      try
+      {
+          InitialContext ctx = new InitialContext();
+          StatelessSessionHome home = (StatelessSessionHome) ctx.lookup("java:comp/env/ejb/ClassloaderLeakEJB");
+          StatelessSession bean = home.create();
+          bean.log("EJB");
+      }
+      catch (Exception e)
+      {
+          throw new javax.servlet.ServletException(e);
+      }
+      PrintWriter writer = arg1.getWriter();
+      writer.println("EJB");
+      writer.flush();
+   }
+   
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleServlet.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleServlet.java	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleServlet.java	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,48 @@
+/*
+ * 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.classloader.leak.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SimpleServlet extends HttpServlet
+{
+   private static final long serialVersionUID = 1L;
+
+   protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException
+   {
+      Log log = LogFactory.getLog("WEBAPP");
+      log.info("WEBAPP is here");
+      PrintWriter writer = arg1.getWriter();
+      writer.println("WEBAPP");
+      writer.flush();
+   }
+   
+}

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-dual.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-dual.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-dual.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<application version="1.4"
+             xmlns="http://java.sun.com/xml/ns/j2ee" 
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
+                                 http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
+>
+
+   <module>
+      <web>
+         <web-uri>classloader-leak-in-war-ejb.war</web-uri>
+         <context-root>/classloader-leak</context-root>
+      </web>
+    </module>
+    <module>
+        <ejb>classloader-leak-ejb.jar</ejb>
+    </module>
+
+</application>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-nolink.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-nolink.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-nolink.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<application version="1.4"
+             xmlns="http://java.sun.com/xml/ns/j2ee" 
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
+                                 http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
+>
+
+   <module>
+      <web>
+         <web-uri>classloader-leak-simple.war</web-uri>
+         <context-root>/classloader-leak</context-root>
+      </web>
+    </module>
+    <module>
+        <ejb>classloader-leak-ejb.jar</ejb>
+    </module>
+
+</application>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-noweb.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-noweb.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application-noweb.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<application version="1.4"
+             xmlns="http://java.sun.com/xml/ns/j2ee" 
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
+                                 http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
+>
+
+   <module>
+        <ejb>classloader-leak-ejb.jar</ejb>
+    </module>
+
+</application>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/application.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<application version="1.4"
+             xmlns="http://java.sun.com/xml/ns/j2ee" 
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
+                                 http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
+>
+
+   <module>
+      <web>
+         <web-uri>classloader-leak-simple-ejb.war</web-uri>
+         <context-root>/classloader-leak</context-root>
+      </web>
+    </module>
+    <module>
+        <ejb>classloader-leak-ejb.jar</ejb>
+    </module>
+
+</application>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/jboss-app.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/jboss-app.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ear/META-INF/jboss-app.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!DOCTYPE jboss-app
+  PUBLIC  "-//JBoss//DTD J2EE Application 1.4//EN"
+          "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd"
+>
+
+<jboss-app>
+
+    <loader-repository>jboss.test:loader=isolated.ear
+      <loader-repository-config>
+         java2ParentDelegation=false
+      </loader-repository-config>
+    </loader-repository>
+   
+</jboss-app>

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/MANIFEST.MF
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/MANIFEST.MF	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/MANIFEST.MF	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Ant-Version: Apache Ant 1.6.5
+Created-By: 1.4.2_10-b03 (Sun Microsystems Inc.)
+Class-Path: lib/commons-logging.jar
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/ejb-jar.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/ejb/META-INF/ejb-jar.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" 
+                         "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+<ejb-jar>
+    
+    <enterprise-beans>
+        
+       <session>
+            <ejb-name>ClassloaderLeakStatelessSession</ejb-name>
+            <home>org.jboss.test.classloader.leak.ejb.interfaces.StatelessSessionHome</home>
+            <remote>org.jboss.test.classloader.leak.ejb.interfaces.StatelessSession</remote>
+            <ejb-class>org.jboss.test.classloader.leak.ejb.bean.StatelessSessionBean</ejb-class>
+            <session-type>Stateless</session-type>
+            <transaction-type>Container</transaction-type>
+        </session>
+        
+    </enterprise-beans>
+    
+</ejb-jar>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/sar/META-INF/jboss-service.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/sar/META-INF/jboss-service.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/sar/META-INF/jboss-service.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+   <mbean code="org.jboss.test.classloader.leak.clstore.ClassLoaderTracker"
+          name="jboss.test:service=ClassLoaderTracker">
+          
+       <depends optional-attribute-name="SecurityManagerService"
+         proxy-type="attribute">jboss.security:service=JaasSecurityManager</depends>
+   </mbean>
+</server>

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/jboss-web.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/jboss-web.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/jboss-web.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,3 @@
+<jboss-web>
+   <context-root>/classloader-leak</context-root>
+</jboss-web>

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web-simple.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web-simple.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web-simple.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC
+   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+   "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+  <!-- Registers an mbean the test driver can use to check the cache state -->
+  <listener>
+  	<listener-class>org.jboss.test.classloader.leak.web.ClassloaderLeakContextListener</listener-class>
+  </listener>
+
+   <servlet>
+      <servlet-name>SimpleServlet</servlet-name>
+      <servlet-class>org.jboss.test.classloader.leak.web.SimpleServlet</servlet-class>
+   </servlet>
+
+   <servlet-mapping>
+      <servlet-name>SimpleServlet</servlet-name>
+      <url-pattern>/SimpleServlet</url-pattern>
+   </servlet-mapping>
+   
+</web-app>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web.xml	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/WEB-INF/web.xml	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC
+   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+   "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+  <!-- Registers an mbean the test driver can use to check the cache state -->
+  <listener>
+  	<listener-class>org.jboss.test.classloader.leak.web.ClassloaderLeakContextListener</listener-class>
+  </listener>
+
+   <servlet>
+      <servlet-name>SimpleServlet</servlet-name>
+      <servlet-class>org.jboss.test.classloader.leak.web.SimpleServlet</servlet-class>
+   </servlet>
+   
+   <servlet>
+      <servlet-name>EJBServlet</servlet-name>
+      <servlet-class>org.jboss.test.classloader.leak.web.EjbServlet</servlet-class>
+   </servlet>
+
+   <servlet-mapping>
+      <servlet-name>SimpleServlet</servlet-name>
+      <url-pattern>/SimpleServlet</url-pattern>
+   </servlet-mapping>
+
+   <servlet-mapping>
+      <servlet-name>EJBServlet</servlet-name>
+      <url-pattern>/EJBServlet</url-pattern>
+   </servlet-mapping>
+      
+   <ejb-ref>
+       <ejb-ref-name>ejb/ClassloaderLeakEJB</ejb-ref-name>
+       <ejb-ref-type>Session</ejb-ref-type>
+       <home>org.jboss.test.classloader.leak.ejb.interfaces.StatelessSessionHome</home>
+       <remote>org.jboss.test.classloader.leak.ejb.interfaces.StatelessSession</remote>
+       <ejb-link>ClassloaderLeakStatelessSession</ejb-link>
+   </ejb-ref>
+   
+</web-app>
+

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/ejb.jsp
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/ejb.jsp	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/ejb.jsp	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,17 @@
+<%@page contentType="text/html"%>
+<%@page import="javax.naming.*"%>
+<%@page import="org.jboss.test.classloader.leak.ejb.interfaces.*"%>
+<%
+  try
+  {
+      InitialContext ctx = new InitialContext();
+      StatelessSessionHome home = (StatelessSessionHome) ctx.lookup("java:comp/env/ejb/ClassloaderLeakEJB");
+      StatelessSession bean = home.create();
+      bean.log("EJB");
+  }
+  catch (Exception e)
+  {
+      throw new javax.servlet.ServletException(e);
+  }
+%>
+EJB
\ No newline at end of file

Added: branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/simple.jsp
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/simple.jsp	2007-01-08 23:26:25 UTC (rev 59423)
+++ branches/Branch_4_2/testsuite/src/resources/classloader/leak/war/simple.jsp	2007-01-08 23:29:24 UTC (rev 59424)
@@ -0,0 +1,8 @@
+<%@page contentType="text/html"%>
+<%@page import="org.apache.commons.logging.Log"%>
+<%@page import="org.apache.commons.logging.LogFactory"%>
+<%
+  Log log = LogFactory.getLog("WEBAPP");
+  log.fatal("WEBAPP is here");
+%>
+WEBAPP
\ No newline at end of file




More information about the jboss-cvs-commits mailing list