ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntikho...@apache.org
Subject ignite git commit: Fixed "IGNITE-6483 Tests for availability of metrics in MX beans". This closes #2806.
Date Mon, 09 Oct 2017 13:36:21 GMT
Repository: ignite
Updated Branches:
  refs/heads/master a45677cf0 -> 218416c3a


Fixed "IGNITE-6483 Tests for availability of metrics in MX beans". This closes #2806.

Signed-off-by: nikolay_tikhonov <ntikhonov@gridgain.com>


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

Branch: refs/heads/master
Commit: 218416c3a432040253cf0bfcb193fc33f02b804b
Parents: a45677c
Author: Ilya Kasnacheev <ilya.kasnacheev@gmail.com>
Authored: Mon Oct 9 16:36:07 2017 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Mon Oct 9 16:36:07 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/CacheMetricsImpl.java      |   2 +-
 .../CacheMetricsForClusterGroupSelfTest.java    | 119 ++++++++++++-------
 ...heapCacheMetricsForClusterGroupSelfTest.java |  19 ++-
 3 files changed, 96 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/218416c3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
index 413b60d..7d9cda8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheMetricsImpl.java
@@ -227,7 +227,7 @@ public class CacheMetricsImpl implements CacheMetrics {
     /** {@inheritDoc} */
     @Override public long getHeapEntriesCount() {
         try {
-            return cctx.cache().localSize(ONHEAP_PEEK_MODES);
+            return cctx.cache().localSizeLong(ONHEAP_PEEK_MODES);
         }
         catch (IgniteCheckedException ignored) {
             return 0;

http://git-wip-us.apache.org/repos/asf/ignite/blob/218416c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
index ee8aa8a..aefbc23 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMetricsForClusterGroupSelfTest.java
@@ -91,26 +91,29 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCommonAbstractTest
     public void testMetricsStatisticsEnabled() throws Exception {
         createCaches(true);
 
-        populateCacheData(cache1, ENTRY_CNT_CACHE1);
-        populateCacheData(cache2, ENTRY_CNT_CACHE2);
+        try {
+            populateCacheData(cache1, ENTRY_CNT_CACHE1);
+            populateCacheData(cache2, ENTRY_CNT_CACHE2);
 
-        readCacheData(cache1, ENTRY_CNT_CACHE1);
-        readCacheData(cache2, ENTRY_CNT_CACHE2);
+            readCacheData(cache1, ENTRY_CNT_CACHE1);
+            readCacheData(cache2, ENTRY_CNT_CACHE2);
 
-        awaitMetricsUpdate();
+            awaitMetricsUpdate();
 
-        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
+            Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
 
-        for (ClusterNode node : nodes) {
-            Map<Integer, CacheMetrics> metrics = ((TcpDiscoveryNode) node).cacheMetrics();
-            assertNotNull(metrics);
-            assertFalse(metrics.isEmpty());
-        }
-
-        assertMetrics(cache1);
-        assertMetrics(cache2);
+            for (ClusterNode node : nodes) {
+                Map<Integer, CacheMetrics> metrics = ((TcpDiscoveryNode)node).cacheMetrics();
+                assertNotNull(metrics);
+                assertFalse(metrics.isEmpty());
+            }
 
-        destroyCaches();
+            assertMetrics(cache1, true);
+            assertMetrics(cache2, true);
+        }
+        finally {
+            destroyCaches();
+        }
     }
 
     /**
@@ -119,26 +122,29 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCommonAbstractTest
     public void testMetricsStatisticsDisabled() throws Exception {
         createCaches(false);
 
-        populateCacheData(cache1, ENTRY_CNT_CACHE1);
-        populateCacheData(cache2, ENTRY_CNT_CACHE2);
+        try {
+            populateCacheData(cache1, ENTRY_CNT_CACHE1);
+            populateCacheData(cache2, ENTRY_CNT_CACHE2);
 
-        readCacheData(cache1, ENTRY_CNT_CACHE1);
-        readCacheData(cache2, ENTRY_CNT_CACHE2);
+            readCacheData(cache1, ENTRY_CNT_CACHE1);
+            readCacheData(cache2, ENTRY_CNT_CACHE2);
 
-        awaitMetricsUpdate();
+            awaitMetricsUpdate();
 
-        Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
+            Collection<ClusterNode> nodes = grid(0).cluster().forRemotes().nodes();
 
-        for (ClusterNode node : nodes) {
-            Map<Integer, CacheMetrics> metrics = ((TcpDiscoveryNode) node).cacheMetrics();
-            assertNotNull(metrics);
-            assertTrue(metrics.isEmpty());
-        }
-
-        assertMetrics(cache1);
-        assertMetrics(cache2);
+            for (ClusterNode node : nodes) {
+                Map<Integer, CacheMetrics> metrics = ((TcpDiscoveryNode) node).cacheMetrics();
+                assertNotNull(metrics);
+                assertTrue(metrics.isEmpty());
+            }
 
-        destroyCaches();
+            assertMetrics(cache1, false);
+            assertMetrics(cache2, false);
+        }
+        finally {
+            destroyCaches();
+        }
     }
 
     /**
@@ -200,13 +206,13 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCommonAbstractTest
      */
     private void readCacheData(IgniteCache<Integer, Integer> cache, int cnt) {
         for (int i = 0; i < cnt; i++)
-            cache.get(i);
+            grid(i % GRID_CNT).cache(cache.getName()).get(i);
     }
 
     /**
      * @param cache Cache.
      */
-    private void assertMetrics(IgniteCache<Integer, Integer> cache) {
+    private void assertMetrics(IgniteCache<Integer, Integer> cache, boolean expectNonZero)
{
         CacheMetrics[] ms = new CacheMetrics[GRID_CNT];
 
         for (int i = 0; i < GRID_CNT; i++) {
@@ -220,36 +226,65 @@ public class CacheMetricsForClusterGroupSelfTest extends GridCommonAbstractTest
                 assertEquals(metrics.name(), ms[j].name());
 
             // Dynamic metrics
-            assertEquals(metrics.getCacheGets(), sum(ms, new IgniteClosure<CacheMetrics,
Long>() {
+            long sumGets = sum(ms, new IgniteClosure<CacheMetrics, Long>() {
                 @Override public Long apply(CacheMetrics input) {
                     return input.getCacheGets();
                 }
-            }));
+            }, expectNonZero);
+
+            assertEquals(metrics.getCacheGets(), sumGets);
+            assertEquals(cache.mxBean().getCacheGets(), sumGets);
 
-            assertEquals(metrics.getCachePuts(), sum(ms, new IgniteClosure<CacheMetrics,
Long>() {
+            long sumPuts = sum(ms, new IgniteClosure<CacheMetrics, Long>() {
                 @Override public Long apply(CacheMetrics input) {
                     return input.getCachePuts();
                 }
-            }));
+            }, expectNonZero);
 
-            assertEquals(metrics.getCacheHits(), sum(ms, new IgniteClosure<CacheMetrics,
Long>() {
+            assertEquals(metrics.getCachePuts(), sumPuts);
+            assertEquals(cache.mxBean().getCachePuts(), sumPuts);
+
+            long sumHits = sum(ms, new IgniteClosure<CacheMetrics, Long>() {
                 @Override public Long apply(CacheMetrics input) {
                     return input.getCacheHits();
                 }
-            }));
+            }, expectNonZero);
+
+            assertEquals(metrics.getCacheHits(), sumHits);
+            assertEquals(cache.mxBean().getCacheHits(), sumHits);
+
+            if (expectNonZero) {
+                long sumHeapEntries = sum(ms, new IgniteClosure<CacheMetrics, Long>()
{
+                    @Override public Long apply(CacheMetrics input) {
+                        return input.getHeapEntriesCount();
+                    }
+                    // Currently non-zero even when statistics is off
+                }, true);
+
+                assertEquals(metrics.getHeapEntriesCount(), sumHeapEntries);
+                assertEquals(cache.mxBean().getHeapEntriesCount(), sumHeapEntries);
+            }
+
         }
     }
 
     /**
      * @param ms Milliseconds.
      * @param f Function.
+     * @param expectNonZero Check if each value is non-zero.
      */
-    private long sum(CacheMetrics[] ms, IgniteClosure<CacheMetrics, Long> f) {
+    private long sum(CacheMetrics[] ms, IgniteClosure<CacheMetrics, Long> f, boolean
expectNonZero) {
         long res = 0;
 
-        for (int i = 0; i < GRID_CNT; i++)
-            res += f.apply(ms[i]);
+        for (int i = 0; i < GRID_CNT; i++) {
+            long val = f.apply(ms[i]);
+
+            if (expectNonZero)
+                assertTrue(val > 0);
+
+            res += val;
+        }
 
         return res;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/218416c3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffheapCacheMetricsForClusterGroupSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffheapCacheMetricsForClusterGroupSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffheapCacheMetricsForClusterGroupSelfTest.java
index a3d3130..e13f99b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffheapCacheMetricsForClusterGroupSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/OffheapCacheMetricsForClusterGroupSelfTest.java
@@ -117,14 +117,31 @@ public class OffheapCacheMetricsForClusterGroupSelfTest extends GridCommonAbstra
     }
 
     private void assertGetOffHeapPrimaryEntriesCount(String cacheName, int count) throws
Exception {
+        long localPrimary = 0L;
+        long localBackups = 0L;
+
         for (int i = 0; i < GRID_CNT; i++) {
             IgniteCache<Integer, Integer> cache = grid("server-" + i).cache(cacheName);
             assertEquals(count, cache.metrics().getOffHeapPrimaryEntriesCount());
+            assertEquals(count, cache.mxBean().getOffHeapPrimaryEntriesCount());
+            assertEquals(count, cache.metrics().getOffHeapBackupEntriesCount());
+            assertEquals(count, cache.mxBean().getOffHeapBackupEntriesCount());
+
+            localPrimary += cache.localMxBean().getOffHeapPrimaryEntriesCount();
+            localBackups += cache.localMxBean().getOffHeapPrimaryEntriesCount();
         }
 
+        assertEquals(count, localPrimary);
+        assertEquals(count, localBackups);
+
         for (int i = 0; i < CLIENT_CNT; i++) {
             IgniteCache<Integer, Integer> cache = grid("client-" + i).cache(cacheName);
             assertEquals(count, cache.metrics().getOffHeapPrimaryEntriesCount());
+            assertEquals(count, cache.mxBean().getOffHeapPrimaryEntriesCount());
+            assertEquals(count, cache.metrics().getOffHeapBackupEntriesCount());
+            assertEquals(count, cache.mxBean().getOffHeapBackupEntriesCount());
+            assertEquals(0L, cache.localMxBean().getOffHeapPrimaryEntriesCount());
+            assertEquals(0L, cache.localMxBean().getOffHeapBackupEntriesCount());
         }
     }
 
@@ -135,4 +152,4 @@ public class OffheapCacheMetricsForClusterGroupSelfTest extends GridCommonAbstra
         cfg.setStatisticsEnabled(true);
         return cfg;
     }
-}
\ No newline at end of file
+}


Mime
View raw message