logger.info("total used=" + Ram.inMb(mem.used()));
}
@Test
public void checkExpiration() throws InterruptedException {
OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(10 * 1024 * 1024);
assertNotNull(mem);
int size = 400;
int howMany = 5000;
logger.info("off-heap capacity=" + Ram.inMb(mem.capacity()));
logger.info("payload size=" + Ram.inKb(size));
logger.info("entries=" + howMany);
byte[] payload = new byte[size];
for (int i = 0; i < howMany; i++) {
mem.store(payload, 2000);
}
assertEquals(size*howMany, mem.used());
logger.info("entries with relative expiration=" + (howMany/2));
for (int i = 0; i < howMany/2; i++) {
mem.store(payload, 100);
}
assertEquals(size*howMany+size*howMany/2, mem.used());
logger.info("entries with absolute expiration=" + (howMany/2));
for (int i = 0; i < howMany/2; i++) {
mem.store(payload, new Date());
}
assertEquals(size*howMany*2, mem.used());
logger.info("total used=" + Ram.inMb(mem.used()));
Thread.sleep(500);
logger.info("calling disposeExpiredAbsolute");
mem.disposeExpiredAbsolute();
logger.info("total used=" + Ram.inMb(mem.used()));
assertEquals(size*howMany+size*howMany/2, mem.used());
logger.info("calling disposeExpiredRelative");
mem.disposeExpiredRelative();
logger.info("total used=" + Ram.inMb(mem.used()));
assertEquals(size*howMany, mem.used());
Thread.sleep(2000);
logger.info("calling disposeExpiredRelative again");
mem.disposeExpiredRelative();
logger.info("total used=" + Ram.inMb(mem.used()));
assertEquals(0, mem.used());
}