Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockito, jacoco and surefire causes out of memory

I am using mockito 1.8.3, jacoco 0.72 and maven 3.0.5 surefire plugin (2.12.4) to execute unit test and generating coverage report, it was working fine.

With more and more tests are added, it starts not working. I continuously encounter out of memory error during test execution, and cannot find out a way to figure out what is wrong.

I have about 1800+ test cases with mockito as the mocking tool. It is working fine if I do not run jacoco during maven test with "org.jacoco:jacoco-maven-plugin:prepare-agent " before test phase, but as long as I add jacoco agent, I get OOO issue with PermGen full.

I already added the PermGen to 2GB by modifying MAVEN_OPTS (which should not work since surefire will fork a new process) and surefire argline argument in pom, but it does not help a lot.

I try to get a core dump when OOO occurs by adding parameter to surefire plugin, but never saw a dump file in any folder. I am suspicious that my JVM setting does not work for the surefire plugin, but not sure what is wrong. Anyone could do me a favor? Thanks.

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire.version}</version>
                <inherited>true</inherited>
                <configuration>
                    <properties>
                        <property>
                            <name>argLine</name>                                    <value>-server -ea -XX:-UseSplitVerifier -XX:MaxPermSize=2g -Xmx3g -XX:+HeapDumpOnOutOfMemoryError </value>
                        </property>
                        <property>
                            <name>forkMode</name>
                            <value>once</value>
                        </property>
                        <property>
                            <name>reportFormat</name>
                            <value>plain</value>
                        </property>
                        <property>
                            <name>skipTests</name>
                            <value>${maven.test.skip}</value>
                        </property>
                    </properties>
                </configuration>
            </plugin>
like image 639
Skywolf Avatar asked Mar 02 '15 10:03

Skywolf


2 Answers

You need to set the memory for maven-surefire-plugin like the following:

<plugins>
[...]
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
        <forkCount>3</forkCount>
        <reuseForks>true</reuseForks>
        <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
        <systemPropertyVariables>
            <databaseSchema>MY_TEST_SCHEMA_${surefire.forkNumber}</databaseSchema>
        </systemPropertyVariables>
    </configuration>
  </plugin>
[...]
</plugins>
like image 61
khmarbaise Avatar answered Oct 27 '22 10:10

khmarbaise


In case you have jacoco configured along with maven failsafe plugin, then you will need to pass memory parameters to that one too:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-failsafe-plugin</artifactId>
   <version>2.14.1</version>
   <configuration>
      <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
   </configuration>
</plugin>
like image 39
vadim Avatar answered Oct 27 '22 11:10

vadim