Search in sources :

Example 61 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.

the class Case3 method dbcp.

public void dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setMinIdle(minIdle);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setConnectionProperties(connectionProperties);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    for (int i = 0; i < TEST_COUNT; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    // dataSource.close();
    System.out.println();
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 62 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.

the class CaseKylin_mysql method dbcp.

public void dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnBorrow(testWhileIdle);
    dataSource.setTestOnBorrow(testOnReturn);
    dataSource.setRemoveAbandoned(removeAbandoned);
    dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    for (int i = 0; i < TEST_COUNT; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 63 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.

the class Oracle_Case0 method test_1.

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(true);
    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }
    System.out.println();
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 64 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.

the class Oracle_Case4 method test_dbcp.

public void test_dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(preparedStatementCache);
    dataSource.setMaxOpenPreparedStatements(preparedStatementCacheSize);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setConnectionProperties(properties);
    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 65 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project druid by alibaba.

the class DBCPTest method test_max.

public void test_max() throws Exception {
    Class.forName("com.alibaba.druid.mock.MockDriver");
    final BasicDataSource dataSource = new BasicDataSource();
    // final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setInitialSize(3);
    dataSource.setMaxActive(20);
    dataSource.setMaxIdle(20);
    dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
    dataSource.setUrl("jdbc:mock:xxx");
    final int THREAD_COUNT = 200;
    final CountDownLatch endLatch = new CountDownLatch(THREAD_COUNT);
    final CountDownLatch startLatch = new CountDownLatch(1);
    Thread[] threads = new Thread[THREAD_COUNT];
    for (int i = 0; i < THREAD_COUNT; ++i) {
        threads[i] = new Thread() {

            public void run() {
                try {
                    startLatch.await();
                    for (int i = 0; i < 1000; ++i) {
                        Connection conn = dataSource.getConnection();
                        Thread.sleep(1);
                        conn.close();
                    }
                } catch (Exception e) {
                } finally {
                    endLatch.countDown();
                }
            }
        };
        threads[i].start();
    }
    startLatch.countDown();
    endLatch.await();
    // System.out.println(dataSource.getNumIdle());
    System.out.println(MockDriver.instance.getConnections().size());
    System.out.println(MockDriver.instance.getConnectionCloseCount());
}
Also used : Connection(java.sql.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

BasicDataSource (org.apache.commons.dbcp.BasicDataSource)141 Connection (java.sql.Connection)25 Test (org.junit.Test)13 SQLException (java.sql.SQLException)12 Properties (java.util.Properties)12 DataSource (javax.sql.DataSource)10 Platform (org.apache.ddlutils.Platform)8 Database (org.apache.ddlutils.model.Database)8 DdlGenerator (siena.jdbc.ddl.DdlGenerator)8 Statement (java.sql.Statement)7 Bean (org.springframework.context.annotation.Bean)6 ResultSet (java.sql.ResultSet)5 Before (org.junit.Before)5 JdbcPersistenceManager (siena.jdbc.JdbcPersistenceManager)5 Config (com.typesafe.config.Config)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 PostgresqlPersistenceManager (siena.jdbc.PostgresqlPersistenceManager)3