Search in sources :

Example 1 with IgniteFutureCancelledException

use of org.apache.ignite.lang.IgniteFutureCancelledException in project ignite by apache.

the class GridTaskCancelSingleNodeSelfTest method checkCancellation.

/**
     * @param timeoutBeforeCancel Timeout.
     * @throws Exception If failed.
     */
@SuppressWarnings("ErrorNotRethrown")
private void checkCancellation(long timeoutBeforeCancel) throws Exception {
    final AtomicInteger finished = new AtomicInteger();
    final AtomicInteger cancelled = new AtomicInteger();
    final AtomicInteger rejected = new AtomicInteger();
    final AtomicBoolean jobStarted = new AtomicBoolean();
    grid().events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            info("Received event: " + evt);
            switch(evt.type()) {
                case EVT_JOB_STARTED:
                    jobStarted.set(true);
                    break;
                case EVT_JOB_FINISHED:
                    finished.incrementAndGet();
                    break;
                case EVT_JOB_CANCELLED:
                    cancelled.incrementAndGet();
                    break;
                case EVT_JOB_REJECTED:
                    rejected.incrementAndGet();
                    break;
                default:
                    assert false : "Unexpected event: " + evt;
            }
            return true;
        }
    }, EVT_JOB_STARTED, EVT_JOB_FINISHED, EVT_JOB_CANCELLED, EVT_JOB_REJECTED);
    ComputeTaskFuture<?> fut = grid().compute().executeAsync(TestTask.class, null);
    if (timeoutBeforeCancel > 0L)
        Thread.sleep(timeoutBeforeCancel);
    assert fut.cancel();
    for (int i = 0; i < 3; i++) {
        try {
            if (timeoutBeforeCancel == 0L) {
                if (jobStarted.get())
                    assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get() + ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']', finished.get() == 1 && cancelled.get() == 1 && rejected.get() == 0);
                else {
                    // job can be rejected if was concurrently cancelled before started
                    assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get() + ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']', finished.get() == 0 && cancelled.get() == 0 && rejected.get() <= 1);
                }
            } else
                assertTrue("Failed on iteration [i=" + i + ", finished=" + finished.get() + ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']', finished.get() == 1 && cancelled.get() == 1 && rejected.get() == 0);
        } catch (AssertionError e) {
            info("Check failed: " + e.getMessage());
            if (timeoutBeforeCancel == 0L && i == 2)
                throw e;
        }
        if (i < 2)
            U.sleep(500);
    }
    try {
        fut.get();
        fail();
    } catch (IgniteFutureCancelledException e) {
        info("Caught expected exception: " + e);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Event(org.apache.ignite.events.Event) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException)

Example 2 with IgniteFutureCancelledException

use of org.apache.ignite.lang.IgniteFutureCancelledException in project ignite by apache.

the class DataStreamProcessorSelfTest method testLoaderApi.

/**
     * @throws Exception If failed.
     */
public void testLoaderApi() throws Exception {
    useCache = true;
    try {
        Ignite g1 = startGrid(1);
        IgniteDataStreamer<Object, Object> ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
        ldr.close(false);
        try {
            ldr.addData(0, 0);
            assert false;
        } catch (IllegalStateException e) {
            info("Caught expected exception: " + e);
        }
        assert ldr.future().isDone();
        ldr.future().get();
        try {
            // Create another loader.
            ldr = g1.dataStreamer("UNKNOWN_CACHE");
            assert false;
        } catch (IllegalStateException e) {
            info("Caught expected exception: " + e);
        }
        ldr.close(true);
        assert ldr.future().isDone();
        ldr.future().get();
        // Create another loader.
        ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
        // Cancel with future.
        ldr.future().cancel();
        try {
            ldr.addData(0, 0);
            assert false;
        } catch (IllegalStateException e) {
            info("Caught expected exception: " + e);
        }
        assert ldr.future().isDone();
        try {
            ldr.future().get();
            assert false;
        } catch (IgniteFutureCancelledException e) {
            info("Caught expected exception: " + e);
        }
        // Create another loader.
        ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
        // This will close loader.
        stopGrid(getTestIgniteInstanceName(1), false);
        try {
            ldr.addData(0, 0);
            assert false;
        } catch (IllegalStateException e) {
            info("Caught expected exception: " + e);
        }
        assert ldr.future().isDone();
        ldr.future().get();
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException)

Example 3 with IgniteFutureCancelledException

use of org.apache.ignite.lang.IgniteFutureCancelledException 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);
        }
    });
    return m;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) 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)

Aggregations

IgniteFutureCancelledException (org.apache.ignite.lang.IgniteFutureCancelledException)3 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)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 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)1 ComputeTaskCancelledException (org.apache.ignite.compute.ComputeTaskCancelledException)1 ComputeTaskTimeoutException (org.apache.ignite.compute.ComputeTaskTimeoutException)1 Event (org.apache.ignite.events.Event)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 C1 (org.apache.ignite.internal.util.typedef.C1)1