#314 - ServerCache API - change from int to long for ServerCacheStatistics (hitCount, missCount) and ServerCache remove putIfAbsent() method

This commit is contained in:
rbygrave
2015-06-30 00:56:11 +12:00
parent 9e3362d004
commit 49babef495
8 changed files with 631 additions and 377 deletions
@@ -0,0 +1,59 @@
package com.avaje.ebeaninternal.server.cache;
import com.avaje.ebean.cache.ServerCacheOptions;
import org.junit.Test;
import static org.junit.Assert.*;
public class DefaultServerCacheTest {
private DefaultServerCache createCache() {
ServerCacheOptions cacheOptions = new ServerCacheOptions();
cacheOptions.setMaxSize(100);
cacheOptions.setMaxIdleSecs(60);
cacheOptions.setMaxSecsToLive(600);
cacheOptions.setTrimFrequency(60);
return new DefaultServerCache("foo", cacheOptions);
}
@Test
public void testGetHitRatio() throws Exception {
DefaultServerCache cache = createCache();
assertEquals(0, cache.getHitRatio());
cache.put("A", "A");
cache.get("A");
assertEquals(100, cache.getHitRatio());
cache.get("B");
assertEquals(50, cache.getHitRatio());
cache.get("B");
cache.get("B");
assertEquals(25, cache.getHitRatio());
}
@Test
public void testSize() throws Exception {
DefaultServerCache cache = createCache();
assertEquals(0, cache.size());
cache.put("A", "A");
assertEquals(1, cache.size());
cache.put("A", "B");
assertEquals(1, cache.size());
cache.put("B", "B");
assertEquals(2, cache.size());
cache.remove("B");
cache.remove("A");
assertEquals(0, cache.size());
}
@Test
public void testGetTrimSize() throws Exception {
DefaultServerCache cache = createCache();
assertEquals(90, cache.getTrimSize());
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ public class TestCacheBasic extends BaseTestCase {
Country c0 = Ebean.getReference(Country.class, "NZ");
ServerCacheStatistics statistics = countryCache.getStatistics(false);
int hc = statistics.getHitCount();
long hc = statistics.getHitCount();
Assert.assertEquals(1, hc);
Assert.assertNotNull(c0);