ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [39/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:13 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/GridTaskMapAsyncSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskMapAsyncSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskMapAsyncSelfTest.java
deleted file mode 100644
index 6420353..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskMapAsyncSelfTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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 GridTaskMapAsyncSelfTest extends GridCommonAbstractTest {
-    /**
-     *
-     */
-    public GridTaskMapAsyncSelfTest() {
-        super(true);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration c = super.getConfiguration(gridName);
-
-        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(getTestGridName());
-
-        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/GridTaskNameAnnotationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskNameAnnotationSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskNameAnnotationSelfTest.java
deleted file mode 100644
index 401e215..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskNameAnnotationSelfTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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 GridTaskNameAnnotationSelfTest extends GridCommonAbstractTest {
-    /** 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 GridTaskNameAnnotationSelfTest() {
-        super(true);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClass() throws Exception {
-        assert grid().compute().execute(TestTask.class, null).equals(TASK_NAME);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassPeerDeployAware() throws Exception {
-        assert grid().compute().execute(PeerDeployAwareTestTask.class, null).equals(PEER_DEPLOY_AWARE_TASK_NAME);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testInstance() throws Exception {
-        assert grid().compute().execute(new TestTask(), null).equals(TASK_NAME);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testInstancePeerDeployAware() throws Exception {
-        assert grid().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/GridTaskResultCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskResultCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskResultCacheSelfTest.java
deleted file mode 100644
index 6e25aaa..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskResultCacheSelfTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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 GridTaskResultCacheSelfTest extends GridCommonAbstractTest {
-    /**
-     *
-     */
-    public GridTaskResultCacheSelfTest() {
-        super(true);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNoCacheResults() throws Exception {
-        Ignite ignite = G.ignite(getTestGridName());
-
-        ignite.compute().execute(GridResultNoCacheTestTask.class, "Grid Result No Cache Test Argument");
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCacheResults() throws Exception {
-        Ignite ignite = G.ignite(getTestGridName());
-
-        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/GridTaskTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskTimeoutSelfTest.java
deleted file mode 100644
index 20ef32b..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskTimeoutSelfTest.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * 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 GridTaskTimeoutSelfTest extends GridCommonAbstractTest {
-    /** 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 GridTaskTimeoutSelfTest() {
-        super(true);
-    }
-
-    /**
-     * @param execId Execution ID.
-     */
-    private void checkTimedOutEvents(final IgniteUuid execId) {
-        Ignite ignite = G.ignite(getTestGridName());
-
-        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(getTestGridName());
-
-        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(getTestGridName());
-
-        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(getTestGridName());
-
-        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;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java
deleted file mode 100644
index 9d97559..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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.lang.*;
-import org.apache.ignite.marshaller.*;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * Grid topic externalization test.
- */
-public class GridTopicExternalizableSelfTest extends IgniteExternalizableAbstractTest {
-    /** */
-    private static final IgniteUuid A_GRID_UUID = IgniteUuid.randomUuid();
-
-    /** */
-    private static final UUID AN_UUID = UUID.randomUUID();
-
-    /** */
-    private static final long A_LONG = Long.MAX_VALUE;
-
-    /** */
-    private static final String A_STRING = "test_test_test_test_test_test_test_test_test_test_test_test_test_test";
-
-    /** */
-    private static final int AN_INT = Integer.MAX_VALUE;
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByGridUuid() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_GRID_UUID);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByGridUuidAndUUID() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_GRID_UUID, AN_UUID);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByGridUuidAndLong() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_GRID_UUID, A_LONG);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByStringAndUUIDAndLong() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_STRING, AN_UUID, A_LONG);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByString() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_STRING);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByStringAndIntAndLong() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_STRING, AN_INT, A_LONG);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByStrinAndLong() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_STRING, A_LONG);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializationTopicCreatedByStringAndUUIDAndIntAndLong() throws Exception {
-        for (IgniteMarshaller marsh : getMarshallers()) {
-            info("Test GridTopic externalization [marshaller=" + marsh + ']');
-
-            for (GridTopic topic : GridTopic.values()) {
-                Externalizable msgOut = (Externalizable)topic.topic(A_STRING, AN_UUID, AN_INT, A_LONG);
-
-                assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/GridTopologyBuildVersionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTopologyBuildVersionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTopologyBuildVersionSelfTest.java
deleted file mode 100644
index 556135f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTopologyBuildVersionSelfTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.configuration.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import java.util.*;
-import java.util.concurrent.atomic.*;
-
-/**
- * Tests build version setting into discovery maps.
- */
-public class GridTopologyBuildVersionSelfTest extends GridCommonAbstractTest {
-    /** IP finder. */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** Counter. */
-    private static final AtomicInteger cnt = new AtomicInteger();
-
-    /** Test compatible versions. */
-    private static final Collection<String> COMPATIBLE_VERS =
-        F.asList("1.0.0-ent", "2.0.0-ent", "3.0.0-ent", "4.0.0-ent");
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        final int idx = cnt.incrementAndGet();
-
-        // Override node attributes in discovery spi.
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi() {
-            @Override public void setNodeAttributes(Map<String, Object> attrs, IgniteProductVersion ver) {
-                super.setNodeAttributes(attrs, ver);
-
-                attrs.put(IgniteNodeAttributes.ATTR_BUILD_VER, idx + ".0.0" + "-ent");
-
-                if (idx < 3)
-                    attrs.remove(IgniteNodeAttributes.ATTR_BUILD_DATE);
-                else
-                    attrs.put(IgniteNodeAttributes.ATTR_BUILD_DATE, "1385099743");
-
-                attrs.put(IgniteNodeAttributes.ATTR_COMPATIBLE_VERS, COMPATIBLE_VERS);
-            }
-        };
-
-        discoSpi.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        return cfg;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testVersioning() throws Exception {
-        startGrids(4);
-
-        try {
-            for (int i = 3; i >= 0; i--) {
-                IgniteKernal g = (IgniteKernal)grid(i);
-
-                NavigableMap<IgniteProductVersion, Collection<ClusterNode>> verMap = g.context().discovery()
-                    .topologyVersionMap();
-
-                assertEquals(4, verMap.size());
-
-                // Now check the map itself.
-                assertEquals(4, verMap.get(IgniteProductVersion.fromString("1.0.0")).size());
-                assertEquals(3, verMap.get(IgniteProductVersion.fromString("2.0.0")).size());
-                assertEquals(2, verMap.get(IgniteProductVersion.fromString("3.0.0-ent-1385099743")).size());
-                assertEquals(1, verMap.get(IgniteProductVersion.fromString("4.0.0-ent-1385099743")).size());
-            }
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
deleted file mode 100644
index 51142d0..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridUpdateNotifierSelfTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.testframework.junits.common.*;
-import org.jetbrains.annotations.*;
-
-import java.util.concurrent.*;
-
-/**
- * Update notifier test.
- */
-@GridCommonTest(group = "Kernal Self")
-public class GridUpdateNotifierSelfTest extends GridCommonAbstractTest {
-    /** {@inheritDoc} */
-    @Override protected long getTestTimeout() {
-        return 30 * 1000;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNotifier() throws Exception {
-        GridUpdateNotifier ntf = new GridUpdateNotifier(null, GridProperties.get("ignite.version"),
-            IgniteKernal.SITE, TEST_GATEWAY, false);
-
-        ntf.checkForNewVersion(new SelfExecutor(), log);
-
-        String ver = ntf.latestVersion();
-
-        info("Latest version: " + ver);
-
-        assertNotNull("GridGain latest version has not been detected.", ver);
-
-        ntf.reportStatus(log);
-    }
-
-    /**
-     * Executor that runs task in current thread.
-     */
-    private static class SelfExecutor implements Executor {
-        /** {@inheritDoc} */
-        @Override public void execute(@NotNull Runnable r) {
-            r.run();
-        }
-    }
-
-    /**
-     * Test kernal gateway that always return uninitialized user stack trace.
-     */
-    private static final GridKernalGateway TEST_GATEWAY = new GridKernalGateway() {
-        @Override public void lightCheck() throws IllegalStateException {}
-
-        @Override public void readLock() throws IllegalStateException {}
-
-        @Override public void setState(GridKernalState state) {}
-
-        @Override public GridKernalState getState() {
-            return null;
-        }
-
-        @Override public void readUnlock() {}
-
-        @Override public void writeLock() {}
-
-        @Override public void writeUnlock() {}
-
-        @Override public void addStopListener(Runnable lsnr) {}
-
-        @Override public void removeStopListener(Runnable lsnr) {}
-
-        @Override public String userStackTrace() {
-            return null;
-        }
-    };
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/GridVersionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridVersionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridVersionSelfTest.java
deleted file mode 100644
index 3b8f205..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridVersionSelfTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import static org.apache.ignite.IgniteSystemProperties.*;
-
-/**
- * Tests version methods.
- */
-public class GridVersionSelfTest extends GridCommonAbstractTest {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testVersions() throws Exception {
-        String propVal = System.getProperty(IGNITE_UPDATE_NOTIFIER);
-
-        System.setProperty(IGNITE_UPDATE_NOTIFIER, "true");
-
-        try {
-            Ignite ignite = startGrid();
-
-            IgniteProductVersion currVer = ignite.product().version();
-
-            String newVer = null;
-
-            for (int i = 0; i < 30; i++) {
-                newVer = ignite.product().latestVersion();
-
-                if (newVer != null)
-                    break;
-
-                U.sleep(100);
-            }
-
-            info("Versions [cur=" + currVer + ", latest=" + newVer + ']');
-
-            assertNotNull(newVer);
-            assertNotSame(currVer.toString(), newVer);
-        }
-        finally {
-            stopGrid();
-
-            if (propVal != null)
-                System.setProperty(IGNITE_UPDATE_NOTIFIER, propVal);
-            else
-                System.clearProperty(IGNITE_UPDATE_NOTIFIER);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityMappedTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityMappedTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityMappedTest.java
new file mode 100644
index 0000000..83c8775
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityMappedTest.java
@@ -0,0 +1,165 @@
+/*
+ * 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.cache.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Tests affinity mapping when {@link org.apache.ignite.cache.affinity.CacheAffinityKeyMapper} is used.
+ */
+public class IgniteAffinityMappedTest extends IgniteCommonAbstractTest {
+    /** VM ip finder for TCP discovery. */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /**
+     *
+     */
+    public IgniteAffinityMappedTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+        disco.setMaxMissedHeartbeats(Integer.MAX_VALUE);
+        disco.setIpFinder(ipFinder);
+        cfg.setDiscoverySpi(disco);
+
+        if (igniteName.endsWith("1"))
+            cfg.setCacheConfiguration(); // Empty cache configuration.
+        else {
+            assert igniteName.endsWith("2") || igniteName.endsWith("3");
+
+            CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+            cacheCfg.setCacheMode(PARTITIONED);
+            cacheCfg.setAffinity(new MockCacheAffinityFunction());
+            cacheCfg.setAffinityMapper(new MockCacheAffinityKeyMapper());
+
+            cfg.setCacheConfiguration(cacheCfg);
+            cfg.setUserAttributes(F.asMap(GridCacheModuloAffinityFunction.IDX_ATTR, igniteName.endsWith("2") ? 0 : 1));
+        }
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startIgnite(1);
+        startIgnite(2);
+        startIgnite(3);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopIgnite(1);
+        stopIgnite(2);
+        stopIgnite(3);
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void testMappedAffinity() throws IgniteCheckedException {
+        Ignite g1 = igniteEx(1);
+        Ignite g2 = igniteEx(2);
+        Ignite g3 = igniteEx(3);
+
+        assert g1.configuration().getCacheConfiguration().length == 0;
+        assert g2.configuration().getCacheConfiguration()[0].getCacheMode() == PARTITIONED;
+        assert g3.configuration().getCacheConfiguration()[0].getCacheMode() == PARTITIONED;
+
+        ClusterNode first = g2.cluster().localNode();
+        ClusterNode second = g3.cluster().localNode();
+
+        //When MockCacheAfinity and MockCacheAffinityKeyMapper are set to cache configuration we expect the following.
+        //Key 0 is mapped to partition 0, first node.
+        //Key 1 is mapped to partition 1, second node.
+        //key 2 is mapped to partition 0, first node because mapper substitutes key 2 with affinity key 0.
+        Map<ClusterNode, Collection<Integer>> map = g1.cluster().mapKeysToNodes(null, F.asList(0));
+
+        assertNotNull(map);
+        assertEquals("Invalid map size: " + map.size(), 1, map.size());
+        assertEquals(F.first(map.keySet()), first);
+
+        UUID id1 = g1.cluster().mapKeyToNode(null, 1).id();
+
+        assertNotNull(id1);
+        assertEquals(second.id(),  id1);
+
+        UUID id2 = g1.cluster().mapKeyToNode(null, 2).id();
+
+        assertNotNull(id2);
+        assertEquals(first.id(),  id2);
+    }
+
+    /**
+     * Mock affinity implementation that ensures constant key-to-node mapping based on {@link GridCacheModuloAffinityFunction}
+     * The partition selection is as follows: 0 maps to partition 0 and any other value maps to partition 1
+     */
+    private static class MockCacheAffinityFunction extends GridCacheModuloAffinityFunction {
+        /**
+         * Initializes module affinity with 2 parts and 0 backups
+         */
+        private MockCacheAffinityFunction() {
+            super(2, 0);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int partition(Object key) {
+            return Integer.valueOf(0) == key ? 0 : 1;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void reset() {
+            //no-op
+        }
+    }
+
+    /**
+     * Mock affinity mapper implementation that substitutes values other than 0 and 1 with 0.
+     */
+    private static class MockCacheAffinityKeyMapper implements CacheAffinityKeyMapper {
+        /** {@inheritDoc} */
+        @Override public Object affinityKey(Object key) {
+            return key instanceof Integer ? 1 == (Integer)key ? key : 0 : key;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void reset() {
+            // This mapper is stateless and needs no initialization logic.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityP2PSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityP2PSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityP2PSelfTest.java
new file mode 100644
index 0000000..2d18de4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinityP2PSelfTest.java
@@ -0,0 +1,206 @@
+/*
+ * 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.cache.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.config.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.net.*;
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Tests affinity and affinity mapper P2P loading.
+ */
+public class IgniteAffinityP2PSelfTest extends IgniteCommonAbstractTest {
+    /** VM ip finder for TCP discovery. */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final String EXT_AFFINITY_MAPPER_CLS_NAME = "org.apache.ignite.tests.p2p.GridExternalAffinityMapper";
+
+    /** */
+    private static final String EXT_AFFINITY_CLS_NAME = "org.apache.ignite.tests.p2p.GridExternalAffinity";
+
+    /** URL of classes. */
+    private static final URL[] URLS;
+
+    /** Current deployment mode. Used in {@link #getConfiguration(String)}. */
+    private IgniteDeploymentMode depMode;
+
+    /**
+     * Initialize URLs.
+     */
+    static {
+        try {
+            URLS = new URL[] {new URL(GridTestProperties.getProperty("p2p.uri.cls"))};
+        }
+        catch (MalformedURLException e) {
+            throw new RuntimeException("Define property p2p.uri.cls", e);
+        }
+    }
+
+    /**
+     *
+     */
+    public IgniteAffinityP2PSelfTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @SuppressWarnings({"unchecked"})
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(igniteName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setMaxMissedHeartbeats(Integer.MAX_VALUE);
+        disco.setIpFinder(ipFinder);
+
+        c.setDiscoverySpi(disco);
+
+        c.setDeploymentMode(depMode);
+
+        if (igniteName.endsWith("1"))
+            c.setCacheConfiguration(); // Empty cache configuration.
+        else {
+            assert igniteName.endsWith("2") || igniteName.endsWith("3");
+
+            CacheConfiguration cc = defaultCacheConfiguration();
+
+            cc.setCacheMode(PARTITIONED);
+
+            GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(URLS);
+
+            cc.setAffinity((CacheAffinityFunction)ldr.loadClass(EXT_AFFINITY_CLS_NAME).newInstance());
+            cc.setAffinityMapper((CacheAffinityKeyMapper)ldr.loadClass(EXT_AFFINITY_MAPPER_CLS_NAME)
+                .newInstance());
+
+            c.setCacheConfiguration(cc);
+            c.setUserAttributes(F.asMap(GridCacheModuloAffinityFunction.IDX_ATTR, igniteName.endsWith("2") ? 0 : 1));
+        }
+
+        return c;
+    }
+
+    /**
+     * Test {@link org.apache.ignite.configuration.IgniteDeploymentMode#PRIVATE} mode.
+     *
+     * @throws Exception if error occur.
+     */
+    public void testPrivateMode() throws Exception {
+        depMode = IgniteDeploymentMode.PRIVATE;
+
+        affinityTest();
+    }
+
+    /**
+     * Test {@link org.apache.ignite.configuration.IgniteDeploymentMode#ISOLATED} mode.
+     *
+     * @throws Exception if error occur.
+     */
+    public void testIsolatedMode() throws Exception {
+        depMode = IgniteDeploymentMode.ISOLATED;
+
+        affinityTest();
+    }
+
+    /**
+     * Test {@link org.apache.ignite.configuration.IgniteDeploymentMode#CONTINUOUS} mode.
+     *
+     * @throws Exception if error occur.
+     */
+    public void testContinuousMode() throws Exception {
+        depMode = IgniteDeploymentMode.CONTINUOUS;
+
+        affinityTest();
+    }
+
+    /**
+     * Test {@link org.apache.ignite.configuration.IgniteDeploymentMode#SHARED} mode.
+     *
+     * @throws Exception if error occur.
+     */
+    public void testSharedMode() throws Exception {
+        depMode = IgniteDeploymentMode.SHARED;
+
+        affinityTest();
+    }
+
+    /** @throws Exception If failed. */
+    private void affinityTest() throws Exception {
+        Ignite g1 = startIgnite(1);
+        Ignite g2 = startIgnite(2);
+        Ignite g3 = startIgnite(3);
+
+        try {
+            assert g1.configuration().getCacheConfiguration().length == 0;
+            assert g2.configuration().getCacheConfiguration()[0].getCacheMode() == PARTITIONED;
+            assert g3.configuration().getCacheConfiguration()[0].getCacheMode() == PARTITIONED;
+
+            ClusterNode first = g2.cluster().localNode();
+            ClusterNode second = g3.cluster().localNode();
+
+            //When external affinity and mapper are set to cache configuration we expect the following.
+            //Key 0 is mapped to partition 0, first node.
+            //Key 1 is mapped to partition 1, second node.
+            //key 2 is mapped to partition 0, first node because mapper substitutes key 2 with affinity key 0.
+            Map<ClusterNode, Collection<Integer>> map = g1.cluster().mapKeysToNodes(null, F.asList(0));
+
+            assertNotNull(map);
+            assertEquals("Invalid map size: " + map.size(), 1, map.size());
+            assertEquals(F.first(map.keySet()), first);
+
+            ClusterNode n1 = g1.cluster().mapKeyToNode(null, 1);
+
+            assertNotNull(n1);
+
+            UUID id1 = n1.id();
+
+            assertNotNull(id1);
+            assertEquals(second.id(), id1);
+
+            ClusterNode n2 = g1.cluster().mapKeyToNode(null, 2);
+
+            assertNotNull(n2);
+
+            UUID id2 = n2.id();
+
+            assertNotNull(id2);
+            assertEquals(first.id(), id2);
+        }
+        finally {
+            stopIgnite(1);
+            stopIgnite(2);
+            stopIgnite(3);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinitySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinitySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinitySelfTest.java
new file mode 100644
index 0000000..6ada241
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAffinitySelfTest.java
@@ -0,0 +1,119 @@
+/*
+ * 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.cache.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ * Tests affinity mapping.
+ */
+public class IgniteAffinitySelfTest extends IgniteCommonAbstractTest {
+    /** VM ip finder for TCP discovery. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setMaxMissedHeartbeats(Integer.MAX_VALUE);
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        if (igniteName.endsWith("1"))
+            cfg.setCacheConfiguration(); // Empty cache configuration.
+        else {
+            assert igniteName.endsWith("2");
+
+            CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+            cacheCfg.setCacheMode(PARTITIONED);
+            cacheCfg.setBackups(1);
+
+            cfg.setCacheConfiguration(cacheCfg);
+        }
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startIgnitesMultiThreaded(1, 2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllIgnites();
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void testAffinity() throws IgniteCheckedException {
+        Ignite g1 = igniteEx(1);
+        Ignite g2 = igniteEx(2);
+
+        assert caches(g1).size() == 0;
+        assert F.first(caches(g2)).getCacheMode() == PARTITIONED;
+
+        Map<ClusterNode, Collection<String>> map = g1.cluster().mapKeysToNodes(null, F.asList("1"));
+
+        assertNotNull(map);
+        assertEquals("Invalid map size: " + map.size(), 1, map.size());
+        assertEquals(F.first(map.keySet()), g2.cluster().localNode());
+
+        UUID id1 = g1.cluster().mapKeyToNode(null, "2").id();
+
+        assertNotNull(id1);
+        assertEquals(g2.cluster().localNode().id(), id1);
+
+        UUID id2 = g1.cluster().mapKeyToNode(null, "3").id();
+
+        assertNotNull(id2);
+        assertEquals(g2.cluster().localNode().id(), id2);
+    }
+
+    /**
+     * @param g Grid.
+     * @return Non-system caches.
+     */
+    private Collection<CacheConfiguration> caches(Ignite g) {
+        return F.view(Arrays.asList(g.configuration().getCacheConfiguration()), new IgnitePredicate<CacheConfiguration>() {
+            @Override public boolean apply(CacheConfiguration c) {
+                return c.getName() == null || !c.getName().equals(CU.UTILITY_CACHE_NAME);
+            }
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteAlwaysFailoverSpiFailSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteAlwaysFailoverSpiFailSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAlwaysFailoverSpiFailSelfTest.java
new file mode 100644
index 0000000..81ecdf6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteAlwaysFailoverSpiFailSelfTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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.spi.failover.*;
+import org.apache.ignite.spi.failover.always.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Always failover SPI test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteAlwaysFailoverSpiFailSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    private boolean isFailoverCalled;
+
+    /** */
+    public IgniteAlwaysFailoverSpiFailSelfTest() {
+        super(true);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration() throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration();
+
+        cfg.setFailoverSpi(new GridTestFailoverSpi());
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings({"UnusedCatchParameter", "ThrowableInstanceNeverThrown"})
+    public void testFailoverTask() throws Exception {
+        isFailoverCalled = false;
+
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        ignite.compute().localDeployTask(GridTestFailoverTask.class, GridTestFailoverTask.class.getClassLoader());
+
+        try {
+            ignite.compute().execute(GridTestFailoverTask.class.getName(),
+                new ComputeExecutionRejectedException("Task should be failed over"));
+
+            assert false;
+        }
+        catch (IgniteException e) {
+            //No-op
+        }
+
+        assert isFailoverCalled;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings({"UnusedCatchParameter", "ThrowableInstanceNeverThrown"})
+    public void testNoneFailoverTask() throws Exception {
+        isFailoverCalled = false;
+
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        ignite.compute().localDeployTask(GridTestFailoverTask.class, GridTestFailoverTask.class.getClassLoader());
+
+        try {
+            ignite.compute().execute(GridTestFailoverTask.class.getName(),
+                new IgniteException("Task should NOT be failed over"));
+
+            assert false;
+        }
+        catch (IgniteException e) {
+            //No-op
+        }
+
+        assert !isFailoverCalled;
+    }
+
+    /** */
+    private class GridTestFailoverSpi extends AlwaysFailoverSpi {
+        /** {@inheritDoc} */
+        @Override public ClusterNode failover(FailoverContext ctx, List<ClusterNode> grid) {
+            isFailoverCalled = true;
+
+            return super.failover(ctx, grid);
+        }
+    }
+
+    /**
+     * Task which splits to the jobs that always fail.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static final class GridTestFailoverTask extends ComputeTaskSplitAdapter<Object, Object> {
+        /** {@inheritDoc} */
+        @Override public Collection<? extends ComputeJob> split(int gridSize, Object arg) {
+            assert gridSize == 1;
+            assert arg instanceof IgniteException;
+
+            Collection<ComputeJob> res = new ArrayList<>(gridSize);
+
+            for (int i = 0; i < gridSize; i++)
+                res.add(new GridTestFailoverJob((IgniteException)arg));
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+            List<ComputeJobResult> received) {
+            if (res.getException() != null)
+                return ComputeJobResultPolicy.FAILOVER;
+
+            return super.result(res, received);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Serializable reduce(List<ComputeJobResult> results) {
+            return null;
+        }
+    }
+
+    /**
+     * Job that always throws exception.
+     */
+    private static class GridTestFailoverJob extends ComputeJobAdapter {
+        /**
+         * @param ex Exception to be thrown in {@link #execute}.
+         */
+        GridTestFailoverJob(IgniteException ex) { super(ex); }
+
+        /** {@inheritDoc} */
+        @Override public IgniteException execute() {
+            throw this.<IgniteException>argument(0);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteCacheProjectionRemoveTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteCacheProjectionRemoveTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCacheProjectionRemoveTest.java
new file mode 100644
index 0000000..d81b6fc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCacheProjectionRemoveTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.internal.processors.cache.*;
+
+/**
+ *
+ */
+public class IgniteCacheProjectionRemoveTest extends IgniteCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void testRemove() throws IgniteCheckedException {
+        cache().put("key", 1);
+
+        assert cache().remove("key", 1);
+        assert !cache().remove("key", 1);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelUnusedJobSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelUnusedJobSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelUnusedJobSelfTest.java
new file mode 100644
index 0000000..35bdbfb
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelUnusedJobSelfTest.java
@@ -0,0 +1,221 @@
+/*
+ * 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.internal.util.typedef.internal.*;
+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 java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Cancel unused job test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteCancelUnusedJobSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    private static final int WAIT_TIME = 100000;
+
+    /** */
+    public static final int SPLIT_COUNT = 10;
+
+    /** */
+    private static volatile int cancelCnt;
+
+    /** */
+    private static volatile int processedCnt;
+
+    /** */
+    private static CountDownLatch startSignal = new CountDownLatch(SPLIT_COUNT);
+
+    /** */
+    private static CountDownLatch stopSignal = new CountDownLatch(SPLIT_COUNT);
+
+    /** */
+    public IgniteCancelUnusedJobSelfTest() {
+        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);
+
+        c.setExecutorService(
+            new ThreadPoolExecutor(
+                SPLIT_COUNT,
+                SPLIT_COUNT,
+                0, TimeUnit.MILLISECONDS,
+                new LinkedBlockingQueue<Runnable>()));
+
+        c.setExecutorServiceShutdown(true);
+
+        return c;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testCancel() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        ignite.compute().localDeployTask(GridCancelTestTask.class, U.detectClassLoader(GridCancelTestTask.class));
+
+        ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridCancelTestTask.class.getName(), null);
+
+        // Wait until jobs begin execution.
+        boolean await = startSignal.await(WAIT_TIME, TimeUnit.MILLISECONDS);
+
+        assert await : "Jobs did not start.";
+
+        info("Test task result: " + fut);
+
+        assert fut != null;
+
+        // Only first job should successfully complete.
+        Object res = fut.get();
+        assert (Integer)res == 1;
+
+        // Wait for all jobs to finish.
+        await = stopSignal.await(WAIT_TIME, TimeUnit.MILLISECONDS);
+        assert await : "Jobs did not stop.";
+
+        // One is definitely processed. But there might be some more processed or cancelled or processed and cancelled.
+        // Thus total number should be at least SPLIT_COUNT and at most (SPLIT_COUNT - 1) *2 +1
+        assert (cancelCnt + processedCnt) >= SPLIT_COUNT && (cancelCnt + processedCnt) <= (SPLIT_COUNT - 1) * 2 +1 :
+            "Invalid cancel count value: " + cancelCnt;
+    }
+
+    /**
+     *
+     */
+    private static class GridCancelTestTask extends ComputeTaskSplitAdapter<Object, Object> {
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) {
+            if (log.isInfoEnabled())
+                log.info("Splitting job [job=" + this + ", gridSize=" + gridSize + ", arg=" + arg + ']');
+
+            Collection<ComputeJob> jobs = new ArrayList<>(SPLIT_COUNT);
+
+            for (int i = 1; i <= SPLIT_COUNT; i++)
+                jobs.add(new GridCancelTestJob(i));
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> received) {
+            return ComputeJobResultPolicy.REDUCE;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Serializable reduce(List<ComputeJobResult> results) {
+            if (log.isInfoEnabled())
+                log.info("Reducing job [job=" + this + ", results=" + results + ']');
+
+            if (results.size() > 1)
+                fail();
+
+            return results.get(0).getData();
+        }
+    }
+
+    /**
+     * Cancel test job.
+     */
+    private static class GridCancelTestJob extends ComputeJobAdapter {
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** */
+        @IgniteTaskSessionResource
+        private ComputeTaskSession ses;
+
+        /**
+         * @param arg Argument.
+         */
+        private GridCancelTestJob(Integer arg) {
+            super(arg);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Serializable execute() {
+            int arg = this.<Integer>argument(0);
+
+            try {
+                if (log.isInfoEnabled())
+                    log.info("Executing job [job=" + this + ", arg=" + arg + ']');
+
+                startSignal.countDown();
+
+                try {
+                    if (!startSignal.await(WAIT_TIME, TimeUnit.MILLISECONDS))
+                        fail();
+
+                    if (arg == 1) {
+                        if (log.isInfoEnabled())
+                            log.info("Job one is proceeding.");
+                    }
+                    else
+                        Thread.sleep(WAIT_TIME);
+                }
+                catch (InterruptedException e) {
+                    if (log.isInfoEnabled())
+                        log.info("Job got cancelled [arg=" + arg + ", ses=" + ses + ", e=" + e + ']');
+
+                    return 0;
+                }
+
+                if (log.isInfoEnabled())
+                    log.info("Completing job: " + ses);
+
+                return argument(0);
+            }
+            finally {
+                stopSignal.countDown();
+
+                processedCnt++;
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void cancel() {
+            cancelCnt++;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelledJobsMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelledJobsMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelledJobsMetricsSelfTest.java
new file mode 100644
index 0000000..5ca46bd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCancelledJobsMetricsSelfTest.java
@@ -0,0 +1,214 @@
+/*
+ * 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.resources.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.collision.*;
+import org.apache.ignite.spi.discovery.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+/**
+ * Cancelled jobs metrics self test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteCancelledJobsMetricsSelfTest extends IgniteCommonAbstractTest {
+
+    /** */
+    private static GridCancelCollisionSpi colSpi = new GridCancelCollisionSpi();
+
+    /** */
+    public IgniteCancelledJobsMetricsSelfTest() {
+        super(true);
+    }
+
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration() throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration();
+
+        cfg.setCollisionSpi(colSpi);
+
+        DiscoverySpi discoSpi = cfg.getDiscoverySpi();
+
+        assert discoSpi instanceof TcpDiscoverySpi;
+
+        ((TcpDiscoverySpi)discoSpi).setHeartbeatFrequency(500);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCancelledJobs() throws Exception {
+        final Ignite ignite = G.ignite(getTestIgniteName());
+
+        Collection<ComputeTaskFuture<?>> futs = new ArrayList<>();
+
+        IgniteCompute comp = ignite.compute().withAsync();
+
+        for (int i = 1; i <= 10; i++) {
+            comp.execute(CancelledTask.class, null);
+
+            futs.add(comp.future());
+        }
+
+        // Wait to be sure that metrics were updated.
+        GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                return ignite.cluster().localNode().metrics().getTotalCancelledJobs() > 0;
+            }
+        }, 5000);
+
+        colSpi.externalCollision();
+
+        for (ComputeTaskFuture<?> fut : futs) {
+            try {
+                fut.get();
+
+                assert false : "Job was not interrupted.";
+            }
+            catch (IgniteException e) {
+                if (e.hasCause(InterruptedException.class))
+                    throw new IgniteCheckedException("Test run has been interrupted.", e);
+
+                info("Caught expected exception: " + e.getMessage());
+            }
+        }
+
+        // Job was cancelled and now we need to calculate metrics.
+        int totalCancelledJobs = ignite.cluster().localNode().metrics().getTotalCancelledJobs();
+
+        assert totalCancelledJobs == 10 : "Metrics were not updated. Expected 10 got " + totalCancelledJobs;
+    }
+
+    /**
+     *
+     */
+    private static final class CancelledTask extends ComputeTaskSplitAdapter<String, Object> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) {
+            return Arrays.asList(new GridCancelledJob());
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object reduce(List<ComputeJobResult> results) {
+            assert results.get(0).isCancelled() : "Wrong job result status.";
+
+            return null;
+        }
+    }
+
+    /**
+     *
+     */
+    private static final class GridCancelledJob extends ComputeJobAdapter {
+        /** {@inheritDoc} */
+        @Override public String execute() {
+            X.println("Executing job.");
+
+            try {
+                Thread.sleep(Long.MAX_VALUE);
+            }
+            catch (InterruptedException ignored) {
+                try {
+                    Thread.sleep(1000);
+                }
+                catch (InterruptedException e1) {
+                    throw new IgniteException("Unexpected exception: ", e1);
+                }
+
+                throw new IgniteException("Job got interrupted while waiting for cancellation.");
+            }
+            finally {
+                X.println("Finished job.");
+            }
+
+            return null;
+        }
+    }
+
+    /**
+     *
+     */
+    @IgniteSpiMultipleInstancesSupport(true)
+    private static class GridCancelCollisionSpi extends IgniteSpiAdapter
+        implements CollisionSpi {
+        /** */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** */
+        private CollisionExternalListener lsnr;
+
+        /** {@inheritDoc} */
+        @Override public void onCollision(CollisionContext ctx) {
+            Collection<CollisionJobContext> activeJobs = ctx.activeJobs();
+            Collection<CollisionJobContext> waitJobs = ctx.waitingJobs();
+
+            for (CollisionJobContext job : waitJobs)
+                job.activate();
+
+            for (CollisionJobContext job : activeJobs) {
+                log.info("Cancelling job : " + job.getJob());
+
+                job.cancel();
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void spiStart(String gridName) throws IgniteSpiException {
+            // Start SPI start stopwatch.
+            startStopwatch();
+
+            // Ack start.
+            if (log.isInfoEnabled())
+                log.info(startInfo());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void spiStop() throws IgniteSpiException {
+            // Ack stop.
+            if (log.isInfoEnabled())
+                log.info(stopInfo());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void setExternalCollisionListener(CollisionExternalListener lsnr) {
+            this.lsnr = lsnr;
+        }
+
+        /** */
+        public void externalCollision() {
+            CollisionExternalListener tmp = lsnr;
+
+            if (tmp != null)
+                tmp.onExternalCollision();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6563e8a9/modules/core/src/test/java/org/apache/ignite/internal/IgniteCollisionJobsContextSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteCollisionJobsContextSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCollisionJobsContextSelfTest.java
new file mode 100644
index 0000000..792b7ee
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteCollisionJobsContextSelfTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.collision.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+/**
+ * Collision job context test.
+ */
+@GridCommonTest(group = "Kernal Self")
+public class IgniteCollisionJobsContextSelfTest extends IgniteCommonAbstractTest {
+    /** */
+    public IgniteCollisionJobsContextSelfTest() {
+        super(/*start grid*/true);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        Ignite ignite = G.ignite(getTestIgniteName());
+
+        assert ignite != null;
+    }
+
+    /** {@inheritDoc}
+     * @param igniteName*/
+    @Override protected IgniteConfiguration getConfiguration(String igniteName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteName);
+
+        cfg.setCollisionSpi(new TestCollisionSpi());
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If test failed.
+     */
+    public void testCollisionJobContext() throws Exception {
+        G.ignite(getTestIgniteName()).compute().execute(new GridTestTask(), "some-arg");
+    }
+
+    /** */
+    @SuppressWarnings( {"PublicInnerClass"})
+    @IgniteSpiMultipleInstancesSupport(true)
+    public static class TestCollisionSpi extends IgniteSpiAdapter implements CollisionSpi {
+        /** Grid logger. */
+        @IgniteLoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override public void onCollision(CollisionContext ctx) {
+            Collection<CollisionJobContext> activeJobs = ctx.activeJobs();
+            Collection<CollisionJobContext> waitJobs = ctx.waitingJobs();
+
+            assert waitJobs != null;
+            assert activeJobs != null;
+
+
+            for (CollisionJobContext job : waitJobs) {
+                assert job.getJob() != null;
+                assert job.getJobContext() != null;
+                assert job.getTaskSession() != null;
+
+                assert job.getJob() instanceof GridTestJob : job.getJob();
+
+                job.activate();
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void spiStart(String gridName) throws IgniteSpiException {
+            // Start SPI start stopwatch.
+            startStopwatch();
+
+            // Ack start.
+            if (log.isInfoEnabled())
+                log.info(startInfo());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void spiStop() throws IgniteSpiException {
+            // Ack stop.
+            if (log.isInfoEnabled())
+                log.info(stopInfo());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void setExternalCollisionListener(CollisionExternalListener lsnr) {
+            // No-op.
+        }
+    }
+}


Mime
View raw message