/** {@inheritDoc} */ @Override protected Void run(VisorCacheResetMetricsTaskArg arg) { IgniteInternalCache cache = ignite.cachex(arg.getCacheName()); if (cache != null) cache.localMxBean().clear(); return null; }
@Override public boolean apply() { boolean res = true; IgniteCache<?, ?> cache = ig.cache(cacheName); try { assertEquals("CachePuts", 0L, cache.mxBean().getCachePuts()); assertEquals("CacheHits", 0L, cache.mxBean().getCacheHits()); assertEquals("CacheGets", 0L, cache.mxBean().getCacheGets()); assertEquals("CacheRemovals", 0L, cache.mxBean().getCacheRemovals()); assertEquals("CacheMisses", 0L, cache.mxBean().getCacheMisses()); assertEquals("AverageGetTime", 0f, cache.mxBean().getAveragePutTime()); assertEquals("AveragePutTime", 0f, cache.mxBean().getAverageGetTime()); assertEquals("AverageRemoveTime", 0f, cache.mxBean().getAverageRemoveTime()); } catch (AssertionError e) { log.warning(e.toString()); res = false; } return res; } }, WAIT_CONDITION_TIMEOUT));
assertEquals(cache.mxBean().getCacheGets(), sumGets); assertEquals(cache.mxBean().getCachePuts(), sumPuts); assertEquals(cache.mxBean().getCacheHits(), sumHits); assertEquals(cache.mxBean().getHeapEntriesCount(), sumHeapEntries);
/** * Asserts that only local metrics are updating. * * @param cacheName Cache name. */ private void assertOnlyLocalMetricsUpdating(String cacheName) { for (int i = 0; i < GRID_CNT; i++) { IgniteCache cache = grid(i).cache(cacheName); CacheMetrics clusterMetrics = cache.metrics(grid(i).cluster().forCacheNodes(cacheName)); CacheMetrics locMetrics = cache.localMetrics(); assertEquals(clusterMetrics.name(), locMetrics.name()); assertEquals(0L, clusterMetrics.getCacheGets()); assertEquals(0L, cache.mxBean().getCacheGets()); assertEquals(locMetrics.getCacheGets(), cache.localMxBean().getCacheGets()); assertEquals(0L, clusterMetrics.getCachePuts()); assertEquals(0L, cache.mxBean().getCachePuts()); assertEquals(locMetrics.getCachePuts(), cache.localMxBean().getCachePuts()); assertEquals(0L, clusterMetrics.getCacheHits()); assertEquals(0L, cache.mxBean().getCacheHits()); assertEquals(locMetrics.getCacheHits(), cache.localMxBean().getCacheHits()); } }
/** * Cache statistics clear message received. * * @param msg Message. */ private void onCacheStatisticsClear(CacheStatisticsClearMessage msg) { assert msg != null; if (msg.initial()) { EnableStatisticsFuture fut = manageStatisticsFuts.get(msg.requestId()); if (fut != null && !cacheNames().containsAll(msg.caches())) { fut.onDone(new IgniteCheckedException("One or more cache descriptors not found [caches=" + caches + ']')); return; } for (String cacheName : msg.caches()) { IgniteInternalCache<?, ?> cache = ctx.cache().cache(cacheName); if (cache != null) cache.localMxBean().clear(); else log.warning("Failed to clear cache statistics, cache not found [cacheName=" + cacheName + ']'); } } else { EnableStatisticsFuture fut = manageStatisticsFuts.get(msg.requestId()); if (fut != null) fut.onDone(); } }
/** * */ @Test public void testJmxApiClearStatistics() throws Exception { startGrids(3); IgniteCache<Integer, String> cache = grid(0).cache(CACHE1); cache.enableStatistics(true); incrementCacheStatistics(cache); mxBean(0, CACHE1, CacheClusterMetricsMXBeanImpl.class).clear(); assertCacheStatisticsIsClear(Collections.singleton(CACHE1)); }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { super.afterTest(); for (int i = 0; i < gridCount(); i++) { Ignite g = grid(i); g.cache(DEFAULT_CACHE_NAME).removeAll(); assert g.cache(DEFAULT_CACHE_NAME).localSize() == 0; g.cache(DEFAULT_CACHE_NAME).localMxBean().clear(); } }
/** * @throws Exception If failed. */ @Test public void testMetrics() throws Exception { grid().cache(DEFAULT_CACHE_NAME).localMxBean().clear(); grid().cache(CACHE_NAME).localMxBean().clear(); grid().cache(DEFAULT_CACHE_NAME).put("key1", "val"); grid().cache(DEFAULT_CACHE_NAME).put("key2", "val"); grid().cache(DEFAULT_CACHE_NAME).put("key2", "val"); grid().cache(DEFAULT_CACHE_NAME).get("key1"); grid().cache(DEFAULT_CACHE_NAME).get("key2"); grid().cache(DEFAULT_CACHE_NAME).get("key2"); grid().cache(CACHE_NAME).put("key1", "val"); grid().cache(CACHE_NAME).put("key2", "val"); grid().cache(CACHE_NAME).put("key2", "val"); grid().cache(CACHE_NAME).get("key1"); grid().cache(CACHE_NAME).get("key2"); grid().cache(CACHE_NAME).get("key2"); Map<String, Long> m = client.cacheMetrics(null); assertNotNull(m); assertEquals(4, m.size()); assertEquals(3, m.get("reads").longValue()); assertEquals(3, m.get("writes").longValue()); m = client.cacheMetrics(CACHE_NAME); assertNotNull(m); assertEquals(4, m.size()); assertEquals(3, m.get("reads").longValue()); assertEquals(3, m.get("writes").longValue()); }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { super.afterTest(); for (int i = 0; i < gridCount(); i++) { Ignite g = grid(i); g.cache(DEFAULT_CACHE_NAME).removeAll(); assert g.cache(DEFAULT_CACHE_NAME).localSize() == 0; } for (int i = 0; i < gridCount(); i++) { Ignite g = grid(i); g.cache(DEFAULT_CACHE_NAME).localMxBean().clear(); g.transactions().resetMetrics(); } }
g.cache(DEFAULT_CACHE_NAME).mxBean().clear();
/** {@inheritDoc} */ @Override protected Void run(VisorCacheResetMetricsTaskArg arg) { IgniteInternalCache cache = ignite.cachex(arg.getCacheName()); if (cache != null) cache.localMxBean().clear(); return null; }
/** * Cache statistics clear message received. * * @param msg Message. */ private void onCacheStatisticsClear(CacheStatisticsClearMessage msg) { assert msg != null; if (msg.initial()) { EnableStatisticsFuture fut = manageStatisticsFuts.get(msg.requestId()); if (fut != null && !cacheNames().containsAll(msg.caches())) { fut.onDone(new IgniteCheckedException("One or more cache descriptors not found [caches=" + caches + ']')); return; } for (String cacheName : msg.caches()) { IgniteInternalCache<?, ?> cache = ctx.cache().cache(cacheName); if (cache != null) cache.localMxBean().clear(); else log.warning("Failed to clear cache statistics, cache not found [cacheName=" + cacheName + ']'); } } else { EnableStatisticsFuture fut = manageStatisticsFuts.get(msg.requestId()); if (fut != null) fut.onDone(); } }