-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Introduce support for generating unique names for embedded databases [SPR-8849] #13491
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
Comments
Chris Beams commented Hi Julian, I have a couple ideas here, but it would be good to see the failure in action before making too many assumptions. Would you be willing to put together a small reproduction project following the instructions here? https://github.com/SpringSource/spring-framework-issues#readme Thanks, Chris |
Mickaël LEDUQUE commented I'm not the original reporter but I tried to provide a test project for this issue. If you don't see it, tell me. |
Sam Brannen commented Hi guys,
Based on your work and Julian's suggested programmatic work-around, I committed a test suite that both demonstrates the problem and a configuration-based work-around using a SpEL expression. See commit 04a682729020af09c70ebbf6a210f42b8cc1c36b for details.
- Sam |
Torsten Krah commented But if those context does use e.g. DataSourceTransactionManager which does need a explicit reference to the above dataSource, how to setup this? |
Sam Brannen commented Torsten Krah, if you generate random IDs in XML configuration, then there won't be a way to know the random ID. So in such cases, you won't be able to refer to the However, if you use Java Config (i.e., an Regards, Sam |
Torsten Krah commented So wouldn't it be better to just have 2 additional properties - the |
Sam Brannen commented Note that Providing an explicit attribute via In summary, I would recommend the following changes:
Regards, Sam |
Sam Brannen commented Regarding support for a If you would like to see that implemented, please open a new JIRA issue to suggest it formally. Thanks, Sam |
Torsten Krah commented Thanks Sam, regarding your suggestions this sounds really good to me having it configurable at the jdbc namespace and at the builder API. regards Torsten. |
Gregory bonk commented This looks like my issue where the TestContext cache tries to re-create beans of embedded databases. |
Sam Brannen commented FYI: the ground work for this issue has just been completed in conjunction with #17431 and #17432. |
Sam Brannen commented The previously proposed work-around has been updated as described in GitHub commit ab771df:
Consequently, the following viable solution now exists for setting a unique name for each embedded database: <jdbc:embedded-database id="dataSource" database-name="#{T(java.util.UUID).randomUUID().toString()}">
<jdbc:script location="..." />
</jdbc:embedded-database> The above solution is, however, still considered a manual work-around until this issue (#13491) has been resolved. |
Sam Brannen commented Completed as described in GitHub commit c0fbe0a:
|
Sam Brannen commented The proper solution to the problem originally raised by this JIRA issue will be available in Spring Framework 4.2 RC1 as follows: <jdbc:embedded-database id="mirDataSource" generate-name="true">
<jdbc:script location="classpath:db/schema.sql" />
<jdbc:script location="classpath:db/tables_hsqldb.sql" />
<jdbc:script location="classpath:db/package_verweildauer.sql" />
<jdbc:script location="classpath:db/data.sql" />
</jdbc:embedded-database> Thus, all that's required to get it working as expected is the addition of |
Sam Brannen commented Out of curiosity, how do people feel about the Is it not descriptive enough, too short? Would something longer be a better choice?
Thanks in advance for feedback! - Sam p.s. please keep in mind that #17432 introduced a new |
Gregory bonk commented Why couldn't the database just be reused instead of generating unique names and duplicate databases?
|
Sam Brannen commented
The unique name generation is a feature that you have to explicitly opt in for. The default behavior is that the database will be reused. Nothing has changed in this regard. The only possible issue is if you have scripts that are used to populate the database. So in that sense, your proposal warrants consideration. Please open a new JIRA issue to track this proposal on its own. Thanks, Sam |
Julian Sareyka opened SPR-8849 and commented
Hi,
I use an embedded database (HSQL) in my integration test suite. Its a maven project with TestNG.
I have one default context configuration (which includes the database) and several extensions:
for instance:
When executing the tests with maven (maven-surefire), all the tests with the first configuration reuse the same context (due to context caching). The first test-setup with the second configuration should create a fresh application context, but it fails with Database-Errors indicating, that the objects to create already exist. (I spent quite some time debugging the maven process).
Here is the maven surefire config:
My theory is, that both contexts connect to the same database instance, because they are in the same vm and the name of the db-instance is the same:
EmbeddedDatabaseFactory.databaseName = "testdb";
I did not find a way to assign the name with the jdbc:embedded-database-Tag.
So I created a custom EmbeddedDatabaseBuilder which assigns a random name (UUID) to every new instance:
With this one the errors are gone. Would it be a solution to add a configuration-option to jdbc:embedded-database for random db-instance names?
Affects: 3.1 GA
Issue Links:
6 votes, 7 watchers
The text was updated successfully, but these errors were encountered: