bug fixed for fail fast.

This commit is contained in:
shaojin.wensj
2019-03-19 19:48:42 +08:00
parent c8ffb82508
commit 9aa1798149
3 changed files with 57 additions and 9 deletions
@@ -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);
}
}
}