use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class Bug_for_happyday517 method test_for_happyday517_0.
public void test_for_happyday517_0() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
stmt.close();
conn.close();
}
use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class FilterChainImplTest3 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setFilters("stat,log4j,wall,encoding");
dataSource.getProxyFilters().add(new FilterAdapter() {
});
dataSource.setDbType("mysql");
dataSource.setDriver(new MockDriver() {
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
return null;
}
public MockStatement createMockStatement(MockConnection conn) {
return new MockStatement(conn) {
public ResultSet getResultSet() throws SQLException {
return null;
}
};
}
});
dataSource.init();
}
use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class TestLogLongTimeTransaction method setUp.
protected void setUp() throws Exception {
driver = new MockDriver() {
protected ResultSet executeQuery(MockStatement stmt, String sql) throws SQLException {
try {
Thread.sleep(2);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.executeQuery(stmt, sql);
}
};
dataSource = new DruidDataSource();
dataSource.setDriver(driver);
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setFilters("stat,trace,log4j,encoding");
dataSource.setTransactionThresholdMillis(1);
}
use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class LogFilterTest method test_logFilter_2.
public void test_logFilter_2() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
Log4jFilter log4jFilter = new Log4jFilter();
{
log4jFilter.init(dataSource);
setLogDisableAll(log4jFilter, true);
config.getFilters().add(log4jFilter);
}
CommonsLogFilter logFilter = new CommonsLogFilter();
{
logFilter.init(dataSource);
setLogDisableAll(logFilter, true);
config.getFilters().add(logFilter);
}
final MockResultSetMetaData rsMeta = new MockResultSetMetaData() {
private int[] types = new int[] { Types.BLOB, Types.CLOB, Types.NCLOB, Types.BINARY, Types.OTHER };
@Override
public int getColumnCount() throws SQLException {
return types.length;
}
@Override
public int getColumnType(int column) throws SQLException {
return types[column - 1];
}
};
ConnectionProxy conn = (ConnectionProxy) dataSource.connect(new Properties());
{
StatementProxy stmt = (StatementProxy) conn.createStatement();
MockResultSet rs = new MockResultSet(null) {
@Override
public ResultSetMetaData getMetaData() throws SQLException {
return rsMeta;
}
@Override
public boolean next() throws SQLException {
return true;
}
@Override
public Object getObject(int columnIndex) throws SQLException {
if (columnIndex == 5) {
throw new SQLException();
}
return null;
}
};
FilterChainImpl chain = new FilterChainImpl(dataSource);
chain.resultSet_next(new ResultSetProxyImpl(stmt, rs, 1001, null));
}
{
final MockResultSet rs = new MockResultSet(null) {
@Override
public ResultSetMetaData getMetaData() throws SQLException {
throw new SQLException();
}
};
StatementProxy stmt = new StatementProxyImpl(conn, new MockStatement(conn) {
public ResultSet getResultSet() throws SQLException {
return rs;
}
}, 0);
FilterChainImpl chain = new FilterChainImpl(dataSource);
chain.statement_getResultSet(stmt);
}
{
StatementProxy stmt = (StatementProxy) conn.createStatement();
MockResultSet rs = new MockResultSet(null) {
@Override
public ResultSetMetaData getMetaData() throws SQLException {
return rsMeta;
}
@Override
public boolean next() throws SQLException {
return true;
}
@Override
public Object getObject(int columnIndex) throws SQLException {
if (columnIndex == 5) {
throw new SQLException();
}
return null;
}
};
{
logFilter.setResultSetLogEnabled(false);
FilterChainImpl chain = new FilterChainImpl(dataSource);
chain.resultSet_next(new ResultSetProxyImpl(stmt, rs, 1001, null));
}
{
logFilter.setResultSetNextAfterLogEnabled(false);
FilterChainImpl chain = new FilterChainImpl(dataSource);
chain.resultSet_next(new ResultSetProxyImpl(stmt, rs, 1001, null));
}
}
}
Aggregations