Source:
public void test() throws InterruptedException, IOException { 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); Configuration cacheConfiguration = new DefaultConfiguration(EvictionTest.class.getClassLoader(), new DefaultPersistenceConfiguration(diskPath.newFolder())); Collection<Service> services = new ArrayList<Service>(); services.add(managementRegistry); CacheManager cacheManager = null; try { cacheManager = new EhcacheManager(cacheConfiguration, services); CacheConfiguration<Long, String> cacheConfig = newCacheConfigurationBuilder(Long.class, String.class, resources).build(); cacheManager.init(); Cache<Long, String> cache = cacheManager.createCache("myCache", cacheConfig); cache.put(1L, "1"); cache.put(2L, "2"); cache.put(3L, "3"); cache.get(4L); cache.get(5L); Context context = StatsUtil.createContext(managementRegistry); long tierMissCountSum = 0; for (int i = 0; i < statNames.size(); i++) { tierMissCountSum += StatsUtil.getExpectedValueFromCounterHistory(statNames.get(i), context, managementRegistry, tierExpectedValues.get(i)); } long cacheMissCount = StatsUtil.getExpectedValueFromCounterHistory("Cache:MissCount", context, managementRegistry, cacheExpectedValue); Assert.assertThat(tierMissCountSum/statNames.size(), is(cacheMissCount)); } 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(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); cache.put(1L, "1"); cache.put(2L, "2"); cache.put(3L, "3"); cache.get(4L); cache.get(5L); Context context = StatsUtil.createContext(managementRegistry); long tierMissCountSum = 0; for (int i = 0; i < statNames.size(); i++) { tierMissCountSum += StatsUtil.getExpectedValueFromCounterHistory(statNames.get(i), context, managementRegistry, tierExpectedValues.get(i)); } long cacheMissCount = StatsUtil.getExpectedValueFromCounterHistory("Cache:MissCount", context, managementRegistry, cacheExpectedValue); Assert.assertThat(tierMissCountSum/statNames.size(), is(cacheMissCount)); } finally { if(cacheManager != null) { cacheManager.close(); } } }