mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add StatFilter testcase for : OpenClobCount, OpenBlobCount, OpenInputStreamCount, OpenReaderCount
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.mock.MockBlob;
|
||||
import com.alibaba.druid.mock.MockClob;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenBlobCountTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
return new MockBlob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
return new MockBlob();
|
||||
}
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getBlob(1);
|
||||
rs.getBlob(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getBlobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getBlob("1");
|
||||
rs.getBlob("2");
|
||||
rs.getBlob("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getBlobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.mock.MockBlob;
|
||||
import com.alibaba.druid.mock.MockClob;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenBlobCountTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
return new MockBlob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
return new MockBlob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
return new MockBlob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
return new MockBlob();
|
||||
}
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject(1);
|
||||
rs.getObject(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getBlobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject("1");
|
||||
rs.getObject("2");
|
||||
rs.getObject("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getBlobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_2() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject(1, Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject(2, Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject(3, Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject(4, Collections.<String, Class<?>> emptyMap());
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(4, sqlStat.getBlobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_4() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject("1", Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject("2", Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject("3", Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject("4", Collections.<String, Class<?>> emptyMap());
|
||||
rs.getObject("5", Collections.<String, Class<?>> emptyMap());
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(5, sqlStat.getBlobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getBlobOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.mock.MockClob;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenClobCountTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public Clob resultSet_getClob(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(),
|
||||
result.getStatementProxy().getConnectionProxy(), new MockClob());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clob resultSet_getClob(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(),
|
||||
result.getStatementProxy().getConnectionProxy(), new MockClob());
|
||||
}
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getClob(1);
|
||||
rs.getClob(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getClobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getClob("1");
|
||||
rs.getClob("2");
|
||||
rs.getClob("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getClobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.mock.MockClob;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenClobCountTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(),
|
||||
result.getStatementProxy().getConnectionProxy(), new MockClob());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(),
|
||||
result.getStatementProxy().getConnectionProxy(), new MockClob());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(),
|
||||
result.getStatementProxy().getConnectionProxy(), new MockClob());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(),
|
||||
result.getStatementProxy().getConnectionProxy(), new MockClob());
|
||||
}
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject(1);
|
||||
rs.getObject(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getClobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject("1");
|
||||
rs.getObject("2");
|
||||
rs.getObject("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getClobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_2() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject(1, Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject(2, Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject(3, Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject(4, Collections.<String,Class<?>>emptyMap());
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(4, sqlStat.getClobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_4() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getObject("1", Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject("2", Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject("3", Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject("4", Collections.<String,Class<?>>emptyMap());
|
||||
rs.getObject("5", Collections.<String,Class<?>>emptyMap());
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(5, sqlStat.getClobOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getClobOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenInputStreamCountTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public java.io.InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.io.InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getBinaryStream(1);
|
||||
rs.getBinaryStream(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getBinaryStream("1");
|
||||
rs.getBinaryStream("2");
|
||||
rs.getBinaryStream("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenInputStreamCountTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public java.io.InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result,
|
||||
int columnIndex) throws SQLException {
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.io.InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result,
|
||||
String columnLabel) throws SQLException {
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
}
|
||||
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getAsciiStream(1);
|
||||
rs.getAsciiStream(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getAsciiStream("1");
|
||||
rs.getAsciiStream("2");
|
||||
rs.getAsciiStream("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getInputStreamOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.nutz.lang.stream.StringReader;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class StatFilterOpenReaderCountTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
@Override
|
||||
public java.io.Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
return new StringReader("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.io.Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
return new StringReader("");
|
||||
}
|
||||
});
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getReaderOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getCharacterStream(1);
|
||||
rs.getCharacterStream(2);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(2, sqlStat.getReaderOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getReaderOpenCount());
|
||||
}
|
||||
|
||||
public void test_stat_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 'x'";
|
||||
PreparedStatement stmt = conn.prepareStatement("select 'x'");
|
||||
|
||||
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getReaderOpenCount());
|
||||
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.getCharacterStream("1");
|
||||
rs.getCharacterStream("2");
|
||||
rs.getCharacterStream("3");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(3, sqlStat.getReaderOpenCount());
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getReaderOpenCount());
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class StatFilterReadBytesLengthTest extends TestCase {
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getReadStringLength());
|
||||
Assert.assertEquals(6, sqlStat.getReadBytesLength());
|
||||
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getReadStringLength());
|
||||
Assert.assertEquals(0, sqlStat.getReadBytesLength());
|
||||
@@ -95,7 +95,7 @@ public class StatFilterReadBytesLengthTest extends TestCase {
|
||||
|
||||
Assert.assertEquals(0, sqlStat.getReadStringLength());
|
||||
Assert.assertEquals(7, sqlStat.getReadBytesLength());
|
||||
|
||||
|
||||
sqlStat.reset();
|
||||
Assert.assertEquals(0, sqlStat.getReadStringLength());
|
||||
Assert.assertEquals(0, sqlStat.getReadBytesLength());
|
||||
|
||||
Reference in New Issue
Block a user