Clear ApplicationContext cache after a test class completes if necessary
The ApplicationContext has a resource cache that it uses while the context is being refreshed. Once the refresh phase completes, the cache is cleared as its content is no longer in use. If beans are lazily initialized, there is a case where the cache might be filled again as processing is deferred past the refresh phase. For those cases, the cache is not cleared. This can be a problem when running in this mode with a large set of test configurations as the TCF caches the related contexts. This commit includes an additional TestExecutionListener to the TCF that clears the resource cache if necessary once a test class completes. It is ordered so that it runs after `@DirtiesContext` support as marking the context as dirty will remove it from the cache and make that extra step unnecessary. Closes gh-30954
This commit is contained in:
@@ -16,6 +16,7 @@ by default, exactly in the following order:
|
||||
Micrometer's `ObservationRegistry`.
|
||||
* `DirtiesContextTestExecutionListener`: Handles the `@DirtiesContext` annotation for
|
||||
"`after`" modes.
|
||||
* `CommonCacheTestExecutionListener`: Clears application context cache if necessary.
|
||||
* `TransactionalTestExecutionListener`: Provides transactional test execution with
|
||||
default rollback semantics.
|
||||
* `SqlScriptsTestExecutionListener`: Runs SQL scripts configured by using the `@Sql`
|
||||
|
||||
Reference in New Issue
Block a user