OutOfMemoryError when running junitreport from ANT

advertisements

We have a Jenkins job for testing our application. When executing we get the famous OutOfMemoryError while executing our target that generates the junitreport using the following snippet.

        <junitreport todir="${tmp.dir}/reports-test-shared">
            <fileset dir="${tmp.dir}/reports-test-shared">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="frames" todir="html" />
        </junitreport>

The exact stack trace we get is the following.

/app/ci/jenkins/jobs/FLEETperfect Trunk Junit Test MOS/workspace/trunk/com.bsiag.fleet.build/build.xml:818: java.lang.OutOfMemoryError: Java heap space
    at com.sun.org.apache.xerces.internal.util.XMLStringBuffer.append(XMLStringBuffer.java:205)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1380)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanCDATASection(XMLDocumentFragmentScannerImpl.java:1654)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2986)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
    at org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator.createDocument(XMLResultAggregator.java:254)
    at org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator.execute(XMLResultAggregator.java:144)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Edit: Line 818 in our build.xml is the junitreport task shown above

I have already looked at some of the suggestions given in other SO question such as here, here and here.

The most commonly given advice is

  • Increase Xms and Xms in JAVA_OPTS
  • Increase Xmx and Xms in ANT_OPTS

Here is what I have done so far:

  • Set env variable JAVA_OPTS to "-Xms512m -Xmx2048m"
  • Set env variable ANT_OPTS to "-Xms512m -Xmx2048m"
  • Created setenv.sh in tomcat/bin directory where I do a: export JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx2048m"
  • Added "-XX:MaxPermSize=256m" to env variables JAVA_OPTS and ANT_OPTS

My problem is the following. I don't know if the memory settings I make are the ones that are taken by ANT to use for running the report generation (junitreport)

Where do I have to increase the heap size in order for junitreport to terminate without an OutOfMemoryError?


A problem like this might be fixed using another approach. Instead of increasing the heap space I tried to find the reason for such a big space requirement. I found a test that wrote a lot of information to sysout. That caused the resulting xml-file to be >200mb large. Apparently too large for a heap size of 2 or 3 gb.