Package com.alibaba.druid.pool

Examples of com.alibaba.druid.pool.DruidDataSource$ActiveConnectionTraceInfo


    public void setUp() throws Exception {
        jdbcUrl = "jdbc:oracle:thin:@xx.xx.xx.xx:1521:emdb";
        user = "wardon";
        password = "wardon";

        dataSource = new DruidDataSource();
        dataSource.setInitialSize(1);
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
        dataSource.setMaxActive(50);
View Full Code Here


        user = "dragoon_admin";
        password = "dragoon_root";

        driverClass = "com.mysql.jdbc.Driver";

        dataSource  = new DruidDataSource();
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
       
        dataSource.setMaxActive(4);
View Full Code Here

public class NutzTransactionTest extends TestCase {

    private DataSource dataSource;

    protected void setUp() throws Exception {
         DruidDataSource dataSource = new DruidDataSource();
         dataSource.setUrl("jdbc:jtds:sqlserver://192.168.1.105/petstore");
         dataSource.setUsername("sa");
         dataSource.setPassword("hello");
         dataSource.setFilters("log4j");

//        BasicDataSource dataSource = new BasicDataSource();
//        dataSource.setDriverClassName("net.sourceforge.jtds.jdbc.Driver");
//        dataSource.setUrl("jdbc:jtds:sqlserver://192.168.1.105/petstore");
//        dataSource.setUsername("sa");
View Full Code Here

        driverClass = "oracle.jdbc.driver.OracleDriver";
    }

    public void test_o() throws Exception {
        DruidDataSource dataSource = new DruidDataSource();

        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
        dataSource.setPoolPreparedStatements(true);
        dataSource.setMaxOpenPreparedStatements(50);
        dataSource.setUseOracleImplicitCache(true);
        // dataSource.setConnectionProperties("oracle.jdbc.FreeMemoryOnEnterImplicitCache=true");

        for (int i = 1; i <= 1; ++i) {
            Connection conn = dataSource.getConnection();

            int rowNum = i + 1; // (i % 50) + 1;
            String sql = SQL + " AND ROWNUM <= " + rowNum;
            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.setInt(1, 61);
            ResultSet rs = stmt.executeQuery();
            int rowCount = 0;
            while (rs.next()) {
                rowCount++;
            }
            Assert.assertEquals(true, rowCount > 0);
            // Assert.isTrue(!rs.isClosed());
            rs.close();
            // Assert.isTrue(!stmt.isClosed());
            stmt.close();

            conn.close();

        }

        dataSource.close();
    }
View Full Code Here

    public void setUp() throws Exception {
        jdbcUrl = "jdbc:oracle:thin:@a.b.c.d:1521:emdb";
        user = "wardon";
        password = "wardon";

        dataSource = new DruidDataSource();
        dataSource.setInitialSize(1);
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
        dataSource.setMaxActive(50);
View Full Code Here

public class TestIdel3 extends TestCase {

    public void test_idle2() throws Exception {
        MockDriver driver = new MockDriver();

        final DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setDriver(driver);
        dataSource.setInitialSize(1);
        dataSource.setMaxActive(14);
        dataSource.setMaxIdle(14);
        dataSource.setMinIdle(1);
        dataSource.setMinEvictableIdleTimeMillis(3 * 100); // 300 / 10
        dataSource.setTimeBetweenEvictionRunsMillis(18 * 10); // 180 / 10
        dataSource.setTestWhileIdle(true);
        dataSource.setTestOnBorrow(false);
        dataSource.setValidationQuery("SELECT 1");
        dataSource.setFilters("stat");

        ManagementFactory.getPlatformMBeanServer().registerMBean(dataSource,
                                                                 new ObjectName("com.alibaba:type=DataSource"));

        // 第一次创建连接
        {
            Assert.assertEquals(0, dataSource.getCreateCount());
            Assert.assertEquals(0, dataSource.getActiveCount());

            Connection conn = dataSource.getConnection();

            Assert.assertEquals(dataSource.getInitialSize(), dataSource.getCreateCount());
            Assert.assertEquals(dataSource.getInitialSize(), driver.getConnections().size());
            Assert.assertEquals(1, dataSource.getActiveCount());

            conn.close();
            Assert.assertEquals(0, dataSource.getDestroyCount());
            Assert.assertEquals(2, driver.getConnections().size());
            Assert.assertEquals(2, dataSource.getCreateCount());
            Assert.assertEquals(0, dataSource.getActiveCount());
        }

        {
            // 并发创建14个
            int count = 14;
            Connection[] connections = new Connection[count];
            for (int i = 0; i < count; ++i) {
                connections[i] = dataSource.getConnection();
                Assert.assertEquals(i + 1, dataSource.getActiveCount());
            }

            Assert.assertEquals(dataSource.getMaxActive(), dataSource.getCreateCount());
            Assert.assertEquals(count, driver.getConnections().size());

            // 全部关闭
            for (int i = 0; i < count; ++i) {
                connections[i].close();
                Assert.assertEquals(count - i - 1, dataSource.getActiveCount());
            }

            Assert.assertEquals(dataSource.getMaxActive(), dataSource.getCreateCount());
            Assert.assertEquals(0, dataSource.getActiveCount());
            Assert.assertEquals(14, driver.getConnections().size());
        }

        concurrent(dataSource, 100, 1000);
        concurrent(dataSource, 1, 1000 * 1000);
        Thread.sleep(1000 * 10);
        concurrent(dataSource, 1, 1000 * 1000);
        Thread.sleep(1000 * 10);
        concurrent(dataSource, 1000, 1000 * 1000);

        Assert.assertEquals(driver.getConnections().size(), dataSource.getPoolingCount());
        Assert.assertEquals(0, dataSource.getActiveCount());

        // 连续打开关闭单个连接
        for (int i = 0; i < 1000; ++i) {
            Assert.assertEquals(0, dataSource.getActiveCount());
            Connection conn = dataSource.getConnection();

            Assert.assertEquals(1, dataSource.getActiveCount());

            Thread.sleep(10);
            conn.close();
        }
        // Assert.assertEquals(2, dataSource.getPoolingCount());

        Thread.sleep(1000 * 100);
        dataSource.close();

    }
View Full Code Here

        jdbcUrl = "jdbc:mysql://hbase-01:3306/sonar";
        user = "sonar";
        password = "sonar";
        driverClass = "com.mysql.jdbc.Driver";

        dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(jdbcUrl);
        dataSource.setPoolPreparedStatements(true);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
View Full Code Here

        String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
        return pid;
    }

  protected void createDs() throws Exception {
        dataSource = new DruidDataSource();
        dataSource.setMinIdle(1);
        dataSource.setUrl("jdbc:h2:mem:test;");
        dataSource.setTestOnBorrow(false);
        dataSource.setFilters("stat");
        dataSource.setRemoveAbandoned(true);
View Full Code Here

        String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
        return pid;
    }

    protected void setUp() throws Exception {
        dataSource = new DruidDataSource();
        dataSource.setMinIdle(1);
        dataSource.setUrl("jdbc:h2:mem:test;");
        dataSource.setTestOnBorrow(false);
        dataSource.setFilters("stat");
        dataSource.setRemoveAbandoned(true);
        dataSource.setRemoveAbandonedTimeout(600);
        JdbcUtils.execute(dataSource, "CREATE TABLE user (id INT, name VARCHAR(40))");
        JdbcUtils.execute(dataSource, "insert into user values(20,'name1')");
        JdbcUtils.execute(dataSource, "insert into user values(30,'name2')");

        dataSource2 = new DruidDataSource();
        dataSource2.setMinIdle(1);
        dataSource2.setUrl("jdbc:h2:mem:test2;");
        dataSource2.setTestOnBorrow(false);
        dataSource2.setFilters("stat");
        dataSource2.setRemoveAbandoned(true);
View Full Code Here

public class QueryTimeoutTest extends TestCase {
    private DruidDataSource dataSource;

    protected void setUp() throws Exception {
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:oracle:thin:@a.b.c.d:1521:OINTEST");
        dataSource.setUsername("alibaba");
        dataSource.setPassword("deYcR7facWSJtCuDpm2r");
        dataSource.setInitialSize(1);
        dataSource.setMaxActive(14);
View Full Code Here

TOP

Related Classes of com.alibaba.druid.pool.DruidDataSource$ActiveConnectionTraceInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.