Search in sources :

Example 31 with RunnableX

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

the class DynamicIndexAbstractConcurrentSelfTest 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.
 * @throws Exception If failed.
 */
private void checkClientReconnect(final boolean restartCache) throws Exception {
    // Start complex topology.
    final Ignite srv = ignitionStart(serverConfiguration(1));
    ignitionStart(serverConfiguration(2));
    ignitionStart(serverConfiguration(3, true));
    final Ignite cli = ignitionStart(clientConfiguration(4));
    createSqlCache(cli);
    // Check index create.
    reconnectClientNode(srv, cli, restartCache, new RunnableX() {

        @Override
        public void runx() throws Exception {
            final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1));
            queryProcessor(srv).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false, 0).get();
        }
    });
    assertIndex(cli, CACHE_NAME, TBL_NAME, IDX_NAME_1, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1));
    assertIndexUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
    // Check index drop.
    reconnectClientNode(srv, cli, restartCache, new RunnableX() {

        @Override
        public void runx() throws Exception {
            if (!restartCache)
                queryProcessor(srv).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_1, false).get();
        }
    });
    assertNoIndex(cli, CACHE_NAME, TBL_NAME, IDX_NAME_1);
    assertIndexNotUsed(IDX_NAME_1, SQL_SIMPLE_FIELD_1, SQL_ARG_1);
    // Update existing index.
    QueryIndex idx = index(IDX_NAME_2, field(aliasUnescaped(FIELD_NAME_2)));
    queryProcessor(srv).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false, 0).get();
    assertIndex(cli, CACHE_NAME, TBL_NAME, IDX_NAME_2, QueryIndex.DFLT_INLINE_SIZE, field(aliasUnescaped(FIELD_NAME_2)));
    assertIndexUsed(IDX_NAME_2, SQL_SIMPLE_FIELD_2, SQL_ARG_2);
    reconnectClientNode(srv, cli, restartCache, new RunnableX() {

        @Override
        public void runx() throws Exception {
            if (!restartCache)
                queryProcessor(srv).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_2, false).get();
            final QueryIndex idx = index(IDX_NAME_2, field(FIELD_NAME_1), field(aliasUnescaped(FIELD_NAME_2)));
            queryProcessor(srv).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, false, 0).get();
        }
    });
    assertIndex(CACHE_NAME, TBL_NAME, IDX_NAME_2, QueryIndex.DFLT_INLINE_SIZE, field(FIELD_NAME_1), field(aliasUnescaped(FIELD_NAME_2)));
    assertIndexUsed(IDX_NAME_2, SQL_COMPOSITE, SQL_ARG_1, SQL_ARG_2);
}
Also used : RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Example 32 with RunnableX

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

the class JmxExporterSpiTest method testFilterAndExport.

/**
 */
@Test
public void testFilterAndExport() throws Exception {
    createAdditionalMetrics(ignite);
    assertThrowsWithCause(new RunnableX() {

        @Override
        public void runx() throws Exception {
            metricRegistry(ignite.name(), "filtered", "metric");
        }
    }, IgniteException.class);
    DynamicMBean bean1 = metricRegistry(ignite.name(), "other", "prefix");
    assertEquals(42L, bean1.getAttribute("test"));
    assertEquals(43L, bean1.getAttribute("test2"));
    DynamicMBean bean2 = metricRegistry(ignite.name(), "other", "prefix2");
    assertEquals(44L, bean2.getAttribute("test3"));
}
Also used : DynamicMBean(javax.management.DynamicMBean) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Example 33 with RunnableX

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

the class JdbcThinConnectionSelfTest method testCommit.

/**
 * @throws Exception If failed.
 */
@Test
public void testCommit() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        // 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");
        assertTrue(conn.getAutoCommit());
        // 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.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) 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 34 with RunnableX

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

the class JdbcThinConnectionSelfTest method testCreateStatement.

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateStatement() throws Exception {
    try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
        try (Statement stmt = conn.createStatement()) {
            assertNotNull(stmt);
            stmt.close();
            conn.close();
            // Exception when called on closed connection
            checkConnectionClosed(new RunnableX() {

                @Override
                public void runx() throws Exception {
                    conn.createStatement();
                }
            });
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) 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 35 with RunnableX

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

the class JdbcThinConnectionSelfTest method testCreateStruct.

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

            @Override
            public Object call() throws Exception {
                return conn.createStruct(null, null);
            }
        }, SQLException.class, "Type name cannot be null");
        final String typeName = "employee";
        final Object[] attrs = new Object[] { 100, "Tom" };
        checkNotSupported(new RunnableX() {

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

            @Override
            public void runx() throws Exception {
                conn.createStruct(typeName, attrs);
            }
        });
    }
}
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)

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