From 57e814314cef2876c957afa6970ae4411b06f172 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 9 Sep 2013 18:41:27 +0000 Subject: [PATCH] Merged from branch DEV/mward/head_cachefactory_conf to HEAD 54858: ALF-19668: Further cache configuration overrides 54859: ALF-19668: added clustered cache types to properties, e.g. createLocalCache, createCache, createInvalidateRemovalCache. 54867: ALF-19668: ClusterAwareCacheFactory now uses *.cluster.type properties to determine cache type. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55148 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/cache-context.xml | 42 +++++----- config/alfresco/caches.properties | 47 +++++++++++ .../repo/cache/AbstractCacheFactory.java | 62 +++++++++++++++ .../org/alfresco/repo/cache/CacheFactory.java | 26 +----- .../repo/cache/DefaultCacheFactory.java | 35 ++------ .../repo/cache/AbstractCacheFactoryTest.java | 79 +++++++++++++++++++ .../repo/cache/DefaultCacheFactoryTest.java | 24 ------ 7 files changed, 216 insertions(+), 99 deletions(-) create mode 100644 source/java/org/alfresco/repo/cache/AbstractCacheFactory.java create mode 100644 source/test-java/org/alfresco/repo/cache/AbstractCacheFactoryTest.java diff --git a/config/alfresco/cache-context.xml b/config/alfresco/cache-context.xml index 3846899759..ee61fbf69e 100644 --- a/config/alfresco/cache-context.xml +++ b/config/alfresco/cache-context.xml @@ -54,7 +54,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -94,13 +94,13 @@ - + - + @@ -110,7 +110,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -130,7 +130,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -159,7 +159,7 @@ - + @@ -175,7 +175,7 @@ - + @@ -185,7 +185,7 @@ - + @@ -195,7 +195,7 @@ - + @@ -371,7 +371,7 @@ - + @@ -384,11 +384,11 @@ - + - + @@ -403,7 +403,7 @@ AbstractRoutingContentStore.selectReadStore(String) will correct incorrect/missing cache entries and it doesn't really make sense to try to replicate or Serialize a ContentStore implementation. --> - + @@ -433,7 +433,7 @@ - + @@ -453,7 +453,7 @@ - + @@ -463,11 +463,11 @@ - + - + diff --git a/config/alfresco/caches.properties b/config/alfresco/caches.properties index ade3c81a06..9c93f3cda9 100644 --- a/config/alfresco/caches.properties +++ b/config/alfresco/caches.properties @@ -7,95 +7,114 @@ cache.propertyValueCache.tx.maxItems=1000 cache.propertyValueCache.maxItems=10000 cache.propertyValueCache.timeToLiveSeconds=0 cache.propertyValueCache.maxIdleSeconds=0 +cache.propertyValueCache.cluster.type=createInvalidateRemovalCache cache.contentDataSharedCache.tx.maxItems=65000 cache.contentDataSharedCache.maxItems=130000 cache.contentDataSharedCache.timeToLiveSeconds=0 cache.contentDataSharedCache.maxIdleSeconds=0 +cache.contentDataSharedCache.cluster.type=createCache cache.immutableEntitySharedCache.tx.maxItems=10000 cache.immutableEntitySharedCache.maxItems=50000 cache.immutableEntitySharedCache.timeToLiveSeconds=0 cache.immutableEntitySharedCache.maxIdleSeconds=0 +cache.immutableEntitySharedCache.cluster.type=createInvalidateRemovalCache cache.node.rootNodesSharedCache.tx.maxItems=1000 cache.node.rootNodesSharedCache.maxItems=1000 cache.node.rootNodesSharedCache.timeToLiveSeconds=0 cache.node.rootNodesSharedCache.maxIdleSeconds=0 +cache.node.rootNodesSharedCache.cluster.type=createInvalidateRemovalCache cache.node.allRootNodesSharedCache.tx.maxItems=500 cache.node.allRootNodesSharedCache.maxItems=1000 cache.node.allRootNodesSharedCache.timeToLiveSeconds=0 cache.node.allRootNodesSharedCache.maxIdleSeconds=0 +cache.node.allRootNodesSharedCache.cluster.type=createInvalidateRemovalCache cache.node.nodesSharedCache.tx.maxItems=125000 cache.node.nodesSharedCache.maxItems=250000 cache.node.nodesSharedCache.timeToLiveSeconds=0 cache.node.nodesSharedCache.maxIdleSeconds=0 +cache.node.nodesSharedCache.cluster.type=createInvalidateRemovalCache cache.node.aspectsSharedCache.tx.maxItems=65000 cache.node.aspectsSharedCache.maxItems=130000 cache.node.aspectsSharedCache.timeToLiveSeconds=0 cache.node.aspectsSharedCache.maxIdleSeconds=0 +cache.node.aspectsSharedCache.cluster.type=createLocalCache cache.node.propertiesSharedCache.tx.maxItems=65000 cache.node.propertiesSharedCache.maxItems=130000 cache.node.propertiesSharedCache.timeToLiveSeconds=0 cache.node.propertiesSharedCache.maxIdleSeconds=0 +cache.node.propertiesSharedCache.cluster.type=createLocalCache cache.node.parentAssocsSharedCache.maxItems=130000 cache.node.parentAssocsSharedCache.timeToLiveSeconds=0 cache.node.parentAssocsSharedCache.maxIdleSeconds=0 +cache.node.parentAssocsSharedCache.cluster.type=createCache cache.node.childByNameSharedCache.tx.maxItems=65000 cache.node.childByNameSharedCache.maxItems=130000 cache.node.childByNameSharedCache.timeToLiveSeconds=0 cache.node.childByNameSharedCache.maxIdleSeconds=0 +cache.node.childByNameSharedCache.cluster.type=createLocalCache cache.userToAuthoritySharedCache.tx.maxItems=100 cache.userToAuthoritySharedCache.maxItems=5000 cache.userToAuthoritySharedCache.timeToLiveSeconds=0 cache.userToAuthoritySharedCache.maxIdleSeconds=0 +cache.userToAuthoritySharedCache.cluster.type=createInvalidateRemovalCache cache.authenticationSharedCache.tx.maxItems=100 cache.authenticationSharedCache.maxItems=5000 cache.authenticationSharedCache.timeToLiveSeconds=0 cache.authenticationSharedCache.maxIdleSeconds=0 +cache.authenticationSharedCache.cluster.type=createCache cache.authoritySharedCache.tx.maxItems=10000 cache.authoritySharedCache.maxItems=10000 cache.authoritySharedCache.timeToLiveSeconds=0 cache.authoritySharedCache.maxIdleSeconds=0 +cache.authoritySharedCache.cluster.type=createInvalidateRemovalCache cache.authorityToChildAuthoritySharedCache.tx.maxItems=40000 cache.authorityToChildAuthoritySharedCache.maxItems=40000 cache.authorityToChildAuthoritySharedCache.timeToLiveSeconds=0 cache.authorityToChildAuthoritySharedCache.maxIdleSeconds=0 +cache.authorityToChildAuthoritySharedCache.cluster.type=createInvalidateRemovalCache cache.zoneToAuthoritySharedCache.tx.maxItems=500 cache.zoneToAuthoritySharedCache.maxItems=500 cache.zoneToAuthoritySharedCache.timeToLiveSeconds=0 cache.zoneToAuthoritySharedCache.maxIdleSeconds=0 +cache.zoneToAuthoritySharedCache.cluster.type=createInvalidateRemovalCache cache.permissionsAccessSharedCache.tx.maxItems=10000 cache.permissionsAccessSharedCache.maxItems=50000 cache.permissionsAccessSharedCache.timeToLiveSeconds=0 cache.permissionsAccessSharedCache.maxIdleSeconds=0 +cache.permissionsAccessSharedCache.cluster.type=createCache cache.readersSharedCache.tx.maxItems=10000 cache.readersSharedCache.maxItems=10000 cache.readersSharedCache.timeToLiveSeconds=0 cache.readersSharedCache.maxIdleSeconds=0 +cache.readersSharedCache.cluster.type=createCache cache.readersDeniedSharedCache.tx.maxItems=10000 cache.readersDeniedSharedCache.maxItems=10000 cache.readersDeniedSharedCache.timeToLiveSeconds=0 cache.readersDeniedSharedCache.maxIdleSeconds=0 +cache.readersDeniedSharedCache.cluster.type=createCache cache.nodeOwnerSharedCache.tx.maxItems=40000 cache.nodeOwnerSharedCache.maxItems=40000 cache.nodeOwnerSharedCache.timeToLiveSeconds=0 cache.nodeOwnerSharedCache.maxIdleSeconds=0 +cache.nodeOwnerSharedCache.cluster.type=createCache cache.nodeRulesSharedCache.tx.maxItems=2000 @@ -103,29 +122,35 @@ cache.personSharedCache.tx.maxItems=1000 cache.personSharedCache.maxItems=1000 cache.personSharedCache.timeToLiveSeconds=0 cache.personSharedCache.maxIdleSeconds=0 +cache.personSharedCache.cluster.type=createCache cache.ticketsCache.maxItems=1000 cache.ticketsCache.timeToLiveSeconds=0 cache.ticketsCache.maxIdleSeconds=0 +cache.ticketsCache.cluster.type=createCache cache.avmEntitySharedCache.tx.maxItems=5000 cache.avmEntitySharedCache.maxItems=5000 cache.avmEntitySharedCache.timeToLiveSeconds=0 cache.avmEntitySharedCache.maxIdleSeconds=0 +cache.avmEntitySharedCache.cluster.type=createCache cache.avmVersionRootEntitySharedCache.maxItems=1000 cache.avmVersionRootEntitySharedCache.timeToLiveSeconds=0 cache.avmVersionRootEntitySharedCache.maxIdleSeconds=0 +cache.avmVersionRootEntitySharedCache.cluster.type=createCache cache.avmNodeSharedCache.tx.maxItems=5000 cache.avmNodeSharedCache.maxItems=5000 cache.avmNodeSharedCache.timeToLiveSeconds=0 cache.avmNodeSharedCache.maxIdleSeconds=0 +cache.avmNodeSharedCache.cluster.type=createCache cache.avmNodeAspectsSharedCache.tx.maxItems=5000 cache.avmNodeAspectsSharedCache.maxItems=5000 cache.avmNodeAspectsSharedCache.timeToLiveSeconds=0 cache.avmNodeAspectsSharedCache.maxIdleSeconds=0 +cache.avmNodeAspectsSharedCache.cluster.type=createCache cache.avmStoreSharedCache.tx.maxItems=1000 @@ -137,80 +162,97 @@ cache.webServicesQuerySessionSharedCache.tx.maxItems=50 cache.webServicesQuerySessionSharedCache.maxItems=1000 cache.webServicesQuerySessionSharedCache.timeToLiveSeconds=0 cache.webServicesQuerySessionSharedCache.maxIdleSeconds=0 +cache.webServicesQuerySessionSharedCache.cluster.type=createCache cache.aclSharedCache.tx.maxItems=20000 cache.aclSharedCache.maxItems=50000 cache.aclSharedCache.timeToLiveSeconds=0 cache.aclSharedCache.maxIdleSeconds=0 +cache.aclSharedCache.cluster.type=createCache cache.aclEntitySharedCache.tx.maxItems=50000 cache.aclEntitySharedCache.maxItems=50000 cache.aclEntitySharedCache.timeToLiveSeconds=0 cache.aclEntitySharedCache.maxIdleSeconds=0 +cache.aclEntitySharedCache.cluster.type=createCache cache.resourceBundleBaseNamesSharedCache.tx.maxItems=1000 cache.resourceBundleBaseNamesSharedCache.maxItems=1000 cache.resourceBundleBaseNamesSharedCache.timeToLiveSeconds=0 cache.resourceBundleBaseNamesSharedCache.maxIdleSeconds=0 +cache.resourceBundleBaseNamesSharedCache.cluster.type=createCache cache.loadedResourceBundlesSharedCache.tx.maxItems=1000 cache.loadedResourceBundlesSharedCache.maxItems=1000 cache.loadedResourceBundlesSharedCache.timeToLiveSeconds=0 cache.loadedResourceBundlesSharedCache.maxIdleSeconds=0 +cache.loadedResourceBundlesSharedCache.cluster.type=createCache cache.messagesSharedCache.tx.maxItems=1000 cache.messagesSharedCache.maxItems=1000 cache.messagesSharedCache.timeToLiveSeconds=0 cache.messagesSharedCache.maxIdleSeconds=0 +cache.messagesSharedCache.cluster.type=createCache cache.compiledModelsSharedCache.maxItems=1000 cache.compiledModelsSharedCache.timeToLiveSeconds=0 cache.compiledModelsSharedCache.maxIdleSeconds=0 +cache.compiledModelsSharedCache.cluster.type=createInvalidateRemovalCache cache.webScriptsRegistrySharedCache.maxItems=1000 cache.webScriptsRegistrySharedCache.timeToLiveSeconds=0 cache.webScriptsRegistrySharedCache.maxIdleSeconds=0 +cache.webScriptsRegistrySharedCache.cluster.type=createInvalidateRemovalCache cache.routingContentStoreSharedCache.tx.maxItems=10000 cache.routingContentStoreSharedCache.maxItems=10000 cache.routingContentStoreSharedCache.timeToLiveSeconds=0 cache.routingContentStoreSharedCache.maxIdleSeconds=0 +cache.routingContentStoreSharedCache.cluster.type=createLocalCache cache.executingActionsCache.maxItems=1000 cache.executingActionsCache.timeToLiveSeconds=0 cache.executingActionsCache.maxIdleSeconds=0 +cache.executingActionsCache.cluster.type=createCache cache.tagscopeSummarySharedCache.tx.maxItems=1000 cache.tagscopeSummarySharedCache.maxItems=1000 cache.tagscopeSummarySharedCache.timeToLiveSeconds=0 cache.tagscopeSummarySharedCache.maxIdleSeconds=0 +cache.tagscopeSummarySharedCache.cluster.type=createCache cache.imapMessageSharedCache.tx.maxItems=1000 cache.imapMessageSharedCache.maxItems=2000 cache.imapMessageSharedCache.timeToLiveSeconds=0 cache.imapMessageSharedCache.maxIdleSeconds=0 +cache.imapMessageSharedCache.cluster.type=createInvalidateRemovalCache cache.tenantEntitySharedCache.tx.maxItems=1000 cache.tenantEntitySharedCache.maxItems=1000 cache.tenantEntitySharedCache.timeToLiveSeconds=0 cache.tenantEntitySharedCache.maxIdleSeconds=0 +cache.tenantEntitySharedCache.cluster.type=createCache cache.immutableSingletonSharedCache.tx.maxItems=12000 cache.immutableSingletonSharedCache.maxItems=12000 cache.immutableSingletonSharedCache.timeToLiveSeconds=0 cache.immutableSingletonSharedCache.maxIdleSeconds=0 +cache.immutableSingletonSharedCache.cluster.type=createInvalidateRemovalCache cache.remoteAlfrescoTicketService.ticketsCache.maxItems=1000 cache.remoteAlfrescoTicketService.ticketsCache.timeToLiveSeconds=0 cache.remoteAlfrescoTicketService.ticketsCache.maxIdleSeconds=0 +cache.remoteAlfrescoTicketService.ticketsCache.cluster.type=createCache cache.contentDiskDriver.fileInfoCache.maxItems=1000 cache.contentDiskDriver.fileInfoCache.timeToLiveSeconds=0 cache.contentDiskDriver.fileInfoCache.maxIdleSeconds=0 +cache.contentDiskDriver.fileInfoCache.cluster.type=createLocalCache cache.globalConfigSharedCache.maxItems=1000 cache.globalConfigSharedCache.timeToLiveSeconds=0 cache.globalConfigSharedCache.maxIdleSeconds=0 +cache.globalConfigSharedCache.cluster.type=createInvalidateRemovalCache cache.permissionEntitySharedCache.tx.maxItems=50000 @@ -218,22 +260,27 @@ cache.propertyUniqueContextSharedCache.tx.maxItems=10000 cache.propertyUniqueContextSharedCache.maxItems=10000 cache.propertyUniqueContextSharedCache.timeToLiveSeconds=0 cache.propertyUniqueContextSharedCache.maxIdleSeconds=0 +cache.propertyUniqueContextSharedCache.cluster.type=createInvalidateRemovalCache cache.siteNodeRefSharedCache.tx.maxItems=5000 cache.siteNodeRefSharedCache.maxItems=5000 cache.siteNodeRefSharedCache.timeToLiveSeconds=0 cache.siteNodeRefSharedCache.maxIdleSeconds=0 +cache.siteNodeRefSharedCache.cluster.type=createCache cache.samlTrustEngineSharedCache.tx.maxItems=5000 cache.samlTrustEngineSharedCache.maxItems=5000 cache.samlTrustEngineSharedCache.timeToLiveSeconds=0 cache.samlTrustEngineSharedCache.maxIdleSeconds=0 +cache.samlTrustEngineSharedCache.cluster.type=createCache # Caching content store, see caching-content-store-context.xml.sample* cache.cachingContentStoreCache.maxItems=5000 cache.cachingContentStoreCache.timeToLiveSeconds=0 cache.cachingContentStoreCache.maxIdleSeconds=86400 +cache.cachingContentStoreCache.cluster.type=createCache cache.publicapi.webScriptsRegistryCache.maxItems=1000 cache.publicapi.webScriptsRegistryCache.timeToLiveSeconds=0 cache.publicapi.webScriptsRegistryCache.maxIdleSeconds=0 +cache.publicapi.webScriptsRegistryCache.cluster.type=createInvalidateRemovalCache diff --git a/source/java/org/alfresco/repo/cache/AbstractCacheFactory.java b/source/java/org/alfresco/repo/cache/AbstractCacheFactory.java new file mode 100644 index 0000000000..4057d1737b --- /dev/null +++ b/source/java/org/alfresco/repo/cache/AbstractCacheFactory.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2005-2013 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.cache; + +import java.io.Serializable; +import java.util.Properties; + +/** + * Abstract {@link CacheFactory} implementation containing common functionality + * such as cache configuration properties support. + * + * @author Matt Ward + */ +public abstract class AbstractCacheFactory implements CacheFactory +{ + private static final String PROP_SEPERATOR = "."; + private Properties properties; + + public String getProperty(String cacheName, String propName, final String defaultValue) + { + final String fqPropName = cacheName + PROP_SEPERATOR + propName; + String value = properties.getProperty(fqPropName); + if (value != null) + { + value = value.trim(); + } + if (value == null || value.isEmpty()) + { + value = defaultValue; + } + return value; + } + + /** + * Provide properties to parameterize cache creation. Cache properties are prefixed + * with the cacheName supplied when invoking {@link DefaultCacheFactory#createCache(String)}. + * For example, for a cache named cache.ticketsCache the property cache.ticketsCache.maxItems + * will determine the capacity of the cache. + * + * @param properties + */ + public void setProperties(Properties properties) + { + this.properties = properties; + } +} diff --git a/source/java/org/alfresco/repo/cache/CacheFactory.java b/source/java/org/alfresco/repo/cache/CacheFactory.java index a712beb914..c94276b3de 100644 --- a/source/java/org/alfresco/repo/cache/CacheFactory.java +++ b/source/java/org/alfresco/repo/cache/CacheFactory.java @@ -30,33 +30,11 @@ import java.io.Serializable; public interface CacheFactory { /** - * Creates a fully distributed cache (when clustering is enabled and active). + * Creates a cache. The type of cache (e.g. localised, clustered etc.) produced is + * dependant on the factory implementation, and will vary at runtime. * * @param cacheName * @return SimpleCache */ SimpleCache createCache(String cacheName); - - /** - * Creates a "local" cache, i.e. one that exists only on the JVM that created it. It does not - * attempt to replicate any data, send invalidation messages etc. and is intended for use - * only where the data does not need to be shared and where remote operations should be avoided for - * performance reasons. - * - * @param cacheName - * @return SimpleCache - */ - SimpleCache createLocalCache(String cacheName); - - /** - *

Creates a local (as opposed to fully-distributed) cache that broadcasts invalidation messages - * to its peers on other cluster members upon cache item removal. Its peers then remove the - * corresponding cache item.

- * - *

This cache does not replicate put(k,v) invocations.

- * - * @param cacheName - * @return SimpleCache - */ - SimpleCache createInvalidateRemovalCache(String cacheName); } diff --git a/source/java/org/alfresco/repo/cache/DefaultCacheFactory.java b/source/java/org/alfresco/repo/cache/DefaultCacheFactory.java index 2222e896f1..7828002c24 100644 --- a/source/java/org/alfresco/repo/cache/DefaultCacheFactory.java +++ b/source/java/org/alfresco/repo/cache/DefaultCacheFactory.java @@ -32,10 +32,10 @@ import org.apache.commons.logging.LogFactory; * * @author Matt Ward */ -public class DefaultCacheFactory implements CacheFactory +public class DefaultCacheFactory extends AbstractCacheFactory { private static final Log log = LogFactory.getLog(DefaultCacheFactory.class); - private Properties properties; + @Override public SimpleCache createCache(String cacheName) @@ -43,8 +43,7 @@ public class DefaultCacheFactory implements CacheFact return createLocalCache(cacheName); } - @Override - public SimpleCache createLocalCache(String cacheName) + private SimpleCache createLocalCache(String cacheName) { DefaultSimpleCache cache = new DefaultSimpleCache(); cache.setCacheName(cacheName); @@ -61,34 +60,10 @@ public class DefaultCacheFactory implements CacheFact return cache; } - private SimpleCache createInvalidatingCache(String cacheName) - { - return createLocalCache(cacheName); - } - - @Override - public SimpleCache createInvalidateRemovalCache(String cacheName) - { - return createLocalCache(cacheName); - } - private int maxItems(String cacheName) { - String maxItemsStr = properties.getProperty(cacheName + ".maxItems"); - Integer maxItems = maxItemsStr != null ? Integer.parseInt(maxItemsStr) : 0; + String maxItemsStr = getProperty(cacheName, "maxItems", "0"); + Integer maxItems = Integer.parseInt(maxItemsStr); return maxItems.intValue(); } - - /** - * Provide properties to parameterize cache creation. Cache properties are prefixed - * with the cacheName supplied when invoking {@link DefaultCacheFactory#createCache(String)}. - * For example, for a cache named cache.ticketsCache the property cache.ticketsCache.maxItems - * will determine the capacity of the cache. - * - * @param properties - */ - public void setProperties(Properties properties) - { - this.properties = properties; - } } diff --git a/source/test-java/org/alfresco/repo/cache/AbstractCacheFactoryTest.java b/source/test-java/org/alfresco/repo/cache/AbstractCacheFactoryTest.java new file mode 100644 index 0000000000..1bab0c1dec --- /dev/null +++ b/source/test-java/org/alfresco/repo/cache/AbstractCacheFactoryTest.java @@ -0,0 +1,79 @@ +package org.alfresco.repo.cache; + +import static org.junit.Assert.*; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; + +public class AbstractCacheFactoryTest +{ + // The class under test. + private AbstractCacheFactory cacheFactory; + private Properties properties; + + @Before + public void setUp() throws Exception + { + cacheFactory = new CacheFactoryTestImpl(); + + properties = new Properties(); + cacheFactory.setProperties(properties); + } + + @Test + public void nullPropertyYieldsDefault() + { + // Null property, null default + assertNull(cacheFactory.getProperty("the.cache.name", "noProperty", null)); + + // Null property, non-empty default + assertEquals("non-empty-default", cacheFactory.getProperty("the.cache.name", "noProperty", "non-empty-default")); + } + + @Test + public void emptyPropertyYieldsDefault() + { + // Empty property, empty default + properties.setProperty("the.cache.name.emptyProperty", ""); + assertEquals("", cacheFactory.getProperty("the.cache.name", "emptyProperty", "")); + + // Empty property, null default + properties.setProperty("the.cache.name.emptyProperty", ""); + assertEquals(null, cacheFactory.getProperty("the.cache.name", "emptyProperty", null)); + + // Empty property, non-empty default + properties.setProperty("the.cache.name.emptyProperty", ""); + assertEquals("non-empty-default", cacheFactory.getProperty("the.cache.name", "emptyProperty", "non-empty-default")); + + // Empty/whitespace property + properties.setProperty("the.cache.name.emptyProperty", " \t "); + assertEquals("default", cacheFactory.getProperty("the.cache.name", "emptyProperty", "default")); + } + + @Test + public void nonEmptyPropertyIsReturned() + { + // Non-empty property + properties.setProperty("the.cache.name.nonEmpty", "this has a non-empty value"); + assertEquals("this has a non-empty value", cacheFactory.getProperty("the.cache.name", "nonEmpty", "default")); + } + + @Test + public void nonEmptyPropertyIsTrimmedOfWhitespace() + { + properties.setProperty("the.cache.name.nonEmpty", " \t value \t"); + assertEquals("value", cacheFactory.getProperty("the.cache.name", "nonEmpty", "default")); + } + + + private static class CacheFactoryTestImpl extends AbstractCacheFactory + { + @Override + public SimpleCache createCache(String cacheName) + { + return null; + } + } +} diff --git a/source/test-java/org/alfresco/repo/cache/DefaultCacheFactoryTest.java b/source/test-java/org/alfresco/repo/cache/DefaultCacheFactoryTest.java index 7ffbc4eba0..a4ed317757 100644 --- a/source/test-java/org/alfresco/repo/cache/DefaultCacheFactoryTest.java +++ b/source/test-java/org/alfresco/repo/cache/DefaultCacheFactoryTest.java @@ -52,28 +52,4 @@ public class DefaultCacheFactoryTest assertEquals(4, cache.getMaxItems()); assertEquals("cache.someCache", cache.getCacheName()); } - - @Test - public void canCreateLocalCache() - { - cache = (DefaultSimpleCache) cacheFactory.createLocalCache("cache.someCache"); - assertEquals(4, cache.getMaxItems()); - assertEquals("cache.someCache", cache.getCacheName()); - } - - @Test - public void canCreateInvalidatingCache() - { - cache = (DefaultSimpleCache) cacheFactory.createInvalidateRemovalCache("cache.someCache"); - assertEquals(4, cache.getMaxItems()); - assertEquals("cache.someCache", cache.getCacheName()); - } - - @Test - public void canCreateInvalidateRemovalCache() - { - cache = (DefaultSimpleCache) cacheFactory.createInvalidateRemovalCache("cache.someCache"); - assertEquals(4, cache.getMaxItems()); - assertEquals("cache.someCache", cache.getCacheName()); - } }