Search in sources :

Example 6 with MockStatement

use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.

the class Bug_for_happyday517 method test_for_happyday517_0.

public void test_for_happyday517_0() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    MockStatement mockStmt = stmt.unwrap(MockStatement.class);
    Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
    Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
    stmt.close();
    conn.close();
}
Also used : MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) MockStatement(com.alibaba.druid.mock.MockStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) MockStatement(com.alibaba.druid.mock.MockStatement)

Example 7 with MockStatement

use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.

the class FilterChainImplTest3 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setFilters("stat,log4j,wall,encoding");
    dataSource.getProxyFilters().add(new FilterAdapter() {
    });
    dataSource.setDbType("mysql");
    dataSource.setDriver(new MockDriver() {

        public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
            return null;
        }

        public MockStatement createMockStatement(MockConnection conn) {
            return new MockStatement(conn) {

                public ResultSet getResultSet() throws SQLException {
                    return null;
                }
            };
        }
    });
    dataSource.init();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) MockStatement(com.alibaba.druid.mock.MockStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection) MockStatementBase(com.alibaba.druid.mock.MockStatementBase)

Example 8 with MockStatement

use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.

the class TestLogLongTimeTransaction method setUp.

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

        protected ResultSet executeQuery(MockStatement stmt, String sql) throws SQLException {
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return super.executeQuery(stmt, sql);
        }
    };
    dataSource = new DruidDataSource();
    dataSource.setDriver(driver);
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setFilters("stat,trace,log4j,encoding");
    dataSource.setTransactionThresholdMillis(1);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) MockStatement(com.alibaba.druid.mock.MockStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 9 with MockStatement

use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.

the class LogFilterTest method test_logFilter_2.

public void test_logFilter_2() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    config.setRawUrl("jdbc:mock:");
    DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
    Log4jFilter log4jFilter = new Log4jFilter();
    {
        log4jFilter.init(dataSource);
        setLogDisableAll(log4jFilter, true);
        config.getFilters().add(log4jFilter);
    }
    CommonsLogFilter logFilter = new CommonsLogFilter();
    {
        logFilter.init(dataSource);
        setLogDisableAll(logFilter, true);
        config.getFilters().add(logFilter);
    }
    final MockResultSetMetaData rsMeta = new MockResultSetMetaData() {

        private int[] types = new int[] { Types.BLOB, Types.CLOB, Types.NCLOB, Types.BINARY, Types.OTHER };

        @Override
        public int getColumnCount() throws SQLException {
            return types.length;
        }

        @Override
        public int getColumnType(int column) throws SQLException {
            return types[column - 1];
        }
    };
    ConnectionProxy conn = (ConnectionProxy) dataSource.connect(new Properties());
    {
        StatementProxy stmt = (StatementProxy) conn.createStatement();
        MockResultSet rs = new MockResultSet(null) {

            @Override
            public ResultSetMetaData getMetaData() throws SQLException {
                return rsMeta;
            }

            @Override
            public boolean next() throws SQLException {
                return true;
            }

            @Override
            public Object getObject(int columnIndex) throws SQLException {
                if (columnIndex == 5) {
                    throw new SQLException();
                }
                return null;
            }
        };
        FilterChainImpl chain = new FilterChainImpl(dataSource);
        chain.resultSet_next(new ResultSetProxyImpl(stmt, rs, 1001, null));
    }
    {
        final MockResultSet rs = new MockResultSet(null) {

            @Override
            public ResultSetMetaData getMetaData() throws SQLException {
                throw new SQLException();
            }
        };
        StatementProxy stmt = new StatementProxyImpl(conn, new MockStatement(conn) {

            public ResultSet getResultSet() throws SQLException {
                return rs;
            }
        }, 0);
        FilterChainImpl chain = new FilterChainImpl(dataSource);
        chain.statement_getResultSet(stmt);
    }
    {
        StatementProxy stmt = (StatementProxy) conn.createStatement();
        MockResultSet rs = new MockResultSet(null) {

            @Override
            public ResultSetMetaData getMetaData() throws SQLException {
                return rsMeta;
            }

            @Override
            public boolean next() throws SQLException {
                return true;
            }

            @Override
            public Object getObject(int columnIndex) throws SQLException {
                if (columnIndex == 5) {
                    throw new SQLException();
                }
                return null;
            }
        };
        {
            logFilter.setResultSetLogEnabled(false);
            FilterChainImpl chain = new FilterChainImpl(dataSource);
            chain.resultSet_next(new ResultSetProxyImpl(stmt, rs, 1001, null));
        }
        {
            logFilter.setResultSetNextAfterLogEnabled(false);
            FilterChainImpl chain = new FilterChainImpl(dataSource);
            chain.resultSet_next(new ResultSetProxyImpl(stmt, rs, 1001, null));
        }
    }
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) CommonsLogFilter(com.alibaba.druid.filter.logging.CommonsLogFilter) FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) MockResultSetMetaData(com.alibaba.druid.mock.MockResultSetMetaData) SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet) Properties(java.util.Properties) ResultSetProxyImpl(com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy) StatementProxyImpl(com.alibaba.druid.proxy.jdbc.StatementProxyImpl) MockResultSetMetaData(com.alibaba.druid.mock.MockResultSetMetaData) ResultSetMetaData(java.sql.ResultSetMetaData) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) MockStatement(com.alibaba.druid.mock.MockStatement)

Aggregations

MockStatement (com.alibaba.druid.mock.MockStatement)9 SQLException (java.sql.SQLException)5 MockConnection (com.alibaba.druid.mock.MockConnection)4 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 Connection (java.sql.Connection)4 Statement (java.sql.Statement)4 MockDriver (com.alibaba.druid.mock.MockDriver)3 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockResultSet (com.alibaba.druid.mock.MockResultSet)2 DruidNativeJdbcExtractor (com.alibaba.druid.support.spring.DruidNativeJdbcExtractor)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)1 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 CommonsLogFilter (com.alibaba.druid.filter.logging.CommonsLogFilter)1 Log4jFilter (com.alibaba.druid.filter.logging.Log4jFilter)1 MockResultSetMetaData (com.alibaba.druid.mock.MockResultSetMetaData)1 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)1 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)1