Commit 8c785b21 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '1.5.x'

parents 7a4b87be bccbbc14
...@@ -132,6 +132,17 @@ ...@@ -132,6 +132,17 @@
<artifactId>spring-hateoas</artifactId> <artifactId>spring-hateoas</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>${derby.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.tomcat.embed</groupId> <groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId> <artifactId>tomcat-embed-websocket</artifactId>
...@@ -152,6 +163,11 @@ ...@@ -152,6 +163,11 @@
<artifactId>websocket-client</artifactId> <artifactId>websocket-client</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
......
...@@ -42,7 +42,6 @@ import org.springframework.context.annotation.Conditional; ...@@ -42,7 +42,6 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
...@@ -85,12 +84,6 @@ public class DevToolsDataSourceAutoConfiguration { ...@@ -85,12 +84,6 @@ public class DevToolsDataSourceAutoConfiguration {
static final class NonEmbeddedInMemoryDatabaseShutdownExecutor static final class NonEmbeddedInMemoryDatabaseShutdownExecutor
implements DisposableBean { implements DisposableBean {
private static final Set<String> IN_MEMORY_DRIVER_CLASS_NAMES = new HashSet<>(
Arrays.asList("org.apache.derby.jdbc.EmbeddedDriver", "org.h2.Driver",
"org.h2.jdbcx.JdbcDataSource", "org.hsqldb.jdbcDriver",
"org.hsqldb.jdbc.JDBCDriver",
"org.hsqldb.jdbc.pool.JDBCXADataSource"));
private final DataSource dataSource; private final DataSource dataSource;
private final DataSourceProperties dataSourceProperties; private final DataSourceProperties dataSourceProperties;
...@@ -109,9 +102,42 @@ public class DevToolsDataSourceAutoConfiguration { ...@@ -109,9 +102,42 @@ public class DevToolsDataSourceAutoConfiguration {
} }
private boolean dataSourceRequiresShutdown() { private boolean dataSourceRequiresShutdown() {
return IN_MEMORY_DRIVER_CLASS_NAMES for (InMemoryDatabase inMemoryDatabase : InMemoryDatabase.values()) {
.contains(this.dataSourceProperties.determineDriverClassName()) if (inMemoryDatabase.matches(this.dataSourceProperties)) {
&& (!(this.dataSource instanceof EmbeddedDatabase)); return true;
}
}
return false;
}
private static enum InMemoryDatabase {
DERBY(null, "org.apache.derby.jdbc.EmbeddedDriver"),
H2("jdbc:h2:mem:", "org.h2.Driver", "org.h2.jdbcx.JdbcDataSource"),
HQSQLDB("jdbc:hsqldb:mem:", "org.hsqldb.jdbcDriver",
"org.hsqldb.jdbc.JDBCDriver",
"org.hsqldb.jdbc.pool.JDBCXADataSource");
private final String urlPrefix;
private final Set<String> driverClassNames;
InMemoryDatabase(String urlPrefix, String... driverClassNames) {
this.urlPrefix = urlPrefix;
this.driverClassNames = new HashSet<String>(
Arrays.asList(driverClassNames));
}
boolean matches(DataSourceProperties properties) {
String url = properties.getUrl();
return (url == null || this.urlPrefix == null
|| url.startsWith(this.urlPrefix))
&& this.driverClassNames
.contains(properties.determineDriverClassName());
}
} }
} }
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -95,8 +95,17 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests { ...@@ -95,8 +95,17 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
return statement; return statement;
} }
protected final ConfigurableApplicationContext createContext(Class<?>... classes) {
return this.createContext(null, classes);
}
protected final ConfigurableApplicationContext createContext(String driverClassName, protected final ConfigurableApplicationContext createContext(String driverClassName,
Class<?>... classes) { Class<?>... classes) {
return this.createContext(driverClassName, null, classes);
}
protected final ConfigurableApplicationContext createContext(String driverClassName,
String url, Class<?>... classes) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(classes); context.register(classes);
context.register(DevToolsDataSourceAutoConfiguration.class); context.register(DevToolsDataSourceAutoConfiguration.class);
...@@ -104,14 +113,13 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests { ...@@ -104,14 +113,13 @@ public abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
EnvironmentTestUtils.addEnvironment(context, EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.driver-class-name:" + driverClassName); "spring.datasource.driver-class-name:" + driverClassName);
} }
if (url != null) {
EnvironmentTestUtils.addEnvironment(context, "spring.datasource.url:" + url);
}
context.refresh(); context.refresh();
return context; return context;
} }
protected final ConfigurableApplicationContext createContext(Class<?>... classes) {
return this.createContext(null, classes);
}
@Configuration @Configuration
static class SingleDataSourceConfiguration { static class SingleDataSourceConfiguration {
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -57,4 +57,70 @@ public class DevToolsPooledDataSourceAutoConfigurationTests ...@@ -57,4 +57,70 @@ public class DevToolsPooledDataSourceAutoConfigurationTests
verify(statement, times(0)).execute("SHUTDOWN"); verify(statement, times(0)).execute("SHUTDOWN");
} }
@Test
public void h2ServerIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.h2.Driver",
"jdbc:h2:hsql://localhost", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void inMemoryh2IsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.h2.Driver",
"jdbc:h2:mem:test", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
}
@Test
public void hsqlServerIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:hsql://localhost", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void inMemoryHsqlIsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:mem:test", DataSourceAutoConfiguration.class,
DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
}
@Test
public void derbyClientIsNotShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext(
"org.apache.derby.jdbc.ClientDriver", "jdbc:derby://localhost",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
context.close();
verify(statement, times(0)).execute("SHUTDOWN");
}
@Test
public void inMemoryDerbyIsShutdown() throws SQLException {
ConfigurableApplicationContext context = createContext(
"org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:test",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class);
Statement statement = configureDataSourceBehaviour(
context.getBean(DataSource.class));
context.close();
verify(statement, times(1)).execute("SHUTDOWN");
}
} }
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