Package com.alibaba.druid.mock

Examples of com.alibaba.druid.mock.MockDriver


    private DruidDataSource dataSource;

    protected void setUp() throws Exception {
        DruidDataSourceStatManager.clear();

        driver = new MockDriver();

        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setDriver(driver);
        dataSource.setInitialSize(1);
View Full Code Here


    protected void tearDown() throws Exception {
        Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
    }

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

        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(30 * 10); // 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(1, driver.getConnections().size());
            Assert.assertEquals(1, dataSource.getCreateCount());
            Assert.assertEquals(0, dataSource.getActiveCount());
        }

        {
View Full Code Here

    private DruidDataSourceC3P0Adapter dataSource;

    protected void setUp() throws Exception {
        Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());

        driver = new MockDriver();

        dataSource = new DruidDataSourceC3P0Adapter();
        dataSource.setJdbcUrl("jdbc:mock:xxx");
        dataSource.setDriver(driver);
        dataSource.setInitialPoolSize(1);
View Full Code Here

    private DruidDataSource dataSource;

    protected void setUp() throws Exception {
        DruidDataSourceStatManager.clear();

        driver = new MockDriver();

        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setDriver(driver);
        dataSource.setInitialSize(1);
View Full Code Here

    protected void setUp() throws Exception {
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setDbType(JdbcConstants.DB2);
        dataSource.setDriver(new MockDriver() {
            public int getMajorVersion() {
                return 10;
            }
        });
        dataSource.setValidationQuery("SELECT 'x'");
View Full Code Here

    protected void setUp() throws Exception {
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setTestOnBorrow(false);
        dataSource.setRemoveAbandoned(true);
        dataSource.setDriver(new MockDriver() {

            public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
                throw new SQLException();
            }
        });
View Full Code Here

    public void test_0() throws Exception {

        final DruidDataSource dataSource = new DruidDataSource();

        dataSource.setDriver(new MockDriver() {

        });
        dataSource.setUrl("jdbc:mock:");

        dataSource.setMinIdle(0);
View Full Code Here

    private DruidDataSource dataSource;
    private MockDriver      driver;

    protected void setUp() throws Exception {
        driver = new MockDriver() {

            private AtomicInteger count = new AtomicInteger();

            public Connection connect(String url, Properties info) throws SQLException {
                if (count.getAndIncrement() % 2 == 0) {
View Full Code Here

        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();
View Full Code Here

    private MockDriver      driver;
    private DruidDataSource dataSource;

    protected void setUp() throws Exception {
        driver = new MockDriver();

        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setDriver(driver);
        dataSource.setInitialSize(1);
View Full Code Here

TOP

Related Classes of com.alibaba.druid.mock.MockDriver

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.