code format

This commit is contained in:
wenshao
2011-11-16 14:07:08 +08:00
parent 146bcd728c
commit bb57f86db1
157 changed files with 888 additions and 912 deletions
@@ -44,100 +44,103 @@ public class ConnectionTest extends TestCase {
public void test_prepare() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
stmt.close();
conn.close();
}
public void test_prepare2() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.close();
conn.close();
}
public void test_prepare3() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", new int[0]);
stmt.close();
conn.close();
}
public void test_prepare4() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", new String[0]);
stmt.close();
conn.close();
}
public void test_prepare5() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS);
stmt.close();
conn.close();
}
public void test_prepareCall() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareCall("SELECT 1");
stmt.close();
conn.close();
}
public void test_prepareCall1() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
stmt.close();
conn.close();
}
public void test_prepareCall2() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.close();
conn.close();
}
public void test_create() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.close();
conn.close();
}
public void test_create1() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
stmt.close();
conn.close();
}
public void test_create2() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
Statement stmt = conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.close();
conn.close();
}
}
@@ -47,100 +47,103 @@ public class ConnectionTest2 extends TestCase {
public void test_prepare() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
stmt.close();
conn.close();
}
public void test_prepare2() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.close();
conn.close();
}
public void test_prepare3() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", new int[0]);
stmt.close();
conn.close();
}
public void test_prepare4() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", new String[0]);
stmt.close();
conn.close();
}
public void test_prepare5() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS);
stmt.close();
conn.close();
}
public void test_prepareCall() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareCall("SELECT 1");
stmt.close();
conn.close();
}
public void test_prepareCall1() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
stmt.close();
conn.close();
}
public void test_prepareCall2() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.close();
conn.close();
}
public void test_create() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.close();
conn.close();
}
public void test_create1() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
stmt.close();
conn.close();
}
public void test_create2() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
Statement stmt = conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
stmt.close();
conn.close();
}
}
@@ -37,7 +37,7 @@ public class ConnectionTest3 extends TestCase {
dataSource.setTestOnBorrow(false);
dataSource.setValidationQuery("SELECT 1");
dataSource.setFilters("stat,trace");
JdbcStatContext context = new JdbcStatContext();
context.setTraceEnable(true);
JdbcStatManager.getInstance().setStatContext(context);
@@ -46,32 +46,32 @@ public class ConnectionTest3 extends TestCase {
protected void tearDown() throws Exception {
dataSource.close();
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
JdbcStatManager.getInstance().setStatContext(null);
}
public void test_basic() throws Exception {
PoolableConnection conn = (PoolableConnection) dataSource.getConnection();
conn.getTransactionInfo();
conn.getMetaData();
conn.setReadOnly(true);
Assert.assertEquals(true, conn.isReadOnly());
conn.setCatalog("xxx");
Assert.assertEquals("xxx", conn.getCatalog());
conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
Assert.assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn.getTransactionIsolation());
conn.getWarnings();
conn.clearWarnings();
conn.getTypeMap();
conn.setTypeMap(null);
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
Assert.assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
conn.setSavepoint();
conn.setSavepoint("savepoint");
conn.rollback();
@@ -86,17 +86,16 @@ public class ConnectionTest3 extends TestCase {
conn.setClientInfo("xx", "11");
conn.getClientInfo("xx");
conn.getClientInfo();
conn.createArrayOf("int", new Object[0]);
conn.createStruct("int", new Object[0]);
conn.addConnectionEventListener(null);
conn.removeConnectionEventListener(null);
conn.addStatementEventListener(null);
conn.removeStatementEventListener(null);
conn.close();
}
}
@@ -65,11 +65,11 @@ public class ConnectionTest4 extends TestCase {
Assert.assertEquals(false, conn.isWrapperFor(null));
Assert.assertEquals(true, conn.isWrapperFor(PoolableConnection.class));
Assert.assertEquals(true, conn.isWrapperFor(Connection.class));
Assert.assertEquals("SELECT 1", conn.nativeSQL("SELECT 1"));
conn.toString();
conn.close();
conn.toString();
}
@@ -403,7 +403,7 @@ public class ConnectionTest4 extends TestCase {
conn.getConnectionHolder().toString();
conn.getConnectionHolder().getUseCount();
conn.getConnectionHolder().getTimeMillis();
conn.close();
}
@@ -441,10 +441,10 @@ public class ConnectionTest4 extends TestCase {
conn.close();
}
public void test_create_2() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getConnection().close();
{
SQLException error = null;
@@ -455,13 +455,13 @@ public class ConnectionTest4 extends TestCase {
}
Assert.assertNotNull(error);
}
conn.close();
}
public void test_setAutoCommit() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getAutoCommit();
conn.setAutoCommit(true);
conn.getConnection().close();
@@ -474,13 +474,13 @@ public class ConnectionTest4 extends TestCase {
}
Assert.assertNotNull(error);
}
conn.close();
}
public void test_commit() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getConnection().close();
{
SQLException error = null;
@@ -491,17 +491,17 @@ public class ConnectionTest4 extends TestCase {
}
Assert.assertNotNull(error);
}
conn.close();
}
public void test_rollback() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1");
conn.getConnection().close();
{
SQLException error = null;
@@ -512,13 +512,13 @@ public class ConnectionTest4 extends TestCase {
}
Assert.assertNotNull(error);
}
conn.close();
}
public void test_rollback_1() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getConnection().close();
{
SQLException error = null;
@@ -529,13 +529,13 @@ public class ConnectionTest4 extends TestCase {
}
Assert.assertNotNull(error);
}
conn.close();
}
public void test_releaseSavepoint_1() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getConnection().close();
{
SQLException error = null;
@@ -546,13 +546,13 @@ public class ConnectionTest4 extends TestCase {
}
Assert.assertNotNull(error);
}
conn.close();
}
public void test_addListenerError() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
@@ -564,10 +564,10 @@ public class ConnectionTest4 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_addListenerError2() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
@@ -579,10 +579,10 @@ public class ConnectionTest4 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_removeConnectionEventListener() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
@@ -594,10 +594,10 @@ public class ConnectionTest4 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_removeStatementEventListener() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
@@ -609,10 +609,10 @@ public class ConnectionTest4 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_checkOpen_error() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
@@ -98,7 +98,7 @@ public class ConnectionTest5 extends TestCase {
conn.close();
}
public void test_handleException_3() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getConnection().close();
@@ -115,7 +115,7 @@ public class ConnectionTest5 extends TestCase {
conn.close();
}
public void test_handleException_4() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.getConnection().close();
@@ -132,24 +132,24 @@ public class ConnectionTest5 extends TestCase {
Assert.assertEquals(true, conn.isClosed());
}
public void test_handleException_5() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.addConnectionEventListener(new ConnectionEventListener() {
@Override
public void connectionClosed(ConnectionEvent event) {
}
@Override
public void connectionErrorOccurred(ConnectionEvent event) {
}
});
conn.close();
{
SQLException error = null;
try {
@@ -159,11 +159,9 @@ public class ConnectionTest5 extends TestCase {
}
Assert.assertNotNull(error);
}
}
public void test_setClientInfo() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
@@ -179,11 +177,11 @@ public class ConnectionTest5 extends TestCase {
}
}
public void test_setClientInfo_1() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
SQLException error = null;
try {
@@ -193,6 +191,6 @@ public class ConnectionTest5 extends TestCase {
}
Assert.assertNotNull(error);
}
}
}
@@ -317,17 +317,17 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_setExceptionSorter() throws Exception {
dataSource.setExceptionSorter(NullExceptionSorter.class.getName());
}
public void test_setProxyFilters() throws Exception {
dataSource.setProxyFilters(null);
dataSource.setFilters(null);
dataSource.setFilters("");
}
public void test_error_validateConnection() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
@@ -343,7 +343,7 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_validateConnection_2() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
@@ -359,7 +359,7 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_validateConnection_3() throws Exception {
dataSource.setValidationQuery(null);
dataSource.setValidConnectionChecker(new MySqlValidConnectionChecker());
@@ -12,34 +12,36 @@ import org.junit.Assert;
import com.alibaba.druid.pool.DruidDataSourceFactory;
public class DruidDataSourceFactoryTest extends TestCase {
@SuppressWarnings("serial")
public void test_factory() throws Exception {
DruidDataSourceFactory factory = new DruidDataSourceFactory();
Assert.assertNull(factory.getObjectInstance(null, null, null, null));
Assert.assertNull(factory.getObjectInstance(new Reference("javax.sql.Date"), null, null, null));
Reference ref = new Reference("javax.sql.DataSource");
ref.add(new RefAddr("user") {
@Override
public Object getContent() {
return null;
}
});
ref.add(new RefAddr("defaultReadOnly") {
@Override
public Object getContent() {
return Boolean.TRUE;
}
});
factory.getObjectInstance(ref, null, null, new Hashtable<Object, Object>());
}
public void test_createDataSource() throws Exception {
Properties properties = new Properties();
properties.setProperty("defaultAutoCommit", "true");
@@ -74,7 +76,7 @@ public class DruidDataSourceFactoryTest extends TestCase {
properties.setProperty("filters", "stat;trace");
properties.setProperty("exceptionSorter", "com.alibaba.druid.pool.vendor.NullExceptionSorter");
properties.setProperty("exception-sorter-class-name", "com.alibaba.druid.pool.vendor.NullExceptionSorter");
DruidDataSourceFactory.createDataSource(properties);
}
}
@@ -28,7 +28,8 @@ public class PoolableCallableStatementTest extends TestCase {
protected void setUp() throws Exception {
raw = new MockCallableStatement(null, null);
stmt = new PoolableCallableStatement(null, new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
stmt = new PoolableCallableStatement(null,
new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -2067,12 +2068,12 @@ public class PoolableCallableStatementTest extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_registerOutParameter_2() throws Exception {
stmt.registerOutParameter(1, Types.INTEGER);
stmt.registerOutParameter("1", Types.INTEGER);
{
SQLException error = null;
try {
@@ -2082,7 +2083,7 @@ public class PoolableCallableStatementTest extends TestCase {
}
Assert.assertNotNull(error);
}
{
SQLException error = null;
try {
@@ -24,7 +24,8 @@ public class PoolablePreparedStatementTest extends TestCase {
protected void setUp() throws Exception {
raw = new MockPreparedStatement(null, null);
stmt = new PoolablePreparedStatement(null, new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
stmt = new PoolablePreparedStatement(null,
new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -309,7 +310,6 @@ public class PoolablePreparedStatementTest extends TestCase {
}
}
public void test_updateCharacterStream_2() throws Exception {
stmt.setCharacterStream(1, (Reader) null, 1L);
@@ -324,7 +324,7 @@ public class PoolablePreparedStatementTest extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_setRef() throws Exception {
stmt.setRef(1, null);
@@ -339,11 +339,11 @@ public class PoolablePreparedStatementTest extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_setArray() throws Exception {
stmt.setArray(1, null);
{
SQLException error = null;
try {
@@ -11,14 +11,15 @@ import org.junit.Assert;
import com.alibaba.druid.mock.MockStatement;
import com.alibaba.druid.pool.PoolableStatement;
public class PoolableStatementTest extends TestCase {
protected Statement raw;
protected Statement raw;
protected PoolableStatement stmt;
protected void setUp() throws Exception {
raw = new MockStatement(null);
stmt = new PoolableStatement(null, raw) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
return (SQLException) error;
@@ -28,11 +29,11 @@ public class PoolableStatementTest extends TestCase {
}
};
}
protected void tearDown() throws Exception {
}
public void test_basic() throws Exception {
Assert.assertEquals(raw, stmt.getStatement());
Assert.assertEquals(null, stmt.getPoolableConnection());
@@ -40,6 +41,5 @@ public class PoolableStatementTest extends TestCase {
Assert.assertEquals(false, stmt.isPoolable());
stmt.toString();
}
}
@@ -47,7 +47,7 @@ public class PoolableStatementTest2 extends TestCase {
Assert.assertTrue(dataSource.getExceptionSorter() instanceof NullExceptionSorter);
dataSource.setExceptionSorterClassName("");
Assert.assertTrue(dataSource.getExceptionSorter() instanceof NullExceptionSorter);
JdbcStatContext context = new JdbcStatContext();
context.setTraceEnable(true);
JdbcStatManager.getInstance().setStatContext(context);
@@ -552,14 +552,14 @@ public class PoolableStatementTest2 extends TestCase {
stmt.close();
conn.close();
}
public void test_executeBatch() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeBatch();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -569,18 +569,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_getMoreResults_1() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.getMoreResults(1);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -590,18 +590,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_getGeneratedKeys() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.getGeneratedKeys();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -611,7 +611,7 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
@@ -619,10 +619,10 @@ public class PoolableStatementTest2 extends TestCase {
public void test_getResultSetHoldability() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.getResultSetHoldability();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -632,18 +632,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_execute() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1", new String[0]);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -653,18 +653,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_execute_1() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1", new int[0]);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -674,18 +674,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_execute_2() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1", Statement.NO_GENERATED_KEYS);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -695,18 +695,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_1() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("SELECT 1", new String[0]);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -716,18 +716,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_2() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("SELECT 1", new int[0]);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -737,18 +737,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_3() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("SELECT 1", Statement.NO_GENERATED_KEYS);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -758,18 +758,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_getMeta() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.getMetaData();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -779,18 +779,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_getParameterMetaData() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.getParameterMetaData();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -800,18 +800,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_wasNull() throws Exception {
Connection conn = dataSource.getConnection();
CallableStatement stmt = conn.prepareCall("SELELCT 1");
stmt.wasNull();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -821,18 +821,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeQuery() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.executeQuery();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -842,18 +842,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_4() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.executeQuery();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -863,18 +863,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_execute_3() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.execute();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -884,19 +884,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_clearParameters() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.clearParameters();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -906,18 +905,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_addBatch_1() throws Exception {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELELCT 1");
stmt.addBatch();
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -927,18 +926,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_5() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("SET 1", Statement.RETURN_GENERATED_KEYS);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -948,18 +947,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_6() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("SET 1", new String[0]);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -969,18 +968,18 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_executeUpdate_7() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("SET 1", new int[0]);
((PoolableStatement) stmt).getStatement().close();
{
SQLException error = null;
try {
@@ -990,18 +989,17 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
public void test_setPoolable() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.setPoolable(true);
{
SQLException error = null;
try {
@@ -1011,7 +1009,7 @@ public class PoolableStatementTest2 extends TestCase {
}
Assert.assertNotNull(error);
}
stmt.close();
conn.close();
}
@@ -11,18 +11,20 @@ public class PoolableStatementTest3 extends TestCase {
public void test_clearResultSetError() throws Exception {
final MockResultSet rs = new MockResultSet(null) {
public void close() throws SQLException {
throw new SQLException();
}
};
PoolableStatement stmt = new PoolableStatement(null, null) {
public void close() throws SQLException {
resultSetTrace.add(rs);
clearResultSet();
}
};
stmt.close();
}
}
@@ -6,19 +6,19 @@ import junit.framework.TestCase;
import com.alibaba.druid.mock.MockConnection;
import com.alibaba.druid.pool.PoolableWrapper;
public class PoolableWrapperTest extends TestCase {
public void test_isWrapper() throws Exception {
PoolableWrapper wrapper = new PoolableWrapper(new MockConnection());
Assert.assertEquals(false, wrapper.isWrapperFor(null));
Assert.assertEquals(true, wrapper.isWrapperFor(PoolableWrapper.class));
Assert.assertEquals(true, wrapper.isWrapperFor(MockConnection.class));
}
public void test_unwrap() throws Exception {
PoolableWrapper wrapper = new PoolableWrapper(new MockConnection());
Assert.assertEquals(null, wrapper.unwrap(null));
Assert.assertEquals(true, wrapper.unwrap(PoolableWrapper.class) != null);
Assert.assertEquals(true, wrapper.unwrap(MockConnection.class) != null);
@@ -13,13 +13,13 @@ import com.alibaba.druid.pool.PreparedStatementHolder;
import com.alibaba.druid.pool.PreparedStatementPool;
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
public class PreparedStatementKeyTest extends TestCase {
public void test_equals_0() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementKey k2 = new PreparedStatementKey("x1", "c2", MethodType.M1);
PreparedStatementKey k3 = new PreparedStatementKey("x1", "c3", MethodType.M1);
Assert.assertFalse(k1.equals(k2));
Assert.assertFalse(k1.equals(k3));
Assert.assertFalse(k2.equals(k1));
@@ -27,12 +27,12 @@ public class PreparedStatementKeyTest extends TestCase {
Assert.assertFalse(k3.equals(k2));
Assert.assertFalse(k3.equals(k1));
}
public void test_equals_2() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementKey k2 = new PreparedStatementKey("x2", "c1", MethodType.M1);
PreparedStatementKey k3 = new PreparedStatementKey("x3", "c1", MethodType.M1);
Assert.assertFalse(k1.equals(k2));
Assert.assertFalse(k1.equals(k3));
Assert.assertFalse(k2.equals(k1));
@@ -40,12 +40,12 @@ public class PreparedStatementKeyTest extends TestCase {
Assert.assertFalse(k3.equals(k2));
Assert.assertFalse(k3.equals(k1));
}
public void test_equals_3() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementKey k2 = new PreparedStatementKey("x1", "c1", MethodType.M2);
PreparedStatementKey k3 = new PreparedStatementKey("x1", "c1", MethodType.M3);
Assert.assertFalse(k1.equals(k2));
Assert.assertFalse(k1.equals(k3));
Assert.assertFalse(k2.equals(k1));
@@ -53,12 +53,12 @@ public class PreparedStatementKeyTest extends TestCase {
Assert.assertFalse(k3.equals(k2));
Assert.assertFalse(k3.equals(k1));
}
public void test_equals_4() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementKey k2 = new PreparedStatementKey("x1", "c2", MethodType.M1);
PreparedStatementKey k3 = new PreparedStatementKey("x1", null, MethodType.M1);
Assert.assertFalse(k1.equals(k2));
Assert.assertFalse(k1.equals(k3));
Assert.assertFalse(k2.equals(k1));
@@ -66,14 +66,14 @@ public class PreparedStatementKeyTest extends TestCase {
Assert.assertFalse(k3.equals(k2));
Assert.assertFalse(k3.equals(k1));
}
public void test_equals_5() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", null, MethodType.M1);
PreparedStatementKey k2 = new PreparedStatementKey("x1", null, MethodType.M2);
PreparedStatementKey k3 = new PreparedStatementKey("x1", null, MethodType.M3);
k1.hashCode();
Assert.assertFalse(k1.equals(k2));
Assert.assertFalse(k1.equals(k3));
Assert.assertFalse(k2.equals(k1));
@@ -81,14 +81,14 @@ public class PreparedStatementKeyTest extends TestCase {
Assert.assertFalse(k3.equals(k2));
Assert.assertFalse(k3.equals(k1));
}
public void test_equals_6() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", null, MethodType.M1);
PreparedStatementKey k2 = new PreparedStatementKey("x2", null, MethodType.M1);
PreparedStatementKey k3 = new PreparedStatementKey("x3", null, MethodType.M1);
k1.hashCode();
Assert.assertFalse(k1.equals(k2));
Assert.assertFalse(k1.equals(k3));
Assert.assertFalse(k2.equals(k1));
@@ -96,16 +96,16 @@ public class PreparedStatementKeyTest extends TestCase {
Assert.assertFalse(k3.equals(k2));
Assert.assertFalse(k3.equals(k1));
}
public void test_contains() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
MockConnection conn = new MockConnection();
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementPool pool = new PreparedStatementPool(new ConnectionHolder(dataSource, conn));
MockPreparedStatement raw = new MockPreparedStatement(null, null);
pool.put(new PreparedStatementHolder(k1, raw));
Assert.assertTrue(pool.get(k1) != null);
Assert.assertTrue(pool.get(k1) != null);
}
@@ -52,7 +52,7 @@ public class TestCommit extends TestCase {
Assert.assertTrue(conn.isWrapperFor(PoolableConnection.class));
Assert.assertNotNull(wrap);
}
{
Statement wrap = conn.unwrap(Statement.class);
Assert.assertTrue(!conn.isWrapperFor(Statement.class));
@@ -40,7 +40,7 @@ public class TestDataSourceBasic extends TestCase {
dataSource.setFilters("stat,trace");
dataSource.setRemoveAbandoned(true);
dataSource.setExceptionSorterClassName(null);
Assert.assertTrue(dataSource.getExceptionSorter() instanceof NullExceptionSorter);
dataSource.setExceptionSorterClassName("");
Assert.assertTrue(dataSource.getExceptionSorter() instanceof NullExceptionSorter);
@@ -53,7 +53,7 @@ public class TestDataSourceBasic extends TestCase {
dataSource.close();
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
}
public void test_toCompositeData() throws Exception {
Connection conn = dataSource.getConnection();
conn.close();
@@ -68,7 +68,7 @@ public class TestDataSourceBasic extends TestCase {
Assert.assertTrue(conn.isWrapperFor(PoolableConnection.class));
Assert.assertNotNull(wrap);
}
{
Statement wrap = conn.unwrap(Statement.class);
Assert.assertTrue(!conn.isWrapperFor(Statement.class));
@@ -80,7 +80,7 @@ public class TestDataSourceBasic extends TestCase {
Statement stmt = conn.createStatement();
stmt.execute("SELECT 1");
stmt.close();
Assert.assertEquals(1, dataSource.getActiveConnectionStackTrace().size());
Assert.assertEquals(1, dataSource.getActiveConnections().size());
conn.commit();
@@ -93,12 +93,12 @@ public class TestDataSourceBasic extends TestCase {
Assert.assertEquals(0, dataSource.getActiveConnectionStackTrace().size());
Assert.assertEquals(0, dataSource.getActiveConnections().size());
}
public void test_wrap() throws Exception {
Assert.assertTrue(!dataSource.isWrapperFor(Date.class));
Assert.assertTrue(!dataSource.isWrapperFor(null));
Assert.assertTrue(dataSource.isWrapperFor(DataSource.class));
Assert.assertTrue(dataSource.unwrap(Date.class) == null);
Assert.assertTrue(dataSource.unwrap(null) == null);
Assert.assertTrue(dataSource.unwrap(DataSource.class) != null);
@@ -18,30 +18,29 @@ public class TestDataSourceBasic2 extends TestCase {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setBreakAfterAcquireFailure(true);
Assert.assertEquals(true, dataSource.isBreakAfterAcquireFailure());
dataSource.setConnectionErrorRetryAttempts(234);
Assert.assertEquals(234, dataSource.getConnectionErrorRetryAttempts());
dataSource.setMaxPoolPreparedStatementPerConnectionSize(234);
Assert.assertEquals(234, dataSource.getMaxPoolPreparedStatementPerConnectionSize());
dataSource.incrementDupCloseCount();
Assert.assertEquals(1, dataSource.getDupCloseCount());
dataSource.setValidConnectionChecker(null);
dataSource.setValidConnectionCheckerClassName(null);
Assert.assertEquals(null, dataSource.getValidConnectionChecker());
dataSource.addConnectionProperty("user", "ljw");
Assert.assertEquals(1, dataSource.getConnectProperties().size());
Assert.assertEquals(0, dataSource.getConnectionInitSqls().size());
dataSource.setConnectionInitSqls(Arrays.<Object>asList("SELECT 1", null, ""));
dataSource.setConnectionInitSqls(Arrays.<Object> asList("SELECT 1", null, ""));
Assert.assertEquals(1, dataSource.getConnectionInitSqls().size());
Assert.assertEquals(30 * 1000, dataSource.getTimeBetweenConnectErrorMillis());
Assert.assertEquals(-1, dataSource.getMaxOpenPreparedStatements());
Assert.assertEquals(300, dataSource.getRemoveAbandonedTimeout());
@@ -51,62 +50,59 @@ public class TestDataSourceBasic2 extends TestCase {
Assert.assertEquals(3, dataSource.getNumTestsPerEvictionRun());
dataSource.setNumTestsPerEvictionRun(4);
Assert.assertEquals(4, dataSource.getNumTestsPerEvictionRun());
dataSource.setMaxWaitThreadCount(4);
Assert.assertEquals(4, dataSource.getMaxWaitThreadCount());
dataSource.setValidationQueryTimeout(4);
Assert.assertEquals(4, dataSource.getValidationQueryTimeout());
dataSource.setAccessToUnderlyingConnectionAllowed(true);
Assert.assertEquals(true, dataSource.isAccessToUnderlyingConnectionAllowed());
dataSource.setDefaultReadOnly(true);
Assert.assertEquals(Boolean.TRUE, dataSource.getDefaultReadOnly());
dataSource.setDefaultTransactionIsolation(10);
Assert.assertEquals(Integer.valueOf(10), dataSource.getDefaultTransactionIsolation());
dataSource.setDefaultCatalog("xxx");
Assert.assertEquals("xxx", dataSource.getDefaultCatalog());
dataSource.setPasswordCallbackClassName(null);
dataSource.setUserCallback(null);
Assert.assertEquals(0, dataSource.getQueryTimeout());
dataSource.setQueryTimeout(10001);
Assert.assertEquals(10001, dataSource.getQueryTimeout());
Assert.assertEquals(-1, dataSource.getMaxWait());
dataSource.setMaxWait(10001);
Assert.assertEquals(10001, dataSource.getMaxWait());
Assert.assertEquals(8, dataSource.getMaxIdle());
dataSource.setMaxIdle(3);
Assert.assertEquals(3, dataSource.getMaxIdle());
Assert.assertEquals(0, dataSource.getLoginTimeout());
dataSource.setLoginTimeout(30);
Assert.assertEquals(30, dataSource.getLoginTimeout());
Assert.assertEquals(null, dataSource.getUsername());
dataSource.setUsername("ljw");
Assert.assertEquals("ljw", dataSource.getUsername());
Assert.assertEquals(null, dataSource.getPassword());
dataSource.setPassword("xxx");
Assert.assertEquals("xxx", dataSource.getPassword());
dataSource.setConnectProperties(new Properties());
Assert.assertEquals(0, dataSource.getConnectProperties().size());
dataSource.setConnectionProperties("a=1;b=2;c");
Assert.assertEquals(3, dataSource.getConnectProperties().size());
dataSource.setExceptionSorter((ExceptionSorter) null);
dataSource.close();
}