Search in sources :

Example 16 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinConnectionMvccEnabledSelfTest method testSetSavepoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testSetSavepoint() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        assert !conn.getMetaData().supportsSavepoints();
        // Disallowed in auto-commit mode
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.setSavepoint();
                return null;
            }
        }, SQLException.class, "Savepoint cannot be set in auto-commit mode");
        conn.setAutoCommit(false);
        // Unsupported
        checkNotSupported(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setSavepoint();
            }
        });
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setSavepoint();
            }
        });
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 17 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinConnectionMvccEnabledSelfTest method testCommit.

/**
 * @throws Exception If failed.
 */
@Test
public void testCommit() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        assertTrue(conn.getMetaData().supportsTransactions());
        // Should not be called in auto-commit mode
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.commit();
                return null;
            }
        }, SQLException.class, "Transaction cannot be committed explicitly in auto-commit mode");
        conn.setAutoCommit(false);
        conn.commit();
        conn.close();
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.commit();
            }
        });
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 18 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinConnectionSelfTest method testGetSetTransactionIsolation.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetSetTransactionIsolation() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        // Invalid parameter value
        assertThrows(log, new Callable<Object>() {

            @SuppressWarnings("MagicConstant")
            @Override
            public Object call() throws Exception {
                conn.setTransactionIsolation(-1);
                return null;
            }
        }, SQLException.class, "Invalid transaction isolation level");
        // default level
        assertEquals(TRANSACTION_NONE, conn.getTransactionIsolation());
        int[] levels = { TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE };
        for (int level : levels) {
            conn.setTransactionIsolation(level);
            assertEquals(level, conn.getTransactionIsolation());
        }
        conn.close();
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.getTransactionIsolation();
            }
        });
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.setTransactionIsolation(TRANSACTION_SERIALIZABLE);
            }
        });
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Savepoint(java.sql.Savepoint) Test(org.junit.Test)

Example 19 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinResultSetSelfTest method testExceptionOnClosedResultSet.

/**
 * @throws Exception If failed.
 */
@Test
public void testExceptionOnClosedResultSet() throws Exception {
    final ResultSet rs = stmt.executeQuery(SQL);
    rs.close();
    // Must do nothing on closed result set
    rs.close();
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBoolean(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBoolean("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getByte(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getByte("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getShort(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getShort("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getInt(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getInt("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getLong(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getLong("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getFloat(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getFloat("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDouble(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDouble("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getString(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getString("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBytes(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getBytes("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate(1, new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getDate("id", new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime(1, new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTime("id", new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp(1);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp(1, new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getTimestamp("id", new GregorianCalendar());
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getObject("objVal");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getObject("objVal", TestObjectField.class);
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.wasNull();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getMetaData();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.next();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.last();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.afterLast();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.beforeFirst();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.first();
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.findColumn("id");
        }
    });
    checkResultSetClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            rs.getRow();
        }
    });
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) ResultSet(java.sql.ResultSet) GregorianCalendar(java.util.GregorianCalendar) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test)

Example 20 with RunnableX

use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.

the class JdbcThinStatementSelfTest method testGetSetMaxFieldSizeUnsupported.

/**
 * @throws Exception If failed.
 */
@org.junit.Test
public void testGetSetMaxFieldSizeUnsupported() throws Exception {
    assertEquals(0, stmt.getMaxFieldSize());
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            stmt.setMaxFieldSize(100);
            return null;
        }
    }, SQLFeatureNotSupportedException.class, "Field size limitation is not supported");
    assertEquals(0, stmt.getMaxFieldSize());
    stmt.close();
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.getMaxFieldSize();
        }
    });
    // Call on a closed statement
    checkStatementClosed(new RunnableX() {

        @Override
        public void runx() throws Exception {
            stmt.setMaxFieldSize(100);
        }
    });
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Aggregations

RunnableX (org.apache.ignite.testframework.GridTestUtils.RunnableX)63 SQLException (java.sql.SQLException)52 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)40 Test (org.junit.Test)39 Connection (java.sql.Connection)32 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 SQLClientInfoException (java.sql.SQLClientInfoException)25 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)25 IgniteException (org.apache.ignite.IgniteException)11 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)10 ResultSet (java.sql.ResultSet)9 Savepoint (java.sql.Savepoint)9 CacheException (javax.cache.CacheException)8 QueryIndex (org.apache.ignite.cache.QueryIndex)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 DatabaseMetaData (java.sql.DatabaseMetaData)5 PreparedStatement (java.sql.PreparedStatement)5 MalformedURLException (java.net.MalformedURLException)3 Statement (java.sql.Statement)3 Ignite (org.apache.ignite.Ignite)3