Search in sources :

Example 76 with DruidDataSource

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

the class DruidDataSourceFactoryTest1 method test_integer.

public void test_integer() throws Exception {
    Properties properties = new Properties();
    properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
    properties.put(DruidDataSourceFactory.PROP_DEFAULTTRANSACTIONISOLATION, Integer.toString(Connection.TRANSACTION_SERIALIZABLE));
    DruidDataSource dataSource = null;
    try {
        dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        Assert.assertEquals("jdbc:mock:xxx", dataSource.getUrl());
        Assert.assertEquals(Connection.TRANSACTION_SERIALIZABLE, dataSource.getDefaultTransactionIsolation().intValue());
    } finally {
        JdbcUtils.close(dataSource);
    }
}
Also used : Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 77 with DruidDataSource

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

the class DruidDataSourceFactoryTest1 method test_SERIALIZABLE.

public void test_SERIALIZABLE() throws Exception {
    Properties properties = new Properties();
    properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
    properties.put(DruidDataSourceFactory.PROP_DEFAULTTRANSACTIONISOLATION, "SERIALIZABLE");
    DruidDataSource dataSource = null;
    try {
        dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        Assert.assertEquals("jdbc:mock:xxx", dataSource.getUrl());
        Assert.assertEquals(Connection.TRANSACTION_SERIALIZABLE, dataSource.getDefaultTransactionIsolation().intValue());
    } finally {
        JdbcUtils.close(dataSource);
    }
}
Also used : Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 78 with DruidDataSource

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

the class DruidDataSourceFilterTest method test_filter.

public void test_filter() throws Exception {
    System.out.println(System.nanoTime() / (1000 * 1000));
    DruidDataSource dataSource = new DruidDataSource();
    Assert.assertEquals(0, dataSource.getProxyFilters().size());
    dataSource.setFilters("stat");
    Assert.assertEquals(1, dataSource.getProxyFilters().size());
    dataSource.close();
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 79 with DruidDataSource

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

the class DruidDataSourceFilterTest method test_filter_3.

public void test_filter_3() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:");
    Assert.assertEquals(0, dataSource.getProxyFilters().size());
    dataSource.setFilters("stat");
    JdbcStatManager.getInstance().reset();
    dataSource.init();
    JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
    //        Assert.assertEquals(1, JdbcStatManager.getInstance().getDataSources().size());
    //        JdbcDataSourceStat dataSourceStat = JdbcStatManager.getInstance().getDataSources().values().iterator().next();
    Assert.assertEquals(0, dataSourceStat.getConnectionStat().getConnectCount());
    Assert.assertEquals(1, dataSource.getProxyFilters().size());
    for (int i = 0; i < 2; ++i) {
        Connection conn = dataSource.getConnection();
        Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectCount());
        Assert.assertEquals(0, dataSourceStat.getConnectionStat().getCloseCount());
        conn.close();
        Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectCount());
        // logic
        Assert.assertEquals(0, dataSourceStat.getConnectionStat().getCloseCount());
    // close不会导致计数器+1
    }
    Assert.assertEquals(1, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
    dataSource.close();
    Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectCount());
    Assert.assertEquals(1, dataSourceStat.getConnectionStat().getCloseCount());
}
Also used : Connection(java.sql.Connection) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 80 with DruidDataSource

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

the class DruidDataSourceTest3 method setUp.

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

        public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
            try {
                Thread.sleep(Long.MAX_VALUE);
            } catch (InterruptedException e) {
            // skip
            }
            return null;
        }
    });
}
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)

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