ASF Bugzilla – Attachment 25566 Details for
Bug 49414
Wrong memory leak detection: executor thread reported as web app thread
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Unit test allowing to generate the wrong log message (but doesn't catpure the log to really test it)
patchTestWrongMemoryLeakWarning.txt (text/plain), 2.55 KB, created by
Marc Guillemot
on 2010-06-09 10:11:08 UTC
(
hide
)
Description:
Unit test allowing to generate the wrong log message (but doesn't catpure the log to really test it)
Filename:
MIME Type:
Creator:
Marc Guillemot
Created:
2010-06-09 10:11:08 UTC
Size:
2.55 KB
patch
obsolete
>Index: test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java >=================================================================== >--- test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java (revision 952992) >+++ test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java (working copy) >@@ -19,8 +19,11 @@ > import java.io.IOException; > import java.util.Timer; > import java.util.TimerTask; >+import java.util.concurrent.atomic.AtomicBoolean; > > import javax.servlet.ServletException; >+import javax.servlet.ServletRequest; >+import javax.servlet.ServletResponse; > import javax.servlet.http.HttpServlet; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; >@@ -118,4 +121,58 @@ > } > > } >+ >+ /** >+ * This test is green as I don't know how to capture log output >+ * Output contains something like: >+ * SEVERE: The web application [/] appears to have started a thread named [http-8001-exec-1] but has failed to stop it. This is very likely to create a memory leak. >+ * what is wrong. >+ * @throws Exception >+ */ >+ public void testWrongLeak() throws Exception { >+ final Tomcat tomcat = getTomcatInstance(); >+ >+ // Must have a real docBase - just use temp >+ final Context ctx = tomcat.addContext("/", System.getProperty("java.io.tmpdir")); >+ >+ final AtomicBoolean requestPerformed = new AtomicBoolean(false); >+ >+ final HttpServlet servlet = new HttpServlet() { >+ @Override >+ public void service(final ServletRequest req, final ServletResponse res) >+ throws ServletException, IOException { >+ requestPerformed.set(true); >+ try { >+ Thread.sleep(5000); >+ } >+ catch (final InterruptedException e) { >+ // ignore, it's ok >+ } >+ } >+ }; >+ Tomcat.addServlet(ctx, "testServlet", servlet); >+ ctx.addServletMapping("/", "testServlet"); >+ >+ tomcat.start(); >+ >+ final Thread bgGet = new Thread("bg get url") { >+ public void run() { >+ try { >+ getUrl("http://localhost:" + getPort() + "/"); >+ } >+ catch (final IOException e) { >+ throw new RuntimeException(e); >+ } >+ } >+ }; >+ bgGet.start(); >+ >+ // wait until request arrives in the servlet >+ while (!requestPerformed.get()) { >+ Thread.sleep(10); >+ } >+ >+ // stop everything when request processing thread is still in service due to the quite long sleep >+ tomcat.stop(); >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 49414
: 25566