Search in sources :

Example 1 with MySqlValidConnectionChecker

use of com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker in project druid by alibaba.

the class DataSourceTest3 method test_error_validateConnection_3.

public void test_error_validateConnection_3() throws Exception {
    dataSource.setValidationQuery(null);
    dataSource.setValidConnectionChecker(new MySqlValidConnectionChecker());
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    dataSource.validateConnection(conn);
}
Also used : MySqlValidConnectionChecker(com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 2 with MySqlValidConnectionChecker

use of com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker in project druid by alibaba.

the class DataSourceTest3 method test_ValidConnectionChecker.

public void test_ValidConnectionChecker() throws Exception {
    dataSource.getValidConnectionCheckerClassName();
    dataSource.setValidConnectionChecker(new MySqlValidConnectionChecker());
    Assert.assertEquals(MySqlValidConnectionChecker.class.getName(), dataSource.getValidConnectionCheckerClassName());
}
Also used : MySqlValidConnectionChecker(com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker)

Example 3 with MySqlValidConnectionChecker

use of com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker in project druid by alibaba.

the class MySQLValidConnectionCheckerTest method setUp.

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);
}
Also used : MySqlValidConnectionChecker(com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 4 with MySqlValidConnectionChecker

use of com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker in project druid by alibaba.

the class MySQLValidConnectionCheckerTest method test_connect.

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();
}
Also used : MySqlValidConnectionChecker(com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker) Connection(java.sql.Connection)

Aggregations

MySqlValidConnectionChecker (com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)1 Connection (java.sql.Connection)1