bug fixed for dataSource.restart()

This commit is contained in:
wenshao
2014-09-24 00:55:04 +08:00
parent f500cc0eee
commit 7cc45ad594
2 changed files with 28 additions and 6 deletions
@@ -286,9 +286,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return discardCount;
}
public void restart() {
public void restart() throws SQLException {
lock.lock();
try {
if (activeCount > 0) {
throw new SQLException("can not restart, activeCount not zero. " + activeCount);
}
if (LOG.isInfoEnabled()) {
LOG.info("{dataSource-" + this.getID() + "} restart");
}
@@ -1,9 +1,11 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import java.sql.SQLException;
import junit.framework.TestCase;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
@@ -22,17 +24,34 @@ public class DruidDataSourceTest extends TestCase {
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_getInitStackTrace() {
String stackTrace = dataSource.getInitStackTrace();
Assert.assertTrue(stackTrace.indexOf("com.alibaba.druid.bvt.pool.DruidDataSourceTest.setUp") != -1);
}
public void test_restart() throws Exception {
Assert.assertEquals(true, dataSource.isInited());
dataSource.restart();
{
Connection conn = dataSource.getConnection();
Assert.assertEquals(1, dataSource.getActiveCount());
Exception error = null;
try {
dataSource.restart();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
Assert.assertEquals(true, dataSource.isInited());
conn.close();
dataSource.restart();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(false, dataSource.isInited());
Connection conn = dataSource.getConnection();
conn.close();
}