mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #663 from wenshao/master
bug fixed for dataSource.restart()
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user