Search in sources :

Example 36 with RunnableX

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

the class JdbcThinConnectionSelfTest method testCreateArrayOf.

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateArrayOf() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        final String typeName = "varchar";
        final String[] elements = new String[] { "apple", "pear" };
        // Invalid typename
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.createArrayOf(null, null);
                return null;
            }
        }, SQLException.class, "Type name cannot be null");
        // Unsupported
        checkNotSupported(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.createArrayOf(typeName, elements);
            }
        });
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.createArrayOf(typeName, elements);
            }
        });
    }
}
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) Test(org.junit.Test)

Example 37 with RunnableX

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

the class JdbcThinConnectionSelfTest method testRollbackSavePoint.

/**
 * @throws Exception If failed.
 */
@Test
public void testRollbackSavePoint() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        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.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) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) Savepoint(java.sql.Savepoint) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 38 with RunnableX

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

the class JdbcThinConnectionSelfTest method testGetSetClientInfoProperties.

/**
 * @throws Exception If failed.
 */
@Test
public void testGetSetClientInfoProperties() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        final String name = "ApplicationName";
        final String val = "SelfTest";
        final Properties props = new Properties();
        props.setProperty(name, val);
        conn.setClientInfo(props);
        Properties propsResult = conn.getClientInfo();
        assertNotNull(propsResult);
        assertTrue(propsResult.isEmpty());
        conn.close();
        checkConnectionClosed(new RunnableX() {

            @Override
            public void runx() throws Exception {
                conn.getClientInfo();
            }
        });
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.setClientInfo(props);
                return null;
            }
        }, SQLClientInfoException.class, "Connection is closed");
    }
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) ConnectionProperties(org.apache.ignite.internal.jdbc.thin.ConnectionProperties) Properties(java.util.Properties) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 39 with RunnableX

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

the class JdbcThinConnectionMvccEnabledSelfTest method testSetSavepointName.

/**
 * @throws Exception If failed.
 */
@Test
public void testSetSavepointName() 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.setSavepoint(null);
                return null;
            }
        }, SQLException.class, "Savepoint name cannot be null");
        final String name = "savepoint";
        // Disallowed in auto-commit mode
        assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                conn.setSavepoint(name);
                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(name);
            }
        });
        conn.close();
        checkConnectionClosed(new RunnableX() {

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

Example 40 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)

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