use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testInsertSame.
@Test
public void testInsertSame() {
// 100 KB, .5 sec expire
Cache cache = new Cache(100 * 1024, 500, 100000, Statistics.nullImplementation);
Query q = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
Result r = getSomeResult(q, "foo");
QueryCacheKey k = new QueryCacheKey(q);
cache.put(k, r);
assertEquals(1, cache.size());
q = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
k = new QueryCacheKey(q);
cache.put(k, r);
assertEquals(1, cache.size());
}
use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testInvalidateLRU.
@Test
public void testInvalidateLRU() {
// 10 MB
Cache cache = new Cache(10 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
byte[] fiveKB = new byte[5 * 1024];
for (int i = 0; i < 5 * 1024; i++) {
fiveKB[i] = 127;
}
byte[] twoKB = new byte[2 * 1024];
for (int i = 0; i < 2 * 1024; i++) {
twoKB[i] = 127;
}
byte[] fourKB = new byte[4 * 1024];
for (int i = 0; i < 4 * 1024; i++) {
fourKB[i] = 127;
}
assertTrue(cache.put("five", fiveKB));
assertTrue(cache.put("two", twoKB));
// Makes two LRU
Object dummy = cache.get("five");
assertEquals(dummy, fiveKB);
assertTrue(cache.put("four", fourKB));
assertNull(cache.get("two"));
assertEquals(cache.get("five"), fiveKB);
assertEquals(cache.get("four"), fourKB);
// Same, without the access, just to check
// 10 KB
cache = new Cache(10 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
assertTrue(cache.put("five", fiveKB));
assertTrue(cache.put("two", twoKB));
assertTrue(cache.put("four", fourKB));
assertEquals(cache.get("two"), twoKB);
assertNull(cache.get("five"));
assertEquals(cache.get("four"), fourKB);
}
use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testPutSameKey.
@Test
public void testPutSameKey() {
// 10 MB
Cache cache = new Cache(10 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
byte[] fiveKB = new byte[5 * 1024];
for (int i = 0; i < 5 * 1024; i++) {
fiveKB[i] = 127;
}
byte[] twoKB = new byte[2 * 1024];
for (int i = 0; i < 2 * 1024; i++) {
twoKB[i] = 127;
}
byte[] fourKB = new byte[4 * 1024];
for (int i = 0; i < 4 * 1024; i++) {
fourKB[i] = 127;
}
assertTrue(cache.put("five", fiveKB));
assertTrue(cache.put("two", twoKB));
assertEquals(cache.get("two"), twoKB);
assertEquals(cache.get("five"), fiveKB);
assertTrue(cache.put("five", twoKB));
assertEquals(cache.get("five"), twoKB);
assertEquals(cache.get("two"), twoKB);
}
use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testMaxSize.
@Test
public void testMaxSize() {
Cache cache = new Cache(20 * 1024, 500, 3 * 1024, Statistics.nullImplementation);
byte[] fourKB = new byte[4 * 1024];
for (int i = 0; i < 4 * 1024; i++) {
fourKB[i] = 127;
}
byte[] twoKB = new byte[2 * 1024];
for (int i = 0; i < 2 * 1024; i++) {
twoKB[i] = 127;
}
assertFalse(cache.put("four", fourKB));
assertTrue(cache.put("two", twoKB));
assertNull(cache.get("four"));
assertNotNull(cache.get("two"));
}
use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testInvalidate.
@Test
public void testInvalidate() {
byte[] tenKB = new byte[10 * 1024];
for (int i = 0; i < 10 * 1024; i++) {
tenKB[i] = 127;
}
byte[] sevenKB = new byte[7 * 1024];
for (int i = 0; i < 7 * 1024; i++) {
sevenKB[i] = 127;
}
// 11 KB
Cache cache = new Cache(11 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
assertTrue(cache.put("foo", sevenKB));
assertTrue(cache.put("bar", tenKB));
assertNull(cache.get("foo"));
assertEquals(cache.get("bar"), tenKB);
}
Aggregations