mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
StatFilter mergeSql support tddl
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class ReuseStatFilterTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSourceA;
|
||||
private DruidDataSource dataSourceB;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSourceA = new DruidDataSource();
|
||||
dataSourceB = new DruidDataSource();
|
||||
|
||||
dataSourceA.setUrl("jdbc:mock:xxx_A");
|
||||
dataSourceB.setUrl("jdbc:mock:xxx_B");
|
||||
|
||||
StatFilter filter = new StatFilter();
|
||||
|
||||
dataSourceA.getProxyFilters().add(filter);
|
||||
dataSourceB.getProxyFilters().add(filter);
|
||||
|
||||
dataSourceA.init();
|
||||
dataSourceB.init();
|
||||
}
|
||||
|
||||
public void test_execute() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSourceA);
|
||||
JdbcUtils.close(dataSourceB);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.alibaba.druid.bvt.proxy.filter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class GlobalStatTest0 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSourceA;
|
||||
private DruidDataSource dataSourceB;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSourceA = new DruidDataSource();
|
||||
dataSourceA.setUrl("jdbc:mock:xx_A");
|
||||
dataSourceA.setFilters("stat");
|
||||
dataSourceA.setUseGloalDataSourceStat(true);
|
||||
|
||||
dataSourceB = new DruidDataSource();
|
||||
dataSourceB.setUrl("jdbc:mock:xx_A");
|
||||
dataSourceB.setFilters("stat");
|
||||
dataSourceB.setUseGloalDataSourceStat(true);
|
||||
}
|
||||
|
||||
public void test_execute() throws Exception {
|
||||
{
|
||||
Connection conn = dataSourceA.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT 1");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
{
|
||||
Connection conn = dataSourceB.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT 1");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Assert.assertSame(JdbcDataSourceStat.getGlobal(), dataSourceA.getDataSourceStat());
|
||||
Assert.assertSame(JdbcDataSourceStat.getGlobal(), dataSourceB.getDataSourceStat());
|
||||
|
||||
Assert.assertEquals(1, JdbcStatManager.getInstance().getSqlList().size());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSourceA);
|
||||
JdbcUtils.close(dataSourceB);
|
||||
}
|
||||
|
||||
}
|
||||
+20
-20
@@ -13,46 +13,46 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
package com.alibaba.druid.bvt.proxy.filter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class PoolStatFilterTest extends TestCase {
|
||||
public class MergeStatFilterTest_tddl extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
|
||||
dataSource.init();
|
||||
dataSource.setUrl("jdbc:mock:xx");
|
||||
dataSource.setFilters("mergeStat");
|
||||
dataSource.setDbType("mysql");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
|
||||
Assert.assertTrue(dataSource.isInited());
|
||||
|
||||
Histogram histogram = dataSource.getDataSourceStat().getConnectionHoldHistogram();
|
||||
|
||||
Assert.assertEquals(0, histogram.getValue(0));
|
||||
public void test_merge() throws Exception {
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
String tableName = "t_" + i;
|
||||
String sql = "select * from " + tableName + " where " + tableName + ".id = " + i;
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute(sql);
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Assert.assertEquals(1, dataSource.getDataSourceStat().getSqlStatMap().size());
|
||||
|
||||
Assert.assertEquals(1, histogram.getValue(0));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user