ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject ignite git commit: IGNITE-1071 IgniteCache.metrics() method returns local metrics
Date Thu, 24 Mar 2016 10:59:35 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1071 [created] 5069a2da1


IGNITE-1071 IgniteCache.metrics() method returns local metrics


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

Branch: refs/heads/ignite-1071
Commit: 5069a2da1befa44a3acdf765bee33d35aad0311a
Parents: aa8dcd1
Author: Anton Vinogradov <av@apache.org>
Authored: Thu Mar 24 13:58:17 2016 +0300
Committer: Anton Vinogradov <av@apache.org>
Committed: Thu Mar 24 13:58:17 2016 +0300

----------------------------------------------------------------------
 .../processors/cache/CacheMetricsSnapshot.java  |  2 +-
 .../processors/cache/IgniteCacheProxy.java      |  2 +-
 .../cache/GridCacheAbstractMetricsSelfTest.java | 49 ++++++++++++++++++--
 ...cheTransactionalAbstractMetricsSelfTest.java |  2 +-
 4 files changed, 47 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a2da/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
index fc7e9a7..3196900 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsSnapshot.java
@@ -353,7 +353,7 @@ public class CacheMetricsSnapshot implements CacheMetrics, Externalizable
{
             reads += e.getCacheGets();
             puts += e.getCachePuts();
             hits += e.getCacheHits();
-            misses += e.getCacheHits();
+            misses += e.getCacheMisses();
             txCommits += e.getCacheTxCommits();
             txRollbacks += e.getCacheTxRollbacks();
             evicts += e.getCacheEvictions();

http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a2da/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 9b7ac4c..b29014b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -222,7 +222,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
         CacheOperationContext prev = onEnter(gate, opCtx);
 
         try {
-            return ctx.cache().metrics();
+            return metrics(ctx.grid().cluster().forCacheNodes(ctx.name()));
         }
         finally {
             onLeave(gate, prev);

http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a2da/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
index 4c04df0..2026d7f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
@@ -24,6 +24,7 @@ import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import javax.cache.expiry.Duration;
 import javax.cache.expiry.ExpiryPolicy;
@@ -34,14 +35,20 @@ import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.events.Event;
 import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.transactions.Transaction;
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.events.EventType.EVT_NODE_METRICS_UPDATED;
 
 /**
  * Cache metrics test.
@@ -55,6 +62,15 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         return false;
     }
 
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setHeartbeatFrequency(500);
+
+        return cfg;
+    }
+
     /**
      * @return Key count.
      */
@@ -101,6 +117,21 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
 
             g.transactions().resetMetrics();
         }
+
+        final CountDownLatch latch = new CountDownLatch((gridCount() + 1) * 2);
+
+        IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
+            @Override public boolean apply(Event ignore) {
+                latch.countDown();
+
+                return true;
+            }
+        };
+
+        for (int i = 0; i < gridCount(); i++)
+            grid(i).events().localListen(lsnr, EVT_NODE_METRICS_UPDATED);
+
+        latch.await(); // wait for heartbeat based metrics clear.
     }
 
     /** {@inheritDoc} */
@@ -539,12 +570,12 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
             expReads += expectedReadsPerPut(isPrimary);
             expMisses += expectedMissesPerPut(isPrimary);
 
-            info("Puts: " + cache0.metrics().getCachePuts());
+            info("Puts: " + cache0.mxBean().getCachePuts());
 
             for (int j = 0; j < gridCount(); j++) {
                 IgniteCache<Integer, Integer> cache = grid(j).cache(null);
 
-                int cacheWrites = (int)cache.metrics().getCachePuts();
+                int cacheWrites = (int)cache.mxBean().getCachePuts();
 
                 assertEquals("Wrong cache metrics [i=" + i + ", grid=" + j + ']', i + 1,
cacheWrites);
             }
@@ -561,7 +592,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         int misses = 0;
 
         for (int i = 0; i < gridCount(); i++) {
-            CacheMetrics m = grid(i).cache(null).metrics();
+            CacheMetrics m = grid(i).cache(null).mxBean();
 
             puts += m.getCachePuts();
             reads += m.getCacheGets();
@@ -589,12 +620,12 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         for (int i = 0; i < keyCnt; i++) {
             cache0.getAndPut(i, i); // +1 read
 
-            info("Puts: " + cache0.metrics().getCachePuts());
+            info("Puts: " + cache0.mxBean().getCachePuts());
 
             for (int j = 0; j < gridCount(); j++) {
                 IgniteCache<Integer, Integer> cache = grid(j).cache(null);
 
-                long cacheWrites = cache.metrics().getCachePuts();
+                long cacheWrites = cache.mxBean().getCachePuts();
 
                 assertEquals("Wrong cache metrics [i=" + i + ", grid=" + j + ']', i + 1,
cacheWrites);
             }
@@ -606,6 +637,14 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         for (int i = 0; i < gridCount(); i++) {
             CacheMetrics m = grid(i).cache(null).metrics();
 
+            GridTestUtils.waitForCondition(
+                new GridAbsPredicate() {
+                    @Override public boolean apply() {
+                        return m.getCachePuts() == keyCnt * 2;
+                    }
+                },
+                20_000);
+
             assertEquals(m.getCacheHits() * 100f / m.getCacheGets(), m.getCacheHitPercentage(),
0.1f);
             assertEquals(m.getCacheMisses() * 100f / m.getCacheGets(), m.getCacheMissPercentage(),
0.1f);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a2da/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTransactionalAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --git 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
index 4bd4c59..3160965 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
@@ -231,7 +231,7 @@ public abstract class GridCacheTransactionalAbstractMetricsSelfTest extends
Grid
 
         for (int i = 0; i < gridCount(); i++) {
             TransactionMetrics metrics = grid(i).transactions().metrics();
-            CacheMetrics cacheMetrics = grid(i).cache(null).metrics();
+            CacheMetrics cacheMetrics = grid(i).cache(null).mxBean();
 
             if (i == 0) {
                 assertEquals(TX_CNT, metrics.txCommits());


Mime
View raw message