Search in sources :

Example 1 with CacheKey

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());
}
Also used : RootNodeMockFactory(com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory) Node(javax.jcr.Node) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CacheKey

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());
}
Also used : RootNodeMockFactory(com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory) Node(javax.jcr.Node) CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with CacheKey

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;
}
Also used : DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

Example 4 with CacheKey

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;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

Example 5 with CacheKey

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);
        }
    }
}
Also used : CacheContent(com.adobe.acs.commons.httpcache.engine.CacheContent) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

CacheKey (com.adobe.acs.commons.httpcache.keys.CacheKey)13 CacheContent (com.adobe.acs.commons.httpcache.engine.CacheContent)6 Node (javax.jcr.Node)6 RootNodeMockFactory (com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HttpCacheConfig (com.adobe.acs.commons.httpcache.config.HttpCacheConfig)2 IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 DynamicClassLoaderManager (org.apache.sling.commons.classloader.DynamicClassLoaderManager)2 HttpCacheServletResponseWrapper (com.adobe.acs.commons.httpcache.engine.HttpCacheServletResponseWrapper)1 DynamicObjectInputStream (com.adobe.acs.commons.util.DynamicObjectInputStream)1 InputStream (java.io.InputStream)1 NodeIterator (javax.jcr.NodeIterator)1 Property (javax.jcr.Property)1