Search in sources :

Example 6 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestFastList method testOverflow.

@Test
public void testOverflow() {
    ArrayList<Statement> verifyList = new ArrayList<>();
    FastList<Statement> list = new FastList<>(Statement.class);
    for (int i = 0; i < 100; i++) {
        StubStatement statement = new StubStatement(null);
        list.add(statement);
        verifyList.add(statement);
    }
    for (int i = 0; i < 100; i++) {
        assertNotNull("Element " + i, list.get(i));
        assertSame(verifyList.get(i), list.get(i));
    }
}
Also used : Statement(java.sql.Statement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestProxies method testStatementProxy.

@Test
public void testStatementProxy() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(1);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        Connection conn = ds.getConnection();
        PreparedStatement stmt = conn.prepareStatement("some sql");
        stmt.executeQuery();
        stmt.executeQuery("some sql");
        assertFalse(stmt.isClosed());
        assertNotNull(stmt.getGeneratedKeys());
        assertNotNull(stmt.getResultSet());
        assertNotNull(stmt.getConnection());
        assertTrue(stmt.unwrap(StubStatement.class) instanceof StubStatement);
        try {
            stmt.unwrap(TestProxies.class);
            fail();
        } catch (SQLException e) {
        // pass
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) StubStatement(com.zaxxer.hikari.mocks.StubStatement) Connection(java.sql.Connection) StubConnection(com.zaxxer.hikari.mocks.StubConnection) PreparedStatement(java.sql.PreparedStatement) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Aggregations

StubStatement (com.zaxxer.hikari.mocks.StubStatement)7 Test (org.junit.Test)7 Statement (java.sql.Statement)6 ArrayList (java.util.ArrayList)3 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 StubConnection (com.zaxxer.hikari.mocks.StubConnection)1 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1