use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class StatFilterTest3 method test_dbType.
@SuppressWarnings("deprecation")
public void test_dbType() throws Exception {
StatFilter filter = new StatFilter();
Assert.assertFalse(filter.isMergeSql());
filter.setDbType("mysql");
filter.setMergeSql(true);
Assert.assertTrue(filter.isMergeSql());
Assert.assertEquals("mysql", filter.getDbType());
Assert.assertEquals("SELECT ?\nLIMIT ?", filter.mergeSql("select 'x' limit 1"));
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class SlowSqlMillisTest2 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setTestWhileIdle(false);
System.setProperty("druid.stat.slowSqlMillis", "500");
dataSource.setFilters("stat");
{
StatFilter filter = (StatFilter) dataSource.getProxyFilters().get(0);
Assert.assertEquals(3000, filter.getSlowSqlMillis());
}
dataSource.init();
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class ConnectPropertiesChangeTest method test_connectPropertiesChange.
public void test_connectPropertiesChange() throws Exception {
Assert.assertEquals(2, dataSource.getConnectProperties().size());
Assert.assertEquals("3", dataSource.getConnectProperties().getProperty("a"));
Assert.assertEquals("4", dataSource.getConnectProperties().getProperty("b"));
Connection conn = dataSource.getConnection();
conn.close();
dataSource.setConnectionProperties("a=3;b=4");
Assert.assertEquals(1, dataSourceLog.getInfoCount());
dataSource.setConnectionProperties("b=5;c=6");
Assert.assertEquals(2, dataSourceLog.getInfoCount());
Assert.assertEquals(2, dataSource.getConnectProperties().size());
Assert.assertEquals("5", dataSource.getConnectProperties().getProperty("b"));
Assert.assertEquals("6", dataSource.getConnectProperties().getProperty("c"));
StatFilter filter = dataSource.unwrap(StatFilter.class);
Assert.assertNotNull(filter);
Assert.assertFalse(filter.isMergeSql());
dataSource.setConnectionProperties("b=5;c=6;druid.stat.mergeSql=true");
Assert.assertTrue(filter.isMergeSql());
Assert.assertEquals(3, dataSource.getConnectProperties().size());
Assert.assertEquals("true", dataSource.getConnectProperties().getProperty("druid.stat.mergeSql"));
Assert.assertEquals("5", dataSource.getConnectProperties().getProperty("b"));
Assert.assertEquals("6", dataSource.getConnectProperties().getProperty("c"));
dataSource.setConnectionProperties("b=5;c=6;druid.stat.mergeSql=false");
Assert.assertFalse(filter.isMergeSql());
Assert.assertEquals("false", dataSource.getConnectProperties().getProperty("druid.stat.mergeSql"));
Assert.assertEquals("5", dataSource.getConnectProperties().getProperty("b"));
Assert.assertEquals("6", dataSource.getConnectProperties().getProperty("c"));
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class ConnectPropertiesChangeTest1 method test_connectPropertiesChange.
public void test_connectPropertiesChange() throws Exception {
Assert.assertEquals(2, dataSource.getConnectProperties().size());
Connection conn = dataSource.getConnection();
conn.close();
StatFilter filter = dataSource.unwrap(StatFilter.class);
Assert.assertNotNull(filter);
Assert.assertFalse(filter.isMergeSql());
Assert.assertEquals(234, dataSource.getDataSourceStat().getMaxSqlSize());
dataSource.setConnectionProperties("druid.stat.mergeSql=true;druid.stat.sql.MaxSize=456");
Assert.assertEquals(456, dataSource.getDataSourceStat().getMaxSqlSize());
Assert.assertTrue(filter.isMergeSql());
Assert.assertEquals(2, dataSource.getConnectProperties().size());
Assert.assertEquals("true", dataSource.getConnectProperties().getProperty("druid.stat.mergeSql"));
dataSource.setConnectionProperties("druid.stat.mergeSql=false");
Assert.assertFalse(filter.isMergeSql());
Assert.assertEquals("false", dataSource.getConnectProperties().getProperty("druid.stat.mergeSql"));
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class CounterFilterTest method test_countFilter.
public void test_countFilter() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(null, config);
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
StatFilter filter = new StatFilter();
filter.init(dataSource);
dataSourceStat.reset();
Assert.assertNull(StatFilter.getStatFilter(dataSource));
Assert.assertNull(dataSourceStat.getSqlStat(Integer.MAX_VALUE));
Assert.assertNull(dataSourceStat.getConnectionStat().getConnectLastTime());
FilterChain chain = new FilterChainImpl(dataSource) {
public ConnectionProxy connection_connect(Properties info) throws SQLException {
throw new SQLException();
}
};
Exception error = null;
try {
filter.connection_connect(chain, new Properties());
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectErrorCount());
Assert.assertNotNull(dataSourceStat.getConnectionStat().getConnectLastTime());
}
Aggregations