Open
Description
I'm trying to understand how idleScanTime
works. I've created a test, and can't realize why it fails. It looks like a bug to me.
public class Test {
public static void main(String[] args) throws InterruptedException {
// GIVEN
var cache = new Cache2kBuilder<Integer, String>() {}
.idleScanTime(Duration.of(500, ChronoUnit.MILLIS))
.build();
// WHEN
cache.put(1, "1");
// THEN
for (int i = 0; i < 60; i++) {
Thread.sleep(30);
if (!"1".equals(cache.get(1))) {
// This exception is thrown on i=33
throw new RuntimeException(
"Cache supposed to have the value as last access was 30 milliseconds ago"
);
}
}
Thread.sleep(1600);
if (cache.get(1) != null) {
throw new RuntimeException(
"Cache supposed to be empty as value last access was more than (idleScanTime * 3) milliseconds ago"
);
}
}
}