You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/06/01 11:27:47 UTC

[01/17] ignite git commit: IGNITE-2718: Added Zookeeper IP finder dependencies. Backport

Repository: ignite
Updated Branches:
  refs/heads/ignite-3038 b4883e654 -> c0e8c420e


IGNITE-2718: Added Zookeeper IP finder dependencies. Backport


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/eade5137
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/eade5137
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/eade5137

Branch: refs/heads/ignite-3038
Commit: eade513759e9df46896bd7524f224a1845adef47
Parents: 303d3ca
Author: shtykh_roman <rs...@yahoo.com>
Authored: Wed Mar 2 06:02:27 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Fri May 27 18:01:55 2016 +0300

----------------------------------------------------------------------
 modules/zookeeper/pom.xml                       | 50 +++++++++++++++++++-
 .../tcp/ipfinder/zk/ZookeeperIpFinderTest.java  | 24 ++++++----
 2 files changed, 63 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/eade5137/modules/zookeeper/pom.xml
----------------------------------------------------------------------
diff --git a/modules/zookeeper/pom.xml b/modules/zookeeper/pom.xml
index e296b55..b749c30 100644
--- a/modules/zookeeper/pom.xml
+++ b/modules/zookeeper/pom.xml
@@ -20,7 +20,8 @@
 <!--
     POM file.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
@@ -55,6 +56,53 @@
 
         <dependency>
             <groupId>org.apache.curator</groupId>
+            <artifactId>curator-client</artifactId>
+            <version>${curator.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>${guava16.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-core-asl</artifactId>
+            <version>${jackson.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-mapper-asl</artifactId>
+            <version>${jackson.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.zookeeper</groupId>
+            <artifactId>zookeeper</artifactId>
+            <version>${zookeeper.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.curator</groupId>
             <artifactId>curator-test</artifactId>
             <version>${curator.version}</version>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/ignite/blob/eade5137/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java
----------------------------------------------------------------------
diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java
index c19a8fc..ec868ea 100644
--- a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java
+++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZookeeperIpFinderTest.java
@@ -27,6 +27,7 @@ import org.apache.curator.retry.ExponentialBackoffRetry;
 import org.apache.curator.retry.RetryNTimes;
 import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.test.TestingCluster;
+import org.apache.curator.utils.CloseableUtils;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.Event;
@@ -64,6 +65,7 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
 
     /**
      * Before test.
+     *
      * @throws Exception
      */
     @Override public void beforeTest() throws Exception {
@@ -72,6 +74,9 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
         // remove stale system properties
         System.getProperties().remove(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING);
 
+        // disable JMX for tests
+        System.setProperty("zookeeper.jmx.log4j.disable", "true");
+
         // start the ZK cluster
         zkCluster = new TestingCluster(ZK_CLUSTER_SIZE);
         zkCluster.start();
@@ -84,18 +89,17 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
 
     /**
      * After test.
+     *
      * @throws Exception
      */
     @Override public void afterTest() throws Exception {
         super.afterTest();
 
         if (zkCurator != null)
-            zkCurator.close();
+            CloseableUtils.closeQuietly(zkCurator);
 
-        if (zkCluster != null) {
-            zkCluster.stop();
-            zkCluster.close();
-        }
+        if (zkCluster != null)
+            CloseableUtils.closeQuietly(zkCluster);
 
         stopAllGrids();
 
@@ -111,7 +115,7 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration configuration = super.getConfiguration(gridName);
 
-        TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi) configuration.getDiscoverySpi();
+        TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)configuration.getDiscoverySpi();
         TcpDiscoveryZookeeperIpFinder zkIpFinder = new TcpDiscoveryZookeeperIpFinder();
         zkIpFinder.setAllowDuplicateRegistrations(isAllowDuplicateRegistrations());
 
@@ -148,7 +152,7 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
         startGrid(0);
 
         // set up an event listener to expect one NODE_JOINED event
-        CountDownLatch latch =  expectJoinEvents(grid(0), 1);
+        CountDownLatch latch = expectJoinEvents(grid(0), 1);
 
         // start the other node
         startGrid(1);
@@ -171,7 +175,7 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
         startGrid(0);
 
         // set up an event listener to expect one NODE_JOINED event
-        CountDownLatch latch =  expectJoinEvents(grid(0), 2);
+        CountDownLatch latch = expectJoinEvents(grid(0), 2);
 
         // start the 2nd node
         startGrid(1);
@@ -202,7 +206,7 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
         startGrid(0);
 
         // set up an event listener to expect one NODE_JOINED event
-        CountDownLatch latch =  expectJoinEvents(grid(0), 3);
+        CountDownLatch latch = expectJoinEvents(grid(0), 3);
 
         // start the 2nd node
         startGrid(1);
@@ -392,4 +396,4 @@ public class ZookeeperIpFinderTest extends GridCommonAbstractTest {
     public boolean isAllowDuplicateRegistrations() {
         return allowDuplicateRegistrations;
     }
-}
\ No newline at end of file
+}


[16/17] ignite git commit: Merge remote-tracking branch 'upstream/gridgain-7.5.24' into gridgain-7.5.24

Posted by sb...@apache.org.
Merge remote-tracking branch 'upstream/gridgain-7.5.24' into gridgain-7.5.24


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/52a2637c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/52a2637c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/52a2637c

Branch: refs/heads/ignite-3038
Commit: 52a2637c27364265bbb3fcf0ee89f1240b11acd7
Parents: b28e7a8 efea097
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue May 31 13:59:32 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue May 31 13:59:32 2016 +0300

----------------------------------------------------------------------
 .../IgniteTxExceptionAbstractSelfTest.java      | 43 ++++++++++++--------
 1 file changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------



[17/17] ignite git commit: Merge remote-tracking branch 'remotes/community/gridgain-7.5.24' into ignite-3038

Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/community/gridgain-7.5.24' into ignite-3038


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c0e8c420
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c0e8c420
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c0e8c420

Branch: refs/heads/ignite-3038
Commit: c0e8c420ec4a69a8c040cb054bbefefe6936845d
Parents: b4883e6 52a2637
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jun 1 14:27:11 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jun 1 14:27:11 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java   |  21 +-
 .../processors/cache/GridCacheAdapter.java      |  12 +-
 .../processors/cache/GridCacheContext.java      |   5 +-
 .../processors/cache/GridCacheSwapManager.java  |  70 ++-
 .../distributed/dht/GridDhtCacheAdapter.java    |   9 +-
 .../cache/query/GridCacheQueryManager.java      |   9 +-
 .../ignite/internal/util/IgniteUtils.java       |   2 +
 .../org/apache/ignite/spi/IgniteSpiAdapter.java |  28 +-
 .../binary/BinaryMarshallerSelfTest.java        |  15 +
 .../cache/IgniteCachePeekModesAbstractTest.java |   8 +-
 .../IgniteTxExceptionAbstractSelfTest.java      |  43 +-
 .../CacheKeepBinaryWithInterceptorTest.java     |  36 +-
 ...CacheLocalOffHeapAndSwapMetricsSelfTest.java | 415 -------------
 .../CacheOffHeapAndSwapMetricsSelfTest.java     | 621 +++++++++++++++++++
 ...CacheKeepBinaryIterationNearEnabledTest.java |  44 ++
 ...acheKeepBinaryIterationStoreEnabledTest.java |  90 +++
 ...CacheKeepBinaryIterationSwapEnabledTest.java |  56 ++
 .../CacheKeepBinaryIterationTest.java           | 471 ++++++++++++++
 .../IgniteCacheMetricsSelfTestSuite.java        |   4 +-
 .../hadoop/fs/BasicHadoopFileSystemFactory.java |  56 +-
 .../fs/CachingHadoopFileSystemFactory.java      |   7 +-
 .../fs/KerberosHadoopFileSystemFactory.java     |   4 +-
 .../ignite/hadoop/util/BasicUserNameMapper.java | 114 ++++
 .../hadoop/util/ChainedUserNameMapper.java      |  94 +++
 .../hadoop/util/KerberosUserNameMapper.java     | 137 ++++
 .../ignite/hadoop/util/UserNameMapper.java      |  37 ++
 .../apache/ignite/hadoop/util/package-info.java |  22 +
 .../util/BasicUserNameMapperSelfTest.java       | 116 ++++
 .../util/ChainedUserNameMapperSelfTest.java     | 107 ++++
 .../util/KerberosUserNameMapperSelfTest.java    |  99 +++
 .../ignite/igfs/Hadoop1DualAbstractTest.java    |  46 ++
 .../testsuites/IgniteHadoopTestSuite.java       |   8 +
 .../IgniteCacheQuerySelfTestSuite3.java         |   8 +
 .../ignite/internal/GridFactorySelfTest.java    |  27 +-
 modules/zookeeper/pom.xml                       |  50 +-
 .../tcp/ipfinder/zk/ZookeeperIpFinderTest.java  |  24 +-
 36 files changed, 2395 insertions(+), 520 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c0e8c420/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------


[11/17] ignite git commit: IGNITE-3202: Hadoop: Implemented user name mappers.

Posted by sb...@apache.org.
IGNITE-3202: Hadoop: Implemented user name mappers.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/14403bb6
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/14403bb6
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/14403bb6

Branch: refs/heads/ignite-3038
Commit: 14403bb667af55a15c4097a80dd08cc3f213f5db
Parents: 7533dfc
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue May 31 10:23:00 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue May 31 10:23:00 2016 +0300

----------------------------------------------------------------------
 .../hadoop/fs/BasicHadoopFileSystemFactory.java |  56 +++++++-
 .../fs/CachingHadoopFileSystemFactory.java      |   7 +-
 .../fs/KerberosHadoopFileSystemFactory.java     |   4 +-
 .../ignite/hadoop/util/BasicUserNameMapper.java | 114 +++++++++++++++
 .../hadoop/util/ChainedUserNameMapper.java      |  94 +++++++++++++
 .../hadoop/util/KerberosUserNameMapper.java     | 137 +++++++++++++++++++
 .../ignite/hadoop/util/UserNameMapper.java      |  37 +++++
 .../util/BasicUserNameMapperSelfTest.java       | 116 ++++++++++++++++
 .../util/ChainedUserNameMapperSelfTest.java     |  90 ++++++++++++
 .../util/KerberosUserNameMapperSelfTest.java    |  99 ++++++++++++++
 .../ignite/igfs/Hadoop1DualAbstractTest.java    |  46 +++++++
 .../testsuites/IgniteHadoopTestSuite.java       |   8 ++
 12 files changed, 796 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
index 01fe6c9..06f76c3 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/BasicHadoopFileSystemFactory.java
@@ -21,6 +21,8 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.hadoop.fs.v1.IgniteHadoopFileSystem;
+import org.apache.ignite.hadoop.util.KerberosUserNameMapper;
+import org.apache.ignite.hadoop.util.UserNameMapper;
 import org.apache.ignite.internal.processors.hadoop.HadoopUtils;
 import org.apache.ignite.internal.processors.igfs.IgfsUtils;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -46,10 +48,13 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
     private static final long serialVersionUID = 0L;
 
     /** File system URI. */
-    protected String uri;
+    private String uri;
 
     /** File system config paths. */
-    protected String[] cfgPaths;
+    private String[] cfgPaths;
+
+    /** User name mapper. */
+    private UserNameMapper usrNameMapper;
 
     /** Configuration of the secondary filesystem, never null. */
     protected transient Configuration cfg;
@@ -65,8 +70,13 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
     }
 
     /** {@inheritDoc} */
-    @Override public FileSystem get(String usrName) throws IOException {
-        return get0(IgfsUtils.fixUserName(usrName));
+    @Override public final FileSystem get(String name) throws IOException {
+        String name0 = IgfsUtils.fixUserName(name);
+
+        if (usrNameMapper != null)
+            name0 = IgfsUtils.fixUserName(usrNameMapper.map(name0));
+
+        return getWithMappedName(name0);
     }
 
     /**
@@ -76,7 +86,7 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
      * @return File system.
      * @throws IOException If failed.
      */
-    protected FileSystem get0(String usrName) throws IOException {
+    protected FileSystem getWithMappedName(String usrName) throws IOException {
         assert cfg != null;
 
         try {
@@ -168,6 +178,32 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
         this.cfgPaths = cfgPaths;
     }
 
+    /**
+     * Get optional user name mapper.
+     * <p>
+     * When IGFS is invoked from Hadoop, user name is passed along the way to ensure that request will be performed
+     * with proper user context. User name is passed in a simple form and doesn't contain any extended information,
+     * such as host, domain or Kerberos realm. You may use name mapper to translate plain user name to full user
+     * name required by security engine of the underlying file system.
+     * <p>
+     * For example you may want to use {@link KerberosUserNameMapper} to user name from {@code "johndoe"} to
+     * {@code "johndoe@YOUR.REALM.COM"}.
+     *
+     * @return User name mapper.
+     */
+    @Nullable public UserNameMapper getUserNameMapper() {
+        return usrNameMapper;
+    }
+
+    /**
+     * Set optional user name mapper. See {@link #getUserNameMapper()} for more information.
+     *
+     * @param usrNameMapper User name mapper.
+     */
+    public void setUserNameMapper(@Nullable UserNameMapper usrNameMapper) {
+        this.usrNameMapper = usrNameMapper;
+    }
+
     /** {@inheritDoc} */
     @Override public void start() throws IgniteException {
         cfg = HadoopUtils.safeCreateConfiguration();
@@ -201,11 +237,15 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
                 throw new IgniteException("Failed to resolve secondary file system URI: " + uri);
             }
         }
+
+        if (usrNameMapper != null && usrNameMapper instanceof LifecycleAware)
+            ((LifecycleAware)usrNameMapper).start();
     }
 
     /** {@inheritDoc} */
     @Override public void stop() throws IgniteException {
-        // No-op.
+        if (usrNameMapper != null && usrNameMapper instanceof LifecycleAware)
+            ((LifecycleAware)usrNameMapper).stop();
     }
 
     /** {@inheritDoc} */
@@ -220,6 +260,8 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
         }
         else
             out.writeInt(-1);
+
+        out.writeObject(usrNameMapper);
     }
 
     /** {@inheritDoc} */
@@ -234,5 +276,7 @@ public class BasicHadoopFileSystemFactory implements HadoopFileSystemFactory, Ex
             for (int i = 0; i < cfgPathsCnt; i++)
                 cfgPaths[i] = U.readString(in);
         }
+
+        usrNameMapper = (UserNameMapper)in.readObject();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/CachingHadoopFileSystemFactory.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/CachingHadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/CachingHadoopFileSystemFactory.java
index e1b30c4..bcbb082 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/CachingHadoopFileSystemFactory.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/CachingHadoopFileSystemFactory.java
@@ -23,7 +23,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.internal.processors.hadoop.fs.HadoopFileSystemsUtils;
 import org.apache.ignite.internal.processors.hadoop.fs.HadoopLazyConcurrentMap;
-import org.apache.ignite.internal.processors.igfs.IgfsUtils;
 
 import java.io.IOException;
 import java.net.URI;
@@ -47,7 +46,7 @@ public class CachingHadoopFileSystemFactory extends BasicHadoopFileSystemFactory
     private final transient HadoopLazyConcurrentMap<String, FileSystem> cache = new HadoopLazyConcurrentMap<>(
         new HadoopLazyConcurrentMap.ValueFactory<String, FileSystem>() {
             @Override public FileSystem createValue(String key) throws IOException {
-                return get0(key);
+                return CachingHadoopFileSystemFactory.super.getWithMappedName(key);
             }
         }
     );
@@ -60,8 +59,8 @@ public class CachingHadoopFileSystemFactory extends BasicHadoopFileSystemFactory
     }
 
     /** {@inheritDoc} */
-    @Override public FileSystem get(String usrName) throws IOException {
-        return cache.getOrCreate(IgfsUtils.fixUserName(usrName));
+    @Override public FileSystem getWithMappedName(String name) throws IOException {
+        return cache.getOrCreate(name);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java
index a78cabc..bbfbc59 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/fs/KerberosHadoopFileSystemFactory.java
@@ -68,10 +68,10 @@ public class KerberosHadoopFileSystemFactory extends BasicHadoopFileSystemFactor
     }
 
     /** {@inheritDoc} */
-    @Override public FileSystem get(String userName) throws IOException {
+    @Override public FileSystem getWithMappedName(String name) throws IOException {
         reloginIfNeeded();
 
-        return super.get(userName);
+        return super.getWithMappedName(name);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/BasicUserNameMapper.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/BasicUserNameMapper.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/BasicUserNameMapper.java
new file mode 100644
index 0000000..aea7196
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/BasicUserNameMapper.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.hadoop.util;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
+
+/**
+ * Name mapper which maps one user name to another based on predefined dictionary. If name is not found in the
+ * dictionary, or dictionary is not defined, either passed user name or some default value could be returned.
+ */
+public class BasicUserNameMapper implements UserNameMapper {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Mappings. */
+    private Map<String, String> mappings;
+
+    /** Whether to use default user name. */
+    private boolean useDfltUsrName;;
+
+    /** Default user name. */
+    private String dfltUsrName;
+
+    /** {@inheritDoc} */
+    @Nullable @Override public String map(String name) {
+        assert mappings != null;
+
+        String res = mappings.get(name);
+
+        return res != null ? res : useDfltUsrName ? dfltUsrName : name;
+    }
+
+    /**
+     * Get mappings.
+     *
+     * @return Mappings.
+     */
+    @Nullable public Map<String, String> getMappings() {
+        return mappings;
+    }
+
+    /**
+     * Set mappings.
+     *
+     * @param mappings Mappings.
+     */
+    public void setMappings(@Nullable Map<String, String> mappings) {
+        this.mappings = mappings;
+    }
+
+    /**
+     * Get whether to use default user name when there is no mapping for current user name.
+     *
+     * @return Whether to use default user name.
+     */
+    public boolean isUseDefaultUserName() {
+        return useDfltUsrName;
+    }
+
+    /**
+     * Set whether to use default user name when there is no mapping for current user name.
+     *
+     * @param useDfltUsrName Whether to use default user name.
+     */
+    public void setUseDefaultUserName(boolean useDfltUsrName) {
+        this.useDfltUsrName = useDfltUsrName;
+    }
+
+    /**
+     * Get default user name (optional).
+     * <p>
+     * This user name will be used if provided mappings doesn't contain mapping for the given user name and
+     * {#isUseDefaultUserName} is set to {@code true}.
+     * <p>
+     * Defaults to {@code null}.
+     *
+     * @return Default user name.
+     */
+    @Nullable public String getDefaultUserName() {
+        return dfltUsrName;
+    }
+
+    /**
+     * Set default user name (optional). See {@link #getDefaultUserName()} for more information.
+     *
+     * @param dfltUsrName Default user name.
+     */
+    public void setDefaultUserName(@Nullable String dfltUsrName) {
+        this.dfltUsrName = dfltUsrName;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BasicUserNameMapper.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
new file mode 100644
index 0000000..7635e25
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
@@ -0,0 +1,94 @@
+/*
+ * 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.hadoop.util;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Arrays;
+
+/**
+ * Chained user name mapper. Delegate name conversion to child mappers.
+ */
+public class ChainedUserNameMapper implements UserNameMapper, LifecycleAware {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Child mappers. */
+    private UserNameMapper[] mappers;
+
+    /** {@inheritDoc} */
+    @Nullable @Override public String map(String name) {
+        for (UserNameMapper mapper : mappers)
+            name = mapper.map(name);
+
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start() throws IgniteException {
+        if (mappers == null)
+            throw new IgniteException("Mappers cannot be null.");
+
+        for (int i = 0; i < mappers.length; i++) {
+            if (mappers[i] == null)
+                throw new IgniteException("Mapper cannot be null [index=" + i + ']');
+        }
+
+        for (UserNameMapper mapper : mappers) {
+            if (mapper instanceof LifecycleAware)
+                ((LifecycleAware)mapper).start();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws IgniteException {
+        assert mappers != null;
+
+        for (UserNameMapper mapper : mappers) {
+            if (mapper instanceof LifecycleAware)
+                ((LifecycleAware)mapper).stop();
+        }
+    }
+
+    /**
+     * Get child mappers.
+     *
+     * @return Child mappers.
+     */
+    public UserNameMapper[] getMappers() {
+        return mappers;
+    }
+
+    /**
+     * Set child mappers.
+     *
+     * @param mappers Child mappers.
+     */
+    public void setMappers(UserNameMapper... mappers) {
+        this.mappers = mappers;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(ChainedUserNameMapper.class, this,
+            "mappers", mappers != null ? Arrays.toString(mappers) : null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
new file mode 100644
index 0000000..433fb82
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
@@ -0,0 +1,137 @@
+/*
+ * 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.hadoop.util;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.igfs.IgfsUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Kerberos user name mapper. Use it when you need to map simple user name to Kerberos principal.
+ * E.g. from {@code johndoe} to {@code johndoe@YOUR.REALM.COM} or {@code johndoe/admin@YOUR.REALM.COM}.
+ */
+public class KerberosUserNameMapper implements UserNameMapper, LifecycleAware {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Instance. */
+    private String instance;
+
+    /** Realm. */
+    private String realm;
+
+    /** State. */
+    private volatile State state;
+
+    /** {@inheritDoc} */
+    @Nullable @Override public String map(String name) {
+        assert state != null;
+
+        name = IgfsUtils.fixUserName(name);
+
+        switch (state) {
+            case NAME:
+                return name;
+
+            case NAME_REALM:
+                return name + '@' + realm;
+
+            case NAME_INSTANCE:
+                return name + '/' + instance;
+
+            default:
+                assert state == State.NAME_INSTANCE_REALM;
+
+                return name + '/' + instance + '@' + realm;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start() throws IgniteException {
+        if (!F.isEmpty(instance))
+            state = F.isEmpty(realm) ? State.NAME_INSTANCE : State.NAME_INSTANCE_REALM;
+        else
+            state = F.isEmpty(realm) ? State.NAME : State.NAME_REALM;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws IgniteException {
+        // No-op.
+    }
+
+    /**
+     * Get Kerberos instance (optional).
+     *
+     * @return Instance.
+     */
+    @Nullable public String getInstance() {
+        return instance;
+    }
+
+    /**
+     * Set Kerberos instance (optional).
+     *
+     * @param instance Kerberos instance.
+     */
+    public void setInstance(@Nullable String instance) {
+        this.instance = instance;
+    }
+
+    /**
+     * Get Kerberos realm (optional).
+     *
+     * @return Kerberos realm.
+     */
+    @Nullable public String getRealm() {
+        return realm;
+    }
+
+    /**
+     * Set Kerberos realm (optional).
+     *
+     * @param realm Kerberos realm.
+     */
+    public void setRealm(@Nullable String realm) {
+        this.realm = realm;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(KerberosUserNameMapper.class, this);
+    }
+
+    /**
+     * State enumeration.
+     */
+    private enum State {
+        /** Name only. */
+        NAME,
+
+        /** Name and realm. */
+        NAME_REALM,
+
+        /** Name and host. */
+        NAME_INSTANCE,
+
+        /** Name, host and realm. */
+        NAME_INSTANCE_REALM,
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/UserNameMapper.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/UserNameMapper.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/UserNameMapper.java
new file mode 100644
index 0000000..26dc4b2
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/UserNameMapper.java
@@ -0,0 +1,37 @@
+/*
+ * 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.hadoop.util;
+
+import org.apache.ignite.hadoop.fs.HadoopFileSystemFactory;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.Serializable;
+
+/**
+ * Hadoop file system name mapper. Used by {@link HadoopFileSystemFactory} implementation to pass proper user names
+ * to the underlying Hadoop file system.
+ */
+public interface UserNameMapper extends Serializable {
+    /**
+     * Map user name.
+     *
+     * @param name User name.
+     * @return Mapped user name.
+     */
+    @Nullable public String map(String name);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
new file mode 100644
index 0000000..54b03f9
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.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.hadoop.util;
+
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test for basic user name mapper.
+ */
+public class BasicUserNameMapperSelfTest extends GridCommonAbstractTest {
+    /**
+     * Test empty mappings.
+     *
+     * @throws Exception If failed.
+     */
+    public void testEmptyMappings() throws Exception {
+        Map<String, String> map = new HashMap<>();
+
+        BasicUserNameMapper mapper = create(map, false, null);
+
+        assertNull(mapper.map(null));
+        assertEquals("1", mapper.map("1"));
+        assertEquals("2", mapper.map("2"));
+
+        mapper = create(map, true, null);
+
+        assertNull(mapper.map(null));
+        assertNull(mapper.map("1"));
+        assertNull(mapper.map("2"));
+
+        mapper = create(map, false, "A");
+
+        assertNull(mapper.map(null));
+        assertEquals("1", mapper.map("1"));
+        assertEquals("2", mapper.map("2"));
+
+        mapper = create(map, true, "A");
+
+        assertEquals("A", mapper.map(null));
+        assertEquals("A", mapper.map("1"));
+        assertEquals("A", mapper.map("2"));
+    }
+
+    /**
+     * Test regular mappings.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMappings() throws Exception {
+        Map<String, String> map = new HashMap<>();
+
+        map.put("1", "101");
+
+        BasicUserNameMapper mapper = create(map, false, null);
+
+        assertNull(mapper.map(null));
+        assertEquals("101", mapper.map("1"));
+        assertEquals("2", mapper.map("2"));
+
+        mapper = create(map, true, null);
+
+        assertNull(mapper.map(null));
+        assertEquals("101", mapper.map("1"));
+        assertNull(mapper.map("2"));
+
+        mapper = create(map, false, "A");
+
+        assertNull(mapper.map(null));
+        assertEquals("101", mapper.map("1"));
+        assertEquals("2", mapper.map("2"));
+
+        mapper = create(map, true, "A");
+
+        assertEquals("A", mapper.map(null));
+        assertEquals("101", mapper.map("1"));
+        assertEquals("A", mapper.map("2"));
+    }
+
+    /**
+     * Create mapper.
+     *
+     * @param dictionary Dictionary.
+     * @param useDfltUsrName Whether to use default user name.
+     * @param dfltUsrName Default user name.
+     * @return Mapper.
+     */
+    private BasicUserNameMapper create(@Nullable Map<String, String> dictionary, boolean useDfltUsrName,
+        @Nullable String dfltUsrName) {
+        BasicUserNameMapper mapper = new BasicUserNameMapper();
+
+        mapper.setMappings(dictionary);
+        mapper.setUseDefaultUserName(useDfltUsrName);
+        mapper.setDefaultUserName(dfltUsrName);
+
+        return mapper;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
new file mode 100644
index 0000000..5bdac8f
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
@@ -0,0 +1,90 @@
+package org.apache.ignite.hadoop.util;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.igfs.IgfsUtils;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+/**
+ * Tests for chained user name mapper.
+ */
+public class ChainedUserNameMapperSelfTest extends GridCommonAbstractTest {
+    /** Test instance. */
+    private static final String INSTANCE = "test_instance";
+
+    /** Test realm. */
+    private static final String REALM = "test_realm";
+
+    /**
+     * Test case when mappers are null.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    public void testNullMappers() throws Exception {
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                create((UserNameMapper[])null);
+
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test case when one of mappers is null.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    public void testNullMapperElement() throws Exception {
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                create(new BasicUserNameMapper(), null);
+
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test actual chaining logic.
+     *
+     * @throws Exception If failed.
+     */
+    public void testChaining() throws Exception {
+        BasicUserNameMapper mapper1 = new BasicUserNameMapper();
+
+        mapper1.setMappings(Collections.singletonMap("1", "101"));
+
+        KerberosUserNameMapper mapper2 = new KerberosUserNameMapper();
+
+        mapper2.setInstance(INSTANCE);
+        mapper2.setRealm(REALM);
+
+        ChainedUserNameMapper mapper = create(mapper1, mapper2);
+
+        assertEquals("101" + "/" + INSTANCE + "@" + REALM, mapper.map("1"));
+        assertEquals("2" + "/" + INSTANCE + "@" + REALM, mapper.map("2"));
+        assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE + "@" + REALM, mapper.map(null));
+    }
+
+    /**
+     * Create chained mapper.
+     *
+     * @param mappers Child mappers.
+     * @return Chained mapper.
+     */
+    private ChainedUserNameMapper create(UserNameMapper... mappers) {
+        ChainedUserNameMapper mapper = new ChainedUserNameMapper();
+
+        mapper.setMappers(mappers);
+
+        mapper.start();
+
+        return mapper;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
new file mode 100644
index 0000000..cc685bb
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.hadoop.util;
+
+import org.apache.ignite.internal.processors.igfs.IgfsUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Tests for Kerberos name mapper.
+ */
+public class KerberosUserNameMapperSelfTest extends GridCommonAbstractTest {
+    /** Test instance. */
+    private static final String INSTANCE = "test_instance";
+
+    /** Test realm. */
+    private static final String REALM = "test_realm";
+
+    /**
+     * Test mapper without instance and realm components.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapper() throws Exception {
+        KerberosUserNameMapper mapper = create(null, null);
+
+        assertEquals(IgfsUtils.fixUserName(null), mapper.map(null));
+        assertEquals("test", mapper.map("test"));
+    }
+
+    /**
+     * Test mapper with instance component.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapperInstance() throws Exception {
+        KerberosUserNameMapper mapper = create(INSTANCE, null);
+
+        assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE, mapper.map(null));
+        assertEquals("test" + "/" + INSTANCE, mapper.map("test"));
+    }
+
+    /**
+     * Test mapper with realm.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapperRealm() throws Exception {
+        KerberosUserNameMapper mapper = create(null, REALM);
+
+        assertEquals(IgfsUtils.fixUserName(null) + "@" + REALM, mapper.map(null));
+        assertEquals("test" + "@" + REALM, mapper.map("test"));
+    }
+
+    /**
+     * Test mapper with instance and realm components.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapperInstanceAndRealm() throws Exception {
+        KerberosUserNameMapper mapper = create(INSTANCE, REALM);
+
+        assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE + "@" + REALM, mapper.map(null));
+        assertEquals("test" + "/" + INSTANCE + "@" + REALM, mapper.map("test"));
+    }
+
+    /**
+     * Create mapper.
+     *
+     * @param instance Instance.
+     * @param realm Realm.
+     * @return Mapper.
+     */
+    private KerberosUserNameMapper create(@Nullable String instance, @Nullable String realm) {
+        KerberosUserNameMapper mapper = new KerberosUserNameMapper();
+
+        mapper.setInstance(instance);
+        mapper.setRealm(realm);
+
+        mapper.start();
+
+        return mapper;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java b/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
index 10b1bcd..81f5743 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/igfs/Hadoop1DualAbstractTest.java
@@ -19,10 +19,16 @@ package org.apache.ignite.igfs;
 
 import java.io.IOException;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.ignite.IgniteException;
 import org.apache.ignite.hadoop.fs.CachingHadoopFileSystemFactory;
 import org.apache.ignite.hadoop.fs.IgniteHadoopIgfsSecondaryFileSystem;
+import org.apache.ignite.hadoop.util.ChainedUserNameMapper;
+import org.apache.ignite.hadoop.util.KerberosUserNameMapper;
+import org.apache.ignite.hadoop.util.UserNameMapper;
 import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
 import org.apache.ignite.internal.processors.igfs.IgfsDualAbstractSelfTest;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.igfs.HadoopSecondaryFileSystemConfigurationTest.IGFS_SCHEME;
 import static org.apache.ignite.igfs.HadoopSecondaryFileSystemConfigurationTest.SECONDARY_CFG_PATH;
@@ -74,10 +80,21 @@ public abstract class Hadoop1DualAbstractTest extends IgfsDualAbstractSelfTest {
 
         prepareConfiguration();
 
+        KerberosUserNameMapper mapper1 = new KerberosUserNameMapper();
+
+        mapper1.setRealm("TEST.COM");
+
+        TestUserNameMapper mapper2 = new TestUserNameMapper();
+
+        ChainedUserNameMapper mapper = new ChainedUserNameMapper();
+
+        mapper.setMappers(mapper1, mapper2);
+
         CachingHadoopFileSystemFactory factory = new CachingHadoopFileSystemFactory();
 
         factory.setUri(secondaryUri);
         factory.setConfigPaths(secondaryConfFullPath);
+        factory.setUserNameMapper(mapper);
 
         IgniteHadoopIgfsSecondaryFileSystem second = new IgniteHadoopIgfsSecondaryFileSystem();
 
@@ -109,4 +126,33 @@ public abstract class Hadoop1DualAbstractTest extends IgfsDualAbstractSelfTest {
 
         secondaryUri = mkUri(IGFS_SCHEME, SECONDARY_AUTHORITY);
     }
+
+    /**
+     * Test user name mapper.
+     */
+    private static class TestUserNameMapper implements UserNameMapper, LifecycleAware {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Started flag. */
+        private boolean started;
+
+        /** {@inheritDoc} */
+        @Nullable @Override public String map(String name) {
+            assert started;
+            assert name != null && name.contains("@");
+
+            return name.substring(0, name.indexOf("@"));
+        }
+
+        /** {@inheritDoc} */
+        @Override public void start() throws IgniteException {
+            started = true;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void stop() throws IgniteException {
+            // No-op.
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/14403bb6/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
index ebc0c23..e0d1142 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
@@ -26,6 +26,10 @@ import org.apache.ignite.client.hadoop.HadoopClientProtocolEmbeddedSelfTest;
 import org.apache.ignite.client.hadoop.HadoopClientProtocolSelfTest;
 import org.apache.ignite.hadoop.cache.HadoopTxConfigCacheTest;
 import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactorySelfTest;
+import org.apache.ignite.hadoop.util.BasicUserNameMapperSelfTest;
+import org.apache.ignite.hadoop.util.ChainedUserNameMapperSelfTest;
+import org.apache.ignite.hadoop.util.KerberosUserNameMapper;
+import org.apache.ignite.hadoop.util.KerberosUserNameMapperSelfTest;
 import org.apache.ignite.igfs.Hadoop1OverIgfsDualAsyncTest;
 import org.apache.ignite.igfs.Hadoop1OverIgfsDualSyncTest;
 import org.apache.ignite.igfs.HadoopFIleSystemFactorySelfTest;
@@ -104,6 +108,10 @@ public class IgniteHadoopTestSuite extends TestSuite {
 
         TestSuite suite = new TestSuite("Ignite Hadoop MR Test Suite");
 
+        suite.addTest(new TestSuite(ldr.loadClass(BasicUserNameMapperSelfTest.class.getName())));
+        suite.addTest(new TestSuite(ldr.loadClass(KerberosUserNameMapperSelfTest.class.getName())));
+        suite.addTest(new TestSuite(ldr.loadClass(ChainedUserNameMapperSelfTest.class.getName())));
+
         suite.addTest(new TestSuite(ldr.loadClass(KerberosHadoopFileSystemFactorySelfTest.class.getName())));
 
         suite.addTest(new TestSuite(ldr.loadClass(HadoopSnappyTest.class.getName())));


[03/17] ignite git commit: Fixed ClassNotFoundException for void.class

Posted by sb...@apache.org.
Fixed ClassNotFoundException for void.class


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f487874e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f487874e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f487874e

Branch: refs/heads/ignite-3038
Commit: f487874e2f6776b217aab0661d4009b73234bd79
Parents: 30ca35b
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Fri Mar 11 14:35:14 2016 -0800
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:27:26 2016 +0300

----------------------------------------------------------------------
 .../src/main/java/org/apache/ignite/internal/util/IgniteUtils.java | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f487874e/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index c5c6398..3717d31 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -592,6 +592,7 @@ public abstract class IgniteUtils {
         primitiveMap.put("double", double.class);
         primitiveMap.put("char", char.class);
         primitiveMap.put("boolean", boolean.class);
+        primitiveMap.put("void", void.class);
 
         boxedClsMap.put(byte.class, Byte.class);
         boxedClsMap.put(short.class, Short.class);
@@ -601,6 +602,7 @@ public abstract class IgniteUtils {
         boxedClsMap.put(double.class, Double.class);
         boxedClsMap.put(char.class, Character.class);
         boxedClsMap.put(boolean.class, Boolean.class);
+        boxedClsMap.put(void.class, Void.class);
 
         try {
             OBJECT_CTOR = Object.class.getConstructor();


[10/17] ignite git commit: IGNITE-3190: OffHeap cache metrics doesn't work properly for OFFHEAP_TIRED mode. Reviewed and merged by Denis Magda (dmagda@gridgain.com)

Posted by sb...@apache.org.
IGNITE-3190: OffHeap cache metrics doesn't work properly for OFFHEAP_TIRED mode.
Reviewed and merged by Denis Magda (dmagda@gridgain.com)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7533dfc2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7533dfc2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7533dfc2

Branch: refs/heads/ignite-3038
Commit: 7533dfc2d909f9ba210939da9ab8e3185acfae51
Parents: 3177562
Author: Vladislav Pyatkov <vl...@gmail.com>
Authored: Tue May 31 10:01:46 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 10:01:46 2016 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheSwapManager.java  |   3 +
 ...CacheLocalOffHeapAndSwapMetricsSelfTest.java | 415 -------------
 .../CacheOffHeapAndSwapMetricsSelfTest.java     | 621 +++++++++++++++++++
 .../IgniteCacheMetricsSelfTestSuite.java        |   4 +-
 4 files changed, 626 insertions(+), 417 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7533dfc2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 001d4a3..d016208 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -820,6 +820,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         IgniteBiTuple<Long, Integer> ptr =
             offheap.valuePointer(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
 
+        if (cctx.config().isStatisticsEnabled())
+            cctx.cache().metrics0().onOffHeapRead(ptr != null);
+
         if (ptr != null) {
             assert ptr.get1() != null;
             assert ptr.get2() != null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/7533dfc2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java
deleted file mode 100644
index b638236..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java
+++ /dev/null
@@ -1,415 +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.processors.cache.local;
-
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMemoryMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-/**
- *
- */
-public class CacheLocalOffHeapAndSwapMetricsSelfTest extends GridCommonAbstractTest {
-    /** Grid count. */
-    private static final int GRID_CNT = 1;
-
-    /** Keys count. */
-    private static final int KEYS_CNT = 1000;
-
-    /** Max size. */
-    private static final int MAX_SIZE = 100;
-
-    /** Entry size. */
-    private static final int ENTRY_SIZE = 86; // Calculated as allocated size divided on entries count.
-
-    /** Offheap max count. */
-    private static final int OFFHEAP_MAX_CNT = KEYS_CNT / 2;
-
-    /** Offheap max size. */
-    private static final int OFFHEAP_MAX_SIZE = ENTRY_SIZE * OFFHEAP_MAX_CNT;
-
-    /** Cache. */
-    private IgniteCache<Integer, Integer> cache;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
-
-        return cfg;
-    }
-
-    /**
-     * @param offHeapSize Max off-heap size.
-     * @param swapEnabled Swap enabled.
-     */
-    private void createCache(int offHeapSize, boolean swapEnabled) {
-        CacheConfiguration ccfg = defaultCacheConfiguration();
-
-        ccfg.setStatisticsEnabled(true);
-
-        ccfg.setCacheMode(CacheMode.LOCAL);
-        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
-        ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);
-
-        ccfg.setOffHeapMaxMemory(offHeapSize);
-        ccfg.setSwapEnabled(swapEnabled);
-
-        ccfg.setEvictionPolicy(new FifoEvictionPolicy(MAX_SIZE));
-
-        cache = grid(0).getOrCreateCache(ccfg);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        super.beforeTestsStarted();
-
-        startGrids(GRID_CNT);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        super.afterTestsStopped();
-
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        if (cache != null)
-            cache.destroy();
-    }
-
-    /**
-     * @throws Exception if failed.
-     */
-    public void testOffHeapMetrics() throws Exception {
-        createCache(0, false);
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.put(i, i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets());
-        assertEquals(0, cache.metrics().getOffHeapHits());
-        assertEquals(0f, cache.metrics().getOffHeapHitPercentage());
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
-        assertEquals(100f, cache.metrics().getOffHeapMissPercentage());
-        assertEquals(0, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(0, cache.metrics().getOffHeapEvictions());
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapEntriesCount());
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.get(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets());
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits());
-        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
-        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(0, cache.metrics().getOffHeapEvictions());
-        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
-            cache.get(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets());
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits());
-        assertEquals(100 / 3.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
-        assertEquals(100 - (100 / 3.0), cache.metrics().getOffHeapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(0, cache.metrics().getOffHeapEvictions());
-        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.remove(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getOffHeapGets());
-        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getOffHeapHits());
-        assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE),
-            cache.metrics().getOffHeapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
-        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE),
-            cache.metrics().getOffHeapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(0, cache.metrics().getOffHeapEvictions());
-        assertEquals(0, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-    }
-
-    /**
-     * @throws Exception if failed.
-     */
-    public void testSwapMetrics() throws Exception {
-        createCache(-1, true);
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.put(i, i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapGets());
-        assertEquals(0, cache.metrics().getSwapHits());
-        assertEquals(0f, cache.metrics().getSwapHitPercentage());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
-        assertEquals(100f, cache.metrics().getSwapMissPercentage());
-        assertEquals(0, cache.metrics().getSwapRemovals());
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapEntriesCount());
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.get(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
-        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
-        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
-
-        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getSwapEntriesCount());
-
-        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
-            cache.get(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
-        assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
-        assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
-
-        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getSwapEntriesCount());
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.remove(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getSwapGets());
-        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getSwapHits());
-        assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE),
-            cache.metrics().getSwapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
-        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE),
-            cache.metrics().getSwapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getSwapRemovals());
-
-        assertEquals(0, cache.metrics().getSwapEntriesCount());
-    }
-
-    /**
-     * @throws Exception if failed.
-     */
-    public void testOffHeapAndSwapMetrics() throws Exception {
-        createCache(OFFHEAP_MAX_SIZE, true);
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.put(i, i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets());
-        assertEquals(0, cache.metrics().getOffHeapHits());
-        assertEquals(0f, cache.metrics().getOffHeapHitPercentage());
-        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
-        assertEquals(100f, cache.metrics().getOffHeapMissPercentage());
-        assertEquals(0, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapGets());
-        assertEquals(0, cache.metrics().getSwapHits());
-        assertEquals(0f, cache.metrics().getSwapHitPercentage());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
-        assertEquals(100f, cache.metrics().getSwapMissPercentage());
-        assertEquals(0, cache.metrics().getSwapRemovals());
-
-        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapEntriesCount());
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.get(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets());
-        assertEquals(0, cache.metrics().getOffHeapHits());
-        assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
-        assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1);
-        assertEquals(0, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
-        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
-        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
-
-        assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount());
-
-        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
-            cache.get(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets());
-        assertEquals(0, cache.metrics().getOffHeapHits());
-        assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapMisses());
-        assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1);
-        assertEquals(0, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets());
-        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
-        assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
-        assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
-
-        assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount());
-
-        for (int i = 0; i < KEYS_CNT; i++)
-            cache.remove(i);
-
-        printStat();
-
-        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
-        assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getOffHeapGets());
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapHits());
-        assertEquals(100 * OFFHEAP_MAX_CNT / (KEYS_CNT * 4.0 - MAX_SIZE),
-            cache.metrics().getOffHeapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 4 - OFFHEAP_MAX_CNT - MAX_SIZE, cache.metrics().getOffHeapMisses());
-        assertEquals(100 * (KEYS_CNT * 4 - OFFHEAP_MAX_CNT - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE),
-            cache.metrics().getOffHeapMissPercentage(), 0.1);
-        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapRemovals());
-
-        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
-        assertEquals(0, cache.metrics().getOffHeapEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount());
-        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
-
-        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
-        assertEquals(KEYS_CNT * 4 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapGets());
-        assertEquals(KEYS_CNT * 2 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapHits());
-        assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE - OFFHEAP_MAX_CNT) / (KEYS_CNT * 4.0 - MAX_SIZE - OFFHEAP_MAX_CNT),
-            cache.metrics().getSwapHitPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
-        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE - OFFHEAP_MAX_CNT),
-            cache.metrics().getSwapMissPercentage(), 0.1);
-        assertEquals(KEYS_CNT * 2 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapRemovals());
-
-        assertEquals(0, cache.metrics().getSwapEntriesCount());
-    }
-
-    /**
-     * Prints stats.
-     */
-    protected void printStat() {
-        System.out.println("!!! -------------------------------------------------------");
-        System.out.println("!!! Puts: cache = " + cache.metrics().getCachePuts() +
-            ", offheap = " + cache.metrics().getOffHeapPuts() +
-            ", swap = " + cache.metrics().getSwapPuts());
-        System.out.println("!!! Gets: cache = " + cache.metrics().getCacheGets() +
-            ", offheap = " + cache.metrics().getOffHeapGets() +
-            ", swap = " + cache.metrics().getSwapGets());
-        System.out.println("!!! Removes: cache = " + cache.metrics().getCacheRemovals() +
-            ", offheap = " + cache.metrics().getOffHeapRemovals() +
-            ", swap = " + cache.metrics().getSwapRemovals());
-        System.out.println("!!! Evictions: cache = " + cache.metrics().getCacheEvictions() +
-            ", offheap = " + cache.metrics().getOffHeapEvictions() +
-            ", swap = none" );
-        System.out.println("!!! Hits: cache = " + cache.metrics().getCacheHits() +
-            ", offheap = " + cache.metrics().getOffHeapHits() +
-            ", swap = " + cache.metrics().getSwapHits());
-        System.out.println("!!! Hit(%): cache = " + cache.metrics().getCacheHitPercentage() +
-            ", offheap = " + cache.metrics().getOffHeapHitPercentage() +
-            ", swap = " + cache.metrics().getSwapHitPercentage());
-        System.out.println("!!! Misses: cache = " + cache.metrics().getCacheMisses() +
-            ", offheap = " + cache.metrics().getOffHeapMisses() +
-            ", swap = " + cache.metrics().getSwapMisses());
-        System.out.println("!!! Miss(%): cache = " + cache.metrics().getCacheMissPercentage() +
-            ", offheap = " + cache.metrics().getOffHeapMissPercentage() +
-            ", swap = " + cache.metrics().getSwapMissPercentage());
-        System.out.println("!!! Entries: cache = " + cache.metrics().getSize() +
-            ", offheap = " + cache.metrics().getOffHeapEntriesCount() +
-            ", swap = " + cache.metrics().getSwapEntriesCount());
-        System.out.println("!!! Size: cache = none" +
-            ", offheap = " + cache.metrics().getOffHeapAllocatedSize() +
-            ", swap = " + cache.metrics().getSwapSize());
-        System.out.println();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/7533dfc2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheOffHeapAndSwapMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheOffHeapAndSwapMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheOffHeapAndSwapMetricsSelfTest.java
new file mode 100644
index 0000000..4d6529e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheOffHeapAndSwapMetricsSelfTest.java
@@ -0,0 +1,621 @@
+/*
+ * 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.processors.cache.local;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class CacheOffHeapAndSwapMetricsSelfTest extends GridCommonAbstractTest {
+    /** Grid count. */
+    private static final int GRID_CNT = 1;
+
+    /** Keys count. */
+    private static final int KEYS_CNT = 1000;
+
+    /** Max size. */
+    private static final int MAX_SIZE = 100;
+
+    /** Entry size. */
+    private static final int ENTRY_SIZE = 86; // Calculated as allocated size divided on entries count.
+
+    /** Offheap max count. */
+    private static final int OFFHEAP_MAX_CNT = KEYS_CNT / 2;
+
+    /** Offheap max size. */
+    private static final int OFFHEAP_MAX_SIZE = ENTRY_SIZE * OFFHEAP_MAX_CNT;
+
+    /** Cache. */
+    private IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+
+        return cfg;
+    }
+
+    /**
+     * @param memoryMode Cache memory mode.
+     * @param offHeapSize Max off-heap size.
+     * @param swapEnabled Swap enabled.
+     */
+    private void createCache(CacheMemoryMode memoryMode, int offHeapSize, boolean swapEnabled) {
+        CacheConfiguration ccfg = defaultCacheConfiguration();
+
+        ccfg.setStatisticsEnabled(true);
+
+        ccfg.setCacheMode(CacheMode.LOCAL);
+        ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+        ccfg.setMemoryMode(memoryMode);
+
+        ccfg.setOffHeapMaxMemory(offHeapSize);
+        ccfg.setSwapEnabled(swapEnabled);
+
+        ccfg.setEvictionPolicy(new FifoEvictionPolicy(MAX_SIZE));
+
+        cache = grid(0).getOrCreateCache(ccfg);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrids(GRID_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        if (cache != null)
+            cache.destroy();
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testOffHeapMetrics() throws Exception {
+        createCache(CacheMemoryMode.ONHEAP_TIERED, 0, false);
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.put(i, i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0f, cache.metrics().getOffHeapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100f, cache.metrics().getOffHeapMissPercentage());
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapEntriesCount());
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits());
+        assertEquals(100 / 3.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
+        assertEquals(100 - (100 / 3.0), cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.remove(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getOffHeapHits());
+        assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE),
+            cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
+        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE),
+            cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(0, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testSwapMetrics() throws Exception {
+        createCache(CacheMemoryMode.ONHEAP_TIERED, -1, true);
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.put(i, i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapGets());
+        assertEquals(0, cache.metrics().getSwapHits());
+        assertEquals(0f, cache.metrics().getSwapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
+        assertEquals(100f, cache.metrics().getSwapMissPercentage());
+        assertEquals(0, cache.metrics().getSwapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getSwapEntriesCount());
+
+        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
+        assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getSwapEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.remove(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getSwapHits());
+        assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE),
+            cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
+        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE),
+            cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getSwapRemovals());
+
+        assertEquals(0, cache.metrics().getSwapEntriesCount());
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testOffHeapAndSwapMetrics() throws Exception {
+        createCache(CacheMemoryMode.ONHEAP_TIERED, OFFHEAP_MAX_SIZE, true);
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.put(i, i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0f, cache.metrics().getOffHeapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100f, cache.metrics().getOffHeapMissPercentage());
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapGets());
+        assertEquals(0, cache.metrics().getSwapHits());
+        assertEquals(0f, cache.metrics().getSwapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
+        assertEquals(100f, cache.metrics().getSwapMissPercentage());
+        assertEquals(0, cache.metrics().getSwapRemovals());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
+        assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount());
+
+        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapMisses());
+        assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
+        assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.remove(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getOffHeapGets());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapHits());
+        assertEquals(100 * OFFHEAP_MAX_CNT / (KEYS_CNT * 4.0 - MAX_SIZE),
+            cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 4 - OFFHEAP_MAX_CNT - MAX_SIZE, cache.metrics().getOffHeapMisses());
+        assertEquals(100 * (KEYS_CNT * 4 - OFFHEAP_MAX_CNT - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE),
+            cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(0, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 4 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT * 2 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE - OFFHEAP_MAX_CNT) / (KEYS_CNT * 4.0 - MAX_SIZE - OFFHEAP_MAX_CNT),
+            cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
+        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE - OFFHEAP_MAX_CNT),
+            cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(0, cache.metrics().getSwapEntriesCount());
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testOffHeapMetricsInOffHeapTiered() throws Exception {
+        createCache(CacheMemoryMode.OFFHEAP_TIERED, 0, false);
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.put(i, i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0f, cache.metrics().getOffHeapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100f, cache.metrics().getOffHeapMissPercentage());
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapEntriesCount());
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits());
+        assertEquals(100 / 3.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
+        assertEquals(100 - (100 / 3.0), cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.remove(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 4, cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapHits());
+        assertEquals(100 * (KEYS_CNT * 2.0) / (KEYS_CNT * 4.0),
+            cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
+        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0),
+            cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(0, cache.metrics().getOffHeapEvictions());
+        assertEquals(0, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testOffHeapAndSwapMetricsInOffHeapTiered() throws Exception {
+        createCache(CacheMemoryMode.OFFHEAP_TIERED, OFFHEAP_MAX_SIZE, true);
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.put(i, i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0f, cache.metrics().getOffHeapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100f, cache.metrics().getOffHeapMissPercentage());
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(KEYS_CNT - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapGets());
+        assertEquals(0, cache.metrics().getSwapHits());
+        assertEquals(0f, cache.metrics().getSwapHitPercentage());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
+        assertEquals(100f, cache.metrics().getSwapMissPercentage());
+        assertEquals(0, cache.metrics().getSwapRemovals());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses());
+        assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapMisses());
+        assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(KEYS_CNT - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount());
+
+        for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++)
+            cache.get(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets());
+        assertEquals(0, cache.metrics().getOffHeapHits());
+        assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapMisses());
+        assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(0, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT - KEYS_CNT,
+            cache.metrics().getOffHeapEvictions());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
+        assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(KEYS_CNT - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount());
+
+        for (int i = 0; i < KEYS_CNT; i++)
+            cache.remove(i);
+
+        printStat();
+
+        assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapGets());
+        assertEquals(KEYS_CNT * 4, cache.metrics().getOffHeapGets());
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapHits());
+        assertEquals(100 * OFFHEAP_MAX_CNT / (KEYS_CNT * 4.0),
+            cache.metrics().getOffHeapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 4 - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapMisses());
+        assertEquals(100 * (KEYS_CNT * 4 - OFFHEAP_MAX_CNT) / (KEYS_CNT * 4.0),
+            cache.metrics().getOffHeapMissPercentage(), 0.1);
+        assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapRemovals());
+
+        assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT - 2 * KEYS_CNT, cache.metrics().getOffHeapEvictions());
+        assertEquals(0, cache.metrics().getOffHeapEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount());
+        assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount());
+
+        assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts());
+        assertEquals(KEYS_CNT * 4 - OFFHEAP_MAX_CNT, cache.metrics().getSwapGets());
+        assertEquals(KEYS_CNT * 2 - OFFHEAP_MAX_CNT, cache.metrics().getSwapHits());
+        assertEquals(100 * (KEYS_CNT * 2.0 - OFFHEAP_MAX_CNT) / (KEYS_CNT * 4.0 - OFFHEAP_MAX_CNT),
+            cache.metrics().getSwapHitPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses());
+        assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - OFFHEAP_MAX_CNT),
+            cache.metrics().getSwapMissPercentage(), 0.1);
+        assertEquals(KEYS_CNT * 2 - OFFHEAP_MAX_CNT, cache.metrics().getSwapRemovals());
+
+        assertEquals(0, cache.metrics().getSwapEntriesCount());
+    }
+
+    /**
+     * Prints stats.
+     */
+    protected void printStat() {
+        System.out.println("!!! -------------------------------------------------------");
+        System.out.println("!!! Puts: cache = " + cache.metrics().getCachePuts() +
+            ", offheap = " + cache.metrics().getOffHeapPuts() +
+            ", swap = " + cache.metrics().getSwapPuts());
+        System.out.println("!!! Gets: cache = " + cache.metrics().getCacheGets() +
+            ", offheap = " + cache.metrics().getOffHeapGets() +
+            ", swap = " + cache.metrics().getSwapGets());
+        System.out.println("!!! Removes: cache = " + cache.metrics().getCacheRemovals() +
+            ", offheap = " + cache.metrics().getOffHeapRemovals() +
+            ", swap = " + cache.metrics().getSwapRemovals());
+        System.out.println("!!! Evictions: cache = " + cache.metrics().getCacheEvictions() +
+            ", offheap = " + cache.metrics().getOffHeapEvictions() +
+            ", swap = none" );
+        System.out.println("!!! Hits: cache = " + cache.metrics().getCacheHits() +
+            ", offheap = " + cache.metrics().getOffHeapHits() +
+            ", swap = " + cache.metrics().getSwapHits());
+        System.out.println("!!! Hit(%): cache = " + cache.metrics().getCacheHitPercentage() +
+            ", offheap = " + cache.metrics().getOffHeapHitPercentage() +
+            ", swap = " + cache.metrics().getSwapHitPercentage());
+        System.out.println("!!! Misses: cache = " + cache.metrics().getCacheMisses() +
+            ", offheap = " + cache.metrics().getOffHeapMisses() +
+            ", swap = " + cache.metrics().getSwapMisses());
+        System.out.println("!!! Miss(%): cache = " + cache.metrics().getCacheMissPercentage() +
+            ", offheap = " + cache.metrics().getOffHeapMissPercentage() +
+            ", swap = " + cache.metrics().getSwapMissPercentage());
+        System.out.println("!!! Entries: cache = " + cache.metrics().getSize() +
+            ", offheap = " + cache.metrics().getOffHeapEntriesCount() +
+            ", swap = " + cache.metrics().getSwapEntriesCount());
+        System.out.println("!!! Size: cache = none" +
+            ", offheap = " + cache.metrics().getOffHeapAllocatedSize() +
+            ", swap = " + cache.metrics().getSwapSize());
+        System.out.println();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/7533dfc2/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
index 9a64d16..90ecbda 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
@@ -26,7 +26,7 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePar
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheAtomicReplicatedMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedMetricsSelfTest;
-import org.apache.ignite.internal.processors.cache.local.CacheLocalOffHeapAndSwapMetricsSelfTest;
+import org.apache.ignite.internal.processors.cache.local.CacheOffHeapAndSwapMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.local.GridCacheAtomicLocalMetricsNoStoreSelfTest;
 import org.apache.ignite.internal.processors.cache.local.GridCacheAtomicLocalMetricsSelfTest;
 import org.apache.ignite.internal.processors.cache.local.GridCacheAtomicLocalTckMetricsSelfTestImpl;
@@ -48,7 +48,7 @@ public class IgniteCacheMetricsSelfTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheReplicatedMetricsSelfTest.class);
         suite.addTestSuite(GridCachePartitionedMetricsSelfTest.class);
         suite.addTestSuite(GridCachePartitionedHitsAndMissesSelfTest.class);
-        suite.addTestSuite(CacheLocalOffHeapAndSwapMetricsSelfTest.class);
+        suite.addTestSuite(CacheOffHeapAndSwapMetricsSelfTest.class);
 
         // Atomic cache.
         suite.addTestSuite(GridCacheAtomicLocalMetricsSelfTest.class);


[06/17] ignite git commit: reverting review IGNITE-2708 Need to validate that SPIs are started only once (cherry picked from commit bf561e1)

Posted by sb...@apache.org.
reverting review IGNITE-2708 Need to validate that SPIs are started only once
(cherry picked from commit bf561e1)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9639e795
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9639e795
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9639e795

Branch: refs/heads/ignite-3038
Commit: 9639e7956d4bf6fc42e223574851014c8c3aa0cb
Parents: 7ea83d6
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Fri May 13 11:59:02 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:29:21 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java   |  3 --
 .../org/apache/ignite/spi/IgniteSpiAdapter.java | 29 ++------------------
 .../ignite/internal/GridFactorySelfTest.java    | 25 -----------------
 3 files changed, 3 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9639e795/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index 58d64f6..cb41d4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -209,9 +209,6 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
         Collection<String> names = U.newHashSet(spis.length);
 
         for (T spi : spis) {
-            if (spi instanceof IgniteSpiAdapter)
-                ((IgniteSpiAdapter)spi).onBeforeStart();
-
             // Inject all spi resources.
             ctx.resource().inject(spi);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/9639e795/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
index 7cb2e13..999013f 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
@@ -25,7 +25,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-import java.util.concurrent.atomic.AtomicBoolean;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -40,6 +39,7 @@ import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgniteNodeAttributes;
 import org.apache.ignite.internal.managers.communication.GridMessageListener;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
 import org.apache.ignite.internal.processors.timeout.GridSpiTimeoutObject;
 import org.apache.ignite.internal.util.IgniteExceptionRegistry;
 import org.apache.ignite.internal.util.typedef.F;
@@ -96,14 +96,11 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     private boolean failureDetectionTimeoutEnabled = true;
 
     /**
-     * Failure detection timeout. Initialized with the value of
-     * {@link IgniteConfiguration#getFailureDetectionTimeout()}.
+     *  Failure detection timeout. Initialized with the value of
+     *  {@link IgniteConfiguration#getFailureDetectionTimeout()}.
      */
     private long failureDetectionTimeout;
 
-    /** Start flag to deny repeating start attempts. */
-    private final AtomicBoolean startedFlag = new AtomicBoolean();
-
     /**
      * Creates new adapter and initializes it from the current (this) class.
      * SPI name will be initialized to the simple name of the class
@@ -120,26 +117,6 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         startTstamp = U.currentTimeMillis();
     }
 
-    /**
-     * This method is called by built-in managers implementation to avoid
-     * repeating SPI start attempts.
-     */
-    public final void onBeforeStart() {
-        if (!startedFlag.compareAndSet(false, true))
-            throw new IllegalStateException("SPI has already been started " +
-                "(always create new configuration instance for each starting Ignite instances) " +
-                "[spi=" + this + ']');
-    }
-
-    /**
-     * Checks if {@link #onBeforeStart()} has been called on this SPI instance.
-     *
-     * @return {@code True} if {@link #onBeforeStart()} has already been called.
-     */
-    public final boolean started() {
-        return startedFlag.get();
-    }
-
     /** {@inheritDoc} */
     @Override public final String getStartTimestampFormatted() {
         return DateFormat.getDateTimeInstance().format(new Date(startTstamp));

http://git-wip-us.apache.org/repos/asf/ignite/blob/9639e795/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
index b94ed48..539067b 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
@@ -902,31 +902,6 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * @throws Exception If failed.
-     */
-    public void testRepeatingStart() throws Exception {
-        try {
-            IgniteConfiguration c = getConfiguration("1");
-
-            startGrid("1", c);
-
-            assert ((TcpDiscoverySpi)c.getDiscoverySpi()).started();
-
-            try {
-                startGrid("2", c);
-
-                fail("Should not be able to start grid using same configuration instance.");
-            }
-            catch (Exception e) {
-                info("Caught expected exception: " + e);
-            }
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
      * Test task.
      */
     private static class TestTask extends ComputeTaskSplitAdapter<Void, Void> {


[05/17] ignite git commit: review IGNITE-2708 Need to validate that SPIs are started only once (cherry picked from commit cd063da)

Posted by sb...@apache.org.
review IGNITE-2708 Need to validate that SPIs are started only once
(cherry picked from commit cd063da)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7ea83d63
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7ea83d63
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7ea83d63

Branch: refs/heads/ignite-3038
Commit: 7ea83d63a1ada25f4a0b9adcaaa7ab7d3282a4e3
Parents: 8b16e1c
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Fri May 13 11:48:00 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:29:11 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java   |  5 +++-
 .../org/apache/ignite/spi/IgniteSpiAdapter.java | 28 ++++++++++++++++++--
 .../ignite/internal/GridFactorySelfTest.java    | 27 ++++++++++++++++++-
 3 files changed, 56 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7ea83d63/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index 21a80c3..58d64f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -209,6 +209,9 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
         Collection<String> names = U.newHashSet(spis.length);
 
         for (T spi : spis) {
+            if (spi instanceof IgniteSpiAdapter)
+                ((IgniteSpiAdapter)spi).onBeforeStart();
+
             // Inject all spi resources.
             ctx.resource().inject(spi);
 
@@ -629,4 +632,4 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
     @Override public final String toString() {
         return S.toString(GridManagerAdapter.class, this, "name", getClass().getName());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ea83d63/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
index 1cb202c..7cb2e13 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
@@ -25,6 +25,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -95,11 +96,14 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     private boolean failureDetectionTimeoutEnabled = true;
 
     /**
-     *  Failure detection timeout. Initialized with the value of
-     *  {@link IgniteConfiguration#getFailureDetectionTimeout()}.
+     * Failure detection timeout. Initialized with the value of
+     * {@link IgniteConfiguration#getFailureDetectionTimeout()}.
      */
     private long failureDetectionTimeout;
 
+    /** Start flag to deny repeating start attempts. */
+    private final AtomicBoolean startedFlag = new AtomicBoolean();
+
     /**
      * Creates new adapter and initializes it from the current (this) class.
      * SPI name will be initialized to the simple name of the class
@@ -116,6 +120,26 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         startTstamp = U.currentTimeMillis();
     }
 
+    /**
+     * This method is called by built-in managers implementation to avoid
+     * repeating SPI start attempts.
+     */
+    public final void onBeforeStart() {
+        if (!startedFlag.compareAndSet(false, true))
+            throw new IllegalStateException("SPI has already been started " +
+                "(always create new configuration instance for each starting Ignite instances) " +
+                "[spi=" + this + ']');
+    }
+
+    /**
+     * Checks if {@link #onBeforeStart()} has been called on this SPI instance.
+     *
+     * @return {@code True} if {@link #onBeforeStart()} has already been called.
+     */
+    public final boolean started() {
+        return startedFlag.get();
+    }
+
     /** {@inheritDoc} */
     @Override public final String getStartTimestampFormatted() {
         return DateFormat.getDateTimeInstance().format(new Date(startTstamp));

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ea83d63/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
index cca3e8b..b94ed48 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
@@ -902,6 +902,31 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testRepeatingStart() throws Exception {
+        try {
+            IgniteConfiguration c = getConfiguration("1");
+
+            startGrid("1", c);
+
+            assert ((TcpDiscoverySpi)c.getDiscoverySpi()).started();
+
+            try {
+                startGrid("2", c);
+
+                fail("Should not be able to start grid using same configuration instance.");
+            }
+            catch (Exception e) {
+                info("Caught expected exception: " + e);
+            }
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
      * Test task.
      */
     private static class TestTask extends ComputeTaskSplitAdapter<Void, Void> {
@@ -930,4 +955,4 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
             return null;
         }
     }
-}
\ No newline at end of file
+}


[08/17] ignite git commit: review IGNITE-2708 Need to validate that SPIs are started only once (added logic to protect properly started grids) (cherry picked from commit b8d624a)

Posted by sb...@apache.org.
review IGNITE-2708 Need to validate that SPIs are started only once (added logic to protect properly started grids)
(cherry picked from commit b8d624a)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/52e2f71a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/52e2f71a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/52e2f71a

Branch: refs/heads/ignite-3038
Commit: 52e2f71a6d57cd4f60582e59ad1660b2baec6f74
Parents: c5019c6
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Fri May 13 12:54:01 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:32:49 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java      | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/52e2f71a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index 58d64f6..a09047b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -19,6 +19,8 @@ package org.apache.ignite.internal.managers;
 
 import java.io.Serializable;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.IdentityHashMap;
 import java.util.Map;
 import java.util.UUID;
 import javax.cache.expiry.Duration;
@@ -84,6 +86,9 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
     /** Checks is SPI implementation is {@code NO-OP} or not. */
     private final boolean enabled;
 
+    /** */
+    private final Map<IgniteSpi, Boolean> spiMap = new IdentityHashMap<>();
+
     /**
      * @param ctx Kernal context.
      * @param spis Specific SPI instance.
@@ -212,6 +217,11 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
             if (spi instanceof IgniteSpiAdapter)
                 ((IgniteSpiAdapter)spi).onBeforeStart();
 
+            // Save SPI to map to make sure to stop it properly.
+            Boolean res = spiMap.put(spi, Boolean.TRUE);
+
+            assert res == null;
+
             // Inject all spi resources.
             ctx.resource().inject(spi);
 
@@ -275,6 +285,13 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
      */
     protected final void stopSpi() throws IgniteCheckedException {
         for (T spi : spis) {
+            if (spiMap.remove(spi) == null) {
+                if (log.isDebugEnabled())
+                    log.debug("Will not stop SPI since it has not been started by this manager: " + spi);
+
+                continue;
+            }
+
             if (log.isDebugEnabled())
                 log.debug("Stopping SPI: " + spi);
 


[15/17] ignite git commit: Added pacajge info for java.org.apache.ignite.hadoop.util package.

Posted by sb...@apache.org.
Added pacajge info for java.org.apache.ignite.hadoop.util package.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b28e7a84
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b28e7a84
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b28e7a84

Branch: refs/heads/ignite-3038
Commit: b28e7a84e617ef87844a7b2d7543ad822c4b0ece
Parents: fcea72d
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue May 31 13:54:32 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue May 31 13:54:32 2016 +0300

----------------------------------------------------------------------
 .../apache/ignite/hadoop/util/package-info.java | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b28e7a84/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/package-info.java b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/package-info.java
new file mode 100644
index 0000000..d84c0ba
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Ignite Hadoop Accelerator utility classes.
+ */
+package org.apache.ignite.hadoop.util;
\ No newline at end of file


[04/17] ignite git commit: IGNITE-3188: Binary marshaller doesn't unmarshal a void type (added tests)

Posted by sb...@apache.org.
IGNITE-3188: Binary marshaller doesn't unmarshal a void type (added tests)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8b16e1c3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8b16e1c3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8b16e1c3

Branch: refs/heads/ignite-3038
Commit: 8b16e1c3f765ca57d4f2ff354afbf095bf3aebbf
Parents: f487874
Author: Denis Magda <dm...@gridgain.com>
Authored: Thu May 26 14:57:52 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:27:41 2016 +0300

----------------------------------------------------------------------
 .../binary/BinaryMarshallerSelfTest.java        | 15 ++++++++
 .../CacheKeepBinaryWithInterceptorTest.java     | 36 ++++++++++----------
 2 files changed, 33 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8b16e1c3/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index c02d823..a504650 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -840,6 +840,21 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testVoid() throws Exception {
+        Class clazz = Void.class;
+
+        assertEquals(clazz, marshalUnmarshal(clazz));
+
+        clazz = Void.TYPE;
+
+        assertEquals(clazz, marshalUnmarshal(clazz));
+    }
+
+
+
+    /**
      *
      */
     private static class EnclosingObj implements Serializable {

http://git-wip-us.apache.org/repos/asf/ignite/blob/8b16e1c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
index 60b48a8..74b8659 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/CacheKeepBinaryWithInterceptorTest.java
@@ -110,23 +110,23 @@ public class CacheKeepBinaryWithInterceptorTest extends GridCommonAbstractTest {
             cache.put(new TestKey(1), new TestValue(10));
 
             BinaryObject obj = (BinaryObject)cache.get(new TestKey(1));
-            assertEquals(10, obj.field("val"));
+            assertEquals(10, (int)obj.field("val"));
 
             asyncCache.get(new TestKey(1));
             obj = (BinaryObject)asyncCache.future().get();
-            assertEquals(10, obj.field("val"));
+            assertEquals(10, (int)obj.field("val"));
 
             Cache.Entry<BinaryObject, BinaryObject> e = (Cache.Entry)cache.getEntry(new TestKey(1));
-            assertEquals(1, e.getKey().field("key"));
-            assertEquals(10, e.getValue().field("val"));
+            assertEquals(1, (int)e.getKey().field("key"));
+            assertEquals(10, (int)e.getValue().field("val"));
 
             asyncCache.getEntry(new TestKey(1));
             e = (Cache.Entry)asyncCache.future().get();
-            assertEquals(1, e.getKey().field("key"));
-            assertEquals(10, e.getValue().field("val"));
+            assertEquals(1, (int)e.getKey().field("key"));
+            assertEquals(10, (int)e.getValue().field("val"));
 
             obj = (BinaryObject)cache.getAndRemove(new TestKey(1));
-            assertEquals(10, obj.field("val"));
+            assertEquals(10, (int)obj.field("val"));
 
             cache.put(new TestKey(1), new TestValue(10));
 
@@ -239,8 +239,8 @@ public class CacheKeepBinaryWithInterceptorTest extends GridCommonAbstractTest {
 
             onGet++;
 
-            assertEquals(1, key.field("key"));
-            assertEquals(10, val.field("val"));
+            assertEquals(1, (int)key.field("key"));
+            assertEquals(10, (int)val.field("val"));
 
             return val;
         }
@@ -252,10 +252,10 @@ public class CacheKeepBinaryWithInterceptorTest extends GridCommonAbstractTest {
             onBeforePut++;
 
             if (entry.getValue() != null)
-                assertEquals(10, entry.getValue().field("val"));
+                assertEquals(10, (int)entry.getValue().field("val"));
 
-            assertEquals(1, entry.getKey().field("key"));
-            assertEquals(10, newVal.field("val"));
+            assertEquals(1, (int)entry.getKey().field("key"));
+            assertEquals(10, (int)newVal.field("val"));
 
             return newVal;
         }
@@ -266,14 +266,14 @@ public class CacheKeepBinaryWithInterceptorTest extends GridCommonAbstractTest {
 
             onAfterPut++;
 
-            assertEquals(1, entry.getKey().field("key"));
-            assertEquals(10, entry.getValue().field("val"));
+            assertEquals(1, (int)entry.getKey().field("key"));
+            assertEquals(10, (int)entry.getValue().field("val"));
         }
 
         /** {@inheritDoc} */
         @Nullable @Override public IgniteBiTuple<Boolean, BinaryObject> onBeforeRemove(Cache.Entry<BinaryObject, BinaryObject> entry) {
-            assertEquals(1, entry.getKey().field("key"));
-            assertEquals(10, entry.getValue().field("val"));
+            assertEquals(1, (int)entry.getKey().field("key"));
+            assertEquals(10, (int)entry.getValue().field("val"));
 
             onBeforeRmv++;
 
@@ -286,8 +286,8 @@ public class CacheKeepBinaryWithInterceptorTest extends GridCommonAbstractTest {
 
             onAfterRmv++;
 
-            assertEquals(1, entry.getKey().field("key"));
-            assertEquals(10, entry.getValue().field("val"));
+            assertEquals(1, (int)entry.getKey().field("key"));
+            assertEquals(10, (int)entry.getValue().field("val"));
         }
     }
 


[13/17] ignite git commit: IGNITE-2708: fix tests that don't create unique IndexingSPI per node

Posted by sb...@apache.org.
IGNITE-2708: fix tests that don't create unique IndexingSPI per node


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f90e424d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f90e424d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f90e424d

Branch: refs/heads/ignite-3038
Commit: f90e424de6d482eafa64cd24ffb9edfd7911856d
Parents: 14403bb
Author: Denis Magda <dm...@gridgain.com>
Authored: Tue May 31 13:50:06 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 13:50:06 2016 +0300

----------------------------------------------------------------------
 .../IgniteTxExceptionAbstractSelfTest.java      | 43 ++++++++++++--------
 1 file changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f90e424d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxExceptionAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxExceptionAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxExceptionAbstractSelfTest.java
index 4826c68..c867d52 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxExceptionAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxExceptionAbstractSelfTest.java
@@ -28,6 +28,7 @@ import javax.cache.processor.EntryProcessor;
 import javax.cache.processor.MutableEntry;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -54,9 +55,6 @@ import static org.apache.ignite.cache.CacheMode.REPLICATED;
  * Tests that transaction is invalidated in case of {@link IgniteTxHeuristicCheckedException}.
  */
 public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstractSelfTest {
-    /** Index SPI throwing exception. */
-    private static TestIndexingSpi idxSpi = new TestIndexingSpi();
-
     /** */
     private static final int PRIMARY = 0;
 
@@ -78,7 +76,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        cfg.setIndexingSpi(idxSpi);
+        cfg.setIndexingSpi(new TestIndexingSpi());
 
         cfg.getTransactionConfiguration().setTxSerializableEnabled(true);
 
@@ -108,7 +106,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
 
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
-        idxSpi.forceFail(false);
+        failIndexingSpi(false);
 
         Transaction tx = jcache().unwrap(Ignite.class).transactions().tx();
 
@@ -321,7 +319,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
         IgniteCache<Integer, Integer> cache = grid(0).cache(null);
 
         if (putBefore) {
-            idxSpi.forceFail(false);
+            failIndexingSpi(false);
 
             info("Start transaction.");
 
@@ -344,7 +342,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
                 grid(i).cache(null).get(key);
         }
 
-        idxSpi.forceFail(true);
+        failIndexingSpi(true);
 
         try {
             info("Start transaction.");
@@ -380,7 +378,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
      */
     @SuppressWarnings("unchecked")
     private void checkUnlocked(final Integer key) throws Exception {
-        idxSpi.forceFail(false);
+        failIndexingSpi(false);
 
         awaitPartitionMapExchange();
 
@@ -448,7 +446,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
      */
     private void checkPut(boolean putBefore, final Integer key) throws Exception {
         if (putBefore) {
-            idxSpi.forceFail(false);
+            failIndexingSpi(false);
 
             info("Put key: " + key);
 
@@ -459,7 +457,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
         for (int i = 0; i < gridCount(); i++)
             grid(i).cache(null).get(key);
 
-        idxSpi.forceFail(true);
+        failIndexingSpi(true);
 
         info("Going to put: " + key);
 
@@ -481,7 +479,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
      */
     private void checkTransform(boolean putBefore, final Integer key) throws Exception {
         if (putBefore) {
-            idxSpi.forceFail(false);
+            failIndexingSpi(false);
 
             info("Put key: " + key);
 
@@ -492,7 +490,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
         for (int i = 0; i < gridCount(); i++)
             grid(i).cache(null).get(key);
 
-        idxSpi.forceFail(true);
+        failIndexingSpi(true);
 
         info("Going to transform: " + key);
 
@@ -524,7 +522,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
         assert keys.length > 1;
 
         if (putBefore) {
-            idxSpi.forceFail(false);
+            failIndexingSpi(false);
 
             Map<Integer, Integer> m = new HashMap<>();
 
@@ -542,7 +540,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
                 grid(i).cache(null).get(key);
         }
 
-        idxSpi.forceFail(true);
+        failIndexingSpi(true);
 
         final Map<Integer, Integer> m = new HashMap<>();
 
@@ -570,7 +568,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
      */
     private void checkRemove(boolean putBefore, final Integer key) throws Exception {
         if (putBefore) {
-            idxSpi.forceFail(false);
+            failIndexingSpi(false);
 
             info("Put key: " + key);
 
@@ -581,7 +579,7 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
         for (int i = 0; i < gridCount(); i++)
             grid(i).cache(null).get(key);
 
-        idxSpi.forceFail(true);
+        failIndexingSpi(true);
 
         info("Going to remove: " + key);
 
@@ -653,6 +651,19 @@ public abstract class IgniteTxExceptionAbstractSelfTest extends GridCacheAbstrac
     }
 
     /**
+     * Controls indexing SPI behavior.
+     *
+     * @param fail fail the SPI or not.
+     */
+    private void failIndexingSpi(boolean fail) {
+        for (Ignite ignite : Ignition.allGrids()) {
+            TestIndexingSpi idxSpi = (TestIndexingSpi)ignite.configuration().getIndexingSpi();
+
+            idxSpi.forceFail(fail);
+        }
+    }
+
+    /**
      * Indexing SPI that can fail on demand.
      */
     private static class TestIndexingSpi extends IgniteSpiAdapter implements IndexingSpi {


[09/17] ignite git commit: review IGNITE-2708 Need to validate that SPIs are started only once (added logic to protect properly started grids) (cherry picked from commit b8d624a)

Posted by sb...@apache.org.
review IGNITE-2708 Need to validate that SPIs are started only once (added logic to protect properly started grids)
(cherry picked from commit b8d624a)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/31775629
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/31775629
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/31775629

Branch: refs/heads/ignite-3038
Commit: 317756294f3d792da58ca72ab17656979cb8f9cf
Parents: 52e2f71
Author: Denis Magda <dm...@gridgain.com>
Authored: Tue May 31 09:33:22 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:33:22 2016 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/internal/managers/GridManagerAdapter.java     | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/31775629/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index a09047b..50662c7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.managers;
 
 import java.io.Serializable;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.IdentityHashMap;
 import java.util.Map;
 import java.util.UUID;


[02/17] ignite git commit: IGNITE-3183 ScanQuery and localEntries are ignored keepBinary flag in OFFHEAP_TIERED mode

Posted by sb...@apache.org.
IGNITE-3183 ScanQuery and localEntries are ignored keepBinary flag in OFFHEAP_TIERED mode


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/30ca35ba
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/30ca35ba
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/30ca35ba

Branch: refs/heads/ignite-3038
Commit: 30ca35ba87eb78e508eb8ba5c8f070dae6d945c2
Parents: eade513
Author: Anton Vinogradov <av...@apache.org>
Authored: Fri May 27 19:51:45 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Fri May 27 19:51:45 2016 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      |  12 +-
 .../processors/cache/GridCacheContext.java      |   5 +-
 .../processors/cache/GridCacheSwapManager.java  |  67 ++-
 .../distributed/dht/GridDhtCacheAdapter.java    |   9 +-
 .../cache/query/GridCacheQueryManager.java      |   9 +-
 .../cache/IgniteCachePeekModesAbstractTest.java |   8 +-
 ...CacheKeepBinaryIterationNearEnabledTest.java |  44 ++
 ...acheKeepBinaryIterationStoreEnabledTest.java |  90 ++++
 ...CacheKeepBinaryIterationSwapEnabledTest.java |  56 +++
 .../CacheKeepBinaryIterationTest.java           | 471 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite3.java         |   8 +
 11 files changed, 737 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 29ca32c..6ccb506 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -677,12 +677,14 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         Collection<Iterator<Cache.Entry<K, V>>> its = new ArrayList<>();
 
+        final boolean keepBinary = ctx.keepBinary();
+
         if (ctx.isLocal()) {
             modes.primary = true;
             modes.backup = true;
 
             if (modes.heap)
-                its.add(iterator(map.entries0().iterator(), !ctx.keepBinary()));
+                its.add(iterator(map.entries0().iterator(), !keepBinary));
         }
         else if (modes.heap) {
             if (modes.near && ctx.isNear())
@@ -691,7 +693,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             if (modes.primary || modes.backup) {
                 GridDhtCacheAdapter<K, V> cache = ctx.isNear() ? ctx.near().dht() : ctx.dht();
 
-                its.add(cache.localEntriesIterator(modes.primary, modes.backup));
+                its.add(cache.localEntriesIterator(modes.primary, modes.backup, keepBinary));
             }
         }
 
@@ -702,10 +704,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
 
             if (modes.swap)
-                its.add(swapMgr.<K, V>swapIterator(modes.primary, modes.backup, topVer));
+                its.add(swapMgr.<K, V>swapIterator(modes.primary, modes.backup, topVer, keepBinary));
 
             if (modes.offheap)
-                its.add(swapMgr.<K, V>offheapIterator(modes.primary, modes.backup, topVer));
+                its.add(swapMgr.<K, V>offheapIterator(modes.primary, modes.backup, topVer, keepBinary));
         }
 
         final Iterator<Cache.Entry<K, V>> it = F.flatIterators(its);
@@ -3932,7 +3934,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             Iterator<Cache.Entry<K, V>> it;
 
             try {
-                it = ctx.swap().offheapIterator(true, true, ctx.affinity().affinityTopologyVersion());
+                it = ctx.swap().offheapIterator(true, true, ctx.affinity().affinityTopologyVersion(), ctx.keepBinary());
             }
             catch (IgniteCheckedException e) {
                 throw CU.convertToCacheException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index 5729959..b7c8592 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1712,14 +1712,15 @@ public class GridCacheContext<K, V> implements Externalizable {
      * @return {@code True} if OFFHEAP_TIERED memory mode is enabled.
      */
     public boolean offheapTiered() {
-        return cacheCfg.getMemoryMode() == OFFHEAP_TIERED && isOffHeapEnabled();
+        return cacheCfg != null && cacheCfg.getMemoryMode() == OFFHEAP_TIERED && isOffHeapEnabled();
     }
 
     /**
      * @return {@code True} if should use entry with offheap value pointer.
      */
     public boolean useOffheapEntry() {
-        return cacheCfg.getMemoryMode() == OFFHEAP_TIERED || cacheCfg.getMemoryMode() == OFFHEAP_VALUES;
+        return cacheCfg != null &&
+            (cacheCfg.getMemoryMode() == OFFHEAP_TIERED || cacheCfg.getMemoryMode() == OFFHEAP_VALUES);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 1f70374..001d4a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -1604,14 +1604,15 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
     }
 
     /**
+     * @param keepBinary Keep binary flag.
      * @return Lazy swap iterator.
      * @throws IgniteCheckedException If failed.
      */
-    public <K, V> Iterator<Map.Entry<K, V>> lazySwapIterator() throws IgniteCheckedException {
+    public <K, V> Iterator<Map.Entry<K, V>> lazySwapIterator(boolean keepBinary) throws IgniteCheckedException {
         if (!swapEnabled)
             return new GridEmptyIterator<>();
 
-        return lazyIterator(cctx.gridSwap().rawIterator(spaceName));
+        return lazyIterator(cctx.gridSwap().rawIterator(spaceName), keepBinary);
     }
 
     /**
@@ -1664,13 +1665,14 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
     }
 
     /**
+     * @param keepBinary Keep binary flag.
      * @return Lazy off-heap iterator.
      */
-    public <K, V> Iterator<Map.Entry<K, V>> lazyOffHeapIterator() {
+    public <K, V> Iterator<Map.Entry<K, V>> lazyOffHeapIterator(boolean keepBinary) {
         if (!offheapEnabled)
             return new GridEmptyCloseableIterator<>();
 
-        return lazyIterator(offheap.iterator(spaceName));
+        return lazyIterator(offheap.iterator(spaceName), keepBinary);
     }
 
     /**
@@ -1695,10 +1697,11 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
      * Gets lazy iterator for which key and value are lazily deserialized.
      *
      * @param it Closeable iterator.
+     * @param keepBinary Keep binary.
      * @return Lazy iterator.
      */
     private <K, V> Iterator<Map.Entry<K, V>> lazyIterator(
-        final GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> it) {
+        final GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> it, final boolean keepBinary) {
         if (it == null)
             return new GridEmptyIterator<>();
 
@@ -1711,7 +1714,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             @Override protected Map.Entry<K, V> onNext() {
                 final Map.Entry<byte[], byte[]> cur0 = it.next();
 
-                cur = new GridVersionedMapEntry<K, V>(cur0);
+                cur = new GridVersionedMapEntry<K, V>(cur0, keepBinary);
 
                 return cur;
             }
@@ -2040,11 +2043,14 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
      * @param primary If {@code true} includes primary entries.
      * @param backup If {@code true} includes backup entries.
      * @param topVer Topology version.
+     * @param keepBinary Keep binary flag.
      * @return Swap entries iterator.
      * @throws IgniteCheckedException If failed.
      */
-    public <K, V> Iterator<Cache.Entry<K, V>> swapIterator(boolean primary, boolean backup, AffinityTopologyVersion topVer)
-        throws IgniteCheckedException
+    public <K, V> Iterator<Cache.Entry<K, V>> swapIterator(boolean primary,
+        boolean backup,
+        AffinityTopologyVersion topVer,
+        boolean keepBinary) throws IgniteCheckedException
     {
         assert primary || backup;
 
@@ -2052,12 +2058,12 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             return F.emptyIterator();
 
         if (primary && backup)
-            return cacheEntryIterator(this.<K, V>lazySwapIterator());
+            return cacheEntryIterator(this.<K, V>lazySwapIterator(keepBinary));
 
         Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) :
             cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
 
-        return new PartitionsIterator<K, V>(parts) {
+        return new PartitionsIterator<K, V>(parts, keepBinary) {
             @Override protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> nextPartition(int part)
                 throws IgniteCheckedException
             {
@@ -2070,12 +2076,14 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
      * @param primary If {@code true} includes primary entries.
      * @param backup If {@code true} includes backup entries.
      * @param topVer Topology version.
+     * @param keepBinary Keep binary flag.
      * @return Offheap entries iterator.
      * @throws IgniteCheckedException If failed.
      */
     public <K, V> Iterator<Cache.Entry<K, V>> offheapIterator(boolean primary,
         boolean backup,
-        AffinityTopologyVersion topVer)
+        AffinityTopologyVersion topVer,
+        boolean keepBinary)
         throws IgniteCheckedException
     {
         assert primary || backup;
@@ -2084,12 +2092,12 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             return F.emptyIterator();
 
         if (primary && backup)
-            return cacheEntryIterator(this.<K, V>lazyOffHeapIterator());
+            return cacheEntryIterator(this.<K, V>lazyOffHeapIterator(keepBinary));
 
         Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) :
             cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
 
-        return new PartitionsIterator<K, V>(parts) {
+        return new PartitionsIterator<K, V>(parts, keepBinary) {
             @Override protected GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> nextPartition(int part) {
                 return offheap.iterator(spaceName, part);
             }
@@ -2311,17 +2319,25 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
      *
      */
     private abstract class PartitionsIterator<K, V> extends PartitionsAbstractIterator<Cache.Entry<K, V>> {
+        /** */
+        private final boolean keepBinary;
+
         /**
          * @param parts Partitions
+         * @param keepBinary Keep binary flag.
          */
-        public PartitionsIterator(Collection<Integer> parts) {
+        public PartitionsIterator(Collection<Integer> parts, boolean keepBinary) {
             super(parts);
+
+            this.keepBinary = keepBinary;
+
+            advance();
         }
 
         /** {@inheritDoc} */
         @Override protected Iterator<Cache.Entry<K, V>> partitionIterator(int part)
             throws IgniteCheckedException {
-            return cacheEntryIterator(GridCacheSwapManager.this.<K, V>lazyIterator(nextPartition(part)));
+            return cacheEntryIterator(GridCacheSwapManager.this.<K, V>lazyIterator(nextPartition(part), keepBinary));
         }
 
         /**
@@ -2347,12 +2363,10 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         private T next;
 
         /**
-         * @param parts Partitions
+         * @param parts Partitions.
          */
         public PartitionsAbstractIterator(Collection<Integer> parts) {
             this.partIt = parts.iterator();
-
-            advance();
         }
 
         /** {@inheritDoc} */
@@ -2380,7 +2394,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         /**
          * Switches to next element.
          */
-        private void advance() {
+        protected final void advance() {
             next = null;
 
             do {
@@ -2524,23 +2538,26 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
      */
     private class GridVersionedMapEntry<K,V> implements Map.Entry<K,V>, GridCacheVersionAware {
         /** */
-        private Map.Entry<byte[], byte[]> entry;
+        final private Map.Entry<byte[], byte[]> entry;
+
+        /** */
+        final private boolean keepBinary;
 
         /**
          * Constructor.
          *
          * @param entry Entry.
+         * @param keepBinary Keep binary.
          */
-        public GridVersionedMapEntry(Map.Entry<byte[], byte[]> entry) {
+        public GridVersionedMapEntry(Map.Entry<byte[], byte[]> entry, boolean keepBinary) {
             this.entry = entry;
+            this.keepBinary = keepBinary;
         }
 
         /** {@inheritDoc} */
         @Override public K getKey() {
             try {
-                KeyCacheObject key = cctx.toCacheKeyObject(entry.getKey());
-
-                return key.value(cctx.cacheObjectContext(), false);
+                return (K)cctx.unwrapBinaryIfNeeded(cctx.toCacheKeyObject(entry.getKey()), keepBinary);
             }
             catch (IgniteCheckedException e) {
                 throw new IgniteException(e);
@@ -2554,7 +2571,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                 assert e != null;
 
-                return e.value().value(cctx.cacheObjectContext(), false);
+                return (V)cctx.unwrapBinaryIfNeeded(e.value(), keepBinary);
             }
             catch (IgniteCheckedException ex) {
                 throw new IgniteException(ex);

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
index a74cf26..5cc079d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
@@ -1174,13 +1174,16 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
     /**
      * @param primary If {@code true} includes primary entries.
      * @param backup If {@code true} includes backup entries.
+     * @param keepBinary Keep binary flag.
      * @return Local entries iterator.
      */
-    public Iterator<Cache.Entry<K, V>> localEntriesIterator(final boolean primary, final boolean backup) {
+    public Iterator<Cache.Entry<K, V>> localEntriesIterator(final boolean primary,
+        final boolean backup,
+        final boolean keepBinary) {
         assert primary || backup;
 
         if (primary && backup)
-            return iterator(map.entries0().iterator(), !ctx.keepBinary());
+            return iterator(map.entries0().iterator(), !keepBinary);
         else {
             final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
 
@@ -1244,7 +1247,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
                 }
             };
 
-            return iterator(it, !ctx.keepBinary());
+            return iterator(it, !keepBinary);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index 3b3c5f6..d376df5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -976,7 +976,9 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
             if (locNode && plc == null && !cctx.isLocal()) {
                 GridDhtCacheAdapter<K, V> cache = cctx.isNear() ? cctx.near().dht() : cctx.dht();
 
-                final Iterator<Cache.Entry<K, V>> iter = cache.localEntriesIterator(true, backups);
+                final Iterator<Cache.Entry<K, V>> iter = cache.localEntriesIterator(true,
+                    backups,
+                    cache.context().keepBinary());
 
                 return new GridIteratorAdapter<IgniteBiTuple<K, V>>() {
                     /** */
@@ -1156,8 +1158,9 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                     K key = e.key();
                     V val = e.value();
 
+                    key = (K)cctx.unwrapBinaryIfNeeded(key, keepBinary);
+
                     if (filter != null || locNode) {
-                        key = (K)cctx.unwrapBinaryIfNeeded(key, keepBinary);
                         val = (V)cctx.unwrapBinaryIfNeeded(val, keepBinary);
                     }
 
@@ -2668,7 +2671,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
                 if (key != null)
                     return key;
 
-                key = cctx.toCacheKeyObject(keyBytes()).value(cctx.cacheObjectContext(), false);
+                key = (K)cctx.toCacheKeyObject(keyBytes());
 
                 return key;
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
index 056affc..c27cccb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
@@ -292,9 +292,9 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
             Iterator<Map.Entry<Integer, String>> offheapIt;
 
             if (internalCache.context().isNear())
-                offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator();
+                offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(false);
             else
-                offheapIt = internalCache.context().swap().lazyOffHeapIterator();
+                offheapIt = internalCache.context().swap().lazyOffHeapIterator(false);
 
             while (offheapIt.hasNext()) {
                 Map.Entry<Integer, String> e = offheapIt.next();
@@ -704,9 +704,9 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
         Iterator<Map.Entry<Integer, String>> offheapIt;
 
         if (internalCache.context().isNear())
-            offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator();
+            offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(false);
         else
-            offheapIt = internalCache.context().swap().lazyOffHeapIterator();
+            offheapIt = internalCache.context().swap().lazyOffHeapIterator(false);
 
         Affinity aff = ignite(nodeIdx).affinity(null);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationNearEnabledTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationNearEnabledTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationNearEnabledTest.java
new file mode 100644
index 0000000..02d72b8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationNearEnabledTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.processors.cache.query.continuous;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+
+/**
+ *
+ */
+public class CacheKeepBinaryIterationNearEnabledTest extends CacheKeepBinaryIterationTest {
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheMemoryMode memoryMode) {
+        CacheConfiguration<Object, Object> ccfg =
+            super.cacheConfiguration(cacheMode, backups, atomicityMode, memoryMode);
+
+        ccfg.setNearConfiguration(new NearCacheConfiguration<>());
+
+        return ccfg;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationStoreEnabledTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationStoreEnabledTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationStoreEnabledTest.java
new file mode 100644
index 0000000..f345611
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationStoreEnabledTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.processors.cache.query.continuous;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+
+/**
+ *
+ */
+public class CacheKeepBinaryIterationStoreEnabledTest extends CacheKeepBinaryIterationTest {
+    /** Cache store. */
+    private static TestStore store = new TestStore();
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheMemoryMode memoryMode) {
+        CacheConfiguration<Object, Object> ccfg =
+            super.cacheConfiguration(cacheMode, backups, atomicityMode, memoryMode);
+
+        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+
+        ccfg.setCacheStoreFactory(singletonFactory(store));
+        ccfg.setReadThrough(true);
+        ccfg.setWriteThrough(true);
+        ccfg.setLoadPreviousValue(true);
+
+        return ccfg;
+    }
+
+    /**
+     *
+     */
+    private static class TestStore extends CacheStoreAdapter<Object, Object> {
+        /** Map. */
+        private ConcurrentMap<Object, Object> map = new ConcurrentHashMap<>();
+
+        /**
+         * @param key Key.
+         * @return Value.
+         */
+        Object value(Object key) {
+            return map.get(key);
+        }
+
+        /** @return {@code True} if empty. */
+        boolean isEmpty() {
+            return map.isEmpty();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object load(Object key) {
+            return map.get(key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(javax.cache.Cache.Entry<? extends Object, ? extends Object> e) {
+            map.put(e.getKey(), e.getValue());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object key) {
+            map.remove(key);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationSwapEnabledTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationSwapEnabledTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationSwapEnabledTest.java
new file mode 100644
index 0000000..fe619c4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationSwapEnabledTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.processors.cache.query.continuous;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.eviction.lru.LruEvictionPolicy;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi;
+
+/**
+ *
+ */
+public class CacheKeepBinaryIterationSwapEnabledTest extends CacheKeepBinaryIterationTest {
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheMemoryMode memoryMode) {
+        CacheConfiguration<Object, Object> ccfg =
+            super.cacheConfiguration(cacheMode, backups, atomicityMode, memoryMode);
+
+        ccfg.setSwapEnabled(true);
+        ccfg.setOffHeapMaxMemory(1000);
+        ccfg.setEvictionPolicy(new LruEvictionPolicy(10));
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
new file mode 100644
index 0000000..a775d21
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheKeepBinaryIterationTest.java
@@ -0,0 +1,471 @@
+/*
+ * 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.processors.cache.query.continuous;
+
+import java.io.Serializable;
+import javax.cache.Cache;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.config.GridTestProperties;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class CacheKeepBinaryIterationTest extends GridCommonAbstractTest {
+    /** */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int NODES = 3;
+
+    /** */
+    private static final int KEYS = 1025;
+
+    static {
+        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+        ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGridsMultiThreaded(getServerNodeCount());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOnHeap() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            ATOMIC,
+            ONHEAP_TIERED
+        );
+
+        doTestScanQuery(ccfg, true, true);
+        doTestScanQuery(ccfg, true, false);
+        doTestScanQuery(ccfg, false, true);
+        doTestScanQuery(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffHeap() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            ATOMIC,
+            OFFHEAP_TIERED
+        );
+
+        doTestScanQuery(ccfg, true, true);
+        doTestScanQuery(ccfg, true, false);
+        doTestScanQuery(ccfg, false, true);
+        doTestScanQuery(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnHeap() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            TRANSACTIONAL,
+            ONHEAP_TIERED
+        );
+
+        doTestScanQuery(ccfg, true, true);
+        doTestScanQuery(ccfg, true, false);
+        doTestScanQuery(ccfg, false, true);
+        doTestScanQuery(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOffHeap() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            TRANSACTIONAL,
+            OFFHEAP_TIERED
+        );
+
+        doTestScanQuery(ccfg, true, true);
+        doTestScanQuery(ccfg, true, false);
+        doTestScanQuery(ccfg, false, true);
+        doTestScanQuery(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOnHeapLocalEntries() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            ATOMIC,
+            ONHEAP_TIERED
+        );
+
+        doTestLocalEntries(ccfg, true, true);
+        doTestLocalEntries(ccfg, true, false);
+        doTestLocalEntries(ccfg, false, true);
+        doTestLocalEntries(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffHeapLocalEntries() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            ATOMIC,
+            OFFHEAP_TIERED
+        );
+
+        doTestLocalEntries(ccfg, true, true);
+        doTestLocalEntries(ccfg, true, false);
+        doTestLocalEntries(ccfg, false, true);
+        doTestLocalEntries(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnHeapLocalEntries() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            TRANSACTIONAL,
+            ONHEAP_TIERED
+        );
+
+        doTestLocalEntries(ccfg, true, true);
+        doTestLocalEntries(ccfg, true, false);
+        doTestLocalEntries(ccfg, false, true);
+        doTestLocalEntries(ccfg, false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOffHeapLocalEntries() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED,
+            1,
+            TRANSACTIONAL,
+            OFFHEAP_TIERED
+        );
+
+        doTestLocalEntries(ccfg, true, true);
+        doTestLocalEntries(ccfg, true, false);
+        doTestLocalEntries(ccfg, false, true);
+        doTestLocalEntries(ccfg, false, false);
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     */
+    private void doTestScanQuery(CacheConfiguration<Object, Object> ccfg, boolean keepBinary,
+        boolean primitives) throws IgniteInterruptedCheckedException {
+        IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
+
+        assertTrue(cache.size() == 0);
+
+        try {
+            for (int i = 0; i < KEYS; i++)
+                if (primitives)
+                    cache.put(i, i);
+                else
+                    cache.put(new QueryTestKey(i), new QueryTestValue(i));
+
+            for (int i = 0; i < getServerNodeCount(); i++) {
+                IgniteCache<Object, Object> cache0 = grid(i).cache(ccfg.getName());
+
+                if (keepBinary)
+                    cache0 = cache0.withKeepBinary();
+
+                ScanQuery<Object, Object> qry = new ScanQuery<>();
+
+                qry.setLocal(true);
+
+                int size = 0;
+
+                try (QueryCursor<Cache.Entry<Object, Object>> cur = cache0.query(qry)) {
+                    for (Cache.Entry<Object, Object> e : cur) {
+                        Object key = e.getKey();
+                        Object val = e.getValue();
+
+                        if (!primitives) {
+                            assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary,
+                                keepBinary == key instanceof BinaryObject);
+                            assertTrue("Got unexpected object: " + val.getClass() + ", keepBinary: " + keepBinary,
+                                keepBinary == val instanceof BinaryObject);
+                        }
+                        else {
+                            assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary,
+                                key instanceof Integer);
+                            assertTrue("Got unexpected object: " + val.getClass() + ", keepBinary: " + keepBinary,
+                                val instanceof Integer);
+                        }
+
+                        ++size;
+                    }
+                }
+
+                assertTrue(size > 0);
+            }
+        }
+        finally {
+            cache.removeAll();
+
+            if (ccfg.getEvictionPolicy() != null)
+                U.sleep(1000); // Fixes evictionPolicy issues at cache destroy.
+
+            grid(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     */
+    private void doTestLocalEntries(CacheConfiguration<Object, Object> ccfg,
+        boolean keepBinary,
+        boolean primitives) throws IgniteInterruptedCheckedException {
+        IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
+
+        assertTrue(cache.size() == 0);
+
+        try {
+            for (int i = 0; i < KEYS; i++)
+                if (primitives)
+                    cache.put(i, i);
+                else
+                    cache.put(new QueryTestKey(i), new QueryTestValue(i));
+
+            for (int i = 0; i < getServerNodeCount(); i++) {
+                IgniteCache<Object, Object> cache0 = grid(i).cache(ccfg.getName());
+
+                if (keepBinary)
+                    cache0 = cache0.withKeepBinary();
+
+                for (CachePeekMode mode : CachePeekMode.values()) {
+                    int size = 0;
+
+                    for (Cache.Entry<Object, Object> e : cache0.localEntries(mode)) {
+                        Object key = e.getKey();
+                        Object val = e.getValue();
+
+                        if (!primitives) {
+                            assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary,
+                                keepBinary == key instanceof BinaryObject);
+                            assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary,
+                                keepBinary == val instanceof BinaryObject);
+                        }
+                        else {
+                            assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary,
+                                key instanceof Integer);
+                            assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary,
+                                val instanceof Integer);
+                        }
+
+                        ++size;
+                    }
+
+                    if (mode == CachePeekMode.ALL ||
+                        mode == CachePeekMode.PRIMARY ||
+                        mode == CachePeekMode.BACKUP ||
+                        (mode == CachePeekMode.NEAR && i == 0 &&
+                            ccfg.getMemoryMode() == CacheMemoryMode.ONHEAP_TIERED &&
+                            ccfg.getNearConfiguration() != null) ||
+                        (mode == CachePeekMode.ONHEAP && ccfg.getMemoryMode() == CacheMemoryMode.ONHEAP_TIERED) ||
+                        (mode == CachePeekMode.OFFHEAP && ccfg.getMemoryMode() == CacheMemoryMode.OFFHEAP_TIERED) ||
+                        (mode == CachePeekMode.SWAP && ccfg.isSwapEnabled()))
+                        assertTrue("Zero result at mode: " + mode, size > 0);
+                }
+            }
+        }
+        finally {
+            cache.removeAll();
+
+            if (ccfg.getEvictionPolicy() != null)
+                U.sleep(1000); // Fixes evictionPolicy issues at cache destroy.
+
+            grid(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @return Count nodes.
+     */
+    protected int getServerNodeCount() {
+        return NODES;
+    }
+
+    /**
+     * @param cacheMode Cache mode.
+     * @param backups Number of backups.
+     * @param atomicityMode Cache atomicity mode.
+     * @param memoryMode Cache memory mode.
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheMemoryMode memoryMode) {
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+        ccfg.setAtomicityMode(atomicityMode);
+        ccfg.setCacheMode(cacheMode);
+        ccfg.setMemoryMode(memoryMode);
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+        ccfg.setAtomicWriteOrderMode(PRIMARY);
+
+        if (cacheMode == PARTITIONED)
+            ccfg.setBackups(backups);
+
+        return ccfg;
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestKey implements Serializable {
+        /** */
+        private final Integer key;
+
+        /**
+         * @param key Key.
+         */
+        public QueryTestKey(Integer key) {
+            this.key = key;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestKey that = (QueryTestKey)o;
+
+            return key.equals(that.key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return key.hashCode();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestKey.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestValue implements Serializable {
+        /** */
+        @GridToStringInclude
+        protected final Integer val1;
+
+        /** */
+        @GridToStringInclude
+        protected final String val2;
+
+        /**
+         * @param val Value.
+         */
+        public QueryTestValue(Integer val) {
+            this.val1 = val;
+            this.val2 = String.valueOf(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestValue that = (QueryTestValue)o;
+
+            return val1.equals(that.val1) && val2.equals(that.val2);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = val1.hashCode();
+
+            res = 31 * res + val2.hashCode();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestValue.class, this);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/30ca35ba/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
index 416ca31..dbef1fb 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
@@ -30,6 +30,10 @@ import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinu
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryOrderingEventTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTwoNodesTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationNearEnabledTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationStoreEnabledTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationSwapEnabledTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicOffheapTieredTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicOffheapValuesTest;
@@ -109,6 +113,10 @@ public class IgniteCacheQuerySelfTestSuite3 extends TestSuite {
         suite.addTestSuite(CacheContinuousQueryExecuteInPrimaryTest.class);
         suite.addTestSuite(CacheContinuousQueryLostPartitionTest.class);
         suite.addTestSuite(IgniteCacheContinuousQueryImmutableEntryTest.class);
+        suite.addTestSuite(CacheKeepBinaryIterationTest.class);
+        suite.addTestSuite(CacheKeepBinaryIterationStoreEnabledTest.class);
+        suite.addTestSuite(CacheKeepBinaryIterationSwapEnabledTest.class);
+        suite.addTestSuite(CacheKeepBinaryIterationNearEnabledTest.class);
 
         return suite;
     }


[12/17] ignite git commit: 7.5.24: Added missing JavaDocs.

Posted by sb...@apache.org.
7.5.24: Added missing JavaDocs.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/fcea72d5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/fcea72d5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/fcea72d5

Branch: refs/heads/ignite-3038
Commit: fcea72d56490c6145cc0fe192425751f56921ce3
Parents: 14403bb
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue May 31 10:40:24 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue May 31 10:40:24 2016 +0300

----------------------------------------------------------------------
 .../hadoop/util/ChainedUserNameMapperSelfTest.java | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fcea72d5/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
index 5bdac8f..bfac49c 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/ChainedUserNameMapperSelfTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.hadoop.util;
 
 import org.apache.ignite.IgniteException;


[07/17] ignite git commit: review IGNITE-2708 Need to validate that SPIs are started only once (commit with proper author) (cherry picked from commit 98338ff)

Posted by sb...@apache.org.
review IGNITE-2708 Need to validate that SPIs are started only once (commit with proper author)
(cherry picked from commit 98338ff)


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c5019c66
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c5019c66
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c5019c66

Branch: refs/heads/ignite-3038
Commit: c5019c661b71665c410dd78a9ef4cb4a39a88ab5
Parents: 9639e79
Author: Ryan Zhao <ry...@gmail.com>
Authored: Fri May 13 12:00:43 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 09:29:33 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java   |  3 ++
 .../org/apache/ignite/spi/IgniteSpiAdapter.java | 29 ++++++++++++++++++--
 .../ignite/internal/GridFactorySelfTest.java    | 25 +++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c5019c66/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index cb41d4b..58d64f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -209,6 +209,9 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements GridMan
         Collection<String> names = U.newHashSet(spis.length);
 
         for (T spi : spis) {
+            if (spi instanceof IgniteSpiAdapter)
+                ((IgniteSpiAdapter)spi).onBeforeStart();
+
             // Inject all spi resources.
             ctx.resource().inject(spi);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c5019c66/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
index 999013f..7cb2e13 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
@@ -25,6 +25,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -39,7 +40,6 @@ import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgniteNodeAttributes;
 import org.apache.ignite.internal.managers.communication.GridMessageListener;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
-import org.apache.ignite.internal.processors.cache.GridCacheUtils;
 import org.apache.ignite.internal.processors.timeout.GridSpiTimeoutObject;
 import org.apache.ignite.internal.util.IgniteExceptionRegistry;
 import org.apache.ignite.internal.util.typedef.F;
@@ -96,11 +96,14 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     private boolean failureDetectionTimeoutEnabled = true;
 
     /**
-     *  Failure detection timeout. Initialized with the value of
-     *  {@link IgniteConfiguration#getFailureDetectionTimeout()}.
+     * Failure detection timeout. Initialized with the value of
+     * {@link IgniteConfiguration#getFailureDetectionTimeout()}.
      */
     private long failureDetectionTimeout;
 
+    /** Start flag to deny repeating start attempts. */
+    private final AtomicBoolean startedFlag = new AtomicBoolean();
+
     /**
      * Creates new adapter and initializes it from the current (this) class.
      * SPI name will be initialized to the simple name of the class
@@ -117,6 +120,26 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         startTstamp = U.currentTimeMillis();
     }
 
+    /**
+     * This method is called by built-in managers implementation to avoid
+     * repeating SPI start attempts.
+     */
+    public final void onBeforeStart() {
+        if (!startedFlag.compareAndSet(false, true))
+            throw new IllegalStateException("SPI has already been started " +
+                "(always create new configuration instance for each starting Ignite instances) " +
+                "[spi=" + this + ']');
+    }
+
+    /**
+     * Checks if {@link #onBeforeStart()} has been called on this SPI instance.
+     *
+     * @return {@code True} if {@link #onBeforeStart()} has already been called.
+     */
+    public final boolean started() {
+        return startedFlag.get();
+    }
+
     /** {@inheritDoc} */
     @Override public final String getStartTimestampFormatted() {
         return DateFormat.getDateTimeInstance().format(new Date(startTstamp));

http://git-wip-us.apache.org/repos/asf/ignite/blob/c5019c66/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
index 539067b..b94ed48 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
@@ -902,6 +902,31 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testRepeatingStart() throws Exception {
+        try {
+            IgniteConfiguration c = getConfiguration("1");
+
+            startGrid("1", c);
+
+            assert ((TcpDiscoverySpi)c.getDiscoverySpi()).started();
+
+            try {
+                startGrid("2", c);
+
+                fail("Should not be able to start grid using same configuration instance.");
+            }
+            catch (Exception e) {
+                info("Caught expected exception: " + e);
+            }
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
      * Test task.
      */
     private static class TestTask extends ComputeTaskSplitAdapter<Void, Void> {


[14/17] ignite git commit: Merge branch 'gridgain-7.5.24' of https://github.com/gridgain/apache-ignite into gridgain-7.5.24

Posted by sb...@apache.org.
Merge branch 'gridgain-7.5.24' of https://github.com/gridgain/apache-ignite into gridgain-7.5.24


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/efea0972
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/efea0972
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/efea0972

Branch: refs/heads/ignite-3038
Commit: efea097252f7ccc321d15c05400f0b701a578aa7
Parents: f90e424 fcea72d
Author: Denis Magda <dm...@gridgain.com>
Authored: Tue May 31 13:50:23 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue May 31 13:50:23 2016 +0300

----------------------------------------------------------------------
 .../hadoop/util/ChainedUserNameMapperSelfTest.java | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------