-
Notifications
You must be signed in to change notification settings - Fork 41.1k
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
Reconsider default for spring.datasource.generate-unique-name as the current one makes test cases brittle #16747
Comments
Yes, I always advocate generating a random database name for embedded databases in Spring integration tests. Over the years I have seen numerous projects that ran into issues with In fact, I updated the Spring Framework reference manual quite awhile ago (several years?) to point that out.
In summary, if it's feasible I think it would be beneficial if |
Digging though the code a bit we think this might be a safe change to make but we'll need some time to experiment to make sure there are no unexpected side effects. |
See #4699 for the DevTools side of things. |
Can we bring this on the table for 2.3 again? |
@odrotbohm Yeah, we'll try again to get this into the next version |
@wilkinsona @philwebb But given the context caching and reuse, isn't this gonna open several db instances in memory? |
Yes, and that is intentional and desirable as explained above by @odrotbohm and @sbrannen. |
This has the side-effect that I would expect setting the |
I'm not sure why you have that expectation. The |
Issue
The current default for
spring.datasource.generate-unique-name
(false
) causes issues in combination with the default used for Hibernates DDL settingspring.jpa.generate-ddl
(create-drop
) in the context of Spring Test's context caching. I've attached a sample project that shows the issue.Steps to reproduce
mvn clean test
Context
Here is what's going on:
create-drop
causes the database schema being wiped and recreated. As this context does not contain the component setting up the reference data, the database remains initialized but unpopulated. This is fine for this particular context. However, as the database is shared across the application contexts, the other cached one is affected, too.Underlying problems
There are a couple of problematic aspects about the current setup:
Workarounds
spring.datasource.generate-unique-name=true
causes database instances to be created perApplicationContext
.Proposed solution
spring.datasource.generate-unique-name
totrue
.Side-effects of the solution
ApplicationContext
and – with the new default – would lose the data entered while using the application. This could be mitigated by letting DevTools explicitly disable the property by default.Further references
AFAIK, @sbrannen had a few thoughts on that as well.
The text was updated successfully, but these errors were encountered: