/** {@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(); } }
/** * */ @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(); } }