Skip to content

Commit

Permalink
Consistently use generated name in embedded databases
Browse files Browse the repository at this point in the history
... to avoid database name conflicts when test classes are executed in
a different order.

See gh-29122
  • Loading branch information
sbrannen committed Oct 16, 2023
1 parent 0adec6d commit 9cac5ee
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -82,8 +82,8 @@ static class Config {

@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.setName("empty-sql-scripts-without-tx-mgr-test-db")//
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,9 +46,9 @@ PlatformTransactionManager transactionManager(DataSource dataSource) {

@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.setName("empty-sql-scripts-test-db")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,20 +97,20 @@ PlatformTransactionManager txMgr2() {

@Bean
DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()//
.setName("database1")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
.build();
}

@Bean
DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()//
.setName("database2")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PlatformTransactionManager transactionManager(DataSource dataSource) {
@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.setName("empty-sql-scripts-test-db")//
.generateUniqueName(true)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,20 +93,20 @@ PlatformTransactionManager txMgr2() {

@Bean
DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()//
.setName("database1")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
.build();
}

@Bean
DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()//
.setName("database2")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
.build();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,20 +94,20 @@ PlatformTransactionManager txMgr2() {

@Bean
DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()//
.setName("database1")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
.build();
}

@Bean
DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()//
.setName("database2")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")
.build();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,10 +42,10 @@ PlatformTransactionManager transactionManager() {

@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.build();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,10 +41,10 @@ public PlatformTransactionManager txMgr() {

@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/jdbc/schema.sql") //
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -286,10 +286,10 @@ PlatformTransactionManager transactionManager() {

@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -183,10 +183,11 @@ PlatformTransactionManager transactionManager() {

@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/jdbc/data.sql")//
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/jdbc/schema.sql")
.addScript("classpath:/org/springframework/test/jdbc/data.sql")
.build();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -257,10 +257,10 @@ public PlatformTransactionManager transactionManager() {

@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.setName("programmatic-tx-mgmt-test-db")//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -277,10 +277,10 @@ PlatformTransactionManager transactionManager() {

@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
.build();
return new EmbeddedDatabaseBuilder()
.generateUniqueName(true)
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
.build();
}
}

Expand Down

0 comments on commit 9cac5ee

Please sign in to comment.