testPolicy("test-lru-with-old-config");
}
private void testPolicy(String cacheName) throws Exception
{
LRUExoCache cache = (LRUExoCache)service_.getCacheInstance(cacheName);
cache.put("a", "a");
cache.put("b", "a");
cache.put("c", "a");
cache.put("d", "a");
assertEquals(4, cache.getCacheSize());
cache.put("e", "a");
assertEquals(5, cache.getCacheSize());
cache.put("f", "a");
assertEquals(6, cache.getCacheSize());
Thread.sleep(1000);
assertFalse(cache.get("b") == null);
assertFalse(cache.get("c") == null);
assertFalse(cache.get("d") == null);
Thread.sleep(600);
assertEquals(3, cache.getCacheSize());
Thread.sleep(500);
assertEquals(0, cache.getCacheSize());
cache.setMaxSize(3);
cache.setTimeToLive(500);
cache.setMaxAge(1000);
cache.put("a", "a");
cache.put("b", "a");
cache.put("c", "a");
cache.put("d", "a");
assertEquals(4, cache.getCacheSize());
cache.put("e", "a");
assertEquals(5, cache.getCacheSize());
cache.put("f", "a");
Thread.sleep(500);
cache.get("a");
cache.get("b");
assertEquals(3, cache.getCacheSize());
Thread.sleep(600);
assertEquals(0, cache.getCacheSize());
}