Search in sources :

Example 46 with MockDriver

use of com.alibaba.druid.mock.MockDriver 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 47 with MockDriver

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

the class StatFilterExecuteTest method setUp.

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

        public MockPreparedStatement createMockPreparedStatement(MockConnection conn, String sql) {
            return new MyMockPreparedStatement(conn, sql);
        }
    };
    dataSource.setDriver(driver);
    dataSource.init();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 48 with MockDriver

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

the class DruidDataSourceTest_exceptionSorter method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setRemoveAbandoned(true);
    dataSource.setDriver(new MockDriver() {

        public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.setExceptionSorter(new ExceptionSorter() {

        @Override
        public boolean isExceptionFatal(SQLException e) {
            return true;
        }

        @Override
        public void configFromProperties(Properties properties) {
        }
    });
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ExceptionSorter(com.alibaba.druid.pool.ExceptionSorter) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 49 with MockDriver

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

the class DruidDataSourceTest_getPooledConnection method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setRemoveAbandoned(true);
    dataSource.setDriver(new MockDriver() {

        public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
            throw new SQLException();
        }
    });
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 50 with MockDriver

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

the class DruidDataSourceTest_oracle2 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setFilters("stat");
    dataSource.setDbType("oracle");
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriver(new MockDriver() {

        @Override
        public int getMajorVersion() {
            return 10;
        }
    });
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

MockDriver (com.alibaba.druid.mock.MockDriver)58 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)48 Connection (java.sql.Connection)15 SQLException (java.sql.SQLException)11 ResultSet (java.sql.ResultSet)10 MockConnection (com.alibaba.druid.mock.MockConnection)8 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)7 Properties (java.util.Properties)7 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)5 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)5 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)5 JdbcStatContext (com.alibaba.druid.stat.JdbcStatContext)5 Log4jFilter (com.alibaba.druid.filter.logging.Log4jFilter)4 CommonsLogFilter (com.alibaba.druid.filter.logging.CommonsLogFilter)3 MockResultSet (com.alibaba.druid.mock.MockResultSet)3 MockStatement (com.alibaba.druid.mock.MockStatement)3 Statement (java.sql.Statement)3 ObjectName (javax.management.ObjectName)3 StatFilter (com.alibaba.druid.filter.stat.StatFilter)2 NullExceptionSorter (com.alibaba.druid.pool.vendor.NullExceptionSorter)2