Search in sources :

Example 1 with ComputeTaskTimeoutException

use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.

the class GridJobCollisionCancelSelfTest method testCancel.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "AssignmentToCatchBlockParameter" })
@Test
public void testCancel() throws Exception {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    ignite.compute().localDeployTask(GridCancelTestTask.class, GridCancelTestTask.class.getClassLoader());
    ComputeTaskFuture<?> res0 = executeAsync(ignite.compute().withTimeout(maxJobExecTime * 2), GridCancelTestTask.class.getName(), null);
    try {
        Object res = res0.get();
        info("Cancel test result: " + res);
        synchronized (mux) {
            // Every execute must be called.
            assert execCnt <= SPLIT_COUNT : "Invalid execute count: " + execCnt;
            // Job returns 1 if was cancelled.
            assert (Integer) res <= SPLIT_COUNT : "Invalid task result: " + res;
            // Should be exactly the same as Jobs number.
            assert cancelCnt <= SPLIT_COUNT : "Invalid cancel count: " + cancelCnt;
            // One per start and one per stop and some that come with metrics update.
            assert colResolutionCnt > SPLIT_COUNT + 1 : "Invalid collision resolution count: " + colResolutionCnt;
        }
    } catch (ComputeTaskTimeoutException e) {
        error("Task execution got timed out.", e);
    } catch (Exception e) {
        assert e.getCause() != null;
        if (e.getCause() instanceof IgniteCheckedException)
            e = (Exception) e.getCause();
        if (e.getCause() instanceof IOException)
            e = (Exception) e.getCause();
        assert e.getCause() instanceof InterruptedException : "Invalid exception cause: " + e.getCause();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Ignite(org.apache.ignite.Ignite) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) IOException(java.io.IOException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with ComputeTaskTimeoutException

use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.

the class ComputeTaskRemoteSecurityContextTest method doNodeTest.

/**
 */
public void doNodeTest(boolean isClient) throws Exception {
    String login = isClient ? "cli" : "srv";
    IgniteEx ignite = grid(login);
    IgniteCompute compute = ignite.compute(ignite.cluster().forNodes(ignite.cluster().nodes()));
    if (failWithTimeout)
        compute.withTimeout(TEST_TASK_TIMEOUT);
    String taskName = mapAsync ? MapAsyncTestTask.class.getName() : TestTask.class.getName();
    ComputeTaskTimeoutException timeoutE = null;
    try {
        if (async)
            compute.executeAsync(taskName, login).get();
        else
            compute.execute(taskName, login);
        checkTaskEvents(login, login, REDUCER_SUCCEEDED_TASK_EVENTS, MAP_NODE_SUCCEEDED_TASK_EVENTS);
    } catch (ComputeTaskTimeoutException e) {
        if (!failWithTimeout)
            throw e;
        timeoutE = e;
    }
    if (failWithTimeout) {
        assertNotNull(timeoutE);
        checkTaskEvents(login, login, REDUCER_FAILED_TASK_EVENTS, MAP_NODE_FAILED_TASK_EVENTS);
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 3 with ComputeTaskTimeoutException

use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.

the class GridTaskTimeoutSelfTest method testSynchronousTimeoutMultithreaded.

/**
 * @throws Exception If failed.
 */
@Test
public void testSynchronousTimeoutMultithreaded() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    final AtomicBoolean finish = new AtomicBoolean();
    final AtomicInteger cnt = new AtomicInteger();
    final CountDownLatch finishLatch = new CountDownLatch(N_THREADS);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(PERIOD);
                info("Stopping test.");
                finish.set(true);
            } catch (InterruptedException ignored) {
                Thread.currentThread().interrupt();
            }
        }
    }).start();
    multithreaded(new Runnable() {

        @Override
        public void run() {
            while (!finish.get()) {
                try {
                    ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null);
                    fut.get();
                    assert false : "Task has not been timed out. Future: " + fut;
                } catch (ComputeTaskTimeoutException ignored) {
                // Expected.
                } catch (IgniteCheckedException e) {
                    // shouldn't happen
                    throw new IllegalStateException(e);
                } finally {
                    int cnt0 = cnt.incrementAndGet();
                    if (cnt0 % 100 == 0)
                        info("Tasks finished: " + cnt0);
                }
            }
            info("Thread " + Thread.currentThread().getId() + " finishing.");
            finishLatch.countDown();
        }
    }, N_THREADS);
    finishLatch.await();
// Grid will be stopped automatically on tearDown().
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Ignite(org.apache.ignite.Ignite) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with ComputeTaskTimeoutException

use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.

the class IgniteUtils method exceptionConverters.

/**
 * Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
 *
 * @return Exception converters.
 */
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
    Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
    m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
        }
    });
    m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteFutureCancelledException(e.getMessage(), e);
        }
    });
    m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteFutureTimeoutException(e.getMessage(), e);
        }
    });
    m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ClusterGroupEmptyException(e.getMessage(), e);
        }
    });
    m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
            ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
            if (checked.retryReadyFuture() != null)
                topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
            return topEx;
        }
    });
    m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteDeploymentException(e.getMessage(), e);
        }
    });
    m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ComputeTaskTimeoutException(e.getMessage(), e);
        }
    });
    m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ComputeTaskCancelledException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionRollbackException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionHeuristicException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            if (e.getCause() instanceof TransactionDeadlockException)
                return new TransactionTimeoutException(e.getMessage(), e.getCause());
            return new TransactionTimeoutException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionOptimisticException(e.getMessage(), e);
        }
    });
    m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
        }
    });
    m.put(IgniteTxSerializationCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionSerializationException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxDuplicateKeyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionDuplicateKeyException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxAlreadyCompletedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionAlreadyCompletedException(e.getMessage(), e);
        }
    });
    return m;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) TransactionDuplicateKeyException(org.apache.ignite.transactions.TransactionDuplicateKeyException) TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TransactionHeuristicException(org.apache.ignite.transactions.TransactionHeuristicException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) C1(org.apache.ignite.internal.util.typedef.C1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) TransactionAlreadyCompletedException(org.apache.ignite.transactions.TransactionAlreadyCompletedException) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 5 with ComputeTaskTimeoutException

use of org.apache.ignite.compute.ComputeTaskTimeoutException in project ignite by apache.

the class GridTaskTimeoutSelfTest method testSynchronousTimeout.

/**
 * @throws Exception If failed.
 */
@Test
public void testSynchronousTimeout() throws Exception {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader());
    ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null);
    try {
        fut.get();
        assert false : "ComputeTaskTimeoutException was not thrown (synchronous apply)";
    } catch (ComputeTaskTimeoutException e) {
        info("Received expected timeout exception (synchronous apply): " + e);
    }
    Thread.sleep(TIMEOUT + 500);
    checkTimedOutEvents(fut.getTaskSession().getId());
}
Also used : Ignite(org.apache.ignite.Ignite) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ComputeTaskTimeoutException (org.apache.ignite.compute.ComputeTaskTimeoutException)5 Ignite (org.apache.ignite.Ignite)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteCompute (org.apache.ignite.IgniteCompute)1 IgniteDeploymentException (org.apache.ignite.IgniteDeploymentException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 ClusterGroupEmptyException (org.apache.ignite.cluster.ClusterGroupEmptyException)1