Limit size of context cache in the TestContext framework

Prior to this commit, the size of the ApplicationContext cache in the
Spring TestContext Framework could grow without bound, leading to
issues with memory and performance in large test suites.

This commit addresses this issue by introducing support for setting the
maximum cache size via a JVM system property or Spring property called
"spring.test.context.cache.maxSize". If no such property is set, a
default value of 32 will be used.

Furthermore, the DefaultContextCache has been refactored to use a
synchronized LRU cache internally instead of a ConcurrentHashMap. The
LRU cache is a simple bounded cache with a "least recently used" (LRU)
eviction policy.

Issue: SPR-8055
This commit is contained in:
Sam Brannen
2016-04-03 20:41:54 +02:00
parent 26378cd604
commit e18d5b591a
9 changed files with 452 additions and 19 deletions

View File

@@ -696,6 +696,10 @@ Spring 4.3 also improves the caching abstraction as follows:
XML files, Groovy scripts, or `@Configuration` classes are detected.
* `@Transactional` test methods are no longer required to be `public` (in TestNG and JUnit 5).
* `@BeforeTransaction` and `@AfterTransaction` methods are no longer required to be `public`.
* The `ApplicationContext` cache in the _Spring TestContext Framework_ is now bounded with a
default maximum size of 32 and a _least recently used_ eviction policy. The maximum size
can be configured by setting a JVM system property or Spring property called
`spring.test.context.cache.maxSize`.
* New `ContextCustomizer` API for customizing a test `ApplicationContext` _after_ bean
definitions have been loaded into the context but _before_ the context has been refreshed.
Customizers can be registered globally by third parties, foregoing the need to implement a