Package com.alibaba.druid.bvt.pool.vendor

Source Code of com.alibaba.druid.bvt.pool.vendor.MySQLValidConnectionCheckerTest

package com.alibaba.druid.bvt.pool.vendor;

import java.sql.Connection;

import junit.framework.TestCase;

import org.junit.Assert;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker;

public class MySQLValidConnectionCheckerTest extends TestCase {

    private DruidDataSource dataSource;

    protected void setUp() throws Exception {
        System.setProperty("druid.mysql.usePingMethod", "false");

        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setDbType("mysql");
        dataSource.setValidationQuery("select 1");
        dataSource.setValidConnectionChecker(new MySqlValidConnectionChecker());
        dataSource.setInitialSize(1);
        dataSource.setTestOnBorrow(true);
    }

    protected void tearDown() throws Exception {
        dataSource.close();

        System.clearProperty("druid.mysql.usePingMethod");
    }

    public void test_connect() throws Exception {
        {
            Connection conn = dataSource.getConnection();
            conn.close();
        }

        MySqlValidConnectionChecker checker = (MySqlValidConnectionChecker) dataSource.getValidConnectionChecker();
        Assert.assertFalse(checker.isUsePingMethod());

        dataSource.setConnectionProperties("druid.mysql.usePingMethod=true");

        Assert.assertTrue(checker.isUsePingMethod());

        Connection conn = dataSource.getConnection();
        conn.close();
    }

}
TOP

Related Classes of com.alibaba.druid.bvt.pool.vendor.MySQLValidConnectionCheckerTest

TOP
Copyright © 2018 www.massapi.com. 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.