Apply eclipse formatting rules to 3dc932db
This commit is contained in:
@@ -24,7 +24,8 @@ import javax.sql.DataSource;
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public abstract class AbstractDataSourceMetadata<D extends DataSource> implements DataSourceMetadata {
|
||||
public abstract class AbstractDataSourceMetadata<D extends DataSource> implements
|
||||
DataSourceMetadata {
|
||||
|
||||
private final D dataSource;
|
||||
|
||||
@@ -55,7 +56,7 @@ public abstract class AbstractDataSourceMetadata<D extends DataSource> implement
|
||||
}
|
||||
|
||||
protected final D getDataSource() {
|
||||
return dataSource;
|
||||
return this.dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ package org.springframework.boot.autoconfigure.jdbc;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
|
||||
/**
|
||||
* A {@link DataSourceMetadata} implementation for the commons dbcp
|
||||
* data source.
|
||||
* A {@link DataSourceMetadata} implementation for the commons dbcp data source.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public class CommonsDbcpDataSourceMetadata extends AbstractDataSourceMetadata<BasicDataSource> {
|
||||
public class CommonsDbcpDataSourceMetadata extends
|
||||
AbstractDataSourceMetadata<BasicDataSource> {
|
||||
|
||||
public CommonsDbcpDataSourceMetadata(BasicDataSource dataSource) {
|
||||
super(dataSource);
|
||||
@@ -50,4 +50,5 @@ public class CommonsDbcpDataSourceMetadata extends AbstractDataSourceMetadata<Ba
|
||||
public String getValidationQuery() {
|
||||
return getDataSource().getValidationQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ public class CompositeDataSourceMetadataProvider implements DataSourceMetadataPr
|
||||
/**
|
||||
* Create an instance with an initial collection of delegates to use.
|
||||
*/
|
||||
public CompositeDataSourceMetadataProvider(Collection<DataSourceMetadataProvider> providers) {
|
||||
public CompositeDataSourceMetadataProvider(
|
||||
Collection<DataSourceMetadataProvider> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
@@ -48,8 +49,9 @@ public class CompositeDataSourceMetadataProvider implements DataSourceMetadataPr
|
||||
|
||||
@Override
|
||||
public DataSourceMetadata getDataSourceMetadata(DataSource dataSource) {
|
||||
for (DataSourceMetadataProvider provider : providers) {
|
||||
DataSourceMetadata dataSourceMetadata = provider.getDataSourceMetadata(dataSource);
|
||||
for (DataSourceMetadataProvider provider : this.providers) {
|
||||
DataSourceMetadata dataSourceMetadata = provider
|
||||
.getDataSourceMetadata(dataSource);
|
||||
if (dataSourceMetadata != null) {
|
||||
return dataSourceMetadata;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,8 @@ package org.springframework.boot.autoconfigure.jdbc;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Provide various metadata regarding a {@link DataSource} that
|
||||
* are shared by most data source types but not accessible in a
|
||||
* standard manner.
|
||||
* Provide various metadata regarding a {@link DataSource} that are shared by most data
|
||||
* source types but not accessible in a standard manner.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
@@ -29,44 +28,39 @@ import javax.sql.DataSource;
|
||||
public interface DataSourceMetadata {
|
||||
|
||||
/**
|
||||
* Return the usage of the pool as a double value between
|
||||
* 0 and 1.
|
||||
* Return the usage of the pool as a double value between 0 and 1.
|
||||
* <ul>
|
||||
* <li>1 means that the maximum number of connections
|
||||
* have been allocated</li>
|
||||
* <li>1 means that the maximum number of connections have been allocated</li>
|
||||
* <li>0 means that no connection is currently active</li>
|
||||
* <li>-1 means there is not limit to the number of connections
|
||||
* that can be allocated</li>
|
||||
* <li>-1 means there is not limit to the number of connections that can be allocated</li>
|
||||
* </ul>
|
||||
* This may also return {@code null} if the data source does
|
||||
* not provide the necessary information to compute the poll usage.
|
||||
* This may also return {@code null} if the data source does not provide the necessary
|
||||
* information to compute the poll usage.
|
||||
*/
|
||||
Float getPoolUsage();
|
||||
|
||||
/**
|
||||
* Return the current number of active connections that
|
||||
* have been allocated from the data source or {@code null}
|
||||
* if that information is not available.
|
||||
* Return the current number of active connections that have been allocated from the
|
||||
* data source or {@code null} if that information is not available.
|
||||
*/
|
||||
Integer getPoolSize();
|
||||
|
||||
/**
|
||||
* Return the maximum number of active connections that can be
|
||||
* allocated at the same time or {@code -1} if there is no
|
||||
* limit. Can also return {@code null} if that information is
|
||||
* not available.
|
||||
* Return the maximum number of active connections that can be allocated at the same
|
||||
* time or {@code -1} if there is no limit. Can also return {@code null} if that
|
||||
* information is not available.
|
||||
*/
|
||||
Integer getMaxPoolSize();
|
||||
|
||||
/**
|
||||
* Return the minimum number of idle connections in the pool
|
||||
* or {@code null} if that information is not available.
|
||||
* Return the minimum number of idle connections in the pool or {@code null} if that
|
||||
* information is not available.
|
||||
*/
|
||||
Integer getMinPoolSize();
|
||||
|
||||
/**
|
||||
* Return the query to use to validate that a connection is
|
||||
* valid or {@code null} if that information is not available.
|
||||
* Return the query to use to validate that a connection is valid or {@code null} if
|
||||
* that information is not available.
|
||||
*/
|
||||
String getValidationQuery();
|
||||
|
||||
|
||||
@@ -27,9 +27,8 @@ import javax.sql.DataSource;
|
||||
public interface DataSourceMetadataProvider {
|
||||
|
||||
/**
|
||||
* Return the {@link DataSourceMetadata} instance able to manage the
|
||||
* specified {@link DataSource} or {@code null} if the given data
|
||||
* source could not be handled.
|
||||
* Return the {@link DataSourceMetadata} instance able to manage the specified
|
||||
* {@link DataSource} or {@code null} if the given data source could not be handled.
|
||||
*/
|
||||
DataSourceMetadata getDataSourceMetadata(DataSource dataSource);
|
||||
|
||||
|
||||
@@ -18,16 +18,16 @@ package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
||||
/**
|
||||
* Register the {@link DataSourceMetadataProvider} instances for the supported
|
||||
* data sources.
|
||||
* Register the {@link DataSourceMetadataProvider} instances for the supported data
|
||||
* sources.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
@@ -45,12 +45,14 @@ public class DataSourceMetadataProvidersConfiguration {
|
||||
@Override
|
||||
public DataSourceMetadata getDataSourceMetadata(DataSource dataSource) {
|
||||
if (dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource) {
|
||||
return new TomcatDataSourceMetadata((org.apache.tomcat.jdbc.pool.DataSource) dataSource);
|
||||
return new TomcatDataSourceMetadata(
|
||||
(org.apache.tomcat.jdbc.pool.DataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -69,6 +71,7 @@ public class DataSourceMetadataProvidersConfiguration {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -81,12 +84,14 @@ public class DataSourceMetadataProvidersConfiguration {
|
||||
@Override
|
||||
public DataSourceMetadata getDataSourceMetadata(DataSource dataSource) {
|
||||
if (dataSource instanceof BasicDataSource) {
|
||||
return new CommonsDbcpDataSourceMetadata((BasicDataSource) dataSource);
|
||||
return new CommonsDbcpDataSourceMetadata(
|
||||
(BasicDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,21 +16,20 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import com.zaxxer.hikari.pool.HikariPool;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import com.zaxxer.hikari.pool.HikariPool;
|
||||
|
||||
/**
|
||||
* A {@link DataSourceMetadata} implementation for the hikari
|
||||
* data source.
|
||||
* A {@link DataSourceMetadata} implementation for the hikari data source.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public class HikariDataSourceMetadata extends AbstractDataSourceMetadata<HikariDataSource> {
|
||||
|
||||
public class HikariDataSourceMetadata extends
|
||||
AbstractDataSourceMetadata<HikariDataSource> {
|
||||
|
||||
private final HikariPoolProvider hikariPoolProvider;
|
||||
|
||||
@@ -41,13 +40,14 @@ public class HikariDataSourceMetadata extends AbstractDataSourceMetadata<HikariD
|
||||
|
||||
@Override
|
||||
public Integer getPoolSize() {
|
||||
HikariPool hikariPool = hikariPoolProvider.getHikariPool();
|
||||
HikariPool hikariPool = this.hikariPoolProvider.getHikariPool();
|
||||
if (hikariPool != null) {
|
||||
return hikariPool.getActiveConnections();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMaxPoolSize() {
|
||||
return getDataSource().getMaximumPoolSize();
|
||||
}
|
||||
@@ -63,9 +63,9 @@ public class HikariDataSourceMetadata extends AbstractDataSourceMetadata<HikariD
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the {@link HikariPool} instance managed internally by
|
||||
* the {@link HikariDataSource} as there is no other way to retrieve
|
||||
* that information except JMX access.
|
||||
* Provide the {@link HikariPool} instance managed internally by the
|
||||
* {@link HikariDataSource} as there is no other way to retrieve that information
|
||||
* except JMX access.
|
||||
*/
|
||||
private static class HikariPoolProvider {
|
||||
private final HikariDataSource dataSource;
|
||||
@@ -78,7 +78,7 @@ public class HikariDataSourceMetadata extends AbstractDataSourceMetadata<HikariD
|
||||
}
|
||||
|
||||
public HikariPool getHikariPool() {
|
||||
if (!poolAvailable) {
|
||||
if (!this.poolAvailable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* A {@link DataSourceMetadata} implementation for the tomcat
|
||||
* data source.
|
||||
* A {@link DataSourceMetadata} implementation for the tomcat data source.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -52,4 +51,5 @@ public class TomcatDataSourceMetadata extends AbstractDataSourceMetadata<DataSou
|
||||
public String getValidationQuery() {
|
||||
return getDataSource().getValidationQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,19 +16,17 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.ConnectionCallback;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractDataSourceMetadataTests<D extends AbstractDataSourceMetadata> {
|
||||
@@ -51,10 +49,12 @@ public abstract class AbstractDataSourceMetadataTests<D extends AbstractDataSour
|
||||
@Test
|
||||
public void getPoolSizeNoConnection() {
|
||||
// Make sure the pool is initialized
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata()
|
||||
.getDataSource());
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
|
||||
public Void doInConnection(Connection connection) throws SQLException,
|
||||
DataAccessException {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -64,10 +64,12 @@ public abstract class AbstractDataSourceMetadataTests<D extends AbstractDataSour
|
||||
|
||||
@Test
|
||||
public void getPoolSizeOneConnection() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata()
|
||||
.getDataSource());
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
|
||||
public Void doInConnection(Connection connection) throws SQLException,
|
||||
DataAccessException {
|
||||
assertEquals(Integer.valueOf(1), getDataSourceMetadata().getPoolSize());
|
||||
assertEquals(Float.valueOf(0.5F), getDataSourceMetadata().getPoolUsage());
|
||||
return null;
|
||||
@@ -77,15 +79,20 @@ public abstract class AbstractDataSourceMetadataTests<D extends AbstractDataSour
|
||||
|
||||
@Test
|
||||
public void getPoolSizeTwoConnections() {
|
||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
|
||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata()
|
||||
.getDataSource());
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
|
||||
public Void doInConnection(Connection connection) throws SQLException,
|
||||
DataAccessException {
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
|
||||
assertEquals(Integer.valueOf(2), getDataSourceMetadata().getPoolSize());
|
||||
assertEquals(Float.valueOf(1F), getDataSourceMetadata().getPoolUsage());
|
||||
public Void doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
assertEquals(Integer.valueOf(2), getDataSourceMetadata()
|
||||
.getPoolSize());
|
||||
assertEquals(Float.valueOf(1F), getDataSourceMetadata()
|
||||
.getPoolUsage());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -98,10 +105,8 @@ public abstract class AbstractDataSourceMetadataTests<D extends AbstractDataSour
|
||||
public abstract void getValidationQuery();
|
||||
|
||||
protected DataSourceBuilder initializeBuilder() {
|
||||
return DataSourceBuilder.create()
|
||||
.driverClassName("org.hsqldb.jdbc.JDBCDriver")
|
||||
.url("jdbc:hsqldb:mem:test")
|
||||
.username("sa");
|
||||
return DataSourceBuilder.create().driverClassName("org.hsqldb.jdbc.JDBCDriver")
|
||||
.url("jdbc:hsqldb:mem:test").username("sa");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,17 +16,18 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CommonsDbcpDataSourceMetadataTests extends AbstractDataSourceMetadataTests<CommonsDbcpDataSourceMetadata> {
|
||||
public class CommonsDbcpDataSourceMetadataTests extends
|
||||
AbstractDataSourceMetadataTests<CommonsDbcpDataSourceMetadata> {
|
||||
|
||||
private CommonsDbcpDataSourceMetadata dataSourceMetadata;
|
||||
|
||||
@@ -42,7 +43,8 @@ public class CommonsDbcpDataSourceMetadataTests extends AbstractDataSourceMetada
|
||||
|
||||
@Test
|
||||
public void getPoolUsageWithNoCurrent() {
|
||||
CommonsDbcpDataSourceMetadata dsm = new CommonsDbcpDataSourceMetadata(createDataSource()) {
|
||||
CommonsDbcpDataSourceMetadata dsm = new CommonsDbcpDataSourceMetadata(
|
||||
createDataSource()) {
|
||||
@Override
|
||||
public Integer getPoolSize() {
|
||||
return null;
|
||||
@@ -53,7 +55,8 @@ public class CommonsDbcpDataSourceMetadataTests extends AbstractDataSourceMetada
|
||||
|
||||
@Test
|
||||
public void getPoolUsageWithNoMax() {
|
||||
CommonsDbcpDataSourceMetadata dsm = new CommonsDbcpDataSourceMetadata(createDataSource()) {
|
||||
CommonsDbcpDataSourceMetadata dsm = new CommonsDbcpDataSourceMetadata(
|
||||
createDataSource()) {
|
||||
@Override
|
||||
public Integer getMaxPoolSize() {
|
||||
return null;
|
||||
@@ -72,10 +75,12 @@ public class CommonsDbcpDataSourceMetadataTests extends AbstractDataSourceMetada
|
||||
public void getValidationQuery() {
|
||||
BasicDataSource dataSource = createDataSource();
|
||||
dataSource.setValidationQuery("SELECT FROM FOO");
|
||||
assertEquals("SELECT FROM FOO", new CommonsDbcpDataSourceMetadata(dataSource).getValidationQuery());
|
||||
assertEquals("SELECT FROM FOO",
|
||||
new CommonsDbcpDataSourceMetadata(dataSource).getValidationQuery());
|
||||
}
|
||||
|
||||
private CommonsDbcpDataSourceMetadata createDataSourceMetadata(int minSize, int maxSize) {
|
||||
private CommonsDbcpDataSourceMetadata createDataSourceMetadata(int minSize,
|
||||
int maxSize) {
|
||||
BasicDataSource dataSource = createDataSource();
|
||||
dataSource.setMinIdle(minSize);
|
||||
dataSource.setMaxActive(maxSize);
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -28,8 +25,11 @@ import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CompositeDataSourceMetadataProviderTests {
|
||||
@@ -55,30 +55,30 @@ public class CompositeDataSourceMetadataProviderTests {
|
||||
@Mock
|
||||
private DataSource unknownDataSource;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(firstProvider.getDataSourceMetadata(firstDataSource)).willReturn(first);
|
||||
given(firstProvider.getDataSourceMetadata(secondDataSource)).willReturn(second);
|
||||
given(this.firstProvider.getDataSourceMetadata(this.firstDataSource)).willReturn(
|
||||
this.first);
|
||||
given(this.firstProvider.getDataSourceMetadata(this.secondDataSource))
|
||||
.willReturn(this.second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithProviders() {
|
||||
CompositeDataSourceMetadataProvider provider =
|
||||
new CompositeDataSourceMetadataProvider(Arrays.asList(firstProvider, secondProvider));
|
||||
assertSame(first, provider.getDataSourceMetadata(firstDataSource));
|
||||
assertSame(second, provider.getDataSourceMetadata(secondDataSource));
|
||||
assertNull(provider.getDataSourceMetadata(unknownDataSource));
|
||||
CompositeDataSourceMetadataProvider provider = new CompositeDataSourceMetadataProvider(
|
||||
Arrays.asList(this.firstProvider, this.secondProvider));
|
||||
assertSame(this.first, provider.getDataSourceMetadata(this.firstDataSource));
|
||||
assertSame(this.second, provider.getDataSourceMetadata(this.secondDataSource));
|
||||
assertNull(provider.getDataSourceMetadata(this.unknownDataSource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addProvider() {
|
||||
CompositeDataSourceMetadataProvider provider =
|
||||
new CompositeDataSourceMetadataProvider();
|
||||
assertNull(provider.getDataSourceMetadata(firstDataSource));
|
||||
provider.addDataSourceMetadataProvider(firstProvider);
|
||||
assertSame(first, provider.getDataSourceMetadata(firstDataSource));
|
||||
CompositeDataSourceMetadataProvider provider = new CompositeDataSourceMetadataProvider();
|
||||
assertNull(provider.getDataSourceMetadata(this.firstDataSource));
|
||||
provider.addDataSourceMetadataProvider(this.firstProvider);
|
||||
assertSame(this.first, provider.getDataSourceMetadata(this.firstDataSource));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,21 +16,23 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.Before;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class HikariDataSourceMetadataTests extends AbstractDataSourceMetadataTests<HikariDataSourceMetadata> {
|
||||
public class HikariDataSourceMetadataTests extends
|
||||
AbstractDataSourceMetadataTests<HikariDataSourceMetadata> {
|
||||
|
||||
private HikariDataSourceMetadata dataSourceMetadata;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.dataSourceMetadata = new HikariDataSourceMetadata(createDataSource(0, 2));
|
||||
this.dataSourceMetadata = new HikariDataSourceMetadata(createDataSource(0, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,11 +44,13 @@ public class HikariDataSourceMetadataTests extends AbstractDataSourceMetadataTes
|
||||
public void getValidationQuery() {
|
||||
HikariDataSource dataSource = createDataSource(0, 4);
|
||||
dataSource.setConnectionTestQuery("SELECT FROM FOO");
|
||||
assertEquals("SELECT FROM FOO", new HikariDataSourceMetadata(dataSource).getValidationQuery());
|
||||
assertEquals("SELECT FROM FOO",
|
||||
new HikariDataSourceMetadata(dataSource).getValidationQuery());
|
||||
}
|
||||
|
||||
private HikariDataSource createDataSource(int minSize, int maxSize) {
|
||||
HikariDataSource dataSource = (HikariDataSource) initializeBuilder().type(HikariDataSource.class).build();
|
||||
HikariDataSource dataSource = (HikariDataSource) initializeBuilder().type(
|
||||
HikariDataSource.class).build();
|
||||
dataSource.setMinimumIdle(minSize);
|
||||
dataSource.setMaximumPoolSize(maxSize);
|
||||
return dataSource;
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.junit.Before;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class TomcatDataSourceMetadataTests extends AbstractDataSourceMetadataTests<TomcatDataSourceMetadata> {
|
||||
public class TomcatDataSourceMetadataTests extends
|
||||
AbstractDataSourceMetadataTests<TomcatDataSourceMetadata> {
|
||||
|
||||
private TomcatDataSourceMetadata dataSourceMetadata;
|
||||
|
||||
@@ -43,11 +43,13 @@ public class TomcatDataSourceMetadataTests extends AbstractDataSourceMetadataTes
|
||||
public void getValidationQuery() {
|
||||
DataSource dataSource = createDataSource(0, 4);
|
||||
dataSource.setValidationQuery("SELECT FROM FOO");
|
||||
assertEquals("SELECT FROM FOO", new TomcatDataSourceMetadata(dataSource).getValidationQuery());
|
||||
assertEquals("SELECT FROM FOO",
|
||||
new TomcatDataSourceMetadata(dataSource).getValidationQuery());
|
||||
}
|
||||
|
||||
private DataSource createDataSource(int minSize, int maxSize) {
|
||||
DataSource dataSource = (DataSource) initializeBuilder().type(DataSource.class).build();
|
||||
DataSource dataSource = (DataSource) initializeBuilder().type(DataSource.class)
|
||||
.build();
|
||||
dataSource.setMinIdle(minSize);
|
||||
dataSource.setMaxActive(maxSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user