assertTrue(map.containsKey("third key"));
assertEquals("third value", map.get("third key"));
}
public void testExpire() {
Cache cache = new CountLimited();
try {
Properties params = new Properties();
params.put(Cache.PARAM_NAME, "dummy");
params.put(CountLimited.PARAM_CAPACITY, "3");
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"));
assertNull(cache.put("b", "#b"));
assertEquals(2, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertNull(cache.put("c", "#c"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertNull(cache.put("d", "#d"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertEquals("#c", cache.put("c", "#c1"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertEquals("#c1", cache.put("c", "#c2"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertEquals("#c2", cache.put("c", "#c3"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertEquals("#b", cache.put("b", "#b"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertNull(cache.put("e", "#e"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("e"));
assertNull(cache.put("f", "#f"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("e"));
assertTrue(cache.containsKey("f"));
assertEquals("#e", cache.remove("e"));
assertEquals(2, cache.size());
assertTrue(cache.containsKey("d"));
assertTrue(cache.containsKey("f"));
assertNull(cache.put("g", "#g"));
assertEquals(2, cache.size());
assertTrue(cache.containsKey("f"));
assertTrue(cache.containsKey("g"));
assertEquals("#f", cache.remove("f"));
assertEquals(1, cache.size());
assertTrue(cache.containsKey("g"));
assertNull(cache.remove("b"));
assertEquals(1, cache.size());
assertTrue(cache.containsKey("g"));
assertEquals("#g", cache.remove("g"));
assertEquals(0, cache.size());
assertNull(cache.remove("x"));
assertEquals(0, cache.size());
assertNull(cache.put("a", "#a"));
assertEquals(1, cache.size());
assertTrue(cache.containsKey("a"));
assertNull(cache.put("b", "#b"));
assertEquals(2, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertNull(cache.put("c", "#c"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("a"));
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertNull(cache.put("d", "#d"));
assertEquals(3, cache.size());
assertTrue(cache.containsKey("b"));
assertTrue(cache.containsKey("c"));
assertTrue(cache.containsKey("d"));
}