Author: markt Date: Mon Mar 19 19:27:31 2012 New Revision: 1302609 URL: http://svn.apache.org/viewvc?rev=1302609&view=rev Log: Create some test support classes required by the memory leak tests that have to be outside of the org.apache.catalina package so they they are not treated as container servlets and loaded by the common class loader rather than the webapp class loader.
Added: tomcat/trunk/test/org/apache/tomcat/unittest/ tomcat/trunk/test/org/apache/tomcat/unittest/TesterCounter.java (with props) tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet1.java (with props) tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet2.java (with props) tomcat/trunk/test/org/apache/tomcat/unittest/TesterThreadScopedHolder.java (with props) Added: tomcat/trunk/test/org/apache/tomcat/unittest/TesterCounter.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterCounter.java?rev=1302609&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/unittest/TesterCounter.java (added) +++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterCounter.java Mon Mar 19 19:27:31 2012 @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomcat.unittest; + +public class TesterCounter { + private int count = 0; + + public void increment() { + count++; + } + + public int getCount() { + return count; + } +} \ No newline at end of file Propchange: tomcat/trunk/test/org/apache/tomcat/unittest/TesterCounter.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet1.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet1.java?rev=1302609&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet1.java (added) +++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet1.java Mon Mar 19 19:27:31 2012 @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomcat.unittest; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class TesterLeakingServlet1 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private ThreadLocal<TesterCounter> myThreadLocal = new ThreadLocal<TesterCounter>(); + + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + + TesterCounter counter = myThreadLocal.get(); + if (counter == null) { + counter = new TesterCounter(); + myThreadLocal.set(counter); + } + + counter.increment(); + response.getWriter().println( + "The current thread served this servlet " + + counter.getCount() + " times"); + } + + @Override + public void destroy() { + super.destroy(); + // normally not needed, just to make my point + myThreadLocal = null; + } +} \ No newline at end of file Propchange: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet1.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet2.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet2.java?rev=1302609&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet2.java (added) +++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet2.java Mon Mar 19 19:27:31 2012 @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomcat.unittest; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +public class TesterLeakingServlet2 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, + IOException { + + List<TesterCounter> counterList = TesterThreadScopedHolder.getFromHolder(); + TesterCounter counter; + if (counterList == null) { + counter = new TesterCounter(); + TesterThreadScopedHolder.saveInHolder(Arrays.asList(counter)); + } else { + counter = counterList.get(0); + } + + counter.increment(); + response.getWriter().println( + "The current thread served this servlet " + + counter.getCount() + " times"); + } +} \ No newline at end of file Propchange: tomcat/trunk/test/org/apache/tomcat/unittest/TesterLeakingServlet2.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/tomcat/unittest/TesterThreadScopedHolder.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/unittest/TesterThreadScopedHolder.java?rev=1302609&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/unittest/TesterThreadScopedHolder.java (added) +++ tomcat/trunk/test/org/apache/tomcat/unittest/TesterThreadScopedHolder.java Mon Mar 19 19:27:31 2012 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomcat.unittest; + +import java.util.List; + +public class TesterThreadScopedHolder { + private static final ThreadLocal<List<TesterCounter>> threadLocal = + new ThreadLocal<List<TesterCounter>>(); + + public static void saveInHolder(List<TesterCounter> o) { + threadLocal.set(o); + } + + public static List<TesterCounter> getFromHolder() { + return threadLocal.get(); + } +} \ No newline at end of file Propchange: tomcat/trunk/test/org/apache/tomcat/unittest/TesterThreadScopedHolder.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org