Search in sources :

Example 1 with MockStatementBase

use of com.alibaba.druid.mock.MockStatementBase 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());
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) MySqlExceptionSorter(com.alibaba.druid.pool.vendor.MySqlExceptionSorter) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 2 with MockStatementBase

use of com.alibaba.druid.mock.MockStatementBase in project druid by alibaba.

the class EncodingConvertFilterTest2 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setFilters("encoding");
    dataSource.setDriver(new MockDriver() {

        public ResultSet createResultSet(MockPreparedStatement stmt) {
            return new MyResultSet(stmt);
        }

        public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
            return new MyResultSet(stmt);
        }
    });
    dataSource.getConnectProperties().put("clientEncoding", CLIENT_ENCODING);
    dataSource.getConnectProperties().put("serverEncoding", SERVER_ENCODING);
    dataSource.init();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet) ResultSet(java.sql.ResultSet) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 3 with MockStatementBase

use of com.alibaba.druid.mock.MockStatementBase in project druid by alibaba.

the class StatFilterBuildSlowParameterTest method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setFilters("stat");
    dataSource.setTestOnBorrow(false);
    dataSource.setConnectionProperties("druid.stat.slowSqlMillis=1");
    MockDriver driver = new MockDriver() {

        public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return super.executeQuery(stmt, sql);
        }
    };
    dataSource.setDriver(driver);
    dataSource.init();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 4 with MockStatementBase

use of com.alibaba.druid.mock.MockStatementBase in project druid by alibaba.

the class EncodingConvertFilterTest method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setFilters("encoding");
    dataSource.setDriver(new MockDriver() {

        public ResultSet createResultSet(MockPreparedStatement stmt) {
            return new MyResultSet(stmt);
        }

        public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
            return new MyResultSet(stmt);
        }
    });
    dataSource.getConnectProperties().put("clientEncoding", CLIENT_ENCODING);
    dataSource.getConnectProperties().put("serverEncoding", SERVER_ENCODING);
    dataSource.init();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet) ResultSet(java.sql.ResultSet) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 5 with MockStatementBase

use of com.alibaba.druid.mock.MockStatementBase 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();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) MockStatement(com.alibaba.druid.mock.MockStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Aggregations

MockDriver (com.alibaba.druid.mock.MockDriver)7 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)7 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)2 MockResultSet (com.alibaba.druid.mock.MockResultSet)2 Properties (java.util.Properties)2 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)1 MockConnection (com.alibaba.druid.mock.MockConnection)1 MockStatement (com.alibaba.druid.mock.MockStatement)1 ExceptionSorter (com.alibaba.druid.pool.ExceptionSorter)1 MySqlExceptionSorter (com.alibaba.druid.pool.vendor.MySqlExceptionSorter)1 Connection (java.sql.Connection)1