From 9cac5eeeabf555337e3e494349cbbced09257522 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 16 Oct 2023 21:28:10 +0200 Subject: [PATCH] Consistently use generated name in embedded databases ... to avoid database name conflicts when test classes are executed in a different order. See gh-29122 --- .../jdbc/DataSourceOnlySqlScriptsTests.java | 6 ++--- .../context/jdbc/EmptyDatabaseConfig.java | 8 +++---- ...ataSourceTransactionalSqlScriptsTests.java | 22 +++++++++---------- ...tureProxyTransactionalSqlScriptsTests.java | 2 +- ...AndTransactionManagersSqlScriptsTests.java | 22 +++++++++---------- ...nManagersTransactionalSqlScriptsTests.java | 22 +++++++++---------- .../jdbc/PopulatedSchemaDatabaseConfig.java | 10 ++++----- .../EmbeddedPersonDatabaseTestsConfig.java | 10 ++++----- .../ProgrammaticTxMgmtSpringRuleTests.java | 10 ++++----- ...TransactionalTestNGSpringContextTests.java | 11 +++++----- .../ProgrammaticTxMgmtTestNGTests.java | 10 ++++----- .../programmatic/ProgrammaticTxMgmtTests.java | 10 ++++----- 12 files changed, 72 insertions(+), 71 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java index 892f122d789..3eaa3b64ada 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java @@ -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. @@ -82,8 +82,8 @@ class DataSourceOnlySqlScriptsTests { @Bean DataSource dataSource() { - return new EmbeddedDatabaseBuilder()// - .setName("empty-sql-scripts-without-tx-mgr-test-db")// + return new EmbeddedDatabaseBuilder() + .generateUniqueName(true) .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java index 432f0bae539..0a79a009233 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java @@ -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. @@ -46,9 +46,9 @@ public class EmptyDatabaseConfig { @Bean DataSource dataSource() { - return new EmbeddedDatabaseBuilder()// - .setName("empty-sql-scripts-test-db")// - .build(); + return new EmbeddedDatabaseBuilder() + .generateUniqueName(true) + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java index b17fb42118e..40d06c82453 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java @@ -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. @@ -97,20 +97,20 @@ class InferredDataSourceTransactionalSqlScriptsTests { @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/InfrastructureProxyTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/InfrastructureProxyTransactionalSqlScriptsTests.java index 600aaf06007..595feb88f41 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/InfrastructureProxyTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/InfrastructureProxyTransactionalSqlScriptsTests.java @@ -81,7 +81,7 @@ class InfrastructureProxyTransactionalSqlScriptsTests extends AbstractTransactio @Bean DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .setName("empty-sql-scripts-test-db")// + .generateUniqueName(true) .build(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java index b859338b4cb..67e0d26ac3e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java @@ -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. @@ -93,20 +93,20 @@ class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java index 87e4c6c5dc1..14ec5ebbd15 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java @@ -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. @@ -94,20 +94,20 @@ class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests { @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java index a7774d38a74..aea3913a712 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java @@ -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. @@ -42,10 +42,10 @@ public class PopulatedSchemaDatabaseConfig { @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 diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/EmbeddedPersonDatabaseTestsConfig.java b/spring-test/src/test/java/org/springframework/test/context/junit4/EmbeddedPersonDatabaseTestsConfig.java index 6edbb78f92d..3ea1f029e0c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/EmbeddedPersonDatabaseTestsConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/EmbeddedPersonDatabaseTestsConfig.java @@ -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. @@ -41,10 +41,10 @@ public class EmbeddedPersonDatabaseTestsConfig { @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java index 86ac39677ef..79ccf31fa71 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java @@ -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. @@ -286,10 +286,10 @@ public class ProgrammaticTxMgmtSpringRuleTests { @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java index 9b324b42d72..aeb8fc24454 100644 --- a/spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java @@ -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. @@ -183,10 +183,11 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java index 1648516d081..1413e41a742 100644 --- a/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java @@ -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. @@ -257,10 +257,10 @@ public class ProgrammaticTxMgmtTestNGTests extends AbstractTransactionalTestNGSp @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(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java index 2e92710ea39..782f04351ee 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java @@ -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. @@ -277,10 +277,10 @@ class ProgrammaticTxMgmtTests { @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(); } }