use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class EntryNodeMapVisitorTest method testNoEntries.
@Test
public void testNoEntries() throws Exception {
final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
settings.setEntryNodeCount(0);
final Node rootNode = new RootNodeMockFactory(settings).build();
final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
visitor.visit(rootNode);
final Map<CacheKey, CacheContent> cache = visitor.getCache();
assertTrue(cache.isEmpty());
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class EntryNodeMapVisitorTest method test5BucketDepth.
@Test
public void test5BucketDepth() throws Exception {
final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
settings.setEntryNodeCount(10);
settings.setBucketDepth(5);
final Node rootNode = new RootNodeMockFactory(settings).build();
final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
visitor.visit(rootNode);
final Map<CacheKey, CacheContent> cache = visitor.getCache();
assertEquals(10, cache.size());
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class EntryNodeByStringKeyVisitorTest method getMockedEntryNodeByStringKeyVisitor.
private EntryNodeByStringKeyVisitor getMockedEntryNodeByStringKeyVisitor(String cacheKeyStr, boolean match) throws Exception {
final DynamicClassLoaderManager dclm = mock(DynamicClassLoaderManager.class);
final EntryNodeByStringKeyVisitor visitor = new EntryNodeByStringKeyVisitor(11, dclm, cacheKeyStr);
final EntryNodeByStringKeyVisitor spy = spy(visitor);
final CacheKey cacheKey = mock(CacheKey.class);
if (match) {
when(cacheKey.toString()).thenReturn(cacheKeyStr);
} else {
when(cacheKey.toString()).thenReturn(RandomStringUtils.random(10000));
}
when(spy, "getCacheKey", any(Node.class)).thenReturn(cacheKey);
return spy;
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class BucketNodeHandler method getEntryIfExists.
public Node getEntryIfExists(CacheKey key) throws RepositoryException, IOException, ClassNotFoundException {
final NodeIterator entryNodeIterator = bucketNode.getNodes();
while (entryNodeIterator.hasNext()) {
Node entryNode = entryNodeIterator.nextNode();
CacheKey entryKey = new EntryNodeToCacheKeyHandler(entryNode, dynamicClassLoaderManager).get();
if (key.equals(entryKey)) {
return entryNode;
}
}
return null;
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class EntryNodeMapVisitor method entering.
protected void entering(final Node node, int level) throws RepositoryException {
super.entering(node, level);
if (isCacheEntryNode(node)) {
CacheKey cacheKey;
try {
cacheKey = getCacheKey(node);
CacheContent content = getCacheContent(node);
cache.put(cacheKey, content);
} catch (Exception e) {
log.error("Error in reading cache node!", e);
}
}
}
Aggregations