Skip to content

Commit 9cac5ee

Browse files
committed
Consistently use generated name in embedded databases
... to avoid database name conflicts when test classes are executed in a different order. See gh-29122
1 parent 0adec6d commit 9cac5ee

12 files changed

+72
-71
lines changed

spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,8 +82,8 @@ static class Config {
8282

8383
@Bean
8484
DataSource dataSource() {
85-
return new EmbeddedDatabaseBuilder()//
86-
.setName("empty-sql-scripts-without-tx-mgr-test-db")//
85+
return new EmbeddedDatabaseBuilder()
86+
.generateUniqueName(true)
8787
.build();
8888
}
8989
}

spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,9 +46,9 @@ PlatformTransactionManager transactionManager(DataSource dataSource) {
4646

4747
@Bean
4848
DataSource dataSource() {
49-
return new EmbeddedDatabaseBuilder()//
50-
.setName("empty-sql-scripts-test-db")//
51-
.build();
49+
return new EmbeddedDatabaseBuilder()
50+
.generateUniqueName(true)
51+
.build();
5252
}
5353

5454
}

spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,20 +97,20 @@ PlatformTransactionManager txMgr2() {
9797

9898
@Bean
9999
DataSource dataSource1() {
100-
return new EmbeddedDatabaseBuilder()//
101-
.setName("database1")//
102-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
103-
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
104-
.build();
100+
return new EmbeddedDatabaseBuilder()
101+
.generateUniqueName(true)
102+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
103+
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
104+
.build();
105105
}
106106

107107
@Bean
108108
DataSource dataSource2() {
109-
return new EmbeddedDatabaseBuilder()//
110-
.setName("database2")//
111-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
112-
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
113-
.build();
109+
return new EmbeddedDatabaseBuilder()
110+
.generateUniqueName(true)
111+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
112+
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
113+
.build();
114114
}
115115
}
116116

spring-test/src/test/java/org/springframework/test/context/jdbc/InfrastructureProxyTransactionalSqlScriptsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ PlatformTransactionManager transactionManager(DataSource dataSource) {
8181
@Bean
8282
DataSource dataSource() {
8383
return new EmbeddedDatabaseBuilder()//
84-
.setName("empty-sql-scripts-test-db")//
84+
.generateUniqueName(true)
8585
.build();
8686
}
8787

spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,20 +93,20 @@ PlatformTransactionManager txMgr2() {
9393

9494
@Bean
9595
DataSource dataSource1() {
96-
return new EmbeddedDatabaseBuilder()//
97-
.setName("database1")//
98-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
99-
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
100-
.build();
96+
return new EmbeddedDatabaseBuilder()
97+
.generateUniqueName(true)
98+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
99+
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
100+
.build();
101101
}
102102

103103
@Bean
104104
DataSource dataSource2() {
105-
return new EmbeddedDatabaseBuilder()//
106-
.setName("database2")//
107-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
108-
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
109-
.build();
105+
return new EmbeddedDatabaseBuilder()
106+
.generateUniqueName(true)
107+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
108+
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
109+
.build();
110110
}
111111

112112
}

spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,20 +94,20 @@ PlatformTransactionManager txMgr2() {
9494

9595
@Bean
9696
DataSource dataSource1() {
97-
return new EmbeddedDatabaseBuilder()//
98-
.setName("database1")//
99-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
100-
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
101-
.build();
97+
return new EmbeddedDatabaseBuilder()
98+
.generateUniqueName(true)
99+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
100+
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
101+
.build();
102102
}
103103

104104
@Bean
105105
DataSource dataSource2() {
106-
return new EmbeddedDatabaseBuilder()//
107-
.setName("database2")//
108-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
109-
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
110-
.build();
106+
return new EmbeddedDatabaseBuilder()
107+
.generateUniqueName(true)
108+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
109+
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
110+
.build();
111111
}
112112

113113
}

spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,10 +42,10 @@ PlatformTransactionManager transactionManager() {
4242

4343
@Bean
4444
DataSource dataSource() {
45-
return new EmbeddedDatabaseBuilder()//
46-
.generateUniqueName(true)
47-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
48-
.build();
45+
return new EmbeddedDatabaseBuilder()
46+
.generateUniqueName(true)
47+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
48+
.build();
4949
}
5050

5151
@Bean

spring-test/src/test/java/org/springframework/test/context/junit4/EmbeddedPersonDatabaseTestsConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,10 +41,10 @@ public PlatformTransactionManager txMgr() {
4141

4242
@Bean
4343
public DataSource dataSource() {
44-
return new EmbeddedDatabaseBuilder()//
45-
.generateUniqueName(true)//
46-
.addScript("classpath:/org/springframework/test/jdbc/schema.sql") //
47-
.build();
44+
return new EmbeddedDatabaseBuilder()
45+
.generateUniqueName(true)
46+
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")
47+
.build();
4848
}
4949

5050
}

spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -286,10 +286,10 @@ PlatformTransactionManager transactionManager() {
286286

287287
@Bean
288288
DataSource dataSource() {
289-
return new EmbeddedDatabaseBuilder()//
290-
.generateUniqueName(true)//
291-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
292-
.build();
289+
return new EmbeddedDatabaseBuilder()
290+
.generateUniqueName(true)
291+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
292+
.build();
293293
}
294294
}
295295

spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -183,10 +183,11 @@ PlatformTransactionManager transactionManager() {
183183

184184
@Bean
185185
DataSource dataSource() {
186-
return new EmbeddedDatabaseBuilder()//
187-
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")//
188-
.addScript("classpath:/org/springframework/test/jdbc/data.sql")//
189-
.build();
186+
return new EmbeddedDatabaseBuilder()
187+
.generateUniqueName(true)
188+
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")
189+
.addScript("classpath:/org/springframework/test/jdbc/data.sql")
190+
.build();
190191
}
191192

192193
}

spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -257,10 +257,10 @@ public PlatformTransactionManager transactionManager() {
257257

258258
@Bean
259259
public DataSource dataSource() {
260-
return new EmbeddedDatabaseBuilder()//
261-
.setName("programmatic-tx-mgmt-test-db")//
262-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
263-
.build();
260+
return new EmbeddedDatabaseBuilder()
261+
.generateUniqueName(true)
262+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
263+
.build();
264264
}
265265
}
266266

spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -277,10 +277,10 @@ PlatformTransactionManager transactionManager() {
277277

278278
@Bean
279279
DataSource dataSource() {
280-
return new EmbeddedDatabaseBuilder()//
281-
.generateUniqueName(true)//
282-
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
283-
.build();
280+
return new EmbeddedDatabaseBuilder()
281+
.generateUniqueName(true)
282+
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
283+
.build();
284284
}
285285
}
286286

0 commit comments

Comments
 (0)