use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testExpire.
@Test
public void testExpire() throws InterruptedException {
// 10 KB, 50ms expire
Cache cache = new Cache(10 * 1024, 50, 10000, Statistics.nullImplementation);
boolean success = false;
for (int tries = 0; tries < 10; tries++) {
long before = System.currentTimeMillis();
cache.put("foo", "bar");
cache.put("hey", "ho");
Object got1 = cache.get("foo");
Object got2 = cache.get("hey");
long after = System.currentTimeMillis();
if (after - before < 50) {
assertEquals(got1, "bar");
assertEquals(got2, "ho");
success = true;
break;
}
}
assertTrue(success);
Thread.sleep(100);
assertNull(cache.get("foo"));
assertNull(cache.get("hey"));
}
use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testBasicGet.
@Test
public void testBasicGet() {
Cache<QueryCacheKey, Result> cache = new Cache<>(100 * 1024, 3600, 100000, Statistics.nullImplementation);
Query q = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
Query q2 = new Query("/std_xmls_a00?hits=5&offset=5&query=flowers+shop&tracelevel=4&objid=ffffffffffffffff");
QueryCacheKey qk = new QueryCacheKey(q);
QueryCacheKey qk2 = new QueryCacheKey(q2);
Result r = getSomeResult(q, "foo");
Result r2 = getSomeResult(q, "bar");
assertNull(cache.get(qk));
cache.put(qk, r);
assertNotNull(cache.get(qk));
assertEquals(cache.get(qk), r);
cache.put(qk2, r);
assertEquals(cache.get(qk2), r);
cache.put(qk, r2);
assertEquals(cache.get(qk), r2);
}
use of com.yahoo.prelude.cache.Cache in project vespa by vespa-engine.
the class CacheTestCase method testPutTooLarge.
@Test
public void testPutTooLarge() {
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;
}
// 9 KB
Cache cache = new Cache(9 * 1024, 3600, 100 * 1024, Statistics.nullImplementation);
assertFalse(cache.put("foo", tenKB));
assertTrue(cache.put("foo", sevenKB));
assertEquals(cache.get("foo"), sevenKB);
}
Aggregations