mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for fail fast.
This commit is contained in:
@@ -4,6 +4,7 @@ import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.alibaba.druid.PoolTestCase;
|
||||
@@ -17,7 +18,8 @@ import junit.framework.TestCase;
|
||||
public class FailFastTest extends PoolTestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
|
||||
private AtomicInteger index = new AtomicInteger();
|
||||
private CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -26,6 +28,11 @@ public class FailFastTest extends PoolTestCase {
|
||||
|
||||
dataSource = new DruidDataSource() {
|
||||
public PhysicalConnectionInfo createPhysicalConnection() throws SQLException {
|
||||
if (index.get() > 2) {
|
||||
return super.createPhysicalConnection();
|
||||
}
|
||||
|
||||
index.incrementAndGet();
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
@@ -79,6 +86,13 @@ public class FailFastTest extends PoolTestCase {
|
||||
connectEndLatch.await(3, TimeUnit.SECONDS);
|
||||
SQLException ex = errorHolder.get();
|
||||
Assert.assertTrue(ex instanceof DataSourceNotAvailableException);
|
||||
|
||||
for (int i = 0; i < 300; ++i) {
|
||||
if (!dataSource.isFailContinuous()) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(100 * 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user