String rootStr = "/org/jboss/test/data/";
for (int i = 0; i < 10; i++)
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
try
{
cache.put(fqn, str, str);
}
catch (Exception e)
{
fail("Failed to insert data" + e);
e.printStackTrace();
}
}
evController.startEviction();
try
{
for (int i = 0; i < 5; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
assertNull("Fqn " + fqn + " should be null", cache.get(fqn, str));
}
for (int i = 5; i < 10; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
assertNotNull(cache.get(fqn, str));
}
// since min is 5 the cache won't deplete past 5 nodes left in the cache.
for (int i = 5; i < 10; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
assertNotNull(cache.get(fqn, str));
}
// now we add some more nodes and we selectively visit some older nodes but not all. they should not get
// evicted when the thread next runs.
for (int i = 5; i < 7; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
cache.get(fqn, str);
}
// add 2 more to push the limit to 5 so we cause the old unvisited nodes to get evicted.
for (int i = 10; i < 13; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
cache.put(fqn, str, str);
// now bring up their hit count for LFU purposes (cache hit count based eviction).
for (int k = 0; k < 10; k++)
{
cache.get(fqn, str);
}
}
evController.startEviction();
// now make sure we still only have 5 nodes and they are the ones we expect based on LFU
for (int i = 5; i < 7; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
assertNotNull(cache.get(fqn, str));
}
for (int i = 7; i < 10; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
assertNull(cache.get(fqn, str));
}
for (int i = 10; i < 13; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
assertNotNull(cache.get(fqn, str));
}
}
catch (Exception e)