Skip to content

ContextCache should close evicted context before loading new context #21007

@spring-projects-issues

Description

@spring-projects-issues

Overview

Christoph Dreis opened SPR-16462 and commented

Hi,

This week we discovered that our integration tests were failing with error messages that told us the database tables were not existent. Our test setup uses Hibernate's create-drop facilities in order to build up the database and drop everything afterwards.

After quite some digging I found out that we reached the cache limit in DefaultContextCache. The problem for us here is that the eventual ApplicationContext.close() happening in DefaultContextCache.remove() can drop the database for the currently or upcoming tests when using create-drop.

While I increased the cache limit for now, I think this is a bug as the eldest ApplicationContext instances should be closed/removed at the end of the test instance, not at the beginning when a new one might be loaded/created and put into the LruCache. (Though it's probably the appropriate place to handle the cache size).

As I don't have a proper idea yet how to defer the ApplicationContext closing in DefaultContextCache, I would highly appreciate any ideas. :)

Cheers,
Christoph

P.S.: I attached a reproduction project. Simply call mvn clean test and you should hopefully notice the test failures saying that the dummy account table doesn't exist.

Related Issues


Affects: 4.3.14

Reference URL: https://github.com/dreis2211/spring-contextcacheclose-tests

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions