When running a few hundred tests, I'm experiencing an OutOfMemoryError. After some debugging it turns out that a large amount of memory is accumulated in over 100 application contexts and bean factories.
Additionally, hundreds of threads called http-nio-auto-\*\-exec-* are created and keep running.
in the application.properties for the test, but it seems this is not used. The method org.springframework.test.context.cache.ContextCacheUtils#retrieveMaxCacheSize also doesn't seem to be invoked ever during tests, according to my breakpoints.
Cleanup doesn't seem to be executed properly. I'm uncertain if this is a bug in my configuration or the application context cache, but I can't seem to find any similar issues anywhere.
The text was updated successfully, but these errors were encountered:
In order to help you, we will need a lot more information.
What version of Spring and spring-test are you using?
What testing framework are you using (e.g., JUnit 4, JUnit Jupiter, TestNG) and what version?
Are you using Spring Boot, and if so what version?
It would appear that you might be using Spring Boot since you mention application.properties.
Please note that the spring.cache.type property is a Spring Boot property for caches such as as Ehcache, JCache, etc. Consequently, this property has nothing to do with the ApplicationContext caching support in spring-test.
Similarly, the spring.test.context.cache.maxSize property must be set either as a JVM system property or as a "Spring Property" via the SpringProperties abstraction (either programmatically or via a spring.properties file in the root of the classpath).
All org.spring.framework packages (including test) are on 5.0.7.RELEASE. All org.spring.framework.boot packages are on 2.0.3.RELEASE.
The tests are ran by Maven Surefire plugin, using JUnit 4.12.
I expected spring.cache.type to not make a difference, but set it just to make sure it was not related.
I will try setting the maxSize property as a JVM system property. However, I expect that this will not help - the documentation and source indicate that the default should be 32, while I'm seeing more than a hundred contexts in the cache when analyzing the heap dump. So either the limit is not honored at all, or something else is keeping these instances alive (even though the heap dump suggests they are referenced from the application context map.