Fqn fqn8 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k");
Fqn fqn9 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k/l");
Fqn fqn10 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k/l/m");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
LFUAlgorithmConfig config = (LFUAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(-1);
config.setMinNodes(100);
region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn4, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn5, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn6, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn7, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn8, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn9, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn10, ADD_NODE_EVENT);
algo.process(region.getEvictionEventQueue());
LFUQueue queue = (LFUQueue) algo.evictionQueue;
assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());
for (NodeEntry ne : queue)
{
assertEquals(1, ne.getNumberOfNodeVisits());
}
// fqn1 visited 4 additional times.
region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
// fqn2 visited 3 additional times.
region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
// fqn3 visited 1 additional time.
region.registerEvictionEvent(fqn3, VISIT_NODE_EVENT);
// fqn4 visited 2 additional times.
region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
// fqn9 visited 1 additional time.
region.registerEvictionEvent(fqn9, VISIT_NODE_EVENT);
// fqn10 visited 2 additional times.
region.registerEvictionEvent(fqn10, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn10, VISIT_NODE_EVENT);
algo.process(region.getEvictionEventQueue());
int count = 0;
for (NodeEntry ne : queue)
{
count++;
if (count == 5 || count == 6)
{
assertEquals(2, ne.getNumberOfNodeVisits());
}
else if (count == 7 || count == 8)
{
assertEquals(3, ne.getNumberOfNodeVisits());
}
else if (count == 9)
{
assertEquals(4, ne.getNumberOfNodeVisits());
}
else if (count == 10)
{
assertEquals(5, ne.getNumberOfNodeVisits());
}
else
{
assertEquals(1, ne.getNumberOfNodeVisits());
}
}
assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());
Fqn fqn11 = Fqn.fromString("/a");
Fqn fqn12 = Fqn.fromString("/a/b");
region.registerEvictionEvent(fqn11, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn12, ADD_NODE_EVENT);
algo.process(region.getEvictionEventQueue());
count = 0;
for (NodeEntry ne : queue)
{
count++;
if (count == 7 || count == 8)
{
assertEquals(2, ne.getNumberOfNodeVisits());
}
else if (count == 9 || count == 10)
{
assertEquals(3, ne.getNumberOfNodeVisits());
}
else if (count == 11)
{
assertEquals(4, ne.getNumberOfNodeVisits());
}
else if (count == 12)
{
assertEquals(5, ne.getNumberOfNodeVisits());
}
else
{
assertEquals(1, ne.getNumberOfNodeVisits());
}
}
assertEquals(12, algo.getEvictionQueue().getNumberOfNodes());
region.registerEvictionEvent(fqn1, REMOVE_NODE_EVENT);
region.registerEvictionEvent(fqn11, REMOVE_NODE_EVENT);
region.registerEvictionEvent(fqn12, REMOVE_NODE_EVENT);
region.registerEvictionEvent(fqn10, REMOVE_NODE_EVENT);
algo.process(region.getEvictionEventQueue());
count = 0;
for (NodeEntry ne : queue)
{
count++;
if (count == 5 || count == 6)
{
assertEquals(2, ne.getNumberOfNodeVisits());
}
else if (count == 7)
{
assertEquals(3, ne.getNumberOfNodeVisits());
}
else if (count == 8)
{
assertEquals(4, ne.getNumberOfNodeVisits());
}
else
{
assertEquals(1, ne.getNumberOfNodeVisits());
}
}
assertEquals(8, algo.getEvictionQueue().getNumberOfNodes());
//test add/visit/remove combination
region.registerEvictionEvent(fqn11, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
// purposefully revisit a node that has been removed. assert that it is readded.
region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
region.registerEvictionEvent(fqn3, REMOVE_NODE_EVENT);
algo.process(region.getEvictionEventQueue());
count = 0;
for (NodeEntry ne : queue)
{
count++;