Search in sources :

Example 41 with MockDriver

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

Example 42 with MockDriver

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

the class CallableStatmentTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(100);
    dataSource.setFilters("log4j");
    dataSource.setDriver(new MockDriver() {

        public MockCallableStatement createMockCallableStatement(MockConnection conn, String sql) {
            return new MyMockCallableStatement(conn, sql);
        }
    });
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 43 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 44 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 45 with MockDriver

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

the class Case0 method test_0.

public void test_0() throws Exception {
    final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriver(new MockDriver() {
    });
    dataSource.setUrl("jdbc:mock:");
    dataSource.setMinIdle(0);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    Connection conn1 = dataSource.getConnection();
    Connection conn2 = dataSource.getConnection();
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch completeLatch = new CountDownLatch(1);
    final AtomicInteger waitCount = new AtomicInteger();
    Thread t = new Thread() {

        public void run() {
            try {
                startLatch.countDown();
                waitCount.incrementAndGet();
                Connection conn = dataSource.getConnection();
                waitCount.decrementAndGet();
                conn.close();
                completeLatch.countDown();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    t.start();
    startLatch.await();
    Assert.assertFalse(completeLatch.await(1, TimeUnit.SECONDS));
    conn1.close();
    Assert.assertTrue(completeLatch.await(1, TimeUnit.SECONDS));
    conn2.close();
    Assert.assertTrue(completeLatch.await(1, TimeUnit.SECONDS));
    dataSource.close();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Connection(java.sql.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

MockDriver (com.alibaba.druid.mock.MockDriver)60 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)49 Connection (java.sql.Connection)17 SQLException (java.sql.SQLException)13 ResultSet (java.sql.ResultSet)10 Properties (java.util.Properties)9 MockConnection (com.alibaba.druid.mock.MockConnection)8 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)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 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)2