*/
public void testExpiredScheduler() throws Exception
{
final int cacheSize = 500;
final int liveTime = 30; // sec
WorkspaceStorageCache cache =
new LinkedWorkspaceStorageCacheImpl("testExpiredScheduler_cache", true, cacheSize, liveTime,
liveTime * 1000 + 10000, 10 * 1000, false, true, 0, true); // (*)
NodeData parent =
new TransientNodeData(QPath.parse("[]:1[]parent:1"), IdGenerator.generate(), 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0], 1, IdGenerator.generate(), new AccessControlList());
cache.put(parent);
List<NodeData> childs = new ArrayList<NodeData>();
for (int i = 0; i < 200; i++)
{
NodeData child =
TransientNodeData.createNodeData(parent, InternalQName.parse("[]node " + i + " :1"),
Constants.NT_UNSTRUCTURED);
cache.put(child);
childs.add(child);
}
assertEquals("Wrong size", 201 * 2, cache.getSize());
Thread.sleep(liveTime * 1000); // wait items expired
// but nothing can be getted
assertNull("Should be uncached (time expired)", cache.get(parent.getIdentifier()));
assertNull("Should be uncached (time expired)", cache.get(childs.get(10).getIdentifier()));
Thread.sleep((liveTime + 10) * 1000); // wait expired items will be removed by scheduler (*)
// items were removed on get
assertEquals("Wrong size", 0, cache.getSize());
}