use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class LogFilterTest method test_logFilter_1.
public void test_logFilter_1() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
Log4jFilter log4jFilter = new Log4jFilter();
log4jFilter.init(dataSource);
config.getFilters().add(log4jFilter);
setLogDisableAll(log4jFilter, true);
CommonsLogFilter commonLogFilter = new CommonsLogFilter() {
@Override
public boolean isDataSourceLogEnabled() {
return false;
}
@Override
public boolean isConnectionLogEnabled() {
return false;
}
@Override
public boolean isStatementLogEnabled() {
return false;
}
@Override
public boolean isResultSetLogEnabled() {
return false;
}
@Override
public boolean isResultSetLogErrorEnabled() {
return false;
}
@Override
public boolean isResultSetNextAfterLogEnabled() {
return false;
}
};
commonLogFilter.init(dataSource);
config.getFilters().add(commonLogFilter);
setLogDisableAll(commonLogFilter, true);
executeSQL(dataSource);
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class ResultSetProxyImplTest method test_resultset.
public void test_resultset() throws Exception {
MockDriver driver = new MockDriver();
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(driver, config);
{
StatFilter filter = new StatFilter();
filter.init(dataSource);
config.getFilters().add(filter);
}
{
Log4jFilter filter = new Log4jFilter();
filter.init(dataSource);
config.getFilters().add(filter);
}
Connection conn = dataSource.connect(null);
conn.setClientInfo("name", null);
Statement stmt = conn.createStatement();
ResultSetProxy rs = (ResultSetProxy) stmt.executeQuery(sql);
rs.insertRow();
rs.refreshRow();
rs.moveToInsertRow();
rs.moveToCurrentRow();
rs.next();
rs.updateRef(1, null);
rs.updateArray(1, null);
rs.updateRowId(1, null);
rs.updateNString(1, null);
rs.updateNClob(1, (NClob) null);
rs.updateNClob(1, (Reader) null);
rs.updateNClob(1, (Reader) null, 0);
rs.updateSQLXML(1, null);
rs.updateNCharacterStream(1, null);
rs.updateNCharacterStream(1, null, 0);
rs.getArray("1");
rs.updateRef("1", null);
rs.updateArray("1", null);
rs.updateRowId("1", null);
rs.updateNString("1", null);
rs.updateNClob("1", (NClob) null);
rs.updateNClob("1", (Reader) null);
rs.updateNClob("1", (Reader) null, 0);
rs.updateSQLXML("1", null);
rs.updateNCharacterStream("1", null);
rs.updateNCharacterStream("1", null, 0);
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class FakeDriverTest method test_0.
public void test_0() throws Exception {
String url = "jdbc:fake:x1";
Properties info = new Properties();
String sql = "SELECT 1";
MockDriver driver = new MockDriver();
Connection conn = driver.connect(url, info);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
Assert.assertEquals(true, rs.next());
Assert.assertEquals(1, rs.getInt(1));
conn.close();
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class CounterFilterTest method test_count_filter.
public void test_count_filter() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
config.setRawUrl("jdbc:mock:");
StatFilter filter = new StatFilter();
MockDriver driver = new MockDriver();
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(driver, config);
filter.init(dataSource);
config.getFilters().add(filter);
Connection conn = dataSource.connect(null);
Statement stmt = conn.createStatement();
ResultSetProxy rs = (ResultSetProxy) stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();
conn.close();
dataSource.getCompositeData();
dataSource.getProperties();
dataSource.getDataSourceMBeanDomain();
}
use of com.alibaba.druid.mock.MockDriver in project druid by alibaba.
the class DiscardTest method setUp.
protected void setUp() throws Exception {
driver = new MockDriver() {
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
if (failed) {
throw new SQLException("", "", 1040);
}
return super.executeQuery(stmt, sql);
}
public Connection connect(String url, Properties info) throws SQLException {
while (failed) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new SQLException(e.getMessage(), e);
}
}
return super.connect(url, info);
}
};
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setDriver(driver);
dataSource.setDbType("mysql");
dataSource.setMinIdle(1);
dataSource.setMaxActive(1);
dataSource.setFilters("log4j");
dataSource.setExceptionSorter(new MySqlExceptionSorter());
}
Aggregations