* cachePurgeTrigFactor * size.
*/
public void testAutoPurge() {
try {
LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
0.70);
Random random = new Random(12345);
byte[] data = new byte[100];
Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
random.nextBytes(data);
byteMap.put("a1", data);
data = new byte[100];
random.nextBytes(data);
byteMap.put("a2", data);
data = new byte[100];
random.nextBytes(data);
byteMap.put("a3", data);
data = new byte[100];
random.nextBytes(data);
byteMap.put("a4", data);
cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
cache.getIfStored("a1"));
assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
cache.getIfStored("a2"));
assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
cache.getIfStored("a3"));
data = new byte[90];
random.nextBytes(data);
byteMap.put("a4", data);
// storing a4 should purge cache
cache.store("a4", new ByteArrayInputStream(byteMap.get("a4")));
Thread.sleep(1000);
assertNull("a1 should be null", cache.getIfStored("a1"));
assertNull("a2 should be null", cache.getIfStored("a2"));
assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
cache.getIfStored("a3"));
assertEquals(new ByteArrayInputStream(byteMap.get("a4")),
cache.getIfStored("a4"));
data = new byte[100];
random.nextBytes(data);
byteMap.put("a5", data);
cache.store("a5", new ByteArrayInputStream(byteMap.get("a5")));
assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
cache.getIfStored("a3"));
} catch (Exception e) {
LOG.error("error:", e);
fail();
}
}