Commit 9ff50f90 authored by Scott Frederick's avatar Scott Frederick

Default spring.datasource.generate-unique-name to true

This change ensures that each test in a test suite that shares an
application context gets a unique embedded database, to prevent
inconsistent embedded database state between tests.

Closes gh-16747
parent 951d0b0f
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
......@@ -44,6 +44,7 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @author Benedikt Ritter
* @author Eddú Meléndez
* @author Scott Frederick
* @since 1.1.0
*/
@ConfigurationProperties(prefix = "spring.datasource")
......@@ -59,7 +60,7 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
/**
* Whether to generate a random datasource name.
*/
private boolean generateUniqueName;
private boolean generateUniqueName = true;
/**
* Fully qualified name of the connection pool implementation to use. By default, it
......
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
......@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Maciej Walkowiak
* @author Stephane Nicoll
* @author Eddú Meléndez
* @author Scott Frederick
*/
class DataSourcePropertiesTests {
......@@ -51,8 +52,9 @@ class DataSourcePropertiesTests {
}
@Test
void determineUrl() throws Exception {
void determineUrlWithoutGenerateUniqueName() throws Exception {
DataSourceProperties properties = new DataSourceProperties();
properties.setGenerateUniqueName(false);
properties.afterPropertiesSet();
assertThat(properties.getUrl()).isNull();
assertThat(properties.determineUrl()).isEqualTo(EmbeddedDatabaseConnection.H2.getUrl("testdb"));
......@@ -79,7 +81,6 @@ class DataSourcePropertiesTests {
@Test
void determineUrlWithGenerateUniqueName() throws Exception {
DataSourceProperties properties = new DataSourceProperties();
properties.setGenerateUniqueName(true);
properties.afterPropertiesSet();
assertThat(properties.determineUrl()).isEqualTo(properties.determineUrl());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment