use of org.apache.catalina.core.JreMemoryLeakPreventionListener in project tomcat by apache.
the class TestVirtualContext method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
Tomcat tomcat = getTomcatInstance();
// BZ 49218: The test fails if JreMemoryLeakPreventionListener is not
// present. The listener affects the JVM, and thus not only the current,
// but also the subsequent tests that are run in the same JVM. So it is
// fair to add it in every test.
tomcat.getServer().addLifecycleListener(new JreMemoryLeakPreventionListener());
}
use of org.apache.catalina.core.JreMemoryLeakPreventionListener in project tomcat by apache.
the class TestWebappClassLoaderThreadLocalMemoryLeak method testThreadLocalLeak1.
@Test
public void testThreadLocalLeak1() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Need to make sure we see a leak for the right reasons
tomcat.getServer().addLifecycleListener(new JreMemoryLeakPreventionListener());
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "leakServlet1", "org.apache.tomcat.unittest.TesterLeakingServlet1");
ctx.addServletMappingDecoded("/leak1", "leakServlet1");
tomcat.start();
Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);
// Configure logging filter to check leak message appears
LogValidationFilter f = new LogValidationFilter("The web application [ROOT] created a ThreadLocal with key of");
LogManager.getLogManager().getLogger("org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f);
// Need to force loading of all web application classes via the web
// application class loader
loadClass("TesterCounter", (WebappClassLoader) ctx.getLoader().getClassLoader());
loadClass("TesterLeakingServlet1", (WebappClassLoader) ctx.getLoader().getClassLoader());
// This will trigger the ThreadLocal creation
int rc = getUrl("http://localhost:" + getPort() + "/leak1", new ByteChunk(), null);
// Make sure request is OK
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
// Destroy the context
ctx.stop();
tomcat.getHost().removeChild(ctx);
ctx = null;
// Make sure we have a memory leak
String[] leaks = ((StandardHost) tomcat.getHost()).findReloadedContextMemoryLeaks();
Assert.assertNotNull(leaks);
Assert.assertTrue(leaks.length > 0);
// Make sure the message was logged
Assert.assertEquals(1, f.getMessageCount());
}
use of org.apache.catalina.core.JreMemoryLeakPreventionListener in project tomcat by apache.
the class TestWebappClassLoaderThreadLocalMemoryLeak method testThreadLocalLeak2.
@Test
public void testThreadLocalLeak2() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Need to make sure we see a leak for the right reasons
tomcat.getServer().addLifecycleListener(new JreMemoryLeakPreventionListener());
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "leakServlet2", "org.apache.tomcat.unittest.TesterLeakingServlet2");
ctx.addServletMappingDecoded("/leak2", "leakServlet2");
tomcat.start();
Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);
// Configure logging filter to check leak message appears
LogValidationFilter f = new LogValidationFilter("The web application [ROOT] created a ThreadLocal with key of");
LogManager.getLogManager().getLogger("org.apache.catalina.loader.WebappClassLoaderBase").setFilter(f);
// Need to force loading of all web application classes via the web
// application class loader
loadClass("TesterCounter", (WebappClassLoader) ctx.getLoader().getClassLoader());
loadClass("TesterThreadScopedHolder", (WebappClassLoader) ctx.getLoader().getClassLoader());
loadClass("TesterLeakingServlet2", (WebappClassLoader) ctx.getLoader().getClassLoader());
// This will trigger the ThreadLocal creation
int rc = getUrl("http://localhost:" + getPort() + "/leak2", new ByteChunk(), null);
// Make sure request is OK
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
// Destroy the context
ctx.stop();
tomcat.getHost().removeChild(ctx);
ctx = null;
// Make sure we have a memory leak
String[] leaks = ((StandardHost) tomcat.getHost()).findReloadedContextMemoryLeaks();
Assert.assertNotNull(leaks);
Assert.assertTrue(leaks.length > 0);
// Make sure the message was logged
Assert.assertEquals(1, f.getMessageCount());
}
use of org.apache.catalina.core.JreMemoryLeakPreventionListener in project tomcat by apache.
the class TestWarDirContext method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
Tomcat tomcat = getTomcatInstance();
// The test fails if JreMemoryLeakPreventionListener is not
// present. The listener affects the JVM, and thus not only the current,
// but also the subsequent tests that are run in the same JVM. So it is
// fair to add it in every test.
tomcat.getServer().addLifecycleListener(new JreMemoryLeakPreventionListener());
}
Aggregations