/** * Test statistics enabling/disabling/clearing * * @throws InterruptedException */ @Test public void testCacheUsageStatistics() throws InterruptedException { // Set size so the second element overflows to disk. Cache cache = new Cache("test", 1, true, false, 5, 2); manager.addCache(cache); // add as a listener AnotherStatistics anotherStats = new AnotherStatistics(); cache.registerCacheUsageListener(anotherStats); cache.setStatisticsEnabled(true); doTestCacheUsageStatistics(cache, true, anotherStats); // test enable/disable statistics cache.setStatisticsEnabled(false); doTestCacheUsageStatistics(cache, false, anotherStats); // remove the listener cache.removeCacheUsageListener(anotherStats); // enable statistics but don't check stats as no longer a listener cache.setStatisticsEnabled(true); doTestCacheUsageStatistics(cache, false, anotherStats); assertEquals( Statistics.STATISTICS_ACCURACY_BEST_EFFORT, cache.getLiveCacheStatistics().getStatisticsAccuracy()); assertEquals("Best Effort", cache.getLiveCacheStatistics().getStatisticsAccuracyDescription()); }
/** CacheStatistics should always be sensible when the cache has not started. */ @Test public void testCacheAlive() { Cache cache = new Cache("test", 1, true, false, 5, 2); String string = cache.toString(); assertTrue(string.contains("test")); try { LiveCacheStatistics statistics = cache.getLiveCacheStatistics(); fail(); } catch (IllegalStateException e) { assertEquals("The test Cache is not alive (STATUS_UNINITIALISED)", e.getMessage()); } // initialize cache now manager.addCache(cache); // add as a listener AnotherStatistics anotherStats = new AnotherStatistics(); cache.registerCacheUsageListener(anotherStats); assertEquals(0, anotherStats.getCacheHitCount()); }
public LiveCacheStatistics getLiveCacheStatistics() { return cache.getLiveCacheStatistics(); }