Search in sources :

Example 86 with RunnableX

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

the class JdbcThinConnectionMvccEnabledSelfTest method testRollback.

/**
 * @throws Exception If failed.
 */
@Test
public void testRollback() 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.rollback();
                return null;
            }
        }, SQLException.class, "Transaction cannot be rolled back explicitly in auto-commit mode.");
        conn.setAutoCommit(false);
        conn.rollback();
        conn.close();
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

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

Example 87 with RunnableX

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

the class JdbcThinConnectionMvccEnabledSelfTest method testRollbackSavePoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testRollbackSavePoint() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        assert !conn.getMetaData().supportsSavepoints();
        // Invalid arg
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.rollback(null);
                return null;
            }
        }, SQLException.class, "Invalid savepoint");
        final Savepoint savepoint = getFakeSavepoint();
        // Disallowed in auto-commit mode
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.rollback(savepoint);
                return null;
            }
        }, SQLException.class, "Auto-commit mode");
        conn.setAutoCommit(false);
        // Unsupported
        checkNotSupported(new RunnableX() {

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

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

Example 88 with RunnableX

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

the class JdbcThinConnectionMvccEnabledSelfTest method testGetSetAutoCommit.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetSetAutoCommit() throws Exception {
    try (Connection conn = DriverManager.getConnection(URL)) {
        assertTrue(conn.getMetaData().supportsTransactions());
        assertTrue(conn.getAutoCommit());
        conn.setAutoCommit(false);
        assertFalse(conn.getAutoCommit());
        conn.setAutoCommit(true);
        assertTrue(conn.getAutoCommit());
        conn.close();
        // Exception when called on closed connection
        checkConnectionClosed(new RunnableX() {

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

Example 89 with RunnableX

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

the class DynamicColumnsAbstractConcurrentSelfTest method checkClientReconnect.

/**
 * Make sure that client receives schema changes made while it was disconnected, optionally with cache restart
 * in the interim.
 *
 * @param restartCache Whether cache needs to be recreated during client's absence.
 * @param dynamicCache Whether recreate, if needed, should be done on dynamic or static cache.
 * @throws Exception If failed.
 */
private void checkClientReconnect(final boolean restartCache, boolean dynamicCache) throws Exception {
    // Start complex topology.
    final IgniteEx srv = ignitionStart(serverConfiguration(1));
    ignitionStart(serverConfiguration(2));
    ignitionStart(serverConfiguration(3, true));
    final Ignite cli = ignitionStart(clientConfiguration(4));
    if (dynamicCache) {
        createSqlCache(cli);
        run(cli, createSql);
    }
    final String schemaName = dynamicCache ? QueryUtils.DFLT_SCHEMA : "idx";
    final QueryField[] cols = new QueryField[] { c("age", Integer.class.getName()), c("city", String.class.getName()) };
    // Check index create.
    reconnectClientNode(srv, cli, restartCache, dynamicCache, new RunnableX() {

        @Override
        public void runx() throws Exception {
            addCols(srv, schemaName, cols).get();
            dropCols(srv, schemaName, "NAME").get();
        }
    });
    checkTableState(srv, schemaName, TBL_NAME, cols);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryField(org.apache.ignite.internal.processors.query.QueryField) IgniteEx(org.apache.ignite.internal.IgniteEx) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Ignite(org.apache.ignite.Ignite) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Example 90 with RunnableX

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

the class DynamicIndexAbstractBasicSelfTest method checkDropNoIndex.

/**
 * Check drop when there is no index.
 *
 * @param mode Mode.
 * @param atomicityMode Atomicity mode.
 * @param near Near flag.
 * @throws Exception If failed.
 */
private void checkDropNoIndex(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    assertIgniteSqlException(new RunnableX() {

        @Override
        public void runx() throws Exception {
            dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, false);
        }
    }, IgniteQueryErrorCode.INDEX_NOT_FOUND);
    dynamicIndexDrop(CACHE_NAME, IDX_NAME_1, true);
    assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Aggregations

RunnableX (org.apache.ignite.testframework.GridTestUtils.RunnableX)126 SQLException (java.sql.SQLException)104 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)80 Test (org.junit.Test)78 Connection (java.sql.Connection)64 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)54 SQLClientInfoException (java.sql.SQLClientInfoException)50 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)50 IgniteException (org.apache.ignite.IgniteException)22 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)20 ResultSet (java.sql.ResultSet)18 Savepoint (java.sql.Savepoint)18 CacheException (javax.cache.CacheException)16 QueryIndex (org.apache.ignite.cache.QueryIndex)16 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)16 DatabaseMetaData (java.sql.DatabaseMetaData)10 PreparedStatement (java.sql.PreparedStatement)10 MalformedURLException (java.net.MalformedURLException)6 Statement (java.sql.Statement)6 Ignite (org.apache.ignite.Ignite)6