Skip to content

Allow configuration to specify randomly generated database name #7004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

robfletcher
Copy link
Contributor

Currently (it seems to me) the only way to have an embedded test database use a random name is to completely override the dataSource bean or to use XML configuration with<embedded-database generate-name="true"/>.
This PR makes it possible to do so by using spring.datasource.generate-name = true in properties or yaml config.

This is useful when running tests with multiple application context configurations as all cached contexts will try to destroy their dataSource bean which by default are all pointing to the same in-memory H2 database.
The first will successfully shut down the embedded database and any subsequent ones will throw exceptions.
This does not cause the tests to fail but does produce a large stacktrace.

@pivotal-issuemaster
Copy link

@robfletcher Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@robfletcher Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 23, 2016
@snicoll
Copy link
Member

snicoll commented Sep 23, 2016

Thanks for the PR! I actually hit that issue as well. With Boot 1.4 and slicing we tend to create more contexts than before. Unfortunately, the in-memory database might be shared (that's what I saw with H2 at a customer at least). They are using data.sql and had to flip continueOnError to avoid their test suite to crash. This isn't new but slicing doesn't help in this area.

Having X in-memory databases lying around until the test suite completes is probably a concern then...

@robfletcher
Copy link
Contributor Author

I'd argue it's no more a concern than having X application contexts lying around!

This isn't new functionality, it's just exposing functionality already available to people using XML config or rolling their own data source.

It looks like these are the original issues for the unique name option and the XML attribute that exposes it.
https://jira.spring.io/browse/SPR-8849
https://jira.spring.io/browse/SPR-12835

@snicoll
Copy link
Member

snicoll commented Sep 23, 2016

I am not sure I agree. Application context caching is here since the early days of the test context framework. Us generating a new database per context is an entire new thing that can have side effects.

Having said that we should fix this issue one way or the other ;)

@snicoll snicoll added for: team-attention An issue we'd like other members of the team to review type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Oct 5, 2016
@snicoll
Copy link
Member

snicoll commented Oct 5, 2016

We just discussed this change and we all agree that the current situation can lead to unpredictable results. More than the error on shutdown, the fact that a single database is shared by multiple application contexts is quite problematic. We'll integrate this PR with 1.4, flipping that property to true in tests for 1.5

@snicoll snicoll added this to the 1.4.2 milestone Oct 5, 2016
@snicoll snicoll self-assigned this Oct 5, 2016
snicoll added a commit that referenced this pull request Oct 6, 2016
* pr/7004:
  Polish contribution
  Allow configuration to specify randomly generated database name
@snicoll snicoll closed this in 03961e6 Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants