https://github.com/evosec/tomcat-classloader-leak-test
An integration test for your webapp that checks if it cleans up after itself.
https://github.com/evosec/tomcat-classloader-leak-test
classloader integration java leak memory metaspace permgen test tomcat webapp
Last synced: 23 days ago
JSON representation
An integration test for your webapp that checks if it cleans up after itself.
- Host: GitHub
- URL: https://github.com/evosec/tomcat-classloader-leak-test
- Owner: evosec
- License: other
- Created: 2017-01-26T15:00:38.000Z (about 9 years ago)
- Default Branch: develop
- Last Pushed: 2018-12-11T14:16:53.000Z (about 7 years ago)
- Last Synced: 2025-07-15T16:48:01.697Z (7 months ago)
- Topics: classloader, integration, java, leak, memory, metaspace, permgen, test, tomcat, webapp
- Language: Java
- Size: 15.9 MB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE.markdown
Awesome Lists containing this project
README
# tomcat-classloader-leak-test
[](https://travis-ci.org/evosec/tomcat-classloader-leak-test)
An integration test for your webapp that checks if it cleans up after itself.
## Usage
`pom.xml`:
~~~
de.evosec
tomcat-classloader-leak-test
0.0.1
test
org.codehaus.mojo
build-helper-maven-plugin
add-test-source
generate-test-sources
add-test-source
src/it/java
org.apache.maven.plugins
maven-failsafe-plugin
integration-test
verify
org.springframework.boot:spring-boot-devtools
${project.basedir}/src/it/java
${project.build.finalName}
~~~
`src/it/java/com/example/ClassLoaderLeakTestIT`:
~~~
package com.example;
import java.nio.file.Paths;
import org.junit.Test;
import de.evosec.leaktest.WebAppTest;
public class ClassLoaderLeakTestIT {
@Test
public void test() throws Exception {
String warName = System.getProperty("warName", "demo-0.0.1-SNAPSHOT");
Path warPath = Paths.get("./target/" + warName + ".war");
new WebAppTest().warPath(warPath).contextParameter("spring.profiles.active", "integration").run();
}
}
~~~
## How it works
1. The test setups an embedded Tomcat.
2. Then the war file from the build is added to the Tomcat
3. Wait for the application to start (By default it waits until the root returns HTTP 200 OK)
4. Get a WeakReference to the started Context
5. Stop the application
6. Start creating classes to put the Metaspace/PermGen under pressure - thus triggering GC eventually.
7. Stop when WeakReference is null - thus the Context has been cleaned up properly. If not, then there is a ClassLoader leak.