mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
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
97 lines
3.5 KiB
Java
97 lines
3.5 KiB
Java
/*
|
|
* Copyright (C) 2005-2012 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package org.alfresco.repo.cache;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import java.util.Properties;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
/**
|
|
* Tests for the {@link DefaultCacheFactory} class.
|
|
*
|
|
* @author Matt Ward
|
|
*/
|
|
public class DefaultCacheFactoryTest
|
|
{
|
|
private DefaultCacheFactory<String, String> cacheFactory;
|
|
private Properties properties;
|
|
private DefaultSimpleCache<String, String> cache;
|
|
|
|
@Before
|
|
public void setUp() throws Exception
|
|
{
|
|
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);
|
|
}
|
|
|
|
@Test
|
|
public void canCreateCache()
|
|
{
|
|
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());
|
|
}
|
|
}
|