Search in sources :

Example 91 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class DruidDataSourceTest_interrupt method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource() {

        protected void createAndStartCreatorThread() {
            return;
        }
    };
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setDefaultAutoCommit(true);
    dataSource.setInitialSize(1);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 92 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class DruidDataSourceTest_lastCreateError method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
            throw new SQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Example 93 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource 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 94 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class Case2 method test_singleThread.

public void test_singleThread() throws Exception {
    Class.forName("com.alibaba.druid.mock.MockDriver");
    Properties properties = new Properties();
    properties.put("maxActive", "100");
    properties.put("maxIdle", "30");
    properties.put("maxWait", "10000");
    properties.put("url", "jdbc:mock:");
    properties.put("filters", "stat");
    properties.put("validationQuery", "SELECT 1");
    DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
    JMXUtils.register("com.alibaba.druid:type=DruidDataSource", dataSource);
    final int COUNT = 10;
    Assert.assertEquals(0, dataSource.getCreateCount());
    Assert.assertEquals(0, dataSource.getDestroyCount());
    Assert.assertEquals(0, dataSource.getPoolingCount());
    Connection[] connections = new Connection[COUNT];
    for (int i = 0; i < COUNT; ++i) {
        connections[i] = dataSource.getConnection();
    }
    for (int i = 0; i < COUNT; ++i) {
        connections[i].close();
    }
    Assert.assertEquals(0, dataSource.getDestroyCount());
    dataSource.close();
    Assert.assertEquals(dataSource.getCreateCount(), dataSource.getDestroyCount());
}
Also used : Connection(java.sql.Connection) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 95 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class ClosedTest method test_close.

public void test_close() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    Connection conn = dataSource.getConnection();
    conn.close();
    dataSource.close();
    DataSourceClosedException error = null;
    try {
        dataSource.getConnection();
    } catch (DataSourceClosedException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : DataSourceClosedException(com.alibaba.druid.pool.DataSourceClosedException) Connection(java.sql.Connection) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

DruidDataSource (com.alibaba.druid.pool.DruidDataSource)389 SQLException (java.sql.SQLException)56 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)55 OracleExceptionSorter (com.alibaba.druid.pool.vendor.OracleExceptionSorter)50 MockDriver (com.alibaba.druid.mock.MockDriver)48 Connection (java.sql.Connection)36 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)35 Properties (java.util.Properties)34 FilterChain (com.alibaba.druid.filter.FilterChain)33 ResultSet (java.sql.ResultSet)19 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)18 MockConnection (com.alibaba.druid.mock.MockConnection)13 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)13 Method (java.lang.reflect.Method)11 PreparedStatement (java.sql.PreparedStatement)11 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10 Field (java.lang.reflect.Field)8 MockResultSet (com.alibaba.druid.mock.MockResultSet)7 TabularData (javax.management.openmbean.TabularData)7 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)6