use of com.alibaba.druid.util.DruidPasswordCallback in project druid by alibaba.
the class DruidDataSourceTest6 method setUp.
protected void setUp() throws Exception {
returnEmptyCount.set(0);
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(true);
dataSource.setInitialSize(1);
dataSource.setValidationQuery("select 1");
dataSource.setValidationQueryTimeout(10);
dataSource.setQueryTimeout(100);
dataSource.setUserCallback(new NameCallback("xx") {
});
dataSource.setPasswordCallback(new DruidPasswordCallback() {
@Override
public char[] getPassword() {
return "xx".toCharArray();
}
});
dataSource.getProxyFilters().add(new FilterAdapter() {
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
if (errorCount.get() > 0) {
errorCount.decrementAndGet();
throw new RuntimeException();
}
if (returnEmptyCount.get() > 0) {
returnEmptyCount.decrementAndGet();
return new ResultSetProxyImpl(statement, new MockResultSet(statement), 0, sql);
}
return chain.statement_executeQuery(statement, sql);
}
});
}
Aggregations