http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTransactionalAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTransactionalAbstractMetricsSelfTest.java
index 0000000,013500f..f0ccce4
mode 000000,100644..100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTransactionalAbstractMetricsSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTransactionalAbstractMetricsSelfTest.java
@@@ -1,0 -1,280 +1,284 @@@
+ /*
+  * 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;
+ 
+ import org.apache.ignite.cache.*;
+ import org.apache.ignite.transactions.*;
+ 
+ import static org.apache.ignite.transactions.IgniteTxConcurrency.*;
+ import static org.apache.ignite.transactions.IgniteTxIsolation.*;
+ 
+ /**
+  * Transactional cache metrics test.
+  */
+ public abstract class GridCacheTransactionalAbstractMetricsSelfTest extends 
GridCacheAbstractMetricsSelfTest {
+     /** */
+     private static final int TX_CNT = 3;
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticReadCommittedCommits() throws Exception {
+         testCommits(OPTIMISTIC, READ_COMMITTED, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticReadCommittedCommitsNoData() throws Exception {
+         testCommits(OPTIMISTIC, READ_COMMITTED, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticRepeatableReadCommits() throws Exception {
+         testCommits(OPTIMISTIC, REPEATABLE_READ, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticRepeatableReadCommitsNoData() throws Exception {
+         testCommits(OPTIMISTIC, REPEATABLE_READ, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticSerializableCommits() throws Exception {
+         testCommits(OPTIMISTIC, SERIALIZABLE, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticSerializableCommitsNoData() throws Exception {
+         testCommits(OPTIMISTIC, SERIALIZABLE, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticReadCommittedCommits() throws Exception {
+         testCommits(PESSIMISTIC, READ_COMMITTED, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticReadCommittedCommitsNoData() throws Exception {
+         testCommits(PESSIMISTIC, READ_COMMITTED, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticRepeatableReadCommits() throws Exception {
+         testCommits(PESSIMISTIC, REPEATABLE_READ, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticRepeatableReadCommitsNoData() throws Exception 
{
+         testCommits(PESSIMISTIC, REPEATABLE_READ, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticSerializableCommits() throws Exception {
+         testCommits(PESSIMISTIC, SERIALIZABLE, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticSerializableCommitsNoData() throws Exception {
+         testCommits(PESSIMISTIC, SERIALIZABLE, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticReadCommittedRollbacks() throws Exception {
+         testRollbacks(OPTIMISTIC, READ_COMMITTED, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticReadCommittedRollbacksNoData() throws Exception 
{
+         testRollbacks(OPTIMISTIC, READ_COMMITTED, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticRepeatableReadRollbacks() throws Exception {
+         testRollbacks(OPTIMISTIC, REPEATABLE_READ, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticRepeatableReadRollbacksNoData() throws 
Exception {
+         testRollbacks(OPTIMISTIC, REPEATABLE_READ, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticSerializableRollbacks() throws Exception {
+         testRollbacks(OPTIMISTIC, SERIALIZABLE, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testOptimisticSerializableRollbacksNoData() throws Exception {
+         testRollbacks(OPTIMISTIC, SERIALIZABLE, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticReadCommittedRollbacks() throws Exception {
+         testRollbacks(PESSIMISTIC, READ_COMMITTED, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticReadCommittedRollbacksNoData() throws 
Exception {
+         testRollbacks(PESSIMISTIC, READ_COMMITTED, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticRepeatableReadRollbacks() throws Exception {
+         testRollbacks(PESSIMISTIC, REPEATABLE_READ, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticRepeatableReadRollbacksNoData() throws 
Exception {
+         testRollbacks(PESSIMISTIC, REPEATABLE_READ, false);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticSerializableRollbacks() throws Exception {
+         testRollbacks(PESSIMISTIC, SERIALIZABLE, true);
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPessimisticSerializableRollbacksNoData() throws Exception 
{
+         testRollbacks(PESSIMISTIC, SERIALIZABLE, false);
+     }
+ 
+     /**
+      * @param concurrency Concurrency control.
+      * @param isolation Isolation level.
+      * @param put Put some data if {@code true}.
+      * @throws Exception If failed.
+      */
+     private void testCommits(IgniteTxConcurrency concurrency, 
IgniteTxIsolation isolation, boolean put)
+         throws Exception {
+         GridCache<Integer, Integer> cache = grid(0).cache(null);
+ 
+         for (int i = 0; i < TX_CNT; i++) {
+             IgniteTx tx = cache.txStart(concurrency, isolation);
+ 
+             if (put)
+                 for (int j = 0; j < keyCount(); j++)
+                     cache.put(j, j);
+ 
+             tx.commit();
+         }
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             IgniteTxMetrics metrics = grid(i).transactions().metrics();
+             CacheMetrics cacheMetrics = grid(i).cache(null).metrics();
+ 
+             if (i == 0) {
+                 assertEquals(TX_CNT, metrics.txCommits());
+ 
 -                if (put)
 -                    assertEquals(TX_CNT, cacheMetrics.txCommits());
++                if (put) {
++                    assertEquals(TX_CNT, cacheMetrics.getCacheTxCommits());
++                    assert cacheMetrics.getAverageTxCommitTime() > 0;
++                }
+             }
+             else {
+                 assertEquals(0, metrics.txCommits());
 -                assertEquals(0, cacheMetrics.txCommits());
++                assertEquals(0, cacheMetrics.getCacheTxCommits());
+             }
+ 
+             assertEquals(0, metrics.txRollbacks());
 -            assertEquals(0, cacheMetrics.txRollbacks());
++            assertEquals(0, cacheMetrics.getCacheTxRollbacks());
+         }
+     }
+ 
+     /**
+      * @param concurrency Concurrency control.
+      * @param isolation Isolation level.
+      * @param put Put some data if {@code true}.
+      * @throws Exception If failed.
+      */
+     private void testRollbacks(IgniteTxConcurrency concurrency, 
IgniteTxIsolation isolation,
+         boolean put) throws Exception {
+         GridCache<Integer, Integer> cache = grid(0).cache(null);
+ 
+         for (int i = 0; i < TX_CNT; i++) {
+             IgniteTx tx = cache.txStart(concurrency, isolation);
+ 
+             if (put)
+                 for (int j = 0; j < keyCount(); j++)
+                     cache.put(j, j);
+ 
+             tx.rollback();
+         }
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             IgniteTxMetrics metrics = grid(i).transactions().metrics();
+             CacheMetrics cacheMetrics = grid(i).cache(null).metrics();
+ 
+             assertEquals(0, metrics.txCommits());
 -            assertEquals(0, cacheMetrics.txCommits());
++            assertEquals(0, cacheMetrics.getCacheTxCommits());
+ 
+             if (i == 0) {
+                 assertEquals(TX_CNT, metrics.txRollbacks());
+ 
 -                if (put)
 -                    assertEquals(TX_CNT, cacheMetrics.txRollbacks());
++                if (put) {
++                    assertEquals(TX_CNT, cacheMetrics.getCacheTxRollbacks());
++                    assert cacheMetrics.getAverageTxRollbackTime() > 0;
++                }
+             }
+             else {
+                 assertEquals(0, metrics.txRollbacks());
 -                assertEquals(0, cacheMetrics.txRollbacks());
++                assertEquals(0, cacheMetrics.getCacheTxRollbacks());
+             }
+         }
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMetricsSelfTest.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMetricsSelfTest.java
index 0000000,1d96725..b38de47
mode 000000,100644..100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMetricsSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedNearDisabledMetricsSelfTest.java
@@@ -1,0 -1,119 +1,119 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ 
+ package org.apache.ignite.internal.processors.cache.distributed.dht;
+ 
+ import org.apache.ignite.*;
+ import org.apache.ignite.cache.*;
+ import org.apache.ignite.configuration.*;
+ import org.apache.ignite.internal.processors.cache.*;
+ 
+ import static org.apache.ignite.cache.CacheDistributionMode.*;
+ import static org.apache.ignite.cache.CacheMode.*;
+ import static org.apache.ignite.cache.CachePreloadMode.*;
+ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+ 
+ /**
+  * Metrics test for partitioned cache with disabled near cache.
+  */
+ public class GridCachePartitionedNearDisabledMetricsSelfTest extends 
GridCacheAbstractSelfTest {
+     /** */
+     private static final int GRID_CNT = 2;
+ 
+     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+         IgniteConfiguration cfg = super.getConfiguration(gridName);
+ 
+         cfg.getTransactionsConfiguration().setTxSerializableEnabled(true);
+ 
+         return cfg;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected CacheConfiguration cacheConfiguration(String 
gridName) throws Exception {
+         CacheConfiguration cfg = super.cacheConfiguration(gridName);
+ 
+         cfg.setCacheMode(PARTITIONED);
+         cfg.setBackups(gridCount() - 1);
+         cfg.setPreloadMode(SYNC);
+         cfg.setWriteSynchronizationMode(FULL_SYNC);
+         cfg.setDistributionMode(PARTITIONED_ONLY);
+ 
+         return cfg;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected int gridCount() {
+         return GRID_CNT;
+     }
+ 
+     // TODO: extend from GridCacheTransactionalAbstractMetricsSelfTest and 
uncomment:
+ 
+ //    /** {@inheritDoc} */
+ //    @Override protected int expectedReadsPerPut(boolean isPrimary) {
+ //        return 1;
+ //    }
+ //
+ //    /** {@inheritDoc} */
+ //    @Override protected int expectedMissesPerPut(boolean isPrimary) {
+ //        return 1;
+ //    }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void _testGettingRemovedKey() throws Exception {
+         GridCache<Integer, Integer> cache = grid(0).cache(null);
+ 
+         cache.put(0, 0);
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             Ignite g = grid(i);
+ 
+             // TODO: getting of removed key will produce 3 inner read 
operations.
+             g.cache(null).removeAll();
+ 
+             // TODO: getting of removed key will produce inner write and 4 
inner read operations.
+             //g.cache(null).remove(0);
+ 
+             assert g.cache(null).isEmpty();
+ 
 -            g.cache(null).resetMetrics();
++            g.cache(null).mxBean().clear();
+         }
+ 
+         assertNull("Value is not null for key: " + 0, cache.get(0));
+ 
+         // Check metrics for the whole cache.
 -        long writes = 0;
++        long removes = 0;
+         long reads = 0;
+         long hits = 0;
+         long misses = 0;
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             CacheMetrics m = grid(i).cache(null).metrics();
+ 
 -            writes += m.writes();
 -            reads += m.reads();
 -            hits += m.hits();
 -            misses += m.misses();
++            removes += m.getCacheRemovals();
++            reads += m.getCacheGets();
++            hits += m.getCacheHits();
++            misses += m.getCacheMisses();
+         }
+ 
 -        assertEquals(0, writes);
++        assertEquals(0, removes);
+         assertEquals(1, reads);
+         assertEquals(0, hits);
+         assertEquals(1, misses);
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPartitionedTckMetricsSelfTestImpl.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPartitionedTckMetricsSelfTestImpl.java
index 0000000,0000000..5a71ced
new file mode 100644
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicPartitionedTckMetricsSelfTestImpl.java
@@@ -1,0 -1,0 +1,185 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one or more
++ * contributor license agreements.  See the NOTICE file distributed with
++ * this work for additional information regarding copyright ownership.
++ * The ASF licenses this file to You under the Apache License, Version 2.0
++ * (the "License"); you may not use this file except in compliance with
++ * the License.  You may obtain a copy of the License at
++ *
++ *      http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing, software
++ * distributed under the License is distributed on an "AS IS" BASIS,
++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++ * See the License for the specific language governing permissions and
++ * limitations under the License.
++ */
++
++package org.apache.ignite.internal.processors.cache.distributed.near;
++
++import org.apache.ignite.IgniteCache;
++
++import javax.cache.processor.EntryProcessor;
++import javax.cache.processor.EntryProcessorException;
++import javax.cache.processor.MutableEntry;
++
++/**
++ * Partitioned atomic cache metrics test.
++ */
++public class GridCacheAtomicPartitionedTckMetricsSelfTestImpl extends 
GridCacheAtomicPartitionedMetricsSelfTest {
++    /** {@inheritDoc} */
++    @Override protected int gridCount() {
++        return 1;
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testEntryProcessorRemove() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        jcache.put(1, 20);
++
++        int result = jcache.invoke(1, new EntryProcessor<Integer, Integer, 
Integer>() {
++            @Override public Integer process(MutableEntry<Integer, Integer> 
entry, Object... arguments)
++                    throws EntryProcessorException {
++                Integer result = entry.getValue();
++
++                entry.remove();
++
++                return result;
++            }
++        });
++
++        assertEquals(1L, cache().metrics().getCachePuts());
++
++        assertEquals(20, result);
++        assertEquals(1L, cache().metrics().getCacheHits());
++        assertEquals(100.0f, cache().metrics().getCacheHitPercentage());
++        assertEquals(0L, cache().metrics().getCacheMisses());
++        assertEquals(0f, cache().metrics().getCacheMissPercentage());
++        assertEquals(1L, cache().metrics().getCachePuts());
++        assertEquals(1L, cache().metrics().getCacheRemovals());
++        assertEquals(0L, cache().metrics().getCacheEvictions());
++        assert cache().metrics().getAveragePutTime() >= 0;
++        assert cache().metrics().getAverageGetTime() >= 0;
++        assert cache().metrics().getAverageRemoveTime() >= 0;
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testCacheStatistics() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        jcache.put(1, 10);
++
++        assertEquals(0, cache().metrics().getCacheRemovals());
++        assertEquals(1, cache().metrics().getCachePuts());
++
++        jcache.remove(1);
++
++        assertEquals(0, cache().metrics().getCacheHits());
++        assertEquals(1, cache().metrics().getCacheRemovals());
++        assertEquals(1, cache().metrics().getCachePuts());
++
++        jcache.remove(1);
++
++        assertEquals(0, cache().metrics().getCacheHits());
++        assertEquals(0, cache().metrics().getCacheMisses());
++        assertEquals(1, cache().metrics().getCacheRemovals());
++        assertEquals(1, cache().metrics().getCachePuts());
++
++        jcache.put(1, 10);
++        assertTrue(jcache.remove(1, 10));
++
++        assertEquals(1, cache().metrics().getCacheHits());
++        assertEquals(0, cache().metrics().getCacheMisses());
++        assertEquals(2, cache().metrics().getCacheRemovals());
++        assertEquals(2, cache().metrics().getCachePuts());
++
++        assertFalse(jcache.remove(1, 10));
++
++        assertEquals(1, cache().metrics().getCacheHits());
++        assertEquals(1, cache().metrics().getCacheMisses());
++        assertEquals(2, cache().metrics().getCacheRemovals());
++        assertEquals(2, cache().metrics().getCachePuts());
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testConditionReplace() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        long hitCount = 0;
++        long missCount = 0;
++        long putCount = 0;
++
++        boolean result = jcache.replace(1, 0, 10);
++
++        ++missCount;
++        assertFalse(result);
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        assertFalse(jcache.containsKey(1));
++
++        jcache.put(1, 10);
++        ++putCount;
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        assertTrue(jcache.containsKey(1));
++
++        result = jcache.replace(1, 10, 20);
++
++        assertTrue(result);
++        ++hitCount;
++        ++putCount;
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        result = jcache.replace(1, 40, 50);
++
++        assertFalse(result);
++        ++hitCount;
++
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testPutIfAbsent() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        long hitCount = 0;
++        long missCount = 0;
++        long putCount = 0;
++
++        boolean result = jcache.putIfAbsent(1, 1);
++
++        ++putCount;
++        assertTrue(result);
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        result = jcache.putIfAbsent(1, 1);
++
++        assertFalse(result);
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++    }
++}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
index 0000000,5e142ba..8eac9a3
mode 000000,100644..100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearMetricsSelfTest.java
@@@ -1,0 -1,395 +1,406 @@@
+ /*
+  * 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.distributed.near;
+ 
+ import org.apache.ignite.*;
+ import org.apache.ignite.cache.*;
+ import org.apache.ignite.internal.processors.cache.*;
+ import org.apache.ignite.internal.util.typedef.internal.*;
+ 
+ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+ 
+ /**
+  * Cache metrics test.
+  */
+ public class GridCacheNearMetricsSelfTest extends GridCacheAbstractSelfTest {
+     /** */
+     private static final int KEY_CNT = 50;
+ 
+     /** {@inheritDoc} */
+     @Override protected CacheWriteSynchronizationMode writeSynchronization() {
+         return FULL_SYNC;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected boolean swapEnabled() {
+         return false;
+     }
+ 
+     /** {@inheritDoc} */
+     protected boolean perEntryMetricsEnabled() {
+         return true;
+     }
+ 
+     /**
+      * @return Key count.
+      */
+     protected int keyCount() {
+         return KEY_CNT;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected int gridCount() {
+         return 3;
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected void afterTest() throws Exception {
+         super.afterTest();
+ 
+         for (int i = 0; i < gridCount(); i++) {
+             Ignite g = grid(i);
+ 
+             g.cache(null).removeAll();
+ 
+             assert g.cache(null).isEmpty();
+ 
 -            g.cache(null).resetMetrics();
++            g.cache(null).mxBean().clear();
++        }
++    }
++
++    /** {@inheritDoc} */
++    @Override protected void beforeTest() throws Exception {
++        super.beforeTest();
++
++        for (int i = 0; i < gridCount(); i++) {
++            Ignite g = grid(i);
++
++            g.cache(null).configuration().setStatisticsEnabled(true);
+         }
+     }
+ 
+     /** {@inheritDoc} */
+     @Override protected CacheConfiguration cacheConfiguration(String 
gridName) throws Exception {
+         CacheConfiguration cc = super.cacheConfiguration(gridName);
+ 
+         cc.setCacheMode(CacheMode.PARTITIONED);
+         cc.setBackups(1);
+ 
+         return cc;
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPrimaryPut() throws Exception {
+         Ignite g0 = grid(0);
+ 
+         GridCache<Integer, Integer> cache0 = g0.cache(null);
+ 
+         int key;
+ 
+         // Put and get a few keys.
+         for (int i = 0; ; i++) {
+             if (cache0.affinity().isPrimary(g0.cluster().localNode(), i)) {
+                 cache0.put(i, i); // +1 read
+ 
+                 cache0.get(i); // +1 read.
+ 
+                 key = i;
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Puts: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 break;
+             }
+         }
+ 
+         for (int j = 0; j < gridCount(); j++) {
+             Ignite g = grid(j);
+ 
+             info("Checking grid: " + g.name());
+ 
 -            info("Writes: " + g.cache(null).metrics().writes());
 -            info("Reads: " + g.cache(null).metrics().reads());
++            info("Puts: " + g.cache(null).metrics().getCachePuts());
++            info("Reads: " + g.cache(null).metrics().getCacheGets());
+ 
+             if 
(g.cache(null).affinity().isPrimaryOrBackup(g.cluster().localNode(), key))
 -                assertEquals(1, g.cache(null).metrics().writes());
++                assertEquals(1, g.cache(null).metrics().getCachePuts());
+             else
 -                assertEquals(0, g.cache(null).metrics().writes());
++                assertEquals(0, g.cache(null).metrics().getCachePuts());
+ 
+             if (g.cache(null).affinity().isPrimary(g.cluster().localNode(), 
key)) {
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(1, g.cache(null).metrics().hits());
 -                assertEquals(1, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(1, g.cache(null).metrics().getCacheHits());
++                assertEquals(1, g.cache(null).metrics().getCacheHits());
+             }
+             else {
 -                assertEquals(0, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(0, g.cache(null).metrics().misses());
++                assertEquals(0, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(0, g.cache(null).metrics().getCacheMisses());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testBackupPut() throws Exception {
+         Ignite g0 = grid(0);
+ 
+         GridCache<Integer, Integer> cache0 = g0.cache(null);
+ 
+         int key;
+ 
+         // Put and get a few keys.
+         for (int i = 0; ; i++) {
+             if (cache0.affinity().isBackup(g0.cluster().localNode(), i)) {
+                 cache0.put(i, i); // +1 read.
+ 
+                 cache0.get(i); // +1 read.
+ 
+                 key = i;
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Puts: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 break;
+             }
+         }
+ 
+         for (int j = 0; j < gridCount(); j++) {
+             Ignite g = grid(j);
+ 
+             if 
(g.cache(null).affinity().isPrimaryOrBackup(g.cluster().localNode(), key))
 -                assertEquals(1, g.cache(null).metrics().writes());
++                assertEquals(1, g.cache(null).metrics().getCachePuts());
+             else
 -                assertEquals(0, g.cache(null).metrics().writes());
++                assertEquals(0, g.cache(null).metrics().getCachePuts());
+ 
+             if (g.cache(null).affinity().isPrimary(g.cluster().localNode(), 
key)) {
 -                assertEquals(1, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(1, g.cache(null).metrics().misses());
++                assertEquals(1, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(1, g.cache(null).metrics().getCacheMisses());
+             }
+             else if 
(g.cache(null).affinity().isBackup(g.cluster().localNode(), key)){
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(1, g.cache(null).metrics().hits());
 -                assertEquals(1, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(1, g.cache(null).metrics().getCacheHits());
++                assertEquals(1, g.cache(null).metrics().getCacheMisses());
+             }
+             else {
 -                assertEquals(0, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(0, g.cache(null).metrics().misses());
++                assertEquals(0, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(0, g.cache(null).metrics().getCacheMisses());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testNearPut() throws Exception {
+         Ignite g0 = grid(0);
+ 
+         GridCache<Integer, Integer> cache0 = g0.cache(null);
+ 
+         int key;
+ 
+         // Put and get a few keys.
+         for (int i = 0; ; i++) {
+             if 
(!cache0.affinity().isPrimaryOrBackup(g0.cluster().localNode(), i)) {
+                 cache0.put(i, i); // +1 read.
+ 
+                 cache0.get(i); // +1 read.
+ 
+                 key = i;
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Writes: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 break;
+             }
+         }
+ 
+         for (int j = 0; j < gridCount(); j++) {
+             Ignite g = grid(j);
+ 
 -            assertEquals(1, g.cache(null).metrics().writes());
++            assertEquals(1, g.cache(null).metrics().getCachePuts());
+ 
+             if (g.cache(null).affinity().isPrimary(g.cluster().localNode(), 
key)) {
 -                assertEquals(1, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(1, g.cache(null).metrics().misses());
++                assertEquals(1, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(1, g.cache(null).metrics().getCacheMisses());
+             }
+             else if 
(g.cache(null).affinity().isBackup(g.cluster().localNode(), key)){
 -                assertEquals(0, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(0, g.cache(null).metrics().misses());
++                assertEquals(0, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(0, g.cache(null).metrics().getCacheMisses());
+             }
+             else {
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(1, g.cache(null).metrics().hits());
 -                assertEquals(1, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(1, g.cache(null).metrics().getCacheHits());
++                assertEquals(1, g.cache(null).metrics().getCacheMisses());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testPrimaryRead() throws Exception {
+         Ignite g0 = grid(0);
+ 
+         GridCache<Integer, Integer> cache0 = g0.cache(null);
+ 
+         int key;
+ 
+         // Put and get a few keys.
+         for (int i = 0; ; i++) {
+             if (cache0.affinity().isPrimary(g0.cluster().localNode(), i)) {
+                 cache0.get(i); // +1 read.
+ 
+                 key = i;
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Writes: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 cache0.get(i); // +1 read.
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Writes: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 break;
+             }
+         }
+ 
+         for (int j = 0; j < gridCount(); j++) {
+             Ignite g = grid(j);
+ 
+             info("Checking grid: " + g.name());
+ 
 -            info("Writes: " + g.cache(null).metrics().writes());
 -            info("Reads: " + g.cache(null).metrics().reads());
++            info("Writes: " + g.cache(null).metrics().getCachePuts());
++            info("Reads: " + g.cache(null).metrics().getCacheGets());
+ 
 -            assertEquals(0, g.cache(null).metrics().writes());
++            assertEquals(0, g.cache(null).metrics().getCachePuts());
+ 
+             if (g.cache(null).affinity().isPrimary(g.cluster().localNode(), 
key)) {
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(2, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(2, g.cache(null).metrics().getCacheMisses());
+             }
+             else {
 -                assertEquals(0, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(0, g.cache(null).metrics().misses());
++                assertEquals(0, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(0, g.cache(null).metrics().getCacheMisses());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testBackupRead() throws Exception {
+         Ignite g0 = grid(0);
+ 
+         GridCache<Integer, Integer> cache0 = g0.cache(null);
+ 
+         int key;
+ 
+         // Put and get a few keys.
+         for (int i = 0; ; i++) {
+             if (cache0.affinity().isBackup(g0.cluster().localNode(), i)) {
+                 cache0.get(i); // +1 read.
+ 
+                 key = i;
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Writes: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 cache0.get(i); // +1 read.
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
++                info("Writes: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 break;
+             }
+         }
+ 
+         for (int j = 0; j < gridCount(); j++) {
+             Ignite g = grid(j);
+ 
 -            assertEquals(0, g.cache(null).metrics().writes());
++            assertEquals(0, g.cache(null).metrics().getCachePuts());
+ 
+             if 
(g.cache(null).affinity().isPrimaryOrBackup(g.cluster().localNode(), key)) {
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(2, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(2, g.cache(null).metrics().getCacheMisses());
+             }
+             else {
 -                assertEquals(0, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(0, g.cache(null).metrics().misses());
++                assertEquals(0, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(0, g.cache(null).metrics().getCacheMisses());
+             }
+         }
+     }
+ 
+     /**
+      * @throws Exception If failed.
+      */
+     public void testNearRead() throws Exception {
+         Ignite g0 = grid(0);
+ 
+         GridCache<Integer, Integer> cache0 = g0.cache(null);
+ 
+         int key;
+ 
+         // Put and get a few keys.
+         for (int i = 0; ; i++) {
+             if 
(!cache0.affinity().isPrimaryOrBackup(g0.cluster().localNode(), i)) {
+                 cache0.get(i); // +1 read.
+                 cache0.get(i); // +1 read.
+ 
+                 key = i;
+ 
 -                info("Writes: " + cache0.metrics().writes());
 -                info("Reads: " + cache0.metrics().reads());
 -                info("Hits: " + cache0.metrics().hits());
 -                info("Misses: " + cache0.metrics().misses());
++                info("Writes: " + cache0.metrics().getCachePuts());
++                info("Reads: " + cache0.metrics().getCacheGets());
++                info("Hits: " + cache0.metrics().getCacheHits());
++                info("Misses: " + cache0.metrics().getCacheMisses());
+                 info("Affinity nodes: " + 
U.nodes2names(cache0.affinity().mapKeyToPrimaryAndBackups(i)));
+ 
+                 break;
+             }
+         }
+ 
+         for (int j = 0; j < gridCount(); j++) {
+             Ignite g = grid(j);
+ 
 -            assertEquals(0, g.cache(null).metrics().writes());
++            assertEquals(0, g.cache(null).metrics().getCachePuts());
+ 
+             if (g.cache(null).affinity().isPrimary(g.cluster().localNode(), 
key)) {
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(2, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(2, g.cache(null).metrics().getCacheMisses());
+             }
+             else if 
(g.cache(null).affinity().isBackup(g.cluster().localNode(), key)){
 -                assertEquals(0, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(0, g.cache(null).metrics().misses());
++                assertEquals(0, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(0, g.cache(null).metrics().getCacheMisses());
+             }
+             else {
 -                assertEquals(2, g.cache(null).metrics().reads());
 -                assertEquals(0, g.cache(null).metrics().hits());
 -                assertEquals(2, g.cache(null).metrics().misses());
++                assertEquals(2, g.cache(null).metrics().getCacheGets());
++                assertEquals(0, g.cache(null).metrics().getCacheHits());
++                assertEquals(2, g.cache(null).metrics().getCacheMisses());
+             }
+         }
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheAtomicLocalTckMetricsSelfTestImpl.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheAtomicLocalTckMetricsSelfTestImpl.java
index 0000000,0000000..ae671ce
new file mode 100644
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheAtomicLocalTckMetricsSelfTestImpl.java
@@@ -1,0 -1,0 +1,161 @@@
++package org.apache.ignite.internal.processors.cache.local;
++
++import org.apache.ignite.*;
++
++import javax.cache.processor.*;
++
++/**
++ * Local atomic cache metrics test with tck specific.
++ */
++public class GridCacheAtomicLocalTckMetricsSelfTestImpl extends 
GridCacheAtomicLocalMetricsSelfTest {
++    /**
++     * @throws Exception If failed.
++     */
++    public void testEntryProcessorRemove() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        jcache.put(1, 20);
++
++        int result = jcache.invoke(1, new EntryProcessor<Integer, Integer, 
Integer>() {
++            @Override public Integer process(MutableEntry<Integer, Integer> 
entry, Object... arguments)
++                    throws EntryProcessorException {
++                Integer result = entry.getValue();
++
++                entry.remove();
++
++                return result;
++            }
++        });
++
++        assertEquals(1L, cache().metrics().getCachePuts());
++
++        assertEquals(20, result);
++        assertEquals(1L, cache().metrics().getCacheHits());
++        assertEquals(100.0f, cache().metrics().getCacheHitPercentage());
++        assertEquals(0L, cache().metrics().getCacheMisses());
++        assertEquals(0f, cache().metrics().getCacheMissPercentage());
++        assertEquals(1L, cache().metrics().getCachePuts());
++        assertEquals(1L, cache().metrics().getCacheRemovals());
++        assertEquals(0L, cache().metrics().getCacheEvictions());
++        assert cache().metrics().getAveragePutTime() >= 0;
++        assert cache().metrics().getAverageGetTime() >= 0;
++        assert cache().metrics().getAverageRemoveTime() >= 0;
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testCacheStatistics() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        jcache.put(1, 10);
++
++        assertEquals(0, cache().metrics().getCacheRemovals());
++        assertEquals(1, cache().metrics().getCachePuts());
++
++        jcache.remove(1);
++
++        assertEquals(0, cache().metrics().getCacheHits());
++        assertEquals(1, cache().metrics().getCacheRemovals());
++        assertEquals(1, cache().metrics().getCachePuts());
++
++        jcache.remove(1);
++
++        assertEquals(0, cache().metrics().getCacheHits());
++        assertEquals(0, cache().metrics().getCacheMisses());
++        assertEquals(1, cache().metrics().getCacheRemovals());
++        assertEquals(1, cache().metrics().getCachePuts());
++
++        jcache.put(1, 10);
++        assertTrue(jcache.remove(1, 10));
++
++        assertEquals(1, cache().metrics().getCacheHits());
++        assertEquals(0, cache().metrics().getCacheMisses());
++        assertEquals(2, cache().metrics().getCacheRemovals());
++        assertEquals(2, cache().metrics().getCachePuts());
++
++        assertFalse(jcache.remove(1, 10));
++
++        assertEquals(1, cache().metrics().getCacheHits());
++        assertEquals(1, cache().metrics().getCacheMisses());
++        assertEquals(2, cache().metrics().getCacheRemovals());
++        assertEquals(2, cache().metrics().getCachePuts());
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testConditionReplace() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        long hitCount = 0;
++        long missCount = 0;
++        long putCount = 0;
++
++        boolean result = jcache.replace(1, 0, 10);
++
++        ++missCount;
++        assertFalse(result);
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        assertFalse(jcache.containsKey(1));
++
++        jcache.put(1, 10);
++        ++putCount;
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        assertTrue(jcache.containsKey(1));
++
++        result = jcache.replace(1, 10, 20);
++
++        assertTrue(result);
++        ++hitCount;
++        ++putCount;
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        result = jcache.replace(1, 40, 50);
++
++        assertFalse(result);
++        ++hitCount;
++
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++    }
++
++    /**
++     * @throws Exception If failed.
++     */
++    public void testPutIfAbsent() throws Exception {
++        IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
++
++        long hitCount = 0;
++        long missCount = 0;
++        long putCount = 0;
++
++        boolean result = jcache.putIfAbsent(1, 1);
++
++        ++putCount;
++        assertTrue(result);
++
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++
++        result = jcache.putIfAbsent(1, 1);
++
++        assertFalse(result);
++        assertEquals(hitCount, cache().metrics().getCacheHits());
++        assertEquals(putCount, cache().metrics().getCachePuts());
++        assertEquals(missCount, cache().metrics().getCacheMisses());
++    }
++}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
----------------------------------------------------------------------
diff --cc 
modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMetricsSelfTestSuite.java
index 0000000,45eb8c6..ae3fa32
mode 000000,100644..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
@@@ -1,0 -1,49 +1,51 @@@
+ /*
+  * 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.testsuites;
+ 
+ import junit.framework.*;
+ import org.apache.ignite.internal.processors.cache.distributed.near.*;
+ import org.apache.ignite.internal.processors.cache.distributed.replicated.*;
+ import org.apache.ignite.internal.processors.cache.local.*;
+ 
+ /**
+  * Test suite for cache metrics.
+  */
+ public class IgniteCacheMetricsSelfTestSuite extends TestSuite {
+     /**
+      * @return Cache metrics test suite.
+      * @throws Exception If failed.
+      */
+     public static TestSuite suite() throws Exception {
+         TestSuite suite = new TestSuite("Cache Metrics Test Suite");
+ 
 -//        suite.addTest(new TestSuite(GridCacheLocalMetricsSelfTest.class));
++        suite.addTest(new TestSuite(GridCacheLocalMetricsSelfTest.class));
+         suite.addTest(new TestSuite(GridCacheNearMetricsSelfTest.class));
+         suite.addTest(new 
TestSuite(GridCacheReplicatedMetricsSelfTest.class));
+         suite.addTest(new 
TestSuite(GridCachePartitionedMetricsSelfTest.class));
+ 
+         // Atomic cache.
+         suite.addTest(new 
TestSuite(GridCacheAtomicLocalMetricsSelfTest.class));
+         suite.addTest(new 
TestSuite(GridCacheAtomicLocalMetricsNoStoreSelfTest.class));
+         suite.addTest(new 
TestSuite(GridCacheAtomicReplicatedMetricsSelfTest.class));
+         suite.addTest(new 
TestSuite(GridCacheAtomicPartitionedMetricsSelfTest.class));
++        suite.addTest(new 
TestSuite(GridCacheAtomicPartitionedTckMetricsSelfTestImpl.class));
++        suite.addTest(new 
TestSuite(GridCacheAtomicLocalTckMetricsSelfTestImpl.class));
+ 
+         return suite;
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c7a9a1db/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
----------------------------------------------------------------------
diff --cc 
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
index 0000000,ee33335..acfe247
mode 000000,100644..100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedHitsAndMissesSelfTest.java
@@@ -1,0 -1,178 +1,179 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *      http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ 
+ package org.apache.ignite.internal.processors.cache.distributed.near;
+ 
+ import org.apache.ignite.*;
+ import org.apache.ignite.cache.*;
+ import org.apache.ignite.cache.query.*;
+ import org.apache.ignite.configuration.*;
+ import org.apache.ignite.dataload.*;
+ import org.apache.ignite.marshaller.optimized.*;
+ import org.apache.ignite.spi.discovery.tcp.*;
+ import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+ import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+ import org.apache.ignite.transactions.*;
+ import org.apache.ignite.testframework.junits.common.*;
+ 
+ import javax.cache.processor.*;
+ import java.util.*;
+ 
+ import static org.apache.ignite.cache.CacheDistributionMode.*;
+ import static org.apache.ignite.cache.CacheMode.*;
+ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+ 
+ /**
+  * Test for issue GG-3997 Total Hits and Misses display wrong value for 
in-memory database.
+  */
+ public class GridCachePartitionedHitsAndMissesSelfTest extends 
GridCommonAbstractTest {
+     /** Amount of grids to start. */
+     private static final int GRID_CNT = 3;
+ 
+     /** Count of total numbers to generate. */
+     private static final int CNT = 2000;
+ 
+     /** IP Finder. */
+     private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
+ 
+     /** {@inheritDoc} */
+     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+         IgniteConfiguration cfg = super.getConfiguration(gridName);
+ 
+         cfg.setMarshaller(new IgniteOptimizedMarshaller(false));
+ 
+         // DiscoverySpi
+         TcpDiscoverySpi disco = new TcpDiscoverySpi();
+         disco.setIpFinder(IP_FINDER);
+         cfg.setDiscoverySpi(disco);
+ 
+         // Cache.
+         cfg.setCacheConfiguration(cacheConfiguration(gridName));
+ 
+         TransactionsConfiguration tCfg = new TransactionsConfiguration();
+ 
+         tCfg.setDefaultTxConcurrency(IgniteTxConcurrency.PESSIMISTIC);
+         tCfg.setDefaultTxIsolation(IgniteTxIsolation.REPEATABLE_READ);
+ 
+         cfg.setTransactionsConfiguration(tCfg);
+ 
+         return cfg;
+     }
+ 
+     /**
+      * Cache configuration.
+      *
+      * @param gridName Grid name.
+      * @return Cache configuration.
+      * @throws Exception In case of error.
+      */
+     protected CacheConfiguration cacheConfiguration(String gridName) throws 
Exception {
+         CacheConfiguration cfg = defaultCacheConfiguration();
+         cfg.setCacheMode(PARTITIONED);
+         cfg.setStartSize(700000);
+         cfg.setWriteSynchronizationMode(FULL_ASYNC);
+         cfg.setEvictionPolicy(null);
+         cfg.setBackups(1);
+         cfg.setDistributionMode(PARTITIONED_ONLY);
+         cfg.setPreloadPartitionedDelay(-1);
+         cfg.setBackups(1);
++        cfg.setStatisticsEnabled(true);
+ 
+         CacheQueryConfiguration qcfg = new CacheQueryConfiguration();
+ 
+         qcfg.setIndexPrimitiveKey(true);
+ 
+         cfg.setQueryConfiguration(qcfg);
+ 
+         return cfg;
+     }
+ 
+     /**
+      * This test is just a wrapper for 
org.gridgain.examples1.data.realtime.GridPopularNumbersRealTimeExample
+      *
+      * @throws Exception If failed.
+      */
+     public void testHitsAndMisses() throws Exception {
+         assert(GRID_CNT > 0);
+ 
+         startGrids(GRID_CNT);
+ 
+         try {
+             final Ignite g = grid(0);
+ 
+             realTimePopulate(g);
+ 
+             // Check metrics for the whole cache.
+             long hits = 0;
+             long misses = 0;
+ 
+             for (int i = 0; i < GRID_CNT; i++) {
+                 CacheMetrics m = grid(i).cache(null).metrics();
+ 
 -                hits += m.hits();
 -                misses += m.misses();
++                hits += m.getCacheHits();
++                misses += m.getCacheMisses();
+             }
+ 
+             assertEquals(CNT / 2, hits);
+             assertEquals(CNT / 2, misses);
+         }
+         finally {
+             stopAllGrids();
+         }
+     }
+ 
+     /**
+      * Populates cache with data loader.
+      *
+      * @param g Grid.
+      * @throws IgniteCheckedException If failed.
+      */
+     private static void realTimePopulate(final Ignite g) throws 
IgniteCheckedException {
+         try (IgniteDataLoader<Integer, Long> ldr = g.dataLoader(null)) {
+             // Sets max values to 1 so cache metrics have correct values.
+             ldr.perNodeParallelLoadOperations(1);
+ 
+             // Count closure which increments a count on remote node.
+             ldr.updater(new IncrementingUpdater());
+ 
+             for (int i = 0; i < CNT; i++)
+                 ldr.addData(i % (CNT / 2), 1L);
+         }
+     }
+ 
+     /**
+      * Increments value for key.
+      */
+     private static class IncrementingUpdater implements 
IgniteDataLoadCacheUpdater<Integer, Long> {
+         /** */
+         private static final EntryProcessor<Integer, Long, Void> INC = new 
EntryProcessor<Integer, Long, Void>() {
+             @Override public Void process(MutableEntry<Integer, Long> e, 
Object... args) {
+                 Long val = e.getValue();
+ 
+                 e.setValue(val == null ? 1 : val + 1);
+ 
+                 return null;
+             }
+         };
+ 
+         /** {@inheritDoc} */
+         @Override public void update(IgniteCache<Integer, Long> cache,
+             Collection<Map.Entry<Integer, Long>> entries) throws 
IgniteCheckedException {
+             for (Map.Entry<Integer, Long> entry : entries)
+                 cache.invoke(entry.getKey(), INC);
+         }
+     }
+ }

Reply via email to