Search in sources :

Example 41 with SqlFieldsQueryEx

use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testCancel.

/**
 * @throws Exception if failed.
 */
@Test
public void testCancel() throws Exception {
    latch = new CountDownLatch(NODE_COUNT + 1);
    fillCaches();
    final IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).cache(CACHE_ORG);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() {
            return cache.query(new SqlFieldsQueryEx("UPDATE Organization SET name = WAIT(name)", false).setSkipReducerOnUpdate(true));
        }
    });
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            Collection<GridRunningQueryInfo> qCol = grid(NODE_CLIENT).context().query().runningQueries(0);
            if (qCol.isEmpty())
                return false;
            for (GridRunningQueryInfo queryInfo : qCol) queryInfo.cancel();
            return true;
        }
    }, 5000);
    latch.await(5000, MILLISECONDS);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws IgniteCheckedException {
            return fut.get();
        }
    }, IgniteCheckedException.class, "Future was cancelled");
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) Collection(java.util.Collection) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 42 with SqlFieldsQueryEx

use of org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx in project ignite by apache.

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testNodeStopDuringUpdate.

/**
 * @throws Exception if failed.
 */
@Test
public void testNodeStopDuringUpdate() throws Exception {
    startGrid(NODE_COUNT + 1);
    awaitPartitionMapExchange();
    fillCaches();
    latch = new CountDownLatch(NODE_COUNT + 1 + 1);
    final IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).cache(CACHE_ORG);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() {
            return cache.query(new SqlFieldsQueryEx("UPDATE Organization SET name = WAIT(name)", false).setSkipReducerOnUpdate(true));
        }
    });
    final CountDownLatch finalLatch = latch;
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return finalLatch.getCount() == 1;
        }
    }, 5000));
    latch.countDown();
    stopGrid(NODE_COUNT + 1);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws IgniteCheckedException {
            return fut.get();
        }
    }, IgniteCheckedException.class, "Update failed because map node left topology");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Aggregations

SqlFieldsQueryEx (org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx)42 Test (org.junit.Test)23 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)17 List (java.util.List)11 ArrayList (java.util.ArrayList)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)8 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)7 BatchUpdateException (java.sql.BatchUpdateException)6 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)6 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)5 SQLException (java.sql.SQLException)4 IgniteException (org.apache.ignite.IgniteException)4 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 BulkLoadContextCursor (org.apache.ignite.cache.query.BulkLoadContextCursor)3 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)3 IgniteLogger (org.apache.ignite.IgniteLogger)2 QueryCursor (org.apache.ignite.cache.query.QueryCursor)2 GridKernalContext (org.apache.ignite.internal.GridKernalContext)2