mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Delete URL Filter related codes committed previously
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
package com.alibaba.druid.filter.url;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test class for HostAndPortHolder
|
||||
*
|
||||
* @author DigitalSonic
|
||||
*/
|
||||
public class HostAndPortHolderTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
HostAndPortHolder.loadProperties("/com/alibaba/druid/filter/url/datasource.properties");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
HostAndPortHolder.getInstance().clearBlacklist();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadFromFileNotExisted() {
|
||||
int size = HostAndPortHolder.getInstance().getHolder().size();
|
||||
HostAndPortHolder.loadProperties("FILE_NOT_FOUND");
|
||||
assertEquals(size, HostAndPortHolder.getInstance().getHolder().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadFromProperties() {
|
||||
Map<String, List<String>> holder = HostAndPortHolder.getInstance().getHolder();
|
||||
assertEquals(3, holder.size());
|
||||
assertEquals("127.0.0.1:3066", holder.get("datasource.foo").get(0));
|
||||
assertEquals("192.168.0.1:3066", holder.get("datasource.foo").get(1));
|
||||
assertFalse(holder.containsKey("datasource.empty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRandomGet() {
|
||||
boolean[] flags = new boolean[] { false, false };
|
||||
HostAndPortHolder holder = HostAndPortHolder.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
String v = holder.get("datasource.foo");
|
||||
if (v.equals("127.0.0.1:3066")) {
|
||||
flags[0] = true;
|
||||
} else if (v.equals("192.168.0.1:3066")) {
|
||||
flags[1] = true;
|
||||
}
|
||||
}
|
||||
assertTrue(flags[0] && flags[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOne() {
|
||||
HostAndPortHolder holder = HostAndPortHolder.getInstance();
|
||||
String value = holder.get("datasource.foo");
|
||||
assertTrue(value.equals("127.0.0.1:3066") || value.equals("192.168.0.1:3066"));
|
||||
assertEquals(HostAndPortHolder.UNAVAILABLE, holder.get("UNAVAILABLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlackList() {
|
||||
HostAndPortHolder holder = HostAndPortHolder.getInstance();
|
||||
holder.addBlacklist("192.168.0.1:3066");
|
||||
for (int i = 0; i < 100; i++) {
|
||||
assertNotEquals("192.168.0.1:3066", holder.get("datasource.foo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.alibaba.druid.filter.url;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test class for HostAndPortValidatorThread
|
||||
*
|
||||
* @author DigitalSonic
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:com/alibaba/druid/filter/url/dataSource.xml")
|
||||
public class HostAndPortValidatorThreadTest {
|
||||
@Autowired
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testValidateFail() throws Exception {
|
||||
assertEquals(0, HostAndPortHolder.getInstance().getBlacklistSize());
|
||||
dataSource.setValidationQuery("select xxx from foo");
|
||||
Thread.sleep(20 * 1000);
|
||||
assertTrue(HostAndPortHolder.getInstance().getBlacklistSize() > 0);
|
||||
assertTrue(dataSource.isTestOnBorrow());
|
||||
assertTrue(dataSource.isTestOnReturn());
|
||||
|
||||
dataSource.setValidationQuery(null);
|
||||
Thread.sleep(20 * 1000);
|
||||
assertEquals(0, HostAndPortHolder.getInstance().getBlacklistSize());
|
||||
assertFalse(dataSource.isTestOnBorrow());
|
||||
assertFalse(dataSource.isTestOnReturn());
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.alibaba.druid.filter.url;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
|
||||
import org.apache.derby.impl.jdbc.EmbedConnection;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Test class for JdbcUrlHostAndPortReplaceFilter
|
||||
*
|
||||
* @author DigitalSonic
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:com/alibaba/druid/filter/url/dataSource.xml")
|
||||
public class JdbcUrlHostAndPortReplaceFilterTest {
|
||||
@Autowired
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testConnectWithDifferentPlaceholderValue() throws Exception {
|
||||
int[] count = new int[] { 0,0 };
|
||||
List<Connection> connectionList = new ArrayList<Connection>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
EmbedConnection embed = ((EmbedConnection)((ConnectionProxyImpl)conn.getConnection()).getRawObject());
|
||||
String connName = embed.toString();
|
||||
|
||||
if (connName.contains("foo")) {
|
||||
count[0]++;
|
||||
} else if (connName.contains("bar")) {
|
||||
count[1]++;
|
||||
} else {
|
||||
fail("NOT foo or bar");
|
||||
}
|
||||
connectionList.add(conn);
|
||||
}
|
||||
assertTrue(count[0] > 0 && count[1] >0);
|
||||
for (Connection c : connectionList) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user