0

We are facing java heap error while running our selenium tests in docker container. We tried to pass MAVEN_OPTS and JAVA_OPTS to increase heap size but none of resolved our issue.

docker run -e JAVA_OPTS='-Xmx3g -Xms3g'  MAVEN_OPTS='-Xmx2048m' oneapi_docker mvn clean install

And our error message: OutOfMemory Java heap space

I just add a logger info to visualize memory consumption while running tests and seems that it was not affected.

- LoggerManager INFO : ========================== Memory Info    ==========================
- LoggerManager INFO : Free memory: 258 MB LoggerManager INFO : Allocated memory: 404 MB 
- LoggerManager INFO :    Max memory: 498 MB LoggerManager INFO : Total free memory: 352 MB
- LoggerManager INFO :    =================================================================

And our docker file like this;

#Step 0: Choose base
FROM maven:latest
#Step 1 : Install the pre-requisite

COPY . .

RUN mkdir -p /root/.m2 \
    && mkdir /root/.m2/repository
    
COPY settings.xml /root/.m2

ARG JAVA_OPTS
ARG MAVEN_OPTS

RUN echo $MAVEN_OPTS
RUN echo $JAVA_OPTS
  • Does this answer your question? [How to set Java heap size (Xms/Xmx) inside Docker container?](https://stackoverflow.com/questions/29923531/how-to-set-java-heap-size-xms-xmx-inside-docker-container) – Giorgi Tsiklauri Sep 24 '20 at 14:08
  • @GiorgiTsiklauri No it was not. –  Sep 24 '20 at 14:19
  • I'm not sure there's a generic answer to this question -- it depends on how the base image is implemented. Some Java-based images respect widely-used environment variables like JAVA_OPTS, but many don't. So far as I can see, there's no documentation for this in the Maven image, and I've generally found that there isn't a better way to figure it out, than to shell into the running container and poke around the scripts. – Kevin Boone Sep 24 '20 at 14:39

1 Answers1

0

How are you executing the Selenium tests? If via the Surefire or Failsafe plugins, you need to tell them you want to increase the heap size. See this answer: java.lang.OutOfMemoryError: Java heap space in Maven

Jamie Bisotti
  • 2,605
  • 19
  • 23