[jboss-cvs] JBossAS SVN: r101135 - in trunk/testsuite: src/main/org/jboss/test/classloader/leak/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 18 18:10:09 EST 2010


Author: dallen6
Date: 2010-02-18 18:10:09 -0500 (Thu, 18 Feb 2010)
New Revision: 101135

Added:
   trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/SimpleCdiClassloaderLeakTestCase.java
   trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiIntrospectSession.java
   trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiInvalidateSession.java
   trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleSessionBean.java
   trunk/testsuite/src/resources/classloader/leak/war/WEB-INF/beans.xml
   trunk/testsuite/src/resources/classloader/leak/war/WEB-INF/web-cdi.xml
Modified:
   trunk/testsuite/imports/sections/classloader.xml
   trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTestBase.java
Log:
Added a Weld classloader leak test

Modified: trunk/testsuite/imports/sections/classloader.xml
===================================================================
--- trunk/testsuite/imports/sections/classloader.xml	2010-02-18 21:51:40 UTC (rev 101134)
+++ trunk/testsuite/imports/sections/classloader.xml	2010-02-18 23:10:09 UTC (rev 101135)
@@ -303,11 +303,23 @@
     	<classes dir="${build.classes}">
     		<include name="org/jboss/test/classloader/leak/web/*"/>
     		<exclude name="org/jboss/test/classloader/leak/web/Ejb*"/>
+    		<exclude name="org/jboss/test/classloader/leak/web/Cdi*"/>
     	</classes>
         <fileset dir="${build.resources}/classloader/leak/war">
           <include name="simple.jsp"/>
         </fileset>
     </war>
+    <war destfile="${build.lib}/classloader-leak-simple-cdi.war"
+        webxml="${build.resources}/classloader/leak/war/WEB-INF/web-cdi.xml">
+    	<webinf dir="${build.resources}/classloader/leak/war/WEB-INF">
+    		<include name="jboss-web.xml"/>
+    		<include name="beans.xml"/>
+    	</webinf>
+    	<classes dir="${build.classes}">
+    		<include name="org/jboss/test/classloader/leak/web/Cdi*"/>
+    		<include name="org/jboss/test/classloader/leak/web/SimpleSessionBean*"/>
+    	</classes>
+    </war>
     <war destfile="${build.lib}/classloader-leak-in-war.war"
         webxml="${build.resources}/classloader/leak/war/WEB-INF/web.xml">
     	<webinf dir="${build.resources}/classloader/leak/war/WEB-INF">
@@ -316,6 +328,7 @@
     	<classes dir="${build.classes}">
     		<include name="org/jboss/test/classloader/leak/web/*"/>
     		<exclude name="org/jboss/test/classloader/leak/web/Ejb*"/>
+    		<exclude name="org/jboss/test/classloader/leak/web/Cdi*"/>
     	</classes>
         <fileset dir="${build.resources}/classloader/leak/war">
           <include name="simple.jsp"/>
@@ -340,6 +353,7 @@
     	<classes dir="${build.classes}">
     		<include name="org/jboss/test/classloader/leak/web/*"/>
     		<exclude name="org/jboss/test/classloader/leak/web/Ejb3Servlet"/>
+    		<exclude name="org/jboss/test/classloader/leak/web/Cdi*"/>
     	</classes>
         <fileset dir="${build.resources}/classloader/leak/war">
           <include name="*.jsp"/>

Modified: trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTestBase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTestBase.java	2010-02-18 21:51:40 UTC (rev 101134)
+++ trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/ClassloaderLeakTestBase.java	2010-02-18 23:10:09 UTC (rev 101135)
@@ -132,7 +132,7 @@
       }
    }
    
-   private void deployComponent(String deployment) throws Exception
+   protected void deployComponent(String deployment) throws Exception
    {
       deploy(deployment);
       deployments.add(deployment);
@@ -321,7 +321,7 @@
       }
    }
    
-   private void flushSecurityCache(String domain) throws Exception
+   protected void flushSecurityCache(String domain) throws Exception
    {
       log.debug("Flushing security cache " + domain);
       MBeanServerConnection adaptor = delegate.getServer();
@@ -331,7 +331,7 @@
       adaptor.invoke(on, "flushSecurityCache", params, signature);
    }
    
-   private void makeWebRequest(String url, String responseContent)
+   protected void makeWebRequest(String url, String responseContent)
    {
       HttpClient client = new HttpClient();
       GetMethod method = new GetMethod(url);

Added: trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/SimpleCdiClassloaderLeakTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/SimpleCdiClassloaderLeakTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/classloader/leak/test/SimpleCdiClassloaderLeakTestCase.java	2010-02-18 23:10:09 UTC (rev 101135)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.test;
+
+import junit.framework.Test;
+
+/**
+ * <p>
+ * Test for classloader leaks following deployment, use and undeployment of a
+ * simple war using Weld.
+ * <p/>
+ * <p>
+ * If these tests 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.
+ * </p>
+ * 
+ * @author David Allen
+ */
+public class SimpleCdiClassloaderLeakTestCase extends J2EEClassloaderLeakTestBase
+{
+
+   private static final String   SIMPLE_CDI_WAR = "classloader-leak-simple-cdi.war";
+   private static final String   WELD           = "WELD";
+   private static final String[] CLASS_LOADERS  = { SERVLET, SERVLET_TCCL, WELD };
+
+   public SimpleCdiClassloaderLeakTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(SimpleCdiClassloaderLeakTestCase.class, "classloader-leak-test.sar");
+   }
+
+   public void testSimpleCdiWar() throws Exception
+   {
+      // Ensure we are starting with a clean slate
+      checkCleanKeys(CLASS_LOADERS);
+
+      deployComponent(SIMPLE_CDI_WAR);
+
+      makeWebRequest(baseURL + "IntrospectCDISession", WEBAPP);
+      makeWebRequest(baseURL + "InvalidateCDISession", WEBAPP);
+
+      // Make sure the expected registrations were done
+      checkKeyRegistration(CLASS_LOADERS);
+
+      // This sleep is a workaround to JBAS-4060
+      sleep(500);
+
+      undeployComponent(SIMPLE_CDI_WAR, true);
+
+      // TODO - probably not needed anymore; remove
+      flushSecurityCache("HsqlDbRealm");
+
+      sleep(500);
+
+      // Confirm the classloaders were released
+      String unregistered = checkClassLoaderRelease(CLASS_LOADERS);
+
+      if (unregistered.trim().length() > 0)
+      {
+         fail("Classloaders unregistered: " + unregistered);
+      }
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiIntrospectSession.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiIntrospectSession.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiIntrospectSession.java	2010-02-18 23:10:09 UTC (rev 101135)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.io.IOException;
+import java.io.PrintWriter;
+
+import javax.inject.Inject;
+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;
+
+/**
+ * Registers the relevant classloaders to monitor leaks.  Uses at least a session context
+ * bean to force use of the session context and management infrastructure in Weld.
+ * 
+ * @author David Allen
+ *
+ */
+public class CdiIntrospectSession extends HttpServlet
+{
+   private static final long serialVersionUID = 1L;
+
+   @Inject
+   private SimpleSessionBean simpleSessionBean;
+
+   @Override
+   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      org.jboss.test.classloader.leak.clstore.ClassLoaderStore.getInstance().storeClassLoader("SERVLET", getClass().getClassLoader());
+      org.jboss.test.classloader.leak.clstore.ClassLoaderStore.getInstance().storeClassLoader("SERVLET_TCCL", Thread.currentThread().getContextClassLoader());
+      org.jboss.test.classloader.leak.clstore.ClassLoaderStore.getInstance().storeClassLoader("WELD", simpleSessionBean.getClass().getClassLoader());
+      
+      Log log = LogFactory.getLog("WEBAPP");
+      log.info("Logging from " + getClass().getName());
+      
+      simpleSessionBean.hashCode();
+      resp.setContentType("text/text");
+      PrintWriter writer = resp.getWriter();
+      writer.println("WEBAPP");
+      writer.flush();
+   }
+
+}

Added: trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiInvalidateSession.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiInvalidateSession.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/CdiInvalidateSession.java	2010-02-18 23:10:09 UTC (rev 101135)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.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 CdiInvalidateSession extends HttpServlet
+{
+   private static final long serialVersionUID = 1L;
+
+   @Override
+   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      Log log = LogFactory.getLog("WEBAPP");
+      log.info("Logging from " + getClass().getName());
+
+      SimpleSessionBean.setBeanDestroyed(false);
+      req.getSession().invalidate();
+
+      resp.setContentType("text/text");
+      PrintWriter writer = resp.getWriter();
+      writer.println("WEBAPP");
+      writer.flush();
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleSessionBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleSessionBean.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/classloader/leak/web/SimpleSessionBean.java	2010-02-18 23:10:09 UTC (rev 101135)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.io.Serializable;
+
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.SessionScoped;
+
+ at SessionScoped
+class SimpleSessionBean implements Serializable
+{
+
+   private static final long serialVersionUID = 1L;
+   private static boolean beanDestroyed = false;
+   
+   @PreDestroy
+   public void destroyBean()
+   {
+      beanDestroyed = true;
+   }
+
+   public static boolean isBeanDestroyed()
+   {
+      return beanDestroyed;
+   }
+
+   public static void setBeanDestroyed(boolean beanDestroyed)
+   {
+      SimpleSessionBean.beanDestroyed = beanDestroyed;
+   }
+}

Added: trunk/testsuite/src/resources/classloader/leak/war/WEB-INF/beans.xml
===================================================================

Added: trunk/testsuite/src/resources/classloader/leak/war/WEB-INF/web-cdi.xml
===================================================================
--- trunk/testsuite/src/resources/classloader/leak/war/WEB-INF/web-cdi.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/classloader/leak/war/WEB-INF/web-cdi.xml	2010-02-18 23:10:09 UTC (rev 101135)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+   <description>Test servlets used to test session contexts.</description>
+   <display-name>Session Context Tests</display-name>
+   <servlet>
+      <display-name>Introspection Service for Sessions</display-name>
+      <servlet-name>sessionIntrospector</servlet-name>
+      <servlet-class>org.jboss.test.classloader.leak.web.CdiIntrospectSession</servlet-class>
+   </servlet>
+   <servlet>
+      <display-name>Session Invalidation</display-name>
+      <servlet-name>invalidator</servlet-name>
+      <servlet-class>org.jboss.test.classloader.leak.web.CdiInvalidateSession</servlet-class>
+   </servlet>
+   <servlet-mapping>
+      <servlet-name>sessionIntrospector</servlet-name>
+      <url-pattern>/IntrospectCDISession</url-pattern>
+   </servlet-mapping>
+   <servlet-mapping>
+      <servlet-name>invalidator</servlet-name>
+      <url-pattern>/InvalidateCDISession</url-pattern>
+   </servlet-mapping>
+   <session-config>
+      <session-timeout>10</session-timeout>
+   </session-config>
+   <login-config>
+      <auth-method>BASIC</auth-method>
+   </login-config>
+</web-app>




More information about the jboss-cvs-commits mailing list