Friday, June 27, 2008

Increasing memory of JUnit TestCases in Maven2

The WSO2 Mashup Server uses Maven2 as its build system. Since of late we were facing an issue where our integration tests were failing regularly with the exception "Caused by: java.lang.OutOfMemoryError: Java heap space". This is the JIRA that tracked this issue . During the integration test phase we start up an instance of the mashup server and deploy some test scripts. We them bombard the server with around 110 request (within a second or two) hence it ran out of memory before the tests completed.

Increasing memory given to maven using MAVEN_OPTS did not solve the problem. As this setting just increases the memory given to the build process and not the individual test cases. The solution was to use the following configuration in the surefire plugin.


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>pertest</forkMode>
<argLine>-Xms256m -Xmx512m</argLine> <testFailureIgnore>false</testFailureIgnore>
<skip>false</skip>
<includes>
<include>**/*IntegrationTestSuite.java</include>
</includes>
</configuration>
</plugin>


The pom for the integration test can be found here. This fixed the heap space issue and now we have our test cases running on the nightly build. You can see the status of our nightly builds at http://builder.wso2.org/browse/MASHUP-NIGHTLY

12 comments:

SteveL said...

Sounds like your code is leaking static data structures; might be worth tracking that down...

a developer said...

It works, thank you!

Keith Chapman said...

sure does work. I had a hard time figuring this out, that's the very reason I thought a blog post on that will be useful for others facing the same situation. Good to hear that someone befited from it.

Mark Kunichika said...

We were butting our heads against this for a while. Like you, we tried setting MAVEN_OPTS to no avail. Your solution did work for us. Thanks, Keith!

Our situation is slightly weirder because developers on Macs didn't have problems with running out of memory in the tests but developers in windows did, so we ended up putting our override of memory settings in our individual .m2/settings.xml files.

Krzysztof Adamczyk said...

Thank you very much for this very valuable and interesting post!

Moshe Ben Shoham said...

Very helpful - thanks a lot!

Petr Charvát said...

Thank you. You saved couple of hours of my life.

Unknown said...

Thanks for the tip.

I kept increasing MAVEN_OPTS heap size without any effect!

Gotta love Maven... :p

A$$@C1n80r said...

maaan thanku so very much!! god bless!

Srinivasa Reddy Challa said...

thanks for the code, it worked like charm for me.

Jake Collins said...

@Mark Kunichika - You could consider putting a Maven profile in your pom.xml that only activates for Windows users, rather than requiring Windows users to edit their settings.xml?

Aak said...

Thank you very much you saved lot of time