Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

59851: Merged BRANCHES/DEV/mward/head_bf_gdata_upgd to BRANCHES/DEV/HEAD-BUG-FIX (local cache improvements):
      59586: DefaultSimpleCache max size is Integer.MAX_VALUE when configured with maxItems of 0.
      59590: maxItems for DefaultSimpleCache is now an optional feature.
      59592: non-clustered caches will not use size-based eviction when {cacheName}.eviction-policy=NONE, to match clustered caches.
      59594: Added TTL to DefaultSimpleCache - not yet configurable through the factory.
      59602: DefaultCacheFactory can create caches with a time-to-live setting enabled.
      59620: Organise imports for DefaultSimpleCache
      59622: DefaultSimpleCache: changed field name from map to cache, as this makes more sense with changing to use of CacheBuilder.
      59627: Added maxIdleSecs property to DefaultSimpleCache - not yet configurable from the cache factory.
      59629: DefaultCacheFactory now supports maxIdleSeconds property for configuring non-clustered caches.
      59633: Updated description of supported non-clustered cache properties in caches.properties


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62192 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-02-12 08:06:59 +00:00
parent bdba166058
commit 79ccf18f85
5 changed files with 263 additions and 32 deletions

View File

@@ -18,7 +18,7 @@
*/
package org.alfresco.repo.cache;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.util.Properties;
@@ -41,7 +41,21 @@ public class DefaultCacheFactoryTest
{
cacheFactory = new DefaultCacheFactory<String, String>();
properties = new Properties();
// cache.someCache
properties.setProperty("cache.someCache.maxItems", "4");
properties.setProperty("cache.someCache.eviction-policy", "EVICT"); // Anything but NONE
// cache.noSizeLimit
properties.setProperty("cache.noSizeLimit.maxItems", "2"); // No effect
properties.setProperty("cache.noSizeLimit.eviction-policy", "NONE");
// cache.withTTL
properties.setProperty("cache.withTTL.maxItems", "0");
properties.setProperty("cache.withTTL.eviction-policy", "NONE");
properties.setProperty("cache.withTTL.timeToLiveSeconds", "6");
// cache.withMaxIdle
properties.setProperty("cache.withMaxIdle.maxItems", "0");
properties.setProperty("cache.withMaxIdle.eviction-policy", "NONE");
properties.setProperty("cache.withMaxIdle.maxIdleSeconds", "7");
cacheFactory.setProperties(properties);
}
@@ -51,5 +65,32 @@ public class DefaultCacheFactoryTest
cache = (DefaultSimpleCache<String, String>) cacheFactory.createCache("cache.someCache");
assertEquals(4, cache.getMaxItems());
assertEquals("cache.someCache", cache.getCacheName());
assertTrue(cache.isUseMaxItems());
}
@Test
public void canCreateUnboundedCache()
{
cache = (DefaultSimpleCache<String, String>) cacheFactory.createCache("cache.noSizeLimit");
assertEquals(2, cache.getMaxItems());
assertEquals("cache.noSizeLimit", cache.getCacheName());
assertFalse(cache.isUseMaxItems());
}
@Test
public void canCreateCacheWithTTL()
{
cache = (DefaultSimpleCache<String, String>) cacheFactory.createCache("cache.withTTL");
assertEquals("cache.withTTL", cache.getCacheName());
assertEquals(6, cache.getTTLSecs());
}
@Test
public void canCreateCacheWithMaxIdle()
{
cache = (DefaultSimpleCache<String, String>) cacheFactory.createCache("cache.withMaxIdle");
assertEquals("cache.withMaxIdle", cache.getCacheName());
assertEquals(0, cache.getTTLSecs());
assertEquals(7, cache.getMaxIdleSecs());
}
}