Source:
public void test() throws InterruptedException, IOException { CacheManager cacheManager = null; try { DefaultManagementRegistryConfiguration registryConfiguration = new DefaultManagementRegistryConfiguration().setCacheManagerAlias("myCacheManager"); registryConfiguration.addConfiguration(new EhcacheStatisticsProviderConfiguration(1,TimeUnit.MINUTES,100,1,TimeUnit.MILLISECONDS,10,TimeUnit.MINUTES)); ManagementRegistryService managementRegistry = new DefaultManagementRegistryService(registryConfiguration); CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, resources).build(); cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .withCache("myCache", cacheConfiguration) .using(managementRegistry) .using(new DefaultPersistenceConfiguration(diskPath.newFolder())) .build(true); Cache<Long, String> cache = cacheManager.getCache("myCache", Long.class, String.class); Context context = StatsUtil.createContext(managementRegistry); StatsUtil.triggerStatComputation(managementRegistry, context, "OnHeap:MissRate","OffHeap:MissRate","Disk:MissRate","Cache:MissRate"); cache.put(1L, "one"); cache.put(2L, "two"); cache.put(3L, "three"); cache.get(4L); cache.get(5L); cache.get(6L); for (int i = 0; i < statNames.size(); i++) { double tierMissRate = StatsUtil.getExpectedValueFromRateHistory(statNames.get(i), context, managementRegistry, tierExpectedValues.get(i)); Assert.assertThat(tierMissRate, is(tierExpectedValues.get(i))); } double cacheMissRate = StatsUtil.getExpectedValueFromRateHistory("Cache:MissRate", context, managementRegistry, CACHE_MISS_RATE); Assert.assertThat(cacheMissRate, is(cacheExpectedValue)); } finally { if(cacheManager != null) { cacheManager.close(); } } }

Target:
public void test() throws InterruptedException, IOException { CacheManager cacheManager = null; try { DefaultManagementRegistryConfiguration registryConfiguration = new DefaultManagementRegistryConfiguration().setCacheManagerAlias("myCacheManager"); registryConfiguration.addConfiguration(EHCACHE_STATISTICS_PROVIDER_CONFIG); ManagementRegistryService managementRegistry = new DefaultManagementRegistryService(registryConfiguration); CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, resources).build(); cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .withCache("myCache", cacheConfiguration) .using(managementRegistry) .using(new DefaultPersistenceConfiguration(diskPath.newFolder())) .build(true); Cache<Long, String> cache = cacheManager.getCache("myCache", Long.class, String.class); Context context = StatsUtil.createContext(managementRegistry); StatsUtil.triggerStatComputation(managementRegistry, context, "OnHeap:MissRate","OffHeap:MissRate","Disk:MissRate","Cache:MissRate"); cache.put(1L, "one"); cache.put(2L, "two"); cache.put(3L, "three"); cache.get(4L); cache.get(5L); cache.get(6L); for (int i = 0; i < statNames.size(); i++) { StatsUtil.getAndAssertExpectedValueFromRateHistory(statNames.get(i), context, managementRegistry, tierExpectedValues.get(i)); } StatsUtil.getAndAssertExpectedValueFromRateHistory("Cache:MissRate", context, managementRegistry, CACHE_MISS_RATE); } finally { if(cacheManager != null) { cacheManager.close(); } } }