ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [33/53] [abbrv] [partial] incubator-ignite git commit: # ignite-164 : GridAbstractTest -> IgniteAbstractTest - auto-renaming with all suggested options + rename all methods and fields inside AbstractTest
Date Wed, 04 Feb 2015 14:38:07 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithCancelSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithCancelSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithCancelSelfTest.java
new file mode 100644
index 0000000..a8c16d4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithCancelSelfTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Tests grid stop with jobs canceling.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteStopWithCancelSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    private static CountDownLatch cnt;
+
+    /** */
+    private static volatile boolean cancelCorrect;
+
+    /**
+     * Constructor.
+     */
+    public IgniteStopWithCancelSelfTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 10000;
+    }
+
+    /**
+     * @throws Exception If an error occurs.
+     */
+    public void testStopGrid() throws Exception {
+        cancelCorrect = false;
+
+        cnt = new CountDownLatch(1);
+
+        try {
+            Ignite ignite = startIgnite("testGrid");
+
+            executeAsync(ignite.compute(), CancelledTask.class, null);
+
+            cnt.await();
+        }
+        finally {
+            stopIgnite("testGrid", true);
+        }
+
+        assert cancelCorrect;
+    }
+
+    /**
+     * Test task that will be canceled.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static final class CancelledTask extends ComputeTaskAdapter<String, Object> {
+        /** Ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+            @Nullable String arg) {
+            for (ClusterNode node : subgrid) {
+                if (node.id().equals(ignite.configuration().getNodeId())) {
+                    return Collections.singletonMap(new ComputeJobAdapter() {
+                        @IgniteInstanceResource
+                        private Ignite ignite;
+
+                        @Override public void cancel() {
+                            cancelCorrect = true;
+                        }
+
+                        @Override public Serializable execute() {
+                            cnt.countDown();
+
+                            try {
+                                Thread.sleep(Long.MAX_VALUE);
+                            }
+                            catch (InterruptedException e) {
+                                throw new IgniteException(e);
+                            }
+
+                            return null;
+                        }
+                    }, node);
+                }
+            }
+
+            throw new IgniteException("Local node not found");
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithWaitSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithWaitSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithWaitSelfTest.java
new file mode 100644
index 0000000..785c6db
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteStopWithWaitSelfTest.java
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.spi.failover.always.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * Tests waiting for unfinished tasks while stopping the grid.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteStopWithWaitSelfTest extends IgniteCommonAbstractTest {
+    /** Initial node that job has been mapped to. */
+    private static final AtomicReference<ClusterNode> nodeRef = new AtomicReference<>(null);
+
+    /** */
+    private static CountDownLatch jobStarted;
+
+    /**
+     *
+     */
+    public IgniteStopWithWaitSelfTest() {
+        super(/*start Grid*/false);
+    }
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteName);
+
+        cfg.setFailoverSpi(new AlwaysFailoverSpi());
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWait() throws Exception {
+        jobStarted = new CountDownLatch(1);
+
+        ComputeTaskFuture<Object> fut = null;
+
+        try {
+            Ignite ignite1 = startIgnite(1);
+            Ignite ignite2 = startIgnite(2);
+
+            assert ignite1 != null;
+            assert ignite2 != null;
+
+            fut = executeAsync(ignite1.compute().withTimeout(10000),
+                GridWaitTask.class.getName(),
+                ignite1.cluster().localNode().id());
+
+            jobStarted.await();
+        }
+        finally {
+            // Do not cancel but wait.
+            G.stop(getTestIgniteName(1), false);
+            G.stop(getTestIgniteName(2), false);
+        }
+
+        assert fut != null;
+
+        Integer res = (Integer)fut.get();
+
+        assert res == 1;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWaitFailover() throws Exception {
+        jobStarted = new CountDownLatch(1);
+
+        ComputeTaskFuture<Object> fut = null;
+
+        Ignite ignite1 = startIgnite(1);
+        Ignite ignite2 = startIgnite(2);
+
+        try {
+            assert ignite1 != null;
+            assert ignite2 != null;
+
+            long timeout = 3000;
+
+            fut = executeAsync(ignite1.compute().withTimeout(timeout), JobFailTask.class.getName(), "1");
+
+            jobStarted.await(timeout, TimeUnit.MILLISECONDS);
+        }
+        finally {
+            // Do not cancel but wait.
+            G.stop(getTestIgniteName(1), false);
+            G.stop(getTestIgniteName(2), false);
+        }
+
+        assert fut != null;
+
+        Integer res = (Integer)fut.get();
+
+        assert res == 1;
+    }
+
+    /**
+     *
+     */
+    @ComputeTaskSessionFullSupport
+    private static class GridWaitTask extends ComputeTaskAdapter<UUID, Integer> {
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, UUID arg) {
+            ClusterNode mappedNode = null;
+
+            for (ClusterNode node : subgrid) {
+                if (node.id().equals(arg)) {
+                    mappedNode = node;
+
+                    break;
+                }
+            }
+
+            assert mappedNode != null;
+
+            return Collections.singletonMap(new ComputeJobAdapter(arg) {
+                @Override public Integer execute() {
+                    jobStarted.countDown();
+
+                    return 1;
+                }
+            }, mappedNode);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer reduce(List<ComputeJobResult> results) {
+            return results.get(0).getData();
+        }
+    }
+
+    /**
+     *
+     */
+    @ComputeTaskSessionFullSupport
+    private static class JobFailTask implements ComputeTask<String, Object> {
+        /** */
+        @IgniteTaskSessionResource
+        private ComputeTaskSession ses;
+
+        /** Ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, String arg) {
+            ses.setAttribute("fail", true);
+
+            ClusterNode node = F.view(subgrid, F.remoteNodes(ignite.configuration().getNodeId())).iterator().next();
+
+            nodeRef.set(node);
+
+            return Collections.singletonMap(new ComputeJobAdapter(arg) {
+                /** Ignite instance. */
+                @IgniteInstanceResource
+                private Ignite ignite;
+
+                /** Logger. */
+                @IgniteLoggerResource
+                private IgniteLogger log;
+
+                @Override public Serializable execute() {
+                    jobStarted.countDown();
+
+                    log.info("Starting to execute job with fail attribute: " + ses.getAttribute("fail"));
+
+                    boolean fail;
+
+                    assert ignite != null;
+
+                    UUID locId = ignite.configuration().getNodeId();
+
+                    assert locId != null;
+
+                    try {
+                        fail = ses.waitForAttribute("fail", 0);
+                    }
+                    catch (InterruptedException e) {
+                        throw new IgniteException("Got interrupted while waiting for attribute to be set.", e);
+                    }
+
+                    log.info("Failed attribute: " + fail);
+
+                    // Should fail on local node and sent to remote one.
+                    if (fail) {
+                        ses.setAttribute("fail", false);
+
+                        assert nodeRef.get().id().equals(locId);
+
+                        log.info("Throwing grid exception from job.");
+
+                        throw new IgniteException("Job exception.");
+                    }
+
+                    assert !nodeRef.get().id().equals(locId);
+
+                    Integer res = Integer.parseInt(this.<String>argument(0));
+
+                    log.info("Returning job result: " + res);
+
+                    // This job does not return any result.
+                    return res;
+                }
+            }, node);
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            if (res.getException() != null && !(res.getException() instanceof ComputeUserUndeclaredException)) {
+                assert res.getNode().id().equals(nodeRef.get().id());
+
+                return ComputeJobResultPolicy.FAILOVER;
+            }
+
+            assert !res.getNode().id().equals(nodeRef.get().id());
+
+            return ComputeJobResultPolicy.REDUCE;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> res) {
+            assert res.size() == 1;
+
+            assert nodeRef.get() != null;
+
+            assert !res.get(0).getNode().id().equals(nodeRef.get().id()) :
+                "Initial node and result one are the same (should be different).";
+
+            return res.get(0).getData();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskCancelSingleNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskCancelSingleNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskCancelSingleNodeSelfTest.java
new file mode 100644
index 0000000..64867b5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskCancelSingleNodeSelfTest.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.events.IgniteEventType.*;
+
+/**
+ * Test for task cancellation issue.
+ * <p/>
+ * http://www.gridgainsystems.com/jiveforums/thread.jspa?messageID=8034
+ */
+public class IgniteTaskCancelSingleNodeSelfTest extends IgniteCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startIgnite();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopIgnite();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testImmediateCancellation() throws Exception {
+        checkCancellation(0L);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCancellation() throws Exception {
+        checkCancellation(2000L);
+    }
+
+    /**
+     * @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();
+
+        igniteEx().events().localListen(new IgnitePredicate<IgniteEvent>() {
+            @Override public boolean apply(IgniteEvent evt) {
+                info("Received event: " + evt);
+
+                switch (evt.type()) {
+                    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_FINISHED, EVT_JOB_CANCELLED, EVT_JOB_REJECTED);
+
+        IgniteCompute comp = igniteEx().compute().withAsync();
+
+        comp.execute(TestTask.class, null);
+
+        ComputeTaskFuture<?> fut = comp.future();
+
+        if (timeoutBeforeCancel > 0L)
+            Thread.sleep(timeoutBeforeCancel);
+
+        assert fut.cancel();
+
+        for (int i = 0; i < 3; i++) {
+            try {
+            if (timeoutBeforeCancel == 0L)
+                assert (finished.get() == 0 && cancelled.get() == 0 && rejected.get() == 0) :
+                    "Failed on iteration [i=" + i + ", finished=" + finished.get() +
+                    ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']';
+            else
+                assert (finished.get() == 1 && cancelled.get() == 1 && rejected.get() == 0) :
+                    "Failed on iteration [i=" + i + ", finished=" + finished.get() +
+                        ", cancelled=" + cancelled.get() + ", rejected=" + rejected.get() + ']';
+            }
+            catch (AssertionError e) {
+                info("Check failed: " + e.getMessage());
+
+                if (timeoutBeforeCancel == 0L && i == 2)
+                    throw e;
+            }
+
+            if (i < 2)
+                U.sleep(500);
+        }
+
+        try {
+            fut.get();
+
+            assert false;
+        }
+        catch (IgniteFutureCancelledException e) {
+            info("Caught expected exception: " + e);
+        }
+    }
+
+    /**
+     *
+     */
+    @ComputeTaskMapAsync
+    private static class TestTask extends ComputeTaskSplitAdapter<Void, Void> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Void arg) {
+            return F.asSet(new ComputeJobAdapter() {
+                /** */
+                @IgniteLoggerResource
+                private IgniteLogger log;
+
+                /** */
+                @IgniteInstanceResource
+                private Ignite g;
+
+                /** {@inheritDoc} */
+                @Override public Object execute() {
+                    log.info("Executing job on node: " + g.cluster().localNode().id());
+
+                    try {
+                        Thread.sleep(5000);
+                    }
+                    catch (InterruptedException ignored) {
+                        log.info("Job thread has been interrupted.");
+
+                        Thread.currentThread().interrupt();
+                    }
+
+                    return null;
+                }
+            });
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Void reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskContinuousMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskContinuousMapperSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskContinuousMapperSelfTest.java
new file mode 100644
index 0000000..0fa79ea
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskContinuousMapperSelfTest.java
@@ -0,0 +1,331 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * {@link org.apache.ignite.compute.ComputeTaskContinuousMapper} test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskContinuousMapperSelfTest extends IgniteCommonAbstractTest {
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testContinuousMapperMethods() throws Exception {
+        try {
+            Ignite ignite = startIgnite(0);
+            startIgnite(1);
+
+            ignite.compute().execute(TestAllMethodsTask.class, null);
+        }
+        finally {
+            stopIgnite(0);
+            stopIgnite(1);
+        }
+    }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testContinuousMapperLifeCycle() throws Exception {
+        try {
+            Ignite ignite = startIgnite(0);
+
+            ignite.compute().execute(TestLifeCycleTask.class, null);
+        }
+        finally {
+            stopIgnite(0);
+        }
+    }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testContinuousMapperNegative() throws Exception {
+        try {
+            Ignite ignite = startIgnite(0);
+
+            ignite.compute().execute(TestNegativeTask.class, null);
+        }
+        finally {
+            stopIgnite(0);
+        }
+    }
+
+    /** */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class TestAllMethodsTask extends ComputeTaskAdapter<Object, Object> {
+        /** */
+        @SuppressWarnings({"UnusedDeclaration"})
+        @IgniteTaskContinuousMapperResource
+        private ComputeTaskContinuousMapper mapper;
+
+        /** */
+        private int cnt;
+
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Object arg) {
+            assert subgrid.size() == 2;
+
+            mapper.send(new TestJob(cnt++), subgrid.get(0));
+
+            Map<ComputeJob, ClusterNode> mappedJobs = new HashMap<>(2);
+
+            mappedJobs.put(new TestJob(cnt++), subgrid.get(0));
+            mappedJobs.put(new TestJob(cnt++), subgrid.get(1));
+
+            mapper.send(mappedJobs);
+
+            mapper.send(new TestJob(cnt++));
+
+            int size = subgrid.size();
+
+            Collection<ComputeJob> jobs = new ArrayList<>(size);
+
+            for (ClusterNode n : subgrid)
+                jobs.add(new TestJob(cnt++));
+
+            mapper.send(jobs);
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            assert results.size() == cnt : "Unexpected result count: " + results.size();
+
+            return null;
+        }
+    }
+
+    /** */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class TestLifeCycleTask extends ComputeTaskAdapter<Object, Object> {
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** */
+        private ComputeTaskContinuousMapper mapper;
+
+        /**
+         * @param mapper Continuous mapper.
+         * @throws IgniteCheckedException Thrown if any exception occurs.
+         */
+        @SuppressWarnings("unused")
+        @IgniteTaskContinuousMapperResource
+        private void setMapper(ComputeTaskContinuousMapper mapper) throws IgniteCheckedException {
+            this.mapper = mapper;
+
+            mapper.send(new TestJob());
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Object arg) {
+            mapper.send(new TestJob());
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> received) {
+            ComputeJobResultPolicy plc = super.result(res, received);
+
+            if (received != null && received.size() == 2)
+                mapper.send(new TestJob());
+
+            return plc;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            assert results.size() == 3 : "Unexpected result count: " + results.size();
+
+            ClusterNode node = results.get(0).getNode();
+
+            try {
+                mapper.send(new TestJob(), node);
+
+                assert false;
+            }
+            catch (IgniteException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send(Collections.singletonMap(new TestJob(), node));
+
+                assert false;
+            }
+            catch (IgniteException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send(new TestJob());
+
+                assert false;
+            }
+            catch (IgniteException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send(Collections.singleton(new TestJob()));
+
+                assert false;
+            }
+            catch (IgniteException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            return null;
+        }
+    }
+
+    /** */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class TestNegativeTask extends ComputeTaskAdapter<Object, Object> {
+        /** */
+        @SuppressWarnings({"UnusedDeclaration"})
+        @IgniteTaskContinuousMapperResource
+        private ComputeTaskContinuousMapper mapper;
+
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, Object arg) {
+            try {
+                mapper.send(new TestJob(), null);
+
+                assert false;
+
+            }
+            catch (NullPointerException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send(null, subgrid.get(0));
+
+                assert false;
+            }
+            catch (NullPointerException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send((Map<? extends ComputeJob, ClusterNode>)null);
+
+                assert false;
+            }
+            catch (NullPointerException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send(Collections.singletonMap(new TestJob(), (ClusterNode)null));
+
+                assert false;
+            }
+            catch (IgniteException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send((ComputeJob)null);
+
+                assert false;
+            }
+            catch (NullPointerException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send((Collection<ComputeJob>)null);
+
+                assert false;
+            }
+            catch (NullPointerException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            try {
+                mapper.send(Collections.singleton((ComputeJob)null));
+
+                assert false;
+            }
+            catch (IgniteException e) {
+                if (log.isInfoEnabled())
+                    log.info("Expected exception: " + e);
+            }
+
+            mapper.send(new TestJob());
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            assert results.size() == 1;
+
+            return null;
+        }
+    }
+
+    /** */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class TestJob extends ComputeJobAdapter {
+        /** */
+        public TestJob() {
+            super(-1);
+        }
+
+        /**
+         * @param idx Index.
+         */
+        public TestJob(int idx) {
+            super(idx);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Serializable execute() {
+            return argument(0);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionContextSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionContextSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionContextSelfTest.java
new file mode 100644
index 0000000..d9af5d9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionContextSelfTest.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.marshaller.optimized.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * Tests for {@code GridProjection.withXXX(..)} methods.
+ */
+public class IgniteTaskExecutionContextSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    private static final AtomicInteger CNT = new AtomicInteger();
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteName);
+
+        cfg.setMarshaller(new IgniteOptimizedMarshaller(false));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startIgnitesMultiThreaded(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllIgnites();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        CNT.set(0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWithName() throws Exception {
+        Callable<String> f = new IgniteCallable<String>() {
+            @IgniteTaskSessionResource
+            private ComputeTaskSession ses;
+
+            @Override public String call() {
+                return ses.getTaskName();
+            }
+        };
+
+        Ignite g = igniteEx(0);
+
+        assert "name1".equals(g.compute().withName("name1").call(f));
+        assert "name2".equals(g.compute().withName("name2").call(f));
+        assert f.getClass().getName().equals(g.compute().call(f));
+
+        assert "name1".equals(g.compute().withName("name1").execute(new TestTask(false), null));
+        assert "name2".equals(g.compute().withName("name2").execute(new TestTask(false), null));
+        assert TestTask.class.getName().equals(g.compute().execute(new TestTask(false), null));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWithNoFailoverClosure() throws Exception {
+        final Runnable r = new GridAbsClosureX() {
+            @Override public void applyx() throws IgniteCheckedException {
+                CNT.incrementAndGet();
+
+                throw new ComputeExecutionRejectedException("Expected error.");
+            }
+        };
+
+        final Ignite g = igniteEx(0);
+
+        GridTestUtils.assertThrows(
+            log,
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    g.compute().withNoFailover().run(r);
+
+                    return null;
+                }
+            },
+            ComputeExecutionRejectedException.class,
+            "Expected error."
+        );
+
+        assertEquals(1, CNT.get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testWithNoFailoverTask() throws Exception {
+        final Ignite g = igniteEx(0);
+
+        GridTestUtils.assertThrows(
+            log,
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    g.compute().withNoFailover().execute(new TestTask(true), null);
+
+                    return null;
+                }
+            },
+            ComputeExecutionRejectedException.class,
+            "Expected error."
+        );
+
+        assertEquals(1, CNT.get());
+    }
+
+    /**
+     * Test task that returns its name.
+     */
+    private static class TestTask extends ComputeTaskSplitAdapter<Void, String> {
+        /** */
+        private final boolean fail;
+
+        /**
+         * @param fail Whether to fail.
+         */
+        private TestTask(boolean fail) {
+            this.fail = fail;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Void arg) {
+            return F.asSet(new ComputeJobAdapter() {
+                @IgniteTaskSessionResource
+                private ComputeTaskSession ses;
+
+                @Override public Object execute() {
+                    CNT.incrementAndGet();
+
+                    if (fail)
+                        throw new ComputeExecutionRejectedException("Expected error.");
+
+                    return ses.getTaskName();
+                }
+            });
+        }
+
+        /** {@inheritDoc} */
+        @Override public String reduce(List<ComputeJobResult> results) {
+            return F.first(results).getData();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionSelfTest.java
new file mode 100644
index 0000000..2d658af
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskExecutionSelfTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * Task execution test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskExecutionSelfTest extends IgniteCommonAbstractTest {
+    /** Grid instance. */
+    private Ignite ignite;
+
+    /** */
+    public IgniteTaskExecutionSelfTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        ignite = startIgnite(1);
+
+        startIgnite(2);
+        startIgnite(3);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopIgnite(1);
+        stopIgnite(2);
+        stopIgnite(3);
+
+        ignite = null;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSynchronousExecute() throws Exception {
+        IgniteCompute comp = ignite.compute().withAsync();
+
+        assertNull(comp.execute(GridTestTask.class,  "testArg"));
+
+        ComputeTaskFuture<?> fut = comp.future();
+
+        assert fut != null;
+
+        info("Task result: " + fut.get());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskFailoverSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskFailoverSelfTest.java
new file mode 100644
index 0000000..66b169f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskFailoverSelfTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Test for task failover.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskFailoverSelfTest extends IgniteCommonAbstractTest {
+    /** Don't change it value. */
+    public static final int SPLIT_COUNT = 2;
+
+    /** */
+    public IgniteTaskFailoverSelfTest() {
+        super(false);
+    }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testFailover() throws Exception {
+        Ignite ignite = startIgnite();
+
+        try {
+            ignite.compute().localDeployTask(GridFailoverTestTask.class, GridFailoverTestTask.class.getClassLoader());
+
+            ComputeTaskFuture<?> fut = ignite.compute().execute(GridFailoverTestTask.class.getName(), null);
+
+            assert fut != null;
+
+            fut.get();
+
+            assert false : "Should never be reached due to exception thrown.";
+        }
+        catch (ClusterTopologyException e) {
+            info("Received correct exception: " + e);
+        }
+        finally {
+            stopIgnite();
+        }
+    }
+
+    /** */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class GridFailoverTestTask extends ComputeTaskSplitAdapter<Serializable, Integer> {
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override public Collection<ComputeJobAdapter> split(int gridSize, Serializable arg) {
+            if (log.isInfoEnabled())
+                log.info("Splitting job [job=" + this + ", gridSize=" + gridSize + ", arg=" + arg + ']');
+
+            Collection<ComputeJobAdapter> jobs = new ArrayList<>(SPLIT_COUNT);
+
+            for (int i = 0; i < SPLIT_COUNT; i++)
+                jobs.add(new ComputeJobAdapter() {
+                    @Override public Serializable execute() {
+                        if (log.isInfoEnabled())
+                            log.info("Computing job [job=" + this + ']');
+
+                        return null;
+                    }
+                });
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> received) {
+            if (res.getException() != null)
+                throw res.getException();
+
+            return ComputeJobResultPolicy.FAILOVER;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer reduce(List<ComputeJobResult> results) {
+            if (log.isInfoEnabled())
+                log.info("Reducing job [job=" + this + ", results=" + results + ']');
+
+            int res = 0;
+
+            for (ComputeJobResult result : results)
+                res += (Integer)result.getData();
+
+            return res;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstanceExecutionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstanceExecutionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstanceExecutionSelfTest.java
new file mode 100644
index 0000000..ad6055a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstanceExecutionSelfTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+/**
+ * Task instance execution test.
+ */
+@SuppressWarnings("PublicInnerClass")
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskInstanceExecutionSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    private static Object testState;
+
+    /** */
+    public IgniteTaskInstanceExecutionSelfTest() {
+        super(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSynchronousExecute() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        testState = 12345;
+
+        GridStatefulTask task = new GridStatefulTask(testState);
+
+        assert task.getState() != null;
+        assert task.getState() == testState;
+
+        IgniteCompute comp = ignite.compute().withAsync();
+
+        assertNull(comp.execute(task,  "testArg"));
+
+        ComputeTaskFuture<?> fut = comp.future();
+
+        assert fut != null;
+
+        info("Task result: " + fut.get());
+    }
+
+    /**
+     * Stateful task.
+     */
+    public static class GridStatefulTask extends GridTestTask {
+        /** */
+        private Object state;
+
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /**
+         * @param state State.
+         */
+        public GridStatefulTask(Object state) {
+            this.state = state;
+        }
+
+        /**
+         * @return The state.
+         */
+        public Object getState() {
+            return state;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Collection<? extends ComputeJob> split(int gridSize, Object arg) {
+            log.info("Task split state: " + state);
+
+            assert state != null;
+            assert state == testState;
+
+            return super.split(gridSize, arg);
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> received) {
+            log.info("Task result state: " + state);
+
+            assert state != null;
+            assert state == testState;
+
+            return super.result(res, received);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            log.info("Task reduce state: " + state);
+
+            assert state != null;
+            assert state == testState;
+
+            return super.reduce(results);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstantiationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstantiationSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstantiationSelfTest.java
new file mode 100644
index 0000000..e06c718
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskInstantiationSelfTest.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Tests instantiation of various task types (defined as private inner class, without default constructor, non-public
+ * default constructor).
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskInstantiationSelfTest extends IgniteCommonAbstractTest {
+    /**
+     * Constructor.
+     */
+    public IgniteTaskInstantiationSelfTest() {
+        super(true);
+    }
+
+    /**
+     * @throws Exception If an error occurs.
+     */
+    public void testTasksInstantiation() throws Exception {
+        igniteEx().compute().execute(PrivateClassTask.class, null);
+
+        igniteEx().compute().execute(NonPublicDefaultConstructorTask.class, null);
+
+        try {
+            igniteEx().compute().execute(NoDefaultConstructorTask.class, null);
+
+            assert false : "Exception should have been thrown.";
+        }
+        catch (Exception e) {
+            info("Caught expected exception: " + e);
+        }
+    }
+
+    /**
+     * Test task defined as private inner class.
+     */
+    private static class PrivateClassTask extends ComputeTaskAdapter<String, Object> {
+        /** Ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+            @Nullable String arg) {
+            for (ClusterNode node : subgrid)
+                if (node.id().equals(ignite.configuration().getNodeId()))
+                    return Collections.singletonMap(new ComputeJobAdapter() {
+                        @Override public Serializable execute() {
+                            return null;
+                        }
+                    }, node);
+
+            throw new IgniteException("Local node not found.");
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+
+    /**
+     * Test task defined with non-public default constructor.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static final class NonPublicDefaultConstructorTask extends PrivateClassTask {
+        /**
+         * No-op constructor.
+         */
+        private NonPublicDefaultConstructorTask() {
+            // No-op.
+        }
+    }
+
+    /**
+     * Test task defined without default constructor.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static final class NoDefaultConstructorTask extends PrivateClassTask {
+        /**
+         * No-op constructor.
+         *
+         * @param param Some parameter.
+         */
+        @SuppressWarnings({"unused"})
+        private NoDefaultConstructorTask(Object param) {
+            // No-op.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskJobRejectSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskJobRejectSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskJobRejectSelfTest.java
new file mode 100644
index 0000000..5bf6ba8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskJobRejectSelfTest.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.collision.fifoqueue.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static java.util.concurrent.TimeUnit.*;
+import static org.apache.ignite.events.IgniteEventType.*;
+
+/**
+ * Test that rejected job is not failed over.
+ */
+public class IgniteTaskJobRejectSelfTest extends IgniteCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startIgnite(1);
+        startIgnite(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopIgnite(1);
+        stopIgnite(2);
+    }
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteName);
+
+        FifoQueueCollisionSpi collision = new FifoQueueCollisionSpi();
+
+        collision.setParallelJobsNumber(1);
+
+        cfg.setCollisionSpi(collision);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReject() throws Exception {
+        igniteEx(1).events().localListen(new IgnitePredicate<IgniteEvent>() {
+            @Override public boolean apply(IgniteEvent evt) {
+                X.println("Task event: " + evt);
+
+                return true;
+            }
+        }, EVTS_TASK_EXECUTION);
+
+        igniteEx(1).events().localListen(new IgnitePredicate<IgniteEvent>() {
+            @Override public boolean apply(IgniteEvent evt) {
+                X.println("Job event: " + evt);
+
+                return true;
+            }
+        }, EVTS_JOB_EXECUTION);
+
+        final CountDownLatch startedLatch = new CountDownLatch(1);
+
+        igniteEx(1).events().localListen(new IgnitePredicate<IgniteEvent>() {
+            @Override public boolean apply(IgniteEvent evt) {
+                startedLatch.countDown();
+
+                return true;
+            }
+        }, EVT_JOB_STARTED);
+
+        final AtomicInteger failedOver = new AtomicInteger(0);
+
+        igniteEx(1).events().localListen(new IgnitePredicate<IgniteEvent>() {
+            @Override public boolean apply(IgniteEvent evt) {
+                failedOver.incrementAndGet();
+
+                return true;
+            }
+        }, EVT_JOB_FAILED_OVER);
+
+        final CountDownLatch finishedLatch = new CountDownLatch(1);
+
+        igniteEx(1).events().localListen(new IgnitePredicate<IgniteEvent>() {
+            @Override public boolean apply(IgniteEvent evt) {
+                finishedLatch.countDown();
+
+                return true;
+            }
+        }, EVT_TASK_FINISHED, EVT_TASK_FAILED);
+
+        final ClusterNode node = igniteEx(1).localNode();
+
+        IgniteCompute comp = igniteEx(1).compute().withAsync();
+
+        comp.execute(new ComputeTaskAdapter<Void, Void>() {
+            @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Void arg) {
+                return F.asMap(new SleepJob(), node, new SleepJob(), node);
+            }
+
+            /** {@inheritDoc} */
+            @Nullable @Override public Void reduce(List<ComputeJobResult> results) {
+                return null;
+            }
+        }, null);
+
+        ComputeTaskFuture<?> fut = comp.future();
+
+        assert startedLatch.await(2, SECONDS);
+
+        fut.cancel();
+
+        assert finishedLatch.await(2, SECONDS);
+
+        assert failedOver.get() == 0;
+    }
+
+    /**
+     * Sleeping job.
+     */
+    private static final class SleepJob extends ComputeJobAdapter {
+        /** {@inheritDoc} */
+        @Override public Object execute() {
+            try {
+                Thread.sleep(10000);
+            }
+            catch (InterruptedException ignored) {
+                Thread.currentThread().interrupt();
+            }
+
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskListenerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskListenerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskListenerSelfTest.java
new file mode 100644
index 0000000..76ac76c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskListenerSelfTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ * This test checks that GridTaskListener is only called once per task.
+ */
+@SuppressWarnings("deprecation")
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskListenerSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    public IgniteTaskListenerSelfTest() {
+        super(/*start grid*/true);
+    }
+
+    /**
+     * Checks that GridTaskListener is only called once per task.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings({"BusyWait", "unchecked"})
+    public void testGridTaskListener() throws Exception {
+        final AtomicInteger cnt = new AtomicInteger(0);
+
+        IgniteInClosure<IgniteFuture<?>> lsnr = new CI1<IgniteFuture<?>>() {
+            @Override public void apply(IgniteFuture<?> fut) {
+                assert fut != null;
+
+                cnt.incrementAndGet();
+            }
+        };
+
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        assert ignite != null;
+
+        ignite.compute().localDeployTask(TestTask.class, TestTask.class.getClassLoader());
+
+        ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), TestTask.class.getName(), null);
+
+        fut.listenAsync(lsnr);
+
+        fut.get();
+
+        while (cnt.get() == 0) {
+            try {
+                Thread.sleep(1000);
+            }
+            catch (InterruptedException e) {
+                error("Got interrupted while sleep.", e);
+
+                break;
+            }
+        }
+
+        assert cnt.get() == 1 : "Unexpected GridTaskListener apply count [count=" + cnt.get() + ", expected=1]";
+    }
+
+    /** Test task. */
+    private static class TestTask extends ComputeTaskSplitAdapter<Serializable, Object> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Serializable arg) {
+            Collection<ComputeJobAdapter> jobs = new ArrayList<>();
+
+            for (int i = 0; i < 5; i++) {
+                jobs.add(new ComputeJobAdapter() {
+                    @Override public Serializable execute() {
+                        return 1;
+                    }
+                });
+            }
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskMapAsyncSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskMapAsyncSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskMapAsyncSelfTest.java
new file mode 100644
index 0000000..033bae6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskMapAsyncSelfTest.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ *
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskMapAsyncSelfTest extends IgniteCommonAbstractTest {
+    /**
+     *
+     */
+    public IgniteTaskMapAsyncSelfTest() {
+        super(true);
+    }
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(igniteName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+
+        c.setDiscoverySpi(discoSpi);
+
+        return c;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTaskMap() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        info("Executing sync mapped task.");
+
+        ignite.compute().execute(SyncMappedTask.class, null);
+
+        info("Executing async mapped task.");
+
+        ignite.compute().execute(AsyncMappedTask.class, null);
+    }
+
+    /**
+     *
+     */
+    @ComputeTaskMapAsync
+    private static class AsyncMappedTask extends BaseTask {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) {
+            Collection<? extends ComputeJob> res = super.split(gridSize, arg);
+
+            assert mainThread != mapper;
+
+            return res;
+        }
+    }
+
+    /**
+     *
+     */
+    private static class SyncMappedTask extends BaseTask {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) {
+            Collection<? extends ComputeJob> res = super.split(gridSize, arg);
+
+            assert mainThread == mapper;
+
+            return res;
+        }
+    }
+
+    /**
+     * Test task.
+     */
+    private abstract static class BaseTask extends ComputeTaskSplitAdapter<Object, Void> {
+        /** */
+        protected static final Thread mainThread = Thread.currentThread();
+
+        /** */
+        protected Thread mapper;
+
+        /** */
+        protected Thread runner;
+
+        /** */
+        @IgniteLoggerResource
+        protected IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) {
+            mapper = Thread.currentThread();
+
+            return Collections.singleton(new ComputeJobAdapter() {
+                @Override public Serializable execute() {
+                    runner = Thread.currentThread();
+
+                    log.info("Runner: " + runner);
+                    log.info("Main: " + mainThread);
+                    log.info("Mapper: " + mapper);
+
+                    return null;
+                }
+            });
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Void reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskNameAnnotationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskNameAnnotationSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskNameAnnotationSelfTest.java
new file mode 100644
index 0000000..ab35b95
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskNameAnnotationSelfTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+import static org.apache.ignite.compute.ComputeJobResultPolicy.*;
+
+/**
+ * Tests for {@link org.apache.ignite.compute.ComputeTaskName} annotation.
+ */
+public class IgniteTaskNameAnnotationSelfTest extends IgniteCommonAbstractTest {
+    /** Task name. */
+    private static final String TASK_NAME = "test-task";
+
+    /** Peer deploy aware task name. */
+    private static final String PEER_DEPLOY_AWARE_TASK_NAME = "peer-deploy-aware-test-task";
+
+    /**
+     * Starts grid.
+     */
+    public IgniteTaskNameAnnotationSelfTest() {
+        super(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClass() throws Exception {
+        assert igniteEx().compute().execute(TestTask.class, null).equals(TASK_NAME);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassPeerDeployAware() throws Exception {
+        assert igniteEx().compute().execute(PeerDeployAwareTestTask.class, null).equals(PEER_DEPLOY_AWARE_TASK_NAME);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInstance() throws Exception {
+        assert igniteEx().compute().execute(new TestTask(), null).equals(TASK_NAME);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInstancePeerDeployAware() throws Exception {
+        assert igniteEx().compute().execute(new PeerDeployAwareTestTask(), null).
+            equals(PEER_DEPLOY_AWARE_TASK_NAME);
+    }
+
+    /**
+     * Test task.
+     */
+    @ComputeTaskName(TASK_NAME)
+    private static class TestTask implements ComputeTask<Void, String> {
+        /** {@inheritDoc} */
+        @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+            @Nullable Void arg) {
+            return F.asMap(new ComputeJobAdapter() {
+                @IgniteTaskSessionResource
+                private ComputeTaskSession ses;
+
+                @Override public Object execute() {
+                    return ses.getTaskName();
+                }
+            }, F.rand(subgrid));
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            return WAIT;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String reduce(List<ComputeJobResult> results) {
+            return F.first(results).getData();
+        }
+    }
+
+    /**
+     * Test task that implements {@link org.apache.ignite.internal.util.lang.GridPeerDeployAware}.
+     */
+    @ComputeTaskName(PEER_DEPLOY_AWARE_TASK_NAME)
+    private static class PeerDeployAwareTestTask extends TestTask implements GridPeerDeployAware {
+        /** {@inheritDoc} */
+        @Override public Class<?> deployClass() {
+            return getClass();
+        }
+
+        /** {@inheritDoc} */
+        @Override public ClassLoader classLoader() {
+            return getClass().getClassLoader();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskResultCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskResultCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskResultCacheSelfTest.java
new file mode 100644
index 0000000..5f7f7e0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskResultCacheSelfTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ *
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskResultCacheSelfTest extends IgniteCommonAbstractTest {
+    /**
+     *
+     */
+    public IgniteTaskResultCacheSelfTest() {
+        super(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNoCacheResults() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        ignite.compute().execute(GridResultNoCacheTestTask.class, "Grid Result No Cache Test Argument");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheResults() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        ignite.compute().execute(GridResultCacheTestTask.class, "Grid Result Cache Test Argument");
+    }
+
+    /**
+     *
+     */
+    @ComputeTaskNoResultCache
+    private static class GridResultNoCacheTestTask extends GridAbstractCacheTestTask {
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            assert res.getData() != null;
+            assert rcvd.isEmpty();
+
+            return super.result(res, rcvd);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            assert results.isEmpty();
+
+            return null;
+        }
+    }
+
+    /**
+     *
+     */
+    private static class GridResultCacheTestTask extends GridAbstractCacheTestTask {
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+            assert res.getData() != null;
+            assert rcvd.contains(res);
+
+            for (ComputeJobResult jobRes : rcvd)
+                assert jobRes.getData() != null;
+
+            return super.result(res, rcvd);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            for (ComputeJobResult res : results) {
+                if (res.getException() != null)
+                    throw res.getException();
+
+                assert res.getData() != null;
+            }
+
+            return null;
+        }
+    }
+
+    /**
+     * Test task.
+     */
+    private abstract static class GridAbstractCacheTestTask extends ComputeTaskSplitAdapter<String, Object> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) {
+            String[] words = arg.split(" ");
+
+            Collection<ComputeJobAdapter> jobs = new ArrayList<>(words.length);
+
+            for (String word : words) {
+                jobs.add(new ComputeJobAdapter(word) {
+                    @Override public Serializable execute() {
+                        return argument(0);
+                    }
+                });
+            }
+
+            return jobs;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskTimeoutSelfTest.java
new file mode 100644
index 0000000..0d427f1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteTaskTimeoutSelfTest.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.events.IgniteEventType.*;
+
+/**
+ *
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteTaskTimeoutSelfTest extends IgniteCommonAbstractTest {
+    /** Number of jobs each task spawns. */
+    private static final int SPLIT_COUNT = 1;
+
+    /** Timeout for task execution in milliseconds. */
+    private static final long TIMEOUT = 1000;
+
+    /** Number of worker threads. */
+    private static final int N_THREADS = 16;
+
+    /** Test execution period in milliseconds. */
+    private static final int PERIOD = 10000;
+
+    /** */
+    public IgniteTaskTimeoutSelfTest() {
+        super(true);
+    }
+
+    /**
+     * @param execId Execution ID.
+     */
+    private void checkTimedOutEvents(final IgniteUuid execId) {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        Collection<IgniteEvent> evts = ignite.events().localQuery(new PE() {
+            @Override public boolean apply(IgniteEvent evt) {
+                return ((IgniteTaskEvent) evt).taskSessionId().equals(execId);
+            }
+        }, EVT_TASK_TIMEDOUT);
+
+        assert evts.size() == 1 : "Invalid number of timed out tasks: " + evts.size();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSynchronousTimeout() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        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());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAsynchronousTimeout() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader());
+
+        ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT),
+            GridTaskTimeoutTestTask.class.getName(), null);
+
+        // Allow timed out events to be executed.
+        Thread.sleep(TIMEOUT + 500);
+
+        checkTimedOutEvents(fut.getTaskSession().getId());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSynchronousTimeoutMultithreaded() throws Exception {
+        final Ignite ignite = G.ignite(getTestIgniteName());
+
+        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() {
+            @SuppressWarnings("InfiniteLoopStatement")
+            @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) {
+                        throw new IllegalStateException(e); //shouldn't happen
+                    }
+                    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().
+    }
+
+    /**
+     *
+     */
+    private static class GridTaskTimeoutTestTask extends ComputeTaskSplitAdapter<Serializable, Object> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Serializable arg) {
+            Collection<GridTaskTimeoutTestJob> jobs = new ArrayList<>(SPLIT_COUNT);
+
+            for (int i = 0; i < SPLIT_COUNT; i++) {
+                GridTaskTimeoutTestJob job = new GridTaskTimeoutTestJob();
+
+                job.setArguments(arg);
+
+                jobs.add(job);
+            }
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+
+    /**
+     *
+     */
+    private static class GridTaskTimeoutTestJob extends ComputeJobAdapter {
+        /** Injected logger. */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override public Serializable execute() {
+            try {
+                Thread.sleep(Long.MAX_VALUE);
+            }
+            catch (InterruptedException ignored) {
+                // No-op.
+            }
+
+            return null;
+        }
+    }
+}


Mime
View raw message