001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.classloader.leak.test;
023:
024: import javax.naming.InitialContext;
025:
026: import junit.framework.Test;
027:
028: import org.jboss.test.classloader.leak.ejb.interfaces.StatefulSession;
029: import org.jboss.test.classloader.leak.ejb.interfaces.StatefulSessionHome;
030: import org.jboss.test.classloader.leak.ejb.interfaces.StatelessSession;
031: import org.jboss.test.classloader.leak.ejb.interfaces.StatelessSessionHome;
032:
033: /**
034: * Test for classloader leaks following deployment, use and undeployment
035: * of various packages (wars, ejb jars and ears with and without scoped
036: * classloaders).
037: * <p/>
038: * These tests were originally written to test for leaks caused by Jakarta
039: * Commons Logging. As a result, there are various permutations of the tests
040: * that store copies of commons-logging in different locations on the classpath.
041: * <p/>
042: * If these tests are run with JBoss Profiler's jbossAgent (.dll or .so) on the path
043: * and the AS is started with -agentlib:jbossAgent, in case of classloader leakage
044: * an extensive report will be logged to the server log, showing the path to root of
045: * all references to the classloader.
046: *
047: * @author Brian Stansberry
048: */
049: public class ClassloaderLeakUnitTestCase extends
050: ClassloaderLeakTestBase {
051: private static final String SIMPLE_WAR = "classloader-leak-simple.war";
052: private static final String WAR_WITH_JCL = "classloader-leak-in-war.war";
053: private static final String SIMPLE_EJB = "classloader-leak-ejb.jar";
054: private static final String SIMPLE_EAR = "classloader-leak-simple.ear";
055: private static final String EAR_WITH_JCL = "classloader-leak-in-ear.ear";
056: private static final String SIMPLE_ISOLATED_EAR = "classloader-leak-simple-isolated.ear";
057: private static final String ISOLATED_EAR_WITH_JCL = "classloader-leak-in-ear-isolated.ear";
058: private static final String EAR_WITH_DUAL_JCL = "classloader-leak-dual.ear";
059: private static final String ISOLATED_EAR_WITH_DUAL_JCL = "classloader-leak-dual-isolated.ear";
060: private static final String NO_WEB_EAR = "classloader-leak-noweb.ear";
061: private static final String ISOLATED_NO_WEB_EAR = "classloader-leak-noweb-isolated.ear";
062:
063: private static final String EJB2_SLSB = "EJB2_SLSB";
064: private static final String EJB2_SFSB = "EJB2_SFSB";
065: private static final String EJB2_SLSB_TCCL = "EJB2_SLSB_TCCL";
066: private static final String EJB2_SFSB_TCCL = "EJB2_SFSB_TCCL";
067:
068: private static final String[] EJB2 = new String[] { EJB2_SLSB,
069: EJB2_SLSB_TCCL, EJB2_SFSB, EJB2_SFSB_TCCL };
070:
071: public ClassloaderLeakUnitTestCase(String name) {
072: super (name);
073: }
074:
075: public static Test suite() throws Exception {
076: return getDeploySetup(ClassloaderLeakUnitTestCase.class,
077: "classloader-leak-test.sar");
078: }
079:
080: public void testSimpleWar() throws Exception {
081: warTest(SIMPLE_WAR);
082: }
083:
084: public void testWarWithJcl() throws Exception {
085: warTest(WAR_WITH_JCL);
086: }
087:
088: public void testSimpleEjb() throws Exception {
089: ejbTest(SIMPLE_EJB);
090: }
091:
092: public void testSimpleEar() throws Exception {
093: earTest(SIMPLE_EAR);
094: }
095:
096: public void testEarWithJcl() throws Exception {
097: earTest(EAR_WITH_JCL);
098: }
099:
100: public void testNoWebEar() throws Exception {
101: ejbTest(NO_WEB_EAR);
102: }
103:
104: public void testSimpleIsolatedEar() throws Exception {
105: earTest(SIMPLE_ISOLATED_EAR);
106: }
107:
108: public void testIsolatedNoWebEar() throws Exception {
109: ejbTest(ISOLATED_NO_WEB_EAR);
110: }
111:
112: public void testIsolatedEarWithJcl() throws Exception {
113: earTest(ISOLATED_EAR_WITH_JCL);
114: }
115:
116: public void testEarWithDualJcl() throws Exception {
117: earTest(EAR_WITH_DUAL_JCL);
118: }
119:
120: public void testIsolatedEarWithDualJcl() throws Exception {
121: earTest(ISOLATED_EAR_WITH_DUAL_JCL);
122: }
123:
124: protected String getWarContextPath() {
125: return "classloader-leak";
126: }
127:
128: protected String[] getEjbKeys() {
129: return EJB2;
130: }
131:
132: protected void makeEjbRequests() throws Exception {
133: InitialContext ctx = new InitialContext();
134: StatelessSessionHome slsbhome = (StatelessSessionHome) ctx
135: .lookup("ClassloaderLeakStatelessSession");
136: StatelessSession slsbbean = slsbhome.create();
137: slsbbean.log("EJB");
138: StatefulSessionHome sfsbhome = (StatefulSessionHome) ctx
139: .lookup("ClassloaderLeakStatefulSession");
140: StatefulSession sfsbbean = sfsbhome.create();
141: sfsbbean.log("EJB");
142: }
143: }
|