Search in sources :

Example 1 with MockDriver

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

the class Case1 method test_f.

public void test_f() throws Exception {
    final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setTimeBetweenConnectErrorMillis(100);
    final long startTime = System.currentTimeMillis();
    final long okTime = startTime + 1000 * 1;
    dataSource.setDriver(new MockDriver() {

        @Override
        public Connection connect(String url, Properties info) throws SQLException {
            if (System.currentTimeMillis() < okTime) {
                throw new SQLException();
            }
            return super.connect(url, info);
        }
    });
    dataSource.setUrl("jdbc:mock:");
    dataSource.setMinIdle(0);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    Connection conn = dataSource.getConnection();
    conn.close();
    dataSource.close();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 2 with MockDriver

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

the class ValidationQueryLogDB2Test method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDbType(JdbcConstants.DB2);
    dataSource.setDriver(new MockDriver() {

        public int getMajorVersion() {
            return 10;
        }
    });
    dataSource.setValidationQuery("SELECT 'x'");
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 3 with MockDriver

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

the class ValidationQueryLogTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDbType(JdbcConstants.ORACLE);
    dataSource.setDriver(new MockDriver() {

        public int getMajorVersion() {
            return 10;
        }
    });
    dataSource.setValidationQuery("SELECT 'x'");
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 4 with MockDriver

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

the class TestCommit method setUp.

protected void setUp() throws Exception {
    DruidDataSourceStatManager.clear();
    driver = new MockDriver();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    dataSource.setMinIdle(1);
    // 300 / 10
    dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
    // 180 / 10
    dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setFilters("stat");
    dataSource.setRemoveAbandoned(true);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 5 with MockDriver

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

the class DruidDataSourceC3P0AdapterTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
    driver = new MockDriver();
    dataSource = new DruidDataSourceC3P0Adapter();
    dataSource.setJdbcUrl("jdbc:mock:xxx");
    dataSource.setDriver(driver);
    dataSource.setInitialPoolSize(1);
    dataSource.setMaxPoolSize(2);
    dataSource.setMinPoolSize(1);
    // 300 / 10
    dataSource.setMaxIdleTime(300);
    // 180 / 10
    dataSource.setIdleConnectionTestPeriod(180);
    dataSource.setTestConnectionOnCheckout(false);
    dataSource.setPreferredTestQuery("SELECT 1");
    dataSource.setFilters("stat");
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DruidDataSourceC3P0Adapter(com.alibaba.druid.pool.DruidDataSourceC3P0Adapter)

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