Search in sources :

Example 6 with CacheKey

use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.

the class InvalidateByCacheConfigVisitorTest method getInvalidateByCacheConfigVisitor.

private InvalidateByCacheConfigVisitor getInvalidateByCacheConfigVisitor(long delta, boolean knows) throws Exception {
    final DynamicClassLoaderManager dclm = mock(DynamicClassLoaderManager.class);
    final CacheKey cacheKey = mockCacheKey();
    final HttpCacheConfig cacheConfig;
    if (knows) {
        cacheConfig = mockCacheStore(cacheKey);
    } else {
        cacheConfig = mockCacheStore();
    }
    final InvalidateByCacheConfigVisitor visitor = new InvalidateByCacheConfigVisitor(11, delta, cacheConfig, dclm);
    final InvalidateByCacheConfigVisitor spy = spy(visitor);
    when(spy, "getCacheKey", any(Node.class)).thenReturn(mockCacheKey());
    return spy;
}
Also used : HttpCacheConfig(com.adobe.acs.commons.httpcache.config.HttpCacheConfig) DynamicClassLoaderManager(org.apache.sling.commons.classloader.DynamicClassLoaderManager) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

Example 7 with CacheKey

use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.

the class InvalidateByCacheConfigVisitorTest method mockCacheStore.

private HttpCacheConfig mockCacheStore(final CacheKey key) throws HttpCacheKeyCreationException {
    final HttpCacheConfig config = mock(HttpCacheConfig.class);
    when(config.knows(any(CacheKey.class))).thenReturn(true);
    return config;
}
Also used : HttpCacheConfig(com.adobe.acs.commons.httpcache.config.HttpCacheConfig) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

Example 8 with CacheKey

use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.

the class EntryNodeMapVisitorTest method test5entries.

@Test
public void test5entries() throws Exception {
    final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
    settings.setEntryNodeCount(5);
    final Node rootNode = new RootNodeMockFactory(settings).build();
    final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
    visitor.visit(rootNode);
    final Map<CacheKey, CacheContent> cache = visitor.getCache();
    assertEquals(5, 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 9 with CacheKey

use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.

the class EntryNodeMapVisitorTest method test10entries.

@Test
public void test10entries() throws Exception {
    final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
    settings.setEntryNodeCount(10);
    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 10 with CacheKey

use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.

the class BucketNodeFactoryTest method buildNodeFactoryWithMocks.

private BucketNodeFactory buildNodeFactoryWithMocks(MockSettings settings) throws RepositoryException, BucketNodeFactoryException {
    final CacheKey cacheKey = mockCacheKey(settings);
    when(session.nodeExists(MockSettings.VALID_ROOT_PATH)).thenReturn(true);
    when(session.getNode(MockSettings.VALID_ROOT_PATH)).thenReturn(cacheRootNode);
    final BucketNodeFactory bucketNodeFactory = new BucketNodeFactory(session, settings.cacheRootPath, cacheKey, settings.bucketNodeDepth);
    final int hashCode = cacheKey.hashCode();
    if (hashCode > 0) {
        final String hashString = StringUtils.leftPad(String.valueOf(hashCode), (int) HASHCODE_LENGTH, "0");
        final int increment = (int) Math.ceil(HASHCODE_LENGTH / settings.bucketNodeDepth);
        final String[] pathArray = new String[settings.bucketNodeDepth];
        for (int position = 0, i = 0; i < settings.bucketNodeDepth; position += increment, i++) {
            int endIndex = (position + increment > hashString.length()) ? hashString.length() : position + increment;
            String nodeName = StringUtils.leftPad(hashString.substring(position, endIndex), 5, "0");
            pathArray[i] = nodeName;
        }
        Node targetNode = cacheRootNode;
        for (String nodeName : pathArray) {
            Node childNode = mock(Node.class);
            when(childNode.getName()).thenReturn(nodeName);
            when(targetNode.hasNode(nodeName)).thenReturn(true);
            when(targetNode.getNode(nodeName)).thenReturn(childNode);
            when(childNode.getParent()).thenReturn(targetNode);
            targetNode = childNode;
        }
    }
    return bucketNodeFactory;
}
Also used : Node(javax.jcr.Node) CacheKey(com.adobe.acs.commons.httpcache.keys.CacheKey)

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