Package com.alibaba.druid.mock

Examples of com.alibaba.druid.mock.MockConnection


        Assert.assertFalse(k3.equals(k1));
    }

    public void test_contains() throws Exception {
        DruidDataSource dataSource = new DruidDataSource();
        MockConnection conn = new MockConnection();
        PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);

        PreparedStatementPool pool = new PreparedStatementPool(new DruidConnectionHolder(dataSource, conn));
        MockPreparedStatement raw = new MockPreparedStatement(null, null);
        pool.put(new PreparedStatementHolder(k1, raw));
View Full Code Here


            pstmt.close();
            conn.close();
        }

        DruidPooledConnection conn = dataSource.getConnection();
        MockConnection mockConn = conn.unwrap(MockConnection.class);
        Assert.assertNotNull(mockConn);

        Statement stmt = conn.createStatement();
        stmt.execute(sql);

        SQLException exception = new SQLException("xx", "xxx", 28);
        mockConn.setError(exception);

        SQLException stmtErrror = null;
        try {
            stmt.getResultSet();
        } catch (SQLException ex) {
View Full Code Here

            pstmt.close();
            conn.close();
        }

        DruidPooledConnection conn = dataSource.getConnection();
        MockConnection mockConn = conn.unwrap(MockConnection.class);
        Assert.assertNotNull(mockConn);

        Statement stmt = conn.createStatement();

        SQLException exception = new SQLException("xx", "xxx", 28);
        mockConn.setError(exception);

        SQLException stmtErrror = null;
        try {
            stmt.setQueryTimeout(10);
        } catch (SQLException ex) {
View Full Code Here

        // dataSource is closed, but connections is not closed
        Assert.assertFalse(conn_0.isClosed());
        Assert.assertFalse(conn_1.isClosed());
        Assert.assertFalse(conn_2.isClosed());
       
        MockConnection mockConn_0 = conn_0.unwrap(MockConnection.class);
        MockConnection mockConn_1 = conn_1.unwrap(MockConnection.class);
        MockConnection mockConn_2 = conn_2.unwrap(MockConnection.class);
       
        Assert.assertFalse(mockConn_0.isClosed());
        Assert.assertFalse(mockConn_1.isClosed());
        Assert.assertFalse(mockConn_2.isClosed());
       
        conn_0.close(); // no error
        conn_1.close(); // no error
        conn_2.close(); // no error
       
        // real connection already closed
        Assert.assertTrue(mockConn_0.isClosed());
        Assert.assertTrue(mockConn_1.isClosed());
        Assert.assertTrue(mockConn_2.isClosed());
       
        // now is new dataSource;
        dataSource = clone;
       
        Connection conn_6 = dataSource.getConnection();
View Full Code Here

            pstmt.close();
            conn.close();
        }

        DruidPooledConnection conn = dataSource.getConnection();
        MockConnection mockConn = conn.unwrap(MockConnection.class);
        Assert.assertNotNull(mockConn);

        Statement stmt = conn.createStatement();

        SQLException exception = new SQLException("xx", "xxx", 28);
        mockConn.setError(exception);

        SQLException execErrror = null;
        try {
            stmt.executeQuery(sql);
        } catch (SQLException ex) {
View Full Code Here

public class MSSQLValidConnectionCheckerTest extends TestCase {

    public void test_0() throws Exception {
        MSSQLValidConnectionChecker checker = new MSSQLValidConnectionChecker();

        MockConnection conn = new MockConnection();

        Assert.assertTrue(checker.isValidConnection(conn, "select 1", 10));

    }
View Full Code Here

    }

    public void test_closed() throws Exception {
        MSSQLValidConnectionChecker checker = new MSSQLValidConnectionChecker();

        MockConnection conn = new MockConnection();

        conn.close();
        Assert.assertFalse(checker.isValidConnection(conn, "select 1", 10));
    }
View Full Code Here

    }

    public void test_error() throws Exception {
        MSSQLValidConnectionChecker checker = new MSSQLValidConnectionChecker();

        MockConnection conn = new MockConnection();
        conn.setError(new SQLException());

        Assert.assertFalse(checker.isValidConnection(conn, "select 1", 10));
    }
View Full Code Here

            pstmt.close();
            conn.close();
        }

        DruidPooledConnection conn = dataSource.getConnection();
        MockConnection mockConn = conn.unwrap(MockConnection.class);
        Assert.assertNotNull(mockConn);

        Statement stmt = conn.createStatement();

        SQLException exception = new SQLException("xx", "xxx", 28);
        mockConn.setError(exception);

        SQLException stmtErrror = null;
        try {
            stmt.setMaxFieldSize(10);
        } catch (SQLException ex) {
View Full Code Here

            pstmt.close();
            conn.close();
        }

        DruidPooledConnection conn = dataSource.getConnection();
        MockConnection mockConn = conn.unwrap(MockConnection.class);
        Assert.assertNotNull(mockConn);

        Statement stmt = conn.createStatement();

        SQLException exception = new SQLException("xx", "xxx", 28);
        mockConn.setError(exception);

        SQLException execErrror = null;
        try {
            stmt.execute(sql, new int[0]);
        } catch (SQLException ex) {
View Full Code Here

TOP

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

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.