implement cache statistics

This commit is contained in:
Sebastian Sdorra
2014-02-19 20:56:14 +01:00
parent 5715851ff1
commit ac88e1f651
6 changed files with 351 additions and 5 deletions

View File

@@ -46,6 +46,7 @@ import sonia.scm.util.IOUtil;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.junit.Assume;
/**
*
@@ -180,6 +181,30 @@ public abstract class CacheTestBase
assertNotNull(cache.get("a-1"));
assertNotNull(cache.get("a-2"));
}
@Test
public void testCacheStatistics(){
CacheStatistics stats = cache.getStatistics();
// skip test if implementation does not support stats
Assume.assumeTrue( stats != null );
assertEquals("test", stats.getName());
assertEquals(0l, stats.getHitCount());
assertEquals(0l, stats.getMissCount());
cache.put("test-1", "test123");
cache.put("test-2", "test456");
cache.get("test-1");
cache.get("test-1");
cache.get("test-1");
cache.get("test-3");
// check that stats have not changed
assertEquals(0l, stats.getHitCount());
assertEquals(0l, stats.getMissCount());
stats = cache.getStatistics();
assertEquals(3l, stats.getHitCount());
assertEquals(1l, stats.getMissCount());
assertEquals(0.75d, stats.getHitRate(), 0.0d);
assertEquals(0.25d, stats.getMissRate(), 0.0d);
}
/**
* Method description