mgr1.enableStatistics(CACHE1, true); mgr2.enableStatistics(CACHE2, false);
/** * Test enableStatistics command on JCache API <br> * <br> * Fix pending in <b>ISPN-7095</b> */ @Test @Ignore("Ignored until ISPN-7095") public void testEnableStatistics() throws Exception { ObjectName mBeanName = getMBeanName(enableStatisticsTestCacheName, "Statistics"); cacheManager.enableStatistics(enableStatisticsTestCacheName, true); assertTrue("Statistics register as disabled after enabling", mBeanServer.isRegistered(mBeanName)); cacheManager.enableStatistics(enableStatisticsTestCacheName, false); assertFalse("Statistics register as enabled after disabling", mBeanServer.isRegistered(mBeanName)); }
@Override @SuppressWarnings("unchecked") public Cache<K, V> build(CacheManager manager) { checkNotNull(manager); checkNotNull(keyType); checkNotNull(valueType); checkNotNull(name); checkNotNull(expiryFactory); CacheConfigurationBuilder<K, V> builder = CacheConfigurationBuilder.newCacheConfigurationBuilder( keyType, valueType, ResourcePoolsBuilder.heap(cacheSize)); builder.withExpiry(mapToEhCacheExpiry(expiryFactory.create())); Cache<K, V> cache = manager.createCache(name, Eh107Configuration.fromEhcacheCacheConfiguration(builder)); manager.enableStatistics(name, statisticsEnabled); manager.enableManagement(name, managementEnabled); if (persister != null) { CacheEventListener listener = (final CacheEvent cacheEvent) -> persister.accept((K) cacheEvent.getKey(), (V) cacheEvent.getOldValue()); Eh107Configuration<K, V> configuration = cache.getConfiguration(Eh107Configuration.class); configuration.unwrap(CacheRuntimeConfiguration.class) .registerCacheEventListener(listener, EventOrdering.UNORDERED, EventFiring.ASYNCHRONOUS, EventType.EVICTED, EventType.REMOVED, EventType.EXPIRED); } return cache; }
@Test public void testDoubleRegistration() throws MalformedObjectNameException { cacheManager.createCache("new cache", configuration); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2)); cacheManager.enableStatistics("new cache", true); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2)); }
@Test(expected = NullPointerException.class) public void enableStatistics_nullCacheName() { CacheManager cacheManager = getCacheManager(); final String NULL_CACHE_NAME = null; cacheManager.enableStatistics(NULL_CACHE_NAME, true); fail(); }
@Before public void moreSetUp() { cache = getCacheManager().getCache(getTestCacheName(), Long.class, String.class); cache.getCacheManager().enableStatistics(cache.getName(), true); statisticsUpdateTimeoutMillis = Integer.valueOf(System.getProperty(STATISTICS_UPDATE_TIMEOUT_PROPERTY, DEFAULT_STATISTICS_UPDATE_TIMEOUT_SECONDS)); }
@Test public void testCacheStatisticsOffThenOnThenOff() throws Exception { MutableConfiguration configuration = new MutableConfiguration(); configuration.setStatisticsEnabled(false); cacheManager.createCache("cache1", configuration); cacheManager.createCache("cache2", configuration); Set<? extends ObjectName> names = mBeanServer.queryNames(new ObjectName("javax.cache:*"), null); Assert.assertTrue(names.size() == 0); configuration.setStatisticsEnabled(true); cacheManager.createCache("cache3", configuration); cacheManager.createCache("cache4", configuration); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2)); cacheManager.enableStatistics("cache3", false); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(1)); cacheManager.enableStatistics("cache3", true); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2)); }
@Test(expected = IllegalStateException.class) public void enableStatistics_managerStopped() { CacheManager cacheManager = getCacheManager(); cacheManager.close(); cacheManager.enableStatistics("notThere", true); fail(); }
@Before public void moreSetUp() { cache = getCacheManager().getCache(getTestCacheName(), Long.class, String.class); cache.getCacheManager().enableStatistics(cache.getName(), true); cache.getCacheManager().enableManagement(cache.getName(), true); }