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());
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class StatFilterTest3 method test_dbType_error.
public void test_dbType_error() throws Exception {
StatFilter filter = new StatFilter();
filter.setDbType("mysql");
filter.setMergeSql(true);
Assert.assertEquals(DbType.mysql, filter.getDbType());
Assert.assertEquals("sdafawer asf ", filter.mergeSql("sdafawer asf "));
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class StatFilterTest3 method test_merge.
public void test_merge() throws Exception {
StatFilter filter = new StatFilter();
filter.setDbType("mysql");
filter.setMergeSql(false);
Assert.assertEquals(DbType.mysql, filter.getDbType());
Assert.assertEquals("select 'x' limit 1", filter.mergeSql("select 'x' limit 1"));
}
use of com.alibaba.druid.filter.stat.StatFilter in project druid by alibaba.
the class StatFilterTest3 method test_merge_pg.
public void test_merge_pg() throws Exception {
StatFilter filter = new StatFilter();
filter.setDbType(JdbcConstants.POSTGRESQL);
filter.setMergeSql(true);
Assert.assertEquals(JdbcConstants.POSTGRESQL, filter.getDbType());
Assert.assertEquals("DROP TABLE IF EXISTS test_site_data_select_111;\n" + "CREATE TABLE test_site_data_select_111\n" + "AS\n" + "SELECT *\n" + "FROM postman_trace_info_one\n" + "WHERE lng > ?\n" + "\tAND lat > ?\n" + "\tAND site_id = ?;", filter.mergeSql("drop table if exists test_site_data_select_111; create table test_site_data_select_111 AS select * from postman_trace_info_one where lng>0 and lat>0 and site_id='17814' ;", JdbcConstants.POSTGRESQL));
}
Aggregations