Search in sources :

Example 41 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 42 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)

Example 43 with DruidDataSource

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

the class ConfigErrorTestMysql method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mysql:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setInitialSize(0);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 44 with DruidDataSource

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

the class ConfigErrorTest3 method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mysql:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setTestWhileIdle(false);
    dataSource.setInitialSize(0);
    dataSource.setPoolPreparedStatements(true);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 45 with DruidDataSource

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

the class MaxEvictableIdleTimeMillisTest2 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setMaxActive(50);
    dataSource.setMinIdle(5);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

DruidDataSource (com.alibaba.druid.pool.DruidDataSource)474 SQLException (java.sql.SQLException)74 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)56 OracleExceptionSorter (com.alibaba.druid.pool.vendor.OracleExceptionSorter)50 MockDriver (com.alibaba.druid.mock.MockDriver)49 Connection (java.sql.Connection)43 Properties (java.util.Properties)41 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)35 FilterChain (com.alibaba.druid.filter.FilterChain)33 Bean (org.springframework.context.annotation.Bean)21 ResultSet (java.sql.ResultSet)20 Test (org.junit.Test)19 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)18 PreparedStatement (java.sql.PreparedStatement)14 Primary (org.springframework.context.annotation.Primary)14 MockConnection (com.alibaba.druid.mock.MockConnection)13 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)13 Method (java.lang.reflect.Method)11 Map (java.util.Map)11 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10