Fixes to get dbcp-related tests pass on the CI system

- Prefer dbcp2 over dbcp
 - Break PooledDataSourceCreatorsTest into multiple small tests
 - Revert Java compatiblity to 1.6
This commit is contained in:
Ramnivas Laddad
2014-03-13 10:39:13 -07:00
parent b8fc8ea1b7
commit e3adddd8b5
4 changed files with 38 additions and 37 deletions

View File

@@ -44,8 +44,8 @@ subprojects {
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.6
targetCompatibility = 1.6
task packageSources(type: Jar) {
classifier = 'sources'

View File

@@ -20,14 +20,12 @@ dependencies {
optional("org.apache.tomcat:tomcat-dbcp:$tomcatVersion")
optional("org.apache.commons:commons-dbcp2:$commonDbcp2Version") {
exclude(module: 'commons-logging')
exclude(module: 'commons-pool')
exclude(module: 'xerces')
exclude(module: 'xercesImpl')
exclude(module: 'xml-apis')
}
optional("commons-dbcp:commons-dbcp:$commonDbcpVersion") {
exclude(module: 'commons-logging')
exclude(module: 'commons-pool')
exclude(module: 'xerces')
exclude(module: 'xercesImpl')
exclude(module: 'xml-apis')

View File

@@ -15,22 +15,21 @@ import org.springframework.cloud.service.common.RelationalServiceInfo;
*/
public class BasicDbcpPooledDataSourceCreator<SI extends RelationalServiceInfo> extends DbcpLikePooledDataSourceCreator<SI> {
@Override
public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig,
String driverClassName, String validationQuery) {
if (hasClass("org.apache.commons.dbcp.BasicDataSource")) {
logger.info("Found DBCP on the classpath. Using it for DataSource connection pooling.");
org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery);
return ds;
} else if (hasClass("org.apache.commons.dbcp2.BasicDataSource")) {
logger.info("Found DBCP on the classpath. Using it for DataSource connection pooling.");
org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource();
setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery);
return ds;
} else {
return null;
}
}
@Override
public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig,
String driverClassName, String validationQuery) {
if (hasClass("org.apache.commons.dbcp2.BasicDataSource")) {
logger.info("Found DBCP2 on the classpath. Using it for DataSource connection pooling.");
org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource();
setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery);
return ds;
} else if (hasClass("org.apache.commons.dbcp.BasicDataSource")) {
logger.info("Found DBCP on the classpath. Using it for DataSource connection pooling.");
org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery);
return ds;
} else {
return null;
}
}
}

View File

@@ -1,8 +1,5 @@
package org.springframework.cloud.service.relational;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.junit.Assert;
@@ -24,19 +21,26 @@ public class PooledDataSourceCreatorsTest {
}
@Test
public void pooledDataSourceCreation() {
List<PooledDataSourceCreator<MysqlServiceInfo>> pooledDataSourceCreators = new ArrayList<PooledDataSourceCreator<MysqlServiceInfo>>();
public void pooledDataSourceCreationDbcp() {
assertPooledDataSource(new BasicDbcpPooledDataSourceCreator<MysqlServiceInfo>());
}
pooledDataSourceCreators.add(new BasicDbcpPooledDataSourceCreator<MysqlServiceInfo>());
pooledDataSourceCreators.add(new TomcatDbcpPooledDataSourceCreator<MysqlServiceInfo>());
pooledDataSourceCreators.add(new TomcatHighPerformancePooledDataSourceCreator<MysqlServiceInfo>());
@Test
public void pooledDataSourceCreationTomcatDbcp() {
assertPooledDataSource(new TomcatDbcpPooledDataSourceCreator<MysqlServiceInfo>());
}
@Test
public void pooledDataSourceCreationTomcatHighPerformance() {
assertPooledDataSource(new TomcatHighPerformancePooledDataSourceCreator<MysqlServiceInfo>());
}
private void assertPooledDataSource(PooledDataSourceCreator<MysqlServiceInfo> testCreator) {
DataSource ds = testCreator.create(mockMysqlServiceInfo, null,
mysqlDataSourceCreator.getDriverClassName(mockMysqlServiceInfo),
"select 1");
Assert.assertNotNull("Failed to create datasource with " + testCreator.getClass().getSimpleName(), ds);
for (PooledDataSourceCreator<MysqlServiceInfo> testCreator : pooledDataSourceCreators) {
DataSource ds = testCreator.create(mockMysqlServiceInfo, null,
mysqlDataSourceCreator.getDriverClassName(mockMysqlServiceInfo),
"select 1");
Assert.assertNotNull("Failed to create datasource with " + testCreator.getClass().getSimpleName(), ds);
}
}
}