assertTrue(map.containsKey("third key"));
assertEquals("third value", map.get("third key"));
}
public void testExpire() throws InterruptedException {
Cache cache = new TimeLimited();
try {
Properties params = new Properties();
params.put(Cache.PARAM_NAME, "dummy");
params.put(TimeLimited.PARAM_TTL, "5");
cache.initialize(params);
} catch (CacheAcquireException ex) {
fail("Unexpected CacheAcquireException at initialization.");
}
assertEquals(0, cache.size());
assertNull(cache.put("a", "#a"));
assertEquals(1, cache.size());
assertTrue(cache.containsKey("a"));
Thread.sleep(500);
assertEquals("#a", cache.put("a", "#a"));
assertEquals(1, cache.size());
assertTrue(cache.containsKey("a"));
Thread.sleep(500);
assertNull(cache.put("b", "#b"));
assertEquals(2, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
Thread.sleep(500);
assertNull(cache.put("c", "#c"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
Thread.sleep(500);
assertNull(cache.put("d", "#d"));
assertEquals(4, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
Thread.sleep(500);
assertNull(cache.put("e", "#e"));
assertEquals(5, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("e"));
Thread.sleep(500);
assertNull(cache.put("f", "#f"));
assertEquals(6, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("e"));
assertTrue(cache.containsKey("f"));
Thread.sleep(500);
assertNull(cache.put("g", "#g"));
assertEquals(7, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("e"));
assertTrue(cache.containsKey("f"));
assertTrue(cache.containsKey("g"));
Thread.sleep(500);
assertNull(cache.put("h", "#h"));
assertEquals(8, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("e"));
assertTrue(cache.containsKey("f"));
assertTrue(cache.containsKey("g"));
assertTrue(cache.containsKey("h"));
while (cache.size() > 0) {
Thread.sleep(500);
checkKeys(cache);
}
}